Fix Cashu hash_to_curve to NUT-00 spec and align live helper for send-proof compatibility
This commit is contained in:
+7
-11
@@ -1797,14 +1797,15 @@ static int cashu_hash_to_curve_pubkey(const char* secret, nostr_secp256k1_pubkey
|
||||
}
|
||||
|
||||
unsigned char candidate[33] = {0};
|
||||
for (int counter = 0; counter < 1024; counter++) {
|
||||
for (int counter = 0; counter < 65536; counter++) {
|
||||
unsigned char h[32] = {0};
|
||||
unsigned char data[36] = {0};
|
||||
memcpy(data, digest, 32);
|
||||
data[32] = (unsigned char)((counter >> 24) & 0xff);
|
||||
data[33] = (unsigned char)((counter >> 16) & 0xff);
|
||||
unsigned char data[37] = {0};
|
||||
data[0] = 0x02;
|
||||
memcpy(data + 1, digest, 32);
|
||||
data[33] = (unsigned char)(counter & 0xff);
|
||||
data[34] = (unsigned char)((counter >> 8) & 0xff);
|
||||
data[35] = (unsigned char)(counter & 0xff);
|
||||
data[35] = (unsigned char)((counter >> 16) & 0xff);
|
||||
data[36] = (unsigned char)((counter >> 24) & 0xff);
|
||||
if (nostr_sha256(data, sizeof(data), h) != 0) {
|
||||
return NOSTR_ERROR_CRYPTO_FAILED;
|
||||
}
|
||||
@@ -1814,11 +1815,6 @@ static int cashu_hash_to_curve_pubkey(const char* secret, nostr_secp256k1_pubkey
|
||||
if (nostr_secp256k1_ec_pubkey_parse(out_y, candidate, sizeof(candidate))) {
|
||||
return NOSTR_SUCCESS;
|
||||
}
|
||||
|
||||
candidate[0] = 0x03;
|
||||
if (nostr_secp256k1_ec_pubkey_parse(out_y, candidate, sizeof(candidate))) {
|
||||
return NOSTR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return NOSTR_ERROR_CRYPTO_FAILED;
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#define NOSTR_CORE_H
|
||||
|
||||
// Version information (auto-updated by increment_and_push.sh)
|
||||
#define VERSION "v0.5.8"
|
||||
#define VERSION "v0.5.9"
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 5
|
||||
#define VERSION_PATCH 8
|
||||
#define VERSION_PATCH 9
|
||||
|
||||
/*
|
||||
* NOSTR Core Library - Complete API Reference
|
||||
|
||||
Binary file not shown.
@@ -36,14 +36,15 @@ static int secret_to_Y_hex(const char* secret, char out_Y_hex[67]) {
|
||||
}
|
||||
|
||||
unsigned char candidate[33] = {0};
|
||||
for (int counter = 0; counter < 1024; counter++) {
|
||||
for (int counter = 0; counter < 65536; counter++) {
|
||||
unsigned char h[32] = {0};
|
||||
unsigned char data[36] = {0};
|
||||
memcpy(data, digest, 32);
|
||||
data[32] = (unsigned char)((counter >> 24) & 0xff);
|
||||
data[33] = (unsigned char)((counter >> 16) & 0xff);
|
||||
unsigned char data[37] = {0};
|
||||
data[0] = 0x02;
|
||||
memcpy(data + 1, digest, 32);
|
||||
data[33] = (unsigned char)(counter & 0xff);
|
||||
data[34] = (unsigned char)((counter >> 8) & 0xff);
|
||||
data[35] = (unsigned char)(counter & 0xff);
|
||||
data[35] = (unsigned char)((counter >> 16) & 0xff);
|
||||
data[36] = (unsigned char)((counter >> 24) & 0xff);
|
||||
|
||||
if (nostr_sha256(data, sizeof(data), h) != 0) {
|
||||
return NOSTR_ERROR_CRYPTO_FAILED;
|
||||
@@ -57,12 +58,6 @@ static int secret_to_Y_hex(const char* secret, char out_Y_hex[67]) {
|
||||
nostr_bytes_to_hex(candidate, sizeof(candidate), out_Y_hex);
|
||||
return NOSTR_SUCCESS;
|
||||
}
|
||||
|
||||
candidate[0] = 0x03;
|
||||
if (nostr_secp256k1_ec_pubkey_parse(&pub, candidate, sizeof(candidate))) {
|
||||
nostr_bytes_to_hex(candidate, sizeof(candidate), out_Y_hex);
|
||||
return NOSTR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return NOSTR_ERROR_CRYPTO_FAILED;
|
||||
|
||||
Reference in New Issue
Block a user