38 lines
1.1 KiB
C
38 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "../nostr_core/nip004.h"
|
|
#include "../nostr_core/nostr_common.h"
|
|
#include "../nostr_core/utils.h"
|
|
|
|
int main(void) {
|
|
// Test vector 1 from the existing test
|
|
const char* sk1_hex = "91ba716fa9e7ea2fcbad360cf4f8e0d312f73984da63d90f524ad61a6a1e7dbe";
|
|
const char* pk2_hex = "dcb33a629560280a0ee3b6b99b68c044fe8914ad8a984001ebf6099a9b474dc3";
|
|
const char* plaintext = "nanana";
|
|
|
|
// Convert hex keys to bytes using the system function
|
|
unsigned char sk1[32], pk2[32];
|
|
nostr_hex_to_bytes(sk1_hex, sk1, 32);
|
|
nostr_hex_to_bytes(pk2_hex, pk2, 32);
|
|
|
|
// Allocate output buffer
|
|
char* encrypted = malloc(NOSTR_NIP04_MAX_ENCRYPTED_SIZE);
|
|
if (!encrypted) {
|
|
printf("Memory allocation failed\n");
|
|
return 1;
|
|
}
|
|
|
|
// Call the encryption function
|
|
int result = nostr_nip04_encrypt(sk1, pk2, plaintext, encrypted, NOSTR_NIP04_MAX_ENCRYPTED_SIZE);
|
|
|
|
if (result == NOSTR_SUCCESS) {
|
|
printf("%s\n", encrypted);
|
|
} else {
|
|
printf("Error: %s\n", nostr_strerror(result));
|
|
}
|
|
|
|
free(encrypted);
|
|
return 0;
|
|
}
|