@qntx/nostr 0.11.0 → 0.12.1

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.
Files changed (68) hide show
  1. package/dist/{builder-GBddxj8i.d.mts → builder-BrmLOVj_.d.mts} +2 -2
  2. package/dist/{builder-BQbFDO6S.mjs → builder-Cf2N12CG.mjs} +2 -2
  3. package/dist/{builder-BQbFDO6S.mjs.map → builder-Cf2N12CG.mjs.map} +1 -1
  4. package/dist/{client-CTmp5w84.mjs → client-B3_vToDX.mjs} +5 -5
  5. package/dist/{client-CTmp5w84.mjs.map → client-B3_vToDX.mjs.map} +1 -1
  6. package/dist/client.d.mts +1 -1
  7. package/dist/client.mjs +1 -1
  8. package/dist/core.d.mts +2 -2
  9. package/dist/core.mjs +2 -2
  10. package/dist/{error-UHkqzWL7.mjs → error-D3VNRVhL.mjs} +6 -2
  11. package/dist/error-D3VNRVhL.mjs.map +1 -0
  12. package/dist/{gossip-BTMdlUI7.d.mts → gossip-u0iBlZ1U.d.mts} +2 -2
  13. package/dist/gossip.d.mts +1 -1
  14. package/dist/{index-CSsnE32i.d.mts → index-DxQO1eWA.d.mts} +6 -6
  15. package/dist/{index-N7HUGgwo.d.mts → index-SwMknboJ.d.mts} +53 -3
  16. package/dist/{index-BP94lABY.d.mts → index-yq9xkONo.d.mts} +5 -5
  17. package/dist/index.d.mts +8 -8
  18. package/dist/index.mjs +9 -9
  19. package/dist/{key-k8LDEPZh.mjs → key-B218_SoL.mjs} +32 -7
  20. package/dist/key-B218_SoL.mjs.map +1 -0
  21. package/dist/{key-CyKN1RTi.d.mts → key-CwMVo14x.d.mts} +16 -4
  22. package/dist/{loaders-Dp2nXEFk.mjs → loaders-Xdbx-K61.mjs} +2 -2
  23. package/dist/{loaders-Dp2nXEFk.mjs.map → loaders-Xdbx-K61.mjs.map} +1 -1
  24. package/dist/loaders.d.mts +1 -1
  25. package/dist/loaders.mjs +1 -1
  26. package/dist/{nip17-B7MI82Iq.d.mts → nip17-BM4hJYBq.d.mts} +4 -4
  27. package/dist/{nip51-O_vhOiK2.d.mts → nip51-D_bu8Hph.d.mts} +2 -2
  28. package/dist/{nip59-CdDoJptA.d.mts → nip59-CGWfoItR.d.mts} +14 -6
  29. package/dist/{nip65-BL79HI8N.d.mts → nip65-DaWMg943.d.mts} +2 -2
  30. package/dist/nips/blossom.d.mts +1 -1
  31. package/dist/nips/blossom.mjs +1 -1
  32. package/dist/nips/nip04.d.mts +10 -0
  33. package/dist/nips/nip04.mjs +38 -8
  34. package/dist/nips/nip04.mjs.map +1 -1
  35. package/dist/nips/nip10.d.mts +1 -1
  36. package/dist/nips/nip10.mjs +1 -1
  37. package/dist/nips/nip17.d.mts +1 -1
  38. package/dist/nips/nip17.mjs +2 -2
  39. package/dist/nips/nip17.mjs.map +1 -1
  40. package/dist/nips/nip44.d.mts +5 -0
  41. package/dist/nips/nip44.mjs +9 -2
  42. package/dist/nips/nip44.mjs.map +1 -1
  43. package/dist/nips/nip49.d.mts +7 -1
  44. package/dist/nips/nip49.mjs +16 -2
  45. package/dist/nips/nip49.mjs.map +1 -1
  46. package/dist/nips/nip51.d.mts +1 -1
  47. package/dist/nips/nip51.mjs +1 -1
  48. package/dist/nips/nip59.d.mts +1 -1
  49. package/dist/nips/nip59.mjs +47 -19
  50. package/dist/nips/nip59.mjs.map +1 -1
  51. package/dist/nips/nip65.d.mts +1 -1
  52. package/dist/nips/nip65.mjs +1 -1
  53. package/dist/nips/nip98.mjs +9 -1
  54. package/dist/nips/nip98.mjs.map +1 -1
  55. package/dist/{pool-BMUsw2un.mjs → pool-THuuOW4S.mjs} +2 -2
  56. package/dist/{pool-BMUsw2un.mjs.map → pool-THuuOW4S.mjs.map} +1 -1
  57. package/dist/{relay-DXtwUEdX.mjs → relay-BGPqiGKF.mjs} +2 -2
  58. package/dist/{relay-DXtwUEdX.mjs.map → relay-BGPqiGKF.mjs.map} +1 -1
  59. package/dist/relay.mjs +2 -2
  60. package/dist/{signer-CWtxpOxc.mjs → signer-CNTIeYH4.mjs} +169 -10
  61. package/dist/signer-CNTIeYH4.mjs.map +1 -0
  62. package/dist/signer.d.mts +2 -2
  63. package/dist/signer.mjs +3 -3
  64. package/dist/testing.mjs +2 -2
  65. package/package.json +1 -1
  66. package/dist/error-UHkqzWL7.mjs.map +0 -1
  67. package/dist/key-k8LDEPZh.mjs.map +0 -1
  68. package/dist/signer-CWtxpOxc.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { n as EventTemplate, r as UnsignedEvent, t as Event } from "./event-j3BwI5dF.mjs";
2
- import { i as SecretKeyInput, t as Keys } from "./key-CyKN1RTi.mjs";
2
+ import { i as SecretKeyInput, t as Keys } from "./key-CwMVo14x.mjs";
3
3
  import { t as Filter } from "./filter-PG7r79rt.mjs";
4
4
  import { a as NostrError } from "./error-BquXDmIN.mjs";
5
5
  import { t as NostrSigner } from "./types-BJ4wZ7JJ.mjs";
@@ -13,12 +13,57 @@ import { n as ClientMetadata, t as BunkerPointer } from "./nip46-BHaxC9TZ.mjs";
13
13
  declare class NoSignerError extends NostrError {
14
14
  name: string;
15
15
  }
16
+ /** Thrown when a method is called on a signer after {@link NostrSigner dispose}. */
17
+ declare class SignerDisposedError extends NostrError {
18
+ name: string;
19
+ }
20
+ //#endregion
21
+ //#region src/signer/delegated.d.ts
22
+ /**
23
+ * The three operations an external key holder (wallet keyring, NFC card, platform secure store)
24
+ * provides. The secret itself never enters this process.
25
+ */
26
+ type NostrKeyOperations = {
27
+ /** Lowercase 64-char hex x-only public key. */
28
+ getPublicKey: () => Promise<string>;
29
+ /** 64-byte BIP-340 signature over the 32-byte event id. */
30
+ signEventId: (id: Uint8Array) => Promise<Uint8Array>;
31
+ /**
32
+ * Optional. 32-byte x-coordinate of `ECDH(secret, lift_x(peer))`, unhashed. Enables NIP-04 and
33
+ * NIP-44.
34
+ */
35
+ sharedSecret?: (peer: string) => Promise<Uint8Array>;
36
+ };
37
+ /**
38
+ * {@link NostrSigner} backed by a {@link NostrKeyOperations} key holder. The signer verifies
39
+ * everything the holder returns: the public key shape, the signature length, and the BIP-340
40
+ * signature itself — a misbehaving holder never produces an event relays would reject.
41
+ */
42
+ declare class DelegatedSigner implements NostrSigner {
43
+ #private;
44
+ constructor(operations: NostrKeyOperations);
45
+ getPublicKey(): Promise<string>;
46
+ signEvent(unsigned: UnsignedEvent): Promise<Event>;
47
+ nip44Encrypt(peer: string, plaintext: string): Promise<string>;
48
+ nip44Decrypt(peer: string, payload: string): Promise<string>;
49
+ nip04Encrypt(peer: string, plaintext: string): Promise<string>;
50
+ nip04Decrypt(peer: string, ciphertext: string): Promise<string>;
51
+ /**
52
+ * Zero-fill and clear every cached NIP-44 conversation key. All later calls reject with
53
+ * {@link SignerDisposedError} and never reach the key holder. Idempotent.
54
+ */
55
+ dispose(): void;
56
+ }
16
57
  //#endregion
17
58
  //#region src/signer/keys.d.ts
18
59
  /** Local secret-key signer with NIP-04 (legacy) and NIP-44 support. */
19
60
  declare class KeysSigner implements NostrSigner {
20
61
  #private;
21
62
  constructor(secretKey: SecretKeyInput | Keys);
63
+ /**
64
+ * The live {@link Keys} instance holding the secret material. {@link KeysSigner.dispose} zeroizes
65
+ * it, so a reference obtained earlier reports a zeroized secret afterwards.
66
+ */
22
67
  get keys(): Keys;
23
68
  getPublicKey(): Promise<string>;
24
69
  signEvent(unsigned: UnsignedEvent): Promise<Event>;
@@ -26,6 +71,11 @@ declare class KeysSigner implements NostrSigner {
26
71
  nip04Decrypt(peer: string, ciphertext: string): Promise<string>;
27
72
  nip44Encrypt(peer: string, plaintext: string): Promise<string>;
28
73
  nip44Decrypt(peer: string, payload: string): Promise<string>;
74
+ /**
75
+ * Zeroize the wrapped secret key and every cached NIP-44 conversation key. All later calls reject
76
+ * with {@link SignerDisposedError}. Idempotent.
77
+ */
78
+ dispose(): void;
29
79
  }
30
80
  //#endregion
31
81
  //#region src/signer/nip07.d.ts
@@ -173,5 +223,5 @@ declare class Nip46Signer implements NostrSigner {
173
223
  close(): Promise<void>;
174
224
  }
175
225
  //#endregion
176
- export { Nip07Signer as a, isNip07Available as c, Nip46Transport as i, KeysSigner as l, Nip46SignerOptions as n, WindowNostr as o, Nip46SubscribeOptions as r, getWindowNostr as s, Nip46Signer as t, NoSignerError as u };
177
- //# sourceMappingURL=index-N7HUGgwo.d.mts.map
226
+ export { Nip07Signer as a, isNip07Available as c, NostrKeyOperations as d, NoSignerError as f, Nip46Transport as i, KeysSigner as l, Nip46SignerOptions as n, WindowNostr as o, SignerDisposedError as p, Nip46SubscribeOptions as r, getWindowNostr as s, Nip46Signer as t, DelegatedSigner as u };
227
+ //# sourceMappingURL=index-SwMknboJ.d.mts.map
@@ -1,13 +1,13 @@
1
1
  import { t as Event } from "./event-j3BwI5dF.mjs";
2
- import { n as ProfileMetadata } from "./builder-GBddxj8i.mjs";
3
- import { t as RelayListItem } from "./nip65-BL79HI8N.mjs";
4
- import { t as Gossip } from "./gossip-BTMdlUI7.mjs";
2
+ import { n as ProfileMetadata } from "./builder-BrmLOVj_.mjs";
3
+ import { t as RelayListItem } from "./nip65-DaWMg943.mjs";
4
+ import { t as Gossip } from "./gossip-u0iBlZ1U.mjs";
5
5
  import { a as NostrError } from "./error-BquXDmIN.mjs";
6
6
  import { _ as Closer, n as Pool } from "./pool-DUuYJ0x4.mjs";
7
7
  import { r as OutboxBound, t as EventStore } from "./types-CqhnT-Mx.mjs";
8
8
  import { t as ReactiveEventStore } from "./reactive-jyKrA9ej.mjs";
9
9
  import { i as EventPointer, t as AddressPointer } from "./nip19-DpPN17bY.mjs";
10
- import { t as MuteItem } from "./nip51-O_vhOiK2.mjs";
10
+ import { t as MuteItem } from "./nip51-D_bu8Hph.mjs";
11
11
  //#region src/loaders/event.d.ts
12
12
  type EventRef = string | EventPointer | AddressPointer;
13
13
  /**
@@ -186,4 +186,4 @@ type CreateLoadersOptions = {
186
186
  declare function createLoaders(opts: CreateLoadersOptions): Loaders;
187
187
  //#endregion
188
188
  export { EventRef as _, OutboxFeed as a, NostrUser as c, ListLoaders as d, ListResult as f, EventLoader as g, ReplaceableLoader as h, OutboxError as i, ProfileLoader as l, ReplaceableLoadResult as m, Loaders as n, OutboxFeedOptions as o, LoadStyle as p, createLoaders as r, groupAuthorsByOutboxRelay as s, CreateLoadersOptions as t, bareNostrUser as u };
189
- //# sourceMappingURL=index-BP94lABY.d.mts.map
189
+ //# sourceMappingURL=index-yq9xkONo.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { C as tagName, S as parseEventAddress, _ as eventAddress, b as getDTag, c as serializeEvent, d as sortedEvents, f as validateEvent, g as TagInput, h as Tag, i as getEventHash, l as signedMatchesUnsigned, m as EventAddress, n as EventTemplate, o as isReplaceableWinner, p as validateSignedEvent, r as UnsignedEvent, s as itemCompare, t as Event, u as sortEvents, w as tagValue, x as isTag, y as formatEventAddress } from "./event-j3BwI5dF.mjs";
2
- import { a as SigningBackend, c as publicKeyFromHex, i as SecretKeyInput, l as signEvent, n as PublicKey, o as finalizeEvent, r as SecretKey, s as getPublicKey, t as Keys, u as toSecretKey } from "./key-CyKN1RTi.mjs";
3
- import { n as ProfileMetadata, t as EventBuilder } from "./builder-GBddxj8i.mjs";
2
+ import { a as SigningBackend, c as publicKeyFromHex, i as SecretKeyInput, l as signEvent, n as PublicKey, o as finalizeEvent, r as SecretKey, s as getPublicKey, t as Keys, u as toSecretKey } from "./key-CwMVo14x.mjs";
3
+ import { n as ProfileMetadata, t as EventBuilder } from "./builder-BrmLOVj_.mjs";
4
4
  import { a as getFilterLimit, i as filterFingerprint, n as canonicalizeFilter, o as matchFilter, r as canonicalizeFilters, s as matchFilters, t as Filter } from "./filter-PG7r79rt.mjs";
5
- import { a as relayListEventBuilder, i as readRelays, n as RelayMarker, o as relayListToTags, r as parseRelayList, s as writeRelays, t as RelayListItem } from "./nip65-BL79HI8N.mjs";
6
- import { i as RoutedFilter, r as PubkeyRoutes, t as Gossip } from "./gossip-BTMdlUI7.mjs";
5
+ import { a as relayListEventBuilder, i as readRelays, n as RelayMarker, o as relayListToTags, r as parseRelayList, s as writeRelays, t as RelayListItem } from "./nip65-DaWMg943.mjs";
6
+ import { i as RoutedFilter, r as PubkeyRoutes, t as Gossip } from "./gossip-u0iBlZ1U.mjs";
7
7
  import { a as ClientMessage, c as SubscriptionId, d as encodeClientMessage, f as encodeRelayMessage, h as parseRelayMessage, i as verifyEvent, l as assertSubscriptionId, m as parseClientMessage, n as SerializedEventVerifier, o as CountResult, p as mergeCountHll, r as createEventVerifier, s as RelayMessage, t as EventVerifier, u as createSubscriptionId } from "./verifier-Cl24c9ph.mjs";
8
8
  import { a as NostrError, i as MessageError, n as EventValidationError, o as UrlError, r as HexError, s as WasmPoisonedError, t as CryptoError } from "./error-BquXDmIN.mjs";
9
9
  import { _ as Closer, a as PoolFetchResult, c as PoolSubscribeOptions, d as RelayOptions, f as RelayStatus, g as RelayFetchResult, h as RelayFetchEnd, i as PoolEventMap, l as Relay, m as PublishResult, n as Pool, o as PoolOptions, p as RelayStatusName, r as PoolCountResult, s as PoolPublishResult, t as InvalidEventPolicy, u as RelayEventMap, v as RelaySubscription, y as SubscribeOptions } from "./pool-DUuYJ0x4.mjs";
@@ -11,15 +11,15 @@ import { i as useWebSocketImplementation } from "./websocket-CmeqvAkp.mjs";
11
11
  import { i as PutResult, n as NegentropyItem, r as OutboxBound, t as EventStore } from "./types-CqhnT-Mx.mjs";
12
12
  import { i as Watch, n as ReactiveEventStoreEventMap, r as ReactiveEventStoreOptions, t as ReactiveEventStore } from "./reactive-jyKrA9ej.mjs";
13
13
  import { _ as noteEncode, a as NAddr, b as nsecEncode, c as NPub, d as Note, f as ProfilePointer, g as neventEncode, h as naddrEncode, i as EventPointer, l as NSec, n as Bech32MaxSize, o as NEvent, p as decode, r as DecodedResult, s as NProfile, t as AddressPointer, u as Nip19Error, v as nprofileEncode, y as npubEncode } from "./nip19-DpPN17bY.mjs";
14
- import { a as OutboxFeed, c as NostrUser, f as ListResult, h as ReplaceableLoader, i as OutboxError, m as ReplaceableLoadResult, n as Loaders, o as OutboxFeedOptions, p as LoadStyle, r as createLoaders, s as groupAuthorsByOutboxRelay, u as bareNostrUser } from "./index-BP94lABY.mjs";
14
+ import { a as OutboxFeed, c as NostrUser, f as ListResult, h as ReplaceableLoader, i as OutboxError, m as ReplaceableLoadResult, n as Loaders, o as OutboxFeedOptions, p as LoadStyle, r as createLoaders, s as groupAuthorsByOutboxRelay, u as bareNostrUser } from "./index-yq9xkONo.mjs";
15
15
  import { t as NostrSigner } from "./types-BJ4wZ7JJ.mjs";
16
16
  import { t as StorageError } from "./error-BD_0QFKT.mjs";
17
- import { _ as SyncSummary, c as PrivateMessageSendResult, d as SendPrivateMessageOptions, g as SyncOptions, h as SyncDirectionName, i as ClientOptions, m as SyncDirection, n as ClientError, p as SubscribePrivateMessagesOptions, r as ClientEventMap, s as FetchPrivateMessagesOptions, t as Client, u as ReceivedPrivateMessage } from "./index-CSsnE32i.mjs";
17
+ import { _ as SyncSummary, c as PrivateMessageSendResult, d as SendPrivateMessageOptions, g as SyncOptions, h as SyncDirectionName, i as ClientOptions, m as SyncDirection, n as ClientError, p as SubscribePrivateMessagesOptions, r as ClientEventMap, s as FetchPrivateMessagesOptions, t as Client, u as ReceivedPrivateMessage } from "./index-DxQO1eWA.mjs";
18
18
  import { S as SUBSCRIPTION_ID_MAX_CHARS, _ as normalizeURL, a as classifyKind, b as SECRET_KEY_BYTES, c as isRegularKind, f as bytesToHex, h as isHex64, i as KnownKind, l as isReplaceableKind, m as isHex32, n as KindClassification, o as isAddressableKind, p as hexToBytes, r as KindName, s as isEphemeralKind, t as Kind, v as EVENT_ID_BYTES, x as SIGNATURE_BYTES, y as PUBLIC_KEY_BYTES } from "./index-Hp26bgYG.mjs";
19
- import { a as Nip07Signer, c as isNip07Available, i as Nip46Transport, l as KeysSigner, n as Nip46SignerOptions, o as WindowNostr, r as Nip46SubscribeOptions, s as getWindowNostr, t as Nip46Signer, u as NoSignerError } from "./index-N7HUGgwo.mjs";
19
+ import { a as Nip07Signer, c as isNip07Available, d as NostrKeyOperations, f as NoSignerError, i as Nip46Transport, l as KeysSigner, n as Nip46SignerOptions, o as WindowNostr, p as SignerDisposedError, r as Nip46SubscribeOptions, s as getWindowNostr, t as Nip46Signer, u as DelegatedSigner } from "./index-SwMknboJ.mjs";
20
20
  import { Nip21Error, NostrURI, isNostrURI, parseNostrURI } from "./nips/nip21.mjs";
21
21
  import { ReplyTagsOptions, ThreadReferences, buildReplyTags, parseThreadTags, replyTo } from "./nips/nip10.mjs";
22
22
  import { isAuthRequired, makeAuthEvent } from "./nips/nip42.mjs";
23
23
  import { a as isInsecureRelayUrl, c as RelayError, d as RelayTimeoutError, l as RelayPublishError, o as RelayClosedError, s as RelayConnectionError, u as RelaySuspendedError } from "./index-DD0Ywpay.mjs";
24
24
  import { a as IndexedDbEventStoreOptions, i as IndexedDbEventStore, n as SqlValue, o as MemoryEventStore, r as SqliteEventStore, t as SqlDriver } from "./index-rKcmI6ex.mjs";
25
- export { type AddressPointer, Bech32MaxSize, Client, ClientError, type ClientEventMap, type ClientMessage, type ClientOptions, type Closer, type CountResult, CryptoError, type DecodedResult, EVENT_ID_BYTES, type Event, type EventAddress, EventBuilder, type EventPointer, type EventStore, type EventTemplate, EventValidationError, type EventVerifier, type FetchPrivateMessagesOptions, type Filter, Gossip, HexError, IndexedDbEventStore, type IndexedDbEventStoreOptions, type InvalidEventPolicy, Keys, KeysSigner, Kind, type KindClassification, type KindName, type KnownKind, type ListResult, type LoadStyle, type Loaders, MemoryEventStore, MessageError, type NAddr, type NEvent, type NProfile, type NPub, type NSec, type NegentropyItem, Nip07Signer, Nip19Error, Nip21Error, Nip46Signer, type Nip46SignerOptions, type Nip46SubscribeOptions, type Nip46Transport, NoSignerError, NostrError, type NostrSigner, type NostrURI, type NostrUser, type Note, type OutboxBound, OutboxError, OutboxFeed, type OutboxFeedOptions, PUBLIC_KEY_BYTES, Pool, type PoolCountResult, type PoolEventMap, type PoolFetchResult, type PoolOptions, type PoolPublishResult, type PoolSubscribeOptions, type PrivateMessageSendResult, type ProfileMetadata, type ProfilePointer, type PubkeyRoutes, type PublicKey, type PublishResult, type PutResult, ReactiveEventStore, type ReactiveEventStoreEventMap, type ReactiveEventStoreOptions, type ReceivedPrivateMessage, Relay, RelayClosedError, RelayConnectionError, RelayError, type RelayEventMap, type RelayFetchEnd, type RelayFetchResult, type RelayListItem, type RelayMarker, type RelayMessage, type RelayOptions, RelayPublishError, RelayStatus, type RelayStatusName, type RelaySubscription, RelaySuspendedError, RelayTimeoutError, type ReplaceableLoadResult, type ReplaceableLoader, type ReplyTagsOptions, type RoutedFilter, SECRET_KEY_BYTES, SIGNATURE_BYTES, SUBSCRIPTION_ID_MAX_CHARS, SecretKey, type SecretKeyInput, type SendPrivateMessageOptions, type SerializedEventVerifier, type SigningBackend, type SqlDriver, type SqlValue, SqliteEventStore, StorageError, type SubscribeOptions, type SubscribePrivateMessagesOptions, type SubscriptionId, SyncDirection, type SyncDirectionName, type SyncOptions, type SyncSummary, Tag, type TagInput, type ThreadReferences, type UnsignedEvent, UrlError, WasmPoisonedError, type Watch, type WindowNostr, assertSubscriptionId, bareNostrUser, buildReplyTags, bytesToHex, canonicalizeFilter, canonicalizeFilters, classifyKind, createEventVerifier, createLoaders, createSubscriptionId, encodeClientMessage, encodeRelayMessage, eventAddress, filterFingerprint, finalizeEvent, formatEventAddress, getDTag, getEventHash, getFilterLimit, getPublicKey, getWindowNostr, groupAuthorsByOutboxRelay, hexToBytes, isAddressableKind, isAuthRequired, isEphemeralKind, isHex32, isHex64, isInsecureRelayUrl, isNip07Available, isNostrURI, isRegularKind, isReplaceableKind, isReplaceableWinner, isTag, itemCompare, makeAuthEvent, matchFilter, matchFilters, mergeCountHll, naddrEncode, neventEncode, decode as nip19Decode, normalizeURL, noteEncode, nprofileEncode, npubEncode, nsecEncode, parseClientMessage, parseEventAddress, parseNostrURI, parseRelayList, parseRelayMessage, parseThreadTags, publicKeyFromHex, readRelays, relayListEventBuilder, relayListToTags, replyTo, serializeEvent, signEvent, signedMatchesUnsigned, sortEvents, sortedEvents, tagName, tagValue, toSecretKey, useWebSocketImplementation, validateEvent, validateSignedEvent, verifyEvent, writeRelays };
25
+ export { type AddressPointer, Bech32MaxSize, Client, ClientError, type ClientEventMap, type ClientMessage, type ClientOptions, type Closer, type CountResult, CryptoError, type DecodedResult, DelegatedSigner, EVENT_ID_BYTES, type Event, type EventAddress, EventBuilder, type EventPointer, type EventStore, type EventTemplate, EventValidationError, type EventVerifier, type FetchPrivateMessagesOptions, type Filter, Gossip, HexError, IndexedDbEventStore, type IndexedDbEventStoreOptions, type InvalidEventPolicy, Keys, KeysSigner, Kind, type KindClassification, type KindName, type KnownKind, type ListResult, type LoadStyle, type Loaders, MemoryEventStore, MessageError, type NAddr, type NEvent, type NProfile, type NPub, type NSec, type NegentropyItem, Nip07Signer, Nip19Error, Nip21Error, Nip46Signer, type Nip46SignerOptions, type Nip46SubscribeOptions, type Nip46Transport, NoSignerError, NostrError, type NostrKeyOperations, type NostrSigner, type NostrURI, type NostrUser, type Note, type OutboxBound, OutboxError, OutboxFeed, type OutboxFeedOptions, PUBLIC_KEY_BYTES, Pool, type PoolCountResult, type PoolEventMap, type PoolFetchResult, type PoolOptions, type PoolPublishResult, type PoolSubscribeOptions, type PrivateMessageSendResult, type ProfileMetadata, type ProfilePointer, type PubkeyRoutes, type PublicKey, type PublishResult, type PutResult, ReactiveEventStore, type ReactiveEventStoreEventMap, type ReactiveEventStoreOptions, type ReceivedPrivateMessage, Relay, RelayClosedError, RelayConnectionError, RelayError, type RelayEventMap, type RelayFetchEnd, type RelayFetchResult, type RelayListItem, type RelayMarker, type RelayMessage, type RelayOptions, RelayPublishError, RelayStatus, type RelayStatusName, type RelaySubscription, RelaySuspendedError, RelayTimeoutError, type ReplaceableLoadResult, type ReplaceableLoader, type ReplyTagsOptions, type RoutedFilter, SECRET_KEY_BYTES, SIGNATURE_BYTES, SUBSCRIPTION_ID_MAX_CHARS, SecretKey, type SecretKeyInput, type SendPrivateMessageOptions, type SerializedEventVerifier, SignerDisposedError, type SigningBackend, type SqlDriver, type SqlValue, SqliteEventStore, StorageError, type SubscribeOptions, type SubscribePrivateMessagesOptions, type SubscriptionId, SyncDirection, type SyncDirectionName, type SyncOptions, type SyncSummary, Tag, type TagInput, type ThreadReferences, type UnsignedEvent, UrlError, WasmPoisonedError, type Watch, type WindowNostr, assertSubscriptionId, bareNostrUser, buildReplyTags, bytesToHex, canonicalizeFilter, canonicalizeFilters, classifyKind, createEventVerifier, createLoaders, createSubscriptionId, encodeClientMessage, encodeRelayMessage, eventAddress, filterFingerprint, finalizeEvent, formatEventAddress, getDTag, getEventHash, getFilterLimit, getPublicKey, getWindowNostr, groupAuthorsByOutboxRelay, hexToBytes, isAddressableKind, isAuthRequired, isEphemeralKind, isHex32, isHex64, isInsecureRelayUrl, isNip07Available, isNostrURI, isRegularKind, isReplaceableKind, isReplaceableWinner, isTag, itemCompare, makeAuthEvent, matchFilter, matchFilters, mergeCountHll, naddrEncode, neventEncode, decode as nip19Decode, normalizeURL, noteEncode, nprofileEncode, npubEncode, nsecEncode, parseClientMessage, parseEventAddress, parseNostrURI, parseRelayList, parseRelayMessage, parseThreadTags, publicKeyFromHex, readRelays, relayListEventBuilder, relayListToTags, replyTo, serializeEvent, signEvent, signedMatchesUnsigned, sortEvents, sortedEvents, tagName, tagValue, toSecretKey, useWebSocketImplementation, validateEvent, validateSignedEvent, verifyEvent, writeRelays };
package/dist/index.mjs CHANGED
@@ -1,27 +1,27 @@
1
1
  import { D as SIGNATURE_BYTES, E as SECRET_KEY_BYTES, O as SUBSCRIPTION_ID_MAX_CHARS, T as PUBLIC_KEY_BYTES, _ as HexError, b as UrlError, c as isHex64, d as normalizeURL, g as EventValidationError, h as CryptoError, i as bytesToHex, o as hexToBytes, s as isHex32, v as MessageError, w as EVENT_ID_BYTES, x as WasmPoisonedError, y as NostrError } from "./util-DDpPkiED.mjs";
2
2
  import { a as isRegularKind, i as isEphemeralKind, n as classifyKind, o as isReplaceableKind, r as isAddressableKind, t as Kind } from "./kind-D8fENiiL.mjs";
3
3
  import { C as tagName, S as parseEventAddress, _ as eventAddress, a as isReplaceableWinner, b as getDTag, d as signedMatchesUnsigned, f as sortEvents, g as Tag, h as validateSignedEvent, l as serializeEvent, m as validateEvent, n as getEventHash, o as itemCompare, p as sortedEvents, w as tagValue, x as isTag, y as formatEventAddress } from "./event-B3ua2_oL.mjs";
4
- import { a as publicKeyFromHex, i as getPublicKey, n as SecretKey, o as signEvent, r as finalizeEvent, s as toSecretKey, t as Keys } from "./key-k8LDEPZh.mjs";
4
+ import { a as publicKeyFromHex, i as getPublicKey, n as SecretKey, o as signEvent, r as finalizeEvent, s as toSecretKey, t as Keys } from "./key-B218_SoL.mjs";
5
5
  import { n as verifyEvent, t as createEventVerifier } from "./verifier-CjH1vnP2.mjs";
6
- import { t as EventBuilder } from "./builder-BQbFDO6S.mjs";
6
+ import { t as EventBuilder } from "./builder-Cf2N12CG.mjs";
7
7
  import { a as matchFilter, i as getFilterLimit, n as canonicalizeFilters, o as matchFilters, r as filterFingerprint, t as canonicalizeFilter } from "./filter-B16P33dz.mjs";
8
8
  import { a as mergeCountHll, i as encodeRelayMessage, n as createSubscriptionId, o as parseClientMessage, r as encodeClientMessage, s as parseRelayMessage, t as assertSubscriptionId } from "./message-pYfVKxPn.mjs";
9
- import { t as NoSignerError } from "./error-UHkqzWL7.mjs";
10
- import { a as KeysSigner, i as isNip07Available, n as Nip07Signer, r as getWindowNostr, t as Nip46Signer } from "./signer-CWtxpOxc.mjs";
9
+ import { n as SignerDisposedError, t as NoSignerError } from "./error-D3VNRVhL.mjs";
10
+ import { a as KeysSigner, i as isNip07Available, n as Nip07Signer, o as DelegatedSigner, r as getWindowNostr, t as Nip46Signer } from "./signer-CNTIeYH4.mjs";
11
11
  import { Bech32MaxSize, Nip19Error, decode, naddrEncode, neventEncode, noteEncode, nprofileEncode, npubEncode, nsecEncode } from "./nips/nip19.mjs";
12
12
  import { Nip21Error, isNostrURI, parseNostrURI } from "./nips/nip21.mjs";
13
13
  import { buildReplyTags, parseThreadTags, replyTo } from "./nips/nip10.mjs";
14
14
  import { isAuthRequired, makeAuthEvent } from "./nips/nip42.mjs";
15
15
  import { parseRelayList, readRelays, relayListEventBuilder, relayListToTags, writeRelays } from "./nips/nip65.mjs";
16
- import { c as RelayConnectionError, d as RelaySuspendedError, f as RelayTimeoutError, l as RelayError, n as Relay, o as useWebSocketImplementation, r as RelayStatus, s as RelayClosedError, u as RelayPublishError } from "./relay-DXtwUEdX.mjs";
17
- import { i as isInsecureRelayUrl, t as Pool } from "./pool-BMUsw2un.mjs";
16
+ import { c as RelayConnectionError, d as RelaySuspendedError, f as RelayTimeoutError, l as RelayError, n as Relay, o as useWebSocketImplementation, r as RelayStatus, s as RelayClosedError, u as RelayPublishError } from "./relay-BGPqiGKF.mjs";
17
+ import { i as isInsecureRelayUrl, t as Pool } from "./pool-THuuOW4S.mjs";
18
18
  import "./relay.mjs";
19
19
  import { t as Gossip } from "./gossip-K_JIexQs.mjs";
20
- import { a as bareNostrUser, i as groupAuthorsByOutboxRelay, n as OutboxError, r as OutboxFeed, t as createLoaders } from "./loaders-Dp2nXEFk.mjs";
20
+ import { a as bareNostrUser, i as groupAuthorsByOutboxRelay, n as OutboxError, r as OutboxFeed, t as createLoaders } from "./loaders-Xdbx-K61.mjs";
21
21
  import { t as StorageError } from "./error-DH4guike.mjs";
22
22
  import { t as MemoryEventStore } from "./memory-VyPnOBU3.mjs";
23
23
  import { t as ReactiveEventStore } from "./reactive--pDpLt2H.mjs";
24
- import { n as ClientError, r as SyncDirection, t as Client } from "./client-CTmp5w84.mjs";
24
+ import { n as ClientError, r as SyncDirection, t as Client } from "./client-B3_vToDX.mjs";
25
25
  import { n as IndexedDbEventStore, t as SqliteEventStore } from "./storage-B5Wdt_Mn.mjs";
26
26
  import "./store.mjs";
27
- export { Bech32MaxSize, Client, ClientError, CryptoError, EVENT_ID_BYTES, EventBuilder, EventValidationError, Gossip, HexError, IndexedDbEventStore, Keys, KeysSigner, Kind, MemoryEventStore, MessageError, Nip07Signer, Nip19Error, Nip21Error, Nip46Signer, NoSignerError, NostrError, OutboxError, OutboxFeed, PUBLIC_KEY_BYTES, Pool, ReactiveEventStore, Relay, RelayClosedError, RelayConnectionError, RelayError, RelayPublishError, RelayStatus, RelaySuspendedError, RelayTimeoutError, SECRET_KEY_BYTES, SIGNATURE_BYTES, SUBSCRIPTION_ID_MAX_CHARS, SecretKey, SqliteEventStore, StorageError, SyncDirection, Tag, UrlError, WasmPoisonedError, assertSubscriptionId, bareNostrUser, buildReplyTags, bytesToHex, canonicalizeFilter, canonicalizeFilters, classifyKind, createEventVerifier, createLoaders, createSubscriptionId, encodeClientMessage, encodeRelayMessage, eventAddress, filterFingerprint, finalizeEvent, formatEventAddress, getDTag, getEventHash, getFilterLimit, getPublicKey, getWindowNostr, groupAuthorsByOutboxRelay, hexToBytes, isAddressableKind, isAuthRequired, isEphemeralKind, isHex32, isHex64, isInsecureRelayUrl, isNip07Available, isNostrURI, isRegularKind, isReplaceableKind, isReplaceableWinner, isTag, itemCompare, makeAuthEvent, matchFilter, matchFilters, mergeCountHll, naddrEncode, neventEncode, decode as nip19Decode, normalizeURL, noteEncode, nprofileEncode, npubEncode, nsecEncode, parseClientMessage, parseEventAddress, parseNostrURI, parseRelayList, parseRelayMessage, parseThreadTags, publicKeyFromHex, readRelays, relayListEventBuilder, relayListToTags, replyTo, serializeEvent, signEvent, signedMatchesUnsigned, sortEvents, sortedEvents, tagName, tagValue, toSecretKey, useWebSocketImplementation, validateEvent, validateSignedEvent, verifyEvent, writeRelays };
27
+ export { Bech32MaxSize, Client, ClientError, CryptoError, DelegatedSigner, EVENT_ID_BYTES, EventBuilder, EventValidationError, Gossip, HexError, IndexedDbEventStore, Keys, KeysSigner, Kind, MemoryEventStore, MessageError, Nip07Signer, Nip19Error, Nip21Error, Nip46Signer, NoSignerError, NostrError, OutboxError, OutboxFeed, PUBLIC_KEY_BYTES, Pool, ReactiveEventStore, Relay, RelayClosedError, RelayConnectionError, RelayError, RelayPublishError, RelayStatus, RelaySuspendedError, RelayTimeoutError, SECRET_KEY_BYTES, SIGNATURE_BYTES, SUBSCRIPTION_ID_MAX_CHARS, SecretKey, SignerDisposedError, SqliteEventStore, StorageError, SyncDirection, Tag, UrlError, WasmPoisonedError, assertSubscriptionId, bareNostrUser, buildReplyTags, bytesToHex, canonicalizeFilter, canonicalizeFilters, classifyKind, createEventVerifier, createLoaders, createSubscriptionId, encodeClientMessage, encodeRelayMessage, eventAddress, filterFingerprint, finalizeEvent, formatEventAddress, getDTag, getEventHash, getFilterLimit, getPublicKey, getWindowNostr, groupAuthorsByOutboxRelay, hexToBytes, isAddressableKind, isAuthRequired, isEphemeralKind, isHex32, isHex64, isInsecureRelayUrl, isNip07Available, isNostrURI, isRegularKind, isReplaceableKind, isReplaceableWinner, isTag, itemCompare, makeAuthEvent, matchFilter, matchFilters, mergeCountHll, naddrEncode, neventEncode, decode as nip19Decode, normalizeURL, noteEncode, nprofileEncode, npubEncode, nsecEncode, parseClientMessage, parseEventAddress, parseNostrURI, parseRelayList, parseRelayMessage, parseThreadTags, publicKeyFromHex, readRelays, relayListEventBuilder, relayListToTags, replyTo, serializeEvent, signEvent, signedMatchesUnsigned, sortEvents, sortedEvents, tagName, tagValue, toSecretKey, useWebSocketImplementation, validateEvent, validateSignedEvent, verifyEvent, writeRelays };
@@ -66,7 +66,13 @@ var Keys = class Keys {
66
66
  constructor(secretKey, backend) {
67
67
  this.secretKey = secretKey;
68
68
  this.backend = backend;
69
- const pubkey = backend.publicKey(secretKey.bytes);
69
+ const secretBytes = secretKey.bytes;
70
+ let pubkey;
71
+ try {
72
+ pubkey = backend.publicKey(secretBytes);
73
+ } finally {
74
+ secretBytes.fill(0);
75
+ }
70
76
  if (pubkey.length !== 32) throw new CryptoError("signing backend returned an invalid public key");
71
77
  this.publicKey = bytesToHex$1(pubkey);
72
78
  }
@@ -80,8 +86,15 @@ var Keys = class Keys {
80
86
  function resolveKeys(secretKey) {
81
87
  return secretKey instanceof Keys ? secretKey : Keys.fromSecretKey(secretKey);
82
88
  }
83
- /** Fill pubkey/id/sig on a template and return a signed event. */
84
- function finalizeEvent(template, secretKey) {
89
+ /**
90
+ * Fill pubkey/id/sig on a template and return a signed event.
91
+ *
92
+ * `auxRand` is the 32-byte BIP-340 auxiliary randomness. It defaults to a fresh `randomBytes(32)`
93
+ * draw; an explicit value makes the signature reproducible, which is required for vectors and
94
+ * tests. This is the counterpart of nk-core `Keys::sign_event_with_aux`. Never reuse aux randomness
95
+ * in production.
96
+ */
97
+ function finalizeEvent(template, secretKey, auxRand) {
85
98
  const keys = resolveKeys(secretKey);
86
99
  return signEvent({
87
100
  kind: template.kind,
@@ -89,14 +102,20 @@ function finalizeEvent(template, secretKey) {
89
102
  content: template.content,
90
103
  created_at: template.created_at,
91
104
  pubkey: keys.publicKey
92
- }, keys);
105
+ }, keys, auxRand);
93
106
  }
94
107
  /**
95
108
  * Sign an already-assembled unsigned event. Rejects when `unsigned.pubkey` does not match the
96
109
  * secret key.
110
+ *
111
+ * `auxRand` is the 32-byte BIP-340 auxiliary randomness. It defaults to a fresh `randomBytes(32)`
112
+ * draw; an explicit value makes the signature reproducible, which is required for vectors and
113
+ * tests. This is the counterpart of nk-core `Keys::sign_event_with_aux`. Never reuse aux randomness
114
+ * in production.
97
115
  */
98
- function signEvent(unsigned, secretKey) {
116
+ function signEvent(unsigned, secretKey, auxRand) {
99
117
  const keys = resolveKeys(secretKey);
118
+ if (auxRand !== void 0 && auxRand.length !== 32) throw new CryptoError("auxRand must be 32 bytes");
100
119
  if (!validateEvent(unsigned)) throw new EventValidationError("cannot sign invalid unsigned event");
101
120
  if (unsigned.pubkey !== keys.publicKey) throw new CryptoError("unsigned event pubkey does not match secret key");
102
121
  const normalized = {
@@ -107,7 +126,13 @@ function signEvent(unsigned, secretKey) {
107
126
  pubkey: keys.publicKey
108
127
  };
109
128
  const id = bytesToHex$1(sha256(utf8Encoder.encode(serializeValidatedEvent(normalized))));
110
- const sig = keys.backend.sign(hexToBytes$1(id), keys.secretKey.bytes, randomBytes(32));
129
+ const secretBytes = keys.secretKey.bytes;
130
+ let sig;
131
+ try {
132
+ sig = keys.backend.sign(hexToBytes$1(id), secretBytes, auxRand ?? randomBytes(32));
133
+ } finally {
134
+ secretBytes.fill(0);
135
+ }
111
136
  if (sig.length !== 64) throw new CryptoError("signing backend returned an invalid signature");
112
137
  const event = {
113
138
  ...normalized,
@@ -120,4 +145,4 @@ function signEvent(unsigned, secretKey) {
120
145
  //#endregion
121
146
  export { publicKeyFromHex as a, getPublicKey as i, SecretKey as n, signEvent as o, finalizeEvent as r, toSecretKey as s, Keys as t };
122
147
 
123
- //# sourceMappingURL=key-k8LDEPZh.mjs.map
148
+ //# sourceMappingURL=key-B218_SoL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-B218_SoL.mjs","names":["hexToBytes","bytesToHex"],"sources":["../src/core/key.ts"],"sourcesContent":["import { schnorr } from \"@noble/curves/secp256k1.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { randomBytes } from \"@noble/hashes/utils.js\";\n\nimport { CryptoError, EventValidationError } from \"./error.ts\";\nimport { markVerified, serializeValidatedEvent, validateEvent } from \"./event.ts\";\nimport type { Event, EventTemplate, UnsignedEvent } from \"./event.ts\";\nimport { assertHex32, assertSecretKeyBytes, bytesToHex, hexToBytes, utf8Encoder } 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/** Anything a secret key can be given as: instance, raw bytes, or hex. */\nexport type SecretKeyInput = SecretKey | Uint8Array | string;\n\n/** Coerce a {@link SecretKeyInput} to {@link SecretKey}. */\nexport function toSecretKey(input: SecretKeyInput): SecretKey {\n if (input instanceof SecretKey) {\n return input;\n }\n if (typeof input === \"string\") {\n return SecretKey.fromHex(input);\n }\n return SecretKey.fromBytes(input);\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/**\n * BIP-340 signing backend. `publicKey` returns the 32-byte x-only public key of a 32-byte secret\n * key; `sign` returns the 64-byte BIP-340 signature of a 32-byte `id` using 32 bytes of auxiliary\n * randomness. Both throw on invalid input (for example an out-of-range secret key).\n */\nexport type SigningBackend = {\n publicKey: (secretKey: Uint8Array) => Uint8Array;\n sign: (id: Uint8Array, secretKey: Uint8Array, auxRand: Uint8Array) => Uint8Array;\n};\n\nconst nobleSigning: SigningBackend = {\n publicKey: (secretKey) => schnorr.getPublicKey(secretKey),\n sign: (id, secretKey, auxRand) => schnorr.sign(id, secretKey, auxRand),\n};\n\n/** Derive the public key for a secret key given as SecretKey, bytes, or hex. */\nexport function getPublicKey(secretKey: SecretKeyInput): PublicKey {\n return bytesToHex(schnorr.getPublicKey(toSecretKey(secretKey).bytes));\n}\n\n/** Keypair convenience wrapper. */\nexport class Keys {\n readonly secretKey: SecretKey;\n readonly publicKey: PublicKey;\n /**\n * BIP-340 backend that derived {@link publicKey} and signs in {@link finalizeEvent}/\n * {@link signEvent}. Defaults to noble; pass a loaded `NostrWasm` module or a native backend to\n * delegate signing.\n */\n readonly backend: SigningBackend;\n\n private constructor(secretKey: SecretKey, backend: SigningBackend) {\n this.secretKey = secretKey;\n this.backend = backend;\n const secretBytes = secretKey.bytes;\n let pubkey: Uint8Array;\n try {\n pubkey = backend.publicKey(secretBytes);\n } finally {\n secretBytes.fill(0);\n }\n if (pubkey.length !== 32) {\n throw new CryptoError(\"signing backend returned an invalid public key\");\n }\n this.publicKey = bytesToHex(pubkey);\n }\n\n static generate(backend: SigningBackend = nobleSigning): Keys {\n return new Keys(SecretKey.generate(), backend);\n }\n\n static fromSecretKey(secretKey: SecretKeyInput, backend: SigningBackend = nobleSigning): Keys {\n return new Keys(toSecretKey(secretKey), backend);\n }\n}\n\nfunction resolveKeys(secretKey: SecretKeyInput | Keys): Keys {\n return secretKey instanceof Keys ? secretKey : Keys.fromSecretKey(secretKey);\n}\n\n/**\n * Fill pubkey/id/sig on a template and return a signed event.\n *\n * `auxRand` is the 32-byte BIP-340 auxiliary randomness. It defaults to a fresh `randomBytes(32)`\n * draw; an explicit value makes the signature reproducible, which is required for vectors and\n * tests. This is the counterpart of nk-core `Keys::sign_event_with_aux`. Never reuse aux randomness\n * in production.\n */\nexport function finalizeEvent(\n template: EventTemplate,\n secretKey: SecretKeyInput | Keys,\n auxRand?: Uint8Array,\n): Event {\n const keys = resolveKeys(secretKey);\n const unsigned: UnsignedEvent = {\n kind: template.kind,\n tags: template.tags,\n content: template.content,\n created_at: template.created_at,\n pubkey: keys.publicKey,\n };\n return signEvent(unsigned, keys, auxRand);\n}\n\n/**\n * Sign an already-assembled unsigned event. Rejects when `unsigned.pubkey` does not match the\n * secret key.\n *\n * `auxRand` is the 32-byte BIP-340 auxiliary randomness. It defaults to a fresh `randomBytes(32)`\n * draw; an explicit value makes the signature reproducible, which is required for vectors and\n * tests. This is the counterpart of nk-core `Keys::sign_event_with_aux`. Never reuse aux randomness\n * in production.\n */\nexport function signEvent(\n unsigned: UnsignedEvent,\n secretKey: SecretKeyInput | Keys,\n auxRand?: Uint8Array,\n): Event {\n const keys = resolveKeys(secretKey);\n if (auxRand !== undefined && auxRand.length !== 32) {\n throw new CryptoError(\"auxRand must be 32 bytes\");\n }\n if (!validateEvent(unsigned)) {\n throw new EventValidationError(\"cannot sign invalid unsigned event\");\n }\n\n if (unsigned.pubkey !== keys.publicKey) {\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: keys.publicKey,\n };\n\n const id = bytesToHex(sha256(utf8Encoder.encode(serializeValidatedEvent(normalized))));\n const secretBytes = keys.secretKey.bytes;\n let sig: Uint8Array;\n try {\n sig = keys.backend.sign(hexToBytes(id), secretBytes, auxRand ?? randomBytes(32));\n } finally {\n secretBytes.fill(0);\n }\n if (sig.length !== 64) {\n throw new CryptoError(\"signing backend returned an invalid signature\");\n }\n const event: Event = { ...normalized, id, sig: bytesToHex(sig) };\n markVerified(event);\n return event;\n}\n"],"mappings":"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"}
@@ -45,13 +45,25 @@ declare class Keys {
45
45
  static generate(backend?: SigningBackend): Keys;
46
46
  static fromSecretKey(secretKey: SecretKeyInput, backend?: SigningBackend): Keys;
47
47
  }
48
- /** Fill pubkey/id/sig on a template and return a signed event. */
49
- declare function finalizeEvent(template: EventTemplate, secretKey: SecretKeyInput | Keys): Event;
48
+ /**
49
+ * Fill pubkey/id/sig on a template and return a signed event.
50
+ *
51
+ * `auxRand` is the 32-byte BIP-340 auxiliary randomness. It defaults to a fresh `randomBytes(32)`
52
+ * draw; an explicit value makes the signature reproducible, which is required for vectors and
53
+ * tests. This is the counterpart of nk-core `Keys::sign_event_with_aux`. Never reuse aux randomness
54
+ * in production.
55
+ */
56
+ declare function finalizeEvent(template: EventTemplate, secretKey: SecretKeyInput | Keys, auxRand?: Uint8Array): Event;
50
57
  /**
51
58
  * Sign an already-assembled unsigned event. Rejects when `unsigned.pubkey` does not match the
52
59
  * secret key.
60
+ *
61
+ * `auxRand` is the 32-byte BIP-340 auxiliary randomness. It defaults to a fresh `randomBytes(32)`
62
+ * draw; an explicit value makes the signature reproducible, which is required for vectors and
63
+ * tests. This is the counterpart of nk-core `Keys::sign_event_with_aux`. Never reuse aux randomness
64
+ * in production.
53
65
  */
54
- declare function signEvent(unsigned: UnsignedEvent, secretKey: SecretKeyInput | Keys): Event;
66
+ declare function signEvent(unsigned: UnsignedEvent, secretKey: SecretKeyInput | Keys, auxRand?: Uint8Array): Event;
55
67
  //#endregion
56
68
  export { SigningBackend as a, publicKeyFromHex as c, SecretKeyInput as i, signEvent as l, PublicKey as n, finalizeEvent as o, SecretKey as r, getPublicKey as s, Keys as t, toSecretKey as u };
57
- //# sourceMappingURL=key-CyKN1RTi.d.mts.map
69
+ //# sourceMappingURL=key-CwMVo14x.d.mts.map
@@ -5,7 +5,7 @@ import { i as throwIfAborted } from "./abort-DBq2STPj.mjs";
5
5
  import { t as invokeSafely } from "./report-CHld4uWj.mjs";
6
6
  import { Nip19Error, decode, npubEncode } from "./nips/nip19.mjs";
7
7
  import { parseRelayList } from "./nips/nip65.mjs";
8
- import "./relay-DXtwUEdX.mjs";
8
+ import "./relay-BGPqiGKF.mjs";
9
9
  import { i as trimOldest, r as touchKey } from "./collections-DtwMc1NU.mjs";
10
10
  import { parseDmRelayList } from "./nips/nip17.mjs";
11
11
  import { parseMuteList } from "./nips/nip51.mjs";
@@ -780,4 +780,4 @@ function createLoaders(opts) {
780
780
  //#endregion
781
781
  export { bareNostrUser as a, groupAuthorsByOutboxRelay as i, OutboxError as n, OutboxFeed as r, createLoaders as t };
782
782
 
783
- //# sourceMappingURL=loaders-Dp2nXEFk.mjs.map
783
+ //# sourceMappingURL=loaders-Xdbx-K61.mjs.map