@docknetwork/wallet-sdk-wasm 1.7.7-alpha.0 → 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 (327) hide show
  1. package/package.json +7 -20
  2. package/rollup.config.mjs +1 -0
  3. package/src/globals.d.ts +4 -1
  4. package/src/services/blockchain/cached-did-resolver.ts +4 -3
  5. package/src/services/blockchain/normalize-did-document.ts +73 -0
  6. package/src/services/blockchain/service.ts +0 -2
  7. package/src/services/credential/bbs-revocation.test.js +147 -0
  8. package/src/services/credential/bbs-revocation.ts +65 -18
  9. package/src/services/credential/config.ts +7 -0
  10. package/src/services/credential/index.test.js +261 -17
  11. package/src/services/credential/oid4vci.js +44 -0
  12. package/src/services/credential/oid4vci.test.js +162 -0
  13. package/src/services/credential/pex-helpers.js +77 -31
  14. package/src/services/credential/pex-helpers.test.js +4 -4
  15. package/src/services/credential/sd-jwt.ts +41 -5
  16. package/src/services/credential/service-rpc.js +6 -0
  17. package/src/services/credential/service.ts +171 -16
  18. package/src/services/credential/utils.js +3 -5
  19. package/src/services/delegation/index.android.js +3 -0
  20. package/src/services/delegation/index.ios.js +3 -0
  21. package/src/services/delegation/index.ts +1 -0
  22. package/src/services/delegation/service-rpc.ts +21 -0
  23. package/src/services/delegation/service.ts +59 -0
  24. package/src/services/edv/service-rpc.js +18 -2
  25. package/src/services/edv/service.test.js +327 -0
  26. package/src/services/edv/service.ts +103 -13
  27. package/src/services/index.js +2 -0
  28. package/src/wallet/rpc-storage-interface.js +9 -4
  29. package/lib/core/crypto.js +0 -45
  30. package/lib/core/crypto.mjs +0 -33
  31. package/lib/core/format-utils.js +0 -51
  32. package/lib/core/format-utils.mjs +0 -42
  33. package/lib/core/keychain.js +0 -61
  34. package/lib/core/keychain.mjs +0 -37
  35. package/lib/core/logger.js +0 -13
  36. package/lib/core/logger.mjs +0 -9
  37. package/lib/core/storage.js +0 -14
  38. package/lib/core/storage.mjs +0 -9
  39. package/lib/core/validation.js +0 -29
  40. package/lib/core/validation.mjs +0 -16
  41. package/lib/core/webview-logger.js +0 -49
  42. package/lib/core/webview-logger.mjs +0 -41
  43. package/lib/errors.js +0 -17
  44. package/lib/errors.mjs +0 -12
  45. package/lib/events.js +0 -18
  46. package/lib/events.mjs +0 -13
  47. package/lib/index.js +0 -146
  48. package/lib/index.mjs +0 -144
  49. package/lib/logger.js +0 -22
  50. package/lib/logger.mjs +0 -17
  51. package/lib/modules/event-manager.js +0 -46
  52. package/lib/modules/event-manager.mjs +0 -37
  53. package/lib/modules/network-manager.js +0 -80
  54. package/lib/modules/network-manager.mjs +0 -71
  55. package/lib/mrklt.js +0 -2
  56. package/lib/mrklt.mjs +0 -1
  57. package/lib/rpc-client.js +0 -83
  58. package/lib/rpc-client.mjs +0 -73
  59. package/lib/rpc-server.js +0 -97
  60. package/lib/rpc-server.mjs +0 -95
  61. package/lib/rpc-util.js +0 -113
  62. package/lib/rpc-util.mjs +0 -103
  63. package/lib/sandbox-rpc-server.js +0 -28
  64. package/lib/sandbox-rpc-server.mjs +0 -26
  65. package/lib/sandbox.js +0 -102
  66. package/lib/sandbox.mjs +0 -100
  67. package/lib/services/blockchain/cached-did-resolver.js +0 -113
  68. package/lib/services/blockchain/cached-did-resolver.mjs +0 -109
  69. package/lib/services/blockchain/configs.js +0 -7
  70. package/lib/services/blockchain/configs.mjs +0 -3
  71. package/lib/services/blockchain/index.android.js +0 -18
  72. package/lib/services/blockchain/index.android.mjs +0 -14
  73. package/lib/services/blockchain/index.ios.js +0 -18
  74. package/lib/services/blockchain/index.ios.mjs +0 -14
  75. package/lib/services/blockchain/index.js +0 -36
  76. package/lib/services/blockchain/index.mjs +0 -28
  77. package/lib/services/blockchain/service-rpc.js +0 -72
  78. package/lib/services/blockchain/service-rpc.mjs +0 -68
  79. package/lib/services/blockchain/service.js +0 -312
  80. package/lib/services/blockchain/service.mjs +0 -306
  81. package/lib/services/credential/bbs-revocation.js +0 -92
  82. package/lib/services/credential/bbs-revocation.mjs +0 -87
  83. package/lib/services/credential/bound-check.js +0 -77
  84. package/lib/services/credential/bound-check.mjs +0 -64
  85. package/lib/services/credential/config.js +0 -56
  86. package/lib/services/credential/config.mjs +0 -47
  87. package/lib/services/credential/delegatable-credentials.js +0 -300
  88. package/lib/services/credential/delegatable-credentials.mjs +0 -263
  89. package/lib/services/credential/index.android.js +0 -19
  90. package/lib/services/credential/index.android.mjs +0 -15
  91. package/lib/services/credential/index.ios.js +0 -19
  92. package/lib/services/credential/index.ios.mjs +0 -15
  93. package/lib/services/credential/index.js +0 -106
  94. package/lib/services/credential/index.mjs +0 -67
  95. package/lib/services/credential/pex-helpers.js +0 -333
  96. package/lib/services/credential/pex-helpers.mjs +0 -319
  97. package/lib/services/credential/range-proofs-example.js +0 -107
  98. package/lib/services/credential/range-proofs-example.mjs +0 -103
  99. package/lib/services/credential/sd-jwt.js +0 -214
  100. package/lib/services/credential/sd-jwt.mjs +0 -200
  101. package/lib/services/credential/service-rpc.js +0 -61
  102. package/lib/services/credential/service-rpc.mjs +0 -57
  103. package/lib/services/credential/service.js +0 -683
  104. package/lib/services/credential/service.mjs +0 -672
  105. package/lib/services/credential/utils.js +0 -103
  106. package/lib/services/credential/utils.mjs +0 -78
  107. package/lib/services/dids/config.js +0 -40
  108. package/lib/services/dids/config.mjs +0 -31
  109. package/lib/services/dids/index.android.js +0 -19
  110. package/lib/services/dids/index.android.mjs +0 -15
  111. package/lib/services/dids/index.ios.js +0 -19
  112. package/lib/services/dids/index.ios.mjs +0 -15
  113. package/lib/services/dids/index.js +0 -23
  114. package/lib/services/dids/index.mjs +0 -19
  115. package/lib/services/dids/keypair-utils.js +0 -142
  116. package/lib/services/dids/keypair-utils.mjs +0 -113
  117. package/lib/services/dids/service-rpc.js +0 -37
  118. package/lib/services/dids/service-rpc.mjs +0 -33
  119. package/lib/services/dids/service.js +0 -100
  120. package/lib/services/dids/service.mjs +0 -92
  121. package/lib/services/edv/configs.js +0 -25
  122. package/lib/services/edv/configs.mjs +0 -16
  123. package/lib/services/edv/hmac.js +0 -88
  124. package/lib/services/edv/hmac.mjs +0 -63
  125. package/lib/services/edv/index.android.js +0 -19
  126. package/lib/services/edv/index.android.mjs +0 -15
  127. package/lib/services/edv/index.ios.js +0 -19
  128. package/lib/services/edv/index.ios.mjs +0 -15
  129. package/lib/services/edv/index.js +0 -32
  130. package/lib/services/edv/index.mjs +0 -24
  131. package/lib/services/edv/service-rpc.js +0 -78
  132. package/lib/services/edv/service-rpc.mjs +0 -74
  133. package/lib/services/edv/service.js +0 -370
  134. package/lib/services/edv/service.mjs +0 -357
  135. package/lib/services/index.js +0 -94
  136. package/lib/services/index.mjs +0 -92
  137. package/lib/services/pex/config.js +0 -29
  138. package/lib/services/pex/config.mjs +0 -20
  139. package/lib/services/pex/index.android.js +0 -19
  140. package/lib/services/pex/index.android.mjs +0 -15
  141. package/lib/services/pex/index.ios.js +0 -19
  142. package/lib/services/pex/index.ios.mjs +0 -15
  143. package/lib/services/pex/index.js +0 -12
  144. package/lib/services/pex/index.mjs +0 -4
  145. package/lib/services/pex/service-rpc.js +0 -39
  146. package/lib/services/pex/service-rpc.mjs +0 -35
  147. package/lib/services/pex/service.js +0 -91
  148. package/lib/services/pex/service.mjs +0 -86
  149. package/lib/services/pex/tests/jest.config.js +0 -25
  150. package/lib/services/pex/tests/jest.config.mjs +0 -23
  151. package/lib/services/relay-service/configs.js +0 -45
  152. package/lib/services/relay-service/configs.mjs +0 -36
  153. package/lib/services/relay-service/index.android.js +0 -21
  154. package/lib/services/relay-service/index.android.mjs +0 -17
  155. package/lib/services/relay-service/index.ios.js +0 -21
  156. package/lib/services/relay-service/index.ios.mjs +0 -17
  157. package/lib/services/relay-service/index.js +0 -14
  158. package/lib/services/relay-service/index.mjs +0 -6
  159. package/lib/services/relay-service/service-rpc.js +0 -47
  160. package/lib/services/relay-service/service-rpc.mjs +0 -43
  161. package/lib/services/relay-service/service.js +0 -181
  162. package/lib/services/relay-service/service.mjs +0 -173
  163. package/lib/services/rpc-service-client.js +0 -36
  164. package/lib/services/rpc-service-client.mjs +0 -28
  165. package/lib/services/sandbox.js +0 -10
  166. package/lib/services/sandbox.mjs +0 -8
  167. package/lib/services/storage/configs.js +0 -7
  168. package/lib/services/storage/configs.mjs +0 -3
  169. package/lib/services/storage/index.android.js +0 -18
  170. package/lib/services/storage/index.android.mjs +0 -14
  171. package/lib/services/storage/index.ios.js +0 -18
  172. package/lib/services/storage/index.ios.mjs +0 -14
  173. package/lib/services/storage/index.js +0 -26
  174. package/lib/services/storage/index.mjs +0 -24
  175. package/lib/services/storage/service-rpc.js +0 -37
  176. package/lib/services/storage/service-rpc.mjs +0 -33
  177. package/lib/services/storage/service.js +0 -32
  178. package/lib/services/storage/service.mjs +0 -27
  179. package/lib/services/test-utils.js +0 -98
  180. package/lib/services/test-utils.mjs +0 -84
  181. package/lib/services/util-crypto/configs.js +0 -23
  182. package/lib/services/util-crypto/configs.mjs +0 -15
  183. package/lib/services/util-crypto/index.android.js +0 -19
  184. package/lib/services/util-crypto/index.android.mjs +0 -15
  185. package/lib/services/util-crypto/index.ios.js +0 -19
  186. package/lib/services/util-crypto/index.ios.mjs +0 -15
  187. package/lib/services/util-crypto/index.js +0 -14
  188. package/lib/services/util-crypto/index.mjs +0 -6
  189. package/lib/services/util-crypto/service-rpc.js +0 -42
  190. package/lib/services/util-crypto/service-rpc.mjs +0 -38
  191. package/lib/services/util-crypto/service.js +0 -108
  192. package/lib/services/util-crypto/service.mjs +0 -83
  193. package/lib/services/wallet/configs.js +0 -32
  194. package/lib/services/wallet/configs.mjs +0 -23
  195. package/lib/services/wallet/index.android.js +0 -21
  196. package/lib/services/wallet/index.android.mjs +0 -17
  197. package/lib/services/wallet/index.ios.js +0 -21
  198. package/lib/services/wallet/index.ios.mjs +0 -17
  199. package/lib/services/wallet/index.js +0 -17
  200. package/lib/services/wallet/index.mjs +0 -9
  201. package/lib/services/wallet/service-rpc.js +0 -33
  202. package/lib/services/wallet/service-rpc.mjs +0 -29
  203. package/lib/services/wallet/service.js +0 -62
  204. package/lib/services/wallet/service.mjs +0 -57
  205. package/lib/setup-nodejs.js +0 -93
  206. package/lib/setup-nodejs.mjs +0 -91
  207. package/lib/setup-tests.js +0 -92
  208. package/lib/setup-tests.mjs +0 -90
  209. package/lib/src/core/crypto.d.ts +0 -8
  210. package/lib/src/core/crypto.d.ts.map +0 -1
  211. package/lib/src/core/format-utils.d.ts +0 -26
  212. package/lib/src/core/format-utils.d.ts.map +0 -1
  213. package/lib/src/core/logger.d.ts +0 -3
  214. package/lib/src/core/logger.d.ts.map +0 -1
  215. package/lib/src/core/storage.d.ts +0 -8
  216. package/lib/src/core/storage.d.ts.map +0 -1
  217. package/lib/src/core/validation.d.ts +0 -6
  218. package/lib/src/core/validation.d.ts.map +0 -1
  219. package/lib/src/errors.d.ts +0 -7
  220. package/lib/src/errors.d.ts.map +0 -1
  221. package/lib/src/logger.d.ts +0 -5
  222. package/lib/src/logger.d.ts.map +0 -1
  223. package/lib/src/modules/event-manager.d.ts +0 -12
  224. package/lib/src/modules/event-manager.d.ts.map +0 -1
  225. package/lib/src/modules/network-manager.d.ts +0 -32
  226. package/lib/src/modules/network-manager.d.ts.map +0 -1
  227. package/lib/src/rpc-client.d.ts +0 -4
  228. package/lib/src/rpc-client.d.ts.map +0 -1
  229. package/lib/src/rpc-util.d.ts +0 -11
  230. package/lib/src/rpc-util.d.ts.map +0 -1
  231. package/lib/src/services/blockchain/cached-did-resolver.d.ts +0 -28
  232. package/lib/src/services/blockchain/cached-did-resolver.d.ts.map +0 -1
  233. package/lib/src/services/blockchain/cached-did-resolver.test.d.ts +0 -2
  234. package/lib/src/services/blockchain/cached-did-resolver.test.d.ts.map +0 -1
  235. package/lib/src/services/blockchain/configs.d.ts +0 -7
  236. package/lib/src/services/blockchain/configs.d.ts.map +0 -1
  237. package/lib/src/services/blockchain/service.d.ts +0 -155
  238. package/lib/src/services/blockchain/service.d.ts.map +0 -1
  239. package/lib/src/services/credential/bbs-revocation.d.ts +0 -10
  240. package/lib/src/services/credential/bbs-revocation.d.ts.map +0 -1
  241. package/lib/src/services/credential/bound-check.d.ts +0 -61
  242. package/lib/src/services/credential/bound-check.d.ts.map +0 -1
  243. package/lib/src/services/credential/bound-check.test.d.ts +0 -2
  244. package/lib/src/services/credential/bound-check.test.d.ts.map +0 -1
  245. package/lib/src/services/credential/config.d.ts +0 -10
  246. package/lib/src/services/credential/config.d.ts.map +0 -1
  247. package/lib/src/services/credential/delegatable-credentials.d.ts +0 -272
  248. package/lib/src/services/credential/delegatable-credentials.d.ts.map +0 -1
  249. package/lib/src/services/credential/index.d.ts +0 -35
  250. package/lib/src/services/credential/index.d.ts.map +0 -1
  251. package/lib/src/services/credential/pex-helpers.d.ts +0 -23
  252. package/lib/src/services/credential/pex-helpers.d.ts.map +0 -1
  253. package/lib/src/services/credential/range-proofs-example.d.ts +0 -2
  254. package/lib/src/services/credential/range-proofs-example.d.ts.map +0 -1
  255. package/lib/src/services/credential/sd-jwt.test.d.ts +0 -2
  256. package/lib/src/services/credential/sd-jwt.test.d.ts.map +0 -1
  257. package/lib/src/services/credential/service.d.ts +0 -313
  258. package/lib/src/services/credential/service.d.ts.map +0 -1
  259. package/lib/src/services/credential/utils.d.ts +0 -3
  260. package/lib/src/services/credential/utils.d.ts.map +0 -1
  261. package/lib/src/services/dids/config.d.ts +0 -24
  262. package/lib/src/services/dids/config.d.ts.map +0 -1
  263. package/lib/src/services/dids/keypair-utils.d.ts +0 -15
  264. package/lib/src/services/dids/keypair-utils.d.ts.map +0 -1
  265. package/lib/src/services/dids/service-rpc.d.ts +0 -11
  266. package/lib/src/services/dids/service-rpc.d.ts.map +0 -1
  267. package/lib/src/services/dids/service.d.ts +0 -70
  268. package/lib/src/services/dids/service.d.ts.map +0 -1
  269. package/lib/src/services/edv/configs.d.ts +0 -12
  270. package/lib/src/services/edv/configs.d.ts.map +0 -1
  271. package/lib/src/services/edv/hmac.d.ts +0 -29
  272. package/lib/src/services/edv/hmac.d.ts.map +0 -1
  273. package/lib/src/services/edv/service.d.ts +0 -229
  274. package/lib/src/services/edv/service.d.ts.map +0 -1
  275. package/lib/src/services/pex/config.d.ts +0 -21
  276. package/lib/src/services/pex/config.d.ts.map +0 -1
  277. package/lib/src/services/pex/service.d.ts +0 -21
  278. package/lib/src/services/pex/service.d.ts.map +0 -1
  279. package/lib/src/services/relay-service/configs.d.ts +0 -35
  280. package/lib/src/services/relay-service/configs.d.ts.map +0 -1
  281. package/lib/src/services/relay-service/service-rpc.d.ts +0 -12
  282. package/lib/src/services/relay-service/service-rpc.d.ts.map +0 -1
  283. package/lib/src/services/relay-service/service.d.ts +0 -159
  284. package/lib/src/services/relay-service/service.d.ts.map +0 -1
  285. package/lib/src/services/rpc-service-client.d.ts +0 -7
  286. package/lib/src/services/rpc-service-client.d.ts.map +0 -1
  287. package/lib/src/services/storage/configs.d.ts +0 -2
  288. package/lib/src/services/storage/configs.d.ts.map +0 -1
  289. package/lib/src/services/storage/index.d.ts +0 -2
  290. package/lib/src/services/storage/index.d.ts.map +0 -1
  291. package/lib/src/services/storage/service-rpc.d.ts +0 -9
  292. package/lib/src/services/storage/service-rpc.d.ts.map +0 -1
  293. package/lib/src/services/storage/service.d.ts +0 -10
  294. package/lib/src/services/storage/service.d.ts.map +0 -1
  295. package/lib/src/services/util-crypto/configs.d.ts +0 -5
  296. package/lib/src/services/util-crypto/configs.d.ts.map +0 -1
  297. package/lib/src/services/util-crypto/index.d.ts +0 -2
  298. package/lib/src/services/util-crypto/index.d.ts.map +0 -1
  299. package/lib/src/services/util-crypto/service.d.ts +0 -10
  300. package/lib/src/services/util-crypto/service.d.ts.map +0 -1
  301. package/lib/src/services/wallet/configs.d.ts +0 -13
  302. package/lib/src/services/wallet/configs.d.ts.map +0 -1
  303. package/lib/src/services/wallet/service.d.ts +0 -13
  304. package/lib/src/services/wallet/service.d.ts.map +0 -1
  305. package/lib/src/types.d.ts +0 -12
  306. package/lib/src/types.d.ts.map +0 -1
  307. package/lib/src/wallet/memory-storage-interface.d.ts +0 -31
  308. package/lib/src/wallet/memory-storage-interface.d.ts.map +0 -1
  309. package/lib/src/wallet/memory-storage-wallet.d.ts +0 -6
  310. package/lib/src/wallet/memory-storage-wallet.d.ts.map +0 -1
  311. package/lib/src/wallet/rpc-storage-interface.d.ts +0 -32
  312. package/lib/src/wallet/rpc-storage-interface.d.ts.map +0 -1
  313. package/lib/src/wallet/rpc-storage-wallet.d.ts +0 -6
  314. package/lib/src/wallet/rpc-storage-wallet.d.ts.map +0 -1
  315. package/lib/test-utils.js +0 -46
  316. package/lib/test-utils.mjs +0 -38
  317. package/lib/tsconfig.tsbuildinfo +0 -1
  318. package/lib/types.js +0 -7
  319. package/lib/types.mjs +0 -3
  320. package/lib/wallet/memory-storage-interface.js +0 -101
  321. package/lib/wallet/memory-storage-interface.mjs +0 -95
  322. package/lib/wallet/memory-storage-wallet.js +0 -30
  323. package/lib/wallet/memory-storage-wallet.mjs +0 -24
  324. package/lib/wallet/rpc-storage-interface.js +0 -134
  325. package/lib/wallet/rpc-storage-interface.mjs +0 -128
  326. package/lib/wallet/rpc-storage-wallet.js +0 -46
  327. package/lib/wallet/rpc-storage-wallet.mjs +0 -40
@@ -3,12 +3,40 @@ import {digest, generateSalt} from '@sd-jwt/crypto-nodejs';
3
3
  import base64url from 'base64url';
4
4
 
5
5
  /**
6
- * Checks if a JWT string is an SD-JWT credential
6
+ * Checks if a value is a decoded SD-JWT payload object — i.e. an SD-JWT VC
7
+ * payload returned as JSON rather than the compact `header.payload.sig~...` form.
7
8
  */
8
- export function isSDJWTCredential(jwt) {
9
- const jwtHeader = jwt.split('.')[0];
10
- const decodedHeader = JSON.parse(base64url.decode(jwtHeader));
11
- return decodedHeader.typ === 'dc+sd-jwt' || decodedHeader.typ === 'vc+sd-jwt';
9
+ export function isDecodedSDJWTPayload(value): boolean {
10
+ return (
11
+ !!value &&
12
+ typeof value === 'object' &&
13
+ !Array.isArray(value) &&
14
+ Array.isArray((value as any)._sd) &&
15
+ typeof (value as any)._sd_alg === 'string'
16
+ );
17
+ }
18
+
19
+ /**
20
+ * Checks if a credential is an SD-JWT credential.
21
+ * Accepts either the compact SD-JWT string or a decoded SD-JWT VC payload object.
22
+ */
23
+ export function isSDJWTCredential(credential) {
24
+ if (isDecodedSDJWTPayload(credential)) {
25
+ return true;
26
+ }
27
+
28
+ if (typeof credential !== 'string' || !credential.includes('.')) {
29
+ return false;
30
+ }
31
+
32
+ try {
33
+ const decodedHeader = JSON.parse(base64url.decode(credential.split('.')[0]));
34
+ return (
35
+ decodedHeader?.typ === 'dc+sd-jwt' || decodedHeader?.typ === 'vc+sd-jwt'
36
+ );
37
+ } catch {
38
+ return false;
39
+ }
12
40
  }
13
41
 
14
42
  export async function createSDJWTPresentation({
@@ -200,6 +228,11 @@ export async function decodeSDJWTToW3C(sdJwtString) {
200
228
  * @returns {Promise<Object>} W3C Verifiable Credential format
201
229
  */
202
230
  export async function credentialToW3C(credential) {
231
+ // Decoded SD-JWT VC payload (no compact serialization available)
232
+ if (isDecodedSDJWTPayload(credential)) {
233
+ return sdJwtToW3C({jwt: {header: {}, payload: credential}, disclosures: []});
234
+ }
235
+
203
236
  // If it's already an object with a type field, assume it's already W3C format
204
237
  if (typeof credential === 'object' && credential.type) {
205
238
  return credential;
@@ -210,6 +243,9 @@ export async function credentialToW3C(credential) {
210
243
  // First try to parse as JSON
211
244
  try {
212
245
  const parsed = JSON.parse(credential);
246
+ if (isDecodedSDJWTPayload(parsed)) {
247
+ return sdJwtToW3C({jwt: {header: {}, payload: parsed}, disclosures: []});
248
+ }
213
249
  if (parsed.type) {
214
250
  return parsed;
215
251
  }
@@ -44,4 +44,10 @@ export class CredentialServiceRPC extends RpcService {
44
44
  async acquireOIDCredential(params) {
45
45
  return this.call('acquireOIDCredential', params);
46
46
  }
47
+ async generatePresentationFromPex(params) {
48
+ return this.call('generatePresentationFromPex', params);
49
+ }
50
+ async prefetchWitnessCache(params) {
51
+ return this.call('prefetchWitnessCache', params);
52
+ }
47
53
  }
@@ -18,10 +18,10 @@ import {OpenID4VCIClientV1_0_13} from '@sphereon/oid4vci-client';
18
18
  import {Alg} from '@sphereon/oid4vci-common';
19
19
  import {getKeypairFromDoc} from '@docknetwork/universal-wallet/methods/keypairs';
20
20
  import {hexToU8a} from '@docknetwork/credential-sdk/utils';
21
+ import * as credentialSdkVc from '@docknetwork/credential-sdk/vc';
21
22
  import {
22
23
  VerifiablePresentation,
23
24
  Presentation,
24
- verifyCredential,
25
25
  verifyPresentation,
26
26
  VerifiableCredential,
27
27
  getSuiteFromKeyDoc,
@@ -33,20 +33,100 @@ import {
33
33
  applyEnforceBounds,
34
34
  hasProvingKey,
35
35
  fetchProvingKey,
36
+ isBase64OrDataUrl,
37
+ blobFromBase64,
38
+ fetchBlobFromUrl,
36
39
  } from './bound-check';
40
+ import {
41
+ generatePresentationFromPexRequest,
42
+ GeneratePresentationStatus,
43
+ } from '@docknetwork/credential-sdk/pex';
44
+ import {LegoProvingKey} from '@docknetwork/crypto-wasm-ts/lib/legosnark';
37
45
  import assert from 'assert';
38
46
  import axios from 'axios';
39
- import {getIsRevoked, getWitnessDetails} from './bbs-revocation';
40
- import {getPexRequiredAttributes, shouldSkipAttribute} from './pex-helpers';
47
+ import {getIsRevoked, getWitnessDetails, prefetchWitnessCache} from './bbs-revocation';
48
+ import {getPexRequiredAttributes, shouldSkipAttribute, findMatchingDescriptor} from './pex-helpers';
41
49
  import {didService} from '../dids/service';
42
50
  import {isSDJWTCredential as checkIsSDJWT, credentialToW3C as convertCredentialToW3C, verifySDJWT, createSDJWTPresentation} from './sd-jwt';
51
+ import {resolveOfferedCredentialConfig, resolveFormatAndType} from './oid4vci';
52
+
43
53
 
54
+ export const credentialUtils = {...credentialSdkVc};
55
+ export const pexUtils = {
56
+ generatePresentationFromPexRequest,
57
+ GeneratePresentationStatus,
58
+ };
44
59
  /**
45
60
  * PEX (Presentation Exchange) instance for credential filtering
46
61
  * @private
47
62
  */
48
63
  const pex: PEX = new PEX();
49
64
 
65
+ /**
66
+ * Resolves the accumulator module class for a credential based on its status ID.
67
+ */
68
+ function getAccumulatorModuleClass(credential) {
69
+ const statusId = credential?.credentialStatus?.id;
70
+ if (!statusId) {
71
+ throw new Error('Credential is missing credentialStatus.id required for witness resolution');
72
+ }
73
+ const chainModule =
74
+ statusId.indexOf('dock:accumulator') === 0
75
+ ? blockchainService.modules.accumulator.modules[0]
76
+ : blockchainService.modules.accumulator.modules[
77
+ blockchainService.modules.accumulator.modules.length - 1
78
+ ];
79
+ return chainModule.constructor;
80
+ }
81
+
82
+ /**
83
+ * Resolves the witness for a single credential into the format expected by credential-sdk.
84
+ * Returns undefined if the credential has no witness.
85
+ */
86
+ async function resolveWitnessForCredential(credential, witness) {
87
+ if (!witness) {
88
+ return undefined;
89
+ }
90
+
91
+ try {
92
+ const details = await getWitnessDetails(credential, witness);
93
+ const accumulatorModuleClass = getAccumulatorModuleClass(credential);
94
+ return {
95
+ membershipWitness: details.membershipWitness,
96
+ accumulated: accumulatorModuleClass.accumulatedFromHex(
97
+ details.accumulator.accumulated,
98
+ AccumulatorType.VBPos,
99
+ ),
100
+ pk: details.pk,
101
+ params: details.params,
102
+ };
103
+ } catch (err) {
104
+ throw new Error(
105
+ `Failed to resolve witness for credential ${credential?.id || 'unknown'}: ${err.message}`,
106
+ );
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Creates a loadProvingKey callback for bound check proofs.
112
+ * Returns undefined if no boundCheckSnarkKey is provided.
113
+ */
114
+ function createProvingKeyLoader(boundCheckSnarkKey) {
115
+ if (!boundCheckSnarkKey) {
116
+ return undefined;
117
+ }
118
+
119
+ return async () => {
120
+ const blob = (await isBase64OrDataUrl(boundCheckSnarkKey))
121
+ ? blobFromBase64(boundCheckSnarkKey)
122
+ : await fetchBlobFromUrl(boundCheckSnarkKey);
123
+ return {
124
+ provingKey: new LegoProvingKey(blob),
125
+ provingKeyId: 'key0',
126
+ };
127
+ };
128
+ }
129
+
50
130
  /**
51
131
  * Checks if a credential uses BBS+ signature
52
132
  * @param {Object} credential - The credential to check
@@ -122,8 +202,15 @@ class CredentialService {
122
202
  CredentialService.prototype.credentialToW3C,
123
203
  CredentialService.prototype.createSDJWTPresentation,
124
204
  CredentialService.prototype.acquireOIDCredential,
205
+ CredentialService.prototype.generatePresentationFromPex,
206
+ CredentialService.prototype.prefetchWitnessCache,
125
207
  ];
126
208
 
209
+ async prefetchWitnessCache(params) {
210
+ const {credential, membershipWitness} = params;
211
+ return prefetchWitnessCache(credential, membershipWitness);
212
+ }
213
+
127
214
 
128
215
  createSDJWTPresentation(params) {
129
216
  const {attributesToReveal, credential} = params;
@@ -285,7 +372,7 @@ class CredentialService {
285
372
  return verifySDJWT(credential);
286
373
  }
287
374
 
288
- const result = await verifyCredential(credential, {
375
+ const result = await credentialUtils.verifyCredential(credential, {
289
376
  resolver: blockchainService.resolver,
290
377
  revocationApi: {dock: blockchainService.dock},
291
378
  });
@@ -454,10 +541,8 @@ class CredentialService {
454
541
  },
455
542
  });
456
543
 
457
- const format = 'ldp_vc';
458
- const { scope } = client.getCredentialsSupported()[0];
459
- const scopeSplit = scope.split(':');
460
- const credentialTypes = scopeSplit[scopeSplit.length - 1];
544
+ const config = resolveOfferedCredentialConfig(client);
545
+ const {format, credentialTypes} = resolveFormatAndType(config);
461
546
 
462
547
  let code;
463
548
 
@@ -526,7 +611,7 @@ class CredentialService {
526
611
  validation.createBBSPresentation(params);
527
612
  const {credentials} = params;
528
613
 
529
- const bbsPlusPresentation = new Presentation();
614
+ const bbsPlusPresentation = new credentialUtils.Presentation();
530
615
  for (const {credential, attributesToReveal} of credentials) {
531
616
  const idx = await bbsPlusPresentation.addCredentialToPresent(credential, {
532
617
  resolver: blockchainService.resolver,
@@ -658,7 +743,7 @@ class CredentialService {
658
743
  async deriveVCFromPresentation(params) {
659
744
  validation.deriveVCFromPresentation(params);
660
745
  const {credentials, options = {}, proofRequest} = params;
661
- const presentation = new Presentation();
746
+ const presentation = new credentialUtils.Presentation();
662
747
  const selectedCredentials = credentials.map(({credential}) => credential);
663
748
  let descriptorBounds = [];
664
749
 
@@ -668,11 +753,31 @@ class CredentialService {
668
753
  });
669
754
  }
670
755
 
671
- if (proofRequest && hasProvingKey(proofRequest)) {
672
- const {provingKey, provingKeyId} = await fetchProvingKey(proofRequest);
756
+ // Filter proof request descriptors to only those matching the provided
757
+ // credentials. This ensures correct mapping when credentials are provided
758
+ // in a different order than the proof request's input_descriptors.
759
+ let filteredProofRequest = proofRequest;
760
+ if (proofRequest?.request?.input_descriptors?.length > 1) {
761
+ const matchedDescriptors = selectedCredentials.map(credential =>
762
+ findMatchingDescriptor(proofRequest.request.input_descriptors, credential),
763
+ ).filter(Boolean);
764
+
765
+ if (matchedDescriptors.length > 0) {
766
+ filteredProofRequest = {
767
+ ...proofRequest,
768
+ request: {
769
+ ...proofRequest.request,
770
+ input_descriptors: matchedDescriptors,
771
+ },
772
+ };
773
+ }
774
+ }
775
+
776
+ if (filteredProofRequest && hasProvingKey(filteredProofRequest)) {
777
+ const {provingKey, provingKeyId} = await fetchProvingKey(filteredProofRequest);
673
778
  descriptorBounds = applyEnforceBounds({
674
779
  builder: presentation.presBuilder,
675
- proofRequest,
780
+ proofRequest: filteredProofRequest,
676
781
  provingKey,
677
782
  provingKeyId,
678
783
  selectedCredentials,
@@ -680,9 +785,9 @@ class CredentialService {
680
785
  }
681
786
 
682
787
  let pexRequiredAttributes = [];
683
- if (proofRequest?.request) {
788
+ if (filteredProofRequest?.request) {
684
789
  pexRequiredAttributes = getPexRequiredAttributes(
685
- proofRequest.request,
790
+ filteredProofRequest.request,
686
791
  selectedCredentials,
687
792
  );
688
793
  }
@@ -692,7 +797,9 @@ class CredentialService {
692
797
  const attributesToSkip = descriptorBounds[idx]
693
798
  ? descriptorBounds[idx].map(bound => bound.attributeName)
694
799
  : [];
695
- const filteredAttributes = attributesToReveal.filter(
800
+ // attributesToReveal may be undefined when using default presentation generation,
801
+ // in which case only PEX-required attributes will be revealed
802
+ const filteredAttributes = (attributesToReveal || []).filter(
696
803
  attribute => !attributesToSkip.includes(attribute) && !shouldSkipAttribute(attribute),
697
804
  );
698
805
  const _pexRequiredAttributes = pexRequiredAttributes[idx] || [];
@@ -739,6 +846,54 @@ class CredentialService {
739
846
  return credentialsFromPresentation;
740
847
  }
741
848
 
849
+ async generatePresentationFromPex(params) {
850
+ validation.generatePresentationFromPex(params);
851
+ const {
852
+ credentials,
853
+ pexRequest,
854
+ holderKeyDoc,
855
+ holderDid,
856
+ challenge,
857
+ domain,
858
+ boundCheckSnarkKey,
859
+ skipSigning,
860
+ } = params;
861
+
862
+ const resolvedWitnesses = await Promise.all(
863
+ credentials.map(c => resolveWitnessForCredential(c.credential, c.witness)),
864
+ );
865
+
866
+ let resolvedKeyDoc = holderKeyDoc;
867
+ if (!skipSigning && holderKeyDoc) {
868
+ resolvedKeyDoc = getKeypairFromDoc(holderKeyDoc);
869
+ resolvedKeyDoc.signer = resolvedKeyDoc.signer();
870
+ }
871
+
872
+ const result = await pexUtils.generatePresentationFromPexRequest({
873
+ credentials: credentials.map(c => c.credential),
874
+ pexRequest,
875
+ holderKeyDoc: resolvedKeyDoc,
876
+ holderDid,
877
+ challenge,
878
+ domain,
879
+ resolver: blockchainService.resolver,
880
+ skipSigning: skipSigning || false,
881
+ loadProvingKey: createProvingKeyLoader(boundCheckSnarkKey),
882
+ selectiveDisclosure: {
883
+ credentials: credentials.map((c, i) => ({
884
+ attributes: [...(c.attributesToReveal || []), 'id'],
885
+ witness: resolvedWitnesses[i],
886
+ })),
887
+ },
888
+ });
889
+
890
+ if (result.status !== pexUtils.GeneratePresentationStatus.SUCCESS) {
891
+ throw result.error || new Error(`Presentation generation failed: ${result.status}`);
892
+ }
893
+
894
+ return result.presentation;
895
+ }
896
+
742
897
  /**
743
898
  * Test method for range proofs
744
899
  * @private
@@ -30,11 +30,9 @@ export async function keyDocToKeypair(keyDoc) {
30
30
  privateKeyBase58 || (privateKeyMultibase && privateKeyMultibase.substr(1));
31
31
  if (!privateKeyEncoded) {
32
32
  throw new Error(
33
- `No private key in document found, this should not happen. Got: ${JSON.stringify(
34
- keyDoc,
35
- null,
36
- 2,
37
- )}`,
33
+ `No private key in document found, this should not happen. keyDoc id: ${
34
+ keyDoc.id || '<unknown>'
35
+ }, type: ${type || '<unknown>'}`,
38
36
  );
39
37
  }
40
38
 
@@ -0,0 +1,3 @@
1
+ import {DelegationServiceRpc} from './service-rpc';
2
+
3
+ export const delegationService = new DelegationServiceRpc();
@@ -0,0 +1,3 @@
1
+ import {DelegationServiceRpc} from './service-rpc';
2
+
3
+ export const delegationService = new DelegationServiceRpc();
@@ -0,0 +1 @@
1
+ export {delegationService} from './service';
@@ -0,0 +1,21 @@
1
+ import {RpcService} from '../rpc-service-client';
2
+ /**
3
+ *
4
+ */
5
+ export class DelegationServiceRpc extends RpcService {
6
+ constructor() {
7
+ super('delegation');
8
+ }
9
+
10
+ async issueCredential(keyPair, credential) {
11
+ return this.call('issueCredential', keyPair, credential);
12
+ }
13
+
14
+ async computePolicyDigestHex(policyObject) {
15
+ return this.call('computePolicyDigestHex', policyObject);
16
+ }
17
+
18
+ async fetchDelegationPolicyJson(policyId) {
19
+ return this.call('fetchDelegationPolicyJson', policyId);
20
+ }
21
+ }
@@ -0,0 +1,59 @@
1
+ // @ts-nocheck
2
+
3
+ import {issueCredential, documentLoader} from '@docknetwork/credential-sdk/vc';
4
+ import {
5
+ computePolicyDigestHex,
6
+ fetchDelegationPolicyJson,
7
+ } from '@docknetwork/vc-delegation-engine';
8
+
9
+ import {getKeypairFromDoc} from '@docknetwork/universal-wallet/methods/keypairs';
10
+ import {blockchainService} from '../blockchain/service';
11
+
12
+ /**
13
+ * Prepares a key document for signing by creating a proper keypair with signer capability
14
+ * @param keyDoc - The key document with id, controller, type, and key material
15
+ * @returns A key document with an active signer
16
+ */
17
+ function prepareKeyForSigning(keyDoc): any {
18
+ const kp = getKeypairFromDoc(keyDoc);
19
+ // Get the signer from the keypair - this returns an object with id and sign method
20
+ const signer = kp.signer();
21
+ // Set the id on the signer to match the verification method
22
+ signer.id = keyDoc.id;
23
+ return {
24
+ ...keyDoc,
25
+ keypair: kp,
26
+ signer,
27
+ };
28
+ }
29
+
30
+ /**
31
+ * Service class for delegatable credentials operations
32
+ */
33
+ class DelegationService {
34
+ name = 'delegation';
35
+
36
+ rpcMethods = [
37
+ DelegationService.prototype.issueCredential,
38
+ DelegationService.prototype.computePolicyDigestHex,
39
+ DelegationService.prototype.fetchDelegationPolicyJson,
40
+ ];
41
+
42
+ async issueCredential(keyPair, credential): Promise<Credential> {
43
+ const preparedKey = prepareKeyForSigning(keyPair);
44
+ return issueCredential(preparedKey, credential);
45
+ }
46
+
47
+ async computePolicyDigestHex(policyObject): Promise<string> {
48
+ return computePolicyDigestHex(policyObject);
49
+ }
50
+
51
+ async fetchDelegationPolicyJson(policyId: string): Promise<any> {
52
+ return fetchDelegationPolicyJson(
53
+ documentLoader(blockchainService.resolver),
54
+ policyId,
55
+ );
56
+ }
57
+ }
58
+
59
+ export const delegationService = new DelegationService();
@@ -11,12 +11,28 @@ export class EDVServiceRpc extends RpcService {
11
11
  return this.call('initialize', params);
12
12
  }
13
13
 
14
+ initializeFromMnemonic(params: {
15
+ mnemonic: string,
16
+ edvUrl: string,
17
+ authKey: string,
18
+ }) {
19
+ return this.call('initializeFromMnemonic', params);
20
+ }
21
+
22
+ initializeFromMasterKey(params: {
23
+ masterKey: any,
24
+ edvUrl: string,
25
+ authKey: string,
26
+ }) {
27
+ return this.call('initializeFromMasterKey', params);
28
+ }
29
+
14
30
  generateKeys() {
15
31
  return this.call('generateKeys');
16
32
  }
17
33
 
18
- deriveKeys() {
19
- return this.call('deriveKeys');
34
+ deriveKeys(masterKey) {
35
+ return this.call('deriveKeys', masterKey);
20
36
  }
21
37
 
22
38
  getController() {