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.1.8 to 2.1.9

7

lib/cjs/abstract-pool.js

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

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
var AbstractRelay = class {

@@ -242,3 +247,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -245,0 +250,0 @@ reject(err);

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

AbstractRelay: () => AbstractRelay,
Subscription: () => Subscription
Subscription: () => Subscription,
useWebSocketImplementation: () => useWebSocketImplementation
});

@@ -180,2 +181,10 @@ module.exports = __toCommonJS(abstract_relay_exports);

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
function useWebSocketImplementation(websocketImplementation) {
_WebSocket = websocketImplementation;
}
var AbstractRelay = class {

@@ -237,3 +246,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -240,0 +249,0 @@ reject(err);

35

lib/cjs/nip46.js

@@ -319,2 +319,7 @@ "use strict";

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
var AbstractRelay = class {

@@ -376,3 +381,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -797,3 +802,2 @@ reject(err);

subCloser;
relays;
isOpen;

@@ -804,4 +808,3 @@ serial;

secretKey;
connectionSecret;
remotePubkey;
bp;
constructor(clientSecretKey, bp, params = {}) {

@@ -813,5 +816,3 @@ if (bp.relays.length === 0) {

this.secretKey = clientSecretKey;
this.relays = bp.relays;
this.remotePubkey = bp.pubkey;
this.connectionSecret = bp.secret || "";
this.bp = bp;
this.isOpen = false;

@@ -823,3 +824,3 @@ this.idPrefix = Math.random().toString(36).substring(7);

this.subCloser = this.pool.subscribeMany(
this.relays,
this.bp.relays,
[{ kinds: [NostrConnect, NostrConnectAdmin], "#p": [getPublicKey(this.secretKey)] }],

@@ -863,11 +864,7 @@ {

const id = `${this.idPrefix}-${this.serial}`;
const encryptedContent = await encrypt(
this.secretKey,
this.remotePubkey,
JSON.stringify({ id, method, params })
);
const encryptedContent = await encrypt(this.secretKey, this.bp.pubkey, JSON.stringify({ id, method, params }));
const verifiedEvent = finalizeEvent(
{
kind: method === "create_account" ? NostrConnectAdmin : NostrConnect,
tags: [["p", this.remotePubkey]],
tags: [["p", this.bp.pubkey]],
content: encryptedContent,

@@ -879,3 +876,3 @@ created_at: Math.floor(Date.now() / 1e3)

this.listeners[id] = { resolve, reject };
await Promise.any(this.pool.publish(this.relays, verifiedEvent));
await Promise.any(this.pool.publish(this.bp.relays, verifiedEvent));
} catch (err) {

@@ -892,6 +889,6 @@ reject(err);

async connect() {
await this.sendRequest("connect", [getPublicKey(this.secretKey), this.connectionSecret]);
await this.sendRequest("connect", [getPublicKey(this.secretKey), this.bp.secret || ""]);
}
async getPublicKey() {
return this.remotePubkey;
return this.bp.pubkey;
}

@@ -904,3 +901,3 @@ async getRelays() {

let signed = JSON.parse(resp);
if (signed.pubkey === this.remotePubkey && verifyEvent(signed)) {
if (signed.pubkey === this.bp.pubkey && verifyEvent(signed)) {
return signed;

@@ -934,3 +931,3 @@ } else {

let pubkey = await rpc.sendRequest("create_account", [username, domain, email || ""]);
rpc.remotePubkey = pubkey;
rpc.bp.pubkey = pubkey;
await rpc.connect();

@@ -937,0 +934,0 @@ return rpc;

@@ -269,2 +269,7 @@ "use strict";

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
var AbstractRelay = class {

@@ -326,3 +331,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -329,0 +334,0 @@ reject(err);

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

Subscription: () => Subscription,
relayConnect: () => relayConnect
relayConnect: () => relayConnect,
useWebSocketImplementation: () => useWebSocketImplementation
});

@@ -268,2 +269,10 @@ module.exports = __toCommonJS(relay_exports);

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
function useWebSocketImplementation(websocketImplementation) {
_WebSocket = websocketImplementation;
}
var AbstractRelay = class {

@@ -325,3 +334,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -328,0 +337,0 @@ reject(err);

@@ -159,2 +159,7 @@ // kinds.ts

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
var AbstractRelay = class {

@@ -216,3 +221,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -219,0 +224,0 @@ reject(err);

@@ -152,2 +152,10 @@ // kinds.ts

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
function useWebSocketImplementation(websocketImplementation) {
_WebSocket = websocketImplementation;
}
var AbstractRelay = class {

@@ -209,3 +217,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -435,3 +443,4 @@ reject(err);

AbstractRelay,
Subscription
Subscription,
useWebSocketImplementation
};

@@ -547,2 +547,10 @@ var __defProp = Object.defineProperty;

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
function useWebSocketImplementation(websocketImplementation) {
_WebSocket = websocketImplementation;
}
var AbstractRelay = class {

@@ -604,3 +612,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -2212,2 +2220,3 @@ reject(err);

serializeEvent,
useWebSocketImplementation,
utils_exports as utils,

@@ -2214,0 +2223,0 @@ validateEvent,

@@ -288,2 +288,7 @@ // pure.ts

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
var AbstractRelay = class {

@@ -345,3 +350,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -766,3 +771,2 @@ reject(err);

subCloser;
relays;
isOpen;

@@ -773,4 +777,3 @@ serial;

secretKey;
connectionSecret;
remotePubkey;
bp;
constructor(clientSecretKey, bp, params = {}) {

@@ -782,5 +785,3 @@ if (bp.relays.length === 0) {

this.secretKey = clientSecretKey;
this.relays = bp.relays;
this.remotePubkey = bp.pubkey;
this.connectionSecret = bp.secret || "";
this.bp = bp;
this.isOpen = false;

@@ -792,3 +793,3 @@ this.idPrefix = Math.random().toString(36).substring(7);

this.subCloser = this.pool.subscribeMany(
this.relays,
this.bp.relays,
[{ kinds: [NostrConnect, NostrConnectAdmin], "#p": [getPublicKey(this.secretKey)] }],

@@ -832,11 +833,7 @@ {

const id = `${this.idPrefix}-${this.serial}`;
const encryptedContent = await encrypt(
this.secretKey,
this.remotePubkey,
JSON.stringify({ id, method, params })
);
const encryptedContent = await encrypt(this.secretKey, this.bp.pubkey, JSON.stringify({ id, method, params }));
const verifiedEvent = finalizeEvent(
{
kind: method === "create_account" ? NostrConnectAdmin : NostrConnect,
tags: [["p", this.remotePubkey]],
tags: [["p", this.bp.pubkey]],
content: encryptedContent,

@@ -848,3 +845,3 @@ created_at: Math.floor(Date.now() / 1e3)

this.listeners[id] = { resolve, reject };
await Promise.any(this.pool.publish(this.relays, verifiedEvent));
await Promise.any(this.pool.publish(this.bp.relays, verifiedEvent));
} catch (err) {

@@ -861,6 +858,6 @@ reject(err);

async connect() {
await this.sendRequest("connect", [getPublicKey(this.secretKey), this.connectionSecret]);
await this.sendRequest("connect", [getPublicKey(this.secretKey), this.bp.secret || ""]);
}
async getPublicKey() {
return this.remotePubkey;
return this.bp.pubkey;
}

@@ -873,3 +870,3 @@ async getRelays() {

let signed = JSON.parse(resp);
if (signed.pubkey === this.remotePubkey && verifyEvent(signed)) {
if (signed.pubkey === this.bp.pubkey && verifyEvent(signed)) {
return signed;

@@ -903,3 +900,3 @@ } else {

let pubkey = await rpc.sendRequest("create_account", [username, domain, email || ""]);
rpc.remotePubkey = pubkey;
rpc.bp.pubkey = pubkey;
await rpc.connect();

@@ -906,0 +903,0 @@ return rpc;

@@ -242,2 +242,7 @@ // pure.ts

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
var AbstractRelay = class {

@@ -299,3 +304,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -302,0 +307,0 @@ reject(err);

@@ -238,2 +238,10 @@ // pure.ts

// abstract-relay.ts
var _WebSocket;
try {
_WebSocket = WebSocket;
} catch {
}
function useWebSocketImplementation(websocketImplementation) {
_WebSocket = websocketImplementation;
}
var AbstractRelay = class {

@@ -295,3 +303,3 @@ url;

try {
this.ws = new WebSocket(this.url);
this.ws = new _WebSocket(this.url);
} catch (err) {

@@ -538,3 +546,4 @@ reject(err);

Subscription,
relayConnect
relayConnect,
useWebSocketImplementation
};
import type { Event, EventTemplate, VerifiedEvent, Nostr } from './core.ts';
import { type Filter } from './filter.ts';
export declare function useWebSocketImplementation(websocketImplementation: any): void;
export declare class AbstractRelay {

@@ -4,0 +5,0 @@ readonly url: string;

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

private subCloser;
private relays;
private isOpen;

@@ -27,4 +26,3 @@ private serial;

private secretKey;
private connectionSecret;
remotePubkey: string;
bp: BunkerPointer;
/**

@@ -31,0 +29,0 @@ * Creates a new instance of the Nip46 class.

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

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

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

```js
import { generateSecretKey, getPublicKey } from 'nostr-tools'
import { generateSecretKey, getPublicKey } from 'nostr-tools/pure'

@@ -32,3 +32,3 @@ let sk = generateSecretKey() // `sk` is a Uint8Array

```js
import { finalizeEvent, verifyEvent } from 'nostr-tools'
import { finalizeEvent, verifyEvent } from 'nostr-tools/pure'

@@ -48,3 +48,4 @@ let event = finalizeEvent({

```js
import { Relay, finalizeEvent, generateSecretKey, getPublicKey } from 'nostr-tools'
import { finalizeEvent, generateSecretKey, getPublicKey } from 'nostr-tools/pure'
import { Relay } from 'nostr-tools/relay'

@@ -97,6 +98,7 @@ const relay = await Relay.connect('wss://relay.example.com')

To use this on Node.js you first must install `websocket-polyfill` and import it:
To use this on Node.js you first must install `ws` and call something like this:
```js
import 'websocket-polyfill'
import { useWebSocketImplementation } from 'nostr-tools/relay'
useWebSocketImplementation(require('ws'))
```

@@ -107,3 +109,3 @@

```js
import { SimplePool } from 'nostr-tools'
import { SimplePool } from 'nostr-tools/pool'

@@ -144,3 +146,3 @@ const pool = new SimplePool()

```js
import { parseReferences } from 'nostr-tools'
import { parseReferences } from 'nostr-tools/references'

@@ -165,5 +167,5 @@ let references = parseReferences(event)

```js
import { nip05 } from 'nostr-tools'
import { queryProfile } from 'nostr-tools/nip05'
let profile = await nip05.queryProfile('jb55.com')
let profile = await queryProfile('jb55.com')
console.log(profile.pubkey)

@@ -178,3 +180,4 @@ // prints: 32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245

```js
nip05.useFetchImplementation(require('node-fetch'))
import { useFetchImplementation } from 'nostr-tools/nip05'
useFetchImplementation(require('node-fetch'))
```

@@ -185,3 +188,4 @@

```js
import { nip19, generateSecretKey, getPublicKey } from 'nostr-tools'
import { generateSecretKey, getPublicKey } from 'nostr-tools/pure'
import * as nip19 from 'nostr-tools/nip19'

@@ -209,17 +213,2 @@ let sk = generateSecretKey()

## Import modes
### Using just the packages you want
Importing the entirety of `nostr-tools` may bloat your build, so you should probably import individual packages instead:
```js
import { generateSecretKey, finalizeEvent, verifyEvent } from 'nostr-tools/pure'
import { SimplePool } from 'nostr-tools/pool'
import { Relay, Subscription } from 'nostr-tools/relay'
import { matchFilter } from 'nostr-tools/filter'
import { decode, nprofileEncode, neventEncode, npubEncode } from 'nostr-tools/nip19'
// and so on and so forth
```
### Using it with `nostr-wasm`

@@ -226,0 +215,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 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