@qntx/nostr 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abort-Ba8tDrOI.mjs +38 -0
- package/dist/abort-Ba8tDrOI.mjs.map +1 -0
- package/dist/{builder-BphJa-Y-.d.mts → builder-BWn55Paf.d.mts} +20 -14
- package/dist/{builder-q0VsvnYE.mjs → builder-CyrGKRVP.mjs} +32 -16
- package/dist/builder-CyrGKRVP.mjs.map +1 -0
- package/dist/{client-Bd8B1mYm.mjs → client-BWsX9Cv1.mjs} +354 -195
- package/dist/client-BWsX9Cv1.mjs.map +1 -0
- package/dist/client.d.mts +1 -1
- package/dist/client.mjs +1 -1
- package/dist/core.d.mts +8 -8
- package/dist/core.mjs +8 -9
- package/dist/error-BW7re1UN.d.mts +9 -0
- package/dist/error-B__OMBRY.mjs +14 -0
- package/dist/error-B__OMBRY.mjs.map +1 -0
- package/dist/{error-WEFS-R-4.d.mts → error-CR8Urc84.d.mts} +20 -8
- package/dist/{error-CwBxle6N.mjs → error-DrEIM7FO.mjs} +5 -3
- package/dist/error-DrEIM7FO.mjs.map +1 -0
- package/dist/{event-CzoQEFMF.mjs → event-D8Nfoh4K.mjs} +40 -32
- package/dist/event-D8Nfoh4K.mjs.map +1 -0
- package/dist/{event-B5D2jxt_.d.mts → event-fU3Y01PR.d.mts} +23 -20
- package/dist/{filter-BxwjEkZp.mjs → filter-BQl3GlHt.mjs} +42 -35
- package/dist/filter-BQl3GlHt.mjs.map +1 -0
- package/dist/filter-C0IMByE3.d.mts +37 -0
- package/dist/{gossip-C5RVB1UB.d.mts → gossip-BRQwIM_q.d.mts} +25 -23
- package/dist/{gossip-3xkRRCm_.mjs → gossip-oloDMWEj.mjs} +52 -34
- package/dist/gossip-oloDMWEj.mjs.map +1 -0
- package/dist/gossip.d.mts +1 -1
- package/dist/gossip.mjs +1 -1
- package/dist/{http-6vevbBlu.d.mts → http-C4HwIu4B.d.mts} +7 -7
- package/dist/{http-D2rhokZo.mjs → http-CuazNRIP.mjs} +10 -6
- package/dist/http-CuazNRIP.mjs.map +1 -0
- package/dist/index-B425CAcQ.d.mts +328 -0
- package/dist/index-BVyfUBuG.d.mts +181 -0
- package/dist/{index-BYMnhRIC.d.mts → index-Ba7bJ7DD.d.mts} +68 -50
- package/dist/{index-DaRyjo7O.d.mts → index-Boe8FshM.d.mts} +13 -7
- package/dist/index-CUIvFQdE.d.mts +73 -0
- package/dist/index-JdaS_uce.d.mts +207 -0
- package/dist/index.d.mts +22 -20
- package/dist/index.mjs +19 -18
- package/dist/{key-Dn-aX4x4.mjs → key-Bbtys6o7.mjs} +22 -14
- package/dist/key-Bbtys6o7.mjs.map +1 -0
- package/dist/{key-BiGxGLhg.d.mts → key-BlsYhN1V.d.mts} +9 -6
- package/dist/{kind-BLl4cLOc.mjs → kind-Cxwhhkx8.mjs} +2 -1
- package/dist/kind-Cxwhhkx8.mjs.map +1 -0
- package/dist/{loaders-BNQszDAn.mjs → loaders-o6YXB_Ri.mjs} +329 -305
- package/dist/loaders-o6YXB_Ri.mjs.map +1 -0
- package/dist/loaders.d.mts +3 -3
- package/dist/loaders.mjs +2 -2
- package/dist/memory-C2EVx0_O.mjs +46 -0
- package/dist/memory-C2EVx0_O.mjs.map +1 -0
- package/dist/{memory-BCmhZPek.mjs → memory-index-Do1mz0WF.mjs} +212 -82
- package/dist/memory-index-Do1mz0WF.mjs.map +1 -0
- package/dist/{message-C_Uj-Y-c.mjs → message-DcY6Fi9o.mjs} +38 -24
- package/dist/message-DcY6Fi9o.mjs.map +1 -0
- package/dist/{message-DJC-Jz6T.d.mts → message-iGPIqnn0.d.mts} +15 -8
- package/dist/{nip17-BWq-Kfq5.d.mts → nip17-DNEkz8rM.d.mts} +18 -17
- package/dist/{nip19-D7905oIv.d.mts → nip19-BevCJZsp.d.mts} +23 -3
- package/dist/{nip46-C_DoxiS_.d.mts → nip46-DDV4dC56.d.mts} +13 -12
- package/dist/{nip59-DljW_sYh.d.mts → nip59-zQgdLcEr.d.mts} +28 -25
- package/dist/{nip65-Di5hZRuV.d.mts → nip65-DBfh2smt.d.mts} +8 -3
- package/dist/{nip77-ByxlgoQO.d.mts → nip77-DH4RhS5r.d.mts} +9 -8
- package/dist/nips/blossom.d.mts +37 -37
- package/dist/nips/blossom.mjs +67 -52
- package/dist/nips/blossom.mjs.map +1 -1
- package/dist/nips/nip04.d.mts +2 -3
- package/dist/nips/nip04.mjs +6 -10
- package/dist/nips/nip04.mjs.map +1 -1
- package/dist/nips/nip05.d.mts +37 -43
- package/dist/nips/nip05.mjs +57 -57
- package/dist/nips/nip05.mjs.map +1 -1
- package/dist/nips/nip10.d.mts +18 -19
- package/dist/nips/nip10.mjs +76 -61
- package/dist/nips/nip10.mjs.map +1 -1
- package/dist/nips/nip11.d.mts +9 -8
- package/dist/nips/nip11.mjs +14 -11
- package/dist/nips/nip11.mjs.map +1 -1
- package/dist/nips/nip13.d.mts +9 -9
- package/dist/nips/nip13.mjs +15 -17
- package/dist/nips/nip13.mjs.map +1 -1
- package/dist/nips/nip17.d.mts +1 -1
- package/dist/nips/nip17.mjs +17 -12
- package/dist/nips/nip17.mjs.map +1 -1
- package/dist/nips/nip19.d.mts +1 -1
- package/dist/nips/nip19.mjs +52 -29
- package/dist/nips/nip19.mjs.map +1 -1
- package/dist/nips/nip21.d.mts +5 -6
- package/dist/nips/nip21.mjs +8 -7
- package/dist/nips/nip21.mjs.map +1 -1
- package/dist/nips/nip27.d.mts +7 -8
- package/dist/nips/nip27.mjs +26 -25
- package/dist/nips/nip27.mjs.map +1 -1
- package/dist/nips/nip42.d.mts +5 -6
- package/dist/nips/nip42.mjs +3 -3
- package/dist/nips/nip42.mjs.map +1 -1
- package/dist/nips/nip44.d.mts +24 -7
- package/dist/nips/nip44.mjs +25 -15
- package/dist/nips/nip44.mjs.map +1 -1
- package/dist/nips/nip46.d.mts +1 -1
- package/dist/nips/nip46.mjs +52 -49
- package/dist/nips/nip46.mjs.map +1 -1
- package/dist/nips/nip49.d.mts +8 -7
- package/dist/nips/nip49.mjs +16 -12
- package/dist/nips/nip49.mjs.map +1 -1
- package/dist/nips/nip51.d.mts +25 -27
- package/dist/nips/nip51.mjs +47 -36
- package/dist/nips/nip51.mjs.map +1 -1
- package/dist/nips/nip57.d.mts +12 -13
- package/dist/nips/nip57.mjs +35 -38
- package/dist/nips/nip57.mjs.map +1 -1
- package/dist/nips/nip59.d.mts +1 -1
- package/dist/nips/nip59.mjs +14 -18
- package/dist/nips/nip59.mjs.map +1 -1
- package/dist/nips/nip65.d.mts +1 -1
- package/dist/nips/nip65.mjs +11 -8
- package/dist/nips/nip65.mjs.map +1 -1
- package/dist/nips/nip77.d.mts +1 -1
- package/dist/nips/nip77.mjs +56 -34
- package/dist/nips/nip77.mjs.map +1 -1
- package/dist/nips/nip96.d.mts +21 -12
- package/dist/nips/nip96.mjs +59 -36
- package/dist/nips/nip96.mjs.map +1 -1
- package/dist/nips/nip98.d.mts +12 -12
- package/dist/nips/nip98.mjs +18 -19
- package/dist/nips/nip98.mjs.map +1 -1
- package/dist/{pool-C_j1OmBB.mjs → pool-XmAGaufS.mjs} +611 -487
- package/dist/pool-XmAGaufS.mjs.map +1 -0
- package/dist/pool-tEr7c5bG.d.mts +302 -0
- package/dist/reactive-DDlThDSZ.mjs +324 -0
- package/dist/reactive-DDlThDSZ.mjs.map +1 -0
- package/dist/reactive-DFpqtIf_.d.mts +66 -0
- package/dist/relay.d.mts +5 -4
- package/dist/relay.mjs +2 -2
- package/dist/report-CHld4uWj.mjs +32 -0
- package/dist/report-CHld4uWj.mjs.map +1 -0
- package/dist/{signer-CZ6K6FUc.mjs → signer-CKR9EHce.mjs} +107 -72
- package/dist/signer-CKR9EHce.mjs.map +1 -0
- package/dist/signer.d.mts +3 -3
- package/dist/signer.mjs +3 -2
- package/dist/storage-xXxLGCVb.mjs +1376 -0
- package/dist/storage-xXxLGCVb.mjs.map +1 -0
- package/dist/storage.d.mts +4 -4
- package/dist/storage.mjs +5 -4
- package/dist/store.d.mts +2 -0
- package/dist/store.mjs +2 -0
- package/dist/testing.d.mts +125 -0
- package/dist/testing.mjs +957 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types-2pCUprRU.d.mts +47 -0
- package/dist/types-CRQEk0Oi.d.mts +19 -0
- package/dist/util-LfQirgDk.mjs +113 -0
- package/dist/util-LfQirgDk.mjs.map +1 -0
- package/dist/wasm.d.mts +4 -4
- package/dist/wasm.mjs +54 -55
- package/dist/wasm.mjs.map +1 -1
- package/dist/websocket-CmeqvAkp.d.mts +27 -0
- package/package.json +31 -9
- package/dist/builder-q0VsvnYE.mjs.map +0 -1
- package/dist/client-Bd8B1mYm.mjs.map +0 -1
- package/dist/error-B49rbDzT.d.mts +0 -7
- package/dist/error-CwBxle6N.mjs.map +0 -1
- package/dist/error-DZEs5OuZ.mjs +0 -24
- package/dist/error-DZEs5OuZ.mjs.map +0 -1
- package/dist/event-CzoQEFMF.mjs.map +0 -1
- package/dist/filter-BxwjEkZp.mjs.map +0 -1
- package/dist/filter-DUEKP3q1.d.mts +0 -40
- package/dist/gossip-3xkRRCm_.mjs.map +0 -1
- package/dist/http-D2rhokZo.mjs.map +0 -1
- package/dist/index-C0C4e-Gn.d.mts +0 -55
- package/dist/index-DgOugrpF.d.mts +0 -275
- package/dist/index-EwL6fHLo.d.mts +0 -267
- package/dist/index-k2YhCgsh.d.mts +0 -57
- package/dist/key-Dn-aX4x4.mjs.map +0 -1
- package/dist/kind-BLl4cLOc.mjs.map +0 -1
- package/dist/loaders-BNQszDAn.mjs.map +0 -1
- package/dist/memory-BCmhZPek.mjs.map +0 -1
- package/dist/message-C_Uj-Y-c.mjs.map +0 -1
- package/dist/pool-C_j1OmBB.mjs.map +0 -1
- package/dist/pool-DhRi7l-b.d.mts +0 -297
- package/dist/signer-CZ6K6FUc.mjs.map +0 -1
- package/dist/storage-DOy0iLRE.mjs +0 -870
- package/dist/storage-DOy0iLRE.mjs.map +0 -1
- package/dist/types-BzyADqnw.d.mts +0 -19
- package/dist/types-Dn24TPFs.d.mts +0 -43
- package/dist/util-6tfLQ9JF.mjs +0 -73
- package/dist/util-6tfLQ9JF.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
7
|
-
import { a as
|
|
8
|
-
import {
|
|
9
|
-
import "./
|
|
10
|
-
import { a as KeysSigner, i as isNip07Available, n as Nip07Signer, r as getWindowNostr, t as Nip46Signer } from "./signer-CZ6K6FUc.mjs";
|
|
1
|
+
import { C as SUBSCRIPTION_ID_MAX_CHARS, S as SIGNATURE_BYTES, _ as UrlError, a as hexToBytes, b as PUBLIC_KEY_BYTES, f as CryptoError, g as NostrError, h as MessageError, i as bytesToHex, l as normalizeURL, m as HexError, o as isHex32, p as EventValidationError, s as isHex64, v as WasmVerifyPoisonedError, x as SECRET_KEY_BYTES, y as EVENT_ID_BYTES } from "./util-LfQirgDk.mjs";
|
|
2
|
+
import { a as isRegularKind, i as isEphemeralKind, n as classifyKind, o as isReplaceableKind, r as isAddressableKind, t as Kind } from "./kind-Cxwhhkx8.mjs";
|
|
3
|
+
import { S as tagValue, _ as formatEventAddress, a as isReplaceableWinner, b as parseEventAddress, d as sortEvents, f as sortedEvents, g as eventAddress, h as Tag, l as serializeEvent, m as validateSignedEvent, n as getEventHash, o as itemCompare, p as validateEvent, u as signedMatchesUnsigned, v as getDTag, x as tagName, y as isTag } from "./event-D8Nfoh4K.mjs";
|
|
4
|
+
import { a as publicKeyFromHex, i as getPublicKey, n as SecretKey, o as signEvent, r as finalizeEvent, s as verifyEvent, t as Keys } from "./key-Bbtys6o7.mjs";
|
|
5
|
+
import { t as EventBuilder } from "./builder-CyrGKRVP.mjs";
|
|
6
|
+
import { a as matchFilter, i as getFilterLimit, n as canonicalizeFilters, o as matchFilters, r as filterFingerprint, s as mergeFilters, t as canonicalizeFilter } from "./filter-BQl3GlHt.mjs";
|
|
7
|
+
import { a as mergeCountHll, i as encodeRelayMessage, n as createSubscriptionId, o as parseClientMessage, r as encodeClientMessage, s as parseRelayMessage, t as assertSubscriptionId } from "./message-DcY6Fi9o.mjs";
|
|
8
|
+
import { t as NoSignerError } from "./error-B__OMBRY.mjs";
|
|
9
|
+
import { a as KeysSigner, i as isNip07Available, n as Nip07Signer, r as getWindowNostr, t as Nip46Signer } from "./signer-CKR9EHce.mjs";
|
|
11
10
|
import { Bech32MaxSize, Nip19Error, decode, decodeNostrURI, naddrEncode, neventEncode, noteEncode, nprofileEncode, npubEncode, nsecEncode } from "./nips/nip19.mjs";
|
|
12
11
|
import { buildReplyTags, parseThreadTags, replyTo } from "./nips/nip10.mjs";
|
|
13
12
|
import { isAuthRequired, makeAuthEvent } from "./nips/nip42.mjs";
|
|
14
13
|
import { markerOf, parseRelayList, readRelays, relayListEventBuilder, relayListToTags, writeRelays } from "./nips/nip65.mjs";
|
|
15
|
-
import { a as RelayStatus, c as isInsecureRelayUrl, d as RelayClosedError, f as RelayConnectionError, i as Relay, m as RelayPublishError, p as RelayError, t as Pool, u as useWebSocketImplementation } from "./pool-
|
|
14
|
+
import { a as RelayStatus, c as isInsecureRelayUrl, d as RelayClosedError, f as RelayConnectionError, h as RelayTimeoutError, i as Relay, m as RelayPublishError, p as RelayError, t as Pool, u as useWebSocketImplementation } from "./pool-XmAGaufS.mjs";
|
|
16
15
|
import "./relay.mjs";
|
|
17
|
-
import { t as Gossip } from "./gossip-
|
|
18
|
-
import { a as groupAuthorsByOutboxRelay,
|
|
19
|
-
import { t as StorageError } from "./error-
|
|
20
|
-
import { t as MemoryEventStore } from "./memory-
|
|
21
|
-
import {
|
|
22
|
-
import { t as
|
|
23
|
-
|
|
16
|
+
import { t as Gossip } from "./gossip-oloDMWEj.mjs";
|
|
17
|
+
import { a as groupAuthorsByOutboxRelay, i as createOutboxFeed, n as OutboxError, o as bareNostrUser, r as OutboxFeed, t as createLoaders } from "./loaders-o6YXB_Ri.mjs";
|
|
18
|
+
import { t as StorageError } from "./error-DrEIM7FO.mjs";
|
|
19
|
+
import { t as MemoryEventStore } from "./memory-C2EVx0_O.mjs";
|
|
20
|
+
import { t as ReactiveEventStore } from "./reactive-DDlThDSZ.mjs";
|
|
21
|
+
import { i as ClientBuilder, n as ClientError, r as SyncDirection, t as Client } from "./client-BWsX9Cv1.mjs";
|
|
22
|
+
import { n as IndexedDbEventStore, t as SqliteEventStore } from "./storage-xXxLGCVb.mjs";
|
|
23
|
+
import "./store.mjs";
|
|
24
|
+
export { Bech32MaxSize, Client, ClientBuilder, ClientError, CryptoError, EVENT_ID_BYTES, EventBuilder, EventValidationError, Gossip, HexError, IndexedDbEventStore, Keys, KeysSigner, Kind, MemoryEventStore, MessageError, Nip07Signer, Nip19Error, Nip46Signer, NoSignerError, NostrError, OutboxError, OutboxFeed, PUBLIC_KEY_BYTES, Pool, ReactiveEventStore, Relay, RelayClosedError, RelayConnectionError, RelayError, RelayPublishError, RelayStatus, RelayTimeoutError, SECRET_KEY_BYTES, SIGNATURE_BYTES, SUBSCRIPTION_ID_MAX_CHARS, SecretKey, SqliteEventStore, StorageError, SyncDirection, Tag, UrlError, WasmVerifyPoisonedError, assertSubscriptionId, bareNostrUser, buildReplyTags, bytesToHex, canonicalizeFilter, canonicalizeFilters, classifyKind, createLoaders, createOutboxFeed, createSubscriptionId, decodeNostrURI, encodeClientMessage, encodeRelayMessage, eventAddress, filterFingerprint, finalizeEvent, formatEventAddress, getDTag, getEventHash, getFilterLimit, getPublicKey, getWindowNostr, groupAuthorsByOutboxRelay, hexToBytes, isAddressableKind, isAuthRequired, isEphemeralKind, isHex32, isHex64, isInsecureRelayUrl, isNip07Available, isRegularKind, isReplaceableKind, isReplaceableWinner, isTag, itemCompare, makeAuthEvent, markerOf, matchFilter, matchFilters, mergeCountHll, mergeFilters, naddrEncode, neventEncode, decode as nip19Decode, normalizeURL, noteEncode, nprofileEncode, npubEncode, nsecEncode, parseClientMessage, parseEventAddress, parseRelayList, parseRelayMessage, parseThreadTags, publicKeyFromHex, readRelays, relayListEventBuilder, relayListToTags, replyTo, serializeEvent, signEvent, signedMatchesUnsigned, sortEvents, sortedEvents, tagName, tagValue, useWebSocketImplementation, validateEvent, validateSignedEvent, verifyEvent, writeRelays };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { f as validateEvent, n as isMarkedFailed, o as markUnverified, p as validateSignedEvent, r as isMarkedVerified, s as markVerified, t as getEventHash } from "./event-CzoQEFMF.mjs";
|
|
1
|
+
import { a as hexToBytes, f as CryptoError, i as bytesToHex, n as assertHex32, r as assertSecretKeyBytes } from "./util-LfQirgDk.mjs";
|
|
2
|
+
import { c as markVerified, i as isMarkedVerified, m as validateSignedEvent, n as getEventHash, p as validateEvent, r as isMarkedFailed, s as markUnverified } from "./event-D8Nfoh4K.mjs";
|
|
4
3
|
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
5
4
|
//#region src/core/key.ts
|
|
6
5
|
/** 32-byte secret key held as bytes; prefer zeroize when done. */
|
|
@@ -30,13 +29,15 @@ var SecretKey = class SecretKey {
|
|
|
30
29
|
zeroize() {
|
|
31
30
|
if (this.#bytes) {
|
|
32
31
|
this.#bytes.fill(0);
|
|
33
|
-
this.#bytes =
|
|
32
|
+
this.#bytes = void 0;
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
};
|
|
36
|
+
/** Validate and normalize a hex public key; throws {@link HexError} on bad input. */
|
|
37
37
|
function publicKeyFromHex(hex) {
|
|
38
38
|
return assertHex32(hex, "public key");
|
|
39
39
|
}
|
|
40
|
+
/** Derive the public key for a secret key given as SecretKey, bytes, or hex. */
|
|
40
41
|
function getPublicKey(secretKey) {
|
|
41
42
|
const bytes = secretKey instanceof SecretKey ? secretKey.bytes : typeof secretKey === "string" ? hexToBytes(assertHex32(secretKey, "secret key")) : (assertSecretKeyBytes(secretKey), secretKey);
|
|
42
43
|
return bytesToHex(schnorr.getPublicKey(bytes));
|
|
@@ -63,10 +64,17 @@ function resolveSecretKeyBytes(secretKey) {
|
|
|
63
64
|
assertSecretKeyBytes(secretKey);
|
|
64
65
|
return secretKey;
|
|
65
66
|
}
|
|
67
|
+
function resolveSigningKey(secretKey) {
|
|
68
|
+
if (secretKey instanceof Keys) return {
|
|
69
|
+
bytes: secretKey.secretKey.bytes,
|
|
70
|
+
publicKey: secretKey.publicKey
|
|
71
|
+
};
|
|
72
|
+
return { bytes: resolveSecretKeyBytes(secretKey) };
|
|
73
|
+
}
|
|
66
74
|
/** Fill pubkey/id/sig on a template and return a signed event. */
|
|
67
75
|
function finalizeEvent(template, secretKey) {
|
|
68
|
-
const sk =
|
|
69
|
-
const pubkey = bytesToHex(schnorr.getPublicKey(sk));
|
|
76
|
+
const { bytes: sk, publicKey } = resolveSigningKey(secretKey);
|
|
77
|
+
const pubkey = publicKey ?? bytesToHex(schnorr.getPublicKey(sk));
|
|
70
78
|
return signEvent({
|
|
71
79
|
kind: template.kind,
|
|
72
80
|
tags: template.tags,
|
|
@@ -76,14 +84,14 @@ function finalizeEvent(template, secretKey) {
|
|
|
76
84
|
}, sk);
|
|
77
85
|
}
|
|
78
86
|
/**
|
|
79
|
-
* Sign an already-assembled unsigned event.
|
|
80
|
-
*
|
|
87
|
+
* Sign an already-assembled unsigned event. Rejects when `unsigned.pubkey` does not match the
|
|
88
|
+
* secret key.
|
|
81
89
|
*/
|
|
82
90
|
function signEvent(unsigned, secretKey) {
|
|
83
|
-
const sk =
|
|
91
|
+
const { bytes: sk, publicKey } = resolveSigningKey(secretKey);
|
|
84
92
|
if (!validateEvent(unsigned)) throw new CryptoError("cannot sign invalid unsigned event");
|
|
85
|
-
const expected = bytesToHex(schnorr.getPublicKey(sk));
|
|
86
|
-
if (unsigned.pubkey
|
|
93
|
+
const expected = publicKey ?? bytesToHex(schnorr.getPublicKey(sk));
|
|
94
|
+
if (unsigned.pubkey !== expected) throw new CryptoError("unsigned event pubkey does not match secret key");
|
|
87
95
|
const normalized = {
|
|
88
96
|
kind: unsigned.kind,
|
|
89
97
|
tags: unsigned.tags,
|
|
@@ -111,11 +119,11 @@ function verifyEvent(event) {
|
|
|
111
119
|
}
|
|
112
120
|
try {
|
|
113
121
|
const hash = getEventHash(event);
|
|
114
|
-
if (hash !== event.id
|
|
122
|
+
if (hash !== event.id) {
|
|
115
123
|
markUnverified(event);
|
|
116
124
|
return false;
|
|
117
125
|
}
|
|
118
|
-
const ok = schnorr.verify(hexToBytes(event.sig
|
|
126
|
+
const ok = schnorr.verify(hexToBytes(event.sig), hexToBytes(hash), hexToBytes(event.pubkey));
|
|
119
127
|
if (ok) markVerified(event);
|
|
120
128
|
else markUnverified(event);
|
|
121
129
|
return ok;
|
|
@@ -127,4 +135,4 @@ function verifyEvent(event) {
|
|
|
127
135
|
//#endregion
|
|
128
136
|
export { publicKeyFromHex as a, getPublicKey as i, SecretKey as n, signEvent as o, finalizeEvent as r, verifyEvent as s, Keys as t };
|
|
129
137
|
|
|
130
|
-
//# sourceMappingURL=key-
|
|
138
|
+
//# sourceMappingURL=key-Bbtys6o7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-Bbtys6o7.mjs","names":[],"sources":["../src/core/key.ts"],"sourcesContent":["import { schnorr } from \"@noble/curves/secp256k1.js\";\n\nimport { CryptoError } from \"./error.ts\";\nimport {\n getEventHash,\n isMarkedFailed,\n isMarkedVerified,\n markUnverified,\n markVerified,\n validateEvent,\n validateSignedEvent,\n} from \"./event.ts\";\nimport type { Event, EventTemplate, UnsignedEvent } from \"./event.ts\";\nimport { assertHex32, assertSecretKeyBytes, bytesToHex, hexToBytes } from \"./util.ts\";\n\n/** 32-byte secret key held as bytes; prefer zeroize when done. */\nexport class SecretKey {\n #bytes: Uint8Array | undefined;\n\n private constructor(bytes: Uint8Array) {\n assertSecretKeyBytes(bytes);\n this.#bytes = new Uint8Array(bytes);\n }\n\n static generate(): SecretKey {\n return new SecretKey(schnorr.utils.randomSecretKey());\n }\n\n static fromBytes(bytes: Uint8Array): SecretKey {\n return new SecretKey(bytes);\n }\n\n static fromHex(hex: string): SecretKey {\n return new SecretKey(hexToBytes(assertHex32(hex, \"secret key\")));\n }\n\n get bytes(): Uint8Array {\n if (!this.#bytes) {\n throw new CryptoError(\"secret key has been zeroized\");\n }\n return new Uint8Array(this.#bytes);\n }\n\n toHex(): string {\n return bytesToHex(this.bytes);\n }\n\n /** Best-effort wipe of the internal buffer. */\n zeroize(): void {\n if (this.#bytes) {\n this.#bytes.fill(0);\n this.#bytes = undefined;\n }\n }\n}\n\n/** Lowercase hex-encoded secp256k1 public key (x-only, 64 chars). */\nexport type PublicKey = string;\n\n/** Validate and normalize a hex public key; throws {@link HexError} on bad input. */\nexport function publicKeyFromHex(hex: string): PublicKey {\n return assertHex32(hex, \"public key\");\n}\n\n/** Derive the public key for a secret key given as SecretKey, bytes, or hex. */\nexport function getPublicKey(secretKey: SecretKey | Uint8Array | string): PublicKey {\n const bytes =\n secretKey instanceof SecretKey\n ? secretKey.bytes\n : typeof secretKey === \"string\"\n ? hexToBytes(assertHex32(secretKey, \"secret key\"))\n : (assertSecretKeyBytes(secretKey), secretKey);\n return bytesToHex(schnorr.getPublicKey(bytes));\n}\n\n/** Keypair convenience wrapper. */\nexport class Keys {\n readonly secretKey: SecretKey;\n readonly publicKey: PublicKey;\n\n private constructor(secretKey: SecretKey) {\n this.secretKey = secretKey;\n this.publicKey = getPublicKey(secretKey);\n }\n\n static generate(): Keys {\n return new Keys(SecretKey.generate());\n }\n\n static fromSecretKey(secretKey: SecretKey | Uint8Array | string): Keys {\n const sk =\n secretKey instanceof SecretKey\n ? secretKey\n : typeof secretKey === \"string\"\n ? SecretKey.fromHex(secretKey)\n : SecretKey.fromBytes(secretKey);\n return new Keys(sk);\n }\n}\n\nfunction resolveSecretKeyBytes(secretKey: SecretKey | Uint8Array | string): Uint8Array {\n if (secretKey instanceof SecretKey) {\n return secretKey.bytes;\n }\n if (typeof secretKey === \"string\") {\n return hexToBytes(assertHex32(secretKey, \"secret key\"));\n }\n assertSecretKeyBytes(secretKey);\n return secretKey;\n}\n\nfunction resolveSigningKey(secretKey: SecretKey | Uint8Array | string | Keys): {\n bytes: Uint8Array;\n publicKey?: PublicKey;\n} {\n if (secretKey instanceof Keys) {\n return { bytes: secretKey.secretKey.bytes, publicKey: secretKey.publicKey };\n }\n return { bytes: resolveSecretKeyBytes(secretKey) };\n}\n\n/** Fill pubkey/id/sig on a template and return a signed event. */\nexport function finalizeEvent(\n template: EventTemplate,\n secretKey: SecretKey | Uint8Array | string | Keys,\n): Event {\n const { bytes: sk, publicKey } = resolveSigningKey(secretKey);\n const pubkey = publicKey ?? bytesToHex(schnorr.getPublicKey(sk));\n const unsigned: UnsignedEvent = {\n kind: template.kind,\n tags: template.tags,\n content: template.content,\n created_at: template.created_at,\n pubkey,\n };\n return signEvent(unsigned, sk);\n}\n\n/**\n * Sign an already-assembled unsigned event. Rejects when `unsigned.pubkey` does not match the\n * secret key.\n */\nexport function signEvent(\n unsigned: UnsignedEvent,\n secretKey: SecretKey | Uint8Array | string | Keys,\n): Event {\n const { bytes: sk, publicKey } = resolveSigningKey(secretKey);\n if (!validateEvent(unsigned)) {\n throw new CryptoError(\"cannot sign invalid unsigned event\");\n }\n\n const expected = publicKey ?? bytesToHex(schnorr.getPublicKey(sk));\n if (unsigned.pubkey !== expected) {\n throw new CryptoError(\"unsigned event pubkey does not match secret key\");\n }\n\n const normalized: UnsignedEvent = {\n kind: unsigned.kind,\n tags: unsigned.tags,\n content: unsigned.content,\n created_at: unsigned.created_at,\n pubkey: expected,\n };\n\n const id = getEventHash(normalized);\n const sig = bytesToHex(schnorr.sign(hexToBytes(id), sk));\n const event: Event = { ...normalized, id, sig };\n markVerified(event);\n return event;\n}\n\n/** Verify event id and BIP-340 signature. Uses WeakSet cache (does not mutate the event). */\nexport function verifyEvent(event: Event): boolean {\n if (isMarkedVerified(event)) {\n return true;\n }\n if (isMarkedFailed(event)) {\n return false;\n }\n\n if (!validateSignedEvent(event)) {\n markUnverified(event);\n return false;\n }\n\n try {\n const hash = getEventHash(event);\n if (hash !== event.id) {\n markUnverified(event);\n return false;\n }\n const ok = schnorr.verify(hexToBytes(event.sig), hexToBytes(hash), hexToBytes(event.pubkey));\n if (ok) {\n markVerified(event);\n } else {\n markUnverified(event);\n }\n return ok;\n } catch {\n markUnverified(event);\n return false;\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as EventTemplate, r as UnsignedEvent, t as Event } from "./event-
|
|
1
|
+
import { n as EventTemplate, r as UnsignedEvent, t as Event } from "./event-fU3Y01PR.mjs";
|
|
2
2
|
//#region src/core/key.d.ts
|
|
3
3
|
/** 32-byte secret key held as bytes; prefer zeroize when done. */
|
|
4
4
|
declare class SecretKey {
|
|
@@ -12,8 +12,11 @@ declare class SecretKey {
|
|
|
12
12
|
/** Best-effort wipe of the internal buffer. */
|
|
13
13
|
zeroize(): void;
|
|
14
14
|
}
|
|
15
|
+
/** Lowercase hex-encoded secp256k1 public key (x-only, 64 chars). */
|
|
15
16
|
type PublicKey = string;
|
|
17
|
+
/** Validate and normalize a hex public key; throws {@link HexError} on bad input. */
|
|
16
18
|
declare function publicKeyFromHex(hex: string): PublicKey;
|
|
19
|
+
/** Derive the public key for a secret key given as SecretKey, bytes, or hex. */
|
|
17
20
|
declare function getPublicKey(secretKey: SecretKey | Uint8Array | string): PublicKey;
|
|
18
21
|
/** Keypair convenience wrapper. */
|
|
19
22
|
declare class Keys {
|
|
@@ -24,14 +27,14 @@ declare class Keys {
|
|
|
24
27
|
static fromSecretKey(secretKey: SecretKey | Uint8Array | string): Keys;
|
|
25
28
|
}
|
|
26
29
|
/** Fill pubkey/id/sig on a template and return a signed event. */
|
|
27
|
-
declare function finalizeEvent(template: EventTemplate, secretKey: SecretKey | Uint8Array | string): Event;
|
|
30
|
+
declare function finalizeEvent(template: EventTemplate, secretKey: SecretKey | Uint8Array | string | Keys): Event;
|
|
28
31
|
/**
|
|
29
|
-
* Sign an already-assembled unsigned event.
|
|
30
|
-
*
|
|
32
|
+
* Sign an already-assembled unsigned event. Rejects when `unsigned.pubkey` does not match the
|
|
33
|
+
* secret key.
|
|
31
34
|
*/
|
|
32
|
-
declare function signEvent(unsigned: UnsignedEvent, secretKey: SecretKey | Uint8Array | string): Event;
|
|
35
|
+
declare function signEvent(unsigned: UnsignedEvent, secretKey: SecretKey | Uint8Array | string | Keys): Event;
|
|
33
36
|
/** Verify event id and BIP-340 signature. Uses WeakSet cache (does not mutate the event). */
|
|
34
37
|
declare function verifyEvent(event: Event): boolean;
|
|
35
38
|
//#endregion
|
|
36
39
|
export { getPublicKey as a, verifyEvent as c, finalizeEvent as i, PublicKey as n, publicKeyFromHex as o, SecretKey as r, signEvent as s, Keys as t };
|
|
37
|
-
//# sourceMappingURL=key-
|
|
40
|
+
//# sourceMappingURL=key-BlsYhN1V.d.mts.map
|
|
@@ -15,6 +15,7 @@ function isEphemeralKind(kind) {
|
|
|
15
15
|
function isAddressableKind(kind) {
|
|
16
16
|
return kind >= 3e4 && kind < 4e4;
|
|
17
17
|
}
|
|
18
|
+
/** Classify a kind number into its NIP-01 storage class (`"unknown"` outside all ranges). */
|
|
18
19
|
function classifyKind(kind) {
|
|
19
20
|
if (isRegularKind(kind)) return "regular";
|
|
20
21
|
if (isReplaceableKind(kind)) return "replaceable";
|
|
@@ -56,4 +57,4 @@ const Kind = {
|
|
|
56
57
|
//#endregion
|
|
57
58
|
export { isRegularKind as a, isEphemeralKind as i, classifyKind as n, isReplaceableKind as o, isAddressableKind as r, Kind as t };
|
|
58
59
|
|
|
59
|
-
//# sourceMappingURL=kind-
|
|
60
|
+
//# sourceMappingURL=kind-Cxwhhkx8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kind-Cxwhhkx8.mjs","names":[],"sources":["../src/core/kind.ts"],"sourcesContent":["/** NIP-01 regular: stored by relays. */\nexport function isRegularKind(kind: number): boolean {\n return kind === 1 || kind === 2 || (kind >= 4 && kind < 45) || (kind >= 1000 && kind < 10000);\n}\n\n/** Replaceable: latest per (pubkey, kind) wins. */\nexport function isReplaceableKind(kind: number): boolean {\n return kind === 0 || kind === 3 || (kind >= 10000 && kind < 20000);\n}\n\n/** Ephemeral: not expected to be stored. */\nexport function isEphemeralKind(kind: number): boolean {\n return kind >= 20000 && kind < 30000;\n}\n\n/** Addressable (parameterized replaceable): latest per (pubkey, kind, d-tag) wins. */\nexport function isAddressableKind(kind: number): boolean {\n return kind >= 30000 && kind < 40000;\n}\n\n/** NIP-01 kind classes: regular / replaceable / ephemeral / addressable. */\nexport type KindClassification =\n | \"regular\"\n | \"replaceable\"\n | \"ephemeral\"\n | \"addressable\"\n | \"unknown\";\n\n/** Classify a kind number into its NIP-01 storage class (`\"unknown\"` outside all ranges). */\nexport function classifyKind(kind: number): KindClassification {\n if (isRegularKind(kind)) {\n return \"regular\";\n }\n if (isReplaceableKind(kind)) {\n return \"replaceable\";\n }\n if (isEphemeralKind(kind)) {\n return \"ephemeral\";\n }\n if (isAddressableKind(kind)) {\n return \"addressable\";\n }\n return \"unknown\";\n}\n\n/** Kind numbers used by this package. */\nexport const Kind = {\n Metadata: 0,\n TextNote: 1,\n Contacts: 3,\n EventDeletion: 5,\n Repost: 6,\n Reaction: 7,\n Seal: 13,\n PrivateDirectMessage: 14,\n GenericRepost: 16,\n GiftWrap: 1059,\n ZapRequest: 9734,\n Zap: 9735,\n MuteList: 10000,\n PinList: 10001,\n RelayList: 10002,\n BookmarkList: 10003,\n FavoriteRelays: 10012,\n UserEmojiList: 10030,\n DirectMessageRelaysList: 10050,\n BlossomServerList: 10063,\n GiftWrapEphemeral: 21059,\n ClientAuth: 22242,\n NostrConnect: 24133,\n BlobsAuth: 24242,\n HttpAuth: 27235,\n RelaySets: 30002,\n EmojiSet: 30030,\n StarterPack: 39089,\n} as const;\n\n/** Name of a kind constant on {@link Kind}. */\nexport type KindName = keyof typeof Kind;\n/** Union of the numeric kind values on {@link Kind}. */\nexport type KnownKind = (typeof Kind)[KindName];\n"],"mappings":";;AACA,SAAgB,cAAc,MAAuB;CACnD,OAAO,SAAS,KAAK,SAAS,KAAM,QAAQ,KAAK,OAAO,MAAQ,QAAQ,OAAQ,OAAO;AACzF;;AAGA,SAAgB,kBAAkB,MAAuB;CACvD,OAAO,SAAS,KAAK,SAAS,KAAM,QAAQ,OAAS,OAAO;AAC9D;;AAGA,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,QAAQ,OAAS,OAAO;AACjC;;AAGA,SAAgB,kBAAkB,MAAuB;CACvD,OAAO,QAAQ,OAAS,OAAO;AACjC;;AAWA,SAAgB,aAAa,MAAkC;CAC7D,IAAI,cAAc,IAAI,GACpB,OAAO;CAET,IAAI,kBAAkB,IAAI,GACxB,OAAO;CAET,IAAI,gBAAgB,IAAI,GACtB,OAAO;CAET,IAAI,kBAAkB,IAAI,GACxB,OAAO;CAET,OAAO;AACT;;AAGA,MAAa,OAAO;CAClB,UAAU;CACV,UAAU;CACV,UAAU;CACV,eAAe;CACf,QAAQ;CACR,UAAU;CACV,MAAM;CACN,sBAAsB;CACtB,eAAe;CACf,UAAU;CACV,YAAY;CACZ,KAAK;CACL,UAAU;CACV,SAAS;CACT,WAAW;CACX,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,yBAAyB;CACzB,mBAAmB;CACnB,mBAAmB;CACnB,YAAY;CACZ,cAAc;CACd,WAAW;CACX,UAAU;CACV,WAAW;CACX,UAAU;CACV,aAAa;AACf"}
|