@peer2peer/cli 0.1.2 → 0.1.4
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/README.md +10 -7
- package/dist/ancestry.d.ts +42 -2
- package/dist/ancestry.js +215 -32
- package/dist/app.d.ts +64 -2
- package/dist/app.js +188 -22
- package/dist/cli.d.ts +30 -3
- package/dist/cli.js +332 -8
- package/dist/config.d.ts +5 -0
- package/dist/doctor.d.ts +7 -0
- package/dist/doctor.js +102 -3
- package/dist/format.d.ts +5 -1
- package/dist/format.js +17 -1
- package/dist/identity.d.ts +6 -2
- package/dist/identity.js +36 -19
- package/dist/keystore.d.ts +223 -0
- package/dist/keystore.js +1021 -0
- package/dist/pretty.js +2 -1
- package/dist/procstart.js +11 -3
- package/dist/projects.d.ts +58 -12
- package/dist/projects.js +217 -49
- package/dist/rotation-lock.d.ts +17 -0
- package/dist/rotation-lock.js +188 -0
- package/dist/rotation.d.ts +46 -1
- package/dist/rotation.js +408 -16
- package/dist/sandbox.d.ts +195 -0
- package/dist/sandbox.js +763 -0
- package/dist/state.d.ts +8 -0
- package/dist/state.js +12 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/watch.js +43 -13
- package/package.json +3 -3
package/dist/state.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { GraphMemoryDoc } from "./graph-memory.js";
|
|
|
6
6
|
import { type LockOptions } from "@peer2peer/core/v3/node";
|
|
7
7
|
import type { DocBackend, RotationStatement, StatusBody } from "@peer2peer/core/v3";
|
|
8
8
|
import { type Progress } from "./progress.js";
|
|
9
|
+
import { KeyStoreBackend } from "./keystore.js";
|
|
9
10
|
export interface KeysDoc {
|
|
10
11
|
v: 1;
|
|
11
12
|
userId: string;
|
|
@@ -414,6 +415,11 @@ type Docs = {
|
|
|
414
415
|
ixNotice: {
|
|
415
416
|
at: number;
|
|
416
417
|
};
|
|
418
|
+
/** When a front end showed the one-time notice to deny P2P_HOME to its agent's sandbox (sandbox.ts), per front end. */
|
|
419
|
+
sandboxNotice: {
|
|
420
|
+
claude?: number;
|
|
421
|
+
codex?: number;
|
|
422
|
+
};
|
|
417
423
|
/** Graph memory (graph-memory.ts): this device's sessions' context waiting for the local Ix graph, and counters. */
|
|
418
424
|
graphMemory: GraphMemoryDoc;
|
|
419
425
|
};
|
|
@@ -448,6 +454,8 @@ export declare class CliState {
|
|
|
448
454
|
constructor(dir: string, progress?: Progress | undefined,
|
|
449
455
|
/** `p2p doctor`: an in-memory overlay (readonly.ts), so nothing is written to `dir`. */
|
|
450
456
|
backend?: CliBackend, lockOpts?: Partial<LockOptions>);
|
|
457
|
+
/** The key store in front of this state's documents (keystore.ts). */
|
|
458
|
+
get keyStore(): KeyStoreBackend;
|
|
451
459
|
get<K extends keyof Docs>(name: K): Promise<Docs[K] | undefined>;
|
|
452
460
|
/** Read-modify-write under the cross-process lock. Return `undefined` as `next` to leave it. */
|
|
453
461
|
/**
|
package/dist/state.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// Every read-modify-write runs under the lock, so `p2p watch` and short
|
|
6
6
|
// commands can run at the same time.
|
|
7
7
|
//
|
|
8
|
-
// keys this device's secrets (and the identity seed on key holders)
|
|
8
|
+
// keys this device's secrets (and the identity seed on key holders); with the keychain backend
|
|
9
|
+
// only the public part, the secrets in the OS keychain (keystore.ts)
|
|
9
10
|
// self name, relays, did, the default circle
|
|
10
11
|
// sessions own session rosters, by sid
|
|
11
12
|
// seq envelope sequence counters, by (own, sid)
|
|
@@ -35,11 +36,14 @@
|
|
|
35
36
|
// projects project policies (projects.ts): shared with circles and people, or private (the default)
|
|
36
37
|
// sessionProjects the projects each session worked in (projects.ts), by sid
|
|
37
38
|
// ixNotice when the one-time "Ix on by default" notice was shown (ix-local.ts)
|
|
39
|
+
// sandboxNotice when a front end showed the one-time "deny P2P_HOME to your agent's sandbox" notice (sandbox.ts)
|
|
38
40
|
// graphMemory graph memory (graph-memory.ts): what was recorded of each own session, the bounded queue, counters
|
|
39
41
|
// history, history-<n> message history (history.ts): sealed with the key in history.key, never plaintext
|
|
40
42
|
import { join } from "node:path";
|
|
41
43
|
import { FileDocBackend } from "@peer2peer/core/v3/node";
|
|
42
44
|
import { debug, step } from "./progress.js";
|
|
45
|
+
import { KeyStoreBackend } from "./keystore.js";
|
|
46
|
+
import { OverlayDocBackend } from "./readonly.js";
|
|
43
47
|
export const sessKey = (own, sid) => `${own}|${sid}`;
|
|
44
48
|
/** Events older than this, or beyond the count cap, are pruned. */
|
|
45
49
|
export const EVENT_RETENTION_MS = 7 * 24 * 3600 * 1000;
|
|
@@ -93,7 +97,13 @@ export class CliState {
|
|
|
93
97
|
backend, lockOpts = {}) {
|
|
94
98
|
this.dir = dir;
|
|
95
99
|
this.progress = progress;
|
|
96
|
-
|
|
100
|
+
// The keys document goes through the key store (keystore.ts): the OS keychain when this home chose it.
|
|
101
|
+
// `p2p doctor`'s overlay keeps every write in memory: so does the key store (no keychain write, no file touched).
|
|
102
|
+
this.backend = new KeyStoreBackend(backend ?? new FileDocBackend(join(dir, "cli"), lockOpts), dir, { memoryOnly: backend instanceof OverlayDocBackend });
|
|
103
|
+
}
|
|
104
|
+
/** The key store in front of this state's documents (keystore.ts). */
|
|
105
|
+
get keyStore() {
|
|
106
|
+
return this.backend;
|
|
97
107
|
}
|
|
98
108
|
async get(name) {
|
|
99
109
|
return (await this.backend.read(name));
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.4";
|
package/dist/version.js
CHANGED
package/dist/watch.js
CHANGED
|
@@ -22,7 +22,7 @@ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
|
22
22
|
import { join } from "node:path";
|
|
23
23
|
import { certExpiresWithin, mayRepublish, nowSec } from "@peer2peer/core/v3";
|
|
24
24
|
import { CLOSE_GRACE_MS, REPUBLISH_DOC_WITHIN_SEC } from "./app.js";
|
|
25
|
-
import { receiving } from "./inbound.js";
|
|
25
|
+
import { makeEvent, receiving } from "./inbound.js";
|
|
26
26
|
import { answerDeferredWants, renewOpenJoinCaps } from "./circle-ops.js";
|
|
27
27
|
import { checkSid, expireSubs } from "./sessions.js";
|
|
28
28
|
import { CliError } from "./errors.js";
|
|
@@ -293,6 +293,43 @@ export async function refreshContacts(app) {
|
|
|
293
293
|
await retryRotationJoins(app).catch(() => []);
|
|
294
294
|
await app.adoptCertFromDoc();
|
|
295
295
|
}
|
|
296
|
+
/** Whether the head's document or one of its device certificates is due for renewal. */
|
|
297
|
+
function renewalDue(head, now) {
|
|
298
|
+
const certSoon = (head.certs ?? []).some((c) => {
|
|
299
|
+
try {
|
|
300
|
+
const exp = JSON.parse(Buffer.from(c.split(".")[1], "base64url").toString()).exp;
|
|
301
|
+
return certExpiresWithin({ exp }, 30 * 86_400, now);
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
return certSoon || head.exp - now <= REPUBLISH_DOC_WITHIN_SEC;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* #78 review: the strict refresh before a renewal was refused because a relay that doesn't answer sent a newer
|
|
311
|
+
* version of our identity earlier (App.ownPendingGuard). Never silent: a warning on every run, and once the
|
|
312
|
+
* renewal is due, a `p2p.alert` (`what: "renewal-held"`) for the mod's status line, raised again each day
|
|
313
|
+
* left, so it escalates as the document nears expiry instead of letting it lapse unnoticed.
|
|
314
|
+
*/
|
|
315
|
+
async function renewalHeld(app, e) {
|
|
316
|
+
const heldBy = e.extra.heldBy.filter((r) => typeof r === "string");
|
|
317
|
+
const v = await app.ownView();
|
|
318
|
+
const now = nowSec();
|
|
319
|
+
const daysLeft = Math.max(0, Math.floor((v.head.exp - now) / 86_400));
|
|
320
|
+
const fix = `try again when ${heldBy.length === 1 ? "it answers" : "they answer"}, or remove ${heldBy.length === 1 ? "it" : "them"} (\`p2p relays remove ${heldBy.join(" ")}\`) if gone for good or no device of yours published that version; \`p2p doctor\` shows the details`;
|
|
321
|
+
app.warn(`can't renew your identity document (expires in ${daysLeft} days): ${heldBy.join(", ")} didn't answer and earlier sent a newer version of it; ${fix}`);
|
|
322
|
+
if (!renewalDue(v.head, now))
|
|
323
|
+
return;
|
|
324
|
+
await app.state.addEvents([
|
|
325
|
+
makeEvent(`renewal-held|${v.head.hash}|${daysLeft}`, "p2p.alert", Date.now(), {
|
|
326
|
+
from: { userId: app.userId, did: app.did, address: await app.addressOf(app.userId), self: true },
|
|
327
|
+
what: "renewal-held",
|
|
328
|
+
daysLeft,
|
|
329
|
+
heldBy,
|
|
330
|
+
}),
|
|
331
|
+
]);
|
|
332
|
+
}
|
|
296
333
|
/** Key holders keep the document and certificates fresh (§2.3 renewal, §2.5 re-publish, single writer). */
|
|
297
334
|
export async function maintain(app) {
|
|
298
335
|
if (!app.isKeyholder) {
|
|
@@ -304,25 +341,18 @@ export async function maintain(app) {
|
|
|
304
341
|
await app.refreshIdentity(app.userId, app.relays, { force: true, strict: true });
|
|
305
342
|
}
|
|
306
343
|
catch (e) {
|
|
307
|
-
if (e instanceof CliError)
|
|
344
|
+
if (e instanceof CliError) {
|
|
345
|
+
if (Array.isArray(e.extra.heldBy))
|
|
346
|
+
await renewalHeld(app, e).catch(() => undefined);
|
|
308
347
|
return;
|
|
348
|
+
}
|
|
309
349
|
throw e;
|
|
310
350
|
}
|
|
311
351
|
const v = await app.ownView();
|
|
312
352
|
if (!v.devices.includes(app.did) || !v.keyholders.includes(app.did))
|
|
313
353
|
return;
|
|
314
354
|
const now = nowSec();
|
|
315
|
-
|
|
316
|
-
try {
|
|
317
|
-
const exp = JSON.parse(Buffer.from(c.split(".")[1], "base64url").toString()).exp;
|
|
318
|
-
return certExpiresWithin({ exp }, 30 * 86_400, now);
|
|
319
|
-
}
|
|
320
|
-
catch {
|
|
321
|
-
return false;
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
const docSoon = v.head.exp - now <= REPUBLISH_DOC_WITHIN_SEC;
|
|
325
|
-
if ((docSoon || certSoon) && mayRepublish(app.did, v.head, now)) {
|
|
355
|
+
if (renewalDue(v.head, now) && mayRepublish(app.did, v.head, now)) {
|
|
326
356
|
await app.publishNext(() => { }).catch((e) => {
|
|
327
357
|
if (!(e instanceof CliError))
|
|
328
358
|
throw e;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peer2peer/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "The standalone Peer2Peer v3 CLI (`p2p`): an account-free identity, friends, circles, end-to-end encrypted session messaging and status over open relays",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"peer2peer",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"registry": "https://registry.npmjs.org/"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@peer2peer/codex-bridge": "0.1.
|
|
57
|
-
"@peer2peer/core": "0.1.
|
|
56
|
+
"@peer2peer/codex-bridge": "0.1.4",
|
|
57
|
+
"@peer2peer/core": "0.1.4",
|
|
58
58
|
"commander": "15.0.0",
|
|
59
59
|
"uqr": "0.1.3",
|
|
60
60
|
"ws": "8.22.0"
|