@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,95 @@
1
+ import { DidResolutionResult, DidResolverCache, DidResolverCacheLevel, DidResolverCacheLevelParams } from '@enbox/dids';
2
+ import { Web5PlatformAgent } from './types/agent.js';
3
+ import { logger } from '@enbox/common';
4
+
5
+
6
+ /**
7
+ * AgentDidResolverCache keeps a stale copy of the Agent's managed Identity DIDs and only evicts and refreshes upon a successful resolution.
8
+ * This allows for quick and offline access to the internal DIDs used by the agent.
9
+ */
10
+ export class AgentDidResolverCache extends DidResolverCacheLevel implements DidResolverCache {
11
+
12
+ /**
13
+ * Holds the instance of a `Web5PlatformAgent` that represents the current execution context for
14
+ * the `AgentDidApi`. This agent is used to interact with other Web5 agent components. It's vital
15
+ * to ensure this instance is set to correctly contextualize operations within the broader Web5
16
+ * Agent framework.
17
+ */
18
+ private _agent?: Web5PlatformAgent;
19
+
20
+ /** A map of DIDs that are currently in-flight. This helps avoid going into an infinite loop */
21
+ private _resolving: Map<string, boolean> = new Map();
22
+
23
+ constructor({ agent, db, location, ttl }: DidResolverCacheLevelParams & { agent?: Web5PlatformAgent }) {
24
+ super ({ db, location, ttl });
25
+ this._agent = agent;
26
+ }
27
+
28
+ get agent() {
29
+ if (!this._agent) {
30
+ throw new Error('Agent not initialized');
31
+ }
32
+ return this._agent;
33
+ }
34
+
35
+ set agent(agent: Web5PlatformAgent) {
36
+ this._agent = agent;
37
+ }
38
+
39
+ /**
40
+ * Get the DID resolution result from the cache for the given DID.
41
+ *
42
+ * If the DID is managed by the agent, or is the agent's own DID, it will not evict it from the cache until a new resolution is successful.
43
+ * This is done to achieve quick and offline access to the agent's own managed DIDs.
44
+ */
45
+ async get(did: string): Promise<DidResolutionResult | void> {
46
+ try {
47
+ const str = await this.cache.get(did);
48
+ const cachedResult = JSON.parse(str);
49
+ if (!this._resolving.has(did) && Date.now() >= cachedResult.ttlMillis) {
50
+ this._resolving.set(did, true);
51
+
52
+ // if a DID is stored in the DID Store, then we don't want to evict it from the cache until we have a successful resolution
53
+ // upon a successful resolution, we will update both the storage and the cache with the newly resolved Document.
54
+ const storedDid = await this.agent.did.get({ didUri: did, tenant: this.agent.agentDid.uri });
55
+ if ('undefined' !== typeof storedDid) {
56
+ try {
57
+ const result = await this.agent.did.resolve(did);
58
+
59
+ // if the resolution was successful, update the stored DID with the new Document
60
+ if (!result.didResolutionMetadata.error && result.didDocument) {
61
+
62
+ const portableDid = {
63
+ ...storedDid,
64
+ document : result.didDocument,
65
+ metadata : result.didDocumentMetadata,
66
+ };
67
+
68
+ try {
69
+ // this will throw an error if the DID is not managed by the agent, or there is no difference between the stored and resolved DID
70
+ // We don't publish the DID in this case, as it was received by the resolver.
71
+ await this.agent.did.update({ portableDid, tenant: this.agent.agentDid.uri, publish: false });
72
+ } catch(error: any) {
73
+ // if the error is not due to no changes detected, log the error
74
+ if (error.message && !error.message.includes('No changes detected, update aborted')) {
75
+ logger.error(`Error updating DID: ${error.message}`);
76
+ }
77
+ }
78
+ }
79
+ } finally {
80
+ this._resolving.delete(did);
81
+ }
82
+ } else {
83
+ this._resolving.delete(did);
84
+ this.cache.nextTick(() => this.cache.del(did));
85
+ }
86
+ }
87
+ return cachedResult.value;
88
+ } catch(error: any) {
89
+ if (error.notFound) {
90
+ return;
91
+ }
92
+ throw error;
93
+ }
94
+ }
95
+ }
@@ -0,0 +1,42 @@
1
+ import { BearerDid } from '@enbox/dids';
2
+ import { IdentityMetadata, PortableIdentity } from './types/identity.js';
3
+
4
+ /**
5
+ * Represents a Web5 Identity with its DID and metadata.
6
+ */
7
+ export class BearerIdentity {
8
+ /** {@inheritDoc BearerDid} */
9
+ public did: BearerDid;
10
+
11
+ /** {@inheritDoc DidMetadata} */
12
+ public metadata: IdentityMetadata;
13
+
14
+ constructor({ did, metadata }: {
15
+ did: BearerDid;
16
+ metadata: IdentityMetadata;
17
+ }) {
18
+ this.did = did;
19
+ this.metadata = metadata;
20
+ }
21
+
22
+ /**
23
+ * Converts a `BearerIdentity` object to a portable format containing the DID and metadata
24
+ * associated with the Identity.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * // Assuming `identity` is an instance of BearerIdentity.
29
+ * const portableIdentity = await identity.export();
30
+ * // portableIdentity now contains the and metadata.
31
+ * ```
32
+ *
33
+ * @returns A `PortableIdentity` containing the DID and metadata associated with the
34
+ * `BearerIdentity`.
35
+ */
36
+ public async export(): Promise<PortableIdentity> {
37
+ return {
38
+ portableDid : await this.did.export(),
39
+ metadata : { ...this.metadata },
40
+ };
41
+ }
42
+ }
package/src/connect.ts ADDED
@@ -0,0 +1,296 @@
1
+
2
+ import type { PushedAuthResponse } from './oidc.js';
3
+ import type { DwnPermissionScope, DwnProtocolDefinition, Web5Agent, Web5ConnectAuthResponse } from './index.js';
4
+
5
+ import {
6
+ Oidc,
7
+ } from './oidc.js';
8
+ import { pollWithTtl } from './utils.js';
9
+
10
+ import { Convert, logger } from '@enbox/common';
11
+ import { CryptoUtils } from '@enbox/crypto';
12
+ import { DidJwk } from '@enbox/dids';
13
+ import { DwnInterfaceName, DwnMethodName } from '@enbox/dwn-sdk-js';
14
+
15
+ /**
16
+ * Initiates the wallet connect process. Used when a client wants to obtain
17
+ * a did from a provider.
18
+ */
19
+ async function initClient({
20
+ displayName,
21
+ connectServerUrl,
22
+ walletUri,
23
+ permissionRequests,
24
+ onWalletUriReady,
25
+ validatePin,
26
+ }: WalletConnectOptions) {
27
+ // ephemeral client did for ECDH, signing, verification
28
+ // TODO: use separate keys for ECDH vs. sign/verify. could maybe use secp256k1.
29
+ const clientDid = await DidJwk.create();
30
+
31
+ // TODO: properly implement PKCE. this implementation is lacking server side validations and more.
32
+ // https://github.com/TBD54566975/web5-js/issues/829
33
+ // Derive the code challenge based on the code verifier
34
+ // const { codeChallengeBytes, codeChallengeBase64Url } =
35
+ // await Oidc.generateCodeChallenge();
36
+ const encryptionKey = CryptoUtils.randomBytes(32);
37
+
38
+ // build callback URL to pass into the auth request
39
+ const callbackEndpoint = Oidc.buildOidcUrl({
40
+ baseURL : connectServerUrl,
41
+ endpoint : 'callback',
42
+ });
43
+
44
+ // build the PAR request
45
+ const request = await Oidc.createAuthRequest({
46
+ client_id : clientDid.uri,
47
+ scope : 'openid did:jwk',
48
+ redirect_uri : callbackEndpoint,
49
+ // custom properties:
50
+ // code_challenge : codeChallengeBase64Url,
51
+ // code_challenge_method : 'S256',
52
+ permissionRequests : permissionRequests,
53
+ displayName,
54
+ });
55
+
56
+ // Sign the Request Object using the Client DID's signing key.
57
+ const requestJwt = await Oidc.signJwt({
58
+ did : clientDid,
59
+ data : request,
60
+ });
61
+
62
+ if (!requestJwt) {
63
+ throw new Error('Unable to sign requestObject');
64
+ }
65
+ // Encrypt the Request Object JWT using the code challenge.
66
+ const requestObjectJwe = await Oidc.encryptAuthRequest({
67
+ jwt: requestJwt,
68
+ encryptionKey,
69
+ });
70
+
71
+ // Convert the encrypted Request Object to URLSearchParams for form encoding.
72
+ const formEncodedRequest = new URLSearchParams({
73
+ request: requestObjectJwe,
74
+ });
75
+
76
+ const pushedAuthorizationRequestEndpoint = Oidc.buildOidcUrl({
77
+ baseURL : connectServerUrl,
78
+ endpoint : 'pushedAuthorizationRequest',
79
+ });
80
+
81
+ const parResponse = await fetch(pushedAuthorizationRequestEndpoint, {
82
+ body : formEncodedRequest,
83
+ method : 'POST',
84
+ headers : {
85
+ 'Content-Type': 'application/x-www-form-urlencoded',
86
+ },
87
+ });
88
+
89
+ if (!parResponse.ok) {
90
+ throw new Error(`${parResponse.status}: ${parResponse.statusText}`);
91
+ }
92
+
93
+ const parData: PushedAuthResponse = await parResponse.json();
94
+
95
+ // a deeplink to a web5 compatible wallet. if the wallet scans this link it should receive
96
+ // a route to its web5 connect provider flow and the params of where to fetch the auth request.
97
+ logger.log(`Wallet URI: ${walletUri}`);
98
+ const generatedWalletUri = new URL(walletUri);
99
+ generatedWalletUri.searchParams.set('request_uri', parData.request_uri);
100
+ generatedWalletUri.searchParams.set(
101
+ 'encryption_key',
102
+ Convert.uint8Array(encryptionKey).toBase64Url()
103
+ );
104
+
105
+ // call user's callback so they can send the URI to the wallet as they see fit
106
+ onWalletUriReady(generatedWalletUri.toString());
107
+
108
+ const tokenUrl = Oidc.buildOidcUrl({
109
+ baseURL : connectServerUrl,
110
+ endpoint : 'token',
111
+ tokenParam : request.state,
112
+ });
113
+
114
+ // subscribe to receiving a response from the wallet with default TTL. receive ciphertext of {@link Web5ConnectAuthResponse}
115
+ const authResponse = await pollWithTtl(() => fetch(tokenUrl));
116
+
117
+ if (authResponse) {
118
+ const jwe = await authResponse?.text();
119
+
120
+ // get the pin from the user and use it as AAD to decrypt
121
+ const pin = await validatePin();
122
+ const jwt = await Oidc.decryptAuthResponse(clientDid, jwe, pin);
123
+ const verifiedAuthResponse = (await Oidc.verifyJwt({
124
+ jwt,
125
+ })) as Web5ConnectAuthResponse;
126
+
127
+ return {
128
+ delegateGrants : verifiedAuthResponse.delegateGrants,
129
+ delegatePortableDid : verifiedAuthResponse.delegatePortableDid,
130
+ connectedDid : verifiedAuthResponse.iss,
131
+ };
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Initiates the wallet connect process. Used when a client wants to obtain
137
+ * a did from a provider.
138
+ */
139
+ export type WalletConnectOptions = {
140
+ /** The user friendly name of the client/app to be displayed when prompting end-user with permission requests. */
141
+ displayName: string;
142
+
143
+ /** The URL of the intermediary server which relays messages between the client and provider. */
144
+ connectServerUrl: string;
145
+
146
+ /**
147
+ * The URI of the Provider (wallet).The `onWalletUriReady` will take this wallet
148
+ * uri and add a payload to it which will be used to obtain and decrypt from the `request_uri`.
149
+ * @example `web5://` or `http://localhost:3000/`.
150
+ */
151
+ walletUri: string;
152
+
153
+ /**
154
+ * The protocols of permissions requested, along with the definition and
155
+ * permission scopes for each protocol. The key is the protocol URL and
156
+ * the value is an object with the protocol definition and the permission scopes.
157
+ */
158
+ permissionRequests: ConnectPermissionRequest[];
159
+
160
+ /**
161
+ * The Web5 API provides a URI to the wallet based on the `walletUri` plus a query params payload valid for 5 minutes.
162
+ * The link can either be used as a deep link on the same device or a QR code for cross device or both.
163
+ * The query params are `{ request_uri: string; encryption_key: string; }`
164
+ * The wallet will use the `request_uri to contact the intermediary server's `authorize` endpoint
165
+ * and pull down the {@link Web5ConnectAuthRequest} and use the `encryption_key` to decrypt it.
166
+ *
167
+ * @param uri - The URI returned by the web5 connect API to be passed to a provider.
168
+ */
169
+ onWalletUriReady: (uri: string) => void;
170
+
171
+ /**
172
+ * Function that must be provided to submit the pin entered by the user on the client.
173
+ * The pin is used to decrypt the {@link Web5ConnectAuthResponse} that was retrieved from the
174
+ * token endpoint by the client inside of web5 connect.
175
+ *
176
+ * @returns A promise that resolves to the PIN as a string.
177
+ */
178
+ validatePin: () => Promise<string>;
179
+ };
180
+
181
+ /**
182
+ * The protocols of permissions requested, along with the definition and permission scopes for each protocol.
183
+ */
184
+ export type ConnectPermissionRequest = {
185
+ /**
186
+ * The definition of the protocol the permissions are being requested for.
187
+ * In the event that the protocol is not already installed, the wallet will install this given protocol definition.
188
+ */
189
+ protocolDefinition: DwnProtocolDefinition;
190
+
191
+ /** The scope of the permissions being requested for the given protocol */
192
+ permissionScopes: DwnPermissionScope[];
193
+ };
194
+
195
+ /**
196
+ * Shorthand for the types of permissions that can be requested.
197
+ */
198
+ export type Permission = 'write' | 'read' | 'delete' | 'query' | 'subscribe' | 'configure';
199
+
200
+ /**
201
+ * The options for creating a permission request for a given protocol.
202
+ */
203
+ export type ProtocolPermissionOptions = {
204
+ /** The protocol definition for the protocol being requested */
205
+ definition: DwnProtocolDefinition;
206
+
207
+ /** The permissions being requested for the protocol */
208
+ permissions: Permission[];
209
+ };
210
+
211
+ /**
212
+ * Creates a set of Dwn Permission Scopes to request for a given protocol.
213
+ *
214
+ * If no permissions are provided, the default is to request all relevant record permissions (write, read, delete, query, subscribe).
215
+ * 'configure' is not included by default, as this gives the application a lot of control over the protocol.
216
+ */
217
+ function createPermissionRequestForProtocol({ definition, permissions }: ProtocolPermissionOptions): ConnectPermissionRequest {
218
+ const requests: DwnPermissionScope[] = [];
219
+
220
+ // Add the ability to query for the specific protocol
221
+ requests.push({
222
+ protocol : definition.protocol,
223
+ interface : DwnInterfaceName.Protocols,
224
+ method : DwnMethodName.Query,
225
+ });
226
+
227
+ // In order to enable sync, we must request permissions for `MessagesQuery`, `MessagesRead` and `MessagesSubscribe`
228
+ requests.push({
229
+ protocol : definition.protocol,
230
+ interface : DwnInterfaceName.Messages,
231
+ method : DwnMethodName.Read,
232
+ }, {
233
+ protocol : definition.protocol,
234
+ interface : DwnInterfaceName.Messages,
235
+ method : DwnMethodName.Query,
236
+ }, {
237
+ protocol : definition.protocol,
238
+ interface : DwnInterfaceName.Messages,
239
+ method : DwnMethodName.Subscribe,
240
+ });
241
+
242
+ // We also request any additional permissions the user has requested for this protocol
243
+ for (const permission of permissions) {
244
+ switch (permission) {
245
+ case 'write':
246
+ requests.push({
247
+ protocol : definition.protocol,
248
+ interface : DwnInterfaceName.Records,
249
+ method : DwnMethodName.Write,
250
+ });
251
+ break;
252
+ case 'read':
253
+ requests.push({
254
+ protocol : definition.protocol,
255
+ interface : DwnInterfaceName.Records,
256
+ method : DwnMethodName.Read,
257
+ });
258
+ break;
259
+ case 'delete':
260
+ requests.push({
261
+ protocol : definition.protocol,
262
+ interface : DwnInterfaceName.Records,
263
+ method : DwnMethodName.Delete,
264
+ });
265
+ break;
266
+ case 'query':
267
+ requests.push({
268
+ protocol : definition.protocol,
269
+ interface : DwnInterfaceName.Records,
270
+ method : DwnMethodName.Query,
271
+ });
272
+ break;
273
+ case 'subscribe':
274
+ requests.push({
275
+ protocol : definition.protocol,
276
+ interface : DwnInterfaceName.Records,
277
+ method : DwnMethodName.Subscribe,
278
+ });
279
+ break;
280
+ case 'configure':
281
+ requests.push({
282
+ protocol : definition.protocol,
283
+ interface : DwnInterfaceName.Protocols,
284
+ method : DwnMethodName.Configure,
285
+ });
286
+ break;
287
+ }
288
+ }
289
+
290
+ return {
291
+ protocolDefinition : definition,
292
+ permissionScopes : requests,
293
+ };
294
+ }
295
+
296
+ export const WalletConnect = { initClient, createPermissionRequestForProtocol };