@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,245 @@
1
+ import type { Jwk } from '@enbox/crypto';
2
+ /**
3
+ * Constant defining the AES key length values in bits.
4
+ *
5
+ * @remarks
6
+ * NIST publication FIPS 197 states:
7
+ * > The AES algorithm is capable of using cryptographic keys of 128, 192, and 256 bits to encrypt
8
+ * > and decrypt data in blocks of 128 bits.
9
+ *
10
+ * This implementation does not support key lengths that are different from the three values
11
+ * defined by this constant.
12
+ *
13
+ * @see {@link https://doi.org/10.6028/NIST.FIPS.197-upd1 | NIST FIPS 197}
14
+ */
15
+ declare const AES_KEY_LENGTHS: readonly [128, 192, 256];
16
+ /**
17
+ * Constant defining the AES-GCM tag length values in bits.
18
+ *
19
+ * @remarks
20
+ * NIST Special Publication 800-38D, Section 5.2.1.2 states that the tag length:
21
+ * > may be any one of the following five values: 128, 120, 112, 104, or 96
22
+ *
23
+ * Although the NIST specification allows for tag lengths of 32 or 64 bits in certain applications,
24
+ * the use of shorter tag lengths can be problematic for GCM due to targeted forgery attacks. As a
25
+ * precaution, this implementation does not support tag lengths that are different from the five
26
+ * values defined by this constant. See Appendix C of the NIST SP 800-38D specification for
27
+ * additional guidance and details.
28
+ *
29
+ * @see {@link https://doi.org/10.6028/NIST.SP.800-38D | NIST SP 800-38D}
30
+ */
31
+ export declare const AES_GCM_TAG_LENGTHS: readonly [96, 104, 112, 120, 128];
32
+ /**
33
+ * The `AesGcm` class provides a comprehensive set of utilities for cryptographic operations
34
+ * using the Advanced Encryption Standard (AES) in Galois/Counter Mode (GCM). This class includes
35
+ * methods for key generation, encryption, decryption, and conversions between raw byte arrays
36
+ * and JSON Web Key (JWK) formats. It is designed to support AES-GCM, a symmetric key algorithm
37
+ * that is widely used for its efficiency, security, and provision of authenticated encryption.
38
+ *
39
+ * AES-GCM is particularly favored for scenarios that require both confidentiality and integrity
40
+ * of data. It integrates the counter mode of encryption with the Galois mode of authentication,
41
+ * offering high performance and parallel processing capabilities.
42
+ *
43
+ * Key Features:
44
+ * - Key Generation: Generate AES symmetric keys in JWK format.
45
+ * - Key Conversion: Transform keys between raw byte arrays and JWK formats.
46
+ * - Encryption: Encrypt data using AES-GCM with the provided symmetric key.
47
+ * - Decryption: Decrypt data encrypted with AES-GCM using the corresponding symmetric key.
48
+ *
49
+ * The methods in this class are asynchronous, returning Promises to accommodate various
50
+ * JavaScript environments.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * // Key Generation
55
+ * const length = 256; // Length of the key in bits (e.g., 128, 192, 256)
56
+ * const privateKey = await AesGcm.generateKey({ length });
57
+ *
58
+ * // Encryption
59
+ * const data = new TextEncoder().encode('Messsage');
60
+ * const iv = new Uint8Array(12); // 12-byte initialization vector
61
+ * const encryptedData = await AesGcm.encrypt({
62
+ * data,
63
+ * iv,
64
+ * key: privateKey
65
+ * });
66
+ *
67
+ * // Decryption
68
+ * const decryptedData = await AesGcm.decrypt({
69
+ * data: encryptedData,
70
+ * iv,
71
+ * key: privateKey
72
+ * });
73
+ *
74
+ * // Key Conversion
75
+ * const privateKeyBytes = await AesGcm.privateKeyToBytes({ privateKey });
76
+ * ```
77
+ */
78
+ export declare class AesGcm {
79
+ /**
80
+ * Converts a raw private key in bytes to its corresponding JSON Web Key (JWK) format.
81
+ *
82
+ * @remarks
83
+ * This method accepts a symmetric key represented as a byte array (Uint8Array) and
84
+ * converts it into a JWK object for use with AES-GCM (Advanced Encryption Standard -
85
+ * Galois/Counter Mode). The conversion process involves encoding the key into
86
+ * base64url format and setting the appropriate JWK parameters.
87
+ *
88
+ * The resulting JWK object includes the following properties:
89
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence (representing a symmetric key).
90
+ * - `k`: The symmetric key, base64url-encoded.
91
+ * - `kid`: Key ID, generated based on the JWK thumbprint.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const privateKeyBytes = new Uint8Array([...]); // Replace with actual symmetric key bytes
96
+ * const privateKey = await AesGcm.bytesToPrivateKey({ privateKeyBytes });
97
+ * ```
98
+ *
99
+ * @param params - The parameters for the symmetric key conversion.
100
+ * @param params.privateKeyBytes - The raw symmetric key as a Uint8Array.
101
+ *
102
+ * @returns A Promise that resolves to the symmetric key in JWK format.
103
+ */
104
+ static bytesToPrivateKey({ privateKeyBytes }: {
105
+ privateKeyBytes: Uint8Array;
106
+ }): Promise<Jwk>;
107
+ /**
108
+ * Decrypts the provided data using AES-GCM.
109
+ *
110
+ * @remarks
111
+ * This method performs AES-GCM decryption on the given encrypted data using the specified key.
112
+ * It requires an initialization vector (IV), the encrypted data along with the decryption key,
113
+ * and optionally, additional authenticated data (AAD). The method returns the decrypted data as a
114
+ * Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
115
+ * tag used when encrypting the data. If not specified, the default tag length of 128 bits is
116
+ * used.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const encryptedData = new Uint8Array([...]); // Encrypted data
121
+ * const iv = new Uint8Array([...]); // Initialization vector used during encryption
122
+ * const additionalData = new Uint8Array([...]); // Optional additional authenticated data
123
+ * const key = { ... }; // A Jwk object representing the AES key
124
+ * const decryptedData = await AesGcm.decrypt({
125
+ * data: encryptedData,
126
+ * iv,
127
+ * additionalData,
128
+ * key,
129
+ * tagLength: 128 // Optional tag length in bits
130
+ * });
131
+ * ```
132
+ *
133
+ * @param params - The parameters for the decryption operation.
134
+ * @param params.key - The key to use for decryption, represented in JWK format.
135
+ * @param params.data - The encrypted data to decrypt, represented as a Uint8Array.
136
+ * @param params.iv - The initialization vector, represented as a Uint8Array.
137
+ * @param params.additionalData - Optional additional authenticated data. Optional.
138
+ * @param params.tagLength - The length of the authentication tag in bits. Optional.
139
+ *
140
+ * @returns A Promise that resolves to the decrypted data as a Uint8Array.
141
+ */
142
+ static decrypt({ key, data, iv, additionalData, tagLength }: {
143
+ key: Jwk;
144
+ data: Uint8Array;
145
+ iv: Uint8Array;
146
+ additionalData?: Uint8Array;
147
+ tagLength?: typeof AES_GCM_TAG_LENGTHS[number];
148
+ }): Promise<Uint8Array>;
149
+ /**
150
+ * Encrypts the provided data using AES-GCM.
151
+ *
152
+ * @remarks
153
+ * This method performs AES-GCM encryption on the given data using the specified key.
154
+ * It requires an initialization vector (IV), the encrypted data along with the decryption key,
155
+ * and optionally, additional authenticated data (AAD). The method returns the encrypted data as a
156
+ * Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
157
+ * tag generated in the encryption operation and used for authentication in the corresponding
158
+ * decryption. If not specified, the default tag length of 128 bits is used.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const data = new TextEncoder().encode('Messsage');
163
+ * const iv = new Uint8Array([...]); // Initialization vector
164
+ * const additionalData = new Uint8Array([...]); // Optional additional authenticated data
165
+ * const key = { ... }; // A Jwk object representing an AES key
166
+ * const encryptedData = await AesGcm.encrypt({
167
+ * data,
168
+ * iv,
169
+ * additionalData,
170
+ * key,
171
+ * tagLength: 128 // Optional tag length in bits
172
+ * });
173
+ * ```
174
+ *
175
+ * @param params - The parameters for the encryption operation.
176
+ * @param params.key - The key to use for encryption, represented in JWK format.
177
+ * @param params.data - The data to encrypt, represented as a Uint8Array.
178
+ * @param params.iv - The initialization vector, represented as a Uint8Array.
179
+ * @param params.additionalData - Optional additional authenticated data. Optional.
180
+ * @param params.tagLength - The length of the authentication tag in bits. Optional.
181
+ *
182
+ * @returns A Promise that resolves to the encrypted data as a Uint8Array.
183
+ */
184
+ static encrypt({ data, iv, key, additionalData, tagLength }: {
185
+ key: Jwk;
186
+ data: Uint8Array;
187
+ iv: Uint8Array;
188
+ additionalData?: Uint8Array;
189
+ tagLength?: typeof AES_GCM_TAG_LENGTHS[number];
190
+ }): Promise<Uint8Array>;
191
+ /**
192
+ * Generates a symmetric key for AES in Galois/Counter Mode (GCM) in JSON Web Key (JWK) format.
193
+ *
194
+ * @remarks
195
+ * This method creates a new symmetric key of a specified length suitable for use with
196
+ * AES-GCM encryption. It leverages cryptographically secure random number generation
197
+ * to ensure the uniqueness and security of the key. The generated key adheres to the JWK
198
+ * format, facilitating compatibility with common cryptographic standards and ease of use
199
+ * in various cryptographic applications.
200
+ *
201
+ * The generated key includes these components:
202
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence, indicating a symmetric key.
203
+ * - `k`: The symmetric key component, base64url-encoded.
204
+ * - `kid`: Key ID, generated based on the JWK thumbprint, providing a unique identifier.
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * const length = 256; // Length of the key in bits (e.g., 128, 192, 256)
209
+ * const privateKey = await AesGcm.generateKey({ length });
210
+ * ```
211
+ *
212
+ * @param params - The parameters for the key generation.
213
+ * @param params.length - The length of the key in bits. Common lengths are 128, 192, and 256 bits.
214
+ *
215
+ * @returns A Promise that resolves to the generated symmetric key in JWK format.
216
+ */
217
+ static generateKey({ length }: {
218
+ length: typeof AES_KEY_LENGTHS[number];
219
+ }): Promise<Jwk>;
220
+ /**
221
+ * Converts a private key from JSON Web Key (JWK) format to a raw byte array (Uint8Array).
222
+ *
223
+ * @remarks
224
+ * This method takes a symmetric key in JWK format and extracts its raw byte representation.
225
+ * It focuses on the 'k' parameter of the JWK, which represents the symmetric key component
226
+ * in base64url encoding. The method decodes this value into a byte array, providing
227
+ * the symmetric key in its raw binary form.
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * const privateKey = { ... }; // A symmetric key in JWK format
232
+ * const privateKeyBytes = await AesGcm.privateKeyToBytes({ privateKey });
233
+ * ```
234
+ *
235
+ * @param params - The parameters for the symmetric key conversion.
236
+ * @param params.privateKey - The symmetric key in JWK format.
237
+ *
238
+ * @returns A Promise that resolves to the symmetric key as a Uint8Array.
239
+ */
240
+ static privateKeyToBytes({ privateKey }: {
241
+ privateKey: Jwk;
242
+ }): Promise<Uint8Array>;
243
+ }
244
+ export {};
245
+ //# sourceMappingURL=aes-gcm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/primitives/aes-gcm.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAmBzC;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,eAAe,0BAA2B,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,mCAAoC,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,MAAM;IACjB;;;;;;;;;;;;;;;;;;;;;;;;KAwBC;WACmB,iBAAiB,CAAC,EAAE,eAAe,EAAE,EAAE;QACzD,eAAe,EAAE,UAAU,CAAC;KAC7B,GAAG,OAAO,CAAC,GAAG,CAAC;IAiBhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;WACiB,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE;QACxE,GAAG,EAAE,GAAG,CAAC;QACT,IAAI,EAAE,UAAU,CAAC;QACjB,EAAE,EAAE,UAAU,CAAC;QACf,cAAc,CAAC,EAAE,UAAU,CAAC;QAC5B,SAAS,CAAC,EAAE,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;KAChD,GAAG,OAAO,CAAC,UAAU,CAAC;IA+BvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;WACiB,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE;QACxE,GAAG,EAAE,GAAG,CAAC;QACT,IAAI,EAAE,UAAU,CAAC;QACjB,EAAE,EAAE,UAAU,CAAC;QACf,cAAc,CAAC,EAAE,UAAU,CAAC;QAC5B,SAAS,CAAC,EAAE,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;KAChD,GAAG,OAAO,CAAC,UAAU,CAAC;IA+BvB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;WACiB,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE;QAC1C,MAAM,EAAE,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;KACxC,GAAG,OAAO,CAAC,GAAG,CAAC;IAuBhB;;;;;;;;;;;;;;;;;;;OAmBG;WACiB,iBAAiB,CAAC,EAAE,UAAU,EAAE,EAAE;QACpD,UAAU,EAAE,GAAG,CAAC;KACjB,GAAG,OAAO,CAAC,UAAU,CAAC;CAWxB"}
@@ -0,0 +1,103 @@
1
+ import type { Jwk } from '@enbox/crypto';
2
+ import type { UnwrapKeyParams, WrapKeyParams } from '../types/params-direct.js';
3
+ /**
4
+ * Constant defining the AES key length values in bits.
5
+ *
6
+ * @remarks
7
+ * NIST publication FIPS 197 states:
8
+ * > The AES algorithm is capable of using cryptographic keys of 128, 192, and 256 bits to encrypt
9
+ * > and decrypt data in blocks of 128 bits.
10
+ *
11
+ * This implementation does not support key lengths that are different from the three values
12
+ * defined by this constant.
13
+ *
14
+ * @see {@link https://doi.org/10.6028/NIST.FIPS.197-upd1 | NIST FIPS 197}
15
+ */
16
+ declare const AES_KEY_LENGTHS: readonly [128, 192, 256];
17
+ export declare class AesKw {
18
+ /**
19
+ * Converts a raw private key in bytes to its corresponding JSON Web Key (JWK) format.
20
+ *
21
+ * @remarks
22
+ * This method takes a symmetric key represented as a byte array (Uint8Array) and
23
+ * converts it into a JWK object for use with AES (Advanced Encryption Standard)
24
+ * for key wrapping. The conversion process involves encoding the key into
25
+ * base64url format and setting the appropriate JWK parameters.
26
+ *
27
+ * The resulting JWK object includes the following properties:
28
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence (representing a symmetric key).
29
+ * - `k`: The symmetric key, base64url-encoded.
30
+ * - `kid`: Key ID, generated based on the JWK thumbprint.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const privateKeyBytes = new Uint8Array([...]); // Replace with actual symmetric key bytes
35
+ * const privateKey = await AesKw.bytesToPrivateKey({ privateKeyBytes });
36
+ * ```
37
+ *
38
+ * @param params - The parameters for the symmetric key conversion.
39
+ * @param params.privateKeyBytes - The raw symmetric key as a Uint8Array.
40
+ *
41
+ * @returns A Promise that resolves to the symmetric key in JWK format.
42
+ */
43
+ static bytesToPrivateKey({ privateKeyBytes }: {
44
+ privateKeyBytes: Uint8Array;
45
+ }): Promise<Jwk>;
46
+ /**
47
+ * Generates a symmetric key for AES for key wrapping in JSON Web Key (JWK) format.
48
+ *
49
+ * @remarks
50
+ * This method creates a new symmetric key of a specified length suitable for use with
51
+ * AES key wrapping. It uses cryptographically secure random number generation to
52
+ * ensure the uniqueness and security of the key. The generated key adheres to the JWK
53
+ * format, making it compatible with common cryptographic standards and easy to use in
54
+ * various cryptographic processes.
55
+ *
56
+ * The generated key includes the following components:
57
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence.
58
+ * - `k`: The symmetric key component, base64url-encoded.
59
+ * - `kid`: Key ID, generated based on the JWK thumbprint.
60
+ * - `alg`: Algorithm, set to 'A128KW', 'A192KW', or 'A256KW' for AES Key Wrap with the
61
+ * specified key length.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const length = 256; // Length of the key in bits (e.g., 128, 192, 256)
66
+ * const privateKey = await AesKw.generateKey({ length });
67
+ * ```
68
+ *
69
+ * @param params - The parameters for the key generation.
70
+ * @param params.length - The length of the key in bits. Common lengths are 128, 192, and 256 bits.
71
+ *
72
+ * @returns A Promise that resolves to the generated symmetric key in JWK format.
73
+ */
74
+ static generateKey({ length }: {
75
+ length: typeof AES_KEY_LENGTHS[number];
76
+ }): Promise<Jwk>;
77
+ /**
78
+ * Converts a private key from JSON Web Key (JWK) format to a raw byte array (Uint8Array).
79
+ *
80
+ * @remarks
81
+ * This method takes a symmetric key in JWK format and extracts its raw byte representation.
82
+ * It decodes the 'k' parameter of the JWK value, which represents the symmetric key in base64url
83
+ * encoding, into a byte array.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * const privateKey = { ... }; // A symmetric key in JWK format
88
+ * const privateKeyBytes = await AesKw.privateKeyToBytes({ privateKey });
89
+ * ```
90
+ *
91
+ * @param params - The parameters for the symmetric key conversion.
92
+ * @param params.privateKey - The symmetric key in JWK format.
93
+ *
94
+ * @returns A Promise that resolves to the symmetric key as a Uint8Array.
95
+ */
96
+ static privateKeyToBytes({ privateKey }: {
97
+ privateKey: Jwk;
98
+ }): Promise<Uint8Array>;
99
+ static unwrapKey({ wrappedKeyBytes, wrappedKeyAlgorithm, decryptionKey }: UnwrapKeyParams): Promise<Jwk>;
100
+ static wrapKey({ unwrappedKey, encryptionKey }: WrapKeyParams): Promise<Uint8Array>;
101
+ }
102
+ export {};
103
+ //# sourceMappingURL=aes-kw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes-kw.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/primitives/aes-kw.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKzC,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGhF;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,eAAe,0BAA2B,CAAC;AAEjD,qBAAa,KAAK;IAChB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;WACiB,iBAAiB,CAAC,EAAE,eAAe,EAAE,EAAE;QACzD,eAAe,EAAE,UAAU,CAAC;KAC7B,GAAG,OAAO,CAAC,GAAG,CAAC;IAiBhB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;WACiB,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE;QAC1C,MAAM,EAAE,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;KACxC,GAAG,OAAO,CAAC,GAAG,CAAC;IAuBhB;;;;;;;;;;;;;;;;;;OAkBG;WACiB,iBAAiB,CAAC,EAAE,UAAU,EAAE,EAAE;QACpD,UAAU,EAAE,GAAG,CAAC;KACjB,GAAG,OAAO,CAAC,UAAU,CAAC;WAYH,SAAS,CAAC,EAAE,eAAe,EAAE,mBAAmB,EAAE,aAAa,EAAE,EACnF,eAAe,GACd,OAAO,CAAC,GAAG,CAAC;WAoDK,OAAO,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,EACzD,aAAa,GACZ,OAAO,CAAC,UAAU,CAAC;CAyDvB"}
@@ -0,0 +1,90 @@
1
+ import { DeriveKeyBytesParams } from '../types/params-direct.js';
2
+ /**
3
+ * The object that should be passed into `Hkdf.deriveKey()`, when using the HKDF algorithm.
4
+ */
5
+ export type HkdfParams = {
6
+ /**
7
+ * A string representing the digest algorithm to use. This may be one of:
8
+ * - 'SHA-256'
9
+ * - 'SHA-384'
10
+ * - 'SHA-512'
11
+ */
12
+ hash: 'SHA-256' | 'SHA-384' | 'SHA-512';
13
+ /**
14
+ * The salt value to use in the derivation process.
15
+ *
16
+ * Ideally, the salt is a random or pseudo-random value with the same length as the output of the
17
+ * digest function. Unlike the input key material passed into deriveKey(), salt does not need to
18
+ * be kept secret.
19
+ *
20
+ * Note: The {@link https://datatracker.ietf.org/doc/html/rfc5869 | HKDF specification} states
21
+ * that adding salt "adds significantly to the strength of HKDF".
22
+ */
23
+ salt: string | Uint8Array;
24
+ /**
25
+ * Optional application-specific information to use in the HKDF.
26
+ *
27
+ * If given, this value is used to bind the derived key to application-specific contextual
28
+ * information. This makes it possible to derive different keys for different contexts while using
29
+ * the same input key material.
30
+ *
31
+ * If not provided, the `info` value is set to an empty array.
32
+ *
33
+ * Note: It is important that the `info` value be independent and unrelated to the input key
34
+ * material.
35
+ */
36
+ info?: string | Uint8Array;
37
+ };
38
+ /**
39
+ * The `Hkdf` class provides an interface for HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
40
+ * as defined in RFC 5869.
41
+ *
42
+ * Note: The `baseKeyBytes` that will be the input key material for HKDF should be a high-entropy secret
43
+ * value, such as a cryptographic key. It should be kept confidential and not be derived from a
44
+ * low-entropy value, such as a password.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const info = new Uint8Array([...]);
49
+ * const derivedKeyBytes = await Hkdf.deriveKeyBytes({
50
+ * baseKeyBytes: new Uint8Array([...]), // Input keying material
51
+ * hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
52
+ * salt: new Uint8Array([...]), // The salt value
53
+ * info: new Uint8Array([...]), // Optional application-specific information
54
+ * length: 256 // The length of the derived key in bits
55
+ * });
56
+ * ```
57
+ */
58
+ export declare class Hkdf {
59
+ /**
60
+ * Derives a key using the HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
61
+ *
62
+ * This method generates a derived key using a hash function from input keying material given as
63
+ * `baseKeyBytes`. The length of the derived key can be specified. Optionally, it can also use a salt
64
+ * and info for the derivation process.
65
+ *
66
+ * HKDF is useful in various cryptographic applications and protocols, especially when
67
+ * there's a need to derive multiple keys from a single source of key material.
68
+ *
69
+ * Note: The `baseKeyBytes` that will be the input key material for HKDF should be a high-entropy
70
+ * secret value, such as a cryptographic key. It should be kept confidential and not be derived
71
+ * from a low-entropy value, such as a password.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const info = new Uint8Array([...]);
76
+ * const derivedKeyBytes = await Hkdf.deriveKeyBytes({
77
+ * baseKeyBytes: new Uint8Array([...]), // Input keying material
78
+ * hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
79
+ * salt: new Uint8Array([...]), // The salt value
80
+ * info: new Uint8Array([...]), // Optional application-specific information
81
+ * length: 256 // The length of the derived key in bits
82
+ * });
83
+ * ```
84
+ *
85
+ * @param params - The parameters for key derivation.
86
+ * @returns A Promise that resolves to the derived key as a byte array.
87
+ */
88
+ static deriveKeyBytes({ baseKeyBytes, length, hash, salt, info }: DeriveKeyBytesParams & HkdfParams): Promise<Uint8Array>;
89
+ }
90
+ //# sourceMappingURL=hkdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/primitives/hkdf.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;OAKG;IACH,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAExC;;;;;;;;;OASG;IACH,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAE1B;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,IAAI;IACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;WACiB,cAAc,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAuB,EAAE,EAC9F,oBAAoB,GAAG,UAAU,GAChC,OAAO,CAAC,UAAU,CAAC;CAuBvB"}
@@ -0,0 +1,84 @@
1
+ import type { DeriveKeyBytesParams } from '../types/params-direct.js';
2
+ /**
3
+ * The object that should be passed into `Pbkdf2.deriveKeyBytes()`, when using the PBKDF2 algorithm.
4
+ */
5
+ export interface Pbkdf2Params {
6
+ /**
7
+ * A string representing the digest algorithm to use. This may be one of:
8
+ * - 'SHA-256'
9
+ * - 'SHA-384'
10
+ * - 'SHA-512'
11
+ */
12
+ hash: 'SHA-256' | 'SHA-384' | 'SHA-512';
13
+ /**
14
+ * The salt value to use in the derivation process, as a Uint8Array. This should be a random or
15
+ * pseudo-random value of at least 16 bytes. Unlike the `password`, `salt` does not need to be
16
+ * kept secret.
17
+ */
18
+ salt: Uint8Array;
19
+ /**
20
+ * A `Number` representing the number of iterations the hash function will be executed in
21
+ * `deriveKey()`. This impacts the computational cost of the `deriveKey()` operation, making it
22
+ * more resistant to dictionary attacks. The higher the number, the more secure, but also slower,
23
+ * the operation. Choose a value that balances security needs and performance for your
24
+ * application.
25
+ */
26
+ iterations: number;
27
+ }
28
+ /**
29
+ * The `Pbkdf2` class provides a secure way to derive cryptographic keys from a password
30
+ * using the PBKDF2 (Password-Based Key Derivation Function 2) algorithm.
31
+ *
32
+ * The PBKDF2 algorithm is widely used for generating keys from passwords, as it applies
33
+ * a pseudorandom function to the input password along with a salt value and iterates the
34
+ * process multiple times to increase the key's resistance to brute-force attacks.
35
+ *
36
+ * Notes:
37
+ * - The `baseKeyBytes` that will be the input key material for PBKDF2 is expected to be a low-entropy
38
+ * value, such as a password or passphrase. It should be kept confidential.
39
+ * - In 2023, {@link https://web.archive.org/web/20230123232056/https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2 | OWASP recommended}
40
+ * a minimum of 600,000 iterations for PBKDF2-HMAC-SHA256 and 210,000 for PBKDF2-HMAC-SHA512.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * // Key Derivation
45
+ * const derivedKeyBytes = await Pbkdf2.deriveKeyBytes({
46
+ * baseKeyBytes: new TextEncoder().encode('password'), // The password as a Uint8Array
47
+ * hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
48
+ * salt: new Uint8Array([...]), // The salt value
49
+ * iterations: 600_000, // The number of iterations
50
+ * length: 256 // The length of the derived key in bits
51
+ * });
52
+ * ```
53
+ *
54
+ * @remarks
55
+ * This class relies on the availability of the Web Crypto API.
56
+ */
57
+ export declare class Pbkdf2 {
58
+ /**
59
+ * Derives a cryptographic key from a password using the PBKDF2 algorithm.
60
+ *
61
+ * @remarks
62
+ * This method applies the PBKDF2 algorithm to the provided password along with
63
+ * a salt value and iterates the process a specified number of times. It uses
64
+ * a cryptographic hash function to enhance security and produce a key of the
65
+ * desired length. The method is capable of utilizing either the Web Crypto API
66
+ * or the Node.js Crypto module, depending on the environment's support.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const derivedKeyBytes = await Pbkdf2.deriveKeyBytes({
71
+ * baseKeyBytes: new TextEncoder().encode('password'), // The password as a Uint8Array
72
+ * hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
73
+ * salt: new Uint8Array([...]), // The salt value
74
+ * iterations: 600_000, // The number of iterations
75
+ * length: 256 // The length of the derived key in bits
76
+ * });
77
+ * ```
78
+ *
79
+ * @param params - The parameters for key derivation.
80
+ * @returns A Promise that resolves to the derived key as a byte array.
81
+ */
82
+ static deriveKeyBytes({ baseKeyBytes, hash, salt, iterations, length }: DeriveKeyBytesParams & Pbkdf2Params): Promise<Uint8Array>;
83
+ }
84
+ //# sourceMappingURL=pbkdf2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/primitives/pbkdf2.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAExC;;;;OAIG;IACH,IAAI,EAAE,UAAU,CAAC;IAEjB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,MAAM;IACjB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACiB,cAAc,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,EACjF,oBAAoB,GAAG,YAAY,GAClC,OAAO,CAAC,UAAU,CAAC;CAyBvB"}
@@ -0,0 +1,14 @@
1
+ export type InferCipherAlgorithm<T> = T extends {
2
+ /**
3
+ * The `encrypt` method signature from which the algorithm type is inferred.
4
+ * This is an internal implementation detail and not part of the public API.
5
+ */
6
+ encrypt(params: infer P): any;
7
+ } ? P extends {
8
+ /**
9
+ * The `algorithm` property within the parameters of `encrypt`.
10
+ * This internal element is used to infer the algorithm type.
11
+ */
12
+ algorithm: infer A;
13
+ } ? A : never : never;
14
+ //# sourceMappingURL=cipher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cipher.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/types/cipher.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,SAAS;IAC9C;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC;CAC/B,GACC,CAAC,SAAS;IACR;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC,CAAA;CACnB,GACC,CAAC,GACD,KAAK,GACP,KAAK,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { Jwk, CryptoApi as OldCryptoApi, KeyWrapper, SignParams, DigestParams, VerifyParams, GenerateKeyParams, GetPublicKeyParams, Cipher } from '@enbox/crypto';
2
+ import type { KeyConverter } from './key-converter.js';
3
+ import type { AsymmetricKeyConverter } from './key-converter.js';
4
+ import type { KeyBytesDeriver, KeyDeriver } from './key-deriver.js';
5
+ import type { BytesToPrivateKeyParams, BytesToPublicKeyParams, CipherParams, DeriveKeyBytesParams, DeriveKeyParams, PrivateKeyToBytesParams, PublicKeyToBytesParams, UnwrapKeyParams, WrapKeyParams } from './params-direct.js';
6
+ /**
7
+ * The `DsaApi` interface integrates key generation, hashing, and signing functionalities,
8
+ * designed for use with a Key Management System (KMS). It extends `AsymmetricKeyGenerator` for
9
+ * generating asymmetric keys, `Hasher` for hash digest computations, and `Signer` for signing and
10
+ * verifying operations.
11
+ *
12
+ * Concrete implementations of this interface are intended to be used with a KMS, which is
13
+ * responsible for generating and storing cryptographic keys. The KMS is also responsible for
14
+ * performing cryptographic operations using the keys it manages. The KMS is typically a cloud
15
+ * service, but it can also be a hardware device or software application.
16
+ *
17
+ * Guidelines for implementing this interface:
18
+ * - Must use JSON Web Keys ({@link Jwk | JWK}) as the key format.
19
+ * - Must IANA registered JSON Object Signing and Encryption
20
+ * {@ link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | (JOSE)}
21
+ * names for algorithm, curves, etc. whenever possible.
22
+ * - All I/O that interacts with private or secret keys must be done via reference using a
23
+ * {@link KeyIdentifier | `KeyIdentifier`}. Implementations can use any string as the key
24
+ * identifier (e.g. JWK thumbprint, UUID generated by hosted KMS, etc.).
25
+ * - Must support key generation, hashing, signing, and verifying operations.
26
+ * - May be extended to support other cryptographic operations.
27
+ * - Implementations of the `DsaApi` interface can be passed as an argument to the public API
28
+ * methods of Web5 libraries that involve key material (e.g., DID creation, VC signing, arbitrary
29
+ * data signing/verification, etc.).
30
+ */
31
+ export interface DsaApi<GenerateKeyInput = GenerateKeyParams, GenerateKeyOutput = Jwk, GetPublicKeyInput = GetPublicKeyParams, DigestInput = DigestParams, SignInput = SignParams, VerifyInput = VerifyParams> extends OldCryptoApi<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput, DigestInput, SignInput, VerifyInput> {
32
+ }
33
+ export interface CryptoApi<GenerateKeyInput = GenerateKeyParams, GenerateKeyOutput = Jwk, GetPublicKeyInput = GetPublicKeyParams, DigestInput = DigestParams, SignInput = SignParams, VerifyInput = VerifyParams, EncryptInput = CipherParams, DecryptInput = CipherParams, BytesToPublicKeyInput = BytesToPublicKeyParams, PublicKeyToBytesInput = PublicKeyToBytesParams, BytesToPrivateKeyInput = BytesToPrivateKeyParams, PrivateKeyToBytesInput = PrivateKeyToBytesParams, DeriveKeyInput = DeriveKeyParams, DeriveKeyOutput = Jwk, DeriveKeyBytesInput = DeriveKeyBytesParams, DeriveKeyBytesOutput = Uint8Array, WrapKeyInput = WrapKeyParams, UnwrapKeyInput = UnwrapKeyParams> extends DsaApi<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput, DigestInput, SignInput, VerifyInput>, Cipher<EncryptInput, DecryptInput>, AsymmetricKeyConverter<BytesToPublicKeyInput, PublicKeyToBytesInput>, KeyConverter<BytesToPrivateKeyInput, PrivateKeyToBytesInput>, KeyDeriver<DeriveKeyInput, DeriveKeyOutput>, KeyBytesDeriver<DeriveKeyBytesInput, DeriveKeyBytesOutput>, KeyWrapper<WrapKeyInput, UnwrapKeyInput> {
34
+ }
35
+ //# sourceMappingURL=crypto-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-api.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/types/crypto-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,GAAG,EACH,SAAS,IAAI,YAAY,EACzB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,EACP,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEhO;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,MAAM,CACrB,gBAAgB,GAAG,iBAAiB,EACpC,iBAAiB,GAAG,GAAG,EACvB,iBAAiB,GAAG,kBAAkB,EACtC,WAAW,GAAG,YAAY,EAC1B,SAAS,GAAG,UAAU,EACtB,WAAW,GAAG,YAAY,CAC1B,SAAQ,YAAY,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,CAAC;CAAG;AAEtH,MAAM,WAAW,SAAS,CACxB,gBAAgB,GAAG,iBAAiB,EACpC,iBAAiB,GAAG,GAAG,EACvB,iBAAiB,GAAG,kBAAkB,EACtC,WAAW,GAAG,YAAY,EAC1B,SAAS,GAAG,UAAU,EACtB,WAAW,GAAG,YAAY,EAC1B,YAAY,GAAG,YAAY,EAC3B,YAAY,GAAG,YAAY,EAC3B,qBAAqB,GAAG,sBAAsB,EAC9C,qBAAqB,GAAG,sBAAsB,EAC9C,sBAAsB,GAAG,uBAAuB,EAChD,sBAAsB,GAAG,uBAAuB,EAChD,cAAc,GAAG,eAAe,EAChC,eAAe,GAAG,GAAG,EACrB,mBAAmB,GAAG,oBAAoB,EAC1C,oBAAoB,GAAG,UAAU,EACjC,YAAY,GAAG,aAAa,EAC5B,cAAc,GAAG,eAAe,CAChC,SACA,MAAM,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,CAAC,EACnG,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,EAClC,sBAAsB,CAAC,qBAAqB,EAAE,qBAAqB,CAAC,EACpE,YAAY,CAAC,sBAAsB,EAAE,sBAAsB,CAAC,EAC5D,UAAU,CAAC,cAAc,EAAE,eAAe,CAAC,EAC3C,eAAe,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,EAC1D,UAAU,CAAC,YAAY,EAAE,cAAc,CAAC;CAAG"}
@@ -0,0 +1,49 @@
1
+ import type { Jwk } from '@enbox/crypto';
2
+ /**
3
+ * `KeyConverter` interface for converting private keys between byte array and JWK formats.
4
+ */
5
+ export interface KeyConverter<BytesToPrivateKeyInput, PrivateKeyToBytesInput> {
6
+ /**
7
+ * Converts a private key from a byte array to JWK format.
8
+ *
9
+ * @param params - The parameters for the private key conversion.
10
+ * @param params.privateKeyBytes - The raw private key as a Uint8Array.
11
+ *
12
+ * @returns A Promise that resolves to the private key in JWK format.
13
+ */
14
+ bytesToPrivateKey(params: BytesToPrivateKeyInput): Promise<Jwk>;
15
+ /**
16
+ * Converts a private key from JWK format to a byte array.
17
+ *
18
+ * @param params - The parameters for the private key conversion.
19
+ * @param params.privateKey - The private key in JWK format.
20
+ *
21
+ * @returns A Promise that resolves to the private key as a Uint8Array.
22
+ */
23
+ privateKeyToBytes(params: PrivateKeyToBytesInput): Promise<Uint8Array>;
24
+ }
25
+ /**
26
+ * `AsymmetricKeyConverter` interface extends {@link KeyConverter |`KeyConverter`}, adding support
27
+ * for public key conversions.
28
+ */
29
+ export interface AsymmetricKeyConverter<BytesToPublicKeyInput, PublicKeyToBytesInput> {
30
+ /**
31
+ * Converts a public key from a byte array to JWK format.
32
+ *
33
+ * @param params - The parameters for the public key conversion.
34
+ * @param params.publicKeyBytes - The raw public key as a Uint8Array.
35
+ *
36
+ * @returns A Promise that resolves to the public key in JWK format.
37
+ */
38
+ bytesToPublicKey(params: BytesToPublicKeyInput): Promise<Jwk>;
39
+ /**
40
+ * Converts a public key from JWK format to a byte array.
41
+ *
42
+ * @param params - The parameters for the public key conversion.
43
+ * @param params.publicKey - The public key in JWK format.
44
+ *
45
+ * @returns A Promise that resolves to the public key as a Uint8Array.
46
+ */
47
+ publicKeyToBytes(params: PublicKeyToBytesInput): Promise<Uint8Array>;
48
+ }
49
+ //# sourceMappingURL=key-converter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-converter.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/types/key-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,sBAAsB,EAAE,sBAAsB;IAE1E;;;;;;;OAOG;IACH,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEhE;;;;;;;OAOG;IACH,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACxE;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CAAC,qBAAqB,EAAE,qBAAqB;IAClF;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAE9D;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACtE"}