67 lines
2.1 KiB
C
67 lines
2.1 KiB
C
/*
|
|
* NOSTR Core Library - NIP-03 Test
|
|
*/
|
|
|
|
#include "nostr_core/nostr_core.h"
|
|
#include "nostr_core/nip003.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
|
|
void test_nip03_create_proof_event() {
|
|
printf("🧪 Testing NIP-03 proof event creation...\n");
|
|
|
|
unsigned char private_key[32];
|
|
unsigned char public_key[32];
|
|
nostr_generate_keypair(private_key, public_key);
|
|
|
|
const char* target_id = "e71c6ea722987debdb60f81f9ea4f604b5ac0664120dd64fb9d23abc4ec7c323";
|
|
int target_kind = 1;
|
|
const char* ots_b64 = "base64encodedotsdata";
|
|
const char* relay = "wss://relay.example.com";
|
|
|
|
cJSON* event = nostr_nip03_create_proof_event(target_id, target_kind, ots_b64, relay, private_key);
|
|
assert(event != NULL);
|
|
|
|
// Verify kind
|
|
cJSON* kind = cJSON_GetObjectItem(event, "kind");
|
|
assert(kind != NULL && kind->valueint == 1040);
|
|
|
|
// Verify content
|
|
cJSON* content = cJSON_GetObjectItem(event, "content");
|
|
assert(content != NULL && strcmp(content->valuestring, ots_b64) == 0);
|
|
|
|
// Verify tags
|
|
cJSON* tags = cJSON_GetObjectItem(event, "tags");
|
|
assert(tags != NULL && cJSON_GetArraySize(tags) == 2);
|
|
|
|
cJSON* e_tag = cJSON_GetArrayItem(tags, 0);
|
|
assert(strcmp(cJSON_GetArrayItem(e_tag, 0)->valuestring, "e") == 0);
|
|
assert(strcmp(cJSON_GetArrayItem(e_tag, 1)->valuestring, target_id) == 0);
|
|
assert(strcmp(cJSON_GetArrayItem(e_tag, 2)->valuestring, relay) == 0);
|
|
|
|
cJSON* k_tag = cJSON_GetArrayItem(tags, 1);
|
|
assert(strcmp(cJSON_GetArrayItem(k_tag, 0)->valuestring, "k") == 0);
|
|
assert(strcmp(cJSON_GetArrayItem(k_tag, 1)->valuestring, "1") == 0);
|
|
|
|
printf("✅ NIP-03 proof event creation test passed!\n");
|
|
cJSON_Delete(event);
|
|
}
|
|
|
|
int main() {
|
|
if (nostr_init() != NOSTR_SUCCESS) {
|
|
fprintf(stderr, "Failed to initialize NOSTR library\n");
|
|
return 1;
|
|
}
|
|
|
|
test_nip03_create_proof_event();
|
|
|
|
// Note: We don't test nostr_nip03_request_timestamp here as it requires a live OTS calendar
|
|
// and network access, which might be flaky in a test environment.
|
|
|
|
nostr_cleanup();
|
|
printf("\n🎉 All NIP-03 tests passed!\n");
|
|
return 0;
|
|
}
|