@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,157 @@
1
+ import type { Jwk, KeyIdentifier, KmsExportKeyParams, KmsGetPublicKeyParams, KmsSignParams } from '@enbox/crypto';
2
+
3
+ import { Ed25519, LocalKeyManager, computeJwkThumbprint } from '@enbox/crypto';
4
+
5
+ import type { Web5PlatformAgent } from './types/agent.js';
6
+
7
+ /**
8
+ * Internal utility functions used by the Web5 platform agent that are not intended for public use
9
+ * and are not exported in the public API.
10
+ */
11
+
12
+ /**
13
+ * Separator used to join the tenant DID and the DID URI that is used to prefix all lookups in the
14
+ * Agent data stores, including the DWN-backed store's index and the in-memory store's map.
15
+ */
16
+ export const TENANT_SEPARATOR = '^';
17
+
18
+ export class DeterministicKeyGenerator extends LocalKeyManager {
19
+ private _predefinedKeys: Map<KeyIdentifier, Jwk>;
20
+ private _keyGenerator: IterableIterator<KeyIdentifier>;
21
+
22
+ constructor() {
23
+ super();
24
+ this._predefinedKeys = new Map();
25
+ this._keyGenerator = this._predefinedKeys.keys();
26
+ }
27
+
28
+ public async addPredefinedKeys({ privateKeys }: { privateKeys: Jwk[] }): Promise<void> {
29
+ const predefinedKeys: { [keyUri: KeyIdentifier]: Jwk } = {};
30
+
31
+ for (const key of privateKeys) {
32
+ // If the key ID is undefined, set it to the JWK thumbprint.
33
+ key.kid ??= await computeJwkThumbprint({ jwk: key });
34
+
35
+ // Compute the key URI for the key.
36
+ const keyUri = await this.getKeyUri({ key });
37
+
38
+ // Store the key.
39
+ predefinedKeys[keyUri] = key;
40
+ }
41
+
42
+ // Store the keys.
43
+ this._predefinedKeys = new Map(Object.entries(predefinedKeys));
44
+
45
+ // Reset the key generator to use the new keys.
46
+ this._keyGenerator = this._predefinedKeys.keys();
47
+ }
48
+
49
+ public async exportKey({ keyUri }:
50
+ KmsExportKeyParams
51
+ ): Promise<Jwk> {
52
+ // Get the private key from the key store.
53
+ const privateKey = this._predefinedKeys.get(keyUri);
54
+
55
+ // Throw an error if the key is not found.
56
+ if (!privateKey) {
57
+ throw new Error(`DeterministicKeyGenerator.exportKey: Key not found: ${keyUri}`);
58
+ }
59
+
60
+ return privateKey;
61
+ }
62
+
63
+ public async generateKey(_params: {
64
+ algorithm: 'Ed25519' | 'secp256k1' | 'secp256r1'
65
+ }): Promise<KeyIdentifier> {
66
+ // Get the next key from the array of predefined keys.
67
+ const { value: keyUri, done } = this._keyGenerator.next();
68
+
69
+ // Throw an error if the generator is empty and there are no more keys to return.
70
+ if (done) {
71
+ throw new Error('Ran out of predefined keys');
72
+ }
73
+
74
+ return keyUri;
75
+ }
76
+
77
+ public async getPublicKey({ keyUri }:
78
+ KmsGetPublicKeyParams
79
+ ): Promise<Jwk> {
80
+ // Get the private key from the key store.
81
+ const privateKey = this._predefinedKeys.get(keyUri);
82
+
83
+ // Throw an error if the key is not found.
84
+ if (!privateKey) {
85
+ throw new Error(`DeterministicKeyGenerator.getPublicKey: Key not found: ${keyUri}`);
86
+ }
87
+
88
+ // Get the public key properties from the private JWK.
89
+ const { d, ...publicKey } = privateKey;
90
+
91
+ return publicKey;
92
+ }
93
+
94
+ public async sign({ keyUri, data }:
95
+ KmsSignParams
96
+ ): Promise<Uint8Array> {
97
+ // Get the private key from the key store.
98
+ const privateKey = this._predefinedKeys.get(keyUri);
99
+
100
+ // Throw an error if the key is not found.
101
+ if (!privateKey) {
102
+ throw new Error(`DeterministicKeyGenerator.sign: Key not found: ${keyUri}`);
103
+ }
104
+
105
+ // Sign the data.
106
+ const signature = await Ed25519.sign({ data, key: privateKey });
107
+
108
+ return signature;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Determines the tenant identifier (DID) for data store operations based on the provided
114
+ * parameters.
115
+ *
116
+ * The function identifies the tenant using a priority order:
117
+ * 1. directly provided tenant DID,
118
+ * 2. the agent's DID,
119
+ * 3. or a specified DID URI.
120
+ *
121
+ * This approach ensures operations are isolated by DID, supporting multi-tenancy.
122
+ *
123
+ * @param params - The parameters for determining the tenant.
124
+ * @param params.agent - The Web5 platform agent instance.
125
+ * @param [params.tenant] - An optional tenant DID. If provided, it takes precedence.
126
+ * @param [params.didUri] - An optional DID URI to use if no tenant DID or agent DID is available.
127
+ * @returns A promise that resolves to the tenant DID.
128
+ * @throws Throws an error if it fails to determine the tenant from the provided inputs.
129
+ */
130
+ export async function getDataStoreTenant({ agent, tenant, didUri }: {
131
+ agent: Web5PlatformAgent;
132
+ tenant?: string;
133
+ didUri?: string;
134
+ }): Promise<string> {
135
+ // Check if a tenant identifier (DID) is explicitly provided and return it immediately if so.
136
+ // This is the highest priority to ensure explicit tenant isolation.
137
+ if (tenant) return tenant;
138
+
139
+ // If the agent's DID is available, return it as the tenant identifier.
140
+ // This allows using the agent's own identity as a fallback tenant.
141
+ if (agent.agentDid) return agent.agentDid.uri;
142
+
143
+ // Throw an error if neither tenant, agent.agentDid, nor didUri are provided,
144
+ // as it's not possible to determine the tenant identifier without any of these.
145
+ if (!didUri) {
146
+ throw new Error(`Failed to determine tenant DID: 'agent.agentDid', 'tenant', and 'didUri' are undefined`);
147
+ }
148
+
149
+ // Return the DID URI as the tenant identifier if both `tenant` and `agent.agentDid` are undefined
150
+ // but a `didUri` is provided. This assumes the agent has the necessary permissions and keys
151
+ // associated with the provided DID for data store operations.
152
+ //
153
+ // Note: This assumes the Agent's key manager has the private key for the given DID URI. No
154
+ // explicit check is made here for performance reasons, relying on downstream processes to
155
+ // validate access rights.
156
+ return didUri;
157
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,181 @@
1
+ import type { DidUrlDereferencer } from '@enbox/dids';
2
+ import { Jws, PaginationCursor, RecordsDeleteMessage, RecordsWriteMessage } from '@enbox/dwn-sdk-js';
3
+
4
+ import { Readable } from '@enbox/common';
5
+ import { utils as didUtils } from '@enbox/dids';
6
+ import { ReadableWebToNodeStream } from 'readable-web-to-node-stream';
7
+ import { DateSort, DwnInterfaceName, DwnMethodName, Message, RecordsWrite } from '@enbox/dwn-sdk-js';
8
+
9
+ export function blobToIsomorphicNodeReadable(blob: Blob): Readable {
10
+ return webReadableToIsomorphicNodeReadable(blob.stream() as ReadableStream<any>);
11
+ }
12
+
13
+ export async function getDwnServiceEndpointUrls(didUri: string, dereferencer: DidUrlDereferencer): Promise<string[]> {
14
+ // Attempt to dereference the DID service with ID fragment #dwn.
15
+ const dereferencingResult = await dereferencer.dereference(`${didUri}#dwn`);
16
+
17
+ if (dereferencingResult.dereferencingMetadata.error) {
18
+ throw new Error(`Failed to dereference '${didUri}#dwn': ${dereferencingResult.dereferencingMetadata.error}`);
19
+ }
20
+
21
+ if (didUtils.isDwnDidService(dereferencingResult.contentStream)) {
22
+ const { serviceEndpoint } = dereferencingResult.contentStream;
23
+ const serviceEndpointUrls = typeof serviceEndpoint === 'string'
24
+ // If the service endpoint is a string, format it as a single-element array.
25
+ ? [serviceEndpoint]
26
+ : Array.isArray(serviceEndpoint) && serviceEndpoint.every(endpoint => typeof endpoint === 'string')
27
+ // If the service endpoint is an array of strings, use it as is.
28
+ ? serviceEndpoint as string[]
29
+ // If the service endpoint is neither a string nor an array of strings, return an empty array.
30
+ : [];
31
+
32
+ if (serviceEndpointUrls.length > 0) {
33
+ return serviceEndpointUrls;
34
+ }
35
+ }
36
+
37
+ // If the DID service with ID fragment #dwn was not found or is not valid, return an empty array.
38
+ return [];
39
+ }
40
+
41
+ export function getRecordAuthor(record: RecordsWriteMessage | RecordsDeleteMessage): string | undefined {
42
+ return Message.getAuthor(record);
43
+ }
44
+
45
+ /**
46
+ * Get the `protocolRole` string from the signature payload of the given RecordsWriteMessage or RecordsDeleteMessage.
47
+ */
48
+ export function getRecordProtocolRole(message: RecordsWriteMessage | RecordsDeleteMessage): string | undefined {
49
+ const signaturePayload = Jws.decodePlainObjectPayload(message.authorization.signature);
50
+ return signaturePayload?.protocolRole;
51
+ }
52
+
53
+ export function isRecordsWrite(obj: unknown): obj is RecordsWrite {
54
+ // Validate that the given value is an object.
55
+ if (!obj || typeof obj !== 'object' || obj === null) return false;
56
+
57
+ // Validate that the object has the necessary properties of RecordsWrite.
58
+ return (
59
+ 'message' in obj && typeof obj.message === 'object' && obj.message !== null &&
60
+ 'descriptor' in obj.message && typeof obj.message.descriptor === 'object' && obj.message.descriptor !== null &&
61
+ 'interface' in obj.message.descriptor && obj.message.descriptor.interface === DwnInterfaceName.Records &&
62
+ 'method' in obj.message.descriptor && obj.message.descriptor.method === DwnMethodName.Write
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Get the CID of the given RecordsWriteMessage.
68
+ */
69
+ export function getRecordMessageCid(message: RecordsWriteMessage): Promise<string> {
70
+ return Message.getCid(message);
71
+ }
72
+
73
+ /**
74
+ * Get the pagination cursor for the given RecordsWriteMessage and DateSort.
75
+ *
76
+ * @param message The RecordsWriteMessage for which to get the pagination cursor.
77
+ * @param dateSort The date sort that will be used in the query or subscription to which the cursor will be applied.
78
+ */
79
+ export async function getPaginationCursor(message: RecordsWriteMessage, dateSort: DateSort): Promise<PaginationCursor> {
80
+ const value = dateSort === DateSort.CreatedAscending || dateSort === DateSort.CreatedDescending ?
81
+ message.descriptor.dateCreated : message.descriptor.datePublished;
82
+
83
+ if (value === undefined) {
84
+ throw new Error('The dateCreated or datePublished property is missing from the record descriptor.');
85
+ }
86
+
87
+ return {
88
+ messageCid: await getRecordMessageCid(message),
89
+ value
90
+ };
91
+ }
92
+
93
+ export function webReadableToIsomorphicNodeReadable(webReadable: ReadableStream<any>) {
94
+ return new ReadableWebToNodeStream(webReadable);
95
+ }
96
+
97
+ /**
98
+ * Polling function with interval, TTL accepting a custom fetch function
99
+ * @template T - the return you expect from the fetcher
100
+ * @param fetchFunction an http fetch function
101
+ * @param [interval=3000] how frequently to poll
102
+ * @param [ttl=300_000] how long until polling stops
103
+ * @returns T - the result of fetch
104
+ */
105
+ export function pollWithTtl(
106
+ fetchFunction: () => Promise<Response>,
107
+ interval = 3000,
108
+ ttl = 300_000,
109
+ abortSignal?: AbortSignal
110
+ ): Promise<Response | null> {
111
+ const endTime = Date.now() + ttl;
112
+ let timeoutId: NodeJS.Timeout | null = null;
113
+ let isPolling = true;
114
+ return new Promise((resolve, reject) => {
115
+ if (abortSignal) {
116
+ abortSignal.addEventListener('abort', () => {
117
+ isPolling = false;
118
+ if (timeoutId !== null) {
119
+ clearTimeout(timeoutId);
120
+ }
121
+ console.log('Polling aborted by user');
122
+ resolve(null);
123
+ });
124
+ }
125
+
126
+ async function poll() {
127
+ if (!isPolling) return;
128
+
129
+ const remainingTime = endTime - Date.now();
130
+
131
+ if (remainingTime <= 0) {
132
+ isPolling = false;
133
+ console.log('Polling stopped: TTL reached');
134
+ resolve(null);
135
+ return;
136
+ }
137
+
138
+ console.log(`Polling... (Remaining time: ${Math.ceil(remainingTime / 1000)}s)`);
139
+
140
+ try {
141
+ const response = await fetchFunction();
142
+
143
+ if (response.ok) {
144
+ isPolling = false;
145
+
146
+ if (timeoutId !== null) {
147
+ clearTimeout(timeoutId);
148
+ }
149
+
150
+ console.log('Polling stopped: Success condition met');
151
+ resolve(response);
152
+ return;
153
+ }
154
+ } catch (error) {
155
+ console.error('Error fetching data:', error);
156
+ reject(error);
157
+ }
158
+
159
+ if (isPolling) {
160
+ timeoutId = setTimeout(poll, interval);
161
+ }
162
+ }
163
+
164
+ poll();
165
+ });
166
+ }
167
+
168
+ /** Concatenates a base URL and a path ensuring that there is exactly one slash between them */
169
+ export function concatenateUrl(baseUrl: string, path: string): string {
170
+ // Remove trailing slash from baseUrl if it exists
171
+ if (baseUrl.endsWith('/')) {
172
+ baseUrl = baseUrl.slice(0, -1);
173
+ }
174
+
175
+ // Remove leading slash from path if it exists
176
+ if (path.startsWith('/')) {
177
+ path = path.slice(1);
178
+ }
179
+
180
+ return `${baseUrl}/${path}`;
181
+ }