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,405 @@
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_asn1 } from "./asn1.mjs";
5
+ //#region ../../node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7asn1.js
6
+ var require_pkcs7asn1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
7
+ /**
8
+ * Javascript implementation of ASN.1 validators for PKCS#7 v1.5.
9
+ *
10
+ * @author Dave Longley
11
+ * @author Stefan Siegl
12
+ *
13
+ * Copyright (c) 2012-2015 Digital Bazaar, Inc.
14
+ * Copyright (c) 2012 Stefan Siegl <stesie@brokenpipe.de>
15
+ *
16
+ * The ASN.1 representation of PKCS#7 is as follows
17
+ * (see RFC #2315 for details, http://www.ietf.org/rfc/rfc2315.txt):
18
+ *
19
+ * A PKCS#7 message consists of a ContentInfo on root level, which may
20
+ * contain any number of further ContentInfo nested into it.
21
+ *
22
+ * ContentInfo ::= SEQUENCE {
23
+ * contentType ContentType,
24
+ * content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL
25
+ * }
26
+ *
27
+ * ContentType ::= OBJECT IDENTIFIER
28
+ *
29
+ * EnvelopedData ::= SEQUENCE {
30
+ * version Version,
31
+ * recipientInfos RecipientInfos,
32
+ * encryptedContentInfo EncryptedContentInfo
33
+ * }
34
+ *
35
+ * EncryptedData ::= SEQUENCE {
36
+ * version Version,
37
+ * encryptedContentInfo EncryptedContentInfo
38
+ * }
39
+ *
40
+ * id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
41
+ * us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
42
+ *
43
+ * SignedData ::= SEQUENCE {
44
+ * version INTEGER,
45
+ * digestAlgorithms DigestAlgorithmIdentifiers,
46
+ * contentInfo ContentInfo,
47
+ * certificates [0] IMPLICIT Certificates OPTIONAL,
48
+ * crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,
49
+ * signerInfos SignerInfos
50
+ * }
51
+ *
52
+ * SignerInfos ::= SET OF SignerInfo
53
+ *
54
+ * SignerInfo ::= SEQUENCE {
55
+ * version Version,
56
+ * issuerAndSerialNumber IssuerAndSerialNumber,
57
+ * digestAlgorithm DigestAlgorithmIdentifier,
58
+ * authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL,
59
+ * digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
60
+ * encryptedDigest EncryptedDigest,
61
+ * unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
62
+ * }
63
+ *
64
+ * EncryptedDigest ::= OCTET STRING
65
+ *
66
+ * Attributes ::= SET OF Attribute
67
+ *
68
+ * Attribute ::= SEQUENCE {
69
+ * attrType OBJECT IDENTIFIER,
70
+ * attrValues SET OF AttributeValue
71
+ * }
72
+ *
73
+ * AttributeValue ::= ANY
74
+ *
75
+ * Version ::= INTEGER
76
+ *
77
+ * RecipientInfos ::= SET OF RecipientInfo
78
+ *
79
+ * EncryptedContentInfo ::= SEQUENCE {
80
+ * contentType ContentType,
81
+ * contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
82
+ * encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL
83
+ * }
84
+ *
85
+ * ContentEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
86
+ *
87
+ * The AlgorithmIdentifier contains an Object Identifier (OID) and parameters
88
+ * for the algorithm, if any. In the case of AES and DES3, there is only one,
89
+ * the IV.
90
+ *
91
+ * AlgorithmIdentifer ::= SEQUENCE {
92
+ * algorithm OBJECT IDENTIFIER,
93
+ * parameters ANY DEFINED BY algorithm OPTIONAL
94
+ * }
95
+ *
96
+ * EncryptedContent ::= OCTET STRING
97
+ *
98
+ * RecipientInfo ::= SEQUENCE {
99
+ * version Version,
100
+ * issuerAndSerialNumber IssuerAndSerialNumber,
101
+ * keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
102
+ * encryptedKey EncryptedKey
103
+ * }
104
+ *
105
+ * IssuerAndSerialNumber ::= SEQUENCE {
106
+ * issuer Name,
107
+ * serialNumber CertificateSerialNumber
108
+ * }
109
+ *
110
+ * CertificateSerialNumber ::= INTEGER
111
+ *
112
+ * KeyEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
113
+ *
114
+ * EncryptedKey ::= OCTET STRING
115
+ */
116
+ var forge = require_forge();
117
+ require_asn1();
118
+ require_util();
119
+ var asn1 = forge.asn1;
120
+ var p7v = module.exports = forge.pkcs7asn1 = forge.pkcs7asn1 || {};
121
+ forge.pkcs7 = forge.pkcs7 || {};
122
+ forge.pkcs7.asn1 = p7v;
123
+ var contentInfoValidator = {
124
+ name: "ContentInfo",
125
+ tagClass: asn1.Class.UNIVERSAL,
126
+ type: asn1.Type.SEQUENCE,
127
+ constructed: true,
128
+ value: [{
129
+ name: "ContentInfo.ContentType",
130
+ tagClass: asn1.Class.UNIVERSAL,
131
+ type: asn1.Type.OID,
132
+ constructed: false,
133
+ capture: "contentType"
134
+ }, {
135
+ name: "ContentInfo.content",
136
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
137
+ type: 0,
138
+ constructed: true,
139
+ optional: true,
140
+ captureAsn1: "content"
141
+ }]
142
+ };
143
+ p7v.contentInfoValidator = contentInfoValidator;
144
+ var encryptedContentInfoValidator = {
145
+ name: "EncryptedContentInfo",
146
+ tagClass: asn1.Class.UNIVERSAL,
147
+ type: asn1.Type.SEQUENCE,
148
+ constructed: true,
149
+ value: [
150
+ {
151
+ name: "EncryptedContentInfo.contentType",
152
+ tagClass: asn1.Class.UNIVERSAL,
153
+ type: asn1.Type.OID,
154
+ constructed: false,
155
+ capture: "contentType"
156
+ },
157
+ {
158
+ name: "EncryptedContentInfo.contentEncryptionAlgorithm",
159
+ tagClass: asn1.Class.UNIVERSAL,
160
+ type: asn1.Type.SEQUENCE,
161
+ constructed: true,
162
+ value: [{
163
+ name: "EncryptedContentInfo.contentEncryptionAlgorithm.algorithm",
164
+ tagClass: asn1.Class.UNIVERSAL,
165
+ type: asn1.Type.OID,
166
+ constructed: false,
167
+ capture: "encAlgorithm"
168
+ }, {
169
+ name: "EncryptedContentInfo.contentEncryptionAlgorithm.parameter",
170
+ tagClass: asn1.Class.UNIVERSAL,
171
+ captureAsn1: "encParameter"
172
+ }]
173
+ },
174
+ {
175
+ name: "EncryptedContentInfo.encryptedContent",
176
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
177
+ type: 0,
178
+ capture: "encryptedContent",
179
+ captureAsn1: "encryptedContentAsn1"
180
+ }
181
+ ]
182
+ };
183
+ p7v.envelopedDataValidator = {
184
+ name: "EnvelopedData",
185
+ tagClass: asn1.Class.UNIVERSAL,
186
+ type: asn1.Type.SEQUENCE,
187
+ constructed: true,
188
+ value: [{
189
+ name: "EnvelopedData.Version",
190
+ tagClass: asn1.Class.UNIVERSAL,
191
+ type: asn1.Type.INTEGER,
192
+ constructed: false,
193
+ capture: "version"
194
+ }, {
195
+ name: "EnvelopedData.RecipientInfos",
196
+ tagClass: asn1.Class.UNIVERSAL,
197
+ type: asn1.Type.SET,
198
+ constructed: true,
199
+ captureAsn1: "recipientInfos"
200
+ }].concat(encryptedContentInfoValidator)
201
+ };
202
+ p7v.encryptedDataValidator = {
203
+ name: "EncryptedData",
204
+ tagClass: asn1.Class.UNIVERSAL,
205
+ type: asn1.Type.SEQUENCE,
206
+ constructed: true,
207
+ value: [{
208
+ name: "EncryptedData.Version",
209
+ tagClass: asn1.Class.UNIVERSAL,
210
+ type: asn1.Type.INTEGER,
211
+ constructed: false,
212
+ capture: "version"
213
+ }].concat(encryptedContentInfoValidator)
214
+ };
215
+ var signerValidator = {
216
+ name: "SignerInfo",
217
+ tagClass: asn1.Class.UNIVERSAL,
218
+ type: asn1.Type.SEQUENCE,
219
+ constructed: true,
220
+ value: [
221
+ {
222
+ name: "SignerInfo.version",
223
+ tagClass: asn1.Class.UNIVERSAL,
224
+ type: asn1.Type.INTEGER,
225
+ constructed: false
226
+ },
227
+ {
228
+ name: "SignerInfo.issuerAndSerialNumber",
229
+ tagClass: asn1.Class.UNIVERSAL,
230
+ type: asn1.Type.SEQUENCE,
231
+ constructed: true,
232
+ value: [{
233
+ name: "SignerInfo.issuerAndSerialNumber.issuer",
234
+ tagClass: asn1.Class.UNIVERSAL,
235
+ type: asn1.Type.SEQUENCE,
236
+ constructed: true,
237
+ captureAsn1: "issuer"
238
+ }, {
239
+ name: "SignerInfo.issuerAndSerialNumber.serialNumber",
240
+ tagClass: asn1.Class.UNIVERSAL,
241
+ type: asn1.Type.INTEGER,
242
+ constructed: false,
243
+ capture: "serial"
244
+ }]
245
+ },
246
+ {
247
+ name: "SignerInfo.digestAlgorithm",
248
+ tagClass: asn1.Class.UNIVERSAL,
249
+ type: asn1.Type.SEQUENCE,
250
+ constructed: true,
251
+ value: [{
252
+ name: "SignerInfo.digestAlgorithm.algorithm",
253
+ tagClass: asn1.Class.UNIVERSAL,
254
+ type: asn1.Type.OID,
255
+ constructed: false,
256
+ capture: "digestAlgorithm"
257
+ }, {
258
+ name: "SignerInfo.digestAlgorithm.parameter",
259
+ tagClass: asn1.Class.UNIVERSAL,
260
+ constructed: false,
261
+ captureAsn1: "digestParameter",
262
+ optional: true
263
+ }]
264
+ },
265
+ {
266
+ name: "SignerInfo.authenticatedAttributes",
267
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
268
+ type: 0,
269
+ constructed: true,
270
+ optional: true,
271
+ capture: "authenticatedAttributes"
272
+ },
273
+ {
274
+ name: "SignerInfo.digestEncryptionAlgorithm",
275
+ tagClass: asn1.Class.UNIVERSAL,
276
+ type: asn1.Type.SEQUENCE,
277
+ constructed: true,
278
+ capture: "signatureAlgorithm"
279
+ },
280
+ {
281
+ name: "SignerInfo.encryptedDigest",
282
+ tagClass: asn1.Class.UNIVERSAL,
283
+ type: asn1.Type.OCTETSTRING,
284
+ constructed: false,
285
+ capture: "signature"
286
+ },
287
+ {
288
+ name: "SignerInfo.unauthenticatedAttributes",
289
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
290
+ type: 1,
291
+ constructed: true,
292
+ optional: true,
293
+ capture: "unauthenticatedAttributes"
294
+ }
295
+ ]
296
+ };
297
+ p7v.signedDataValidator = {
298
+ name: "SignedData",
299
+ tagClass: asn1.Class.UNIVERSAL,
300
+ type: asn1.Type.SEQUENCE,
301
+ constructed: true,
302
+ value: [
303
+ {
304
+ name: "SignedData.Version",
305
+ tagClass: asn1.Class.UNIVERSAL,
306
+ type: asn1.Type.INTEGER,
307
+ constructed: false,
308
+ capture: "version"
309
+ },
310
+ {
311
+ name: "SignedData.DigestAlgorithms",
312
+ tagClass: asn1.Class.UNIVERSAL,
313
+ type: asn1.Type.SET,
314
+ constructed: true,
315
+ captureAsn1: "digestAlgorithms"
316
+ },
317
+ contentInfoValidator,
318
+ {
319
+ name: "SignedData.Certificates",
320
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
321
+ type: 0,
322
+ optional: true,
323
+ captureAsn1: "certificates"
324
+ },
325
+ {
326
+ name: "SignedData.CertificateRevocationLists",
327
+ tagClass: asn1.Class.CONTEXT_SPECIFIC,
328
+ type: 1,
329
+ optional: true,
330
+ captureAsn1: "crls"
331
+ },
332
+ {
333
+ name: "SignedData.SignerInfos",
334
+ tagClass: asn1.Class.UNIVERSAL,
335
+ type: asn1.Type.SET,
336
+ capture: "signerInfos",
337
+ optional: true,
338
+ value: [signerValidator]
339
+ }
340
+ ]
341
+ };
342
+ p7v.recipientInfoValidator = {
343
+ name: "RecipientInfo",
344
+ tagClass: asn1.Class.UNIVERSAL,
345
+ type: asn1.Type.SEQUENCE,
346
+ constructed: true,
347
+ value: [
348
+ {
349
+ name: "RecipientInfo.version",
350
+ tagClass: asn1.Class.UNIVERSAL,
351
+ type: asn1.Type.INTEGER,
352
+ constructed: false,
353
+ capture: "version"
354
+ },
355
+ {
356
+ name: "RecipientInfo.issuerAndSerial",
357
+ tagClass: asn1.Class.UNIVERSAL,
358
+ type: asn1.Type.SEQUENCE,
359
+ constructed: true,
360
+ value: [{
361
+ name: "RecipientInfo.issuerAndSerial.issuer",
362
+ tagClass: asn1.Class.UNIVERSAL,
363
+ type: asn1.Type.SEQUENCE,
364
+ constructed: true,
365
+ captureAsn1: "issuer"
366
+ }, {
367
+ name: "RecipientInfo.issuerAndSerial.serialNumber",
368
+ tagClass: asn1.Class.UNIVERSAL,
369
+ type: asn1.Type.INTEGER,
370
+ constructed: false,
371
+ capture: "serial"
372
+ }]
373
+ },
374
+ {
375
+ name: "RecipientInfo.keyEncryptionAlgorithm",
376
+ tagClass: asn1.Class.UNIVERSAL,
377
+ type: asn1.Type.SEQUENCE,
378
+ constructed: true,
379
+ value: [{
380
+ name: "RecipientInfo.keyEncryptionAlgorithm.algorithm",
381
+ tagClass: asn1.Class.UNIVERSAL,
382
+ type: asn1.Type.OID,
383
+ constructed: false,
384
+ capture: "encAlgorithm"
385
+ }, {
386
+ name: "RecipientInfo.keyEncryptionAlgorithm.parameter",
387
+ tagClass: asn1.Class.UNIVERSAL,
388
+ constructed: false,
389
+ captureAsn1: "encParameter",
390
+ optional: true
391
+ }]
392
+ },
393
+ {
394
+ name: "RecipientInfo.encryptedKey",
395
+ tagClass: asn1.Class.UNIVERSAL,
396
+ type: asn1.Type.OCTETSTRING,
397
+ constructed: false,
398
+ capture: "encKey"
399
+ }
400
+ ]
401
+ };
402
+ }));
403
+ //#endregion
404
+ export default require_pkcs7asn1();
405
+ export { require_pkcs7asn1 };
@@ -0,0 +1,101 @@
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_oids } from "./oids.mjs";
5
+ import { require_asn1 } from "./asn1.mjs";
6
+ import { require_pem } from "./pem.mjs";
7
+ import { require_pbkdf2 } from "./pbkdf2.mjs";
8
+ import { require_rsa } from "./rsa.mjs";
9
+ import { require_pbe } from "./pbe.mjs";
10
+ import { require_pss } from "./pss.mjs";
11
+ import { require_x509 } from "./x509.mjs";
12
+ import { require_pkcs12 } from "./pkcs12.mjs";
13
+ //#region ../../node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pki.js
14
+ var require_pki = /* @__PURE__ */ __commonJSMin(((exports, module) => {
15
+ /**
16
+ * Javascript implementation of a basic Public Key Infrastructure, including
17
+ * support for RSA public and private keys.
18
+ *
19
+ * @author Dave Longley
20
+ *
21
+ * Copyright (c) 2010-2013 Digital Bazaar, Inc.
22
+ */
23
+ var forge = require_forge();
24
+ require_asn1();
25
+ require_oids();
26
+ require_pbe();
27
+ require_pem();
28
+ require_pbkdf2();
29
+ require_pkcs12();
30
+ require_pss();
31
+ require_rsa();
32
+ require_util();
33
+ require_x509();
34
+ var asn1 = forge.asn1;
35
+ var pki = module.exports = forge.pki = forge.pki || {};
36
+ /**
37
+ * NOTE: THIS METHOD IS DEPRECATED. Use pem.decode() instead.
38
+ *
39
+ * Converts PEM-formatted data to DER.
40
+ *
41
+ * @param pem the PEM-formatted data.
42
+ *
43
+ * @return the DER-formatted data.
44
+ */
45
+ pki.pemToDer = function(pem) {
46
+ var msg = forge.pem.decode(pem)[0];
47
+ if (msg.procType && msg.procType.type === "ENCRYPTED") throw new Error("Could not convert PEM to DER; PEM is encrypted.");
48
+ return forge.util.createBuffer(msg.body);
49
+ };
50
+ /**
51
+ * Converts an RSA private key from PEM format.
52
+ *
53
+ * @param pem the PEM-formatted private key.
54
+ *
55
+ * @return the private key.
56
+ */
57
+ pki.privateKeyFromPem = function(pem) {
58
+ var msg = forge.pem.decode(pem)[0];
59
+ if (msg.type !== "PRIVATE KEY" && msg.type !== "RSA PRIVATE KEY") {
60
+ var error = /* @__PURE__ */ new Error("Could not convert private key from PEM; PEM header type is not \"PRIVATE KEY\" or \"RSA PRIVATE KEY\".");
61
+ error.headerType = msg.type;
62
+ throw error;
63
+ }
64
+ if (msg.procType && msg.procType.type === "ENCRYPTED") throw new Error("Could not convert private key from PEM; PEM is encrypted.");
65
+ var obj = asn1.fromDer(msg.body);
66
+ return pki.privateKeyFromAsn1(obj);
67
+ };
68
+ /**
69
+ * Converts an RSA private key to PEM format.
70
+ *
71
+ * @param key the private key.
72
+ * @param maxline the maximum characters per line, defaults to 64.
73
+ *
74
+ * @return the PEM-formatted private key.
75
+ */
76
+ pki.privateKeyToPem = function(key, maxline) {
77
+ var msg = {
78
+ type: "RSA PRIVATE KEY",
79
+ body: asn1.toDer(pki.privateKeyToAsn1(key)).getBytes()
80
+ };
81
+ return forge.pem.encode(msg, { maxline });
82
+ };
83
+ /**
84
+ * Converts a PrivateKeyInfo to PEM format.
85
+ *
86
+ * @param pki the PrivateKeyInfo.
87
+ * @param maxline the maximum characters per line, defaults to 64.
88
+ *
89
+ * @return the PEM-formatted private key.
90
+ */
91
+ pki.privateKeyInfoToPem = function(pki, maxline) {
92
+ var msg = {
93
+ type: "PRIVATE KEY",
94
+ body: asn1.toDer(pki).getBytes()
95
+ };
96
+ return forge.pem.encode(msg, { maxline });
97
+ };
98
+ }));
99
+ //#endregion
100
+ export default require_pki();
101
+ export { require_pki };
@@ -0,0 +1,193 @@
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_random } from "./random.mjs";
5
+ import { require_jsbn } from "./jsbn.mjs";
6
+ //#region ../../node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prime.js
7
+ var require_prime = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8
+ /**
9
+ * Prime number generation API.
10
+ *
11
+ * @author Dave Longley
12
+ *
13
+ * Copyright (c) 2014 Digital Bazaar, Inc.
14
+ */
15
+ var forge = require_forge();
16
+ require_util();
17
+ require_jsbn();
18
+ require_random();
19
+ (function() {
20
+ if (forge.prime) {
21
+ module.exports = forge.prime;
22
+ return;
23
+ }
24
+ var prime = module.exports = forge.prime = forge.prime || {};
25
+ var BigInteger = forge.jsbn.BigInteger;
26
+ var GCD_30_DELTA = [
27
+ 6,
28
+ 4,
29
+ 2,
30
+ 4,
31
+ 2,
32
+ 4,
33
+ 6,
34
+ 2
35
+ ];
36
+ var THIRTY = new BigInteger(null);
37
+ THIRTY.fromInt(30);
38
+ var op_or = function(x, y) {
39
+ return x | y;
40
+ };
41
+ /**
42
+ * Generates a random probable prime with the given number of bits.
43
+ *
44
+ * Alternative algorithms can be specified by name as a string or as an
45
+ * object with custom options like so:
46
+ *
47
+ * {
48
+ * name: 'PRIMEINC',
49
+ * options: {
50
+ * maxBlockTime: <the maximum amount of time to block the main
51
+ * thread before allowing I/O other JS to run>,
52
+ * millerRabinTests: <the number of miller-rabin tests to run>,
53
+ * workerScript: <the worker script URL>,
54
+ * workers: <the number of web workers (if supported) to use,
55
+ * -1 to use estimated cores minus one>.
56
+ * workLoad: the size of the work load, ie: number of possible prime
57
+ * numbers for each web worker to check per work assignment,
58
+ * (default: 100).
59
+ * }
60
+ * }
61
+ *
62
+ * @param bits the number of bits for the prime number.
63
+ * @param options the options to use.
64
+ * [algorithm] the algorithm to use (default: 'PRIMEINC').
65
+ * [prng] a custom crypto-secure pseudo-random number generator to use,
66
+ * that must define "getBytesSync".
67
+ *
68
+ * @return callback(err, num) called once the operation completes.
69
+ */
70
+ prime.generateProbablePrime = function(bits, options, callback) {
71
+ if (typeof options === "function") {
72
+ callback = options;
73
+ options = {};
74
+ }
75
+ options = options || {};
76
+ var algorithm = options.algorithm || "PRIMEINC";
77
+ if (typeof algorithm === "string") algorithm = { name: algorithm };
78
+ algorithm.options = algorithm.options || {};
79
+ var prng = options.prng || forge.random;
80
+ var rng = { nextBytes: function(x) {
81
+ var b = prng.getBytesSync(x.length);
82
+ for (var i = 0; i < x.length; ++i) x[i] = b.charCodeAt(i);
83
+ } };
84
+ if (algorithm.name === "PRIMEINC") return primeincFindPrime(bits, rng, algorithm.options, callback);
85
+ throw new Error("Invalid prime generation algorithm: " + algorithm.name);
86
+ };
87
+ function primeincFindPrime(bits, rng, options, callback) {
88
+ if ("workers" in options) return primeincFindPrimeWithWorkers(bits, rng, options, callback);
89
+ return primeincFindPrimeWithoutWorkers(bits, rng, options, callback);
90
+ }
91
+ function primeincFindPrimeWithoutWorkers(bits, rng, options, callback) {
92
+ var num = generateRandom(bits, rng);
93
+ var deltaIdx = 0;
94
+ var mrTests = getMillerRabinTests(num.bitLength());
95
+ if ("millerRabinTests" in options) mrTests = options.millerRabinTests;
96
+ var maxBlockTime = 10;
97
+ if ("maxBlockTime" in options) maxBlockTime = options.maxBlockTime;
98
+ _primeinc(num, bits, rng, deltaIdx, mrTests, maxBlockTime, callback);
99
+ }
100
+ function _primeinc(num, bits, rng, deltaIdx, mrTests, maxBlockTime, callback) {
101
+ var start = +/* @__PURE__ */ new Date();
102
+ do {
103
+ if (num.bitLength() > bits) num = generateRandom(bits, rng);
104
+ if (num.isProbablePrime(mrTests)) return callback(null, num);
105
+ num.dAddOffset(GCD_30_DELTA[deltaIdx++ % 8], 0);
106
+ } while (maxBlockTime < 0 || +/* @__PURE__ */ new Date() - start < maxBlockTime);
107
+ forge.util.setImmediate(function() {
108
+ _primeinc(num, bits, rng, deltaIdx, mrTests, maxBlockTime, callback);
109
+ });
110
+ }
111
+ function primeincFindPrimeWithWorkers(bits, rng, options, callback) {
112
+ if (typeof Worker === "undefined") return primeincFindPrimeWithoutWorkers(bits, rng, options, callback);
113
+ var num = generateRandom(bits, rng);
114
+ var numWorkers = options.workers;
115
+ var workLoad = options.workLoad || 100;
116
+ var range = workLoad * 30 / 8;
117
+ var workerScript = options.workerScript || "forge/prime.worker.js";
118
+ if (numWorkers === -1) return forge.util.estimateCores(function(err, cores) {
119
+ if (err) cores = 2;
120
+ numWorkers = cores - 1;
121
+ generate();
122
+ });
123
+ generate();
124
+ function generate() {
125
+ numWorkers = Math.max(1, numWorkers);
126
+ var workers = [];
127
+ for (var i = 0; i < numWorkers; ++i) workers[i] = new Worker(workerScript);
128
+ var running = numWorkers;
129
+ for (var i = 0; i < numWorkers; ++i) workers[i].addEventListener("message", workerMessage);
130
+ var found = false;
131
+ function workerMessage(e) {
132
+ if (found) return;
133
+ --running;
134
+ var data = e.data;
135
+ if (data.found) {
136
+ for (var i = 0; i < workers.length; ++i) workers[i].terminate();
137
+ found = true;
138
+ return callback(null, new BigInteger(data.prime, 16));
139
+ }
140
+ if (num.bitLength() > bits) num = generateRandom(bits, rng);
141
+ var hex = num.toString(16);
142
+ e.target.postMessage({
143
+ hex,
144
+ workLoad
145
+ });
146
+ num.dAddOffset(range, 0);
147
+ }
148
+ }
149
+ }
150
+ /**
151
+ * Generates a random number using the given number of bits and RNG.
152
+ *
153
+ * @param bits the number of bits for the number.
154
+ * @param rng the random number generator to use.
155
+ *
156
+ * @return the random number.
157
+ */
158
+ function generateRandom(bits, rng) {
159
+ var num = new BigInteger(bits, rng);
160
+ var bits1 = bits - 1;
161
+ if (!num.testBit(bits1)) num.bitwiseTo(BigInteger.ONE.shiftLeft(bits1), op_or, num);
162
+ num.dAddOffset(31 - num.mod(THIRTY).byteValue(), 0);
163
+ return num;
164
+ }
165
+ /**
166
+ * Returns the required number of Miller-Rabin tests to generate a
167
+ * prime with an error probability of (1/2)^80.
168
+ *
169
+ * See Handbook of Applied Cryptography Chapter 4, Table 4.4.
170
+ *
171
+ * @param bits the bit size.
172
+ *
173
+ * @return the required number of iterations.
174
+ */
175
+ function getMillerRabinTests(bits) {
176
+ if (bits <= 100) return 27;
177
+ if (bits <= 150) return 18;
178
+ if (bits <= 200) return 15;
179
+ if (bits <= 250) return 12;
180
+ if (bits <= 300) return 9;
181
+ if (bits <= 350) return 8;
182
+ if (bits <= 400) return 7;
183
+ if (bits <= 500) return 6;
184
+ if (bits <= 600) return 5;
185
+ if (bits <= 800) return 4;
186
+ if (bits <= 1250) return 3;
187
+ return 2;
188
+ }
189
+ })();
190
+ }));
191
+ //#endregion
192
+ export default require_prime();
193
+ export { require_prime };