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,597 @@
1
+ import { __commonJSMin } from "../../../../../../_virtual/_rolldown/runtime.mjs";
2
+ import { require_forge } from "./forge.mjs";
3
+ import { require_util } from "./util.mjs";
4
+ //#region ../../node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipherModes.js
5
+ var require_cipherModes = /* @__PURE__ */ __commonJSMin(((exports, module) => {
6
+ /**
7
+ * Supported cipher modes.
8
+ *
9
+ * @author Dave Longley
10
+ *
11
+ * Copyright (c) 2010-2014 Digital Bazaar, Inc.
12
+ */
13
+ var forge = require_forge();
14
+ require_util();
15
+ forge.cipher = forge.cipher || {};
16
+ var modes = module.exports = forge.cipher.modes = forge.cipher.modes || {};
17
+ /** Electronic codebook (ECB) (Don't use this; it's not secure) **/
18
+ modes.ecb = function(options) {
19
+ options = options || {};
20
+ this.name = "ECB";
21
+ this.cipher = options.cipher;
22
+ this.blockSize = options.blockSize || 16;
23
+ this._ints = this.blockSize / 4;
24
+ this._inBlock = new Array(this._ints);
25
+ this._outBlock = new Array(this._ints);
26
+ };
27
+ modes.ecb.prototype.start = function(options) {};
28
+ modes.ecb.prototype.encrypt = function(input, output, finish) {
29
+ if (input.length() < this.blockSize && !(finish && input.length() > 0)) return true;
30
+ for (var i = 0; i < this._ints; ++i) this._inBlock[i] = input.getInt32();
31
+ this.cipher.encrypt(this._inBlock, this._outBlock);
32
+ for (var i = 0; i < this._ints; ++i) output.putInt32(this._outBlock[i]);
33
+ };
34
+ modes.ecb.prototype.decrypt = function(input, output, finish) {
35
+ if (input.length() < this.blockSize && !(finish && input.length() > 0)) return true;
36
+ for (var i = 0; i < this._ints; ++i) this._inBlock[i] = input.getInt32();
37
+ this.cipher.decrypt(this._inBlock, this._outBlock);
38
+ for (var i = 0; i < this._ints; ++i) output.putInt32(this._outBlock[i]);
39
+ };
40
+ modes.ecb.prototype.pad = function(input, options) {
41
+ var padding = input.length() === this.blockSize ? this.blockSize : this.blockSize - input.length();
42
+ input.fillWithByte(padding, padding);
43
+ return true;
44
+ };
45
+ modes.ecb.prototype.unpad = function(output, options) {
46
+ if (options.overflow > 0) return false;
47
+ var len = output.length();
48
+ var count = output.at(len - 1);
49
+ if (count > this.blockSize << 2) return false;
50
+ output.truncate(count);
51
+ return true;
52
+ };
53
+ /** Cipher-block Chaining (CBC) **/
54
+ modes.cbc = function(options) {
55
+ options = options || {};
56
+ this.name = "CBC";
57
+ this.cipher = options.cipher;
58
+ this.blockSize = options.blockSize || 16;
59
+ this._ints = this.blockSize / 4;
60
+ this._inBlock = new Array(this._ints);
61
+ this._outBlock = new Array(this._ints);
62
+ };
63
+ modes.cbc.prototype.start = function(options) {
64
+ if (options.iv === null) {
65
+ if (!this._prev) throw new Error("Invalid IV parameter.");
66
+ this._iv = this._prev.slice(0);
67
+ } else if (!("iv" in options)) throw new Error("Invalid IV parameter.");
68
+ else {
69
+ this._iv = transformIV(options.iv, this.blockSize);
70
+ this._prev = this._iv.slice(0);
71
+ }
72
+ };
73
+ modes.cbc.prototype.encrypt = function(input, output, finish) {
74
+ if (input.length() < this.blockSize && !(finish && input.length() > 0)) return true;
75
+ for (var i = 0; i < this._ints; ++i) this._inBlock[i] = this._prev[i] ^ input.getInt32();
76
+ this.cipher.encrypt(this._inBlock, this._outBlock);
77
+ for (var i = 0; i < this._ints; ++i) output.putInt32(this._outBlock[i]);
78
+ this._prev = this._outBlock;
79
+ };
80
+ modes.cbc.prototype.decrypt = function(input, output, finish) {
81
+ if (input.length() < this.blockSize && !(finish && input.length() > 0)) return true;
82
+ for (var i = 0; i < this._ints; ++i) this._inBlock[i] = input.getInt32();
83
+ this.cipher.decrypt(this._inBlock, this._outBlock);
84
+ for (var i = 0; i < this._ints; ++i) output.putInt32(this._prev[i] ^ this._outBlock[i]);
85
+ this._prev = this._inBlock.slice(0);
86
+ };
87
+ modes.cbc.prototype.pad = function(input, options) {
88
+ var padding = input.length() === this.blockSize ? this.blockSize : this.blockSize - input.length();
89
+ input.fillWithByte(padding, padding);
90
+ return true;
91
+ };
92
+ modes.cbc.prototype.unpad = function(output, options) {
93
+ if (options.overflow > 0) return false;
94
+ var len = output.length();
95
+ var count = output.at(len - 1);
96
+ if (count > this.blockSize << 2) return false;
97
+ output.truncate(count);
98
+ return true;
99
+ };
100
+ /** Cipher feedback (CFB) **/
101
+ modes.cfb = function(options) {
102
+ options = options || {};
103
+ this.name = "CFB";
104
+ this.cipher = options.cipher;
105
+ this.blockSize = options.blockSize || 16;
106
+ this._ints = this.blockSize / 4;
107
+ this._inBlock = null;
108
+ this._outBlock = new Array(this._ints);
109
+ this._partialBlock = new Array(this._ints);
110
+ this._partialOutput = forge.util.createBuffer();
111
+ this._partialBytes = 0;
112
+ };
113
+ modes.cfb.prototype.start = function(options) {
114
+ if (!("iv" in options)) throw new Error("Invalid IV parameter.");
115
+ this._iv = transformIV(options.iv, this.blockSize);
116
+ this._inBlock = this._iv.slice(0);
117
+ this._partialBytes = 0;
118
+ };
119
+ modes.cfb.prototype.encrypt = function(input, output, finish) {
120
+ var inputLength = input.length();
121
+ if (inputLength === 0) return true;
122
+ this.cipher.encrypt(this._inBlock, this._outBlock);
123
+ if (this._partialBytes === 0 && inputLength >= this.blockSize) {
124
+ for (var i = 0; i < this._ints; ++i) {
125
+ this._inBlock[i] = input.getInt32() ^ this._outBlock[i];
126
+ output.putInt32(this._inBlock[i]);
127
+ }
128
+ return;
129
+ }
130
+ var partialBytes = (this.blockSize - inputLength) % this.blockSize;
131
+ if (partialBytes > 0) partialBytes = this.blockSize - partialBytes;
132
+ this._partialOutput.clear();
133
+ for (var i = 0; i < this._ints; ++i) {
134
+ this._partialBlock[i] = input.getInt32() ^ this._outBlock[i];
135
+ this._partialOutput.putInt32(this._partialBlock[i]);
136
+ }
137
+ if (partialBytes > 0) input.read -= this.blockSize;
138
+ else for (var i = 0; i < this._ints; ++i) this._inBlock[i] = this._partialBlock[i];
139
+ if (this._partialBytes > 0) this._partialOutput.getBytes(this._partialBytes);
140
+ if (partialBytes > 0 && !finish) {
141
+ output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
142
+ this._partialBytes = partialBytes;
143
+ return true;
144
+ }
145
+ output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
146
+ this._partialBytes = 0;
147
+ };
148
+ modes.cfb.prototype.decrypt = function(input, output, finish) {
149
+ var inputLength = input.length();
150
+ if (inputLength === 0) return true;
151
+ this.cipher.encrypt(this._inBlock, this._outBlock);
152
+ if (this._partialBytes === 0 && inputLength >= this.blockSize) {
153
+ for (var i = 0; i < this._ints; ++i) {
154
+ this._inBlock[i] = input.getInt32();
155
+ output.putInt32(this._inBlock[i] ^ this._outBlock[i]);
156
+ }
157
+ return;
158
+ }
159
+ var partialBytes = (this.blockSize - inputLength) % this.blockSize;
160
+ if (partialBytes > 0) partialBytes = this.blockSize - partialBytes;
161
+ this._partialOutput.clear();
162
+ for (var i = 0; i < this._ints; ++i) {
163
+ this._partialBlock[i] = input.getInt32();
164
+ this._partialOutput.putInt32(this._partialBlock[i] ^ this._outBlock[i]);
165
+ }
166
+ if (partialBytes > 0) input.read -= this.blockSize;
167
+ else for (var i = 0; i < this._ints; ++i) this._inBlock[i] = this._partialBlock[i];
168
+ if (this._partialBytes > 0) this._partialOutput.getBytes(this._partialBytes);
169
+ if (partialBytes > 0 && !finish) {
170
+ output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
171
+ this._partialBytes = partialBytes;
172
+ return true;
173
+ }
174
+ output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
175
+ this._partialBytes = 0;
176
+ };
177
+ /** Output feedback (OFB) **/
178
+ modes.ofb = function(options) {
179
+ options = options || {};
180
+ this.name = "OFB";
181
+ this.cipher = options.cipher;
182
+ this.blockSize = options.blockSize || 16;
183
+ this._ints = this.blockSize / 4;
184
+ this._inBlock = null;
185
+ this._outBlock = new Array(this._ints);
186
+ this._partialOutput = forge.util.createBuffer();
187
+ this._partialBytes = 0;
188
+ };
189
+ modes.ofb.prototype.start = function(options) {
190
+ if (!("iv" in options)) throw new Error("Invalid IV parameter.");
191
+ this._iv = transformIV(options.iv, this.blockSize);
192
+ this._inBlock = this._iv.slice(0);
193
+ this._partialBytes = 0;
194
+ };
195
+ modes.ofb.prototype.encrypt = function(input, output, finish) {
196
+ var inputLength = input.length();
197
+ if (input.length() === 0) return true;
198
+ this.cipher.encrypt(this._inBlock, this._outBlock);
199
+ if (this._partialBytes === 0 && inputLength >= this.blockSize) {
200
+ for (var i = 0; i < this._ints; ++i) {
201
+ output.putInt32(input.getInt32() ^ this._outBlock[i]);
202
+ this._inBlock[i] = this._outBlock[i];
203
+ }
204
+ return;
205
+ }
206
+ var partialBytes = (this.blockSize - inputLength) % this.blockSize;
207
+ if (partialBytes > 0) partialBytes = this.blockSize - partialBytes;
208
+ this._partialOutput.clear();
209
+ for (var i = 0; i < this._ints; ++i) this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);
210
+ if (partialBytes > 0) input.read -= this.blockSize;
211
+ else for (var i = 0; i < this._ints; ++i) this._inBlock[i] = this._outBlock[i];
212
+ if (this._partialBytes > 0) this._partialOutput.getBytes(this._partialBytes);
213
+ if (partialBytes > 0 && !finish) {
214
+ output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
215
+ this._partialBytes = partialBytes;
216
+ return true;
217
+ }
218
+ output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
219
+ this._partialBytes = 0;
220
+ };
221
+ modes.ofb.prototype.decrypt = modes.ofb.prototype.encrypt;
222
+ /** Counter (CTR) **/
223
+ modes.ctr = function(options) {
224
+ options = options || {};
225
+ this.name = "CTR";
226
+ this.cipher = options.cipher;
227
+ this.blockSize = options.blockSize || 16;
228
+ this._ints = this.blockSize / 4;
229
+ this._inBlock = null;
230
+ this._outBlock = new Array(this._ints);
231
+ this._partialOutput = forge.util.createBuffer();
232
+ this._partialBytes = 0;
233
+ };
234
+ modes.ctr.prototype.start = function(options) {
235
+ if (!("iv" in options)) throw new Error("Invalid IV parameter.");
236
+ this._iv = transformIV(options.iv, this.blockSize);
237
+ this._inBlock = this._iv.slice(0);
238
+ this._partialBytes = 0;
239
+ };
240
+ modes.ctr.prototype.encrypt = function(input, output, finish) {
241
+ var inputLength = input.length();
242
+ if (inputLength === 0) return true;
243
+ this.cipher.encrypt(this._inBlock, this._outBlock);
244
+ if (this._partialBytes === 0 && inputLength >= this.blockSize) for (var i = 0; i < this._ints; ++i) output.putInt32(input.getInt32() ^ this._outBlock[i]);
245
+ else {
246
+ var partialBytes = (this.blockSize - inputLength) % this.blockSize;
247
+ if (partialBytes > 0) partialBytes = this.blockSize - partialBytes;
248
+ this._partialOutput.clear();
249
+ for (var i = 0; i < this._ints; ++i) this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);
250
+ if (partialBytes > 0) input.read -= this.blockSize;
251
+ if (this._partialBytes > 0) this._partialOutput.getBytes(this._partialBytes);
252
+ if (partialBytes > 0 && !finish) {
253
+ output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
254
+ this._partialBytes = partialBytes;
255
+ return true;
256
+ }
257
+ output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
258
+ this._partialBytes = 0;
259
+ }
260
+ inc32(this._inBlock);
261
+ };
262
+ modes.ctr.prototype.decrypt = modes.ctr.prototype.encrypt;
263
+ /** Galois/Counter Mode (GCM) **/
264
+ modes.gcm = function(options) {
265
+ options = options || {};
266
+ this.name = "GCM";
267
+ this.cipher = options.cipher;
268
+ this.blockSize = options.blockSize || 16;
269
+ this._ints = this.blockSize / 4;
270
+ this._inBlock = new Array(this._ints);
271
+ this._outBlock = new Array(this._ints);
272
+ this._partialOutput = forge.util.createBuffer();
273
+ this._partialBytes = 0;
274
+ this._R = 3774873600;
275
+ };
276
+ modes.gcm.prototype.start = function(options) {
277
+ if (!("iv" in options)) throw new Error("Invalid IV parameter.");
278
+ var iv = forge.util.createBuffer(options.iv);
279
+ this._cipherLength = 0;
280
+ var additionalData;
281
+ if ("additionalData" in options) additionalData = forge.util.createBuffer(options.additionalData);
282
+ else additionalData = forge.util.createBuffer();
283
+ if ("tagLength" in options) this._tagLength = options.tagLength;
284
+ else this._tagLength = 128;
285
+ this._tag = null;
286
+ if (options.decrypt) {
287
+ this._tag = forge.util.createBuffer(options.tag).getBytes();
288
+ if (this._tag.length !== this._tagLength / 8) throw new Error("Authentication tag does not match tag length.");
289
+ }
290
+ this._hashBlock = new Array(this._ints);
291
+ this.tag = null;
292
+ this._hashSubkey = new Array(this._ints);
293
+ this.cipher.encrypt([
294
+ 0,
295
+ 0,
296
+ 0,
297
+ 0
298
+ ], this._hashSubkey);
299
+ this.componentBits = 4;
300
+ this._m = this.generateHashTable(this._hashSubkey, this.componentBits);
301
+ var ivLength = iv.length();
302
+ if (ivLength === 12) this._j0 = [
303
+ iv.getInt32(),
304
+ iv.getInt32(),
305
+ iv.getInt32(),
306
+ 1
307
+ ];
308
+ else {
309
+ this._j0 = [
310
+ 0,
311
+ 0,
312
+ 0,
313
+ 0
314
+ ];
315
+ while (iv.length() > 0) this._j0 = this.ghash(this._hashSubkey, this._j0, [
316
+ iv.getInt32(),
317
+ iv.getInt32(),
318
+ iv.getInt32(),
319
+ iv.getInt32()
320
+ ]);
321
+ this._j0 = this.ghash(this._hashSubkey, this._j0, [0, 0].concat(from64To32(ivLength * 8)));
322
+ }
323
+ this._inBlock = this._j0.slice(0);
324
+ inc32(this._inBlock);
325
+ this._partialBytes = 0;
326
+ additionalData = forge.util.createBuffer(additionalData);
327
+ this._aDataLength = from64To32(additionalData.length() * 8);
328
+ var overflow = additionalData.length() % this.blockSize;
329
+ if (overflow) additionalData.fillWithByte(0, this.blockSize - overflow);
330
+ this._s = [
331
+ 0,
332
+ 0,
333
+ 0,
334
+ 0
335
+ ];
336
+ while (additionalData.length() > 0) this._s = this.ghash(this._hashSubkey, this._s, [
337
+ additionalData.getInt32(),
338
+ additionalData.getInt32(),
339
+ additionalData.getInt32(),
340
+ additionalData.getInt32()
341
+ ]);
342
+ };
343
+ modes.gcm.prototype.encrypt = function(input, output, finish) {
344
+ var inputLength = input.length();
345
+ if (inputLength === 0) return true;
346
+ this.cipher.encrypt(this._inBlock, this._outBlock);
347
+ if (this._partialBytes === 0 && inputLength >= this.blockSize) {
348
+ for (var i = 0; i < this._ints; ++i) output.putInt32(this._outBlock[i] ^= input.getInt32());
349
+ this._cipherLength += this.blockSize;
350
+ } else {
351
+ var partialBytes = (this.blockSize - inputLength) % this.blockSize;
352
+ if (partialBytes > 0) partialBytes = this.blockSize - partialBytes;
353
+ this._partialOutput.clear();
354
+ for (var i = 0; i < this._ints; ++i) this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);
355
+ if (partialBytes <= 0 || finish) {
356
+ if (finish) {
357
+ var overflow = inputLength % this.blockSize;
358
+ this._cipherLength += overflow;
359
+ this._partialOutput.truncate(this.blockSize - overflow);
360
+ } else this._cipherLength += this.blockSize;
361
+ for (var i = 0; i < this._ints; ++i) this._outBlock[i] = this._partialOutput.getInt32();
362
+ this._partialOutput.read -= this.blockSize;
363
+ }
364
+ if (this._partialBytes > 0) this._partialOutput.getBytes(this._partialBytes);
365
+ if (partialBytes > 0 && !finish) {
366
+ input.read -= this.blockSize;
367
+ output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
368
+ this._partialBytes = partialBytes;
369
+ return true;
370
+ }
371
+ output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
372
+ this._partialBytes = 0;
373
+ }
374
+ this._s = this.ghash(this._hashSubkey, this._s, this._outBlock);
375
+ inc32(this._inBlock);
376
+ };
377
+ modes.gcm.prototype.decrypt = function(input, output, finish) {
378
+ var inputLength = input.length();
379
+ if (inputLength < this.blockSize && !(finish && inputLength > 0)) return true;
380
+ this.cipher.encrypt(this._inBlock, this._outBlock);
381
+ inc32(this._inBlock);
382
+ this._hashBlock[0] = input.getInt32();
383
+ this._hashBlock[1] = input.getInt32();
384
+ this._hashBlock[2] = input.getInt32();
385
+ this._hashBlock[3] = input.getInt32();
386
+ this._s = this.ghash(this._hashSubkey, this._s, this._hashBlock);
387
+ for (var i = 0; i < this._ints; ++i) output.putInt32(this._outBlock[i] ^ this._hashBlock[i]);
388
+ if (inputLength < this.blockSize) this._cipherLength += inputLength % this.blockSize;
389
+ else this._cipherLength += this.blockSize;
390
+ };
391
+ modes.gcm.prototype.afterFinish = function(output, options) {
392
+ var rval = true;
393
+ if (options.decrypt && options.overflow) output.truncate(this.blockSize - options.overflow);
394
+ this.tag = forge.util.createBuffer();
395
+ var lengths = this._aDataLength.concat(from64To32(this._cipherLength * 8));
396
+ this._s = this.ghash(this._hashSubkey, this._s, lengths);
397
+ var tag = [];
398
+ this.cipher.encrypt(this._j0, tag);
399
+ for (var i = 0; i < this._ints; ++i) this.tag.putInt32(this._s[i] ^ tag[i]);
400
+ this.tag.truncate(this.tag.length() % (this._tagLength / 8));
401
+ if (options.decrypt && this.tag.bytes() !== this._tag) rval = false;
402
+ return rval;
403
+ };
404
+ /**
405
+ * See NIST SP-800-38D 6.3 (Algorithm 1). This function performs Galois
406
+ * field multiplication. The field, GF(2^128), is defined by the polynomial:
407
+ *
408
+ * x^128 + x^7 + x^2 + x + 1
409
+ *
410
+ * Which is represented in little-endian binary form as: 11100001 (0xe1). When
411
+ * the value of a coefficient is 1, a bit is set. The value R, is the
412
+ * concatenation of this value and 120 zero bits, yielding a 128-bit value
413
+ * which matches the block size.
414
+ *
415
+ * This function will multiply two elements (vectors of bytes), X and Y, in
416
+ * the field GF(2^128). The result is initialized to zero. For each bit of
417
+ * X (out of 128), x_i, if x_i is set, then the result is multiplied (XOR'd)
418
+ * by the current value of Y. For each bit, the value of Y will be raised by
419
+ * a power of x (multiplied by the polynomial x). This can be achieved by
420
+ * shifting Y once to the right. If the current value of Y, prior to being
421
+ * multiplied by x, has 0 as its LSB, then it is a 127th degree polynomial.
422
+ * Otherwise, we must divide by R after shifting to find the remainder.
423
+ *
424
+ * @param x the first block to multiply by the second.
425
+ * @param y the second block to multiply by the first.
426
+ *
427
+ * @return the block result of the multiplication.
428
+ */
429
+ modes.gcm.prototype.multiply = function(x, y) {
430
+ var z_i = [
431
+ 0,
432
+ 0,
433
+ 0,
434
+ 0
435
+ ];
436
+ var v_i = y.slice(0);
437
+ for (var i = 0; i < 128; ++i) {
438
+ if (x[i / 32 | 0] & 1 << 31 - i % 32) {
439
+ z_i[0] ^= v_i[0];
440
+ z_i[1] ^= v_i[1];
441
+ z_i[2] ^= v_i[2];
442
+ z_i[3] ^= v_i[3];
443
+ }
444
+ this.pow(v_i, v_i);
445
+ }
446
+ return z_i;
447
+ };
448
+ modes.gcm.prototype.pow = function(x, out) {
449
+ var lsb = x[3] & 1;
450
+ for (var i = 3; i > 0; --i) out[i] = x[i] >>> 1 | (x[i - 1] & 1) << 31;
451
+ out[0] = x[0] >>> 1;
452
+ if (lsb) out[0] ^= this._R;
453
+ };
454
+ modes.gcm.prototype.tableMultiply = function(x) {
455
+ var z = [
456
+ 0,
457
+ 0,
458
+ 0,
459
+ 0
460
+ ];
461
+ for (var i = 0; i < 32; ++i) {
462
+ var x_i = x[i / 8 | 0] >>> (7 - i % 8) * 4 & 15;
463
+ var ah = this._m[i][x_i];
464
+ z[0] ^= ah[0];
465
+ z[1] ^= ah[1];
466
+ z[2] ^= ah[2];
467
+ z[3] ^= ah[3];
468
+ }
469
+ return z;
470
+ };
471
+ /**
472
+ * A continuing version of the GHASH algorithm that operates on a single
473
+ * block. The hash block, last hash value (Ym) and the new block to hash
474
+ * are given.
475
+ *
476
+ * @param h the hash block.
477
+ * @param y the previous value for Ym, use [0, 0, 0, 0] for a new hash.
478
+ * @param x the block to hash.
479
+ *
480
+ * @return the hashed value (Ym).
481
+ */
482
+ modes.gcm.prototype.ghash = function(h, y, x) {
483
+ y[0] ^= x[0];
484
+ y[1] ^= x[1];
485
+ y[2] ^= x[2];
486
+ y[3] ^= x[3];
487
+ return this.tableMultiply(y);
488
+ };
489
+ /**
490
+ * Precomputes a table for multiplying against the hash subkey. This
491
+ * mechanism provides a substantial speed increase over multiplication
492
+ * performed without a table. The table-based multiplication this table is
493
+ * for solves X * H by multiplying each component of X by H and then
494
+ * composing the results together using XOR.
495
+ *
496
+ * This function can be used to generate tables with different bit sizes
497
+ * for the components, however, this implementation assumes there are
498
+ * 32 components of X (which is a 16 byte vector), therefore each component
499
+ * takes 4-bits (so the table is constructed with bits=4).
500
+ *
501
+ * @param h the hash subkey.
502
+ * @param bits the bit size for a component.
503
+ */
504
+ modes.gcm.prototype.generateHashTable = function(h, bits) {
505
+ var multiplier = 8 / bits;
506
+ var perInt = 4 * multiplier;
507
+ var size = 16 * multiplier;
508
+ var m = new Array(size);
509
+ for (var i = 0; i < size; ++i) {
510
+ var tmp = [
511
+ 0,
512
+ 0,
513
+ 0,
514
+ 0
515
+ ];
516
+ var idx = i / perInt | 0;
517
+ var shft = (perInt - 1 - i % perInt) * bits;
518
+ tmp[idx] = 1 << bits - 1 << shft;
519
+ m[i] = this.generateSubHashTable(this.multiply(tmp, h), bits);
520
+ }
521
+ return m;
522
+ };
523
+ /**
524
+ * Generates a table for multiplying against the hash subkey for one
525
+ * particular component (out of all possible component values).
526
+ *
527
+ * @param mid the pre-multiplied value for the middle key of the table.
528
+ * @param bits the bit size for a component.
529
+ */
530
+ modes.gcm.prototype.generateSubHashTable = function(mid, bits) {
531
+ var size = 1 << bits;
532
+ var half = size >>> 1;
533
+ var m = new Array(size);
534
+ m[half] = mid.slice(0);
535
+ var i = half >>> 1;
536
+ while (i > 0) {
537
+ this.pow(m[2 * i], m[i] = []);
538
+ i >>= 1;
539
+ }
540
+ i = 2;
541
+ while (i < half) {
542
+ for (var j = 1; j < i; ++j) {
543
+ var m_i = m[i];
544
+ var m_j = m[j];
545
+ m[i + j] = [
546
+ m_i[0] ^ m_j[0],
547
+ m_i[1] ^ m_j[1],
548
+ m_i[2] ^ m_j[2],
549
+ m_i[3] ^ m_j[3]
550
+ ];
551
+ }
552
+ i *= 2;
553
+ }
554
+ m[0] = [
555
+ 0,
556
+ 0,
557
+ 0,
558
+ 0
559
+ ];
560
+ for (i = half + 1; i < size; ++i) {
561
+ var c = m[i ^ half];
562
+ m[i] = [
563
+ mid[0] ^ c[0],
564
+ mid[1] ^ c[1],
565
+ mid[2] ^ c[2],
566
+ mid[3] ^ c[3]
567
+ ];
568
+ }
569
+ return m;
570
+ };
571
+ /** Utility functions */
572
+ function transformIV(iv, blockSize) {
573
+ if (typeof iv === "string") iv = forge.util.createBuffer(iv);
574
+ if (forge.util.isArray(iv) && iv.length > 4) {
575
+ var tmp = iv;
576
+ iv = forge.util.createBuffer();
577
+ for (var i = 0; i < tmp.length; ++i) iv.putByte(tmp[i]);
578
+ }
579
+ if (iv.length() < blockSize) throw new Error("Invalid IV length; got " + iv.length() + " bytes and expected " + blockSize + " bytes.");
580
+ if (!forge.util.isArray(iv)) {
581
+ var ints = [];
582
+ var blocks = blockSize / 4;
583
+ for (var i = 0; i < blocks; ++i) ints.push(iv.getInt32());
584
+ iv = ints;
585
+ }
586
+ return iv;
587
+ }
588
+ function inc32(block) {
589
+ block[block.length - 1] = block[block.length - 1] + 1 & 4294967295;
590
+ }
591
+ function from64To32(num) {
592
+ return [num / 4294967296 | 0, num & 4294967295];
593
+ }
594
+ }));
595
+ //#endregion
596
+ export default require_cipherModes();
597
+ export { require_cipherModes };