@enbox/agent 0.0.1

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 (348) hide show
  1. package/dist/browser.js +2215 -0
  2. package/dist/browser.js.map +7 -0
  3. package/dist/browser.mjs +2215 -0
  4. package/dist/browser.mjs.map +7 -0
  5. package/dist/cjs/index.js +8530 -0
  6. package/dist/cjs/index.js.map +7 -0
  7. package/dist/cjs/package.json +1 -0
  8. package/dist/esm/agent-did-resolver-cache.js +87 -0
  9. package/dist/esm/agent-did-resolver-cache.js.map +1 -0
  10. package/dist/esm/bearer-identity.js +41 -0
  11. package/dist/esm/bearer-identity.js.map +1 -0
  12. package/dist/esm/connect.js +191 -0
  13. package/dist/esm/connect.js.map +1 -0
  14. package/dist/esm/crypto-api.js +346 -0
  15. package/dist/esm/crypto-api.js.map +1 -0
  16. package/dist/esm/did-api.js +278 -0
  17. package/dist/esm/did-api.js.map +1 -0
  18. package/dist/esm/dwn-api.js +336 -0
  19. package/dist/esm/dwn-api.js.map +1 -0
  20. package/dist/esm/dwn-registrar.js +120 -0
  21. package/dist/esm/dwn-registrar.js.map +1 -0
  22. package/dist/esm/hd-identity-vault.js +729 -0
  23. package/dist/esm/hd-identity-vault.js.map +1 -0
  24. package/dist/esm/identity-api.js +262 -0
  25. package/dist/esm/identity-api.js.map +1 -0
  26. package/dist/esm/index.js +23 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/local-key-manager.js +498 -0
  29. package/dist/esm/local-key-manager.js.map +1 -0
  30. package/dist/esm/oidc.js +507 -0
  31. package/dist/esm/oidc.js.map +1 -0
  32. package/dist/esm/permissions-api.js +322 -0
  33. package/dist/esm/permissions-api.js.map +1 -0
  34. package/dist/esm/prototyping/clients/dwn-rpc-types.js +2 -0
  35. package/dist/esm/prototyping/clients/dwn-rpc-types.js.map +1 -0
  36. package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js +74 -0
  37. package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js.map +1 -0
  38. package/dist/esm/prototyping/clients/http-dwn-rpc-client.js +105 -0
  39. package/dist/esm/prototyping/clients/http-dwn-rpc-client.js.map +1 -0
  40. package/dist/esm/prototyping/clients/json-rpc-socket.js +150 -0
  41. package/dist/esm/prototyping/clients/json-rpc-socket.js.map +1 -0
  42. package/dist/esm/prototyping/clients/json-rpc.js +58 -0
  43. package/dist/esm/prototyping/clients/json-rpc.js.map +1 -0
  44. package/dist/esm/prototyping/clients/server-info-types.js +2 -0
  45. package/dist/esm/prototyping/clients/server-info-types.js.map +1 -0
  46. package/dist/esm/prototyping/clients/web-socket-clients.js +90 -0
  47. package/dist/esm/prototyping/clients/web-socket-clients.js.map +1 -0
  48. package/dist/esm/prototyping/common/object.js +14 -0
  49. package/dist/esm/prototyping/common/object.js.map +1 -0
  50. package/dist/esm/prototyping/common/type-utils.js +2 -0
  51. package/dist/esm/prototyping/common/type-utils.js.map +1 -0
  52. package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js +147 -0
  53. package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js.map +1 -0
  54. package/dist/esm/prototyping/crypto/algorithms/aes-kw.js +137 -0
  55. package/dist/esm/prototyping/crypto/algorithms/aes-kw.js.map +1 -0
  56. package/dist/esm/prototyping/crypto/algorithms/ecdsa.js +307 -0
  57. package/dist/esm/prototyping/crypto/algorithms/ecdsa.js.map +1 -0
  58. package/dist/esm/prototyping/crypto/algorithms/eddsa.js +264 -0
  59. package/dist/esm/prototyping/crypto/algorithms/eddsa.js.map +1 -0
  60. package/dist/esm/prototyping/crypto/algorithms/hkdf.js +39 -0
  61. package/dist/esm/prototyping/crypto/algorithms/hkdf.js.map +1 -0
  62. package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js +41 -0
  63. package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js.map +1 -0
  64. package/dist/esm/prototyping/crypto/crypto-error.js +41 -0
  65. package/dist/esm/prototyping/crypto/crypto-error.js.map +1 -0
  66. package/dist/esm/prototyping/crypto/dsa.js +236 -0
  67. package/dist/esm/prototyping/crypto/dsa.js.map +1 -0
  68. package/dist/esm/prototyping/crypto/jose/jwe-compact.js +130 -0
  69. package/dist/esm/prototyping/crypto/jose/jwe-compact.js.map +1 -0
  70. package/dist/esm/prototyping/crypto/jose/jwe-flattened.js +294 -0
  71. package/dist/esm/prototyping/crypto/jose/jwe-flattened.js.map +1 -0
  72. package/dist/esm/prototyping/crypto/jose/jwe.js +308 -0
  73. package/dist/esm/prototyping/crypto/jose/jwe.js.map +1 -0
  74. package/dist/esm/prototyping/crypto/primitives/aes-gcm.js +352 -0
  75. package/dist/esm/prototyping/crypto/primitives/aes-gcm.js.map +1 -0
  76. package/dist/esm/prototyping/crypto/primitives/aes-kw.js +247 -0
  77. package/dist/esm/prototyping/crypto/primitives/aes-kw.js.map +1 -0
  78. package/dist/esm/prototyping/crypto/primitives/hkdf.js +80 -0
  79. package/dist/esm/prototyping/crypto/primitives/hkdf.js.map +1 -0
  80. package/dist/esm/prototyping/crypto/primitives/pbkdf2.js +85 -0
  81. package/dist/esm/prototyping/crypto/primitives/pbkdf2.js.map +1 -0
  82. package/dist/esm/prototyping/crypto/types/cipher.js +2 -0
  83. package/dist/esm/prototyping/crypto/types/cipher.js.map +1 -0
  84. package/dist/esm/prototyping/crypto/types/crypto-api.js +2 -0
  85. package/dist/esm/prototyping/crypto/types/crypto-api.js.map +1 -0
  86. package/dist/esm/prototyping/crypto/types/key-converter.js +2 -0
  87. package/dist/esm/prototyping/crypto/types/key-converter.js.map +1 -0
  88. package/dist/esm/prototyping/crypto/types/key-deriver.js +2 -0
  89. package/dist/esm/prototyping/crypto/types/key-deriver.js.map +1 -0
  90. package/dist/esm/prototyping/crypto/types/key-io.js +2 -0
  91. package/dist/esm/prototyping/crypto/types/key-io.js.map +1 -0
  92. package/dist/esm/prototyping/crypto/types/key-manager.js +2 -0
  93. package/dist/esm/prototyping/crypto/types/key-manager.js.map +1 -0
  94. package/dist/esm/prototyping/crypto/types/key-wrapper.js +2 -0
  95. package/dist/esm/prototyping/crypto/types/key-wrapper.js.map +1 -0
  96. package/dist/esm/prototyping/crypto/types/params-direct.js +2 -0
  97. package/dist/esm/prototyping/crypto/types/params-direct.js.map +1 -0
  98. package/dist/esm/prototyping/crypto/types/params-kms.js +2 -0
  99. package/dist/esm/prototyping/crypto/types/params-kms.js.map +1 -0
  100. package/dist/esm/prototyping/crypto/utils.js +19 -0
  101. package/dist/esm/prototyping/crypto/utils.js.map +1 -0
  102. package/dist/esm/prototyping/dids/resolver-cache-memory.js +77 -0
  103. package/dist/esm/prototyping/dids/resolver-cache-memory.js.map +1 -0
  104. package/dist/esm/prototyping/dids/utils.js +9 -0
  105. package/dist/esm/prototyping/dids/utils.js.map +1 -0
  106. package/dist/esm/rpc-client.js +123 -0
  107. package/dist/esm/rpc-client.js.map +1 -0
  108. package/dist/esm/store-data-protocols.js +38 -0
  109. package/dist/esm/store-data-protocols.js.map +1 -0
  110. package/dist/esm/store-data.js +320 -0
  111. package/dist/esm/store-data.js.map +1 -0
  112. package/dist/esm/store-did.js +136 -0
  113. package/dist/esm/store-did.js.map +1 -0
  114. package/dist/esm/store-identity.js +140 -0
  115. package/dist/esm/store-identity.js.map +1 -0
  116. package/dist/esm/store-key.js +136 -0
  117. package/dist/esm/store-key.js.map +1 -0
  118. package/dist/esm/sync-api.js +61 -0
  119. package/dist/esm/sync-api.js.map +1 -0
  120. package/dist/esm/sync-engine-level.js +618 -0
  121. package/dist/esm/sync-engine-level.js.map +1 -0
  122. package/dist/esm/test-harness.js +239 -0
  123. package/dist/esm/test-harness.js.map +1 -0
  124. package/dist/esm/types/agent.js +2 -0
  125. package/dist/esm/types/agent.js.map +1 -0
  126. package/dist/esm/types/dwn.js +31 -0
  127. package/dist/esm/types/dwn.js.map +1 -0
  128. package/dist/esm/types/identity-vault.js +2 -0
  129. package/dist/esm/types/identity-vault.js.map +1 -0
  130. package/dist/esm/types/identity.js +2 -0
  131. package/dist/esm/types/identity.js.map +1 -0
  132. package/dist/esm/types/key-manager.js +2 -0
  133. package/dist/esm/types/key-manager.js.map +1 -0
  134. package/dist/esm/types/permissions.js +2 -0
  135. package/dist/esm/types/permissions.js.map +1 -0
  136. package/dist/esm/types/sync.js +2 -0
  137. package/dist/esm/types/sync.js.map +1 -0
  138. package/dist/esm/types/vc.js +5 -0
  139. package/dist/esm/types/vc.js.map +1 -0
  140. package/dist/esm/utils-internal.js +147 -0
  141. package/dist/esm/utils-internal.js.map +1 -0
  142. package/dist/esm/utils.js +161 -0
  143. package/dist/esm/utils.js.map +1 -0
  144. package/dist/types/agent-did-resolver-cache.d.ts +30 -0
  145. package/dist/types/agent-did-resolver-cache.d.ts.map +1 -0
  146. package/dist/types/bearer-identity.d.ts +31 -0
  147. package/dist/types/bearer-identity.d.ts.map +1 -0
  148. package/dist/types/connect.d.ts +88 -0
  149. package/dist/types/connect.d.ts.map +1 -0
  150. package/dist/types/crypto-api.d.ts +286 -0
  151. package/dist/types/crypto-api.d.ts.map +1 -0
  152. package/dist/types/did-api.d.ts +119 -0
  153. package/dist/types/did-api.d.ts.map +1 -0
  154. package/dist/types/dwn-api.d.ts +66 -0
  155. package/dist/types/dwn-api.d.ts.map +1 -0
  156. package/dist/types/dwn-registrar.d.ts +29 -0
  157. package/dist/types/dwn-registrar.d.ts.map +1 -0
  158. package/dist/types/hd-identity-vault.d.ts +306 -0
  159. package/dist/types/hd-identity-vault.d.ts.map +1 -0
  160. package/dist/types/identity-api.d.ts +107 -0
  161. package/dist/types/identity-api.d.ts.map +1 -0
  162. package/dist/types/index.d.ts +30 -0
  163. package/dist/types/index.d.ts.map +1 -0
  164. package/dist/types/local-key-manager.d.ts +311 -0
  165. package/dist/types/local-key-manager.d.ts.map +1 -0
  166. package/dist/types/oidc.d.ts +247 -0
  167. package/dist/types/oidc.d.ts.map +1 -0
  168. package/dist/types/permissions-api.d.ts +35 -0
  169. package/dist/types/permissions-api.d.ts.map +1 -0
  170. package/dist/types/prototyping/clients/dwn-rpc-types.d.ts +45 -0
  171. package/dist/types/prototyping/clients/dwn-rpc-types.d.ts.map +1 -0
  172. package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts +57 -0
  173. package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts.map +1 -0
  174. package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts +13 -0
  175. package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts.map +1 -0
  176. package/dist/types/prototyping/clients/json-rpc-socket.d.ts +43 -0
  177. package/dist/types/prototyping/clients/json-rpc-socket.d.ts.map +1 -0
  178. package/dist/types/prototyping/clients/json-rpc.d.ts +49 -0
  179. package/dist/types/prototyping/clients/json-rpc.d.ts.map +1 -0
  180. package/dist/types/prototyping/clients/server-info-types.d.ts +20 -0
  181. package/dist/types/prototyping/clients/server-info-types.d.ts.map +1 -0
  182. package/dist/types/prototyping/clients/web-socket-clients.d.ts +10 -0
  183. package/dist/types/prototyping/clients/web-socket-clients.d.ts.map +1 -0
  184. package/dist/types/prototyping/common/object.d.ts +2 -0
  185. package/dist/types/prototyping/common/object.d.ts.map +1 -0
  186. package/dist/types/prototyping/common/type-utils.d.ts +7 -0
  187. package/dist/types/prototyping/common/type-utils.d.ts.map +1 -0
  188. package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts +151 -0
  189. package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts.map +1 -0
  190. package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts +109 -0
  191. package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts.map +1 -0
  192. package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts +160 -0
  193. package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts.map +1 -0
  194. package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts +157 -0
  195. package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts.map +1 -0
  196. package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts +21 -0
  197. package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts.map +1 -0
  198. package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts +21 -0
  199. package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts.map +1 -0
  200. package/dist/types/prototyping/crypto/crypto-error.d.ts +29 -0
  201. package/dist/types/prototyping/crypto/crypto-error.d.ts.map +1 -0
  202. package/dist/types/prototyping/crypto/dsa.d.ts +169 -0
  203. package/dist/types/prototyping/crypto/dsa.d.ts.map +1 -0
  204. package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts +135 -0
  205. package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts.map +1 -0
  206. package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts +134 -0
  207. package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts.map +1 -0
  208. package/dist/types/prototyping/crypto/jose/jwe.d.ts +378 -0
  209. package/dist/types/prototyping/crypto/jose/jwe.d.ts.map +1 -0
  210. package/dist/types/prototyping/crypto/primitives/aes-gcm.d.ts +245 -0
  211. package/dist/types/prototyping/crypto/primitives/aes-gcm.d.ts.map +1 -0
  212. package/dist/types/prototyping/crypto/primitives/aes-kw.d.ts +103 -0
  213. package/dist/types/prototyping/crypto/primitives/aes-kw.d.ts.map +1 -0
  214. package/dist/types/prototyping/crypto/primitives/hkdf.d.ts +90 -0
  215. package/dist/types/prototyping/crypto/primitives/hkdf.d.ts.map +1 -0
  216. package/dist/types/prototyping/crypto/primitives/pbkdf2.d.ts +84 -0
  217. package/dist/types/prototyping/crypto/primitives/pbkdf2.d.ts.map +1 -0
  218. package/dist/types/prototyping/crypto/types/cipher.d.ts +14 -0
  219. package/dist/types/prototyping/crypto/types/cipher.d.ts.map +1 -0
  220. package/dist/types/prototyping/crypto/types/crypto-api.d.ts +35 -0
  221. package/dist/types/prototyping/crypto/types/crypto-api.d.ts.map +1 -0
  222. package/dist/types/prototyping/crypto/types/key-converter.d.ts +49 -0
  223. package/dist/types/prototyping/crypto/types/key-converter.d.ts.map +1 -0
  224. package/dist/types/prototyping/crypto/types/key-deriver.d.ts +50 -0
  225. package/dist/types/prototyping/crypto/types/key-deriver.d.ts.map +1 -0
  226. package/dist/types/prototyping/crypto/types/key-io.d.ts +49 -0
  227. package/dist/types/prototyping/crypto/types/key-io.d.ts.map +1 -0
  228. package/dist/types/prototyping/crypto/types/key-manager.d.ts +69 -0
  229. package/dist/types/prototyping/crypto/types/key-manager.d.ts.map +1 -0
  230. package/dist/types/prototyping/crypto/types/key-wrapper.d.ts +14 -0
  231. package/dist/types/prototyping/crypto/types/key-wrapper.d.ts.map +1 -0
  232. package/dist/types/prototyping/crypto/types/params-direct.d.ts +75 -0
  233. package/dist/types/prototyping/crypto/types/params-direct.d.ts.map +1 -0
  234. package/dist/types/prototyping/crypto/types/params-kms.d.ts +63 -0
  235. package/dist/types/prototyping/crypto/types/params-kms.d.ts.map +1 -0
  236. package/dist/types/prototyping/crypto/utils.d.ts +7 -0
  237. package/dist/types/prototyping/crypto/utils.d.ts.map +1 -0
  238. package/dist/types/prototyping/dids/resolver-cache-memory.d.ts +57 -0
  239. package/dist/types/prototyping/dids/resolver-cache-memory.d.ts.map +1 -0
  240. package/dist/types/prototyping/dids/utils.d.ts +3 -0
  241. package/dist/types/prototyping/dids/utils.d.ts.map +1 -0
  242. package/dist/types/rpc-client.d.ts +51 -0
  243. package/dist/types/rpc-client.d.ts.map +1 -0
  244. package/dist/types/store-data-protocols.d.ts +4 -0
  245. package/dist/types/store-data-protocols.d.ts.map +1 -0
  246. package/dist/types/store-data.d.ts +95 -0
  247. package/dist/types/store-data.d.ts.map +1 -0
  248. package/dist/types/store-did.d.ts +33 -0
  249. package/dist/types/store-did.d.ts.map +1 -0
  250. package/dist/types/store-identity.d.ts +34 -0
  251. package/dist/types/store-identity.d.ts.map +1 -0
  252. package/dist/types/store-key.d.ts +32 -0
  253. package/dist/types/store-key.d.ts.map +1 -0
  254. package/dist/types/sync-api.d.ts +41 -0
  255. package/dist/types/sync-api.d.ts.map +1 -0
  256. package/dist/types/sync-engine-level.d.ts +85 -0
  257. package/dist/types/sync-engine-level.d.ts.map +1 -0
  258. package/dist/types/test-harness.d.ts +69 -0
  259. package/dist/types/test-harness.d.ts.map +1 -0
  260. package/dist/types/types/agent.d.ts +172 -0
  261. package/dist/types/types/agent.d.ts.map +1 -0
  262. package/dist/types/types/dwn.d.ts +178 -0
  263. package/dist/types/types/dwn.d.ts.map +1 -0
  264. package/dist/types/types/identity-vault.d.ts +129 -0
  265. package/dist/types/types/identity-vault.d.ts.map +1 -0
  266. package/dist/types/types/identity.d.ts +16 -0
  267. package/dist/types/types/identity.d.ts.map +1 -0
  268. package/dist/types/types/key-manager.d.ts +9 -0
  269. package/dist/types/types/key-manager.d.ts.map +1 -0
  270. package/dist/types/types/permissions.d.ts +98 -0
  271. package/dist/types/types/permissions.d.ts.map +1 -0
  272. package/dist/types/types/sync.d.ts +66 -0
  273. package/dist/types/types/sync.d.ts.map +1 -0
  274. package/dist/types/types/vc.d.ts +7 -0
  275. package/dist/types/types/vc.d.ts.map +1 -0
  276. package/dist/types/utils-internal.d.ts +50 -0
  277. package/dist/types/utils-internal.d.ts.map +1 -0
  278. package/dist/types/utils.d.ts +37 -0
  279. package/dist/types/utils.d.ts.map +1 -0
  280. package/package.json +112 -0
  281. package/src/agent-did-resolver-cache.ts +95 -0
  282. package/src/bearer-identity.ts +42 -0
  283. package/src/connect.ts +296 -0
  284. package/src/crypto-api.ts +593 -0
  285. package/src/did-api.ts +429 -0
  286. package/src/dwn-api.ts +462 -0
  287. package/src/dwn-registrar.ts +127 -0
  288. package/src/hd-identity-vault.ts +853 -0
  289. package/src/identity-api.ts +324 -0
  290. package/src/index.ts +30 -0
  291. package/src/local-key-manager.ts +672 -0
  292. package/src/oidc.ts +857 -0
  293. package/src/permissions-api.ts +408 -0
  294. package/src/prototyping/clients/dwn-rpc-types.ts +55 -0
  295. package/src/prototyping/clients/dwn-server-info-cache-memory.ts +79 -0
  296. package/src/prototyping/clients/http-dwn-rpc-client.ts +110 -0
  297. package/src/prototyping/clients/json-rpc-socket.ts +169 -0
  298. package/src/prototyping/clients/json-rpc.ts +113 -0
  299. package/src/prototyping/clients/server-info-types.ts +21 -0
  300. package/src/prototyping/clients/web-socket-clients.ts +100 -0
  301. package/src/prototyping/common/object.ts +15 -0
  302. package/src/prototyping/common/type-utils.ts +6 -0
  303. package/src/prototyping/crypto/algorithms/aes-gcm.ts +211 -0
  304. package/src/prototyping/crypto/algorithms/aes-kw.ts +164 -0
  305. package/src/prototyping/crypto/algorithms/ecdsa.ts +365 -0
  306. package/src/prototyping/crypto/algorithms/eddsa.ts +310 -0
  307. package/src/prototyping/crypto/algorithms/hkdf.ts +40 -0
  308. package/src/prototyping/crypto/algorithms/pbkdf2.ts +44 -0
  309. package/src/prototyping/crypto/crypto-error.ts +45 -0
  310. package/src/prototyping/crypto/dsa.ts +367 -0
  311. package/src/prototyping/crypto/jose/jwe-compact.ts +225 -0
  312. package/src/prototyping/crypto/jose/jwe-flattened.ts +459 -0
  313. package/src/prototyping/crypto/jose/jwe.ts +653 -0
  314. package/src/prototyping/crypto/primitives/aes-gcm.ts +374 -0
  315. package/src/prototyping/crypto/primitives/aes-kw.ts +271 -0
  316. package/src/prototyping/crypto/primitives/hkdf.ts +121 -0
  317. package/src/prototyping/crypto/primitives/pbkdf2.ts +116 -0
  318. package/src/prototyping/crypto/types/cipher.ts +17 -0
  319. package/src/prototyping/crypto/types/crypto-api.ts +78 -0
  320. package/src/prototyping/crypto/types/key-converter.ts +53 -0
  321. package/src/prototyping/crypto/types/key-deriver.ts +56 -0
  322. package/src/prototyping/crypto/types/key-io.ts +51 -0
  323. package/src/prototyping/crypto/types/key-manager.ts +83 -0
  324. package/src/prototyping/crypto/types/key-wrapper.ts +17 -0
  325. package/src/prototyping/crypto/types/params-direct.ts +95 -0
  326. package/src/prototyping/crypto/types/params-kms.ts +76 -0
  327. package/src/prototyping/crypto/utils.ts +41 -0
  328. package/src/prototyping/dids/resolver-cache-memory.ts +83 -0
  329. package/src/prototyping/dids/utils.ts +10 -0
  330. package/src/rpc-client.ts +162 -0
  331. package/src/store-data-protocols.ts +40 -0
  332. package/src/store-data.ts +400 -0
  333. package/src/store-did.ts +105 -0
  334. package/src/store-identity.ts +109 -0
  335. package/src/store-key.ts +104 -0
  336. package/src/sync-api.ts +71 -0
  337. package/src/sync-engine-level.ts +714 -0
  338. package/src/test-harness.ts +330 -0
  339. package/src/types/agent.ts +195 -0
  340. package/src/types/dwn.ts +278 -0
  341. package/src/types/identity-vault.ts +137 -0
  342. package/src/types/identity.ts +18 -0
  343. package/src/types/key-manager.ts +15 -0
  344. package/src/types/permissions.ts +115 -0
  345. package/src/types/sync.ts +58 -0
  346. package/src/types/vc.ts +7 -0
  347. package/src/utils-internal.ts +157 -0
  348. package/src/utils.ts +181 -0
@@ -0,0 +1,346 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Sha2Algorithm, computeJwkThumbprint } from '@enbox/crypto';
11
+ import { HkdfAlgorithm } from './prototyping/crypto/algorithms/hkdf.js';
12
+ import { EcdsaAlgorithm } from './prototyping/crypto/algorithms/ecdsa.js';
13
+ import { EdDsaAlgorithm } from './prototyping/crypto/algorithms/eddsa.js';
14
+ import { AesKwAlgorithm } from './prototyping/crypto/algorithms/aes-kw.js';
15
+ import { Pbkdf2Algorithm } from './prototyping/crypto/algorithms/pbkdf2.js';
16
+ import { AesGcmAlgorithm } from './prototyping/crypto/algorithms/aes-gcm.js';
17
+ import { CryptoError, CryptoErrorCode } from './prototyping/crypto/crypto-error.js';
18
+ /**
19
+ * `supportedAlgorithms` is an object mapping algorithm names to their respective implementations
20
+ * Each entry in this map specifies the algorithm name and its associated properties, including the
21
+ * implementation class and any relevant names or identifiers for the algorithm. This structure
22
+ * allows for easy retrieval and instantiation of algorithm implementations based on the algorithm
23
+ * name or key specification. It facilitates the support of multiple algorithms within the
24
+ * `LocalKeyManager` class.
25
+ */
26
+ const supportedAlgorithms = {
27
+ 'AES-GCM': {
28
+ implementation: AesGcmAlgorithm,
29
+ names: ['A128GCM', 'A192GCM', 'A256GCM'],
30
+ operations: ['bytesToPrivateKey', 'decrypt', 'encrypt', 'generateKey'],
31
+ },
32
+ 'AES-KW': {
33
+ implementation: AesKwAlgorithm,
34
+ names: ['A128KW', 'A192KW', 'A256KW'],
35
+ operations: ['bytesToPrivateKey', 'generateKey', 'privateKeyToBytes', 'wrapKey', 'unwrapKey'],
36
+ },
37
+ 'Ed25519': {
38
+ implementation: EdDsaAlgorithm,
39
+ names: ['Ed25519'],
40
+ operations: ['bytesToPrivateKey', 'bytesToPublicKey', 'generateKey', 'sign', 'verify'],
41
+ },
42
+ 'HKDF': {
43
+ implementation: HkdfAlgorithm,
44
+ names: ['HKDF-256', 'HKDF-384', 'HKDF-512'],
45
+ operations: ['deriveKey', 'deriveKeyBytes'],
46
+ },
47
+ 'PBKDF2': {
48
+ implementation: Pbkdf2Algorithm,
49
+ names: ['PBES2-HS256+A128KW', 'PBES2-HS384+A192KW', 'PBES2-HS512+A256KW'],
50
+ operations: ['deriveKey', 'deriveKeyBytes'],
51
+ },
52
+ 'secp256k1': {
53
+ implementation: EcdsaAlgorithm,
54
+ names: ['ES256K', 'secp256k1'],
55
+ operations: ['bytesToPrivateKey', 'bytesToPublicKey', 'generateKey', 'sign', 'verify'],
56
+ },
57
+ 'secp256r1': {
58
+ implementation: EcdsaAlgorithm,
59
+ names: ['ES256', 'secp256r1'],
60
+ operations: ['bytesToPrivateKey', 'bytesToPublicKey', 'generateKey', 'sign', 'verify'],
61
+ },
62
+ 'SHA-256': {
63
+ implementation: Sha2Algorithm,
64
+ names: ['SHA-256'],
65
+ operations: ['digest'],
66
+ }
67
+ };
68
+ export class AgentCryptoApi {
69
+ constructor() {
70
+ /**
71
+ * A private map that stores instances of cryptographic algorithm implementations. Each key in
72
+ * this map is an `AlgorithmConstructor`, and its corresponding value is an instance of a class
73
+ * that implements a specific cryptographic algorithm. This map is used to cache and reuse
74
+ * instances for performance optimization, ensuring that each algorithm is instantiated only once.
75
+ */
76
+ this._algorithmInstances = new Map();
77
+ }
78
+ bytesToPrivateKey({ algorithm: algorithmIdentifier, privateKeyBytes }) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ // Determine the algorithm name based on the given algorithm identifier.
81
+ const algorithm = this.getAlgorithmName({ algorithm: algorithmIdentifier });
82
+ // Get the key converter based on the algorithm name.
83
+ const keyConverter = this.getAlgorithm({ algorithm });
84
+ // Convert the byte array to a JWK.
85
+ const privateKey = yield keyConverter.bytesToPrivateKey({ algorithm: algorithmIdentifier, privateKeyBytes });
86
+ return privateKey;
87
+ });
88
+ }
89
+ bytesToPublicKey({ algorithm: algorithmIdentifier, publicKeyBytes }) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ // Determine the algorithm name based on the given algorithm identifier.
92
+ const algorithm = this.getAlgorithmName({ algorithm: algorithmIdentifier });
93
+ // Get the key converter based on the algorithm name.
94
+ const keyConverter = this.getAlgorithm({ algorithm });
95
+ // Convert the byte array to a JWK.
96
+ const publicKey = yield keyConverter.bytesToPublicKey({ algorithm: algorithmIdentifier, publicKeyBytes });
97
+ return publicKey;
98
+ });
99
+ }
100
+ decrypt(params) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ // Determine the algorithm name based on the JWK's `alg` property.
103
+ const algorithm = this.getAlgorithmName({ key: params.key });
104
+ // Get the cipher algorithm based on the algorithm name.
105
+ const cipher = this.getAlgorithm({ algorithm });
106
+ // Decrypt the data.
107
+ return yield cipher.decrypt(params);
108
+ });
109
+ }
110
+ deriveKey(params) {
111
+ var _a, _b;
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ // Determine the algorithm name based on the given algorithm identifier.
114
+ const algorithm = this.getAlgorithmName({ algorithm: params.algorithm });
115
+ // Get the key derivation function based on the algorithm name.
116
+ const kdf = this.getAlgorithm({ algorithm });
117
+ let derivedKeyAlgorithm;
118
+ switch (params.algorithm) {
119
+ case 'HKDF-256':
120
+ case 'HKDF-384':
121
+ case 'HKDF-512': {
122
+ derivedKeyAlgorithm = params.derivedKeyAlgorithm;
123
+ break;
124
+ }
125
+ case 'PBES2-HS256+A128KW':
126
+ case 'PBES2-HS384+A192KW':
127
+ case 'PBES2-HS512+A256KW': {
128
+ derivedKeyAlgorithm = params.algorithm.split(/[-+]/)[2];
129
+ break;
130
+ }
131
+ default:
132
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The specified "algorithm" is not supported: ${params.algorithm}`);
133
+ }
134
+ // Determine the bit length of the derived key based on the given algorithm.
135
+ const length = +((_b = (_a = derivedKeyAlgorithm.match(/\d+/)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : -1);
136
+ if (length === -1) {
137
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The derived key algorithm" is not supported: ${derivedKeyAlgorithm}`);
138
+ }
139
+ // Derive the byte array.
140
+ const privateKeyBytes = yield kdf.deriveKeyBytes(Object.assign(Object.assign({}, params), { length }));
141
+ return yield this.bytesToPrivateKey({ algorithm: derivedKeyAlgorithm, privateKeyBytes });
142
+ });
143
+ }
144
+ deriveKeyBytes(params) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ // Determine the algorithm name based on the given algorithm identifier.
147
+ const algorithm = this.getAlgorithmName({ algorithm: params.algorithm });
148
+ // Get the key derivation function based on the algorithm name.
149
+ const kdf = this.getAlgorithm({ algorithm });
150
+ // Derive the byte array.
151
+ const derivedKeyBytes = yield kdf.deriveKeyBytes(params);
152
+ return derivedKeyBytes;
153
+ });
154
+ }
155
+ /**
156
+ * Generates a hash digest of the provided data.
157
+ *
158
+ * @remarks
159
+ * A digest is the output of the hash function. It's a fixed-size string of bytes that uniquely
160
+ * represents the data input into the hash function. The digest is often used for data integrity
161
+ * checks, as any alteration in the input data results in a significantly different digest.
162
+ *
163
+ * It takes the algorithm identifier of the hash function and data to digest as input and returns
164
+ * the digest of the data.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const cryptoApi = new AgentCryptoApi();
169
+ * const data = new Uint8Array([...]);
170
+ * const digest = await cryptoApi.digest({ algorithm: 'SHA-256', data });
171
+ * ```
172
+ *
173
+ * @param params - The parameters for the digest operation.
174
+ * @param params.algorithm - The name of hash function to use.
175
+ * @param params.data - The data to digest.
176
+ *
177
+ * @returns A Promise which will be fulfilled with the hash digest.
178
+ */
179
+ digest({ algorithm, data }) {
180
+ return __awaiter(this, void 0, void 0, function* () {
181
+ // Get the hash function implementation based on the specified `algorithm` parameter.
182
+ const hasher = this.getAlgorithm({ algorithm });
183
+ // Compute the hash.
184
+ const hash = yield hasher.digest({ algorithm, data });
185
+ return hash;
186
+ });
187
+ }
188
+ encrypt(params) {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ // If th
191
+ // Determine the algorithm name based on the JWK's `alg` property.
192
+ const algorithm = this.getAlgorithmName({ key: params.key });
193
+ // Get the cipher algorithm based on the algorithm name.
194
+ const cipher = this.getAlgorithm({ algorithm });
195
+ // Encrypt the data and return the ciphertext.
196
+ return yield cipher.encrypt(params);
197
+ });
198
+ }
199
+ generateKey(params) {
200
+ var _a;
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ // Determine the algorithm name based on the given algorithm identifier.
203
+ const algorithm = this.getAlgorithmName({ algorithm: params.algorithm });
204
+ // Get the key generator implementation based on the algorithm.
205
+ const keyGenerator = this.getAlgorithm({ algorithm });
206
+ // Generate the key.
207
+ const privateKey = yield keyGenerator.generateKey({ algorithm: params.algorithm });
208
+ // If the key ID is undefined, set it to the JWK thumbprint.
209
+ (_a = privateKey.kid) !== null && _a !== void 0 ? _a : (privateKey.kid = yield computeJwkThumbprint({ jwk: privateKey }));
210
+ return privateKey;
211
+ });
212
+ }
213
+ // ! TODO: Remove this once the `Dsa` interface is updated in @enbox/crypto to remove KMS-specific methods.
214
+ getKeyUri(_params) {
215
+ return __awaiter(this, void 0, void 0, function* () {
216
+ throw new Error('Method not implemented.');
217
+ });
218
+ }
219
+ getPublicKey({ key }) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ // Determine the algorithm name based on the JWK's `alg` and `crv` properties.
222
+ const algorithm = this.getAlgorithmName({ key });
223
+ // Get the key generator based on the algorithm name.
224
+ const keyGenerator = this.getAlgorithm({ algorithm });
225
+ // Get the public key properties from the private JWK.
226
+ const publicKey = yield keyGenerator.getPublicKey({ key });
227
+ return publicKey;
228
+ });
229
+ }
230
+ privateKeyToBytes({ privateKey }) {
231
+ return __awaiter(this, void 0, void 0, function* () {
232
+ // Determine the algorithm name based on the JWK's `alg` property.
233
+ const algorithm = this.getAlgorithmName({ key: privateKey });
234
+ // Get the key converter based on the algorithm name.
235
+ const keyConverter = this.getAlgorithm({ algorithm });
236
+ // Convert the JWK to a byte array.
237
+ const privateKeyBytes = yield keyConverter.privateKeyToBytes({ privateKey });
238
+ return privateKeyBytes;
239
+ });
240
+ }
241
+ publicKeyToBytes({ publicKey }) {
242
+ return __awaiter(this, void 0, void 0, function* () {
243
+ // Determine the algorithm name based on the JWK's `alg` property.
244
+ const algorithm = this.getAlgorithmName({ key: publicKey });
245
+ // Get the key converter based on the algorithm name.
246
+ const keyConverter = this.getAlgorithm({ algorithm });
247
+ // Convert the JWK to a byte array.
248
+ const publicKeyBytes = yield keyConverter.publicKeyToBytes({ publicKey });
249
+ return publicKeyBytes;
250
+ });
251
+ }
252
+ sign({ key, data }) {
253
+ return __awaiter(this, void 0, void 0, function* () {
254
+ // Determine the algorithm name based on the JWK's `alg` and `crv` properties.
255
+ const algorithm = this.getAlgorithmName({ key });
256
+ // Get the signature algorithm based on the algorithm name.
257
+ const signer = this.getAlgorithm({ algorithm });
258
+ // Sign the data.
259
+ const signature = signer.sign({ data, key });
260
+ return signature;
261
+ });
262
+ }
263
+ unwrapKey(params) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ // Determine the algorithm name based on the JWK's `alg` property.
266
+ const algorithm = this.getAlgorithmName({ key: params.decryptionKey });
267
+ // Get the key wrapping algorithm based on the algorithm name.
268
+ const keyWrapper = this.getAlgorithm({ algorithm });
269
+ // decrypt the key and return the ciphertext.
270
+ return yield keyWrapper.unwrapKey(params);
271
+ });
272
+ }
273
+ verify({ key, signature, data }) {
274
+ return __awaiter(this, void 0, void 0, function* () {
275
+ // Determine the algorithm name based on the JWK's `alg` and `crv` properties.
276
+ const algorithm = this.getAlgorithmName({ key });
277
+ // Get the signature algorithm based on the algorithm name.
278
+ const signer = this.getAlgorithm({ algorithm });
279
+ // Verify the signature.
280
+ const isSignatureValid = signer.verify({ key, signature, data });
281
+ return isSignatureValid;
282
+ });
283
+ }
284
+ wrapKey(params) {
285
+ return __awaiter(this, void 0, void 0, function* () {
286
+ // Determine the algorithm name based on the JWK's `alg` property.
287
+ const algorithm = this.getAlgorithmName({ key: params.encryptionKey });
288
+ // Get the key wrapping algorithm based on the algorithm name.
289
+ const keyWrapper = this.getAlgorithm({ algorithm });
290
+ // Encrypt the key and return the ciphertext.
291
+ return yield keyWrapper.wrapKey(params);
292
+ });
293
+ }
294
+ /**
295
+ * Retrieves an algorithm implementation instance based on the provided algorithm name.
296
+ *
297
+ * @remarks
298
+ * This method checks if the requested algorithm is supported and returns a cached instance
299
+ * if available. If an instance does not exist, it creates and caches a new one. This approach
300
+ * optimizes performance by reusing algorithm instances across cryptographic operations.
301
+ *
302
+ * @example
303
+ * ```ts
304
+ * const signer = this.getAlgorithm({ algorithm: 'Ed25519' });
305
+ * ```
306
+ *
307
+ * @param params - The parameters for retrieving the algorithm implementation.
308
+ * @param params.algorithm - The name of the algorithm to retrieve.
309
+ *
310
+ * @returns An instance of the requested algorithm implementation.
311
+ *
312
+ * @throws Error if the requested algorithm is not supported.
313
+ */
314
+ getAlgorithm({ algorithm }) {
315
+ var _a;
316
+ // Check if algorithm is supported.
317
+ const AlgorithmImplementation = (_a = supportedAlgorithms[algorithm]) === null || _a === void 0 ? void 0 : _a['implementation'];
318
+ if (!AlgorithmImplementation) {
319
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
320
+ }
321
+ // Check if instance already exists for the `AlgorithmImplementation`.
322
+ if (!this._algorithmInstances.has(AlgorithmImplementation)) {
323
+ // If not, create a new instance and store it in the cache
324
+ this._algorithmInstances.set(AlgorithmImplementation, new AlgorithmImplementation());
325
+ }
326
+ // Return the cached instance
327
+ return this._algorithmInstances.get(AlgorithmImplementation);
328
+ }
329
+ getAlgorithmName({ algorithm, key }) {
330
+ var _a;
331
+ const algProperty = (_a = key === null || key === void 0 ? void 0 : key.alg) !== null && _a !== void 0 ? _a : algorithm;
332
+ const crvProperty = key === null || key === void 0 ? void 0 : key.crv;
333
+ for (const algorithmIdentifier of Object.keys(supportedAlgorithms)) {
334
+ const algorithmNames = supportedAlgorithms[algorithmIdentifier].names;
335
+ if (algProperty && algorithmNames.includes(algProperty)) {
336
+ return algorithmIdentifier;
337
+ }
338
+ else if (crvProperty && algorithmNames.includes(crvProperty)) {
339
+ return algorithmIdentifier;
340
+ }
341
+ }
342
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported based on provided input: alg=${algProperty}, crv=${crvProperty}. ` +
343
+ 'Please check the documentation for the list of supported algorithms.');
344
+ }
345
+ }
346
+ //# sourceMappingURL=crypto-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-api.js","sourceRoot":"","sources":["../../src/crypto-api.ts"],"names":[],"mappings":";;;;;;;;;AAgBA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AAC,EAAE;gBACvD,OAAO,mBAAmB,CAAC;aAC5B;iBAAM,IAAI,WAAW,IAAI,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;gBAC9D,OAAO,mBAAmB,CAAC;aAC5B;SACF;QAED,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EACzD,wDAAwD,WAAW,SAAS,WAAW,IAAI;YAC3F,sEAAsE,CACvE,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,278 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { BearerDid, Did, DidDht, UniversalResolver } from '@enbox/dids';
11
+ import { InMemoryDidStore } from './store-did.js';
12
+ import { AgentDidResolverCache } from './agent-did-resolver-cache.js';
13
+ import { canonicalize } from '@enbox/crypto';
14
+ export var DidInterface;
15
+ (function (DidInterface) {
16
+ DidInterface["Create"] = "Create";
17
+ // Deactivate = 'Deactivate',
18
+ DidInterface["Resolve"] = "Resolve";
19
+ // Update = 'Update'
20
+ })(DidInterface || (DidInterface = {}));
21
+ export function isDidRequest(didRequest, messageType) {
22
+ return didRequest.messageType === messageType;
23
+ }
24
+ /**
25
+ * This API is used to manage and interact with DIDs within the Web5 Agent framework.
26
+ *
27
+ * If a DWN Data Store is used, the DID information is stored under DID's own tenant by default.
28
+ * If a tenant property is passed, that tenant will be used to store the DID information.
29
+ */
30
+ export class AgentDidApi extends UniversalResolver {
31
+ constructor({ agent, didMethods, resolverCache, store }) {
32
+ if (!didMethods) {
33
+ throw new TypeError(`AgentDidApi: Required parameter missing: 'didMethods'`);
34
+ }
35
+ // Initialize the DID resolver with the given DID methods and resolver cache, or use a default
36
+ // AgentDidResolverCache if none is provided.
37
+ super({
38
+ didResolvers: didMethods,
39
+ cache: resolverCache !== null && resolverCache !== void 0 ? resolverCache : new AgentDidResolverCache({ agent, location: 'DATA/AGENT/DID_CACHE' })
40
+ });
41
+ this._didMethods = new Map();
42
+ this._agent = agent;
43
+ // If `store` is not given, use an in-memory store by default.
44
+ this._store = store !== null && store !== void 0 ? store : new InMemoryDidStore();
45
+ for (const didMethod of didMethods) {
46
+ this._didMethods.set(didMethod.methodName, didMethod);
47
+ }
48
+ }
49
+ /**
50
+ * Retrieves the `Web5PlatformAgent` execution context.
51
+ *
52
+ * @returns The `Web5PlatformAgent` instance that represents the current execution context.
53
+ * @throws Will throw an error if the `agent` instance property is undefined.
54
+ */
55
+ get agent() {
56
+ if (this._agent === undefined) {
57
+ throw new Error('AgentDidApi: Unable to determine agent execution context.');
58
+ }
59
+ return this._agent;
60
+ }
61
+ set agent(agent) {
62
+ this._agent = agent;
63
+ // AgentDidResolverCache should set the agent if it is the type of cache being used
64
+ if ('agent' in this.cache) {
65
+ this.cache.agent = agent;
66
+ }
67
+ }
68
+ create({ method, tenant, options, store }) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ // Get the DID method implementation, which also verifies the method is supported.
71
+ const didMethod = this.getMethod(method);
72
+ // Create the DID and store the generated keys in the Agent's key manager.
73
+ const bearerDid = yield didMethod.create({ keyManager: this.agent.keyManager, options });
74
+ // pre-populate the resolution cache with the document and metadata
75
+ yield this.cache.set(bearerDid.uri, { didDocument: bearerDid.document, didResolutionMetadata: {}, didDocumentMetadata: bearerDid.metadata });
76
+ // Persist the DID to the store, by default, unless the `store` option is set to false.
77
+ if (store !== null && store !== void 0 ? store : true) {
78
+ // Data stored in the Agent's DID store must be in PortableDid format.
79
+ const { uri, document, metadata } = bearerDid;
80
+ const portableDid = { uri, document, metadata };
81
+ // Unless an existing `tenant` is specified, a record that includes the DID's URI, document,
82
+ // and metadata will be stored under a new tenant controlled by the newly created DID.
83
+ yield this._store.set({
84
+ id: portableDid.uri,
85
+ data: portableDid,
86
+ agent: this.agent,
87
+ tenant: tenant !== null && tenant !== void 0 ? tenant : portableDid.uri,
88
+ preventDuplicates: false,
89
+ useCache: true
90
+ });
91
+ }
92
+ return bearerDid;
93
+ });
94
+ }
95
+ export({ didUri, tenant }) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ // Attempt to retrieve the DID from the agent's DID store.
98
+ const bearerDid = yield this.get({ didUri, tenant });
99
+ if (!bearerDid) {
100
+ throw new Error(`AgentDidApi: Failed to export due to DID not found: ${didUri}`);
101
+ }
102
+ // If the DID was found, return the DID in a portable format, and if supported by the Agent's
103
+ // key manager, the private key material.
104
+ const portableDid = yield bearerDid.export();
105
+ return portableDid;
106
+ });
107
+ }
108
+ get({ didUri, tenant }) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const portableDid = yield this._store.get({ id: didUri, agent: this.agent, tenant, useCache: true });
111
+ if (!portableDid)
112
+ return undefined;
113
+ const bearerDid = yield BearerDid.import({ portableDid, keyManager: this.agent.keyManager });
114
+ return bearerDid;
115
+ });
116
+ }
117
+ getSigningMethod({ didUri, methodId }) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ // Verify the DID method is supported.
120
+ const parsedDid = Did.parse(didUri);
121
+ if (!parsedDid) {
122
+ throw new Error(`Invalid DID URI: ${didUri}`);
123
+ }
124
+ // Get the DID method implementation, which also verifies the method is supported.
125
+ const didMethod = this.getMethod(parsedDid.method);
126
+ // Resolve the DID document.
127
+ const { didDocument, didResolutionMetadata } = yield this.resolve(didUri);
128
+ if (!didDocument) {
129
+ throw new Error(`DID resolution failed for '${didUri}': ${JSON.stringify(didResolutionMetadata)}`);
130
+ }
131
+ // Retrieve the method-specific verification method to be used for signing operations.
132
+ const verificationMethod = yield didMethod.getSigningMethod({ didDocument, methodId });
133
+ return verificationMethod;
134
+ });
135
+ }
136
+ update({ tenant, portableDid, publish = true }) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ // Check if the DID exists in the store.
139
+ const existingDid = yield this.get({ didUri: portableDid.uri, tenant: tenant !== null && tenant !== void 0 ? tenant : portableDid.uri });
140
+ if (!existingDid) {
141
+ throw new Error(`AgentDidApi: Could not update, DID not found: ${portableDid.uri}`);
142
+ }
143
+ // If the document has not changed, abort the update.
144
+ if (canonicalize(portableDid.document) === canonicalize(existingDid.document)) {
145
+ throw new Error('AgentDidApi: No changes detected, update aborted');
146
+ }
147
+ // If private keys are present in the PortableDid, import the key material into the Agent's key
148
+ // manager. Validate that the key material for every verification method in the DID document is
149
+ // present in the key manager. If no keys are present, this will fail.
150
+ // NOTE: We currently do not delete the previous keys from the document.
151
+ // TODO: Add support for deleting the keys no longer present in the document.
152
+ const bearerDid = yield BearerDid.import({ keyManager: this.agent.keyManager, portableDid });
153
+ // Only the DID URI, document, and metadata are stored in the Agent's DID store.
154
+ const { uri, document, metadata } = bearerDid;
155
+ const portableDidWithoutKeys = { uri, document, metadata };
156
+ // pre-populate the resolution cache with the document and metadata
157
+ yield this.cache.set(uri, { didDocument: document, didResolutionMetadata: {}, didDocumentMetadata: metadata });
158
+ yield this._store.set({
159
+ id: uri,
160
+ data: portableDidWithoutKeys,
161
+ agent: this.agent,
162
+ tenant: tenant !== null && tenant !== void 0 ? tenant : uri,
163
+ updateExisting: true,
164
+ useCache: true
165
+ });
166
+ if (publish) {
167
+ const parsedDid = Did.parse(uri);
168
+ // currently only supporting DHT as a publishable method.
169
+ // TODO: abstract this into the didMethod class so that other publishable methods can be supported.
170
+ if (parsedDid && parsedDid.method === 'dht') {
171
+ yield DidDht.publish({ did: bearerDid });
172
+ }
173
+ }
174
+ return bearerDid;
175
+ });
176
+ }
177
+ import({ portableDid, tenant }) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ // If private keys are present in the PortableDid, import the key material into the Agent's key
180
+ // manager. Validate that the key material for every verification method in the DID document is
181
+ // present in the key manager.
182
+ const bearerDid = yield BearerDid.import({ keyManager: this.agent.keyManager, portableDid });
183
+ // Only the DID URI, document, and metadata are stored in the Agent's DID store.
184
+ const { uri, document, metadata } = bearerDid;
185
+ const portableDidWithoutKeys = { uri, document, metadata };
186
+ // pre-populate the resolution cache with the document and metadata
187
+ yield this.cache.set(uri, { didDocument: document, didResolutionMetadata: {}, didDocumentMetadata: metadata });
188
+ // Store the DID in the agent's DID store.
189
+ // Unless an existing `tenant` is specified, a record that includes the DID's URI, document,
190
+ // and metadata will be stored under a new tenant controlled by the imported DID.
191
+ yield this._store.set({
192
+ id: portableDidWithoutKeys.uri,
193
+ data: portableDidWithoutKeys,
194
+ agent: this.agent,
195
+ tenant: tenant !== null && tenant !== void 0 ? tenant : portableDidWithoutKeys.uri,
196
+ preventDuplicates: true,
197
+ useCache: true
198
+ });
199
+ return bearerDid;
200
+ });
201
+ }
202
+ delete({ didUri, tenant, deleteKey = true }) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ const portableDid = yield this._store.get({ id: didUri, agent: this.agent, tenant, useCache: false });
205
+ if (!portableDid) {
206
+ throw new Error('AgentDidApi: Could not delete, DID not found');
207
+ }
208
+ // delete from the cache
209
+ yield this.cache.delete(didUri);
210
+ // Delete the data before deleting the associated keys.
211
+ yield this._store.delete({ id: didUri, agent: this.agent, tenant });
212
+ if (deleteKey) {
213
+ // Delete the keys associated with the DID
214
+ // TODO: this could be made a static method on `BearerDid` class
215
+ yield this.deleteKeys({ portableDid });
216
+ }
217
+ });
218
+ }
219
+ deleteKeys({ portableDid }) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ for (const verificationMethod of portableDid.document.verificationMethod || []) {
222
+ if (!verificationMethod.publicKeyJwk) {
223
+ continue;
224
+ }
225
+ // Compute the key URI of the verification method's public key.
226
+ const keyUri = yield this.agent.keyManager.getKeyUri({ key: verificationMethod.publicKeyJwk });
227
+ yield this.agent.keyManager.deleteKey({ keyUri });
228
+ }
229
+ });
230
+ }
231
+ processRequest(request) {
232
+ var _a;
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ // Process Create DID request.
235
+ if (isDidRequest(request, DidInterface.Create)) {
236
+ try {
237
+ const bearerDid = yield this.create(Object.assign({}, request.messageParams));
238
+ const response = {
239
+ result: {
240
+ uri: bearerDid.uri,
241
+ document: bearerDid.document,
242
+ metadata: bearerDid.metadata,
243
+ },
244
+ ok: true,
245
+ status: { code: 201, message: 'Created' }
246
+ };
247
+ return response;
248
+ }
249
+ catch (error) {
250
+ return {
251
+ ok: false,
252
+ status: { code: 500, message: (_a = error.message) !== null && _a !== void 0 ? _a : 'Unknown error occurred' }
253
+ };
254
+ }
255
+ }
256
+ // Process Resolve DID request.
257
+ if (isDidRequest(request, DidInterface.Resolve)) {
258
+ const { didUri, options } = request.messageParams;
259
+ const resolutionResult = yield this.resolve(didUri, options);
260
+ const response = {
261
+ result: resolutionResult,
262
+ ok: true,
263
+ status: { code: 200, message: 'OK' }
264
+ };
265
+ return response;
266
+ }
267
+ throw new Error(`AgentDidApi: Unsupported request type: ${request.messageType}`);
268
+ });
269
+ }
270
+ getMethod(methodName) {
271
+ const didMethodApi = this._didMethods.get(methodName);
272
+ if (didMethodApi === undefined) {
273
+ throw new Error(`DID Method not supported: ${methodName}`);
274
+ }
275
+ return didMethodApi;
276
+ }
277
+ }
278
+ //# sourceMappingURL=did-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-api.js","sourceRoot":"","sources":["../../src/did-api.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,eA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