@serfab/cadre-core 0.8.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/bootstrap-peer-store-file.d.ts +13 -0
- package/dist/bootstrap-peer-store-file.js +42 -0
- package/dist/bootstrap-peer-store-file.js.map +1 -0
- package/dist/bootstrap-peer-store.d.ts +73 -0
- package/dist/bootstrap-peer-store.js +128 -0
- package/dist/bootstrap-peer-store.js.map +1 -0
- package/dist/cadre-node.d.ts +1006 -101
- package/dist/cadre-node.js +1977 -283
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-authorization.d.ts +93 -0
- package/dist/control-authorization.js +57 -0
- package/dist/control-authorization.js.map +1 -0
- package/dist/control-cohort.d.ts +15 -15
- package/dist/control-cohort.js +14 -14
- package/dist/control-cohort.js.map +1 -1
- package/dist/control-database.d.ts +1033 -76
- package/dist/control-database.js +1520 -153
- package/dist/control-database.js.map +1 -1
- package/dist/control-formation-recorder.d.ts +91 -12
- package/dist/control-formation-recorder.js +131 -16
- package/dist/control-formation-recorder.js.map +1 -1
- package/dist/control-schema.d.ts +1 -1
- package/dist/control-schema.js +774 -186
- package/dist/control-schema.js.map +1 -1
- package/dist/control-stream.d.ts +38 -4
- package/dist/control-stream.js +70 -4
- package/dist/control-stream.js.map +1 -1
- package/dist/control-write-retry.d.ts +151 -0
- package/dist/control-write-retry.js +411 -0
- package/dist/control-write-retry.js.map +1 -0
- package/dist/delegate-admission.d.ts +134 -0
- package/dist/delegate-admission.js +244 -0
- package/dist/delegate-admission.js.map +1 -0
- package/dist/device-token.d.ts +12 -12
- package/dist/device-token.js +15 -14
- package/dist/device-token.js.map +1 -1
- package/dist/ed25519-key.d.ts +68 -0
- package/dist/ed25519-key.js +106 -0
- package/dist/ed25519-key.js.map +1 -0
- package/dist/file-durable-slot.d.ts +20 -0
- package/dist/file-durable-slot.js +53 -0
- package/dist/file-durable-slot.js.map +1 -0
- package/dist/formation-approval.d.ts +157 -0
- package/dist/formation-approval.js +375 -0
- package/dist/formation-approval.js.map +1 -0
- package/dist/fs-atomic.d.ts +38 -0
- package/dist/fs-atomic.js +97 -0
- package/dist/fs-atomic.js.map +1 -0
- package/dist/identity-key.d.ts +49 -0
- package/dist/identity-key.js +81 -0
- package/dist/identity-key.js.map +1 -0
- package/dist/index.d.ts +16 -6
- package/dist/index.js +44 -10
- package/dist/index.js.map +1 -1
- package/dist/key-store-file.d.ts +2 -24
- package/dist/key-store-file.js +10 -77
- package/dist/key-store-file.js.map +1 -1
- package/dist/key-store.d.ts +1 -1
- package/dist/key-store.js +1 -1
- package/dist/membership-connection-gater.d.ts +146 -0
- package/dist/membership-connection-gater.js +180 -0
- package/dist/membership-connection-gater.js.map +1 -0
- package/dist/node-local-snapshot.d.ts +109 -0
- package/dist/node-local-snapshot.js +182 -0
- package/dist/node-local-snapshot.js.map +1 -0
- package/dist/peer-authorization.d.ts +150 -11
- package/dist/peer-authorization.js +170 -13
- package/dist/peer-authorization.js.map +1 -1
- package/dist/peer-record.d.ts +24 -11
- package/dist/peer-record.js +29 -13
- package/dist/peer-record.js.map +1 -1
- package/dist/push-node.d.ts +38 -0
- package/dist/push-node.js +48 -0
- package/dist/push-node.js.map +1 -0
- package/dist/push-notifier-apns.d.ts +10 -2
- package/dist/push-notifier-apns.js +14 -10
- package/dist/push-notifier-apns.js.map +1 -1
- package/dist/push-notifier-fcm.d.ts +7 -1
- package/dist/push-notifier-fcm.js +9 -10
- package/dist/push-notifier-fcm.js.map +1 -1
- package/dist/push-notifier.d.ts +16 -35
- package/dist/push-notifier.js +16 -44
- package/dist/push-notifier.js.map +1 -1
- package/dist/relay-addrs.d.ts +45 -0
- package/dist/relay-addrs.js +103 -0
- package/dist/relay-addrs.js.map +1 -0
- package/dist/relay-reservation.d.ts +266 -0
- package/dist/relay-reservation.js +613 -0
- package/dist/relay-reservation.js.map +1 -0
- package/dist/seed-bootstrap.d.ts +263 -79
- package/dist/seed-bootstrap.js +413 -211
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/seed-trust-policy.d.ts +50 -24
- package/dist/seed-trust-policy.js +28 -19
- package/dist/seed-trust-policy.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +42 -13
- package/dist/strand-addr-protocol.js +58 -52
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-backfill.d.ts +109 -0
- package/dist/strand-backfill.js +279 -0
- package/dist/strand-backfill.js.map +1 -0
- package/dist/strand-database.d.ts +5 -5
- package/dist/strand-database.js +4 -4
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-formation-manager.d.ts +38 -9
- package/dist/strand-formation-manager.js +120 -17
- package/dist/strand-formation-manager.js.map +1 -1
- package/dist/strand-formation-protocol.d.ts +104 -5
- package/dist/strand-formation-protocol.js +233 -5
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +40 -2
- package/dist/strand-instance-manager.js +93 -15
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-member-key.d.ts +6 -6
- package/dist/strand-member-key.js +6 -6
- package/dist/strand-member-key.js.map +1 -1
- package/dist/strand-member-registry.d.ts +12 -12
- package/dist/strand-member-registry.js +22 -14
- package/dist/strand-member-registry.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +532 -138
- package/dist/strand-membership-writer.js +800 -179
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-solicitation.d.ts +99 -33
- package/dist/strand-solicitation.js +100 -52
- package/dist/strand-solicitation.js.map +1 -1
- package/dist/strand-transport-key.d.ts +40 -0
- package/dist/strand-transport-key.js +56 -0
- package/dist/strand-transport-key.js.map +1 -0
- package/dist/strand-wake-protocol.d.ts +9 -7
- package/dist/strand-wake-protocol.js +22 -46
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/strand-watcher.d.ts +17 -2
- package/dist/strand-watcher.js +47 -3
- package/dist/strand-watcher.js.map +1 -1
- package/dist/trusted-owner-store-file.d.ts +12 -0
- package/dist/trusted-owner-store-file.js +39 -0
- package/dist/trusted-owner-store-file.js.map +1 -0
- package/dist/trusted-owner-store.d.ts +64 -0
- package/dist/trusted-owner-store.js +126 -0
- package/dist/trusted-owner-store.js.map +1 -0
- package/dist/types.d.ts +325 -50
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -1
- package/package.json +23 -8
- package/src/bootstrap-peer-store-file.ts +44 -0
- package/src/bootstrap-peer-store.ts +172 -0
- package/src/cadre-node.ts +2129 -295
- package/src/control-authorization.ts +114 -0
- package/src/control-cohort.ts +17 -17
- package/src/control-database.ts +1766 -191
- package/src/control-formation-recorder.ts +174 -21
- package/src/control-schema.ts +786 -198
- package/src/control-stream.ts +81 -4
- package/src/control-write-retry.ts +473 -0
- package/src/delegate-admission.ts +302 -0
- package/src/device-token.ts +19 -14
- package/src/ed25519-key.ts +134 -0
- package/src/file-durable-slot.ts +61 -0
- package/src/formation-approval.ts +604 -0
- package/src/fs-atomic.ts +107 -0
- package/src/identity-key.ts +109 -0
- package/src/index.ts +157 -24
- package/src/key-store-file.ts +10 -81
- package/src/key-store.ts +1 -1
- package/src/membership-connection-gater.ts +204 -0
- package/src/node-local-snapshot.ts +260 -0
- package/src/peer-authorization.ts +219 -13
- package/src/peer-record.ts +31 -13
- package/src/push-node.ts +64 -0
- package/src/push-notifier-apns.ts +16 -12
- package/src/push-notifier-fcm.ts +9 -10
- package/src/push-notifier.ts +16 -57
- package/src/relay-addrs.ts +111 -0
- package/src/relay-reservation.ts +823 -0
- package/src/seed-bootstrap.ts +490 -226
- package/src/seed-trust-policy.ts +65 -32
- package/src/strand-addr-protocol.ts +84 -53
- package/src/strand-backfill.ts +366 -0
- package/src/strand-database.ts +6 -6
- package/src/strand-formation-manager.ts +145 -19
- package/src/strand-formation-protocol.ts +310 -9
- package/src/strand-instance-manager.ts +113 -16
- package/src/strand-member-key.ts +7 -7
- package/src/strand-member-registry.ts +28 -23
- package/src/strand-membership-writer.ts +1430 -640
- package/src/strand-solicitation.ts +155 -90
- package/src/strand-transport-key.ts +58 -0
- package/src/strand-wake-protocol.ts +29 -46
- package/src/strand-watcher.ts +66 -3
- package/src/trusted-owner-store-file.ts +41 -0
- package/src/trusted-owner-store.ts +171 -0
- package/src/types.ts +342 -51
- package/dist/authority-key.d.ts +0 -41
- package/dist/authority-key.js +0 -52
- package/dist/authority-key.js.map +0 -1
- package/src/authority-key.ts +0 -68
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays';
|
|
2
3
|
import type { Libp2p } from '@libp2p/interface';
|
|
3
4
|
import type {
|
|
4
5
|
OpenInvitation,
|
|
5
6
|
FormStrandResult,
|
|
6
7
|
StrandFormationDisclosure
|
|
7
8
|
} from './types.js';
|
|
9
|
+
import {
|
|
10
|
+
FormationApprovalError,
|
|
11
|
+
type FormationApprovalFailure
|
|
12
|
+
} from './formation-approval.js';
|
|
13
|
+
// control-database does not import this manager, so this import introduces no cycle.
|
|
14
|
+
import { FormationAbortedError, InvitationExhaustedError } from './control-database.js';
|
|
15
|
+
import { canonicalJson } from './canonical-json.js';
|
|
8
16
|
import type {
|
|
9
17
|
DisclosureValidator,
|
|
10
18
|
FormationUsageRecorder,
|
|
@@ -14,6 +22,8 @@ import type {
|
|
|
14
22
|
} from './strand-solicitation.js';
|
|
15
23
|
import {
|
|
16
24
|
FormationListener,
|
|
25
|
+
INVALID_TOKEN_REASON,
|
|
26
|
+
PROVISION_RESPONSE_TRAVEL_MARGIN_MS,
|
|
17
27
|
dialFormation,
|
|
18
28
|
isValidResponderCreatesResult,
|
|
19
29
|
type FormationContactMessage,
|
|
@@ -24,6 +34,28 @@ import {
|
|
|
24
34
|
|
|
25
35
|
const log = debug('sereus:cadre:formation-manager');
|
|
26
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Largest serialized disclosure a responder will accept (8 KiB). The disclosure is
|
|
39
|
+
* attacker-influenced text destined for a replicated table (`FormationUsage.Disclosure`)
|
|
40
|
+
* and for the approval hook's signed digest — the cap bounds both, and is enforced BEFORE
|
|
41
|
+
* any database read or hook contact so an oversized blob costs nothing downstream.
|
|
42
|
+
*/
|
|
43
|
+
const MAX_DISCLOSURE_BYTES = 8 * 1024;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Rejection reason a would-be joiner is told for each approval-failure category
|
|
47
|
+
* (see {@link FormationApprovalFailure}). Distinct per category on purpose: mapping any
|
|
48
|
+
* of these onto the generic 'Formation conflict, retry' would tell an operator to retry
|
|
49
|
+
* what retrying can never fix (e.g. a non-enrolled validation key).
|
|
50
|
+
*/
|
|
51
|
+
const APPROVAL_REJECTION_REASONS: Record<FormationApprovalFailure, string> = {
|
|
52
|
+
refused: 'Formation approval refused',
|
|
53
|
+
unavailable: 'Formation approval unavailable, retry',
|
|
54
|
+
malformed: 'Formation approval invalid',
|
|
55
|
+
unenrolled: 'Formation approval key is not enrolled',
|
|
56
|
+
misconfigured: 'Formation approval misconfigured'
|
|
57
|
+
};
|
|
58
|
+
|
|
27
59
|
/**
|
|
28
60
|
* Configuration for StrandFormationManager
|
|
29
61
|
*/
|
|
@@ -32,6 +64,14 @@ export interface StrandFormationManagerConfig {
|
|
|
32
64
|
sessionTimeoutMs?: number;
|
|
33
65
|
/** Step timeout in milliseconds */
|
|
34
66
|
stepTimeoutMs?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Provisioning budget in milliseconds for the RESPONDER's `provisionStrand` hook call.
|
|
69
|
+
* The initiator's `await-response` wait is derived automatically from this value plus
|
|
70
|
+
* `PROVISION_RESPONSE_TRAVEL_MARGIN_MS` (`strand-formation-protocol.ts`) — never set
|
|
71
|
+
* directly — so the ordering documented there (approval hook < responder provisioning <
|
|
72
|
+
* initiator await-response < session) cannot collapse when this is configured.
|
|
73
|
+
*/
|
|
74
|
+
provisionTimeoutMs?: number;
|
|
35
75
|
/** Maximum concurrent sessions */
|
|
36
76
|
maxConcurrentSessions?: number;
|
|
37
77
|
/** Enable debug logging */
|
|
@@ -97,11 +137,12 @@ export class StrandFormationManager {
|
|
|
97
137
|
this.listener = new FormationListener({
|
|
98
138
|
validateToken: (token) => this.validateToken(token),
|
|
99
139
|
validateDisclosure: (token, disclosure) => this.validateDisclosure(token, disclosure),
|
|
100
|
-
provisionStrand: (
|
|
101
|
-
this.provisionAsResponder(
|
|
140
|
+
provisionStrand: (contact, signal) =>
|
|
141
|
+
this.provisionAsResponder(contact, signal),
|
|
102
142
|
getResponderIdentity: () => ({ partyId: this.partyId, cadrePeerAddrs: this.cadrePeerAddrs }),
|
|
103
143
|
sessionTimeoutMs: this.config.sessionTimeoutMs,
|
|
104
144
|
stepTimeoutMs: this.config.stepTimeoutMs,
|
|
145
|
+
provisionTimeoutMs: this.config.provisionTimeoutMs,
|
|
105
146
|
maxConcurrentSessions: this.config.maxConcurrentSessions
|
|
106
147
|
});
|
|
107
148
|
|
|
@@ -138,12 +179,15 @@ export class StrandFormationManager {
|
|
|
138
179
|
* Form a strand with a responder via an open invitation (initiator side).
|
|
139
180
|
*
|
|
140
181
|
* Builds a contact message carrying the real token + disclosure + this party's
|
|
141
|
-
* real cadre addresses
|
|
142
|
-
*
|
|
182
|
+
* real cadre addresses + the joiner's consent (minted and signed by the
|
|
183
|
+
* solicitation layer — this manager only places it on the contact), dials the
|
|
184
|
+
* responder over the native protocol, and validates the responder's result
|
|
185
|
+
* before returning.
|
|
143
186
|
*/
|
|
144
187
|
async formStrand(
|
|
145
188
|
invitation: OpenInvitation,
|
|
146
189
|
disclosure: StrandFormationDisclosure,
|
|
190
|
+
consent: { peerKey: string; usageStampId: string; peerSignature: string },
|
|
147
191
|
node: Libp2p
|
|
148
192
|
): Promise<FormStrandResult> {
|
|
149
193
|
log('Forming strand with invitation token: %s', invitation.token);
|
|
@@ -151,6 +195,9 @@ export class StrandFormationManager {
|
|
|
151
195
|
const contact: FormationContactMessage = {
|
|
152
196
|
token: invitation.token,
|
|
153
197
|
partyId: disclosure.partyId ?? this.partyId,
|
|
198
|
+
peerKey: consent.peerKey,
|
|
199
|
+
usageStampId: consent.usageStampId,
|
|
200
|
+
peerSignature: consent.peerSignature,
|
|
154
201
|
disclosure,
|
|
155
202
|
cadrePeerAddrs: this.cadrePeerAddrs
|
|
156
203
|
};
|
|
@@ -163,6 +210,7 @@ export class StrandFormationManager {
|
|
|
163
210
|
validateResponse: (response) => this.validateResponse(invitation, disclosure, response),
|
|
164
211
|
sessionTimeoutMs: this.config.sessionTimeoutMs,
|
|
165
212
|
stepTimeoutMs: this.config.stepTimeoutMs,
|
|
213
|
+
provisionTimeoutMs: this.initiatorProvisionTimeoutMs(),
|
|
166
214
|
protocolId: this.config.protocolId
|
|
167
215
|
});
|
|
168
216
|
|
|
@@ -189,6 +237,20 @@ export class StrandFormationManager {
|
|
|
189
237
|
return { listeners: this.listener.activeCount, dialers: this.dialerSessions };
|
|
190
238
|
}
|
|
191
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Derive the initiator's await-response budget from the configured RESPONDER budget —
|
|
242
|
+
* never the same number (see `StrandFormationManagerConfig.provisionTimeoutMs`). Mirrors
|
|
243
|
+
* `resolveProvisionTimeoutMs`'s own "`0`/negative means unset" rule so an unset config
|
|
244
|
+
* still lets both sides fall back to their own independent defaults; must NOT hardcode
|
|
245
|
+
* `DEFAULT_PROVISION_TIMEOUT_MS` here, or the per-role clamping downstream is defeated.
|
|
246
|
+
* A value too large for the session is clamped per role, and the responder's ceiling holds
|
|
247
|
+
* the same margin back, so the ordering survives there too.
|
|
248
|
+
*/
|
|
249
|
+
private initiatorProvisionTimeoutMs(): number | undefined {
|
|
250
|
+
const host = this.config.provisionTimeoutMs;
|
|
251
|
+
return host && host > 0 ? host + PROVISION_RESPONSE_TRAVEL_MARGIN_MS : undefined;
|
|
252
|
+
}
|
|
253
|
+
|
|
192
254
|
// ── Responder-side hooks ─────────────────────────────────────────────────────
|
|
193
255
|
|
|
194
256
|
private async validateToken(token: string): Promise<{ valid: boolean }> {
|
|
@@ -234,18 +296,33 @@ export class StrandFormationManager {
|
|
|
234
296
|
* deferred `StrandExists` CHECK at commit and drop the frame.
|
|
235
297
|
* - **unbound** (no binding): the responder-provisions fallback — see {@link provisionUnbound}.
|
|
236
298
|
*
|
|
237
|
-
* Defense-in-depth: known provisioning/redeem failures
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* not
|
|
299
|
+
* Defense-in-depth: known provisioning/redeem failures are caught and mapped to a logged
|
|
300
|
+
* protocol rejection rather than a thrown insert + a silently-closed stream. The mapping is
|
|
301
|
+
* per-failure, NOT blanket retry-suggesting: an exhausted invitation
|
|
302
|
+
* ({@link InvitationExhaustedError}, raised by `ControlDatabase` whenever a redemption's use
|
|
303
|
+
* number is past the invite's seat budget — including a first attempt racing another
|
|
304
|
+
* redemption of the same token on this node, not only a retry) is reported as `'Invalid
|
|
305
|
+
* token'`, because retrying it can never succeed. The
|
|
306
|
+
* `(Token, UseNumber)` PK collision that concurrent redemptions of one invite used to
|
|
307
|
+
* surface here is now retried a layer down and no longer reaches this method. The
|
|
308
|
+
* LOG-before-reject keeps this a deliberate internal-error→protocol-rejection conversion
|
|
309
|
+
* (AGENTS.md: don't eat exceptions silently), not control-flow-by-exception.
|
|
243
310
|
*/
|
|
244
311
|
private async provisionAsResponder(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
_disclosure: StrandFormationDisclosure
|
|
312
|
+
contact: FormationContactMessage,
|
|
313
|
+
signal?: AbortSignal
|
|
248
314
|
): Promise<ResponderProvisionOutcome> {
|
|
315
|
+
const token = contact.token;
|
|
316
|
+
// CANONICALLY serialized — both sides derive the identical string: this is the exact
|
|
317
|
+
// text the joiner signed (consent), the approver signs (vouch), and the recorder writes
|
|
318
|
+
// to `FormationUsage.Disclosure` — a re-serialization anywhere below would break the
|
|
319
|
+
// signature-over-stored-bytes invariant.
|
|
320
|
+
const disclosureText = canonicalJson(contact.disclosure);
|
|
321
|
+
if (uint8ArrayFromString(disclosureText, 'utf8').byteLength > MAX_DISCLOSURE_BYTES) {
|
|
322
|
+
log('Disclosure over %d bytes; rejecting token %s', MAX_DISCLOSURE_BYTES, token);
|
|
323
|
+
return { approved: false, reason: 'Disclosure too large' };
|
|
324
|
+
}
|
|
325
|
+
|
|
249
326
|
const recorder = this.formationUsageRecorder;
|
|
250
327
|
const resolved: ResolvedHostStrand = recorder?.resolveStrand
|
|
251
328
|
? await recorder.resolveStrand(token)
|
|
@@ -255,7 +332,15 @@ export class StrandFormationManager {
|
|
|
255
332
|
switch (resolved.kind) {
|
|
256
333
|
case 'bound': {
|
|
257
334
|
// recorder is guaranteed non-null here: only resolveStrand can yield 'bound'.
|
|
258
|
-
await recorder!.recordUsage(
|
|
335
|
+
await recorder!.recordUsage({
|
|
336
|
+
token,
|
|
337
|
+
peerKey: contact.peerKey,
|
|
338
|
+
peerSignature: contact.peerSignature,
|
|
339
|
+
usageStampId: contact.usageStampId,
|
|
340
|
+
strandId: resolved.strandId,
|
|
341
|
+
disclosure: disclosureText,
|
|
342
|
+
signal
|
|
343
|
+
});
|
|
259
344
|
return this.approve({
|
|
260
345
|
strand: { strandId: resolved.strandId, createdBy: 'responder' },
|
|
261
346
|
memberPrivateKey: resolved.memberPrivateKey ?? undefined,
|
|
@@ -267,9 +352,40 @@ export class StrandFormationManager {
|
|
|
267
352
|
return { approved: false, reason: 'Host strand not yet available on this responder' };
|
|
268
353
|
}
|
|
269
354
|
case 'unbound':
|
|
270
|
-
return await this.provisionUnbound(
|
|
355
|
+
return await this.provisionUnbound(contact, disclosureText, signal);
|
|
271
356
|
}
|
|
272
357
|
} catch (err) {
|
|
358
|
+
if (err instanceof FormationAbortedError) {
|
|
359
|
+
// The listener's timeout path owns the reply for an abandoned provisioning; mapping
|
|
360
|
+
// this onto 'Formation conflict, retry' would misreport it as a conflict.
|
|
361
|
+
throw err;
|
|
362
|
+
}
|
|
363
|
+
if (err instanceof FormationApprovalError) {
|
|
364
|
+
log('approval failed (%s) for token %s: %o', err.failure, token, err);
|
|
365
|
+
return { approved: false, reason: APPROVAL_REJECTION_REASONS[err.failure] };
|
|
366
|
+
}
|
|
367
|
+
if (err instanceof InvitationExhaustedError) {
|
|
368
|
+
// Shares `INVALID_TOKEN_REASON` with the up-front `validateToken` rejection so the loser
|
|
369
|
+
// of the race that exposed the spent invite — same-node, first attempt, or a retry that
|
|
370
|
+
// ran out — sees exactly what a non-racing latecomer sees. No wire-visible distinction between "invalid" and "exhausted" — the
|
|
371
|
+
// operator signal lives in this log line instead.
|
|
372
|
+
// NOTE: if a joining client ever has to tell "never valid" from "used up" WITHOUT node
|
|
373
|
+
// logs, that is a new protocol reason string, not a local change here.
|
|
374
|
+
log(
|
|
375
|
+
'invitation exhausted for token %s: use #%d past limit of %d',
|
|
376
|
+
err.token,
|
|
377
|
+
err.useNumber,
|
|
378
|
+
err.totalUses
|
|
379
|
+
);
|
|
380
|
+
return { approved: false, reason: INVALID_TOKEN_REASON };
|
|
381
|
+
}
|
|
382
|
+
// An approval obtained before landing here is RETRIED, not discarded: the database
|
|
383
|
+
// layer re-presents the same approver sign-off under a fresh use number when it loses
|
|
384
|
+
// one to a writer its local write queue does not serialize — another node of the cadre,
|
|
385
|
+
// another `Database` handle over the same store (see
|
|
386
|
+
// `ControlDatabase.withUseNumberRetry`). Reaching this catch-all means either that retry
|
|
387
|
+
// ran out (surfaced above as `InvitationExhaustedError`) or the failure was never
|
|
388
|
+
// retryable to begin with.
|
|
273
389
|
log('provisionAsResponder failed for token %s: %o', token, err);
|
|
274
390
|
return { approved: false, reason: 'Formation conflict, retry' };
|
|
275
391
|
}
|
|
@@ -297,13 +413,23 @@ export class StrandFormationManager {
|
|
|
297
413
|
* at all?" question lives in backlog `formation-initiatorcreates-cover-or-remove`.
|
|
298
414
|
*/
|
|
299
415
|
private async provisionUnbound(
|
|
300
|
-
|
|
301
|
-
|
|
416
|
+
contact: FormationContactMessage,
|
|
417
|
+
disclosureText: string,
|
|
418
|
+
signal?: AbortSignal
|
|
302
419
|
): Promise<ResponderProvisionOutcome> {
|
|
420
|
+
const token = contact.token;
|
|
303
421
|
const recorder = this.formationUsageRecorder;
|
|
304
422
|
if (recorder?.provisionAndRecord) {
|
|
305
423
|
const sAppId = await this.resolveInviteSAppId(token);
|
|
306
|
-
const provisioned = await recorder.provisionAndRecord(
|
|
424
|
+
const provisioned = await recorder.provisionAndRecord({
|
|
425
|
+
token,
|
|
426
|
+
peerKey: contact.peerKey,
|
|
427
|
+
peerSignature: contact.peerSignature,
|
|
428
|
+
usageStampId: contact.usageStampId,
|
|
429
|
+
sAppId,
|
|
430
|
+
disclosure: disclosureText,
|
|
431
|
+
signal
|
|
432
|
+
});
|
|
307
433
|
return this.approve({
|
|
308
434
|
strand: { strandId: provisioned.strandId, createdBy: 'responder' },
|
|
309
435
|
memberPrivateKey: provisioned.memberPrivateKey ?? undefined,
|
|
@@ -313,7 +439,7 @@ export class StrandFormationManager {
|
|
|
313
439
|
|
|
314
440
|
if (this.strandProvisioner) {
|
|
315
441
|
const sAppId = await this.resolveInviteSAppId(token);
|
|
316
|
-
const result = await this.strandProvisioner.provisionStrand(sAppId,
|
|
442
|
+
const result = await this.strandProvisioner.provisionStrand(sAppId, contact.partyId, this.partyId);
|
|
317
443
|
return this.approve({
|
|
318
444
|
strand: { strandId: result.strandId, createdBy: 'responder' },
|
|
319
445
|
dbConnectionInfo: { endpoint: 'local', credentialsRef: '' }
|