@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,507 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { Convert, logger } from '@enbox/common';
22
+ import { Ed25519, EdDsaAlgorithm, Sha256, X25519, CryptoUtils, } from '@enbox/crypto';
23
+ import { concatenateUrl } from './utils.js';
24
+ import { xchacha20poly1305 } from '@noble/ciphers/chacha';
25
+ import { DidJwk } from '@enbox/dids';
26
+ import { DwnInterface } from './types/dwn.js';
27
+ import { AgentPermissionsApi } from './permissions-api.js';
28
+ import { isRecordPermissionScope } from './dwn-api.js';
29
+ import { DwnInterfaceName, DwnMethodName } from '@enbox/dwn-sdk-js';
30
+ /**
31
+ * Gets the correct OIDC endpoint out of the {@link OidcEndpoint} options provided.
32
+ * Handles a trailing slash on baseURL
33
+ *
34
+ * @param {Object} options the options object
35
+ * @param {string} options.baseURL for example `http://foo.com/connect/
36
+ * @param {OidcEndpoint} options.endpoint the OIDC endpoint desired
37
+ * @param {string} options.authParam this is the unique id which must be provided when getting the `authorize` endpoint
38
+ * @param {string} options.tokenParam this is the random state as b64url which must be provided with the `token` endpoint
39
+ */
40
+ function buildOidcUrl({ baseURL, endpoint, authParam, tokenParam, }) {
41
+ switch (endpoint) {
42
+ /** 1. client sends {@link PushedAuthRequest} & client receives {@link PushedAuthResponse} */
43
+ case 'pushedAuthorizationRequest':
44
+ return concatenateUrl(baseURL, 'par');
45
+ /** 2. provider gets {@link Web5ConnectAuthRequest} */
46
+ case 'authorize':
47
+ if (!authParam)
48
+ throw new Error(`authParam must be providied when building a token URL`);
49
+ return concatenateUrl(baseURL, `authorize/${authParam}.jwt`);
50
+ /** 3. provider sends {@link Web5ConnectAuthResponse} */
51
+ case 'callback':
52
+ return concatenateUrl(baseURL, `callback`);
53
+ /** 4. client gets {@link Web5ConnectAuthResponse */
54
+ case 'token':
55
+ if (!tokenParam)
56
+ throw new Error(`tokenParam must be providied when building a token URL`);
57
+ return concatenateUrl(baseURL, `token/${tokenParam}.jwt`);
58
+ // TODO: metadata endpoints?
59
+ default:
60
+ throw new Error(`No matches for endpoint specified: ${endpoint}`);
61
+ }
62
+ }
63
+ /**
64
+ * Generates a cryptographically random "code challenge" in
65
+ * accordance with the RFC 7636 PKCE specification.
66
+ *
67
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.2 | RFC 7636 }
68
+ */
69
+ function generateCodeChallenge() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const codeVerifierBytes = CryptoUtils.randomBytes(32);
72
+ const codeChallengeBytes = yield Sha256.digest({ data: codeVerifierBytes });
73
+ const codeChallengeBase64Url = Convert.uint8Array(codeChallengeBytes).toBase64Url();
74
+ return { codeChallengeBytes, codeChallengeBase64Url };
75
+ });
76
+ }
77
+ /** Client creates the {@link Web5ConnectAuthRequest} */
78
+ function createAuthRequest(options) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ // Generate a random state value to associate the authorization request with the response.
81
+ const stateBytes = CryptoUtils.randomBytes(16);
82
+ // Generate a random nonce value to associate the ID Token with the authorization request.
83
+ const nonceBytes = CryptoUtils.randomBytes(16);
84
+ const requestObject = Object.assign(Object.assign({}, options), { nonce: Convert.uint8Array(nonceBytes).toBase64Url(), response_type: 'id_token', response_mode: 'direct_post', state: Convert.uint8Array(stateBytes).toBase64Url(), client_metadata: {
85
+ subject_syntax_types_supported: ['did:dht', 'did:jwk'],
86
+ } });
87
+ return requestObject;
88
+ });
89
+ }
90
+ /** Encrypts the auth request with the key which will be passed through QR code */
91
+ function encryptAuthRequest({ jwt, encryptionKey, }) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const protectedHeader = {
94
+ alg: 'dir',
95
+ cty: 'JWT',
96
+ enc: 'XC20P',
97
+ typ: 'JWT',
98
+ };
99
+ const nonce = CryptoUtils.randomBytes(24);
100
+ const additionalData = Convert.object(protectedHeader).toUint8Array();
101
+ const jwtBytes = Convert.string(jwt).toUint8Array();
102
+ const chacha = xchacha20poly1305(encryptionKey, nonce, additionalData);
103
+ const ciphertextAndTag = chacha.encrypt(jwtBytes);
104
+ /** The cipher output concatenates the encrypted data and tag
105
+ * so we need to extract the values for use in the JWE. */
106
+ const ciphertext = ciphertextAndTag.subarray(0, -16);
107
+ const authenticationTag = ciphertextAndTag.subarray(-16);
108
+ const compactJwe = [
109
+ Convert.object(protectedHeader).toBase64Url(),
110
+ '',
111
+ Convert.uint8Array(nonce).toBase64Url(),
112
+ Convert.uint8Array(ciphertext).toBase64Url(),
113
+ Convert.uint8Array(authenticationTag).toBase64Url(),
114
+ ].join('.');
115
+ return compactJwe;
116
+ });
117
+ }
118
+ /** Create a response object compatible with Web5 Connect and OIDC SIOPv2 */
119
+ function createResponseObject(options) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ const currentTimeInSeconds = Math.floor(Date.now() / 1000);
122
+ const responseObject = Object.assign(Object.assign({}, options), { iat: currentTimeInSeconds, exp: currentTimeInSeconds + 600 });
123
+ return responseObject;
124
+ });
125
+ }
126
+ /** sign an object and transform it into a jwt using a did */
127
+ function signJwt({ did, data, }) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ const header = Convert.object({
130
+ alg: 'EdDSA',
131
+ kid: did.document.verificationMethod[0].id,
132
+ typ: 'JWT',
133
+ }).toBase64Url();
134
+ const payload = Convert.object(data).toBase64Url();
135
+ // signs using ed25519 EdDSA
136
+ const signer = yield did.getSigner();
137
+ const signature = yield signer.sign({
138
+ data: Convert.string(`${header}.${payload}`).toUint8Array(),
139
+ });
140
+ const signatureBase64Url = Convert.uint8Array(signature).toBase64Url();
141
+ const jwt = `${header}.${payload}.${signatureBase64Url}`;
142
+ return jwt;
143
+ });
144
+ }
145
+ /** Take the decrypted JWT and verify it was signed by its public DID. Return parsed object. */
146
+ function verifyJwt({ jwt }) {
147
+ var _a, _b;
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ const [headerB64U, payloadB64U, signatureB64U] = jwt.split('.');
150
+ // Convert the header back to a JOSE object and verify that the 'kid' header value is present.
151
+ const header = Convert.base64Url(headerB64U).toObject();
152
+ if (!header.kid)
153
+ throw new Error(`OIDC: Object could not be verified due to missing 'kid' header value.`);
154
+ // Resolve the Client DID document.
155
+ const { didDocument } = yield DidJwk.resolve(header.kid.split('#')[0]);
156
+ if (!didDocument)
157
+ throw new Error('OIDC: Object could not be verified due to Client DID resolution issue.');
158
+ // Get the public key used to sign the Object from the DID document.
159
+ const { publicKeyJwk } = (_b = (_a = didDocument.verificationMethod) === null || _a === void 0 ? void 0 : _a.find((method) => {
160
+ return method.id === header.kid;
161
+ })) !== null && _b !== void 0 ? _b : {};
162
+ if (!publicKeyJwk)
163
+ throw new Error('OIDC: Object could not be verified due to missing public key in DID document.');
164
+ const EdDsa = new EdDsaAlgorithm();
165
+ const isValid = yield EdDsa.verify({
166
+ key: publicKeyJwk,
167
+ signature: Convert.base64Url(signatureB64U).toUint8Array(),
168
+ data: Convert.string(`${headerB64U}.${payloadB64U}`).toUint8Array(),
169
+ });
170
+ if (!isValid)
171
+ throw new Error('OIDC: Object failed verification due to invalid signature.');
172
+ const object = Convert.base64Url(payloadB64U).toObject();
173
+ return object;
174
+ });
175
+ }
176
+ /**
177
+ * Fetches the {@Web5ConnectAuthRequest} from the authorize endpoint and decrypts it
178
+ * using the encryption key passed via QR code.
179
+ */
180
+ const getAuthRequest = (request_uri, encryption_key) => __awaiter(void 0, void 0, void 0, function* () {
181
+ const authRequest = yield fetch(request_uri);
182
+ const jwe = yield authRequest.text();
183
+ const jwt = decryptAuthRequest({
184
+ jwe,
185
+ encryption_key,
186
+ });
187
+ const web5ConnectAuthRequest = (yield verifyJwt({
188
+ jwt,
189
+ }));
190
+ return web5ConnectAuthRequest;
191
+ });
192
+ /** Take the encrypted JWE, decrypt using the code challenge and return a JWT string which will need to be verified */
193
+ function decryptAuthRequest({ jwe, encryption_key, }) {
194
+ const [protectedHeaderB64U, , nonceB64U, ciphertextB64U, authenticationTagB64U,] = jwe.split('.');
195
+ const encryptionKeyBytes = Convert.base64Url(encryption_key).toUint8Array();
196
+ const protectedHeader = Convert.base64Url(protectedHeaderB64U).toUint8Array();
197
+ const additionalData = protectedHeader;
198
+ const nonce = Convert.base64Url(nonceB64U).toUint8Array();
199
+ const ciphertext = Convert.base64Url(ciphertextB64U).toUint8Array();
200
+ const authenticationTag = Convert.base64Url(authenticationTagB64U).toUint8Array();
201
+ // The cipher expects the encrypted data and tag to be concatenated.
202
+ const ciphertextAndTag = new Uint8Array([
203
+ ...ciphertext,
204
+ ...authenticationTag,
205
+ ]);
206
+ const chacha = xchacha20poly1305(encryptionKeyBytes, nonce, additionalData);
207
+ const decryptedJwtBytes = chacha.decrypt(ciphertextAndTag);
208
+ const jwt = Convert.uint8Array(decryptedJwtBytes).toString();
209
+ return jwt;
210
+ }
211
+ /**
212
+ * The client uses to decrypt the jwe obtained from the auth server which contains
213
+ * the {@link Web5ConnectAuthResponse} that was sent by the provider to the auth server.
214
+ *
215
+ * @async
216
+ * @param {BearerDid} clientDid - The did that was initially used by the client for ECDH at connect init.
217
+ * @param {string} jwe - The encrypted data as a jwe.
218
+ * @param {string} pin - The pin that was obtained from the user.
219
+ */
220
+ function decryptAuthResponse(clientDid, jwe, pin) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ const [protectedHeaderB64U, , nonceB64U, ciphertextB64U, authenticationTagB64U,] = jwe.split('.');
223
+ // get the delegatedid public key from the header
224
+ const header = Convert.base64Url(protectedHeaderB64U).toObject();
225
+ const delegateResolvedDid = yield DidJwk.resolve(header.kid.split('#')[0]);
226
+ // derive ECDH shared key using the provider's public key and our clientDid private key
227
+ const sharedKey = yield Oidc.deriveSharedKey(clientDid, delegateResolvedDid.didDocument);
228
+ // add the pin to the AAD
229
+ const additionalData = Object.assign(Object.assign({}, header), { pin: pin });
230
+ const AAD = Convert.object(additionalData).toUint8Array();
231
+ const nonce = Convert.base64Url(nonceB64U).toUint8Array();
232
+ const ciphertext = Convert.base64Url(ciphertextB64U).toUint8Array();
233
+ const authenticationTag = Convert.base64Url(authenticationTagB64U).toUint8Array();
234
+ // The cipher expects the encrypted data and tag to be concatenated.
235
+ const ciphertextAndTag = new Uint8Array([
236
+ ...ciphertext,
237
+ ...authenticationTag,
238
+ ]);
239
+ // decrypt using the sharedKey
240
+ const chacha = xchacha20poly1305(sharedKey, nonce, AAD);
241
+ const decryptedJwtBytes = chacha.decrypt(ciphertextAndTag);
242
+ const jwt = Convert.uint8Array(decryptedJwtBytes).toString();
243
+ return jwt;
244
+ });
245
+ }
246
+ /** Derives a shared ECDH private key in order to encrypt the {@link Web5ConnectAuthResponse} */
247
+ function deriveSharedKey(privateKeyDid, publicKeyDid) {
248
+ var _a, _b;
249
+ return __awaiter(this, void 0, void 0, function* () {
250
+ const privatePortableDid = yield privateKeyDid.export();
251
+ const publicJwk = (_a = publicKeyDid.verificationMethod) === null || _a === void 0 ? void 0 : _a[0].publicKeyJwk;
252
+ const privateJwk = (_b = privatePortableDid.privateKeys) === null || _b === void 0 ? void 0 : _b[0];
253
+ publicJwk.alg = 'EdDSA';
254
+ const publicX25519 = yield Ed25519.convertPublicKeyToX25519({
255
+ publicKey: publicJwk,
256
+ });
257
+ const privateX25519 = yield Ed25519.convertPrivateKeyToX25519({
258
+ privateKey: privateJwk,
259
+ });
260
+ const sharedKey = yield X25519.sharedSecret({
261
+ privateKeyA: privateX25519,
262
+ publicKeyB: publicX25519,
263
+ });
264
+ const derivedKey = yield crypto.subtle.importKey('raw', sharedKey, { name: 'HKDF' }, false, ['deriveBits']);
265
+ const derivedKeyBits = yield crypto.subtle.deriveBits({
266
+ name: 'HKDF',
267
+ hash: 'SHA-256',
268
+ info: new Uint8Array(),
269
+ salt: new Uint8Array(),
270
+ }, derivedKey, 256);
271
+ const sharedEncryptionKey = new Uint8Array(derivedKeyBits);
272
+ return sharedEncryptionKey;
273
+ });
274
+ }
275
+ /**
276
+ * Encrypts the auth response jwt. Requires a randomPin is added to the AAD of the
277
+ * encryption algorithm in order to prevent man in the middle and eavesdropping attacks.
278
+ * The keyid of the delegate did is used to pass the public key to the client in order
279
+ * for the client to derive the shared ECDH private key.
280
+ */
281
+ function encryptAuthResponse({ jwt, encryptionKey, delegateDidKeyId, randomPin, }) {
282
+ const protectedHeader = {
283
+ alg: 'dir',
284
+ cty: 'JWT',
285
+ enc: 'XC20P',
286
+ typ: 'JWT',
287
+ kid: delegateDidKeyId,
288
+ };
289
+ const nonce = CryptoUtils.randomBytes(24);
290
+ const additionalData = Convert.object(Object.assign(Object.assign({}, protectedHeader), { pin: randomPin })).toUint8Array();
291
+ const jwtBytes = Convert.string(jwt).toUint8Array();
292
+ const chacha = xchacha20poly1305(encryptionKey, nonce, additionalData);
293
+ const ciphertextAndTag = chacha.encrypt(jwtBytes);
294
+ /** The cipher output concatenates the encrypted data and tag
295
+ * so we need to extract the values for use in the JWE. */
296
+ const ciphertext = ciphertextAndTag.subarray(0, -16);
297
+ const authenticationTag = ciphertextAndTag.subarray(-16);
298
+ const compactJwe = [
299
+ Convert.object(protectedHeader).toBase64Url(),
300
+ '',
301
+ Convert.uint8Array(nonce).toBase64Url(),
302
+ Convert.uint8Array(ciphertext).toBase64Url(),
303
+ Convert.uint8Array(authenticationTag).toBase64Url(),
304
+ ].join('.');
305
+ return compactJwe;
306
+ }
307
+ function shouldUseDelegatePermission(scope) {
308
+ // Currently all record permissions are treated as delegated permissions
309
+ // In the future only methods that modify state will be delegated and the rest will be normal permissions
310
+ if (isRecordPermissionScope(scope)) {
311
+ return true;
312
+ }
313
+ else if (scope.interface === DwnInterfaceName.Protocols && scope.method === DwnMethodName.Configure) {
314
+ // ProtocolConfigure messages are also delegated, as they modify state
315
+ return true;
316
+ }
317
+ // All other permissions are not treated as delegated
318
+ return false;
319
+ }
320
+ /**
321
+ * Creates the permission grants that assign to the selectedDid the level of
322
+ * permissions that the web app requested in the {@link Web5ConnectAuthRequest}
323
+ */
324
+ function createPermissionGrants(selectedDid, delegateBearerDid, agent, scopes) {
325
+ return __awaiter(this, void 0, void 0, function* () {
326
+ const permissionsApi = new AgentPermissionsApi({ agent });
327
+ // TODO: cleanup all grants if one fails by deleting them from the DWN: https://github.com/TBD54566975/web5-js/issues/849
328
+ logger.log(`Creating permission grants for ${scopes.length} scopes given...`);
329
+ const permissionGrants = yield Promise.all(scopes.map((scope) => {
330
+ // check if the scope is a records permission scope, or a protocol configure scope, if so it should use a delegated permission.
331
+ const delegated = shouldUseDelegatePermission(scope);
332
+ return permissionsApi.createGrant({
333
+ delegated,
334
+ store: true,
335
+ grantedTo: delegateBearerDid.uri,
336
+ scope,
337
+ dateExpires: '2040-06-25T16:09:16.693356Z',
338
+ author: selectedDid,
339
+ });
340
+ }));
341
+ logger.log(`Sending ${permissionGrants.length} permission grants to remote DWN...`);
342
+ const messagePromises = permissionGrants.map((grant) => __awaiter(this, void 0, void 0, function* () {
343
+ // Quirk: we have to pull out encodedData out of the message the schema validator doesn't want it there
344
+ const _a = grant.message, { encodedData } = _a, rawMessage = __rest(_a, ["encodedData"]);
345
+ const data = Convert.base64Url(encodedData).toUint8Array();
346
+ const { reply } = yield agent.sendDwnRequest({
347
+ author: selectedDid,
348
+ target: selectedDid,
349
+ messageType: DwnInterface.RecordsWrite,
350
+ dataStream: new Blob([data]),
351
+ rawMessage,
352
+ });
353
+ // check if the message was sent successfully, if the remote returns 409 the message may have come through already via sync
354
+ if (reply.status.code !== 202 && reply.status.code !== 409) {
355
+ logger.error(`Error sending RecordsWrite: ${reply.status.detail}`);
356
+ logger.error(`RecordsWrite message: ${rawMessage}`);
357
+ throw new Error(`Could not send the message. Error details: ${reply.status.detail}`);
358
+ }
359
+ return grant.message;
360
+ }));
361
+ try {
362
+ const messages = yield Promise.all(messagePromises);
363
+ return messages;
364
+ }
365
+ catch (error) {
366
+ logger.error(`Error during batch-send of permission grants: ${error}`);
367
+ throw error;
368
+ }
369
+ });
370
+ }
371
+ /**
372
+ * Installs the protocol required by the Client on the Provider if it doesn't already exist.
373
+ */
374
+ function prepareProtocol(selectedDid, agent, protocolDefinition) {
375
+ return __awaiter(this, void 0, void 0, function* () {
376
+ const queryMessage = yield agent.processDwnRequest({
377
+ author: selectedDid,
378
+ messageType: DwnInterface.ProtocolsQuery,
379
+ target: selectedDid,
380
+ messageParams: { filter: { protocol: protocolDefinition.protocol } },
381
+ });
382
+ if (queryMessage.reply.status.code !== 200) {
383
+ // if the query failed, throw an error
384
+ throw new Error(`Could not fetch protocol: ${queryMessage.reply.status.detail}`);
385
+ }
386
+ else if (queryMessage.reply.entries === undefined || queryMessage.reply.entries.length === 0) {
387
+ logger.log(`Protocol does not exist, creating: ${protocolDefinition.protocol}`);
388
+ // send the protocol definition to the remote DWN first, if it passes we can process it locally
389
+ const { reply: sendReply, message: configureMessage } = yield agent.sendDwnRequest({
390
+ author: selectedDid,
391
+ target: selectedDid,
392
+ messageType: DwnInterface.ProtocolsConfigure,
393
+ messageParams: { definition: protocolDefinition },
394
+ });
395
+ // check if the message was sent successfully, if the remote returns 409 the message may have come through already via sync
396
+ if (sendReply.status.code !== 202 && sendReply.status.code !== 409) {
397
+ throw new Error(`Could not send protocol: ${sendReply.status.detail}`);
398
+ }
399
+ // process the protocol locally, we don't have to check if it exists as this is just a convenience over waiting for sync.
400
+ yield agent.processDwnRequest({
401
+ author: selectedDid,
402
+ target: selectedDid,
403
+ messageType: DwnInterface.ProtocolsConfigure,
404
+ rawMessage: configureMessage
405
+ });
406
+ }
407
+ else {
408
+ logger.log(`Protocol already exists: ${protocolDefinition.protocol}`);
409
+ // the protocol already exists, let's make sure it exists on the remote DWN as the requesting app will need it
410
+ const configureMessage = queryMessage.reply.entries[0];
411
+ const { reply: sendReply } = yield agent.sendDwnRequest({
412
+ author: selectedDid,
413
+ target: selectedDid,
414
+ messageType: DwnInterface.ProtocolsConfigure,
415
+ rawMessage: configureMessage,
416
+ });
417
+ if (sendReply.status.code !== 202 && sendReply.status.code !== 409) {
418
+ throw new Error(`Could not send protocol: ${sendReply.status.detail}`);
419
+ }
420
+ }
421
+ });
422
+ }
423
+ /**
424
+ * Creates a delegate did which the web app will use as its future indentity.
425
+ * Assigns to that DID the level of permissions that the web app requested in
426
+ * the {@link Web5ConnectAuthRequest}. Encrypts via ECDH key that the web app
427
+ * will have access to because the web app has the public key which it provided
428
+ * in the {@link Web5ConnectAuthRequest}. Then sends the ciphertext of this
429
+ * {@link Web5ConnectAuthResponse} to the callback endpoint. Which the
430
+ * web app will need to retrieve from the token endpoint and decrypt with the pin to access.
431
+ */
432
+ function submitAuthResponse(selectedDid, authRequest, randomPin, agent) {
433
+ return __awaiter(this, void 0, void 0, function* () {
434
+ const delegateBearerDid = yield DidJwk.create();
435
+ const delegatePortableDid = yield delegateBearerDid.export();
436
+ // TODO: roll back permissions and protocol configurations if an error occurs. Need a way to delete protocols to achieve this.
437
+ const delegateGrantPromises = authRequest.permissionRequests.map((permissionRequest) => __awaiter(this, void 0, void 0, function* () {
438
+ const { protocolDefinition, permissionScopes } = permissionRequest;
439
+ // We validate that all permission scopes match the protocol uri of the protocol definition they are provided with.
440
+ const grantsMatchProtocolUri = permissionScopes.every(scope => 'protocol' in scope && scope.protocol === protocolDefinition.protocol);
441
+ if (!grantsMatchProtocolUri) {
442
+ throw new Error('All permission scopes must match the protocol uri they are provided with.');
443
+ }
444
+ yield prepareProtocol(selectedDid, agent, protocolDefinition);
445
+ const permissionGrants = yield Oidc.createPermissionGrants(selectedDid, delegateBearerDid, agent, permissionScopes);
446
+ return permissionGrants;
447
+ }));
448
+ const delegateGrants = (yield Promise.all(delegateGrantPromises)).flat();
449
+ logger.log('Generating auth response object...');
450
+ const responseObject = yield Oidc.createResponseObject({
451
+ //* the IDP's did that was selected to be connected
452
+ iss: selectedDid,
453
+ //* the client's new identity
454
+ sub: delegateBearerDid.uri,
455
+ //* the client's temporary ephemeral did used for connect
456
+ aud: authRequest.client_id,
457
+ //* the nonce of the original auth request
458
+ nonce: authRequest.nonce,
459
+ delegateGrants,
460
+ delegatePortableDid,
461
+ });
462
+ // Sign the Response Object using the ephemeral DID's signing key.
463
+ logger.log('Signing auth response object...');
464
+ const responseObjectJwt = yield Oidc.signJwt({
465
+ did: delegateBearerDid,
466
+ data: responseObject,
467
+ });
468
+ const clientDid = yield DidJwk.resolve(authRequest.client_id);
469
+ const sharedKey = yield Oidc.deriveSharedKey(delegateBearerDid, clientDid === null || clientDid === void 0 ? void 0 : clientDid.didDocument);
470
+ logger.log('Encrypting auth response object...');
471
+ const encryptedResponse = Oidc.encryptAuthResponse({
472
+ jwt: responseObjectJwt,
473
+ encryptionKey: sharedKey,
474
+ delegateDidKeyId: delegateBearerDid.document.verificationMethod[0].id,
475
+ randomPin,
476
+ });
477
+ const formEncodedRequest = new URLSearchParams({
478
+ id_token: encryptedResponse,
479
+ state: authRequest.state,
480
+ }).toString();
481
+ logger.log(`Sending auth response object to Web5 Connect server: ${authRequest.redirect_uri}`);
482
+ yield fetch(authRequest.redirect_uri, {
483
+ body: formEncodedRequest,
484
+ method: 'POST',
485
+ headers: {
486
+ 'Content-Type': 'application/x-www-form-urlencoded',
487
+ },
488
+ });
489
+ });
490
+ }
491
+ export const Oidc = {
492
+ createAuthRequest,
493
+ encryptAuthRequest,
494
+ getAuthRequest,
495
+ decryptAuthRequest,
496
+ createPermissionGrants,
497
+ createResponseObject,
498
+ encryptAuthResponse,
499
+ decryptAuthResponse,
500
+ deriveSharedKey,
501
+ signJwt,
502
+ verifyJwt,
503
+ buildOidcUrl,
504
+ generateCodeChallenge,
505
+ submitAuthResponse,
506
+ };
507
+ //# sourceMappingURL=oidc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oidc.js","sourceRoot":"","sources":["../../src/oidc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAC7D,OAAO,EACL,OAAO,EACP,cAAc,EAGd,MAAM,EACN,MAAM,EACN,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAe,MAAM,EAA+B,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