nostr-tools
2.20.02.21.0
lib/esm/nip47.js~
lib/esm/nip47.jsModified+12−12
Index: package/lib/esm/nip47.js
===================================================================
--- package/lib/esm/nip47.js
+++ package/lib/esm/nip47.js
@@ -1,7 +1,7 @@
// pure.ts
-import { schnorr } from "@noble/curves/secp256k1";
-import { bytesToHex as bytesToHex2 } from "@noble/hashes/utils";
+import { schnorr } from "@noble/curves/secp256k1.js";
+import { bytesToHex as bytesToHex2, hexToBytes as hexToBytes2 } from "@noble/hashes/utils.js";
// core.ts
var verifiedSymbol = Symbol("verified");
var isRecord = (obj) => obj instanceof Object;
@@ -32,28 +32,28 @@
return true;
}
// pure.ts
-import { sha256 } from "@noble/hashes/sha256";
+import { sha256 } from "@noble/hashes/sha2.js";
// utils.ts
-import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
+import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
var utf8Decoder = new TextDecoder("utf-8");
var utf8Encoder = new TextEncoder();
// pure.ts
var JS = class {
generateSecretKey() {
- return schnorr.utils.randomPrivateKey();
+ return schnorr.utils.randomSecretKey();
}
getPublicKey(secretKey) {
return bytesToHex2(schnorr.getPublicKey(secretKey));
}
finalizeEvent(t, secretKey) {
const event = t;
event.pubkey = bytesToHex2(schnorr.getPublicKey(secretKey));
event.id = getEventHash(event);
- event.sig = bytesToHex2(schnorr.sign(getEventHash(event), secretKey));
+ event.sig = bytesToHex2(schnorr.sign(hexToBytes2(getEventHash(event)), secretKey));
event[verifiedSymbol] = true;
return event;
}
verifyEvent(event) {
@@ -64,9 +64,9 @@
event[verifiedSymbol] = false;
return false;
}
try {
- const valid = schnorr.verify(event.sig, hash, event.pubkey);
+ const valid = schnorr.verify(hexToBytes2(event.sig), hexToBytes2(hash), hexToBytes2(event.pubkey));
event[verifiedSymbol] = valid;
return valid;
} catch (err) {
event[verifiedSymbol] = false;
@@ -92,15 +92,15 @@
// kinds.ts
var NWCWalletRequest = 23194;
// nip04.ts
-import { bytesToHex as bytesToHex3, randomBytes } from "@noble/hashes/utils";
-import { secp256k1 } from "@noble/curves/secp256k1";
-import { cbc } from "@noble/ciphers/aes";
+import { hexToBytes as hexToBytes3, randomBytes } from "@noble/hashes/utils.js";
+import { secp256k1 } from "@noble/curves/secp256k1.js";
+import { cbc } from "@noble/ciphers/aes.js";
import { base64 } from "@scure/base";
function encrypt(secretKey, pubkey, text) {
- const privkey = secretKey instanceof Uint8Array ? bytesToHex3(secretKey) : secretKey;
- const key = secp256k1.getSharedSecret(privkey, "02" + pubkey);
+ const privkey = secretKey instanceof Uint8Array ? secretKey : hexToBytes3(secretKey);
+ const key = secp256k1.getSharedSecret(privkey, hexToBytes3("02" + pubkey));
const normalizedKey = getNormalizedX(key);
let iv = Uint8Array.from(randomBytes(16));
let plaintext = utf8Encoder.encode(text);
let ciphertext = cbc(normalizedKey, iv).encrypt(plaintext);