@qntx/nostr 0.0.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.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/builder-BphJa-Y-.d.mts +67 -0
- package/dist/builder-q0VsvnYE.mjs +158 -0
- package/dist/builder-q0VsvnYE.mjs.map +1 -0
- package/dist/client-Bd8B1mYm.mjs +835 -0
- package/dist/client-Bd8B1mYm.mjs.map +1 -0
- package/dist/client.d.mts +2 -0
- package/dist/client.mjs +2 -0
- package/dist/core.d.mts +8 -0
- package/dist/core.mjs +9 -0
- package/dist/error-B49rbDzT.d.mts +7 -0
- package/dist/error-CwBxle6N.mjs +13 -0
- package/dist/error-CwBxle6N.mjs.map +1 -0
- package/dist/error-DZEs5OuZ.mjs +24 -0
- package/dist/error-DZEs5OuZ.mjs.map +1 -0
- package/dist/error-WEFS-R-4.d.mts +20 -0
- package/dist/event-B5D2jxt_.d.mts +108 -0
- package/dist/event-CzoQEFMF.mjs +188 -0
- package/dist/event-CzoQEFMF.mjs.map +1 -0
- package/dist/filter-BxwjEkZp.mjs +113 -0
- package/dist/filter-BxwjEkZp.mjs.map +1 -0
- package/dist/filter-DUEKP3q1.d.mts +40 -0
- package/dist/gossip-3xkRRCm_.mjs +220 -0
- package/dist/gossip-3xkRRCm_.mjs.map +1 -0
- package/dist/gossip-C5RVB1UB.d.mts +71 -0
- package/dist/gossip.d.mts +3 -0
- package/dist/gossip.mjs +2 -0
- package/dist/http-6vevbBlu.d.mts +22 -0
- package/dist/http-D2rhokZo.mjs +24 -0
- package/dist/http-D2rhokZo.mjs.map +1 -0
- package/dist/index-BYMnhRIC.d.mts +161 -0
- package/dist/index-C0C4e-Gn.d.mts +55 -0
- package/dist/index-CaxrMD1A.d.mts +1 -0
- package/dist/index-DaRyjo7O.d.mts +77 -0
- package/dist/index-DgOugrpF.d.mts +275 -0
- package/dist/index-EwL6fHLo.d.mts +267 -0
- package/dist/index-k2YhCgsh.d.mts +57 -0
- package/dist/index.d.mts +22 -0
- package/dist/index.mjs +23 -0
- package/dist/key-BiGxGLhg.d.mts +37 -0
- package/dist/key-Dn-aX4x4.mjs +130 -0
- package/dist/key-Dn-aX4x4.mjs.map +1 -0
- package/dist/kind-BLl4cLOc.mjs +59 -0
- package/dist/kind-BLl4cLOc.mjs.map +1 -0
- package/dist/loaders-BNQszDAn.mjs +767 -0
- package/dist/loaders-BNQszDAn.mjs.map +1 -0
- package/dist/loaders.d.mts +3 -0
- package/dist/loaders.mjs +2 -0
- package/dist/memory-BCmhZPek.mjs +461 -0
- package/dist/memory-BCmhZPek.mjs.map +1 -0
- package/dist/message-C_Uj-Y-c.mjs +179 -0
- package/dist/message-C_Uj-Y-c.mjs.map +1 -0
- package/dist/message-DJC-Jz6T.d.mts +32 -0
- package/dist/nip17-BWq-Kfq5.d.mts +38 -0
- package/dist/nip19-D7905oIv.d.mts +63 -0
- package/dist/nip46-C_DoxiS_.d.mts +51 -0
- package/dist/nip59-DljW_sYh.d.mts +76 -0
- package/dist/nip65-Di5hZRuV.d.mts +21 -0
- package/dist/nip77-ByxlgoQO.d.mts +55 -0
- package/dist/nips/blossom.d.mts +93 -0
- package/dist/nips/blossom.mjs +325 -0
- package/dist/nips/blossom.mjs.map +1 -0
- package/dist/nips/nip04.d.mts +8 -0
- package/dist/nips/nip04.mjs +41 -0
- package/dist/nips/nip04.mjs.map +1 -0
- package/dist/nips/nip05.d.mts +89 -0
- package/dist/nips/nip05.mjs +147 -0
- package/dist/nips/nip05.mjs.map +1 -0
- package/dist/nips/nip10.d.mts +43 -0
- package/dist/nips/nip10.mjs +194 -0
- package/dist/nips/nip10.mjs.map +1 -0
- package/dist/nips/nip11.d.mts +43 -0
- package/dist/nips/nip11.mjs +99 -0
- package/dist/nips/nip11.mjs.map +1 -0
- package/dist/nips/nip13.d.mts +23 -0
- package/dist/nips/nip13.mjs +88 -0
- package/dist/nips/nip13.mjs.map +1 -0
- package/dist/nips/nip17.d.mts +2 -0
- package/dist/nips/nip17.mjs +138 -0
- package/dist/nips/nip17.mjs.map +1 -0
- package/dist/nips/nip19.d.mts +2 -0
- package/dist/nips/nip19.mjs +174 -0
- package/dist/nips/nip19.mjs.map +1 -0
- package/dist/nips/nip21.d.mts +17 -0
- package/dist/nips/nip21.mjs +29 -0
- package/dist/nips/nip21.mjs.map +1 -0
- package/dist/nips/nip27.d.mts +42 -0
- package/dist/nips/nip27.mjs +175 -0
- package/dist/nips/nip27.mjs.map +1 -0
- package/dist/nips/nip42.d.mts +12 -0
- package/dist/nips/nip42.mjs +22 -0
- package/dist/nips/nip42.mjs.map +1 -0
- package/dist/nips/nip44.d.mts +12 -0
- package/dist/nips/nip44.mjs +125 -0
- package/dist/nips/nip44.mjs.map +1 -0
- package/dist/nips/nip46.d.mts +2 -0
- package/dist/nips/nip46.mjs +132 -0
- package/dist/nips/nip46.mjs.map +1 -0
- package/dist/nips/nip49.d.mts +12 -0
- package/dist/nips/nip49.mjs +80 -0
- package/dist/nips/nip49.mjs.map +1 -0
- package/dist/nips/nip51.d.mts +88 -0
- package/dist/nips/nip51.mjs +246 -0
- package/dist/nips/nip51.mjs.map +1 -0
- package/dist/nips/nip57.d.mts +43 -0
- package/dist/nips/nip57.mjs +230 -0
- package/dist/nips/nip57.mjs.map +1 -0
- package/dist/nips/nip59.d.mts +2 -0
- package/dist/nips/nip59.mjs +171 -0
- package/dist/nips/nip59.mjs.map +1 -0
- package/dist/nips/nip65.d.mts +2 -0
- package/dist/nips/nip65.mjs +76 -0
- package/dist/nips/nip65.mjs.map +1 -0
- package/dist/nips/nip77.d.mts +2 -0
- package/dist/nips/nip77.mjs +421 -0
- package/dist/nips/nip77.mjs.map +1 -0
- package/dist/nips/nip96.d.mts +31 -0
- package/dist/nips/nip96.mjs +95 -0
- package/dist/nips/nip96.mjs.map +1 -0
- package/dist/nips/nip98.d.mts +28 -0
- package/dist/nips/nip98.mjs +91 -0
- package/dist/nips/nip98.mjs.map +1 -0
- package/dist/nostr_crypto_wasm_bg-hi5aXi5P.mjs +4 -0
- package/dist/nostr_crypto_wasm_bg.wasm +0 -0
- package/dist/pool-C_j1OmBB.mjs +1881 -0
- package/dist/pool-C_j1OmBB.mjs.map +1 -0
- package/dist/pool-DhRi7l-b.d.mts +297 -0
- package/dist/relay.d.mts +4 -0
- package/dist/relay.mjs +2 -0
- package/dist/signer-CZ6K6FUc.mjs +473 -0
- package/dist/signer-CZ6K6FUc.mjs.map +1 -0
- package/dist/signer.d.mts +3 -0
- package/dist/signer.mjs +2 -0
- package/dist/storage-DOy0iLRE.mjs +870 -0
- package/dist/storage-DOy0iLRE.mjs.map +1 -0
- package/dist/storage.d.mts +4 -0
- package/dist/storage.mjs +4 -0
- package/dist/types-BzyADqnw.d.mts +19 -0
- package/dist/types-Dn24TPFs.d.mts +43 -0
- package/dist/util-6tfLQ9JF.mjs +73 -0
- package/dist/util-6tfLQ9JF.mjs.map +1 -0
- package/dist/wasm.d.mts +19 -0
- package/dist/wasm.mjs +237 -0
- package/dist/wasm.mjs.map +1 -0
- package/package.json +204 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { n as EventTemplate, r as UnsignedEvent, t as Event } from "./event-B5D2jxt_.mjs";
|
|
2
|
+
import { r as SecretKey, t as Keys } from "./key-BiGxGLhg.mjs";
|
|
3
|
+
import { t as Filter } from "./filter-DUEKP3q1.mjs";
|
|
4
|
+
import { t as NostrSigner } from "./types-BzyADqnw.mjs";
|
|
5
|
+
import { n as BunkerPointer, r as ClientMetadata } from "./nip46-C_DoxiS_.mjs";
|
|
6
|
+
//#region src/signer/keys.d.ts
|
|
7
|
+
/** Local secret-key signer with NIP-04 (legacy) and NIP-44 support. */
|
|
8
|
+
declare class KeysSigner implements NostrSigner {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(secretKey: SecretKey | Uint8Array | string | Keys);
|
|
11
|
+
get keys(): Keys;
|
|
12
|
+
getPublicKey(): Promise<string>;
|
|
13
|
+
signEvent(unsigned: UnsignedEvent): Promise<Event>;
|
|
14
|
+
nip04Encrypt(peer: string, plaintext: string): Promise<string>;
|
|
15
|
+
nip04Decrypt(peer: string, ciphertext: string): Promise<string>;
|
|
16
|
+
nip44Encrypt(peer: string, plaintext: string): Promise<string>;
|
|
17
|
+
nip44Decrypt(peer: string, payload: string): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/signer/nip07.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* Minimal NIP-07 provider surface (browser extension `window.nostr`).
|
|
23
|
+
* @see https://github.com/nostr-protocol/nips/blob/master/07.md
|
|
24
|
+
*/
|
|
25
|
+
type WindowNostr = {
|
|
26
|
+
getPublicKey(): Promise<string>;
|
|
27
|
+
signEvent(event: EventTemplate): Promise<Event>;
|
|
28
|
+
nip04?: {
|
|
29
|
+
encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
30
|
+
decrypt(pubkey: string, ciphertext: string): Promise<string>;
|
|
31
|
+
};
|
|
32
|
+
nip44?: {
|
|
33
|
+
encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
34
|
+
decrypt(pubkey: string, ciphertext: string): Promise<string>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/** Resolve `window.nostr` / `globalThis.nostr` when present. */
|
|
38
|
+
declare function getWindowNostr(): WindowNostr | undefined;
|
|
39
|
+
/** True when a NIP-07 provider is injected in the current environment. */
|
|
40
|
+
declare function isNip07Available(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Signer backed by a NIP-07 browser extension (or any injected provider).
|
|
43
|
+
* Never holds secret keys in-process.
|
|
44
|
+
*/
|
|
45
|
+
declare class Nip07Signer implements NostrSigner {
|
|
46
|
+
#private;
|
|
47
|
+
constructor(provider?: WindowNostr);
|
|
48
|
+
getPublicKey(): Promise<string>;
|
|
49
|
+
signEvent(unsigned: UnsignedEvent): Promise<Event>;
|
|
50
|
+
nip04Encrypt(peer: string, plaintext: string): Promise<string>;
|
|
51
|
+
nip04Decrypt(peer: string, ciphertext: string): Promise<string>;
|
|
52
|
+
nip44Encrypt(peer: string, plaintext: string): Promise<string>;
|
|
53
|
+
nip44Decrypt(peer: string, payload: string): Promise<string>;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/signer/nip46.d.ts
|
|
57
|
+
/** Subscribe options used by NIP-46 transport (structural subset of Pool). */
|
|
58
|
+
type Nip46SubscribeOptions = {
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
onevent?: (event: Event) => void;
|
|
61
|
+
onclose?: (reason: string) => void;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Structural relay transport for NIP-46 RPC.
|
|
65
|
+
* Satisfied by {@link import("../relay/pool.ts").Pool}; constructed above the signer layer
|
|
66
|
+
* so `signer` never imports `relay` (ADR-0001).
|
|
67
|
+
*/
|
|
68
|
+
type Nip46Transport = {
|
|
69
|
+
subscribe(relays: string[], filters: Filter[], opts?: Nip46SubscribeOptions): {
|
|
70
|
+
close: (reason?: string) => void;
|
|
71
|
+
};
|
|
72
|
+
publish(relays: string[], event: Event): Promise<unknown>;
|
|
73
|
+
close(urls?: string[]): void;
|
|
74
|
+
};
|
|
75
|
+
type Nip46SignerOptions = {
|
|
76
|
+
/**
|
|
77
|
+
* Shared transport. When set, the signer does not close it on {@link Nip46Signer.close}.
|
|
78
|
+
*/
|
|
79
|
+
pool?: Nip46Transport;
|
|
80
|
+
/**
|
|
81
|
+
* Factory for a private transport when `pool` is omitted.
|
|
82
|
+
* Typical: `() => new Pool({ websocketImplementation, enableReconnect: true })`.
|
|
83
|
+
*/
|
|
84
|
+
createPool?: () => Nip46Transport;
|
|
85
|
+
/**
|
|
86
|
+
* Relays used when the bunker pointer has none, and merged uniquely onto a
|
|
87
|
+
* nonempty pointer (pointer first).
|
|
88
|
+
*/
|
|
89
|
+
relays?: string[];
|
|
90
|
+
/**
|
|
91
|
+
* Bunker connection secret when the pointer or bunker:// URL has none.
|
|
92
|
+
*/
|
|
93
|
+
secret?: string | null;
|
|
94
|
+
/** Local client key used to encrypt RPC (not the remote user key). */
|
|
95
|
+
clientSecretKey?: SecretKey | Uint8Array | string;
|
|
96
|
+
/** Called when bunker returns `auth_url` for a pending request. */
|
|
97
|
+
onAuthUrl?: (url: string) => void;
|
|
98
|
+
/** Per-request timeout in ms. Default 30s. */
|
|
99
|
+
timeoutMs?: number;
|
|
100
|
+
/** Requested permissions sent with `connect` (`method[:kind]` list). */
|
|
101
|
+
perms?: string[];
|
|
102
|
+
/** Client metadata sent with bunker-initiated `connect`. */
|
|
103
|
+
metadata?: ClientMetadata;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* NIP-46 remote signer (bunker / nostrconnect).
|
|
107
|
+
* Implements {@link NostrSigner}; never holds the remote user's secret key.
|
|
108
|
+
* Network I/O is injected via {@link Nip46Transport} (no relay import).
|
|
109
|
+
*/
|
|
110
|
+
declare class Nip46Signer implements NostrSigner {
|
|
111
|
+
#private;
|
|
112
|
+
private constructor();
|
|
113
|
+
get bunker(): Readonly<BunkerPointer>;
|
|
114
|
+
get clientPublicKey(): string;
|
|
115
|
+
/**
|
|
116
|
+
* Subscribe to an already-known bunker pointer. Does not send the `connect` RPC
|
|
117
|
+
* (reconnect without a new handshake).
|
|
118
|
+
* Requires `clientSecretKey` — reconnect must reuse the original client identity.
|
|
119
|
+
*/
|
|
120
|
+
static fromBunker(pointer: BunkerPointer, opts: Nip46SignerOptions & {
|
|
121
|
+
clientSecretKey: SecretKey | Uint8Array | string;
|
|
122
|
+
}): Nip46Signer;
|
|
123
|
+
/**
|
|
124
|
+
* Connect using a `bunker://` URL or pre-parsed pointer.
|
|
125
|
+
* Invalid strings throw. A NIP-05 identifier is not a bunker pointer.
|
|
126
|
+
* When both pointer and `opts.relays` are nonempty, unique `opts.relays` are appended.
|
|
127
|
+
*/
|
|
128
|
+
static connect(input: string | BunkerPointer, opts?: Nip46SignerOptions): Promise<Nip46Signer>;
|
|
129
|
+
/**
|
|
130
|
+
* Wait for a bunker to complete a client-initiated `nostrconnect://` handshake.
|
|
131
|
+
* Requires `clientSecretKey` whose pubkey matches the URI client pubkey
|
|
132
|
+
* (build the URI with {@link createNostrConnectURI} after generating keys).
|
|
133
|
+
*/
|
|
134
|
+
static fromNostrConnectURI(connectionURI: string, opts: Nip46SignerOptions & {
|
|
135
|
+
clientSecretKey: SecretKey | Uint8Array | string;
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
handshakeTimeoutMs?: number;
|
|
138
|
+
}): Promise<Nip46Signer>;
|
|
139
|
+
connectRemote(overrides?: {
|
|
140
|
+
metadata?: ClientMetadata;
|
|
141
|
+
perms?: string[];
|
|
142
|
+
}): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Ask the bunker for its preferred relay list and resubscribe when it changes.
|
|
145
|
+
* Spec result is a JSON array of URLs, or `null` when nothing changes.
|
|
146
|
+
*/
|
|
147
|
+
switchRelays(): Promise<string[] | null>;
|
|
148
|
+
/** Courtesy session teardown. Always closes the local signer afterwards. */
|
|
149
|
+
logout(): Promise<void>;
|
|
150
|
+
ping(): Promise<void>;
|
|
151
|
+
getPublicKey(): Promise<string>;
|
|
152
|
+
signEvent(unsigned: UnsignedEvent): Promise<Event>;
|
|
153
|
+
nip04Encrypt(peer: string, plaintext: string): Promise<string>;
|
|
154
|
+
nip04Decrypt(peer: string, ciphertext: string): Promise<string>;
|
|
155
|
+
nip44Encrypt(peer: string, plaintext: string): Promise<string>;
|
|
156
|
+
nip44Decrypt(peer: string, payload: string): Promise<string>;
|
|
157
|
+
close(): Promise<void>;
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
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 };
|
|
161
|
+
//# sourceMappingURL=index-BYMnhRIC.d.mts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { t as Event } from "./event-B5D2jxt_.mjs";
|
|
2
|
+
import { t as Filter } from "./filter-DUEKP3q1.mjs";
|
|
3
|
+
import { a as NostrError } from "./error-WEFS-R-4.mjs";
|
|
4
|
+
import { t as Pool } from "./pool-DhRi7l-b.mjs";
|
|
5
|
+
//#region src/relay/error.d.ts
|
|
6
|
+
declare class RelayError extends NostrError {
|
|
7
|
+
readonly url?: string;
|
|
8
|
+
constructor(message: string, url?: string);
|
|
9
|
+
}
|
|
10
|
+
declare class RelayConnectionError extends RelayError {}
|
|
11
|
+
declare class RelayPublishError extends RelayError {}
|
|
12
|
+
declare class RelayClosedError extends RelayError {}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/relay/url.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* True for `ws:` / `http:` URLs that are not `.onion`.
|
|
17
|
+
* Local-network `ws://` is still insecure; allow those via a trusted set.
|
|
18
|
+
*/
|
|
19
|
+
declare function isInsecureRelayUrl(url: string): boolean;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/relay/fan-in.d.ts
|
|
22
|
+
type RoutedJob = {
|
|
23
|
+
urls: readonly string[];
|
|
24
|
+
filters: readonly Filter[];
|
|
25
|
+
id?: string;
|
|
26
|
+
};
|
|
27
|
+
type FanInOptions = {
|
|
28
|
+
onevent?: (event: Event) => void;
|
|
29
|
+
oneose?: () => void;
|
|
30
|
+
onclose?: (reason: string) => void;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
/** Armed at fan-in only. Never forwarded to relay.subscribe. */
|
|
33
|
+
eoseTimeoutMs?: number;
|
|
34
|
+
alreadyHaveEvent?: (id: string) => boolean;
|
|
35
|
+
receivedEvent?: (id: string) => void;
|
|
36
|
+
closeOnEose?: boolean;
|
|
37
|
+
/** Optional. ensureRelay uses Pool.#opts.connectTimeoutMs when omitted. */
|
|
38
|
+
connectTimeoutMs?: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Aggregate EOSE/close across routed jobs. One `seen` set.
|
|
42
|
+
* `pending` counts URL list entries (duplicates included).
|
|
43
|
+
* `pendingEose` counts unique `jobIndex:url` keys.
|
|
44
|
+
*/
|
|
45
|
+
declare function fanIn(pool: Pool, jobs: readonly RoutedJob[], opts?: FanInOptions): {
|
|
46
|
+
close: (reason?: string) => void;
|
|
47
|
+
};
|
|
48
|
+
declare function fetchRouted(pool: Pool, jobs: readonly RoutedJob[], opts?: {
|
|
49
|
+
timeoutMs?: number;
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
connectTimeoutMs?: number;
|
|
52
|
+
}): Promise<Event[]>;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { isInsecureRelayUrl as a, RelayError as c, fetchRouted as i, RelayPublishError as l, RoutedJob as n, RelayClosedError as o, fanIn as r, RelayConnectionError as s, FanInOptions as t };
|
|
55
|
+
//# sourceMappingURL=index-C0C4e-Gn.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/core/limits.d.ts
|
|
2
|
+
/** NIP-01 event id length in bytes. */
|
|
3
|
+
declare const EVENT_ID_BYTES = 32;
|
|
4
|
+
/** BIP-340 signature length in bytes. */
|
|
5
|
+
declare const SIGNATURE_BYTES = 64;
|
|
6
|
+
/** BIP-340 public key length in bytes (x-only). */
|
|
7
|
+
declare const PUBLIC_KEY_BYTES = 32;
|
|
8
|
+
/** BIP-340 secret key length in bytes. */
|
|
9
|
+
declare const SECRET_KEY_BYTES = 32;
|
|
10
|
+
/** NIP-01 subscription id max character length. */
|
|
11
|
+
declare const SUBSCRIPTION_ID_MAX_CHARS = 64;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/core/util.d.ts
|
|
14
|
+
declare const utf8Encoder: import("node:util").TextEncoder;
|
|
15
|
+
declare const utf8Decoder: import("node:util").TextDecoder;
|
|
16
|
+
/** Lowercase hex encode. */
|
|
17
|
+
declare function bytesToHex(bytes: Uint8Array): string;
|
|
18
|
+
/** Decode lowercase or mixed-case hex to bytes. */
|
|
19
|
+
declare function hexToBytes(hex: string): Uint8Array;
|
|
20
|
+
/** True when value is a 64-char hex string (any case) — 32 bytes. */
|
|
21
|
+
declare function isHex32(value: string): boolean;
|
|
22
|
+
/** True when value is a 128-char hex string (any case) — 64 bytes. */
|
|
23
|
+
declare function isHex64(value: string): boolean;
|
|
24
|
+
declare function assertHex32(value: string, label: string): string;
|
|
25
|
+
declare function assertSecretKeyBytes(bytes: Uint8Array): void;
|
|
26
|
+
/**
|
|
27
|
+
* Normalize a relay URL to a stable form (wss preferred, no trailing slash, sorted query).
|
|
28
|
+
*/
|
|
29
|
+
declare function normalizeURL(url: string): string;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/core/kind.d.ts
|
|
32
|
+
/** NIP-01 regular: stored by relays. */
|
|
33
|
+
declare function isRegularKind(kind: number): boolean;
|
|
34
|
+
/** Replaceable: latest per (pubkey, kind) wins. */
|
|
35
|
+
declare function isReplaceableKind(kind: number): boolean;
|
|
36
|
+
/** Ephemeral: not expected to be stored. */
|
|
37
|
+
declare function isEphemeralKind(kind: number): boolean;
|
|
38
|
+
/** Addressable (parameterized replaceable): latest per (pubkey, kind, d-tag) wins. */
|
|
39
|
+
declare function isAddressableKind(kind: number): boolean;
|
|
40
|
+
type KindClassification = "regular" | "replaceable" | "ephemeral" | "addressable" | "unknown";
|
|
41
|
+
declare function classifyKind(kind: number): KindClassification;
|
|
42
|
+
/** Kind numbers used by this package. */
|
|
43
|
+
declare const Kind: {
|
|
44
|
+
readonly Metadata: 0;
|
|
45
|
+
readonly TextNote: 1;
|
|
46
|
+
readonly Contacts: 3;
|
|
47
|
+
readonly EventDeletion: 5;
|
|
48
|
+
readonly Repost: 6;
|
|
49
|
+
readonly Reaction: 7;
|
|
50
|
+
readonly Seal: 13;
|
|
51
|
+
readonly PrivateDirectMessage: 14;
|
|
52
|
+
readonly GenericRepost: 16;
|
|
53
|
+
readonly GiftWrap: 1059;
|
|
54
|
+
readonly ZapRequest: 9734;
|
|
55
|
+
readonly Zap: 9735;
|
|
56
|
+
readonly MuteList: 10000;
|
|
57
|
+
readonly PinList: 10001;
|
|
58
|
+
readonly RelayList: 10002;
|
|
59
|
+
readonly BookmarkList: 10003;
|
|
60
|
+
readonly FavoriteRelays: 10012;
|
|
61
|
+
readonly UserEmojiList: 10030;
|
|
62
|
+
readonly DirectMessageRelaysList: 10050;
|
|
63
|
+
readonly BlossomServerList: 10063;
|
|
64
|
+
readonly GiftWrapEphemeral: 21059;
|
|
65
|
+
readonly ClientAuth: 22242;
|
|
66
|
+
readonly NostrConnect: 24133;
|
|
67
|
+
readonly BlobsAuth: 24242;
|
|
68
|
+
readonly HttpAuth: 27235;
|
|
69
|
+
readonly RelaySets: 30002;
|
|
70
|
+
readonly EmojiSet: 30030;
|
|
71
|
+
readonly StarterPack: 39089;
|
|
72
|
+
};
|
|
73
|
+
type KindName = keyof typeof Kind;
|
|
74
|
+
type KnownKind = (typeof Kind)[KindName];
|
|
75
|
+
//#endregion
|
|
76
|
+
export { SUBSCRIPTION_ID_MAX_CHARS as C, SIGNATURE_BYTES as S, utf8Decoder as _, classifyKind as a, PUBLIC_KEY_BYTES as b, isRegularKind as c, assertSecretKeyBytes as d, bytesToHex as f, normalizeURL as g, isHex64 as h, KnownKind as i, isReplaceableKind as l, isHex32 as m, KindClassification as n, isAddressableKind as o, hexToBytes as p, KindName as r, isEphemeralKind as s, Kind as t, assertHex32 as u, utf8Encoder as v, SECRET_KEY_BYTES as x, EVENT_ID_BYTES as y };
|
|
77
|
+
//# sourceMappingURL=index-DaRyjo7O.d.mts.map
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { n as EventTemplate, r as UnsignedEvent, t as Event } from "./event-B5D2jxt_.mjs";
|
|
2
|
+
import { t as EventBuilder } from "./builder-BphJa-Y-.mjs";
|
|
3
|
+
import { t as Filter } from "./filter-DUEKP3q1.mjs";
|
|
4
|
+
import { t as Gossip } from "./gossip-C5RVB1UB.mjs";
|
|
5
|
+
import { a as NostrError } from "./error-WEFS-R-4.mjs";
|
|
6
|
+
import { i as PoolPublishResult, t as Pool, u as WebSocketConstructor } from "./pool-DhRi7l-b.mjs";
|
|
7
|
+
import { a as OutboxFeed, n as Loaders } from "./index-EwL6fHLo.mjs";
|
|
8
|
+
import { t as EventStore } from "./types-Dn24TPFs.mjs";
|
|
9
|
+
import { a as Rumor } from "./nip59-DljW_sYh.mjs";
|
|
10
|
+
import { i as ReplyTo, r as Recipient } from "./nip17-BWq-Kfq5.mjs";
|
|
11
|
+
import { t as NostrSigner } from "./types-BzyADqnw.mjs";
|
|
12
|
+
import { t as StorageError } from "./error-B49rbDzT.mjs";
|
|
13
|
+
//#region src/client/builder.d.ts
|
|
14
|
+
/** Fluent constructor for {@link Client}. */
|
|
15
|
+
declare class ClientBuilder {
|
|
16
|
+
#private;
|
|
17
|
+
signer(signer: NostrSigner): this;
|
|
18
|
+
relays(urls: readonly string[]): this;
|
|
19
|
+
addRelay(url: string): this;
|
|
20
|
+
websocketImplementation(impl: WebSocketConstructor): this;
|
|
21
|
+
verifyEvent(fn: (event: Event) => boolean): this;
|
|
22
|
+
connectTimeoutMs(ms: number): this;
|
|
23
|
+
publishTimeoutMs(ms: number): this;
|
|
24
|
+
automaticAuth(enabled: boolean): this;
|
|
25
|
+
enableReconnect(enabled: boolean): this;
|
|
26
|
+
enablePing(enabled: boolean): this;
|
|
27
|
+
pingIntervalMs(ms: number): this;
|
|
28
|
+
pingTimeoutMs(ms: number): this;
|
|
29
|
+
/**
|
|
30
|
+
* Local event store. Defaults to {@link MemoryEventStore}.
|
|
31
|
+
* Browser apps that want persistence must pass {@link IndexedDbEventStore} and `await open()`.
|
|
32
|
+
*/
|
|
33
|
+
storage(store: EventStore): this;
|
|
34
|
+
/** When false, Client will not auto-write events to storage. Default true. */
|
|
35
|
+
persistEvents(enabled: boolean): this;
|
|
36
|
+
gossip(gossip: Gossip): this;
|
|
37
|
+
onstorageerror(fn: (err: StorageError) => void): this;
|
|
38
|
+
build(): Client;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/client/types.d.ts
|
|
42
|
+
declare const SyncDirection: {
|
|
43
|
+
readonly Up: "up";
|
|
44
|
+
readonly Down: "down";
|
|
45
|
+
readonly Both: "both";
|
|
46
|
+
};
|
|
47
|
+
type SyncDirectionName = (typeof SyncDirection)[keyof typeof SyncDirection];
|
|
48
|
+
type SyncOptions = {
|
|
49
|
+
relays?: readonly string[];
|
|
50
|
+
direction?: SyncDirectionName;
|
|
51
|
+
/**
|
|
52
|
+
* Wall-clock deadline for the Negentropy reconciliation session
|
|
53
|
+
* (`NEG-OPEN` through `NEG-CLOSE`), in milliseconds.
|
|
54
|
+
* One clock for the whole session — not reset per `NEG-MSG`.
|
|
55
|
+
* Default: the relay `publishTimeoutMs`.
|
|
56
|
+
* Upload/download phases reuse this value as their per-call timeout.
|
|
57
|
+
*/
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
dryRun?: boolean;
|
|
61
|
+
/** When false, skip observe/storage on downloaded events. Default true. */
|
|
62
|
+
observe?: boolean;
|
|
63
|
+
};
|
|
64
|
+
type SyncSummary = {
|
|
65
|
+
local: string[];
|
|
66
|
+
remote: string[];
|
|
67
|
+
sent: string[];
|
|
68
|
+
received: string[];
|
|
69
|
+
sendFailures: Record<string, string>;
|
|
70
|
+
persistFailures: Record<string, string>;
|
|
71
|
+
};
|
|
72
|
+
type ClientOptions = {
|
|
73
|
+
signer?: NostrSigner;
|
|
74
|
+
relays?: readonly string[];
|
|
75
|
+
websocketImplementation?: WebSocketConstructor;
|
|
76
|
+
/** Injected EVENT verifier. Default is core BIP-340. */
|
|
77
|
+
verifyEvent?: (event: Event) => boolean;
|
|
78
|
+
connectTimeoutMs?: number;
|
|
79
|
+
publishTimeoutMs?: number;
|
|
80
|
+
/** When true (default if signer present), answer NIP-42 AUTH automatically. */
|
|
81
|
+
automaticAuth?: boolean;
|
|
82
|
+
/** When true (default), relays reconnect with backoff after disconnect. */
|
|
83
|
+
enableReconnect?: boolean;
|
|
84
|
+
/** Keepalive ping. Default false. */
|
|
85
|
+
enablePing?: boolean;
|
|
86
|
+
pingIntervalMs?: number;
|
|
87
|
+
pingTimeoutMs?: number;
|
|
88
|
+
gossip?: Gossip;
|
|
89
|
+
/**
|
|
90
|
+
* Local event store. Defaults to {@link MemoryEventStore}.
|
|
91
|
+
* Browser apps that want persistence must pass {@link IndexedDbEventStore} and `await open()`.
|
|
92
|
+
*/
|
|
93
|
+
storage?: EventStore;
|
|
94
|
+
/**
|
|
95
|
+
* When true (default), every ingested event is written to storage.
|
|
96
|
+
* Set false to disable automatic persistence while keeping the store for manual use.
|
|
97
|
+
*/
|
|
98
|
+
persistEvents?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Storage I/O failures: live `putMany` flush and `fetchEvents({ localFirst: true })` query.
|
|
101
|
+
* Those paths do not throw.
|
|
102
|
+
*/
|
|
103
|
+
onstorageerror?: (err: StorageError) => void;
|
|
104
|
+
};
|
|
105
|
+
type FetchEventsOptions = {
|
|
106
|
+
relays?: string[];
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
signal?: AbortSignal;
|
|
109
|
+
gossip?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* When true, query local storage first and merge with network results.
|
|
112
|
+
* Defaults to false.
|
|
113
|
+
*/
|
|
114
|
+
localFirst?: boolean;
|
|
115
|
+
/** When false, skip writing fetched events to storage/observe. Default true. */
|
|
116
|
+
observe?: boolean;
|
|
117
|
+
};
|
|
118
|
+
type SubscribeOptions = {
|
|
119
|
+
relays?: string[];
|
|
120
|
+
onevent?: (event: Event) => void;
|
|
121
|
+
oneose?: () => void;
|
|
122
|
+
onclose?: (reason: string) => void;
|
|
123
|
+
signal?: AbortSignal;
|
|
124
|
+
id?: string;
|
|
125
|
+
/**
|
|
126
|
+
* If set, fire `oneose` once after this many ms if not all relays have EOSEd.
|
|
127
|
+
* Does not close the subscription.
|
|
128
|
+
*/
|
|
129
|
+
eoseTimeoutMs?: number;
|
|
130
|
+
/** Fan out REQs via NIP-65 gossip routes when available. */
|
|
131
|
+
gossip?: boolean;
|
|
132
|
+
/** When false, skip writing received events to storage/observe. Default true. */
|
|
133
|
+
observe?: boolean;
|
|
134
|
+
};
|
|
135
|
+
type PublishOptions = {
|
|
136
|
+
relays?: string[];
|
|
137
|
+
timeoutMs?: number;
|
|
138
|
+
gossip?: boolean;
|
|
139
|
+
/** When false, skip writing the published event to storage/observe. Default true. */
|
|
140
|
+
observe?: boolean;
|
|
141
|
+
};
|
|
142
|
+
type SendPrivateMessageOptions = {
|
|
143
|
+
readonly subject?: string;
|
|
144
|
+
readonly replyTo?: ReplyTo;
|
|
145
|
+
readonly created_at?: number;
|
|
146
|
+
readonly timeoutMs?: number;
|
|
147
|
+
readonly observe?: boolean;
|
|
148
|
+
};
|
|
149
|
+
type PrivateMessageSendResult = {
|
|
150
|
+
rumor: Rumor;
|
|
151
|
+
wraps: ReadonlyArray<{
|
|
152
|
+
recipient: string;
|
|
153
|
+
wrap: Event;
|
|
154
|
+
results: PoolPublishResult[];
|
|
155
|
+
}>;
|
|
156
|
+
};
|
|
157
|
+
type ReceivedPrivateMessage = {
|
|
158
|
+
wrap: Event;
|
|
159
|
+
rumor: Rumor;
|
|
160
|
+
};
|
|
161
|
+
type FetchPrivateMessagesOptions = {
|
|
162
|
+
readonly since?: number;
|
|
163
|
+
readonly until?: number;
|
|
164
|
+
readonly timeoutMs?: number;
|
|
165
|
+
readonly signal?: AbortSignal;
|
|
166
|
+
readonly observe?: boolean;
|
|
167
|
+
};
|
|
168
|
+
type SubscribePrivateMessagesOptions = {
|
|
169
|
+
readonly since?: number;
|
|
170
|
+
readonly onevent?: (msg: ReceivedPrivateMessage) => void;
|
|
171
|
+
readonly oneose?: () => void;
|
|
172
|
+
readonly onclose?: (reason: string) => void;
|
|
173
|
+
readonly signal?: AbortSignal;
|
|
174
|
+
readonly eoseTimeoutMs?: number;
|
|
175
|
+
readonly observe?: boolean;
|
|
176
|
+
};
|
|
177
|
+
/** Client lifecycle, configuration, or abort failure (not cryptographic). */
|
|
178
|
+
declare class ClientError extends NostrError {}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/client/client.d.ts
|
|
181
|
+
/**
|
|
182
|
+
* Layer-5 facade: signer + default relays + pool + loaders + gossip + event store.
|
|
183
|
+
*/
|
|
184
|
+
declare class Client {
|
|
185
|
+
#private;
|
|
186
|
+
readonly pool: Pool;
|
|
187
|
+
readonly loaders: Loaders;
|
|
188
|
+
readonly gossip: Gossip;
|
|
189
|
+
readonly storage: EventStore;
|
|
190
|
+
onstorageerror: ((err: StorageError) => void) | null;
|
|
191
|
+
constructor(opts?: ClientOptions);
|
|
192
|
+
static builder(): ClientBuilder;
|
|
193
|
+
get signer(): NostrSigner | undefined;
|
|
194
|
+
get relays(): readonly string[];
|
|
195
|
+
get isShutdown(): boolean;
|
|
196
|
+
setSigner(signer: NostrSigner): void;
|
|
197
|
+
addRelay(url: string): void;
|
|
198
|
+
removeRelay(url: string): void;
|
|
199
|
+
/** Connect all configured relays (best-effort; failures are ignored). */
|
|
200
|
+
connect(opts?: {
|
|
201
|
+
signal?: AbortSignal;
|
|
202
|
+
}): Promise<void>;
|
|
203
|
+
shutdown(): Promise<void>;
|
|
204
|
+
/**
|
|
205
|
+
* Unified ingest pipeline: gossip + replaceable loader cache immediately;
|
|
206
|
+
* storage writes are coalesced into a single-flight `putMany`.
|
|
207
|
+
*/
|
|
208
|
+
observe(event: Event): void;
|
|
209
|
+
/** Observe many events (deduped by id, order preserved) as one persist batch. */
|
|
210
|
+
observeAll(events: readonly Event[]): void;
|
|
211
|
+
/**
|
|
212
|
+
* Explicitly load kind:10002 and kind:10050 lists for pubkeys and feed gossip.
|
|
213
|
+
* Does not background-fetch unknown authors on every subscribe (predictable DX).
|
|
214
|
+
*/
|
|
215
|
+
hydrateGossip(pubkeys: readonly string[], opts?: {
|
|
216
|
+
hints?: string[];
|
|
217
|
+
force?: boolean;
|
|
218
|
+
}): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Create an outbox-model feed for the given authors (NIP-65 write relays).
|
|
221
|
+
* Live events go through {@link observe}; sync persists via applySync.
|
|
222
|
+
*/
|
|
223
|
+
outbox(opts: {
|
|
224
|
+
authors: readonly string[];
|
|
225
|
+
kinds?: readonly number[];
|
|
226
|
+
onEvent?: (event: Event) => void;
|
|
227
|
+
maxRelaysPerAuthor?: number;
|
|
228
|
+
}): OutboxFeed;
|
|
229
|
+
getPublicKey(): Promise<string>;
|
|
230
|
+
signEvent(unsigned: UnsignedEvent): Promise<Event>;
|
|
231
|
+
signEventBuilder(builder: EventBuilder): Promise<Event>;
|
|
232
|
+
signTemplate(template: EventTemplate): Promise<Event>;
|
|
233
|
+
/**
|
|
234
|
+
* Sign (if builder) and publish to relays.
|
|
235
|
+
* With `gossip: true`, prefers the author's NIP-65 outbox relays, tagged `p`
|
|
236
|
+
* inboxes, and up to 5 `e`/`a` tag relay hints when known.
|
|
237
|
+
* On any successful OK, observes the event into storage/gossip.
|
|
238
|
+
*/
|
|
239
|
+
publish(eventOrBuilder: Event | EventBuilder, opts?: PublishOptions): Promise<PoolPublishResult[]>;
|
|
240
|
+
/**
|
|
241
|
+
* Fetch events. With `gossip: true`, routes filters by NIP-65 when possible.
|
|
242
|
+
* With `localFirst: true`, merges storage hits with network results.
|
|
243
|
+
*/
|
|
244
|
+
fetchEvents(filter: Filter | Filter[], opts?: FetchEventsOptions): Promise<Event[]>;
|
|
245
|
+
/**
|
|
246
|
+
* Query local storage only (no network).
|
|
247
|
+
*/
|
|
248
|
+
queryLocal(filter: Filter | Filter[]): Promise<Event[]>;
|
|
249
|
+
subscribe(filter: Filter | Filter[], opts?: SubscribeOptions): {
|
|
250
|
+
close: (reason?: string) => void;
|
|
251
|
+
};
|
|
252
|
+
/** Publish a kind:10050 NIP-17 DM relay list (`relay` tags). Not kind 10002. */
|
|
253
|
+
setDmRelays(relays: readonly string[], opts?: PublishOptions): Promise<PoolPublishResult[]>;
|
|
254
|
+
sendPrivateMessage(recipients: string | Recipient | readonly (string | Recipient)[], content: string, opts?: SendPrivateMessageOptions): Promise<PrivateMessageSendResult>;
|
|
255
|
+
fetchPrivateMessages(opts?: FetchPrivateMessagesOptions): Promise<ReceivedPrivateMessage[]>;
|
|
256
|
+
subscribePrivateMessages(opts?: SubscribePrivateMessagesOptions): Promise<{
|
|
257
|
+
close: (reason?: string) => void;
|
|
258
|
+
}>;
|
|
259
|
+
/**
|
|
260
|
+
* NIP-77 sync against one relay: reconcile, then optionally upload
|
|
261
|
+
* local-only events and/or download remote-only events.
|
|
262
|
+
* `observe: false` skips putMany and ingestMeta; received ids are still listed.
|
|
263
|
+
* `persistEvents: false` skips putMany, still ingestMeta when observe is on.
|
|
264
|
+
*/
|
|
265
|
+
syncToRelay(url: string, filter: Filter, opts?: Omit<SyncOptions, "relays">): Promise<SyncSummary>;
|
|
266
|
+
/**
|
|
267
|
+
* NIP-77 sync against the given relays (or Client default relays).
|
|
268
|
+
* Independent sessions run in parallel. Fulfilled summaries are merged;
|
|
269
|
+
* if every relay rejects, throws the first rejection in URL order.
|
|
270
|
+
*/
|
|
271
|
+
sync(filter: Filter, opts?: SyncOptions): Promise<SyncSummary>;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { FetchPrivateMessagesOptions as a, ReceivedPrivateMessage as c, SubscribePrivateMessagesOptions as d, SyncDirection as f, ClientBuilder as g, SyncSummary as h, FetchEventsOptions as i, SendPrivateMessageOptions as l, SyncOptions as m, ClientError as n, PrivateMessageSendResult as o, SyncDirectionName as p, ClientOptions as r, PublishOptions as s, Client as t, SubscribeOptions as u };
|
|
275
|
+
//# sourceMappingURL=index-DgOugrpF.d.mts.map
|