@dharma-ai-labs/agent-fabric-relay-client 0.2.27 → 0.2.29

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupClaim.js","sourceRoot":"","sources":["../src/setupClaim.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACpH,OAAO,EACL,wBAAwB,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,YAAY,EAC1F,gCAAgC,EAAE,+BAA+B,GAElE,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAA0B,MAAM,2CAA2C,CAAC;AAC5G,OAAO,EACL,0BAA0B,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAC/E,0BAA0B,EAAE,wBAAwB,GAErD,MAAM,YAAY,CAAC;AAEpB,MAAM,IAAI,GAAG,4CAA4C,CAAC;AAC1D,MAAM,MAAM,GAAG,CAAC,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa;IAClG,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAClF,MAAM,IAAI,GAAG,GAAU,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,MAAM,IAAI,GAAG,2EAA2E,CAAC;AAWzF;6EAC6E;AAC7E,MAAM,UAAU,4BAA4B,CAAC,MACe,EAAE,qBAA6B;IACzF,IAAI,MAAM,CAAC,+BAA+B,KAAK,qBAAqB;QAAE,OAAO,EAAE,CAAC;IAChF,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,mBA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AE,CAAC,CAAC;YACvD,CAAC,CAAC;YACF,MAAM,YAAY,EAAE,CAAC;YACrB,MAAM,wBAAwB,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,CAAC,cAAc;gBAC1E,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,CAAC,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;YACvF,MAAM,YAAY,EAAE,CAAC;YACrB,MAAM,0BAA0B,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;YACpD,MAAM,YAAY,EAAE,CAAC;YACrB,MAAM,gBAAgB,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACjD,MAAM,YAAY,EAAE,CAAC;YACrB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,IAAI,EAAE,CAAC;IAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=setupClaim.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupClaim.test.d.ts","sourceRoot":"","sources":["../src/setupClaim.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,564 @@
1
+ import assert from 'node:assert/strict';
2
+ import { createHash, createPublicKey, generateKeyPairSync, verify } from 'node:crypto';
3
+ import { mkdtemp, readFile, rm } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { resolve } from 'node:path';
6
+ import test from 'node:test';
7
+ import { claimSetupReference, parseSetupClaimRecipientApproval, setupClaimSourceRegistration } from './setupClaim.js';
8
+ import { loadOrganizationApiToken } from './index.js';
9
+ import { sealSetupClaimCredential, signCanonicalObject, setupClaimSigningPayload, validateContract } from '@dharma-ai-labs/agent-fabric-contracts';
10
+ const scope = {
11
+ hqUrl: 'https://hq.example', organizationId: 'org_demo',
12
+ setupReference: '11111111-1111-4111-8111-111111111111',
13
+ recipientMembershipId: '22222222-2222-4222-8222-222222222222',
14
+ repositoryFingerprint: `sha256:${'a'.repeat(64)}`, scopeDigest: `sha256:${'b'.repeat(64)}`,
15
+ contractDigest: `sha256:${'c'.repeat(64)}`, policyRevision: 'policy-v1',
16
+ name: 'Synthetic client', platform: 'linux', configPath: 'unused-device.json',
17
+ };
18
+ function store() {
19
+ const values = new Map();
20
+ return { backend: 'linux-secret-service', get: async (k) => values.get(k) ?? null,
21
+ put: async (k, v) => { values.set(k, v); }, delete: async (k) => { values.delete(k); } };
22
+ }
23
+ test('locked protected store fails before any HTTP operation and sanitizes vendor errors', async () => {
24
+ let requests = 0;
25
+ const locked = store();
26
+ locked.get = async () => { throw new Error('secret-canary'); };
27
+ await assert.rejects(claimSetupReference({ ...scope, store: locked,
28
+ fetcher: async () => { requests++; throw new Error('network'); } }), /^Error: setup_claim_failed$/);
29
+ assert.equal(requests, 0);
30
+ });
31
+ test('protected store write denial fails before challenge, including readable existing stores', async () => {
32
+ let requests = 0;
33
+ const locked = store();
34
+ locked.put = async () => { throw new Error('secret-canary'); };
35
+ await assert.rejects(claimSetupReference({ ...scope, store: locked, fetcher: async () => {
36
+ requests++;
37
+ return Response.json({});
38
+ } }), /^Error: setup_claim_failed$/);
39
+ assert.equal(requests, 0);
40
+ });
41
+ test('transport denies redirects, oversized responses and reflected server errors', async () => {
42
+ for (const response of [new Response(JSON.stringify({ error: 'secret-canary' }), { status: 500 }),
43
+ new Response('x'.repeat(65_537)), new Response('{}', { status: 302 })]) {
44
+ await assert.rejects(claimSetupReference({ ...scope, store: store(), fetcher: async (_url, init) => {
45
+ assert.equal(init?.redirect, 'error');
46
+ return response;
47
+ } }), /^Error: setup_claim_failed$/);
48
+ }
49
+ });
50
+ test('wrong scope and expired challenges never finalize', async () => {
51
+ for (const changed of [{ scopeDigest: `sha256:${'d'.repeat(64)}` }, { expiresAt: '2020-01-01T00:00:00.000Z' }]) {
52
+ let requests = 0;
53
+ await assert.rejects(claimSetupReference({ ...scope, store: store(), fetcher: async (_url, init) => {
54
+ requests++;
55
+ const sent = JSON.parse(String(init?.body));
56
+ return Response.json({ ok: true, device: sent.device, challenge: {
57
+ setupReference: scope.setupReference, organizationId: scope.organizationId,
58
+ recipientMembershipId: scope.recipientMembershipId, repositoryFingerprint: scope.repositoryFingerprint,
59
+ scopeDigest: scope.scopeDigest, contractDigest: scope.contractDigest, policyRevision: scope.policyRevision,
60
+ origin: scope.hqUrl, publicKeyEd25519: sent.publicKeyEd25519,
61
+ credentialEncryptionPublicKey: sent.credentialEncryptionPublicKey, mode: 'source',
62
+ schema: 'dharma.setup-claim-challenge/v1', method: 'POST', path: '/api/v1/agent-fabric/bootstrap/setup-claim',
63
+ nonce: Buffer.alloc(32, 1).toString('base64url'), authenticator: Buffer.alloc(32, 2).toString('base64url'),
64
+ issuedAt: new Date().toISOString(), expiresAt: new Date(Date.now() + 60_000).toISOString(), ...changed,
65
+ } });
66
+ } }), /^Error: setup_claim_failed$/);
67
+ assert.equal(requests, 1);
68
+ }
69
+ });
70
+ async function fixture(change, pending = false, issuedAheadMs = 0) {
71
+ const root = await mkdtemp(resolve(tmpdir(), 'fabric-claim-synthetic-'));
72
+ let time = Date.now();
73
+ let challenge;
74
+ let calls = 0;
75
+ let stage = 'start';
76
+ const secret = `dharma_org_${'s'.repeat(48)}`;
77
+ const memory = store();
78
+ const server = generateKeyPairSync('ed25519');
79
+ const publicKey = server.publicKey.export({ format: 'jwk' }).x;
80
+ const start = new Date(time - 1_000).toISOString(), end = new Date(time + 3_600_000).toISOString();
81
+ const unsigned = { schema: 'dharma.server-signing-keyset/v1', organizationId: scope.organizationId,
82
+ generation: 1, keys: [{ keyVersion: 'kms/1', publicKeyEd25519: publicKey, status: 'active',
83
+ notBefore: start, notAfter: end }], signedByKeyVersion: 'kms/1', issuedAt: start, expiresAt: end };
84
+ const keyset = { ...unsigned, signature: signCanonicalObject(unsigned, server.privateKey) };
85
+ const fetcher = async (_url, init) => {
86
+ calls++;
87
+ assert.equal(init?.redirect, 'error');
88
+ const sent = JSON.parse(String(init?.body));
89
+ assert.equal(String(init?.body).includes(secret), false);
90
+ if (sent.action === 'challenge') {
91
+ challenge = { schema: 'dharma.setup-claim-challenge/v1', origin: scope.hqUrl,
92
+ setupReference: scope.setupReference, organizationId: scope.organizationId,
93
+ recipientMembershipId: scope.recipientMembershipId, publicKeyEd25519: sent.publicKeyEd25519,
94
+ credentialEncryptionPublicKey: sent.credentialEncryptionPublicKey, repositoryFingerprint: scope.repositoryFingerprint,
95
+ mode: 'source', policyRevision: scope.policyRevision, scopeDigest: scope.scopeDigest, contractDigest: scope.contractDigest,
96
+ method: 'POST', path: '/api/v1/agent-fabric/bootstrap/setup-claim', nonce: Buffer.alloc(32, 1).toString('base64url'),
97
+ authenticator: Buffer.alloc(32, 2).toString('base64url'), issuedAt: new Date(time + issuedAheadMs).toISOString(),
98
+ expiresAt: new Date(time + 60_000).toISOString() };
99
+ return Response.json({ ok: true, challenge, device: sent.device });
100
+ }
101
+ stage = 'challenge-check';
102
+ assert.deepEqual(sent.challenge, challenge);
103
+ stage = 'signature-check';
104
+ assert.equal(verify(null, setupClaimSigningPayload(challenge), createPublicKey({ format: 'jwk',
105
+ key: { kty: 'OKP', crv: 'Ed25519', x: challenge.publicKeyEd25519 } }), Buffer.from(sent.signature, 'base64url')), true);
106
+ stage = 'signature-verified';
107
+ if (pending && calls === 2) {
108
+ const expectedApproval = {
109
+ url: `${scope.hqUrl}/portal/agent-fabric/setup-claim-approval#request=${Buffer.from(JSON.stringify({ challenge, signature: sent.signature, device: sent.device })).toString('base64url')}`,
110
+ expiresAt: challenge.expiresAt, repositoryFingerprint: challenge.repositoryFingerprint,
111
+ fingerprint: `sha256:${createHash('sha256').update(Buffer.from(challenge.publicKeyEd25519, 'base64url')).digest('hex')}`,
112
+ };
113
+ stage = 'approval-check';
114
+ parseSetupClaimRecipientApproval(expectedApproval, challenge, sent.signature, sent.device, time);
115
+ stage = 'approval-verified';
116
+ return Response.json({ ok: false, status: 'recipient_approval_required', approval: expectedApproval }, { status: 409 });
117
+ }
118
+ const payload = { ok: true, status: 'approved', organizationId: scope.organizationId,
119
+ deviceId: '33333333-3333-4333-8333-333333333333', relayUrl: 'wss://relay.example', serverPublicKeyEd25519: publicKey,
120
+ serverSigningKeyset: keyset, organizationApiToken: secret, organizationApiTokenScopes: [
121
+ 'agents:read', 'agents:run', 'evals:read', 'evals:run', 'traces:read', 'skills:read', 'skills:write', 'usage:read', 'reports:read', 'fabric:devices', 'fabric:tasks'
122
+ ],
123
+ setupReference: challenge.setupReference, recipientMembershipId: challenge.recipientMembershipId,
124
+ publicKeyEd25519: challenge.publicKeyEd25519, repositoryFingerprint: challenge.repositoryFingerprint,
125
+ scopeDigest: challenge.scopeDigest, contractDigest: challenge.contractDigest };
126
+ change?.(payload);
127
+ return Response.json({ ok: true, status: 'approved', credential: sealSetupClaimCredential(challenge, JSON.stringify(payload)) });
128
+ };
129
+ return { root, secret, memory, get calls() { return calls; }, get stage() { return stage; },
130
+ input: { ...scope, configPath: resolve(root, 'device.json'), store: memory, fetcher, now: () => time,
131
+ sleep: async (ms) => { time += ms; } }, advance: (ms) => { time += ms; } };
132
+ }
133
+ test('small server clock lead waits for strict time validity before approval or finalize', async (t) => {
134
+ for (const lead of [2208, 5000])
135
+ await t.test(`lead_${lead}ms`, async () => {
136
+ const f = await fixture(undefined, true, lead);
137
+ const waits = [];
138
+ try {
139
+ const result = await claimSetupReference({ ...f.input, sleep: async (ms) => { waits.push(ms); f.advance(ms); } });
140
+ assert.equal(waits[0], lead);
141
+ assert.equal(result.config.setupClaimReference, scope.setupReference);
142
+ assert.equal(f.calls, 3);
143
+ }
144
+ finally {
145
+ await rm(f.root, { recursive: true, force: true });
146
+ }
147
+ });
148
+ });
149
+ test('future challenge never weakens scope, expiry, maximum wait or a stalled local clock', async (t) => {
150
+ for (const kind of ['excessive_lead', 'deadline', 'stalled_clock', 'expiry', 'wrong_scope']) {
151
+ await t.test(kind, async () => {
152
+ const f = await fixture(undefined, false, kind === 'excessive_lead' ? 5001 : 2208);
153
+ let waits = 0;
154
+ const fetcher = async (url, init) => {
155
+ const response = await f.input.fetcher(url, init);
156
+ if (kind !== 'wrong_scope')
157
+ return response;
158
+ const body = await response.json();
159
+ body.challenge.scopeDigest = `sha256:${'d'.repeat(64)}`;
160
+ return Response.json(body);
161
+ };
162
+ try {
163
+ await assert.rejects(claimSetupReference({ ...f.input, fetcher,
164
+ maximumWaitMs: kind === 'deadline' ? 2000 : 900_000,
165
+ sleep: async (ms) => { waits++; if (kind !== 'stalled_clock')
166
+ f.advance(kind === 'expiry' ? 60_001 : ms); },
167
+ }), /^Error: setup_claim_failed$/);
168
+ assert.equal(f.calls, 1);
169
+ assert.equal(waits, ['stalled_clock', 'expiry'].includes(kind) ? 1 : 0);
170
+ await assert.rejects(readFile(f.input.configPath), { code: 'ENOENT' });
171
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
172
+ }
173
+ finally {
174
+ await rm(f.root, { recursive: true, force: true });
175
+ }
176
+ });
177
+ }
178
+ });
179
+ test('nonTTY claim signs exact approval request and stores credential without returning it', async () => {
180
+ const f = await fixture(undefined, true);
181
+ let approvals = 0;
182
+ try {
183
+ const result = await claimSetupReference({ ...f.input, onRecipientApprovalRequired: approval => {
184
+ approvals++;
185
+ assert.equal(approval.url.includes(f.secret), false);
186
+ } }).catch(() => { throw new Error(`synthetic_success_failed_requests_${f.calls}_approvals_${approvals}_${f.stage}`); });
187
+ assert.equal(approvals, 1);
188
+ assert.equal(f.calls, 3);
189
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), f.secret);
190
+ assert.equal(JSON.stringify(result).includes(f.secret), false);
191
+ assert.equal(result.config.setupClaimReference, scope.setupReference);
192
+ assert.equal(result.config.setupClaimRepositoryFingerprint, scope.repositoryFingerprint);
193
+ assert.deepEqual(setupClaimSourceRegistration(result.config, scope.repositoryFingerprint), { setupClaimReference: scope.setupReference });
194
+ assert.deepEqual(setupClaimSourceRegistration(result.config, `sha256:${'d'.repeat(64)}`), {});
195
+ assert.equal((await readFile(f.input.configPath, 'utf8')).includes(f.secret), false);
196
+ }
197
+ finally {
198
+ await rm(f.root, { recursive: true, force: true });
199
+ }
200
+ });
201
+ test('source dispatch is exact, grant-free and does not block legacy sibling repositories', () => {
202
+ const config = { setupClaimReference: scope.setupReference, setupClaimRepositoryFingerprint: scope.repositoryFingerprint };
203
+ assert.deepEqual(setupClaimSourceRegistration(config, scope.repositoryFingerprint), { setupClaimReference: scope.setupReference });
204
+ assert.deepEqual(setupClaimSourceRegistration(config, `sha256:${'d'.repeat(64)}`), {});
205
+ assert.deepEqual(setupClaimSourceRegistration({}, scope.repositoryFingerprint), {});
206
+ assert.throws(() => setupClaimSourceRegistration({ ...config, setupClaimReference: 'invalid' }, scope.repositoryFingerprint), /^Error: setup_claim_failed$/);
207
+ });
208
+ test('sealed authority substitution and malformed scopes/token/trust never write enrollment', async (t) => {
209
+ const mutations = [
210
+ (p) => { p.recipientMembershipId = '44444444-4444-4444-8444-444444444444'; },
211
+ (p) => { p.publicKeyEd25519 = Buffer.alloc(32).toString('base64url'); },
212
+ (p) => { p.scopeDigest = `sha256:${'d'.repeat(64)}`; },
213
+ (p) => { p.repositoryFingerprint = `sha256:${'d'.repeat(64)}`; },
214
+ (p) => { p.contractDigest = `sha256:${'d'.repeat(64)}`; },
215
+ (p) => { p.organizationApiTokenScopes = ['fabric:devices', 'admin']; },
216
+ (p) => { p.organizationApiToken = 'secret-canary'; },
217
+ (p) => { p.serverSigningKeyset = null; },
218
+ (p) => { p.serverSigningKeyset.signature = Buffer.alloc(64).toString('base64url'); },
219
+ ];
220
+ for (const [index, change] of mutations.entries())
221
+ await t.test(String(index), async () => {
222
+ const f = await fixture(change);
223
+ try {
224
+ await assert.rejects(claimSetupReference(f.input), /^Error: setup_claim_failed$/);
225
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
226
+ await assert.rejects(readFile(f.input.configPath));
227
+ }
228
+ finally {
229
+ await rm(f.root, { recursive: true, force: true });
230
+ }
231
+ });
232
+ });
233
+ test('expiry while recipient approval runs prevents another HTTP request/store write', async () => {
234
+ const f = await fixture(undefined, true);
235
+ try {
236
+ await assert.rejects(claimSetupReference({ ...f.input, onRecipientApprovalRequired: () => f.advance(60_001) }), /^Error: setup_claim_failed$/);
237
+ assert.equal(f.calls, 2);
238
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
239
+ }
240
+ finally {
241
+ await rm(f.root, { recursive: true, force: true });
242
+ }
243
+ });
244
+ test('approval URL never allows another origin/path/query/signature/device context', async (t) => {
245
+ for (const field of ['origin', 'path', 'query', 'fingerprint', 'device'])
246
+ await t.test(field, async () => {
247
+ const f = await fixture(undefined, true);
248
+ const fetcher = async (url, init) => {
249
+ const response = await f.input.fetcher(url, init);
250
+ if (response.status !== 409)
251
+ return response;
252
+ const body = await response.json();
253
+ if (field === 'origin')
254
+ body.approval.url = body.approval.url.replace('hq.example', 'foreign.example');
255
+ if (field === 'path')
256
+ body.approval.url = body.approval.url.replace('setup-claim-approval', 'bootstrap-approval');
257
+ if (field === 'query')
258
+ body.approval.url = body.approval.url.replace('#', '?redirect=foreign#');
259
+ if (field === 'fingerprint')
260
+ body.approval.fingerprint = `sha256:${'0'.repeat(64)}`;
261
+ if (field === 'device') {
262
+ const uri = new URL(body.approval.url);
263
+ const value = JSON.parse(Buffer.from(uri.hash.slice(9), 'base64url').toString());
264
+ value.device.name = 'foreign';
265
+ uri.hash = `request=${Buffer.from(JSON.stringify(value)).toString('base64url')}`;
266
+ body.approval.url = uri.toString();
267
+ }
268
+ return Response.json(body, { status: 409 });
269
+ };
270
+ try {
271
+ await assert.rejects(claimSetupReference({ ...f.input, fetcher }), /^Error: setup_claim_failed$/);
272
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
273
+ }
274
+ finally {
275
+ await rm(f.root, { recursive: true, force: true });
276
+ }
277
+ });
278
+ });
279
+ test('sealed ciphertext substitution and live response expiry do not commit credentials', async (t) => {
280
+ for (const field of ['tag', 'ephemeralPublicKey', 'expiresAt', 'clock'])
281
+ await t.test(field, async () => {
282
+ const f = await fixture();
283
+ const fetcher = async (url, init) => {
284
+ const response = await f.input.fetcher(url, init);
285
+ const sent = JSON.parse(String(init?.body));
286
+ if (sent.action !== 'finalize')
287
+ return response;
288
+ const body = await response.json();
289
+ if (field === 'clock')
290
+ f.advance(60_001);
291
+ else if (field === 'expiresAt')
292
+ body.credential.expiresAt = '2030-01-01T00:00:00.000Z';
293
+ else
294
+ body.credential[field] = Buffer.alloc(field === 'tag' ? 16 : 32).toString('base64url');
295
+ return Response.json(body);
296
+ };
297
+ try {
298
+ await assert.rejects(claimSetupReference({ ...f.input, fetcher }), /^Error: setup_claim_failed$/);
299
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
300
+ }
301
+ finally {
302
+ await rm(f.root, { recursive: true, force: true });
303
+ }
304
+ });
305
+ });
306
+ test('runtime requests and response envelopes agree with strict published schemas', async () => {
307
+ const f = await fixture(undefined, true);
308
+ const schemas = resolve(import.meta.dirname, '../../../schemas');
309
+ const fetcher = async (url, init) => {
310
+ const request = JSON.parse(String(init?.body));
311
+ assert.equal((await validateContract(schemas, 'https://schemas.dharma-ai.io/setup-claim-request/v1', request)).ok, true);
312
+ assert.equal((await validateContract(schemas, 'https://schemas.dharma-ai.io/setup-claim-request/v1', { ...request, grant: 'forbidden' })).ok, false);
313
+ const response = await f.input.fetcher(url, init);
314
+ const body = await response.json();
315
+ assert.equal((await validateContract(schemas, 'https://schemas.dharma-ai.io/setup-claim-response/v1', body)).ok, true);
316
+ assert.equal((await validateContract(schemas, 'https://schemas.dharma-ai.io/setup-claim-response/v1', { ...body, organizationApiToken: 'forbidden' })).ok, false);
317
+ return Response.json(body, { status: response.status });
318
+ };
319
+ try {
320
+ await claimSetupReference({ ...f.input, fetcher });
321
+ }
322
+ finally {
323
+ await rm(f.root, { recursive: true, force: true });
324
+ }
325
+ });
326
+ test('lost response recovery uses the same protected device key with a fresh encrypted challenge', async () => {
327
+ const f = await fixture();
328
+ let firstKey = '';
329
+ let lost = true;
330
+ const fetcher = async (url, init) => {
331
+ const request = JSON.parse(String(init?.body));
332
+ if (request.action === 'challenge') {
333
+ if (firstKey)
334
+ assert.equal(request.publicKeyEd25519, firstKey);
335
+ else
336
+ firstKey = request.publicKeyEd25519;
337
+ }
338
+ const response = await f.input.fetcher(url, init);
339
+ if (request.action === 'finalize' && lost) {
340
+ lost = false;
341
+ throw new Error('synthetic-lost-response-secret-canary');
342
+ }
343
+ return response;
344
+ };
345
+ try {
346
+ await assert.rejects(claimSetupReference({ ...f.input, fetcher }), /^Error: setup_claim_failed$/);
347
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
348
+ const result = await claimSetupReference({ ...f.input, fetcher });
349
+ assert.equal(result.config.publicKeyEd25519, firstKey);
350
+ assert.equal(JSON.stringify(result).includes(f.secret), false);
351
+ assert.equal(f.calls, 4);
352
+ }
353
+ finally {
354
+ await rm(f.root, { recursive: true, force: true });
355
+ }
356
+ });
357
+ test('claim name boundary rejects 121 characters and short/control names before store or HTTP effects', async () => {
358
+ for (const name of ['a'.repeat(121), 'a', 'a\n']) {
359
+ let effects = 0;
360
+ const forbidden = { backend: 'linux-secret-service',
361
+ get: async () => { effects++; return null; }, put: async () => { effects++; }, delete: async () => { effects++; } };
362
+ await assert.rejects(claimSetupReference({ ...scope, name, store: forbidden, fetcher: async () => {
363
+ effects++;
364
+ return Response.json({});
365
+ } }), /^Error: setup_claim_failed$/);
366
+ assert.equal(effects, 0);
367
+ }
368
+ });
369
+ test('claim name boundary permits 120 characters and request schema agrees', async () => {
370
+ const f = await fixture();
371
+ const name = 'a'.repeat(120);
372
+ const fetcher = async (url, init) => {
373
+ const request = JSON.parse(String(init?.body));
374
+ if (request.action === 'challenge') {
375
+ const schemas = resolve(import.meta.dirname, '../../../schemas');
376
+ assert.equal((await validateContract(schemas, 'https://schemas.dharma-ai.io/setup-claim-request/v1', request)).ok, true);
377
+ assert.equal((await validateContract(schemas, 'https://schemas.dharma-ai.io/setup-claim-request/v1', {
378
+ ...request, device: { ...request.device, name: 'a'.repeat(121) }
379
+ })).ok, false);
380
+ }
381
+ return f.input.fetcher(url, init);
382
+ };
383
+ try {
384
+ const result = await claimSetupReference({ ...f.input, name, fetcher });
385
+ assert.equal(result.config.deviceName, name);
386
+ }
387
+ finally {
388
+ await rm(f.root, { recursive: true, force: true });
389
+ }
390
+ });
391
+ test('approved rate limit retries exact signed request with Retry-After and preserves request timeout', async () => {
392
+ const f = await fixture();
393
+ const finalized = [];
394
+ let limited = true;
395
+ const waits = [];
396
+ const fetcher = async (url, init) => {
397
+ const request = JSON.parse(String(init?.body));
398
+ assert.ok(init?.signal);
399
+ if (request.action === 'finalize') {
400
+ finalized.push(String(init?.body));
401
+ if (limited) {
402
+ limited = false;
403
+ return Response.json({ ok: false, error: { code: 'rate_limited', message: 'secret-canary' } }, { status: 429, headers: { 'retry-after': '1' } });
404
+ }
405
+ }
406
+ return f.input.fetcher(url, init);
407
+ };
408
+ try {
409
+ const result = await claimSetupReference({ ...f.input, fetcher, sleep: async (ms) => { waits.push(ms); f.advance(ms); } });
410
+ assert.equal(result.config.setupClaimReference, scope.setupReference);
411
+ assert.equal(finalized.length, 2);
412
+ assert.equal(finalized[0], finalized[1]);
413
+ assert.deepEqual(waits, [1_000]);
414
+ assert.equal(f.calls, 2);
415
+ }
416
+ finally {
417
+ await rm(f.root, { recursive: true, force: true });
418
+ }
419
+ });
420
+ test('rate limit retry cannot exceed fixed expiry or accept malformed Retry-After/error context', async (t) => {
421
+ for (const kind of ['deadline', 'missing', 'malformed', 'wrong-code'])
422
+ await t.test(kind, async () => {
423
+ const f = await fixture();
424
+ let finalized = 0, waits = 0;
425
+ const fetcher = async (url, init) => {
426
+ const request = JSON.parse(String(init?.body));
427
+ if (request.action === 'finalize') {
428
+ finalized++;
429
+ return Response.json({ ok: false, error: { code: kind === 'wrong-code' ? 'foreign' : 'rate_limited' } }, { status: 429, headers: kind === 'missing' ? {} : { 'retry-after': kind === 'deadline' ? '60' : kind === 'malformed' ? 'invalid' : '1' } });
430
+ }
431
+ return f.input.fetcher(url, init);
432
+ };
433
+ try {
434
+ await assert.rejects(claimSetupReference({ ...f.input, fetcher, sleep: async () => { waits++; } }), /^Error: setup_claim_failed$/);
435
+ assert.equal(finalized, 1);
436
+ assert.equal(waits, 0);
437
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
438
+ }
439
+ finally {
440
+ await rm(f.root, { recursive: true, force: true });
441
+ }
442
+ });
443
+ });
444
+ test('repeated approved rate limits stop at overall deadline without new challenge or proof', async () => {
445
+ const f = await fixture();
446
+ const finalized = [];
447
+ const waits = [];
448
+ const fetcher = async (url, init) => {
449
+ const request = JSON.parse(String(init?.body));
450
+ if (request.action !== 'finalize')
451
+ return f.input.fetcher(url, init);
452
+ finalized.push(String(init?.body));
453
+ return Response.json({ ok: false, error: { code: 'rate_limited' } }, { status: 429, headers: { 'retry-after': '1' } });
454
+ };
455
+ try {
456
+ await assert.rejects(claimSetupReference({ ...f.input, fetcher, maximumWaitMs: 2_500,
457
+ sleep: async (ms) => { waits.push(ms); f.advance(ms); } }), /^Error: setup_claim_failed$/);
458
+ assert.deepEqual(waits, [1_000, 1_000]);
459
+ assert.equal(finalized.length, 3);
460
+ assert.equal(new Set(finalized).size, 1);
461
+ assert.equal(f.calls, 1);
462
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
463
+ }
464
+ finally {
465
+ await rm(f.root, { recursive: true, force: true });
466
+ }
467
+ });
468
+ test('relay normalization never returns or persists an untrusted path canary', async () => {
469
+ const canary = 'synthetic-relay-path-canary';
470
+ const f = await fixture(p => { p.relayUrl = `wss://relay.example/${canary}`; });
471
+ try {
472
+ const result = await claimSetupReference(f.input);
473
+ assert.equal(result.config.relayUrl, 'wss://relay.example');
474
+ assert.equal(JSON.stringify(result).includes(canary), false);
475
+ assert.equal((await readFile(f.input.configPath, 'utf8')).includes(canary), false);
476
+ }
477
+ finally {
478
+ await rm(f.root, { recursive: true, force: true });
479
+ }
480
+ });
481
+ test('relay query or userinfo secrets are rejected without public output or credential commit', async (t) => {
482
+ for (const relayUrl of ['wss://relay.example/?token=synthetic-canary', 'wss://synthetic-canary@relay.example'])
483
+ await t.test('invalid relay authority', async () => {
484
+ const f = await fixture(p => { p.relayUrl = relayUrl; });
485
+ try {
486
+ await assert.rejects(claimSetupReference(f.input), /^Error: setup_claim_failed$/);
487
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
488
+ }
489
+ finally {
490
+ await rm(f.root, { recursive: true, force: true });
491
+ }
492
+ });
493
+ });
494
+ test('protected device key changes after approval cannot commit enrollment credentials', async () => {
495
+ const f = await fixture();
496
+ const currentGet = f.memory.get;
497
+ f.memory.getFresh = async (account) => account.startsWith('device-key-') ? null : currentGet(account);
498
+ try {
499
+ await assert.rejects(claimSetupReference(f.input), /^Error: setup_claim_failed$/);
500
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
501
+ await assert.rejects(readFile(f.input.configPath));
502
+ }
503
+ finally {
504
+ await rm(f.root, { recursive: true, force: true });
505
+ }
506
+ });
507
+ test('expiry during protected token write stops later anchor/config publication without destructive rollback', async () => {
508
+ const f = await fixture();
509
+ const put = f.memory.put;
510
+ let anchors = 0;
511
+ f.memory.put = async (account, value) => {
512
+ await put(account, value);
513
+ if (account.startsWith('organization-api-'))
514
+ f.advance(60_001);
515
+ if (account.startsWith('device-enrollment-'))
516
+ anchors++;
517
+ };
518
+ try {
519
+ await assert.rejects(claimSetupReference(f.input), /^Error: setup_claim_failed$/);
520
+ assert.equal(anchors, 0);
521
+ await assert.rejects(readFile(f.input.configPath));
522
+ // The already-written protected credential is preserved for authenticated
523
+ // same-key recovery; no claim of transactional native-store rollback.
524
+ assert.equal(Boolean(await loadOrganizationApiToken({ ...scope, store: f.memory })), true);
525
+ }
526
+ finally {
527
+ await rm(f.root, { recursive: true, force: true });
528
+ }
529
+ });
530
+ test('protected token write interruption is sanitized and cannot publish a device config', async () => {
531
+ const f = await fixture();
532
+ const put = f.memory.put;
533
+ let anchors = 0;
534
+ f.memory.put = async (account, value) => {
535
+ if (account.startsWith('organization-api-'))
536
+ throw new Error('synthetic-secret-interruption');
537
+ if (account.startsWith('device-enrollment-'))
538
+ anchors++;
539
+ await put(account, value);
540
+ };
541
+ try {
542
+ await assert.rejects(claimSetupReference(f.input), /^Error: setup_claim_failed$/);
543
+ assert.equal(anchors, 0);
544
+ await assert.rejects(readFile(f.input.configPath));
545
+ }
546
+ finally {
547
+ await rm(f.root, { recursive: true, force: true });
548
+ }
549
+ });
550
+ test('recipient approval cancellation stops without credential writes or a public config', async () => {
551
+ const f = await fixture(undefined, true);
552
+ try {
553
+ await assert.rejects(claimSetupReference({ ...f.input, onRecipientApprovalRequired: () => {
554
+ throw new Error('synthetic-private-cancellation');
555
+ } }), /^Error: setup_claim_failed$/);
556
+ assert.equal(await loadOrganizationApiToken({ ...scope, store: f.memory }), null);
557
+ await assert.rejects(readFile(f.input.configPath));
558
+ assert.equal(f.calls, 2);
559
+ }
560
+ finally {
561
+ await rm(f.root, { recursive: true, force: true });
562
+ }
563
+ });
564
+ //# sourceMappingURL=setupClaim.test.js.map