chirli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +18 -20
- package/CONTRIBUTING.md +7 -3
- package/README.md +63 -55
- package/SECURITY.md +11 -11
- package/dist/allowlist.d.ts +3 -0
- package/dist/allowlist.js +9 -0
- package/dist/announcements.d.ts +4 -4
- package/dist/announcements.js +66 -34
- package/dist/attachments.d.ts +43 -0
- package/dist/attachments.js +340 -0
- package/dist/blossom.d.ts +2 -2
- package/dist/blossom.js +120 -66
- package/dist/bot-handlers.d.ts +9 -18
- package/dist/bot-handlers.js +125 -66
- package/dist/bot.d.ts +17 -20
- package/dist/bot.js +150 -55
- package/dist/client.d.ts +43 -39
- package/dist/client.js +476 -290
- package/dist/command-discovery.d.ts +2 -2
- package/dist/command-discovery.js +16 -7
- package/dist/command-schema.d.ts +2 -2
- package/dist/command-schema.js +62 -31
- package/dist/commands.d.ts +7 -6
- package/dist/commands.js +116 -51
- package/dist/defaults.js +13 -6
- package/dist/errors.d.ts +12 -12
- package/dist/errors.js +55 -18
- package/dist/inbox.d.ts +9 -7
- package/dist/inbox.js +107 -62
- package/dist/index.d.ts +25 -24
- package/dist/index.js +11 -11
- package/dist/key-sync.d.ts +4 -4
- package/dist/key-sync.js +88 -50
- package/dist/keys.d.ts +7 -6
- package/dist/keys.js +187 -93
- package/dist/message-storage-sqlite.d.ts +1 -1
- package/dist/message-storage-sqlite.js +32 -27
- package/dist/message-storage.d.ts +2 -2
- package/dist/messaging-metadata.d.ts +4 -4
- package/dist/messaging-metadata.js +73 -46
- package/dist/metadata.d.ts +3 -3
- package/dist/metadata.js +29 -15
- package/dist/modes.d.ts +7 -7
- package/dist/modes.js +53 -24
- package/dist/nip4e-compat.d.ts +2 -2
- package/dist/nip4e-compat.js +2 -2
- package/dist/nipcd.d.ts +14 -14
- package/dist/nipcd.js +225 -126
- package/dist/protocol.d.ts +7 -6
- package/dist/protocol.js +101 -54
- package/dist/public-inbox.d.ts +17 -15
- package/dist/public-inbox.js +129 -138
- package/dist/public-thread.d.ts +7 -4
- package/dist/public-thread.js +205 -88
- package/dist/relay-pool.d.ts +5 -5
- package/dist/relay-pool.js +172 -67
- package/dist/relay-roles.js +22 -13
- package/dist/relay.d.ts +11 -11
- package/dist/relay.js +194 -100
- package/dist/request-timing.d.ts +2 -2
- package/dist/request-timing.js +19 -7
- package/dist/session.js +7 -5
- package/dist/signer.d.ts +1 -1
- package/dist/signers/bunker-relays.d.ts +2 -2
- package/dist/signers/bunker-relays.js +16 -13
- package/dist/signers/bunker.d.ts +2 -2
- package/dist/signers/bunker.js +57 -37
- package/dist/signers/nsec.d.ts +2 -2
- package/dist/signers/nsec.js +8 -8
- package/dist/signers.d.ts +8 -8
- package/dist/signers.js +25 -18
- package/dist/storage-sqlite.d.ts +3 -1
- package/dist/storage-sqlite.js +110 -58
- package/dist/storage.d.ts +10 -6
- package/dist/store.d.ts +12 -8
- package/dist/store.js +156 -78
- package/docs/ACCESS.md +14 -25
- package/docs/API.md +125 -79
- package/docs/KEYS.md +3 -3
- package/docs/NIP-CD.md +29 -19
- package/docs/PUBLIC.md +33 -23
- package/docs/RECOVERY.md +7 -5
- package/docs/RELAYS.md +6 -6
- package/docs/SESSIONS.md +25 -21
- package/docs/SIGNERS.md +5 -3
- package/docs/STORAGE.md +15 -15
- package/docs/TUTORIAL.md +42 -39
- package/package.json +1 -37
- package/dist/inbound-policy.d.ts +0 -4
- package/dist/inbound-policy.js +0 -9
package/dist/protocol.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Event, type EventTemplate } from
|
|
2
|
-
export { generateSecretKey, getPublicKey } from
|
|
3
|
-
export type Rumor = Omit<Event,
|
|
1
|
+
import { type Event, type EventTemplate } from "nostr-tools";
|
|
2
|
+
export { generateSecretKey, getPublicKey } from "nostr-tools";
|
|
3
|
+
export type Rumor = Omit<Event, "sig">;
|
|
4
4
|
export interface Identity {
|
|
5
5
|
pubkey: string;
|
|
6
6
|
/** Split messaging key in nip4e; identity secret itself in nip17. */
|
|
@@ -26,8 +26,9 @@ export declare const createSplitIdentity: typeof localIdentity;
|
|
|
26
26
|
export declare const hexKey: (s: unknown) => s is string;
|
|
27
27
|
/** Reject fractional/negative/unsafe protocol times before crypto or SQLite ordering. */
|
|
28
28
|
export declare function validTimestamp(seconds: number): boolean;
|
|
29
|
-
export declare function timestamp(r: Pick<Rumor,
|
|
30
|
-
export declare function
|
|
29
|
+
export declare function timestamp(r: Pick<Rumor, "tags" | "created_at">): number;
|
|
30
|
+
export declare function createdAtOrAfter(r: Pick<Rumor, "tags" | "created_at">, activatedAt: number): boolean;
|
|
31
|
+
export declare function replyTarget(rumor: Pick<Rumor, "tags">): string | undefined;
|
|
31
32
|
export declare function rumor(identity: string, peer: string, text: string, now?: number, replyTo?: string): Rumor;
|
|
32
33
|
export declare function reactionRumor(identity: string, peer: string, target: string, reaction: string): Rumor;
|
|
33
34
|
export declare function fileRumor(identity: string, peer: string, url: string, fileTags: string[][], reference?: string): Rumor;
|
|
@@ -63,5 +64,5 @@ export type DecodedEnvelope = {
|
|
|
63
64
|
encryptionPubkey: string;
|
|
64
65
|
};
|
|
65
66
|
export declare function unwrap(event: Event, identity: Identity, policy?: EnvelopePolicy): DecodedEnvelope | undefined;
|
|
66
|
-
export declare function unwrapAsync(event: Event, identity: Identity, policy?: EnvelopePolicy): Promise<DecodedEnvelope | undefined>;
|
|
67
|
+
export declare function unwrapAsync(event: Event, identity: Identity, policy?: EnvelopePolicy, active?: () => boolean): Promise<DecodedEnvelope | undefined>;
|
|
67
68
|
export declare function announcement(identity: Identity, now?: number): Promise<Event>;
|
package/dist/protocol.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { SignerError } from
|
|
2
|
-
import { finalizeEvent, generateSecretKey, getPublicKey, getEventHash, nip44, validateEvent, verifyEvent, } from
|
|
3
|
-
export { generateSecretKey, getPublicKey } from
|
|
1
|
+
import { SignerError } from "./errors.js";
|
|
2
|
+
import { finalizeEvent, generateSecretKey, getPublicKey, getEventHash, nip44, validateEvent, verifyEvent, } from "nostr-tools";
|
|
3
|
+
export { generateSecretKey, getPublicKey } from "nostr-tools";
|
|
4
4
|
/** Local split-key account for protocol fixtures and internal envelope tooling. */
|
|
5
5
|
export function localIdentity(secret = generateSecretKey(), encryptionKey = generateSecretKey()) {
|
|
6
6
|
return {
|
|
7
7
|
pubkey: getPublicKey(secret),
|
|
8
8
|
encryptionKey,
|
|
9
9
|
identityEncryption: localMessagingKey(secret),
|
|
10
|
-
sign: async (t) => finalizeEvent(t, secret)
|
|
10
|
+
sign: async (t) => finalizeEvent(t, secret),
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
/** Unified identity signing/decryption key for the default NIP-17 mode. */
|
|
@@ -18,17 +18,28 @@ export function localNip17Identity(secret = generateSecretKey()) {
|
|
|
18
18
|
export const createIdentity = localNip17Identity;
|
|
19
19
|
/** Explicit split-key identity; select Client mode: nip4e. */
|
|
20
20
|
export const createSplitIdentity = localIdentity;
|
|
21
|
-
export const hexKey = (s) => typeof s ===
|
|
21
|
+
export const hexKey = (s) => typeof s === "string" && /^[0-9a-f]{64}$/.test(s);
|
|
22
22
|
/** Reject fractional/negative/unsafe protocol times before crypto or SQLite ordering. */
|
|
23
23
|
export function validTimestamp(seconds) {
|
|
24
|
-
return Number.isSafeInteger(seconds) &&
|
|
24
|
+
return (Number.isSafeInteger(seconds) &&
|
|
25
|
+
seconds >= 0 &&
|
|
26
|
+
seconds <= Math.floor((Number.MAX_SAFE_INTEGER - 999) / 1000));
|
|
25
27
|
}
|
|
26
28
|
export function timestamp(r) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
return r.created_at * 1000 + (rumorMilliseconds(r) ?? 0);
|
|
30
|
+
}
|
|
31
|
+
function rumorMilliseconds(r) {
|
|
32
|
+
const ms = r.tags.find((t) => t[0] === "ms")?.[1];
|
|
33
|
+
return ms && /^\d{1,3}$/.test(ms) ? +ms : undefined;
|
|
34
|
+
}
|
|
35
|
+
export function createdAtOrAfter(r, activatedAt) {
|
|
36
|
+
const milliseconds = rumorMilliseconds(r);
|
|
37
|
+
return milliseconds === undefined
|
|
38
|
+
? r.created_at >= Math.floor(activatedAt / 1000)
|
|
39
|
+
: r.created_at * 1000 + milliseconds >= activatedAt;
|
|
29
40
|
}
|
|
30
41
|
export function replyTarget(rumor) {
|
|
31
|
-
const target = rumor.tags?.find(tag => tag[0] ===
|
|
42
|
+
const target = rumor.tags?.find((tag) => tag[0] === "e")?.[1];
|
|
32
43
|
return hexKey(target) ? target : undefined;
|
|
33
44
|
}
|
|
34
45
|
export function rumor(identity, peer, text, now = Date.now(), replyTo) {
|
|
@@ -41,9 +52,13 @@ export function fileRumor(identity, peer, url, fileTags, reference) {
|
|
|
41
52
|
return dmRumor(15, identity, peer, url, Date.now(), reference, fileTags);
|
|
42
53
|
}
|
|
43
54
|
function dmRumor(kind, identity, peer, content, now, reference, extraTags = []) {
|
|
44
|
-
const tags = [
|
|
55
|
+
const tags = [
|
|
56
|
+
["p", peer],
|
|
57
|
+
["ms", String(now % 1000)],
|
|
58
|
+
["nonce", Buffer.from(generateSecretKey()).toString("hex")],
|
|
59
|
+
];
|
|
45
60
|
if (reference !== undefined)
|
|
46
|
-
tags.push([
|
|
61
|
+
tags.push(["e", reference]);
|
|
47
62
|
tags.push(...extraTags);
|
|
48
63
|
const r = {
|
|
49
64
|
pubkey: identity,
|
|
@@ -53,7 +68,8 @@ function dmRumor(kind, identity, peer, content, now, reference, extraTags = [])
|
|
|
53
68
|
tags,
|
|
54
69
|
};
|
|
55
70
|
return {
|
|
56
|
-
...r,
|
|
71
|
+
...r,
|
|
72
|
+
id: getEventHash(r),
|
|
57
73
|
};
|
|
58
74
|
}
|
|
59
75
|
const encrypt = (text, secret, peer) => nip44.v2.encrypt(text, nip44.v2.utils.getConversationKey(secret, peer));
|
|
@@ -62,76 +78,85 @@ export function localMessagingKey(key) {
|
|
|
62
78
|
return {
|
|
63
79
|
publicKey: getPublicKey(key),
|
|
64
80
|
encrypt: (text, peer) => encrypt(text, key, peer),
|
|
65
|
-
decrypt: (text, peer) => decrypt(text, key, peer)
|
|
81
|
+
decrypt: (text, peer) => decrypt(text, key, peer),
|
|
66
82
|
};
|
|
67
83
|
}
|
|
68
84
|
export function splitKey(identity) {
|
|
69
85
|
if (!identity.encryptionKey) {
|
|
70
|
-
throw new Error(
|
|
86
|
+
throw new Error("nip4e requires a local, separate messaging encryptionKey");
|
|
71
87
|
}
|
|
72
88
|
return identity.encryptionKey;
|
|
73
89
|
}
|
|
74
90
|
const randomPast = () => Math.floor(Date.now() / 1000) - Math.floor(Math.random() * 172800);
|
|
75
91
|
export const splitEnvelope = {
|
|
76
|
-
keys: identity => [splitKey(identity), ...(identity.oldEncryptionKeys ?? [])].map(localMessagingKey),
|
|
77
|
-
tags: identity => [[
|
|
78
|
-
sealTime: r => r.created_at,
|
|
79
|
-
senderKey: seal => seal.tags.find(t => t[0] ===
|
|
80
|
-
acceptsRoute: (event, account) => event.tags.some(t => t[0] ===
|
|
92
|
+
keys: (identity) => [splitKey(identity), ...(identity.oldEncryptionKeys ?? [])].map(localMessagingKey),
|
|
93
|
+
tags: (identity) => [["n", getPublicKey(splitKey(identity))]],
|
|
94
|
+
sealTime: (r) => r.created_at,
|
|
95
|
+
senderKey: (seal) => seal.tags.find((t) => t[0] === "n")?.[1],
|
|
96
|
+
acceptsRoute: (event, account) => event.tags.some((t) => t[0] === "p" && t[1] === account),
|
|
81
97
|
};
|
|
82
98
|
export function identityMessagingKey(identity) {
|
|
83
99
|
const capability = identity.identityEncryption ?? identity.messaging;
|
|
84
100
|
if (capability) {
|
|
85
101
|
if (capability.publicKey !== identity.pubkey) {
|
|
86
|
-
throw new Error(
|
|
102
|
+
throw new Error("Identity encryption capability must match identity pubkey");
|
|
87
103
|
}
|
|
88
104
|
return capability;
|
|
89
105
|
}
|
|
90
|
-
if (identity.encryptionKey &&
|
|
106
|
+
if (identity.encryptionKey &&
|
|
107
|
+
getPublicKey(identity.encryptionKey) === identity.pubkey) {
|
|
91
108
|
return localMessagingKey(identity.encryptionKey);
|
|
92
109
|
}
|
|
93
|
-
throw new Error(
|
|
110
|
+
throw new Error("Both protocols require identity-key NIP-44 capability; use localIdentity/localNip17Identity or identityFromSigner");
|
|
94
111
|
}
|
|
95
112
|
export function validateNip17Identity(identity) {
|
|
96
113
|
identityMessagingKey(identity);
|
|
97
|
-
if (identity.encryptionKey &&
|
|
98
|
-
|
|
114
|
+
if (identity.encryptionKey &&
|
|
115
|
+
getPublicKey(identity.encryptionKey) !== identity.pubkey) {
|
|
116
|
+
throw new Error("nip17 requires the identity secret; select mode: nip4e explicitly for a separate encryptionKey");
|
|
99
117
|
}
|
|
100
118
|
}
|
|
101
119
|
export const standardEnvelope = {
|
|
102
|
-
keys: identity => [identityMessagingKey(identity)],
|
|
120
|
+
keys: (identity) => [identityMessagingKey(identity)],
|
|
103
121
|
tags: () => [],
|
|
104
122
|
sealTime: () => randomPast(),
|
|
105
|
-
senderKey: seal => seal.tags.length === 0 ? seal.pubkey : undefined,
|
|
123
|
+
senderKey: (seal) => (seal.tags.length === 0 ? seal.pubkey : undefined),
|
|
106
124
|
acceptsRoute: (event, account) => {
|
|
107
|
-
const recipients = event.tags.filter(t => t[0] ===
|
|
125
|
+
const recipients = event.tags.filter((t) => t[0] === "p");
|
|
108
126
|
return recipients.length === 1 && recipients[0][1] === account;
|
|
109
127
|
},
|
|
110
128
|
};
|
|
111
129
|
/** Accept standard seals or the explicit, authenticated PsstPsst split-key extension. */
|
|
112
130
|
export const compatibilityEnvelope = {
|
|
113
131
|
...standardEnvelope,
|
|
114
|
-
keys: identity => {
|
|
115
|
-
const keys = [identity.encryptionKey, ...(identity.oldEncryptionKeys ?? [])]
|
|
132
|
+
keys: (identity) => {
|
|
133
|
+
const keys = [identity.encryptionKey, ...(identity.oldEncryptionKeys ?? [])]
|
|
134
|
+
.filter((key) => !!key && getPublicKey(key) !== identity.pubkey)
|
|
135
|
+
.map(localMessagingKey);
|
|
116
136
|
return [...keys, identityMessagingKey(identity)];
|
|
117
137
|
},
|
|
118
|
-
senderKey: seal => seal.tags.length === 0
|
|
138
|
+
senderKey: (seal) => seal.tags.length === 0
|
|
139
|
+
? seal.pubkey
|
|
140
|
+
: seal.tags.find((tag) => tag[0] === "n")?.[1],
|
|
119
141
|
};
|
|
120
142
|
/** PsstPsst requires n even when the sender encrypts with its identity key. */
|
|
121
143
|
export const identitySplitEnvelope = {
|
|
122
144
|
...compatibilityEnvelope,
|
|
123
|
-
keys: identity => [identityMessagingKey(identity)],
|
|
124
|
-
tags: identity => [[
|
|
125
|
-
sealTime: rumor => rumor.created_at,
|
|
145
|
+
keys: (identity) => [identityMessagingKey(identity)],
|
|
146
|
+
tags: (identity) => [["n", identity.pubkey]],
|
|
147
|
+
sealTime: (rumor) => rumor.created_at,
|
|
126
148
|
};
|
|
127
149
|
/** A signer may be external, but must return the exact event requested. */
|
|
128
150
|
export async function signChecked(identity, template) {
|
|
129
151
|
const expectedId = getEventHash({
|
|
130
|
-
...template,
|
|
152
|
+
...template,
|
|
153
|
+
pubkey: identity.pubkey,
|
|
131
154
|
});
|
|
132
155
|
const event = await identity.sign(template);
|
|
133
|
-
if (event.pubkey !== identity.pubkey ||
|
|
134
|
-
|
|
156
|
+
if (event.pubkey !== identity.pubkey ||
|
|
157
|
+
event.id !== expectedId ||
|
|
158
|
+
!verifyEvent(JSON.parse(JSON.stringify(event)))) {
|
|
159
|
+
throw new Error("Identity signer returned an invalid or altered event");
|
|
135
160
|
}
|
|
136
161
|
return event;
|
|
137
162
|
}
|
|
@@ -141,21 +166,24 @@ export async function wrap(r, identity, recipient, encryptionPubkey, policy = sp
|
|
|
141
166
|
kind: 13,
|
|
142
167
|
created_at: policy.sealTime(r),
|
|
143
168
|
tags: policy.tags(identity),
|
|
144
|
-
content: await key.encrypt(JSON.stringify(r), encryptionPubkey)
|
|
169
|
+
content: await key.encrypt(JSON.stringify(r), encryptionPubkey),
|
|
145
170
|
});
|
|
146
171
|
const ephemeral = generateSecretKey();
|
|
147
172
|
return finalizeEvent({
|
|
148
173
|
kind: 1059,
|
|
149
174
|
created_at: randomPast(),
|
|
150
|
-
tags: [[
|
|
151
|
-
content: encrypt(JSON.stringify(seal), ephemeral, encryptionPubkey)
|
|
175
|
+
tags: [["p", recipient]],
|
|
176
|
+
content: encrypt(JSON.stringify(seal), ephemeral, encryptionPubkey),
|
|
152
177
|
}, ephemeral);
|
|
153
178
|
}
|
|
154
179
|
/** One validation state machine serves synchronous local and asynchronous signer crypto. */
|
|
155
180
|
function* decode(event, identity, policy) {
|
|
156
181
|
try {
|
|
157
182
|
event = JSON.parse(JSON.stringify(event));
|
|
158
|
-
if (event.kind !== 1059 ||
|
|
183
|
+
if (event.kind !== 1059 ||
|
|
184
|
+
!validTimestamp(event.created_at) ||
|
|
185
|
+
!verifyEvent(event) ||
|
|
186
|
+
!policy.acceptsRoute(event, identity.pubkey)) {
|
|
159
187
|
return;
|
|
160
188
|
}
|
|
161
189
|
for (const key of policy.keys(identity)) {
|
|
@@ -163,9 +191,11 @@ function* decode(event, identity, policy) {
|
|
|
163
191
|
const seal = JSON.parse(yield {
|
|
164
192
|
key,
|
|
165
193
|
content: event.content,
|
|
166
|
-
peer: event.pubkey
|
|
194
|
+
peer: event.pubkey,
|
|
167
195
|
});
|
|
168
|
-
if (seal.kind !== 13 ||
|
|
196
|
+
if (seal.kind !== 13 ||
|
|
197
|
+
!validTimestamp(seal.created_at) ||
|
|
198
|
+
!verifyEvent(seal)) {
|
|
169
199
|
continue;
|
|
170
200
|
}
|
|
171
201
|
const encryptionPubkey = policy.senderKey(seal);
|
|
@@ -175,13 +205,20 @@ function* decode(event, identity, policy) {
|
|
|
175
205
|
const r = JSON.parse(yield {
|
|
176
206
|
key,
|
|
177
207
|
content: seal.content,
|
|
178
|
-
peer: encryptionPubkey
|
|
208
|
+
peer: encryptionPubkey,
|
|
179
209
|
});
|
|
180
|
-
if (!validateEvent(r) ||
|
|
210
|
+
if (!validateEvent(r) ||
|
|
211
|
+
!validTimestamp(r.created_at) ||
|
|
212
|
+
(r.kind !== 14 && r.kind !== 15) ||
|
|
213
|
+
r.pubkey !== seal.pubkey ||
|
|
214
|
+
r.id !== getEventHash(r) ||
|
|
215
|
+
"sig" in r) {
|
|
181
216
|
continue;
|
|
182
217
|
}
|
|
183
|
-
const peers = r.tags.filter(t => t[0] ===
|
|
184
|
-
if (peers.length !== 1 ||
|
|
218
|
+
const peers = r.tags.filter((t) => t[0] === "p");
|
|
219
|
+
if (peers.length !== 1 ||
|
|
220
|
+
!hexKey(peers[0][1]) ||
|
|
221
|
+
r.tags.some((t) => ["h", "action"].includes(t[0]))) {
|
|
185
222
|
continue;
|
|
186
223
|
}
|
|
187
224
|
if (r.pubkey !== identity.pubkey && peers[0][1] !== identity.pubkey) {
|
|
@@ -190,7 +227,7 @@ function* decode(event, identity, policy) {
|
|
|
190
227
|
return {
|
|
191
228
|
rumor: r,
|
|
192
229
|
seal,
|
|
193
|
-
encryptionPubkey
|
|
230
|
+
encryptionPubkey,
|
|
194
231
|
};
|
|
195
232
|
}
|
|
196
233
|
catch (error) {
|
|
@@ -217,9 +254,8 @@ export function unwrap(event, identity, policy = splitEnvelope) {
|
|
|
217
254
|
}
|
|
218
255
|
try {
|
|
219
256
|
const text = key.decrypt(content, peer);
|
|
220
|
-
if (typeof text !==
|
|
221
|
-
void text.catch(() => {
|
|
222
|
-
});
|
|
257
|
+
if (typeof text !== "string") {
|
|
258
|
+
void text.catch(() => { });
|
|
223
259
|
decoder.return(undefined);
|
|
224
260
|
return;
|
|
225
261
|
}
|
|
@@ -231,15 +267,26 @@ export function unwrap(event, identity, policy = splitEnvelope) {
|
|
|
231
267
|
}
|
|
232
268
|
return step.value;
|
|
233
269
|
}
|
|
234
|
-
export async function unwrapAsync(event, identity, policy = splitEnvelope) {
|
|
270
|
+
export async function unwrapAsync(event, identity, policy = splitEnvelope, active = () => true) {
|
|
271
|
+
if (!active())
|
|
272
|
+
return undefined;
|
|
235
273
|
const decoder = decode(event, identity, policy);
|
|
236
274
|
let step = decoder.next();
|
|
237
275
|
while (!step.done) {
|
|
238
276
|
const { key, content, peer } = step.value;
|
|
239
277
|
try {
|
|
240
|
-
|
|
278
|
+
const text = await key.decrypt(content, peer);
|
|
279
|
+
if (!active()) {
|
|
280
|
+
decoder.return(undefined);
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
step = decoder.next(text);
|
|
241
284
|
}
|
|
242
285
|
catch (error) {
|
|
286
|
+
if (!active()) {
|
|
287
|
+
decoder.return(undefined);
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
243
290
|
step = decoder.throw(error);
|
|
244
291
|
}
|
|
245
292
|
}
|
|
@@ -249,7 +296,7 @@ export function announcement(identity, now = Math.floor(Date.now() / 1000)) {
|
|
|
249
296
|
return signChecked(identity, {
|
|
250
297
|
kind: 10044,
|
|
251
298
|
created_at: now,
|
|
252
|
-
tags: [[
|
|
253
|
-
content:
|
|
299
|
+
tags: [["n", getPublicKey(splitKey(identity))]],
|
|
300
|
+
content: "",
|
|
254
301
|
});
|
|
255
302
|
}
|
package/dist/public-inbox.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { UploadFileResult } from
|
|
2
|
-
import type { Event } from
|
|
3
|
-
import { type Identity } from
|
|
4
|
-
import { type CommandDefinition } from
|
|
5
|
-
import { type ReconnectOptions } from
|
|
6
|
-
import { PublicThreads, type PublicThreadOptions, type ThreadOptions } from
|
|
7
|
-
import type { Store } from
|
|
8
|
-
import { type Transport } from
|
|
1
|
+
import type { UploadFileResult } from "./blossom.js";
|
|
2
|
+
import type { Event } from "nostr-tools";
|
|
3
|
+
import { type Identity } from "./protocol.js";
|
|
4
|
+
import { type CommandDefinition } from "./nipcd.js";
|
|
5
|
+
import { type ReconnectOptions } from "./inbox.js";
|
|
6
|
+
import { PublicThreads, type PublicThreadOptions, type ThreadOptions } from "./public-thread.js";
|
|
7
|
+
import type { Store } from "./store.js";
|
|
8
|
+
import { type Transport } from "./relay.js";
|
|
9
9
|
export interface PublicInboxOptions {
|
|
10
10
|
relays: readonly string[];
|
|
11
11
|
thread?: PublicThreadOptions;
|
|
@@ -23,7 +23,6 @@ export declare class PublicInbox {
|
|
|
23
23
|
private writes;
|
|
24
24
|
private reconnect;
|
|
25
25
|
private definitions;
|
|
26
|
-
private allowed;
|
|
27
26
|
private process;
|
|
28
27
|
private report;
|
|
29
28
|
private state;
|
|
@@ -34,18 +33,17 @@ export declare class PublicInbox {
|
|
|
34
33
|
private starting?;
|
|
35
34
|
private generation;
|
|
36
35
|
private queues;
|
|
37
|
-
private scheduled;
|
|
38
36
|
private flushing?;
|
|
39
37
|
private relays;
|
|
40
38
|
readonly threads: PublicThreads;
|
|
41
|
-
constructor(identity: Identity, store: Store, transport: Transport, options: PublicInboxOptions, writes: string[], reconnect: false | ReconnectOptions | undefined, definitions: () => CommandDefinition[],
|
|
39
|
+
constructor(identity: Identity, store: Store, transport: Transport, options: PublicInboxOptions, writes: string[], reconnect: false | ReconnectOptions | undefined, definitions: () => CommandDefinition[], process: (input: PublicInput) => Promise<void>, report: (error: unknown) => void);
|
|
42
40
|
private save;
|
|
43
41
|
private conversation;
|
|
44
42
|
private accepted;
|
|
45
43
|
start(kinds: number[]): Promise<void>;
|
|
46
|
-
receive(input: Event, source:
|
|
44
|
+
receive(input: Event, source: "live" | "history", relay?: string): boolean;
|
|
47
45
|
private enqueue;
|
|
48
|
-
/**
|
|
46
|
+
/** A delayed signed event is sufficient but does not carry verified relay provenance. */
|
|
49
47
|
target(input: Event): PublicInput;
|
|
50
48
|
reply(input: PublicInput, text: string): Promise<{
|
|
51
49
|
id: string;
|
|
@@ -55,9 +53,13 @@ export declare class PublicInbox {
|
|
|
55
53
|
id: string;
|
|
56
54
|
status: "pending" | "relay-accepted";
|
|
57
55
|
}>;
|
|
58
|
-
|
|
56
|
+
react(input: PublicInput, reaction?: string): Promise<{
|
|
57
|
+
id: string;
|
|
58
|
+
status: "pending" | "relay-accepted";
|
|
59
|
+
}>;
|
|
60
|
+
private sourceRelay;
|
|
61
|
+
private publishOutput;
|
|
59
62
|
flush(): Promise<void>;
|
|
60
|
-
retry(ids?: Set<string>): void;
|
|
61
63
|
thread(input: PublicInput, options?: ThreadOptions): Promise<import("./public-thread.js").ThreadResult>;
|
|
62
64
|
stop(): void;
|
|
63
65
|
idle(): Promise<void>;
|