@real-life/trust-protocol 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +165 -0
- package/README.md +68 -3
- package/dist/adapters/vti-mediator.d.ts +112 -5
- package/dist/adapters/vti-mediator.d.ts.map +1 -1
- package/dist/adapters/vti-mediator.js +370 -28
- package/dist/adapters/vti-mediator.js.map +1 -1
- package/dist/encounter/ceremony.d.ts +10 -0
- package/dist/encounter/ceremony.d.ts.map +1 -1
- package/dist/encounter/ceremony.js +70 -13
- package/dist/encounter/ceremony.js.map +1 -1
- package/dist/encounter.d.ts +4 -0
- package/dist/encounter.d.ts.map +1 -1
- package/dist/encounter.js +3 -1
- package/dist/encounter.js.map +1 -1
- package/dist/holder-api.d.ts +18 -2
- package/dist/holder-api.d.ts.map +1 -1
- package/dist/holder-api.js +16 -4
- package/dist/holder-api.js.map +1 -1
- package/dist/identity-state.d.ts +13 -1
- package/dist/identity-state.d.ts.map +1 -1
- package/dist/identity-state.js +36 -1
- package/dist/identity-state.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/results.d.ts +4 -0
- package/dist/results.d.ts.map +1 -1
- package/dist/results.js.map +1 -1
- package/dist/views.d.ts +14 -0
- package/dist/views.d.ts.map +1 -1
- package/dist/views.js +34 -5
- package/dist/views.js.map +1 -1
- package/package.json +2 -2
package/dist/holder-api.d.ts
CHANGED
|
@@ -26,6 +26,17 @@ export interface HumanActOptions {
|
|
|
26
26
|
when: Millis;
|
|
27
27
|
actId: string;
|
|
28
28
|
}
|
|
29
|
+
/** A carrier offer for the card of show or scan: the relationship's
|
|
30
|
+
* carrier nonce N, 32 bytes the app draws fresh (Identity §7a.3), and the
|
|
31
|
+
* delivery hints it built from N for the card (at least one; Encounter
|
|
32
|
+
* 6090: at most eight, each at most 512 characters; their form is the carrier
|
|
33
|
+
* profile's, e.g. the VTI mediator adapter profile §1b). The library
|
|
34
|
+
* signs the hints into the card, records N in the register under the
|
|
35
|
+
* relationship the card opens, and interprets neither. */
|
|
36
|
+
export interface CarrierOffer {
|
|
37
|
+
nonce: Uint8Array;
|
|
38
|
+
deliveryHints: readonly string[];
|
|
39
|
+
}
|
|
29
40
|
export interface Holder {
|
|
30
41
|
/** any registered command by name, for modules and tests; apps use the typed acts */
|
|
31
42
|
act(command: string, input: unknown, when: Millis, opts?: {
|
|
@@ -70,15 +81,20 @@ export interface Holder {
|
|
|
70
81
|
/** a displayed card with a fresh own challenge under a fresh pair
|
|
71
82
|
* anchor (Encounter 5.3, 4.4): the event encounter.shown carries the
|
|
72
83
|
* card to display; `name` the card's display name (default: the own
|
|
73
|
-
* profile's);
|
|
84
|
+
* profile's); `carrier` the delivery hints the card carries and the
|
|
85
|
+
* carrier nonce of the relationship it opens (card-invalid with ref
|
|
86
|
+
* RLTP-ENC-6090, carrier-nonce-invalid); human */
|
|
74
87
|
show(opts: HumanActOptions & {
|
|
75
88
|
name?: string;
|
|
89
|
+
carrier?: CarrierOffer;
|
|
76
90
|
}): Promise<ActResult>;
|
|
77
91
|
/** the scanner's step on a displayed card (Encounter 5.8): the record,
|
|
78
92
|
* the fresh tuple, the bundle; encounter.scanned carries the sent card
|
|
79
|
-
* for the optical leg;
|
|
93
|
+
* for the optical leg; `carrier` as with show, its hints in the sent
|
|
94
|
+
* card; human */
|
|
80
95
|
scan(card: Json, opts: HumanActOptions & {
|
|
81
96
|
name?: string;
|
|
97
|
+
carrier?: CarrierOffer;
|
|
82
98
|
}): Promise<ActResult>;
|
|
83
99
|
/** the optical leg (Encounter 5.8, 5710): a sent card shown by the scanner; human */
|
|
84
100
|
captureSentCard(card: Json, opts: HumanActOptions): Promise<ActResult>;
|
package/dist/holder-api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"holder-api.d.ts","sourceRoot":"","sources":["../src/holder-api.ts"],"names":[],"m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opts) identity.revokeDevice human
|
|
35
35
|
// rotateAnchor(opts) identity.rotate human
|
|
36
36
|
// setProfile({name, image?, text?}, opts) profile.set human
|
|
37
|
-
// show(opts{name?})
|
|
38
|
-
// scan(card, opts{name?})
|
|
37
|
+
// show(opts{name?, carrier?}) encounter.show human
|
|
38
|
+
// scan(card, opts{name?, carrier?}) encounter.scan human
|
|
39
39
|
// captureSentCard(card, opts) encounter.capture human
|
|
40
40
|
// counter(contactId, opts) encounter.counter human
|
|
41
41
|
// foundGroup({name, vouchThreshold?, listed?}, opts) membership.found human
|
|
@@ -109,7 +109,13 @@ import { ENCOUNTER_COMMANDS, encounterModule } from './encounter/ceremony.js';
|
|
|
109
109
|
import { MEMBERSHIP_COMMANDS, localAccess, membershipModule } from './membership/holder.js';
|
|
110
110
|
import { INTRODUCTION_COMMANDS, introductionModule } from './introduction/holder.js';
|
|
111
111
|
import { MESSAGE_COMMANDS, messageModule } from './message/holder.js';
|
|
112
|
+
import { b64uOf } from './core.js';
|
|
112
113
|
import { contactView, contactsView, deliveryStatusView, groupsView, inboxView, profileView, promptsView } from './views.js';
|
|
114
|
+
/** The offer as act input: N in canonical base64url (bound and journaled with the act). */
|
|
115
|
+
const offerInput = (c) => c === undefined ? undefined : {
|
|
116
|
+
nonce: c?.nonce instanceof Uint8Array ? b64uOf(c.nonce) : null,
|
|
117
|
+
deliveryHints: Array.isArray(c?.deliveryHints) ? [...c.deliveryHints] : null,
|
|
118
|
+
};
|
|
113
119
|
/** A holder over its ports: `{store, keys, entropy?, log?, access?, retry?, crypto?}`.
|
|
114
120
|
* The crypto handle (default globalThis.crypto) is resolved and probed
|
|
115
121
|
* here and also feeds the default entropy; an app that injects one
|
|
@@ -140,8 +146,14 @@ export async function createHolder(ports, opts = {}) {
|
|
|
140
146
|
recover: (o) => engine.act(TRUST_COMMANDS.recover, {}, o?.when),
|
|
141
147
|
rotateAnchor: (o) => human(IDENTITY_COMMANDS.rotate, {}, o),
|
|
142
148
|
setProfile: (content, o) => human(PROFILE_SET, content, o),
|
|
143
|
-
show: (o) =>
|
|
144
|
-
|
|
149
|
+
show: (o) => {
|
|
150
|
+
const carrier = offerInput(o?.carrier);
|
|
151
|
+
return human(ENCOUNTER_COMMANDS.show, { ...(o?.name === undefined ? {} : { name: o.name }), ...(carrier === undefined ? {} : { carrier }) }, o);
|
|
152
|
+
},
|
|
153
|
+
scan: (card, o) => {
|
|
154
|
+
const carrier = offerInput(o?.carrier);
|
|
155
|
+
return human(ENCOUNTER_COMMANDS.scan, { card, ...(o?.name === undefined ? {} : { name: o.name }), ...(carrier === undefined ? {} : { carrier }) }, o);
|
|
156
|
+
},
|
|
145
157
|
captureSentCard: (card, o) => human(ENCOUNTER_COMMANDS.capture, { card }, o),
|
|
146
158
|
counter: (contactId, o) => human(ENCOUNTER_COMMANDS.counter, { contactId }, o),
|
|
147
159
|
foundGroup: (g, o) => human(MEMBERSHIP_COMMANDS.found, g, o),
|
package/dist/holder-api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"holder-api.js","sourceRoot":"","sources":["../src/holder-api.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,wEAAwE;AACxE,qEAAqE;AACrE,4EAA4E;AAC5E,wEAAwE;AACxE,sEAAsE;AACtE,uEAAuE;AACvE,uEAAuE;AACvE,0EAA0E;AAC1E,wIAAwI;AACxI,0EAA0E;AAC1E,wEAAwE;AACxE,yEAAyE;AACzE,yEAAyE;AACzE,wEAAwE;AACxE,oEAAoE;AACpE,EAAE;AACF,sEAAsE;AACtE,uEAAuE;AACvE,0EAA0E;AAC1E,yEAAyE;AACzE,qEAAqE;AACrE,SAAS;AACT,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;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E,KAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;QAC5G,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;QAC3B,IAAI,MAAM,KAAM,OAAO,MAAM,CAAC,MAAM,CAAA,CAAC,CAAC;KACvC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["// holder-api — createHolder, the facade over the engine (lib Stage 2,\n// note §4.1, §4.5). Domain modules (identity, encounter, trust, continuity,\n// membership, profile) register with the engine as they graduate; today\n// the facade carries the engine's built-ins, the prompts module, the\n// encounter module (encounter/ceremony.ts: show, scan, the optical leg, the\n// counter-step, the bundle and the credential delivery), the membership\n// module (membership/holder.ts: founding, the prelude and invite, the\n// accept on a group-invite prompt, admission and welcome, evidence and\n// vouches; and the in-library Access over the holder's groups where no\n// Access port is given), the introduction module (introduction/holder.ts:\n// the three roles of Trust §8 and the mediator's start), the identity module (identity-state.ts: device names, the rotation), the trust\n// module (trust/mapping.ts: the Trust act, the class settings, the anchor\n// mapping's issuance and reception, the entry commit; trust/star.ts and\n// trust/group-star.ts: the star and the group star, reconciled on resume\n// and received with their assemblies; trust/entries.ts: merge, split and\n// departure; trust/continuity.ts: the probe, the continuity mapping and\n// the chaining; trust/profile.ts: profile@1) and the modules given.\n//\n// The human acts (note §4.2) are typed methods with an options object\n// `{when, actId}`; actId is required, minted by the app when the human\n// acts, and journaled with the act's result (a repeat with the same actId\n// replays it, another input under it is actid-conflict). They wrap `act`\n// with the trust module's command names, which stays for modules and\n// tests:\n// trust(contactId, opts) trust.set {on: true} human\n// untrust(contactId, opts) trust.set {on: false} human\n// pauseTrust(contactId, paused, opts) trust.pause human\n// setClass(contactId, cls, setting, opts) trust.setClass human\n// setGroupClass(contactId, groupId, setting, opts) trust.setGroupClass human\n// merge(contactIds, opts) trust.merge human\n// depart(contactId, opts{relationshipId?}) trust.depart human\n// decide(promptId, choice, opts) prompt.decide human\n// addDevice(name, opts) identity.addDevice human\n// revokeDevice(name, opts) identity.revokeDevice human\n// rotateAnchor(opts) identity.rotate human\n// setProfile({name, image?, text?}, opts) profile.set human\n// show(opts{name?}) encounter.show human\n// scan(card, opts{name?}) encounter.scan human\n// captureSentCard(card, opts) encounter.capture human\n// counter(contactId, opts) encounter.counter human\n// foundGroup({name, vouchThreshold?, listed?}, opts) membership.found human\n// invite(groupId, contactId, opts) membership.invite human\n// vouchFor(groupId, member, opts{provenance?}) membership.vouch human\n// introduce(requesterId, targetId, opts) introduction.introduce human\n// sendMessage(contactId, text, opts{replyTo?}) message.send human\n// block(contactId, opts) message.block {blocked: true} human\n// unblock(contactId, opts) message.block {blocked: false} human\n// recover({when}) trust.recover not human\n// takeMessages(ids, {when}) message.take not human\n// and the read deviceKey(name, contextLabel): the device key of a held,\n// unrevoked name under an own anchor context (identity-state.ts).\n// A missing actId is refused at runtime as actid-missing.\n//\n// One actId, one result: replay(actId, when) reads the journaled result of\n// any of the human acts above (its events: for sendMessage `message.sent`\n// with mid and digest; its commit time; its documents and whether a repeat\n// would hand them out at `when`), or answers unknown-act. It runs nothing\n// and commits nothing, needs no keys, and works on every opening over the\n// store. A repeat of the act under the same actId answers the same events\n// at any clock, across a lock and a new opening; the journal holds an act\n// for the retention max(P90D, retry.horizonMs) after its commit and after\n// the last step of each of its documents, in holder time (engine.ts),\n// after which the actId is unknown. An app that does not\n// know whether an act committed (a crash, an unknown-commit-outcome, a\n// lock) asks replay; on unknown-act the act did not commit or has left\n// the journal, and only the human decides to act anew.\n//\n// Reading: the views (views.ts) over one snapshot each, carrying its\n// commitSeq. `subscribe` announces every commit with its commitSeq and\n// events; the app re-reads the views it shows, and a view read after the\n// announcement is at that commitSeq or later.\n//\n// Delivery: `receive(env, when)` runs Delivery §6.2 in the core and\n// dispatches through the task register (receive.ts); `report` takes the\n// adapter's reports (on an ack's digest: accepted or delivered marks it\n// sent, failed gives it up, awaiting-transport records that the adapter\n// holds it); `resume` re-emits, runs due duties and re-emits unsent acks;\n// `tick` expires and retains (engine.ts).\n//\n// Custody (Delivery 0.83 RLTP-DEL-6120 to 6135): the holder keeps every\n// outbound document until a service takes it or the holder gives it up,\n// across a lock and the end of a process. One createHolder is one opening.\n// After its first resume, `pendingTransport(when)` names what is to be\n// handed over: the outbox items neither terminal nor accepted (held ones\n// included) and the unsent acks, each with its envelope, its first\n// submission and its deadline, none past it. A transport hands over only\n// such entries, through `handOver(entry, when, start)`: the check of\n// `mayHandOver` and the start of the deposit in one step of the holder's\n// queue, true only for an entry this opening issued that is still pending,\n// unchanged, before its deadline. A duplicate's stored ack past its retries\n// appears once as a `resend` entry (Delivery RLTP-DEL-6330). A document missing from the\n// view is no longer to be sent. `await close()` ends the opening at a lock or\n// the end of a process (resolved once the running operation finished, the\n// moment the next opening may start): every later call rejects with InfraError\n// 'closed', mayHandOver answers false, and nothing issued before\n// authorizes anything; the next opening is a new createHolder over the\n// same store, resumed first.\nimport { createEngine } from './engine.js'\nimport type { CommitListener, EnginePorts, HolderModule, TransportEntry, TransportRefusal, TransportView } from './engine.js'\nimport type { DeliveryReport } from './ports.js'\nimport { DECIDE, collectDecisions, promptsModule } from './prompts.js'\nimport type { ActResult, ReceiveResult, ReplayResult, ResumeResult } from './results.js'\nimport { InfraError } from './results.js'\nimport { commitViolations } from './invariants.js'\nimport type { CommitOp } from './invariants.js'\nimport type { HolderState } from './state.js'\nimport { toOpaque } from './state.js'\nimport { trustModule } from './trust/mapping.js'\nimport { IDENTITY_COMMANDS, deviceKeyOf, identityModule } from './identity-state.js'\nimport type { DeviceKeyResult } from './identity-state.js'\nimport { PROFILE_SET } from './trust/profile.js'\nimport type { ProfileContent } from './profile.js'\nimport type { Dec, Millis, OpaqueHolderState, PromptChoice, Setting, TrustClass } from './state.js'\nimport { TRUST_COMMANDS } from './trust/mapping.js'\nimport { ENTRY_COMMANDS } from './trust/entries.js'\nimport { ENCOUNTER_COMMANDS, encounterModule } from './encounter/ceremony.js'\nimport { MEMBERSHIP_COMMANDS, localAccess, membershipModule } from './membership/holder.js'\nimport { INTRODUCTION_COMMANDS, introductionModule } from './introduction/holder.js'\nimport { MESSAGE_COMMANDS, messageModule } from './message/holder.js'\nimport type { Json } from './core.js'\nimport { contactView, contactsView, deliveryStatusView, groupsView, inboxView, profileView, promptsView } from './views.js'\nimport type { ContactView, DeliveryStatusView, GroupView, InboxMessageView, ProfileView, PromptView } from './views.js'\n\n/** The committed state and its commitSeq; the state is opaque (note §4.5):\n * apps read the views, store tooling may persist it. */\nexport interface HolderSnapshot { commitSeq: Dec, state: OpaqueHolderState }\n\nexport interface HolderOptions {\n /** domain modules to register beside the built-ins, the prompts and the trust module */\n modules?: readonly HolderModule[]\n /** testing mode: check the invariants of invariants.ts on every commit,\n * before the store's CAS; a violation throws InfraError\n * 'invariant-violated' (cause: the violations) and nothing commits */\n invariants?: boolean\n}\n\n/** The options of a human act (note §4.2): its time and the actId the app\n * mints when the human acts. */\nexport interface HumanActOptions { when: Millis, actId: string }\n\nexport interface Holder {\n /** any registered command by name, for modules and tests; apps use the typed acts */\n act (command: string, input: unknown, when: Millis, opts?: { actId?: string }): Promise<ActResult>\n /** the human's decision on an open prompt: a human act under the app's\n * actId (note §4.2); a missing actId is also refused at runtime */\n decide (promptId: string, choice: PromptChoice, opts: HumanActOptions): Promise<ActResult>\n /** the Trust act: the anchor mapping class on toward the contact (2770); human */\n trust (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** trust withdrawn: the anchor mapping class off (2840, 2850); human */\n untrust (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** the pause of 5.4: star and blinded group star off, or back to default; human */\n pauseTrust (contactId: string, paused: boolean, opts: HumanActOptions): Promise<ActResult>\n /** one class's setting toward the contact (2780, 2810); human */\n setClass (contactId: string, cls: TrustClass, setting: Setting, opts: HumanActOptions): Promise<ActResult>\n /** the sealed group star's setting for one group toward the contact (2830); human */\n setGroupClass (contactId: string, groupId: string, setting: Setting, opts: HumanActOptions): Promise<ActResult>\n /** the manual merge (6640): at most one of them holds an entry; human */\n merge (contactIds: string[], opts: HumanActOptions): Promise<ActResult>\n /** departure (2260): the entry, the relationships of an alias, or one\n * relationship (relationshipId); human */\n depart (contactId: string, opts: HumanActOptions & { relationshipId?: string }): Promise<ActResult>\n /** 2240: entries re-commit from verified mappings recovered without them; not human */\n recover (opts: { when: Millis }): Promise<ActResult>\n /** a device name into the register before any key derived from it is presented (Identity §5.5); human */\n addDevice (name: string, opts: HumanActOptions): Promise<ActResult>\n /** the name's revocation mark: never removed, the name never given again (Identity §5.5); human */\n revokeDevice (name: string, opts: HumanActOptions): Promise<ActResult>\n /** the community anchor's rotation (Identity §5.4): step 1 (label,\n * closure, 6596 decided) when none runs, else step 2 of the running one\n * through the Log port; resume carries step 2 on its own (identity-state.ts) */\n rotateAnchor (opts: HumanActOptions): Promise<ActResult>\n /** the own profile (Trust 6b): validated (6430, 6435, 6475), the next\n * revision of the one counter (6450), delivered on every relationship\n * the profile class is on for (6455); human */\n setProfile (content: ProfileContent, opts: HumanActOptions): Promise<ActResult>\n /** a displayed card with a fresh own challenge under a fresh pair\n * anchor (Encounter 5.3, 4.4): the event encounter.shown carries the\n * card to display; `name` the card's display name (default: the own\n * profile's); human */\n show (opts: HumanActOptions & { name?: string }): Promise<ActResult>\n /** the scanner's step on a displayed card (Encounter 5.8): the record,\n * the fresh tuple, the bundle; encounter.scanned carries the sent card\n * for the optical leg; human */\n scan (card: Json, opts: HumanActOptions & { name?: string }): Promise<ActResult>\n /** the optical leg (Encounter 5.8, 5710): a sent card shown by the scanner; human */\n captureSentCard (card: Json, opts: HumanActOptions): Promise<ActResult>\n /** the counter-step toward a contact met as displayer (Encounter 5.8 step 4); human */\n counter (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** a group founded under a fresh pair anchor (Access 3.4.1); its rule\n * vouchThreshold (default \"1\") is group state; event group.founded; human */\n foundGroup (group: { name: string, vouchThreshold?: string, listed?: boolean }, opts: HumanActOptions): Promise<ActResult>\n /** invite a contact into a group: the prelude, then the invite on its\n * answer (Membership 1.2, 3.1); the contact decides on a group-invite\n * prompt; human */\n invite (groupId: string, contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** the mediator's act (Trust §8, this library's start of it): the\n * requester gets an offer naming the target by an opaque designator and\n * at most the `label` the human types here, with the mediator's\n * ack-delay declaration; the requester decides on an\n * `introduction` prompt, the target on another; human */\n introduce (requesterId: string, targetId: string, opts: HumanActOptions & { label?: string }): Promise<ActResult>\n /** a vouch@2 for a member anchor whose consent pair this holder holds\n * (Access 5.3, Membership 3.4); human */\n vouchFor (groupId: string, member: string, opts: HumanActOptions & { provenance?: 'met' | 'introduced' }): Promise<ActResult>\n /** a text message to the contact (Message Tasks 3, 5): 1 to 4096 code\n * points, replyTo the mid of an earlier message of the relationship. It\n * goes on a ready, unblocked relationship (canMessage); otherwise refused\n * as not-ready, blocked or no-own-channel, and the app keeps it unsent.\n * Event message.sent {mid, digest}; deliveryStatus(digest) is its sender\n * status. Undelivered, it ends as failed(expired-by-adapter-policy) at\n * the retry horizon (P7D by default, P90D at most), before its sender\n * lifetime sentAt + P179D: failed(task-expired) is not reached for a\n * message under any horizon the engine admits; human */\n sendMessage (contactId: string, text: string, opts: HumanActOptions & { replyTo?: string }): Promise<ActResult>\n /** the inbox entries the app has durably taken over leave the inbox\n * (4420); their completion record stays (4350); not human */\n takeMessages (ids: string[], opts: { when: Millis }): Promise<ActResult>\n /** the block (Message Tasks 6): set on every relationship of the\n * contact's entry. Messages, invitations and the holder's own offers on\n * them stop; the protocol steps owed continue; the contact observes\n * nothing it would not without the block. Event contact.blocked; human */\n block (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** the block cleared on every relationship of the entry: nothing that\n * was discarded under it reappears (6510); human */\n unblock (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** the device key of a held, unrevoked device name under an own anchor\n * context (Identity §5.5); reads, changes nothing */\n deviceKey (name: string, contextLabel: string): Promise<DeviceKeyResult>\n tick (when: Millis): Promise<ActResult>\n resume (when: Millis): Promise<ResumeResult>\n report (report: DeliveryReport, when: Millis): Promise<ActResult>\n /** an arriving envelope, as the app's transport delivered it (non-human,\n * no actId; idempotent over the document digest) */\n receive (env: unknown, when: Millis): Promise<ReceiveResult>\n /** after every commit: its commitSeq and events, the cue to re-read the views */\n subscribe (listener: CommitListener): () => void\n snapshot (): Promise<HolderSnapshot>\n contacts (): Promise<ContactView[]>\n /** by entry id or alias */\n contact (id: string): Promise<ContactView | undefined>\n groups (): Promise<GroupView[]>\n profile (): Promise<ProfileView>\n prompts (): Promise<PromptView[]>\n /** the messages accepted and not yet taken over (Message Tasks 4.5),\n * by display time; event message.received announces each */\n inbox (): Promise<InboxMessageView[]>\n /** by document digest or threadId */\n deliveryStatus (digestOrThreadId: string): Promise<DeliveryStatusView>\n /** the journaled result of the human act `actId` (any of the acts above:\n * for sendMessage its `message.sent` event with `mid` and `digest`), or\n * `{ok: false, code: 'unknown-act'}`; a pure read that never runs the\n * act, never mints a mid, commits nothing. The question an app asks\n * after a crash or a lock instead of repeating the act blind */\n replay (actId: string, when: Millis): Promise<ReplayResult>\n /** what the holder keeps for transport at `when`, after this opening's\n * first completed resume (else `{ok: false, code: 'not-resumed'}`) */\n pendingTransport (when: Millis): Promise<TransportView | TransportRefusal>\n /** right before a hand-over: whether this opening's `entry` may go now */\n mayHandOver (entry: TransportEntry, when: Millis): Promise<boolean>\n /** the hand-over: the same check, then `start()` (which starts the\n * deposit synchronously and says whether it did) inside the holder's\n * queue; true when both said yes */\n handOver (entry: TransportEntry, when: Millis, start: () => boolean): Promise<boolean>\n /** ends this opening (a lock, the end of a process); resolves once the\n * operation running at the call has finished: after that the opening\n * commits nothing more, and the next opening may start */\n close (): Promise<void>\n readonly closed: boolean\n}\n\n/** A holder over its ports: `{store, keys, entropy?, log?, access?, retry?, crypto?}`.\n * The crypto handle (default globalThis.crypto) is resolved and probed\n * here and also feeds the default entropy; an app that injects one\n * passes the same handle to seedKeys(seed, crypto). */\nexport async function createHolder (ports: EnginePorts, opts: HolderOptions = {}): Promise<Holder> {\n const modules = [identityModule(), trustModule(), encounterModule(), membershipModule(), introductionModule(), messageModule(), ...(opts.modules ?? [])]\n const check = opts.invariants === true\n ? (before: Readonly<HolderState>, after: Readonly<HolderState>, op: CommitOp) => {\n const v = commitViolations(before, after, op)\n if (v.length) throw new InfraError('invariant-violated', `invariants broken by ${op.kind}: ${v.map((x) => `[${x.invariant}] ${x.detail}`).join('; ')}`, { cause: v })\n }\n : undefined\n const engine = await createEngine(ports, [promptsModule(collectDecisions(modules)), ...modules], { ...(check ? { check } : {}), accessFrom: localAccess })\n const read = async () => (await engine.snapshot()).state\n /** a human act: `when` and actId from the options, a missing actId refused by the engine */\n const human = (command: string, input: unknown, o: HumanActOptions | undefined) =>\n engine.act(command, input, o?.when as Millis, o?.actId === undefined ? {} : { actId: o.actId })\n return Object.freeze({\n act: (command: string, input: unknown, when: Millis, o?: { actId?: string }) => engine.act(command, input, when, o),\n decide: (promptId: string, choice: PromptChoice, o: HumanActOptions) => human(DECIDE, { promptId, choice }, o),\n trust: (contactId: string, o: HumanActOptions) => human(TRUST_COMMANDS.set, { contactId, on: true }, o),\n untrust: (contactId: string, o: HumanActOptions) => human(TRUST_COMMANDS.set, { contactId, on: false }, o),\n pauseTrust: (contactId: string, paused: boolean, o: HumanActOptions) => human(TRUST_COMMANDS.pause, { contactId, paused }, o),\n setClass: (contactId: string, cls: TrustClass, setting: Setting, o: HumanActOptions) => human(TRUST_COMMANDS.setClass, { contactId, cls, setting }, o),\n setGroupClass: (contactId: string, groupId: string, setting: Setting, o: HumanActOptions) =>\n human(TRUST_COMMANDS.setGroupClass, { contactId, groupId, setting }, o),\n merge: (contactIds: string[], o: HumanActOptions) => human(ENTRY_COMMANDS.merge, { contactIds }, o),\n depart: (contactId: string, o: HumanActOptions & { relationshipId?: string }) =>\n human(ENTRY_COMMANDS.depart, o?.relationshipId === undefined ? { contactId } : { contactId, relationshipId: o.relationshipId }, o),\n recover: (o: { when: Millis }) => engine.act(TRUST_COMMANDS.recover, {}, o?.when as Millis),\n rotateAnchor: (o: HumanActOptions) => human(IDENTITY_COMMANDS.rotate, {}, o),\n setProfile: (content: ProfileContent, o: HumanActOptions) => human(PROFILE_SET, content, o),\n show: (o: HumanActOptions & { name?: string }) => human(ENCOUNTER_COMMANDS.show, o?.name === undefined ? {} : { name: o.name }, o),\n scan: (card: Json, o: HumanActOptions & { name?: string }) => human(ENCOUNTER_COMMANDS.scan, o?.name === undefined ? { card } : { card, name: o.name }, o),\n captureSentCard: (card: Json, o: HumanActOptions) => human(ENCOUNTER_COMMANDS.capture, { card }, o),\n counter: (contactId: string, o: HumanActOptions) => human(ENCOUNTER_COMMANDS.counter, { contactId }, o),\n foundGroup: (g: { name: string, vouchThreshold?: string, listed?: boolean }, o: HumanActOptions) => human(MEMBERSHIP_COMMANDS.found, g, o),\n invite: (groupId: string, contactId: string, o: HumanActOptions) => human(MEMBERSHIP_COMMANDS.invite, { groupId, contactId }, o),\n vouchFor: (groupId: string, member: string, o: HumanActOptions & { provenance?: 'met' | 'introduced' }) =>\n human(MEMBERSHIP_COMMANDS.vouch, o?.provenance === undefined ? { groupId, member } : { groupId, member, provenance: o.provenance }, o),\n introduce: (requesterId: string, targetId: string, o: HumanActOptions & { label?: string }) =>\n human(INTRODUCTION_COMMANDS.introduce, o?.label === undefined ? { requesterId, targetId } : { requesterId, targetId, label: o.label }, o),\n sendMessage: (contactId: string, text: string, o: HumanActOptions & { replyTo?: string }) =>\n human(MESSAGE_COMMANDS.send, o?.replyTo === undefined ? { contactId, text } : { contactId, text, replyTo: o.replyTo }, o),\n takeMessages: (ids: string[], o: { when: Millis }) => engine.act(MESSAGE_COMMANDS.take, { ids }, o?.when as Millis),\n block: (contactId: string, o: HumanActOptions) => human(MESSAGE_COMMANDS.block, { contactId, blocked: true }, o),\n unblock: (contactId: string, o: HumanActOptions) => human(MESSAGE_COMMANDS.block, { contactId, blocked: false }, o),\n addDevice: (name: string, o: HumanActOptions) => human(IDENTITY_COMMANDS.addDevice, { name }, o),\n revokeDevice: (name: string, o: HumanActOptions) => human(IDENTITY_COMMANDS.revokeDevice, { name }, o),\n deviceKey: async (name: string, contextLabel: string) => deviceKeyOf(await read(), ports.keys, name, contextLabel),\n tick: (when: Millis) => engine.tick(when),\n resume: (when: Millis) => engine.resume(when),\n report: (report: DeliveryReport, when: Millis) => engine.report(report, when),\n receive: (env: unknown, when: Millis) => engine.receive(env, when),\n subscribe: (listener: CommitListener) => engine.subscribe(listener),\n snapshot: async (): Promise<HolderSnapshot> => {\n const s = await engine.snapshot()\n return Object.freeze({ commitSeq: s.commitSeq, state: toOpaque(s.state) })\n },\n contacts: async () => contactsView(await read()),\n contact: async (id: string) => contactView(await read(), id),\n groups: async () => groupsView(await read()),\n profile: async () => profileView(await read()),\n prompts: async () => promptsView(await read()),\n inbox: async () => inboxView(await read()),\n deliveryStatus: async (x: string) => deliveryStatusView(await read(), x),\n replay: (actId: string, when: Millis) => engine.replay(actId, when),\n pendingTransport: (when: Millis) => engine.pendingTransport(when),\n mayHandOver: (entry: TransportEntry, when: Millis) => engine.mayHandOver(entry, when),\n handOver: (entry: TransportEntry, when: Millis, start: () => boolean) => engine.handOver(entry, when, start),\n close: () => engine.close(),\n get closed () { return engine.closed },\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"holder-api.js","sourceRoot":"","sources":["../src/holder-api.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,wEAAwE;AACxE,qEAAqE;AACrE,4EAA4E;AAC5E,wEAAwE;AACxE,sEAAsE;AACtE,uEAAuE;AACvE,uEAAuE;AACvE,0EAA0E;AAC1E,wIAAwI;AACxI,0EAA0E;AAC1E,wEAAwE;AACxE,yEAAyE;AACzE,yEAAyE;AACzE,wEAAwE;AACxE,oEAAoE;AACpE,EAAE;AACF,sEAAsE;AACtE,uEAAuE;AACvE,0EAA0E;AAC1E,yEAAyE;AACzE,qEAAqE;AACrE,SA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E;QAC3B,IAAI,MAAM,KAAM,OAAO,MAAM,CAAC,MAAM,CAAA,CAAC,CAAC;KACvC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["// holder-api — createHolder, the facade over the engine (lib Stage 2,\n// note §4.1, §4.5). Domain modules (identity, encounter, trust, continuity,\n// membership, profile) register with the engine as they graduate; today\n// the facade carries the engine's built-ins, the prompts module, the\n// encounter module (encounter/ceremony.ts: show, scan, the optical leg, the\n// counter-step, the bundle and the credential delivery), the membership\n// module (membership/holder.ts: founding, the prelude and invite, the\n// accept on a group-invite prompt, admission and welcome, evidence and\n// vouches; and the in-library Access over the holder's groups where no\n// Access port is given), the introduction module (introduction/holder.ts:\n// the three roles of Trust §8 and the mediator's start), the identity module (identity-state.ts: device names, the rotation), the trust\n// module (trust/mapping.ts: the Trust act, the class settings, the anchor\n// mapping's issuance and reception, the entry commit; trust/star.ts and\n// trust/group-star.ts: the star and the group star, reconciled on resume\n// and received with their assemblies; trust/entries.ts: merge, split and\n// departure; trust/continuity.ts: the probe, the continuity mapping and\n// the chaining; trust/profile.ts: profile@1) and the modules given.\n//\n// The human acts (note §4.2) are typed methods with an options object\n// `{when, actId}`; actId is required, minted by the app when the human\n// acts, and journaled with the act's result (a repeat with the same actId\n// replays it, another input under it is actid-conflict). They wrap `act`\n// with the trust module's command names, which stays for modules and\n// tests:\n// trust(contactId, opts) trust.set {on: true} human\n// untrust(contactId, opts) trust.set {on: false} human\n// pauseTrust(contactId, paused, opts) trust.pause human\n// setClass(contactId, cls, setting, opts) trust.setClass human\n// setGroupClass(contactId, groupId, setting, opts) trust.setGroupClass human\n// merge(contactIds, opts) trust.merge human\n// depart(contactId, opts{relationshipId?}) trust.depart human\n// decide(promptId, choice, opts) prompt.decide human\n// addDevice(name, opts) identity.addDevice human\n// revokeDevice(name, opts) identity.revokeDevice human\n// rotateAnchor(opts) identity.rotate human\n// setProfile({name, image?, text?}, opts) profile.set human\n// show(opts{name?, carrier?}) encounter.show human\n// scan(card, opts{name?, carrier?}) encounter.scan human\n// captureSentCard(card, opts) encounter.capture human\n// counter(contactId, opts) encounter.counter human\n// foundGroup({name, vouchThreshold?, listed?}, opts) membership.found human\n// invite(groupId, contactId, opts) membership.invite human\n// vouchFor(groupId, member, opts{provenance?}) membership.vouch human\n// introduce(requesterId, targetId, opts) introduction.introduce human\n// sendMessage(contactId, text, opts{replyTo?}) message.send human\n// block(contactId, opts) message.block {blocked: true} human\n// unblock(contactId, opts) message.block {blocked: false} human\n// recover({when}) trust.recover not human\n// takeMessages(ids, {when}) message.take not human\n// and the read deviceKey(name, contextLabel): the device key of a held,\n// unrevoked name under an own anchor context (identity-state.ts).\n// A missing actId is refused at runtime as actid-missing.\n//\n// One actId, one result: replay(actId, when) reads the journaled result of\n// any of the human acts above (its events: for sendMessage `message.sent`\n// with mid and digest; its commit time; its documents and whether a repeat\n// would hand them out at `when`), or answers unknown-act. It runs nothing\n// and commits nothing, needs no keys, and works on every opening over the\n// store. A repeat of the act under the same actId answers the same events\n// at any clock, across a lock and a new opening; the journal holds an act\n// for the retention max(P90D, retry.horizonMs) after its commit and after\n// the last step of each of its documents, in holder time (engine.ts),\n// after which the actId is unknown. An app that does not\n// know whether an act committed (a crash, an unknown-commit-outcome, a\n// lock) asks replay; on unknown-act the act did not commit or has left\n// the journal, and only the human decides to act anew.\n//\n// Reading: the views (views.ts) over one snapshot each, carrying its\n// commitSeq. `subscribe` announces every commit with its commitSeq and\n// events; the app re-reads the views it shows, and a view read after the\n// announcement is at that commitSeq or later.\n//\n// Delivery: `receive(env, when)` runs Delivery §6.2 in the core and\n// dispatches through the task register (receive.ts); `report` takes the\n// adapter's reports (on an ack's digest: accepted or delivered marks it\n// sent, failed gives it up, awaiting-transport records that the adapter\n// holds it); `resume` re-emits, runs due duties and re-emits unsent acks;\n// `tick` expires and retains (engine.ts).\n//\n// Custody (Delivery 0.83 RLTP-DEL-6120 to 6135): the holder keeps every\n// outbound document until a service takes it or the holder gives it up,\n// across a lock and the end of a process. One createHolder is one opening.\n// After its first resume, `pendingTransport(when)` names what is to be\n// handed over: the outbox items neither terminal nor accepted (held ones\n// included) and the unsent acks, each with its envelope, its first\n// submission and its deadline, none past it. A transport hands over only\n// such entries, through `handOver(entry, when, start)`: the check of\n// `mayHandOver` and the start of the deposit in one step of the holder's\n// queue, true only for an entry this opening issued that is still pending,\n// unchanged, before its deadline. A duplicate's stored ack past its retries\n// appears once as a `resend` entry (Delivery RLTP-DEL-6330). A document missing from the\n// view is no longer to be sent. `await close()` ends the opening at a lock or\n// the end of a process (resolved once the running operation finished, the\n// moment the next opening may start): every later call rejects with InfraError\n// 'closed', mayHandOver answers false, and nothing issued before\n// authorizes anything; the next opening is a new createHolder over the\n// same store, resumed first.\nimport { createEngine } from './engine.js'\nimport type { CommitListener, EnginePorts, HolderModule, TransportEntry, TransportRefusal, TransportView } from './engine.js'\nimport type { DeliveryReport } from './ports.js'\nimport { DECIDE, collectDecisions, promptsModule } from './prompts.js'\nimport type { ActResult, ReceiveResult, ReplayResult, ResumeResult } from './results.js'\nimport { InfraError } from './results.js'\nimport { commitViolations } from './invariants.js'\nimport type { CommitOp } from './invariants.js'\nimport type { HolderState } from './state.js'\nimport { toOpaque } from './state.js'\nimport { trustModule } from './trust/mapping.js'\nimport { IDENTITY_COMMANDS, deviceKeyOf, identityModule } from './identity-state.js'\nimport type { DeviceKeyResult } from './identity-state.js'\nimport { PROFILE_SET } from './trust/profile.js'\nimport type { ProfileContent } from './profile.js'\nimport type { Dec, Millis, OpaqueHolderState, PromptChoice, Setting, TrustClass } from './state.js'\nimport { TRUST_COMMANDS } from './trust/mapping.js'\nimport { ENTRY_COMMANDS } from './trust/entries.js'\nimport { ENCOUNTER_COMMANDS, encounterModule } from './encounter/ceremony.js'\nimport { MEMBERSHIP_COMMANDS, localAccess, membershipModule } from './membership/holder.js'\nimport { INTRODUCTION_COMMANDS, introductionModule } from './introduction/holder.js'\nimport { MESSAGE_COMMANDS, messageModule } from './message/holder.js'\nimport type { Json } from './core.js'\nimport { b64uOf } from './core.js'\nimport { contactView, contactsView, deliveryStatusView, groupsView, inboxView, profileView, promptsView } from './views.js'\nimport type { ContactView, DeliveryStatusView, GroupView, InboxMessageView, ProfileView, PromptView } from './views.js'\n\n/** The committed state and its commitSeq; the state is opaque (note §4.5):\n * apps read the views, store tooling may persist it. */\nexport interface HolderSnapshot { commitSeq: Dec, state: OpaqueHolderState }\n\nexport interface HolderOptions {\n /** domain modules to register beside the built-ins, the prompts and the trust module */\n modules?: readonly HolderModule[]\n /** testing mode: check the invariants of invariants.ts on every commit,\n * before the store's CAS; a violation throws InfraError\n * 'invariant-violated' (cause: the violations) and nothing commits */\n invariants?: boolean\n}\n\n/** The options of a human act (note §4.2): its time and the actId the app\n * mints when the human acts. */\nexport interface HumanActOptions { when: Millis, actId: string }\n\n/** A carrier offer for the card of show or scan: the relationship's\n * carrier nonce N, 32 bytes the app draws fresh (Identity §7a.3), and the\n * delivery hints it built from N for the card (at least one; Encounter\n * 6090: at most eight, each at most 512 characters; their form is the carrier\n * profile's, e.g. the VTI mediator adapter profile §1b). The library\n * signs the hints into the card, records N in the register under the\n * relationship the card opens, and interprets neither. */\nexport interface CarrierOffer { nonce: Uint8Array, deliveryHints: readonly string[] }\n\n/** The offer as act input: N in canonical base64url (bound and journaled with the act). */\nconst offerInput = (c: CarrierOffer | undefined): Record<string, Json> | undefined => c === undefined ? undefined : {\n nonce: c?.nonce instanceof Uint8Array ? b64uOf(c.nonce) : null,\n deliveryHints: Array.isArray(c?.deliveryHints) ? [...c.deliveryHints] : null,\n}\n\nexport interface Holder {\n /** any registered command by name, for modules and tests; apps use the typed acts */\n act (command: string, input: unknown, when: Millis, opts?: { actId?: string }): Promise<ActResult>\n /** the human's decision on an open prompt: a human act under the app's\n * actId (note §4.2); a missing actId is also refused at runtime */\n decide (promptId: string, choice: PromptChoice, opts: HumanActOptions): Promise<ActResult>\n /** the Trust act: the anchor mapping class on toward the contact (2770); human */\n trust (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** trust withdrawn: the anchor mapping class off (2840, 2850); human */\n untrust (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** the pause of 5.4: star and blinded group star off, or back to default; human */\n pauseTrust (contactId: string, paused: boolean, opts: HumanActOptions): Promise<ActResult>\n /** one class's setting toward the contact (2780, 2810); human */\n setClass (contactId: string, cls: TrustClass, setting: Setting, opts: HumanActOptions): Promise<ActResult>\n /** the sealed group star's setting for one group toward the contact (2830); human */\n setGroupClass (contactId: string, groupId: string, setting: Setting, opts: HumanActOptions): Promise<ActResult>\n /** the manual merge (6640): at most one of them holds an entry; human */\n merge (contactIds: string[], opts: HumanActOptions): Promise<ActResult>\n /** departure (2260): the entry, the relationships of an alias, or one\n * relationship (relationshipId); human */\n depart (contactId: string, opts: HumanActOptions & { relationshipId?: string }): Promise<ActResult>\n /** 2240: entries re-commit from verified mappings recovered without them; not human */\n recover (opts: { when: Millis }): Promise<ActResult>\n /** a device name into the register before any key derived from it is presented (Identity §5.5); human */\n addDevice (name: string, opts: HumanActOptions): Promise<ActResult>\n /** the name's revocation mark: never removed, the name never given again (Identity §5.5); human */\n revokeDevice (name: string, opts: HumanActOptions): Promise<ActResult>\n /** the community anchor's rotation (Identity §5.4): step 1 (label,\n * closure, 6596 decided) when none runs, else step 2 of the running one\n * through the Log port; resume carries step 2 on its own (identity-state.ts) */\n rotateAnchor (opts: HumanActOptions): Promise<ActResult>\n /** the own profile (Trust 6b): validated (6430, 6435, 6475), the next\n * revision of the one counter (6450), delivered on every relationship\n * the profile class is on for (6455); human */\n setProfile (content: ProfileContent, opts: HumanActOptions): Promise<ActResult>\n /** a displayed card with a fresh own challenge under a fresh pair\n * anchor (Encounter 5.3, 4.4): the event encounter.shown carries the\n * card to display; `name` the card's display name (default: the own\n * profile's); `carrier` the delivery hints the card carries and the\n * carrier nonce of the relationship it opens (card-invalid with ref\n * RLTP-ENC-6090, carrier-nonce-invalid); human */\n show (opts: HumanActOptions & { name?: string, carrier?: CarrierOffer }): Promise<ActResult>\n /** the scanner's step on a displayed card (Encounter 5.8): the record,\n * the fresh tuple, the bundle; encounter.scanned carries the sent card\n * for the optical leg; `carrier` as with show, its hints in the sent\n * card; human */\n scan (card: Json, opts: HumanActOptions & { name?: string, carrier?: CarrierOffer }): Promise<ActResult>\n /** the optical leg (Encounter 5.8, 5710): a sent card shown by the scanner; human */\n captureSentCard (card: Json, opts: HumanActOptions): Promise<ActResult>\n /** the counter-step toward a contact met as displayer (Encounter 5.8 step 4); human */\n counter (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** a group founded under a fresh pair anchor (Access 3.4.1); its rule\n * vouchThreshold (default \"1\") is group state; event group.founded; human */\n foundGroup (group: { name: string, vouchThreshold?: string, listed?: boolean }, opts: HumanActOptions): Promise<ActResult>\n /** invite a contact into a group: the prelude, then the invite on its\n * answer (Membership 1.2, 3.1); the contact decides on a group-invite\n * prompt; human */\n invite (groupId: string, contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** the mediator's act (Trust §8, this library's start of it): the\n * requester gets an offer naming the target by an opaque designator and\n * at most the `label` the human types here, with the mediator's\n * ack-delay declaration; the requester decides on an\n * `introduction` prompt, the target on another; human */\n introduce (requesterId: string, targetId: string, opts: HumanActOptions & { label?: string }): Promise<ActResult>\n /** a vouch@2 for a member anchor whose consent pair this holder holds\n * (Access 5.3, Membership 3.4); human */\n vouchFor (groupId: string, member: string, opts: HumanActOptions & { provenance?: 'met' | 'introduced' }): Promise<ActResult>\n /** a text message to the contact (Message Tasks 3, 5): 1 to 4096 code\n * points, replyTo the mid of an earlier message of the relationship. It\n * goes on a ready, unblocked relationship (canMessage); otherwise refused\n * as not-ready, blocked or no-own-channel, and the app keeps it unsent.\n * Event message.sent {mid, digest}; deliveryStatus(digest) is its sender\n * status. Undelivered, it ends as failed(expired-by-adapter-policy) at\n * the retry horizon (P7D by default, P90D at most), before its sender\n * lifetime sentAt + P179D: failed(task-expired) is not reached for a\n * message under any horizon the engine admits; human */\n sendMessage (contactId: string, text: string, opts: HumanActOptions & { replyTo?: string }): Promise<ActResult>\n /** the inbox entries the app has durably taken over leave the inbox\n * (4420); their completion record stays (4350); not human */\n takeMessages (ids: string[], opts: { when: Millis }): Promise<ActResult>\n /** the block (Message Tasks 6): set on every relationship of the\n * contact's entry. Messages, invitations and the holder's own offers on\n * them stop; the protocol steps owed continue; the contact observes\n * nothing it would not without the block. Event contact.blocked; human */\n block (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** the block cleared on every relationship of the entry: nothing that\n * was discarded under it reappears (6510); human */\n unblock (contactId: string, opts: HumanActOptions): Promise<ActResult>\n /** the device key of a held, unrevoked device name under an own anchor\n * context (Identity §5.5); reads, changes nothing */\n deviceKey (name: string, contextLabel: string): Promise<DeviceKeyResult>\n tick (when: Millis): Promise<ActResult>\n resume (when: Millis): Promise<ResumeResult>\n report (report: DeliveryReport, when: Millis): Promise<ActResult>\n /** an arriving envelope, as the app's transport delivered it (non-human,\n * no actId; idempotent over the document digest) */\n receive (env: unknown, when: Millis): Promise<ReceiveResult>\n /** after every commit: its commitSeq and events, the cue to re-read the views */\n subscribe (listener: CommitListener): () => void\n snapshot (): Promise<HolderSnapshot>\n contacts (): Promise<ContactView[]>\n /** by entry id or alias */\n contact (id: string): Promise<ContactView | undefined>\n groups (): Promise<GroupView[]>\n profile (): Promise<ProfileView>\n prompts (): Promise<PromptView[]>\n /** the messages accepted and not yet taken over (Message Tasks 4.5),\n * by display time; event message.received announces each */\n inbox (): Promise<InboxMessageView[]>\n /** by document digest or threadId */\n deliveryStatus (digestOrThreadId: string): Promise<DeliveryStatusView>\n /** the journaled result of the human act `actId` (any of the acts above:\n * for sendMessage its `message.sent` event with `mid` and `digest`), or\n * `{ok: false, code: 'unknown-act'}`; a pure read that never runs the\n * act, never mints a mid, commits nothing. The question an app asks\n * after a crash or a lock instead of repeating the act blind */\n replay (actId: string, when: Millis): Promise<ReplayResult>\n /** what the holder keeps for transport at `when`, after this opening's\n * first completed resume (else `{ok: false, code: 'not-resumed'}`) */\n pendingTransport (when: Millis): Promise<TransportView | TransportRefusal>\n /** right before a hand-over: whether this opening's `entry` may go now */\n mayHandOver (entry: TransportEntry, when: Millis): Promise<boolean>\n /** the hand-over: the same check, then `start()` (which starts the\n * deposit synchronously and says whether it did) inside the holder's\n * queue; true when both said yes */\n handOver (entry: TransportEntry, when: Millis, start: () => boolean): Promise<boolean>\n /** ends this opening (a lock, the end of a process); resolves once the\n * operation running at the call has finished: after that the opening\n * commits nothing more, and the next opening may start */\n close (): Promise<void>\n readonly closed: boolean\n}\n\n/** A holder over its ports: `{store, keys, entropy?, log?, access?, retry?, crypto?}`.\n * The crypto handle (default globalThis.crypto) is resolved and probed\n * here and also feeds the default entropy; an app that injects one\n * passes the same handle to seedKeys(seed, crypto). */\nexport async function createHolder (ports: EnginePorts, opts: HolderOptions = {}): Promise<Holder> {\n const modules = [identityModule(), trustModule(), encounterModule(), membershipModule(), introductionModule(), messageModule(), ...(opts.modules ?? [])]\n const check = opts.invariants === true\n ? (before: Readonly<HolderState>, after: Readonly<HolderState>, op: CommitOp) => {\n const v = commitViolations(before, after, op)\n if (v.length) throw new InfraError('invariant-violated', `invariants broken by ${op.kind}: ${v.map((x) => `[${x.invariant}] ${x.detail}`).join('; ')}`, { cause: v })\n }\n : undefined\n const engine = await createEngine(ports, [promptsModule(collectDecisions(modules)), ...modules], { ...(check ? { check } : {}), accessFrom: localAccess })\n const read = async () => (await engine.snapshot()).state\n /** a human act: `when` and actId from the options, a missing actId refused by the engine */\n const human = (command: string, input: unknown, o: HumanActOptions | undefined) =>\n engine.act(command, input, o?.when as Millis, o?.actId === undefined ? {} : { actId: o.actId })\n return Object.freeze({\n act: (command: string, input: unknown, when: Millis, o?: { actId?: string }) => engine.act(command, input, when, o),\n decide: (promptId: string, choice: PromptChoice, o: HumanActOptions) => human(DECIDE, { promptId, choice }, o),\n trust: (contactId: string, o: HumanActOptions) => human(TRUST_COMMANDS.set, { contactId, on: true }, o),\n untrust: (contactId: string, o: HumanActOptions) => human(TRUST_COMMANDS.set, { contactId, on: false }, o),\n pauseTrust: (contactId: string, paused: boolean, o: HumanActOptions) => human(TRUST_COMMANDS.pause, { contactId, paused }, o),\n setClass: (contactId: string, cls: TrustClass, setting: Setting, o: HumanActOptions) => human(TRUST_COMMANDS.setClass, { contactId, cls, setting }, o),\n setGroupClass: (contactId: string, groupId: string, setting: Setting, o: HumanActOptions) =>\n human(TRUST_COMMANDS.setGroupClass, { contactId, groupId, setting }, o),\n merge: (contactIds: string[], o: HumanActOptions) => human(ENTRY_COMMANDS.merge, { contactIds }, o),\n depart: (contactId: string, o: HumanActOptions & { relationshipId?: string }) =>\n human(ENTRY_COMMANDS.depart, o?.relationshipId === undefined ? { contactId } : { contactId, relationshipId: o.relationshipId }, o),\n recover: (o: { when: Millis }) => engine.act(TRUST_COMMANDS.recover, {}, o?.when as Millis),\n rotateAnchor: (o: HumanActOptions) => human(IDENTITY_COMMANDS.rotate, {}, o),\n setProfile: (content: ProfileContent, o: HumanActOptions) => human(PROFILE_SET, content, o),\n show: (o: HumanActOptions & { name?: string, carrier?: CarrierOffer }) => {\n const carrier = offerInput(o?.carrier)\n return human(ENCOUNTER_COMMANDS.show, { ...(o?.name === undefined ? {} : { name: o.name }), ...(carrier === undefined ? {} : { carrier }) }, o)\n },\n scan: (card: Json, o: HumanActOptions & { name?: string, carrier?: CarrierOffer }) => {\n const carrier = offerInput(o?.carrier)\n return human(ENCOUNTER_COMMANDS.scan, { card, ...(o?.name === undefined ? {} : { name: o.name }), ...(carrier === undefined ? {} : { carrier }) }, o)\n },\n captureSentCard: (card: Json, o: HumanActOptions) => human(ENCOUNTER_COMMANDS.capture, { card }, o),\n counter: (contactId: string, o: HumanActOptions) => human(ENCOUNTER_COMMANDS.counter, { contactId }, o),\n foundGroup: (g: { name: string, vouchThreshold?: string, listed?: boolean }, o: HumanActOptions) => human(MEMBERSHIP_COMMANDS.found, g, o),\n invite: (groupId: string, contactId: string, o: HumanActOptions) => human(MEMBERSHIP_COMMANDS.invite, { groupId, contactId }, o),\n vouchFor: (groupId: string, member: string, o: HumanActOptions & { provenance?: 'met' | 'introduced' }) =>\n human(MEMBERSHIP_COMMANDS.vouch, o?.provenance === undefined ? { groupId, member } : { groupId, member, provenance: o.provenance }, o),\n introduce: (requesterId: string, targetId: string, o: HumanActOptions & { label?: string }) =>\n human(INTRODUCTION_COMMANDS.introduce, o?.label === undefined ? { requesterId, targetId } : { requesterId, targetId, label: o.label }, o),\n sendMessage: (contactId: string, text: string, o: HumanActOptions & { replyTo?: string }) =>\n human(MESSAGE_COMMANDS.send, o?.replyTo === undefined ? { contactId, text } : { contactId, text, replyTo: o.replyTo }, o),\n takeMessages: (ids: string[], o: { when: Millis }) => engine.act(MESSAGE_COMMANDS.take, { ids }, o?.when as Millis),\n block: (contactId: string, o: HumanActOptions) => human(MESSAGE_COMMANDS.block, { contactId, blocked: true }, o),\n unblock: (contactId: string, o: HumanActOptions) => human(MESSAGE_COMMANDS.block, { contactId, blocked: false }, o),\n addDevice: (name: string, o: HumanActOptions) => human(IDENTITY_COMMANDS.addDevice, { name }, o),\n revokeDevice: (name: string, o: HumanActOptions) => human(IDENTITY_COMMANDS.revokeDevice, { name }, o),\n deviceKey: async (name: string, contextLabel: string) => deviceKeyOf(await read(), ports.keys, name, contextLabel),\n tick: (when: Millis) => engine.tick(when),\n resume: (when: Millis) => engine.resume(when),\n report: (report: DeliveryReport, when: Millis) => engine.report(report, when),\n receive: (env: unknown, when: Millis) => engine.receive(env, when),\n subscribe: (listener: CommitListener) => engine.subscribe(listener),\n snapshot: async (): Promise<HolderSnapshot> => {\n const s = await engine.snapshot()\n return Object.freeze({ commitSeq: s.commitSeq, state: toOpaque(s.state) })\n },\n contacts: async () => contactsView(await read()),\n contact: async (id: string) => contactView(await read(), id),\n groups: async () => groupsView(await read()),\n profile: async () => profileView(await read()),\n prompts: async () => promptsView(await read()),\n inbox: async () => inboxView(await read()),\n deliveryStatus: async (x: string) => deliveryStatusView(await read(), x),\n replay: (actId: string, when: Millis) => engine.replay(actId, when),\n pendingTransport: (when: Millis) => engine.pendingTransport(when),\n mayHandOver: (entry: TransportEntry, when: Millis) => engine.mayHandOver(entry, when),\n handOver: (entry: TransportEntry, when: Millis, start: () => boolean) => engine.handOver(entry, when, start),\n close: () => engine.close(),\n get closed () { return engine.closed },\n })\n}\n"]}
|
package/dist/identity-state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HolderModule } from './engine.js';
|
|
2
|
-
import type { Dec, HolderState, Register } from './state.js';
|
|
2
|
+
import type { CarrierNonce, Dec, HolderState, Register } from './state.js';
|
|
3
3
|
import type { KeyProvider } from './ports.js';
|
|
4
4
|
/** The identity module's command names. */
|
|
5
5
|
export declare const IDENTITY_COMMANDS: Readonly<{
|
|
@@ -17,6 +17,18 @@ export declare const withLabel: (r: Readonly<Register>, label: string) => Regist
|
|
|
17
17
|
/** The register with a pair label and its relationship nonce (Identity
|
|
18
18
|
* §6.1): the nonce is recorded alongside the label and never changes. */
|
|
19
19
|
export declare function withPairNonce(r: Readonly<Register>, label: string, nonce: string): Register;
|
|
20
|
+
/** Does the register hold `nonce` (canonical base64url) as a carrier
|
|
21
|
+
* nonce of any relationship, or as a pair nonce (Identity §7a.3: N is
|
|
22
|
+
* fresh and never a pair nonce)? */
|
|
23
|
+
export declare const carrierNonceHeld: (r: Readonly<Register>, nonce: string) => boolean;
|
|
24
|
+
/** The register with the first carrier-nonce entry of relationship
|
|
25
|
+
* `relId`, generation 1 (Identity §7a.3). A relationship that already
|
|
26
|
+
* holds an entry is not given a second one here: rotation is not this. */
|
|
27
|
+
export declare function withCarrierNonce(r: Readonly<Register>, relId: string, nonce: string): Register;
|
|
28
|
+
/** The canonical carrier-nonce entry of a relationship (Identity §7a.3):
|
|
29
|
+
* the highest generation, among equal ones the nonce whose bytes are
|
|
30
|
+
* smallest in unsigned bytewise order; undefined where none is held. */
|
|
31
|
+
export declare function canonicalCarrierNonce(r: Readonly<Register>, relId: string): CarrierNonce | undefined;
|
|
20
32
|
/** The rotation duty's id for a rotation. */
|
|
21
33
|
export declare const rotationDutyId: (rotationId: string) => string;
|
|
22
34
|
/** A re-issue duty's id after the rotation to generation `to` (6370). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-state.d.ts","sourceRoot":"","sources":["../src/identity-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"identity-state.d.ts","sourceRoot":"","sources":["../src/identity-state.ts"],"names":[],"mappings":"AA8FA,OAAO,KAAK,EAAoC,YAAY,EAAuB,MAAM,aAAa,CAAA;AACtG,OAAO,KAAK,EAAE,YAAY,EAAE,GAAG,EAAQ,WAAW,EAAU,QAAQ,EAA8C,MAAM,YAAY,CAAA;AAEpI,OAAO,KAAK,EAAE,WAAW,EAAW,MAAM,YAAY,CAAA;AAMtD,2CAA2C;AAC3C,eAAO,MAAM,iBAAiB;;;;EAEnB,CAAA;AAEX,yEAAyE;AACzE,eAAO,MAAM,eAAe,QAA8B,CAAA;AAE1D,MAAM,WAAW,WAAW;IAAG,IAAI,EAAE,MAAM,CAAA;CAAE;AAE7C,sEAAsE;AACtE,eAAO,MAAM,SAAS,GAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,MAAM,KAAG,QACkB,CAAA;AAEnF;0EAC0E;AAC1E,wBAAgB,aAAa,CAAE,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAM5F;AAED;;qCAEqC;AACrC,eAAO,MAAM,gBAAgB,GAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,MAAM,KAAG,OACsD,CAAA;AAE9H;;2EAE2E;AAC3E,wBAAgB,gBAAgB,CAAE,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAG/F;AAED;;yEAEyE;AACzE,wBAAgB,qBAAqB,CAAE,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CASrG;AAmDD,6CAA6C;AAC7C,eAAO,MAAM,cAAc,GAAI,YAAY,MAAM,KAAG,MAAkC,CAAA;AACtF,yEAAyE;AACzE,eAAO,MAAM,SAAS,GAAI,IAAI,GAAG,EAAE,OAAO,MAAM,KAAG,MAAkC,CAAA;AAkOrF;8DAC8D;AAC9D,MAAM,MAAM,eAAe,GACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,iBAAiB,CAAA;CAAE,CAAA;AAqBhF;;;;GAIG;AACH,wBAAsB,WAAW,CAAE,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAUhJ;AAED,mEAAmE;AACnE,wBAAgB,cAAc,IAAK,YAAY,CAM9C"}
|
package/dist/identity-state.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { canonicalLabel, communityLabel, deviceLabel, deviceName } from './identity.js';
|
|
2
|
-
import { jcs } from './core.js';
|
|
2
|
+
import { fromB64u, jcs } from './core.js';
|
|
3
3
|
import { bindingOf, rawProofValue } from './anchor.js';
|
|
4
4
|
import { classOnToward, entryOf, entryRelationships, lags, liveRel } from './trust/state.js';
|
|
5
5
|
/** The identity module's command names. */
|
|
@@ -20,6 +20,41 @@ export function withPairNonce(r, label, nonce) {
|
|
|
20
20
|
}
|
|
21
21
|
return { ...withLabel(r, label), pairNonces: { ...r.pairNonces, [label]: nonce } };
|
|
22
22
|
}
|
|
23
|
+
/** Does the register hold `nonce` (canonical base64url) as a carrier
|
|
24
|
+
* nonce of any relationship, or as a pair nonce (Identity §7a.3: N is
|
|
25
|
+
* fresh and never a pair nonce)? */
|
|
26
|
+
export const carrierNonceHeld = (r, nonce) => Object.values(r.carriers).some((list) => list.some((e) => e.nonce === nonce)) || Object.values(r.pairNonces).includes(nonce);
|
|
27
|
+
/** The register with the first carrier-nonce entry of relationship
|
|
28
|
+
* `relId`, generation 1 (Identity §7a.3). A relationship that already
|
|
29
|
+
* holds an entry is not given a second one here: rotation is not this. */
|
|
30
|
+
export function withCarrierNonce(r, relId, nonce) {
|
|
31
|
+
if (Object.hasOwn(r.carriers, relId))
|
|
32
|
+
throw new Error(`identity: ${relId} already holds a carrier nonce (§7a.3)`);
|
|
33
|
+
return { ...r, carriers: { ...r.carriers, [relId]: [{ nonce, generation: '1' }] } };
|
|
34
|
+
}
|
|
35
|
+
/** The canonical carrier-nonce entry of a relationship (Identity §7a.3):
|
|
36
|
+
* the highest generation, among equal ones the nonce whose bytes are
|
|
37
|
+
* smallest in unsigned bytewise order; undefined where none is held. */
|
|
38
|
+
export function canonicalCarrierNonce(r, relId) {
|
|
39
|
+
const list = Object.hasOwn(r.carriers, relId) ? r.carriers[relId] : [];
|
|
40
|
+
let best;
|
|
41
|
+
for (const e of list) {
|
|
42
|
+
if (!best) {
|
|
43
|
+
best = e;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const g = BigInt(e.generation) - BigInt(best.generation);
|
|
47
|
+
if (g > 0n || (g === 0n && bytewiseLess(fromB64u(e.nonce), fromB64u(best.nonce))))
|
|
48
|
+
best = e;
|
|
49
|
+
}
|
|
50
|
+
return best;
|
|
51
|
+
}
|
|
52
|
+
const bytewiseLess = (a, b) => {
|
|
53
|
+
for (let i = 0; i < Math.min(a.length, b.length); i++)
|
|
54
|
+
if (a[i] !== b[i])
|
|
55
|
+
return a[i] < b[i];
|
|
56
|
+
return a.length < b.length;
|
|
57
|
+
};
|
|
23
58
|
const needName = (x, cmd) => {
|
|
24
59
|
if (x === null || typeof x !== 'object' || Array.isArray(x))
|
|
25
60
|
throw new TypeError(`${cmd} needs an input object`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-state.js","sourceRoot":"","sources":["../src/identity-state.ts"],"names":[],"mappings":"AA8FA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAEvF,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE/B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE5F,2CAA2C;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,oBAAoB,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,EAAE,iBAAiB;CACzF,CAAC,CAAA;AAEX,yEAAyE;AACzE,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,gBAAgB,GAAG,CAAC,CAAA;AAI1D,sEAAsE;AACtE,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAqB,EAAE,KAAa,EAAY,EAAE,CAC1E,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAa,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAA;AAEnF;0EAC0E;AAC1E,MAAM,UAAU,aAAa,CAAE,CAAqB,EAAE,KAAa,EAAE,KAAa;IAChF,IAAI,MAAM,CAAC,MAAM,CAAC,CAA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BAAiB,EAAE,CAAA;IACtF,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACrC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACpC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC,YAAY,EAAE,CAAA;AAC5E,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,cAAc;IAC5B,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;QACnF,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;KAClD,CAAC,CAAA;AACJ,CAAC","sourcesContent":["// identity-state — the Identity Layer on the holder (lib Stage 2, PR 6):\n// the label register (Identity §2, §6.3) with its device names and\n// revocation marks (§5.5), and the community anchor's rotation as a\n// resumable procedure over the Log port (§5.4; Trust 6360–6420, 6596;\n// Access §5.6). Module `identity`, built into createHolder.\n//\n// Labels and addresses: a pair label's key is a delivery address (Delivery\n// §5): retired, it becomes a tombstone for ever. A member label\n// group/<digest> is an identity context (§6.1): one derivation per group,\n// reused whenever the holder is invited to that group again, so its key\n// leaves `addresses` without a tombstone (engine.ts tick). The register\n// keeps every label either way.\n//\n// What the module registers:\n// commands identity.addDevice {name} a device name into the\n// register (§5.5), before any key derived from it is\n// presented; human\n// identity.revokeDevice {name} the name's revocation mark\n// (§5.5): never removed, the name never given again; human\n// identity.rotate {} the community anchor's rotation\n// (§5.4): step 1 when none runs, else step 2 of the running\n// one; human (holder.rotateAnchor)\n// duty rotation/1 {rotationId} step 2 on resume, until the log\n// holds the entry\n//\n// The rotation, a procedure in state.rotations (note §2.1, §3 Log: head,\n// at, append):\n// where the log stands (standing), for a rotation g → g+1 (§5.4, RLTP-\n// ACC-5980): the genesis must match; a log whose generation g+1 is\n// held (head.gen ≥ g+1) holds this rotation where at(g+1) names its\n// next and commit (present: this device's append whose answer was\n// lost, or another device of the seed, the log since moved on or not),\n// else a fork (diverged); otherwise the device may append over the\n// head that holds the lineage through g (empty for g = 1, else gen g,\n// next = prev, commit = the binding of next); an earlier head is\n// behind, any other diverged\n// step 1 (identity.rotate, one commit) anchor-rotation@2 built (prev g,\n// next g+1, commit = the binding of g+2) and signed by prev and next\n// through the KeyProvider; the head read and the log's standing checked\n// BEFORE anything commits: behind and diverged are refused (log-behind,\n// log-diverged), so the label and the 6596 decision persist only when\n// the device may rotate. Then in one commit the label of g+1 (§5.4:\n// persisted before any presentation; 6360: before the log entry), per\n// relationship the withholding of 6596 decided against the entry state\n// now (awaitHead: H, the entry's anchor head, where it lags; null where\n// it does not; only where the anchor mapping class is on), the closure\n// {entry: {rotation}, overHead: the head read}, the rotation duty. The\n// register's head stays g: nothing is issued under g+1 before the log\n// holds it, and no device key derives under g+1 (deviceKey)\n// step 2 (the rotation duty on resume, or identity.rotate again) the\n// standing again: present completes without an append; behind and\n// diverged keep the rotation pending (the duty refused, no timer: the\n// log's sync is the cue; the act answers log-behind, log-diverged). An\n// append goes only ever over the head the rotation record names, so the\n// port's idempotence over exactly (entry, overHead) holds across a lost\n// answer: where the head the device may append over is another, it is\n// persisted first (the record's overHead, the duty due at once) and the\n// append follows on the next run. append on appended/exists completes the\n// rotation in one commit: the register's head g+1, the rotation in\n// register.lineage, the rotation and its duty gone, anchor.rotated, and\n// the re-issue duties of 6370 opened from the awaitHead decided at step\n// 1 (reissue-mapping/1, id reissue:<g+1>:<relId>) — and for a live\n// relationship the class is on for now that was not in it (new since\n// step 1), decided at completion. A chaining in between unions the\n// decisions onto the chain (null wins). head-conflict re-reads (four\n// reads); failure, or a port that throws, keeps the rotation pending:\n// the duty is due again after the retry backoff (attempt, lastAt), the\n// act answers log-failure\n// 6380 (the self card under the new anchor wherever it is carried): the\n// card travels only inside anchor-mapping@4 here (6.1 card), so the\n// re-issue of 6370 carries it; no duty of its own until the encounter\n// (PR 7) carries a card elsewhere\n// A throw of the Log port at step 1 is InfraError('log'): nothing\n// commits. Without a Log port the rotation is refused (log-missing); at the last\n// generation 2^53 − 2 it is refused (scope-exhausted, Identity §5.4)\n//\n// Pure register helpers for the modules that open contexts (the encounter\n// in PR 7, continuity.newTuple until then): withLabel, withPairNonce.\n//\n// Choices this file makes where note and spec leave them open:\n// - a device name is stored in its 6.2 canonical form (NFC applied), so\n// the register compares what the derivation uses\n// - a name the register already holds is refused (device-name-held: the\n// SHOULD of §5.5 is followed); a revoked name is refused as\n// device-name-revoked (the MUST)\n// - revoking a name already revoked is ok and changes nothing; revoking\n// a name the register does not hold is unknown-device\n// - deviceKey (holder) derives only for a held, unrevoked name and an\n// own anchor context: a label of the register or a generation of the\n// community anchor up to its head (§5.5: names recorded before any\n// derived key is presented; a revoked name offers no key for a new\n// binding). Reading it changes nothing\nimport type { Applied, CommandDef, DutyHandler, HolderModule, PrepareCtx, Refusal } from './engine.js'\nimport type { Dec, Duty, HolderState, Millis, Register, ReissueMappingDuty, Rotation, RotationDuty } from './state.js'\nimport { canonicalLabel, communityLabel, deviceLabel, deviceName } from './identity.js'\nimport type { KeyProvider, LogHead } from './ports.js'\nimport { jcs } from './core.js'\nimport type { Json } from './core.js'\nimport { bindingOf, rawProofValue } from './anchor.js'\nimport { classOnToward, entryOf, entryRelationships, lags, liveRel } from './trust/state.js'\n\n/** The identity module's command names. */\nexport const IDENTITY_COMMANDS = Object.freeze({\n addDevice: 'identity.addDevice', revokeDevice: 'identity.revokeDevice', rotate: 'identity.rotate',\n} as const)\n\n/** The last generation a rotation moves to (Identity §5.4): 2^53 − 2. */\nexport const GENERATION_LAST = Number.MAX_SAFE_INTEGER - 1\n\nexport interface DeviceInput { name: string }\n\n/** The register with `label` among its labels (a set: added once). */\nexport const withLabel = (r: Readonly<Register>, label: string): Register =>\n r.labels.includes(label) ? r as Register : { ...r, labels: [...r.labels, label] }\n\n/** The register with a pair label and its relationship nonce (Identity\n * §6.1): the nonce is recorded alongside the label and never changes. */\nexport function withPairNonce (r: Readonly<Register>, label: string, nonce: string): Register {\n if (Object.hasOwn(r.pairNonces, label)) {\n if (r.pairNonces[label] !== nonce) throw new Error(`identity: ${label} already holds another relationship nonce (§6.1)`)\n return withLabel(r, label)\n }\n return { ...withLabel(r, label), pairNonces: { ...r.pairNonces, [label]: nonce } }\n}\n\nconst needName = (x: unknown, cmd: string): string => {\n if (x === null || typeof x !== 'object' || Array.isArray(x)) throw new TypeError(`${cmd} needs an input object`)\n const n = (x as { name?: unknown }).name\n if (typeof n !== 'string') throw new TypeError(`${cmd}: name must be a string`)\n return n\n}\n\nconst refuse = (code: Refusal['code'], ref?: string): Refusal => ({ ok: false, code, ...(ref ? { ref } : {}) })\n\nconst commands: Record<string, CommandDef> = {\n // §5.5: the name is persisted before any key derived from it is presented\n [IDENTITY_COMMANDS.addDevice]: {\n human: true,\n apply (state, _p, input: DeviceInput) {\n const n = deviceName(needName(input, IDENTITY_COMMANDS.addDevice))\n if (n === null) return refuse('device-name-invalid', 'Identity §6.2')\n const d = state.register.devices\n if (d.revoked.includes(n)) return refuse('device-name-revoked', 'Identity §5.5')\n if (d.names.includes(n)) return refuse('device-name-held', 'Identity §5.5')\n return {\n state: { ...state, register: { ...state.register, devices: { ...d, names: [...d.names, n] } } },\n events: [{ type: 'device.added', name: n }],\n }\n },\n } satisfies CommandDef<DeviceInput>,\n // §5.5: revocation consumes the name; the mark is never removed\n [IDENTITY_COMMANDS.revokeDevice]: {\n human: true,\n apply (state, _p, input: DeviceInput) {\n const n = deviceName(needName(input, IDENTITY_COMMANDS.revokeDevice))\n const d = state.register.devices\n if (n === null || !d.names.includes(n)) return refuse('unknown-device', 'Identity §5.5')\n if (d.revoked.includes(n)) return { state: state as HolderState }\n return {\n state: { ...state, register: { ...state.register, devices: { ...d, revoked: [...d.revoked, n] } } },\n events: [{ type: 'device.revoked', name: n }],\n }\n },\n } satisfies CommandDef<DeviceInput>,\n}\n\n\n// ── the rotation (Identity §5.4, Trust 6360–6420, 6596, Access §5.6) ──\n\n/** The rotation duty's id for a rotation. */\nexport const rotationDutyId = (rotationId: string): string => `rotation:${rotationId}`\n/** A re-issue duty's id after the rotation to generation `to` (6370). */\nexport const reissueId = (to: Dec, relId: string): string => `reissue:${to}:${relId}`\n\ntype RotationArtifact = { body: { type: 'anchor-rotation@2', prev: string, next: string, commit: string }, proof: { proofValue: string, successorProofValue: string } }\n\n/** What step 2 found at the log. */\ntype LogOutcome =\n | { status: 'done', head: LogHead }\n /** the log stands where this device may rotate, over a head other than\n * the persisted closure's: persist it before appending over it */\n | { status: 'moved', head: LogHead }\n | { status: 'behind' | 'diverged', head: LogHead }\n | { status: 'failure', reason: string }\n | { status: 'log-missing' }\n\ntype Rot = RotationArtifact['body']\n\n/**\n * Where the log stands for the rotation g → g+1 (Identity §5.4, RLTP-ACC-\n * 5980): `present`, its generation g+1 holds this rotation (at(g+1) names\n * this next and commit — appended by this device with its answer lost, or\n * by another device of the same seed, the log since moved on or not);\n * `{over}`, the device may append over that head (empty for g = 1, else\n * the entry that introduced g: gen g, next = prev, commit = the binding of\n * next); `behind`, the log has not reached g; `diverged`, another genesis,\n * another entry at g+1 (a fork), or a head the rotation does not continue.\n */\nasync function standing (ctx: PrepareCtx, head: LogHead, genesis: string, from: number, rot: Rot): Promise<'present' | 'behind' | 'diverged' | { over: string | null }> {\n if (head.genesis !== genesis) return 'diverged'\n if ('empty' in head) return from === 1 ? { over: null } : 'behind'\n if (head.gen >= from + 1) {\n const e = await ctx.log!.at(from + 1)\n return e && e.next === rot.next && e.commit === rot.commit ? 'present' : 'diverged'\n }\n if (head.gen === from && head.next === rot.prev && head.commit === await bindingOf(rot.next, ctx.crypto.subtle)) return { over: head.entryId }\n return head.gen < from ? 'behind' : 'diverged'\n}\n\nconst headId = (h: LogHead): string | null => ('empty' in h ? null : h.entryId)\n\n/**\n * Step 2 through the Log port (see the header): where the log stands, then\n * append(entry, the persisted overHead) — only ever over the head the\n * rotation record names, so the port's idempotence over exactly (entry,\n * overHead) holds across a lost answer; a head that moved is persisted\n * first ('moved'). head-conflict re-reads. A port that throws is a\n * failure: the rotation stays pending.\n */\nasync function logStep (ctx: PrepareCtx, r: Readonly<Rotation>, genesis: string): Promise<LogOutcome> {\n const log = ctx.log\n if (!log) return { status: 'log-missing' }\n const rot = (r.entry as { rotation: RotationArtifact }).rotation\n try {\n for (let i = 0; i < 4; i++) {\n const head = await log.head()\n const at = await standing(ctx, head, genesis, Number(r.from), rot.body)\n if (at === 'present') return { status: 'done', head }\n if (at === 'behind' || at === 'diverged') return { status: at, head }\n if (at.over !== headId(r.overHead) || head.genesis !== r.overHead.genesis) return { status: 'moved', head }\n const a = await log.append({ rotation: rot } as unknown as Json, at.over)\n if (a.status === 'appended' || a.status === 'exists') return { status: 'done', head: a.head }\n if (a.status === 'failure') return { status: 'failure', reason: a.reason }\n // head-conflict: re-read\n }\n return { status: 'failure', reason: 'head-conflict persisted' }\n } catch (e) {\n return { status: 'failure', reason: (e as Error)?.message ?? String(e) }\n }\n}\n\n/** 6596, per relationship: the anchor mapping class on for it (live, under\n * its entry), and whether it lags there — then H, else null. */\nfunction withholding (state: Readonly<HolderState>, relId: string): { contactId: string, awaitHead: string | null } | null {\n const r = state.relationships[relId]\n if (!r || !liveRel(r)) return null\n const e = entryOf(state, r)\n if (!e || !e.relIds.includes(r.id) || !classOnToward(e, 'anchorMapping')) return null\n return { contactId: e.id, awaitHead: lags(r, entryRelationships(state, e)) && e.anchorHead !== null ? e.anchorHead : null }\n}\n\n/** Step 1's commit (see the header). */\nfunction startRotation (state: Readonly<HolderState>, p: { id: string, from: Dec, to: Dec, entry: Json, overHead: LogHead, label: string }, when: Millis): Applied | Refusal {\n const com = state.register.community\n if (com === null || com.head !== p.from || Object.keys(state.rotations).length) return refuse('in-flight')\n const awaitHead: Record<string, string | null> = {}\n for (const id of Object.keys(state.relationships).sort()) {\n const w = withholding(state, id)\n if (w) awaitHead[id] = w.awaitHead\n }\n const rotation: Rotation = { id: p.id, from: p.from, to: p.to, step: 'log', startedAt: when, entry: p.entry, overHead: p.overHead, awaitHead }\n const duty: RotationDuty = { kind: 'rotation', v: 1, id: rotationDutyId(p.id), rotationId: p.id }\n return {\n state: { ...state, register: withLabel(state.register, p.label), rotations: { ...state.rotations, [p.id]: rotation } },\n duties: [duty],\n }\n}\n\n/** The completion's commit: head, lineage, the re-issues of 6370 (6596). */\nfunction completeRotation (state: Readonly<HolderState>, r: Readonly<Rotation>): Applied | Refusal {\n const com = state.register.community\n if (com === null || com.head !== r.from) return refuse('in-flight')\n const rot = (r.entry as { rotation: RotationArtifact }).rotation\n const duties: ReissueMappingDuty[] = []\n const reissue = (relId: string, contactId: string, awaitHead: string | null): void => {\n duties.push({ kind: 'reissue-mapping', v: 1, id: reissueId(r.to, relId), contactId, relId, awaitHead })\n }\n // decided at step 1 (6596), where the class is still on for it now\n for (const [relId, awaitHead] of Object.entries(r.awaitHead).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {\n const w = withholding(state, relId)\n if (w) reissue(relId, w.contactId, awaitHead)\n }\n // on for it now, unknown to step 1: decided now\n for (const relId of Object.keys(state.relationships).sort()) {\n if (Object.hasOwn(r.awaitHead, relId)) continue\n const w = withholding(state, relId)\n if (w) reissue(relId, w.contactId, w.awaitHead)\n }\n const rotations = { ...state.rotations }\n delete rotations[r.id]\n const left = { ...state.duties }\n delete left[rotationDutyId(r.id)]\n return {\n state: {\n ...state,\n register: { ...withLabel(state.register, communityLabel(com.genesis, Number(r.to))), community: { ...com, head: r.to }, lineage: [...state.register.lineage, rot as unknown as Json as Register['lineage'][number]] },\n rotations,\n duties: left,\n },\n events: [{ type: 'anchor.rotated', generation: r.to }],\n duties,\n }\n}\n\n/** What step 2's outcome means for the rotation: completion, or why not. */\nfunction afterLog (state: Readonly<HolderState>, rotationId: string, o: LogOutcome, when: Millis): Applied | Refusal {\n const r = Object.hasOwn(state.rotations, rotationId) ? state.rotations[rotationId] : undefined\n if (!r) return refuse('in-flight')\n switch (o.status) {\n case 'done': return completeRotation(state, r)\n case 'moved': {\n // the closure's head, persisted before any append over it; the duty\n // runs again at once (lastAt marks the change, no dueAt)\n const id = rotationDutyId(r.id)\n const held = Object.hasOwn(state.duties, id) ? state.duties[id] as RotationDuty : { kind: 'rotation' as const, v: 1 as const, id, rotationId: r.id }\n const { dueAt: _, ...rest } = held\n const duty: RotationDuty = { ...rest, lastAt: when }\n // single path: the duty leaves the state and comes back as Applied.duties,\n // on the act path and in resume alike\n const left = { ...state.duties }\n delete left[id]\n return {\n state: { ...state, rotations: { ...state.rotations, [r.id]: { ...r, overHead: o.head } }, duties: left },\n duties: [duty],\n }\n }\n case 'behind': return refuse('log-behind', 'RLTP-ACC-5980')\n case 'diverged': return refuse('log-diverged', 'RLTP-ACC-5980')\n case 'log-missing': return refuse('log-missing')\n case 'failure': return refuse('log-failure')\n }\n}\n\ntype RotatePrepared =\n | { kind: 'refuse', code: Refusal['code'], ref?: string }\n | { kind: 'start', id: string, from: Dec, to: Dec, entry: Json, overHead: LogHead, label: string }\n | { kind: 'resume', rotationId: string, outcome: LogOutcome }\n\nconst rotateCommand: CommandDef<Record<string, never>, RotatePrepared> = {\n human: true,\n async prepare (ctx) {\n const st = ctx.snapshot\n const com = st.register.community\n if (com === null) return { kind: 'refuse', code: 'no-community' }\n if (!ctx.log) return { kind: 'refuse', code: 'log-missing' }\n const running = Object.values(st.rotations)[0]\n if (running) return { kind: 'resume', rotationId: running.id, outcome: await logStep(ctx, running, com.genesis) }\n const g = Number(com.head)\n if (!Number.isSafeInteger(g) || g < 1 || g + 1 > GENERATION_LAST) return { kind: 'refuse', code: 'scope-exhausted', ref: 'Identity §5.4' }\n const [prevL, nextL, afterL] = [g, g + 1, g + 2].map((k) => communityLabel(com.genesis, k))\n const [prev, next, after] = await Promise.all([prevL, nextL, afterL].map((l) => ctx.keys.anchorOf(l)))\n const body = { type: 'anchor-rotation@2' as const, prev: prev.anchor, next: next.anchor, commit: await bindingOf(after.anchor, ctx.crypto.subtle) }\n const bytes = new TextEncoder().encode(jcs(body))\n const rotation: RotationArtifact = {\n body,\n proof: { proofValue: rawProofValue(await ctx.keys.sign(prevL, bytes)), successorProofValue: rawProofValue(await ctx.keys.sign(nextL, bytes)) },\n }\n // §5.4: the device rotates only over the log it holds — checked before\n // anything commits, so label and 6596 decision persist only when it may\n const overHead = await ctx.log.head()\n const at = await standing(ctx, overHead, com.genesis, g, body)\n if (at === 'behind') return { kind: 'refuse', code: 'log-behind', ref: 'RLTP-ACC-5980' }\n if (at === 'diverged') return { kind: 'refuse', code: 'log-diverged', ref: 'RLTP-ACC-5980' }\n const to = String(g + 1)\n return { kind: 'start', id: to, from: com.head, to, entry: { rotation } as unknown as Json, overHead, label: nextL }\n },\n apply (state, prepared, _input, when) {\n const p = prepared.value\n if (p.kind === 'refuse') return refuse(p.code, p.ref)\n if (p.kind === 'start') return startRotation(state, p, when)\n return afterLog(state, p.rotationId, p.outcome, when)\n },\n}\n\n/** The rotation duty (rotation/1): step 2 on resume. */\nconst rotationDuty: DutyHandler<LogOutcome | null> = {\n v: 1,\n async prepare (ctx, duty) {\n const r = ctx.snapshot.rotations[(duty as RotationDuty).rotationId]\n const com = ctx.snapshot.register.community\n return r && com ? logStep(ctx, r, com.genesis) : null\n },\n apply (state, duty, ctx, when) {\n const d = duty as RotationDuty\n // a rotation completed (by the act) or gone: nothing left to do\n if (!Object.hasOwn(state.rotations, d.rotationId)) return { state: state as HolderState }\n const o = ctx.prepared.value\n if (o === null) return 'not-due'\n if (o.status === 'failure') {\n // pending, due again after the retry backoff (the duty's own attempt)\n const attempt = (d.attempt ?? 0) + 1\n const again: RotationDuty = { ...d, attempt, lastAt: when, dueAt: Math.min(when + Math.max(0, Math.ceil(ctx.backoff(attempt))), Number.MAX_SAFE_INTEGER) }\n return { state: state as HolderState, duties: [again] }\n }\n return afterLog(state, d.rotationId, o, when)\n },\n}\n\n/** A device key as deviceKey derives it: the device label, the device's\n * did:key and its key-agreement multikey (Identity §5.5). */\nexport type DeviceKeyResult =\n | { ok: true, label: string, device: string, keyAgreement: string }\n | { ok: false, code: 'unknown-device' | 'device-revoked' | 'unknown-context' }\n\n/** Whether `label` names an own anchor context: a label of the register,\n * or a generation of the community anchor up to its head (§5.4). */\nfunction ownContext (state: Readonly<HolderState>, label: string): boolean {\n if (label.startsWith('device/')) return false\n // the community's generations first, bounded by the head: the label of\n // a pending g+1 is recorded, but no key is presented under it before the\n // rotation completes (§5.4)\n const c = state.register.community\n if (c !== null) {\n const base = communityLabel(c.genesis, 1)\n if (label === base) return true\n if (label.startsWith(base + '/')) {\n const g = BigInt(label.slice(base.length + 1))\n return g >= 2n && g <= BigInt(c.head)\n }\n }\n return state.register.labels.includes(label)\n}\n\n/**\n * The device key of a held, unrevoked device name under an own anchor\n * context (Identity §5.5): derived through the KeyProvider, never stored\n * (keys are not state, 9.3).\n */\nexport async function deviceKeyOf (state: Readonly<HolderState>, keys: KeyProvider, name: string, contextLabel: string): Promise<DeviceKeyResult> {\n const n = deviceName(name)\n const d = state.register.devices\n if (n === null || !d.names.includes(n)) return { ok: false, code: 'unknown-device' }\n if (d.revoked.includes(n)) return { ok: false, code: 'device-revoked' }\n const a = canonicalLabel(contextLabel)\n if (a === null || !ownContext(state, a)) return { ok: false, code: 'unknown-context' }\n const label = await deviceLabel(n, a)\n const k = await keys.anchorOf(label)\n return { ok: true, label, device: k.anchor, keyAgreement: k.keyAgreement }\n}\n\n/** The identity module createHolder builds in (see the header). */\nexport function identityModule (): HolderModule {\n return Object.freeze({\n name: 'identity',\n commands: Object.freeze({ ...commands, [IDENTITY_COMMANDS.rotate]: rotateCommand }),\n duties: Object.freeze({ rotation: rotationDuty }),\n })\n}\n"]}
|
|
1
|
+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ib Stage 2, PR 6):\n// the label register (Identity §2, §6.3) with its device names and\n// revocation marks (§5.5), and the community anchor's rotation as a\n// resumable procedure over the Log port (§5.4; Trust 6360–6420, 6596;\n// Access §5.6). Module `identity`, built into createHolder.\n//\n// Labels and addresses: a pair label's key is a delivery address (Delivery\n// §5): retired, it becomes a tombstone for ever. A member label\n// group/<digest> is an identity context (§6.1): one derivation per group,\n// reused whenever the holder is invited to that group again, so its key\n// leaves `addresses` without a tombstone (engine.ts tick). The register\n// keeps every label either way.\n//\n// What the module registers:\n// commands identity.addDevice {name} a device name into the\n// register (§5.5), before any key derived from it is\n// presented; human\n// identity.revokeDevice {name} the name's revocation mark\n// (§5.5): never removed, the name never given again; human\n// identity.rotate {} the community anchor's rotation\n// (§5.4): step 1 when none runs, else step 2 of the running\n// one; human (holder.rotateAnchor)\n// duty rotation/1 {rotationId} step 2 on resume, until the log\n// holds the entry\n//\n// The rotation, a procedure in state.rotations (note §2.1, §3 Log: head,\n// at, append):\n// where the log stands (standing), for a rotation g → g+1 (§5.4, RLTP-\n// ACC-5980): the genesis must match; a log whose generation g+1 is\n// held (head.gen ≥ g+1) holds this rotation where at(g+1) names its\n// next and commit (present: this device's append whose answer was\n// lost, or another device of the seed, the log since moved on or not),\n// else a fork (diverged); otherwise the device may append over the\n// head that holds the lineage through g (empty for g = 1, else gen g,\n// next = prev, commit = the binding of next); an earlier head is\n// behind, any other diverged\n// step 1 (identity.rotate, one commit) anchor-rotation@2 built (prev g,\n// next g+1, commit = the binding of g+2) and signed by prev and next\n// through the KeyProvider; the head read and the log's standing checked\n// BEFORE anything commits: behind and diverged are refused (log-behind,\n// log-diverged), so the label and the 6596 decision persist only when\n// the device may rotate. Then in one commit the label of g+1 (§5.4:\n// persisted before any presentation; 6360: before the log entry), per\n// relationship the withholding of 6596 decided against the entry state\n// now (awaitHead: H, the entry's anchor head, where it lags; null where\n// it does not; only where the anchor mapping class is on), the closure\n// {entry: {rotation}, overHead: the head read}, the rotation duty. The\n// register's head stays g: nothing is issued under g+1 before the log\n// holds it, and no device key derives under g+1 (deviceKey)\n// step 2 (the rotation duty on resume, or identity.rotate again) the\n// standing again: present completes without an append; behind and\n// diverged keep the rotation pending (the duty refused, no timer: the\n// log's sync is the cue; the act answers log-behind, log-diverged). An\n// append goes only ever over the head the rotation record names, so the\n// port's idempotence over exactly (entry, overHead) holds across a lost\n// answer: where the head the device may append over is another, it is\n// persisted first (the record's overHead, the duty due at once) and the\n// append follows on the next run. append on appended/exists completes the\n// rotation in one commit: the register's head g+1, the rotation in\n// register.lineage, the rotation and its duty gone, anchor.rotated, and\n// the re-issue duties of 6370 opened from the awaitHead decided at step\n// 1 (reissue-mapping/1, id reissue:<g+1>:<relId>) — and for a live\n// relationship the class is on for now that was not in it (new since\n// step 1), decided at completion. A chaining in between unions the\n// decisions onto the chain (null wins). head-conflict re-reads (four\n// reads); failure, or a port that throws, keeps the rotation pending:\n// the duty is due again after the retry backoff (attempt, lastAt), the\n// act answers log-failure\n// 6380 (the self card under the new anchor wherever it is carried): the\n// card travels only inside anchor-mapping@4 here (6.1 card), so the\n// re-issue of 6370 carries it; no duty of its own until the encounter\n// (PR 7) carries a card elsewhere\n// A throw of the Log port at step 1 is InfraError('log'): nothing\n// commits. Without a Log port the rotation is refused (log-missing); at the last\n// generation 2^53 − 2 it is refused (scope-exhausted, Identity §5.4)\n//\n// Pure register helpers for the modules that open contexts (the encounter\n// in PR 7, continuity.newTuple until then): withLabel, withPairNonce; and\n// for the carrier nonce of a relationship (Identity §7a.3): carrierNonceHeld,\n// withCarrierNonce, canonicalCarrierNonce.\n//\n// Choices this file makes where note and spec leave them open:\n// - a device name is stored in its 6.2 canonical form (NFC applied), so\n// the register compares what the derivation uses\n// - a name the register already holds is refused (device-name-held: the\n// SHOULD of §5.5 is followed); a revoked name is refused as\n// device-name-revoked (the MUST)\n// - revoking a name already revoked is ok and changes nothing; revoking\n// a name the register does not hold is unknown-device\n// - deviceKey (holder) derives only for a held, unrevoked name and an\n// own anchor context: a label of the register or a generation of the\n// community anchor up to its head (§5.5: names recorded before any\n// derived key is presented; a revoked name offers no key for a new\n// binding). Reading it changes nothing\nimport type { Applied, CommandDef, DutyHandler, HolderModule, PrepareCtx, Refusal } from './engine.js'\nimport type { CarrierNonce, Dec, Duty, HolderState, Millis, Register, ReissueMappingDuty, Rotation, RotationDuty } from './state.js'\nimport { canonicalLabel, communityLabel, deviceLabel, deviceName } from './identity.js'\nimport type { KeyProvider, LogHead } from './ports.js'\nimport { fromB64u, jcs } from './core.js'\nimport type { Json } from './core.js'\nimport { bindingOf, rawProofValue } from './anchor.js'\nimport { classOnToward, entryOf, entryRelationships, lags, liveRel } from './trust/state.js'\n\n/** The identity module's command names. */\nexport const IDENTITY_COMMANDS = Object.freeze({\n addDevice: 'identity.addDevice', revokeDevice: 'identity.revokeDevice', rotate: 'identity.rotate',\n} as const)\n\n/** The last generation a rotation moves to (Identity §5.4): 2^53 − 2. */\nexport const GENERATION_LAST = Number.MAX_SAFE_INTEGER - 1\n\nexport interface DeviceInput { name: string }\n\n/** The register with `label` among its labels (a set: added once). */\nexport const withLabel = (r: Readonly<Register>, label: string): Register =>\n r.labels.includes(label) ? r as Register : { ...r, labels: [...r.labels, label] }\n\n/** The register with a pair label and its relationship nonce (Identity\n * §6.1): the nonce is recorded alongside the label and never changes. */\nexport function withPairNonce (r: Readonly<Register>, label: string, nonce: string): Register {\n if (Object.hasOwn(r.pairNonces, label)) {\n if (r.pairNonces[label] !== nonce) throw new Error(`identity: ${label} already holds another relationship nonce (§6.1)`)\n return withLabel(r, label)\n }\n return { ...withLabel(r, label), pairNonces: { ...r.pairNonces, [label]: nonce } }\n}\n\n/** Does the register hold `nonce` (canonical base64url) as a carrier\n * nonce of any relationship, or as a pair nonce (Identity §7a.3: N is\n * fresh and never a pair nonce)? */\nexport const carrierNonceHeld = (r: Readonly<Register>, nonce: string): boolean =>\n Object.values(r.carriers).some((list) => list.some((e) => e.nonce === nonce)) || Object.values(r.pairNonces).includes(nonce)\n\n/** The register with the first carrier-nonce entry of relationship\n * `relId`, generation 1 (Identity §7a.3). A relationship that already\n * holds an entry is not given a second one here: rotation is not this. */\nexport function withCarrierNonce (r: Readonly<Register>, relId: string, nonce: string): Register {\n if (Object.hasOwn(r.carriers, relId)) throw new Error(`identity: ${relId} already holds a carrier nonce (§7a.3)`)\n return { ...r, carriers: { ...r.carriers, [relId]: [{ nonce, generation: '1' }] } }\n}\n\n/** The canonical carrier-nonce entry of a relationship (Identity §7a.3):\n * the highest generation, among equal ones the nonce whose bytes are\n * smallest in unsigned bytewise order; undefined where none is held. */\nexport function canonicalCarrierNonce (r: Readonly<Register>, relId: string): CarrierNonce | undefined {\n const list = Object.hasOwn(r.carriers, relId) ? r.carriers[relId] : []\n let best: CarrierNonce | undefined\n for (const e of list) {\n if (!best) { best = e; continue }\n const g = BigInt(e.generation) - BigInt(best.generation)\n if (g > 0n || (g === 0n && bytewiseLess(fromB64u(e.nonce), fromB64u(best.nonce)))) best = e\n }\n return best\n}\n\nconst bytewiseLess = (a: Uint8Array, b: Uint8Array): boolean => {\n for (let i = 0; i < Math.min(a.length, b.length); i++) if (a[i] !== b[i]) return a[i] < b[i]\n return a.length < b.length\n}\n\nconst needName = (x: unknown, cmd: string): string => {\n if (x === null || typeof x !== 'object' || Array.isArray(x)) throw new TypeError(`${cmd} needs an input object`)\n const n = (x as { name?: unknown }).name\n if (typeof n !== 'string') throw new TypeError(`${cmd}: name must be a string`)\n return n\n}\n\nconst refuse = (code: Refusal['code'], ref?: string): Refusal => ({ ok: false, code, ...(ref ? { ref } : {}) })\n\nconst commands: Record<string, CommandDef> = {\n // §5.5: the name is persisted before any key derived from it is presented\n [IDENTITY_COMMANDS.addDevice]: {\n human: true,\n apply (state, _p, input: DeviceInput) {\n const n = deviceName(needName(input, IDENTITY_COMMANDS.addDevice))\n if (n === null) return refuse('device-name-invalid', 'Identity §6.2')\n const d = state.register.devices\n if (d.revoked.includes(n)) return refuse('device-name-revoked', 'Identity §5.5')\n if (d.names.includes(n)) return refuse('device-name-held', 'Identity §5.5')\n return {\n state: { ...state, register: { ...state.register, devices: { ...d, names: [...d.names, n] } } },\n events: [{ type: 'device.added', name: n }],\n }\n },\n } satisfies CommandDef<DeviceInput>,\n // §5.5: revocation consumes the name; the mark is never removed\n [IDENTITY_COMMANDS.revokeDevice]: {\n human: true,\n apply (state, _p, input: DeviceInput) {\n const n = deviceName(needName(input, IDENTITY_COMMANDS.revokeDevice))\n const d = state.register.devices\n if (n === null || !d.names.includes(n)) return refuse('unknown-device', 'Identity §5.5')\n if (d.revoked.includes(n)) return { state: state as HolderState }\n return {\n state: { ...state, register: { ...state.register, devices: { ...d, revoked: [...d.revoked, n] } } },\n events: [{ type: 'device.revoked', name: n }],\n }\n },\n } satisfies CommandDef<DeviceInput>,\n}\n\n\n// ── the rotation (Identity §5.4, Trust 6360–6420, 6596, Access §5.6) ──\n\n/** The rotation duty's id for a rotation. */\nexport const rotationDutyId = (rotationId: string): string => `rotation:${rotationId}`\n/** A re-issue duty's id after the rotation to generation `to` (6370). */\nexport const reissueId = (to: Dec, relId: string): string => `reissue:${to}:${relId}`\n\ntype RotationArtifact = { body: { type: 'anchor-rotation@2', prev: string, next: string, commit: string }, proof: { proofValue: string, successorProofValue: string } }\n\n/** What step 2 found at the log. */\ntype LogOutcome =\n | { status: 'done', head: LogHead }\n /** the log stands where this device may rotate, over a head other than\n * the persisted closure's: persist it before appending over it */\n | { status: 'moved', head: LogHead }\n | { status: 'behind' | 'diverged', head: LogHead }\n | { status: 'failure', reason: string }\n | { status: 'log-missing' }\n\ntype Rot = RotationArtifact['body']\n\n/**\n * Where the log stands for the rotation g → g+1 (Identity §5.4, RLTP-ACC-\n * 5980): `present`, its generation g+1 holds this rotation (at(g+1) names\n * this next and commit — appended by this device with its answer lost, or\n * by another device of the same seed, the log since moved on or not);\n * `{over}`, the device may append over that head (empty for g = 1, else\n * the entry that introduced g: gen g, next = prev, commit = the binding of\n * next); `behind`, the log has not reached g; `diverged`, another genesis,\n * another entry at g+1 (a fork), or a head the rotation does not continue.\n */\nasync function standing (ctx: PrepareCtx, head: LogHead, genesis: string, from: number, rot: Rot): Promise<'present' | 'behind' | 'diverged' | { over: string | null }> {\n if (head.genesis !== genesis) return 'diverged'\n if ('empty' in head) return from === 1 ? { over: null } : 'behind'\n if (head.gen >= from + 1) {\n const e = await ctx.log!.at(from + 1)\n return e && e.next === rot.next && e.commit === rot.commit ? 'present' : 'diverged'\n }\n if (head.gen === from && head.next === rot.prev && head.commit === await bindingOf(rot.next, ctx.crypto.subtle)) return { over: head.entryId }\n return head.gen < from ? 'behind' : 'diverged'\n}\n\nconst headId = (h: LogHead): string | null => ('empty' in h ? null : h.entryId)\n\n/**\n * Step 2 through the Log port (see the header): where the log stands, then\n * append(entry, the persisted overHead) — only ever over the head the\n * rotation record names, so the port's idempotence over exactly (entry,\n * overHead) holds across a lost answer; a head that moved is persisted\n * first ('moved'). head-conflict re-reads. A port that throws is a\n * failure: the rotation stays pending.\n */\nasync function logStep (ctx: PrepareCtx, r: Readonly<Rotation>, genesis: string): Promise<LogOutcome> {\n const log = ctx.log\n if (!log) return { status: 'log-missing' }\n const rot = (r.entry as { rotation: RotationArtifact }).rotation\n try {\n for (let i = 0; i < 4; i++) {\n const head = await log.head()\n const at = await standing(ctx, head, genesis, Number(r.from), rot.body)\n if (at === 'present') return { status: 'done', head }\n if (at === 'behind' || at === 'diverged') return { status: at, head }\n if (at.over !== headId(r.overHead) || head.genesis !== r.overHead.genesis) return { status: 'moved', head }\n const a = await log.append({ rotation: rot } as unknown as Json, at.over)\n if (a.status === 'appended' || a.status === 'exists') return { status: 'done', head: a.head }\n if (a.status === 'failure') return { status: 'failure', reason: a.reason }\n // head-conflict: re-read\n }\n return { status: 'failure', reason: 'head-conflict persisted' }\n } catch (e) {\n return { status: 'failure', reason: (e as Error)?.message ?? String(e) }\n }\n}\n\n/** 6596, per relationship: the anchor mapping class on for it (live, under\n * its entry), and whether it lags there — then H, else null. */\nfunction withholding (state: Readonly<HolderState>, relId: string): { contactId: string, awaitHead: string | null } | null {\n const r = state.relationships[relId]\n if (!r || !liveRel(r)) return null\n const e = entryOf(state, r)\n if (!e || !e.relIds.includes(r.id) || !classOnToward(e, 'anchorMapping')) return null\n return { contactId: e.id, awaitHead: lags(r, entryRelationships(state, e)) && e.anchorHead !== null ? e.anchorHead : null }\n}\n\n/** Step 1's commit (see the header). */\nfunction startRotation (state: Readonly<HolderState>, p: { id: string, from: Dec, to: Dec, entry: Json, overHead: LogHead, label: string }, when: Millis): Applied | Refusal {\n const com = state.register.community\n if (com === null || com.head !== p.from || Object.keys(state.rotations).length) return refuse('in-flight')\n const awaitHead: Record<string, string | null> = {}\n for (const id of Object.keys(state.relationships).sort()) {\n const w = withholding(state, id)\n if (w) awaitHead[id] = w.awaitHead\n }\n const rotation: Rotation = { id: p.id, from: p.from, to: p.to, step: 'log', startedAt: when, entry: p.entry, overHead: p.overHead, awaitHead }\n const duty: RotationDuty = { kind: 'rotation', v: 1, id: rotationDutyId(p.id), rotationId: p.id }\n return {\n state: { ...state, register: withLabel(state.register, p.label), rotations: { ...state.rotations, [p.id]: rotation } },\n duties: [duty],\n }\n}\n\n/** The completion's commit: head, lineage, the re-issues of 6370 (6596). */\nfunction completeRotation (state: Readonly<HolderState>, r: Readonly<Rotation>): Applied | Refusal {\n const com = state.register.community\n if (com === null || com.head !== r.from) return refuse('in-flight')\n const rot = (r.entry as { rotation: RotationArtifact }).rotation\n const duties: ReissueMappingDuty[] = []\n const reissue = (relId: string, contactId: string, awaitHead: string | null): void => {\n duties.push({ kind: 'reissue-mapping', v: 1, id: reissueId(r.to, relId), contactId, relId, awaitHead })\n }\n // decided at step 1 (6596), where the class is still on for it now\n for (const [relId, awaitHead] of Object.entries(r.awaitHead).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {\n const w = withholding(state, relId)\n if (w) reissue(relId, w.contactId, awaitHead)\n }\n // on for it now, unknown to step 1: decided now\n for (const relId of Object.keys(state.relationships).sort()) {\n if (Object.hasOwn(r.awaitHead, relId)) continue\n const w = withholding(state, relId)\n if (w) reissue(relId, w.contactId, w.awaitHead)\n }\n const rotations = { ...state.rotations }\n delete rotations[r.id]\n const left = { ...state.duties }\n delete left[rotationDutyId(r.id)]\n return {\n state: {\n ...state,\n register: { ...withLabel(state.register, communityLabel(com.genesis, Number(r.to))), community: { ...com, head: r.to }, lineage: [...state.register.lineage, rot as unknown as Json as Register['lineage'][number]] },\n rotations,\n duties: left,\n },\n events: [{ type: 'anchor.rotated', generation: r.to }],\n duties,\n }\n}\n\n/** What step 2's outcome means for the rotation: completion, or why not. */\nfunction afterLog (state: Readonly<HolderState>, rotationId: string, o: LogOutcome, when: Millis): Applied | Refusal {\n const r = Object.hasOwn(state.rotations, rotationId) ? state.rotations[rotationId] : undefined\n if (!r) return refuse('in-flight')\n switch (o.status) {\n case 'done': return completeRotation(state, r)\n case 'moved': {\n // the closure's head, persisted before any append over it; the duty\n // runs again at once (lastAt marks the change, no dueAt)\n const id = rotationDutyId(r.id)\n const held = Object.hasOwn(state.duties, id) ? state.duties[id] as RotationDuty : { kind: 'rotation' as const, v: 1 as const, id, rotationId: r.id }\n const { dueAt: _, ...rest } = held\n const duty: RotationDuty = { ...rest, lastAt: when }\n // single path: the duty leaves the state and comes back as Applied.duties,\n // on the act path and in resume alike\n const left = { ...state.duties }\n delete left[id]\n return {\n state: { ...state, rotations: { ...state.rotations, [r.id]: { ...r, overHead: o.head } }, duties: left },\n duties: [duty],\n }\n }\n case 'behind': return refuse('log-behind', 'RLTP-ACC-5980')\n case 'diverged': return refuse('log-diverged', 'RLTP-ACC-5980')\n case 'log-missing': return refuse('log-missing')\n case 'failure': return refuse('log-failure')\n }\n}\n\ntype RotatePrepared =\n | { kind: 'refuse', code: Refusal['code'], ref?: string }\n | { kind: 'start', id: string, from: Dec, to: Dec, entry: Json, overHead: LogHead, label: string }\n | { kind: 'resume', rotationId: string, outcome: LogOutcome }\n\nconst rotateCommand: CommandDef<Record<string, never>, RotatePrepared> = {\n human: true,\n async prepare (ctx) {\n const st = ctx.snapshot\n const com = st.register.community\n if (com === null) return { kind: 'refuse', code: 'no-community' }\n if (!ctx.log) return { kind: 'refuse', code: 'log-missing' }\n const running = Object.values(st.rotations)[0]\n if (running) return { kind: 'resume', rotationId: running.id, outcome: await logStep(ctx, running, com.genesis) }\n const g = Number(com.head)\n if (!Number.isSafeInteger(g) || g < 1 || g + 1 > GENERATION_LAST) return { kind: 'refuse', code: 'scope-exhausted', ref: 'Identity §5.4' }\n const [prevL, nextL, afterL] = [g, g + 1, g + 2].map((k) => communityLabel(com.genesis, k))\n const [prev, next, after] = await Promise.all([prevL, nextL, afterL].map((l) => ctx.keys.anchorOf(l)))\n const body = { type: 'anchor-rotation@2' as const, prev: prev.anchor, next: next.anchor, commit: await bindingOf(after.anchor, ctx.crypto.subtle) }\n const bytes = new TextEncoder().encode(jcs(body))\n const rotation: RotationArtifact = {\n body,\n proof: { proofValue: rawProofValue(await ctx.keys.sign(prevL, bytes)), successorProofValue: rawProofValue(await ctx.keys.sign(nextL, bytes)) },\n }\n // §5.4: the device rotates only over the log it holds — checked before\n // anything commits, so label and 6596 decision persist only when it may\n const overHead = await ctx.log.head()\n const at = await standing(ctx, overHead, com.genesis, g, body)\n if (at === 'behind') return { kind: 'refuse', code: 'log-behind', ref: 'RLTP-ACC-5980' }\n if (at === 'diverged') return { kind: 'refuse', code: 'log-diverged', ref: 'RLTP-ACC-5980' }\n const to = String(g + 1)\n return { kind: 'start', id: to, from: com.head, to, entry: { rotation } as unknown as Json, overHead, label: nextL }\n },\n apply (state, prepared, _input, when) {\n const p = prepared.value\n if (p.kind === 'refuse') return refuse(p.code, p.ref)\n if (p.kind === 'start') return startRotation(state, p, when)\n return afterLog(state, p.rotationId, p.outcome, when)\n },\n}\n\n/** The rotation duty (rotation/1): step 2 on resume. */\nconst rotationDuty: DutyHandler<LogOutcome | null> = {\n v: 1,\n async prepare (ctx, duty) {\n const r = ctx.snapshot.rotations[(duty as RotationDuty).rotationId]\n const com = ctx.snapshot.register.community\n return r && com ? logStep(ctx, r, com.genesis) : null\n },\n apply (state, duty, ctx, when) {\n const d = duty as RotationDuty\n // a rotation completed (by the act) or gone: nothing left to do\n if (!Object.hasOwn(state.rotations, d.rotationId)) return { state: state as HolderState }\n const o = ctx.prepared.value\n if (o === null) return 'not-due'\n if (o.status === 'failure') {\n // pending, due again after the retry backoff (the duty's own attempt)\n const attempt = (d.attempt ?? 0) + 1\n const again: RotationDuty = { ...d, attempt, lastAt: when, dueAt: Math.min(when + Math.max(0, Math.ceil(ctx.backoff(attempt))), Number.MAX_SAFE_INTEGER) }\n return { state: state as HolderState, duties: [again] }\n }\n return afterLog(state, d.rotationId, o, when)\n },\n}\n\n/** A device key as deviceKey derives it: the device label, the device's\n * did:key and its key-agreement multikey (Identity §5.5). */\nexport type DeviceKeyResult =\n | { ok: true, label: string, device: string, keyAgreement: string }\n | { ok: false, code: 'unknown-device' | 'device-revoked' | 'unknown-context' }\n\n/** Whether `label` names an own anchor context: a label of the register,\n * or a generation of the community anchor up to its head (§5.4). */\nfunction ownContext (state: Readonly<HolderState>, label: string): boolean {\n if (label.startsWith('device/')) return false\n // the community's generations first, bounded by the head: the label of\n // a pending g+1 is recorded, but no key is presented under it before the\n // rotation completes (§5.4)\n const c = state.register.community\n if (c !== null) {\n const base = communityLabel(c.genesis, 1)\n if (label === base) return true\n if (label.startsWith(base + '/')) {\n const g = BigInt(label.slice(base.length + 1))\n return g >= 2n && g <= BigInt(c.head)\n }\n }\n return state.register.labels.includes(label)\n}\n\n/**\n * The device key of a held, unrevoked device name under an own anchor\n * context (Identity §5.5): derived through the KeyProvider, never stored\n * (keys are not state, 9.3).\n */\nexport async function deviceKeyOf (state: Readonly<HolderState>, keys: KeyProvider, name: string, contextLabel: string): Promise<DeviceKeyResult> {\n const n = deviceName(name)\n const d = state.register.devices\n if (n === null || !d.names.includes(n)) return { ok: false, code: 'unknown-device' }\n if (d.revoked.includes(n)) return { ok: false, code: 'device-revoked' }\n const a = canonicalLabel(contextLabel)\n if (a === null || !ownContext(state, a)) return { ok: false, code: 'unknown-context' }\n const label = await deviceLabel(n, a)\n const k = await keys.anchorOf(label)\n return { ok: true, label, device: k.anchor, keyAgreement: k.keyAgreement }\n}\n\n/** The identity module createHolder builds in (see the header). */\nexport function identityModule (): HolderModule {\n return Object.freeze({\n name: 'identity',\n commands: Object.freeze({ ...commands, [IDENTITY_COMMANDS.rotate]: rotateCommand }),\n duties: Object.freeze({ rotation: rotationDuty }),\n })\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type { Entropy, EntropyPurpose, EntropyErrorCode, PlatformRandom } from '
|
|
|
29
29
|
export { storeContract } from './store-contract.js';
|
|
30
30
|
export { seedKeys } from './keys-seed.js';
|
|
31
31
|
export { createHolder } from './holder-api.js';
|
|
32
|
-
export type { Holder, HolderOptions, HolderSnapshot, HumanActOptions } from './holder-api.js';
|
|
32
|
+
export type { CarrierOffer, Holder, HolderOptions, HolderSnapshot, HumanActOptions } from './holder-api.js';
|
|
33
33
|
export type { DeviceKeyResult } from './identity-state.js';
|
|
34
34
|
export type { ContactView, RelationshipView, ClassView, SealedClassView, ClassesView, ContactProfileView, GroupView, ProfileView, PromptView, InboxMessageView, DeliveryItemView, DeliveryStatusView } from './views.js';
|
|
35
35
|
export type { EnginePorts, CommitListener, CryptoHandle, TransportEntry, TransportView, TransportRefusal } from './engine.js';
|