@docknetwork/wallet-sdk-core 1.7.6 → 1.9.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.
Files changed (76) hide show
  1. package/lib/cloud-wallet.d.ts +79 -3
  2. package/lib/cloud-wallet.d.ts.map +1 -1
  3. package/lib/cloud-wallet.js +147 -14
  4. package/lib/cloud-wallet.js.map +1 -1
  5. package/lib/credential-provider.d.ts.map +1 -1
  6. package/lib/credential-provider.js +10 -4
  7. package/lib/credential-provider.js.map +1 -1
  8. package/lib/delegation/delegation-chain.d.ts +8 -0
  9. package/lib/delegation/delegation-chain.d.ts.map +1 -0
  10. package/lib/delegation/delegation-chain.js +33 -0
  11. package/lib/delegation/delegation-chain.js.map +1 -0
  12. package/lib/delegation/delegation-fixtures.d.ts +69 -0
  13. package/lib/delegation/delegation-fixtures.d.ts.map +1 -0
  14. package/lib/delegation/delegation-fixtures.js +553 -0
  15. package/lib/delegation/delegation-fixtures.js.map +1 -0
  16. package/lib/delegation/delegation-issuance.d.ts +19 -0
  17. package/lib/delegation/delegation-issuance.d.ts.map +1 -0
  18. package/lib/delegation/delegation-issuance.js +60 -0
  19. package/lib/delegation/delegation-issuance.js.map +1 -0
  20. package/lib/delegation/delegation-offer.d.ts +84 -0
  21. package/lib/delegation/delegation-offer.d.ts.map +1 -0
  22. package/lib/delegation/delegation-offer.js +349 -0
  23. package/lib/delegation/delegation-offer.js.map +1 -0
  24. package/lib/delegation/delegation-policy-validation.d.ts +28 -0
  25. package/lib/delegation/delegation-policy-validation.d.ts.map +1 -0
  26. package/lib/delegation/delegation-policy-validation.js +170 -0
  27. package/lib/delegation/delegation-policy-validation.js.map +1 -0
  28. package/lib/delegation/delegation-policy.d.ts +21 -0
  29. package/lib/delegation/delegation-policy.d.ts.map +1 -0
  30. package/lib/delegation/delegation-policy.js +73 -0
  31. package/lib/delegation/delegation-policy.js.map +1 -0
  32. package/lib/delegation/delegation-tree.d.ts +17 -0
  33. package/lib/delegation/delegation-tree.d.ts.map +1 -0
  34. package/lib/delegation/delegation-tree.js +58 -0
  35. package/lib/delegation/delegation-tree.js.map +1 -0
  36. package/lib/delegation/delegation-types.d.ts +56 -0
  37. package/lib/delegation/delegation-types.d.ts.map +1 -0
  38. package/lib/delegation/delegation-types.js +3 -0
  39. package/lib/delegation/delegation-types.js.map +1 -0
  40. package/lib/delegation/delegation-utils.d.ts +3 -0
  41. package/lib/delegation/delegation-utils.d.ts.map +1 -0
  42. package/lib/delegation/delegation-utils.js +10 -0
  43. package/lib/delegation/delegation-utils.js.map +1 -0
  44. package/lib/did-provider.d.ts +2 -1
  45. package/lib/did-provider.d.ts.map +1 -1
  46. package/lib/did-provider.js +11 -7
  47. package/lib/did-provider.js.map +1 -1
  48. package/lib/message-provider.js +1 -1
  49. package/lib/message-provider.js.map +1 -1
  50. package/lib/verification-controller.d.ts +30 -11
  51. package/lib/verification-controller.d.ts.map +1 -1
  52. package/lib/verification-controller.js +372 -68
  53. package/lib/verification-controller.js.map +1 -1
  54. package/package.json +3 -3
  55. package/src/cloud-wallet.test.js +369 -0
  56. package/src/cloud-wallet.ts +206 -18
  57. package/src/credential-provider.ts +13 -4
  58. package/src/delegation/delegation-chain.test.ts +64 -0
  59. package/src/delegation/delegation-chain.ts +34 -0
  60. package/src/delegation/delegation-fixtures.ts +552 -0
  61. package/src/delegation/delegation-issuance.ts +92 -0
  62. package/src/delegation/delegation-offer.ts +488 -0
  63. package/src/delegation/delegation-policy-validation.test.ts +237 -0
  64. package/src/delegation/delegation-policy-validation.ts +281 -0
  65. package/src/delegation/delegation-policy.ts +100 -0
  66. package/src/delegation/delegation-tree.test.ts +110 -0
  67. package/src/delegation/delegation-tree.ts +60 -0
  68. package/src/delegation/delegation-types.ts +65 -0
  69. package/src/delegation/delegation-utils.ts +10 -0
  70. package/src/did-provider.ts +10 -6
  71. package/src/globals.d.ts +6 -0
  72. package/src/message-provider.ts +1 -1
  73. package/src/verification-controller.test.ts +23 -0
  74. package/src/verification-controller.ts +534 -82
  75. package/tsconfig.build.json +2 -1
  76. package/tsconfig.build.tsbuildinfo +1 -1
@@ -0,0 +1,64 @@
1
+ import {addDelegationChain, getDelegationChain} from './delegation-chain';
2
+
3
+ describe('getDelegationChain', () => {
4
+ it('looks up the chain document by `${credential.id}#delegationChain`', async () => {
5
+ const wallet = {
6
+ addDocument: jest.fn(),
7
+ getDocumentById: jest.fn().mockResolvedValue(null),
8
+ };
9
+ const credential = {
10
+ id: 'cred-123',
11
+ '@context': [
12
+ 'https://www.w3.org/2018/credentials/v1',
13
+ 'https://ld.truvera.io/credentials/delegation',
14
+ ],
15
+ };
16
+
17
+ await getDelegationChain(credential, wallet);
18
+
19
+ expect(wallet.getDocumentById).toHaveBeenCalledWith('cred-123#delegationChain');
20
+ });
21
+ });
22
+
23
+ describe('addDelegationChain', () => {
24
+ it('stores a chain document when none exists for the credential', async () => {
25
+ const wallet = {
26
+ addDocument: jest.fn(),
27
+ getDocumentById: jest.fn().mockResolvedValue(null),
28
+ };
29
+ const credential = {id: 'cred-123'};
30
+ const delegationChain = [credential];
31
+
32
+ const stored = await addDelegationChain(
33
+ credential,
34
+ delegationChain,
35
+ wallet,
36
+ );
37
+
38
+ expect(wallet.addDocument).toHaveBeenCalledTimes(1);
39
+ const [storedDoc] = wallet.addDocument.mock.calls[0];
40
+ expect(storedDoc).toMatchObject({
41
+ id: 'cred-123#delegationChain',
42
+ type: 'DelegationChain',
43
+ credentialId: 'cred-123',
44
+ delegationChain,
45
+ });
46
+ expect(stored).toBe(storedDoc);
47
+ });
48
+
49
+ it('throws and does not write when a chain already exists', async () => {
50
+ const wallet = {
51
+ addDocument: jest.fn(),
52
+ getDocumentById: jest.fn().mockResolvedValue({
53
+ id: 'cred-123#delegationChain',
54
+ type: 'DelegationChain',
55
+ }),
56
+ };
57
+
58
+ await expect(
59
+ addDelegationChain({id: 'cred-123'}, [], wallet),
60
+ ).rejects.toThrow(/already exists/i);
61
+
62
+ expect(wallet.addDocument).not.toHaveBeenCalled();
63
+ });
64
+ });
@@ -0,0 +1,34 @@
1
+ import assert from 'assert';
2
+ import {isDelegatableCredential} from './delegation-utils';
3
+
4
+ export async function getDelegationChain(credential, wallet) {
5
+ assert(isDelegatableCredential(credential), 'Credential is not delegatable');
6
+ const document = await wallet.getDocumentById(
7
+ `${credential.id}#delegationChain`,
8
+ );
9
+ const delegationChain = Array.isArray(document?.delegationChain)
10
+ ? document.delegationChain
11
+ : [];
12
+
13
+ return [credential, ...delegationChain];
14
+ }
15
+
16
+ export async function addDelegationChain(credential, delegationChain, wallet) {
17
+ const delegationChainId = `${credential.id}#delegationChain`;
18
+ const existingChain = await wallet.getDocumentById(delegationChainId);
19
+
20
+ if (existingChain) {
21
+ throw new Error('Delegation chain already exists for this credential');
22
+ }
23
+
24
+ const delegationChainDocument = {
25
+ id: delegationChainId,
26
+ type: 'DelegationChain',
27
+ credentialId: credential.id,
28
+ delegationChain,
29
+ };
30
+
31
+ await wallet.addDocument(delegationChainDocument);
32
+
33
+ return delegationChainDocument;
34
+ }
@@ -0,0 +1,552 @@
1
+ import {DelegationPolicy} from './delegation-types';
2
+
3
+ export const delegationPolicyPharmacy = {
4
+ id: 'urn:uuid:65763e5c-8b8c-4db6-916c-e367b71644b0',
5
+ type: 'DelegationPolicy',
6
+ ruleset: {
7
+ roles: [
8
+ {
9
+ label: 'Prescribing Doctor',
10
+ roleId: '6ed167b3-90be-4f9a-a8d2-542d2f212d79',
11
+ attributes: ['*'],
12
+ parentRoleId: null,
13
+ capabilityGrants: [
14
+ {
15
+ schema: {
16
+ type: 'boolean',
17
+ const: true,
18
+ },
19
+ capability: 'Can Pick Up',
20
+ },
21
+ {
22
+ schema: {
23
+ type: 'boolean',
24
+ const: true,
25
+ },
26
+ capability: 'Can Pay',
27
+ },
28
+ {
29
+ schema: {
30
+ type: 'boolean',
31
+ const: true,
32
+ },
33
+ capability: 'Can Cancel',
34
+ },
35
+ {
36
+ schema: {
37
+ type: 'array',
38
+ items: {
39
+ enum: ['Pay', 'Cancel', 'PickUp'],
40
+ type: 'string',
41
+ },
42
+ minItems: 1,
43
+ uniqueItems: true,
44
+ },
45
+ capability: 'Allowed Claims',
46
+ },
47
+ ],
48
+ },
49
+ {
50
+ label: 'Pharmacy',
51
+ roleId: '053077d1-6e60-44a4-8c69-dad68eeca36e',
52
+ attributes: ['*'],
53
+ parentRoleId: '6ed167b3-90be-4f9a-a8d2-542d2f212d79',
54
+ capabilityGrants: [
55
+ {
56
+ schema: {
57
+ type: 'boolean',
58
+ const: true,
59
+ },
60
+ capability: 'Can Pick Up',
61
+ },
62
+ {
63
+ schema: {
64
+ type: 'boolean',
65
+ const: true,
66
+ },
67
+ capability: 'Can Pay',
68
+ },
69
+ {
70
+ schema: {
71
+ type: 'boolean',
72
+ const: true,
73
+ },
74
+ capability: 'Can Cancel',
75
+ },
76
+ {
77
+ schema: {
78
+ type: 'array',
79
+ items: {
80
+ enum: ['PickUp', 'Pay', 'Cancel'],
81
+ type: 'string',
82
+ },
83
+ minItems: 1,
84
+ uniqueItems: true,
85
+ },
86
+ capability: 'Allowed Claims',
87
+ },
88
+ ],
89
+ },
90
+ {
91
+ label: 'Patient',
92
+ roleId: '560195e9-922d-4002-b851-95b730577421',
93
+ attributes: ['*'],
94
+ parentRoleId: '053077d1-6e60-44a4-8c69-dad68eeca36e',
95
+ capabilityGrants: [
96
+ {
97
+ schema: {
98
+ type: 'boolean',
99
+ const: true,
100
+ },
101
+ capability: 'Can Pick Up',
102
+ },
103
+ {
104
+ schema: {
105
+ type: 'boolean',
106
+ const: true,
107
+ },
108
+ capability: 'Can Pay',
109
+ },
110
+ {
111
+ schema: {
112
+ type: 'boolean',
113
+ const: true,
114
+ },
115
+ capability: 'Can Cancel',
116
+ },
117
+ {
118
+ schema: {
119
+ type: 'array',
120
+ items: {
121
+ enum: ['PickUp', 'Pay', 'Cancel'],
122
+ type: 'string',
123
+ },
124
+ minItems: 1,
125
+ uniqueItems: true,
126
+ },
127
+ capability: 'Allowed Claims',
128
+ },
129
+ ],
130
+ },
131
+ {
132
+ label: 'Guardian',
133
+ roleId: '781aa007-ff3e-463a-82ac-b177359ea02c',
134
+ attributes: ['*'],
135
+ parentRoleId: '560195e9-922d-4002-b851-95b730577421',
136
+ capabilityGrants: [
137
+ {
138
+ schema: {
139
+ type: 'boolean',
140
+ const: true,
141
+ },
142
+ capability: 'Can Pick Up',
143
+ },
144
+ {
145
+ schema: {
146
+ type: 'boolean',
147
+ const: true,
148
+ },
149
+ capability: 'Can Pay',
150
+ },
151
+ {
152
+ schema: {
153
+ type: 'boolean',
154
+ const: true,
155
+ },
156
+ capability: 'Can Cancel',
157
+ },
158
+ ],
159
+ },
160
+ ],
161
+ capabilities: [
162
+ {
163
+ name: 'Can Pick Up',
164
+ schema: {
165
+ type: 'boolean',
166
+ const: true,
167
+ },
168
+ },
169
+ {
170
+ name: 'Can Pay',
171
+ schema: {
172
+ type: 'boolean',
173
+ const: true,
174
+ },
175
+ },
176
+ {
177
+ name: 'Can Cancel',
178
+ schema: {
179
+ type: 'boolean',
180
+ const: true,
181
+ },
182
+ },
183
+ {
184
+ name: 'Allowed Claims',
185
+ schema: {
186
+ type: 'array',
187
+ items: {
188
+ enum: ['PickUp', 'Pay', 'Cancel'],
189
+ type: 'string',
190
+ },
191
+ minItems: 1,
192
+ uniqueItems: true,
193
+ },
194
+ },
195
+ ],
196
+ delegationTarget: 'single-credential',
197
+ overallConstraints: {
198
+ maxDelegationDepth: 4,
199
+ delegatedCredentialLifetime: {
200
+ unit: 'years',
201
+ value: 1,
202
+ },
203
+ },
204
+ },
205
+ createdAt: '2026-04-29',
206
+ name: 'Prescription',
207
+ };
208
+
209
+ export const delegationPolicyTravelAgent = {
210
+ id: 'urn:uuid:0850f80d-7af5-4fda-8fda-a85ef5c8672d',
211
+ type: 'DelegationPolicy',
212
+ ruleset: {
213
+ roles: [
214
+ {
215
+ label: 'Travel Agent 1',
216
+ roleId: 'e79c0d16-8739-4e54-94d7-53d9f1c97c71',
217
+ attributes: ['*'],
218
+ parentRoleId: null,
219
+ capabilityGrants: [
220
+ {
221
+ schema: {
222
+ type: 'array',
223
+ items: {
224
+ type: 'string',
225
+ },
226
+ minItems: 1,
227
+ uniqueItems: true,
228
+ },
229
+ capability: 'Allowed Routes',
230
+ },
231
+ {
232
+ schema: {
233
+ type: 'integer',
234
+ maximum: 100,
235
+ },
236
+ capability: 'Purchase',
237
+ },
238
+ {
239
+ schema: {
240
+ type: 'boolean',
241
+ const: true,
242
+ },
243
+ capability: 'Reserve Flights',
244
+ },
245
+ {
246
+ schema: {
247
+ type: 'boolean',
248
+ const: true,
249
+ },
250
+ capability: 'Reserve Hotels',
251
+ },
252
+ ],
253
+ },
254
+ {
255
+ label: 'Corporate Account Manager',
256
+ roleId: '8e5abc88-7006-42ae-ae48-9e34f8f66124',
257
+ attributes: ['*'],
258
+ parentRoleId: 'e79c0d16-8739-4e54-94d7-53d9f1c97c71',
259
+ capabilityGrants: [
260
+ {
261
+ schema: {
262
+ type: 'array',
263
+ items: {
264
+ type: 'string',
265
+ },
266
+ minItems: 1,
267
+ uniqueItems: true,
268
+ },
269
+ capability: 'Allowed Routes',
270
+ },
271
+ {
272
+ schema: {
273
+ type: 'integer',
274
+ maximum: 100,
275
+ },
276
+ capability: 'Purchase',
277
+ },
278
+ {
279
+ schema: {
280
+ type: 'boolean',
281
+ const: true,
282
+ },
283
+ capability: 'Reserve Flights',
284
+ },
285
+ {
286
+ schema: {
287
+ type: 'boolean',
288
+ const: true,
289
+ },
290
+ capability: 'Reserve Hotels',
291
+ },
292
+ ],
293
+ },
294
+ {
295
+ label: 'Booking Specialist',
296
+ roleId: '6375baa1-a52d-4838-9100-3facea02ba49',
297
+ attributes: ['*'],
298
+ parentRoleId: '8e5abc88-7006-42ae-ae48-9e34f8f66124',
299
+ capabilityGrants: [
300
+ {
301
+ schema: {
302
+ type: 'array',
303
+ items: {
304
+ type: 'string',
305
+ },
306
+ minItems: 1,
307
+ uniqueItems: true,
308
+ },
309
+ capability: 'Allowed Routes',
310
+ },
311
+ {
312
+ schema: {
313
+ type: 'integer',
314
+ maximum: 100,
315
+ },
316
+ capability: 'Purchase',
317
+ },
318
+ {
319
+ schema: {
320
+ type: 'boolean',
321
+ const: true,
322
+ },
323
+ capability: 'Reserve Flights',
324
+ },
325
+ {
326
+ schema: {
327
+ type: 'boolean',
328
+ const: true,
329
+ },
330
+ capability: 'Reserve Hotels',
331
+ },
332
+ ],
333
+ },
334
+ {
335
+ label: 'Hotel Sub-agent',
336
+ roleId: '16f68474-bf3b-4494-9fe5-f141a7d74a33',
337
+ attributes: ['*'],
338
+ parentRoleId: '8e5abc88-7006-42ae-ae48-9e34f8f66124',
339
+ capabilityGrants: [
340
+ {
341
+ schema: {
342
+ type: 'array',
343
+ items: {
344
+ type: 'string',
345
+ },
346
+ minItems: 1,
347
+ uniqueItems: true,
348
+ },
349
+ capability: 'Allowed Routes',
350
+ },
351
+ {
352
+ schema: {
353
+ type: 'integer',
354
+ maximum: 50,
355
+ },
356
+ capability: 'Purchase',
357
+ },
358
+ {
359
+ schema: {
360
+ type: 'boolean',
361
+ const: true,
362
+ },
363
+ capability: 'Reserve Hotels',
364
+ },
365
+ ],
366
+ },
367
+ {
368
+ label: 'Flight Sub-agent',
369
+ roleId: 'c1bd8821-c645-4dd6-ab07-9bc087755db9',
370
+ attributes: ['*'],
371
+ parentRoleId: '8e5abc88-7006-42ae-ae48-9e34f8f66124',
372
+ capabilityGrants: [
373
+ {
374
+ schema: {
375
+ type: 'array',
376
+ items: {
377
+ type: 'string',
378
+ },
379
+ minItems: 1,
380
+ uniqueItems: true,
381
+ },
382
+ capability: 'Allowed Routes',
383
+ },
384
+ {
385
+ schema: {
386
+ type: 'integer',
387
+ maximum: 50,
388
+ },
389
+ capability: 'Purchase',
390
+ },
391
+ {
392
+ schema: {
393
+ type: 'boolean',
394
+ const: true,
395
+ },
396
+ capability: 'Reserve Flights',
397
+ },
398
+ ],
399
+ },
400
+ {
401
+ label: 'Car Rental Sub-agent',
402
+ roleId: '9726317c-cb60-4ae7-a828-e334b10f6f52',
403
+ attributes: ['*'],
404
+ parentRoleId: 'e79c0d16-8739-4e54-94d7-53d9f1c97c71',
405
+ capabilityGrants: [
406
+ {
407
+ schema: {
408
+ type: 'array',
409
+ items: {
410
+ type: 'string',
411
+ },
412
+ minItems: 1,
413
+ uniqueItems: true,
414
+ },
415
+ capability: 'Allowed Routes',
416
+ },
417
+ {
418
+ schema: {
419
+ type: 'integer',
420
+ maximum: 100,
421
+ },
422
+ capability: 'Purchase',
423
+ },
424
+ {
425
+ schema: {
426
+ type: 'boolean',
427
+ const: true,
428
+ },
429
+ capability: 'Reserve Flights',
430
+ },
431
+ {
432
+ schema: {
433
+ type: 'boolean',
434
+ const: true,
435
+ },
436
+ capability: 'Reserve Hotels',
437
+ },
438
+ ],
439
+ },
440
+ {
441
+ label: 'Flight Sub-agent',
442
+ roleId: '888aeee9-c3ed-469b-86bd-910490c9aa20',
443
+ attributes: ['*'],
444
+ parentRoleId: '9726317c-cb60-4ae7-a828-e334b10f6f52',
445
+ capabilityGrants: [
446
+ {
447
+ schema: {
448
+ type: 'array',
449
+ items: {
450
+ type: 'string',
451
+ },
452
+ minItems: 1,
453
+ uniqueItems: true,
454
+ },
455
+ capability: 'Allowed Routes',
456
+ },
457
+ {
458
+ schema: {
459
+ type: 'integer',
460
+ maximum: 50,
461
+ },
462
+ capability: 'Purchase',
463
+ },
464
+ {
465
+ schema: {
466
+ type: 'boolean',
467
+ const: true,
468
+ },
469
+ capability: 'Reserve Flights',
470
+ },
471
+ ],
472
+ },
473
+ {
474
+ label: 'Booking Executor',
475
+ roleId: 'd39f29c4-fc3e-4b5d-9eae-9f576576e4fb',
476
+ attributes: ['*'],
477
+ parentRoleId: '9726317c-cb60-4ae7-a828-e334b10f6f52',
478
+ capabilityGrants: [
479
+ {
480
+ schema: {
481
+ type: 'array',
482
+ items: {
483
+ type: 'string',
484
+ },
485
+ minItems: 1,
486
+ uniqueItems: true,
487
+ },
488
+ capability: 'Allowed Routes',
489
+ },
490
+ {
491
+ schema: {
492
+ type: 'integer',
493
+ maximum: 50,
494
+ },
495
+ capability: 'Purchase',
496
+ },
497
+ {
498
+ schema: {
499
+ type: 'boolean',
500
+ const: true,
501
+ },
502
+ capability: 'Reserve Hotels',
503
+ },
504
+ ],
505
+ },
506
+ ],
507
+ capabilities: [
508
+ {
509
+ name: 'Allowed Routes',
510
+ schema: {
511
+ type: 'array',
512
+ items: {
513
+ type: 'string',
514
+ },
515
+ minItems: 1,
516
+ uniqueItems: true,
517
+ },
518
+ },
519
+ {
520
+ name: 'Purchase',
521
+ schema: {
522
+ type: 'integer',
523
+ maximum: 100,
524
+ },
525
+ },
526
+ {
527
+ name: 'Reserve Flights',
528
+ schema: {
529
+ type: 'boolean',
530
+ const: true,
531
+ },
532
+ },
533
+ {
534
+ name: 'Reserve Hotels',
535
+ schema: {
536
+ type: 'boolean',
537
+ const: true,
538
+ },
539
+ },
540
+ ],
541
+ delegationTarget: 'single-credential',
542
+ overallConstraints: {
543
+ maxDelegationDepth: 4,
544
+ delegatedCredentialLifetime: {
545
+ unit: 'years',
546
+ value: 1,
547
+ },
548
+ },
549
+ },
550
+ createdAt: '2026-04-29',
551
+ name: 'Travel Agent',
552
+ } as DelegationPolicy;