@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,150 @@
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 { CryptoUtils } from '@enbox/crypto';
11
+ import IsomorphicWebSocket from 'isomorphic-ws';
12
+ import { createJsonRpcSubscriptionRequest, parseJson } from './json-rpc.js';
13
+ // These were arbitrarily chosen, but can be modified via connect options
14
+ const CONNECT_TIMEOUT = 3000;
15
+ const RESPONSE_TIMEOUT = 30000;
16
+ /**
17
+ * JSON RPC Socket Client for WebSocket request/response and long-running subscriptions.
18
+ *
19
+ * NOTE: This is temporarily copied over from https://github.com/TBD54566975/dwn-server/blob/main/src/json-rpc-socket.ts
20
+ * This was done in order to avoid taking a dependency on the `dwn-server`, until a future time when there will be a `clients` package.
21
+ */
22
+ export class JsonRpcSocket {
23
+ constructor(socket, responseTimeout) {
24
+ this.socket = socket;
25
+ this.responseTimeout = responseTimeout;
26
+ this.messageHandlers = new Map();
27
+ }
28
+ static connect(url, options = {}) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const { connectTimeout = CONNECT_TIMEOUT, responseTimeout = RESPONSE_TIMEOUT, onclose, onerror } = options;
31
+ const socket = new IsomorphicWebSocket(url);
32
+ if (!onclose) {
33
+ socket.onclose = () => {
34
+ console.info(`JSON RPC Socket close ${url}`);
35
+ };
36
+ }
37
+ else {
38
+ socket.onclose = onclose;
39
+ }
40
+ if (!onerror) {
41
+ socket.onerror = (error) => {
42
+ console.error(`JSON RPC Socket error ${url}`, error);
43
+ };
44
+ }
45
+ else {
46
+ socket.onerror = onerror;
47
+ }
48
+ return new Promise((resolve, reject) => {
49
+ socket.addEventListener('open', () => {
50
+ const jsonRpcSocket = new JsonRpcSocket(socket, responseTimeout);
51
+ socket.addEventListener('message', (event) => {
52
+ const jsonRpcResponse = parseJson(event.data);
53
+ const handler = jsonRpcSocket.messageHandlers.get(jsonRpcResponse.id);
54
+ if (handler) {
55
+ handler(event);
56
+ }
57
+ });
58
+ resolve(jsonRpcSocket);
59
+ });
60
+ socket.addEventListener('error', (error) => {
61
+ reject(error);
62
+ });
63
+ setTimeout(() => reject, connectTimeout);
64
+ });
65
+ });
66
+ }
67
+ close() {
68
+ this.socket.close();
69
+ }
70
+ /**
71
+ * Sends a JSON-RPC request through the socket and waits for a single response.
72
+ */
73
+ request(request) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ return new Promise((resolve, reject) => {
76
+ var _a;
77
+ (_a = request.id) !== null && _a !== void 0 ? _a : (request.id = CryptoUtils.randomUuid());
78
+ const handleResponse = (event) => {
79
+ const jsonRpsResponse = parseJson(event.data);
80
+ if (jsonRpsResponse.id === request.id) {
81
+ // if the incoming response id matches the request id, we will remove the listener and resolve the response
82
+ this.messageHandlers.delete(request.id);
83
+ return resolve(jsonRpsResponse);
84
+ }
85
+ };
86
+ // add the listener to the map of message handlers
87
+ this.messageHandlers.set(request.id, handleResponse);
88
+ this.send(request);
89
+ // reject this promise if we don't receive any response back within the timeout period
90
+ setTimeout(() => {
91
+ this.messageHandlers.delete(request.id);
92
+ reject(new Error('request timed out'));
93
+ }, this.responseTimeout);
94
+ });
95
+ });
96
+ }
97
+ /**
98
+ * Sends a JSON-RPC request through the socket and keeps a listener open to read associated responses as they arrive.
99
+ * Returns a close method to clean up the listener.
100
+ */
101
+ subscribe(request, listener) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ if (!request.method.startsWith('rpc.subscribe.')) {
104
+ throw new Error('subscribe rpc requests must include the `rpc.subscribe` prefix');
105
+ }
106
+ if (!request.subscription) {
107
+ throw new Error('subscribe rpc requests must include subscribe options');
108
+ }
109
+ const subscriptionId = request.subscription.id;
110
+ const socketEventListener = (event) => {
111
+ const jsonRpcResponse = parseJson(event.data.toString());
112
+ if (jsonRpcResponse.id === subscriptionId) {
113
+ if (jsonRpcResponse.error !== undefined) {
114
+ // remove the event listener upon receipt of a JSON RPC Error.
115
+ this.messageHandlers.delete(subscriptionId);
116
+ this.closeSubscription(subscriptionId);
117
+ }
118
+ listener(jsonRpcResponse);
119
+ }
120
+ };
121
+ this.messageHandlers.set(subscriptionId, socketEventListener);
122
+ const response = yield this.request(request);
123
+ if (response.error) {
124
+ this.messageHandlers.delete(subscriptionId);
125
+ return { response };
126
+ }
127
+ // clean up listener and create a `rpc.subscribe.close` message to use when closing this JSON RPC subscription
128
+ const close = () => __awaiter(this, void 0, void 0, function* () {
129
+ this.messageHandlers.delete(subscriptionId);
130
+ yield this.closeSubscription(subscriptionId);
131
+ });
132
+ return {
133
+ response,
134
+ close
135
+ };
136
+ });
137
+ }
138
+ closeSubscription(id) {
139
+ const requestId = CryptoUtils.randomUuid();
140
+ const request = createJsonRpcSubscriptionRequest(requestId, 'close', id, {});
141
+ return this.request(request);
142
+ }
143
+ /**
144
+ * Sends a JSON-RPC request through the socket. You must subscribe to a message listener separately to capture the response.
145
+ */
146
+ send(request) {
147
+ this.socket.send(JSON.stringify(request));
148
+ }
149
+ }
150
+ //# sourceMappingURL=json-rpc-socket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-rpc-socket.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/json-rpc-socket.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,mBAAmB,MAAM,eAAe,CAAC;AAChD,OAAO,EAA8C,gCAAgC,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAExH,yEAAyE;AACzE,MAAM,eAAe,GAAG,IAAK,CAAC;AAC9B,MAAM,gBAAgB,GAAG,KAAM,CAAC;AAahC;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IAGxB,YAA4B,MAA2B,EAAU,eAAuB;QAA5D,WAAM,GAAN,MAAM,CAAqB;QAAU,oBAAe,GAAf,eAAe,CAAQ;QAFhF,oBAAe,GAAmD,IAAI,GAAG,EAAE,CAAC;IAEO,CAAC;IAE5F,MAAM,CAAO,OAAO,CAAC,GAAW,EAAE,UAAgC,EAAE;;YAClE,MAAM,EAAE,cAAc,GAAG,eAAe,EAAE,eAAe,GAAG,gBAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;YAE3G,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAE5C,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,CAAC,OAAO,GAAG,GAAQ,EAAE;oBACzB,OAAO,CAAC,IAAI,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC;gBAC/C,CAAC,CAAC;aACH;iBAAM;gBACL,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;aAC1B;YAED,IAAI,CAAC,OAAO,EAA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B;QAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,58 @@
1
+ export var JsonRpcErrorCodes;
2
+ (function (JsonRpcErrorCodes) {
3
+ // JSON-RPC 2.0 pre-defined errors
4
+ JsonRpcErrorCodes[JsonRpcErrorCodes["InvalidRequest"] = -32600] = "InvalidRequest";
5
+ JsonRpcErrorCodes[JsonRpcErrorCodes["MethodNotFound"] = -32601] = "MethodNotFound";
6
+ JsonRpcErrorCodes[JsonRpcErrorCodes["InvalidParams"] = -32602] = "InvalidParams";
7
+ JsonRpcErrorCodes[JsonRpcErrorCodes["InternalError"] = -32603] = "InternalError";
8
+ JsonRpcErrorCodes[JsonRpcErrorCodes["ParseError"] = -32700] = "ParseError";
9
+ JsonRpcErrorCodes[JsonRpcErrorCodes["TransportError"] = -32300] = "TransportError";
10
+ // App defined errors
11
+ JsonRpcErrorCodes[JsonRpcErrorCodes["BadRequest"] = -50400] = "BadRequest";
12
+ JsonRpcErrorCodes[JsonRpcErrorCodes["Unauthorized"] = -50401] = "Unauthorized";
13
+ JsonRpcErrorCodes[JsonRpcErrorCodes["Forbidden"] = -50403] = "Forbidden";
14
+ JsonRpcErrorCodes[JsonRpcErrorCodes["Conflict"] = -50409] = "Conflict";
15
+ })(JsonRpcErrorCodes || (JsonRpcErrorCodes = {}));
16
+ export const createJsonRpcErrorResponse = (id, code, message, data) => {
17
+ const error = { code, message, data };
18
+ return {
19
+ jsonrpc: '2.0',
20
+ id,
21
+ error,
22
+ };
23
+ };
24
+ export const createJsonRpcRequest = (id, method, params) => {
25
+ return {
26
+ jsonrpc: '2.0',
27
+ id,
28
+ method,
29
+ params,
30
+ };
31
+ };
32
+ export const createJsonRpcSubscriptionRequest = (id, method, subscriptionId, params) => {
33
+ return {
34
+ jsonrpc: '2.0',
35
+ id,
36
+ method: `rpc.subscribe.${method}`,
37
+ params,
38
+ subscription: {
39
+ id: subscriptionId,
40
+ }
41
+ };
42
+ };
43
+ export const createJsonRpcSuccessResponse = (id, result) => {
44
+ return {
45
+ jsonrpc: '2.0',
46
+ id,
47
+ result,
48
+ };
49
+ };
50
+ export function parseJson(text) {
51
+ try {
52
+ return JSON.parse(text);
53
+ }
54
+ catch (_a) {
55
+ return null;
56
+ }
57
+ }
58
+ //# sourceMappingURL=json-rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-rpc.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/json-rpc.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAN,IAAY,iBAcX;AAdD,WAAY,iBAAiB;IAC3B,kCAAkC;IAClC,kFAAuB,CAAA;IACvB,kFAAuB,CAAA;IACvB,gFAAsB,CAAA;IACtB,gFAAsB,CAAA;IACtB,0EAAmB,CAAA;IACnB,kFAAuB,CAAA;IAEvB,qBAAqB;IACrB,0EAAmB,CAAA;IACnB,8EAAqB,CAAA;IACrB,wEAAkB,CAAA;IAClB,sEAAiB,CAAA;AACnB,CAAC,EAdW,iBAAiB,KAAjB,iBAAiB,QAc5B;AAkBD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,EAAa,EACb,IAAuB,EACvB,OAAe,EACf,IAAU,EACY,EAAE;IACxB,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACpD,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,EAAa,EACb,MAAc,EACd,MAAsB,EACN,EAAE;IAClB,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,MAAM;QACN,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,EAAa,EACb,MAAc,EACd,cAAyB,EACzB,MAAY,EACI,EAAE;IAClB,OAAO;QACL,OAAO,EAAQ,KAAK;QACpB,EAAE;QACF,MAAM,EAAS,iBAAiB,MAAM,EAAE;QACxC,MAAM;QACN,YAAY,EAAG;YACb,EAAE,EAAE,cAAc;SACnB;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,EAAa,EACb,MAAW,EACa,EAAE;IAC1B,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACzB;IAAC,WAAM;QACN,OAAO,IAAI,CAAC;KACb;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=server-info-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-info-types.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/server-info-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,90 @@
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 { CryptoUtils } from '@enbox/crypto';
11
+ import { createJsonRpcRequest, createJsonRpcSubscriptionRequest } from './json-rpc.js';
12
+ import { JsonRpcSocket } from './json-rpc-socket.js';
13
+ export class WebSocketDwnRpcClient {
14
+ get transportProtocols() { return ['ws:', 'wss:']; }
15
+ sendDwnRequest(request, jsonRpcSocketOptions) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ // validate that the dwn URL provided is a valid WebSocket URL
18
+ const url = new URL(request.dwnUrl);
19
+ if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {
20
+ throw new Error(`Invalid websocket protocol ${url.protocol}`);
21
+ }
22
+ // check if there is already a connection to this host, if it does not exist, initiate a new connection
23
+ const hasConnection = WebSocketDwnRpcClient.connections.has(url.host);
24
+ if (!hasConnection) {
25
+ try {
26
+ const socket = yield JsonRpcSocket.connect(url.toString(), jsonRpcSocketOptions);
27
+ const subscriptions = new Map();
28
+ WebSocketDwnRpcClient.connections.set(url.host, { socket, subscriptions });
29
+ }
30
+ catch (error) {
31
+ throw new Error(`Error connecting to ${url.host}: ${error.message}`);
32
+ }
33
+ }
34
+ const connection = WebSocketDwnRpcClient.connections.get(url.host);
35
+ const { targetDid, message, subscriptionHandler } = request;
36
+ if (subscriptionHandler) {
37
+ return WebSocketDwnRpcClient.subscriptionRequest(connection, targetDid, message, subscriptionHandler);
38
+ }
39
+ return WebSocketDwnRpcClient.processMessage(connection, targetDid, message);
40
+ });
41
+ }
42
+ static processMessage(connection, target, message) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const requestId = CryptoUtils.randomUuid();
45
+ const request = createJsonRpcRequest(requestId, 'dwn.processMessage', { target, message });
46
+ const { socket } = connection;
47
+ const response = yield socket.request(request);
48
+ const { error, result } = response;
49
+ if (error !== undefined) {
50
+ throw new Error(`error sending DWN request: ${error.message}`);
51
+ }
52
+ return result.reply;
53
+ });
54
+ }
55
+ static subscriptionRequest(connection, target, message, messageHandler) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const requestId = CryptoUtils.randomUuid();
58
+ const subscriptionId = CryptoUtils.randomUuid();
59
+ const request = createJsonRpcSubscriptionRequest(requestId, 'dwn.processMessage', subscriptionId, { target, message });
60
+ const { socket, subscriptions } = connection;
61
+ const { response, close } = yield socket.subscribe(request, (response) => {
62
+ const { result, error } = response;
63
+ if (error) {
64
+ // if there is an error, close the subscription and delete it from the connection
65
+ const subscription = subscriptions.get(subscriptionId);
66
+ if (subscription) {
67
+ subscription.close();
68
+ }
69
+ subscriptions.delete(subscriptionId);
70
+ return;
71
+ }
72
+ const { event } = result;
73
+ messageHandler(event);
74
+ });
75
+ const { error, result } = response;
76
+ if (error) {
77
+ throw new Error(`could not subscribe via jsonrpc socket: ${error.message}`);
78
+ }
79
+ const { reply } = result;
80
+ if (reply.subscription && close) {
81
+ subscriptions.set(subscriptionId, Object.assign(Object.assign({}, reply.subscription), { close }));
82
+ reply.subscription.close = close;
83
+ }
84
+ return reply;
85
+ });
86
+ }
87
+ }
88
+ // a map of dwn host to WebSocket connection
89
+ WebSocketDwnRpcClient.connections = new Map();
90
+ //# sourceMappingURL=web-socket-clients.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-socket-clients.js","sourceRoot":"","sources":["../../../../src/prototyping/clients/web-socket-clients.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,EAAE,aAAa,EAAwB,MAAM,sBAAsB,CAAC;AAO3E,MAAM,OAAO,qBAAqB;IAChC,IAAW,kBAAkB,KAAK,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAIrD,cAAc,CAAC,OAAsB,EAAE,oBAA2C;;YAEtF,8DAA8D;YAC9D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACpC,IAAI,GAAG,CAAC,QAAQ,KAAK,KAAK,IAAI,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE;gBACrD,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;aAC/D;YAED,uGAAuG;YACvG,MAAM,aAAa,GAAG,qB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AAC;YACnC,IAAI,KAAK,EAAE;gBACT,MAAM,IAAI,KAAK,CAAC,2CAA2C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;aAC7E;YAED,MAAM,EAAE,KAAK,EAAE,GAAG,MAAsC,CAAC;YACzD,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,EAAE;gBAC/B,aAAa,CAAC,GAAG,CAAC,cAAc,kCAAO,KAAK,CAAC,YAAY,KAAE,KAAK,IAAG,CAAC;gBACpE,KAAK,CAAC,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;aAClC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;;AApFD,4CAA4C;AAC7B,iCAAW,GAAG,IAAI,GAAG,EAA4B,CAAC"}
@@ -0,0 +1,14 @@
1
+ export function hasDuplicateProperties(...objects) {
2
+ const propertySet = new Set();
3
+ const objectsWithoutUndefined = objects.filter(Boolean); // Remove any undefined values
4
+ for (const obj of objectsWithoutUndefined) {
5
+ for (const key in obj) {
6
+ if (propertySet.has(key)) {
7
+ return true; // Return true if a duplicate property is found
8
+ }
9
+ propertySet.add(key);
10
+ }
11
+ }
12
+ return false; // Return false if no duplicates are found
13
+ }
14
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../../../src/prototyping/common/object.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,sBAAsB,CAAC,GAAG,OAA+C;IACvF,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IACtC,MAAM,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,8BAA8B;IAEvF,KAAK,MAAM,GAAG,IAAI,uBAAuB,EAAE;QACzC,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;YACrB,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBACxB,OAAO,IAAI,CAAC,CAAC,+CAA+C;aAC7D;YACD,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACtB;KACF;IAED,OAAO,KAAK,CAAC,CAAC,0CAA0C;AAC1D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-utils.js","sourceRoot":"","sources":["../../../../src/prototyping/common/type-utils.ts"],"names":[],"mappings":""}
@@ -0,0 +1,147 @@
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 { AesGcm, CryptoAlgorithm } from '@enbox/crypto';
11
+ /**
12
+ * The `AesGcmAlgorithm` class provides a concrete implementation for cryptographic operations using
13
+ * the AES algorithm in Galois/Counter Mode (GCM). This class implements both
14
+ * {@link Cipher | `Cipher`} and { @link KeyGenerator | `KeyGenerator`} interfaces, providing
15
+ * key generation, encryption, and decryption features.
16
+ *
17
+ * This class is typically accessed through implementations that extend the
18
+ * {@link CryptoApi | `CryptoApi`} interface.
19
+ */
20
+ export class AesGcmAlgorithm extends CryptoAlgorithm {
21
+ bytesToPrivateKey({ privateKeyBytes }) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ // Convert the byte array to a JWK.
24
+ const privateKey = yield AesGcm.bytesToPrivateKey({ privateKeyBytes });
25
+ // Set the `alg` property based on the key length.
26
+ privateKey.alg = { 16: 'A128GCM', 24: 'A192GCM', 32: 'A256GCM' }[privateKeyBytes.length];
27
+ return privateKey;
28
+ });
29
+ }
30
+ /**
31
+ * Decrypts the provided data using AES-GCM.
32
+ *
33
+ * @remarks
34
+ * This method performs AES-GCM decryption on the given encrypted data using the specified key.
35
+ * It requires an initialization vector (IV), the encrypted data along with the decryption key,
36
+ * and optionally, additional authenticated data (AAD). The method returns the decrypted data as a
37
+ * Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
38
+ * tag used when encrypting the data. If not specified, the default tag length of 128 bits is
39
+ * used.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const aesGcm = new AesGcmAlgorithm();
44
+ * const encryptedData = new Uint8Array([...]); // Encrypted data
45
+ * const iv = new Uint8Array([...]); // Initialization vector used during encryption
46
+ * const additionalData = new Uint8Array([...]); // Optional additional authenticated data
47
+ * const key = { ... }; // A Jwk object representing the AES key
48
+ * const decryptedData = await aesGcm.decrypt({
49
+ * data: encryptedData,
50
+ * iv,
51
+ * additionalData,
52
+ * key,
53
+ * tagLength: 128 // Optional tag length in bits
54
+ * });
55
+ * ```
56
+ *
57
+ * @param params - The parameters for the decryption operation.
58
+ *
59
+ * @returns A Promise that resolves to the decrypted data as a Uint8Array.
60
+ */
61
+ decrypt(params) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const plaintext = AesGcm.decrypt(params);
64
+ return plaintext;
65
+ });
66
+ }
67
+ /**
68
+ * Encrypts the provided data using AES-GCM.
69
+ *
70
+ * @remarks
71
+ * This method performs AES-GCM encryption on the given data using the specified key.
72
+ * It requires an initialization vector (IV), the encrypted data along with the decryption key,
73
+ * and optionally, additional authenticated data (AAD). The method returns the encrypted data as a
74
+ * Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
75
+ * tag generated in the encryption operation and used for authentication in the corresponding
76
+ * decryption. If not specified, the default tag length of 128 bits is used.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const aesGcm = new AesGcmAlgorithm();
81
+ * const data = new TextEncoder().encode('Messsage');
82
+ * const iv = new Uint8Array([...]); // Initialization vector
83
+ * const additionalData = new Uint8Array([...]); // Optional additional authenticated data
84
+ * const key = { ... }; // A Jwk object representing an AES key
85
+ * const encryptedData = await aesGcm.encrypt({
86
+ * data,
87
+ * iv,
88
+ * additionalData,
89
+ * key,
90
+ * tagLength: 128 // Optional tag length in bits
91
+ * });
92
+ * ```
93
+ *
94
+ * @param params - The parameters for the encryption operation.
95
+ *
96
+ * @returns A Promise that resolves to the encrypted data as a Uint8Array.
97
+ */
98
+ encrypt(params) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const ciphertext = AesGcm.encrypt(params);
101
+ return ciphertext;
102
+ });
103
+ }
104
+ /**
105
+ * Generates a symmetric key for AES in Galois/Counter Mode (GCM) in JSON Web Key (JWK) format.
106
+ *
107
+ * @remarks
108
+ * This method generates a symmetric AES key for use in GCM mode, based on the specified
109
+ * `algorithm` parameter which determines the key length. It uses cryptographically secure random
110
+ * number generation to ensure the uniqueness and security of the key. The key is returned in JWK
111
+ * format.
112
+ *
113
+ * The generated key includes the following components:
114
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence.
115
+ * - `k`: The symmetric key component, base64url-encoded.
116
+ * - `kid`: Key ID, generated based on the JWK thumbprint.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const aesGcm = new AesGcmAlgorithm();
121
+ * const privateKey = await aesGcm.generateKey({ algorithm: 'A256GCM' });
122
+ * ```
123
+ *
124
+ * @param params - The parameters for the key generation.
125
+ *
126
+ * @returns A Promise that resolves to the generated symmetric key in JWK format.
127
+ */
128
+ generateKey({ algorithm }) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ // Map algorithm name to key length.
131
+ const length = { A128GCM: 128, A192GCM: 192, A256GCM: 256 }[algorithm];
132
+ // Generate a random private key.
133
+ const privateKey = yield AesGcm.generateKey({ length });
134
+ // Set the `alg` property based on the specified algorithm.
135
+ privateKey.alg = algorithm;
136
+ return privateKey;
137
+ });
138
+ }
139
+ privateKeyToBytes({ privateKey }) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ // Convert the JWK to a byte array.
142
+ const privateKeyBytes = yield AesGcm.privateKeyToBytes({ privateKey });
143
+ return privateKeyBytes;
144
+ });
145
+ }
146
+ }
147
+ //# sourceMappingURL=aes-gcm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/algorithms/aes-gcm.ts"],"names":[],"mappings":";;;;;;;;;AAUA,OAAO,EAAE,MAAM,EAAuB,eAAe,EAAE,MAAM,eAAe,CAAC;AAqD7E;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAKrC,iBAAiB,CAAC,EAAE,eAAe,EAA2B;;YACzE,mCAAmC;YACnC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;YAEvE,kDAAkD;YAClD,UAAU,CAAC,GAAG,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAEzF,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,OAAO,CAAC,MACS;;YAE5B,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAEzC,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,OAAO,CAAC,MACS;;YAE5B,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAE1C,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,WAAW,CAAC,EAAE,SAAS,EACX;;YAEvB,oCAAoC;YACpC,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAoB,CAAC;YAE1F,iCAAiC;YACjC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAExD,2DAA2D;YAC3D,UAAU,CAAC,GAAG,GAAG,SAAS,CAAC;YAE3B,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAEY,iBAAiB,CAAC,EAAE,UAAU,EAA2B;;YACpE,mCAAmC;YACnC,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;YAEvE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
@@ -0,0 +1,137 @@
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 { CryptoAlgorithm } from '@enbox/crypto';
11
+ import { AesKw } from '../primitives/aes-kw.js';
12
+ /**
13
+ * The `AesKwAlgorithm` class provides a concrete implementation for cryptographic operations using
14
+ * the AES algorithm for key wrapping. This class implements both
15
+ * {@link KeyGenerator | `KeyGenerator`} and {@link KeyWrapper | `KeyWrapper`} interfaces, providing
16
+ * key generation, key wrapping, and key unwrapping features.
17
+ *
18
+ * This class is typically accessed through implementations that extend the
19
+ * {@link CryptoApi | `CryptoApi`} interface.
20
+ */
21
+ export class AesKwAlgorithm extends CryptoAlgorithm {
22
+ bytesToPrivateKey({ privateKeyBytes }) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ // Convert the byte array to a JWK.
25
+ const privateKey = yield AesKw.bytesToPrivateKey({ privateKeyBytes });
26
+ // Set the `alg` property based on the key length.
27
+ privateKey.alg = { 16: 'A128KW', 24: 'A192KW', 32: 'A256KW' }[privateKeyBytes.length];
28
+ return privateKey;
29
+ });
30
+ }
31
+ /**
32
+ * Generates a symmetric key for AES for key wrapping in JSON Web Key (JWK) format.
33
+ *
34
+ * @remarks
35
+ * This method generates a symmetric AES key for use in key wrapping mode, based on the specified
36
+ * `algorithm` parameter which determines the key length. It uses cryptographically secure random
37
+ * number generation to ensure the uniqueness and security of the key. The key is returned in JWK
38
+ * format.
39
+ *
40
+ * The generated key includes the following components:
41
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence.
42
+ * - `k`: The symmetric key component, base64url-encoded.
43
+ * - `kid`: Key ID, generated based on the JWK thumbprint.
44
+ * - `alg`: Algorithm, set to 'A128KW', 'A192KW', or 'A256KW' for AES Key Wrap with the
45
+ * specified key length.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const aesKw = new AesKwAlgorithm();
50
+ * const privateKey = await aesKw.generateKey({ algorithm: 'A256KW' });
51
+ * ```
52
+ *
53
+ * @param params - The parameters for the key generation.
54
+ *
55
+ * @returns A Promise that resolves to the generated symmetric key in JWK format.
56
+ */
57
+ generateKey({ algorithm }) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ // Map algorithm name to key length.
60
+ const length = { A128KW: 128, A192KW: 192, A256KW: 256 }[algorithm];
61
+ // Generate a random private key.
62
+ const privateKey = yield AesKw.generateKey({ length });
63
+ // Set the `alg` property based on the specified algorithm.
64
+ privateKey.alg = algorithm;
65
+ return privateKey;
66
+ });
67
+ }
68
+ privateKeyToBytes({ privateKey }) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ // Convert the JWK to a byte array.
71
+ const privateKeyBytes = yield AesKw.privateKeyToBytes({ privateKey });
72
+ return privateKeyBytes;
73
+ });
74
+ }
75
+ /**
76
+ * Decrypts a wrapped key using the AES Key Wrap algorithm.
77
+ *
78
+ * @remarks
79
+ * This method unwraps a previously wrapped cryptographic key using the AES Key Wrap algorithm.
80
+ * The wrapped key, provided as a byte array, is unwrapped using the decryption key specified in
81
+ * the parameters.
82
+ *
83
+ * This operation is useful for securely receiving keys transmitted over untrusted mediums. The
84
+ * method returns the unwrapped key as a JSON Web Key (JWK).
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const aesKw = new AesKwAlgorithm();
89
+ * const wrappedKeyBytes = new Uint8Array([...]); // Byte array of a wrapped AES-256 GCM key
90
+ * const decryptionKey = { ... }; // A Jwk object representing the AES unwrapping key
91
+ * const unwrappedKey = await aesKw.unwrapKey({
92
+ * wrappedKeyBytes,
93
+ * wrappedKeyAlgorithm: 'A256GCM',
94
+ * decryptionKey
95
+ * });
96
+ * ```
97
+ *
98
+ * @param params - The parameters for the key unwrapping operation.
99
+ *
100
+ * @returns A Promise that resolves to the unwrapped key in JWK format.
101
+ */
102
+ unwrapKey(params) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const unwrappedKey = yield AesKw.unwrapKey(params);
105
+ return unwrappedKey;
106
+ });
107
+ }
108
+ /**
109
+ * Encrypts a given key using the AES Key Wrap algorithm.
110
+ *
111
+ * @remarks
112
+ * This method wraps a given cryptographic key using the AES Key Wrap algorithm. The private key
113
+ * to be wrapped is provided in the form of a JSON Web Key (JWK).
114
+ *
115
+ * This operation is useful for securely transmitting keys over untrusted mediums. The method
116
+ * returns the wrapped key as a byte array.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const aesKw = new AesKwAlgorithm();
121
+ * const unwrappedKey = { ... }; // A Jwk object representing the key to be wrapped
122
+ * const encryptionKey = { ... }; // A Jwk object representing the AES wrapping key
123
+ * const wrappedKeyBytes = await aesKw.wrapKey({ unwrappedKey, encryptionKey });
124
+ * ```
125
+ *
126
+ * @param params - The parameters for the key wrapping operation.
127
+ *
128
+ * @returns A Promise that resolves to the wrapped key as a Uint8Array.
129
+ */
130
+ wrapKey(params) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ const wrappedKeyBytes = AesKw.wrapKey(params);
133
+ return wrappedKeyBytes;
134
+ });
135
+ }
136
+ }
137
+ //# sourceMappingURL=aes-kw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes-kw.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/algorithms/aes-kw.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIhD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAiBhD;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAKpC,iBAAiB,CAAC,EAAE,eAAe,EACS;;YAEvD,mCAAmC;YACnC,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;YAEtE,kDAAkD;YAClD,UAAU,CAAC,GAAG,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAEtF,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,WAAW,CAAC,EAAE,SAAS,EACZ;;YAEtB,oCAAoC;YACpC,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,CAAoB,CAAC;YAEvF,iCAAiC;YACjC,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAEvD,2DAA2D;YAC3D,UAAU,CAAC,GAAG,GAAG,SAAS,CAAC;YAE3B,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAEY,iBAAiB,CAAC,E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