Socket
Socket
Sign inDemoInstall

nostr-tools

Package Overview
Dependencies
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nostr-tools - npm Package Compare versions

Comparing version 2.5.2 to 2.6.0

lib/cjs/nip07.js

11

lib/cjs/abstract-pool.js

@@ -33,12 +33,9 @@ "use strict";

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -45,0 +42,0 @@ for (let f in filter) {

@@ -35,12 +35,9 @@ "use strict";

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -47,0 +44,0 @@ for (let f in filter) {

@@ -38,12 +38,9 @@ "use strict";

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -50,0 +47,0 @@ for (let f in filter) {

@@ -23,2 +23,5 @@ "use strict";

__export(nip06_exports, {
accountFromExtendedKey: () => accountFromExtendedKey,
accountFromSeedWords: () => accountFromSeedWords,
extendedKeysFromSeedWords: () => extendedKeysFromSeedWords,
generateSeedWords: () => generateSeedWords,

@@ -33,5 +36,6 @@ privateKeyFromSeedWords: () => privateKeyFromSeedWords,

var import_bip32 = require("@scure/bip32");
var DERIVATION_PATH = `m/44'/1237'`;
function privateKeyFromSeedWords(mnemonic, passphrase, accountIndex = 0) {
let root = import_bip32.HDKey.fromMasterSeed((0, import_bip39.mnemonicToSeedSync)(mnemonic, passphrase));
let privateKey = root.derive(`m/44'/1237'/${accountIndex}'/0/0`).privateKey;
let privateKey = root.derive(`${DERIVATION_PATH}/${accountIndex}'/0/0`).privateKey;
if (!privateKey)

@@ -41,2 +45,36 @@ throw new Error("could not derive private key");

}
function accountFromSeedWords(mnemonic, passphrase, accountIndex = 0) {
const root = import_bip32.HDKey.fromMasterSeed((0, import_bip39.mnemonicToSeedSync)(mnemonic, passphrase));
const seed = root.derive(`${DERIVATION_PATH}/${accountIndex}'/0/0`);
const privateKey = (0, import_utils.bytesToHex)(seed.privateKey);
const publicKey = (0, import_utils.bytesToHex)(seed.publicKey.slice(1));
if (!privateKey && !publicKey) {
throw new Error("could not derive key pair");
}
return { privateKey, publicKey };
}
function extendedKeysFromSeedWords(mnemonic, passphrase, extendedAccountIndex = 0) {
let root = import_bip32.HDKey.fromMasterSeed((0, import_bip39.mnemonicToSeedSync)(mnemonic, passphrase));
let seed = root.derive(`${DERIVATION_PATH}/${extendedAccountIndex}'`);
let privateExtendedKey = seed.privateExtendedKey;
let publicExtendedKey = seed.publicExtendedKey;
if (!privateExtendedKey && !publicExtendedKey)
throw new Error("could not derive extended key pair");
return { privateExtendedKey, publicExtendedKey };
}
function accountFromExtendedKey(base58key, accountIndex = 0) {
let extendedKey = import_bip32.HDKey.fromExtendedKey(base58key);
let version = base58key.slice(0, 4);
let child = extendedKey.deriveChild(0).deriveChild(accountIndex);
let publicKey = (0, import_utils.bytesToHex)(child.publicKey.slice(1));
if (!publicKey)
throw new Error("could not derive public key");
if (version === "xprv") {
let privateKey = (0, import_utils.bytesToHex)(child.privateKey);
if (!privateKey)
throw new Error("could not derive private key");
return { privateKey, publicKey };
}
return { publicKey };
}
function generateSeedWords() {

@@ -43,0 +81,0 @@ return (0, import_bip39.generateMnemonic)(import_english.wordlist);

@@ -6,3 +6,2 @@ "use strict";

var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {

@@ -21,6 +20,2 @@ for (var name in all)

var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};

@@ -30,3 +25,5 @@ // nip44.ts

__export(nip44_exports, {
default: () => nip44_default,
decrypt: () => decrypt,
encrypt: () => encrypt,
getConversationKey: () => getConversationKey,
v2: () => v2

@@ -43,105 +40,107 @@ });

var import_base = require("@scure/base");
var decoder = new TextDecoder();
var _u = class {
static utf8Decode(bytes) {
return decoder.decode(bytes);
// utils.ts
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");
}
function getMessageKeys(conversationKey, nonce) {
const keys = (0, import_hkdf.expand)(import_sha256.sha256, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
};
}
function calcPaddedLen(len) {
if (!Number.isSafeInteger(len) || len < 1)
throw new Error("expected positive integer");
if (len <= 32)
return 32;
const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
return chunk * (Math.floor((len - 1) / chunk) + 1);
}
function writeU16BE(num) {
if (!Number.isSafeInteger(num) || num < minPlaintextSize || num > maxPlaintextSize)
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
const arr = new Uint8Array(2);
new DataView(arr.buffer).setUint16(0, num, false);
return arr;
}
function pad(plaintext) {
const unpadded = utf8Encoder.encode(plaintext);
const unpaddedLen = unpadded.length;
const prefix = writeU16BE(unpaddedLen);
const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
return (0, import_utils2.concatBytes)(prefix, unpadded, suffix);
}
function unpad(padded) {
const unpaddedLen = new DataView(padded.buffer).getUint16(0);
const unpadded = padded.subarray(2, 2 + unpaddedLen);
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + calcPaddedLen(unpaddedLen))
throw new Error("invalid padding");
return utf8Decoder.decode(unpadded);
}
function hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = (0, import_utils2.concatBytes)(aad, message);
return (0, import_hmac.hmac)(import_sha256.sha256, key, combined);
}
function decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");
const plen = payload.length;
if (plen < 132 || plen > 87472)
throw new Error("invalid payload length: " + plen);
if (payload[0] === "#")
throw new Error("unknown encryption version");
let data;
try {
data = import_base.base64.decode(payload);
} catch (error) {
throw new Error("invalid base64: " + error.message);
}
static 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");
}
static getMessageKeys(conversationKey, nonce) {
const keys = (0, import_hkdf.expand)(import_sha256.sha256, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
};
}
static calcPaddedLen(len) {
if (!Number.isSafeInteger(len) || len < 1)
throw new Error("expected positive integer");
if (len <= 32)
return 32;
const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
return chunk * (Math.floor((len - 1) / chunk) + 1);
}
static writeU16BE(num) {
if (!Number.isSafeInteger(num) || num < _u.minPlaintextSize || num > _u.maxPlaintextSize)
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
const arr = new Uint8Array(2);
new DataView(arr.buffer).setUint16(0, num, false);
return arr;
}
static pad(plaintext) {
const unpadded = _u.utf8Encode(plaintext);
const unpaddedLen = unpadded.length;
const prefix = _u.writeU16BE(unpaddedLen);
const suffix = new Uint8Array(_u.calcPaddedLen(unpaddedLen) - unpaddedLen);
return (0, import_utils2.concatBytes)(prefix, unpadded, suffix);
}
static unpad(padded) {
const unpaddedLen = new DataView(padded.buffer).getUint16(0);
const unpadded = padded.subarray(2, 2 + unpaddedLen);
if (unpaddedLen < _u.minPlaintextSize || unpaddedLen > _u.maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + _u.calcPaddedLen(unpaddedLen))
throw new Error("invalid padding");
return _u.utf8Decode(unpadded);
}
static hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = (0, import_utils2.concatBytes)(aad, message);
return (0, import_hmac.hmac)(import_sha256.sha256, key, combined);
}
static decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");
const plen = payload.length;
if (plen < 132 || plen > 87472)
throw new Error("invalid payload length: " + plen);
if (payload[0] === "#")
throw new Error("unknown encryption version");
let data;
try {
data = import_base.base64.decode(payload);
} catch (error) {
throw new Error("invalid base64: " + error.message);
}
const dlen = data.length;
if (dlen < 99 || dlen > 65603)
throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2)
throw new Error("unknown encryption version " + vers);
return {
nonce: data.subarray(1, 33),
ciphertext: data.subarray(33, -32),
mac: data.subarray(-32)
};
}
const dlen = data.length;
if (dlen < 99 || dlen > 65603)
throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2)
throw new Error("unknown encryption version " + vers);
return {
nonce: data.subarray(1, 33),
ciphertext: data.subarray(33, -32),
mac: data.subarray(-32)
};
}
function encrypt(plaintext, conversationKey, nonce = (0, import_utils2.randomBytes)(32)) {
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
const padded = pad(plaintext);
const ciphertext = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, padded);
const mac = hmacAad(hmac_key, ciphertext, nonce);
return import_base.base64.encode((0, import_utils2.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
}
function decrypt(payload, conversationKey) {
const { nonce, ciphertext, mac } = decodePayload(payload);
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
if (!(0, import_utils.equalBytes)(calculatedMac, mac))
throw new Error("invalid MAC");
const padded = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, ciphertext);
return unpad(padded);
}
var v2 = {
utils: {
getConversationKey,
calcPaddedLen
},
encrypt,
decrypt
};
var u = _u;
__publicField(u, "minPlaintextSize", 1);
__publicField(u, "maxPlaintextSize", 65535);
__publicField(u, "utf8Encode", import_utils2.utf8ToBytes);
var v2 = class {
static encrypt(plaintext, conversationKey, nonce = (0, import_utils2.randomBytes)(32)) {
const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(conversationKey, nonce);
const padded = u.pad(plaintext);
const ciphertext = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, padded);
const mac = u.hmacAad(hmac_key, ciphertext, nonce);
return import_base.base64.encode((0, import_utils2.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
}
static decrypt(payload, conversationKey) {
const { nonce, ciphertext, mac } = u.decodePayload(payload);
const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(conversationKey, nonce);
const calculatedMac = u.hmacAad(hmac_key, ciphertext, nonce);
if (!(0, import_utils.equalBytes)(calculatedMac, mac))
throw new Error("invalid MAC");
const padded = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, ciphertext);
return u.unpad(padded);
}
};
__publicField(v2, "utils", u);
var nip44_default = { v2 };

@@ -32,2 +32,3 @@ "use strict";

module.exports = __toCommonJS(nip46_exports);
var import_utils10 = require("@noble/hashes/utils");

@@ -212,2 +213,83 @@ // pure.ts

// nip44.ts
var import_chacha = require("@noble/ciphers/chacha");
var import_utils5 = require("@noble/ciphers/utils");
var import_secp256k13 = require("@noble/curves/secp256k1");
var import_hkdf = require("@noble/hashes/hkdf");
var import_hmac = require("@noble/hashes/hmac");
var import_sha2562 = require("@noble/hashes/sha256");
var import_utils6 = require("@noble/hashes/utils");
var import_base2 = require("@scure/base");
var minPlaintextSize = 1;
var maxPlaintextSize = 65535;
function getConversationKey(privkeyA, pubkeyB) {
const sharedX = import_secp256k13.secp256k1.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
return (0, import_hkdf.extract)(import_sha2562.sha256, sharedX, "nip44-v2");
}
function getMessageKeys(conversationKey, nonce) {
const keys = (0, import_hkdf.expand)(import_sha2562.sha256, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
};
}
function calcPaddedLen(len) {
if (!Number.isSafeInteger(len) || len < 1)
throw new Error("expected positive integer");
if (len <= 32)
return 32;
const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
return chunk * (Math.floor((len - 1) / chunk) + 1);
}
function unpad(padded) {
const unpaddedLen = new DataView(padded.buffer).getUint16(0);
const unpadded = padded.subarray(2, 2 + unpaddedLen);
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + calcPaddedLen(unpaddedLen))
throw new Error("invalid padding");
return utf8Decoder.decode(unpadded);
}
function hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = (0, import_utils6.concatBytes)(aad, message);
return (0, import_hmac.hmac)(import_sha2562.sha256, key, combined);
}
function decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");
const plen = payload.length;
if (plen < 132 || plen > 87472)
throw new Error("invalid payload length: " + plen);
if (payload[0] === "#")
throw new Error("unknown encryption version");
let data;
try {
data = import_base2.base64.decode(payload);
} catch (error) {
throw new Error("invalid base64: " + error.message);
}
const dlen = data.length;
if (dlen < 99 || dlen > 65603)
throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2)
throw new Error("unknown encryption version " + vers);
return {
nonce: data.subarray(1, 33),
ciphertext: data.subarray(33, -32),
mac: data.subarray(-32)
};
}
function decrypt2(payload, conversationKey) {
const { nonce, ciphertext, mac } = decodePayload(payload);
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
if (!(0, import_utils5.equalBytes)(calculatedMac, mac))
throw new Error("invalid MAC");
const padded = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, ciphertext);
return unpad(padded);
}
// nip05.ts

@@ -229,12 +311,9 @@ var NIP05_REGEX = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/;

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -765,3 +844,2 @@ for (let f in filter) {

// nip46.ts
var import_utils7 = require("@noble/hashes/utils");
var _fetch2;

@@ -832,2 +910,3 @@ try {

const waitingForAuth = this.waitingForAuth;
const skBytes = this.secretKey;
this.subCloser = this.pool.subscribeMany(

@@ -838,3 +917,9 @@ this.bp.relays,

async onevent(event) {
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content));
let o;
try {
o = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content));
} catch (err) {
o = JSON.parse(decrypt2(event.content, getConversationKey(skBytes, event.pubkey)));
}
const { id, result, error } = o;
if (result === "auth_url" && waitingForAuth[id]) {

@@ -924,3 +1009,3 @@ delete waitingForAuth[id];

let resp = await this.sendRequest("nip44_get_key", [thirdPartyPubkey]);
return (0, import_utils7.hexToBytes)(resp);
return (0, import_utils10.hexToBytes)(resp);
}

@@ -927,0 +1012,0 @@ async nip44Encrypt(thirdPartyPubkey, plaintext) {

@@ -182,12 +182,9 @@ "use strict";

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -194,0 +191,0 @@ for (let f in filter) {

@@ -185,12 +185,9 @@ "use strict";

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -197,0 +194,0 @@ for (let f in filter) {

@@ -7,12 +7,9 @@ // kinds.ts

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -19,0 +16,0 @@ for (let f in filter) {

@@ -7,12 +7,9 @@ // kinds.ts

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -19,0 +16,0 @@ for (let f in filter) {

@@ -9,12 +9,9 @@ // kinds.ts

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -21,0 +18,0 @@ for (let f in filter) {

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {

@@ -7,6 +6,2 @@ for (var name in all)

};
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};

@@ -407,12 +402,9 @@ // pure.ts

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -1824,3 +1816,5 @@ for (let f in filter) {

__export(nip44_exports, {
default: () => nip44_default,
decrypt: () => decrypt2,
encrypt: () => encrypt2,
getConversationKey: () => getConversationKey,
v2: () => v2

@@ -1834,108 +1828,104 @@ });

import { sha256 as sha2562 } from "@noble/hashes/sha256";
import { concatBytes as concatBytes2, randomBytes as randomBytes2, utf8ToBytes } from "@noble/hashes/utils";
import { concatBytes as concatBytes2, randomBytes as randomBytes2 } from "@noble/hashes/utils";
import { base64 as base642 } from "@scure/base";
var decoder = new TextDecoder();
var _u = class {
static utf8Decode(bytes) {
return decoder.decode(bytes);
var minPlaintextSize = 1;
var maxPlaintextSize = 65535;
function getConversationKey(privkeyA, pubkeyB) {
const sharedX = secp256k12.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
return hkdf_extract(sha2562, sharedX, "nip44-v2");
}
function getMessageKeys(conversationKey, nonce) {
const keys = hkdf_expand(sha2562, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
};
}
function calcPaddedLen(len) {
if (!Number.isSafeInteger(len) || len < 1)
throw new Error("expected positive integer");
if (len <= 32)
return 32;
const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
return chunk * (Math.floor((len - 1) / chunk) + 1);
}
function writeU16BE(num) {
if (!Number.isSafeInteger(num) || num < minPlaintextSize || num > maxPlaintextSize)
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
const arr = new Uint8Array(2);
new DataView(arr.buffer).setUint16(0, num, false);
return arr;
}
function pad(plaintext) {
const unpadded = utf8Encoder.encode(plaintext);
const unpaddedLen = unpadded.length;
const prefix = writeU16BE(unpaddedLen);
const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
return concatBytes2(prefix, unpadded, suffix);
}
function unpad(padded) {
const unpaddedLen = new DataView(padded.buffer).getUint16(0);
const unpadded = padded.subarray(2, 2 + unpaddedLen);
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + calcPaddedLen(unpaddedLen))
throw new Error("invalid padding");
return utf8Decoder.decode(unpadded);
}
function hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = concatBytes2(aad, message);
return hmac(sha2562, key, combined);
}
function decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");
const plen = payload.length;
if (plen < 132 || plen > 87472)
throw new Error("invalid payload length: " + plen);
if (payload[0] === "#")
throw new Error("unknown encryption version");
let data;
try {
data = base642.decode(payload);
} catch (error) {
throw new Error("invalid base64: " + error.message);
}
static getConversationKey(privkeyA, pubkeyB) {
const sharedX = secp256k12.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
return hkdf_extract(sha2562, sharedX, "nip44-v2");
}
static getMessageKeys(conversationKey, nonce) {
const keys = hkdf_expand(sha2562, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
};
}
static calcPaddedLen(len) {
if (!Number.isSafeInteger(len) || len < 1)
throw new Error("expected positive integer");
if (len <= 32)
return 32;
const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
return chunk * (Math.floor((len - 1) / chunk) + 1);
}
static writeU16BE(num) {
if (!Number.isSafeInteger(num) || num < _u.minPlaintextSize || num > _u.maxPlaintextSize)
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
const arr = new Uint8Array(2);
new DataView(arr.buffer).setUint16(0, num, false);
return arr;
}
static pad(plaintext) {
const unpadded = _u.utf8Encode(plaintext);
const unpaddedLen = unpadded.length;
const prefix = _u.writeU16BE(unpaddedLen);
const suffix = new Uint8Array(_u.calcPaddedLen(unpaddedLen) - unpaddedLen);
return concatBytes2(prefix, unpadded, suffix);
}
static unpad(padded) {
const unpaddedLen = new DataView(padded.buffer).getUint16(0);
const unpadded = padded.subarray(2, 2 + unpaddedLen);
if (unpaddedLen < _u.minPlaintextSize || unpaddedLen > _u.maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + _u.calcPaddedLen(unpaddedLen))
throw new Error("invalid padding");
return _u.utf8Decode(unpadded);
}
static hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = concatBytes2(aad, message);
return hmac(sha2562, key, combined);
}
static decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");
const plen = payload.length;
if (plen < 132 || plen > 87472)
throw new Error("invalid payload length: " + plen);
if (payload[0] === "#")
throw new Error("unknown encryption version");
let data;
try {
data = base642.decode(payload);
} catch (error) {
throw new Error("invalid base64: " + error.message);
}
const dlen = data.length;
if (dlen < 99 || dlen > 65603)
throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2)
throw new Error("unknown encryption version " + vers);
return {
nonce: data.subarray(1, 33),
ciphertext: data.subarray(33, -32),
mac: data.subarray(-32)
};
}
const dlen = data.length;
if (dlen < 99 || dlen > 65603)
throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2)
throw new Error("unknown encryption version " + vers);
return {
nonce: data.subarray(1, 33),
ciphertext: data.subarray(33, -32),
mac: data.subarray(-32)
};
}
function encrypt2(plaintext, conversationKey, nonce = randomBytes2(32)) {
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
const padded = pad(plaintext);
const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
const mac = hmacAad(hmac_key, ciphertext, nonce);
return base642.encode(concatBytes2(new Uint8Array([2]), nonce, ciphertext, mac));
}
function decrypt2(payload, conversationKey) {
const { nonce, ciphertext, mac } = decodePayload(payload);
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
if (!equalBytes(calculatedMac, mac))
throw new Error("invalid MAC");
const padded = chacha20(chacha_key, chacha_nonce, ciphertext);
return unpad(padded);
}
var v2 = {
utils: {
getConversationKey,
calcPaddedLen
},
encrypt: encrypt2,
decrypt: decrypt2
};
var u = _u;
__publicField(u, "minPlaintextSize", 1);
__publicField(u, "maxPlaintextSize", 65535);
__publicField(u, "utf8Encode", utf8ToBytes);
var v2 = class {
static encrypt(plaintext, conversationKey, nonce = randomBytes2(32)) {
const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(conversationKey, nonce);
const padded = u.pad(plaintext);
const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
const mac = u.hmacAad(hmac_key, ciphertext, nonce);
return base642.encode(concatBytes2(new Uint8Array([2]), nonce, ciphertext, mac));
}
static decrypt(payload, conversationKey) {
const { nonce, ciphertext, mac } = u.decodePayload(payload);
const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(conversationKey, nonce);
const calculatedMac = u.hmacAad(hmac_key, ciphertext, nonce);
if (!equalBytes(calculatedMac, mac))
throw new Error("invalid MAC");
const padded = chacha20(chacha_key, chacha_nonce, ciphertext);
return u.unpad(padded);
}
};
__publicField(v2, "utils", u);
var nip44_default = { v2 };

@@ -1942,0 +1932,0 @@ // nip47.ts

@@ -6,5 +6,6 @@ // nip06.ts

import { HDKey } from "@scure/bip32";
var DERIVATION_PATH = `m/44'/1237'`;
function privateKeyFromSeedWords(mnemonic, passphrase, accountIndex = 0) {
let root = HDKey.fromMasterSeed(mnemonicToSeedSync(mnemonic, passphrase));
let privateKey = root.derive(`m/44'/1237'/${accountIndex}'/0/0`).privateKey;
let privateKey = root.derive(`${DERIVATION_PATH}/${accountIndex}'/0/0`).privateKey;
if (!privateKey)

@@ -14,2 +15,36 @@ throw new Error("could not derive private key");

}
function accountFromSeedWords(mnemonic, passphrase, accountIndex = 0) {
const root = HDKey.fromMasterSeed(mnemonicToSeedSync(mnemonic, passphrase));
const seed = root.derive(`${DERIVATION_PATH}/${accountIndex}'/0/0`);
const privateKey = bytesToHex(seed.privateKey);
const publicKey = bytesToHex(seed.publicKey.slice(1));
if (!privateKey && !publicKey) {
throw new Error("could not derive key pair");
}
return { privateKey, publicKey };
}
function extendedKeysFromSeedWords(mnemonic, passphrase, extendedAccountIndex = 0) {
let root = HDKey.fromMasterSeed(mnemonicToSeedSync(mnemonic, passphrase));
let seed = root.derive(`${DERIVATION_PATH}/${extendedAccountIndex}'`);
let privateExtendedKey = seed.privateExtendedKey;
let publicExtendedKey = seed.publicExtendedKey;
if (!privateExtendedKey && !publicExtendedKey)
throw new Error("could not derive extended key pair");
return { privateExtendedKey, publicExtendedKey };
}
function accountFromExtendedKey(base58key, accountIndex = 0) {
let extendedKey = HDKey.fromExtendedKey(base58key);
let version = base58key.slice(0, 4);
let child = extendedKey.deriveChild(0).deriveChild(accountIndex);
let publicKey = bytesToHex(child.publicKey.slice(1));
if (!publicKey)
throw new Error("could not derive public key");
if (version === "xprv") {
let privateKey = bytesToHex(child.privateKey);
if (!privateKey)
throw new Error("could not derive private key");
return { privateKey, publicKey };
}
return { publicKey };
}
function generateSeedWords() {

@@ -22,2 +57,5 @@ return generateMnemonic(wordlist);

export {
accountFromExtendedKey,
accountFromSeedWords,
extendedKeysFromSeedWords,
generateSeedWords,

@@ -24,0 +62,0 @@ privateKeyFromSeedWords,

@@ -1,8 +0,1 @@

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
// nip44.ts

@@ -15,111 +8,115 @@ import { chacha20 } from "@noble/ciphers/chacha";

import { sha256 } from "@noble/hashes/sha256";
import { concatBytes, randomBytes, utf8ToBytes } from "@noble/hashes/utils";
import { concatBytes, randomBytes } from "@noble/hashes/utils";
import { base64 } from "@scure/base";
var decoder = new TextDecoder();
var _u = class {
static utf8Decode(bytes) {
return decoder.decode(bytes);
// utils.ts
var utf8Decoder = new TextDecoder("utf-8");
var utf8Encoder = new TextEncoder();
// nip44.ts
var minPlaintextSize = 1;
var maxPlaintextSize = 65535;
function getConversationKey(privkeyA, pubkeyB) {
const sharedX = secp256k1.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
return hkdf_extract(sha256, sharedX, "nip44-v2");
}
function getMessageKeys(conversationKey, nonce) {
const keys = hkdf_expand(sha256, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
};
}
function calcPaddedLen(len) {
if (!Number.isSafeInteger(len) || len < 1)
throw new Error("expected positive integer");
if (len <= 32)
return 32;
const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
return chunk * (Math.floor((len - 1) / chunk) + 1);
}
function writeU16BE(num) {
if (!Number.isSafeInteger(num) || num < minPlaintextSize || num > maxPlaintextSize)
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
const arr = new Uint8Array(2);
new DataView(arr.buffer).setUint16(0, num, false);
return arr;
}
function pad(plaintext) {
const unpadded = utf8Encoder.encode(plaintext);
const unpaddedLen = unpadded.length;
const prefix = writeU16BE(unpaddedLen);
const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
return concatBytes(prefix, unpadded, suffix);
}
function unpad(padded) {
const unpaddedLen = new DataView(padded.buffer).getUint16(0);
const unpadded = padded.subarray(2, 2 + unpaddedLen);
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + calcPaddedLen(unpaddedLen))
throw new Error("invalid padding");
return utf8Decoder.decode(unpadded);
}
function hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = concatBytes(aad, message);
return hmac(sha256, key, combined);
}
function decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");
const plen = payload.length;
if (plen < 132 || plen > 87472)
throw new Error("invalid payload length: " + plen);
if (payload[0] === "#")
throw new Error("unknown encryption version");
let data;
try {
data = base64.decode(payload);
} catch (error) {
throw new Error("invalid base64: " + error.message);
}
static getConversationKey(privkeyA, pubkeyB) {
const sharedX = secp256k1.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
return hkdf_extract(sha256, sharedX, "nip44-v2");
}
static getMessageKeys(conversationKey, nonce) {
const keys = hkdf_expand(sha256, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
};
}
static calcPaddedLen(len) {
if (!Number.isSafeInteger(len) || len < 1)
throw new Error("expected positive integer");
if (len <= 32)
return 32;
const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
return chunk * (Math.floor((len - 1) / chunk) + 1);
}
static writeU16BE(num) {
if (!Number.isSafeInteger(num) || num < _u.minPlaintextSize || num > _u.maxPlaintextSize)
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
const arr = new Uint8Array(2);
new DataView(arr.buffer).setUint16(0, num, false);
return arr;
}
static pad(plaintext) {
const unpadded = _u.utf8Encode(plaintext);
const unpaddedLen = unpadded.length;
const prefix = _u.writeU16BE(unpaddedLen);
const suffix = new Uint8Array(_u.calcPaddedLen(unpaddedLen) - unpaddedLen);
return concatBytes(prefix, unpadded, suffix);
}
static unpad(padded) {
const unpaddedLen = new DataView(padded.buffer).getUint16(0);
const unpadded = padded.subarray(2, 2 + unpaddedLen);
if (unpaddedLen < _u.minPlaintextSize || unpaddedLen > _u.maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + _u.calcPaddedLen(unpaddedLen))
throw new Error("invalid padding");
return _u.utf8Decode(unpadded);
}
static hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = concatBytes(aad, message);
return hmac(sha256, key, combined);
}
static decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");
const plen = payload.length;
if (plen < 132 || plen > 87472)
throw new Error("invalid payload length: " + plen);
if (payload[0] === "#")
throw new Error("unknown encryption version");
let data;
try {
data = base64.decode(payload);
} catch (error) {
throw new Error("invalid base64: " + error.message);
}
const dlen = data.length;
if (dlen < 99 || dlen > 65603)
throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2)
throw new Error("unknown encryption version " + vers);
return {
nonce: data.subarray(1, 33),
ciphertext: data.subarray(33, -32),
mac: data.subarray(-32)
};
}
const dlen = data.length;
if (dlen < 99 || dlen > 65603)
throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2)
throw new Error("unknown encryption version " + vers);
return {
nonce: data.subarray(1, 33),
ciphertext: data.subarray(33, -32),
mac: data.subarray(-32)
};
}
function encrypt(plaintext, conversationKey, nonce = randomBytes(32)) {
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
const padded = pad(plaintext);
const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
const mac = hmacAad(hmac_key, ciphertext, nonce);
return base64.encode(concatBytes(new Uint8Array([2]), nonce, ciphertext, mac));
}
function decrypt(payload, conversationKey) {
const { nonce, ciphertext, mac } = decodePayload(payload);
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
if (!equalBytes(calculatedMac, mac))
throw new Error("invalid MAC");
const padded = chacha20(chacha_key, chacha_nonce, ciphertext);
return unpad(padded);
}
var v2 = {
utils: {
getConversationKey,
calcPaddedLen
},
encrypt,
decrypt
};
var u = _u;
__publicField(u, "minPlaintextSize", 1);
__publicField(u, "maxPlaintextSize", 65535);
__publicField(u, "utf8Encode", utf8ToBytes);
var v2 = class {
static encrypt(plaintext, conversationKey, nonce = randomBytes(32)) {
const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(conversationKey, nonce);
const padded = u.pad(plaintext);
const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
const mac = u.hmacAad(hmac_key, ciphertext, nonce);
return base64.encode(concatBytes(new Uint8Array([2]), nonce, ciphertext, mac));
}
static decrypt(payload, conversationKey) {
const { nonce, ciphertext, mac } = u.decodePayload(payload);
const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(conversationKey, nonce);
const calculatedMac = u.hmacAad(hmac_key, ciphertext, nonce);
if (!equalBytes(calculatedMac, mac))
throw new Error("invalid MAC");
const padded = chacha20(chacha_key, chacha_nonce, ciphertext);
return u.unpad(padded);
}
};
__publicField(v2, "utils", u);
var nip44_default = { v2 };
export {
nip44_default as default,
decrypt,
encrypt,
getConversationKey,
v2
};

@@ -0,1 +1,4 @@

// nip46.ts
import { hexToBytes } from "@noble/hashes/utils";
// pure.ts

@@ -179,2 +182,83 @@ import { schnorr } from "@noble/curves/secp256k1";

// nip44.ts
import { chacha20 } from "@noble/ciphers/chacha";
import { equalBytes } from "@noble/ciphers/utils";
import { secp256k1 as secp256k12 } 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 as randomBytes2 } from "@noble/hashes/utils";
import { base64 as base642 } from "@scure/base";
var minPlaintextSize = 1;
var maxPlaintextSize = 65535;
function getConversationKey(privkeyA, pubkeyB) {
const sharedX = secp256k12.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
return hkdf_extract(sha2562, sharedX, "nip44-v2");
}
function getMessageKeys(conversationKey, nonce) {
const keys = hkdf_expand(sha2562, conversationKey, nonce, 76);
return {
chacha_key: keys.subarray(0, 32),
chacha_nonce: keys.subarray(32, 44),
hmac_key: keys.subarray(44, 76)
};
}
function calcPaddedLen(len) {
if (!Number.isSafeInteger(len) || len < 1)
throw new Error("expected positive integer");
if (len <= 32)
return 32;
const nextPower = 1 << Math.floor(Math.log2(len - 1)) + 1;
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
return chunk * (Math.floor((len - 1) / chunk) + 1);
}
function unpad(padded) {
const unpaddedLen = new DataView(padded.buffer).getUint16(0);
const unpadded = padded.subarray(2, 2 + unpaddedLen);
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== 2 + calcPaddedLen(unpaddedLen))
throw new Error("invalid padding");
return utf8Decoder.decode(unpadded);
}
function hmacAad(key, message, aad) {
if (aad.length !== 32)
throw new Error("AAD associated data must be 32 bytes");
const combined = concatBytes(aad, message);
return hmac(sha2562, key, combined);
}
function decodePayload(payload) {
if (typeof payload !== "string")
throw new Error("payload must be a valid string");
const plen = payload.length;
if (plen < 132 || plen > 87472)
throw new Error("invalid payload length: " + plen);
if (payload[0] === "#")
throw new Error("unknown encryption version");
let data;
try {
data = base642.decode(payload);
} catch (error) {
throw new Error("invalid base64: " + error.message);
}
const dlen = data.length;
if (dlen < 99 || dlen > 65603)
throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2)
throw new Error("unknown encryption version " + vers);
return {
nonce: data.subarray(1, 33),
ciphertext: data.subarray(33, -32),
mac: data.subarray(-32)
};
}
function decrypt2(payload, conversationKey) {
const { nonce, ciphertext, mac } = decodePayload(payload);
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
if (!equalBytes(calculatedMac, mac))
throw new Error("invalid MAC");
const padded = chacha20(chacha_key, chacha_nonce, ciphertext);
return unpad(padded);
}
// nip05.ts

@@ -196,12 +280,9 @@ var NIP05_REGEX = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/;

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -732,3 +813,2 @@ for (let f in filter) {

// nip46.ts
import { hexToBytes } from "@noble/hashes/utils";
var _fetch2;

@@ -799,2 +879,3 @@ try {

const waitingForAuth = this.waitingForAuth;
const skBytes = this.secretKey;
this.subCloser = this.pool.subscribeMany(

@@ -805,3 +886,9 @@ this.bp.relays,

async onevent(event) {
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content));
let o;
try {
o = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content));
} catch (err) {
o = JSON.parse(decrypt2(event.content, getConversationKey(skBytes, event.pubkey)));
}
const { id, result, error } = o;
if (result === "auth_url" && waitingForAuth[id]) {

@@ -808,0 +895,0 @@ delete waitingForAuth[id];

@@ -155,12 +155,9 @@ // pure.ts

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -167,0 +164,0 @@ for (let f in filter) {

@@ -155,12 +155,9 @@ // pure.ts

if (filter.ids && filter.ids.indexOf(event.id) === -1) {
if (!filter.ids.some((prefix) => event.id.startsWith(prefix))) {
return false;
}
return false;
}
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1)
if (filter.kinds && filter.kinds.indexOf(event.kind) === -1) {
return false;
}
if (filter.authors && filter.authors.indexOf(event.pubkey) === -1) {
if (!filter.authors.some((prefix) => event.pubkey.startsWith(prefix))) {
return false;
}
return false;
}

@@ -167,0 +164,0 @@ for (let f in filter) {

export declare function privateKeyFromSeedWords(mnemonic: string, passphrase?: string, accountIndex?: number): string;
export declare function accountFromSeedWords(mnemonic: string, passphrase?: string, accountIndex?: number): {
privateKey: string;
publicKey: string;
};
export declare function extendedKeysFromSeedWords(mnemonic: string, passphrase?: string, extendedAccountIndex?: number): {
privateExtendedKey: string;
publicExtendedKey: string;
};
export declare function accountFromExtendedKey(base58key: string, accountIndex?: number): {
privateKey?: string;
publicKey: string;
};
export declare function generateSeedWords(): string;
export declare function validateWords(words: string): boolean;

@@ -1,32 +0,13 @@

import { utf8ToBytes } from '@noble/hashes/utils';
declare class u {
static minPlaintextSize: number;
static maxPlaintextSize: number;
static utf8Encode: typeof utf8ToBytes;
static utf8Decode(bytes: Uint8Array): string;
static getConversationKey(privkeyA: string, pubkeyB: string): Uint8Array;
static getMessageKeys(conversationKey: Uint8Array, nonce: Uint8Array): {
chacha_key: Uint8Array;
chacha_nonce: Uint8Array;
hmac_key: Uint8Array;
export declare function getConversationKey(privkeyA: Uint8Array, pubkeyB: string): Uint8Array;
declare function calcPaddedLen(len: number): number;
export declare function encrypt(plaintext: string, conversationKey: Uint8Array, nonce?: Uint8Array): string;
export declare function decrypt(payload: string, conversationKey: Uint8Array): string;
export declare const v2: {
utils: {
getConversationKey: typeof getConversationKey;
calcPaddedLen: typeof calcPaddedLen;
};
static calcPaddedLen(len: number): number;
static writeU16BE(num: number): Uint8Array;
static pad(plaintext: string): Uint8Array;
static unpad(padded: Uint8Array): string;
static hmacAad(key: Uint8Array, message: Uint8Array, aad: Uint8Array): Uint8Array;
static decodePayload(payload: string): {
nonce: Uint8Array;
ciphertext: Uint8Array;
mac: Uint8Array;
};
}
export declare class v2 {
static utils: typeof u;
static encrypt(plaintext: string, conversationKey: Uint8Array, nonce?: Uint8Array): string;
static decrypt(payload: string, conversationKey: Uint8Array): string;
}
declare const _default: {
v2: typeof v2;
encrypt: typeof encrypt;
decrypt: typeof decrypt;
};
export default _default;
export {};
import { UnsignedEvent, VerifiedEvent } from './core.ts';
import { AbstractSimplePool } from './abstract-pool.ts';
import type { RelayRecord } from './relay.ts';
export declare function useFetchImplementation(fetchImplementation: any): void;

@@ -53,8 +54,3 @@ export declare const BUNKER_REGEX: RegExp;

*/
getRelays(): Promise<{
[relay: string]: {
read: boolean;
write: boolean;
};
}>;
getRelays(): Promise<RelayRecord>;
/**

@@ -61,0 +57,0 @@ * Signs an event using the remote private key.

@@ -10,2 +10,6 @@ import { AbstractRelay } from './abstract-relay.ts';

}
export type RelayRecord = Record<string, {
read: boolean;
write: boolean;
}>;
export * from './abstract-relay.ts';
{
"type": "module",
"name": "nostr-tools",
"version": "2.5.2",
"version": "2.6.0",
"description": "Tools for making a Nostr client.",

@@ -88,2 +88,5 @@ "repository": {

},
"./nip07": {
"types": "./lib/types/nip07.d.ts"
},
"./nip10": {

@@ -90,0 +93,0 @@ "import": "./lib/esm/nip10.js",

@@ -33,3 +33,3 @@ # ![](https://img.shields.io/github/actions/workflow/status/nbd-wtf/nostr-tools/test.yml) nostr-tools

let skHex = bytesToHex(sk)
let skHex = bytesToHex(sk)
let backToBytes = hexToBytes(skHex)

@@ -187,2 +187,13 @@ ```

### Including NIP-07 types
```js
import type { WindowNostr } from 'nostr-tools/nip07'
declare global {
interface Window {
nostr?: WindowNostr;
}
}
```
### Encoding and decoding NIP-19 codes

@@ -189,0 +200,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc