nostr-tools
2.20.02.21.0
lib/cjs/nip44.js~
lib/cjs/nip44.jsModified+12−12
Index: package/lib/cjs/nip44.js
===================================================================
--- package/lib/cjs/nip44.js
+++ package/lib/cjs/nip44.js
@@ -25,31 +25,31 @@
getConversationKey: () => getConversationKey,
v2: () => v2
});
module.exports = __toCommonJS(nip44_exports);
-var import_chacha = require("@noble/ciphers/chacha");
-var import_utils2 = require("@noble/ciphers/utils");
-var import_secp256k1 = require("@noble/curves/secp256k1");
-var import_hkdf = require("@noble/hashes/hkdf");
-var import_hmac = require("@noble/hashes/hmac");
-var import_sha256 = require("@noble/hashes/sha256");
-var import_utils3 = require("@noble/hashes/utils");
+var import_chacha = require("@noble/ciphers/chacha.js");
+var import_utils2 = require("@noble/ciphers/utils.js");
+var import_secp256k1 = require("@noble/curves/secp256k1.js");
+var import_hkdf = require("@noble/hashes/hkdf.js");
+var import_hmac = require("@noble/hashes/hmac.js");
+var import_sha2 = require("@noble/hashes/sha2.js");
+var import_utils3 = require("@noble/hashes/utils.js");
var import_base = require("@scure/base");
// utils.ts
-var import_utils = require("@noble/hashes/utils");
+var import_utils = require("@noble/hashes/utils.js");
var utf8Decoder = new TextDecoder("utf-8");
var utf8Encoder = new TextEncoder();
// nip44.ts
var minPlaintextSize = 1;
var maxPlaintextSize = 65535;
function getConversationKey(privkeyA, pubkeyB) {
- const sharedX = import_secp256k1.secp256k1.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
- return (0, import_hkdf.extract)(import_sha256.sha256, sharedX, "nip44-v2");
+ const sharedX = import_secp256k1.secp256k1.getSharedSecret(privkeyA, (0, import_utils3.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
+ return (0, import_hkdf.extract)(import_sha2.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
}
function getMessageKeys(conversationKey, nonce) {
- const keys = (0, import_hkdf.expand)(import_sha256.sha256, conversationKey, nonce, 76);
+ const keys = (0, import_hkdf.expand)(import_sha2.sha256, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
@@ -88,9 +88,9 @@
function hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = (0, import_utils3.concatBytes)(aad, message);
- return (0, import_hmac.hmac)(import_sha256.sha256, key, combined);
+ return (0, import_hmac.hmac)(import_sha2.sha256, key, combined);
}
function decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");