better-auth 1.7.0-beta.2 → 1.7.0-beta.4

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 (282) hide show
  1. package/README.md +14 -15
  2. package/dist/_virtual/_rolldown/runtime.mjs +10 -1
  3. package/dist/api/index.d.mts +18 -48
  4. package/dist/api/routes/account.d.mts +4 -23
  5. package/dist/api/routes/account.mjs +102 -75
  6. package/dist/api/routes/callback.mjs +42 -20
  7. package/dist/api/routes/email-verification.d.mts +1 -0
  8. package/dist/api/routes/email-verification.mjs +6 -5
  9. package/dist/api/routes/error.mjs +1 -1
  10. package/dist/api/routes/password.mjs +1 -1
  11. package/dist/api/routes/session.mjs +15 -10
  12. package/dist/api/routes/sign-in.d.mts +3 -1
  13. package/dist/api/routes/sign-in.mjs +13 -15
  14. package/dist/api/routes/sign-up.d.mts +1 -0
  15. package/dist/api/routes/sign-up.mjs +10 -8
  16. package/dist/api/routes/update-user.mjs +8 -8
  17. package/dist/api/to-auth-endpoints.mjs +7 -1
  18. package/dist/auth/base.mjs +30 -27
  19. package/dist/client/config.mjs +8 -1
  20. package/dist/client/fetch-plugins.mjs +2 -1
  21. package/dist/client/index.d.mts +2 -2
  22. package/dist/client/lynx/index.d.mts +13 -0
  23. package/dist/client/lynx/index.mjs +2 -1
  24. package/dist/client/parser.mjs +0 -1
  25. package/dist/client/plugins/index.d.mts +4 -17
  26. package/dist/client/plugins/index.mjs +1 -4
  27. package/dist/client/proxy.mjs +2 -1
  28. package/dist/client/react/index.d.mts +13 -0
  29. package/dist/client/react/index.mjs +2 -1
  30. package/dist/client/session-atom.mjs +12 -1
  31. package/dist/client/solid/index.d.mts +13 -0
  32. package/dist/client/solid/index.mjs +3 -2
  33. package/dist/client/svelte/index.d.mts +13 -0
  34. package/dist/client/svelte/index.mjs +2 -1
  35. package/dist/client/vanilla.d.mts +13 -0
  36. package/dist/client/vanilla.mjs +2 -1
  37. package/dist/client/vue/index.d.mts +13 -0
  38. package/dist/client/vue/index.mjs +2 -1
  39. package/dist/context/create-context.mjs +10 -14
  40. package/dist/context/helpers.mjs +3 -2
  41. package/dist/cookies/cookie-utils.d.mts +33 -1
  42. package/dist/cookies/cookie-utils.mjs +95 -14
  43. package/dist/cookies/index.d.mts +2 -3
  44. package/dist/cookies/index.mjs +39 -11
  45. package/dist/cookies/session-store.mjs +4 -23
  46. package/dist/db/get-migration.mjs +4 -4
  47. package/dist/db/index.d.mts +2 -2
  48. package/dist/db/index.mjs +3 -2
  49. package/dist/db/internal-adapter.mjs +129 -27
  50. package/dist/db/schema.d.mts +14 -1
  51. package/dist/db/schema.mjs +26 -1
  52. package/dist/db/with-hooks.d.mts +1 -0
  53. package/dist/db/with-hooks.mjs +58 -1
  54. package/dist/index.d.mts +2 -2
  55. package/dist/index.mjs +2 -2
  56. package/dist/integrations/cookie-plugin-guard.mjs +18 -0
  57. package/dist/integrations/next-js.mjs +6 -0
  58. package/dist/integrations/svelte-kit.mjs +6 -0
  59. package/dist/integrations/tanstack-start-solid.mjs +6 -0
  60. package/dist/integrations/tanstack-start.mjs +6 -0
  61. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/index.mjs +32 -0
  62. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/linux.mjs +55 -0
  63. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/macos.mjs +26 -0
  64. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/termux.mjs +39 -0
  65. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/windows.mjs +19 -0
  66. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/chunks/prompt.mjs +845 -0
  67. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs +386 -0
  68. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs +320 -0
  69. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +62 -0
  70. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +190 -0
  71. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/utils.mjs +2 -0
  72. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.mjs +29 -0
  73. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.mjs +42 -0
  74. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.mjs +67 -0
  75. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.mjs +23 -0
  76. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.mjs +22 -0
  77. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.mjs +36 -0
  78. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/adapters/node.d.mts +292 -0
  79. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/adapters/node.mjs +127 -0
  80. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/index.d.mts +145 -0
  81. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.BQXMA5bH.d.mts +298 -0
  82. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.By9qWDAI.mjs +9 -0
  83. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.CipVM6lf.mjs +3549 -0
  84. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.D9ehKjSh.mjs +66 -0
  85. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.DfCzGthR.mjs +227 -0
  86. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.mjs +224 -0
  87. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/command.mjs +52 -0
  88. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/error.mjs +54 -0
  89. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/kill.mjs +62 -0
  90. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/pipe.mjs +26 -0
  91. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/promise.mjs +32 -0
  92. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/stdio.mjs +19 -0
  93. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/stream.mjs +98 -0
  94. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/verbose.mjs +15 -0
  95. package/dist/node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.d.mts +15 -0
  96. package/dist/node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs +220 -0
  97. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/array-buffer.mjs +54 -0
  98. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/array.mjs +2 -0
  99. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/buffer.mjs +14 -0
  100. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/contents.mjs +76 -0
  101. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/index.mjs +6 -0
  102. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/string.mjs +35 -0
  103. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/utils.mjs +10 -0
  104. package/dist/node_modules/.pnpm/http-shutdown@1.2.2/node_modules/http-shutdown/index.mjs +76 -0
  105. package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/core.mjs +274 -0
  106. package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/main.mjs +44 -0
  107. package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/realtime.mjs +15 -0
  108. package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/signals.mjs +23 -0
  109. package/dist/node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.mjs +24 -0
  110. package/dist/node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.mjs +18 -0
  111. package/dist/node_modules/.pnpm/is-stream@3.0.0/node_modules/is-stream/index.mjs +9 -0
  112. package/dist/node_modules/.pnpm/is-wsl@3.1.1/node_modules/is-wsl/index.mjs +20 -0
  113. package/dist/node_modules/.pnpm/is64bit@2.0.0/node_modules/is64bit/index.mjs +13 -0
  114. package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.mjs +47 -0
  115. package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.mjs +33 -0
  116. package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.mjs +33 -0
  117. package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/chunks/xdg-open.mjs +1070 -0
  118. package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/index.mjs +619 -0
  119. package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/shared/listhen.1c46e31d.d.mts +83 -0
  120. package/dist/node_modules/.pnpm/merge-stream@2.0.0/node_modules/merge-stream/index.mjs +38 -0
  121. package/dist/node_modules/.pnpm/mimic-fn@4.0.0/node_modules/mimic-fn/index.mjs +38 -0
  122. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/aes.mjs +597 -0
  123. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/aesCipherSuites.mjs +195 -0
  124. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/asn1-validator.mjs +76 -0
  125. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/asn1.mjs +967 -0
  126. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/baseN.mjs +137 -0
  127. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipher.mjs +186 -0
  128. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipherModes.mjs +597 -0
  129. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/des.mjs +1187 -0
  130. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/ed25519.mjs +1029 -0
  131. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/forge.mjs +15 -0
  132. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/hmac.mjs +107 -0
  133. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/index.mjs +66 -0
  134. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/jsbn.mjs +1334 -0
  135. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/kem.mjs +146 -0
  136. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/log.mjs +241 -0
  137. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md.all.mjs +24 -0
  138. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md.mjs +18 -0
  139. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md5.mjs +324 -0
  140. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/mgf.mjs +20 -0
  141. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/mgf1.mjs +44 -0
  142. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/oids.mjs +154 -0
  143. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pbe.mjs +815 -0
  144. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pbkdf2.mjs +125 -0
  145. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pem.mjs +175 -0
  146. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs1.mjs +200 -0
  147. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs12.mjs +724 -0
  148. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7.mjs +642 -0
  149. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7asn1.mjs +405 -0
  150. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pki.mjs +101 -0
  151. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prime.mjs +193 -0
  152. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prng.mjs +290 -0
  153. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pss.mjs +141 -0
  154. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/random.mjs +141 -0
  155. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/rc2.mjs +538 -0
  156. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/rsa.mjs +1309 -0
  157. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha1.mjs +230 -0
  158. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha256.mjs +267 -0
  159. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha512.mjs +413 -0
  160. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/ssh.mjs +194 -0
  161. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/tls.mjs +3655 -0
  162. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/util.mjs +2117 -0
  163. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/x509.mjs +2168 -0
  164. package/dist/node_modules/.pnpm/npm-run-path@5.3.0/node_modules/npm-run-path/index.mjs +34 -0
  165. package/dist/node_modules/.pnpm/onetime@6.0.0/node_modules/onetime/index.mjs +26 -0
  166. package/dist/node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.mjs +14 -0
  167. package/dist/node_modules/.pnpm/path-key@4.0.0/node_modules/path-key/index.mjs +8 -0
  168. package/dist/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.mjs +176 -0
  169. package/dist/node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.mjs +17 -0
  170. package/dist/node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.mjs +8 -0
  171. package/dist/node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.mjs +169 -0
  172. package/dist/node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.mjs +33 -0
  173. package/dist/node_modules/.pnpm/std-env@3.10.0/node_modules/std-env/dist/index.mjs +171 -0
  174. package/dist/node_modules/.pnpm/strip-final-newline@3.0.0/node_modules/strip-final-newline/index.mjs +10 -0
  175. package/dist/node_modules/.pnpm/system-architecture@0.1.0/node_modules/system-architecture/index.mjs +16 -0
  176. package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.node.mjs +7 -0
  177. package/dist/node_modules/.pnpm/untun@0.1.3/node_modules/untun/dist/chunks/index.mjs +154 -0
  178. package/dist/node_modules/.pnpm/untun@0.1.3/node_modules/untun/dist/index.mjs +34 -0
  179. package/dist/node_modules/.pnpm/uqr@0.1.2/node_modules/uqr/dist/index.mjs +896 -0
  180. package/dist/node_modules/.pnpm/which@2.0.2/node_modules/which/which.mjs +76 -0
  181. package/dist/oauth2/errors.mjs +27 -0
  182. package/dist/oauth2/index.d.mts +2 -2
  183. package/dist/oauth2/index.mjs +3 -3
  184. package/dist/oauth2/link-account.d.mts +27 -1
  185. package/dist/oauth2/link-account.mjs +30 -5
  186. package/dist/oauth2/state.mjs +8 -2
  187. package/dist/{package.mjs → packages/better-auth/package.mjs} +1 -1
  188. package/dist/plugins/access/access.d.mts +3 -15
  189. package/dist/plugins/access/access.mjs +11 -6
  190. package/dist/plugins/access/index.d.mts +2 -2
  191. package/dist/plugins/access/types.d.mts +11 -4
  192. package/dist/plugins/admin/access/statement.d.mts +29 -93
  193. package/dist/plugins/admin/admin.mjs +0 -4
  194. package/dist/plugins/admin/client.d.mts +6 -1
  195. package/dist/plugins/admin/client.mjs +5 -0
  196. package/dist/plugins/admin/routes.mjs +3 -2
  197. package/dist/plugins/anonymous/client.d.mts +1 -0
  198. package/dist/plugins/anonymous/error-codes.d.mts +1 -0
  199. package/dist/plugins/anonymous/error-codes.mjs +1 -0
  200. package/dist/plugins/anonymous/index.d.mts +1 -0
  201. package/dist/plugins/anonymous/index.mjs +16 -2
  202. package/dist/plugins/bearer/index.mjs +5 -12
  203. package/dist/plugins/captcha/index.mjs +14 -1
  204. package/dist/plugins/device-authorization/error-codes.mjs +1 -0
  205. package/dist/plugins/device-authorization/index.d.mts +1 -0
  206. package/dist/plugins/device-authorization/routes.mjs +34 -3
  207. package/dist/plugins/email-otp/routes.mjs +4 -4
  208. package/dist/plugins/generic-oauth/error-codes.mjs +0 -1
  209. package/dist/plugins/generic-oauth/index.d.mts +2 -4
  210. package/dist/plugins/generic-oauth/index.mjs +23 -17
  211. package/dist/plugins/generic-oauth/providers/auth0.mjs +1 -0
  212. package/dist/plugins/generic-oauth/providers/gumroad.mjs +1 -0
  213. package/dist/plugins/generic-oauth/providers/hubspot.mjs +1 -0
  214. package/dist/plugins/generic-oauth/providers/keycloak.mjs +1 -0
  215. package/dist/plugins/generic-oauth/providers/line.mjs +1 -0
  216. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +1 -0
  217. package/dist/plugins/generic-oauth/providers/okta.mjs +1 -0
  218. package/dist/plugins/generic-oauth/providers/patreon.mjs +1 -0
  219. package/dist/plugins/generic-oauth/providers/slack.mjs +1 -0
  220. package/dist/plugins/generic-oauth/types.d.mts +30 -8
  221. package/dist/plugins/index.d.mts +2 -2
  222. package/dist/plugins/jwt/utils.d.mts +1 -1
  223. package/dist/plugins/last-login-method/client.mjs +2 -2
  224. package/dist/plugins/magic-link/index.d.mts +8 -1
  225. package/dist/plugins/magic-link/index.mjs +4 -17
  226. package/dist/plugins/mcp/authorize.mjs +8 -2
  227. package/dist/plugins/mcp/index.mjs +75 -35
  228. package/dist/plugins/multi-session/index.mjs +2 -2
  229. package/dist/plugins/oauth-proxy/index.mjs +45 -32
  230. package/dist/plugins/oauth-proxy/utils.mjs +3 -10
  231. package/dist/plugins/oidc-provider/authorize.mjs +8 -2
  232. package/dist/plugins/oidc-provider/index.mjs +65 -38
  233. package/dist/plugins/one-tap/client.mjs +9 -2
  234. package/dist/plugins/one-tap/index.mjs +19 -36
  235. package/dist/plugins/open-api/generator.mjs +25 -5
  236. package/dist/plugins/organization/access/statement.d.mts +68 -201
  237. package/dist/plugins/organization/adapter.d.mts +1 -1
  238. package/dist/plugins/organization/adapter.mjs +65 -58
  239. package/dist/plugins/organization/client.d.mts +3 -1
  240. package/dist/plugins/organization/client.mjs +1 -1
  241. package/dist/plugins/organization/error-codes.d.mts +2 -0
  242. package/dist/plugins/organization/error-codes.mjs +3 -1
  243. package/dist/plugins/organization/routes/crud-access-control.d.mts +2 -2
  244. package/dist/plugins/organization/routes/crud-invites.d.mts +8 -1
  245. package/dist/plugins/organization/routes/crud-invites.mjs +8 -3
  246. package/dist/plugins/organization/routes/crud-org.d.mts +4 -4
  247. package/dist/plugins/organization/routes/crud-org.mjs +2 -2
  248. package/dist/plugins/organization/routes/crud-team.mjs +7 -2
  249. package/dist/plugins/organization/schema.d.mts +1 -1
  250. package/dist/plugins/organization/types.d.mts +15 -5
  251. package/dist/plugins/phone-number/routes.mjs +1 -1
  252. package/dist/plugins/siwe/client.d.mts +4 -0
  253. package/dist/plugins/siwe/client.mjs +5 -1
  254. package/dist/plugins/siwe/index.d.mts +13 -2
  255. package/dist/plugins/siwe/index.mjs +179 -165
  256. package/dist/plugins/two-factor/backup-codes/index.d.mts +4 -3
  257. package/dist/plugins/two-factor/client.mjs +2 -1
  258. package/dist/plugins/two-factor/index.mjs +3 -2
  259. package/dist/plugins/username/client.d.mts +1 -0
  260. package/dist/plugins/username/error-codes.d.mts +1 -0
  261. package/dist/plugins/username/error-codes.mjs +2 -1
  262. package/dist/plugins/username/index.d.mts +43 -2
  263. package/dist/plugins/username/index.mjs +73 -6
  264. package/dist/state.d.mts +2 -2
  265. package/dist/state.mjs +18 -4
  266. package/dist/test-utils/headers.mjs +2 -7
  267. package/dist/test-utils/http-test-instance.d.mts +397 -0
  268. package/dist/test-utils/http-test-instance.mjs +54 -0
  269. package/dist/test-utils/index.d.mts +2 -1
  270. package/dist/test-utils/index.mjs +2 -1
  271. package/dist/test-utils/test-instance.d.mts +4110 -224
  272. package/dist/test-utils/test-instance.mjs +11 -2
  273. package/dist/types/auth.d.mts +4 -0
  274. package/dist/utils/index.d.mts +1 -1
  275. package/dist/utils/url.d.mts +2 -1
  276. package/dist/utils/url.mjs +9 -3
  277. package/dist/version.mjs +1 -1
  278. package/package.json +14 -14
  279. package/dist/oauth2/error-codes.d.mts +0 -20
  280. package/dist/plugins/generic-oauth/client.d.mts +0 -32
  281. package/dist/plugins/generic-oauth/client.mjs +0 -19
  282. package/dist/plugins/generic-oauth/error-codes.d.mts +0 -10
@@ -0,0 +1,642 @@
1
+ import { __commonJSMin } from "../../../../../../_virtual/_rolldown/runtime.mjs";
2
+ import { require_forge } from "./forge.mjs";
3
+ import { require_util } from "./util.mjs";
4
+ import { require_aes } from "./aes.mjs";
5
+ import { require_oids } from "./oids.mjs";
6
+ import { require_asn1 } from "./asn1.mjs";
7
+ import { require_pem } from "./pem.mjs";
8
+ import { require_des } from "./des.mjs";
9
+ import { require_random } from "./random.mjs";
10
+ import { require_pkcs7asn1 } from "./pkcs7asn1.mjs";
11
+ import { require_x509 } from "./x509.mjs";
12
+ //#region ../../node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7.js
13
+ var require_pkcs7 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
14
+ /**
15
+ * Javascript implementation of PKCS#7 v1.5.
16
+ *
17
+ * @author Stefan Siegl
18
+ * @author Dave Longley
19
+ *
20
+ * Copyright (c) 2012 Stefan Siegl <stesie@brokenpipe.de>
21
+ * Copyright (c) 2012-2015 Digital Bazaar, Inc.
22
+ *
23
+ * Currently this implementation only supports ContentType of EnvelopedData,
24
+ * EncryptedData, or SignedData at the root level. The top level elements may
25
+ * contain only a ContentInfo of ContentType Data, i.e. plain data. Further
26
+ * nesting is not (yet) supported.
27
+ *
28
+ * The Forge validators for PKCS #7's ASN.1 structures are available from
29
+ * a separate file pkcs7asn1.js, since those are referenced from other
30
+ * PKCS standards like PKCS #12.
31
+ */
32
+ var forge = require_forge();
33
+ require_aes();
34
+ require_asn1();
35
+ require_des();
36
+ require_oids();
37
+ require_pem();
38
+ require_pkcs7asn1();
39
+ require_random();
40
+ require_util();
41
+ require_x509();
42
+ var asn1 = forge.asn1;
43
+ var p7 = module.exports = forge.pkcs7 = forge.pkcs7 || {};
44
+ /**
45
+ * Converts a PKCS#7 message from PEM format.
46
+ *
47
+ * @param pem the PEM-formatted PKCS#7 message.
48
+ *
49
+ * @return the PKCS#7 message.
50
+ */
51
+ p7.messageFromPem = function(pem) {
52
+ var msg = forge.pem.decode(pem)[0];
53
+ if (msg.type !== "PKCS7") {
54
+ var error = /* @__PURE__ */ new Error("Could not convert PKCS#7 message from PEM; PEM header type is not \"PKCS#7\".");
55
+ error.headerType = msg.type;
56
+ throw error;
57
+ }
58
+ if (msg.procType && msg.procType.type === "ENCRYPTED") throw new Error("Could not convert PKCS#7 message from PEM; PEM is encrypted.");
59
+ var obj = asn1.fromDer(msg.body);
60
+ return p7.messageFromAsn1(obj);
61
+ };
62
+ /**
63
+ * Converts a PKCS#7 message to PEM format.
64
+ *
65
+ * @param msg The PKCS#7 message object
66
+ * @param maxline The maximum characters per line, defaults to 64.
67
+ *
68
+ * @return The PEM-formatted PKCS#7 message.
69
+ */
70
+ p7.messageToPem = function(msg, maxline) {
71
+ var pemObj = {
72
+ type: "PKCS7",
73
+ body: asn1.toDer(msg.toAsn1()).getBytes()
74
+ };
75
+ return forge.pem.encode(pemObj, { maxline });
76
+ };
77
+ /**
78
+ * Converts a PKCS#7 message from an ASN.1 object.
79
+ *
80
+ * @param obj the ASN.1 representation of a ContentInfo.
81
+ *
82
+ * @return the PKCS#7 message.
83
+ */
84
+ p7.messageFromAsn1 = function(obj) {
85
+ var capture = {};
86
+ var errors = [];
87
+ if (!asn1.validate(obj, p7.asn1.contentInfoValidator, capture, errors)) {
88
+ var error = /* @__PURE__ */ new Error("Cannot read PKCS#7 message. ASN.1 object is not an PKCS#7 ContentInfo.");
89
+ error.errors = errors;
90
+ throw error;
91
+ }
92
+ var contentType = asn1.derToOid(capture.contentType);
93
+ var msg;
94
+ switch (contentType) {
95
+ case forge.pki.oids.envelopedData:
96
+ msg = p7.createEnvelopedData();
97
+ break;
98
+ case forge.pki.oids.encryptedData:
99
+ msg = p7.createEncryptedData();
100
+ break;
101
+ case forge.pki.oids.signedData:
102
+ msg = p7.createSignedData();
103
+ break;
104
+ default: throw new Error("Cannot read PKCS#7 message. ContentType with OID " + contentType + " is not (yet) supported.");
105
+ }
106
+ msg.fromAsn1(capture.content.value[0]);
107
+ return msg;
108
+ };
109
+ p7.createSignedData = function() {
110
+ var msg = null;
111
+ msg = {
112
+ type: forge.pki.oids.signedData,
113
+ version: 1,
114
+ certificates: [],
115
+ crls: [],
116
+ signers: [],
117
+ digestAlgorithmIdentifiers: [],
118
+ contentInfo: null,
119
+ signerInfos: [],
120
+ fromAsn1: function(obj) {
121
+ _fromAsn1(msg, obj, p7.asn1.signedDataValidator);
122
+ msg.certificates = [];
123
+ msg.crls = [];
124
+ msg.digestAlgorithmIdentifiers = [];
125
+ msg.contentInfo = null;
126
+ msg.signerInfos = [];
127
+ if (msg.rawCapture.certificates) {
128
+ var certs = msg.rawCapture.certificates.value;
129
+ for (var i = 0; i < certs.length; ++i) msg.certificates.push(forge.pki.certificateFromAsn1(certs[i]));
130
+ }
131
+ },
132
+ toAsn1: function() {
133
+ if (!msg.contentInfo) msg.sign();
134
+ var certs = [];
135
+ for (var i = 0; i < msg.certificates.length; ++i) certs.push(forge.pki.certificateToAsn1(msg.certificates[i]));
136
+ var crls = [];
137
+ var signedData = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
138
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(msg.version).getBytes()),
139
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, msg.digestAlgorithmIdentifiers),
140
+ msg.contentInfo
141
+ ])]);
142
+ if (certs.length > 0) signedData.value[0].value.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, certs));
143
+ if (crls.length > 0) signedData.value[0].value.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, crls));
144
+ signedData.value[0].value.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, msg.signerInfos));
145
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(msg.type).getBytes()), signedData]);
146
+ },
147
+ addSigner: function(signer) {
148
+ var issuer = signer.issuer;
149
+ var serialNumber = signer.serialNumber;
150
+ if (signer.certificate) {
151
+ var cert = signer.certificate;
152
+ if (typeof cert === "string") cert = forge.pki.certificateFromPem(cert);
153
+ issuer = cert.issuer.attributes;
154
+ serialNumber = cert.serialNumber;
155
+ }
156
+ var key = signer.key;
157
+ if (!key) throw new Error("Could not add PKCS#7 signer; no private key specified.");
158
+ if (typeof key === "string") key = forge.pki.privateKeyFromPem(key);
159
+ var digestAlgorithm = signer.digestAlgorithm || forge.pki.oids.sha1;
160
+ switch (digestAlgorithm) {
161
+ case forge.pki.oids.sha1:
162
+ case forge.pki.oids.sha256:
163
+ case forge.pki.oids.sha384:
164
+ case forge.pki.oids.sha512:
165
+ case forge.pki.oids.md5: break;
166
+ default: throw new Error("Could not add PKCS#7 signer; unknown message digest algorithm: " + digestAlgorithm);
167
+ }
168
+ var authenticatedAttributes = signer.authenticatedAttributes || [];
169
+ if (authenticatedAttributes.length > 0) {
170
+ var contentType = false;
171
+ var messageDigest = false;
172
+ for (var i = 0; i < authenticatedAttributes.length; ++i) {
173
+ var attr = authenticatedAttributes[i];
174
+ if (!contentType && attr.type === forge.pki.oids.contentType) {
175
+ contentType = true;
176
+ if (messageDigest) break;
177
+ continue;
178
+ }
179
+ if (!messageDigest && attr.type === forge.pki.oids.messageDigest) {
180
+ messageDigest = true;
181
+ if (contentType) break;
182
+ continue;
183
+ }
184
+ }
185
+ if (!contentType || !messageDigest) throw new Error("Invalid signer.authenticatedAttributes. If signer.authenticatedAttributes is specified, then it must contain at least two attributes, PKCS #9 content-type and PKCS #9 message-digest.");
186
+ }
187
+ msg.signers.push({
188
+ key,
189
+ version: 1,
190
+ issuer,
191
+ serialNumber,
192
+ digestAlgorithm,
193
+ signatureAlgorithm: forge.pki.oids.rsaEncryption,
194
+ signature: null,
195
+ authenticatedAttributes,
196
+ unauthenticatedAttributes: []
197
+ });
198
+ },
199
+ sign: function(options) {
200
+ options = options || {};
201
+ if (typeof msg.content !== "object" || msg.contentInfo === null) {
202
+ msg.contentInfo = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(forge.pki.oids.data).getBytes())]);
203
+ if ("content" in msg) {
204
+ var content;
205
+ if (msg.content instanceof forge.util.ByteBuffer) content = msg.content.bytes();
206
+ else if (typeof msg.content === "string") content = forge.util.encodeUtf8(msg.content);
207
+ if (options.detached) msg.detachedContent = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, content);
208
+ else msg.contentInfo.value.push(asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, content)]));
209
+ }
210
+ }
211
+ if (msg.signers.length === 0) return;
212
+ addSignerInfos(addDigestAlgorithmIds());
213
+ },
214
+ verify: function() {
215
+ throw new Error("PKCS#7 signature verification not yet implemented.");
216
+ },
217
+ addCertificate: function(cert) {
218
+ if (typeof cert === "string") cert = forge.pki.certificateFromPem(cert);
219
+ msg.certificates.push(cert);
220
+ },
221
+ addCertificateRevokationList: function(crl) {
222
+ throw new Error("PKCS#7 CRL support not yet implemented.");
223
+ }
224
+ };
225
+ return msg;
226
+ function addDigestAlgorithmIds() {
227
+ var mds = {};
228
+ for (var i = 0; i < msg.signers.length; ++i) {
229
+ var signer = msg.signers[i];
230
+ var oid = signer.digestAlgorithm;
231
+ if (!(oid in mds)) mds[oid] = forge.md[forge.pki.oids[oid]].create();
232
+ if (signer.authenticatedAttributes.length === 0) signer.md = mds[oid];
233
+ else signer.md = forge.md[forge.pki.oids[oid]].create();
234
+ }
235
+ msg.digestAlgorithmIdentifiers = [];
236
+ for (var oid in mds) msg.digestAlgorithmIdentifiers.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(oid).getBytes()), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, "")]));
237
+ return mds;
238
+ }
239
+ function addSignerInfos(mds) {
240
+ var content;
241
+ if (msg.detachedContent) content = msg.detachedContent;
242
+ else {
243
+ content = msg.contentInfo.value[1];
244
+ content = content.value[0];
245
+ }
246
+ if (!content) throw new Error("Could not sign PKCS#7 message; there is no content to sign.");
247
+ var contentType = asn1.derToOid(msg.contentInfo.value[0].value);
248
+ var bytes = asn1.toDer(content);
249
+ bytes.getByte();
250
+ asn1.getBerValueLength(bytes);
251
+ bytes = bytes.getBytes();
252
+ for (var oid in mds) mds[oid].start().update(bytes);
253
+ var signingTime = /* @__PURE__ */ new Date();
254
+ for (var i = 0; i < msg.signers.length; ++i) {
255
+ var signer = msg.signers[i];
256
+ if (signer.authenticatedAttributes.length === 0) {
257
+ if (contentType !== forge.pki.oids.data) throw new Error("Invalid signer; authenticatedAttributes must be present when the ContentInfo content type is not PKCS#7 Data.");
258
+ } else {
259
+ signer.authenticatedAttributesAsn1 = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, []);
260
+ var attrsAsn1 = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, []);
261
+ for (var ai = 0; ai < signer.authenticatedAttributes.length; ++ai) {
262
+ var attr = signer.authenticatedAttributes[ai];
263
+ if (attr.type === forge.pki.oids.messageDigest) attr.value = mds[signer.digestAlgorithm].digest();
264
+ else if (attr.type === forge.pki.oids.signingTime) {
265
+ if (!attr.value) attr.value = signingTime;
266
+ }
267
+ attrsAsn1.value.push(_attributeToAsn1(attr));
268
+ signer.authenticatedAttributesAsn1.value.push(_attributeToAsn1(attr));
269
+ }
270
+ bytes = asn1.toDer(attrsAsn1).getBytes();
271
+ signer.md.start().update(bytes);
272
+ }
273
+ signer.signature = signer.key.sign(signer.md, "RSASSA-PKCS1-V1_5");
274
+ }
275
+ msg.signerInfos = _signersToAsn1(msg.signers);
276
+ }
277
+ };
278
+ /**
279
+ * Creates an empty PKCS#7 message of type EncryptedData.
280
+ *
281
+ * @return the message.
282
+ */
283
+ p7.createEncryptedData = function() {
284
+ var msg = null;
285
+ msg = {
286
+ type: forge.pki.oids.encryptedData,
287
+ version: 0,
288
+ encryptedContent: { algorithm: forge.pki.oids["aes256-CBC"] },
289
+ fromAsn1: function(obj) {
290
+ _fromAsn1(msg, obj, p7.asn1.encryptedDataValidator);
291
+ },
292
+ decrypt: function(key) {
293
+ if (key !== void 0) msg.encryptedContent.key = key;
294
+ _decryptContent(msg);
295
+ }
296
+ };
297
+ return msg;
298
+ };
299
+ /**
300
+ * Creates an empty PKCS#7 message of type EnvelopedData.
301
+ *
302
+ * @return the message.
303
+ */
304
+ p7.createEnvelopedData = function() {
305
+ var msg = null;
306
+ msg = {
307
+ type: forge.pki.oids.envelopedData,
308
+ version: 0,
309
+ recipients: [],
310
+ encryptedContent: { algorithm: forge.pki.oids["aes256-CBC"] },
311
+ fromAsn1: function(obj) {
312
+ var capture = _fromAsn1(msg, obj, p7.asn1.envelopedDataValidator);
313
+ msg.recipients = _recipientsFromAsn1(capture.recipientInfos.value);
314
+ },
315
+ toAsn1: function() {
316
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(msg.type).getBytes()), asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
317
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(msg.version).getBytes()),
318
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, _recipientsToAsn1(msg.recipients)),
319
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, _encryptedContentToAsn1(msg.encryptedContent))
320
+ ])])]);
321
+ },
322
+ findRecipient: function(cert) {
323
+ var sAttr = cert.issuer.attributes;
324
+ for (var i = 0; i < msg.recipients.length; ++i) {
325
+ var r = msg.recipients[i];
326
+ var rAttr = r.issuer;
327
+ if (r.serialNumber !== cert.serialNumber) continue;
328
+ if (rAttr.length !== sAttr.length) continue;
329
+ var match = true;
330
+ for (var j = 0; j < sAttr.length; ++j) if (rAttr[j].type !== sAttr[j].type || rAttr[j].value !== sAttr[j].value) {
331
+ match = false;
332
+ break;
333
+ }
334
+ if (match) return r;
335
+ }
336
+ return null;
337
+ },
338
+ decrypt: function(recipient, privKey) {
339
+ if (msg.encryptedContent.key === void 0 && recipient !== void 0 && privKey !== void 0) switch (recipient.encryptedContent.algorithm) {
340
+ case forge.pki.oids.rsaEncryption:
341
+ case forge.pki.oids.desCBC:
342
+ var key = privKey.decrypt(recipient.encryptedContent.content);
343
+ msg.encryptedContent.key = forge.util.createBuffer(key);
344
+ break;
345
+ default: throw new Error("Unsupported asymmetric cipher, OID " + recipient.encryptedContent.algorithm);
346
+ }
347
+ _decryptContent(msg);
348
+ },
349
+ addRecipient: function(cert) {
350
+ msg.recipients.push({
351
+ version: 0,
352
+ issuer: cert.issuer.attributes,
353
+ serialNumber: cert.serialNumber,
354
+ encryptedContent: {
355
+ algorithm: forge.pki.oids.rsaEncryption,
356
+ key: cert.publicKey
357
+ }
358
+ });
359
+ },
360
+ encrypt: function(key, cipher) {
361
+ if (msg.encryptedContent.content === void 0) {
362
+ cipher = cipher || msg.encryptedContent.algorithm;
363
+ key = key || msg.encryptedContent.key;
364
+ var keyLen, ivLen, ciphFn;
365
+ switch (cipher) {
366
+ case forge.pki.oids["aes128-CBC"]:
367
+ keyLen = 16;
368
+ ivLen = 16;
369
+ ciphFn = forge.aes.createEncryptionCipher;
370
+ break;
371
+ case forge.pki.oids["aes192-CBC"]:
372
+ keyLen = 24;
373
+ ivLen = 16;
374
+ ciphFn = forge.aes.createEncryptionCipher;
375
+ break;
376
+ case forge.pki.oids["aes256-CBC"]:
377
+ keyLen = 32;
378
+ ivLen = 16;
379
+ ciphFn = forge.aes.createEncryptionCipher;
380
+ break;
381
+ case forge.pki.oids["des-EDE3-CBC"]:
382
+ keyLen = 24;
383
+ ivLen = 8;
384
+ ciphFn = forge.des.createEncryptionCipher;
385
+ break;
386
+ default: throw new Error("Unsupported symmetric cipher, OID " + cipher);
387
+ }
388
+ if (key === void 0) key = forge.util.createBuffer(forge.random.getBytes(keyLen));
389
+ else if (key.length() != keyLen) throw new Error("Symmetric key has wrong length; got " + key.length() + " bytes, expected " + keyLen + ".");
390
+ msg.encryptedContent.algorithm = cipher;
391
+ msg.encryptedContent.key = key;
392
+ msg.encryptedContent.parameter = forge.util.createBuffer(forge.random.getBytes(ivLen));
393
+ var ciph = ciphFn(key);
394
+ ciph.start(msg.encryptedContent.parameter.copy());
395
+ ciph.update(msg.content);
396
+ if (!ciph.finish()) throw new Error("Symmetric encryption failed.");
397
+ msg.encryptedContent.content = ciph.output;
398
+ }
399
+ for (var i = 0; i < msg.recipients.length; ++i) {
400
+ var recipient = msg.recipients[i];
401
+ if (recipient.encryptedContent.content !== void 0) continue;
402
+ switch (recipient.encryptedContent.algorithm) {
403
+ case forge.pki.oids.rsaEncryption:
404
+ recipient.encryptedContent.content = recipient.encryptedContent.key.encrypt(msg.encryptedContent.key.data);
405
+ break;
406
+ default: throw new Error("Unsupported asymmetric cipher, OID " + recipient.encryptedContent.algorithm);
407
+ }
408
+ }
409
+ }
410
+ };
411
+ return msg;
412
+ };
413
+ /**
414
+ * Converts a single recipient from an ASN.1 object.
415
+ *
416
+ * @param obj the ASN.1 RecipientInfo.
417
+ *
418
+ * @return the recipient object.
419
+ */
420
+ function _recipientFromAsn1(obj) {
421
+ var capture = {};
422
+ var errors = [];
423
+ if (!asn1.validate(obj, p7.asn1.recipientInfoValidator, capture, errors)) {
424
+ var error = /* @__PURE__ */ new Error("Cannot read PKCS#7 RecipientInfo. ASN.1 object is not an PKCS#7 RecipientInfo.");
425
+ error.errors = errors;
426
+ throw error;
427
+ }
428
+ return {
429
+ version: capture.version.charCodeAt(0),
430
+ issuer: forge.pki.RDNAttributesAsArray(capture.issuer),
431
+ serialNumber: forge.util.createBuffer(capture.serial).toHex(),
432
+ encryptedContent: {
433
+ algorithm: asn1.derToOid(capture.encAlgorithm),
434
+ parameter: capture.encParameter ? capture.encParameter.value : void 0,
435
+ content: capture.encKey
436
+ }
437
+ };
438
+ }
439
+ /**
440
+ * Converts a single recipient object to an ASN.1 object.
441
+ *
442
+ * @param obj the recipient object.
443
+ *
444
+ * @return the ASN.1 RecipientInfo.
445
+ */
446
+ function _recipientToAsn1(obj) {
447
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
448
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(obj.version).getBytes()),
449
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [forge.pki.distinguishedNameToAsn1({ attributes: obj.issuer }), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, forge.util.hexToBytes(obj.serialNumber))]),
450
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(obj.encryptedContent.algorithm).getBytes()), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, "")]),
451
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, obj.encryptedContent.content)
452
+ ]);
453
+ }
454
+ /**
455
+ * Map a set of RecipientInfo ASN.1 objects to recipient objects.
456
+ *
457
+ * @param infos an array of ASN.1 representations RecipientInfo (i.e. SET OF).
458
+ *
459
+ * @return an array of recipient objects.
460
+ */
461
+ function _recipientsFromAsn1(infos) {
462
+ var ret = [];
463
+ for (var i = 0; i < infos.length; ++i) ret.push(_recipientFromAsn1(infos[i]));
464
+ return ret;
465
+ }
466
+ /**
467
+ * Map an array of recipient objects to ASN.1 RecipientInfo objects.
468
+ *
469
+ * @param recipients an array of recipientInfo objects.
470
+ *
471
+ * @return an array of ASN.1 RecipientInfos.
472
+ */
473
+ function _recipientsToAsn1(recipients) {
474
+ var ret = [];
475
+ for (var i = 0; i < recipients.length; ++i) ret.push(_recipientToAsn1(recipients[i]));
476
+ return ret;
477
+ }
478
+ /**
479
+ * Converts a single signerInfo object to an ASN.1 object.
480
+ *
481
+ * @param obj the signerInfo object.
482
+ *
483
+ * @return the ASN.1 representation of a SignerInfo.
484
+ */
485
+ function _signerToAsn1(obj) {
486
+ var rval = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
487
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, asn1.integerToDer(obj.version).getBytes()),
488
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [forge.pki.distinguishedNameToAsn1({ attributes: obj.issuer }), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false, forge.util.hexToBytes(obj.serialNumber))]),
489
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(obj.digestAlgorithm).getBytes()), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, "")])
490
+ ]);
491
+ if (obj.authenticatedAttributesAsn1) rval.value.push(obj.authenticatedAttributesAsn1);
492
+ rval.value.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(obj.signatureAlgorithm).getBytes()), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, "")]));
493
+ rval.value.push(asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, obj.signature));
494
+ if (obj.unauthenticatedAttributes.length > 0) {
495
+ var attrsAsn1 = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, []);
496
+ for (var i = 0; i < obj.unauthenticatedAttributes.length; ++i) {
497
+ var attr = obj.unauthenticatedAttributes[i];
498
+ attrsAsn1.values.push(_attributeToAsn1(attr));
499
+ }
500
+ rval.value.push(attrsAsn1);
501
+ }
502
+ return rval;
503
+ }
504
+ /**
505
+ * Map an array of signer objects to ASN.1 objects.
506
+ *
507
+ * @param signers an array of signer objects.
508
+ *
509
+ * @return an array of ASN.1 SignerInfos.
510
+ */
511
+ function _signersToAsn1(signers) {
512
+ var ret = [];
513
+ for (var i = 0; i < signers.length; ++i) ret.push(_signerToAsn1(signers[i]));
514
+ return ret;
515
+ }
516
+ /**
517
+ * Convert an attribute object to an ASN.1 Attribute.
518
+ *
519
+ * @param attr the attribute object.
520
+ *
521
+ * @return the ASN.1 Attribute.
522
+ */
523
+ function _attributeToAsn1(attr) {
524
+ var value;
525
+ if (attr.type === forge.pki.oids.contentType) value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(attr.value).getBytes());
526
+ else if (attr.type === forge.pki.oids.messageDigest) value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, attr.value.bytes());
527
+ else if (attr.type === forge.pki.oids.signingTime) {
528
+ var jan_1_1950 = /* @__PURE__ */ new Date("1950-01-01T00:00:00Z");
529
+ var jan_1_2050 = /* @__PURE__ */ new Date("2050-01-01T00:00:00Z");
530
+ var date = attr.value;
531
+ if (typeof date === "string") {
532
+ var timestamp = Date.parse(date);
533
+ if (!isNaN(timestamp)) date = new Date(timestamp);
534
+ else if (date.length === 13) date = asn1.utcTimeToDate(date);
535
+ else date = asn1.generalizedTimeToDate(date);
536
+ }
537
+ if (date >= jan_1_1950 && date < jan_1_2050) value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.UTCTIME, false, asn1.dateToUtcTime(date));
538
+ else value = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.GENERALIZEDTIME, false, asn1.dateToGeneralizedTime(date));
539
+ }
540
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(attr.type).getBytes()), asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [value])]);
541
+ }
542
+ /**
543
+ * Map messages encrypted content to ASN.1 objects.
544
+ *
545
+ * @param ec The encryptedContent object of the message.
546
+ *
547
+ * @return ASN.1 representation of the encryptedContent object (SEQUENCE).
548
+ */
549
+ function _encryptedContentToAsn1(ec) {
550
+ return [
551
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(forge.pki.oids.data).getBytes()),
552
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false, asn1.oidToDer(ec.algorithm).getBytes()), !ec.parameter ? void 0 : asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, ec.parameter.getBytes())]),
553
+ asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, ec.content.getBytes())])
554
+ ];
555
+ }
556
+ /**
557
+ * Reads the "common part" of an PKCS#7 content block (in ASN.1 format)
558
+ *
559
+ * This function reads the "common part" of the PKCS#7 content blocks
560
+ * EncryptedData and EnvelopedData, i.e. version number and symmetrically
561
+ * encrypted content block.
562
+ *
563
+ * The result of the ASN.1 validate and capture process is returned
564
+ * to allow the caller to extract further data, e.g. the list of recipients
565
+ * in case of a EnvelopedData object.
566
+ *
567
+ * @param msg the PKCS#7 object to read the data to.
568
+ * @param obj the ASN.1 representation of the content block.
569
+ * @param validator the ASN.1 structure validator object to use.
570
+ *
571
+ * @return the value map captured by validator object.
572
+ */
573
+ function _fromAsn1(msg, obj, validator) {
574
+ var capture = {};
575
+ if (!asn1.validate(obj, validator, capture, [])) {
576
+ var error = /* @__PURE__ */ new Error("Cannot read PKCS#7 message. ASN.1 object is not a supported PKCS#7 message.");
577
+ error.errors = error;
578
+ throw error;
579
+ }
580
+ if (asn1.derToOid(capture.contentType) !== forge.pki.oids.data) throw new Error("Unsupported PKCS#7 message. Only wrapped ContentType Data supported.");
581
+ if (capture.encryptedContent) {
582
+ var content = "";
583
+ if (forge.util.isArray(capture.encryptedContent)) for (var i = 0; i < capture.encryptedContent.length; ++i) {
584
+ if (capture.encryptedContent[i].type !== asn1.Type.OCTETSTRING) throw new Error("Malformed PKCS#7 message, expecting encrypted content constructed of only OCTET STRING objects.");
585
+ content += capture.encryptedContent[i].value;
586
+ }
587
+ else content = capture.encryptedContent;
588
+ msg.encryptedContent = {
589
+ algorithm: asn1.derToOid(capture.encAlgorithm),
590
+ parameter: forge.util.createBuffer(capture.encParameter.value),
591
+ content: forge.util.createBuffer(content)
592
+ };
593
+ }
594
+ if (capture.content) {
595
+ var content = "";
596
+ if (forge.util.isArray(capture.content)) for (var i = 0; i < capture.content.length; ++i) {
597
+ if (capture.content[i].type !== asn1.Type.OCTETSTRING) throw new Error("Malformed PKCS#7 message, expecting content constructed of only OCTET STRING objects.");
598
+ content += capture.content[i].value;
599
+ }
600
+ else content = capture.content;
601
+ msg.content = forge.util.createBuffer(content);
602
+ }
603
+ msg.version = capture.version.charCodeAt(0);
604
+ msg.rawCapture = capture;
605
+ return capture;
606
+ }
607
+ /**
608
+ * Decrypt the symmetrically encrypted content block of the PKCS#7 message.
609
+ *
610
+ * Decryption is skipped in case the PKCS#7 message object already has a
611
+ * (decrypted) content attribute. The algorithm, key and cipher parameters
612
+ * (probably the iv) are taken from the encryptedContent attribute of the
613
+ * message object.
614
+ *
615
+ * @param The PKCS#7 message object.
616
+ */
617
+ function _decryptContent(msg) {
618
+ if (msg.encryptedContent.key === void 0) throw new Error("Symmetric key not available.");
619
+ if (msg.content === void 0) {
620
+ var ciph;
621
+ switch (msg.encryptedContent.algorithm) {
622
+ case forge.pki.oids["aes128-CBC"]:
623
+ case forge.pki.oids["aes192-CBC"]:
624
+ case forge.pki.oids["aes256-CBC"]:
625
+ ciph = forge.aes.createDecryptionCipher(msg.encryptedContent.key);
626
+ break;
627
+ case forge.pki.oids["desCBC"]:
628
+ case forge.pki.oids["des-EDE3-CBC"]:
629
+ ciph = forge.des.createDecryptionCipher(msg.encryptedContent.key);
630
+ break;
631
+ default: throw new Error("Unsupported symmetric cipher, OID " + msg.encryptedContent.algorithm);
632
+ }
633
+ ciph.start(msg.encryptedContent.parameter);
634
+ ciph.update(msg.encryptedContent.content);
635
+ if (!ciph.finish()) throw new Error("Symmetric decryption failed.");
636
+ msg.content = ciph.output;
637
+ }
638
+ }
639
+ }));
640
+ //#endregion
641
+ export default require_pkcs7();
642
+ export { require_pkcs7 };