@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/app.js
CHANGED
|
@@ -9,10 +9,11 @@
|
|
|
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
|
+
import { finishPendingMove } from "./keystore.js";
|
|
13
14
|
import { confirmOnTty } from "./tty-confirm.js";
|
|
14
15
|
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";
|
|
16
|
+
import { addIdentityVersion, b64uDecode, b64uEncode, capAllowsKind, CircleChain, createCap, createDeviceCert, createIdentityDoc, decodeTyped, deviceKeysV3FromSecrets, displayAddress, displayFingerprint, getIdentityView, MAX_DEVICES, mergeFields, mergePrevTip, scheduledWriter, refreshIdentity as coreRefreshIdentity, heldBackByOf, heldBackForOf, heldBackHeadOf, unconnectedRelaysOf, unconnectedVersionsOf, IdentityChain, identityKeyFromSeed, isUserId, isValidName, nowSec, P2PError, peekIdentityDoc, pendingHeadSenders, canonicalRelayUrl, sealEnvelopeV3, storeCertResolver, storeSignerContext, TYP3, verifyDeviceCertV3, verifyRotationSignatures, } from "@peer2peer/core/v3";
|
|
16
17
|
import { FileDocBackend, FileTrustStoreV3 } from "@peer2peer/core/v3/node";
|
|
17
18
|
import { OverlayDocBackend, ReadOnlyTrustStoreV3 } from "./readonly.js";
|
|
18
19
|
import { basename, join } from "node:path";
|
|
@@ -44,6 +45,16 @@ const CAP_PRIORITY = (c) => (c.kinds[0] === "*" ? 0 : 1);
|
|
|
44
45
|
export class App {
|
|
45
46
|
/** The person's front end vouched for this command (P2P_PERSON_TOKEN, checked once and removed: projects.ts). */
|
|
46
47
|
front = false;
|
|
48
|
+
/**
|
|
49
|
+
* The token `front` rests on, kept in memory (never in the environment), so the keys this command
|
|
50
|
+
* loads are checked against it (load): a home whose files change after the start never lends the
|
|
51
|
+
* token to other keys. Undefined for an embedder that vouches without one.
|
|
52
|
+
*/
|
|
53
|
+
frontToken;
|
|
54
|
+
/** The home held no identity when the token was checked (a front end's first run). */
|
|
55
|
+
frontFresh = false;
|
|
56
|
+
/** This command made, restored or swapped in the identity it holds (init, link join, restore, a rotation's swap). */
|
|
57
|
+
identityMadeHere = false;
|
|
47
58
|
/** The person's "yes" on their controlling terminal (tty-confirm.ts); cli.ts may stand another in (tests). */
|
|
48
59
|
confirmTty = confirmOnTty;
|
|
49
60
|
env;
|
|
@@ -98,6 +109,10 @@ export class App {
|
|
|
98
109
|
// An embedder holding the person token is a front end (the CLI's main() checks and removes it first,
|
|
99
110
|
// then sets this from its own check).
|
|
100
111
|
this.front = personTokenOk(this.env, this.home);
|
|
112
|
+
if (this.front) {
|
|
113
|
+
this.frontToken = this.env.P2P_PERSON_TOKEN?.trim();
|
|
114
|
+
this.frontFresh = !identityHere(this.home);
|
|
115
|
+
}
|
|
101
116
|
// Progress and P2P_DEBUG lines go to stderr (never secrets: see progress.ts).
|
|
102
117
|
this.progress = { ...makeProgress(opts.env, (m) => opts.io.err(`p2p: ${m}`)), signal: this.abort.signal };
|
|
103
118
|
this.readOnly = opts.readOnly === true;
|
|
@@ -120,9 +135,31 @@ export class App {
|
|
|
120
135
|
throw new CliError("no_identity", "no identity here yet: run `p2p init` (or `p2p link join` / `p2p backup restore`)");
|
|
121
136
|
return false;
|
|
122
137
|
}
|
|
138
|
+
this.checkFrontKeys(keys);
|
|
123
139
|
this.setKeys(keys, self);
|
|
140
|
+
// A home that chose the OS keychain whose keys are still in keys.json (an interrupted move, or a
|
|
141
|
+
// rotation that swapped in a new identity's files): moved now (keystore.ts). Never on a read-only run.
|
|
142
|
+
if (!this.readOnly) {
|
|
143
|
+
const w = await finishPendingMove(this.state.keyStore);
|
|
144
|
+
if (w)
|
|
145
|
+
this.warn(w);
|
|
146
|
+
}
|
|
124
147
|
return true;
|
|
125
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* The person token this command was given must be the one these keys derive (projects.ts
|
|
151
|
+
* personTokenMatchesKeys), unless this command made the identity itself. A home that had no
|
|
152
|
+
* identity when the token was checked, and has one now that this command didn't make, never
|
|
153
|
+
* keeps it. Otherwise the command stops: the home changed under it.
|
|
154
|
+
*/
|
|
155
|
+
checkFrontKeys(keys) {
|
|
156
|
+
if (!this.front || this.frontToken === undefined || this.identityMadeHere)
|
|
157
|
+
return;
|
|
158
|
+
if (!this.frontFresh && personTokenMatchesKeys(this.home, keys.spk, this.frontToken))
|
|
159
|
+
return;
|
|
160
|
+
this.front = false;
|
|
161
|
+
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`);
|
|
162
|
+
}
|
|
126
163
|
setKeys(keys, self) {
|
|
127
164
|
this.keys = keys;
|
|
128
165
|
this.self = self;
|
|
@@ -417,13 +454,25 @@ export class App {
|
|
|
417
454
|
* Network I/O for core's refreshIdentity (§5.6), per relay so core can cap
|
|
418
455
|
* each relay's answer on its own: `tips` and the `chain` walk
|
|
419
456
|
* (`/v3/identity/<id>/chain?to=&n=`) on every listed relay (at most 5).
|
|
457
|
+
*
|
|
458
|
+
* #78: a relay that couldn't be reached (an error or a timeout) is left out of the answer, and when none
|
|
459
|
+
* of the relays asked answered the call fails, so core counts it as a relay that didn't answer (core asks
|
|
460
|
+
* one relay per call), never as one that answered "nothing": its silence doesn't make up a majority that
|
|
461
|
+
* clears pending heads or counts as fresh, and a relay is never named as forging over a gap the silent
|
|
462
|
+
* one wasn't really asked about.
|
|
420
463
|
*/
|
|
421
464
|
fetcher() {
|
|
422
465
|
const t = this.tun.connectTimeoutMs;
|
|
423
466
|
const perRelay = async (relays, get) => {
|
|
424
467
|
const list = [...new Set(relays)].slice(0, 5);
|
|
425
|
-
const answers = await Promise.
|
|
426
|
-
|
|
468
|
+
const answers = await Promise.allSettled(list.map((r) => get(r)));
|
|
469
|
+
const ok = list.flatMap((r, i) => {
|
|
470
|
+
const a = answers[i];
|
|
471
|
+
return a.status === "fulfilled" ? [[r, a.value]] : [];
|
|
472
|
+
});
|
|
473
|
+
if (list.length > 0 && ok.length === 0)
|
|
474
|
+
throw answers[0].reason;
|
|
475
|
+
return Object.fromEntries(ok);
|
|
427
476
|
};
|
|
428
477
|
return {
|
|
429
478
|
tips: (userId, relays) => perRelay(relays, (r) => fetchTips(this.transport(r), userId, t, this.progress, this.guardedLookup(r))),
|
|
@@ -451,8 +500,11 @@ export class App {
|
|
|
451
500
|
throw new CliError("refresh_failed", `no relays to refresh ${userId} from`);
|
|
452
501
|
return held;
|
|
453
502
|
}
|
|
454
|
-
const
|
|
503
|
+
const own = userId === this.keys?.userId;
|
|
504
|
+
const refreshFrom = (rs) => step(this.progress, `refreshing ${userId}'s identity document from ${rs.join(", ")}`, () => coreRefreshIdentity(this.store, userId, this.fetcher(), { relays: rs, own }));
|
|
455
505
|
let v;
|
|
506
|
+
/** #78: the relays core named as serving versions that don't connect (a forged chain's). */
|
|
507
|
+
let named = [];
|
|
456
508
|
try {
|
|
457
509
|
v = await refreshFrom(list);
|
|
458
510
|
}
|
|
@@ -461,12 +513,15 @@ export class App {
|
|
|
461
513
|
throw e;
|
|
462
514
|
// Strict callers (publishing our own next version) must not build on a head they couldn't confirm.
|
|
463
515
|
if (opts.strict) {
|
|
464
|
-
|
|
516
|
+
// #79: relays core held the refresh back for count like the ones it names (see the incomplete case below).
|
|
517
|
+
const heldBy = own ? heldBackByOf(e) : [];
|
|
518
|
+
const unconnected = [...new Set([...unconnectedRelaysOf(e), ...(own ? await this.ownHeldBack(heldBy, heldBackForOf(e), heldBackHeadOf(e)) : [])])];
|
|
465
519
|
const versions = unconnectedVersionsOf(e);
|
|
466
|
-
const
|
|
467
|
-
if (!
|
|
468
|
-
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 =
|
|
520
|
+
const fb = e.reason === "chain-broken" ? await this.ownStrictFallback(userId, list, unconnected, versions, opts.setAside, refreshFrom) : undefined;
|
|
521
|
+
if (!fb)
|
|
522
|
+
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, heldBy)}`);
|
|
523
|
+
v = fb;
|
|
524
|
+
named = unconnected;
|
|
470
525
|
}
|
|
471
526
|
else {
|
|
472
527
|
if (e.reason === "chain-broken" && held && !opts.quiet) {
|
|
@@ -482,11 +537,20 @@ export class App {
|
|
|
482
537
|
this.warn(`refreshing ${await this.addressOf(userId)}'s identity document was cut short; using what was held before (try again)`);
|
|
483
538
|
return held;
|
|
484
539
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
540
|
+
// #79: relays core held the refresh back for (they sent a version of our identity that doesn't connect to
|
|
541
|
+
// a current one we hold and lists more than it) count like the relays it names as serving versions that
|
|
542
|
+
// don't connect: a rotation sets them aside, any other edit refuses and names them. Only when what they left
|
|
543
|
+
// out is a version our own devices published (ownHeldBack).
|
|
544
|
+
const heldBy = own ? (v.heldBackBy ?? []) : [];
|
|
545
|
+
const unconnected = [...new Set([...(v.unconnectedRelays ?? []), ...(own ? await this.ownHeldBack(heldBy, v.heldBackFor ?? [], v.heldBackHead) : [])])];
|
|
546
|
+
const fb = await this.ownStrictFallback(userId, list, unconnected, v.unconnectedVersions ?? [], opts.setAside, refreshFrom);
|
|
547
|
+
if (!fb)
|
|
548
|
+
throw new CliError("refresh_failed", `refreshing the identity document was cut short; try again${this.unconnectedHint(unconnected, v.unconnectedVersions ?? [], userId, heldBy)}`);
|
|
549
|
+
named = unconnected;
|
|
550
|
+
v = fb;
|
|
489
551
|
}
|
|
552
|
+
if (opts.strict && own)
|
|
553
|
+
await this.ownPendingGuard(userId, list, v, named, opts.setAside);
|
|
490
554
|
// Recorded moments ago by another p2p process of this home (a watch and a command refresh
|
|
491
555
|
// the same people in a burst): no write. Only ever leaves the time a little older, so the
|
|
492
556
|
// next refresh comes no later.
|
|
@@ -496,22 +560,76 @@ export class App {
|
|
|
496
560
|
await this.state.update("fetched", (cur = {}) => ({ next: { ...cur, [userId]: Math.max(cur[userId] ?? 0, now) }, result: undefined }));
|
|
497
561
|
return v;
|
|
498
562
|
}
|
|
563
|
+
/**
|
|
564
|
+
* #79, #92 follow-up: the relays core held a refresh of our own identity back for (`by`, they sent a head that
|
|
565
|
+
* would leave out the versions `left`), counted like the relays core names as serving versions that don't connect
|
|
566
|
+
* (a rotation sets them aside, the hint names them) only when one of `left` is our own current tip: a tip of our
|
|
567
|
+
* stored chain (never an old version a relay replays: that is an ancestor of what we hold, or not held at all)
|
|
568
|
+
* that our devices published (the publish log) and that the head held back for (`head`) revoked no device of (#99),
|
|
569
|
+
* or, when the head held back for (`head`) leaves this device out as a key holder (a thief's head against the owner's devices, #79), that a device a version in the publish log lists
|
|
570
|
+
* published (another owner device whose versions haven't reached this device's log yet, the provenance rule of
|
|
571
|
+
* ownBranchTip in rotation.ts). That provenance alone never counts against a head that still lists this device: the
|
|
572
|
+
* devices a logged version lists include ones the owner revoked since, and a version such a device signed, held
|
|
573
|
+
* here, must not get the relays serving the owner's revocation set aside. Otherwise none: a relay replaying an old
|
|
574
|
+
* version (history pruned past what the relays keep) can't get an honest relay set aside, and a relay that really
|
|
575
|
+
* holds the owner up can still be removed (`p2p relays remove`).
|
|
576
|
+
*/
|
|
577
|
+
async ownHeldBack(by, left, head) {
|
|
578
|
+
if (by.length === 0 || left.length === 0 || !this.keys)
|
|
579
|
+
return [];
|
|
580
|
+
const stored = await this.store.getIdentity(this.keys.userId);
|
|
581
|
+
if (!stored || stored.versions.length === 0)
|
|
582
|
+
return [];
|
|
583
|
+
const chain = IdentityChain.fromStored({ ...stored, pendingHeads: [], leftOut: [] });
|
|
584
|
+
const tips = new Set(chain.tips().map((t) => t.hash));
|
|
585
|
+
const published = new Set((await this.store.getPublishLog()).published);
|
|
586
|
+
// Unknown (an older core): as if it listed this device, so provenance alone never counts.
|
|
587
|
+
const headLeavesMeOut = head !== undefined && !head.keyholders.includes(this.did);
|
|
588
|
+
const trusted = headLeavesMeOut ? new Set([this.did, ...[...published].flatMap((h) => chain.get(h)?.devices ?? [])]) : new Set();
|
|
589
|
+
// #99: our own published tip V counts against a head that still lists this device only when that head lists
|
|
590
|
+
// every device V lists. A head that dropped one may be the owner's revocation, reached from another device while
|
|
591
|
+
// this one was offline longer than the relays keep the history between them: a relay still serving V must not get
|
|
592
|
+
// the relays serving that revocation set aside (the rotation would plan from V's stale device list). That case
|
|
593
|
+
// can't be told apart from a thief's head that keeps this device and drops another device V lists: whoever holds
|
|
594
|
+
// the key chooses what its head lists, so it can make this rule refuse. Refusing is the fail-closed choice (no
|
|
595
|
+
// relay is set aside on evidence the head's signer picks); the error then names the relays the refresh was held
|
|
596
|
+
// back for and says how to remove one (unconnectedHint's `heldBy`). An unknown head (an older core) revoked
|
|
597
|
+
// something, for all we know.
|
|
598
|
+
const revokedNone = (v) => head?.devices !== undefined && v.devices.every((d) => head.devices.includes(d));
|
|
599
|
+
const own = left.some((h) => {
|
|
600
|
+
const v = tips.has(h) ? chain.get(h) : undefined;
|
|
601
|
+
return v !== undefined && ((published.has(h) && (headLeavesMeOut || revokedNone(v))) || trusted.has(v.by));
|
|
602
|
+
});
|
|
603
|
+
return own ? [...by] : [];
|
|
604
|
+
}
|
|
499
605
|
/**
|
|
500
606
|
* For a strict refresh of our own identity that failed: what to do. The key-compromise wording only for relays
|
|
501
607
|
* core named (#67 review F1): each sent a version whose missing parent every relay was asked for and none had,
|
|
502
608
|
* so nothing a device of ours published would be there. Otherwise only which relays sent the newer versions.
|
|
609
|
+
* #99 review: `heldBy`, the relays core held the refresh back for, are named too when they weren't counted
|
|
610
|
+
* (ownHeldBack refused, as when their head drops a device this device's current version lists), with what to do:
|
|
611
|
+
* nothing else names them.
|
|
503
612
|
*/
|
|
504
|
-
unconnectedHint(unconnected, versions, userId) {
|
|
613
|
+
unconnectedHint(unconnected, versions, userId, heldBy = []) {
|
|
505
614
|
if (userId !== this.keys?.userId)
|
|
506
615
|
return "";
|
|
616
|
+
const held = [...new Set(heldBy)].filter((r) => !unconnected.includes(r));
|
|
617
|
+
const heldHint = held.length === 0 ? "" : this.heldBackHint(held);
|
|
507
618
|
if (unconnected.length > 0) {
|
|
508
619
|
const one = unconnected.length === 1;
|
|
509
|
-
return
|
|
620
|
+
return `${heldHint}. ${unconnected.join(", ")} ${one ? "serves" : "serve"} versions of your identity, signed with your identity key, that don't connect to your history and that no relay holds the history of: if no device of yours published them, someone else holds your identity key. Remove ${one ? "that relay" : "those relays"} (\`p2p relays remove <url>\`) or rotate your identity (\`p2p identity rotate\`)`;
|
|
510
621
|
}
|
|
511
|
-
const from = [...new Set(versions.flatMap((x) => x.relays))];
|
|
622
|
+
const from = [...new Set(versions.flatMap((x) => x.relays))].filter((r) => !held.includes(r));
|
|
512
623
|
if (from.length === 0)
|
|
513
|
-
return
|
|
514
|
-
return
|
|
624
|
+
return heldHint;
|
|
625
|
+
return `${heldHint}. Newer versions of your identity from ${from.join(", ")} don't connect to the history this device holds yet; if one of those relays keeps serving versions no device of yours published, remove it (\`p2p relays remove <url>\`)`;
|
|
626
|
+
}
|
|
627
|
+
/** #99 review: the relays a refresh of our own identity was held back for, not set aside (ownHeldBack refused). */
|
|
628
|
+
heldBackHint(held) {
|
|
629
|
+
const one = held.length === 1;
|
|
630
|
+
return (`. ${held.join(", ")} ${one ? "serves" : "serve"} a newer version of your identity, signed with your identity key, that leaves out this device's current version and doesn't connect to it. ` +
|
|
631
|
+
`This device can't tell whether that is a change you made on another device (such as revoking a device there) or someone else holding your identity key, so ${one ? "that relay isn't" : "those relays aren't"} set aside automatically. ` +
|
|
632
|
+
`If no device of yours made that change, remove ${one ? "it" : "them"} (\`p2p relays remove <url>\`: that goes ahead on what your other relays confirm), then rotate your identity (\`p2p identity rotate\`)`);
|
|
515
633
|
}
|
|
516
634
|
/**
|
|
517
635
|
* #67: a strict refresh of our OWN identity couldn't confirm the head over every listed relay. Before an
|
|
@@ -537,8 +655,7 @@ export class App {
|
|
|
537
655
|
* none), never one whose genuine gap the walk merely didn't reach. And the confirmed head must not be
|
|
538
656
|
* below any version the full refresh left unconnected, unless every relay that sent that version is set
|
|
539
657
|
* 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.)
|
|
658
|
+
* (A newer version an earlier refresh stored as a pending head, from a relay silent now: ownPendingGuard.)
|
|
542
659
|
* Returns the view, or undefined when this doesn't apply (the caller then refuses as before).
|
|
543
660
|
*/
|
|
544
661
|
async ownStrictFallback(userId, list, unconnected, versions, setAside, refreshFrom) {
|
|
@@ -569,6 +686,49 @@ export class App {
|
|
|
569
686
|
}
|
|
570
687
|
return v;
|
|
571
688
|
}
|
|
689
|
+
/**
|
|
690
|
+
* #78: a strict refresh of our own identity skips relays that don't answer, so a lagging relay could
|
|
691
|
+
* "confirm" a stale head while the up-to-date one times out. This device may already hold the newer
|
|
692
|
+
* version, as a pending head an earlier, incomplete refresh recorded with the relays that sent it. Refuses
|
|
693
|
+
* when a pending head above the confirmed head was sent by a relay that:
|
|
694
|
+
* - is still listed and isn't set aside by this edit (`setAside.relays`: the relays it removes), so
|
|
695
|
+
* `p2p relays remove` always gets past a relay that holds the owner up. A pending head another relay
|
|
696
|
+
* sent too still holds the edit up while that one is silent (#78 re-review: removing a relay that
|
|
697
|
+
* replayed an honest relay's version, and now withholds it, mustn't fork against it); silent relays
|
|
698
|
+
* that hold each other up are removed together (`relays remove` takes several);
|
|
699
|
+
* - wasn't named as serving versions that don't connect (a forged chain's, core's unconnectedRelays);
|
|
700
|
+
* - didn't answer this refresh: a relay that answered gave its current tips, so what it still serves is
|
|
701
|
+
* already in this refresh (connected, or the refresh failed or was cut short), and what it no longer
|
|
702
|
+
* serves doesn't hold the owner up.
|
|
703
|
+
* So one relay can hold an edit up only while it stays silent, and only with a version signed with the
|
|
704
|
+
* identity key above the head the other relays confirm (a genuine newer version, which building below would
|
|
705
|
+
* fork, or a thief's); removing that relay always goes ahead. A pending head stored without its senders
|
|
706
|
+
* (older builds), expired, or not a valid version of this identity never holds an edit up.
|
|
707
|
+
*/
|
|
708
|
+
async ownPendingGuard(userId, list, v, named, setAside) {
|
|
709
|
+
const stored = await this.store.getIdentity(userId);
|
|
710
|
+
if (!stored)
|
|
711
|
+
return;
|
|
712
|
+
const heard = new Set(v.answeredRelays);
|
|
713
|
+
const skip = new Set([...(setAside?.relays ?? []), ...named]);
|
|
714
|
+
const silent = new Set();
|
|
715
|
+
let newest = 0;
|
|
716
|
+
for (const p of pendingHeadSenders(stored)) {
|
|
717
|
+
if (p.ver <= v.head.ver)
|
|
718
|
+
continue;
|
|
719
|
+
const by = p.relays.filter((r) => list.includes(r) && !skip.has(r) && !heard.has(r));
|
|
720
|
+
if (by.length === 0)
|
|
721
|
+
continue;
|
|
722
|
+
for (const r of by)
|
|
723
|
+
silent.add(r);
|
|
724
|
+
newest = Math.max(newest, p.ver);
|
|
725
|
+
}
|
|
726
|
+
if (silent.size === 0)
|
|
727
|
+
return;
|
|
728
|
+
const rs = [...silent];
|
|
729
|
+
const one = rs.length === 1;
|
|
730
|
+
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 });
|
|
731
|
+
}
|
|
572
732
|
/** Relays a (bundled, unverified) identity document lists: only a hint for where to refresh from. */
|
|
573
733
|
static relaysOf(docJws) {
|
|
574
734
|
if (!docJws)
|
|
@@ -792,13 +952,19 @@ export class App {
|
|
|
792
952
|
const stored = await this.store.getIdentity(this.userId);
|
|
793
953
|
// Only devices a merge dropped come back: never one revoked along the head's ancestry, nor one
|
|
794
954
|
// core denies after a history jump.
|
|
795
|
-
const plan = stored && merges.length > 0 ? planReadd(IdentityChain.fromStored({ ...stored, pendingHeads: [] }), preTips, unionDevices, view.devices, head.hash, stored.denied ?? []) : { readd: [], skipped: [] };
|
|
955
|
+
const plan = stored && merges.length > 0 ? planReadd(IdentityChain.fromStored({ ...stored, pendingHeads: [], leftOut: [] }), preTips, unionDevices, view.devices, head.hash, stored.denied ?? []) : { readd: [], skipped: [] };
|
|
796
956
|
for (const d of plan.skipped)
|
|
797
957
|
this.warn(`device ${d} was dropped by the merge of your identity document's branches; link it again (this device's copy of the history can't prove it wasn't revoked)`);
|
|
798
958
|
const readd = plan.readd;
|
|
799
959
|
const devices = [...view.devices, ...readd].slice(0, MAX_DEVICES);
|
|
800
960
|
const keyholders = [...view.keyholders, ...unionKeyholders.filter((d) => readd.includes(d) && devices.includes(d))];
|
|
801
961
|
if (!opts.restoring && (!devices.includes(this.did) || !keyholders.includes(this.did))) {
|
|
962
|
+
// #75: the merges above were never published; kept, they'd leave this device unlisted in its own
|
|
963
|
+
// view (a fork made by a version that leaves it out), and rotation, the remedy, couldn't find its branch.
|
|
964
|
+
if (merges.length > 0) {
|
|
965
|
+
const drop = new Set(merges.map((m) => peekIdentityDoc(m).hash));
|
|
966
|
+
await this.store.updateIdentity(this.userId, (cur) => (cur ? { next: { ...cur, versions: cur.versions.filter((v) => !drop.has(peekIdentityDoc(v).hash)) }, result: undefined } : { result: undefined }));
|
|
967
|
+
}
|
|
802
968
|
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
969
|
}
|
|
804
970
|
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;
|
|
@@ -140,7 +147,9 @@ export declare const realOps: {
|
|
|
140
147
|
MAX_GRAPH_PATHS: 64;
|
|
141
148
|
IX_CLOUD_ENV: readonly string[];
|
|
142
149
|
IX_KEEP: readonly string[];
|
|
150
|
+
branchSummary(hash: string, ver: number, by: readonly string[], relays: readonly string[]): rotation.BranchSummary;
|
|
143
151
|
readRotationState(home: string): Promise<rotation.RotationState | undefined>;
|
|
152
|
+
assertAdopted(app: App, userId: string): void;
|
|
144
153
|
adoptHome(app: App, src: string, tag: string): Promise<string>;
|
|
145
154
|
raiseRotationAlert(app: App, r: import("@peer2peer/core/v3").VerifiedRotation, by?: string): Promise<boolean>;
|
|
146
155
|
alertForeignRotations(app: App): Promise<void>;
|
|
@@ -214,6 +223,7 @@ export declare const realOps: {
|
|
|
214
223
|
keyholder: boolean;
|
|
215
224
|
}>;
|
|
216
225
|
}>;
|
|
226
|
+
rotationLockOf: (home: string) => string;
|
|
217
227
|
DEVICE_SEEN_WINDOW_SEC: number;
|
|
218
228
|
RESEND_PER_HOUR: 50;
|
|
219
229
|
shellQuote(s: string): string;
|
|
@@ -247,7 +257,7 @@ export declare const realOps: {
|
|
|
247
257
|
}>;
|
|
248
258
|
removeUser(app: App, who: string): Promise<codes.RemoveResult>;
|
|
249
259
|
CODE_LABEL_MAX: 64;
|
|
250
|
-
codeHint: (code: string) => string;
|
|
260
|
+
codeHint: (code: string /** 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). */) => string;
|
|
251
261
|
PLUGIN_INSTALL: string[];
|
|
252
262
|
CODEX_INSTALL_URL: "https://github.com/ix-infrastructure/Peer2Peer/blob/main/packages/codex-bridge/README.md#install";
|
|
253
263
|
CodePreviewReady: typeof codes.CodePreviewReady;
|
|
@@ -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>;
|