nostr-tools
Advanced tools
Comparing version 1.11.1 to 1.11.2
@@ -76,2 +76,4 @@ "use strict"; | ||
__export(utils_exports, { | ||
MessageNode: () => MessageNode, | ||
MessageQueue: () => MessageQueue, | ||
insertEventIntoAscendingList: () => insertEventIntoAscendingList, | ||
@@ -168,2 +170,71 @@ insertEventIntoDescendingList: () => insertEventIntoDescendingList, | ||
} | ||
var MessageNode = class { | ||
_value; | ||
_next; | ||
get value() { | ||
return this._value; | ||
} | ||
set value(message) { | ||
this._value = message; | ||
} | ||
get next() { | ||
return this._next; | ||
} | ||
set next(node) { | ||
this._next = node; | ||
} | ||
constructor(message) { | ||
this._value = message; | ||
this._next = null; | ||
} | ||
}; | ||
var MessageQueue = class { | ||
_first; | ||
_last; | ||
get first() { | ||
return this._first; | ||
} | ||
set first(messageNode) { | ||
this._first = messageNode; | ||
} | ||
get last() { | ||
return this._last; | ||
} | ||
set last(messageNode) { | ||
this._last = messageNode; | ||
} | ||
_size; | ||
get size() { | ||
return this._size; | ||
} | ||
set size(v) { | ||
this._size = v; | ||
} | ||
constructor() { | ||
this._first = null; | ||
this._last = null; | ||
this._size = 0; | ||
} | ||
enqueue(message) { | ||
const newNode = new MessageNode(message); | ||
if (this._size === 0 || !this._last) { | ||
this._first = newNode; | ||
this._last = newNode; | ||
} else { | ||
this._last.next = newNode; | ||
this._last = newNode; | ||
} | ||
this._size++; | ||
return true; | ||
} | ||
dequeue() { | ||
if (this._size === 0 || !this._first) | ||
return null; | ||
let prev = this._first; | ||
this._first = prev.next; | ||
prev.next = null; | ||
this._size--; | ||
return prev.value; | ||
} | ||
}; | ||
@@ -395,6 +466,6 @@ // event.ts | ||
}; | ||
let incomingMessageQueue = []; | ||
let incomingMessageQueue = new MessageQueue(); | ||
let handleNextInterval; | ||
ws.onmessage = (e) => { | ||
incomingMessageQueue.push(e.data); | ||
incomingMessageQueue.enqueue(e.data); | ||
if (!handleNextInterval) { | ||
@@ -405,3 +476,3 @@ handleNextInterval = setInterval(handleNext, 0); | ||
function handleNext() { | ||
if (incomingMessageQueue.length === 0) { | ||
if (incomingMessageQueue.size === 0) { | ||
clearInterval(handleNextInterval); | ||
@@ -411,3 +482,3 @@ handleNextInterval = null; | ||
} | ||
var json = incomingMessageQueue.shift(); | ||
var json = incomingMessageQueue.dequeue(); | ||
if (!json) | ||
@@ -828,3 +899,3 @@ return; | ||
}); | ||
var import_utils5 = require("@noble/hashes/utils"); | ||
var import_utils6 = require("@noble/hashes/utils"); | ||
var import_base = require("@scure/base"); | ||
@@ -846,3 +917,3 @@ var Bech32MaxSize = 5e3; | ||
data: { | ||
pubkey: (0, import_utils5.bytesToHex)(tlv[0][0]), | ||
pubkey: (0, import_utils6.bytesToHex)(tlv[0][0]), | ||
relays: tlv[1] ? tlv[1].map((d) => utf8Decoder.decode(d)) : [] | ||
@@ -863,5 +934,5 @@ } | ||
data: { | ||
id: (0, import_utils5.bytesToHex)(tlv[0][0]), | ||
id: (0, import_utils6.bytesToHex)(tlv[0][0]), | ||
relays: tlv[1] ? tlv[1].map((d) => utf8Decoder.decode(d)) : [], | ||
author: tlv[2]?.[0] ? (0, import_utils5.bytesToHex)(tlv[2][0]) : void 0 | ||
author: tlv[2]?.[0] ? (0, import_utils6.bytesToHex)(tlv[2][0]) : void 0 | ||
} | ||
@@ -886,4 +957,4 @@ }; | ||
identifier: utf8Decoder.decode(tlv[0][0]), | ||
pubkey: (0, import_utils5.bytesToHex)(tlv[2][0]), | ||
kind: parseInt((0, import_utils5.bytesToHex)(tlv[3][0]), 16), | ||
pubkey: (0, import_utils6.bytesToHex)(tlv[2][0]), | ||
kind: parseInt((0, import_utils6.bytesToHex)(tlv[3][0]), 16), | ||
relays: tlv[1] ? tlv[1].map((d) => utf8Decoder.decode(d)) : [] | ||
@@ -905,3 +976,3 @@ } | ||
case "note": | ||
return { type: prefix, data: (0, import_utils5.bytesToHex)(data) }; | ||
return { type: prefix, data: (0, import_utils6.bytesToHex)(data) }; | ||
default: | ||
@@ -917,6 +988,8 @@ throw new Error(`unknown prefix ${prefix}`); | ||
let l = rest[1]; | ||
if (!l) | ||
throw new Error(`malformed TLV ${t}`); | ||
let v = rest.slice(2, 2 + l); | ||
rest = rest.slice(2 + l); | ||
if (v.length < l) | ||
continue; | ||
throw new Error(`not enough data to read on TLV ${t}`); | ||
result[t] = result[t] || []; | ||
@@ -937,3 +1010,3 @@ result[t].push(v); | ||
function encodeBytes(prefix, hex) { | ||
let data = (0, import_utils5.hexToBytes)(hex); | ||
let data = (0, import_utils6.hexToBytes)(hex); | ||
let words = import_base.bech32.toWords(data); | ||
@@ -944,3 +1017,3 @@ return import_base.bech32.encode(prefix, words, Bech32MaxSize); | ||
let data = encodeTLV({ | ||
0: [(0, import_utils5.hexToBytes)(profile.pubkey)], | ||
0: [(0, import_utils6.hexToBytes)(profile.pubkey)], | ||
1: (profile.relays || []).map((url) => utf8Encoder.encode(url)) | ||
@@ -953,5 +1026,5 @@ }); | ||
let data = encodeTLV({ | ||
0: [(0, import_utils5.hexToBytes)(event.id)], | ||
0: [(0, import_utils6.hexToBytes)(event.id)], | ||
1: (event.relays || []).map((url) => utf8Encoder.encode(url)), | ||
2: event.author ? [(0, import_utils5.hexToBytes)(event.author)] : [] | ||
2: event.author ? [(0, import_utils6.hexToBytes)(event.author)] : [] | ||
}); | ||
@@ -967,3 +1040,3 @@ let words = import_base.bech32.toWords(data); | ||
1: (addr.relays || []).map((url) => utf8Encoder.encode(url)), | ||
2: [(0, import_utils5.hexToBytes)(addr.pubkey)], | ||
2: [(0, import_utils6.hexToBytes)(addr.pubkey)], | ||
3: [new Uint8Array(kind)] | ||
@@ -992,3 +1065,3 @@ }); | ||
}); | ||
return (0, import_utils5.concatBytes)(...entries); | ||
return (0, import_utils6.concatBytes)(...entries); | ||
} | ||
@@ -1091,3 +1164,3 @@ | ||
}); | ||
var import_utils7 = require("@noble/hashes/utils"); | ||
var import_utils8 = require("@noble/hashes/utils"); | ||
var import_secp256k13 = require("@noble/curves/secp256k1"); | ||
@@ -1101,3 +1174,3 @@ var import_base2 = require("@scure/base"); | ||
const normalizedKey = getNormalizedX(key); | ||
let iv = Uint8Array.from((0, import_utils7.randomBytes)(16)); | ||
let iv = Uint8Array.from((0, import_utils8.randomBytes)(16)); | ||
let plaintext = utf8Encoder.encode(text); | ||
@@ -1211,3 +1284,3 @@ let cryptoKey = await crypto.subtle.importKey( | ||
}); | ||
var import_utils9 = require("@noble/hashes/utils"); | ||
var import_utils10 = require("@noble/hashes/utils"); | ||
var import_english = require("@scure/bip39/wordlists/english.js"); | ||
@@ -1221,3 +1294,3 @@ var import_bip39 = require("@scure/bip39"); | ||
throw new Error("could not derive private key"); | ||
return (0, import_utils9.bytesToHex)(privateKey); | ||
return (0, import_utils10.bytesToHex)(privateKey); | ||
} | ||
@@ -1294,5 +1367,5 @@ function generateSeedWords() { | ||
}); | ||
var import_utils10 = require("@noble/hashes/utils"); | ||
var import_utils11 = require("@noble/hashes/utils"); | ||
function getPow(id) { | ||
return getLeadingZeroBits((0, import_utils10.hexToBytes)(id)); | ||
return getLeadingZeroBits((0, import_utils11.hexToBytes)(id)); | ||
} | ||
@@ -1462,3 +1535,3 @@ function getLeadingZeroBits(hash) { | ||
var import_secp256k14 = require("@noble/curves/secp256k1"); | ||
var import_utils11 = require("@noble/hashes/utils"); | ||
var import_utils12 = require("@noble/hashes/utils"); | ||
var import_sha2562 = require("@noble/hashes/sha256"); | ||
@@ -1479,3 +1552,3 @@ function createDelegation(privateKey, parameters) { | ||
); | ||
let sig = (0, import_utils11.bytesToHex)( | ||
let sig = (0, import_utils12.bytesToHex)( | ||
import_secp256k14.schnorr.sign(sighash, privateKey) | ||
@@ -1482,0 +1555,0 @@ ); |
@@ -7,1 +7,24 @@ import type { Event } from './event.ts'; | ||
export declare function insertEventIntoAscendingList(sortedArray: Event<number>[], event: Event<number>): Event<number>[]; | ||
export declare class MessageNode { | ||
private _value; | ||
private _next; | ||
get value(): string; | ||
set value(message: string); | ||
get next(): MessageNode | null; | ||
set next(node: MessageNode | null); | ||
constructor(message: string); | ||
} | ||
export declare class MessageQueue { | ||
private _first; | ||
private _last; | ||
get first(): MessageNode | null; | ||
set first(messageNode: MessageNode | null); | ||
get last(): MessageNode | null; | ||
set last(messageNode: MessageNode | null); | ||
private _size; | ||
get size(): number; | ||
set size(v: number); | ||
constructor(); | ||
enqueue(message: string): boolean; | ||
dequeue(): string | null; | ||
} |
{ | ||
"name": "nostr-tools", | ||
"version": "1.11.1", | ||
"version": "1.11.2", | ||
"description": "Tools for making a Nostr client.", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1019784
12490