@peer2peer/cli 0.0.0-stage → 0.1.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 (105) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +366 -2
  3. package/dist/ancestry.d.ts +13 -0
  4. package/dist/ancestry.js +71 -0
  5. package/dist/app.d.ts +363 -0
  6. package/dist/app.js +1177 -0
  7. package/dist/bin.d.ts +2 -0
  8. package/dist/bin.js +56 -0
  9. package/dist/circle-ops.d.ts +402 -0
  10. package/dist/circle-ops.js +1725 -0
  11. package/dist/cli.d.ts +611 -0
  12. package/dist/cli.js +1650 -0
  13. package/dist/codes.d.ts +231 -0
  14. package/dist/codes.js +998 -0
  15. package/dist/config.d.ts +112 -0
  16. package/dist/config.js +243 -0
  17. package/dist/doctor.d.ts +99 -0
  18. package/dist/doctor.js +817 -0
  19. package/dist/errors.d.ts +8 -0
  20. package/dist/errors.js +29 -0
  21. package/dist/ext-host.d.ts +32 -0
  22. package/dist/ext-host.js +259 -0
  23. package/dist/extensions.d.ts +386 -0
  24. package/dist/extensions.js +395 -0
  25. package/dist/features.d.ts +91 -0
  26. package/dist/features.js +164 -0
  27. package/dist/format.d.ts +57 -0
  28. package/dist/format.js +248 -0
  29. package/dist/identity.d.ts +236 -0
  30. package/dist/identity.js +751 -0
  31. package/dist/inbound.d.ts +32 -0
  32. package/dist/inbound.js +258 -0
  33. package/dist/index.d.ts +8 -0
  34. package/dist/index.js +14 -0
  35. package/dist/join-answers.d.ts +49 -0
  36. package/dist/join-answers.js +149 -0
  37. package/dist/outbox.d.ts +109 -0
  38. package/dist/outbox.js +337 -0
  39. package/dist/pretty.d.ts +100 -0
  40. package/dist/pretty.js +256 -0
  41. package/dist/procstart.d.ts +1 -0
  42. package/dist/procstart.js +66 -0
  43. package/dist/progress.d.ts +30 -0
  44. package/dist/progress.js +78 -0
  45. package/dist/projects.d.ts +240 -0
  46. package/dist/projects.js +699 -0
  47. package/dist/prompt/picker.d.ts +64 -0
  48. package/dist/prompt/picker.js +152 -0
  49. package/dist/prompt/tty.d.ts +29 -0
  50. package/dist/prompt/tty.js +122 -0
  51. package/dist/readonly.d.ts +20 -0
  52. package/dist/readonly.js +50 -0
  53. package/dist/receipts.d.ts +99 -0
  54. package/dist/receipts.js +180 -0
  55. package/dist/relay-client.d.ts +277 -0
  56. package/dist/relay-client.js +873 -0
  57. package/dist/relay-info.d.ts +24 -0
  58. package/dist/relay-info.js +53 -0
  59. package/dist/rotation.d.ts +402 -0
  60. package/dist/rotation.js +2054 -0
  61. package/dist/running.d.ts +5 -0
  62. package/dist/running.js +74 -0
  63. package/dist/sessions.d.ts +340 -0
  64. package/dist/sessions.js +1152 -0
  65. package/dist/shortcode.d.ts +149 -0
  66. package/dist/shortcode.js +465 -0
  67. package/dist/social.d.ts +139 -0
  68. package/dist/social.js +485 -0
  69. package/dist/state.d.ts +483 -0
  70. package/dist/state.js +217 -0
  71. package/dist/stdin.d.ts +17 -0
  72. package/dist/stdin.js +46 -0
  73. package/dist/sync.d.ts +77 -0
  74. package/dist/sync.js +375 -0
  75. package/dist/transient.d.ts +1 -0
  76. package/dist/transient.js +28 -0
  77. package/dist/trust.d.ts +37 -0
  78. package/dist/trust.js +134 -0
  79. package/dist/tty-confirm.d.ts +2 -0
  80. package/dist/tty-confirm.js +53 -0
  81. package/dist/tui/command.d.ts +20 -0
  82. package/dist/tui/command.js +70 -0
  83. package/dist/tui/frame.d.ts +43 -0
  84. package/dist/tui/frame.js +111 -0
  85. package/dist/tui/model.d.ts +215 -0
  86. package/dist/tui/model.js +255 -0
  87. package/dist/tui/sanitize.d.ts +13 -0
  88. package/dist/tui/sanitize.js +151 -0
  89. package/dist/tui/terminal.d.ts +88 -0
  90. package/dist/tui/terminal.js +354 -0
  91. package/dist/tui/tui.d.ts +71 -0
  92. package/dist/tui/tui.js +571 -0
  93. package/dist/tui/view.d.ts +4 -0
  94. package/dist/tui/view.js +356 -0
  95. package/dist/unknown-kinds.d.ts +12 -0
  96. package/dist/unknown-kinds.js +66 -0
  97. package/dist/version.d.ts +1 -0
  98. package/dist/version.js +5 -0
  99. package/dist/want-pow.d.ts +12 -0
  100. package/dist/want-pow.js +46 -0
  101. package/dist/watch.d.ts +35 -0
  102. package/dist/watch.js +325 -0
  103. package/dist/xstate.d.ts +125 -0
  104. package/dist/xstate.js +422 -0
  105. package/package.json +60 -4
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2026 Ix Infrastructure Inc.
3
+ //
4
+ // The `p2p` executable.
5
+ import { createInterface } from "node:readline/promises";
6
+ import { main } from "./cli.js";
7
+ import { readAll } from "./stdin.js";
8
+ import { runPicker } from "./prompt/tty.js";
9
+ import { colorWanted } from "./tui/terminal.js";
10
+ const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
11
+ // Pickers: a person at a terminal only. Never in CI, and never inside an agent's tool call (Claude Code
12
+ // and Codex set these), even if it has a terminal: an agent can't pick for the person.
13
+ const agent = Boolean(process.env.CLAUDECODE || process.env.CODEX_THREAD_ID || process.env.CODEX_SESSION_ID);
14
+ const ci = Boolean(process.env.CI) && process.env.CI !== "0" && process.env.CI !== "false";
15
+ const pickers = interactive && !agent && !ci;
16
+ const color = colorWanted(process.env, process.stdout);
17
+ const io = {
18
+ out: (s) => process.stdout.write(s + "\n"),
19
+ err: (s) => process.stderr.write(s + "\n"),
20
+ ...(interactive
21
+ ? {
22
+ prompt: async (q) => {
23
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
24
+ try {
25
+ return await rl.question(q);
26
+ }
27
+ finally {
28
+ rl.close();
29
+ }
30
+ },
31
+ promptSecret: async (q) => {
32
+ // The answer isn't echoed (a backup phrase must not land in scrollback or a screen share).
33
+ process.stdout.write(q);
34
+ const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
35
+ const out = rl;
36
+ out._writeToOutput = () => { };
37
+ try {
38
+ return await rl.question("");
39
+ }
40
+ finally {
41
+ rl.close();
42
+ process.stdout.write("\n");
43
+ }
44
+ },
45
+ }
46
+ : {}),
47
+ readStdin: (o) => readAll(process.stdin, { implicit: o?.implicit, hint: (m) => process.stderr.write(`p2p: ${m}\n`) }),
48
+ ...(pickers ? { select: (spec) => runPicker(spec, process.stdin, process.stdout, { color }) } : {}),
49
+ // Laid-out output (pretty.ts) only when stdout is a terminal; piped output is the plain text.
50
+ ...(process.stdout.isTTY && !agent ? { pretty: { color, cols: process.stdout.columns || 80 } } : {}),
51
+ };
52
+ const code = await main(process.argv.slice(2), { env: process.env, io });
53
+ process.exitCode = code;
54
+ // Every step is bounded, but a socket or timer left behind must not keep the process (and the
55
+ // user's terminal) waiting: give stdout a moment to flush, then exit.
56
+ setTimeout(() => process.exit(code), 1500).unref();
@@ -0,0 +1,402 @@
1
+ import { type AcceptedMessageV3, type CirclePolicy, type LoadedCircle, type NextVersionParams, type VerifiedCircleVersion, type VerifiedMembership, type AnswerPart } from "@peer2peer/core/v3";
2
+ import { App, type Delivery } from "./app.js";
3
+ import { type NewEvent } from "./inbound.js";
4
+ import type { AnswerPartsRec, HeldItem } from "./state.js";
5
+ import { type WantPow } from "./want-pow.js";
6
+ export declare function resolveCircle(app: App, input: string): Promise<LoadedCircle>;
7
+ export interface CircleHint {
8
+ doc?: string;
9
+ join?: string;
10
+ }
11
+ export declare function encodeCircleLink(head: string, hint: CircleHint | undefined, web?: boolean): string;
12
+ export declare function parseCircleLink(link: string): {
13
+ head: string;
14
+ hint?: CircleHint;
15
+ };
16
+ export declare function circleLink(app: App, cidOrName: string): Promise<{
17
+ cid: string;
18
+ link: string;
19
+ web: string;
20
+ policy: CirclePolicy;
21
+ }>;
22
+ /** Signs and records our own join (§3.3), with a fresh co-member cap. */
23
+ export declare function signOwnJoin(app: App, cid: string, at: string): Promise<VerifiedMembership>;
24
+ /**
25
+ * Re-signs our join in `cid` (n+1, a fresh co-member cap on our current
26
+ * relays) and sends it to the members and our other devices (review L5).
27
+ */
28
+ export declare function resignJoin(app: App, cid: string): Promise<boolean>;
29
+ /** Thin wrapper: the core hardening PR changes recordOwnJoin's signature (adds `self`). */
30
+ export declare function recordJoin(app: App, v: VerifiedMembership): Promise<void>;
31
+ export interface CircleSummary {
32
+ cid: string;
33
+ name: string;
34
+ ver: number;
35
+ policy: CirclePolicy;
36
+ owner: string;
37
+ ownerAddress: string;
38
+ role: "owner" | "admin" | "member" | "invited" | "former";
39
+ joined: boolean;
40
+ members: number;
41
+ standing: number;
42
+ frozen?: string;
43
+ isDefault: boolean;
44
+ }
45
+ export declare function createCircleCmd(app: App, name: string, opts: {
46
+ open?: boolean;
47
+ }): Promise<CircleSummary & {
48
+ link?: string;
49
+ }>;
50
+ export declare function listCircles(app: App): Promise<CircleSummary[]>;
51
+ export interface MemberRow {
52
+ userId: string;
53
+ address: string;
54
+ owner: boolean;
55
+ admin: boolean;
56
+ stands: boolean;
57
+ statement: "join" | "leave" | null;
58
+ self: boolean;
59
+ }
60
+ export declare function circleMembers(app: App, cidOrName: string): Promise<{
61
+ circle: CircleSummary;
62
+ founder: string;
63
+ members: MemberRow[];
64
+ }>;
65
+ /**
66
+ * Sets (or with undefined unsets) the default circle. `byJoin`: a code join set it because there was
67
+ * none, so sessions already running don't move into it (sessions.ts getSession); the user's own
68
+ * `circle default` clears that, and sessions follow it again.
69
+ */
70
+ export declare function setDefaultCircle(app: App, cidOrName: string | undefined, opts?: {
71
+ byJoin?: boolean;
72
+ }): Promise<{
73
+ defaultCircle: string | null;
74
+ }>;
75
+ /** Signs the owner's next version, applies it here, and sends it out. */
76
+ export declare function ownerPublish(app: App, cid: string, p: NextVersionParams, opts?: {
77
+ alsoTo?: string[];
78
+ }): Promise<VerifiedCircleVersion>;
79
+ /** Sends the chain and every statement held to every member (and `extra`), and to our own devices. */
80
+ export declare function distribute(app: App, cid: string, extra?: readonly string[]): Promise<{
81
+ delivered: string[];
82
+ failed: string[];
83
+ }>;
84
+ export declare function deliverCircle(app: App, to: string, body: {
85
+ circles?: string[];
86
+ joins?: string[];
87
+ ops?: string[];
88
+ }, extraCaps?: string[]): Promise<Delivery>;
89
+ export declare function inviteToCircle(app: App, cidOrName: string, who: string): Promise<{
90
+ cid: string;
91
+ invited: string;
92
+ address: string;
93
+ added: boolean;
94
+ delivered: Delivery;
95
+ }>;
96
+ /**
97
+ * P4: adds `u`, who just redeemed one of our short codes for `cid`. The owner
98
+ * (on a key-holding device) publishes the next version at once, which
99
+ * distribution delivers to `u` too; an admin proposes the add to the owner
100
+ * and sends `u` the circle as it stands. Never drains (it runs while
101
+ * envelopes are being handled).
102
+ */
103
+ export declare function addMemberViaCode(app: App, cid: string, u: string): Promise<{
104
+ status: "added" | "already" | "proposed" | "failed";
105
+ name?: string;
106
+ reason?: string;
107
+ }>;
108
+ /** P4 `p2p remove`: takes `u` out of a circle we own (or proposes it as an admin). */
109
+ export declare function removeMember(app: App, cid: string, u: string): Promise<"removed" | "proposed" | "not-member" | "not-allowed">;
110
+ /** The co-member cap from `u`'s current join statement, for paths where we may no longer stand (leave, removal). */
111
+ export declare function memberCaps(c: LoadedCircle, u: string): string[];
112
+ export interface JoinResult {
113
+ status: "joined" | "waiting" | "unconfirmed" | "already" | "refused";
114
+ /** status "refused": why (JoinInput.accept). */
115
+ refused?: string;
116
+ cid: string;
117
+ name: string;
118
+ owner: string;
119
+ ownerAddress: string;
120
+ founder: string;
121
+ inviter?: string;
122
+ ownershipChanged: boolean;
123
+ policy: CirclePolicy;
124
+ confirmation?: "confirmed" | "owner-only" | "unconfirmed";
125
+ asked: string[];
126
+ answered: string[];
127
+ delivered?: Delivery[];
128
+ openWarning?: boolean;
129
+ }
130
+ export interface JoinInput {
131
+ head: string;
132
+ chain?: string[];
133
+ joins?: string[];
134
+ inviter?: string;
135
+ hint?: CircleHint;
136
+ /**
137
+ * Checked on the head actually joined (the newest consistent chain, which may be newer than the
138
+ * offered head) before anything is stored: a reason refuses the join (status "refused"). A code
139
+ * join passes its own rules here (codes.ts), so a circle that turned open, or changed hands or
140
+ * name, since the code was made is never joined from it.
141
+ */
142
+ accept?: (head: VerifiedCircleVersion) => string | undefined;
143
+ }
144
+ /**
145
+ * Stores a confirmer's answer for a pending join; true when it matched one. An answer can span
146
+ * several envelopes (a chunked bundle, each marked `part` i of n): versions accumulate, the parts
147
+ * received are recorded so the join knows when the answer is whole, and a part carrying only
148
+ * statements names its circle with `cid`.
149
+ */
150
+ export declare function recordJoinAnswer(app: App, from: string, versions: readonly string[], joins: readonly string[], opts?: {
151
+ cid?: string;
152
+ part?: AnswerPart;
153
+ }): Promise<boolean>;
154
+ /** The highest version `n` such that `versions` hold every version of their circle from 1 to `n` (0: none). */
155
+ export declare function contiguousTop(versions: readonly string[] | undefined): number;
156
+ /**
157
+ * Whether a confirmer's answer is whole (§3.3): it holds every version from 1 up to the offered
158
+ * head's `ver` (a prefix of the chain confirms nothing), and, when it came in marked parts, every
159
+ * part of one answer that reached that far arrived, statements included. An unmarked answer (one
160
+ * envelope, or an older member) counts once its versions reach the offered head.
161
+ */
162
+ export declare function answerComplete(versions: readonly string[] | undefined, parts: Record<string, AnswerPartsRec> | undefined, offeredVer: number): boolean;
163
+ /** How old an unanswered request for a circle's history is before a join asks again. */
164
+ export declare const JOIN_REASK_MS = 60000;
165
+ export declare function joinCircle(app: App, input: JoinInput, opts?: {
166
+ waitSec?: number;
167
+ yes?: boolean;
168
+ confirm?: (q: string) => Promise<boolean>;
169
+ }): Promise<JoinResult>;
170
+ export declare function joinFromLink(app: App, link: string, opts: {
171
+ waitSec?: number;
172
+ yes?: boolean;
173
+ confirm?: (q: string) => Promise<boolean>;
174
+ allowPrivateRelay?: boolean;
175
+ }): Promise<JoinResult>;
176
+ export declare function joinFromHeld(app: App, item: HeldItem, opts: {
177
+ waitSec?: number;
178
+ yes?: boolean;
179
+ confirm?: (q: string) => Promise<boolean>;
180
+ }): Promise<JoinResult>;
181
+ /**
182
+ * Open circles (P2, pre-release review M4): re-sign our join (n+1, a fresh cap of at
183
+ * most 14 days) when the owner removed anyone since our cap was issued, when
184
+ * the cap outlives 14 days, or when it lapses within 3 days; revoke the old
185
+ * cap at its relays, and tell the members. Returns how many were renewed.
186
+ */
187
+ export declare function renewOpenJoinCaps(app: App): Promise<number>;
188
+ /**
189
+ * §3.2 block, for circles: the blocked user holds our join cap (sub "*"), so
190
+ * revoking friend caps alone doesn't stop it reaching our mailbox. In every
191
+ * joined circle that lists them, re-sign our join with a fresh cap, revoke the
192
+ * old one at its relays, and send the new statement to the other members
193
+ * (never to the blocked user). Returns the circles re-keyed.
194
+ */
195
+ export declare function rekeyJoinsExcluding(app: App, blocked: string): Promise<string[]>;
196
+ export declare function leaveCircle(app: App, cidOrName: string): Promise<{
197
+ cid: string;
198
+ left: boolean;
199
+ told: number;
200
+ }>;
201
+ export declare function propose(app: App, cidOrName: string, op: string, arg: string): Promise<{
202
+ cid: string;
203
+ op: string;
204
+ applied: boolean;
205
+ ver?: number;
206
+ sentTo?: string;
207
+ }>;
208
+ export declare function transfer(app: App, cidOrName: string, who: string | undefined, opts: {
209
+ accept?: boolean;
210
+ consent?: string;
211
+ }): Promise<Record<string, unknown>>;
212
+ export declare function setPolicy(app: App, cidOrName: string, policy: string): Promise<{
213
+ cid: string;
214
+ policy: CirclePolicy;
215
+ ver: number;
216
+ }>;
217
+ /**
218
+ * §3.3 "the owner may also set a policy to hold proposals for approval":
219
+ * a local, per-circle setting on the owner's devices. While on, admins'
220
+ * proposals and rotated members (§2.8) wait in `p2p held` for the owner.
221
+ */
222
+ export declare function setCircleHold(app: App, cidOrName: string, on: boolean | undefined): Promise<{
223
+ cid: string;
224
+ hold: boolean;
225
+ }>;
226
+ /** Owner: approves a held join request. */
227
+ export declare function approveJoinRequest(app: App, item: HeldItem): Promise<{
228
+ cid: string;
229
+ added: string;
230
+ ver: number;
231
+ }>;
232
+ export declare function onCircleEnvelope(app: App, env: string, r: AcceptedMessageV3, relay: string): Promise<NewEvent[]>;
233
+ /**
234
+ * Answers to one asker's `want`s per rolling hour (all circles; members too, review M1). The byte
235
+ * budgets (per asker, per circle, the non-member pools) are what bound the cost; this only caps
236
+ * how often. 3 was too few: a member who leaves and joins again a few times in an hour (each join
237
+ * needs an answer) was refused, and could not join until the hour passed (pre-release soak, seed 21).
238
+ */
239
+ export declare const ANSWERS_PER_ASKER_PER_HOUR = 10;
240
+ export interface WantAnswersDoc {
241
+ /** When each asker was answered. */
242
+ by: Record<string, number[]>;
243
+ /** Bytes sent to each asker. */
244
+ bytes: Record<string, {
245
+ at: number;
246
+ bytes: number;
247
+ }[]>;
248
+ /** Bytes sent to non-members, all together, by pool (`reserve`: their want carried a valid proof of work; `open`: it didn't). */
249
+ sent: {
250
+ at: number;
251
+ bytes: number;
252
+ pool?: "reserve" | "open" | "link";
253
+ }[];
254
+ /** Proofs of work already used this hour (each counts once). */
255
+ pows?: {
256
+ id: string;
257
+ at: number;
258
+ }[];
259
+ /** The highest version sent to `asker|cid`, when, and whether it was already sent again once. */
260
+ last: Record<string, {
261
+ ver: number;
262
+ at: number;
263
+ resent?: boolean;
264
+ }>;
265
+ /** Bytes sent to members of each circle, all together (re-review N2), by cid. */
266
+ members?: Record<string, {
267
+ at: number;
268
+ bytes: number;
269
+ }[]>;
270
+ /** When a device of ours last refused `asker|cid` (ms; review F2): the others don't answer it either. */
271
+ refused?: Record<string, number>;
272
+ }
273
+ /** Askers (or asker|circle pairs) whose answer records are kept, the most recent first (review N-B). */
274
+ export declare const MAX_ANSWER_ASKERS = 2048;
275
+ /** Circles whose member pools are kept. */
276
+ export declare const MAX_ANSWER_CIRCLES = 512;
277
+ /** Entries per pool list before the oldest are folded into one. */
278
+ export declare const MAX_POOL_ENTRIES = 4096;
279
+ export type AnswerAllowance = {
280
+ ok: true;
281
+ bytes: number;
282
+ } | {
283
+ ok: false;
284
+ why: string;
285
+ };
286
+ /** Who an answer is for: a member of the head, or a non-member whose want carried a valid proof of work (`reserve`), or neither (`open`). */
287
+ export type AnswerPool = "member" | "reserve" | "open";
288
+ /** What `asker` may still be sent this hour, checked before anything is built or fetched (review L4). Charges nothing. */
289
+ export declare function answerAllowance(app: App, asker: string, pool: AnswerPool, cid: string): Promise<AnswerAllowance & {
290
+ last: WantAnswersDoc["last"];
291
+ pows: Set<string>;
292
+ }>;
293
+ /**
294
+ * Charges one answer of `bytes` to `asker` (and to the non-member pool), re-checking the limits
295
+ * under the lock, and records the highest version sent (`ver`) for `cid`. Refused when another
296
+ * answer spent the budget meanwhile.
297
+ */
298
+ /** What one charge recorded, so an answer that didn't go out can be refunded (refundAnswer). */
299
+ export interface AnswerReceipt {
300
+ asker: string;
301
+ pool: AnswerPool;
302
+ cid: string;
303
+ at: number;
304
+ bytes: number;
305
+ pow?: string;
306
+ /** `last` for asker|cid before the charge (undefined: none). */
307
+ prevLast?: {
308
+ ver: number;
309
+ at: number;
310
+ resent?: boolean;
311
+ };
312
+ }
313
+ export declare function chargeAnswer(app: App, asker: string, pool: AnswerPool, bytes: number, mark?: {
314
+ cid: string;
315
+ ver: number;
316
+ resent: boolean;
317
+ pow?: string;
318
+ }): Promise<AnswerAllowance & {
319
+ receipt?: AnswerReceipt;
320
+ }>;
321
+ /**
322
+ * Settles a charge with what actually went out (pre-release review N-A, review P1): the bytes this member
323
+ * wrote to the wire (each part's sealed size times the relays it was written to, whatever they
324
+ * replied: a relay can store a part and answer an error), never less than ANSWER_ATTEMPT_MIN_BYTES, stay charged
325
+ * against the asker and the pools; only the undelivered remainder comes back. `last` goes back to
326
+ * what it was when the answer didn't fully go out, so the asker may ask for the rest without
327
+ * being refused as a resend; the proof of work comes back only when nothing went out at all. An
328
+ * asker steering parts to a relay that drops one of them can't get the rest for free.
329
+ */
330
+ export declare const ANSWER_ATTEMPT_MIN_BYTES = 4096;
331
+ export declare function settleAnswer(app: App, r: AnswerReceipt, spent: number): Promise<void>;
332
+ /** Undoes a charge entirely (nothing went out). */
333
+ export declare function refundAnswer(app: App, r: AnswerReceipt): Promise<void>;
334
+ /**
335
+ * The parts of an answer from version `fromVer`, cut to `budget` bytes: whole versions in order,
336
+ * then the statements if everything up to the head fits; a cut answer always stops short of the
337
+ * head, so the answer that reaches it carries the statements. What doesn't fit is asked for again
338
+ * later (`fromVer`), so a chain larger than one hour's budget still gets through over hours.
339
+ */
340
+ export declare function answerParts(versions: readonly string[], statements: readonly string[], budget: number, cost: (plainBytes: number) => number): {
341
+ parts: {
342
+ circles: string[];
343
+ joins: string[];
344
+ }[];
345
+ bytes: number;
346
+ sentVersions: number;
347
+ };
348
+ /**
349
+ * The one device of ours that answers `want`s (review M3), chosen the same way on every device
350
+ * from our identity document: the lowest-sorting did among the key holders it lists (they hold
351
+ * every circle we own and sign its versions), else the lowest-sorting listed device.
352
+ */
353
+ export declare function answeringDevice(view: {
354
+ devices: readonly string[];
355
+ keyholders: readonly string[];
356
+ }): string | undefined;
357
+ /**
358
+ * This device's place in the answering order (re-review N6): 0 answers at once, rank r answers a
359
+ * want r fallback delays later if no device of ours has answered it by then (the order is the
360
+ * election's: key holders first, then the other listed devices, each lowest-sorting first). A
361
+ * device can't see what the others hold, so one that doesn't hold the circle just can't answer,
362
+ * and the next in line does. `undefined`: not listed (answer, as before).
363
+ */
364
+ export declare function answeringRank(view: {
365
+ devices: readonly string[];
366
+ keyholders: readonly string[];
367
+ }, did: string): number | undefined;
368
+ export interface DeferredWant {
369
+ from: string;
370
+ fdid: string;
371
+ want: {
372
+ cid: string;
373
+ fromVer: number;
374
+ };
375
+ relay: string;
376
+ cap?: string;
377
+ pow?: WantPow;
378
+ /** The want's envelope `ts` (ms; review F2), and when this device answers it if nobody has. */
379
+ at: number;
380
+ due: number;
381
+ }
382
+ /** At most this many wants wait for a fallback answer on one device (the oldest go first). */
383
+ export declare const MAX_DEFERRED_WANTS = 64;
384
+ /** At most this many from one asker (review F3). */
385
+ export declare const MAX_DEFERRED_PER_ASKER = 4;
386
+ /** A deferred want older than this (by its envelope's `ts`) is dropped unanswered (review F2). */
387
+ export declare const DEFERRED_WANT_MAX_AGE_MS: number;
388
+ /**
389
+ * Answers the deferred wants that are due (re-review N6), unless a device of ours answered or
390
+ * refused that asker about that circle since (the synced `wantAnswers`), and drops those too old
391
+ * to answer (review F2). The answer re-checks everything, the proof of work's window included.
392
+ */
393
+ export declare function answerDeferredWants(app: App): Promise<number>;
394
+ /** Merges our other devices' answer and refusal records into this device's (sync.ts): every budget and pool is shared. */
395
+ export declare function importWantAnswered(app: App, recs: unknown): Promise<void>;
396
+ /** Records a refusal here and tells our other devices, at most once per asker and circle every 10 minutes. */
397
+ export declare function noteRefused(app: App, asker: string, cid: string): Promise<void>;
398
+ /**
399
+ * What one answer envelope costs on the wire (review L2): sealing and two layers of base64 make it
400
+ * about 16/9 of its plaintext, plus ~3 KiB of certificate and fields, sent once to each relay.
401
+ */
402
+ export declare const sealedCost: (relays: number) => (plainBytes: number) => number;