chirli 0.0.0-stage → 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.
Files changed (97) hide show
  1. package/ARCHITECTURE.md +103 -0
  2. package/CONTRIBUTING.md +56 -0
  3. package/LICENSE +22 -0
  4. package/README.md +281 -2
  5. package/SECURITY.md +55 -0
  6. package/THIRD_PARTY_NOTICES.md +51 -0
  7. package/dist/allowlist.d.ts +3 -0
  8. package/dist/allowlist.js +9 -0
  9. package/dist/announcements.d.ts +25 -0
  10. package/dist/announcements.js +142 -0
  11. package/dist/attachments.d.ts +43 -0
  12. package/dist/attachments.js +340 -0
  13. package/dist/blossom.d.ts +30 -0
  14. package/dist/blossom.js +233 -0
  15. package/dist/bot-handlers.d.ts +70 -0
  16. package/dist/bot-handlers.js +317 -0
  17. package/dist/bot.d.ts +63 -0
  18. package/dist/bot.js +244 -0
  19. package/dist/client.d.ts +221 -0
  20. package/dist/client.js +1197 -0
  21. package/dist/command-discovery.d.ts +4 -0
  22. package/dist/command-discovery.js +33 -0
  23. package/dist/command-schema.d.ts +4 -0
  24. package/dist/command-schema.js +101 -0
  25. package/dist/commands.d.ts +32 -0
  26. package/dist/commands.js +253 -0
  27. package/dist/defaults.d.ts +9 -0
  28. package/dist/defaults.js +22 -0
  29. package/dist/errors.d.ts +55 -0
  30. package/dist/errors.js +126 -0
  31. package/dist/inbox.d.ts +55 -0
  32. package/dist/inbox.js +376 -0
  33. package/dist/index.d.ts +25 -0
  34. package/dist/index.js +11 -0
  35. package/dist/key-sync.d.ts +33 -0
  36. package/dist/key-sync.js +293 -0
  37. package/dist/keys.d.ts +66 -0
  38. package/dist/keys.js +418 -0
  39. package/dist/message-storage-sqlite.d.ts +6 -0
  40. package/dist/message-storage-sqlite.js +90 -0
  41. package/dist/message-storage.d.ts +32 -0
  42. package/dist/message-storage.js +1 -0
  43. package/dist/messaging-metadata.d.ts +48 -0
  44. package/dist/messaging-metadata.js +280 -0
  45. package/dist/metadata.d.ts +7 -0
  46. package/dist/metadata.js +63 -0
  47. package/dist/modes.d.ts +26 -0
  48. package/dist/modes.js +108 -0
  49. package/dist/nip4e-compat.d.ts +4 -0
  50. package/dist/nip4e-compat.js +14 -0
  51. package/dist/nipcd.d.ts +109 -0
  52. package/dist/nipcd.js +555 -0
  53. package/dist/protocol.d.ts +68 -0
  54. package/dist/protocol.js +302 -0
  55. package/dist/public-inbox.d.ts +66 -0
  56. package/dist/public-inbox.js +295 -0
  57. package/dist/public-thread.d.ts +62 -0
  58. package/dist/public-thread.js +436 -0
  59. package/dist/relay-pool.d.ts +43 -0
  60. package/dist/relay-pool.js +429 -0
  61. package/dist/relay-roles.d.ts +18 -0
  62. package/dist/relay-roles.js +55 -0
  63. package/dist/relay.d.ts +52 -0
  64. package/dist/relay.js +493 -0
  65. package/dist/request-timing.d.ts +12 -0
  66. package/dist/request-timing.js +37 -0
  67. package/dist/session.d.ts +16 -0
  68. package/dist/session.js +51 -0
  69. package/dist/signer.d.ts +13 -0
  70. package/dist/signer.js +1 -0
  71. package/dist/signers/bunker-relays.d.ts +15 -0
  72. package/dist/signers/bunker-relays.js +87 -0
  73. package/dist/signers/bunker.d.ts +7 -0
  74. package/dist/signers/bunker.js +194 -0
  75. package/dist/signers/nsec.d.ts +3 -0
  76. package/dist/signers/nsec.js +62 -0
  77. package/dist/signers.d.ts +18 -0
  78. package/dist/signers.js +59 -0
  79. package/dist/storage-sqlite.d.ts +29 -0
  80. package/dist/storage-sqlite.js +221 -0
  81. package/dist/storage.d.ts +85 -0
  82. package/dist/storage.js +1 -0
  83. package/dist/store.d.ts +96 -0
  84. package/dist/store.js +404 -0
  85. package/docs/ACCESS.md +28 -0
  86. package/docs/API.md +382 -0
  87. package/docs/INTEROPERABILITY.md +32 -0
  88. package/docs/KEYS.md +75 -0
  89. package/docs/NIP-CD.md +112 -0
  90. package/docs/PUBLIC.md +88 -0
  91. package/docs/RECOVERY.md +59 -0
  92. package/docs/RELAYS.md +145 -0
  93. package/docs/SESSIONS.md +108 -0
  94. package/docs/SIGNERS.md +59 -0
  95. package/docs/STORAGE.md +71 -0
  96. package/docs/TUTORIAL.md +178 -0
  97. package/package.json +47 -4
@@ -0,0 +1,55 @@
1
+ import { type Event, type Filter } from "nostr-tools";
2
+ import { type Subscription, type Transport } from "./relay.js";
3
+ import type { Store } from "./store.js";
4
+ export interface ReconnectOptions {
5
+ initialDelayMs?: number;
6
+ maxDelayMs?: number;
7
+ jitter?: number;
8
+ stableResetMs?: number;
9
+ }
10
+ export interface RecoveryOptions {
11
+ pageSize?: number;
12
+ maxPages?: number;
13
+ overlapSeconds?: number;
14
+ }
15
+ export interface HistorySyncResult {
16
+ relay: string;
17
+ coverage: "window";
18
+ since: number;
19
+ until: number;
20
+ pages: number;
21
+ status: "window-complete" | "incomplete" | "aborted" | "disabled";
22
+ reason?: "page-limit" | "boundary-overflow" | "query-failed";
23
+ }
24
+ /** Headless per-relay demand, generation cancellation and fixed-window catch-up. */
25
+ export declare class InboxSubscription implements Subscription {
26
+ private options;
27
+ readonly ready: Promise<void>;
28
+ private closed;
29
+ private replicas;
30
+ private retry?;
31
+ private recovery?;
32
+ constructor(options: {
33
+ transport: Transport;
34
+ store: Store;
35
+ relays: string[];
36
+ filter: Filter;
37
+ reconnect?: false | ReconnectOptions;
38
+ recovery?: false | RecoveryOptions;
39
+ /** Activation date in seconds is the baseline until this relay completes a pass. */
40
+ recoveryBaseline?: number;
41
+ localReadWindow?: boolean;
42
+ receive(event: Event, source: "live" | "history", relay: string): void | Promise<void>;
43
+ error(error: unknown): void;
44
+ reconnected(): Promise<void>;
45
+ });
46
+ /** An unfailed owned subscription, not physical connection success or historical EOSE. */
47
+ hasUsableSubscription(): boolean;
48
+ private current;
49
+ private connect;
50
+ private recover;
51
+ private result;
52
+ private scan;
53
+ sync(): Promise<HistorySyncResult[]>;
54
+ close(): void;
55
+ }
package/dist/inbox.js ADDED
@@ -0,0 +1,376 @@
1
+ import { RelayError } from "./errors.js";
2
+ import { verifyEvent } from "nostr-tools";
3
+ import { physicalConnectionState, subscribeInbox, } from "./relay.js";
4
+ import { validTimestamp } from "./protocol.js";
5
+ function integer(value, name, min, max) {
6
+ if (!Number.isSafeInteger(value) || value < min || value > max) {
7
+ throw new TypeError(`${name} must be an integer in ${min}..${max}`);
8
+ }
9
+ return value;
10
+ }
11
+ /** Headless per-relay demand, generation cancellation and fixed-window catch-up. */
12
+ export class InboxSubscription {
13
+ options;
14
+ ready;
15
+ closed = false;
16
+ replicas = [];
17
+ retry;
18
+ recovery;
19
+ constructor(options) {
20
+ this.options = options;
21
+ if (options.reconnect !== false) {
22
+ const initial = integer(options.reconnect?.initialDelayMs ?? 1000, "initialDelayMs", 1, 60000);
23
+ const max = integer(options.reconnect?.maxDelayMs ?? 60000, "maxDelayMs", initial, 3600000);
24
+ const jitter = options.reconnect?.jitter ?? 0.2;
25
+ if (!Number.isFinite(jitter) || jitter < 0 || jitter > 1) {
26
+ throw new TypeError("jitter must be in 0..1");
27
+ }
28
+ this.retry = {
29
+ initial,
30
+ max,
31
+ jitter,
32
+ stepped: options.reconnect?.initialDelayMs === undefined,
33
+ stableReset: integer(options.reconnect?.stableResetMs ?? 30000, "stableResetMs", 1, 3600000),
34
+ };
35
+ }
36
+ if (options.recovery !== false) {
37
+ this.recovery = {
38
+ pageSize: integer(options.recovery?.pageSize ?? 500, "pageSize", 1, 1000),
39
+ maxPages: integer(options.recovery?.maxPages ?? 20, "maxPages", 1, 1000),
40
+ overlap: integer(options.recovery?.overlapSeconds ?? 176400, "overlapSeconds", 172800, 31536000),
41
+ };
42
+ }
43
+ for (const url of new Set(options.relays)) {
44
+ let resolve, reject;
45
+ const initial = new Promise((yes, no) => {
46
+ resolve = yes;
47
+ reject = no;
48
+ });
49
+ this.replicas.push({
50
+ url,
51
+ failures: 0,
52
+ connectedBefore: false,
53
+ initial,
54
+ resolve,
55
+ reject,
56
+ });
57
+ }
58
+ this.ready = (this.replicas.length === 1
59
+ ? this.replicas[0].initial
60
+ : Promise.any(this.replicas.map((replica) => replica.initial))).then(() => { });
61
+ for (const replica of this.replicas) {
62
+ this.connect(replica);
63
+ }
64
+ }
65
+ /** An unfailed owned subscription, not physical connection success or historical EOSE. */
66
+ hasUsableSubscription() {
67
+ return (!this.closed &&
68
+ this.replicas.some((replica) => replica.attempt?.subscription !== undefined &&
69
+ physicalConnectionState(this.options.transport, replica.url) !==
70
+ false));
71
+ }
72
+ current(replica, attempt) {
73
+ return !this.closed && replica.attempt === attempt;
74
+ }
75
+ connect(replica) {
76
+ if (this.closed) {
77
+ return;
78
+ }
79
+ let cancel;
80
+ const attempt = {
81
+ canceled: new Promise((resolve) => {
82
+ cancel = resolve;
83
+ }),
84
+ cancel: () => cancel(),
85
+ };
86
+ replica.attempt = attempt;
87
+ const reconnecting = replica.connectedBefore || replica.failures > 0;
88
+ const fail = (error) => {
89
+ if (!this.current(replica, attempt)) {
90
+ return;
91
+ }
92
+ replica.attempt = undefined;
93
+ clearTimeout(replica.stable);
94
+ replica.stable = undefined;
95
+ attempt.cancel();
96
+ attempt.subscription?.close();
97
+ attempt.query?.close();
98
+ const diagnostic = error instanceof RelayError
99
+ ? error
100
+ : new RelayError("Relay subscription failed", {
101
+ relay: replica.url,
102
+ operation: "subscribe",
103
+ code: "RELAY_SUBSCRIPTION_FAILED",
104
+ });
105
+ // Established connections get a grace period for automatic network recovery.
106
+ const transient = new Set([
107
+ "RELAY_CONNECTION_FAILED",
108
+ "RELAY_CONNECT_TIMEOUT",
109
+ "RELAY_EOSE_TIMEOUT",
110
+ "RELAY_CLOSED",
111
+ "RELAY_SUBSCRIPTION_FAILED",
112
+ ]);
113
+ if (this.retry &&
114
+ replica.connectedBefore &&
115
+ transient.has(diagnostic.code)) {
116
+ replica.outageError = diagnostic;
117
+ if (!replica.outageTimer && !replica.outageReported) {
118
+ replica.outageTimer = setTimeout(() => {
119
+ replica.outageTimer = undefined;
120
+ if (!this.closed && replica.outageError) {
121
+ replica.outageReported = true;
122
+ this.options.error(replica.outageError);
123
+ }
124
+ }, 30000);
125
+ }
126
+ }
127
+ else {
128
+ this.options.error(diagnostic);
129
+ }
130
+ if (!replica.connectedBefore) {
131
+ replica.reject(error);
132
+ }
133
+ if (!this.retry) {
134
+ replica.reject(error);
135
+ return;
136
+ }
137
+ const steps = [1000, 2000, 5000, 10000, 20000, 30000, 60000];
138
+ const attemptIndex = replica.failures++;
139
+ const base = Math.min(this.retry.max, this.retry.stepped
140
+ ? steps[Math.min(attemptIndex, steps.length - 1)]
141
+ : this.retry.initial * 2 ** Math.min(attemptIndex, 30));
142
+ const delay = Math.min(this.retry.max, Math.max(1, Math.round(base *
143
+ (1 - this.retry.jitter + Math.random() * this.retry.jitter * 2))));
144
+ replica.retry = setTimeout(() => {
145
+ replica.retry = undefined;
146
+ this.connect(replica);
147
+ }, delay);
148
+ };
149
+ try {
150
+ const subscription = (this.options.localReadWindow
151
+ ? subscribeInbox.bind(undefined, this.options.transport)
152
+ : this.options.transport.subscribe.bind(this.options.transport))([replica.url], this.options.filter, (event, source) => {
153
+ if (this.current(replica, attempt)) {
154
+ void Promise.resolve(this.options.receive(event, source, replica.url)).catch((error) => this.options.error(error));
155
+ }
156
+ }, fail);
157
+ attempt.subscription = subscription;
158
+ if (!this.current(replica, attempt)) {
159
+ subscription.close();
160
+ return;
161
+ }
162
+ void subscription.ready
163
+ .then(async () => {
164
+ if (!this.current(replica, attempt)) {
165
+ return;
166
+ }
167
+ replica.connectedBefore = true;
168
+ // A brief EOSE followed by another drop must not restart a tight retry loop.
169
+ if (this.retry) {
170
+ replica.stable = setTimeout(() => {
171
+ replica.stable = undefined;
172
+ if (this.current(replica, attempt)) {
173
+ replica.failures = 0;
174
+ }
175
+ }, this.retry.stableReset);
176
+ }
177
+ await this.recover(replica, attempt);
178
+ if (!this.current(replica, attempt)) {
179
+ return;
180
+ }
181
+ clearTimeout(replica.outageTimer);
182
+ replica.outageTimer = undefined;
183
+ replica.outageError = undefined;
184
+ replica.outageReported = false;
185
+ replica.resolve();
186
+ if (reconnecting) {
187
+ void this.options
188
+ .reconnected()
189
+ .catch((error) => this.options.error(error));
190
+ }
191
+ })
192
+ .catch(fail);
193
+ }
194
+ catch (error) {
195
+ fail(error);
196
+ }
197
+ }
198
+ recover(replica, attempt) {
199
+ if (replica.recovering && replica.recoveringAttempt === attempt) {
200
+ return replica.recovering;
201
+ }
202
+ if (replica.recovering) {
203
+ return replica.recovering.then(() => {
204
+ if (!this.current(replica, attempt)) {
205
+ return this.result(replica.url, "aborted");
206
+ }
207
+ return this.recover(replica, attempt);
208
+ });
209
+ }
210
+ const task = this.scan(replica, attempt).finally(() => {
211
+ if (replica.recovering === task) {
212
+ replica.recovering = undefined;
213
+ }
214
+ });
215
+ replica.recovering = task;
216
+ replica.recoveringAttempt = attempt;
217
+ return task;
218
+ }
219
+ result(relay, status) {
220
+ return {
221
+ relay,
222
+ coverage: "window",
223
+ since: 0,
224
+ until: 0,
225
+ pages: 0,
226
+ status,
227
+ };
228
+ }
229
+ async scan(replica, attempt) {
230
+ const config = this.recovery;
231
+ if (!config) {
232
+ return this.result(replica.url, "disabled");
233
+ }
234
+ const through = Math.floor(Date.now() / 1000);
235
+ const since = Math.max(0, Math.min(this.options.store.checkpoint(replica.url) ??
236
+ this.options.recoveryBaseline ??
237
+ through, through) - config.overlap);
238
+ let until = through;
239
+ const result = {
240
+ relay: replica.url,
241
+ coverage: "window",
242
+ since,
243
+ until: through,
244
+ pages: 0,
245
+ status: "incomplete",
246
+ };
247
+ const incomplete = (reason) => {
248
+ result.reason = reason;
249
+ this.options.error(new RelayError(`Inbox history recovery incomplete (${reason}); checkpoint unchanged`, {
250
+ relay: replica.url,
251
+ operation: "history",
252
+ code: "RELAY_HISTORY_INCOMPLETE",
253
+ historyReason: reason,
254
+ }));
255
+ return result;
256
+ };
257
+ try {
258
+ while (this.current(replica, attempt) && result.pages < config.maxPages) {
259
+ const events = [];
260
+ const sub = this.options.transport.subscribe([replica.url], {
261
+ ...this.options.filter,
262
+ since,
263
+ until,
264
+ limit: config.pageSize,
265
+ }, (event, source) => {
266
+ if (source === "history" && this.current(replica, attempt)) {
267
+ events.push(event);
268
+ }
269
+ });
270
+ attempt.query = sub;
271
+ try {
272
+ await Promise.race([sub.ready, attempt.canceled]);
273
+ }
274
+ finally {
275
+ sub.close();
276
+ if (attempt.query === sub) {
277
+ attempt.query = undefined;
278
+ }
279
+ }
280
+ if (!this.current(replica, attempt)) {
281
+ return {
282
+ ...result,
283
+ status: "aborted",
284
+ };
285
+ }
286
+ const page = [
287
+ ...new Map(events
288
+ .filter((event) => {
289
+ try {
290
+ return (event.kind === 1059 &&
291
+ validTimestamp(event.created_at) &&
292
+ event.created_at >= since &&
293
+ event.created_at <= until &&
294
+ event.tags.some((tag) => tag[0] === "p" &&
295
+ tag[1] === this.options.filter["#p"]?.[0]) &&
296
+ verifyEvent(JSON.parse(JSON.stringify(event))));
297
+ }
298
+ catch {
299
+ return false;
300
+ }
301
+ })
302
+ .map((event) => [event.id, event])).values(),
303
+ ].sort((a, b) => b.created_at - a.created_at || a.id.localeCompare(b.id));
304
+ result.pages++;
305
+ for (const event of page) {
306
+ if (!this.current(replica, attempt)) {
307
+ return {
308
+ ...result,
309
+ status: "aborted",
310
+ };
311
+ }
312
+ await this.options.receive(event, "history", replica.url);
313
+ }
314
+ if (!this.current(replica, attempt)) {
315
+ return {
316
+ ...result,
317
+ status: "aborted",
318
+ };
319
+ }
320
+ if (page.length < config.pageSize) {
321
+ this.options.store.saveCheckpoint(replica.url, through);
322
+ return {
323
+ ...result,
324
+ status: "window-complete",
325
+ };
326
+ }
327
+ const oldest = page.at(-1)?.created_at;
328
+ if (oldest === undefined || oldest >= until) {
329
+ return incomplete("boundary-overflow");
330
+ }
331
+ until = oldest; // Inclusive boundary: re-read it before moving to an earlier second.
332
+ await new Promise((resolve) => setTimeout(resolve, 0)); // Yield between bounded crypto/SQLite pages.
333
+ }
334
+ return this.current(replica, attempt)
335
+ ? incomplete("page-limit")
336
+ : {
337
+ ...result,
338
+ status: "aborted",
339
+ };
340
+ }
341
+ catch (error) {
342
+ if (!this.current(replica, attempt)) {
343
+ return {
344
+ ...result,
345
+ status: "aborted",
346
+ };
347
+ }
348
+ this.options.error(error);
349
+ return incomplete("query-failed");
350
+ }
351
+ }
352
+ async sync() {
353
+ await this.ready;
354
+ return Promise.all(this.replicas.map((replica) => replica.attempt
355
+ ? this.recover(replica, replica.attempt)
356
+ : this.result(replica.url, "aborted")));
357
+ }
358
+ close() {
359
+ if (this.closed) {
360
+ return;
361
+ }
362
+ this.closed = true;
363
+ for (const replica of this.replicas) {
364
+ clearTimeout(replica.retry);
365
+ clearTimeout(replica.outageTimer);
366
+ clearTimeout(replica.stable);
367
+ replica.attempt?.cancel();
368
+ replica.attempt?.subscription?.close();
369
+ replica.attempt?.query?.close();
370
+ replica.attempt = undefined;
371
+ clearTimeout(replica.stable);
372
+ replica.stable = undefined;
373
+ replica.resolve();
374
+ }
375
+ }
376
+ }
@@ -0,0 +1,25 @@
1
+ export type { FileAttachment, FileDownloadError, FileDownloadErrorCode, FileDownloadResult, } from "./attachments.js";
2
+ export type { ReplyFileOptions, SendFileOptions, UploadFileOptions, UploadFileResult, } from "./blossom.js";
3
+ export type { MessageObserver, ErrorHandler, IntakeMetadata, SendOptions, SendResult, } from "./client.js";
4
+ export { Bot, type Context, type CommandContext, type MessageHandler, type Middleware, type Next, type BotCommandOptions, type CommandHandler, type BotOptions, type Session, type SessionStore, } from "./bot.js";
5
+ export { generateSecretKey, getPublicKey, type Rumor } from "./protocol.js";
6
+ export { WebSocketTransport, DEFAULT_RELAY_TIMEOUTS, type RelayTimeouts, type WebSocketTransportOptions, type Transport, type Subscription, type RelayTiming, type RelayTimingObserver, } from "./relay.js";
7
+ export type { Message, HistoryPage, MessageRecord, MessageList, MessageListOptions, } from "./store.js";
8
+ export type { ProtocolMode } from "./modes.js";
9
+ export type { ReconnectOptions, RecoveryOptions, HistorySyncResult, } from "./inbox.js";
10
+ export { nsecSigner, bunkerSigner, type Signer, type BunkerOptions, } from "./signers.js";
11
+ export { SignerError, Nip4eCompatibilityError, StorageEncryptionError, RelayError, type RelayOperation, type RelayErrorCode, type RelayErrorDetails, } from "./errors.js";
12
+ export { COMMAND_DEFINITION_KIND, validateCommandDefinition, encodeCommandDefinition, decodeCommandDefinition, encodeCommandRevocation, selectCommandDefinitions, commandAddress, matchesCommandScopes, parseCommand, type CommandDefinition, type BotCommandDefinition, type CommandArgument, type CommandArgs, type CommandArgumentType, type CommandAddress, type CommandValue, type CommandEvent, type CommandMatchContext, type CommandInvocation, type CommandParseResult, type PublishedCommand, type CommandDiscoveryResult, type DiscoverCommandsOptions, } from "./nipcd.js";
13
+ export type { KeyRotationOptions, AnnounceOptions, EncryptionKeyStatus, } from "./keys.js";
14
+ export type { MessageState } from "./storage.js";
15
+ export { sqliteMessageStorage, type SQLiteMessageStorage, } from "./message-storage-sqlite.js";
16
+ export type { MessageStorage, MessageStorageEntry, MessageStorageQuery, } from "./message-storage.js";
17
+ export { DEFAULT_DM_RELAYS, DEFAULT_READ_RELAYS, DEFAULT_WRITE_RELAYS, DEFAULT_DISCOVERY_RELAYS, DEFAULT_BLOSSOM_SERVERS, } from "./defaults.js";
18
+ export type { MetadataCacheOptions } from "./messaging-metadata.js";
19
+ export type { KeySyncOptions } from "./key-sync.js";
20
+ export type { CommandSyncResult } from "./commands.js";
21
+ export { allowlist } from "./allowlist.js";
22
+ export { requestTiming, type RequestTiming, type RequestTimingObserver, type RequestTimingOptions, } from "./request-timing.js";
23
+ export type { Input, ThreadResult, ThreadOptions, PublicThreadOptions, } from "./public-thread.js";
24
+ export type { PublicInboxOptions } from "./public-inbox.js";
25
+ export { InvalidArgsError } from "./errors.js";
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { Bot, } from "./bot.js";
2
+ export { generateSecretKey, getPublicKey } from "./protocol.js";
3
+ export { WebSocketTransport, DEFAULT_RELAY_TIMEOUTS, } from "./relay.js";
4
+ export { nsecSigner, bunkerSigner, } from "./signers.js";
5
+ export { SignerError, Nip4eCompatibilityError, StorageEncryptionError, RelayError, } from "./errors.js";
6
+ export { COMMAND_DEFINITION_KIND, validateCommandDefinition, encodeCommandDefinition, decodeCommandDefinition, encodeCommandRevocation, selectCommandDefinitions, commandAddress, matchesCommandScopes, parseCommand, } from "./nipcd.js";
7
+ export { sqliteMessageStorage, } from "./message-storage-sqlite.js";
8
+ export { DEFAULT_DM_RELAYS, DEFAULT_READ_RELAYS, DEFAULT_WRITE_RELAYS, DEFAULT_DISCOVERY_RELAYS, DEFAULT_BLOSSOM_SERVERS, } from "./defaults.js";
9
+ export { allowlist } from "./allowlist.js";
10
+ export { requestTiming, } from "./request-timing.js";
11
+ export { InvalidArgsError } from "./errors.js";
@@ -0,0 +1,33 @@
1
+ import { type Event } from "nostr-tools";
2
+ import { type Identity } from "./protocol.js";
3
+ import type { Store } from "./store.js";
4
+ import type { Transport } from "./relay.js";
5
+ export interface KeySyncOptions {
6
+ timeoutMs?: number;
7
+ }
8
+ /** Same-identity NIP-4E transfer only; identity signing secrets are never exportable. */
9
+ export declare class KeySync {
10
+ private identity;
11
+ private store;
12
+ private transport;
13
+ private relays;
14
+ private exportKey;
15
+ private current;
16
+ private stopped;
17
+ private generation;
18
+ private responses;
19
+ private jobs;
20
+ private requests;
21
+ private cancel;
22
+ private timeout;
23
+ constructor(identity: Identity, store: Store, transport: Transport, relays: string[], exportKey: (key?: string) => Uint8Array | undefined, current: () => string | undefined, options?: KeySyncOptions);
24
+ private verified;
25
+ private single;
26
+ handle(event: Event): Promise<void>;
27
+ private persist;
28
+ request(expected: string): Promise<Uint8Array>;
29
+ private runRequest;
30
+ start(): void;
31
+ stop(): void;
32
+ idle(): Promise<void>;
33
+ }