@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,320 @@
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 ms from 'ms';
11
+ import { Convert, NodeStream, TtlCache } from '@enbox/common';
12
+ import { TENANT_SEPARATOR } from './utils-internal.js';
13
+ import { getDataStoreTenant } from './utils-internal.js';
14
+ import { DwnInterface } from './types/dwn.js';
15
+ export class DwnDataStore {
16
+ constructor() {
17
+ this.name = 'DwnDataStore';
18
+ /**
19
+ * Cache of Store Objects referenced by DWN record ID to Store Objects.
20
+ *
21
+ * Up to 100 entries are retained for 15 minutes.
22
+ */
23
+ this._cache = new TtlCache({ ttl: ms('15 minutes'), max: 100 });
24
+ /**
25
+ * Index for mappings from Store Identifier to DWN record ID.
26
+ * Since these values don't change, we can use a long TTL.
27
+ *
28
+ * Up to 1,000 entries are retained for 21 days.
29
+ * NOTE: The maximum number for the ttl is 2^31 - 1 milliseconds (24.8 days), setting to 21 days to be safe.
30
+ */
31
+ this._index = new TtlCache({ ttl: ms('21 days'), max: 1000 });
32
+ /**
33
+ * Cache of tenant DIDs that have been initialized with the protocol.
34
+ * This is used to avoid redundant protocol initialization requests.
35
+ *
36
+ * Since these are default protocols and unlikely to change, we can use a long TTL.
37
+ */
38
+ this._protocolInitializedCache = new TtlCache({ ttl: ms('21 days'), max: 1000 });
39
+ /**
40
+ * Properties to use when writing and querying records with the DWN store.
41
+ */
42
+ this._recordProperties = {
43
+ dataFormat: 'application/json',
44
+ };
45
+ }
46
+ delete({ id, agent, tenant }) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ // Determine the tenant identifier (DID) for the delete operation.
49
+ const tenantDid = yield getDataStoreTenant({ agent, tenant, didUri: id });
50
+ // Look up the DWN record ID of the object in the store with the given `id`.
51
+ let matchingRecordId = yield this.lookupRecordId({ id, tenantDid, agent });
52
+ // Return false if the given ID was not found in the store.
53
+ if (!matchingRecordId)
54
+ return false;
55
+ // If a record for the given ID was found, attempt to delete it.
56
+ const { reply: { status } } = yield agent.dwn.processRequest({
57
+ author: tenantDid,
58
+ target: tenantDid,
59
+ messageType: DwnInterface.RecordsDelete,
60
+ messageParams: { recordId: matchingRecordId }
61
+ });
62
+ // If the record was successfully deleted, update the index/cache and return true;
63
+ if (status.code === 202) {
64
+ this._index.delete(`${tenantDid}${TENANT_SEPARATOR}${id}`);
65
+ this._cache.delete(matchingRecordId);
66
+ return true;
67
+ }
68
+ // If the Delete operation failed, throw an error.
69
+ throw new Error(`${this.name}: Failed to delete '${id}' from store: (${status.code}) ${status.detail}`);
70
+ });
71
+ }
72
+ get({ id, agent, tenant, useCache = false }) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ // Determine the tenant identifier (DID) for the list operation.
75
+ const tenantDid = yield getDataStoreTenant({ agent, tenant, didUri: id });
76
+ // Look up the DWN record ID of the object in the store with the given `id`.
77
+ let matchingRecordId = yield this.lookupRecordId({ id, tenantDid, agent });
78
+ // Return undefined if no matches were found.
79
+ if (!matchingRecordId)
80
+ return undefined;
81
+ // Retrieve and return the stored object.
82
+ return yield this.getRecord({ recordId: matchingRecordId, tenantDid, agent, useCache });
83
+ });
84
+ }
85
+ list({ agent, tenant }) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ // Determine the tenant identifier (DID) for the list operation.
88
+ const tenantDid = yield getDataStoreTenant({ tenant, agent });
89
+ // Query the DWN for all stored record objects.
90
+ const storedRecords = yield this.getAllRecords({ agent, tenantDid });
91
+ return storedRecords;
92
+ });
93
+ }
94
+ set({ id, data, tenant, agent, preventDuplicates = true, updateExisting = false, useCache = false }) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ // Determine the tenant identifier (DID) for the set operation.
97
+ const tenantDid = yield getDataStoreTenant({ agent, tenant, didUri: id });
98
+ // initialize the storage protocol if not already done
99
+ yield this.initialize({ tenant: tenantDid, agent });
100
+ const messageParams = Object.assign({}, this._recordProperties);
101
+ if (updateExisting) {
102
+ // Look up the DWN record ID of the object in the store with the given `id`.
103
+ const matchingRecordEntry = yield this.getExistingRecordEntry({ id, tenantDid, agent });
104
+ if (!matchingRecordEntry) {
105
+ throw new Error(`${this.name}: Update failed due to missing entry for: ${id}`);
106
+ }
107
+ // set the recordId in the messageParams to update the existing record
108
+ // set the dateCreated to the existing dateCreated as this is an immutable property
109
+ messageParams.recordId = matchingRecordEntry.recordsWrite.recordId;
110
+ messageParams.dateCreated = matchingRecordEntry.recordsWrite.descriptor.dateCreated;
111
+ }
112
+ else if (preventDuplicates) {
113
+ // Look up the DWN record ID of the object in the store with the given `id`.
114
+ const matchingRecordId = yield this.lookupRecordId({ id, tenantDid, agent });
115
+ if (matchingRecordId) {
116
+ throw new Error(`${this.name}: Import failed due to duplicate entry for: ${id}`);
117
+ }
118
+ }
119
+ // Convert the store object to a byte array, which will be the data payload of the DWN record.
120
+ const dataBytes = Convert.object(data).toUint8Array();
121
+ // Store the record in the DWN.
122
+ const { message, reply: { status } } = yield agent.dwn.processRequest({
123
+ author: tenantDid,
124
+ target: tenantDid,
125
+ messageType: DwnInterface.RecordsWrite,
126
+ messageParams: Object.assign(Object.assign({}, this._recordProperties), messageParams),
127
+ dataStream: new Blob([dataBytes], { type: 'application/json' })
128
+ });
129
+ // If the write fails, throw an error.
130
+ if (!(message && status.code === 202)) {
131
+ throw new Error(`${this.name}: Failed to write data to store for ${id}: ${status.detail}`);
132
+ }
133
+ // Add the ID of the newly created record to the index.
134
+ this._index.set(`${tenantDid}${TENANT_SEPARATOR}${id}`, message.recordId);
135
+ // If caching is enabled, add the store object to the cache.
136
+ if (useCache) {
137
+ this._cache.set(message.recordId, data);
138
+ }
139
+ });
140
+ }
141
+ /**
142
+ * Initialize the relevant protocol for the given tenant.
143
+ * This confirms that the storage protocol is configured, otherwise it will be installed.
144
+ */
145
+ initialize({ tenant, agent }) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ const tenantDid = yield getDataStoreTenant({ agent, tenant });
148
+ if (this._protocolInitializedCache.has(tenantDid)) {
149
+ return;
150
+ }
151
+ const { reply: { status, entries } } = yield agent.dwn.processRequest({
152
+ author: tenantDid,
153
+ target: tenantDid,
154
+ messageType: DwnInterface.ProtocolsQuery,
155
+ messageParams: {
156
+ filter: {
157
+ protocol: this._recordProtocolDefinition.protocol
158
+ }
159
+ },
160
+ });
161
+ if (status.code !== 200) {
162
+ throw new Error(`Failed to query for protocols: ${status.code} - ${status.detail}`);
163
+ }
164
+ if ((entries === null || entries === void 0 ? void 0 : entries.length) === 0) {
165
+ // protocol is not installed, install it
166
+ yield this.installProtocol(tenantDid, agent);
167
+ }
168
+ this._protocolInitializedCache.set(tenantDid, true);
169
+ });
170
+ }
171
+ getAllRecords(_params) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ throw new Error('Not implemented: Classes extending DwnDataStore must implement getAllRecords()');
174
+ });
175
+ }
176
+ getRecord({ recordId, tenantDid, agent, useCache }) {
177
+ var _a;
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ // If caching is enabled, check the cache for the record ID.
180
+ if (useCache) {
181
+ const record = this._cache.get(recordId);
182
+ // If the record ID was present in the cache, return the associated store object.
183
+ if (record)
184
+ return record;
185
+ // Otherwise, continue to read from the store.
186
+ }
187
+ // Read the record from the store.
188
+ const { reply: readReply } = yield agent.dwn.processRequest({
189
+ author: tenantDid,
190
+ target: tenantDid,
191
+ messageType: DwnInterface.RecordsRead,
192
+ messageParams: { filter: { recordId } }
193
+ });
194
+ if (!((_a = readReply.entry) === null || _a === void 0 ? void 0 : _a.data)) {
195
+ throw new Error(`${this.name}: Failed to read data from DWN for: ${recordId}`);
196
+ }
197
+ // If the record was found, convert back to store object format.
198
+ const storeObject = yield NodeStream.consumeToJson({ readable: readReply.entry.data });
199
+ // If caching is enabled, add the store object to the cache.
200
+ if (useCache) {
201
+ this._cache.set(recordId, storeObject);
202
+ }
203
+ return storeObject;
204
+ });
205
+ }
206
+ /**
207
+ * Install the protocol for the given tenant using a `ProtocolsConfigure` message.
208
+ */
209
+ installProtocol(tenant, agent) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const { reply: { status } } = yield agent.dwn.processRequest({
212
+ author: tenant,
213
+ target: tenant,
214
+ messageType: DwnInterface.ProtocolsConfigure,
215
+ messageParams: {
216
+ definition: this._recordProtocolDefinition
217
+ },
218
+ });
219
+ if (status.code !== 202) {
220
+ throw new Error(`Failed to install protocol: ${status.code} - ${status.detail}`);
221
+ }
222
+ });
223
+ }
224
+ lookupRecordId({ id, tenantDid, agent }) {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ // Check the index for a matching ID and extend the index TTL.
227
+ let recordId = this._index.get(`${tenantDid}${TENANT_SEPARATOR}${id}`, { updateAgeOnGet: true });
228
+ // If no matching record ID was found in the index...
229
+ if (!recordId) {
230
+ // Query the DWN for all stored objects, which rebuilds the index.
231
+ yield this.getAllRecords({ agent, tenantDid });
232
+ // Check the index again for a matching ID.
233
+ recordId = this._index.get(`${tenantDid}${TENANT_SEPARATOR}${id}`);
234
+ }
235
+ return recordId;
236
+ });
237
+ }
238
+ getExistingRecordEntry({ id, tenantDid, agent }) {
239
+ return __awaiter(this, void 0, void 0, function* () {
240
+ // Look up the DWN record ID of the object in the store with the given `id`.
241
+ const recordId = yield this.lookupRecordId({ id, tenantDid, agent });
242
+ if (recordId) {
243
+ // Read the record from the store.
244
+ const { reply: readReply } = yield agent.dwn.processRequest({
245
+ author: tenantDid,
246
+ target: tenantDid,
247
+ messageType: DwnInterface.RecordsRead,
248
+ messageParams: { filter: { recordId } }
249
+ });
250
+ return readReply.entry;
251
+ }
252
+ });
253
+ }
254
+ }
255
+ export class InMemoryDataStore {
256
+ constructor() {
257
+ this.name = 'InMemoryDataStore';
258
+ /**
259
+ * A private field that contains the Map used as the in-memory data store.
260
+ */
261
+ this.store = new Map();
262
+ }
263
+ delete({ id, agent, tenant }) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ // Determine the tenant identifier (DID) for the delete operation.
266
+ const tenantDid = yield getDataStoreTenant({ agent, tenant, didUri: id });
267
+ if (this.store.has(`${tenantDid}${TENANT_SEPARATOR}${id}`)) {
268
+ // Record with given identifier exists so proceed with delete.
269
+ this.store.delete(`${tenantDid}${TENANT_SEPARATOR}${id}`);
270
+ return true;
271
+ }
272
+ // Record with given identifier not present so delete operation not possible.
273
+ return false;
274
+ });
275
+ }
276
+ get({ id, agent, tenant }) {
277
+ return __awaiter(this, void 0, void 0, function* () {
278
+ // Determine the tenant identifier (DID) for the get operation.
279
+ const tenantDid = yield getDataStoreTenant({ agent, tenant, didUri: id });
280
+ return this.store.get(`${tenantDid}${TENANT_SEPARATOR}${id}`);
281
+ });
282
+ }
283
+ list({ agent, tenant }) {
284
+ return __awaiter(this, void 0, void 0, function* () {
285
+ // Determine the tenant identifier (DID) for the list operation.
286
+ const tenantDid = yield getDataStoreTenant({ tenant, agent });
287
+ const result = [];
288
+ for (const [key, storedRecord] of this.store.entries()) {
289
+ if (key.startsWith(`${tenantDid}${TENANT_SEPARATOR}`)) {
290
+ result.push(storedRecord);
291
+ }
292
+ }
293
+ return result;
294
+ });
295
+ }
296
+ set({ id, data, tenant, agent, preventDuplicates, updateExisting }) {
297
+ return __awaiter(this, void 0, void 0, function* () {
298
+ // Determine the tenant identifier (DID) for the set operation.
299
+ const tenantDid = yield getDataStoreTenant({ agent, tenant, didUri: id });
300
+ // If enabled, check if a record with the given `id` is already present in the store.
301
+ if (updateExisting) {
302
+ // Look up the DWN record ID of the object in the store with the given `id`.
303
+ if (!this.store.has(`${tenantDid}${TENANT_SEPARATOR}${id}`)) {
304
+ throw new Error(`${this.name}: Update failed due to missing entry for: ${id}`);
305
+ }
306
+ // set the recordId in the messageParams to update the existing record
307
+ }
308
+ else if (preventDuplicates) {
309
+ const duplicateFound = this.store.has(`${tenantDid}${TENANT_SEPARATOR}${id}`);
310
+ if (duplicateFound) {
311
+ throw new Error(`${this.name}: Import failed due to duplicate entry for: ${id}`);
312
+ }
313
+ }
314
+ // Make a deep copy so that the object stored does not share the same references as the input.
315
+ const clonedData = structuredClone(data);
316
+ this.store.set(`${tenantDid}${TENANT_SEPARATOR}${id}`, clonedData);
317
+ });
318
+ }
319
+ }
320
+ //# sourceMappingURL=store-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-data.js","sourceRoot":"","sources":["../../src/store-data.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAI9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,q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CAAC;iBAC3B;aACF;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;IAEY,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAoC;;YAC/G,+DAA+D;YAC/D,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;YAE1E,qFAAqF;YACrF,IAAI,cAAc,EAAE;gBAClB,4EAA4E;gBAC5E,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,gBAAgB,GAAG,EAAE,EAAE,CAAC,EAAE;oBAC3D,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,6CAA6C,EAAE,EAAE,CAAC,CAAC;iBAChF;gBAED,sEAAsE;aACvE;iBAAM,IAAI,iBAAiB,EAAE;gBAC5B,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,gBAAgB,GAAG,EAAE,EAAE,CAAC,CAAC;gBAC9E,IAAI,cAAc,EAAE;oBAClB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,+CAA+C,EAAE,EAAE,CAAC,CAAC;iBAClF;aACF;YAED,8FAA8F;YAC9F,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,gBAAgB,GAAG,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QACrE,CAAC;KAAA;CACF"}
@@ -0,0 +1,136 @@
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 { Convert } from '@enbox/common';
11
+ import { DwnInterface } from './types/dwn.js';
12
+ import { IdentityProtocolDefinition } from './store-data-protocols.js';
13
+ import { isPortableDid } from './prototyping/dids/utils.js';
14
+ import { TENANT_SEPARATOR } from './utils-internal.js';
15
+ import { DwnDataStore, InMemoryDataStore } from './store-data.js';
16
+ export class DwnDidStore extends DwnDataStore {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.name = 'DwnDidStore';
20
+ this._recordProtocolDefinition = IdentityProtocolDefinition;
21
+ /**
22
+ * Properties to use when writing and querying DID records with the DWN store.
23
+ */
24
+ this._recordProperties = {
25
+ dataFormat: 'application/json',
26
+ protocol: this._recordProtocolDefinition.protocol,
27
+ protocolPath: 'portableDid',
28
+ schema: this._recordProtocolDefinition.types.portableDid.schema,
29
+ };
30
+ }
31
+ delete(params) {
32
+ const _super = Object.create(null, {
33
+ delete: { get: () => super.delete }
34
+ });
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ return yield _super.delete.call(this, params);
37
+ });
38
+ }
39
+ get(params) {
40
+ const _super = Object.create(null, {
41
+ get: { get: () => super.get }
42
+ });
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ return yield _super.get.call(this, params);
45
+ });
46
+ }
47
+ list(params) {
48
+ const _super = Object.create(null, {
49
+ list: { get: () => super.list }
50
+ });
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return yield _super.list.call(this, params);
53
+ });
54
+ }
55
+ set(params) {
56
+ const _super = Object.create(null, {
57
+ set: { get: () => super.set }
58
+ });
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ return yield _super.set.call(this, params);
61
+ });
62
+ }
63
+ getAllRecords({ agent, tenantDid }) {
64
+ var _a;
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ // Clear the index since it will be rebuilt from the query results.
67
+ this._index.clear();
68
+ // Query the DWN for all stored PortableDid objects.
69
+ const { reply: queryReply } = yield agent.dwn.processRequest({
70
+ author: tenantDid,
71
+ target: tenantDid,
72
+ messageType: DwnInterface.RecordsQuery,
73
+ messageParams: { filter: Object.assign({}, this._recordProperties) }
74
+ });
75
+ // Loop through all of the stored DID records and accumulate the DID objects.
76
+ let storedDids = [];
77
+ for (const record of (_a = queryReply.entries) !== null && _a !== void 0 ? _a : []) {
78
+ // All DID records are expected to be small enough such that the data is returned with the
79
+ // query results. If a record is returned without `encodedData` this is unexpected so throw
80
+ // an error.
81
+ if (!record.encodedData) {
82
+ throw new Error(`${this.name}: Expected 'encodedData' to be present in the DWN query result entry`);
83
+ }
84
+ const storedDid = Convert.base64Url(record.encodedData).toObject();
85
+ if (isPortableDid(storedDid)) {
86
+ // Update the index with the matching record ID.
87
+ const indexKey = `${tenantDid}${TENANT_SEPARATOR}${storedDid.uri}`;
88
+ this._index.set(indexKey, record.recordId);
89
+ // Add the stored DID to the cache.
90
+ this._cache.set(record.recordId, storedDid);
91
+ storedDids.push(storedDid);
92
+ }
93
+ }
94
+ return storedDids;
95
+ });
96
+ }
97
+ }
98
+ export class InMemoryDidStore extends InMemoryDataStore {
99
+ constructor() {
100
+ super(...arguments);
101
+ this.name = 'InMemoryDidStore';
102
+ }
103
+ delete(params) {
104
+ const _super = Object.create(null, {
105
+ delete: { get: () => super.delete }
106
+ });
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ return yield _super.delete.call(this, params);
109
+ });
110
+ }
111
+ get(params) {
112
+ const _super = Object.create(null, {
113
+ get: { get: () => super.get }
114
+ });
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ return yield _super.get.call(this, params);
117
+ });
118
+ }
119
+ list(params) {
120
+ const _super = Object.create(null, {
121
+ list: { get: () => super.list }
122
+ });
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ return yield _super.list.call(this, params);
125
+ });
126
+ }
127
+ set(params) {
128
+ const _super = Object.create(null, {
129
+ set: { get: () => super.set }
130
+ });
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ return yield _super.set.call(this, params);
133
+ });
134
+ }
135
+ }
136
+ //# sourceMappingURL=store-did.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-did.js","sourceRoot":"","sources":["../../src/store-did.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAKxC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,OAAO,WAAY,SAAQ,YAAyB;IAA1D;;QACY,SAAI,GAAG,aAAa,CAAC;QAErB,8BAAyB,GAAG,0BAA0B,CAAC;QAEjE;;WAEG;QACO,sBAAiB,GAAG;YAC5B,UAAU,EAAK,kBAAkB;YACjC,QAAQ,EAAO,IAAI,CAAC,yBAAyB,CAAC,QAAQ;YACtD,YAAY,EAAG,aAAa;YAC5B,MAAM,EAAS,IAAI,CAAC,yBAAyB,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM;SACvE,CAAC;IA0DJ,CAAC;IAxDc,MAAM,CAAC,MAA6B;;;;;YAC/C,OAAO,MAAM,OAAM,MAAM,YAAC,MAAM,CAAC,CAAC;QACpC,CAAC;KAAA;IAEY,GAAG,CAAC,MAA0B;;;;;YACzC,OAAO,MAAM,OAAM,GAAG,YAAC,MAAM,CAAC,CAAC;QACjC,CAAC;KAAA;IAEY,IAAI,CAAC,MAA2B;;;;;YAC3C,OAAO,MAAM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M,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;oBAE5C,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBAC5B;aACF;YAED,OAAO,UAAU,CAAC;;KACnB;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,iBAA8B;IAApE;;QACY,SAAI,GAAG,kBAAkB,CAAC;IAiBtC,CAAC;IAfc,MAAM,CAAC,MAA6B;;;;;YAC/C,OAAO,MAAM,OAAM,MAAM,YAAC,MAAM,CAAC,CAAC;QACpC,CAAC;KAAA;IAEY,GAAG,CAAC,MAA0B;;;;;YACzC,OAAO,MAAM,OAAM,GAAG,YAAC,MAAM,CAAC,CAAC;QACjC,CAAC;KAAA;IAEY,IAAI,CAAC,MAA2B;;;;;YAC3C,OAAO,MAAM,OAAM,IAAI,YAAC,MAAM,CAAC,CAAC;QAClC,CAAC;KAAA;IAEY,GAAG,CAAC,MAAuC;;;;;YACtD,OAAO,MAAM,OAAM,GAAG,YAAC,MAAM,CAAC,CAAC;QACjC,CAAC;KAAA;CACF"}
@@ -0,0 +1,140 @@
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 { Convert } from '@enbox/common';
11
+ import { DwnInterface } from './types/dwn.js';
12
+ import { IdentityProtocolDefinition } from './store-data-protocols.js';
13
+ import { TENANT_SEPARATOR } from './utils-internal.js';
14
+ import { DwnDataStore, InMemoryDataStore } from './store-data.js';
15
+ export function isIdentityMetadata(obj) {
16
+ // Validate that the given value is an object that has the necessary properties of IdentityMetadata.
17
+ return !(!obj || typeof obj !== 'object' || obj === null)
18
+ && 'name' in obj;
19
+ }
20
+ export class DwnIdentityStore extends DwnDataStore {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.name = 'DwnIdentityStore';
24
+ this._recordProtocolDefinition = IdentityProtocolDefinition;
25
+ /**
26
+ * Properties to use when writing and querying Identity records with the DWN store.
27
+ */
28
+ this._recordProperties = {
29
+ dataFormat: 'application/json',
30
+ protocol: this._recordProtocolDefinition.protocol,
31
+ protocolPath: 'identityMetadata',
32
+ schema: this._recordProtocolDefinition.types.identityMetadata.schema,
33
+ };
34
+ }
35
+ delete(params) {
36
+ const _super = Object.create(null, {
37
+ delete: { get: () => super.delete }
38
+ });
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return yield _super.delete.call(this, params);
41
+ });
42
+ }
43
+ get(params) {
44
+ const _super = Object.create(null, {
45
+ get: { get: () => super.get }
46
+ });
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return yield _super.get.call(this, params);
49
+ });
50
+ }
51
+ set(params) {
52
+ const _super = Object.create(null, {
53
+ set: { get: () => super.set }
54
+ });
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ return yield _super.set.call(this, params);
57
+ });
58
+ }
59
+ list(params) {
60
+ const _super = Object.create(null, {
61
+ list: { get: () => super.list }
62
+ });
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ return yield _super.list.call(this, params);
65
+ });
66
+ }
67
+ getAllRecords({ agent, tenantDid }) {
68
+ var _a;
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ // Clear the index since it will be rebuilt from the query results.
71
+ this._index.clear();
72
+ // Query the DWN for all stored IdentityMetadata objects.
73
+ const { reply: queryReply } = yield agent.dwn.processRequest({
74
+ author: tenantDid,
75
+ target: tenantDid,
76
+ messageType: DwnInterface.RecordsQuery,
77
+ messageParams: { filter: Object.assign({}, this._recordProperties) }
78
+ });
79
+ // Loop through all of the stored IdentityMetadata records and accumulate the objects.
80
+ let storedIdentities = [];
81
+ for (const record of (_a = queryReply.entries) !== null && _a !== void 0 ? _a : []) {
82
+ // All IdentityMetadata records are expected to be small enough such that the data is returned
83
+ // with the query results. If a record is returned without `encodedData` this is unexpected so
84
+ // throw an error.
85
+ if (!record.encodedData) {
86
+ throw new Error(`${this.name}: Expected 'encodedData' to be present in the DWN query result entry`);
87
+ }
88
+ const storedIdentity = Convert.base64Url(record.encodedData).toObject();
89
+ if (isIdentityMetadata(storedIdentity)) {
90
+ // Update the index with the matching record ID.
91
+ const indexKey = `${tenantDid}${TENANT_SEPARATOR}${storedIdentity.uri}`;
92
+ this._index.set(indexKey, record.recordId);
93
+ // Add the stored Identity to the cache.
94
+ this._cache.set(record.recordId, storedIdentity);
95
+ storedIdentities.push(storedIdentity);
96
+ }
97
+ }
98
+ return storedIdentities;
99
+ });
100
+ }
101
+ }
102
+ export class InMemoryIdentityStore extends InMemoryDataStore {
103
+ constructor() {
104
+ super(...arguments);
105
+ this.name = 'InMemoryIdentityStore';
106
+ }
107
+ delete(params) {
108
+ const _super = Object.create(null, {
109
+ delete: { get: () => super.delete }
110
+ });
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ return yield _super.delete.call(this, params);
113
+ });
114
+ }
115
+ get(params) {
116
+ const _super = Object.create(null, {
117
+ get: { get: () => super.get }
118
+ });
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ return yield _super.get.call(this, params);
121
+ });
122
+ }
123
+ list(params) {
124
+ const _super = Object.create(null, {
125
+ list: { get: () => super.list }
126
+ });
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ return yield _super.list.call(this, params);
129
+ });
130
+ }
131
+ set(params) {
132
+ const _super = Object.create(null, {
133
+ set: { get: () => super.set }
134
+ });
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ return yield _super.set.call(this, params);
137
+ });
138
+ }
139
+ }
140
+ //# sourceMappingURL=store-identity.js.map
@@ -0,0 +1 @@
1
+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