@peer2peer/cli 0.1.2 → 0.1.3
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 +8 -6
- package/dist/ancestry.d.ts +42 -2
- package/dist/ancestry.js +215 -32
- package/dist/app.d.ts +44 -2
- package/dist/app.js +116 -15
- package/dist/cli.d.ts +30 -3
- package/dist/cli.js +133 -8
- package/dist/doctor.js +29 -1
- package/dist/format.d.ts +2 -0
- package/dist/format.js +5 -1
- package/dist/identity.d.ts +6 -2
- package/dist/identity.js +34 -19
- package/dist/pretty.js +2 -1
- package/dist/projects.d.ts +58 -12
- package/dist/projects.js +220 -48
- package/dist/rotation.d.ts +20 -1
- package/dist/rotation.js +280 -14
- 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/app.js
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
// next version of our own), sealing and delivering envelopes (§4.1, §5.4,
|
|
10
10
|
// §5.8), finding caps, resolving addresses and petnames, and syncing state to
|
|
11
11
|
// the user's other devices.
|
|
12
|
-
import { personTokenOk } from "./projects.js";
|
|
12
|
+
import { identityHere, personTokenMatchesKeys, personTokenOk } from "./projects.js";
|
|
13
13
|
import { confirmOnTty } from "./tty-confirm.js";
|
|
14
14
|
import { hostname, userInfo } from "node:os";
|
|
15
|
-
import { addIdentityVersion, b64uDecode, b64uEncode, capAllowsKind, CircleChain, createCap, createDeviceCert, createIdentityDoc, decodeTyped, deviceKeysV3FromSecrets, displayAddress, displayFingerprint, getIdentityView, MAX_DEVICES, mergeFields, mergePrevTip, scheduledWriter, refreshIdentity as coreRefreshIdentity, unconnectedRelaysOf, unconnectedVersionsOf, IdentityChain, identityKeyFromSeed, isUserId, isValidName, nowSec, P2PError, peekIdentityDoc, canonicalRelayUrl, sealEnvelopeV3, storeCertResolver, storeSignerContext, TYP3, verifyDeviceCertV3, verifyRotationSignatures, } from "@peer2peer/core/v3";
|
|
15
|
+
import { addIdentityVersion, b64uDecode, b64uEncode, capAllowsKind, CircleChain, createCap, createDeviceCert, createIdentityDoc, decodeTyped, deviceKeysV3FromSecrets, displayAddress, displayFingerprint, getIdentityView, MAX_DEVICES, mergeFields, mergePrevTip, scheduledWriter, refreshIdentity as coreRefreshIdentity, heldBackByOf, unconnectedRelaysOf, unconnectedVersionsOf, IdentityChain, identityKeyFromSeed, isUserId, isValidName, nowSec, P2PError, peekIdentityDoc, pendingHeadSenders, canonicalRelayUrl, sealEnvelopeV3, storeCertResolver, storeSignerContext, TYP3, verifyDeviceCertV3, verifyRotationSignatures, } from "@peer2peer/core/v3";
|
|
16
16
|
import { FileDocBackend, FileTrustStoreV3 } from "@peer2peer/core/v3/node";
|
|
17
17
|
import { OverlayDocBackend, ReadOnlyTrustStoreV3 } from "./readonly.js";
|
|
18
18
|
import { basename, join } from "node:path";
|
|
@@ -44,6 +44,16 @@ const CAP_PRIORITY = (c) => (c.kinds[0] === "*" ? 0 : 1);
|
|
|
44
44
|
export class App {
|
|
45
45
|
/** The person's front end vouched for this command (P2P_PERSON_TOKEN, checked once and removed: projects.ts). */
|
|
46
46
|
front = false;
|
|
47
|
+
/**
|
|
48
|
+
* The token `front` rests on, kept in memory (never in the environment), so the keys this command
|
|
49
|
+
* loads are checked against it (load): a home whose files change after the start never lends the
|
|
50
|
+
* token to other keys. Undefined for an embedder that vouches without one.
|
|
51
|
+
*/
|
|
52
|
+
frontToken;
|
|
53
|
+
/** The home held no identity when the token was checked (a front end's first run). */
|
|
54
|
+
frontFresh = false;
|
|
55
|
+
/** This command made, restored or swapped in the identity it holds (init, link join, restore, a rotation's swap). */
|
|
56
|
+
identityMadeHere = false;
|
|
47
57
|
/** The person's "yes" on their controlling terminal (tty-confirm.ts); cli.ts may stand another in (tests). */
|
|
48
58
|
confirmTty = confirmOnTty;
|
|
49
59
|
env;
|
|
@@ -98,6 +108,10 @@ export class App {
|
|
|
98
108
|
// An embedder holding the person token is a front end (the CLI's main() checks and removes it first,
|
|
99
109
|
// then sets this from its own check).
|
|
100
110
|
this.front = personTokenOk(this.env, this.home);
|
|
111
|
+
if (this.front) {
|
|
112
|
+
this.frontToken = this.env.P2P_PERSON_TOKEN?.trim();
|
|
113
|
+
this.frontFresh = !identityHere(this.home);
|
|
114
|
+
}
|
|
101
115
|
// Progress and P2P_DEBUG lines go to stderr (never secrets: see progress.ts).
|
|
102
116
|
this.progress = { ...makeProgress(opts.env, (m) => opts.io.err(`p2p: ${m}`)), signal: this.abort.signal };
|
|
103
117
|
this.readOnly = opts.readOnly === true;
|
|
@@ -120,9 +134,24 @@ export class App {
|
|
|
120
134
|
throw new CliError("no_identity", "no identity here yet: run `p2p init` (or `p2p link join` / `p2p backup restore`)");
|
|
121
135
|
return false;
|
|
122
136
|
}
|
|
137
|
+
this.checkFrontKeys(keys);
|
|
123
138
|
this.setKeys(keys, self);
|
|
124
139
|
return true;
|
|
125
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* The person token this command was given must be the one these keys derive (projects.ts
|
|
143
|
+
* personTokenMatchesKeys), unless this command made the identity itself. A home that had no
|
|
144
|
+
* identity when the token was checked, and has one now that this command didn't make, never
|
|
145
|
+
* keeps it. Otherwise the command stops: the home changed under it.
|
|
146
|
+
*/
|
|
147
|
+
checkFrontKeys(keys) {
|
|
148
|
+
if (!this.front || this.frontToken === undefined || this.identityMadeHere)
|
|
149
|
+
return;
|
|
150
|
+
if (!this.frontFresh && personTokenMatchesKeys(this.home, keys.spk, this.frontToken))
|
|
151
|
+
return;
|
|
152
|
+
this.front = false;
|
|
153
|
+
throw new CliError("refused", `the person token doesn't belong to the identity ${this.home} holds now (its files changed while the command ran): it stopped here. Run it again`);
|
|
154
|
+
}
|
|
126
155
|
setKeys(keys, self) {
|
|
127
156
|
this.keys = keys;
|
|
128
157
|
this.self = self;
|
|
@@ -417,13 +446,25 @@ export class App {
|
|
|
417
446
|
* Network I/O for core's refreshIdentity (§5.6), per relay so core can cap
|
|
418
447
|
* each relay's answer on its own: `tips` and the `chain` walk
|
|
419
448
|
* (`/v3/identity/<id>/chain?to=&n=`) on every listed relay (at most 5).
|
|
449
|
+
*
|
|
450
|
+
* #78: a relay that couldn't be reached (an error or a timeout) is left out of the answer, and when none
|
|
451
|
+
* of the relays asked answered the call fails, so core counts it as a relay that didn't answer (core asks
|
|
452
|
+
* one relay per call), never as one that answered "nothing": its silence doesn't make up a majority that
|
|
453
|
+
* clears pending heads or counts as fresh, and a relay is never named as forging over a gap the silent
|
|
454
|
+
* one wasn't really asked about.
|
|
420
455
|
*/
|
|
421
456
|
fetcher() {
|
|
422
457
|
const t = this.tun.connectTimeoutMs;
|
|
423
458
|
const perRelay = async (relays, get) => {
|
|
424
459
|
const list = [...new Set(relays)].slice(0, 5);
|
|
425
|
-
const answers = await Promise.
|
|
426
|
-
|
|
460
|
+
const answers = await Promise.allSettled(list.map((r) => get(r)));
|
|
461
|
+
const ok = list.flatMap((r, i) => {
|
|
462
|
+
const a = answers[i];
|
|
463
|
+
return a.status === "fulfilled" ? [[r, a.value]] : [];
|
|
464
|
+
});
|
|
465
|
+
if (list.length > 0 && ok.length === 0)
|
|
466
|
+
throw answers[0].reason;
|
|
467
|
+
return Object.fromEntries(ok);
|
|
427
468
|
};
|
|
428
469
|
return {
|
|
429
470
|
tips: (userId, relays) => perRelay(relays, (r) => fetchTips(this.transport(r), userId, t, this.progress, this.guardedLookup(r))),
|
|
@@ -451,8 +492,11 @@ export class App {
|
|
|
451
492
|
throw new CliError("refresh_failed", `no relays to refresh ${userId} from`);
|
|
452
493
|
return held;
|
|
453
494
|
}
|
|
454
|
-
const
|
|
495
|
+
const own = userId === this.keys?.userId;
|
|
496
|
+
const refreshFrom = (rs) => step(this.progress, `refreshing ${userId}'s identity document from ${rs.join(", ")}`, () => coreRefreshIdentity(this.store, userId, this.fetcher(), { relays: rs, own }));
|
|
455
497
|
let v;
|
|
498
|
+
/** #78: the relays core named as serving versions that don't connect (a forged chain's). */
|
|
499
|
+
let named = [];
|
|
456
500
|
try {
|
|
457
501
|
v = await refreshFrom(list);
|
|
458
502
|
}
|
|
@@ -461,12 +505,14 @@ export class App {
|
|
|
461
505
|
throw e;
|
|
462
506
|
// Strict callers (publishing our own next version) must not build on a head they couldn't confirm.
|
|
463
507
|
if (opts.strict) {
|
|
464
|
-
|
|
508
|
+
// #79: relays core held the refresh back for count like the ones it names (see the incomplete case below).
|
|
509
|
+
const unconnected = [...new Set([...unconnectedRelaysOf(e), ...(own ? heldBackByOf(e) : [])])];
|
|
465
510
|
const versions = unconnectedVersionsOf(e);
|
|
466
|
-
const
|
|
467
|
-
if (!
|
|
511
|
+
const fb = e.reason === "chain-broken" ? await this.ownStrictFallback(userId, list, unconnected, versions, opts.setAside, refreshFrom) : undefined;
|
|
512
|
+
if (!fb)
|
|
468
513
|
throw new CliError("refresh_failed", `couldn't confirm the current identity document on the relays (${e.reason}): not publishing on a possibly stale head${this.unconnectedHint(unconnected, versions, userId)}`);
|
|
469
|
-
v =
|
|
514
|
+
v = fb;
|
|
515
|
+
named = unconnected;
|
|
470
516
|
}
|
|
471
517
|
else {
|
|
472
518
|
if (e.reason === "chain-broken" && held && !opts.quiet) {
|
|
@@ -482,11 +528,18 @@ export class App {
|
|
|
482
528
|
this.warn(`refreshing ${await this.addressOf(userId)}'s identity document was cut short; using what was held before (try again)`);
|
|
483
529
|
return held;
|
|
484
530
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
531
|
+
// #79: relays core held the refresh back for (they sent a version of our identity that doesn't connect to
|
|
532
|
+
// a current one we hold and lists more than it) count like the relays it names as serving versions that
|
|
533
|
+
// don't connect: a rotation sets them aside, any other edit refuses and names them.
|
|
534
|
+
const unconnected = [...new Set([...(v.unconnectedRelays ?? []), ...(own ? (v.heldBackBy ?? []) : [])])];
|
|
535
|
+
const fb = await this.ownStrictFallback(userId, list, unconnected, v.unconnectedVersions ?? [], opts.setAside, refreshFrom);
|
|
536
|
+
if (!fb)
|
|
537
|
+
throw new CliError("refresh_failed", `refreshing the identity document was cut short; try again${this.unconnectedHint(unconnected, v.unconnectedVersions ?? [], userId)}`);
|
|
538
|
+
named = unconnected;
|
|
539
|
+
v = fb;
|
|
489
540
|
}
|
|
541
|
+
if (opts.strict && own)
|
|
542
|
+
await this.ownPendingGuard(userId, list, v, named, opts.setAside);
|
|
490
543
|
// Recorded moments ago by another p2p process of this home (a watch and a command refresh
|
|
491
544
|
// the same people in a burst): no write. Only ever leaves the time a little older, so the
|
|
492
545
|
// next refresh comes no later.
|
|
@@ -537,8 +590,7 @@ export class App {
|
|
|
537
590
|
* none), never one whose genuine gap the walk merely didn't reach. And the confirmed head must not be
|
|
538
591
|
* below any version the full refresh left unconnected, unless every relay that sent that version is set
|
|
539
592
|
* aside: a lagging kept relay can't "confirm" a stale head while another relay serves a newer version.
|
|
540
|
-
* (
|
|
541
|
-
* version shows it in this refresh.)
|
|
593
|
+
* (A newer version an earlier refresh stored as a pending head, from a relay silent now: ownPendingGuard.)
|
|
542
594
|
* Returns the view, or undefined when this doesn't apply (the caller then refuses as before).
|
|
543
595
|
*/
|
|
544
596
|
async ownStrictFallback(userId, list, unconnected, versions, setAside, refreshFrom) {
|
|
@@ -569,6 +621,49 @@ export class App {
|
|
|
569
621
|
}
|
|
570
622
|
return v;
|
|
571
623
|
}
|
|
624
|
+
/**
|
|
625
|
+
* #78: a strict refresh of our own identity skips relays that don't answer, so a lagging relay could
|
|
626
|
+
* "confirm" a stale head while the up-to-date one times out. This device may already hold the newer
|
|
627
|
+
* version, as a pending head an earlier, incomplete refresh recorded with the relays that sent it. Refuses
|
|
628
|
+
* when a pending head above the confirmed head was sent by a relay that:
|
|
629
|
+
* - is still listed and isn't set aside by this edit (`setAside.relays`: the relays it removes), so
|
|
630
|
+
* `p2p relays remove` always gets past a relay that holds the owner up. A pending head another relay
|
|
631
|
+
* sent too still holds the edit up while that one is silent (#78 re-review: removing a relay that
|
|
632
|
+
* replayed an honest relay's version, and now withholds it, mustn't fork against it); silent relays
|
|
633
|
+
* that hold each other up are removed together (`relays remove` takes several);
|
|
634
|
+
* - wasn't named as serving versions that don't connect (a forged chain's, core's unconnectedRelays);
|
|
635
|
+
* - didn't answer this refresh: a relay that answered gave its current tips, so what it still serves is
|
|
636
|
+
* already in this refresh (connected, or the refresh failed or was cut short), and what it no longer
|
|
637
|
+
* serves doesn't hold the owner up.
|
|
638
|
+
* So one relay can hold an edit up only while it stays silent, and only with a version signed with the
|
|
639
|
+
* identity key above the head the other relays confirm (a genuine newer version, which building below would
|
|
640
|
+
* fork, or a thief's); removing that relay always goes ahead. A pending head stored without its senders
|
|
641
|
+
* (older builds), expired, or not a valid version of this identity never holds an edit up.
|
|
642
|
+
*/
|
|
643
|
+
async ownPendingGuard(userId, list, v, named, setAside) {
|
|
644
|
+
const stored = await this.store.getIdentity(userId);
|
|
645
|
+
if (!stored)
|
|
646
|
+
return;
|
|
647
|
+
const heard = new Set(v.answeredRelays);
|
|
648
|
+
const skip = new Set([...(setAside?.relays ?? []), ...named]);
|
|
649
|
+
const silent = new Set();
|
|
650
|
+
let newest = 0;
|
|
651
|
+
for (const p of pendingHeadSenders(stored)) {
|
|
652
|
+
if (p.ver <= v.head.ver)
|
|
653
|
+
continue;
|
|
654
|
+
const by = p.relays.filter((r) => list.includes(r) && !skip.has(r) && !heard.has(r));
|
|
655
|
+
if (by.length === 0)
|
|
656
|
+
continue;
|
|
657
|
+
for (const r of by)
|
|
658
|
+
silent.add(r);
|
|
659
|
+
newest = Math.max(newest, p.ver);
|
|
660
|
+
}
|
|
661
|
+
if (silent.size === 0)
|
|
662
|
+
return;
|
|
663
|
+
const rs = [...silent];
|
|
664
|
+
const one = rs.length === 1;
|
|
665
|
+
throw new CliError("refresh_failed", `${rs.join(", ")} didn't answer, and ${one ? "it" : "they"} earlier sent a newer version of your identity (ver ${newest}) than the relays that answered confirm (ver ${v.head.ver}): not publishing on a possibly stale head. Try again when ${one ? "it answers" : "they answer"}; if ${one ? "that relay is" : "those relays are"} gone for good, or no device of yours published that version, remove ${one ? "it" : "them"} (\`p2p relays remove ${one ? "<url>" : "<url> <url>"}\`)`, { heldBy: rs, pendingVer: newest, confirmedVer: v.head.ver });
|
|
666
|
+
}
|
|
572
667
|
/** Relays a (bundled, unverified) identity document lists: only a hint for where to refresh from. */
|
|
573
668
|
static relaysOf(docJws) {
|
|
574
669
|
if (!docJws)
|
|
@@ -799,6 +894,12 @@ export class App {
|
|
|
799
894
|
const devices = [...view.devices, ...readd].slice(0, MAX_DEVICES);
|
|
800
895
|
const keyholders = [...view.keyholders, ...unionKeyholders.filter((d) => readd.includes(d) && devices.includes(d))];
|
|
801
896
|
if (!opts.restoring && (!devices.includes(this.did) || !keyholders.includes(this.did))) {
|
|
897
|
+
// #75: the merges above were never published; kept, they'd leave this device unlisted in its own
|
|
898
|
+
// view (a fork made by a version that leaves it out), and rotation, the remedy, couldn't find its branch.
|
|
899
|
+
if (merges.length > 0) {
|
|
900
|
+
const drop = new Set(merges.map((m) => peekIdentityDoc(m).hash));
|
|
901
|
+
await this.store.updateIdentity(this.userId, (cur) => (cur ? { next: { ...cur, versions: cur.versions.filter((v) => !drop.has(peekIdentityDoc(v).hash)) }, result: undefined } : { result: undefined }));
|
|
902
|
+
}
|
|
802
903
|
throw new CliError("device_revoked", "this device is no longer a listed key holder of your identity: it can't publish (only identity rotation, §2.8, replaces a lost key holder's key; run it from a listed key holder)");
|
|
803
904
|
}
|
|
804
905
|
const p = {
|
package/dist/cli.d.ts
CHANGED
|
@@ -68,10 +68,14 @@ export declare const realOps: {
|
|
|
68
68
|
agentEnv(env: Record<string, string | undefined> | undefined): boolean;
|
|
69
69
|
agentContext(env: Record<string, string | undefined> | undefined): boolean;
|
|
70
70
|
personTokenFile(home: string): string;
|
|
71
|
+
personSaltFile(home: string): string;
|
|
72
|
+
homeFilesOwn(home: string): boolean;
|
|
73
|
+
personTokenMatchesKeys(home: string, spk: string, token: string): boolean;
|
|
71
74
|
personToken(home: string): string;
|
|
72
|
-
renewPersonToken(home: string): string;
|
|
75
|
+
renewPersonToken(home: string, spk?: string): string;
|
|
73
76
|
identityHere(home: string): boolean;
|
|
74
77
|
personTokenOk(env: Record<string, string | undefined> | undefined, home: string | undefined): boolean;
|
|
78
|
+
healPersonToken(home: string): void;
|
|
75
79
|
takePersonToken(env: Record<string, string | undefined>, home: string | undefined): boolean;
|
|
76
80
|
assertPersonForWidening(app: Pick<App, "env"> & {
|
|
77
81
|
front?: boolean;
|
|
@@ -83,6 +87,9 @@ export declare const realOps: {
|
|
|
83
87
|
personHere(app: Pick<App, "env"> & {
|
|
84
88
|
front?: boolean;
|
|
85
89
|
}): boolean;
|
|
90
|
+
personHereStrict(app: Pick<App, "env"> & {
|
|
91
|
+
front?: boolean;
|
|
92
|
+
}): boolean;
|
|
86
93
|
sessionBinding(app: App, sid: string): Promise<projects.SessionBinding | undefined>;
|
|
87
94
|
privateReasons(doc: projects.ProjectsDoc, b: projects.SessionBinding): projects.PrivateReason[];
|
|
88
95
|
privateRemedy(causes: readonly projects.PrivateCause[], names: string[]): string;
|
|
@@ -141,12 +148,15 @@ export declare const realOps: {
|
|
|
141
148
|
IX_CLOUD_ENV: readonly string[];
|
|
142
149
|
IX_KEEP: readonly string[];
|
|
143
150
|
readRotationState(home: string): Promise<rotation.RotationState | undefined>;
|
|
151
|
+
assertAdopted(app: App, userId: string): void;
|
|
144
152
|
adoptHome(app: App, src: string, tag: string): Promise<string>;
|
|
145
153
|
raiseRotationAlert(app: App, r: import("@peer2peer/core/v3").VerifiedRotation, by?: string): Promise<boolean>;
|
|
146
154
|
alertForeignRotations(app: App): Promise<void>;
|
|
147
155
|
friendVerdict(st: rotation.RotationState, peer: string): {
|
|
148
156
|
invite: boolean;
|
|
149
|
-
why
|
|
157
|
+
why
|
|
158
|
+
/** setup, "I already use Peer2Peer on another device": `p2p link join`, inline. No identity is made here, so no backup is asked. */
|
|
159
|
+
? /** setup, "I already use Peer2Peer on another device": `p2p link join`, inline. No identity is made here, so no backup is asked. */: string;
|
|
150
160
|
};
|
|
151
161
|
rotatePlan(app: App, opts?: rotation.RotateOptions): Promise<rotation.RotationPlan>;
|
|
152
162
|
rotateCancel(app: App): Promise<{
|
|
@@ -582,7 +592,7 @@ export declare const realOps: {
|
|
|
582
592
|
rejoined: string[];
|
|
583
593
|
}>;
|
|
584
594
|
relaysAdd(app: App, url: string): Promise<identity.RelaysChange>;
|
|
585
|
-
relaysRemove(app: App,
|
|
595
|
+
relaysRemove(app: App, urls: string | readonly string[]): Promise<identity.RelaysChange>;
|
|
586
596
|
devices(app: App): Promise<identity.DeviceRow[]>;
|
|
587
597
|
whoami(app: App): Promise<identity.WhoamiResult>;
|
|
588
598
|
revokeDevice(app: App, did: string): Promise<{
|
|
@@ -669,11 +679,28 @@ export interface ProgramDeps {
|
|
|
669
679
|
front?: boolean;
|
|
670
680
|
/** A person token was passed that isn't this home's (person.key was replaced since): every command refuses it (main()). */
|
|
671
681
|
personTokenStale?: boolean;
|
|
682
|
+
/** A person token was passed to a home whose files are links (projects.ts homeFilesOwn): every command refuses it (main()). */
|
|
683
|
+
personTokenLinked?: boolean;
|
|
684
|
+
/** The token `front` rests on (main() keeps it in memory, never in the environment): re-checked against the home as the command finds it, and against the keys it loads (App.load). */
|
|
685
|
+
frontToken?: string;
|
|
686
|
+
/** The home held no identity when main() checked the token. */
|
|
687
|
+
frontFresh?: boolean;
|
|
672
688
|
/** The person's "yes" on their controlling terminal (tty-confirm.ts; tests stand in). */
|
|
673
689
|
confirmTty?: projects.ConfirmTty;
|
|
674
690
|
}
|
|
675
691
|
/** The widening command `cmd` is (its path from the program, with `session roster` only when it adds), or undefined. */
|
|
676
692
|
export declare function wideningOf(cmd: Command): string | undefined;
|
|
693
|
+
/**
|
|
694
|
+
* The person-only command `cmd` is ({what, why}), or undefined. Reads stay open: a bare
|
|
695
|
+
* `receipts`, `circle hold <cid>` and `ix config`, and a bare `identity rotate --plan` (it makes
|
|
696
|
+
* or shows the plan: the new fingerprint and which devices follow; nothing is published or
|
|
697
|
+
* revealed, and accepting it is gated).
|
|
698
|
+
*/
|
|
699
|
+
export declare function personOnlyOf(cmd: Command): {
|
|
700
|
+
what: string;
|
|
701
|
+
why: string;
|
|
702
|
+
agentOnly?: boolean;
|
|
703
|
+
} | undefined;
|
|
677
704
|
export declare function buildProgram(deps: ProgramDeps): Command;
|
|
678
705
|
/** Writes a line to stdout; resolves false once the reader is gone (EPIPE). */
|
|
679
706
|
export declare function stdoutWriter(ctl: AbortController): (line: string) => Promise<boolean>;
|
package/dist/cli.js
CHANGED
|
@@ -65,6 +65,88 @@ export function wideningOf(cmd) {
|
|
|
65
65
|
}
|
|
66
66
|
return undefined;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Commands that touch the person's identity key, their identity document, or their own setup (or
|
|
70
|
+
* narrow who reaches them): run only by the person, through the same gate as widening (their
|
|
71
|
+
* front end's token, or their "yes" typed on their own terminal; never from inside an agent's
|
|
72
|
+
* session). The CLI decides by the command it parsed and its agent detection (environment and
|
|
73
|
+
* process ancestry), not by the command line's words: a name built at run time, or a script the
|
|
74
|
+
* agent wrote and runs in its own process tree, is refused like the plain command. It is not a
|
|
75
|
+
* boundary against an agent that runs as the same user and means to get past it: a process started
|
|
76
|
+
* outside the agent's tree that fakes a terminal can answer the "yes", and the key files can be
|
|
77
|
+
* read directly. That boundary is the OS sandbox's read and write deny on P2P_HOME
|
|
78
|
+
* (docs/security/threat-model.md). Internal maintenance (`p2p watch`
|
|
79
|
+
* renewing the document and certificates, the retry of unpublished relays on connect) calls the
|
|
80
|
+
* App directly, never these commands, and is not gated.
|
|
81
|
+
*/
|
|
82
|
+
const PERSON_ONLY = new Map([
|
|
83
|
+
["backup show", "shows your identity key (its backup phrase)"],
|
|
84
|
+
["backup restore", "replaces this device's identity key"],
|
|
85
|
+
["identity rotate", "moves your identity to a new key"],
|
|
86
|
+
["identity republish", "publishes your identity document"],
|
|
87
|
+
["identity dispute", "decides which identity a friend of yours is"],
|
|
88
|
+
["devices revoke", "changes the devices your identity lists"],
|
|
89
|
+
["relays add", "changes the relays your identity lists"],
|
|
90
|
+
["relays remove", "changes the relays your identity lists"],
|
|
91
|
+
["trust remove", "changes who you trust"],
|
|
92
|
+
["invites revoke", "changes your invites"],
|
|
93
|
+
["remove", "changes your friendships and circles"],
|
|
94
|
+
["unfriend", "changes your friendships"],
|
|
95
|
+
["circle propose", "changes a circle's members"],
|
|
96
|
+
["circle transfer", "changes who owns a circle"],
|
|
97
|
+
["circle hold", "changes how your circle takes changes"],
|
|
98
|
+
["extensions disable", "changes which extensions run with your identity"],
|
|
99
|
+
["ix import", "writes into your Ix graph"],
|
|
100
|
+
["ix resolve", "runs your Ix for a peer's reference"],
|
|
101
|
+
["ix config", "changes how your Ix footprints name files"],
|
|
102
|
+
["receipts", "changes whether you send delivery receipts"],
|
|
103
|
+
["profile set", "publishes a new version of your identity document"],
|
|
104
|
+
["proof add", "publishes a new version of your identity document"],
|
|
105
|
+
["block", "changes who reaches you"],
|
|
106
|
+
["petname", "changes the names you know people by"],
|
|
107
|
+
["circle leave", "changes your circles"],
|
|
108
|
+
["held decline", "decides a held request for you"],
|
|
109
|
+
]);
|
|
110
|
+
/** `identity rotate` options that do something beyond making or showing the plan. */
|
|
111
|
+
const ROTATE_ACTS = ["resume", "cancel", "exclude", "keep", "invite", "keepKeyholders", "backupFile", "contest", "resend", "yes", "branch"];
|
|
112
|
+
/**
|
|
113
|
+
* The person-only command `cmd` is ({what, why}), or undefined. Reads stay open: a bare
|
|
114
|
+
* `receipts`, `circle hold <cid>` and `ix config`, and a bare `identity rotate --plan` (it makes
|
|
115
|
+
* or shows the plan: the new fingerprint and which devices follow; nothing is published or
|
|
116
|
+
* revealed, and accepting it is gated).
|
|
117
|
+
*/
|
|
118
|
+
export function personOnlyOf(cmd) {
|
|
119
|
+
const path = [];
|
|
120
|
+
for (let c = cmd; c && c.parent; c = c.parent)
|
|
121
|
+
path.unshift(c.name());
|
|
122
|
+
const p = path.join(" ");
|
|
123
|
+
const why = PERSON_ONLY.get(p);
|
|
124
|
+
if (why === undefined)
|
|
125
|
+
return undefined;
|
|
126
|
+
const args = cmd.args ?? [];
|
|
127
|
+
switch (p) {
|
|
128
|
+
case "receipts":
|
|
129
|
+
return args.length > 0 ? { what: args[0] === "on" || args[0] === "off" ? `receipts ${args[0]}` : "receipts", why } : undefined;
|
|
130
|
+
case "circle hold":
|
|
131
|
+
return args.length > 1 ? { what: args[1] === "on" || args[1] === "off" ? `circle hold <cid> ${args[1]}` : "circle hold", why } : undefined;
|
|
132
|
+
case "ix config":
|
|
133
|
+
return args.length > 0 ? { what: "ix config", why } : undefined;
|
|
134
|
+
// Restore runs only on a fresh home and needs the phrase itself, typed or piped: that is the
|
|
135
|
+
// person's proof outside an agent's session (a fresh home has no person token yet, and a
|
|
136
|
+
// headless restore must keep working). Inside an agent's session it is refused, as `link join`.
|
|
137
|
+
case "backup restore":
|
|
138
|
+
return { what: p, why, agentOnly: true };
|
|
139
|
+
case "identity rotate": {
|
|
140
|
+
const o = cmd.opts();
|
|
141
|
+
const acts = ROTATE_ACTS.filter((k) => o[k] !== undefined && o[k] !== false && !(Array.isArray(o[k]) && o[k].length === 0));
|
|
142
|
+
if (o.plan && acts.length === 0)
|
|
143
|
+
return undefined;
|
|
144
|
+
return { what: o.cancel ? "identity rotate --cancel" : o.plan ? "identity rotate --plan" : "identity rotate", why };
|
|
145
|
+
}
|
|
146
|
+
default:
|
|
147
|
+
return { what: p, why };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
68
150
|
const posInt = (name) => (v) => {
|
|
69
151
|
const n = Number(v);
|
|
70
152
|
if (!Number.isSafeInteger(n) || n < 0)
|
|
@@ -107,6 +189,10 @@ export function buildProgram(deps) {
|
|
|
107
189
|
const app = baseMakeApp(env, i, o);
|
|
108
190
|
app.extensions ??= extensions;
|
|
109
191
|
app.front = deps.front === true;
|
|
192
|
+
if (app.front && deps.frontToken !== undefined) {
|
|
193
|
+
app.frontToken = deps.frontToken;
|
|
194
|
+
app.frontFresh = deps.frontFresh === true;
|
|
195
|
+
}
|
|
110
196
|
app.confirmTty = confirmTty;
|
|
111
197
|
return app;
|
|
112
198
|
};
|
|
@@ -124,6 +210,9 @@ export function buildProgram(deps) {
|
|
|
124
210
|
const app = makeApp(deps.env, io, opts.readOnly ? { readOnly: true } : undefined);
|
|
125
211
|
let stop = () => { };
|
|
126
212
|
try {
|
|
213
|
+
if (deps.personTokenLinked) {
|
|
214
|
+
throw new CliError("refused", `the person token is never taken in ${app.home}: its cli folder, keys, self document, token, salt or v3 store is a symbolic link (or a hard-linked copy). A home kept by a dotfile manager or linked from elsewhere can't use the token: point P2P_HOME at the real folder. Nothing was done`);
|
|
215
|
+
}
|
|
127
216
|
if (deps.personTokenStale) {
|
|
128
217
|
throw new CliError("person_token_stale", `P2P_PERSON_TOKEN isn't this device's person token: ${projects.personTokenFile(app.home)} is replaced when an identity is created or restored here. Nothing was done: read that file again and run the command again. A front end does this itself (in Claude Code, reloading the Peer2Peer plugin also does it)`);
|
|
129
218
|
}
|
|
@@ -131,10 +220,23 @@ export function buildProgram(deps) {
|
|
|
131
220
|
// read-only command, which must leave the home exactly as it found it).
|
|
132
221
|
if (typeof app.home === "string" && !opts.readOnly)
|
|
133
222
|
await rotation.recoverInterruptedFollow(app.home).catch(() => false);
|
|
223
|
+
// The token was checked when the command started; the home may have changed since (an
|
|
224
|
+
// interrupted follow finished just now, or files swapped in by something else). Checked again
|
|
225
|
+
// as the home is now, before any gate: a home that had no identity then and has one now keeps
|
|
226
|
+
// no token. The keys the command loads are checked against it too (App.load).
|
|
227
|
+
if (app.front && app.frontToken !== undefined) {
|
|
228
|
+
const still = projects.personTokenOk({ P2P_PERSON_TOKEN: app.frontToken }, app.home);
|
|
229
|
+
if (!still || (app.frontFresh && projects.identityHere(app.home)))
|
|
230
|
+
app.front = false;
|
|
231
|
+
}
|
|
134
232
|
// An agent can't widen who reaches this user, however it runs p2p (projects.ts).
|
|
135
233
|
const widening = wideningOf(cmd);
|
|
136
234
|
if (widening)
|
|
137
235
|
await projects.assertPersonForWidening(app, widening, confirmTty, undefined, { noTokenBeforeIdentity: widening === "link join" });
|
|
236
|
+
// Nor touch the identity key, the identity document or the person's own setup (PERSON_ONLY).
|
|
237
|
+
const personOnly = personOnlyOf(cmd);
|
|
238
|
+
if (personOnly && !(personOnly.agentOnly && projects.personHereStrict(app)))
|
|
239
|
+
await projects.assertPersonForWidening(app, personOnly.what, confirmTty, personOnly.why);
|
|
138
240
|
if (opts.requireIdentity !== false)
|
|
139
241
|
await app.load(true);
|
|
140
242
|
// The person token the person's front ends pass back (projects.ts), made once, in the CLI's own folder.
|
|
@@ -420,6 +522,11 @@ export function buildProgram(deps) {
|
|
|
420
522
|
.action(run(async (app, o) => {
|
|
421
523
|
let mode = o.backupFile !== undefined ? "file" : o.printBackup ? "print" : o.backup === false ? "none" : undefined;
|
|
422
524
|
const existed = await app.load(false);
|
|
525
|
+
// On a home that already holds an identity, setup's backup options reveal the existing key's
|
|
526
|
+
// phrase (`backup show`'s gate): the person's only. A new identity's own phrase is not.
|
|
527
|
+
if (existed && (o.printBackup || o.backupFile !== undefined)) {
|
|
528
|
+
await projects.assertPersonForWidening(app, o.printBackup ? "setup --print-backup" : "setup --backup-file", confirmTty, PERSON_ONLY.get("backup show"));
|
|
529
|
+
}
|
|
423
530
|
const p2p = identity.p2pCommand();
|
|
424
531
|
// Asked only once an identity exists here (its key was just made): never before.
|
|
425
532
|
const askBackup = async () => {
|
|
@@ -593,8 +700,8 @@ export function buildProgram(deps) {
|
|
|
593
700
|
}));
|
|
594
701
|
for (const verb of ["add", "remove"]) {
|
|
595
702
|
relays
|
|
596
|
-
.command(
|
|
597
|
-
.description(verb === "add" ? "Add a relay (1-5 in all)" : "Remove
|
|
703
|
+
.command(verb === "add" ? "add <url>" : "remove <url...>")
|
|
704
|
+
.description(verb === "add" ? "Add a relay (1-5 in all)" : "Remove one or more relays, in one new version (one must stay)")
|
|
598
705
|
.option("--json", "JSON output")
|
|
599
706
|
.action(run(async (app, url) => {
|
|
600
707
|
const r = verb === "add" ? await ops.relaysAdd(app, url) : await ops.relaysRemove(app, url);
|
|
@@ -625,6 +732,7 @@ export function buildProgram(deps) {
|
|
|
625
732
|
.option("--keep-keyholders", "Devices that held the old identity key also get the new one (default: they follow as ordinary devices)")
|
|
626
733
|
.option("--wait <seconds>", "How long to wait for your other devices to follow (default 600, the link code's life)", posInt("--wait"))
|
|
627
734
|
.option("--backup-file [path]", "Save the new key's 24-word backup phrase to a 0600 file (default <home>/backup-phrase-<fingerprint>.txt)")
|
|
735
|
+
.option("--branch <hash>", "Your identity is forked by a version that leaves this device out and more than one branch still lists it: the one that is yours (its jwsHash, as the error lists them)")
|
|
628
736
|
.option("--contest", "On a key holder: answer a rotation of your identity this device didn't publish with a competing one, so your friends see a conflict and apply neither")
|
|
629
737
|
.option("--resend", "After a rotation: send the new identity's invite again to the friends it didn't reach (throttled)")
|
|
630
738
|
.option("-y, --yes", "Accept the plan without asking (scripts)")
|
|
@@ -661,7 +769,7 @@ export function buildProgram(deps) {
|
|
|
661
769
|
human: `Sent your new identity's invite to ${fmt.plural(r.sent, "friend")}${r.failed.length ? `; ${r.failed.length} still not reached` : ""}${r.throttled ? ` (${r.remaining} wait for the relays' hourly limit: run it again later)` : ""}.`,
|
|
662
770
|
};
|
|
663
771
|
}
|
|
664
|
-
const opts = { resume: o.resume, exclude: o.exclude, keep: o.keep, invite: o.invite, keepKeyholders: o.keepKeyholders, contest: o.contest, ...backup };
|
|
772
|
+
const opts = { resume: o.resume, exclude: o.exclude, keep: o.keep, invite: o.invite, keepKeyholders: o.keepKeyholders, branch: o.branch, contest: o.contest, ...backup };
|
|
665
773
|
if (o.plan) {
|
|
666
774
|
const plan = await ops.rotatePlan(app, opts);
|
|
667
775
|
return { json: { plan: true, ...plan }, human: `${fmt.formatRotationPlan(plan)}\nAccept it with \`p2p identity rotate --resume\` (add --exclude <did> to drop a device), or drop it with --cancel.` };
|
|
@@ -961,8 +1069,13 @@ export function buildProgram(deps) {
|
|
|
961
1069
|
.description("Your invite codes and what became of them; `invites revoke <code>` cancels one")
|
|
962
1070
|
.option("--json", "JSON output")
|
|
963
1071
|
.action(run(async (app) => {
|
|
964
|
-
const
|
|
965
|
-
|
|
1072
|
+
const all = await ops.listCodes(app);
|
|
1073
|
+
// A live code (open, or taken and not yet joined) lets whoever holds it in: inside an agent's
|
|
1074
|
+
// session (or where that can't be told) without the person's token, it is cut as a redeemed
|
|
1075
|
+
// one is, in the JSON too. The status stays readable.
|
|
1076
|
+
const redacted = !projects.personHereStrict(app);
|
|
1077
|
+
const r = redacted ? all.map((c) => ({ ...c, code: fmt.shortCode(c.code), ...(c.status === "open" || c.status === "taken" ? { redacted: true } : {}) })) : all;
|
|
1078
|
+
return { json: { invites: r, ...(redacted ? { redacted: true } : {}) }, human: fmt.formatCodes(r), pretty: (p) => pretty.prettyCodes(r, p) };
|
|
966
1079
|
}));
|
|
967
1080
|
invites
|
|
968
1081
|
.command("revoke [code]")
|
|
@@ -1959,14 +2072,26 @@ export async function main(argvIn, deps) {
|
|
|
1959
2072
|
{
|
|
1960
2073
|
// A copy without it (an embedder's object is left as it was); the process's own environment loses it too.
|
|
1961
2074
|
const env = { ...deps.env };
|
|
1962
|
-
const
|
|
1963
|
-
const
|
|
2075
|
+
const token = (env.P2P_PERSON_TOKEN ?? "").trim();
|
|
2076
|
+
const given = token !== "";
|
|
2077
|
+
const home = resolveHome(env);
|
|
2078
|
+
const byToken = projects.takePersonToken(env, home);
|
|
2079
|
+
const front = deps.front === true || byToken;
|
|
2080
|
+
const linked = given && !front && !projects.homeFilesOwn(home);
|
|
2081
|
+
if (given && !front && !linked)
|
|
2082
|
+
projects.healPersonToken(home);
|
|
1964
2083
|
if (deps.env === process.env)
|
|
1965
2084
|
delete process.env.P2P_PERSON_TOKEN;
|
|
1966
2085
|
// A token that isn't this home's is refused outright, never quietly taken as "not the person": the
|
|
1967
2086
|
// person.key it was read from was replaced when an identity was created or restored here
|
|
1968
2087
|
// (projects.ts renewPersonToken), and the front end that passed it reads the file again.
|
|
1969
|
-
deps = {
|
|
2088
|
+
deps = {
|
|
2089
|
+
...deps,
|
|
2090
|
+
front,
|
|
2091
|
+
env,
|
|
2092
|
+
...(byToken && deps.front !== true ? { frontToken: token, frontFresh: !projects.identityHere(home) } : {}),
|
|
2093
|
+
...(linked ? { personTokenLinked: true } : given && !front ? { personTokenStale: true } : {}),
|
|
2094
|
+
};
|
|
1970
2095
|
}
|
|
1971
2096
|
// `--no-input` anywhere before `--`: no pickers, no questions (as a script would run).
|
|
1972
2097
|
const end = argvIn.indexOf("--");
|
package/dist/doctor.js
CHANGED
|
@@ -30,7 +30,7 @@ import { readdirSync, statSync } from "node:fs";
|
|
|
30
30
|
import { readFile, stat } from "node:fs/promises";
|
|
31
31
|
import { dirname, join } from "node:path";
|
|
32
32
|
import { fileURLToPath } from "node:url";
|
|
33
|
-
import { capAllowsKind, daysPastExp, decodeTyped, DEFAULT_SKEW_SEC, displayAddress, identityFreshness, isLive, isUserId, liveFriendshipsV3, nowSec, peekIdentityDoc, sanitizePeerText, TYP3, unfriendApplies, refreshIdentity as coreRefreshIdentity, } from "@peer2peer/core/v3";
|
|
33
|
+
import { capAllowsKind, daysPastExp, decodeTyped, DEFAULT_SKEW_SEC, displayAddress, identityFreshness, isLive, isUserId, liveFriendshipsV3, nowSec, peekIdentityDoc, sanitizePeerText, TYP3, unfriendApplies, pendingHeadSenders, refreshIdentity as coreRefreshIdentity, } from "@peer2peer/core/v3";
|
|
34
34
|
import { App, capPeek, joinCapOf, orderRelays, REPUBLISH_DOC_WITHIN_SEC } from "./app.js";
|
|
35
35
|
import { CAP_PROJECTS, CLI_CAPS, KNOWN_FEATURES, peerDevices, unavailableBetween } from "./features.js";
|
|
36
36
|
import { circleMembers, listCircles } from "./circle-ops.js";
|
|
@@ -416,6 +416,33 @@ async function versionCheck(c, app, o, ms) {
|
|
|
416
416
|
async function circlesOf(app, ms) {
|
|
417
417
|
return (await bounded(listCircles(app), ms)).value ?? [];
|
|
418
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* #78: newer versions of our own identity this device holds as pending heads, with the listed relays that
|
|
421
|
+
* sent them. While one of those relays doesn't answer, edits and the key holder's renewal are refused
|
|
422
|
+
* (App.ownPendingGuard), so the document can lapse: name the relays this probe couldn't reach, and the fix.
|
|
423
|
+
* Local data only (no refresh).
|
|
424
|
+
*/
|
|
425
|
+
async function pendingHeadsCheck(c, app, view, reports, ms) {
|
|
426
|
+
const stored = (await bounded(app.store.getIdentity(app.userId), ms)).value;
|
|
427
|
+
if (!stored)
|
|
428
|
+
return;
|
|
429
|
+
const above = pendingHeadSenders(stored).filter((p) => p.ver > view.head.ver && p.relays.some((r) => view.relays.includes(r)));
|
|
430
|
+
if (above.length === 0)
|
|
431
|
+
return;
|
|
432
|
+
const newest = Math.max(...above.map((p) => p.ver));
|
|
433
|
+
const senders = [...new Set(above.flatMap((p) => p.relays.filter((r) => view.relays.includes(r))))];
|
|
434
|
+
const down = senders.filter((r) => reports.find((x) => x.relay === r)?.reachable === false);
|
|
435
|
+
const what = `this device holds version ${newest} of your identity, newer than its head (version ${view.head.ver}), from ${senders.join(", ")}`;
|
|
436
|
+
if (down.length === 0 && senders.some((r) => !reports.some((x) => x.relay === r))) {
|
|
437
|
+
c.add("pending-heads", "unknown", "newer versions of your identity", `${what}; not probed here`, "run `p2p doctor` again; if one of them stays unreachable, edits and renewals are refused until it answers or you remove it (`p2p relays remove <url>`)");
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (down.length === 0) {
|
|
441
|
+
c.add("pending-heads", "ok", "newer versions of your identity", `${what}; ${senders.length === 1 ? "it answers" : "they answer"}, so your next edit or renewal fetches it`);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
c.add("pending-heads", "fail", "newer versions of your identity", `${what}; ${down.join(", ")} ${down.length === 1 ? "doesn't" : "don't"} answer, so edits and renewing your identity document are refused until ${down.length === 1 ? "it answers" : "they answer"}`, `wait for ${down.length === 1 ? "it" : "them"} to come back; if ${down.length === 1 ? "it is" : "they are"} gone for good, or no device of yours published that version: \`p2p relays remove ${down.join(" ")}\``);
|
|
445
|
+
}
|
|
419
446
|
async function deviceChecks(c, app, o, ms, reports) {
|
|
420
447
|
const view = (await bounded(app.view(app.userId), ms)).value;
|
|
421
448
|
const name = view?.head.name ?? app.self?.name ?? "?";
|
|
@@ -440,6 +467,7 @@ async function deviceChecks(c, app, o, ms, reports) {
|
|
|
440
467
|
c.add("document-fork", "fail", "identity document history", "forked (two versions claim the same place)", "run `p2p identity republish` on a key holder: it merges the branches");
|
|
441
468
|
if (view.rotations.length > 0)
|
|
442
469
|
c.add("document-rotated", "fail", "identity", "this identity moved to a new key", "follow it: `p2p held` shows the move (approve it there), or re-link with `p2p link join <code> --rotated`");
|
|
470
|
+
await pendingHeadsCheck(c, app, view, reports, ms);
|
|
443
471
|
}
|
|
444
472
|
relayChecks(c, app, reports, view ? { hash: view.head.hash, ver: view.head.ver } : undefined);
|
|
445
473
|
clockCheck(c, reports);
|
package/dist/format.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare function formatAge(sec: number): string;
|
|
|
9
9
|
export declare function formatDate(sec: number): string;
|
|
10
10
|
export declare function plural(n: number, one: string, many?: string): string;
|
|
11
11
|
export declare function formatCodes(rows: CodeRow[]): string;
|
|
12
|
+
/** A code cut to its first four characters (after any link prefix): what the listing shows of a code that no longer lets anyone in. */
|
|
13
|
+
export declare function shortCode(code: string): string;
|
|
12
14
|
/** "delivered via 2 relays (1 device)". */
|
|
13
15
|
export declare function formatDelivery(d: Pick<Delivery, "relays" | "devices">): string;
|
|
14
16
|
/** A terminal QR code of `text`; empty when it can't be rendered. */
|
package/dist/format.js
CHANGED
|
@@ -47,11 +47,15 @@ export function formatCodes(rows) {
|
|
|
47
47
|
default:
|
|
48
48
|
st = r.status;
|
|
49
49
|
}
|
|
50
|
-
const shown = r.status === "open" || r.status === "taken" ? r.code : r.code
|
|
50
|
+
const shown = (r.status === "open" || r.status === "taken") && !r.redacted ? r.code : shortCode(r.code);
|
|
51
51
|
return `${shown}${who}${circle}${to}: ${st}`;
|
|
52
52
|
})
|
|
53
53
|
.join("\n");
|
|
54
54
|
}
|
|
55
|
+
/** A code cut to its first four characters (after any link prefix): what the listing shows of a code that no longer lets anyone in. */
|
|
56
|
+
export function shortCode(code) {
|
|
57
|
+
return code.endsWith("…") ? code : code.replace(/[^/]*$/, (c) => `${c.slice(0, 4)}…`);
|
|
58
|
+
}
|
|
55
59
|
/** "delivered via 2 relays (1 device)". */
|
|
56
60
|
export function formatDelivery(d) {
|
|
57
61
|
return `delivered via ${plural(d.relays.length, "relay")} (${plural(d.devices, "device")})`;
|
package/dist/identity.d.ts
CHANGED
|
@@ -89,8 +89,12 @@ export declare function reissueForRelays(app: App): Promise<{
|
|
|
89
89
|
}>;
|
|
90
90
|
/** Adds a relay to your identity document (the next version, published to old and new relays). */
|
|
91
91
|
export declare function relaysAdd(app: App, url: string): Promise<RelaysChange>;
|
|
92
|
-
/**
|
|
93
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Removes relays (at least one must stay), in one new version. The removed relays get it too, so they stop
|
|
94
|
+
* admitting removed state. Several at once (#78 review): two relays that both went silent while holding a
|
|
95
|
+
* newer version each hold up removing the other one alone (App.ownPendingGuard).
|
|
96
|
+
*/
|
|
97
|
+
export declare function relaysRemove(app: App, urls: string | readonly string[]): Promise<RelaysChange>;
|
|
94
98
|
export interface DeviceRow {
|
|
95
99
|
did: string;
|
|
96
100
|
label: string;
|