@docknetwork/wallet-sdk-wasm 1.4.0 → 1.5.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 (190) hide show
  1. package/lib/{account-3c88155a.js → account-bf00e5c0.js} +5 -5
  2. package/lib/{account-8f5cbc4d.js → account-e48dc9b6.js} +5 -5
  3. package/lib/core/polkadot-utils.js +18 -4
  4. package/lib/core/polkadot-utils.mjs +15 -2
  5. package/lib/index.js +14 -17
  6. package/lib/index.mjs +14 -17
  7. package/lib/modules/account.js +9 -5
  8. package/lib/modules/account.mjs +9 -5
  9. package/lib/modules/accounts.js +9 -5
  10. package/lib/modules/accounts.mjs +9 -5
  11. package/lib/modules/network-manager.js +4 -2
  12. package/lib/modules/network-manager.mjs +4 -2
  13. package/lib/modules/wallet.js +12 -8
  14. package/lib/modules/wallet.mjs +12 -8
  15. package/lib/rpc-server.js +14 -17
  16. package/lib/rpc-server.mjs +14 -17
  17. package/lib/services/blockchain/configs.js +7 -0
  18. package/lib/services/blockchain/configs.mjs +3 -0
  19. package/lib/services/{dock → blockchain}/index.android.js +3 -4
  20. package/lib/services/{dock → blockchain}/index.android.mjs +3 -4
  21. package/lib/services/{dock → blockchain}/index.ios.js +3 -4
  22. package/lib/services/{dock → blockchain}/index.ios.mjs +3 -4
  23. package/lib/services/blockchain/index.js +30 -0
  24. package/lib/services/blockchain/index.mjs +22 -0
  25. package/lib/services/{dock → blockchain}/service-rpc.js +5 -7
  26. package/lib/services/{dock → blockchain}/service-rpc.mjs +5 -7
  27. package/lib/services/blockchain/service.js +212 -0
  28. package/lib/services/blockchain/service.mjs +206 -0
  29. package/lib/services/credential/bbs-revocation.js +33 -61
  30. package/lib/services/credential/bbs-revocation.mjs +34 -62
  31. package/lib/services/credential/bound-check.js +0 -8
  32. package/lib/services/credential/bound-check.mjs +1 -5
  33. package/lib/services/credential/index.js +20 -23
  34. package/lib/services/credential/index.mjs +20 -23
  35. package/lib/services/credential/pex-helpers.js +134 -34
  36. package/lib/services/credential/pex-helpers.mjs +133 -35
  37. package/lib/services/credential/service.js +54 -55
  38. package/lib/services/credential/service.mjs +43 -41
  39. package/lib/services/credential/utils.js +12 -18
  40. package/lib/services/credential/utils.mjs +11 -14
  41. package/lib/services/dids/config.js +8 -0
  42. package/lib/services/dids/config.mjs +8 -0
  43. package/lib/services/dids/index.js +8 -7
  44. package/lib/services/dids/index.mjs +8 -7
  45. package/lib/services/dids/service-rpc.js +2 -2
  46. package/lib/services/dids/service-rpc.mjs +2 -2
  47. package/lib/services/dids/service.js +22 -32
  48. package/lib/services/dids/service.mjs +22 -32
  49. package/lib/services/edv/hmac.js +5 -0
  50. package/lib/services/edv/hmac.mjs +5 -0
  51. package/lib/services/edv/index.js +10 -8
  52. package/lib/services/edv/index.mjs +10 -8
  53. package/lib/services/edv/service-rpc.js +4 -0
  54. package/lib/services/edv/service-rpc.mjs +4 -0
  55. package/lib/services/edv/service.js +26 -10
  56. package/lib/services/edv/service.mjs +25 -10
  57. package/lib/services/example/service.js +3 -1
  58. package/lib/services/example/service.mjs +3 -1
  59. package/lib/services/index.js +12 -15
  60. package/lib/services/index.mjs +12 -15
  61. package/lib/services/keyring/configs.js +12 -0
  62. package/lib/services/keyring/configs.mjs +12 -0
  63. package/lib/services/keyring/service.js +5 -0
  64. package/lib/services/keyring/service.mjs +5 -0
  65. package/lib/services/pex/service.js +17 -15
  66. package/lib/services/pex/service.mjs +17 -15
  67. package/lib/services/substrate/api-utils.js +18 -6
  68. package/lib/services/substrate/api-utils.mjs +18 -6
  69. package/lib/services/substrate/index.js +13 -6
  70. package/lib/services/substrate/index.mjs +13 -6
  71. package/lib/services/substrate/service.js +16 -9
  72. package/lib/services/substrate/service.mjs +16 -9
  73. package/lib/services/test-utils.js +27 -18
  74. package/lib/services/test-utils.mjs +27 -18
  75. package/lib/services/trust-registry/index.js +16 -5
  76. package/lib/services/trust-registry/index.mjs +16 -5
  77. package/lib/services/trust-registry/service.js +26 -10
  78. package/lib/services/trust-registry/service.mjs +26 -10
  79. package/lib/services/util-crypto/configs.js +3 -0
  80. package/lib/services/util-crypto/configs.mjs +3 -0
  81. package/lib/services/util-crypto/service-rpc.js +6 -0
  82. package/lib/services/util-crypto/service-rpc.mjs +6 -0
  83. package/lib/services/util-crypto/service.js +5 -0
  84. package/lib/services/util-crypto/service.mjs +6 -1
  85. package/lib/setup-nodejs.js +14 -17
  86. package/lib/setup-nodejs.mjs +14 -17
  87. package/lib/setup-tests.js +14 -17
  88. package/lib/setup-tests.mjs +14 -17
  89. package/lib/src/core/polkadot-utils.d.ts +1 -0
  90. package/lib/src/core/polkadot-utils.d.ts.map +1 -1
  91. package/lib/src/modules/network-manager.d.ts +1 -0
  92. package/lib/src/modules/network-manager.d.ts.map +1 -1
  93. package/lib/src/services/blockchain/configs.d.ts +8 -0
  94. package/lib/src/services/blockchain/configs.d.ts.map +1 -0
  95. package/lib/src/services/blockchain/index.d.ts +2 -0
  96. package/lib/src/services/blockchain/index.d.ts.map +1 -0
  97. package/lib/src/services/{dock → blockchain}/service.d.ts +12 -11
  98. package/lib/src/services/blockchain/service.d.ts.map +1 -0
  99. package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
  100. package/lib/src/services/credential/bound-check.d.ts +0 -4
  101. package/lib/src/services/credential/bound-check.d.ts.map +1 -1
  102. package/lib/src/services/credential/index.d.ts +2 -7
  103. package/lib/src/services/credential/index.d.ts.map +1 -1
  104. package/lib/src/services/credential/pex-helpers.d.ts +5 -3
  105. package/lib/src/services/credential/pex-helpers.d.ts.map +1 -1
  106. package/lib/src/services/credential/service.d.ts +2 -7
  107. package/lib/src/services/credential/service.d.ts.map +1 -1
  108. package/lib/src/services/credential/utils.d.ts.map +1 -1
  109. package/lib/src/services/dids/config.d.ts +5 -0
  110. package/lib/src/services/dids/config.d.ts.map +1 -1
  111. package/lib/src/services/dids/service-rpc.d.ts +1 -1
  112. package/lib/src/services/dids/service-rpc.d.ts.map +1 -1
  113. package/lib/src/services/dids/service.d.ts +9 -7
  114. package/lib/src/services/dids/service.d.ts.map +1 -1
  115. package/lib/src/services/edv/hmac.d.ts +1 -0
  116. package/lib/src/services/edv/hmac.d.ts.map +1 -1
  117. package/lib/src/services/edv/service.d.ts +5 -0
  118. package/lib/src/services/edv/service.d.ts.map +1 -1
  119. package/lib/src/services/example/service.d.ts.map +1 -1
  120. package/lib/src/services/keyring/configs.d.ts +6 -0
  121. package/lib/src/services/keyring/configs.d.ts.map +1 -1
  122. package/lib/src/services/pex/service.d.ts.map +1 -1
  123. package/lib/src/services/trust-registry/service.d.ts.map +1 -1
  124. package/lib/src/services/util-crypto/configs.d.ts +1 -0
  125. package/lib/src/services/util-crypto/configs.d.ts.map +1 -1
  126. package/lib/src/services/util-crypto/service.d.ts +1 -0
  127. package/lib/src/services/util-crypto/service.d.ts.map +1 -1
  128. package/lib/test/setup-test-state.js +10 -6
  129. package/lib/test/setup-test-state.mjs +10 -6
  130. package/lib/tsconfig.tsbuildinfo +1 -1
  131. package/package.json +5 -7
  132. package/src/core/polkadot-utils.js +14 -3
  133. package/src/modules/network-manager.ts +5 -2
  134. package/src/modules/wallet.ts +5 -5
  135. package/src/services/blockchain/configs.ts +11 -0
  136. package/src/services/blockchain/index.android.js +3 -0
  137. package/src/services/blockchain/index.ios.js +3 -0
  138. package/src/services/blockchain/index.js +1 -0
  139. package/src/services/blockchain/index.test.js +34 -0
  140. package/src/services/{dock → blockchain}/service-rpc.js +5 -6
  141. package/src/services/blockchain/service.ts +261 -0
  142. package/src/services/credential/bbs-revocation.ts +42 -90
  143. package/src/services/credential/bound-check.test.ts +2 -5
  144. package/src/services/credential/bound-check.ts +0 -5
  145. package/src/services/credential/index.test.js +148 -7
  146. package/src/services/credential/pex-helpers.js +132 -34
  147. package/src/services/credential/pex-helpers.test.js +284 -27
  148. package/src/services/credential/service.ts +44 -27
  149. package/src/services/credential/utils.js +5 -14
  150. package/src/services/dids/config.ts +15 -0
  151. package/src/services/dids/index.test.js +5 -46
  152. package/src/services/dids/service-rpc.ts +2 -2
  153. package/src/services/dids/service.ts +17 -34
  154. package/src/services/edv/hmac.ts +13 -0
  155. package/src/services/edv/index.test.js +22 -0
  156. package/src/services/edv/service-rpc.js +4 -0
  157. package/src/services/edv/service.ts +22 -0
  158. package/src/services/example/service.ts +3 -1
  159. package/src/services/index.js +2 -2
  160. package/src/services/keyring/configs.ts +21 -0
  161. package/src/services/keyring/service.ts +13 -0
  162. package/src/services/pex/service.ts +29 -18
  163. package/src/services/pex/tests/pex-service.test.js +163 -6
  164. package/src/services/substrate/api-utils.test.js +7 -7
  165. package/src/services/substrate/api-utils.ts +3 -3
  166. package/src/services/substrate/service.ts +6 -6
  167. package/src/services/test-utils.js +13 -11
  168. package/src/services/trust-registry/index.test.js +6 -4
  169. package/src/services/trust-registry/service.ts +13 -7
  170. package/src/services/util-crypto/configs.ts +4 -0
  171. package/src/services/util-crypto/service-rpc.js +6 -0
  172. package/src/services/util-crypto/service.ts +8 -0
  173. package/src/test/setup-test-state.js +2 -2
  174. package/lib/services/dock/configs.js +0 -18
  175. package/lib/services/dock/configs.mjs +0 -10
  176. package/lib/services/dock/index.js +0 -18
  177. package/lib/services/dock/index.mjs +0 -10
  178. package/lib/services/dock/service.js +0 -136
  179. package/lib/services/dock/service.mjs +0 -128
  180. package/lib/src/services/dock/configs.d.ts +0 -7
  181. package/lib/src/services/dock/configs.d.ts.map +0 -1
  182. package/lib/src/services/dock/index.d.ts +0 -2
  183. package/lib/src/services/dock/index.d.ts.map +0 -1
  184. package/lib/src/services/dock/service.d.ts.map +0 -1
  185. package/src/services/dock/configs.ts +0 -12
  186. package/src/services/dock/index.android.js +0 -3
  187. package/src/services/dock/index.ios.js +0 -3
  188. package/src/services/dock/index.js +0 -1
  189. package/src/services/dock/index.test.js +0 -48
  190. package/src/services/dock/service.ts +0 -159
@@ -196,6 +196,40 @@ describe('pex helpers', () => {
196
196
  ]);
197
197
  expect(result.length).toBe(1);
198
198
  });
199
+
200
+ it('should not include fields marked as optional', () => {
201
+ const result = getPexRequiredAttributes(
202
+ {
203
+ id: 'test-optional',
204
+ input_descriptors: [
205
+ {
206
+ id: 'Credential Optional',
207
+ constraints: {
208
+ fields: [
209
+ {
210
+ path: ['$.credentialSubject.id'],
211
+ },
212
+ {
213
+ path: ['$.credentialSubject.optionalField'],
214
+ optional: true,
215
+ },
216
+ ],
217
+ },
218
+ },
219
+ ],
220
+ },
221
+ [
222
+ {
223
+ credentialSubject: {
224
+ id: 'abc',
225
+ optionalField: 'shouldNotAppear',
226
+ },
227
+ },
228
+ ],
229
+ )[0];
230
+
231
+ expect(result).toEqual(['credentialSubject.id']);
232
+ });
199
233
  });
200
234
 
201
235
  describe('pexToBounds', () => {
@@ -210,14 +244,14 @@ describe('pex helpers', () => {
210
244
  type: 'number',
211
245
  minimum: 0,
212
246
  },
213
- path: ['$.age'],
247
+ path: ['$.credentialSubject.age'],
214
248
  },
215
249
  {
216
250
  filter: {
217
251
  format: 'date',
218
252
  minimum: '2021-01-01',
219
253
  },
220
- path: ['$.dateOfBirth'],
254
+ path: ['$.credentialSubject.dateOfBirth'],
221
255
  },
222
256
  ],
223
257
  },
@@ -225,23 +259,30 @@ describe('pex helpers', () => {
225
259
  ],
226
260
  };
227
261
 
228
- const bounds = pexToBounds(pexRequest);
262
+ const bounds = pexToBounds(pexRequest, [
263
+ {
264
+ credentialSubject: {
265
+ age: 10000000000,
266
+ },
267
+ },
268
+ {
269
+ credentialSubject: {
270
+ dateOfBirth: '2021-01-01',
271
+ },
272
+ },
273
+ ]);
229
274
 
230
275
  expect(bounds).toEqual([
231
276
  [
232
277
  {
233
- attributeName: 'age',
278
+ attributeName: 'credentialSubject.age',
234
279
  min: 0,
235
- max: 1000000000000000000,
236
- type: 'number',
237
- format: undefined,
280
+ max: 10000000000,
238
281
  },
239
282
  {
240
- attributeName: 'dateOfBirth',
283
+ attributeName: 'credentialSubject.dateOfBirth',
241
284
  min: new Date('2021-01-01'),
242
285
  max: new Date(884541351600000),
243
- type: undefined,
244
- format: 'date',
245
286
  },
246
287
  ],
247
288
  ]);
@@ -258,7 +299,7 @@ describe('pex helpers', () => {
258
299
  type: 'number',
259
300
  minimum: 0,
260
301
  },
261
- path: ['$.age'],
302
+ path: ['$.credentialSubject.age'],
262
303
  },
263
304
  ],
264
305
  },
@@ -266,16 +307,24 @@ describe('pex helpers', () => {
266
307
  ],
267
308
  };
268
309
 
269
- const bounds = pexToBounds(pexRequest, [], true);
310
+ const bounds = pexToBounds(
311
+ pexRequest,
312
+ [
313
+ {
314
+ credentialSubject: {
315
+ age: 2,
316
+ },
317
+ },
318
+ ],
319
+ true,
320
+ );
270
321
 
271
322
  expect(bounds).toEqual([
272
323
  [
273
324
  {
274
- attributeName: 'age',
325
+ attributeName: 'credentialSubject.age',
275
326
  min: 0,
276
- max: undefined,
277
- type: 'number',
278
- format: undefined,
327
+ max: 10000000000,
279
328
  },
280
329
  ],
281
330
  ]);
@@ -300,7 +349,11 @@ describe('pex helpers', () => {
300
349
  ],
301
350
  };
302
351
 
303
- const bounds = pexToBounds(pexRequest);
352
+ const bounds = pexToBounds(pexRequest, [
353
+ {
354
+ expirationDate: '2021-01-01',
355
+ },
356
+ ]);
304
357
 
305
358
  expect(bounds).toEqual([
306
359
  [
@@ -308,8 +361,6 @@ describe('pex helpers', () => {
308
361
  attributeName: 'expirationDate',
309
362
  min: new Date('2021-01-01T00:00:00Z'),
310
363
  max: new Date('2022-01-01T00:00:00Z'),
311
- type: undefined,
312
- format: 'date-time',
313
364
  },
314
365
  ],
315
366
  ]);
@@ -335,7 +386,11 @@ describe('pex helpers', () => {
335
386
  ],
336
387
  };
337
388
 
338
- const bounds = pexToBounds(pexRequest);
389
+ const bounds = pexToBounds(pexRequest, [
390
+ {
391
+ amount: 10,
392
+ },
393
+ ]);
339
394
 
340
395
  expect(bounds).toEqual([
341
396
  [
@@ -343,8 +398,6 @@ describe('pex helpers', () => {
343
398
  attributeName: 'amount',
344
399
  min: 0,
345
400
  max: 100,
346
- type: 'number',
347
- format: undefined,
348
401
  },
349
402
  ],
350
403
  ]);
@@ -378,7 +431,12 @@ describe('pex helpers', () => {
378
431
  ],
379
432
  };
380
433
 
381
- const bounds = pexToBounds(pexRequest);
434
+ const bounds = pexToBounds(pexRequest, [
435
+ {
436
+ amount: 10,
437
+ date: '2021-01-01',
438
+ },
439
+ ]);
382
440
 
383
441
  expect(bounds).toEqual([
384
442
  [
@@ -386,15 +444,11 @@ describe('pex helpers', () => {
386
444
  attributeName: 'startDate',
387
445
  min: new Date('2021-01-01'),
388
446
  max: new Date('2022-01-01'),
389
- type: undefined,
390
- format: 'date',
391
447
  },
392
448
  {
393
449
  attributeName: 'amount',
394
450
  min: 0,
395
451
  max: 100,
396
- type: 'number',
397
- format: undefined,
398
452
  },
399
453
  ],
400
454
  ]);
@@ -409,5 +463,208 @@ describe('pex helpers', () => {
409
463
 
410
464
  expect(bounds).toEqual([]);
411
465
  });
466
+
467
+ it('should not have undefined attributeNames, exclude not found bounds', () => {
468
+ const pexRequest = {
469
+ id: '3cb2c1db-54d7-427a-a6a2-4b8f73a33700',
470
+ input_descriptors: [
471
+ {
472
+ id: 'Credential 1',
473
+ name: 'Mortgage Application Qualification',
474
+ group: ['A'],
475
+ purpose:
476
+ 'Proof of assets (>100k), employment, and credit score (>800)',
477
+ constraints: {
478
+ fields: [
479
+ {
480
+ path: ['$.credentialSubject.id'],
481
+ optional: true,
482
+ },
483
+ {
484
+ path: ['$.credentialSchema.id'],
485
+ filter: {
486
+ const:
487
+ 'https://schema.dock.io/ProofOfEmployment-V1-1703767227542.json',
488
+ },
489
+ },
490
+ {
491
+ path: ['$.expirationDate', '$.vc.expirationDate'],
492
+ filter: {
493
+ type: 'string',
494
+ format: 'date-time',
495
+ formatMinimum: '2024-12-10T00:00:00.000Z',
496
+ },
497
+ optional: true,
498
+ predicate: 'required',
499
+ },
500
+ ],
501
+ },
502
+ },
503
+ {
504
+ id: 'Credential 2',
505
+ name: 'Mortgage Application Qualification',
506
+ group: ['A'],
507
+ purpose:
508
+ 'Proof of assets (>100k), employment, and credit score (>800)',
509
+ constraints: {
510
+ fields: [
511
+ {
512
+ path: ['$.credentialSubject.id'],
513
+ optional: true,
514
+ },
515
+ {
516
+ path: ['$.expirationDate'],
517
+ optional: true,
518
+ },
519
+ {
520
+ path: ['$.credentialSchema.id'],
521
+ filter: {
522
+ const:
523
+ 'https://schema.dock.io/CreditScore-V1-1732907844039.json',
524
+ },
525
+ },
526
+ {
527
+ path: ['$.credentialSubject.creditScore'],
528
+ filter: {
529
+ type: 'number',
530
+ minimum: 800,
531
+ },
532
+ predicate: 'required',
533
+ },
534
+ ],
535
+ },
536
+ },
537
+ {
538
+ id: 'Credential 3',
539
+ name: 'Mortgage Application Qualification',
540
+ group: ['A'],
541
+ purpose:
542
+ 'Proof of assets (>100k), employment, and credit score (>800)',
543
+ constraints: {
544
+ fields: [
545
+ {
546
+ path: ['$.credentialSubject.id'],
547
+ optional: true,
548
+ },
549
+ {
550
+ path: ['$.expirationDate'],
551
+ optional: true,
552
+ },
553
+ {
554
+ path: ['$.credentialSchema.id'],
555
+ filter: {
556
+ const:
557
+ 'https://schema.dock.io/ProofOfAssets-V1-1733843536548.json',
558
+ },
559
+ },
560
+ {
561
+ path: ['$.credentialSubject.sIN'],
562
+ optional: true,
563
+ },
564
+ {
565
+ path: ['$.credentialSubject.name'],
566
+ optional: true,
567
+ },
568
+ {
569
+ path: ['$.credentialSubject.propertiesOwned'],
570
+ filter: {
571
+ type: 'number',
572
+ minimum: 1,
573
+ },
574
+ predicate: 'required',
575
+ },
576
+ {
577
+ path: ['$.credentialSubject.totalPropertyAssetValue'],
578
+ filter: {
579
+ type: 'number',
580
+ minimum: 100000,
581
+ },
582
+ predicate: 'required',
583
+ },
584
+ ],
585
+ },
586
+ },
587
+ ],
588
+ submission_requirements: [
589
+ {
590
+ from: 'A',
591
+ name: 'Multi Credential Request',
592
+ rule: 'pick',
593
+ count: 1,
594
+ },
595
+ ],
596
+ };
597
+
598
+ const bounds = pexToBounds(pexRequest, [
599
+ {
600
+ '@context': [
601
+ 'https://www.w3.org/2018/credentials/v1',
602
+ 'https://ld.dock.io/credentials/extensions-v1',
603
+ 'https://ld.dock.io/security/bbs23/v1',
604
+ {
605
+ CreditScore: 'dk:CreditScore',
606
+ bankruptcies: 'dk:bankruptcies',
607
+ creditScore: 'dk:creditScore',
608
+ dk: 'https://ld.dock.io/credentials#',
609
+ },
610
+ ],
611
+ credentialStatus: {
612
+ id: 'dock:accumulator:0xb803980eb9433bb5d5d433f60c08fcd17e82eb2eb8ae3ac88fef79a3fb2f5fd9',
613
+ type: 'DockVBAccumulator2022',
614
+ revocationCheck: 'membership',
615
+ revocationId: '7',
616
+ },
617
+ id: 'https://creds-testnet.dock.io/15ca3b92504514756671ab5377ef23f7407f1c26c692b60363c97ba4775abab3',
618
+ type: ['VerifiableCredential', 'CreditScore'],
619
+ credentialSubject: {
620
+ name: 'tester',
621
+ creditScore: 800,
622
+ bankruptcies: 0,
623
+ },
624
+ issuanceDate: '2024-12-13T12:43:20.925Z',
625
+ issuer: {
626
+ name: 'CIBC',
627
+ description: 'CIBC - a bank',
628
+ logo: 'https://img.dock.io/e5715cbf78f2222924f5fe4e109d76a5',
629
+ id: 'did:dock:5CwdfTvda68vfdLu4yxNRFHuhdiXDzqLxw5TkoMfX6sC784a',
630
+ },
631
+ credentialSchema: {
632
+ id: 'https://schema.dock.io/CreditScore-V1-1732907844039.json',
633
+ type: 'JsonSchemaValidator2018',
634
+ details:
635
+ '{"jsonSchema":{"$id":"https://schema.dock.io/CreditScore-V1-1732907844039.json","$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":true,"description":"Proof of Credit","name":"Credit Score","properties":{"@context":{"type":"string"},"credentialSchema":{"properties":{"details":{"type":"string"},"id":{"type":"string"},"type":{"type":"string"},"version":{"type":"string"}},"type":"object"},"credentialStatus":{"properties":{"id":{"type":"string"},"revocationCheck":{"type":"string"},"revocationId":{"type":"string"},"type":{"type":"string"}},"type":"object"},"credentialSubject":{"properties":{"bankruptcies":{"description":"How many times have you declared bankruptcy","title":"Bankruptcies","type":"integer"},"creditScore":{"description":"","title":"Credit Score","type":"number"},"name":{"description":"Name of individual","title":"Name","type":"string"}},"required":["creditScore","bankruptcies","name"],"type":"object"},"cryptoVersion":{"type":"string"},"id":{"type":"string"},"issuanceDate":{"format":"date-time","type":"string"},"issuer":{"properties":{"description":{"type":"string"},"id":{"type":"string"},"logo":{"type":"string"},"name":{"type":"string"}},"type":"object"},"name":{"type":"string"},"proof":{"properties":{"@context":{"items":[{"properties":{"proof":{"properties":{"@container":{"type":"string"},"@id":{"type":"string"},"@type":{"type":"string"}},"type":"object"},"sec":{"type":"string"}},"type":"object"},{"type":"string"}],"type":"array"},"created":{"format":"date-time","type":"string"},"proofPurpose":{"type":"string"},"type":{"type":"string"},"verificationMethod":{"type":"string"}},"type":"object"},"type":{"type":"string"}},"type":"object"},"parsingOptions":{"defaultDecimalPlaces":4,"defaultMinimumDate":-17592186044415,"defaultMinimumInteger":-4294967295,"useDefaults":true}}',
636
+ version: '0.4.0',
637
+ },
638
+ name: 'Credit Score',
639
+ cryptoVersion: '0.6.0',
640
+ proof: {
641
+ '@context': [
642
+ {
643
+ sec: 'https://w3id.org/security#',
644
+ proof: {
645
+ '@id': 'sec:proof',
646
+ '@type': '@id',
647
+ '@container': '@graph',
648
+ },
649
+ },
650
+ 'https://ld.dock.io/security/bbs23/v1',
651
+ ],
652
+ type: 'Bls12381BBSSignatureDock2023',
653
+ created: '2024-12-13T12:43:42Z',
654
+ verificationMethod:
655
+ 'did:dock:5CwdfTvda68vfdLu4yxNRFHuhdiXDzqLxw5TkoMfX6sC784a#keys-2',
656
+ proofPurpose: 'assertionMethod',
657
+ proofValue:
658
+ 'z2PyUbLtaHuMbrdJagELMtFqroKXSoxtMaKLshc3PvT7VXpCHWWeeDMkvGf8MoKjjhNfwGPEXn9zYZuyZv7JGETWXs2TU2aSaKAHkvcmnVXcu8D',
659
+ },
660
+ },
661
+ ]);
662
+
663
+ bounds.forEach(() => {
664
+ expect(
665
+ bounds[0].every(bound => bound.attributeName !== undefined),
666
+ ).toBe(true);
667
+ });
668
+ });
412
669
  });
413
670
  });
@@ -2,24 +2,24 @@
2
2
  import {serviceName, validation} from './config';
3
3
  import {
4
4
  Accumulator,
5
- PositiveAccumulator,
6
- dockAccumulatorParams,
7
5
  VB_ACCUMULATOR_22 as AccumulatorType,
8
6
  WitnessUpdatePublicInfo,
9
7
  MembershipWitness,
10
8
  } from '@docknetwork/crypto-wasm-ts';
11
9
  import {OpenID4VCIClientV1_0_13} from '@sphereon/oid4vci-client';
12
10
  import {Alg} from '@sphereon/oid4vci-common';
13
- import {getDockRevIdFromCredential} from '@docknetwork/sdk/utils/revocation';
14
- import VerifiableCredential from '@docknetwork/sdk/verifiable-credential';
15
11
  import {getKeypairFromDoc} from '@docknetwork/universal-wallet/methods/keypairs';
16
- import {getSuiteFromKeyDoc} from '@docknetwork/sdk/utils/vc/helpers';
17
- import VerifiablePresentation from '@docknetwork/sdk/verifiable-presentation';
18
- import Presentation from '@docknetwork/sdk/presentation';
19
- import {verifyCredential} from '@docknetwork/sdk/utils/vc/credentials';
12
+ import {
13
+ VerifiablePresentation,
14
+ Presentation,
15
+ verifyCredential,
16
+ verifyPresentation,
17
+ VerifiableCredential,
18
+ getSuiteFromKeyDoc,
19
+ } from '@docknetwork/credential-sdk/vc';
20
20
  import {PEX} from '@sphereon/pex';
21
21
  import {keyDocToKeypair} from './utils';
22
- import {dockService, getDock} from '../dock/service';
22
+ import {blockchainService, getDock} from '../blockchain/service';
23
23
  import {
24
24
  applyEnforceBounds,
25
25
  hasProvingKey,
@@ -117,20 +117,25 @@ class CredentialService {
117
117
  vp.setHolder(keyDoc.controller);
118
118
  }
119
119
 
120
- keyDoc.keypair = keyDocToKeypair(keyDoc, getDock());
120
+ keyDoc.keypair = keyDocToKeypair(keyDoc, blockchainService.dock);
121
121
 
122
122
  if (shouldSkipSigning) {
123
123
  return vp.toJSON();
124
124
  }
125
125
 
126
- return vp.sign(keyDoc, challenge, domain, dockService.resolver);
126
+ return vp.sign(keyDoc, challenge, domain, blockchainService.resolver);
127
+ }
128
+
129
+ async verifyPresentation({ presentation, options }: any) {
130
+ return verifyPresentation(presentation, options);
127
131
  }
132
+
128
133
  async verifyCredential(params) {
129
134
  validation.verifyCredential(params);
130
135
  const {credential, membershipWitness} = params;
131
136
  const result = await verifyCredential(credential, {
132
- resolver: dockService.resolver,
133
- revocationApi: {dock: getDock()},
137
+ resolver: blockchainService.resolver,
138
+ revocationApi: {dock: blockchainService.dock},
134
139
  });
135
140
 
136
141
  const {credentialStatus} = credential;
@@ -191,15 +196,9 @@ class CredentialService {
191
196
  uri: string;
192
197
  authorizationCode?: string;
193
198
  holderKeyDocument: any;
194
- }) {
199
+ }): Promise<any> {
195
200
  const searchParams = new URL(uri).searchParams;
196
201
  const params = new URLSearchParams(searchParams);
197
- const credentialOfferEncoded = params.get('credential_offer');
198
- const credentialOfferDecoded = decodeURIComponent(credentialOfferEncoded);
199
- const credentialOffer = JSON.parse(credentialOfferDecoded);
200
- const scope = credentialOffer.credentials[0];
201
- const format = 'ldp_vc';
202
- const credentialTypes = scope.replace('ldp_vc:', '');
203
202
 
204
203
  const client = await OpenID4VCIClientV1_0_13.fromURI({
205
204
  uri: uri,
@@ -207,10 +206,14 @@ class CredentialService {
207
206
  authorizationRequest: {
208
207
  redirectUri: 'dock-wallet://credentials/callback',
209
208
  clientId: 'dock.wallet',
210
- scope: credentialOffer.credentials[0],
211
209
  },
212
210
  });
213
211
 
212
+ const format = 'ldp_vc';
213
+ const { scope } = client.getCredentialsSupported()[0];
214
+ const scopeSplit = scope.split(':');
215
+ const credentialTypes = scopeSplit[scopeSplit.length - 1];
216
+
214
217
  let code;
215
218
 
216
219
  if (client.credentialOffer?.preAuthorizedCode) {
@@ -229,7 +232,6 @@ class CredentialService {
229
232
  code,
230
233
  });
231
234
 
232
-
233
235
  try {
234
236
  const response = await client.acquireCredentials({
235
237
  credentialTypes,
@@ -245,6 +247,7 @@ class CredentialService {
245
247
  return jwt;
246
248
  },
247
249
  },
250
+ context: 'truverawallet',
248
251
  format: format,
249
252
  alg: Alg.EdDSA,
250
253
  kid: holderKeyDocument.id,
@@ -265,7 +268,7 @@ class CredentialService {
265
268
  const bbsPlusPresentation = new Presentation();
266
269
  for (const {credential, attributesToReveal} of credentials) {
267
270
  const idx = await bbsPlusPresentation.addCredentialToPresent(credential, {
268
- resolver: dockService.resolver,
271
+ resolver: blockchainService.resolver,
269
272
  });
270
273
  if (Array.isArray(attributesToReveal) && attributesToReveal.length > 0) {
271
274
  await bbsPlusPresentation.addAttributeToReveal(idx, attributesToReveal);
@@ -280,7 +283,7 @@ class CredentialService {
280
283
  return null;
281
284
  }
282
285
 
283
- return credential?.credentialStatus.id.replace('dock:accumulator:', '');
286
+ return credential?.credentialStatus.id;
284
287
  }
285
288
 
286
289
  async getAccumulatorData({credential}) {
@@ -291,7 +294,10 @@ class CredentialService {
291
294
  return null;
292
295
  }
293
296
 
294
- return getDock().accumulatorModule.getAccumulator(accumulatorId, false);
297
+ return blockchainService.dock.accumulatorModule.getAccumulator(
298
+ accumulatorId,
299
+ false,
300
+ );
295
301
  }
296
302
 
297
303
  /**
@@ -359,7 +365,7 @@ class CredentialService {
359
365
 
360
366
  for (const {credential} of credentials) {
361
367
  await presentation.addCredentialToPresent(credential, {
362
- resolver: dockService.resolver,
368
+ resolver: blockchainService.resolver,
363
369
  });
364
370
  }
365
371
 
@@ -404,10 +410,21 @@ class CredentialService {
404
410
 
405
411
  if (witness) {
406
412
  const details = await getWitnessDetails(credential, witness);
413
+ const chainModule =
414
+ credential.credentialStatus.id.indexOf('dock:accumulator') === 0
415
+ ? blockchainService.modules.accumulator.modules[0]
416
+ : blockchainService.modules.accumulator.modules[
417
+ blockchainService.modules.accumulator.modules.length - 1
418
+ ];
419
+ const accumulatorModuleClass = chainModule.constructor;
420
+
407
421
  presentation.presBuilder.addAccumInfoForCredStatus(
408
422
  idx,
409
423
  details.membershipWitness,
410
- details.accumulator.accumulated,
424
+ accumulatorModuleClass.accumulatedFromHex(
425
+ details.accumulator.accumulated,
426
+ AccumulatorType.VBPos,
427
+ ),
411
428
  details.pk,
412
429
  details.params,
413
430
  );
@@ -1,14 +1,7 @@
1
1
  import * as bs58 from 'base58-universal';
2
- import {generateEcdsaSecp256k1Keypair} from '@docknetwork/sdk/utils/misc';
3
- import {randomAsHex} from '@polkadot/util-crypto';
4
- import {u8aToHex} from '@polkadot/util';
5
- import Bls12381G2KeyPairDock2022 from '@docknetwork/sdk/utils/vc/crypto/Bls12381G2KeyPairDock2022';
6
- function createSecp256k1Keypair(privateKeyHex) {
7
- const pk = privateKeyHex || randomAsHex(32);
8
- const kp = generateEcdsaSecp256k1Keypair(pk);
9
- kp.pk = pk;
10
- return kp;
11
- }
2
+ import {Bls12381G2KeyPairDock2022} from '@docknetwork/credential-sdk/vc/crypto';
3
+ import {getKeyring} from '../keyring/service';
4
+
12
5
  const docToKeyMap = {
13
6
  Sr25519VerificationKey2020: 'sr25519',
14
7
  Ed25519VerificationKey2018: 'ed25519',
@@ -25,9 +18,7 @@ export function keyDocToKeypair(keyDoc, dock) {
25
18
  const privateKeyEncoded = privateKeyBase58 || privateKeyMultibase.substr(1);
26
19
  const privateKeyBytes = bs58.decode(privateKeyEncoded);
27
20
 
28
- if (type === 'EcdsaSecp256k1VerificationKey2019') {
29
- return createSecp256k1Keypair(u8aToHex(privateKeyBytes));
30
- } else if (type === 'Bls12381G2VerificationKeyDock2022') {
21
+ if (type === 'Bls12381G2VerificationKeyDock2022') {
31
22
  return new Bls12381G2KeyPairDock2022(keyDoc);
32
23
  } else {
33
24
  const publicKeyEncoded = publicKeyBase58 || publicKeyMultibase.substr(1);
@@ -36,7 +27,7 @@ export function keyDocToKeypair(keyDoc, dock) {
36
27
  throw new Error(`Unsupported key type: ${type}`);
37
28
  }
38
29
 
39
- return dock.keyring.createFromPair(
30
+ return getKeyring().createFromPair(
40
31
  {
41
32
  publicKey: bs58.decode(publicKeyEncoded),
42
33
  secretKey: privateKeyBytes,
@@ -23,6 +23,16 @@ export const validation = {
23
23
  assert(typeof type === 'string', 'invalid type');
24
24
  }
25
25
  },
26
+
27
+ deriveKeyDoc: ({ pair, type }: DeriveKeyDocParams) => {
28
+ assert(typeof pair === 'object', 'invalid pair');
29
+ assert(pair.publicKey instanceof Uint8Array, 'invalid publicKey');
30
+ assert(pair.secretKey instanceof Uint8Array, 'invalid secretKey');
31
+
32
+ if (type) {
33
+ assert(typeof type === 'string', 'invalid type');
34
+ }
35
+ },
26
36
  };
27
37
 
28
38
  export type KeypairToDIDKeyDocumentParams = {
@@ -39,3 +49,8 @@ export type GenerateKeyDocParams = {
39
49
  derivePath: string;
40
50
  keyPairJSON: any;
41
51
  };
52
+
53
+ export type DeriveKeyDocParams = {
54
+ pair: any;
55
+ type: string;
56
+ };