122 lines
3.9 KiB
C
122 lines
3.9 KiB
C
/*
|
|
* Example: NIP-60/NIP-61 Cashu Wallet Flow
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include "../nostr_core/nostr_core.h"
|
|
|
|
static void print_event(const char* title, cJSON* evt) {
|
|
if (!evt) {
|
|
printf("%s: <null>\n", title);
|
|
return;
|
|
}
|
|
char* s = cJSON_Print(evt);
|
|
if (s) {
|
|
printf("\n%s\n%s\n", title, s);
|
|
free(s);
|
|
}
|
|
}
|
|
|
|
int main(void) {
|
|
if (nostr_init() != NOSTR_SUCCESS) {
|
|
printf("Failed to initialize library\n");
|
|
return 1;
|
|
}
|
|
|
|
const char* user_sk_hex = "91ba716fa9e7ea2fcbad360cf4f8e0d312f73984da63d90f524ad61a6a1e7dbe";
|
|
unsigned char user_sk[32];
|
|
if (nostr_hex_to_bytes(user_sk_hex, user_sk, 32) != 0) {
|
|
printf("Invalid private key\n");
|
|
nostr_cleanup();
|
|
return 1;
|
|
}
|
|
|
|
/* 1) Create wallet event (kind:17375) */
|
|
char* mint_urls[] = {
|
|
"https://mint1.example.com",
|
|
"https://mint2.example.com"
|
|
};
|
|
|
|
nostr_nip60_wallet_data_t wallet_data;
|
|
memset(&wallet_data, 0, sizeof(wallet_data));
|
|
strcpy(wallet_data.privkey, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
|
wallet_data.mint_urls = mint_urls;
|
|
wallet_data.mint_count = 2;
|
|
|
|
cJSON* wallet_event = nostr_nip60_create_wallet_event(&wallet_data, user_sk, 0);
|
|
print_event("Wallet Event (kind:17375)", wallet_event);
|
|
|
|
/* 2) Create token event (kind:7375) */
|
|
nostr_cashu_proof_t proofs[2];
|
|
memset(proofs, 0, sizeof(proofs));
|
|
|
|
strcpy(proofs[0].id, "005c2502034d4f12");
|
|
proofs[0].amount = 1;
|
|
proofs[0].secret = "secret-1";
|
|
proofs[0].C = "0241d98a8197ef238a192d47edf191a9de78b657308937b4f7dd0aa53beae72c46";
|
|
|
|
strcpy(proofs[1].id, "005c2502034d4f12");
|
|
proofs[1].amount = 2;
|
|
proofs[1].secret = "secret-2";
|
|
proofs[1].C = "02277c66191736eb72fce9d975d08e3191f8f96afb73ab1eec37e4465683066d3f";
|
|
|
|
nostr_nip60_token_data_t token_data;
|
|
memset(&token_data, 0, sizeof(token_data));
|
|
token_data.mint_url = "https://mint1.example.com";
|
|
token_data.proofs = proofs;
|
|
token_data.proof_count = 2;
|
|
|
|
cJSON* token_event = nostr_nip60_create_token_event(&token_data, user_sk, 0);
|
|
print_event("Token Event (kind:7375)", token_event);
|
|
|
|
/* 3) Create spend history event (kind:7376) */
|
|
nostr_nip60_history_ref_t refs[1];
|
|
memset(refs, 0, sizeof(refs));
|
|
strcpy(refs[0].event_id, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
|
refs[0].marker = NOSTR_NIP60_REF_CREATED;
|
|
|
|
nostr_nip60_history_data_t hist;
|
|
memset(&hist, 0, sizeof(hist));
|
|
hist.direction = NOSTR_NIP60_DIRECTION_IN;
|
|
hist.amount = 3;
|
|
hist.refs = refs;
|
|
hist.ref_count = 1;
|
|
|
|
cJSON* history_event = nostr_nip60_create_history_event(&hist, user_sk, 0);
|
|
print_event("History Event (kind:7376)", history_event);
|
|
|
|
/* 4) Create nutzap info event (kind:10019) */
|
|
char* relays[] = {"wss://relay1.example.com", "wss://relay2.example.com"};
|
|
char* mint_units[] = {"sat"};
|
|
|
|
nostr_nip61_mint_entry_t mint_entry;
|
|
memset(&mint_entry, 0, sizeof(mint_entry));
|
|
mint_entry.url = "https://mint1.example.com";
|
|
mint_entry.units = mint_units;
|
|
mint_entry.unit_count = 1;
|
|
|
|
nostr_nip61_nutzap_info_t info;
|
|
memset(&info, 0, sizeof(info));
|
|
info.relay_urls = relays;
|
|
info.relay_count = 2;
|
|
info.mints = &mint_entry;
|
|
info.mint_count = 1;
|
|
strcpy(info.pubkey, "02eaee8939e3565e48cc62967e2fde9d8e2a4b3ec0081f29eceff5c64ef10ac1ed");
|
|
|
|
cJSON* info_event = nostr_nip61_create_nutzap_info_event(&info, user_sk, 0);
|
|
print_event("Nutzap Info Event (kind:10019)", info_event);
|
|
|
|
/* 5) Optionally call Cashu mint HTTP endpoints with [cashu_mint_get_info()] */
|
|
printf("\nCashu mint integration is available via cashu_mint_* APIs.\n");
|
|
|
|
cJSON_Delete(info_event);
|
|
cJSON_Delete(history_event);
|
|
cJSON_Delete(token_event);
|
|
cJSON_Delete(wallet_event);
|
|
|
|
nostr_cleanup();
|
|
return 0;
|
|
}
|