@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.
@@ -1 +1 @@
1
- {"version":3,"file":"vti-mediator.js","sourceRoot":"","sources":["../../src/adapters/vti-mediator.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,4EAA4E;AAC5E,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,uEAAuE;AACvE,mEAAmE;AACnE,oEAAoE;AACpE,wEAAwE;AACxE,2EAA2E;AAC3E,0EAA0E;AAC1E,yFAAyF;AACzF,2EAA2E;AAC3E,yEAAyE;AACzE,qEAAqE;AACrE,yEAAyE;AACzE,0EAA0E;AAC1E,uEAAuE;AACvE,UAAU;AACV,EAAE;AACF,qEAAqE;AACrE,kDAAkD;AAClD,0DAA0D;AAC1D,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,0EAA0E;AAC1E,oEAAoE;AACpE,oEAAoE;AACpE,8BAA8B;AAC9B,EAAE;AACF,kCAAkC;AAClC,6DAA6D;AAC7D,oEAAoE;AACpE,mDAAmD;AACnD,qEAAqE;AACrE,mEAAmE;AACnE,8DAA8D;AAC9D,uDAAuD;AACvD,gEAAgE;AAChE,oCAAoC;AAEpC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAOhF,uEAAuE;AACvE,qEAAqE;AACrE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,eAAe,EAAE,EAAE,GAAG,SAAS;IAC/B,eAAe,EAAE,MAAM;IACvB,eAAe,EAAE,EAAE;IACnB,eAAe,EAAE,SAAS;IAC1B,aAAa,EAAE,UAAU;IACzB,iBAAiB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G,EAAE,GAAG,CAAC,CAAA;QACjE,CAAC;QACD,+DAA+D;QAC/D,gEAAgE;QAChE,+DAA+D;QAC/D,6DAA6D;QAC7D,gDAAgD;QAChD,KAAK,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3C,IAAI,GAAG,GAAG,EAAE,IAAI,QAAQ,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC5E,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBAC9B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;QACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;IAED;;;;mBAIe;IACf,KAAK,KAAY,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA,CAAC,CAAC;IAEtC,IAAI,MAAM,KAAe,OAAO,IAAI,CAAC,OAAO,CAAA,CAAC,CAAC;CAC/C;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,KAAiB,EAAmB,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA","sourcesContent":["// RLTP transport adapter: VTI mediator — published as\n// @real-life/trust-protocol/adapters/vti-mediator (lib Stage 2, note §4.6).\n//\n// It takes the holder's documents from the holder's custody (Delivery 0.83\n// RLTP-DEL-6120 to 6135, lib 0.6.0): reconcile(view, gate, now) files every\n// entry of holder.pendingTransport(when) not yet filed, and withdraws every\n// filed submission still before the trias whose digest the view no longer\n// names — a missing entry means stop, never keep sending. Before every\n// deposit it asks gate.mayHandOver(entry, now) (the holder): false\n// withdraws the submission, an error skips the attempt. It keeps no\n// custody of its own: its copies are volatile and bound to the holder's\n// opening: bound to the holder of its first reconcile, it refuses another,\n// so after holder.close() nothing it holds goes out, and the next opening\n// gets a new adapter (restored from ackState like any other). Its give-up horizon counts\n// from the entry's first submission (`since`), never from when it took the\n// entry over (RLTP-DEL-6130). Its reports reach the holder as the ports'\n// DeliveryReport: report(id) maps the adapter's SubmissionState onto\n// DeliveryReport (deliveryReportOf), keyed by the document digest, which\n// the app hands to holder.report(). An adapter's `delivered` is its claim\n// about transport; the holder's receive core verifies the delivery-ack\n// itself.\n//\n// Profile: spec/adapter-vti-mediator.md v0.23 (twenty-third casting;\n// round journals under design/adapter-review*). A\n// transport adapter contract — NOT a carrier at the port.\n//\n// Beyond the profile (lib 0.5.0): conclude(collection, now, {keep}) leaves\n// the items whose disposition is transient unconcluded and offers them\n// again (Delivery 0.82 RLTP-DEL-5810, 5820: failed(rate-limited) is never\n// concluded); `concludable(result)` says which receive outcomes are\n// terminal. The profile's §4 concludes a collection whole; its next\n// casting is to take this up.\n//\n// Structural rules (reviews 3+4):\n// · No port operation ever awaits the mediator — including\n// register: keylist synchronization is a recorded intent with a\n// tracked background task, retried by advance.\n// · No report is invented, and absence is ABSENT: before the first\n// honest report exists, status() returns null (§6.1 grants the\n// window; representing it as a queryable fourth value was\n// review-4 B2). has() distinguishes an unknown id.\n// · A retired instance mutates nothing and refuses everything\n// except reading its ack state.\n\nimport { jcs } from '../core.js'\nimport { sha } from '../crypto.js'\nimport { carrierPrincipal, carrierScopedIdentity } from '../carrier-identity.js'\nimport type { CarrierPrincipal, CarrierScopedIdentity } from '../carrier-identity.js'\nimport type { DeliveryReport, ReceiverRefusalCode, SubmissionRef } from '../ports.js'\nimport type { TransportEntry, TransportView } from '../engine.js'\nimport type { ReceiveResult } from '../results.js'\nexport type { ReceiverRefusalCode } from '../ports.js'\n\n// ── Declared constants (profile §2) — promises of THIS casting ──────\n// frozen: the declared promises cannot be changed at run time either\nexport const DECLARED = Object.freeze({\n giveUpHorizonMs: 72 * 3_600_000,\n statusHorizonMs: 60_000,\n queueFloorCount: 64,\n queueFloorBytes: 1_048_576,\n maxQueueBytes: 16_777_216,\n duplicateWindowMs: 30 * 86_400_000,\n} as const)\n\n// ── The injected wire ────────────────────────────────────────────────\nexport type WireErrorKind =\n | 'unreachable' | 'refused-retriable' | 'refused-admission' | 'oversize'\n\nexport class WireError extends Error {\n kind: WireErrorKind\n constructor (kind: WireErrorKind, message?: string) {\n super(message ?? kind)\n this.kind = kind\n }\n}\n\nexport interface MediatorWire {\n authChallenge (did: string): Promise<{ challenge: string, sessionId: string }>\n authenticate (answer: { did: string, challenge: string, sessionId: string }): Promise<TokenSet>\n // A transient failure MUST be a WireError 'unreachable' or\n // 'refused-retriable' (the tokens are kept); any other error means the\n // mediator refused the refresh token (the adapter re-runs the handshake).\n refresh (refreshToken: string): Promise<TokenSet>\n keylistUpdate (accessToken: string, rkids: string[]): Promise<void>\n deposit (accessToken: string, bytes: Uint8Array, egressDid: string): Promise<void>\n ackReceived (accessToken: string, queueIds: string[]): Promise<void>\n onDeliver (cb: (bytes: Uint8Array) => Promise<void>): void\n /** Optional truthful connectivity signal; absent means unknown. */\n offline? (): boolean\n}\n\nexport interface TokenSet {\n accessToken: string\n accessExpiresAt: number\n refreshToken: string\n refreshExpiresAt: number\n}\n\n// ── Sender states (§6.1 — the closed sets, nothing else) ────────────\n// ReceiverRefusalCode is the ports' (one closed set, one place)\nconst RECEIVER_REFUSAL_CODES: ReadonlySet<ReceiverRefusalCode> = new Set<ReceiverRefusalCode>([\n 'malformedRequest', 'unsupportedType', 'proofRequired',\n 'proofInvalid', 'wrongRecipient', 'identityMismatch',\n])\n\nexport type SubmissionState =\n | { state: 'awaiting-transport', reason: 'offline' | 'transport-unreachable' | 'carrier-refused-retriable' }\n | { state: 'accepted' }\n | { state: 'delivered', late: boolean }\n | { state: 'failed', reason: 'unroutable' | 'oversize' | 'expired-by-adapter-policy' }\n | { state: 'failed', reason: 'rejected-by-receiver', code: ReceiverRefusalCode }\n\n/** The ports' DeliveryReport for a document `digest` in adapter state `st`\n * (Delivery §6.1): one-to-one, `late` and the refusal code carried over. */\nexport function deliveryReportOf (digest: string, st: SubmissionState): DeliveryReport {\n switch (st.state) {\n case 'awaiting-transport': return { digest, status: 'awaiting-transport', reason: st.reason }\n case 'accepted': return { digest, status: 'accepted' }\n case 'delivered': return { digest, status: 'delivered', late: st.late }\n case 'failed': return st.reason === 'rejected-by-receiver'\n ? { digest, status: 'failed', reason: 'rejected-by-receiver', code: st.code }\n : { digest, status: 'failed', reason: st.reason }\n }\n}\n\n/** Whether a receive outcome is terminal and its item may be concluded\n * (Delivery 5a.8): every disposition but `failed(rate-limited)`, the one\n * failure that is transient (RLTP-DEL-5820). An InfraError of the\n * holder's store is transient as well (RLTP-DEL-5810): an item whose\n * receive threw is kept, too. */\nexport function concludable (r: ReceiveResult): boolean {\n return !(r.disposition === 'failed' && r.reason === 'rate-limited')\n}\n\n/** The adapter's own copy of a wire's token set: the wire keeps no handle on it. */\nconst tokenCopy = (t: TokenSet): TokenSet => ({ accessToken: t.accessToken, accessExpiresAt: t.accessExpiresAt, refreshToken: t.refreshToken, refreshExpiresAt: t.refreshExpiresAt })\n\nexport interface CollectedItem { bytes: Uint8Array, queueId: string }\nexport interface Collection { id: string, items: CollectedItem[] }\n\n/** Ack state for the host to persist (profile §4). Invariant: every\n * pending id names a concluded entry; violations are refused at\n * construction (fail-closed). */\nexport interface AckState {\n concluded: Array<{ queueId: string, concludedAt: number }>\n pending: string[]\n}\n\n/** The holder's side of a hand-over (lib 0.6.0): the holder itself.\n * handOver checks the entry and calls `start` inside the holder's queue;\n * `start` re-checks the adapter's own state, starts the deposit\n * synchronously and says whether it did. `closed` is read in `start`. */\nexport interface TransportGate {\n handOver (entry: TransportEntry, when: number, start: () => boolean): Promise<boolean>\n readonly closed?: boolean\n}\n\ninterface Submission {\n id: string\n /** the document digest, for submissions filed by reconcile */\n digest?: string\n /** the holder's entry and its gate, for submissions filed by reconcile */\n entry?: TransportEntry\n gate?: TransportGate\n bytes: Uint8Array\n submittedAt: number\n attemptStartedAt: number | null\n lastKind: WireErrorKind | null\n st: SubmissionState | null // null = no honest report exists yet\n}\n\nconst hex = (b: Uint8Array): string =>\n Array.from(b, (x) => x.toString(16).padStart(2, '0')).join('')\n\n// construction capability: only create() holds it\nconst KEY = Symbol('MediatorCarrierAdapter.create')\n\n// ── The adapter ──────────────────────────────────────────────────────\nexport class MediatorCarrierAdapter {\n // JS-hard identity fields: TS `readonly` is a compile-time promise\n // only, and §8 claims runtime unforgeability — so the values live\n // in true privates behind getters (R8-B1)\n #principal: string\n #connectionDid: string\n #egressDid: string\n get principal (): string { return this.#principal }\n get connectionDid (): string { return this.#connectionDid }\n get egressDid (): string { return this.#egressDid }\n #wire: MediatorWire\n #tokens: TokenSet | null = null\n #clock = Number.NEGATIVE_INFINITY\n #closed = false\n /** the opening this adapter serves, bound at its first reconcile */\n #gate: TransportGate | null = null\n\n #subs = new Map<string, Submission>()\n #inflight = new Set<Promise<void>>()\n #nextId = 1\n\n #desiredRkids: string[] | null = null\n #keylistSynced = false\n #keylistSyncing = false\n\n #inbox: CollectedItem[] = []\n #inboxBytes = 0\n #inboxDigests = new Set<string>()\n #outstanding = new Map<string, Map<string, CollectedItem>>()\n #outstandingBytes = 0\n #concluded = new Map<string, number>()\n #pendingAcks = new Set<string>()\n #flightAcks = new Set<string>() // ids inside the in-flight flush snapshot\n #flushing = false\n #nextColId = 1\n\n #transitions: Array<{ id: string, to: 'delivered' }> = []\n\n /** The only way to build an adapter: the trio is DERIVED here from\n * one root, one carrier, one nonce — so principal, connection DID\n * and egress identity cannot come from different relationships\n * (R7-B2: the coupling is enforced by construction, not by\n * inspecting caller-supplied identities). */\n static async create (\n rootIkm: Uint8Array, carrier: string, nonce: Uint8Array,\n wire: MediatorWire, restored?: AckState, restoredAt?: number,\n ): Promise<MediatorCarrierAdapter> {\n // ONE tuple, snapshotted at entry: a caller mutating its buffers\n // between the three awaited derivations must not be able to mix\n // identities from two tuples (R8-B2)\n const ikm = new Uint8Array(rootIkm)\n const n = new Uint8Array(nonce)\n const principal = await carrierPrincipal(ikm, carrier, n)\n const connection = await carrierScopedIdentity(ikm, carrier, n, 'connection')\n const egress = await carrierScopedIdentity(ikm, carrier, n, 'egress')\n return new MediatorCarrierAdapter(KEY, principal, connection, egress, wire, restored, restoredAt)\n }\n\n constructor (\n key: symbol,\n principal: CarrierPrincipal,\n connection: CarrierScopedIdentity,\n egress: CarrierScopedIdentity,\n wire: MediatorWire,\n restored?: AckState,\n restoredAt?: number,\n ) {\n if (key !== KEY) {\n throw new Error('use MediatorCarrierAdapter.create — the identity trio must be derived, not supplied (5a.10)')\n }\n if (connection.scope !== 'connection' || egress.scope !== 'egress') {\n throw new Error('scoped identities passed in the wrong roles')\n }\n const three = new Set([principal.principal, connection.did, egress.did])\n if (three.size !== 3) {\n throw new Error('principal, connection DID and egress identity must be pairwise distinct (5a.10)')\n }\n this.#principal = principal.principal\n this.#connectionDid = connection.did\n this.#egressDid = egress.did\n this.#wire = wire\n if (restored) {\n // The restore instant anchors the duplicate-window: an expired,\n // debt-free entry is dropped HERE, not at the first advance —\n // otherwise a redelivery arriving before any port call would be\n // absorbed beyond the declared window (review-4 B4).\n if (typeof restoredAt !== 'number' || !Number.isFinite(restoredAt)) {\n throw new Error('restoring ack state requires a finite restoredAt instant')\n }\n this.#now(restoredAt)\n const pending = new Set(restored.pending)\n const known = new Set(restored.concluded.map((c) => c.queueId))\n for (const id of pending) {\n if (!known.has(id)) {\n throw new Error('ack snapshot violates its invariant: pending intent without a concluded entry')\n }\n }\n for (const { queueId, concludedAt } of restored.concluded) {\n if (!Number.isFinite(concludedAt) || concludedAt > restoredAt) {\n // a conclusion \"from the future\" would stretch the window\n // past its declared span (R5-B4) — fail closed\n throw new Error('ack snapshot: conclusion instant is non-finite or after restoredAt')\n }\n // the window beats everything (round-14 B): an expired entry\n // falls at the restore instant, owed or not — a phantom debt\n // from an ack that landed just before a close can never\n // outlive the window and delete a fresh copy (R14-B2)\n if (restoredAt - concludedAt >= DECLARED.duplicateWindowMs) continue\n this.#concluded.set(queueId, concludedAt)\n if (pending.has(queueId)) this.#pendingAcks.add(queueId)\n }\n }\n this.#wire.onDeliver(async (raw) => {\n if (this.#closed) return\n // a plain copy of its own: a Node Buffer's slice() would share memory\n const bytes = new Uint8Array(raw)\n const queueId = hex(await sha(bytes))\n if (this.#closed) return\n // Absorption is WINDOW-checked at the moment it happens\n // (R11-B1), and the window beats everything (round-14 B):\n // beyond it, entry AND any leftover intent fall, and the frame\n // is a new item — so no acknowledgement, owed or phantom, can\n // ever delete the only fresh copy.\n const concludedAt = this.#concluded.get(queueId)\n if (concludedAt !== undefined) {\n if (this.#flightAcks.has(queueId) ||\n this.#clock - concludedAt < DECLARED.duplicateWindowMs) {\n // inside the window — or deferred: an id inside an\n // in-flight flush keeps absorbing until that flush ends,\n // because its irrecallable ack may still land (R15-B1)\n this.#pendingAcks.add(queueId)\n return\n }\n this.#concluded.delete(queueId)\n this.#pendingAcks.delete(queueId)\n }\n if (this.#inboxDigests.has(queueId)) return\n for (const col of this.#outstanding.values()) if (col.has(queueId)) return\n const held = this.#inboxBytes + this.#outstandingBytes\n const underFloor = this.#inbox.length < DECLARED.queueFloorCount &&\n held + bytes.length <= DECLARED.queueFloorBytes\n const underCap = held + bytes.length <= DECLARED.maxQueueBytes\n if (!underFloor && !underCap) return\n this.#inbox.push({ bytes, queueId })\n this.#inboxBytes += bytes.length\n this.#inboxDigests.add(queueId)\n })\n }\n\n #now (raw: number): number {\n if (!Number.isFinite(raw)) throw new Error('non-finite time')\n if (raw > this.#clock) this.#clock = raw\n return this.#clock\n }\n\n #open (): void { if (this.#closed) throw new Error('retired (5a.10 lifecycle)') }\n\n #track (p: Promise<void>): void {\n const t = p.catch(() => {})\n this.#inflight.add(t)\n void t.finally(() => this.#inflight.delete(t))\n }\n\n // ── auth: silent carrier policy ─────────────────────────────────\n // Single-flight: concurrent callers share one handshake — the ATM\n // challenge/response is a session, and two interleaved sessions\n // under one connection DID would answer each other's challenges.\n #authing: Promise<string> | null = null\n\n #ensureAuth (now: number): Promise<string> {\n if (this.#tokens && now < this.#tokens.accessExpiresAt) return Promise.resolve(this.#tokens.accessToken)\n if (this.#authing) return this.#authing\n const run = (async (): Promise<string> => {\n if (this.#tokens && now < this.#tokens.refreshExpiresAt) {\n try {\n const refreshed = await this.#wire.refresh(this.#tokens.refreshToken)\n if (this.#closed) throw new Error('retired') // as on the handshake path (R6-B1)\n this.#tokens = tokenCopy(refreshed)\n return this.#tokens.accessToken\n } catch (e) {\n if (this.#closed) throw e\n // a transient failure (mediator unreachable, retriable refusal)\n // says nothing about the token: keep it for the next attempt (#9)\n if (e instanceof WireError && (e.kind === 'unreachable' || e.kind === 'refused-retriable')) throw e\n // a refused refresh (revoked before its expiry) is never replayed:\n // drop the tokens and take the challenge handshake below\n this.#tokens = null\n }\n }\n const { challenge, sessionId } = await this.#wire.authChallenge(this.#connectionDid)\n if (this.#closed) throw new Error('retired') // nothing new starts, not even the answer (R6-B1)\n this.#tokens = tokenCopy(await this.#wire.authenticate({ did: this.#connectionDid, challenge, sessionId }))\n return this.#tokens.accessToken\n })()\n this.#authing = run.finally(() => { this.#authing = null })\n return this.#authing\n }\n\n // ── transport registration (profile §3 — NOT §5a.3) ─────────────\n /** Records the desired keylist and returns; synchronization runs\n * as a tracked background task and advance retries it until it\n * lands (review-4 B1). */\n register (rkids: string[], rawNow: number): void {\n this.#open()\n const now = this.#now(rawNow)\n this.#desiredRkids = [...rkids]\n this.#keylistSynced = false\n this.#startKeylistSync(now)\n }\n\n get keylistSynced (): boolean {\n this.#open()\n return this.#keylistSynced\n }\n\n #startKeylistSync (now: number): void {\n if (this.#keylistSyncing || this.#keylistSynced || this.#desiredRkids === null) return\n this.#keylistSyncing = true\n const wanted = [...this.#desiredRkids]\n this.#track((async () => {\n try {\n const token = await this.#ensureAuth(now)\n if (this.#closed) return\n await this.#wire.keylistUpdate(token, [...wanted]) // the wire's own list: `wanted` is compared below\n // land only if the desire has not moved meanwhile\n if (!this.#closed && this.#desiredRkids !== null &&\n wanted.join(' ') === this.#desiredRkids.join(' ')) {\n this.#keylistSynced = true\n }\n } catch {\n // intent survives; advance retries\n } finally {\n this.#keylistSyncing = false\n }\n })())\n }\n\n // ── sender side ─────────────────────────────────────────────────\n /** Returns the submission id synchronously. Before the first\n * honest report exists, status() returns null — §6.1's own\n * pre-report window, represented as absence, not as a value. */\n submit (envelopeBytes: Uint8Array, rawNow: number): string {\n this.#open()\n const now = this.#now(rawNow)\n const id = 's' + this.#nextId++\n const knownOffline = this.#wire.offline?.() === true\n const sub: Submission = {\n id,\n // a plain copy of its own (a Node Buffer's slice() shares memory)\n bytes: new Uint8Array(envelopeBytes),\n submittedAt: now,\n attemptStartedAt: null,\n lastKind: null,\n st: null,\n }\n this.#subs.set(id, sub)\n if (!knownOffline) this.#startAttempt(sub, now)\n return id\n }\n\n /** Takes the holder's custody set (holder.pendingTransport, after a\n * resume of this opening) and the holder as the gate: files every entry\n * not yet filed under its digest (its envelope as JCS bytes; the give-up\n * horizon from entry.since) and returns their SubmissionRefs; withdraws\n * every filed submission still before the trias (no report, or\n * awaiting-transport) whose digest the view does not name. Accepted and\n * terminal submissions stay for their reports. */\n reconcile (view: TransportView, gate: TransportGate, rawNow: number): SubmissionRef[] {\n this.#open()\n if (view?.ok !== true || !Array.isArray(view.entries)) throw new Error('reconcile needs a view of holder.pendingTransport')\n if (typeof gate?.handOver !== 'function') throw new Error('reconcile needs the holder as its gate')\n // one adapter per opening: its copies and the holder's grants belong to\n // that opening, and the next opening gets an adapter of its own\n if (this.#gate === null) this.#gate = gate\n else if (this.#gate !== gate) throw new Error('one adapter per opening: this adapter reconciles with another holder (create a new adapter for the next opening)')\n const now = this.#now(rawNow)\n // a submission's key: the digest, and for a duplicate's answer its\n // grant too — the retries and each answer are hand-overs of their own\n const keyOf = (digest: string, resend: number | undefined): string => resend === undefined ? digest : `${digest}#${resend}`\n const named = new Set(view.entries.map((e) => keyOf(e.digest, e.resend)))\n const filed = new Map<string, Submission>()\n for (const [id, sub] of this.#subs) {\n if (sub.digest === undefined) continue\n const key = keyOf(sub.digest, sub.entry?.resend)\n const before = sub.st === null || sub.st.state === 'awaiting-transport'\n if (before && !named.has(key)) { this.#subs.delete(id); continue }\n filed.set(key, sub)\n }\n const refs: SubmissionRef[] = []\n for (const entry of view.entries) {\n const had = filed.get(keyOf(entry.digest, entry.resend))\n if (had !== undefined) {\n // the newest entry of a live submission is the one its gate checks\n if (had.st === null || had.st.state === 'awaiting-transport') { had.entry = entry; had.gate = gate; continue }\n // an answer the holder still offers is still owed — its hand-over\n // never began, or the holder could not record that it did: a\n // terminal submission of it is filed again (the holder ends it)\n if (entry.resend === undefined) continue\n this.#subs.delete(had.id)\n }\n const id = 's' + this.#nextId++\n const sub: Submission = {\n id, digest: entry.digest, entry, gate,\n bytes: new TextEncoder().encode(jcs(entry.envelope)),\n // a duplicate's ack is a hand-over of its own, from now\n submittedAt: entry.resend !== undefined ? now : Math.min(entry.since, now),\n attemptStartedAt: null, lastKind: null, st: null,\n }\n this.#subs.set(id, sub)\n refs.push({ submissionId: id, digest: entry.digest })\n // taken over past its horizon (counted from the first submission,\n // RLTP-DEL-6130): given up at once, never attempted\n if (now - sub.submittedAt >= DECLARED.giveUpHorizonMs) { sub.st = { state: 'failed', reason: 'expired-by-adapter-policy' }; continue }\n if (this.#wire.offline?.() !== true) this.#startAttempt(sub, now)\n }\n return refs\n }\n\n /** The current state as the ports' DeliveryReport for holder.report(),\n * or null while no honest report exists (and for an unknown id). A\n * submission filed without a digest (submit) has no report form. */\n report (id: string): DeliveryReport | null {\n const st = this.status(id)\n if (st === null) return null\n const digest = this.#subs.get(id)!.digest\n if (digest === undefined) throw new Error('submitted without a document digest: file holder documents through reconcile')\n return deliveryReportOf(digest, st)\n }\n\n has (id: string): boolean {\n this.#open()\n return this.#subs.has(id)\n }\n\n #startAttempt (sub: Submission, now: number): void {\n if (sub.attemptStartedAt !== null) return\n sub.attemptStartedAt = now\n this.#track(this.#trySend(sub, now).finally(() => { sub.attemptStartedAt = null }))\n }\n\n async #trySend (sub: Submission, now: number): Promise<void> {\n if (sub.st !== null && sub.st.state !== 'awaiting-transport') return\n let next: SubmissionState\n try {\n const token = await this.#ensureAuth(now)\n if (this.#closed) return // retirement between auth and deposit: nothing new starts (R5-B2)\n // each attempt hands the wire a copy: what it does with it never reaches the next\n const deposit = (): Promise<void> => {\n try { return this.#wire.deposit(token, new Uint8Array(sub.bytes), this.#egressDid) } catch (e) { return Promise.reject(e) }\n }\n if (sub.gate !== undefined) {\n // the holder decides, and the deposit starts in the same step of its\n // queue (Delivery RLTP-DEL-6125 to 6135); the adapter re-checks its\n // own state there: retired, withdrawn, past the trias, past the\n // entry's deadline or its own horizon → no deposit\n // the deposit's outcome, caught at once: the holder's step may still\n // be committing when the wire answers\n let started: Promise<unknown> | null = null\n let declined = false\n const entry = sub.entry!\n const start = (): boolean => {\n if (this.#closed || this.#subs.get(sub.id) !== sub || sub.gate!.closed === true ||\n (sub.st !== null && sub.st.state !== 'awaiting-transport') || this.#clock >= entry.notAfter ||\n this.#clock - sub.submittedAt >= DECLARED.giveUpHorizonMs) { declined = true; return false }\n started = deposit().then(() => null, (e: unknown) => ({ failed: e }))\n return true\n }\n let ok: boolean | null\n try { ok = await sub.gate.handOver(entry, this.#clock, start) } catch { ok = null }\n if (started === null) {\n // the holder said no: withdrawn; the adapter declined or the\n // holder was unreachable: not this attempt\n if (ok === false && !declined && this.#subs.get(sub.id) === sub) this.#subs.delete(sub.id)\n return\n }\n const outcome = await (started as Promise<unknown>)\n if (outcome !== null) throw (outcome as { failed: unknown }).failed\n } else {\n await deposit()\n }\n sub.lastKind = null\n next = { state: 'accepted' }\n } catch (e) {\n const kind: WireErrorKind = e instanceof WireError ? e.kind : 'unreachable'\n sub.lastKind = kind\n next = kind === 'oversize'\n ? { state: 'failed', reason: 'oversize' }\n : {\n state: 'awaiting-transport',\n reason: kind === 'unreachable' ? 'transport-unreachable' : 'carrier-refused-retriable',\n }\n }\n if (this.#closed) return\n // An interim report (including a horizon-corrected one) never\n // outranks the attempt's real outcome; only a TERMINAL state —\n // a give-up, a refusal, a delivery — stands (R5-B1). Without\n // this, an accepted deposit would stay reported unreachable and\n // be sent a second time.\n if (sub.st === null || sub.st.state === 'awaiting-transport') sub.st = next\n }\n\n /** Host teardown aid, NOT a port operation (profile §6): awaits\n * the in-flight background tasks so a host can drain before\n * persisting ackState. On a hanging wire it waits as long as the\n * wire does — a host bounds it externally (Promise.race) exactly\n * because this library holds no clock of its own. */\n async settle (): Promise<void> {\n while (this.#inflight.size > 0) await Promise.all([...this.#inflight])\n }\n\n /** The §6.1 report, or null while none exists yet (has()\n * distinguishes an unknown id). status is a PORT: after close it\n * refuses like every other port operation (R5-B3).\n *\n * The pre-transport report is an HONEST SNAPSHOT, derived at the\n * moment of observation by one precedence order (Option B of the\n * round-14 halt) — never a stored patchwork:\n * (a) the wire knows itself offline → offline\n * (b) an attempt is overdue → transport-unreachable\n * (c) the last completed attempt's kind → its report\n * (d) otherwise → no report yet (null)\n * Terminal states and `accepted` are stored and stand. */\n status (id: string): SubmissionState | null {\n this.#open()\n const sub = this.#subs.get(id)\n if (!sub) return null\n if (sub.st !== null && sub.st.state !== 'awaiting-transport') return { ...sub.st }\n if (this.#wire.offline?.() === true) {\n return { state: 'awaiting-transport', reason: 'offline' }\n }\n if (sub.attemptStartedAt !== null &&\n this.#clock - sub.attemptStartedAt >= DECLARED.statusHorizonMs) {\n return { state: 'awaiting-transport', reason: 'transport-unreachable' }\n }\n return sub.st === null ? null : { ...sub.st }\n }\n\n acknowledged (id: string): void {\n if (this.#closed) return\n const sub = this.#subs.get(id)\n if (!sub) return\n if (sub.st?.state === 'delivered') return // idempotent: a duplicate ack never rewrites `late` (R9-M4)\n const late = sub.st?.state === 'failed'\n sub.st = { state: 'delivered', late }\n if (late) this.#transitions.push({ id, to: 'delivered' })\n }\n\n /** Refusals act on live submissions only (§6.1 knows exactly one\n * late correction — the valid ack). The code set is closed and\n * TERMINAL: retryable counterpart conditions (unavailable,\n * internalError) are transport outcomes, never receiver verdicts\n * — they have no entry here, and an unknown code is refused\n * fail-closed rather than minted into a verdict (R6-B2). */\n receiverRefused (id: string, code: ReceiverRefusalCode): void {\n if (this.#closed) return\n if (!RECEIVER_REFUSAL_CODES.has(code)) {\n throw new Error('not a terminal receiver refusal code — retryable conditions are transport outcomes')\n }\n const sub = this.#subs.get(id)\n if (!sub) return\n // A VALIDATED refusal is itself the proof of receipt — the\n // mediator can have accepted and forwarded while our deposit\n // promise is still unresolved, so the report-less phase is a\n // legitimate moment for it (R9-B2, reversing the R8-B3\n // overcorrection). Only terminal states stand against it.\n if (sub.st !== null && sub.st.state !== 'awaiting-transport' && sub.st.state !== 'accepted') return\n sub.st = { state: 'failed', reason: 'rejected-by-receiver', code }\n }\n\n drainTransitions (): Array<{ id: string, to: 'delivered' }> {\n this.#open()\n return this.#transitions.splice(0)\n }\n\n // ── receiver side ───────────────────────────────────────────────\n collect (rawNow: number): Collection {\n this.#open()\n this.#now(rawNow)\n if (this.#inbox.length === 0) return { id: 'c-empty', items: [] }\n const items = this.#inbox.splice(0)\n this.#outstandingBytes += this.#inboxBytes\n this.#inboxBytes = 0\n this.#inboxDigests.clear()\n const id = 'c' + this.#nextColId++\n this.#outstanding.set(id, new Map(items.map((i) => [i.queueId, i])))\n // the caller gets its own copies: the outstanding entries stay intact,\n // whatever it does with the bytes, for a conclusion that keeps them\n return { id, items: items.map((i) => ({ ...i, bytes: new Uint8Array(i.bytes) })) }\n }\n\n /** Concludes a collection (profile §4, Delivery 5a.8): its items'\n * digests become ack intent. `keep` names the items whose disposition\n * is transient (Delivery RLTP-DEL-5810, 5820: `failed(rate-limited)`,\n * or a transaction that could not commit, see `concludable`): they are\n * not concluded and not acknowledged, they go back to the buffer and the\n * next collect offers them again, and the mediator keeps its copy. */\n conclude (collection: { id: string }, rawNow: number, opts: { keep?: readonly string[] } = {}): void {\n this.#open()\n const now = this.#now(rawNow)\n const col = this.#outstanding.get(collection.id)\n if (!col) return\n this.#outstanding.delete(collection.id)\n const keep = new Set(opts.keep ?? [])\n for (const item of col.values()) {\n this.#outstandingBytes -= item.bytes.length\n if (keep.has(item.queueId)) {\n // transient: back to the buffer, offered again, never acknowledged\n this.#inbox.push(item)\n this.#inboxBytes += item.bytes.length\n this.#inboxDigests.add(item.queueId)\n continue\n }\n this.#concluded.set(item.queueId, now)\n this.#pendingAcks.add(item.queueId)\n }\n this.#startFlush(now)\n }\n\n ackState (): AckState {\n return {\n concluded: [...this.#concluded].map(([queueId, concludedAt]) => ({ queueId, concludedAt })),\n pending: [...this.#pendingAcks],\n }\n }\n\n #startFlush (now: number): void {\n if (this.#flushing || this.#pendingAcks.size === 0) return\n this.#flushing = true\n const snapshot = new Set(this.#pendingAcks)\n this.#track(this.#flushAcks(now, [...snapshot]).finally(() => {\n this.#flushing = false\n // lost-wake-up guard (review-4 M6): intents that arrived while\n // this flush ran get their own flush now — but only newcomers,\n // so a failing wire waits for the next advance instead of\n // spinning\n if (!this.#closed) {\n for (const id of this.#pendingAcks) {\n if (!snapshot.has(id)) { this.#startFlush(this.#clock); break }\n }\n }\n }))\n }\n\n async #flushAcks (now: number, ids: string[]): Promise<void> {\n try {\n const token = await this.#ensureAuth(now)\n if (this.#closed) return\n // Only NOW does anything become irrecallable (R16-B1): the\n // stay of expiry begins at the wire call itself, never at the\n // snapshot — a hanging auth extends no window. And \"live\" is\n // WINDOW-live (R17-B1): an entry whose window already closed —\n // even if no prune has swept it yet — is never sent.\n const live = ids.filter((id) => {\n const at = this.#concluded.get(id)\n return at !== undefined && this.#clock - at < DECLARED.duplicateWindowMs\n })\n if (live.length === 0) return\n for (const id of live) this.#flightAcks.add(id)\n try {\n // the wire gets its own list: what it does with it never reaches the bookkeeping below\n await this.#wire.ackReceived(token, [...live])\n if (!this.#closed) for (const id of live) this.#pendingAcks.delete(id)\n } finally {\n for (const id of live) this.#flightAcks.delete(id)\n // deferred window sweep: entries whose window closed while\n // the ack flew fall now — intent, entry and absorption\n // together (R15-B1). Never on a retired instance: after\n // close, ackState() is the host's final-persist surface and\n // a late-returning wire mutates nothing (R17-B2).\n if (!this.#closed) {\n for (const id of live) {\n const at = this.#concluded.get(id)\n if (at !== undefined && this.#clock - at >= DECLARED.duplicateWindowMs) {\n this.#concluded.delete(id)\n this.#pendingAcks.delete(id)\n }\n }\n }\n }\n } catch {\n // intent survives; the next advance starts a fresh flush\n }\n }\n\n // ── the adapter clock — never awaits the mediator ───────────────\n advance (rawNow: number): void {\n this.#open()\n const now = this.#now(rawNow)\n for (const sub of this.#subs.values()) {\n const live = sub.st === null || sub.st.state === 'awaiting-transport' || sub.st.state === 'accepted'\n if (!live) continue\n if (now - sub.submittedAt >= DECLARED.giveUpHorizonMs) {\n // unroutable only when the LAST COMPLETED attempt was an\n // admission refusal and no attempt is in flight whose outcome\n // is unknown (review-4 B3)\n // the give-up verdict applies the SAME precedence as every\n // observation (R17-B3): a wire that knows itself offline at\n // the horizon outranks any stored refusal class — unroutable\n // needs a completed admission refusal, no unknown outcome in\n // flight, AND no offline signal standing over it\n sub.st = {\n state: 'failed',\n reason: sub.lastKind === 'refused-admission' && sub.attemptStartedAt === null &&\n this.#wire.offline?.() !== true\n ? 'unroutable'\n : 'expired-by-adapter-policy',\n }\n continue\n }\n if (sub.st !== null && sub.st.state === 'accepted') continue\n // reports are DERIVED at observation (see status()); the clock\n // only decides here whether to start an attempt — and never\n // against a wire that knows itself offline\n if (this.#wire.offline?.() === true) continue\n if (sub.attemptStartedAt === null) this.#startAttempt(sub, now)\n }\n // THE WINDOW BEATS EVERYTHING (Option B of the round-14 halt):\n // an ack intent is retried until the window closes; then intent\n // and absorption fall together. There is no ageless debt whose\n // truth the adapter would have to know — the receiver's §6.2\n // absorption owns everything beyond the window.\n for (const [digest, at] of this.#concluded) {\n if (now - at >= DECLARED.duplicateWindowMs && !this.#flightAcks.has(digest)) {\n this.#concluded.delete(digest)\n this.#pendingAcks.delete(digest)\n }\n }\n this.#startKeylistSync(now)\n this.#startFlush(now)\n }\n\n /** §5a.10 lifecycle boundary: after close, every state port is\n * inert — port operations refuse, inbound reports (acknowledged,\n * receiverRefused) are no-ops, late wire resolutions mutate\n * nothing. Only ackState() stays readable for the host's final\n * persist. */\n close (): void { this.#closed = true }\n\n get closed (): boolean { return this.#closed }\n}\n\nexport const queueIdOf = async (bytes: Uint8Array): Promise<string> => hex(await sha(bytes))\n"]}
1
+ {"version":3,"file":"vti-mediator.js","sourceRoot":"","sources":["../../src/adapters/vti-mediator.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,4EAA4E;AAC5E,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,uEAAuE;AACvE,mEAAmE;AACnE,oEAAoE;AACpE,wEAAwE;AACxE,2EAA2E;AAC3E,0EAA0E;AAC1E,yFAAyF;AACzF,2EAA2E;AAC3E,yEAAyE;AACzE,qEAAqE;AACrE,yEAAyE;AACzE,0EAA0E;AAC1E,uEAAuE;AACvE,UAAU;AACV,EAAE;AACF,qEAAqE;AACrE,kDAAkD;AAClD,8DAA8D;AAC9D,uEAAuE;AACvE,mEAAmE;AACnE,0EAA0E;AAC1E,2EAA2E;AAC3E,kFAAkF;AAClF,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,gEAAgE;AAChE,wEAAwE;AACxE,oEAAoE;AACpE,yEAAyE;AACzE,wEAAwE;AACxE,qEAAqE;AACrE,uEAAuE;AACvE,wEAAwE;AACxE,0EAA0E;AAC1E,uEAAuE;AACvE,uEAAuE;AACvE,wEAAwE;AACxE,2DAA2D;AAC3D,sEAAsE;AACtE,kEAAkE;AAClE,wEAAwE;AACxE,uEAAuE;AACvE,gDAAgD;AAChD,qEAAqE;AACrE,sEAAsE;AACtE,sDAAsD;AACtD,gEAAgE;AAChE,yCAAyC;AACzC,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,kEA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,KAAK,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3C,IAAI,GAAG,GAAG,EAAE,IAAI,QAAQ,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC5E,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBAC9B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;QACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;IAED;;;;mBAIe;IACf,KAAK,KAAY,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA,CAAC,CAAC;IAEtC,IAAI,MAAM,KAAe,OAAO,IAAI,CAAC,OAAO,CAAA,CAAC,CAAC;CAC/C;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,KAAiB,EAAmB,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA","sourcesContent":["// RLTP transport adapter: VTI mediator — published as\n// @real-life/trust-protocol/adapters/vti-mediator (lib Stage 2, note §4.6).\n//\n// It takes the holder's documents from the holder's custody (Delivery 0.83\n// RLTP-DEL-6120 to 6135, lib 0.6.0): reconcile(view, gate, now) files every\n// entry of holder.pendingTransport(when) not yet filed, and withdraws every\n// filed submission still before the trias whose digest the view no longer\n// names — a missing entry means stop, never keep sending. Before every\n// deposit it asks gate.mayHandOver(entry, now) (the holder): false\n// withdraws the submission, an error skips the attempt. It keeps no\n// custody of its own: its copies are volatile and bound to the holder's\n// opening: bound to the holder of its first reconcile, it refuses another,\n// so after holder.close() nothing it holds goes out, and the next opening\n// gets a new adapter (restored from ackState like any other). Its give-up horizon counts\n// from the entry's first submission (`since`), never from when it took the\n// entry over (RLTP-DEL-6130). Its reports reach the holder as the ports'\n// DeliveryReport: report(id) maps the adapter's SubmissionState onto\n// DeliveryReport (deliveryReportOf), keyed by the document digest, which\n// the app hands to holder.report(). An adapter's `delivered` is its claim\n// about transport; the holder's receive core verifies the delivery-ack\n// itself.\n//\n// Profile: spec/adapter-vti-mediator.md v0.25 (twenty-fifth casting;\n// round journals under design/adapter-review*). A\n// transport adapter contract — NOT a carrier at the port. The\n// counterpart's connection DID and egress identity the wire needs come\n// from the counterpart's delivery hint in the card that opened the\n// relationship (profile §1b); the holder hands the hints on uninterpreted\n// (RelationshipView.counterpartDeliveryHints) and this adapter derives its\n// own trio from the relationship's carrier nonce (RelationshipView.carrierNonce).\n//\n// Sending form (profile §3a, lib 0.7.0): every deposit names its mode to\n// the wire. Mode `routed` (the mode of every instance from construction):\n// an inner TSP `direct` message egress identity → counterpart's\n// connection DID inside an outer routed message connection DID → C with\n// the route [counterpart's connection DID], on the connection DID's\n// session. Mode `egress-session` (fallback): the inner message alone, on\n// a send-only session of the egress identity. The wire packs the layers\n// (depositAddressing says who addresses whom); the adapter keeps the\n// relationship's send state (the mode and the open routed deposits) in\n// its ack state (RLTP-VTI-3130). Open are: every document with a digest\n// (an entry of kind `document` filed by reconcile) accepted in routed and\n// not yet answered — a valid acknowledgement, a validated refusal or a\n// validated idConflict for its digest answers it. Acknowledgements are\n// no open deposits: a side that only acknowledges never switches by the\n// deadline (Open Issue 9). The adapter switches one way to\n// `egress-session` when an open deposit is routed-ack-deadline (72 h)\n// old, checked in an advance after a conclusion that left nothing\n// pending and while nothing is pending again — \"nothing pending\" is the\n// binding's statement through queueEmpty() (RLTP-VTI-7150); without it\n// the adapter never switches — and at once on a\n// validated refusal of the routed form (WireError 'routed-refused').\n// At the switch the open deposits leave; nothing returns to routed. A\n// submit() without a digest opens nothing. An attempt\n// ends in the mode it began in; an accepted submission is never\n// deposited again (RLTP-VTI-3135, 7130).\n//\n// The app's transport contract (web-of-trust TRANSPORT.md, rules 5 and\n// 6), as far as it holds here: (5) a withdrawal — reconcile without the\n// entry — means the adapter starts no deposit for that submission\n// afterwards, and an outcome that resolves late changes nothing here\n// (has() false, report() null, no send state) — except a validated refusal\n// of the routed form, which switches the relationship (a finding about the\n// mediator, RLTP-VTI-3130). A wire call already\n// running cannot be recalled and may still land at the mediator (the §6\n// boundary); the copy that then arrives is a duplicate the receiver\n// absorbs (Delivery §6.2). (6) Every deposit is a submission with an id\n// of its own, a duplicate's answer (`resend`) included; the\n// DeliveryReport handed to the holder carries the digest, and the app\n// pairs it with its deposit through the submission id it polls.\n//\n// Beyond the profile (lib 0.5.0): conclude(collection, now, {keep}) leaves\n// the items whose disposition is transient unconcluded and offers them\n// again (Delivery 0.82 RLTP-DEL-5810, 5820: failed(rate-limited) is never\n// concluded); `concludable(result)` says which receive outcomes are\n// terminal. The profile's §4 concludes a collection whole; its next\n// casting is to take this up.\n//\n// Structural rules (reviews 3+4):\n// · No port operation ever awaits the mediator — including\n// register: keylist synchronization is a recorded intent with a\n// tracked background task, retried by advance.\n// · No report is invented, and absence is ABSENT: before the first\n// honest report exists, status() returns null (§6.1 grants the\n// window; representing it as a queryable fourth value was\n// review-4 B2). has() distinguishes an unknown id.\n// · A retired instance mutates nothing and refuses everything\n// except reading its ack state.\n\nimport { jcs } from '../core.js'\nimport type { Json } from '../core.js'\nimport { anchorOfEd, edRawOfAnchor, sha } from '../crypto.js'\nimport { carrierPrincipal, carrierScopedIdentity } from '../carrier-identity.js'\nimport type { CarrierPrincipal, CarrierScopedIdentity } from '../carrier-identity.js'\nimport type { DeliveryReport, ReceiverRefusalCode, SubmissionRef } from '../ports.js'\nimport type { TransportEntry, TransportView } from '../engine.js'\nimport type { ReceiveResult } from '../results.js'\nexport type { ReceiverRefusalCode } from '../ports.js'\n\n// ── Declared constants (profile §2) — promises of THIS casting ──────\n// frozen: the declared promises cannot be changed at run time either\nexport const DECLARED = Object.freeze({\n giveUpHorizonMs: 72 * 3_600_000,\n statusHorizonMs: 60_000,\n queueFloorCount: 64,\n queueFloorBytes: 1_048_576,\n maxQueueBytes: 16_777_216,\n duplicateWindowMs: 30 * 86_400_000,\n routedAckDeadlineMs: 72 * 3_600_000,\n} as const)\n\n// ── The delivery hint (profile §1b) ──────────────────────────────────\n// Below the port line: the holder carries hints uninterpreted; this\n// adapter builds its own and reads the counterpart's.\n\n/** The counterpart's wire identities at one carrier, as its hint names them. */\nexport interface DeliveryHintIdentities { connectionDid: string, egressDid: string, carrier: string }\n\nconst HINT_MEMBERS = jcs(['id', 'rltpEgress', 'serviceEndpoint', 'type'])\n/** An Ed25519 did:key in the form RLTP-VTI-1210 fixes: `did:key:z` and the\n * base58btc of multicodec 0xed01 followed by the 32-byte key, rendered\n * canonically (decoding and re-encoding gives the same string). */\nconst edDidKey = (x: unknown): x is string => {\n // the canonical form has exactly 56 characters; checked first, so no long input reaches the base58 decoder\n if (typeof x !== 'string' || x.length !== 56) return false\n const raw = edRawOfAnchor(x)\n return raw !== null && anchorOfEd(raw) === x\n}\n\n/** This side's hint for carrier `C` in the relationship of carrier nonce\n * `N` (RLTP-VTI-1210, 1215): the connection DID and the egress identity\n * derived here from (root, `C`, `N`), exactly as the factory derives the\n * instance's trio — derived, not supplied, so the two cannot come from\n * different relationships — as the JCS form of the TSPTransport service\n * entry naming the connection DID (`id`, with `#tsp`), `C`\n * (`serviceEndpoint`) and the egress identity (`rltpEgress`). */\nexport async function deliveryHint (rootIkm: Uint8Array, carrier: string, nonce: Uint8Array): Promise<string> {\n // snapshot at entry, as create does (R8-B2): a caller's buffer changed\n // between the two derivations must not couple two relationships\n const ikm = new Uint8Array(rootIkm)\n const n = new Uint8Array(nonce)\n const connection = await carrierScopedIdentity(ikm, carrier, n, 'connection')\n const egress = await carrierScopedIdentity(ikm, carrier, n, 'egress')\n return jcs({ id: connection.did + '#tsp', type: 'TSPTransport', serviceEndpoint: carrier, rltpEgress: egress.did })\n}\n\n/** One hint read strictly (RLTP-VTI-1210, 1220) for carrier `C`: JSON,\n * byte-equal to its JCS form, exactly the four members, type\n * TSPTransport, an `id` ending in `#tsp`, both identities distinct\n * canonical Ed25519 did:key, `serviceEndpoint` byte-equal to `C`.\n * Total (RLTP-VTI-1220): any other input — not a string, not JSON, no JCS\n * form (a lone surrogate), any other shape — is null, ignored; it never\n * throws. */\nexport function readDeliveryHint (hint: unknown, carrier: unknown): DeliveryHintIdentities | null {\n try {\n return readStrict(hint, carrier)\n } catch {\n return null\n }\n}\n\nfunction readStrict (hint: unknown, carrier: unknown): DeliveryHintIdentities | null {\n if (typeof hint !== 'string' || typeof carrier !== 'string' || carrier.length === 0) return null\n const o: unknown = JSON.parse(hint)\n if (o === null || typeof o !== 'object' || Array.isArray(o) || jcs(o as Json) !== hint) return null\n const e = o as Record<string, unknown>\n if (jcs(Object.keys(e).sort()) !== HINT_MEMBERS || e.type !== 'TSPTransport' || e.serviceEndpoint !== carrier) return null\n if (typeof e.id !== 'string' || !e.id.endsWith('#tsp')) return null\n const connectionDid = e.id.slice(0, -'#tsp'.length)\n if (!edDidKey(connectionDid) || !edDidKey(e.rltpEgress) || connectionDid === e.rltpEgress) return null\n return { connectionDid, egressDid: e.rltpEgress, carrier }\n}\n\n/** The counterpart's wire identities at `C` from the hints of the card\n * that opened the relationship, read by the side `self` (its own\n * connection DID and egress identity of this relationship and carrier):\n * every hint read as readDeliveryHint does; a hint naming one of `self`'s\n * identities is ignored (RLTP-VTI-1227); of what remains, the one hint\n * for `C` (RLTP-VTI-1225, 1240) — none, or more than one, is null: the\n * relationship is not carried at `C` (RLTP-VTI-1235). Total: any input\n * answers null or the identities, never a throw; without a well-formed\n * `self` nothing is read. */\nexport function readDeliveryHints (hints: unknown, carrier: unknown, self: unknown): DeliveryHintIdentities | null {\n try {\n if (!Array.isArray(hints)) return null\n const me = self as { connection?: unknown, egress?: unknown } | null\n if (me === null || typeof me !== 'object' || !edDidKey(me.connection) || !edDidKey(me.egress)) return null\n const own = new Set<string>([me.connection, me.egress])\n const read = hints.map((h) => readDeliveryHint(h, carrier))\n .filter((x): x is DeliveryHintIdentities => x !== null && !own.has(x.connectionDid) && !own.has(x.egressDid))\n return read.length === 1 ? read[0] : null\n } catch {\n return null\n }\n}\n\n// ── The sending form (profile §3a) ───────────────────────────────────\n/** How a deposit reaches the mediator (RLTP-VTI-3110, 3120). */\nexport type SendMode = 'routed' | 'egress-session'\nconst SEND_MODES: ReadonlySet<string> = new Set<SendMode>(['routed', 'egress-session'])\n\n/** One TSP layer's addressing (no keys, no bytes: those are the wire's). */\nexport interface LayerAddressing {\n messageType: 'direct' | 'routed'\n sender: string\n receiver: string\n route?: string[]\n}\n\n/** The addressing of a deposit in `mode` (RLTP-VTI-1110, 1120, 3110,\n * 3115, 3120): the inner `direct` message from this side's egress\n * identity to the counterpart's connection DID; in mode `routed` an\n * outer routed message from this side's connection DID to the carrier\n * `C` with the route [counterpart's connection DID], deposited on the\n * connection DID's session; in mode `egress-session` no outer layer,\n * deposited on the egress identity's send-only session. */\nexport function depositAddressing (\n mode: SendMode, self: { connection: string, egress: string }, peerConnection: string, carrier: string,\n): { inner: LayerAddressing, outer: LayerAddressing | null, session: string } {\n if (!SEND_MODES.has(mode)) throw new Error(`unknown send mode ${String(mode)}`)\n const inner: LayerAddressing = { messageType: 'direct', sender: self.egress, receiver: peerConnection }\n if (mode === 'routed') {\n return {\n inner,\n outer: { messageType: 'routed', sender: self.connection, receiver: carrier, route: [peerConnection] },\n session: self.connection,\n }\n }\n return { inner, outer: null, session: self.egress }\n}\n\n// ── The injected wire ────────────────────────────────────────────────\nexport type WireErrorKind =\n | 'unreachable' | 'refused-retriable' | 'refused-admission' | 'oversize'\n /** the mediator refused a routed deposit for its routed form, and the\n * binding authenticated that refusal as the mediator's (RLTP-VTI-3130):\n * the relationship switches to egress-session at once */\n | 'routed-refused'\n\nexport class WireError extends Error {\n kind: WireErrorKind\n constructor (kind: WireErrorKind, message?: string) {\n super(message ?? kind)\n this.kind = kind\n }\n}\n\nexport interface MediatorWire {\n authChallenge (did: string): Promise<{ challenge: string, sessionId: string }>\n authenticate (answer: { did: string, challenge: string, sessionId: string }): Promise<TokenSet>\n // A transient failure MUST be a WireError 'unreachable' or\n // 'refused-retriable' (the tokens are kept); any other error means the\n // mediator refused the refresh token (the adapter re-runs the handshake).\n refresh (refreshToken: string): Promise<TokenSet>\n keylistUpdate (accessToken: string, rkids: string[]): Promise<void>\n /** `mode` is the sending form of this deposit (profile §3a): the wire\n * packs and sends it as depositAddressing(mode, …) describes. */\n deposit (accessToken: string, bytes: Uint8Array, egressDid: string, mode: SendMode): Promise<void>\n ackReceived (accessToken: string, queueIds: string[]): Promise<void>\n /** The adapter's consumer answers whether it took the frame (buffered,\n * already held, or absorbed as a duplicate): false means the frame is\n * left with the mediator (above max-queue-bytes, or a retired\n * instance), and a wire must not take its queue for drained until the\n * frame is offered again (RLTP-VTI-3130, queueEmpty). */\n onDeliver (cb: (bytes: Uint8Array) => Promise<boolean>): void\n /** Optional truthful connectivity signal; absent means unknown. */\n offline? (): boolean\n /** Optional: true when the mediator holds nothing more for this\n * connection (RLTP-VTI-3130: a conclusion that left no frame\n * pending). Closed: absent, no collection counts as complete, so an\n * adapter over a wire without it never switches to egress-session. */\n queueEmpty? (): boolean\n}\n\nexport interface TokenSet {\n accessToken: string\n accessExpiresAt: number\n refreshToken: string\n refreshExpiresAt: number\n}\n\n// ── Sender states (§6.1 — the closed sets, nothing else) ────────────\n// ReceiverRefusalCode is the ports' (one closed set, one place)\nconst RECEIVER_REFUSAL_CODES: ReadonlySet<ReceiverRefusalCode> = new Set<ReceiverRefusalCode>([\n 'malformedRequest', 'unsupportedType', 'proofRequired',\n 'proofInvalid', 'wrongRecipient', 'identityMismatch',\n])\n\nexport type SubmissionState =\n | { state: 'awaiting-transport', reason: 'offline' | 'transport-unreachable' | 'carrier-refused-retriable' }\n | { state: 'accepted' }\n | { state: 'delivered', late: boolean }\n | { state: 'failed', reason: 'unroutable' | 'oversize' | 'expired-by-adapter-policy' }\n | { state: 'failed', reason: 'rejected-by-receiver', code: ReceiverRefusalCode }\n\n/** The ports' DeliveryReport for a document `digest` in adapter state `st`\n * (Delivery §6.1): one-to-one, `late` and the refusal code carried over. */\nexport function deliveryReportOf (digest: string, st: SubmissionState): DeliveryReport {\n switch (st.state) {\n case 'awaiting-transport': return { digest, status: 'awaiting-transport', reason: st.reason }\n case 'accepted': return { digest, status: 'accepted' }\n case 'delivered': return { digest, status: 'delivered', late: st.late }\n case 'failed': return st.reason === 'rejected-by-receiver'\n ? { digest, status: 'failed', reason: 'rejected-by-receiver', code: st.code }\n : { digest, status: 'failed', reason: st.reason }\n }\n}\n\n/** Whether a receive outcome is terminal and its item may be concluded\n * (Delivery 5a.8): every disposition but `failed(rate-limited)`, the one\n * failure that is transient (RLTP-DEL-5820). An InfraError of the\n * holder's store is transient as well (RLTP-DEL-5810): an item whose\n * receive threw is kept, too. */\nexport function concludable (r: ReceiveResult): boolean {\n return !(r.disposition === 'failed' && r.reason === 'rate-limited')\n}\n\n/** The adapter's own copy of a wire's token set: the wire keeps no handle on it. */\nconst tokenCopy = (t: TokenSet): TokenSet => ({ accessToken: t.accessToken, accessExpiresAt: t.accessExpiresAt, refreshToken: t.refreshToken, refreshExpiresAt: t.refreshExpiresAt })\n\nexport interface CollectedItem { bytes: Uint8Array, queueId: string }\nexport interface Collection { id: string, items: CollectedItem[] }\n\n/** Ack state for the host to persist (profile §4). Invariant: every\n * pending id names a concluded entry; violations are refused at\n * construction (fail-closed). */\nexport interface AckState {\n concluded: Array<{ queueId: string, concludedAt: number }>\n pending: string[]\n /** the relationship's send state (RLTP-VTI-3130); absent → `routed` */\n send?: SendState\n}\n\n/** The send state of a relationship (profile §3a, RLTP-VTI-3130),\n * persisted with the ack state: the mode and the open routed deposits —\n * this side's documents accepted in routed and not yet answered, each\n * with its digest and acceptance instant. Acknowledgements are no open\n * deposits. In egress-session `open` is empty. */\nexport interface SendState {\n mode: SendMode\n open: Array<{ digest: string, acceptedAt: number }>\n}\n\n/** how long an open routed deposit stays in the send state at most\n * (RLTP-VTI-3130): the state is bounded even where no switch check runs */\nconst OPEN_KEEP_MS = DECLARED.routedAckDeadlineMs + DECLARED.duplicateWindowMs\n\nconst finite = (x: unknown): x is number => typeof x === 'number' && Number.isFinite(x)\n\n/** A restored send state, checked fail-closed (§4): exactly `mode` and\n * `open`, a known mode, each entry exactly a digest and a finite\n * acceptance instant not after restoredAt, each digest once, nothing open\n * in egress-session. Any other field — the acknowledgement fields of an\n * earlier form included — is refused, not ignored. */\nfunction restoreSendState (send: unknown, restoredAt: number): SendState {\n const refuse = (why: string): never => { throw new Error(`ack snapshot: send state ${why}`) }\n if (typeof send !== 'object' || send === null) return refuse('is not an object')\n const s = send as Record<string, unknown>\n const exactly = (o: object, keys: string[]): boolean => {\n const own = Object.keys(o)\n return own.length === keys.length && keys.every((k) => own.includes(k))\n }\n if (!exactly(s, ['mode', 'open'])) refuse('has other fields than mode and open')\n if (typeof s.mode !== 'string' || !SEND_MODES.has(s.mode)) refuse('names an unknown mode')\n if (!Array.isArray(s.open)) refuse('open deposits are not a list')\n const open = (s.open as unknown[]).map((r) => {\n const e = r as Record<string, unknown> | null\n if (typeof e !== 'object' || e === null || !exactly(e, ['digest', 'acceptedAt']) ||\n typeof e.digest !== 'string' || !finite(e.acceptedAt) || e.acceptedAt > restoredAt) {\n return refuse('open deposit is malformed, non-finite or accepted after restoredAt')\n }\n return { digest: e.digest, acceptedAt: e.acceptedAt }\n })\n if (new Set(open.map((o) => o.digest)).size !== open.length) refuse('names an open deposit twice')\n // the switch empties it: an egress-session with open deposits was never produced\n if (s.mode === 'egress-session' && open.length > 0) refuse('is egress-session with open routed deposits')\n return { mode: s.mode as SendMode, open }\n}\n\n/** The holder's side of a hand-over (lib 0.6.0): the holder itself.\n * handOver checks the entry and calls `start` inside the holder's queue;\n * `start` re-checks the adapter's own state, starts the deposit\n * synchronously and says whether it did. `closed` is read in `start`. */\nexport interface TransportGate {\n handOver (entry: TransportEntry, when: number, start: () => boolean): Promise<boolean>\n readonly closed?: boolean\n}\n\ninterface Submission {\n id: string\n /** the document digest, for submissions filed by reconcile */\n digest?: string\n /** the holder's entry and its gate, for submissions filed by reconcile */\n entry?: TransportEntry\n gate?: TransportGate\n bytes: Uint8Array\n submittedAt: number\n attemptStartedAt: number | null\n lastKind: WireErrorKind | null\n st: SubmissionState | null // null = no honest report exists yet\n /** the mode of the last deposit call started for it (RLTP-VTI-3135) */\n sentMode: SendMode | null\n /** a verdict on it arrived: its digest is never opened after it */\n answered?: boolean\n}\n\nconst hex = (b: Uint8Array): string =>\n Array.from(b, (x) => x.toString(16).padStart(2, '0')).join('')\n\n// construction capability: only create() holds it\nconst KEY = Symbol('MediatorCarrierAdapter.create')\n\n// ── The adapter ──────────────────────────────────────────────────────\nexport class MediatorCarrierAdapter {\n // JS-hard identity fields: TS `readonly` is a compile-time promise\n // only, and §8 claims runtime unforgeability — so the values live\n // in true privates behind getters (R8-B1)\n #principal: string\n #connectionDid: string\n #egressDid: string\n get principal (): string { return this.#principal }\n get connectionDid (): string { return this.#connectionDid }\n get egressDid (): string { return this.#egressDid }\n #wire: MediatorWire\n #tokens: TokenSet | null = null\n #clock = Number.NEGATIVE_INFINITY\n #closed = false\n /** the opening this adapter serves, bound at its first reconcile */\n #gate: TransportGate | null = null\n\n #subs = new Map<string, Submission>()\n #inflight = new Set<Promise<void>>()\n #nextId = 1\n\n #desiredRkids: string[] | null = null\n #keylistSynced = false\n #keylistSyncing = false\n\n #inbox: CollectedItem[] = []\n #inboxBytes = 0\n #inboxDigests = new Set<string>()\n #outstanding = new Map<string, Map<string, CollectedItem>>()\n #outstandingBytes = 0\n #concluded = new Map<string, number>()\n #pendingAcks = new Set<string>()\n #flightAcks = new Set<string>() // ids inside the in-flight flush snapshot\n #flushing = false\n #nextColId = 1\n\n #transitions: Array<{ id: string, to: 'delivered' }> = []\n\n // the relationship's send state (RLTP-VTI-3130)\n #mode: SendMode = 'routed'\n /** open routed deposits (documents), keyed by digest */\n #openDeposits = new Map<string, number>()\n /** this instance has concluded a collection that left nothing pending */\n #cleanConcluded = false\n\n /** The only way to build an adapter: the trio is DERIVED here from\n * one root, one carrier, one nonce — so principal, connection DID\n * and egress identity cannot come from different relationships\n * (R7-B2: the coupling is enforced by construction, not by\n * inspecting caller-supplied identities). */\n static async create (\n rootIkm: Uint8Array, carrier: string, nonce: Uint8Array,\n wire: MediatorWire, restored?: AckState, restoredAt?: number,\n ): Promise<MediatorCarrierAdapter> {\n // ONE tuple, snapshotted at entry: a caller mutating its buffers\n // between the three awaited derivations must not be able to mix\n // identities from two tuples (R8-B2)\n const ikm = new Uint8Array(rootIkm)\n const n = new Uint8Array(nonce)\n const principal = await carrierPrincipal(ikm, carrier, n)\n const connection = await carrierScopedIdentity(ikm, carrier, n, 'connection')\n const egress = await carrierScopedIdentity(ikm, carrier, n, 'egress')\n return new MediatorCarrierAdapter(KEY, principal, connection, egress, wire, restored, restoredAt)\n }\n\n constructor (\n key: symbol,\n principal: CarrierPrincipal,\n connection: CarrierScopedIdentity,\n egress: CarrierScopedIdentity,\n wire: MediatorWire,\n restored?: AckState,\n restoredAt?: number,\n ) {\n if (key !== KEY) {\n throw new Error('use MediatorCarrierAdapter.create — the identity trio must be derived, not supplied (5a.10)')\n }\n if (connection.scope !== 'connection' || egress.scope !== 'egress') {\n throw new Error('scoped identities passed in the wrong roles')\n }\n const three = new Set([principal.principal, connection.did, egress.did])\n if (three.size !== 3) {\n throw new Error('principal, connection DID and egress identity must be pairwise distinct (5a.10)')\n }\n this.#principal = principal.principal\n this.#connectionDid = connection.did\n this.#egressDid = egress.did\n this.#wire = wire\n if (restored) {\n // The restore instant anchors the duplicate-window: an expired,\n // debt-free entry is dropped HERE, not at the first advance —\n // otherwise a redelivery arriving before any port call would be\n // absorbed beyond the declared window (review-4 B4).\n if (typeof restoredAt !== 'number' || !Number.isFinite(restoredAt)) {\n throw new Error('restoring ack state requires a finite restoredAt instant')\n }\n this.#now(restoredAt)\n const pending = new Set(restored.pending)\n const known = new Set(restored.concluded.map((c) => c.queueId))\n for (const id of pending) {\n if (!known.has(id)) {\n throw new Error('ack snapshot violates its invariant: pending intent without a concluded entry')\n }\n }\n for (const { queueId, concludedAt } of restored.concluded) {\n if (!Number.isFinite(concludedAt) || concludedAt > restoredAt) {\n // a conclusion \"from the future\" would stretch the window\n // past its declared span (R5-B4) — fail closed\n throw new Error('ack snapshot: conclusion instant is non-finite or after restoredAt')\n }\n // the window beats everything (round-14 B): an expired entry\n // falls at the restore instant, owed or not — a phantom debt\n // from an ack that landed just before a close can never\n // outlive the window and delete a fresh copy (R14-B2)\n if (restoredAt - concludedAt >= DECLARED.duplicateWindowMs) continue\n this.#concluded.set(queueId, concludedAt)\n if (pending.has(queueId)) this.#pendingAcks.add(queueId)\n }\n // absent: a host that persisted none starts again in routed\n if (restored.send !== undefined) {\n const send = restoreSendState(restored.send, restoredAt)\n this.#mode = send.mode\n // an open deposit falls routed-ack-deadline plus duplicate-window\n // after its acceptance: cut here, not refused\n for (const o of send.open) if (restoredAt - o.acceptedAt < OPEN_KEEP_MS) this.#openDeposits.set(o.digest, o.acceptedAt)\n }\n }\n this.#wire.onDeliver(async (raw): Promise<boolean> => {\n if (this.#closed) return false\n // a plain copy of its own: a Node Buffer's slice() would share memory\n const bytes = new Uint8Array(raw)\n const queueId = hex(await sha(bytes))\n if (this.#closed) return false\n // Absorption is checked at the moment it happens (R11-B1): the\n // adapter absorbs a copy only for give-up-horizon after its\n // conclusion (profile §2, §4); a later copy is a new item for the\n // holder, whose absorption answers it again with the stored\n // acknowledgement (RLTP-DEL-6330, 6335) — so a counterpart that\n // resubmits after a lost acknowledgement is answered. The entry and\n // its ack intent stand for the duplicate window, and the window\n // beats everything (round-14 B): beyond it, both fall.\n // buffered and outstanding go before concluded (§3): a redelivery of\n // a later copy the holder has not concluded yet is ignored\n if (this.#inboxDigests.has(queueId)) return true\n for (const col of this.#outstanding.values()) if (col.has(queueId)) return true\n const concludedAt = this.#concluded.get(queueId)\n if (concludedAt !== undefined) {\n if (this.#flightAcks.has(queueId) ||\n this.#clock - concludedAt < DECLARED.giveUpHorizonMs) {\n // inside the horizon — or deferred: an id inside an\n // in-flight flush keeps absorbing until that flush ends,\n // because its irrecallable ack may still land (R15-B1)\n this.#pendingAcks.add(queueId)\n return true\n }\n if (this.#clock - concludedAt >= DECLARED.duplicateWindowMs) {\n this.#concluded.delete(queueId)\n this.#pendingAcks.delete(queueId)\n }\n }\n const held = this.#inboxBytes + this.#outstandingBytes\n const underFloor = this.#inbox.length < DECLARED.queueFloorCount &&\n held + bytes.length <= DECLARED.queueFloorBytes\n const underCap = held + bytes.length <= DECLARED.maxQueueBytes\n // not acknowledged and not taken: the mediator keeps its copy\n if (!underFloor && !underCap) return false\n this.#inbox.push({ bytes, queueId })\n this.#inboxBytes += bytes.length\n this.#inboxDigests.add(queueId)\n return true\n })\n }\n\n #now (raw: number): number {\n if (!Number.isFinite(raw)) throw new Error('non-finite time')\n if (raw > this.#clock) this.#clock = raw\n return this.#clock\n }\n\n #open (): void { if (this.#closed) throw new Error('retired (5a.10 lifecycle)') }\n\n #track (p: Promise<void>): void {\n const t = p.catch(() => {})\n this.#inflight.add(t)\n void t.finally(() => this.#inflight.delete(t))\n }\n\n // ── auth: silent carrier policy ─────────────────────────────────\n // Single-flight: concurrent callers share one handshake — the ATM\n // challenge/response is a session, and two interleaved sessions\n // under one connection DID would answer each other's challenges.\n #authing: Promise<string> | null = null\n\n #ensureAuth (now: number): Promise<string> {\n if (this.#tokens && now < this.#tokens.accessExpiresAt) return Promise.resolve(this.#tokens.accessToken)\n if (this.#authing) return this.#authing\n const run = (async (): Promise<string> => {\n if (this.#tokens && now < this.#tokens.refreshExpiresAt) {\n try {\n const refreshed = await this.#wire.refresh(this.#tokens.refreshToken)\n if (this.#closed) throw new Error('retired') // as on the handshake path (R6-B1)\n this.#tokens = tokenCopy(refreshed)\n return this.#tokens.accessToken\n } catch (e) {\n if (this.#closed) throw e\n // a transient failure (mediator unreachable, retriable refusal)\n // says nothing about the token: keep it for the next attempt (#9)\n if (e instanceof WireError && (e.kind === 'unreachable' || e.kind === 'refused-retriable')) throw e\n // a refused refresh (revoked before its expiry) is never replayed:\n // drop the tokens and take the challenge handshake below\n this.#tokens = null\n }\n }\n const { challenge, sessionId } = await this.#wire.authChallenge(this.#connectionDid)\n if (this.#closed) throw new Error('retired') // nothing new starts, not even the answer (R6-B1)\n this.#tokens = tokenCopy(await this.#wire.authenticate({ did: this.#connectionDid, challenge, sessionId }))\n return this.#tokens.accessToken\n })()\n this.#authing = run.finally(() => { this.#authing = null })\n return this.#authing\n }\n\n // ── transport registration (profile §3 — NOT §5a.3) ─────────────\n /** Records the desired keylist and returns; synchronization runs\n * as a tracked background task and advance retries it until it\n * lands (review-4 B1). */\n register (rkids: string[], rawNow: number): void {\n this.#open()\n const now = this.#now(rawNow)\n this.#desiredRkids = [...rkids]\n this.#keylistSynced = false\n this.#startKeylistSync(now)\n }\n\n get keylistSynced (): boolean {\n this.#open()\n return this.#keylistSynced\n }\n\n #startKeylistSync (now: number): void {\n if (this.#keylistSyncing || this.#keylistSynced || this.#desiredRkids === null) return\n this.#keylistSyncing = true\n const wanted = [...this.#desiredRkids]\n this.#track((async () => {\n try {\n const token = await this.#ensureAuth(now)\n if (this.#closed) return\n await this.#wire.keylistUpdate(token, [...wanted]) // the wire's own list: `wanted` is compared below\n // land only if the desire has not moved meanwhile\n if (!this.#closed && this.#desiredRkids !== null &&\n wanted.join(' ') === this.#desiredRkids.join(' ')) {\n this.#keylistSynced = true\n }\n } catch {\n // intent survives; advance retries\n } finally {\n this.#keylistSyncing = false\n }\n })())\n }\n\n // ── sender side ─────────────────────────────────────────────────\n /** Returns the submission id synchronously. Before the first\n * honest report exists, status() returns null — §6.1's own\n * pre-report window, represented as absence, not as a value. */\n submit (envelopeBytes: Uint8Array, rawNow: number): string {\n this.#open()\n const now = this.#now(rawNow)\n const id = 's' + this.#nextId++\n const knownOffline = this.#wire.offline?.() === true\n const sub: Submission = {\n id,\n // a plain copy of its own (a Node Buffer's slice() shares memory)\n bytes: new Uint8Array(envelopeBytes),\n submittedAt: now,\n attemptStartedAt: null,\n lastKind: null,\n st: null,\n sentMode: null,\n }\n this.#subs.set(id, sub)\n if (!knownOffline) this.#startAttempt(sub, now)\n return id\n }\n\n /** Takes the holder's custody set (holder.pendingTransport, after a\n * resume of this opening) and the holder as the gate: files every entry\n * not yet filed under its digest (its envelope as JCS bytes; the give-up\n * horizon from entry.since) and returns their SubmissionRefs; withdraws\n * every filed submission still before the trias (no report, or\n * awaiting-transport) whose digest the view does not name. Accepted and\n * terminal submissions stay for their reports. */\n reconcile (view: TransportView, gate: TransportGate, rawNow: number): SubmissionRef[] {\n this.#open()\n if (view?.ok !== true || !Array.isArray(view.entries)) throw new Error('reconcile needs a view of holder.pendingTransport')\n if (typeof gate?.handOver !== 'function') throw new Error('reconcile needs the holder as its gate')\n // one adapter per opening: its copies and the holder's grants belong to\n // that opening, and the next opening gets an adapter of its own\n if (this.#gate === null) this.#gate = gate\n else if (this.#gate !== gate) throw new Error('one adapter per opening: this adapter reconciles with another holder (create a new adapter for the next opening)')\n const now = this.#now(rawNow)\n // a submission's key: the digest, and for a duplicate's answer its\n // grant too — the retries and each answer are hand-overs of their own\n const keyOf = (digest: string, resend: number | undefined): string => resend === undefined ? digest : `${digest}#${resend}`\n const named = new Set(view.entries.map((e) => keyOf(e.digest, e.resend)))\n const filed = new Map<string, Submission>()\n for (const [id, sub] of this.#subs) {\n if (sub.digest === undefined) continue\n const key = keyOf(sub.digest, sub.entry?.resend)\n const before = sub.st === null || sub.st.state === 'awaiting-transport'\n if (before && !named.has(key)) { this.#subs.delete(id); continue }\n filed.set(key, sub)\n }\n const refs: SubmissionRef[] = []\n for (const entry of view.entries) {\n const had = filed.get(keyOf(entry.digest, entry.resend))\n if (had !== undefined) {\n // the newest entry of a live submission is the one its gate checks\n if (had.st === null || had.st.state === 'awaiting-transport') { had.entry = entry; had.gate = gate; continue }\n // an answer the holder still offers is still owed — its hand-over\n // never began, or the holder could not record that it did: a\n // terminal submission of it is filed again (the holder ends it)\n if (entry.resend === undefined) continue\n this.#subs.delete(had.id)\n }\n const id = 's' + this.#nextId++\n const sub: Submission = {\n id, digest: entry.digest, entry, gate,\n bytes: new TextEncoder().encode(jcs(entry.envelope)),\n // a duplicate's ack is a hand-over of its own, from now\n submittedAt: entry.resend !== undefined ? now : Math.min(entry.since, now),\n attemptStartedAt: null, lastKind: null, st: null, sentMode: null,\n }\n this.#subs.set(id, sub)\n refs.push({ submissionId: id, digest: entry.digest })\n // taken over past its horizon (counted from the first submission,\n // RLTP-DEL-6130): given up at once, never attempted\n if (now - sub.submittedAt >= DECLARED.giveUpHorizonMs) { sub.st = { state: 'failed', reason: 'expired-by-adapter-policy' }; continue }\n if (this.#wire.offline?.() !== true) this.#startAttempt(sub, now)\n }\n return refs\n }\n\n /** The current state as the ports' DeliveryReport for holder.report(),\n * or null while no honest report exists (and for an unknown id). A\n * submission filed without a digest (submit) has no report form. */\n report (id: string): DeliveryReport | null {\n const st = this.status(id)\n if (st === null) return null\n const digest = this.#subs.get(id)!.digest\n if (digest === undefined) throw new Error('submitted without a document digest: file holder documents through reconcile')\n return deliveryReportOf(digest, st)\n }\n\n has (id: string): boolean {\n this.#open()\n return this.#subs.has(id)\n }\n\n #startAttempt (sub: Submission, now: number): void {\n if (sub.attemptStartedAt !== null) return\n sub.attemptStartedAt = now\n this.#track(this.#trySend(sub, now).finally(() => { sub.attemptStartedAt = null }))\n }\n\n async #trySend (sub: Submission, now: number): Promise<void> {\n if (sub.st !== null && sub.st.state !== 'awaiting-transport') return\n let next: SubmissionState\n let routedRefused = false\n try {\n const token = await this.#ensureAuth(now)\n if (this.#closed) return // retirement between auth and deposit: nothing new starts (R5-B2)\n // each attempt hands the wire a copy: what it does with it never reaches the next.\n // The mode is read at the hand-over itself: from a switch on, every\n // hand-over uses the new mode, and a call already made ends in its own\n // (RLTP-VTI-3135)\n const deposit = (): Promise<void> => {\n sub.sentMode = this.#mode\n try { return this.#wire.deposit(token, new Uint8Array(sub.bytes), this.#egressDid, sub.sentMode) } catch (e) { return Promise.reject(e) }\n }\n if (sub.gate !== undefined) {\n // the holder decides, and the deposit starts in the same step of its\n // queue (Delivery RLTP-DEL-6125 to 6135); the adapter re-checks its\n // own state there: retired, withdrawn, past the trias, past the\n // entry's deadline or its own horizon → no deposit\n // the deposit's outcome, caught at once: the holder's step may still\n // be committing when the wire answers\n let started: Promise<unknown> | null = null\n let declined = false\n const entry = sub.entry!\n const start = (): boolean => {\n if (this.#closed || this.#subs.get(sub.id) !== sub || sub.gate!.closed === true ||\n (sub.st !== null && sub.st.state !== 'awaiting-transport') || this.#clock >= entry.notAfter ||\n this.#clock - sub.submittedAt >= DECLARED.giveUpHorizonMs) { declined = true; return false }\n started = deposit().then(() => null, (e: unknown) => ({ failed: e }))\n return true\n }\n let ok: boolean | null\n try { ok = await sub.gate.handOver(entry, this.#clock, start) } catch { ok = null }\n if (started === null) {\n // the holder said no: withdrawn; the adapter declined or the\n // holder was unreachable: not this attempt\n if (ok === false && !declined && this.#subs.get(sub.id) === sub) this.#subs.delete(sub.id)\n return\n }\n const outcome = await (started as Promise<unknown>)\n if (outcome !== null) throw (outcome as { failed: unknown }).failed\n } else {\n await deposit()\n }\n sub.lastKind = null\n next = { state: 'accepted' }\n } catch (e) {\n let kind: WireErrorKind = e instanceof WireError ? e.kind : 'unreachable'\n // a validated refusal of the routed form: the relationship switches\n // below, the submission stays in custody as a retriable refusal\n if (kind === 'routed-refused') { routedRefused = sub.sentMode === 'routed'; kind = 'refused-retriable' }\n sub.lastKind = kind\n next = kind === 'oversize'\n ? { state: 'failed', reason: 'oversize' }\n : {\n state: 'awaiting-transport',\n reason: kind === 'unreachable' ? 'transport-unreachable' : 'carrier-refused-retriable',\n }\n }\n if (this.#closed) return\n // evidence against routed (RLTP-VTI-3130): the switch, at once\n if (routedRefused) this.#switchToEgress()\n // withdrawn meanwhile (app contract rule 5): the late outcome changes nothing\n if (this.#subs.get(sub.id) !== sub) return\n // a document with a digest accepted in routed is an open routed deposit\n // (RLTP-VTI-3130) — only while the relationship is still routed (an\n // attempt begun before a switch opens nothing after it). Acknowledgements\n // and a submit() without a digest open nothing. Answered already (the\n // verdict outran the deposit's resolution): not opened. acceptedAt is the\n // adapter clock when the deposit resolved, not when it was handed over:\n // later by the deposit's own run time\n if (next.state === 'accepted' && sub.sentMode === 'routed' && this.#mode === 'routed' &&\n sub.digest !== undefined && this.#isDocument(sub) && sub.answered !== true &&\n !this.#openDeposits.has(sub.digest)) {\n this.#openDeposits.set(sub.digest, this.#clock)\n }\n // An interim report (including a horizon-corrected one) never\n // outranks the attempt's real outcome; only a TERMINAL state —\n // a give-up, a refusal, a delivery — stands (R5-B1). Without\n // this, an accepted deposit would stay reported unreachable and\n // be sent a second time.\n if (sub.st === null || sub.st.state === 'awaiting-transport') sub.st = next\n }\n\n #isDocument (sub: Submission): boolean {\n return sub.entry === undefined || sub.entry.kind === 'document'\n }\n\n /** A verdict on a document answers its open routed deposit\n * (RLTP-VTI-3130), if the send state names it at that moment. A verdict\n * before the acceptance marks the submission, so it is not opened\n * afterwards. Acknowledgements are answered by nothing. */\n #answer (sub: Submission): void {\n if (!this.#isDocument(sub)) return\n sub.answered = true\n if (sub.digest !== undefined) this.#openDeposits.delete(sub.digest)\n }\n\n /** The switch (RLTP-VTI-3130): one way; the open routed deposits leave\n * the send state. */\n #switchToEgress (): void {\n this.#mode = 'egress-session'\n this.#openDeposits.clear()\n }\n\n /** The current sending mode of the relationship (profile §3a). */\n get sendMode (): SendMode { return this.#mode }\n\n /** An answer the holder hands this instance for a document an earlier\n * instance deposited (RLTP-VTI-3130): a valid acknowledgement, a\n * validated receiver refusal or a validated `idConflict` answer for\n * `digest`. If the send state names the document as an open routed\n * deposit, it is answered and leaves; otherwise it answers nothing. A\n * no-op on a retired instance, like acknowledged. */\n answered (digest: string, rawNow: number): void {\n if (this.#closed) return\n this.#now(rawNow)\n this.#openDeposits.delete(digest)\n // a document of this instance whose attempt still runs is answered too:\n // its acceptance after this opens nothing\n for (const sub of this.#subs.values()) if (sub.digest === digest && this.#isDocument(sub)) sub.answered = true\n }\n\n /** Host teardown aid, NOT a port operation (profile §6): awaits\n * the in-flight background tasks so a host can drain before\n * persisting ackState. On a hanging wire it waits as long as the\n * wire does — a host bounds it externally (Promise.race) exactly\n * because this library holds no clock of its own. */\n async settle (): Promise<void> {\n while (this.#inflight.size > 0) await Promise.all([...this.#inflight])\n }\n\n /** The §6.1 report, or null while none exists yet (has()\n * distinguishes an unknown id). status is a PORT: after close it\n * refuses like every other port operation (R5-B3).\n *\n * The pre-transport report is an HONEST SNAPSHOT, derived at the\n * moment of observation by one precedence order (Option B of the\n * round-14 halt) — never a stored patchwork:\n * (a) the wire knows itself offline → offline\n * (b) an attempt is overdue → transport-unreachable\n * (c) the last completed attempt's kind → its report\n * (d) otherwise → no report yet (null)\n * Terminal states and `accepted` are stored and stand. */\n status (id: string): SubmissionState | null {\n this.#open()\n const sub = this.#subs.get(id)\n if (!sub) return null\n if (sub.st !== null && sub.st.state !== 'awaiting-transport') return { ...sub.st }\n if (this.#wire.offline?.() === true) {\n return { state: 'awaiting-transport', reason: 'offline' }\n }\n if (sub.attemptStartedAt !== null &&\n this.#clock - sub.attemptStartedAt >= DECLARED.statusHorizonMs) {\n return { state: 'awaiting-transport', reason: 'transport-unreachable' }\n }\n return sub.st === null ? null : { ...sub.st }\n }\n\n /** A valid acknowledgement for submission `id`. Reports that a\n * collection carries are applied before that collection's conclude,\n * at the latest before the next advance: the switch check of\n * RLTP-VTI-3130 counts on them, and a report applied late can let the\n * relationship switch although its deposits were answered. */\n acknowledged (id: string): void {\n if (this.#closed) return\n const sub = this.#subs.get(id)\n if (!sub) return\n this.#answer(sub)\n if (sub.st?.state === 'delivered') return // idempotent: a duplicate ack never rewrites `late` (R9-M4)\n const late = sub.st?.state === 'failed'\n sub.st = { state: 'delivered', late }\n if (late) this.#transitions.push({ id, to: 'delivered' })\n }\n\n /** Refusals act on live submissions only (§6.1 knows exactly one\n * late correction — the valid ack). The code set is closed and\n * TERMINAL: retryable counterpart conditions (unavailable,\n * internalError) are transport outcomes, never receiver verdicts\n * — they have no entry here, and an unknown code is refused\n * fail-closed rather than minted into a verdict (R6-B2). Applied, like\n * acknowledged, before the conclude of the collection that carried\n * it (RLTP-VTI-3130). */\n receiverRefused (id: string, code: ReceiverRefusalCode): void {\n if (this.#closed) return\n if (!RECEIVER_REFUSAL_CODES.has(code)) {\n throw new Error('not a terminal receiver refusal code — retryable conditions are transport outcomes')\n }\n const sub = this.#subs.get(id)\n if (!sub) return\n this.#answer(sub)\n // A VALIDATED refusal is itself the proof of receipt — the\n // mediator can have accepted and forwarded while our deposit\n // promise is still unresolved, so the report-less phase is a\n // legitimate moment for it (R9-B2, reversing the R8-B3\n // overcorrection). Only terminal states stand against it.\n if (sub.st !== null && sub.st.state !== 'awaiting-transport' && sub.st.state !== 'accepted') return\n sub.st = { state: 'failed', reason: 'rejected-by-receiver', code }\n }\n\n drainTransitions (): Array<{ id: string, to: 'delivered' }> {\n this.#open()\n return this.#transitions.splice(0)\n }\n\n // ── receiver side ───────────────────────────────────────────────\n collect (rawNow: number): Collection {\n this.#open()\n this.#now(rawNow)\n if (this.#inbox.length === 0) return { id: 'c-empty', items: [] }\n const items = this.#inbox.splice(0)\n this.#outstandingBytes += this.#inboxBytes\n this.#inboxBytes = 0\n this.#inboxDigests.clear()\n const id = 'c' + this.#nextColId++\n this.#outstanding.set(id, new Map(items.map((i) => [i.queueId, i])))\n // the caller gets its own copies: the outstanding entries stay intact,\n // whatever it does with the bytes, for a conclusion that keeps them\n return { id, items: items.map((i) => ({ ...i, bytes: new Uint8Array(i.bytes) })) }\n }\n\n /** Concludes a collection (profile §4, Delivery 5a.8): its items'\n * digests become ack intent. `keep` names the items whose disposition\n * is transient (Delivery RLTP-DEL-5810, 5820: `failed(rate-limited)`,\n * or a transaction that could not commit, see `concludable`): they are\n * not concluded and not acknowledged, they go back to the buffer and the\n * next collect offers them again, and the mediator keeps its copy.\n * The reports the collection carries (acknowledged, receiverRefused,\n * answered) are applied BEFORE this call, at the latest before the next\n * advance: a conclusion that leaves nothing pending opens the switch\n * check of RLTP-VTI-3130, which counts them as applied. */\n conclude (collection: { id: string }, rawNow: number, opts: { keep?: readonly string[] } = {}): void {\n this.#open()\n const now = this.#now(rawNow)\n const col = this.#outstanding.get(collection.id)\n if (!col) {\n // an empty collection is concluded too: it may be the one that leaves nothing pending\n if (collection.id === 'c-empty') this.#concludedClean()\n return\n }\n this.#outstanding.delete(collection.id)\n const keep = new Set(opts.keep ?? [])\n for (const item of col.values()) {\n this.#outstandingBytes -= item.bytes.length\n if (keep.has(item.queueId)) {\n // transient: back to the buffer, offered again, never acknowledged\n this.#inbox.push(item)\n this.#inboxBytes += item.bytes.length\n this.#inboxDigests.add(item.queueId)\n continue\n }\n this.#concluded.set(item.queueId, now)\n this.#pendingAcks.add(item.queueId)\n }\n this.#concludedClean()\n this.#startFlush(now)\n }\n\n /** Nothing pending for this connection: the wire says the mediator\n * holds nothing more (queueEmpty; a wire without it never says so),\n * nothing waits in the buffer, no collection is outstanding. */\n #nothingPending (): boolean {\n return this.#wire.queueEmpty?.() === true && this.#inbox.length === 0 && this.#outstanding.size === 0\n }\n\n /** After a conclusion (RLTP-VTI-3130): when it left nothing pending,\n * the switch check may run in a later advance. */\n #concludedClean (): void {\n if (!this.#nothingPending()) return\n this.#cleanConcluded = true\n }\n\n ackState (): AckState {\n return {\n concluded: [...this.#concluded].map(([queueId, concludedAt]) => ({ queueId, concludedAt })),\n pending: [...this.#pendingAcks],\n send: {\n mode: this.#mode,\n open: [...this.#openDeposits].map(([digest, acceptedAt]) => ({ digest, acceptedAt })),\n },\n }\n }\n\n #startFlush (now: number): void {\n if (this.#flushing || this.#pendingAcks.size === 0) return\n this.#flushing = true\n const snapshot = new Set(this.#pendingAcks)\n this.#track(this.#flushAcks(now, [...snapshot]).finally(() => {\n this.#flushing = false\n // lost-wake-up guard (review-4 M6): intents that arrived while\n // this flush ran get their own flush now — but only newcomers,\n // so a failing wire waits for the next advance instead of\n // spinning\n if (!this.#closed) {\n for (const id of this.#pendingAcks) {\n if (!snapshot.has(id)) { this.#startFlush(this.#clock); break }\n }\n }\n }))\n }\n\n async #flushAcks (now: number, ids: string[]): Promise<void> {\n try {\n const token = await this.#ensureAuth(now)\n if (this.#closed) return\n // Only NOW does anything become irrecallable (R16-B1): the\n // stay of expiry begins at the wire call itself, never at the\n // snapshot — a hanging auth extends no window. And \"live\" is\n // WINDOW-live (R17-B1): an entry whose window already closed —\n // even if no prune has swept it yet — is never sent.\n const live = ids.filter((id) => {\n const at = this.#concluded.get(id)\n // a later copy of it that the holder has not concluded yet (in the\n // buffer or outstanding) is not acknowledged before it is handled:\n // hand off → await → ack; the intent stays for the next flush\n if (this.#inboxDigests.has(id) || [...this.#outstanding.values()].some((c) => c.has(id))) return false\n return at !== undefined && this.#clock - at < DECLARED.duplicateWindowMs\n })\n if (live.length === 0) return\n for (const id of live) this.#flightAcks.add(id)\n try {\n // the wire gets its own list: what it does with it never reaches the bookkeeping below\n await this.#wire.ackReceived(token, [...live])\n if (!this.#closed) for (const id of live) this.#pendingAcks.delete(id)\n } finally {\n for (const id of live) this.#flightAcks.delete(id)\n // deferred window sweep: entries whose window closed while\n // the ack flew fall now — intent, entry and absorption\n // together (R15-B1). Never on a retired instance: after\n // close, ackState() is the host's final-persist surface and\n // a late-returning wire mutates nothing (R17-B2).\n if (!this.#closed) {\n for (const id of live) {\n const at = this.#concluded.get(id)\n if (at !== undefined && this.#clock - at >= DECLARED.duplicateWindowMs) {\n this.#concluded.delete(id)\n this.#pendingAcks.delete(id)\n }\n }\n }\n }\n } catch {\n // intent survives; the next advance starts a fresh flush\n }\n }\n\n // ── the adapter clock — never awaits the mediator ───────────────\n advance (rawNow: number): void {\n this.#open()\n const now = this.#now(rawNow)\n // open routed deposits fall routed-ack-deadline plus duplicate-window\n // after their acceptance, also where no switch check can run (no\n // statement that nothing is pending, RLTP-VTI-7150)\n for (const [digest, at] of this.#openDeposits) if (now - at >= OPEN_KEEP_MS) this.#openDeposits.delete(digest)\n // the switch (RLTP-VTI-3130): only after a conclusion that left nothing\n // pending and while nothing is pending again at the check (an\n // acknowledgement that arrived since is collected and reported first),\n // when an open routed deposit is a deadline old — one way; checked\n // before the retries below, which hand over in the new mode\n if (this.#mode === 'routed' && this.#cleanConcluded && this.#nothingPending()) {\n for (const acceptedAt of this.#openDeposits.values()) {\n if (now - acceptedAt >= DECLARED.routedAckDeadlineMs) { this.#switchToEgress(); break }\n }\n }\n for (const sub of this.#subs.values()) {\n const live = sub.st === null || sub.st.state === 'awaiting-transport' || sub.st.state === 'accepted'\n if (!live) continue\n if (now - sub.submittedAt >= DECLARED.giveUpHorizonMs) {\n // unroutable only when the LAST COMPLETED attempt was an\n // admission refusal and no attempt is in flight whose outcome\n // is unknown (review-4 B3)\n // the give-up verdict applies the SAME precedence as every\n // observation (R17-B3): a wire that knows itself offline at\n // the horizon outranks any stored refusal class — unroutable\n // needs a completed admission refusal, no unknown outcome in\n // flight, AND no offline signal standing over it\n sub.st = {\n state: 'failed',\n reason: sub.lastKind === 'refused-admission' && sub.attemptStartedAt === null &&\n this.#wire.offline?.() !== true\n ? 'unroutable'\n : 'expired-by-adapter-policy',\n }\n continue\n }\n if (sub.st !== null && sub.st.state === 'accepted') continue\n // reports are DERIVED at observation (see status()); the clock\n // only decides here whether to start an attempt — and never\n // against a wire that knows itself offline\n if (this.#wire.offline?.() === true) continue\n if (sub.attemptStartedAt === null) this.#startAttempt(sub, now)\n }\n // THE WINDOW BEATS EVERYTHING (Option B of the round-14 halt):\n // an ack intent is retried until the window closes; then intent\n // and absorption fall together. There is no ageless debt whose\n // truth the adapter would have to know — the receiver's §6.2\n // absorption owns everything beyond the window.\n for (const [digest, at] of this.#concluded) {\n if (now - at >= DECLARED.duplicateWindowMs && !this.#flightAcks.has(digest)) {\n this.#concluded.delete(digest)\n this.#pendingAcks.delete(digest)\n }\n }\n this.#startKeylistSync(now)\n this.#startFlush(now)\n }\n\n /** §5a.10 lifecycle boundary: after close, every state port is\n * inert — port operations refuse, inbound reports (acknowledged,\n * receiverRefused) are no-ops, late wire resolutions mutate\n * nothing. Only ackState() stays readable for the host's final\n * persist. */\n close (): void { this.#closed = true }\n\n get closed (): boolean { return this.#closed }\n}\n\nexport const queueIdOf = async (bytes: Uint8Array): Promise<string> => hex(await sha(bytes))\n"]}
@@ -10,12 +10,22 @@ export declare const ENCOUNTER_COMMANDS: Readonly<{
10
10
  capture: "encounter.capture";
11
11
  counter: "encounter.counter";
12
12
  }>;
13
+ /** The carrier offer as the act binds it: the relationship's carrier
14
+ * nonce N (Identity §7a.3) in canonical base64url, and the delivery hints
15
+ * the app built from it (Encounter 6080; their form is the carrier
16
+ * profile's, the library interprets none). */
17
+ export interface CarrierOfferInput {
18
+ nonce: string;
19
+ deliveryHints: string[];
20
+ }
13
21
  export interface ShowInput {
14
22
  name?: string;
23
+ carrier?: CarrierOfferInput;
15
24
  }
16
25
  export interface ScanInput {
17
26
  card: Json;
18
27
  name?: string;
28
+ carrier?: CarrierOfferInput;
19
29
  }
20
30
  export interface CaptureInput {
21
31
  card: Json;
@@ -1 +1 @@
1
- {"version":3,"file":"ceremony.d.ts","sourceRoot":"","sources":["../../src/encounter/ceremony.ts"],"names":[],"mappings":"AAoFA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,YAAY,CAAA;AAGlD,OAAO,EACL,WAAW,EAA+C,aAAa,EAExE,MAAM,iBAAiB,CAAA;AAMxB,OAAO,KAAK,EAAgD,YAAY,EAAmD,MAAM,cAAc,CAAA;AAC/I,OAAO,KAAK,EAAmC,WAAW,EAAE,MAAM,EAAU,MAAM,aAAa,CAAA;AAI/F,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAA;AAErC,2CAA2C;AAC3C,eAAO,MAAM,kBAAkB;;;;;EAK7B,CAAA;AAEF,MAAM,WA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AE,MAAM,EAAE,CAAA;CAAE;AAC7E,MAAM,WAAW,SAAS;IAAG,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAAE;AACzE,MAAM,WAAW,SAAS;IAAG,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAAE;AACrF,MAAM,WAAW,YAAY;IAAG,IAAI,EAAE,IAAI,CAAA;CAAE;AAC5C,MAAM,WAAW,YAAY;IAAG,SAAS,EAAE,MAAM,CAAA;CAAE;AASnD,6EAA6E;AAC7E,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAGvE,CAAA;AAED,qEAAqE;AACrE,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,KAAG,MAA4B,CAAA;AAE1E,yEAAyE;AACzE,wBAAgB,OAAO,CAAE,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAInH;AAwjBD,mDAAmD;AACnD,wBAAgB,eAAe,IAAK,YAAY,CAc/C"}
@@ -12,8 +12,13 @@
12
12
  // into the register before display (4110,
13
13
  // Identity 6.1), the key's lastShown in
14
14
  // `addresses` (Delivery §5), the challenge
15
- // held open; event encounter.shown carries
16
- // the card, the optical payload
15
+ // held open; with a carrier offer the
16
+ // card carries its delivery hints (6080)
17
+ // and its carrier nonce enters the
18
+ // register under the relationship the
19
+ // card opens (Identity §7a.3); event
20
+ // encounter.shown carries the card, the
21
+ // optical payload
17
22
  // encounter.scan the scanner's step (5.8 trunk 2–3):
18
23
  // the displayed card checked, a fresh
19
24
  // label and own challenge c_A, the record
@@ -22,8 +27,10 @@
22
27
  // its prior candidates frozen, its
23
28
  // continuity probe pending, 6820) and the
24
29
  // bundle into the outbox, in one commit;
25
- // event encounter.scanned carries the
26
- // sent card for the optical leg
30
+ // a carrier offer as with show, its hints
31
+ // in the sent card; event
32
+ // encounter.scanned carries the sent card
33
+ // for the optical leg
27
34
  // encounter.capture the optical leg (5.8, 5710): a sent
28
35
  // card presented to the displayer
29
36
  // encounter.counter the counter-step (5.8 step 4)
@@ -76,17 +83,27 @@
76
83
  // needs an active tuple (tuple-deactivated), its document waits for
77
84
  // the bundle's thread where the record arose on the optical leg (5780)
78
85
  // and goes out with the bundle's record-aware effect
86
+ // - the carrier offer {nonce, deliveryHints}: the app draws the carrier
87
+ // nonce N and builds the hints from it (an adapter derives the wire
88
+ // identities from root, carrier and N), so the offer is plain act
89
+ // input, bound and journaled with the act; the library checks 6090 on
90
+ // the hints (card-invalid), N's form and freshness (carrier-nonce-
91
+ // invalid: 32 bytes, held nowhere in the register), and interprets no
92
+ // hint. N enters the register at show already, under the relationship
93
+ // id the card's label opens, as the label and its pair nonce do (4110);
94
+ // a card that ages unscanned leaves it there, like its label (the
95
+ // register only grows)
79
96
  // - encounter.capture of a card already recorded with the same material
80
97
  // is an idempotent success (5430): the act commits its journal entry only
81
98
  // - no automatic optical switch (5690 RECOMMENDS ack-wait as its
82
99
  // trigger): the app shows the sent card (encounter.scanned) when it
83
100
  // sees the bundle undelivered (deliveryStatus)
84
- import { b64uOf, iso, jcs, makeValidator, sameDigest } from '../core.js';
101
+ import { b64uOf, fromB64u, iso, jcs, makeValidator, sameDigest } from '../core.js';
85
102
  import { diSignWith, diVerify, digestBytes, digestDoc } from '../crypto.js';
86
103
  import { seal } from '../delivery.js';
87
104
  import { BUNDLE_TYPE, CEREMONY, CHALLENGE_MAX_AGE, SKEW_TOLERANCE, DELIVERY_TYPE, acceptTail, bundleForm, cardBody, cardOk, challengeAged, challengeOf, credHead, credentialBody, deliveryForm, dispositionOf, futureOk, issuanceEnd, issuanceOpen, windowOk, } from '../encounter.js';
88
105
  import { SCHEMAS } from '../schemas.js';
89
- import { withPairNonce } from '../identity-state.js';
106
+ import { carrierNonceHeld, withCarrierNonce, withPairNonce } from '../identity-state.js';
90
107
  import { tupleByRkid } from '../receive.js';
91
108
  import { openTuple } from '../trust/continuity.js';
92
109
  import { entryOf, findContact, tupleByLabel } from '../trust/state.js';
@@ -165,6 +182,8 @@ function placeOf(state, r) {
165
182
  return { contactId: idsOf(r.label).contactId, relationshipId: r.relId };
166
183
  return { contactId: entryOf(state, at.rel)?.id ?? at.tuple.entryId, relationshipId: at.rel.id };
167
184
  }
185
+ /** The register with the offer's carrier nonce under `relId`, or unchanged without an offer. */
186
+ const carrierOf = (r, relId, carrier) => carrier === undefined ? r : withCarrierNonce(r, relId, carrier.nonce);
168
187
  const sealWith = (ctx, doc, keyAgreement) => seal(doc, keyAgreement, { ephSeed: ctx.entropy.bytes('seal.eph', 32), nonce: ctx.entropy.bytes('seal.nonce', 12) }, ctx.crypto.subtle);
169
188
  const signer = (ctx, label) => (b) => ctx.keys.sign(label, b);
170
189
  /** The display name a card carries: the input's, else the own profile's, at most 200 characters (6090). */
@@ -172,6 +191,29 @@ const nameFor = (state, name) => {
172
191
  const n = typeof name === 'string' ? name : state.profile.body?.name;
173
192
  return typeof n === 'string' && n.length ? [...n].slice(0, 200).join('') : undefined;
174
193
  };
194
+ /** The carrier offer's own checks, before anything is signed: at least
195
+ * one hint, each a string (else card-invalid without a ref: an empty offer
196
+ * announces nothing, a card without hints needs no offer); the bounds of
197
+ * 6090 (at most eight, each at most 512 characters); then N's form (32
198
+ * bytes, canonical base64url). null where there is no offer or it passes. */
199
+ function offerRefusal(carrier) {
200
+ if (carrier === undefined)
201
+ return null;
202
+ const c = carrier;
203
+ const h = c?.deliveryHints;
204
+ // an offer announces its carrier: no hint (a card without hints is a card
205
+ // without an offer, 6080) or a hint that is no string is no offer
206
+ if (!Array.isArray(h) || h.length < 1 || !h.every((x) => typeof x === 'string'))
207
+ return no('card-invalid');
208
+ if (h.length > 8 || !h.every((x) => [...x].length <= 512))
209
+ return no('card-invalid', 'RLTP-ENC-6090');
210
+ const n = c?.nonce;
211
+ if (typeof n !== 'string' || !/^[A-Za-z0-9_-]{43}$/.test(n) || b64uOf(fromB64u(n)) !== n)
212
+ return no('carrier-nonce-invalid');
213
+ return null;
214
+ }
215
+ /** N is fresh (Identity §7a.3): no carrier or pair nonce of the register, and not this act's pair nonce. */
216
+ const nonceStale = (state, carrier, pairNonce) => carrier !== undefined && (carrier.nonce === pairNonce || carrierNonceHeld(state.register, carrier.nonce));
175
217
  /** A fresh pair label from 32 fresh nonce bytes (Identity 6.1, Encounter 4.4). */
176
218
  async function freshLabel(ctx) {
177
219
  const n = ctx.entropy.bytes('founding.nonce', 32);
@@ -180,17 +222,25 @@ async function freshLabel(ctx) {
180
222
  const showDef = {
181
223
  human: true,
182
224
  async prepare(ctx, input) {
225
+ const offer = offerRefusal(input?.carrier);
226
+ if (offer)
227
+ return offer;
183
228
  const { label, nonce } = await freshLabel(ctx);
184
229
  const own = await ctx.keys.anchorOf(label);
185
230
  const value = challengeOf(ctx.entropy.bytes('challenge', 17));
186
231
  const at = iso(ctx.when);
187
232
  const name = nameFor(ctx.snapshot, input?.name);
188
- const body = cardBody(own, { ...(name !== undefined ? { name } : {}), challenge: { value, issuedAt: at } });
233
+ const hints = input?.carrier !== undefined ? { deliveryHints: input.carrier.deliveryHints } : {};
234
+ const body = cardBody(own, { ...(name !== undefined ? { name } : {}), ...hints, challenge: { value, issuedAt: at } });
189
235
  const card = await diSignWith(own.anchor, signer(ctx, label), body, at, ctx.crypto.subtle);
190
236
  return { label, nonce, rkid: own.keyAgreement, value, card };
191
237
  },
192
- apply(state, prepared, _input, when) {
238
+ apply(state, prepared, input, when) {
193
239
  const p = prepared.value;
240
+ if (isRefusal(p))
241
+ return p;
242
+ if (nonceStale(state, input?.carrier, p.nonce))
243
+ return no('carrier-nonce-invalid');
194
244
  // fresh-always (4.4, 4150) and single use (5140): fresh entropy never
195
245
  // repeats; a repeat is a broken entropy source, not a human's refusal
196
246
  if (state.register.labels.includes(p.label) || tupleByLabel(state, p.label))
@@ -200,8 +250,9 @@ const showDef = {
200
250
  return {
201
251
  state: {
202
252
  ...state,
203
- // 4110: the label in the register before the card is displayed
204
- register: withPairNonce(state.register, p.label, p.nonce),
253
+ // 4110: the label in the register before the card is displayed;
254
+ // the carrier nonce beside it, under the relationship the card opens
255
+ register: carrierOf(withPairNonce(state.register, p.label, p.nonce), idsOf(p.label).relId, input?.carrier),
205
256
  addresses: { ...state.addresses, keys: { ...state.addresses.keys, [p.rkid]: { label: p.label, lastShown: when } } },
206
257
  encounter: { ...state.encounter, challenges: { ...state.encounter.challenges, [p.value]: { value: p.value, tCh: when, label: p.label, card: p.card } } },
207
258
  },
@@ -218,6 +269,9 @@ const scanDef = {
218
269
  // a displayed card carries neither sentTo nor boundTo (6070)
219
270
  if (peer.sentTo !== undefined || peer.boundTo !== undefined)
220
271
  return no('card-invalid', 'RLTP-ENC-6070');
272
+ const offer = offerRefusal(input?.carrier);
273
+ if (offer)
274
+ return offer;
221
275
  const S = ctx.crypto.subtle;
222
276
  const { label, nonce } = await freshLabel(ctx);
223
277
  const me = await ctx.keys.anchorOf(label);
@@ -232,7 +286,8 @@ const scanDef = {
232
286
  const sign = signer(ctx, label);
233
287
  const credential = await diSignWith(me.anchor, sign, credentialBody(me.anchor, peer.anchor, CEREMONY, peer.challenge.value, bind, at), at, S);
234
288
  const name = nameFor(ctx.snapshot, input?.name);
235
- const sent = cardBody(me, { ...(name !== undefined ? { name } : {}), challenge: { value: own, issuedAt: at }, sentTo: peer.anchor, boundTo: peer.challenge.value });
289
+ const hints = input?.carrier !== undefined ? { deliveryHints: input.carrier.deliveryHints } : {};
290
+ const sent = cardBody(me, { ...(name !== undefined ? { name } : {}), ...hints, challenge: { value: own, issuedAt: at }, sentTo: peer.anchor, boundTo: peer.challenge.value });
236
291
  const sentCard = await diSignWith(me.anchor, sign, sent, at, S);
237
292
  const threadId = ctx.entropy.id('thread.id');
238
293
  const doc = { id: ctx.entropy.id('doc.id'), type: BUNDLE_TYPE, issuer: me.anchor, recipient: peer.anchor, threadId, issuedAt: at, payload: { card: sentCard, credential } };
@@ -241,10 +296,12 @@ const scanDef = {
241
296
  doc: { digest: await digestDoc(doc, S), envelope: await sealWith(ctx, doc, peer.keyAgreement) },
242
297
  };
243
298
  },
244
- apply(state, prepared, _input, when) {
299
+ apply(state, prepared, input, when) {
245
300
  const p = prepared.value;
246
301
  if (isRefusal(p))
247
302
  return p;
303
+ if (nonceStale(state, input?.carrier, p.nonce))
304
+ return no('carrier-nonce-invalid');
248
305
  const peerValue = p.peer.challenge.value;
249
306
  // 5.3 single use from the scanner's side: a displayed value already in
250
307
  // one of the own records never enters a second enactment (5170)
@@ -270,7 +327,7 @@ const scanDef = {
270
327
  thread: p.threadId, bundleDigest: p.doc.digest, threads: {}, sentCard: p.sentCard, counterPending: false,
271
328
  };
272
329
  return {
273
- state: withRecord(opened.state, record),
330
+ state: withRecord({ ...opened.state, register: carrierOf(opened.state.register, ids.relId, input?.carrier) }, record),
274
331
  outbound: [{
275
332
  digest: p.doc.digest, envelope: p.doc.envelope, type: BUNDLE_TYPE, threadId: p.threadId,
276
333
  recipient: { contactId: ids.contactId, rkid: p.rkid, keyAgreement: p.peer.keyAgreement },