/* * Simple NIP-44 Test * Basic functionality test for NIP-44 encryption/decryption */ #include #include #include #include "../nostr_core/nostr_core.h" int main() { printf("๐Ÿงช Simple NIP-44 Test\n"); printf("=====================\n\n"); // Initialize the library if (nostr_init() != NOSTR_SUCCESS) { printf("โŒ Failed to initialize NOSTR library\n"); return 1; } // Test keys (from successful NIP-04 test) const char* sender_key_hex = "91ba716fa9e7ea2fcbad360cf4f8e0d312f73984da63d90f524ad61a6a1e7dbe"; const char* recipient_key_hex = "96f6fa197aa07477ab88f6981118466ae3a982faab8ad5db9d5426870c73d220"; unsigned char sender_private_key[32]; unsigned char recipient_private_key[32]; unsigned char recipient_public_key[32]; // Parse keys if (nostr_hex_to_bytes(sender_key_hex, sender_private_key, 32) != 0) { printf("โŒ Failed to parse sender private key\n"); nostr_cleanup(); return 1; } if (nostr_hex_to_bytes(recipient_key_hex, recipient_private_key, 32) != 0) { printf("โŒ Failed to parse recipient private key\n"); nostr_cleanup(); return 1; } // Generate recipient's public key if (nostr_ec_public_key_from_private_key(recipient_private_key, recipient_public_key) != 0) { printf("โŒ Failed to generate recipient public key\n"); nostr_cleanup(); return 1; } printf("โœ… Keys parsed successfully\n"); // Test message const char* test_message = "Hello, NIP-44! This is a test message."; printf("๐Ÿ“ Test message: \"%s\"\n", test_message); // Test encryption char encrypted[8192]; printf("๐Ÿ” Testing NIP-44 encryption...\n"); int encrypt_result = nostr_nip44_encrypt( sender_private_key, recipient_public_key, test_message, encrypted, sizeof(encrypted) ); if (encrypt_result != NOSTR_SUCCESS) { printf("โŒ NIP-44 encryption failed with error: %d\n", encrypt_result); nostr_cleanup(); return 1; } printf("โœ… NIP-44 encryption successful!\n"); printf("๐Ÿ“ฆ Encrypted length: %zu bytes\n", strlen(encrypted)); printf("๐Ÿ“ฆ First 80 chars: %.80s...\n", encrypted); // Test decryption char decrypted[8192]; unsigned char sender_public_key[32]; // Generate sender's public key for decryption if (nostr_ec_public_key_from_private_key(sender_private_key, sender_public_key) != 0) { printf("โŒ Failed to generate sender public key\n"); nostr_cleanup(); return 1; } printf("๐Ÿ”“ Testing NIP-44 decryption...\n"); int decrypt_result = nostr_nip44_decrypt( recipient_private_key, sender_public_key, encrypted, decrypted, sizeof(decrypted) ); if (decrypt_result != NOSTR_SUCCESS) { printf("โŒ NIP-44 decryption failed with error: %d\n", decrypt_result); nostr_cleanup(); return 1; } printf("โœ… NIP-44 decryption successful!\n"); printf("๐Ÿ“ Decrypted: \"%s\"\n", decrypted); // Verify round-trip if (strcmp(test_message, decrypted) == 0) { printf("โœ… Round-trip successful! Messages match perfectly.\n"); printf("\n๐ŸŽ‰ NIP-44 TEST PASSED! ๐ŸŽ‰\n"); nostr_cleanup(); return 0; } else { printf("โŒ Round-trip failed! Messages don't match.\n"); printf("๐Ÿ“ Original: \"%s\"\n", test_message); printf("๐Ÿ“ Decrypted: \"%s\"\n", decrypted); nostr_cleanup(); return 1; } }