nostr-tools
2.20.02.21.0
lib/esm/nip46.js~
lib/esm/nip46.jsModified+16−16
Index: package/lib/esm/nip46.js
===================================================================
--- package/lib/esm/nip46.js
+++ package/lib/esm/nip46.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,12 +32,12 @@
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();
function normalizeURL(url) {
try {
@@ -111,18 +111,18 @@
// 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) {
@@ -133,9 +133,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;
@@ -158,21 +158,21 @@
var finalizeEvent = i.finalizeEvent;
var verifyEvent = i.verifyEvent;
// nip44.ts
-import { chacha20 } from "@noble/ciphers/chacha";
-import { equalBytes } from "@noble/ciphers/utils";
-import { secp256k1 } from "@noble/curves/secp256k1";
-import { extract as hkdf_extract, expand as hkdf_expand } from "@noble/hashes/hkdf";
-import { hmac } from "@noble/hashes/hmac";
-import { sha256 as sha2562 } from "@noble/hashes/sha256";
-import { concatBytes, randomBytes } from "@noble/hashes/utils";
+import { chacha20 } from "@noble/ciphers/chacha.js";
+import { equalBytes } from "@noble/ciphers/utils.js";
+import { secp256k1 } from "@noble/curves/secp256k1.js";
+import { extract as hkdf_extract, expand as hkdf_expand } from "@noble/hashes/hkdf.js";
+import { hmac } from "@noble/hashes/hmac.js";
+import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
+import { concatBytes, hexToBytes as hexToBytes3, randomBytes } from "@noble/hashes/utils.js";
import { base64 } from "@scure/base";
var minPlaintextSize = 1;
var maxPlaintextSize = 65535;
function getConversationKey(privkeyA, pubkeyB) {
- const sharedX = secp256k1.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
- return hkdf_extract(sha2562, sharedX, "nip44-v2");
+ const sharedX = secp256k1.getSharedSecret(privkeyA, hexToBytes3("02" + pubkeyB)).subarray(1, 33);
+ return hkdf_extract(sha2562, sharedX, utf8Encoder.encode("nip44-v2"));
}
function getMessageKeys(conversationKey, nonce) {
const keys = hkdf_expand(sha2562, conversationKey, nonce, 76);
return {