Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nostr-tools

Package Overview
Dependencies
Maintainers
1
Versions
151
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.9.4 to 2.10.0

20

lib/cjs/abstract-pool.js

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

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -335,7 +336,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -387,2 +390,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -389,0 +399,0 @@ }

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

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -329,7 +330,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -381,2 +384,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -383,0 +393,0 @@ }

@@ -36,3 +36,4 @@ "use strict";

_fetch = fetch;
} catch {
} catch (_) {
null;
}

@@ -45,3 +46,6 @@ function useFetchImplementation(fetchImplementation) {

const url = `https://${domain}/.well-known/nostr.json?name=${query}`;
const res = await _fetch(url, { redirect: "error" });
const res = await _fetch(url, { redirect: "manual" });
if (res.status !== 200) {
throw Error("Wrong response code");
}
const json = await res.json();

@@ -57,8 +61,12 @@ return json.names;

return null;
const [_, name = "_", domain] = match;
const [, name = "_", domain] = match;
try {
const url = `https://${domain}/.well-known/nostr.json?name=${name}`;
const res = await (await _fetch(url, { redirect: "error" })).json();
let pubkey = res.names[name];
return pubkey ? { pubkey, relays: res.relays?.[pubkey] } : null;
const res = await _fetch(url, { redirect: "manual" });
if (res.status !== 200) {
throw Error("Wrong response code");
}
const json = await res.json();
const pubkey = json.names[name];
return pubkey ? { pubkey, relays: json.relays?.[pubkey] } : null;
} catch (_e) {

@@ -69,4 +77,4 @@ return null;

async function isValid(pubkey, nip05) {
let res = await queryProfile(nip05);
const res = await queryProfile(nip05);
return res ? res.pubkey === pubkey : false;
}

@@ -186,13 +186,2 @@ "use strict";

var import_base = require("@scure/base");
async function encrypt(secretKey, pubkey, text) {
const privkey = secretKey instanceof Uint8Array ? (0, import_utils3.bytesToHex)(secretKey) : secretKey;
const key = import_secp256k12.secp256k1.getSharedSecret(privkey, "02" + pubkey);
const normalizedKey = getNormalizedX(key);
let iv = Uint8Array.from((0, import_utils3.randomBytes)(16));
let plaintext = utf8Encoder.encode(text);
let ciphertext = (0, import_aes.cbc)(normalizedKey, iv).encrypt(plaintext);
let ctb64 = import_base.base64.encode(new Uint8Array(ciphertext));
let ivb64 = import_base.base64.encode(new Uint8Array(iv.buffer));
return `${ctb64}?iv=${ivb64}`;
}
async function decrypt(secretKey, pubkey, data) {

@@ -244,2 +233,16 @@ const privkey = secretKey instanceof Uint8Array ? (0, import_utils3.bytesToHex)(secretKey) : secretKey;

}
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_utils6.concatBytes)(prefix, unpadded, suffix);
}
function unpad(padded) {

@@ -284,2 +287,9 @@ const unpaddedLen = new DataView(padded.buffer).getUint16(0);

}
function encrypt(plaintext, conversationKey, nonce = (0, import_utils6.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_base2.base64.encode((0, import_utils6.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
}
function decrypt2(payload, conversationKey) {

@@ -300,3 +310,4 @@ const { nonce, ciphertext, mac } = decodePayload(payload);

_fetch = fetch;
} catch {
} catch (_) {
null;
}

@@ -405,2 +416,3 @@

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -549,7 +561,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -601,2 +615,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -921,2 +942,3 @@ }

secretKey;
conversationKey;
bp;

@@ -930,2 +952,3 @@ cachedPubKey;

this.secretKey = clientSecretKey;
this.conversationKey = getConversationKey(clientSecretKey, bp.pubkey);
this.bp = bp;

@@ -939,6 +962,6 @@ this.isOpen = false;

const waitingForAuth = this.waitingForAuth;
const skBytes = this.secretKey;
const convKey = this.conversationKey;
this.subCloser = this.pool.subscribeMany(
this.bp.relays,
[{ kinds: [NostrConnect], "#p": [getPublicKey(this.secretKey)] }],
[{ kinds: [NostrConnect], authors: [bp.pubkey], "#p": [getPublicKey(this.secretKey)] }],
{

@@ -948,5 +971,5 @@ async onevent(event) {

try {
o = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content));
o = JSON.parse(decrypt2(event.content, convKey));
} catch (err) {
o = JSON.parse(decrypt2(event.content, getConversationKey(skBytes, event.pubkey)));
o = JSON.parse(await decrypt(event.content, event.pubkey, event.content));
}

@@ -989,3 +1012,3 @@ const { id, result, error } = o;

const id = `${this.idPrefix}-${this.serial}`;
const encryptedContent = await encrypt(this.secretKey, this.bp.pubkey, JSON.stringify({ id, method, params }));
const encryptedContent = encrypt(JSON.stringify({ id, method, params }), this.conversationKey);
const verifiedEvent = finalizeEvent(

@@ -992,0 +1015,0 @@ {

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

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -420,7 +421,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -472,2 +475,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -474,0 +484,0 @@ }

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

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -418,7 +419,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -470,2 +473,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -472,0 +482,0 @@ }

@@ -165,2 +165,3 @@ // core.ts

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -309,7 +310,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -361,2 +364,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -363,0 +373,0 @@ }

@@ -158,2 +158,3 @@ // utils.ts

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -302,7 +303,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -354,2 +357,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -356,0 +366,0 @@ }

@@ -7,3 +7,4 @@ // nip05.ts

_fetch = fetch;
} catch {
} catch (_) {
null;
}

@@ -16,3 +17,6 @@ function useFetchImplementation(fetchImplementation) {

const url = `https://${domain}/.well-known/nostr.json?name=${query}`;
const res = await _fetch(url, { redirect: "error" });
const res = await _fetch(url, { redirect: "manual" });
if (res.status !== 200) {
throw Error("Wrong response code");
}
const json = await res.json();

@@ -28,8 +32,12 @@ return json.names;

return null;
const [_, name = "_", domain] = match;
const [, name = "_", domain] = match;
try {
const url = `https://${domain}/.well-known/nostr.json?name=${name}`;
const res = await (await _fetch(url, { redirect: "error" })).json();
let pubkey = res.names[name];
return pubkey ? { pubkey, relays: res.relays?.[pubkey] } : null;
const res = await _fetch(url, { redirect: "manual" });
if (res.status !== 200) {
throw Error("Wrong response code");
}
const json = await res.json();
const pubkey = json.names[name];
return pubkey ? { pubkey, relays: json.relays?.[pubkey] } : null;
} catch (_e) {

@@ -40,3 +48,3 @@ return null;

async function isValid(pubkey, nip05) {
let res = await queryProfile(nip05);
const res = await queryProfile(nip05);
return res ? res.pubkey === pubkey : false;

@@ -43,0 +51,0 @@ }

@@ -154,13 +154,2 @@ // pure.ts

import { base64 } from "@scure/base";
async function encrypt(secretKey, pubkey, text) {
const privkey = secretKey instanceof Uint8Array ? bytesToHex2(secretKey) : secretKey;
const key = secp256k1.getSharedSecret(privkey, "02" + pubkey);
const normalizedKey = getNormalizedX(key);
let iv = Uint8Array.from(randomBytes(16));
let plaintext = utf8Encoder.encode(text);
let ciphertext = cbc(normalizedKey, iv).encrypt(plaintext);
let ctb64 = base64.encode(new Uint8Array(ciphertext));
let ivb64 = base64.encode(new Uint8Array(iv.buffer));
return `${ctb64}?iv=${ivb64}`;
}
async function decrypt(secretKey, pubkey, data) {

@@ -212,2 +201,16 @@ const privkey = secretKey instanceof Uint8Array ? bytesToHex2(secretKey) : secretKey;

}
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) {

@@ -252,2 +255,9 @@ const unpaddedLen = new DataView(padded.buffer).getUint16(0);

}
function encrypt(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(concatBytes(new Uint8Array([2]), nonce, ciphertext, mac));
}
function decrypt2(payload, conversationKey) {

@@ -268,3 +278,4 @@ const { nonce, ciphertext, mac } = decodePayload(payload);

_fetch = fetch;
} catch {
} catch (_) {
null;
}

@@ -373,2 +384,3 @@

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -517,7 +529,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -569,2 +583,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -889,2 +910,3 @@ }

secretKey;
conversationKey;
bp;

@@ -898,2 +920,3 @@ cachedPubKey;

this.secretKey = clientSecretKey;
this.conversationKey = getConversationKey(clientSecretKey, bp.pubkey);
this.bp = bp;

@@ -907,6 +930,6 @@ this.isOpen = false;

const waitingForAuth = this.waitingForAuth;
const skBytes = this.secretKey;
const convKey = this.conversationKey;
this.subCloser = this.pool.subscribeMany(
this.bp.relays,
[{ kinds: [NostrConnect], "#p": [getPublicKey(this.secretKey)] }],
[{ kinds: [NostrConnect], authors: [bp.pubkey], "#p": [getPublicKey(this.secretKey)] }],
{

@@ -916,5 +939,5 @@ async onevent(event) {

try {
o = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content));
o = JSON.parse(decrypt2(event.content, convKey));
} catch (err) {
o = JSON.parse(decrypt2(event.content, getConversationKey(skBytes, event.pubkey)));
o = JSON.parse(await decrypt(event.content, event.pubkey, event.content));
}

@@ -957,3 +980,3 @@ const { id, result, error } = o;

const id = `${this.idPrefix}-${this.serial}`;
const encryptedContent = await encrypt(this.secretKey, this.bp.pubkey, JSON.stringify({ id, method, params }));
const encryptedContent = encrypt(JSON.stringify({ id, method, params }), this.conversationKey);
const verifiedEvent = finalizeEvent(

@@ -960,0 +983,0 @@ {

@@ -248,2 +248,3 @@ // pure.ts

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -392,7 +393,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -444,2 +447,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -446,0 +456,0 @@ }

@@ -244,2 +244,3 @@ // pure.ts

connectionTimeout = 4400;
publishTimeout = 4400;
openSubs = /* @__PURE__ */ new Map();

@@ -388,7 +389,9 @@ connectionTimeoutHandle;

const ep = this.openEventPublishes.get(id);
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
if (ep) {
if (ok)
ep.resolve(reason);
else
ep.reject(new Error(reason));
this.openEventPublishes.delete(id);
}
return;

@@ -440,2 +443,9 @@ }

this.send('["EVENT",' + JSON.stringify(event) + "]");
setTimeout(() => {
const ep = this.openEventPublishes.get(event.id);
if (ep) {
ep.reject(new Error("publish timed out"));
this.openEventPublishes.delete(event.id);
}
}, this.publishTimeout);
return ret;

@@ -442,0 +452,0 @@ }

@@ -15,2 +15,3 @@ import type { Event, EventTemplate, VerifiedEvent, Nostr } from './core.ts';

connectionTimeout: number;
publishTimeout: number;
openSubs: Map<string, Subscription>;

@@ -17,0 +18,0 @@ private connectionTimeoutHandle;

@@ -12,3 +12,3 @@ import { ProfilePointer } from './nip19.ts';

export declare const isNip05: (value?: string | null) => value is `${string}@${string}`;
export declare function useFetchImplementation(fetchImplementation: any): void;
export declare function useFetchImplementation(fetchImplementation: unknown): void;
export declare function searchDomain(domain: string, query?: string): Promise<{

@@ -15,0 +15,0 @@ [name: string]: string;

@@ -28,2 +28,3 @@ import { UnsignedEvent, VerifiedEvent } from './core.ts';

private secretKey;
private conversationKey;
bp: BunkerPointer;

@@ -30,0 +31,0 @@ private cachedPubKey;

{
"type": "module",
"name": "nostr-tools",
"version": "2.9.4",
"version": "2.10.0",
"description": "Tools for making a Nostr client.",

@@ -6,0 +6,0 @@ "repository": {

@@ -1,2 +0,2 @@

# ![](https://img.shields.io/github/actions/workflow/status/nbd-wtf/nostr-tools/test.yml) nostr-tools
# ![](https://img.shields.io/github/actions/workflow/status/nbd-wtf/nostr-tools/test.yml) [![JSR](https://jsr.io/badges/@nostr/tools)](https://jsr.io/@nostr/tools) nostr-tools

@@ -12,3 +12,7 @@ Tools for developing [Nostr](https://github.com/fiatjaf/nostr) clients.

```bash
npm install nostr-tools # or yarn add nostr-tools
# npm
npm install --save nostr-tools
# jsr
npx jsr add @nostr/tools
```

@@ -18,2 +22,6 @@

## Documentation
https://jsr.io/@nostr/tools/doc
## Usage

@@ -20,0 +28,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 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 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 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