@yielded/auth 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1466) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/dist/Atom.d.mts +5 -0
  4. package/dist/Atom.mjs +5 -0
  5. package/dist/Auth.d.mts +9 -0
  6. package/dist/Auth.mjs +7 -0
  7. package/dist/AuthContract.d.mts +4 -0
  8. package/dist/AuthContract.mjs +4 -0
  9. package/dist/AuthSession.d.mts +82 -0
  10. package/dist/AuthSession.mjs +138 -0
  11. package/dist/AuthSession.mjs.map +1 -0
  12. package/dist/AuthStore.d.mts +68 -0
  13. package/dist/AuthStore.mjs +194 -0
  14. package/dist/AuthStore.mjs.map +1 -0
  15. package/dist/AuthTokenCodec.d.mts +40 -0
  16. package/dist/AuthTokenCodec.mjs +104 -0
  17. package/dist/AuthTokenCodec.mjs.map +1 -0
  18. package/dist/Client.d.mts +2 -0
  19. package/dist/Client.mjs +2 -0
  20. package/dist/Cloudflare.d.mts +89 -0
  21. package/dist/Cloudflare.mjs +166 -0
  22. package/dist/Cloudflare.mjs.map +1 -0
  23. package/dist/Drizzle.d.mts +28 -0
  24. package/dist/Drizzle.mjs +27 -0
  25. package/dist/DrizzleD1.d.mts +935 -0
  26. package/dist/DrizzleD1.mjs +29 -0
  27. package/dist/DrizzleD1.mjs.map +1 -0
  28. package/dist/DrizzleLibsql.d.mts +2288 -0
  29. package/dist/DrizzleLibsql.mjs +85 -0
  30. package/dist/DrizzleLibsql.mjs.map +1 -0
  31. package/dist/DrizzleMysql2.d.mts +1809 -0
  32. package/dist/DrizzleMysql2.mjs +55 -0
  33. package/dist/DrizzleMysql2.mjs.map +1 -0
  34. package/dist/DrizzlePglite.d.mts +1808 -0
  35. package/dist/DrizzlePglite.mjs +45 -0
  36. package/dist/DrizzlePglite.mjs.map +1 -0
  37. package/dist/DrizzlePostgres.d.mts +1808 -0
  38. package/dist/DrizzlePostgres.mjs +45 -0
  39. package/dist/DrizzlePostgres.mjs.map +1 -0
  40. package/dist/DrizzleSqliteBun.d.mts +2287 -0
  41. package/dist/DrizzleSqliteBun.mjs +62 -0
  42. package/dist/DrizzleSqliteBun.mjs.map +1 -0
  43. package/dist/DrizzleSqliteDo.d.mts +2343 -0
  44. package/dist/DrizzleSqliteDo.mjs +105 -0
  45. package/dist/DrizzleSqliteDo.mjs.map +1 -0
  46. package/dist/DrizzleSqliteNode.d.mts +2287 -0
  47. package/dist/DrizzleSqliteNode.mjs +62 -0
  48. package/dist/DrizzleSqliteNode.mjs.map +1 -0
  49. package/dist/DrizzleSqliteWasm.d.mts +2287 -0
  50. package/dist/DrizzleSqliteWasm.mjs +62 -0
  51. package/dist/DrizzleSqliteWasm.mjs.map +1 -0
  52. package/dist/Email.d.mts +12 -0
  53. package/dist/Email.mjs +11 -0
  54. package/dist/EmailOtp.d.mts +42 -0
  55. package/dist/EmailOtp.mjs +120 -0
  56. package/dist/EmailOtp.mjs.map +1 -0
  57. package/dist/EmailOtpSender.d.mts +22 -0
  58. package/dist/EmailOtpSender.mjs +18 -0
  59. package/dist/EmailOtpSender.mjs.map +1 -0
  60. package/dist/Errors.d.mts +55 -0
  61. package/dist/Errors.mjs +31 -0
  62. package/dist/Errors.mjs.map +1 -0
  63. package/dist/GitHub.d.mts +5 -0
  64. package/dist/GitHub.mjs +4 -0
  65. package/dist/Hooks.d.mts +6 -0
  66. package/dist/Hooks.mjs +6 -0
  67. package/dist/Http.d.mts +12 -0
  68. package/dist/Http.mjs +12 -0
  69. package/dist/HttpServer.d.mts +103 -0
  70. package/dist/HttpServer.mjs +326 -0
  71. package/dist/HttpServer.mjs.map +1 -0
  72. package/dist/Identity.d.mts +9 -0
  73. package/dist/Identity.mjs +9 -0
  74. package/dist/IdentityResolver.d.mts +16 -0
  75. package/dist/IdentityResolver.mjs +12 -0
  76. package/dist/IdentityResolver.mjs.map +1 -0
  77. package/dist/OAuth.d.mts +36 -0
  78. package/dist/OAuth.mjs +35 -0
  79. package/dist/OpenIdClient.d.mts +3 -0
  80. package/dist/OpenIdClient.mjs +3 -0
  81. package/dist/OpenIdClientConnected.d.mts +4 -0
  82. package/dist/OpenIdClientConnected.mjs +3 -0
  83. package/dist/OperationHttp.d.mts +3 -0
  84. package/dist/OperationHttp.mjs +3 -0
  85. package/dist/OperationHttpClient.d.mts +2 -0
  86. package/dist/OperationHttpClient.mjs +2 -0
  87. package/dist/OperationHttpServer.d.mts +5 -0
  88. package/dist/OperationHttpServer.mjs +4 -0
  89. package/dist/Operations.d.mts +8 -0
  90. package/dist/Operations.mjs +8 -0
  91. package/dist/Passkey.d.mts +12 -0
  92. package/dist/Passkey.mjs +12 -0
  93. package/dist/PasskeyBrowser.d.mts +4 -0
  94. package/dist/PasskeyBrowser.mjs +4 -0
  95. package/dist/PasskeyContract.d.mts +641 -0
  96. package/dist/PasskeyContract.mjs +174 -0
  97. package/dist/PasskeyContract.mjs.map +1 -0
  98. package/dist/PasskeyPassword.d.mts +412 -0
  99. package/dist/PasskeyPassword.mjs +174 -0
  100. package/dist/PasskeyPassword.mjs.map +1 -0
  101. package/dist/PasskeySimpleWebAuthn.d.mts +3 -0
  102. package/dist/PasskeySimpleWebAuthn.mjs +3 -0
  103. package/dist/Password.d.mts +19 -0
  104. package/dist/Password.mjs +17 -0
  105. package/dist/PasswordAuth.d.mts +45 -0
  106. package/dist/PasswordAuth.mjs +79 -0
  107. package/dist/PasswordAuth.mjs.map +1 -0
  108. package/dist/PasswordCredentialStore.d.mts +46 -0
  109. package/dist/PasswordCredentialStore.mjs +62 -0
  110. package/dist/PasswordCredentialStore.mjs.map +1 -0
  111. package/dist/PasswordHasher.d.mts +31 -0
  112. package/dist/PasswordHasher.mjs +76 -0
  113. package/dist/PasswordHasher.mjs.map +1 -0
  114. package/dist/PhoneOtp.d.mts +11 -0
  115. package/dist/PhoneOtp.mjs +11 -0
  116. package/dist/Policy.d.mts +52 -0
  117. package/dist/Policy.mjs +36 -0
  118. package/dist/Policy.mjs.map +1 -0
  119. package/dist/Proofs.d.mts +14 -0
  120. package/dist/Proofs.mjs +13 -0
  121. package/dist/Rpc.d.mts +12 -0
  122. package/dist/Rpc.mjs +11 -0
  123. package/dist/Rpc.mjs.map +1 -0
  124. package/dist/Schema.d.mts +160 -0
  125. package/dist/Schema.mjs +141 -0
  126. package/dist/Schema.mjs.map +1 -0
  127. package/dist/SessionContract.d.mts +3 -0
  128. package/dist/SessionContract.mjs +3 -0
  129. package/dist/Sessions.d.mts +14 -0
  130. package/dist/Sessions.mjs +12 -0
  131. package/dist/Testing.d.mts +7 -0
  132. package/dist/Testing.mjs +7 -0
  133. package/dist/Totp.d.mts +8 -0
  134. package/dist/Totp.mjs +8 -0
  135. package/dist/TotpContract.d.mts +318 -0
  136. package/dist/TotpContract.mjs +119 -0
  137. package/dist/TotpContract.mjs.map +1 -0
  138. package/dist/WebCrypto.d.mts +28 -0
  139. package/dist/WebCrypto.mjs +42 -0
  140. package/dist/WebCrypto.mjs.map +1 -0
  141. package/dist/Workflows.d.mts +16 -0
  142. package/dist/Workflows.mjs +11 -0
  143. package/dist/Workflows.mjs.map +1 -0
  144. package/dist/atom/AuthAtomLifetime.d.mts +35 -0
  145. package/dist/atom/AuthAtomLifetime.mjs +50 -0
  146. package/dist/atom/AuthAtomLifetime.mjs.map +1 -0
  147. package/dist/atom/AuthAtomWorkflow.d.mts +17 -0
  148. package/dist/atom/AuthAtomWorkflow.mjs +9 -0
  149. package/dist/atom/AuthAtomWorkflow.mjs.map +1 -0
  150. package/dist/atom/client.d.mts +43 -0
  151. package/dist/atom/client.mjs +168 -0
  152. package/dist/atom/client.mjs.map +1 -0
  153. package/dist/atom/operations.d.mts +35 -0
  154. package/dist/atom/operations.mjs +58 -0
  155. package/dist/atom/operations.mjs.map +1 -0
  156. package/dist/atom/scoped-runtime.mjs +151 -0
  157. package/dist/atom/scoped-runtime.mjs.map +1 -0
  158. package/dist/auth/Auth.d.mts +7806 -0
  159. package/dist/auth/Auth.mjs +141 -0
  160. package/dist/auth/Auth.mjs.map +1 -0
  161. package/dist/auth/AuthConfigurationError.d.mts +10 -0
  162. package/dist/auth/AuthConfigurationError.mjs +14 -0
  163. package/dist/auth/AuthConfigurationError.mjs.map +1 -0
  164. package/dist/auth/AuthRequest.d.mts +21 -0
  165. package/dist/auth/AuthRequest.mjs +10 -0
  166. package/dist/auth/AuthRequest.mjs.map +1 -0
  167. package/dist/auth/AuthStrategy.d.mts +23 -0
  168. package/dist/auth/AuthStrategy.mjs +33 -0
  169. package/dist/auth/AuthStrategy.mjs.map +1 -0
  170. package/dist/auth/ConsumeDecision.d.mts +11 -0
  171. package/dist/auth/actions.d.mts +18 -0
  172. package/dist/auth/actions.mjs +70 -0
  173. package/dist/auth/actions.mjs.map +1 -0
  174. package/dist/auth/defaults.mjs +12 -0
  175. package/dist/auth/defaults.mjs.map +1 -0
  176. package/dist/auth/definition.d.mts +46 -0
  177. package/dist/auth/session.d.mts +27 -0
  178. package/dist/auth/session.mjs +56 -0
  179. package/dist/auth/session.mjs.map +1 -0
  180. package/dist/drizzle/D1BatchStatements.d.mts +11 -0
  181. package/dist/drizzle/D1BatchStatements.mjs +8 -0
  182. package/dist/drizzle/D1BatchStatements.mjs.map +1 -0
  183. package/dist/drizzle/PasswordPreparedPostconditions.mjs +12 -0
  184. package/dist/drizzle/PasswordPreparedPostconditions.mjs.map +1 -0
  185. package/dist/drizzle/SuppliedService.d.mts +10 -0
  186. package/dist/drizzle/d1-emails.d.mts +68 -0
  187. package/dist/drizzle/d1-emails.mjs +580 -0
  188. package/dist/drizzle/d1-emails.mjs.map +1 -0
  189. package/dist/drizzle/d1-generated-statement.mjs +79 -0
  190. package/dist/drizzle/d1-generated-statement.mjs.map +1 -0
  191. package/dist/drizzle/d1-identity.d.mts +33 -0
  192. package/dist/drizzle/d1-identity.mjs +120 -0
  193. package/dist/drizzle/d1-identity.mjs.map +1 -0
  194. package/dist/drizzle/d1-oauth.d.mts +316 -0
  195. package/dist/drizzle/d1-oauth.mjs +79 -0
  196. package/dist/drizzle/d1-oauth.mjs.map +1 -0
  197. package/dist/drizzle/d1-passkey.d.mts +52 -0
  198. package/dist/drizzle/d1-passkey.mjs +97 -0
  199. package/dist/drizzle/d1-passkey.mjs.map +1 -0
  200. package/dist/drizzle/d1-password-prepared.d.mts +27 -0
  201. package/dist/drizzle/d1-password-prepared.mjs +464 -0
  202. package/dist/drizzle/d1-password-prepared.mjs.map +1 -0
  203. package/dist/drizzle/d1-passwords.d.mts +96 -0
  204. package/dist/drizzle/d1-passwords.mjs +1008 -0
  205. package/dist/drizzle/d1-passwords.mjs.map +1 -0
  206. package/dist/drizzle/d1-phone.d.mts +29 -0
  207. package/dist/drizzle/d1-phone.mjs +33 -0
  208. package/dist/drizzle/d1-phone.mjs.map +1 -0
  209. package/dist/drizzle/d1-planning.d.mts +12 -0
  210. package/dist/drizzle/d1-planning.mjs +43 -0
  211. package/dist/drizzle/d1-planning.mjs.map +1 -0
  212. package/dist/drizzle/d1-proofs.d.mts +88 -0
  213. package/dist/drizzle/d1-proofs.mjs +833 -0
  214. package/dist/drizzle/d1-proofs.mjs.map +1 -0
  215. package/dist/drizzle/d1-sessions.d.mts +77 -0
  216. package/dist/drizzle/d1-sessions.mjs +970 -0
  217. package/dist/drizzle/d1-sessions.mjs.map +1 -0
  218. package/dist/drizzle/d1-totp.d.mts +27 -0
  219. package/dist/drizzle/d1-totp.mjs +28 -0
  220. package/dist/drizzle/d1-totp.mjs.map +1 -0
  221. package/dist/drizzle/email-model.d.mts +352 -0
  222. package/dist/drizzle/email-model.mjs +21 -0
  223. package/dist/drizzle/email-model.mjs.map +1 -0
  224. package/dist/drizzle/email-registration.d.mts +33 -0
  225. package/dist/drizzle/email-registration.mjs +238 -0
  226. package/dist/drizzle/email-registration.mjs.map +1 -0
  227. package/dist/drizzle/email-sql.d.mts +18 -0
  228. package/dist/drizzle/email-sql.mjs +473 -0
  229. package/dist/drizzle/email-sql.mjs.map +1 -0
  230. package/dist/drizzle/email-target.d.mts +28 -0
  231. package/dist/drizzle/email-target.mjs +75 -0
  232. package/dist/drizzle/email-target.mjs.map +1 -0
  233. package/dist/drizzle/model.d.mts +259 -0
  234. package/dist/drizzle/model.mjs +81 -0
  235. package/dist/drizzle/model.mjs.map +1 -0
  236. package/dist/drizzle/mysql-emails.d.mts +82 -0
  237. package/dist/drizzle/mysql-emails.mjs +38 -0
  238. package/dist/drizzle/mysql-emails.mjs.map +1 -0
  239. package/dist/drizzle/mysql-identity.d.mts +24 -0
  240. package/dist/drizzle/mysql-identity.mjs +95 -0
  241. package/dist/drizzle/mysql-identity.mjs.map +1 -0
  242. package/dist/drizzle/mysql-password-prepared.d.mts +32 -0
  243. package/dist/drizzle/mysql-password-prepared.mjs +16 -0
  244. package/dist/drizzle/mysql-password-prepared.mjs.map +1 -0
  245. package/dist/drizzle/mysql-passwords.d.mts +102 -0
  246. package/dist/drizzle/mysql-passwords.mjs +38 -0
  247. package/dist/drizzle/mysql-passwords.mjs.map +1 -0
  248. package/dist/drizzle/mysql-proofs.d.mts +83 -0
  249. package/dist/drizzle/mysql-proofs.mjs +23 -0
  250. package/dist/drizzle/mysql-proofs.mjs.map +1 -0
  251. package/dist/drizzle/mysql-sessions.d.mts +250 -0
  252. package/dist/drizzle/mysql-sessions.mjs +53 -0
  253. package/dist/drizzle/mysql-sessions.mjs.map +1 -0
  254. package/dist/drizzle/mysql.d.mts +73 -0
  255. package/dist/drizzle/mysql.mjs +221 -0
  256. package/dist/drizzle/mysql.mjs.map +1 -0
  257. package/dist/drizzle/oauth-accounts.mjs +361 -0
  258. package/dist/drizzle/oauth-accounts.mjs.map +1 -0
  259. package/dist/drizzle/oauth-connected-access.mjs +210 -0
  260. package/dist/drizzle/oauth-connected-access.mjs.map +1 -0
  261. package/dist/drizzle/oauth-connected-collection.mjs +202 -0
  262. package/dist/drizzle/oauth-connected-collection.mjs.map +1 -0
  263. package/dist/drizzle/oauth-connected-custody.mjs +146 -0
  264. package/dist/drizzle/oauth-connected-custody.mjs.map +1 -0
  265. package/dist/drizzle/oauth-connected-drivers.mjs +78 -0
  266. package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -0
  267. package/dist/drizzle/oauth-connected-flow.mjs +248 -0
  268. package/dist/drizzle/oauth-connected-flow.mjs.map +1 -0
  269. package/dist/drizzle/oauth-connected-input.mjs +105 -0
  270. package/dist/drizzle/oauth-connected-input.mjs.map +1 -0
  271. package/dist/drizzle/oauth-connected-maintenance.mjs +215 -0
  272. package/dist/drizzle/oauth-connected-maintenance.mjs.map +1 -0
  273. package/dist/drizzle/oauth-connected-management.mjs +228 -0
  274. package/dist/drizzle/oauth-connected-management.mjs.map +1 -0
  275. package/dist/drizzle/oauth-connected-model.d.mts +278 -0
  276. package/dist/drizzle/oauth-connected-model.mjs +22 -0
  277. package/dist/drizzle/oauth-connected-model.mjs.map +1 -0
  278. package/dist/drizzle/oauth-connected-reference.d.mts +17 -0
  279. package/dist/drizzle/oauth-connected-reference.mjs +53 -0
  280. package/dist/drizzle/oauth-connected-reference.mjs.map +1 -0
  281. package/dist/drizzle/oauth-connected-settlement.mjs +117 -0
  282. package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -0
  283. package/dist/drizzle/oauth-connected-state.d.mts +16 -0
  284. package/dist/drizzle/oauth-connected-state.mjs +422 -0
  285. package/dist/drizzle/oauth-connected-state.mjs.map +1 -0
  286. package/dist/drizzle/oauth-connected-target.d.mts +114 -0
  287. package/dist/drizzle/oauth-connected-target.mjs +94 -0
  288. package/dist/drizzle/oauth-connected-target.mjs.map +1 -0
  289. package/dist/drizzle/oauth-drivers.mjs +53 -0
  290. package/dist/drizzle/oauth-drivers.mjs.map +1 -0
  291. package/dist/drizzle/oauth-flow.d.mts +7 -0
  292. package/dist/drizzle/oauth-flow.mjs +255 -0
  293. package/dist/drizzle/oauth-flow.mjs.map +1 -0
  294. package/dist/drizzle/oauth-input.mjs +130 -0
  295. package/dist/drizzle/oauth-input.mjs.map +1 -0
  296. package/dist/drizzle/oauth-model.d.mts +468 -0
  297. package/dist/drizzle/oauth-model.mjs +49 -0
  298. package/dist/drizzle/oauth-model.mjs.map +1 -0
  299. package/dist/drizzle/oauth-mysql.mjs +8 -0
  300. package/dist/drizzle/oauth-mysql.mjs.map +1 -0
  301. package/dist/drizzle/oauth-owner.d.mts +4 -0
  302. package/dist/drizzle/oauth-owner.mjs +10 -0
  303. package/dist/drizzle/oauth-owner.mjs.map +1 -0
  304. package/dist/drizzle/oauth-registration.d.mts +8 -0
  305. package/dist/drizzle/oauth-registration.mjs +375 -0
  306. package/dist/drizzle/oauth-registration.mjs.map +1 -0
  307. package/dist/drizzle/oauth-state.mjs +109 -0
  308. package/dist/drizzle/oauth-state.mjs.map +1 -0
  309. package/dist/drizzle/oauth-target.d.mts +125 -0
  310. package/dist/drizzle/oauth-target.mjs +252 -0
  311. package/dist/drizzle/oauth-target.mjs.map +1 -0
  312. package/dist/drizzle/passkey-admission.mjs +203 -0
  313. package/dist/drizzle/passkey-admission.mjs.map +1 -0
  314. package/dist/drizzle/passkey-credentials.mjs +239 -0
  315. package/dist/drizzle/passkey-credentials.mjs.map +1 -0
  316. package/dist/drizzle/passkey-drivers.mjs +34 -0
  317. package/dist/drizzle/passkey-drivers.mjs.map +1 -0
  318. package/dist/drizzle/passkey-enrollment.mjs +132 -0
  319. package/dist/drizzle/passkey-enrollment.mjs.map +1 -0
  320. package/dist/drizzle/passkey-flow.mjs +436 -0
  321. package/dist/drizzle/passkey-flow.mjs.map +1 -0
  322. package/dist/drizzle/passkey-management.mjs +225 -0
  323. package/dist/drizzle/passkey-management.mjs.map +1 -0
  324. package/dist/drizzle/passkey-model.d.mts +275 -0
  325. package/dist/drizzle/passkey-model.mjs +36 -0
  326. package/dist/drizzle/passkey-model.mjs.map +1 -0
  327. package/dist/drizzle/passkey-registration-ceremony-model.d.mts +50 -0
  328. package/dist/drizzle/passkey-registration-ceremony-model.mjs +18 -0
  329. package/dist/drizzle/passkey-registration-ceremony-model.mjs.map +1 -0
  330. package/dist/drizzle/passkey-registration-ceremony.mjs +124 -0
  331. package/dist/drizzle/passkey-registration-ceremony.mjs.map +1 -0
  332. package/dist/drizzle/passkey-registration-custody.mjs +51 -0
  333. package/dist/drizzle/passkey-registration-custody.mjs.map +1 -0
  334. package/dist/drizzle/passkey-registration-write.mjs +205 -0
  335. package/dist/drizzle/passkey-registration-write.mjs.map +1 -0
  336. package/dist/drizzle/passkey-state.d.mts +5 -0
  337. package/dist/drizzle/passkey-state.mjs +207 -0
  338. package/dist/drizzle/passkey-state.mjs.map +1 -0
  339. package/dist/drizzle/passkey-target.d.mts +16 -0
  340. package/dist/drizzle/passkey-target.mjs +174 -0
  341. package/dist/drizzle/passkey-target.mjs.map +1 -0
  342. package/dist/drizzle/passkey-write-drivers.mjs +33 -0
  343. package/dist/drizzle/passkey-write-drivers.mjs.map +1 -0
  344. package/dist/drizzle/passkey-write-model.d.mts +192 -0
  345. package/dist/drizzle/passkey-write-model.mjs +13 -0
  346. package/dist/drizzle/passkey-write-model.mjs.map +1 -0
  347. package/dist/drizzle/passkey-write-state.mjs +326 -0
  348. package/dist/drizzle/passkey-write-state.mjs.map +1 -0
  349. package/dist/drizzle/passkey-write-target.d.mts +14 -0
  350. package/dist/drizzle/passkey-write-target.mjs +185 -0
  351. package/dist/drizzle/passkey-write-target.mjs.map +1 -0
  352. package/dist/drizzle/password-model.d.mts +330 -0
  353. package/dist/drizzle/password-model.mjs +22 -0
  354. package/dist/drizzle/password-model.mjs.map +1 -0
  355. package/dist/drizzle/password-prepared-model.d.mts +93 -0
  356. package/dist/drizzle/password-prepared-model.mjs +11 -0
  357. package/dist/drizzle/password-prepared-model.mjs.map +1 -0
  358. package/dist/drizzle/password-prepared-sql.mjs +394 -0
  359. package/dist/drizzle/password-prepared-sql.mjs.map +1 -0
  360. package/dist/drizzle/password-prepared-state.mjs +107 -0
  361. package/dist/drizzle/password-prepared-state.mjs.map +1 -0
  362. package/dist/drizzle/password-prepared-target.d.mts +12 -0
  363. package/dist/drizzle/password-prepared-target.mjs +57 -0
  364. package/dist/drizzle/password-prepared-target.mjs.map +1 -0
  365. package/dist/drizzle/password-registration.d.mts +23 -0
  366. package/dist/drizzle/password-registration.mjs +136 -0
  367. package/dist/drizzle/password-registration.mjs.map +1 -0
  368. package/dist/drizzle/password-sql.d.mts +20 -0
  369. package/dist/drizzle/password-sql.mjs +702 -0
  370. package/dist/drizzle/password-sql.mjs.map +1 -0
  371. package/dist/drizzle/password-target.d.mts +25 -0
  372. package/dist/drizzle/password-target.mjs +63 -0
  373. package/dist/drizzle/password-target.mjs.map +1 -0
  374. package/dist/drizzle/pg-emails.d.mts +83 -0
  375. package/dist/drizzle/pg-emails.mjs +38 -0
  376. package/dist/drizzle/pg-emails.mjs.map +1 -0
  377. package/dist/drizzle/pg-password-prepared.d.mts +33 -0
  378. package/dist/drizzle/pg-password-prepared.mjs +16 -0
  379. package/dist/drizzle/pg-password-prepared.mjs.map +1 -0
  380. package/dist/drizzle/pg-passwords.d.mts +103 -0
  381. package/dist/drizzle/pg-passwords.mjs +38 -0
  382. package/dist/drizzle/pg-passwords.mjs.map +1 -0
  383. package/dist/drizzle/pg-proofs.d.mts +84 -0
  384. package/dist/drizzle/pg-proofs.mjs +22 -0
  385. package/dist/drizzle/pg-proofs.mjs.map +1 -0
  386. package/dist/drizzle/pg-sessions.d.mts +251 -0
  387. package/dist/drizzle/pg-sessions.mjs +53 -0
  388. package/dist/drizzle/pg-sessions.mjs.map +1 -0
  389. package/dist/drizzle/pg.d.mts +88 -0
  390. package/dist/drizzle/pg.mjs +294 -0
  391. package/dist/drizzle/pg.mjs.map +1 -0
  392. package/dist/drizzle/phone-model.d.mts +117 -0
  393. package/dist/drizzle/phone-model.mjs +39 -0
  394. package/dist/drizzle/phone-model.mjs.map +1 -0
  395. package/dist/drizzle/phone-state.mjs +426 -0
  396. package/dist/drizzle/phone-state.mjs.map +1 -0
  397. package/dist/drizzle/phone-target.d.mts +19 -0
  398. package/dist/drizzle/phone-target.mjs +171 -0
  399. package/dist/drizzle/phone-target.mjs.map +1 -0
  400. package/dist/drizzle/proof-model.d.mts +287 -0
  401. package/dist/drizzle/proof-model.mjs +17 -0
  402. package/dist/drizzle/proof-model.mjs.map +1 -0
  403. package/dist/drizzle/proof-sql.d.mts +16 -0
  404. package/dist/drizzle/proof-sql.mjs +618 -0
  405. package/dist/drizzle/proof-sql.mjs.map +1 -0
  406. package/dist/drizzle/proof-target.d.mts +17 -0
  407. package/dist/drizzle/proof-target.mjs +38 -0
  408. package/dist/drizzle/proof-target.mjs.map +1 -0
  409. package/dist/drizzle/session-model.d.mts +201 -0
  410. package/dist/drizzle/session-model.mjs +19 -0
  411. package/dist/drizzle/session-model.mjs.map +1 -0
  412. package/dist/drizzle/session-sql.mjs +732 -0
  413. package/dist/drizzle/session-sql.mjs.map +1 -0
  414. package/dist/drizzle/session-target.d.mts +37 -0
  415. package/dist/drizzle/session-target.mjs +47 -0
  416. package/dist/drizzle/session-target.mjs.map +1 -0
  417. package/dist/drizzle/sqlite-emails.mjs +45 -0
  418. package/dist/drizzle/sqlite-emails.mjs.map +1 -0
  419. package/dist/drizzle/sqlite-identity.mjs +92 -0
  420. package/dist/drizzle/sqlite-identity.mjs.map +1 -0
  421. package/dist/drizzle/sqlite-password-prepared.mjs +21 -0
  422. package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -0
  423. package/dist/drizzle/sqlite-passwords.mjs +49 -0
  424. package/dist/drizzle/sqlite-passwords.mjs.map +1 -0
  425. package/dist/drizzle/sqlite-proofs.mjs +29 -0
  426. package/dist/drizzle/sqlite-proofs.mjs.map +1 -0
  427. package/dist/drizzle/sqlite-sessions.mjs +74 -0
  428. package/dist/drizzle/sqlite-sessions.mjs.map +1 -0
  429. package/dist/drizzle/sqlite.d.mts +81 -0
  430. package/dist/drizzle/sqlite.mjs +220 -0
  431. package/dist/drizzle/sqlite.mjs.map +1 -0
  432. package/dist/drizzle/standalone-guard.mjs +19 -0
  433. package/dist/drizzle/standalone-guard.mjs.map +1 -0
  434. package/dist/drizzle/step-up-model.d.mts +65 -0
  435. package/dist/drizzle/step-up-model.mjs +9 -0
  436. package/dist/drizzle/step-up-model.mjs.map +1 -0
  437. package/dist/drizzle/step-up-state.mjs +34 -0
  438. package/dist/drizzle/step-up-state.mjs.map +1 -0
  439. package/dist/drizzle/totp-model.d.mts +85 -0
  440. package/dist/drizzle/totp-model.mjs +13 -0
  441. package/dist/drizzle/totp-model.mjs.map +1 -0
  442. package/dist/drizzle/totp-state.d.mts +39 -0
  443. package/dist/drizzle/totp-state.mjs +288 -0
  444. package/dist/drizzle/totp-state.mjs.map +1 -0
  445. package/dist/drizzle/totp-target.d.mts +16 -0
  446. package/dist/drizzle/totp-target.mjs +83 -0
  447. package/dist/drizzle/totp-target.mjs.map +1 -0
  448. package/dist/drizzle/transaction-execution.d.mts +20 -0
  449. package/dist/drizzle/transaction-execution.mjs +111 -0
  450. package/dist/drizzle/transaction-execution.mjs.map +1 -0
  451. package/dist/drizzle/transaction-mysql.mjs +46 -0
  452. package/dist/drizzle/transaction-mysql.mjs.map +1 -0
  453. package/dist/drizzle/transaction-owner.d.mts +6 -0
  454. package/dist/drizzle/transaction-owner.mjs +252 -0
  455. package/dist/drizzle/transaction-owner.mjs.map +1 -0
  456. package/dist/email/EmailActionEvidence.d.mts +33 -0
  457. package/dist/email/EmailActionEvidence.mjs +15 -0
  458. package/dist/email/EmailActionEvidence.mjs.map +1 -0
  459. package/dist/email/EmailAddressPersistence.d.mts +63 -0
  460. package/dist/email/EmailAddressPersistence.mjs +19 -0
  461. package/dist/email/EmailAddressPersistence.mjs.map +1 -0
  462. package/dist/email/EmailIdentifierNotifier.d.mts +30 -0
  463. package/dist/email/EmailIdentifierNotifier.mjs +31 -0
  464. package/dist/email/EmailIdentifierNotifier.mjs.map +1 -0
  465. package/dist/email/EmailReturnTargets.d.mts +19 -0
  466. package/dist/email/EmailReturnTargets.mjs +29 -0
  467. package/dist/email/EmailReturnTargets.mjs.map +1 -0
  468. package/dist/email/EmailSignInTargets.d.mts +20 -0
  469. package/dist/email/EmailSignInTargets.mjs +12 -0
  470. package/dist/email/EmailSignInTargets.mjs.map +1 -0
  471. package/dist/email/addresses.d.mts +33 -0
  472. package/dist/email/addresses.mjs +404 -0
  473. package/dist/email/addresses.mjs.map +1 -0
  474. package/dist/email/definition.d.mts +10153 -0
  475. package/dist/email/definition.mjs +111 -0
  476. package/dist/email/definition.mjs.map +1 -0
  477. package/dist/email/errors.d.mts +15 -0
  478. package/dist/email/errors.mjs +11 -0
  479. package/dist/email/errors.mjs.map +1 -0
  480. package/dist/email/magicLink.d.mts +33 -0
  481. package/dist/email/magicLink.mjs +58 -0
  482. package/dist/email/magicLink.mjs.map +1 -0
  483. package/dist/email/models.d.mts +56 -0
  484. package/dist/email/models.mjs +31 -0
  485. package/dist/email/models.mjs.map +1 -0
  486. package/dist/email/module.d.mts +22296 -0
  487. package/dist/email/module.mjs +415 -0
  488. package/dist/email/module.mjs.map +1 -0
  489. package/dist/email/registration.d.mts +28 -0
  490. package/dist/email/registration.mjs +243 -0
  491. package/dist/email/registration.mjs.map +1 -0
  492. package/dist/email/snapshot.mjs +37 -0
  493. package/dist/email/snapshot.mjs.map +1 -0
  494. package/dist/hooks/LifecycleHooks.d.mts +34 -0
  495. package/dist/hooks/LifecycleHooks.mjs +74 -0
  496. package/dist/hooks/LifecycleHooks.mjs.map +1 -0
  497. package/dist/hooks/commit.d.mts +66 -0
  498. package/dist/hooks/commit.mjs +136 -0
  499. package/dist/hooks/commit.mjs.map +1 -0
  500. package/dist/hooks/models.d.mts +51 -0
  501. package/dist/hooks/models.mjs +87 -0
  502. package/dist/hooks/models.mjs.map +1 -0
  503. package/dist/hooks/plugins.d.mts +36 -0
  504. package/dist/hooks/plugins.mjs +60 -0
  505. package/dist/hooks/plugins.mjs.map +1 -0
  506. package/dist/hooks/transactions.d.mts +31 -0
  507. package/dist/hooks/transactions.mjs +38 -0
  508. package/dist/hooks/transactions.mjs.map +1 -0
  509. package/dist/http/auth-api.d.mts +9 -0
  510. package/dist/http/auth-api.mjs +13 -0
  511. package/dist/http/auth-api.mjs.map +1 -0
  512. package/dist/http/auth-contract.d.mts +84 -0
  513. package/dist/http/auth-contract.mjs +75 -0
  514. package/dist/http/auth-contract.mjs.map +1 -0
  515. package/dist/http/auth-http.d.mts +216 -0
  516. package/dist/http/auth-http.mjs +184 -0
  517. package/dist/http/auth-http.mjs.map +1 -0
  518. package/dist/http/endpoints/get-session.d.mts +8 -0
  519. package/dist/http/endpoints/get-session.mjs +12 -0
  520. package/dist/http/endpoints/get-session.mjs.map +1 -0
  521. package/dist/http/endpoints/password-sign-in.d.mts +8 -0
  522. package/dist/http/endpoints/password-sign-in.mjs +18 -0
  523. package/dist/http/endpoints/password-sign-in.mjs.map +1 -0
  524. package/dist/http/endpoints/request-email-otp.d.mts +8 -0
  525. package/dist/http/endpoints/request-email-otp.mjs +17 -0
  526. package/dist/http/endpoints/request-email-otp.mjs.map +1 -0
  527. package/dist/http/endpoints/set-password.d.mts +9 -0
  528. package/dist/http/endpoints/set-password.mjs +19 -0
  529. package/dist/http/endpoints/set-password.mjs.map +1 -0
  530. package/dist/http/endpoints/sign-out.d.mts +6 -0
  531. package/dist/http/endpoints/sign-out.mjs +7 -0
  532. package/dist/http/endpoints/sign-out.mjs.map +1 -0
  533. package/dist/http/endpoints/verify-email-otp.d.mts +9 -0
  534. package/dist/http/endpoints/verify-email-otp.mjs +18 -0
  535. package/dist/http/endpoints/verify-email-otp.mjs.map +1 -0
  536. package/dist/http/models.d.mts +49 -0
  537. package/dist/http/models.mjs +35 -0
  538. package/dist/http/models.mjs.map +1 -0
  539. package/dist/http/security.d.mts +91 -0
  540. package/dist/http/security.mjs +77 -0
  541. package/dist/http/security.mjs.map +1 -0
  542. package/dist/http/session-contract.d.mts +303 -0
  543. package/dist/http/session-contract.mjs +38 -0
  544. package/dist/http/session-contract.mjs.map +1 -0
  545. package/dist/http-operation/OperationHttpInvocation.d.mts +16 -0
  546. package/dist/http-operation/OperationHttpInvocation.mjs +11 -0
  547. package/dist/http-operation/OperationHttpInvocation.mjs.map +1 -0
  548. package/dist/http-operation/OperationHttpServerConfig.d.mts +18 -0
  549. package/dist/http-operation/OperationHttpServerConfig.mjs +72 -0
  550. package/dist/http-operation/OperationHttpServerConfig.mjs.map +1 -0
  551. package/dist/http-operation/auth-client.d.mts +75 -0
  552. package/dist/http-operation/auth-client.mjs +116 -0
  553. package/dist/http-operation/auth-client.mjs.map +1 -0
  554. package/dist/http-operation/client.d.mts +50 -0
  555. package/dist/http-operation/client.mjs +188 -0
  556. package/dist/http-operation/client.mjs.map +1 -0
  557. package/dist/http-operation/configuration-schema.mjs +19 -0
  558. package/dist/http-operation/configuration-schema.mjs.map +1 -0
  559. package/dist/http-operation/contract.d.mts +40 -0
  560. package/dist/http-operation/contract.mjs +37 -0
  561. package/dist/http-operation/contract.mjs.map +1 -0
  562. package/dist/http-operation/errors.d.mts +13 -0
  563. package/dist/http-operation/errors.mjs +31 -0
  564. package/dist/http-operation/errors.mjs.map +1 -0
  565. package/dist/http-operation/models.d.mts +32 -0
  566. package/dist/http-operation/models.mjs +14 -0
  567. package/dist/http-operation/models.mjs.map +1 -0
  568. package/dist/http-operation/private.mjs +35 -0
  569. package/dist/http-operation/private.mjs.map +1 -0
  570. package/dist/http-operation/security.mjs +58 -0
  571. package/dist/http-operation/security.mjs.map +1 -0
  572. package/dist/http-operation/server.d.mts +33 -0
  573. package/dist/http-operation/server.mjs +268 -0
  574. package/dist/http-operation/server.mjs.map +1 -0
  575. package/dist/identity/ExternalIdentityMutation.d.mts +15 -0
  576. package/dist/identity/ExternalIdentityMutation.mjs +11 -0
  577. package/dist/identity/ExternalIdentityMutation.mjs.map +1 -0
  578. package/dist/identity/IdentityMutation.d.mts +22 -0
  579. package/dist/identity/IdentityMutation.mjs +17 -0
  580. package/dist/identity/IdentityMutation.mjs.map +1 -0
  581. package/dist/identity/IdentityRepository.d.mts +20 -0
  582. package/dist/identity/IdentityRepository.mjs +11 -0
  583. package/dist/identity/IdentityRepository.mjs.map +1 -0
  584. package/dist/identity/SubjectLifecycle.d.mts +58 -0
  585. package/dist/identity/SubjectLifecycle.mjs +43 -0
  586. package/dist/identity/SubjectLifecycle.mjs.map +1 -0
  587. package/dist/identity/SubjectProvisioner.d.mts +37 -0
  588. package/dist/identity/SubjectProvisioner.mjs +20 -0
  589. package/dist/identity/SubjectProvisioner.mjs.map +1 -0
  590. package/dist/identity/codecs.d.mts +34 -0
  591. package/dist/identity/codecs.mjs +40 -0
  592. package/dist/identity/codecs.mjs.map +1 -0
  593. package/dist/identity/models.d.mts +62 -0
  594. package/dist/identity/models.mjs +51 -0
  595. package/dist/identity/models.mjs.map +1 -0
  596. package/dist/identity/operations.d.mts +118 -0
  597. package/dist/identity/operations.mjs +124 -0
  598. package/dist/identity/operations.mjs.map +1 -0
  599. package/dist/index.d.mts +23 -0
  600. package/dist/index.mjs +23 -0
  601. package/dist/internal/AuthStoreDecisions.d.mts +22 -0
  602. package/dist/internal/AuthStoreDecisions.mjs +8 -0
  603. package/dist/internal/AuthStoreDecisions.mjs.map +1 -0
  604. package/dist/internal/CurrentSession.d.mts +9 -0
  605. package/dist/internal/CurrentSession.mjs +8 -0
  606. package/dist/internal/CurrentSession.mjs.map +1 -0
  607. package/dist/internal/diagnostics.mjs +23 -0
  608. package/dist/internal/diagnostics.mjs.map +1 -0
  609. package/dist/oauth/GithubOAuthProvider.d.mts +43 -0
  610. package/dist/oauth/GithubOAuthProvider.mjs +66 -0
  611. package/dist/oauth/GithubOAuthProvider.mjs.map +1 -0
  612. package/dist/oauth/OAuth.d.mts +73 -0
  613. package/dist/oauth/OAuth.mjs +180 -0
  614. package/dist/oauth/OAuth.mjs.map +1 -0
  615. package/dist/oauth/OAuthAccountsPersistence.d.mts +109 -0
  616. package/dist/oauth/OAuthAccountsPersistence.mjs +12 -0
  617. package/dist/oauth/OAuthAccountsPersistence.mjs.map +1 -0
  618. package/dist/oauth/OAuthActionEvidence.d.mts +28 -0
  619. package/dist/oauth/OAuthActionEvidence.mjs +15 -0
  620. package/dist/oauth/OAuthActionEvidence.mjs.map +1 -0
  621. package/dist/oauth/OAuthConnectedActionEvidence.d.mts +22 -0
  622. package/dist/oauth/OAuthConnectedActionEvidence.mjs +9 -0
  623. package/dist/oauth/OAuthConnectedActionEvidence.mjs.map +1 -0
  624. package/dist/oauth/OAuthConnectedPersistence.d.mts +129 -0
  625. package/dist/oauth/OAuthConnectedPersistence.mjs +12 -0
  626. package/dist/oauth/OAuthConnectedPersistence.mjs.map +1 -0
  627. package/dist/oauth/OAuthConnectedProtocol.d.mts +41 -0
  628. package/dist/oauth/OAuthConnectedProtocol.mjs +13 -0
  629. package/dist/oauth/OAuthConnectedProtocol.mjs.map +1 -0
  630. package/dist/oauth/OAuthConnectedRevocations.d.mts +167 -0
  631. package/dist/oauth/OAuthConnectedRevocations.mjs +21 -0
  632. package/dist/oauth/OAuthConnectedRevocations.mjs.map +1 -0
  633. package/dist/oauth/OAuthConnectedTokenProtector.d.mts +24 -0
  634. package/dist/oauth/OAuthConnectedTokenProtector.mjs +153 -0
  635. package/dist/oauth/OAuthConnectedTokenProtector.mjs.map +1 -0
  636. package/dist/oauth/OAuthConnectedTransactionProtector.d.mts +23 -0
  637. package/dist/oauth/OAuthConnectedTransactionProtector.mjs +37 -0
  638. package/dist/oauth/OAuthConnectedTransactionProtector.mjs.map +1 -0
  639. package/dist/oauth/OAuthConnectedUseAuthority.d.mts +22 -0
  640. package/dist/oauth/OAuthConnectedUseAuthority.mjs +10 -0
  641. package/dist/oauth/OAuthConnectedUseAuthority.mjs.map +1 -0
  642. package/dist/oauth/OAuthConnectionStore.d.mts +33 -0
  643. package/dist/oauth/OAuthConnectionStore.mjs +38 -0
  644. package/dist/oauth/OAuthConnectionStore.mjs.map +1 -0
  645. package/dist/oauth/OAuthLinkTransactionProtector.d.mts +25 -0
  646. package/dist/oauth/OAuthLinkTransactionProtector.mjs +39 -0
  647. package/dist/oauth/OAuthLinkTransactionProtector.mjs.map +1 -0
  648. package/dist/oauth/OAuthProtocol.d.mts +33 -0
  649. package/dist/oauth/OAuthProtocol.mjs +16 -0
  650. package/dist/oauth/OAuthProtocol.mjs.map +1 -0
  651. package/dist/oauth/OAuthProvider.d.mts +70 -0
  652. package/dist/oauth/OAuthProvider.mjs +39 -0
  653. package/dist/oauth/OAuthProvider.mjs.map +1 -0
  654. package/dist/oauth/OAuthProviders.d.mts +27 -0
  655. package/dist/oauth/OAuthProviders.mjs +33 -0
  656. package/dist/oauth/OAuthProviders.mjs.map +1 -0
  657. package/dist/oauth/OAuthRegistrationIntents.d.mts +87 -0
  658. package/dist/oauth/OAuthRegistrationIntents.mjs +19 -0
  659. package/dist/oauth/OAuthRegistrationIntents.mjs.map +1 -0
  660. package/dist/oauth/OAuthReturnTargets.d.mts +15 -0
  661. package/dist/oauth/OAuthReturnTargets.mjs +24 -0
  662. package/dist/oauth/OAuthReturnTargets.mjs.map +1 -0
  663. package/dist/oauth/OAuthSignInPersistence.d.mts +68 -0
  664. package/dist/oauth/OAuthSignInPersistence.mjs +12 -0
  665. package/dist/oauth/OAuthSignInPersistence.mjs.map +1 -0
  666. package/dist/oauth/OAuthStateDecisions.d.mts +14 -0
  667. package/dist/oauth/OAuthStateDecisions.mjs +8 -0
  668. package/dist/oauth/OAuthStateDecisions.mjs.map +1 -0
  669. package/dist/oauth/OAuthStateStore.d.mts +35 -0
  670. package/dist/oauth/OAuthStateStore.mjs +64 -0
  671. package/dist/oauth/OAuthStateStore.mjs.map +1 -0
  672. package/dist/oauth/OAuthTransactionProtector.d.mts +26 -0
  673. package/dist/oauth/OAuthTransactionProtector.mjs +78 -0
  674. package/dist/oauth/OAuthTransactionProtector.mjs.map +1 -0
  675. package/dist/oauth/accounts.d.mts +29 -0
  676. package/dist/oauth/accounts.mjs +515 -0
  677. package/dist/oauth/accounts.mjs.map +1 -0
  678. package/dist/oauth/accountsModels.d.mts +463 -0
  679. package/dist/oauth/accountsModels.mjs +155 -0
  680. package/dist/oauth/accountsModels.mjs.map +1 -0
  681. package/dist/oauth/connected.d.mts +442 -0
  682. package/dist/oauth/connected.mjs +526 -0
  683. package/dist/oauth/connected.mjs.map +1 -0
  684. package/dist/oauth/connectedAccess.d.mts +20 -0
  685. package/dist/oauth/connectedAccess.mjs +279 -0
  686. package/dist/oauth/connectedAccess.mjs.map +1 -0
  687. package/dist/oauth/connectedMaintenance.d.mts +19 -0
  688. package/dist/oauth/connectedMaintenance.mjs +133 -0
  689. package/dist/oauth/connectedMaintenance.mjs.map +1 -0
  690. package/dist/oauth/connectedModels.d.mts +2023 -0
  691. package/dist/oauth/connectedModels.mjs +375 -0
  692. package/dist/oauth/connectedModels.mjs.map +1 -0
  693. package/dist/oauth/definition.d.mts +4396 -0
  694. package/dist/oauth/definition.mjs +120 -0
  695. package/dist/oauth/definition.mjs.map +1 -0
  696. package/dist/oauth/errors.d.mts +49 -0
  697. package/dist/oauth/errors.mjs +42 -0
  698. package/dist/oauth/errors.mjs.map +1 -0
  699. package/dist/oauth/github/identity.d.mts +8 -0
  700. package/dist/oauth/github/identity.mjs +24 -0
  701. package/dist/oauth/github/identity.mjs.map +1 -0
  702. package/dist/oauth/github/models.d.mts +34 -0
  703. package/dist/oauth/github/protocol.d.mts +54 -0
  704. package/dist/oauth/github/protocol.mjs +204 -0
  705. package/dist/oauth/github/protocol.mjs.map +1 -0
  706. package/dist/oauth/openid-client/ProviderRevocation.d.mts +4 -0
  707. package/dist/oauth/openid-client/ProviderRevocation.mjs +11 -0
  708. package/dist/oauth/openid-client/ProviderRevocation.mjs.map +1 -0
  709. package/dist/oauth/openid-client/compatibility.d.mts +1 -0
  710. package/dist/oauth/openid-client/compatibility.mjs +6 -0
  711. package/dist/oauth/openid-client/compatibility.mjs.map +1 -0
  712. package/dist/oauth/openid-client/configuration.mjs +305 -0
  713. package/dist/oauth/openid-client/configuration.mjs.map +1 -0
  714. package/dist/oauth/openid-client/connected/configuration.mjs +338 -0
  715. package/dist/oauth/openid-client/connected/configuration.mjs.map +1 -0
  716. package/dist/oauth/openid-client/connected/models.d.mts +42 -0
  717. package/dist/oauth/openid-client/connected/protocol.d.mts +16 -0
  718. package/dist/oauth/openid-client/connected/protocol.mjs +402 -0
  719. package/dist/oauth/openid-client/connected/protocol.mjs.map +1 -0
  720. package/dist/oauth/openid-client/models.d.mts +67 -0
  721. package/dist/oauth/openid-client/models.mjs +16 -0
  722. package/dist/oauth/openid-client/models.mjs.map +1 -0
  723. package/dist/oauth/openid-client/protocol.d.mts +27 -0
  724. package/dist/oauth/openid-client/protocol.mjs +218 -0
  725. package/dist/oauth/openid-client/protocol.mjs.map +1 -0
  726. package/dist/oauth/openid-client/transport.mjs +59 -0
  727. package/dist/oauth/openid-client/transport.mjs.map +1 -0
  728. package/dist/oauth/policy.d.mts +18 -0
  729. package/dist/oauth/policy.mjs +16 -0
  730. package/dist/oauth/policy.mjs.map +1 -0
  731. package/dist/oauth/registration.d.mts +24 -0
  732. package/dist/oauth/registration.mjs +177 -0
  733. package/dist/oauth/registration.mjs.map +1 -0
  734. package/dist/oauth/registrationModels.d.mts +152 -0
  735. package/dist/oauth/registrationModels.mjs +93 -0
  736. package/dist/oauth/registrationModels.mjs.map +1 -0
  737. package/dist/oauth/registrationSecrets.mjs +70 -0
  738. package/dist/oauth/registrationSecrets.mjs.map +1 -0
  739. package/dist/oauth/schema.d.mts +86 -0
  740. package/dist/oauth/schema.mjs +81 -0
  741. package/dist/oauth/schema.mjs.map +1 -0
  742. package/dist/oauth/signInErrors.d.mts +17 -0
  743. package/dist/oauth/signInErrors.mjs +16 -0
  744. package/dist/oauth/signInErrors.mjs.map +1 -0
  745. package/dist/oauth/signInModels.d.mts +343 -0
  746. package/dist/oauth/signInModels.mjs +181 -0
  747. package/dist/oauth/signInModels.mjs.map +1 -0
  748. package/dist/oauth/signInModule.d.mts +1546 -0
  749. package/dist/oauth/signInModule.mjs +430 -0
  750. package/dist/oauth/signInModule.mjs.map +1 -0
  751. package/dist/oauth/signInSnapshot.mjs +29 -0
  752. package/dist/oauth/signInSnapshot.mjs.map +1 -0
  753. package/dist/oauth/transactionEncryption.d.mts +14 -0
  754. package/dist/oauth/transactionEncryption.mjs +129 -0
  755. package/dist/oauth/transactionEncryption.mjs.map +1 -0
  756. package/dist/operations/RequestBindingConfig.d.mts +11 -0
  757. package/dist/operations/RequestBindingConfig.mjs +10 -0
  758. package/dist/operations/RequestBindingConfig.mjs.map +1 -0
  759. package/dist/operations/actions.d.mts +947 -0
  760. package/dist/operations/actions.mjs +148 -0
  761. package/dist/operations/actions.mjs.map +1 -0
  762. package/dist/operations/context.d.mts +63 -0
  763. package/dist/operations/context.mjs +55 -0
  764. package/dist/operations/context.mjs.map +1 -0
  765. package/dist/operations/credentials.d.mts +39 -0
  766. package/dist/operations/credentials.mjs +60 -0
  767. package/dist/operations/credentials.mjs.map +1 -0
  768. package/dist/operations/errors.d.mts +24 -0
  769. package/dist/operations/errors.mjs +31 -0
  770. package/dist/operations/errors.mjs.map +1 -0
  771. package/dist/operations/operation.d.mts +124 -0
  772. package/dist/operations/operation.mjs +220 -0
  773. package/dist/operations/operation.mjs.map +1 -0
  774. package/dist/operations/requestBinding.d.mts +46 -0
  775. package/dist/operations/requestBinding.mjs +130 -0
  776. package/dist/operations/requestBinding.mjs.map +1 -0
  777. package/dist/operations/requestBindingModels.d.mts +13 -0
  778. package/dist/operations/requestBindingModels.mjs +12 -0
  779. package/dist/operations/requestBindingModels.mjs.map +1 -0
  780. package/dist/operations/reveals.d.mts +28 -0
  781. package/dist/operations/reveals.mjs +88 -0
  782. package/dist/operations/reveals.mjs.map +1 -0
  783. package/dist/passkey/PasskeyActionEvidence.d.mts +22 -0
  784. package/dist/passkey/PasskeyActionEvidence.mjs +9 -0
  785. package/dist/passkey/PasskeyActionEvidence.mjs.map +1 -0
  786. package/dist/passkey/PasskeyCredentials.d.mts +16 -0
  787. package/dist/passkey/PasskeyCredentials.mjs +9 -0
  788. package/dist/passkey/PasskeyCredentials.mjs.map +1 -0
  789. package/dist/passkey/PasskeyEnrollmentContext.d.mts +22 -0
  790. package/dist/passkey/PasskeyEnrollmentContext.mjs +9 -0
  791. package/dist/passkey/PasskeyEnrollmentContext.mjs.map +1 -0
  792. package/dist/passkey/PasskeyManagementPersistence.d.mts +106 -0
  793. package/dist/passkey/PasskeyManagementPersistence.mjs +9 -0
  794. package/dist/passkey/PasskeyManagementPersistence.mjs.map +1 -0
  795. package/dist/passkey/PasskeyPersistence.d.mts +63 -0
  796. package/dist/passkey/PasskeyPersistence.mjs +10 -0
  797. package/dist/passkey/PasskeyPersistence.mjs.map +1 -0
  798. package/dist/passkey/PasskeyProtocol.d.mts +38 -0
  799. package/dist/passkey/PasskeyProtocol.mjs +11 -0
  800. package/dist/passkey/PasskeyProtocol.mjs.map +1 -0
  801. package/dist/passkey/actions.d.mts +50 -0
  802. package/dist/passkey/actions.mjs +376 -0
  803. package/dist/passkey/actions.mjs.map +1 -0
  804. package/dist/passkey/browser/PasskeyBrowser.d.mts +18 -0
  805. package/dist/passkey/browser/PasskeyBrowser.mjs +9 -0
  806. package/dist/passkey/browser/PasskeyBrowser.mjs.map +1 -0
  807. package/dist/passkey/browser/models.d.mts +38 -0
  808. package/dist/passkey/browser/models.mjs +41 -0
  809. package/dist/passkey/browser/models.mjs.map +1 -0
  810. package/dist/passkey/browser/simplewebauthn.d.mts +17 -0
  811. package/dist/passkey/browser/simplewebauthn.mjs +411 -0
  812. package/dist/passkey/browser/simplewebauthn.mjs.map +1 -0
  813. package/dist/passkey/definition.d.mts +5626 -0
  814. package/dist/passkey/definition.mjs +114 -0
  815. package/dist/passkey/definition.mjs.map +1 -0
  816. package/dist/passkey/errors.d.mts +20 -0
  817. package/dist/passkey/errors.mjs +20 -0
  818. package/dist/passkey/errors.mjs.map +1 -0
  819. package/dist/passkey/management.mjs +276 -0
  820. package/dist/passkey/management.mjs.map +1 -0
  821. package/dist/passkey/models.d.mts +1245 -0
  822. package/dist/passkey/models.mjs +301 -0
  823. package/dist/passkey/models.mjs.map +1 -0
  824. package/dist/passkey/module.d.mts +2132 -0
  825. package/dist/passkey/module.mjs +174 -0
  826. package/dist/passkey/module.mjs.map +1 -0
  827. package/dist/passkey/pending.mjs +99 -0
  828. package/dist/passkey/pending.mjs.map +1 -0
  829. package/dist/passkey/policy.d.mts +48 -0
  830. package/dist/passkey/policy.mjs +77 -0
  831. package/dist/passkey/policy.mjs.map +1 -0
  832. package/dist/passkey/registration.mjs +107 -0
  833. package/dist/passkey/registration.mjs.map +1 -0
  834. package/dist/passkey/simplewebauthn/configuration.mjs +45 -0
  835. package/dist/passkey/simplewebauthn/configuration.mjs.map +1 -0
  836. package/dist/passkey/simplewebauthn/models.d.mts +21 -0
  837. package/dist/passkey/simplewebauthn/models.mjs +8 -0
  838. package/dist/passkey/simplewebauthn/models.mjs.map +1 -0
  839. package/dist/passkey/simplewebauthn/protocol.d.mts +62 -0
  840. package/dist/passkey/simplewebauthn/protocol.mjs +402 -0
  841. package/dist/passkey/simplewebauthn/protocol.mjs.map +1 -0
  842. package/dist/passkey/snapshot.mjs +31 -0
  843. package/dist/passkey/snapshot.mjs.map +1 -0
  844. package/dist/passkey/stepUp.mjs +101 -0
  845. package/dist/passkey/stepUp.mjs.map +1 -0
  846. package/dist/password/CompromisedPasswords.d.mts +26 -0
  847. package/dist/password/CompromisedPasswords.mjs +23 -0
  848. package/dist/password/CompromisedPasswords.mjs.map +1 -0
  849. package/dist/password/NewPasswordCheck.d.mts +21 -0
  850. package/dist/password/NewPasswordCheck.mjs +39 -0
  851. package/dist/password/NewPasswordCheck.mjs.map +1 -0
  852. package/dist/password/PasswordHashing.d.mts +24 -0
  853. package/dist/password/PasswordHashing.mjs +96 -0
  854. package/dist/password/PasswordHashing.mjs.map +1 -0
  855. package/dist/password/PasswordKdfAdmission.d.mts +19 -0
  856. package/dist/password/PasswordKdfAdmission.mjs +25 -0
  857. package/dist/password/PasswordKdfAdmission.mjs.map +1 -0
  858. package/dist/password/configuration.d.mts +43 -0
  859. package/dist/password/configuration.mjs +64 -0
  860. package/dist/password/configuration.mjs.map +1 -0
  861. package/dist/password/defaults.mjs +13 -0
  862. package/dist/password/defaults.mjs.map +1 -0
  863. package/dist/password/encoding.mjs +64 -0
  864. package/dist/password/encoding.mjs.map +1 -0
  865. package/dist/password/errors.d.mts +28 -0
  866. package/dist/password/errors.mjs +25 -0
  867. package/dist/password/errors.mjs.map +1 -0
  868. package/dist/password/methods/PasswordActionEvidence.d.mts +38 -0
  869. package/dist/password/methods/PasswordActionEvidence.mjs +22 -0
  870. package/dist/password/methods/PasswordActionEvidence.mjs.map +1 -0
  871. package/dist/password/methods/PasswordPersistence.d.mts +102 -0
  872. package/dist/password/methods/PasswordPersistence.mjs +13 -0
  873. package/dist/password/methods/PasswordPersistence.mjs.map +1 -0
  874. package/dist/password/methods/PasswordPreparedPersistence.d.mts +111 -0
  875. package/dist/password/methods/contracts.d.mts +43 -0
  876. package/dist/password/methods/contracts.mjs +33 -0
  877. package/dist/password/methods/contracts.mjs.map +1 -0
  878. package/dist/password/methods/definition.d.mts +3813 -0
  879. package/dist/password/methods/definition.mjs +56 -0
  880. package/dist/password/methods/definition.mjs.map +1 -0
  881. package/dist/password/methods/errors.d.mts +15 -0
  882. package/dist/password/methods/errors.mjs +11 -0
  883. package/dist/password/methods/errors.mjs.map +1 -0
  884. package/dist/password/methods/models.d.mts +70 -0
  885. package/dist/password/methods/models.mjs +44 -0
  886. package/dist/password/methods/models.mjs.map +1 -0
  887. package/dist/password/methods/module.d.mts +3567 -0
  888. package/dist/password/methods/module.mjs +553 -0
  889. package/dist/password/methods/module.mjs.map +1 -0
  890. package/dist/password/methods/policy.d.mts +84 -0
  891. package/dist/password/methods/policy.mjs +80 -0
  892. package/dist/password/methods/policy.mjs.map +1 -0
  893. package/dist/password/methods/preparation.mjs +54 -0
  894. package/dist/password/methods/preparation.mjs.map +1 -0
  895. package/dist/password/methods/prepared.d.mts +53 -0
  896. package/dist/password/methods/prepared.mjs +610 -0
  897. package/dist/password/methods/prepared.mjs.map +1 -0
  898. package/dist/password/methods/preparedModels.d.mts +1295 -0
  899. package/dist/password/methods/preparedModels.mjs +278 -0
  900. package/dist/password/methods/preparedModels.mjs.map +1 -0
  901. package/dist/password/methods/signIn.d.mts +180 -0
  902. package/dist/password/methods/signIn.mjs +73 -0
  903. package/dist/password/methods/signIn.mjs.map +1 -0
  904. package/dist/password/methods/snapshot.mjs +38 -0
  905. package/dist/password/methods/snapshot.mjs.map +1 -0
  906. package/dist/password/methods/verification.mjs +138 -0
  907. package/dist/password/methods/verification.mjs.map +1 -0
  908. package/dist/password/models.d.mts +13 -0
  909. package/dist/password/models.mjs +12 -0
  910. package/dist/password/models.mjs.map +1 -0
  911. package/dist/password/policy.d.mts +33 -0
  912. package/dist/password/policy.mjs +37 -0
  913. package/dist/password/policy.mjs.map +1 -0
  914. package/dist/phone/PhoneActionEvidence.d.mts +23 -0
  915. package/dist/phone/PhoneActionEvidence.mjs +10 -0
  916. package/dist/phone/PhoneActionEvidence.mjs.map +1 -0
  917. package/dist/phone/PhoneAdmission.d.mts +29 -0
  918. package/dist/phone/PhoneAdmission.mjs +10 -0
  919. package/dist/phone/PhoneAdmission.mjs.map +1 -0
  920. package/dist/phone/PhoneDeliveryEligibility.d.mts +11 -0
  921. package/dist/phone/PhoneDeliveryEligibility.mjs +8 -0
  922. package/dist/phone/PhoneDeliveryEligibility.mjs.map +1 -0
  923. package/dist/phone/PhonePersistence.d.mts +33 -0
  924. package/dist/phone/PhonePersistence.mjs +10 -0
  925. package/dist/phone/PhonePersistence.mjs.map +1 -0
  926. package/dist/phone/PhoneRequestContext.d.mts +10 -0
  927. package/dist/phone/PhoneRequestContext.mjs +8 -0
  928. package/dist/phone/PhoneRequestContext.mjs.map +1 -0
  929. package/dist/phone/PhoneSignInTargets.d.mts +19 -0
  930. package/dist/phone/PhoneSignInTargets.mjs +13 -0
  931. package/dist/phone/PhoneSignInTargets.mjs.map +1 -0
  932. package/dist/phone/definition.d.mts +7190 -0
  933. package/dist/phone/definition.mjs +28 -0
  934. package/dist/phone/definition.mjs.map +1 -0
  935. package/dist/phone/failure.mjs +23 -0
  936. package/dist/phone/failure.mjs.map +1 -0
  937. package/dist/phone/lifecycle.mjs +427 -0
  938. package/dist/phone/lifecycle.mjs.map +1 -0
  939. package/dist/phone/lifecycleModels.d.mts +164 -0
  940. package/dist/phone/lifecycleModels.mjs +91 -0
  941. package/dist/phone/lifecycleModels.mjs.map +1 -0
  942. package/dist/phone/models.d.mts +41 -0
  943. package/dist/phone/models.mjs +29 -0
  944. package/dist/phone/models.mjs.map +1 -0
  945. package/dist/phone/module.d.mts +6027 -0
  946. package/dist/phone/module.mjs +293 -0
  947. package/dist/phone/module.mjs.map +1 -0
  948. package/dist/proofs/EmailProofDelivery.d.mts +13 -0
  949. package/dist/proofs/EmailProofDelivery.mjs +11 -0
  950. package/dist/proofs/EmailProofDelivery.mjs.map +1 -0
  951. package/dist/proofs/HostIngressLimiter.d.mts +20 -0
  952. package/dist/proofs/HostIngressLimiter.mjs +13 -0
  953. package/dist/proofs/HostIngressLimiter.mjs.map +1 -0
  954. package/dist/proofs/ProofPersistence.d.mts +140 -0
  955. package/dist/proofs/ProofPersistence.mjs +13 -0
  956. package/dist/proofs/ProofPersistence.mjs.map +1 -0
  957. package/dist/proofs/SmsProofDelivery.d.mts +13 -0
  958. package/dist/proofs/SmsProofDelivery.mjs +11 -0
  959. package/dist/proofs/SmsProofDelivery.mjs.map +1 -0
  960. package/dist/proofs/abuse.d.mts +15 -0
  961. package/dist/proofs/abuse.mjs +12 -0
  962. package/dist/proofs/abuse.mjs.map +1 -0
  963. package/dist/proofs/completion.d.mts +22 -0
  964. package/dist/proofs/crypto.d.mts +196 -0
  965. package/dist/proofs/crypto.mjs +189 -0
  966. package/dist/proofs/crypto.mjs.map +1 -0
  967. package/dist/proofs/definition.d.mts +335 -0
  968. package/dist/proofs/definition.mjs +10 -0
  969. package/dist/proofs/definition.mjs.map +1 -0
  970. package/dist/proofs/delivery.d.mts +30 -0
  971. package/dist/proofs/delivery.mjs +26 -0
  972. package/dist/proofs/delivery.mjs.map +1 -0
  973. package/dist/proofs/dispatch.d.mts +20 -0
  974. package/dist/proofs/dispatch.mjs +54 -0
  975. package/dist/proofs/dispatch.mjs.map +1 -0
  976. package/dist/proofs/errors.d.mts +21 -0
  977. package/dist/proofs/errors.mjs +25 -0
  978. package/dist/proofs/errors.mjs.map +1 -0
  979. package/dist/proofs/models.d.mts +141 -0
  980. package/dist/proofs/models.mjs +93 -0
  981. package/dist/proofs/models.mjs.map +1 -0
  982. package/dist/proofs/module.d.mts +344 -0
  983. package/dist/proofs/module.mjs +350 -0
  984. package/dist/proofs/module.mjs.map +1 -0
  985. package/dist/proofs/policy.d.mts +152 -0
  986. package/dist/proofs/policy.mjs +51 -0
  987. package/dist/proofs/policy.mjs.map +1 -0
  988. package/dist/sessions/AuthenticationAuthority.d.mts +31 -0
  989. package/dist/sessions/AuthenticationAuthority.mjs +8 -0
  990. package/dist/sessions/AuthenticationAuthority.mjs.map +1 -0
  991. package/dist/sessions/PendingAuthentication.d.mts +108 -0
  992. package/dist/sessions/PendingAuthentication.mjs +40 -0
  993. package/dist/sessions/PendingAuthentication.mjs.map +1 -0
  994. package/dist/sessions/SessionStepUpPersistence.d.mts +152 -0
  995. package/dist/sessions/SessionStepUpPersistence.mjs +63 -0
  996. package/dist/sessions/SessionStepUpPersistence.mjs.map +1 -0
  997. package/dist/sessions/assurance.d.mts +163 -0
  998. package/dist/sessions/assurance.mjs +95 -0
  999. package/dist/sessions/assurance.mjs.map +1 -0
  1000. package/dist/sessions/commit.d.mts +13 -0
  1001. package/dist/sessions/configuration.d.mts +46 -0
  1002. package/dist/sessions/configuration.mjs +55 -0
  1003. package/dist/sessions/configuration.mjs.map +1 -0
  1004. package/dist/sessions/contract.d.mts +663 -0
  1005. package/dist/sessions/contract.mjs +174 -0
  1006. package/dist/sessions/contract.mjs.map +1 -0
  1007. package/dist/sessions/crypto.d.mts +24 -0
  1008. package/dist/sessions/crypto.mjs +106 -0
  1009. package/dist/sessions/crypto.mjs.map +1 -0
  1010. package/dist/sessions/definition.d.mts +11 -0
  1011. package/dist/sessions/definition.mjs +10 -0
  1012. package/dist/sessions/definition.mjs.map +1 -0
  1013. package/dist/sessions/errors.d.mts +35 -0
  1014. package/dist/sessions/errors.mjs +34 -0
  1015. package/dist/sessions/errors.mjs.map +1 -0
  1016. package/dist/sessions/invalidation.d.mts +23 -0
  1017. package/dist/sessions/invalidation.mjs +33 -0
  1018. package/dist/sessions/invalidation.mjs.map +1 -0
  1019. package/dist/sessions/models.d.mts +143 -0
  1020. package/dist/sessions/models.mjs +94 -0
  1021. package/dist/sessions/models.mjs.map +1 -0
  1022. package/dist/sessions/module.d.mts +1091 -0
  1023. package/dist/sessions/module.mjs +943 -0
  1024. package/dist/sessions/module.mjs.map +1 -0
  1025. package/dist/sessions/persistence.d.mts +93 -0
  1026. package/dist/sessions/policy.d.mts +80 -0
  1027. package/dist/sessions/policy.mjs +66 -0
  1028. package/dist/sessions/policy.mjs.map +1 -0
  1029. package/dist/testing/conformance/AuthStore.d.mts +11 -0
  1030. package/dist/testing/conformance/AuthStore.mjs +173 -0
  1031. package/dist/testing/conformance/AuthStore.mjs.map +1 -0
  1032. package/dist/testing/conformance/OAuthConnectionStore.d.mts +11 -0
  1033. package/dist/testing/conformance/OAuthConnectionStore.mjs +102 -0
  1034. package/dist/testing/conformance/OAuthConnectionStore.mjs.map +1 -0
  1035. package/dist/testing/conformance/OAuthStateStore.d.mts +11 -0
  1036. package/dist/testing/conformance/OAuthStateStore.mjs +45 -0
  1037. package/dist/testing/conformance/OAuthStateStore.mjs.map +1 -0
  1038. package/dist/testing/conformance/PasswordCredentialStore.d.mts +20 -0
  1039. package/dist/testing/conformance/PasswordCredentialStore.mjs +103 -0
  1040. package/dist/testing/conformance/PasswordCredentialStore.mjs.map +1 -0
  1041. package/dist/testing/conformance/support.mjs +17 -0
  1042. package/dist/testing/conformance/support.mjs.map +1 -0
  1043. package/dist/testing/crypto.d.mts +11 -0
  1044. package/dist/testing/crypto.mjs +41 -0
  1045. package/dist/testing/crypto.mjs.map +1 -0
  1046. package/dist/testing/keyring.d.mts +9 -0
  1047. package/dist/testing/keyring.mjs +17 -0
  1048. package/dist/testing/keyring.mjs.map +1 -0
  1049. package/dist/totp/TotpActionEvidence.d.mts +18 -0
  1050. package/dist/totp/TotpActionEvidence.mjs +8 -0
  1051. package/dist/totp/TotpActionEvidence.mjs.map +1 -0
  1052. package/dist/totp/TotpPersistence.d.mts +19 -0
  1053. package/dist/totp/TotpPersistence.mjs +8 -0
  1054. package/dist/totp/TotpPersistence.mjs.map +1 -0
  1055. package/dist/totp/TotpSecretKeys.d.mts +15 -0
  1056. package/dist/totp/TotpSecretKeys.mjs +8 -0
  1057. package/dist/totp/TotpSecretKeys.mjs.map +1 -0
  1058. package/dist/totp/crypto.mjs +96 -0
  1059. package/dist/totp/crypto.mjs.map +1 -0
  1060. package/dist/totp/definition.d.mts +764 -0
  1061. package/dist/totp/definition.mjs +24 -0
  1062. package/dist/totp/definition.mjs.map +1 -0
  1063. package/dist/totp/errors.d.mts +16 -0
  1064. package/dist/totp/errors.mjs +18 -0
  1065. package/dist/totp/errors.mjs.map +1 -0
  1066. package/dist/totp/models.d.mts +377 -0
  1067. package/dist/totp/models.mjs +137 -0
  1068. package/dist/totp/models.mjs.map +1 -0
  1069. package/dist/totp/module.d.mts +737 -0
  1070. package/dist/totp/module.mjs +355 -0
  1071. package/dist/totp/module.mjs.map +1 -0
  1072. package/package.json +1 -0
  1073. package/src/Atom.ts +4 -0
  1074. package/src/Auth.ts +16 -0
  1075. package/src/AuthContract.ts +17 -0
  1076. package/src/AuthSession.ts +298 -0
  1077. package/src/AuthStore.ts +367 -0
  1078. package/src/AuthTokenCodec.ts +226 -0
  1079. package/src/Client.ts +9 -0
  1080. package/src/Cloudflare.ts +345 -0
  1081. package/src/Drizzle.ts +378 -0
  1082. package/src/DrizzleD1.ts +136 -0
  1083. package/src/DrizzleLibsql.ts +288 -0
  1084. package/src/DrizzleMysql2.ts +184 -0
  1085. package/src/DrizzlePglite.ts +160 -0
  1086. package/src/DrizzlePostgres.ts +160 -0
  1087. package/src/DrizzleSqliteBun.ts +244 -0
  1088. package/src/DrizzleSqliteDo.ts +473 -0
  1089. package/src/DrizzleSqliteNode.ts +245 -0
  1090. package/src/DrizzleSqliteWasm.ts +245 -0
  1091. package/src/Email.ts +55 -0
  1092. package/src/EmailOtp.ts +250 -0
  1093. package/src/EmailOtpSender.ts +28 -0
  1094. package/src/Errors.ts +103 -0
  1095. package/src/GitHub.ts +16 -0
  1096. package/src/Hooks.ts +50 -0
  1097. package/src/Http.ts +47 -0
  1098. package/src/HttpServer.ts +742 -0
  1099. package/src/Identity.ts +53 -0
  1100. package/src/IdentityResolver.ts +18 -0
  1101. package/src/OAuth.ts +242 -0
  1102. package/src/OpenIdClient.ts +13 -0
  1103. package/src/OpenIdClientConnected.ts +18 -0
  1104. package/src/OperationHttp.ts +14 -0
  1105. package/src/OperationHttpClient.ts +6 -0
  1106. package/src/OperationHttpServer.ts +15 -0
  1107. package/src/Operations.ts +69 -0
  1108. package/src/Passkey.ts +81 -0
  1109. package/src/PasskeyBrowser.ts +19 -0
  1110. package/src/PasskeyContract.ts +212 -0
  1111. package/src/PasskeyPassword.ts +319 -0
  1112. package/src/PasskeySimpleWebAuthn.ts +6 -0
  1113. package/src/Password.ts +113 -0
  1114. package/src/PasswordAuth.ts +197 -0
  1115. package/src/PasswordCredentialStore.ts +140 -0
  1116. package/src/PasswordHasher.ts +147 -0
  1117. package/src/PhoneOtp.ts +32 -0
  1118. package/src/Policy.ts +95 -0
  1119. package/src/Proofs.ts +71 -0
  1120. package/src/Rpc.ts +15 -0
  1121. package/src/Schema.ts +235 -0
  1122. package/src/SessionContract.ts +2 -0
  1123. package/src/Sessions.ts +105 -0
  1124. package/src/Testing.ts +24 -0
  1125. package/src/Totp.ts +28 -0
  1126. package/src/TotpContract.ts +147 -0
  1127. package/src/WebCrypto.ts +61 -0
  1128. package/src/Workflows.ts +12 -0
  1129. package/src/atom/AuthAtomLifetime.ts +87 -0
  1130. package/src/atom/AuthAtomWorkflow.ts +27 -0
  1131. package/src/atom/client.ts +364 -0
  1132. package/src/atom/operations.ts +183 -0
  1133. package/src/atom/scoped-runtime.ts +249 -0
  1134. package/src/auth/Auth.ts +482 -0
  1135. package/src/auth/AuthConfigurationError.ts +9 -0
  1136. package/src/auth/AuthRequest.ts +21 -0
  1137. package/src/auth/AuthStrategy.ts +116 -0
  1138. package/src/auth/ConsumeDecision.ts +4 -0
  1139. package/src/auth/actions.ts +220 -0
  1140. package/src/auth/defaults.ts +23 -0
  1141. package/src/auth/definition.ts +88 -0
  1142. package/src/auth/session.ts +146 -0
  1143. package/src/drizzle/D1BatchStatements.ts +10 -0
  1144. package/src/drizzle/PasswordPreparedPostconditions.ts +30 -0
  1145. package/src/drizzle/SuppliedService.ts +10 -0
  1146. package/src/drizzle/d1-emails.ts +1808 -0
  1147. package/src/drizzle/d1-generated-statement.ts +129 -0
  1148. package/src/drizzle/d1-identity.ts +374 -0
  1149. package/src/drizzle/d1-oauth.ts +338 -0
  1150. package/src/drizzle/d1-passkey.ts +371 -0
  1151. package/src/drizzle/d1-password-prepared.ts +1273 -0
  1152. package/src/drizzle/d1-passwords.ts +2661 -0
  1153. package/src/drizzle/d1-phone.ts +94 -0
  1154. package/src/drizzle/d1-planning.ts +105 -0
  1155. package/src/drizzle/d1-proofs.ts +2305 -0
  1156. package/src/drizzle/d1-sessions.ts +2867 -0
  1157. package/src/drizzle/d1-totp.ts +79 -0
  1158. package/src/drizzle/email-model.ts +512 -0
  1159. package/src/drizzle/email-registration.ts +696 -0
  1160. package/src/drizzle/email-sql.ts +1468 -0
  1161. package/src/drizzle/email-target.ts +243 -0
  1162. package/src/drizzle/model.ts +492 -0
  1163. package/src/drizzle/mysql-emails.ts +323 -0
  1164. package/src/drizzle/mysql-identity.ts +323 -0
  1165. package/src/drizzle/mysql-password-prepared.ts +206 -0
  1166. package/src/drizzle/mysql-passwords.ts +341 -0
  1167. package/src/drizzle/mysql-proofs.ts +183 -0
  1168. package/src/drizzle/mysql-sessions.ts +742 -0
  1169. package/src/drizzle/mysql.ts +686 -0
  1170. package/src/drizzle/oauth-accounts.ts +801 -0
  1171. package/src/drizzle/oauth-connected-access.ts +354 -0
  1172. package/src/drizzle/oauth-connected-collection.ts +324 -0
  1173. package/src/drizzle/oauth-connected-custody.ts +277 -0
  1174. package/src/drizzle/oauth-connected-drivers.ts +463 -0
  1175. package/src/drizzle/oauth-connected-flow.ts +439 -0
  1176. package/src/drizzle/oauth-connected-input.ts +128 -0
  1177. package/src/drizzle/oauth-connected-maintenance.ts +345 -0
  1178. package/src/drizzle/oauth-connected-management.ts +365 -0
  1179. package/src/drizzle/oauth-connected-model.ts +347 -0
  1180. package/src/drizzle/oauth-connected-reference.ts +112 -0
  1181. package/src/drizzle/oauth-connected-settlement.ts +226 -0
  1182. package/src/drizzle/oauth-connected-state.ts +846 -0
  1183. package/src/drizzle/oauth-connected-target.ts +264 -0
  1184. package/src/drizzle/oauth-drivers.ts +567 -0
  1185. package/src/drizzle/oauth-flow.ts +461 -0
  1186. package/src/drizzle/oauth-input.ts +205 -0
  1187. package/src/drizzle/oauth-model.ts +610 -0
  1188. package/src/drizzle/oauth-mysql.ts +10 -0
  1189. package/src/drizzle/oauth-owner.ts +29 -0
  1190. package/src/drizzle/oauth-registration.ts +638 -0
  1191. package/src/drizzle/oauth-state.ts +213 -0
  1192. package/src/drizzle/oauth-target.ts +751 -0
  1193. package/src/drizzle/passkey-admission.ts +333 -0
  1194. package/src/drizzle/passkey-credentials.ts +465 -0
  1195. package/src/drizzle/passkey-drivers.ts +385 -0
  1196. package/src/drizzle/passkey-enrollment.ts +280 -0
  1197. package/src/drizzle/passkey-flow.ts +983 -0
  1198. package/src/drizzle/passkey-management.ts +369 -0
  1199. package/src/drizzle/passkey-model.ts +350 -0
  1200. package/src/drizzle/passkey-registration-ceremony-model.ts +69 -0
  1201. package/src/drizzle/passkey-registration-ceremony.ts +254 -0
  1202. package/src/drizzle/passkey-registration-custody.ts +82 -0
  1203. package/src/drizzle/passkey-registration-write.ts +378 -0
  1204. package/src/drizzle/passkey-state.ts +307 -0
  1205. package/src/drizzle/passkey-target.ts +528 -0
  1206. package/src/drizzle/passkey-write-drivers.ts +396 -0
  1207. package/src/drizzle/passkey-write-model.ts +265 -0
  1208. package/src/drizzle/passkey-write-state.ts +627 -0
  1209. package/src/drizzle/passkey-write-target.ts +406 -0
  1210. package/src/drizzle/password-model.ts +491 -0
  1211. package/src/drizzle/password-prepared-model.ts +259 -0
  1212. package/src/drizzle/password-prepared-sql.ts +1198 -0
  1213. package/src/drizzle/password-prepared-state.ts +232 -0
  1214. package/src/drizzle/password-prepared-target.ts +158 -0
  1215. package/src/drizzle/password-registration.ts +372 -0
  1216. package/src/drizzle/password-sql.ts +2082 -0
  1217. package/src/drizzle/password-target.ts +223 -0
  1218. package/src/drizzle/pg-emails.ts +323 -0
  1219. package/src/drizzle/pg-password-prepared.ts +207 -0
  1220. package/src/drizzle/pg-passwords.ts +340 -0
  1221. package/src/drizzle/pg-proofs.ts +193 -0
  1222. package/src/drizzle/pg-sessions.ts +751 -0
  1223. package/src/drizzle/pg.ts +982 -0
  1224. package/src/drizzle/phone-model.ts +185 -0
  1225. package/src/drizzle/phone-state.ts +802 -0
  1226. package/src/drizzle/phone-target.ts +471 -0
  1227. package/src/drizzle/proof-model.ts +398 -0
  1228. package/src/drizzle/proof-sql.ts +1912 -0
  1229. package/src/drizzle/proof-target.ts +120 -0
  1230. package/src/drizzle/session-model.ts +368 -0
  1231. package/src/drizzle/session-sql.ts +2152 -0
  1232. package/src/drizzle/session-target.ts +335 -0
  1233. package/src/drizzle/sqlite-emails.ts +368 -0
  1234. package/src/drizzle/sqlite-identity.ts +343 -0
  1235. package/src/drizzle/sqlite-password-prepared.ts +262 -0
  1236. package/src/drizzle/sqlite-passwords.ts +499 -0
  1237. package/src/drizzle/sqlite-proofs.ts +204 -0
  1238. package/src/drizzle/sqlite-sessions.ts +972 -0
  1239. package/src/drizzle/sqlite.ts +704 -0
  1240. package/src/drizzle/standalone-guard.ts +38 -0
  1241. package/src/drizzle/step-up-model.ts +129 -0
  1242. package/src/drizzle/step-up-state.ts +141 -0
  1243. package/src/drizzle/totp-model.ts +91 -0
  1244. package/src/drizzle/totp-state.ts +520 -0
  1245. package/src/drizzle/totp-target.ts +304 -0
  1246. package/src/drizzle/transaction-execution.ts +290 -0
  1247. package/src/drizzle/transaction-mysql.ts +104 -0
  1248. package/src/drizzle/transaction-owner.ts +570 -0
  1249. package/src/email/EmailActionEvidence.ts +37 -0
  1250. package/src/email/EmailAddressPersistence.ts +71 -0
  1251. package/src/email/EmailIdentifierNotifier.ts +48 -0
  1252. package/src/email/EmailReturnTargets.ts +50 -0
  1253. package/src/email/EmailSignInTargets.ts +20 -0
  1254. package/src/email/addresses.ts +630 -0
  1255. package/src/email/definition.ts +309 -0
  1256. package/src/email/errors.ts +23 -0
  1257. package/src/email/magicLink.ts +84 -0
  1258. package/src/email/models.ts +50 -0
  1259. package/src/email/module.ts +664 -0
  1260. package/src/email/registration.ts +415 -0
  1261. package/src/email/snapshot.ts +51 -0
  1262. package/src/hooks/LifecycleHooks.ts +136 -0
  1263. package/src/hooks/commit.ts +271 -0
  1264. package/src/hooks/models.ts +111 -0
  1265. package/src/hooks/plugins.ts +87 -0
  1266. package/src/hooks/transactions.ts +51 -0
  1267. package/src/http/auth-api.ts +17 -0
  1268. package/src/http/auth-contract.ts +148 -0
  1269. package/src/http/auth-http.ts +467 -0
  1270. package/src/http/endpoints/get-session.ts +9 -0
  1271. package/src/http/endpoints/password-sign-in.ts +19 -0
  1272. package/src/http/endpoints/request-email-otp.ts +10 -0
  1273. package/src/http/endpoints/set-password.ts +18 -0
  1274. package/src/http/endpoints/sign-out.ts +5 -0
  1275. package/src/http/endpoints/verify-email-otp.ts +15 -0
  1276. package/src/http/models.ts +80 -0
  1277. package/src/http/security.ts +102 -0
  1278. package/src/http/session-contract.ts +92 -0
  1279. package/src/http-operation/OperationHttpInvocation.ts +39 -0
  1280. package/src/http-operation/OperationHttpServerConfig.ts +124 -0
  1281. package/src/http-operation/auth-client.ts +273 -0
  1282. package/src/http-operation/client.ts +453 -0
  1283. package/src/http-operation/configuration-schema.ts +19 -0
  1284. package/src/http-operation/contract.ts +116 -0
  1285. package/src/http-operation/errors.ts +38 -0
  1286. package/src/http-operation/models.ts +42 -0
  1287. package/src/http-operation/private.ts +50 -0
  1288. package/src/http-operation/security.ts +93 -0
  1289. package/src/http-operation/server.ts +544 -0
  1290. package/src/identity/ExternalIdentityMutation.ts +18 -0
  1291. package/src/identity/IdentityMutation.ts +41 -0
  1292. package/src/identity/IdentityRepository.ts +37 -0
  1293. package/src/identity/SubjectLifecycle.ts +80 -0
  1294. package/src/identity/SubjectProvisioner.ts +40 -0
  1295. package/src/identity/codecs.ts +54 -0
  1296. package/src/identity/models.ts +82 -0
  1297. package/src/identity/operations.ts +182 -0
  1298. package/src/index.ts +23 -0
  1299. package/src/internal/AuthStoreDecisions.ts +23 -0
  1300. package/src/internal/CurrentSession.ts +8 -0
  1301. package/src/internal/diagnostics.ts +71 -0
  1302. package/src/oauth/GithubOAuthProvider.ts +106 -0
  1303. package/src/oauth/OAuth.ts +436 -0
  1304. package/src/oauth/OAuthAccountsPersistence.ts +142 -0
  1305. package/src/oauth/OAuthActionEvidence.ts +31 -0
  1306. package/src/oauth/OAuthConnectedActionEvidence.ts +28 -0
  1307. package/src/oauth/OAuthConnectedPersistence.ts +163 -0
  1308. package/src/oauth/OAuthConnectedProtocol.ts +54 -0
  1309. package/src/oauth/OAuthConnectedRevocations.ts +48 -0
  1310. package/src/oauth/OAuthConnectedTokenProtector.ts +240 -0
  1311. package/src/oauth/OAuthConnectedTransactionProtector.ts +56 -0
  1312. package/src/oauth/OAuthConnectedUseAuthority.ts +26 -0
  1313. package/src/oauth/OAuthConnectionStore.ts +59 -0
  1314. package/src/oauth/OAuthLinkTransactionProtector.ts +58 -0
  1315. package/src/oauth/OAuthProtocol.ts +39 -0
  1316. package/src/oauth/OAuthProvider.ts +126 -0
  1317. package/src/oauth/OAuthProviders.ts +53 -0
  1318. package/src/oauth/OAuthRegistrationIntents.ts +42 -0
  1319. package/src/oauth/OAuthReturnTargets.ts +44 -0
  1320. package/src/oauth/OAuthSignInPersistence.ts +91 -0
  1321. package/src/oauth/OAuthStateDecisions.ts +16 -0
  1322. package/src/oauth/OAuthStateStore.ts +102 -0
  1323. package/src/oauth/OAuthTransactionProtector.ts +103 -0
  1324. package/src/oauth/accounts.ts +987 -0
  1325. package/src/oauth/accountsModels.ts +214 -0
  1326. package/src/oauth/connected.ts +995 -0
  1327. package/src/oauth/connectedAccess.ts +644 -0
  1328. package/src/oauth/connectedMaintenance.ts +248 -0
  1329. package/src/oauth/connectedModels.ts +495 -0
  1330. package/src/oauth/definition.ts +414 -0
  1331. package/src/oauth/errors.ts +78 -0
  1332. package/src/oauth/github/identity.ts +26 -0
  1333. package/src/oauth/github/models.ts +37 -0
  1334. package/src/oauth/github/protocol.ts +329 -0
  1335. package/src/oauth/openid-client/ProviderRevocation.ts +22 -0
  1336. package/src/oauth/openid-client/compatibility.ts +47 -0
  1337. package/src/oauth/openid-client/configuration.ts +472 -0
  1338. package/src/oauth/openid-client/connected/configuration.ts +565 -0
  1339. package/src/oauth/openid-client/connected/models.ts +58 -0
  1340. package/src/oauth/openid-client/connected/protocol.ts +866 -0
  1341. package/src/oauth/openid-client/models.ts +78 -0
  1342. package/src/oauth/openid-client/protocol.ts +437 -0
  1343. package/src/oauth/openid-client/transport.ts +67 -0
  1344. package/src/oauth/policy.ts +26 -0
  1345. package/src/oauth/registration.ts +410 -0
  1346. package/src/oauth/registrationModels.ts +115 -0
  1347. package/src/oauth/registrationSecrets.ts +127 -0
  1348. package/src/oauth/schema.ts +102 -0
  1349. package/src/oauth/signInErrors.ts +23 -0
  1350. package/src/oauth/signInModels.ts +266 -0
  1351. package/src/oauth/signInModule.ts +875 -0
  1352. package/src/oauth/signInSnapshot.ts +37 -0
  1353. package/src/oauth/transactionEncryption.ts +198 -0
  1354. package/src/operations/RequestBindingConfig.ts +12 -0
  1355. package/src/operations/actions.ts +342 -0
  1356. package/src/operations/context.ts +130 -0
  1357. package/src/operations/credentials.ts +121 -0
  1358. package/src/operations/errors.ts +53 -0
  1359. package/src/operations/operation.ts +740 -0
  1360. package/src/operations/requestBinding.ts +237 -0
  1361. package/src/operations/requestBindingModels.ts +18 -0
  1362. package/src/operations/reveals.ts +147 -0
  1363. package/src/passkey/PasskeyActionEvidence.ts +25 -0
  1364. package/src/passkey/PasskeyCredentials.ts +16 -0
  1365. package/src/passkey/PasskeyEnrollmentContext.ts +26 -0
  1366. package/src/passkey/PasskeyManagementPersistence.ts +124 -0
  1367. package/src/passkey/PasskeyPersistence.ts +85 -0
  1368. package/src/passkey/PasskeyProtocol.ts +48 -0
  1369. package/src/passkey/actions.ts +905 -0
  1370. package/src/passkey/browser/PasskeyBrowser.ts +26 -0
  1371. package/src/passkey/browser/models.ts +67 -0
  1372. package/src/passkey/browser/simplewebauthn.ts +621 -0
  1373. package/src/passkey/definition.ts +386 -0
  1374. package/src/passkey/errors.ts +39 -0
  1375. package/src/passkey/management.ts +552 -0
  1376. package/src/passkey/models.ts +414 -0
  1377. package/src/passkey/module.ts +367 -0
  1378. package/src/passkey/pending.ts +203 -0
  1379. package/src/passkey/policy.ts +88 -0
  1380. package/src/passkey/registration.ts +251 -0
  1381. package/src/passkey/simplewebauthn/configuration.ts +97 -0
  1382. package/src/passkey/simplewebauthn/models.ts +9 -0
  1383. package/src/passkey/simplewebauthn/protocol.ts +729 -0
  1384. package/src/passkey/snapshot.ts +48 -0
  1385. package/src/passkey/stepUp.ts +212 -0
  1386. package/src/password/CompromisedPasswords.ts +36 -0
  1387. package/src/password/NewPasswordCheck.ts +89 -0
  1388. package/src/password/PasswordHashing.ts +209 -0
  1389. package/src/password/PasswordKdfAdmission.ts +44 -0
  1390. package/src/password/configuration.ts +52 -0
  1391. package/src/password/defaults.ts +15 -0
  1392. package/src/password/encoding.ts +137 -0
  1393. package/src/password/errors.ts +43 -0
  1394. package/src/password/methods/PasswordActionEvidence.ts +41 -0
  1395. package/src/password/methods/PasswordPersistence.ts +128 -0
  1396. package/src/password/methods/PasswordPreparedPersistence.ts +123 -0
  1397. package/src/password/methods/contracts.ts +47 -0
  1398. package/src/password/methods/definition.ts +199 -0
  1399. package/src/password/methods/errors.ts +26 -0
  1400. package/src/password/methods/models.ts +80 -0
  1401. package/src/password/methods/module.ts +986 -0
  1402. package/src/password/methods/policy.ts +68 -0
  1403. package/src/password/methods/preparation.ts +73 -0
  1404. package/src/password/methods/prepared.ts +1199 -0
  1405. package/src/password/methods/preparedModels.ts +496 -0
  1406. package/src/password/methods/signIn.ts +136 -0
  1407. package/src/password/methods/snapshot.ts +53 -0
  1408. package/src/password/methods/verification.ts +266 -0
  1409. package/src/password/models.ts +15 -0
  1410. package/src/password/policy.ts +41 -0
  1411. package/src/phone/PhoneActionEvidence.ts +26 -0
  1412. package/src/phone/PhoneAdmission.ts +29 -0
  1413. package/src/phone/PhoneDeliveryEligibility.ts +9 -0
  1414. package/src/phone/PhonePersistence.ts +43 -0
  1415. package/src/phone/PhoneRequestContext.ts +7 -0
  1416. package/src/phone/PhoneSignInTargets.ts +19 -0
  1417. package/src/phone/definition.ts +87 -0
  1418. package/src/phone/failure.ts +40 -0
  1419. package/src/phone/lifecycle.ts +662 -0
  1420. package/src/phone/lifecycleModels.ts +108 -0
  1421. package/src/phone/models.ts +41 -0
  1422. package/src/phone/module.ts +433 -0
  1423. package/src/proofs/EmailProofDelivery.ts +19 -0
  1424. package/src/proofs/HostIngressLimiter.ts +20 -0
  1425. package/src/proofs/ProofPersistence.ts +172 -0
  1426. package/src/proofs/SmsProofDelivery.ts +19 -0
  1427. package/src/proofs/abuse.ts +23 -0
  1428. package/src/proofs/completion.ts +23 -0
  1429. package/src/proofs/crypto.ts +326 -0
  1430. package/src/proofs/definition.ts +39 -0
  1431. package/src/proofs/delivery.ts +73 -0
  1432. package/src/proofs/dispatch.ts +99 -0
  1433. package/src/proofs/errors.ts +46 -0
  1434. package/src/proofs/models.ts +131 -0
  1435. package/src/proofs/module.ts +620 -0
  1436. package/src/proofs/policy.ts +77 -0
  1437. package/src/sessions/AuthenticationAuthority.ts +51 -0
  1438. package/src/sessions/PendingAuthentication.ts +121 -0
  1439. package/src/sessions/SessionStepUpPersistence.ts +164 -0
  1440. package/src/sessions/assurance.ts +192 -0
  1441. package/src/sessions/commit.ts +13 -0
  1442. package/src/sessions/configuration.ts +133 -0
  1443. package/src/sessions/contract.ts +203 -0
  1444. package/src/sessions/crypto.ts +181 -0
  1445. package/src/sessions/definition.ts +25 -0
  1446. package/src/sessions/errors.ts +68 -0
  1447. package/src/sessions/invalidation.ts +46 -0
  1448. package/src/sessions/models.ts +138 -0
  1449. package/src/sessions/module.ts +1991 -0
  1450. package/src/sessions/persistence.ts +135 -0
  1451. package/src/sessions/policy.ts +103 -0
  1452. package/src/testing/conformance/AuthStore.ts +314 -0
  1453. package/src/testing/conformance/OAuthConnectionStore.ts +167 -0
  1454. package/src/testing/conformance/OAuthStateStore.ts +105 -0
  1455. package/src/testing/conformance/PasswordCredentialStore.ts +205 -0
  1456. package/src/testing/conformance/support.ts +38 -0
  1457. package/src/testing/crypto.ts +55 -0
  1458. package/src/testing/keyring.ts +17 -0
  1459. package/src/totp/TotpActionEvidence.ts +18 -0
  1460. package/src/totp/TotpPersistence.ts +26 -0
  1461. package/src/totp/TotpSecretKeys.ts +15 -0
  1462. package/src/totp/crypto.ts +160 -0
  1463. package/src/totp/definition.ts +78 -0
  1464. package/src/totp/errors.ts +25 -0
  1465. package/src/totp/models.ts +164 -0
  1466. package/src/totp/module.ts +717 -0
@@ -0,0 +1,2082 @@
1
+ /* oxlint-disable no-explicit-any -- the shared dialect kernel intentionally erases consumer Drizzle table types. */
2
+ import { and, eq, gte, inArray, lte, notExists, sql } from "drizzle-orm";
3
+ import type { EffectDrizzleQueryError } from "drizzle-orm/effect-core";
4
+ import { Cause, Context, DateTime, Effect, Option, Redacted, Schema } from "effect";
5
+ import type * as SqlError from "effect/unstable/sql/SqlError";
6
+
7
+ import {
8
+ coordinateCommit,
9
+ CurrentCommitJournal,
10
+ hasCommitScope,
11
+ type CommitJournal,
12
+ type PreparedCommit,
13
+ } from "../hooks/commit";
14
+ import { LifecycleHooks } from "../hooks/LifecycleHooks";
15
+ import { HookConfigurationError } from "../hooks/models";
16
+ import type { LoginIdentifier } from "../identity/models";
17
+ import { reportPersistenceFailure } from "../internal/diagnostics";
18
+ import { PasswordUnavailable } from "../password/methods/errors";
19
+ import type {
20
+ PasswordAction,
21
+ PasswordAttemptDecision,
22
+ PasswordCredentialSnapshot,
23
+ PasswordMutationDecision,
24
+ } from "../password/methods/models";
25
+ import {
26
+ PasswordPersistence,
27
+ type PasswordMutationInput,
28
+ } from "../password/methods/PasswordPersistence";
29
+ import type { PasswordAttemptPolicy } from "../password/methods/policy";
30
+ import {
31
+ snapshotPasswordCredential,
32
+ snapshotPasswordRequirement,
33
+ snapshotPasswordRevision,
34
+ } from "../password/methods/snapshot";
35
+ import type { ProofCompletionPlan } from "../proofs/completion";
36
+ import { ProofUnavailable } from "../proofs/errors";
37
+ import type { ProofCompletionInput } from "../proofs/ProofPersistence";
38
+ import { snapshotAuthenticationEvidence } from "../sessions/assurance";
39
+ import type {
40
+ AuthenticationEvidence,
41
+ AuthenticationRequirement,
42
+ SecurityRevision,
43
+ } from "../sessions/models";
44
+ import { column, DrizzleMappingError, updateValues } from "./model";
45
+ import {
46
+ type AnyPasswordPersistenceMapping,
47
+ type PasswordAttemptAction,
48
+ type PasswordRateScopeKind,
49
+ type PasswordScopeKeys,
50
+ requiredPasswordConstraints,
51
+ } from "./password-model";
52
+ import {
53
+ CurrentProofSql,
54
+ type ProofSqlConfiguration,
55
+ type ProofSqlDatabase,
56
+ completeProofPlanIn,
57
+ } from "./proof-sql";
58
+
59
+ type AdapterFailure = EffectDrizzleQueryError | DrizzleMappingError | SqlError.SqlError;
60
+
61
+ export interface PasswordSqlQuery<A = ReadonlyArray<any>> extends Effect.Effect<A, AdapterFailure> {
62
+ readonly getSQL: () => ReturnType<typeof sql>;
63
+ readonly from: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
64
+ readonly where: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
65
+ readonly limit: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
66
+ readonly orderBy: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
67
+ readonly for: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
68
+ readonly set: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
69
+ readonly values: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
70
+ readonly returning: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
71
+ readonly $returningId: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
72
+ readonly onConflictDoNothing: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
73
+ readonly onDuplicateKeyUpdate: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
74
+ }
75
+
76
+ export interface PasswordSqlDatabase {
77
+ readonly select: (...args: ReadonlyArray<any>) => PasswordSqlQuery;
78
+ readonly insert: (...args: ReadonlyArray<any>) => PasswordSqlQuery;
79
+ readonly update: (...args: ReadonlyArray<any>) => PasswordSqlQuery;
80
+ readonly delete: (...args: ReadonlyArray<any>) => PasswordSqlQuery;
81
+ readonly transaction: <A, E, R>(
82
+ body: (transaction: PasswordSqlDatabase) => Effect.Effect<A, E, R>,
83
+ ) => Effect.Effect<A, E | SqlError.SqlError, R>;
84
+ }
85
+
86
+ export class CurrentPasswordSql extends Context.Service<CurrentPasswordSql, PasswordSqlDatabase>()(
87
+ "effect-auth/CurrentPasswordSql",
88
+ ) {}
89
+
90
+ export interface PasswordSqlConfiguration {
91
+ readonly mode: "interactive" | "synchronous";
92
+ readonly locking: boolean;
93
+ readonly standaloneGuard: Effect.Effect<void, PasswordUnavailable>;
94
+ readonly coordinated?: boolean;
95
+ readonly insertIfAbsent: (
96
+ query: PasswordSqlQuery,
97
+ selfKey: string,
98
+ selfValue: unknown,
99
+ ) => PasswordSqlQuery;
100
+ readonly proof?: {
101
+ readonly mapping: any;
102
+ readonly configuration: ProofSqlConfiguration;
103
+ };
104
+ }
105
+
106
+ type Database = PasswordSqlDatabase;
107
+ type Mapping = AnyPasswordPersistenceMapping;
108
+ const unavailable = () => PasswordUnavailable.make({});
109
+
110
+ const translateFailure = <A, E, R>(
111
+ effect: Effect.Effect<A, E, R>,
112
+ ): Effect.Effect<A, PasswordUnavailable, R> =>
113
+ reportPersistenceFailure(
114
+ effect,
115
+ (error) =>
116
+ Schema.is(PasswordUnavailable)(error) ||
117
+ Schema.is(ProofUnavailable)(error) ||
118
+ Schema.is(HookConfigurationError)(error),
119
+ ).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
120
+
121
+ const nowMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));
122
+
123
+ const validConstraints = (mapping: Mapping) =>
124
+ Object.entries(requiredPasswordConstraints).every(
125
+ ([key, value]) =>
126
+ mapping.constraints[key as keyof typeof requiredPasswordConstraints] === value,
127
+ );
128
+
129
+ const selectRows = (query: PasswordSqlQuery, locking: boolean) =>
130
+ locking && typeof query.for === "function" ? query.for("update") : query;
131
+
132
+ const subjectColumns = (mapping: Mapping) => ({
133
+ id: column(mapping.subject.table, mapping.subject.id),
134
+ status: column(mapping.subject.table, mapping.subject.status),
135
+ securityRevision: column(mapping.subject.table, mapping.subject.securityRevision),
136
+ });
137
+
138
+ const identifierColumns = (mapping: Mapping) => ({
139
+ namespace: column(mapping.identifier.table, mapping.identifier.namespace),
140
+ value: column(mapping.identifier.table, mapping.identifier.value),
141
+ subjectId: column(mapping.identifier.table, mapping.identifier.subjectId),
142
+ verifiedAt: column(mapping.identifier.table, mapping.identifier.verifiedAt),
143
+ bindingRevision: column(mapping.identifier.table, mapping.identifier.bindingRevision),
144
+ });
145
+
146
+ const credentialColumns = (mapping: Mapping) => ({
147
+ moduleId: column(mapping.credential.table, mapping.credential.moduleId),
148
+ subjectId: column(mapping.credential.table, mapping.credential.subjectId),
149
+ credentialId: column(mapping.credential.table, mapping.credential.credentialId),
150
+ credentialRevision: column(mapping.credential.table, mapping.credential.credentialRevision),
151
+ verifierVersion: column(mapping.credential.table, mapping.credential.verifierVersion),
152
+ verifier: column(mapping.credential.table, mapping.credential.verifier),
153
+ normalization: column(mapping.credential.table, mapping.credential.normalization),
154
+ });
155
+
156
+ const authorityCredentialColumns = (mapping: Mapping) => ({
157
+ subjectId: column(mapping.authorityCredential.table, mapping.authorityCredential.subjectId),
158
+ credentialId: column(mapping.authorityCredential.table, mapping.authorityCredential.credentialId),
159
+ revision: column(mapping.authorityCredential.table, mapping.authorityCredential.revision),
160
+ });
161
+
162
+ const attemptColumns = (mapping: Mapping) => ({
163
+ moduleId: column(mapping.attempt.table, mapping.attempt.moduleId),
164
+ action: column(mapping.attempt.table, mapping.attempt.action),
165
+ attemptId: column(mapping.attempt.table, mapping.attempt.attemptId),
166
+ identifierNamespace: column(mapping.attempt.table, mapping.attempt.identifierNamespace),
167
+ identifierValue: column(mapping.attempt.table, mapping.attempt.identifierValue),
168
+ subjectId: column(mapping.attempt.table, mapping.attempt.subjectId),
169
+ credentialId: column(mapping.attempt.table, mapping.attempt.credentialId),
170
+ securityRevision: column(mapping.attempt.table, mapping.attempt.securityRevision),
171
+ credentialRevision: column(mapping.attempt.table, mapping.attempt.credentialRevision),
172
+ verifierVersion: column(mapping.attempt.table, mapping.attempt.verifierVersion),
173
+ identifierBindingRevision: column(
174
+ mapping.attempt.table,
175
+ mapping.attempt.identifierBindingRevision,
176
+ ),
177
+ admittedAt: column(mapping.attempt.table, mapping.attempt.admittedAt),
178
+ deadline: column(mapping.attempt.table, mapping.attempt.deadline),
179
+ retentionUntil: column(mapping.attempt.table, mapping.attempt.retentionUntil),
180
+ state: column(mapping.attempt.table, mapping.attempt.state),
181
+ });
182
+
183
+ const scopeColumns = (mapping: Mapping) => ({
184
+ moduleId: column(mapping.rateScope.table, mapping.rateScope.moduleId),
185
+ action: column(mapping.rateScope.table, mapping.rateScope.action),
186
+ scopeKind: column(mapping.rateScope.table, mapping.rateScope.scopeKind),
187
+ scopeKey: column(mapping.rateScope.table, mapping.rateScope.scopeKey),
188
+ });
189
+
190
+ const chargeColumns = (mapping: Mapping) => ({
191
+ moduleId: column(mapping.charge.table, mapping.charge.moduleId),
192
+ action: column(mapping.charge.table, mapping.charge.action),
193
+ scopeKind: column(mapping.charge.table, mapping.charge.scopeKind),
194
+ scopeKey: column(mapping.charge.table, mapping.charge.scopeKey),
195
+ attemptId: column(mapping.charge.table, mapping.charge.attemptId),
196
+ occurredAt: column(mapping.charge.table, mapping.charge.occurredAt),
197
+ retentionUntil: column(mapping.charge.table, mapping.charge.retentionUntil),
198
+ });
199
+
200
+ const commandColumns = (mapping: Mapping) => ({
201
+ moduleId: column(mapping.command.table, mapping.command.moduleId),
202
+ commandId: column(mapping.command.table, mapping.command.commandId),
203
+ action: column(mapping.command.table, mapping.command.action),
204
+ bindingDigest: column(mapping.command.table, mapping.command.bindingDigest),
205
+ decision: column(mapping.command.table, mapping.command.decision),
206
+ retentionUntil: column(mapping.command.table, mapping.command.retentionUntil),
207
+ });
208
+
209
+ const allocate = <A>(
210
+ mode: PasswordSqlConfiguration["mode"],
211
+ asyncValue: Effect.Effect<A, DrizzleMappingError> | undefined,
212
+ syncValue: (() => A) | undefined,
213
+ ): Effect.Effect<A, PasswordUnavailable | DrizzleMappingError> => {
214
+ if (mode === "synchronous")
215
+ return syncValue === undefined
216
+ ? Effect.fail(unavailable())
217
+ : Effect.try({
218
+ try: syncValue,
219
+ catch: (cause) => new DrizzleMappingError({ operation: "mapping", cause }),
220
+ });
221
+ if (asyncValue !== undefined) return asyncValue;
222
+
223
+ return syncValue === undefined
224
+ ? Effect.fail(unavailable())
225
+ : Effect.try({
226
+ try: syncValue,
227
+ catch: (cause) => new DrizzleMappingError({ operation: "mapping", cause }),
228
+ });
229
+ };
230
+
231
+ const allocateNextSecurityRevision = (
232
+ mapping: Mapping,
233
+ mode: PasswordSqlConfiguration["mode"],
234
+ current: SecurityRevision,
235
+ ) => {
236
+ const asyncValue = mapping.subject.nextSecurityRevision?.(current);
237
+
238
+ const syncValue =
239
+ mapping.subject.nextSecurityRevisionSync === undefined
240
+ ? undefined
241
+ : () => mapping.subject.nextSecurityRevisionSync!(current);
242
+
243
+ return allocate(
244
+ mode,
245
+ asyncValue ?? mapping.allocateRevision,
246
+ syncValue ?? mapping.allocateRevisionSync,
247
+ );
248
+ };
249
+
250
+ const sameIdentifier = (left: LoginIdentifier, right: LoginIdentifier) =>
251
+ left.namespace === right.namespace && left.value === right.value;
252
+
253
+ const sameCredentialSnapshot = (
254
+ left: PasswordCredentialSnapshot,
255
+ right: PasswordCredentialSnapshot,
256
+ ) =>
257
+ left.moduleId === right.moduleId &&
258
+ left.revision.subjectId === right.revision.subjectId &&
259
+ left.revision.securityRevision === right.revision.securityRevision &&
260
+ left.credentialId === right.credentialId &&
261
+ left.credentialRevision === right.credentialRevision &&
262
+ left.verifierVersion === right.verifierVersion &&
263
+ left.normalization === right.normalization &&
264
+ left.identifierVerifiedAtMillis === right.identifierVerifiedAtMillis &&
265
+ left.revision.credentials.length === right.revision.credentials.length &&
266
+ left.revision.credentials.every((entry) =>
267
+ right.revision.credentials.some(
268
+ (other) => other.credentialId === entry.credentialId && other.revision === entry.revision,
269
+ ),
270
+ ) &&
271
+ left.identifierBindingRevision === right.identifierBindingRevision &&
272
+ sameIdentifier(left.identifier, right.identifier) &&
273
+ Redacted.value(left.verifier) === Redacted.value(right.verifier);
274
+
275
+ const evidenceSatisfiedAt = (
276
+ evidence: AuthenticationEvidence,
277
+ requirement: AuthenticationRequirement,
278
+ now: number,
279
+ ): boolean => {
280
+ if (evidence.proofs.length > 64 || evidence.revision.credentials.length > 64) return false;
281
+ const revisions = new Map<string, string>();
282
+
283
+ for (const item of evidence.revision.credentials) {
284
+ if (revisions.has(item.credentialId)) return false;
285
+ revisions.set(item.credentialId, item.revision);
286
+ }
287
+ if (evidence.proofs.some((proof) => !revisions.has(proof.credentialId))) return false;
288
+ if (evidence.proofs.some((proof) => now < DateTime.toEpochMillis(proof.verifiedAt))) return false;
289
+
290
+ const eligible = evidence.proofs.filter((proof) => {
291
+ const age = now - DateTime.toEpochMillis(proof.verifiedAt);
292
+
293
+ return age >= 0 && age < requirement.maximumAgeMillis;
294
+ });
295
+
296
+ const factors = new Set(eligible.flatMap((proof) => proof.factors));
297
+ const credentials = new Set(eligible.map((proof) => proof.credentialId));
298
+
299
+ return requirement.alternatives.some(
300
+ (alternative) =>
301
+ alternative.factors.every((factor) => factors.has(factor)) &&
302
+ credentials.size >= alternative.minimumCredentials &&
303
+ eligible.some(
304
+ (proof) =>
305
+ (!alternative.userVerified || proof.userVerified) &&
306
+ (!alternative.phishingResistant || proof.phishingResistant),
307
+ ),
308
+ );
309
+ };
310
+
311
+ const snapshotMutationInput = Effect.fn("DrizzlePassword.snapshotMutationInput")(function* (
312
+ input: PasswordMutationInput,
313
+ ) {
314
+ const expectedRevision = snapshotPasswordRevision(input.expectedRevision);
315
+
316
+ const evidence = yield* snapshotAuthenticationEvidence(input.authorization.evidence).pipe(
317
+ Effect.mapError(unavailable),
318
+ );
319
+
320
+ const requirement = yield* snapshotPasswordRequirement(input.authorization.requirement);
321
+
322
+ const credential =
323
+ input.credential === undefined
324
+ ? undefined
325
+ : yield* snapshotPasswordCredential(input.credential);
326
+
327
+ return Object.freeze({
328
+ ...input,
329
+ expectedRevision,
330
+ replacement: Object.freeze({
331
+ verifier: Redacted.make(Redacted.value(input.replacement.verifier)),
332
+ normalization: input.replacement.normalization,
333
+ }),
334
+ invalidation: Object.freeze({ ...input.invalidation }),
335
+ ...(credential === undefined ? {} : { credential }),
336
+ authorization: Object.freeze({
337
+ challenge: Object.freeze({
338
+ ...input.authorization.challenge,
339
+ revision: snapshotPasswordRevision(input.authorization.challenge.revision),
340
+ }),
341
+ evidence,
342
+ requirement,
343
+ }),
344
+ });
345
+ });
346
+
347
+ const lockSubject = Effect.fn("DrizzlePassword.lockSubject")(function* (
348
+ mapping: Mapping,
349
+ subjectId: string,
350
+ locking: boolean,
351
+ ) {
352
+ const database = yield* CurrentPasswordSql;
353
+
354
+ const nativeSubjectId = yield* mapping.subjectId.toNative(subjectId as any);
355
+ const c = subjectColumns(mapping);
356
+
357
+ const rows = yield* selectRows(
358
+ database.select().from(mapping.subject.table).where(eq(c.id, nativeSubjectId)).limit(1),
359
+ locking,
360
+ );
361
+
362
+ return { nativeSubjectId, row: rows[0] };
363
+ });
364
+
365
+ const lockIdentifier = Effect.fn("Drizzle.lockIdentifier")(function* (
366
+ mapping: Mapping,
367
+ identifier: LoginIdentifier,
368
+ locking: boolean,
369
+ ) {
370
+ const database = yield* CurrentPasswordSql;
371
+
372
+ const c = identifierColumns(mapping);
373
+
374
+ return yield* selectRows(
375
+ database
376
+ .select()
377
+ .from(mapping.identifier.table)
378
+ .where(and(eq(c.namespace, identifier.namespace), eq(c.value, identifier.value)))
379
+ .limit(1),
380
+ locking,
381
+ );
382
+ });
383
+
384
+ const readPasswordCredential = Effect.fn("Drizzle.readPasswordCredential")(function* (
385
+ mapping: Mapping,
386
+ moduleId: string,
387
+ nativeSubjectId: unknown,
388
+ locking: boolean,
389
+ ) {
390
+ const database = yield* CurrentPasswordSql;
391
+
392
+ const c = credentialColumns(mapping);
393
+
394
+ return yield* selectRows(
395
+ database
396
+ .select()
397
+ .from(mapping.credential.table)
398
+ .where(and(eq(c.moduleId, moduleId), eq(c.subjectId, nativeSubjectId)))
399
+ .limit(1),
400
+ locking,
401
+ );
402
+ });
403
+
404
+ const resolveCredential = Effect.fn("DrizzlePassword.resolveCredential")(function* (
405
+ mapping: Mapping,
406
+ moduleId: string,
407
+ identifier: LoginIdentifier,
408
+ requestedSubjectId: string | undefined,
409
+ locking: boolean,
410
+ ) {
411
+ const database = yield* CurrentPasswordSql;
412
+
413
+ // The unlocked lookup only discovers the prospective subject. The canonical
414
+ // protected order starts with the subject and then rechecks the identifier.
415
+ const discovered = (yield* lockIdentifier(mapping, identifier, false))[0];
416
+
417
+ if (discovered === undefined || !mapping.identifier.isCurrent(discovered)) return undefined;
418
+ const discoveredNative = discovered[mapping.identifier.subjectId];
419
+
420
+ const subjectRows = yield* selectRows(
421
+ database
422
+ .select()
423
+ .from(mapping.subject.table)
424
+ .where(eq(subjectColumns(mapping).id, discoveredNative))
425
+ .limit(1),
426
+ locking,
427
+ );
428
+
429
+ const subject = subjectRows[0];
430
+
431
+ if (subject === undefined || !mapping.subject.isActiveStatus(subject[mapping.subject.status]))
432
+ return undefined;
433
+ const identifiers = yield* lockIdentifier(mapping, identifier, locking);
434
+ const identifierRow = identifiers[0];
435
+
436
+ if (
437
+ identifierRow === undefined ||
438
+ !mapping.identifier.isCurrent(identifierRow) ||
439
+ !mapping.subjectId.equals(discoveredNative, identifierRow[mapping.identifier.subjectId])
440
+ )
441
+ return undefined;
442
+ const subjectId = yield* mapping.subjectId.toSubject(discoveredNative);
443
+
444
+ if (requestedSubjectId !== undefined && requestedSubjectId !== subjectId) return undefined;
445
+ const credentials = yield* readPasswordCredential(mapping, moduleId, discoveredNative, locking);
446
+ const credential = credentials[0];
447
+
448
+ if (credential === undefined)
449
+ return { nativeSubjectId: discoveredNative, subject, identifier: identifierRow };
450
+
451
+ const snapshot = yield* mapping.credential
452
+ .decode({ moduleId, subject, identifier: identifierRow, credential })
453
+ .pipe(Effect.flatMap(snapshotPasswordCredential));
454
+
455
+ return {
456
+ nativeSubjectId: discoveredNative,
457
+ subject,
458
+ identifier: identifierRow,
459
+ credential,
460
+ snapshot,
461
+ };
462
+ });
463
+
464
+ interface ScopeEntry {
465
+ readonly kind: PasswordRateScopeKind;
466
+ readonly key: string;
467
+ readonly limit: number;
468
+ readonly windowMillis: number;
469
+ }
470
+
471
+ const scopeEntries = (
472
+ keys: PasswordScopeKeys,
473
+ policy: PasswordAttemptPolicy,
474
+ ): ReadonlyArray<ScopeEntry> => {
475
+ const values: ScopeEntry[] = [
476
+ { kind: "action", key: keys.action, ...policy.action },
477
+ { kind: "identifier", key: keys.identifier, ...policy.identifier },
478
+ ];
479
+
480
+ if (keys.subject !== undefined)
481
+ values.push({ kind: "subject", key: keys.subject, ...policy.subject });
482
+
483
+ return values;
484
+ };
485
+
486
+ const lockScope = Effect.fn("DrizzlePassword.lockScope")(function* (
487
+ mapping: Mapping,
488
+ configuration: PasswordSqlConfiguration,
489
+ moduleId: string,
490
+ action: PasswordAttemptAction,
491
+ entry: ScopeEntry,
492
+ ) {
493
+ const database = yield* CurrentPasswordSql;
494
+
495
+ const query = database.insert(mapping.rateScope.table).values(
496
+ mapping.rateScope.encodeInsert({
497
+ moduleId,
498
+ action,
499
+ scopeKind: entry.kind,
500
+ scopeKey: entry.key,
501
+ }),
502
+ );
503
+
504
+ yield* configuration.insertIfAbsent(query, mapping.rateScope.scopeKey, entry.key);
505
+ const c = scopeColumns(mapping);
506
+
507
+ yield* selectRows(
508
+ database
509
+ .select()
510
+ .from(mapping.rateScope.table)
511
+ .where(
512
+ and(
513
+ eq(c.moduleId, moduleId),
514
+ eq(c.action, action),
515
+ eq(c.scopeKind, entry.kind),
516
+ eq(c.scopeKey, entry.key),
517
+ ),
518
+ )
519
+ .limit(1),
520
+ configuration.locking,
521
+ );
522
+ });
523
+
524
+ const scopeAdmits = Effect.fn("DrizzlePassword.scopeAdmits")(function* (
525
+ mapping: Mapping,
526
+ moduleId: string,
527
+ action: PasswordAttemptAction,
528
+ entry: ScopeEntry,
529
+ policy: PasswordAttemptPolicy,
530
+ identifier: LoginIdentifier,
531
+ nativeSubjectId: unknown | undefined,
532
+ now: number,
533
+ ) {
534
+ const database = yield* CurrentPasswordSql;
535
+
536
+ const c = chargeColumns(mapping);
537
+
538
+ const charges = yield* selectRows(
539
+ database
540
+ .select({ attemptId: c.attemptId })
541
+ .from(mapping.charge.table)
542
+ .where(
543
+ and(
544
+ eq(c.moduleId, moduleId),
545
+ eq(c.action, action),
546
+ eq(c.scopeKind, entry.kind),
547
+ eq(c.scopeKey, entry.key),
548
+ gte(c.occurredAt, mapping.encodeInstant(now - entry.windowMillis)),
549
+ ),
550
+ )
551
+ .limit(entry.limit),
552
+ true,
553
+ );
554
+
555
+ if (charges.length >= entry.limit) return false;
556
+ const a = attemptColumns(mapping);
557
+
558
+ const pendingWhere =
559
+ entry.kind === "action"
560
+ ? and(eq(a.moduleId, moduleId), eq(a.action, action), eq(a.state, "pending"))
561
+ : entry.kind === "identifier"
562
+ ? and(
563
+ eq(a.moduleId, moduleId),
564
+ eq(a.action, action),
565
+ eq(a.identifierNamespace, identifier.namespace),
566
+ eq(a.identifierValue, identifier.value),
567
+ eq(a.state, "pending"),
568
+ )
569
+ : and(
570
+ eq(a.moduleId, moduleId),
571
+ eq(a.action, action),
572
+ eq(a.subjectId, nativeSubjectId),
573
+ eq(a.state, "pending"),
574
+ );
575
+
576
+ const pending = yield* selectRows(
577
+ database
578
+ .select({ attemptId: a.attemptId })
579
+ .from(mapping.attempt.table)
580
+ .where(pendingWhere)
581
+ .limit(policy.maximumPending),
582
+ true,
583
+ );
584
+
585
+ return pending.length < policy.maximumPending;
586
+ });
587
+
588
+ const insertCharge = Effect.fn("Drizzle.insertCharge")(function* (
589
+ mapping: Mapping,
590
+ moduleId: string,
591
+ action: PasswordAttemptAction,
592
+ entry: ScopeEntry,
593
+ attemptId: any,
594
+ now: number,
595
+ ) {
596
+ const database = yield* CurrentPasswordSql;
597
+
598
+ return yield* database.insert(mapping.charge.table).values(
599
+ mapping.charge.encodeInsert({
600
+ moduleId,
601
+ action,
602
+ scopeKind: entry.kind,
603
+ scopeKey: entry.key,
604
+ attemptId,
605
+ occurredAtMillis: now,
606
+ retentionUntilMillis: now + entry.windowMillis,
607
+ }),
608
+ );
609
+ });
610
+
611
+ const owned = <A, E, R>(
612
+ database: Database,
613
+ mapping: Mapping,
614
+ configuration: PasswordSqlConfiguration,
615
+ body: Effect.Effect<A, E, R>,
616
+ ) => {
617
+ if (!validConstraints(mapping)) return Effect.fail(unavailable());
618
+
619
+ const run = coordinateCommit(
620
+ () =>
621
+ database.transaction((transaction) =>
622
+ body.pipe(
623
+ Effect.provideService(CurrentPasswordSql, transaction),
624
+ Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),
625
+ ),
626
+ ),
627
+ { mode: configuration.mode },
628
+ ).pipe(Effect.map((result) => result.value));
629
+
630
+ return configuration.coordinated !== true
631
+ ? Effect.gen(function* () {
632
+ if (yield* hasCommitScope) return yield* unavailable();
633
+ yield* configuration.standaloneGuard;
634
+
635
+ return yield* run;
636
+ })
637
+ : run;
638
+ };
639
+
640
+ const safeRead = <A, E, R>(
641
+ database: Database,
642
+ configuration: PasswordSqlConfiguration,
643
+ body: Effect.Effect<A, E, R>,
644
+ ) =>
645
+ Effect.gen(function* () {
646
+ if (configuration.coordinated !== true) {
647
+ if (yield* hasCommitScope) return yield* unavailable();
648
+ yield* configuration.standaloneGuard;
649
+ }
650
+
651
+ return yield* database.transaction((transaction) =>
652
+ body.pipe(
653
+ Effect.provideService(CurrentPasswordSql, transaction),
654
+ Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),
655
+ ),
656
+ );
657
+ });
658
+
659
+ const proofCompletionMatchesPassword = (
660
+ input: PasswordMutationInput & { readonly completion: ProofCompletionPlan },
661
+ ) => {
662
+ const completion = input.completion.input;
663
+ const binding = completion.binding;
664
+
665
+ if (
666
+ completion.moduleId !== `${input.moduleId}/reset` ||
667
+ completion.purpose !== "password-reset" ||
668
+ binding._tag !== "Subject" ||
669
+ input.credential === undefined ||
670
+ binding.revision.subjectId !== input.expectedRevision.subjectId ||
671
+ binding.revision.securityRevision !== input.expectedRevision.securityRevision ||
672
+ !sameIdentifier(binding.identifier, input.credential.identifier)
673
+ )
674
+ return false;
675
+
676
+ const expected = [...input.expectedRevision.credentials].sort((left, right) =>
677
+ left.credentialId.localeCompare(right.credentialId),
678
+ );
679
+
680
+ const actual = [...binding.revision.credentials].sort((left, right) =>
681
+ left.credentialId.localeCompare(right.credentialId),
682
+ );
683
+
684
+ return (
685
+ expected.length === actual.length &&
686
+ expected.every(
687
+ (item, index) =>
688
+ item.credentialId === actual[index]!.credentialId &&
689
+ item.revision === actual[index]!.revision,
690
+ )
691
+ );
692
+ };
693
+
694
+ const probeProofCompletion = Effect.fn("Drizzle.probeProofCompletion")(function* (
695
+ configuration: PasswordSqlConfiguration,
696
+ input: ProofCompletionInput,
697
+ ) {
698
+ const database = yield* CurrentPasswordSql;
699
+
700
+ if (configuration.proof === undefined) return yield* Effect.fail(unavailable());
701
+ const validProbe = { _tag: "PasswordProofCompletionValid" } as const;
702
+
703
+ const plan: ProofCompletionPlan = {
704
+ input,
705
+ prepare: (decision, journal, project) => journal.prepare(project(decision)),
706
+ };
707
+
708
+ const probe = coordinateCommit(
709
+ () =>
710
+ database.transaction((transaction) =>
711
+ completeProofPlanIn(
712
+ configuration.proof!.mapping,
713
+ configuration.proof!.configuration,
714
+ plan,
715
+ Effect.fail(validProbe),
716
+ () => false,
717
+ ).pipe(Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase)),
718
+ ),
719
+ { mode: configuration.mode },
720
+ );
721
+
722
+ if (configuration.coordinated === true || (yield* hasCommitScope)) return yield* unavailable();
723
+ yield* configuration.standaloneGuard;
724
+
725
+ return yield* probe.pipe(
726
+ Effect.as(false),
727
+ Effect.catchCause((cause) => {
728
+ const reason = cause.reasons[0];
729
+
730
+ return cause.reasons.length === 1 &&
731
+ reason !== undefined &&
732
+ Cause.isFailReason(reason) &&
733
+ reason.error === validProbe
734
+ ? Effect.succeed(true)
735
+ : Effect.failCause(cause);
736
+ }),
737
+ );
738
+ });
739
+
740
+ const validateMutationAuthority = Effect.fn("DrizzlePassword.validateMutationAuthority")(function* (
741
+ mapping: Mapping,
742
+ configuration: PasswordSqlConfiguration,
743
+ input: PasswordMutationInput,
744
+ action: PasswordAction,
745
+ ) {
746
+ const database = yield* CurrentPasswordSql;
747
+
748
+ const locked = yield* lockSubject(
749
+ mapping,
750
+ input.expectedRevision.subjectId,
751
+ configuration.locking,
752
+ );
753
+
754
+ const row = locked.row;
755
+
756
+ if (
757
+ row === undefined ||
758
+ !mapping.subject.isActiveStatus(row[mapping.subject.status]) ||
759
+ row[mapping.subject.securityRevision] !== input.expectedRevision.securityRevision
760
+ )
761
+ return undefined;
762
+ if (
763
+ input.authorization.challenge.moduleId !== input.moduleId ||
764
+ input.authorization.challenge.action !== action ||
765
+ input.authorization.challenge.commandId !== input.commandId ||
766
+ input.authorization.challenge.revision.subjectId !== input.expectedRevision.subjectId ||
767
+ input.authorization.challenge.revision.securityRevision !==
768
+ input.expectedRevision.securityRevision ||
769
+ (input.authorization.evidence.flowId as string) !== (input.commandId as string) ||
770
+ input.authorization.evidence.bindingDigest !== input.authorization.challenge.bindingDigest ||
771
+ input.authorization.evidence.revision.subjectId !== input.expectedRevision.subjectId ||
772
+ input.authorization.evidence.revision.securityRevision !==
773
+ input.expectedRevision.securityRevision ||
774
+ (action === "add-password" &&
775
+ (input.credential !== undefined ||
776
+ input.authorization.challenge.targetCredentialId !== undefined))
777
+ )
778
+ return undefined;
779
+ if (
780
+ input.expectedRevision.credentials.some(
781
+ (expected) =>
782
+ !input.authorization.evidence.revision.credentials.some(
783
+ (actual) =>
784
+ actual.credentialId === expected.credentialId && actual.revision === expected.revision,
785
+ ),
786
+ )
787
+ )
788
+ return undefined;
789
+ if (input.credential !== undefined) {
790
+ const identifier = (yield* lockIdentifier(
791
+ mapping,
792
+ input.credential.identifier,
793
+ configuration.locking,
794
+ ))[0];
795
+
796
+ if (
797
+ identifier === undefined ||
798
+ !mapping.identifier.isCurrent(identifier) ||
799
+ !mapping.subjectId.equals(identifier[mapping.identifier.subjectId], locked.nativeSubjectId) ||
800
+ identifier[mapping.identifier.bindingRevision] !== input.credential.identifierBindingRevision
801
+ )
802
+ return undefined;
803
+ }
804
+
805
+ const allExpected = [
806
+ ...input.expectedRevision.credentials,
807
+ ...input.authorization.evidence.revision.credentials,
808
+ ];
809
+
810
+ const expected = [...new Map(allExpected.map((item) => [item.credentialId, item])).values()].sort(
811
+ (left, right) => left.credentialId.localeCompare(right.credentialId),
812
+ );
813
+
814
+ const ac = authorityCredentialColumns(mapping);
815
+
816
+ const credentialRows =
817
+ expected.length === 0
818
+ ? []
819
+ : yield* selectRows(
820
+ database
821
+ .select()
822
+ .from(mapping.authorityCredential.table)
823
+ .where(
824
+ and(
825
+ eq(ac.subjectId, locked.nativeSubjectId),
826
+ inArray(
827
+ ac.credentialId,
828
+ expected.map((item) => item.credentialId),
829
+ ),
830
+ ),
831
+ )
832
+ .orderBy(ac.credentialId),
833
+ configuration.locking,
834
+ );
835
+
836
+ if (credentialRows.length !== expected.length) return undefined;
837
+ for (let index = 0; index < credentialRows.length; index++) {
838
+ const actual = credentialRows[index]!;
839
+ const wanted = expected[index]!;
840
+
841
+ if (
842
+ actual[mapping.authorityCredential.credentialId] !== wanted.credentialId ||
843
+ actual[mapping.authorityCredential.revision] !== wanted.revision ||
844
+ (mapping.authorityCredential.status !== undefined &&
845
+ mapping.authorityCredential.isActiveStatus?.(actual[mapping.authorityCredential.status]) !==
846
+ true)
847
+ )
848
+ return undefined;
849
+ }
850
+ if (input.credential !== undefined) {
851
+ const identifier = (yield* lockIdentifier(mapping, input.credential.identifier, false))[0];
852
+
853
+ const credential = (yield* readPasswordCredential(
854
+ mapping,
855
+ input.moduleId,
856
+ locked.nativeSubjectId,
857
+ configuration.locking,
858
+ ))[0];
859
+
860
+ if (identifier === undefined || credential === undefined) return undefined;
861
+
862
+ const snapshot = yield* mapping.credential.decode({
863
+ moduleId: input.moduleId,
864
+ subject: row,
865
+ identifier,
866
+ credential,
867
+ });
868
+
869
+ if (!sameCredentialSnapshot(snapshot, input.credential)) return undefined;
870
+ }
871
+ const currentRequirement = yield* mapping.subject.decodeActionRequirement(row, action);
872
+ const now = yield* nowMillis;
873
+
874
+ if (
875
+ !evidenceSatisfiedAt(input.authorization.evidence, input.authorization.requirement, now) ||
876
+ !evidenceSatisfiedAt(input.authorization.evidence, currentRequirement, now)
877
+ )
878
+ return undefined;
879
+ if (
880
+ input.invalidation.existingSessions === "immediate" &&
881
+ mapping.sessionInvalidation !== "same-authority-immediate"
882
+ )
883
+ return undefined;
884
+
885
+ return { ...locked, now };
886
+ });
887
+
888
+ const commandExists = Effect.fn("Drizzle.commandExists")(function* (
889
+ mapping: Mapping,
890
+ moduleId: string,
891
+ commandId: string,
892
+ locking: boolean,
893
+ ) {
894
+ const database = yield* CurrentPasswordSql;
895
+
896
+ const c = commandColumns(mapping);
897
+
898
+ return yield* selectRows(
899
+ database
900
+ .select()
901
+ .from(mapping.command.table)
902
+ .where(and(eq(c.moduleId, moduleId), eq(c.commandId, commandId)))
903
+ .limit(1),
904
+ locking,
905
+ );
906
+ });
907
+
908
+ const insertCommand = Effect.fn("Drizzle.insertCommand")(function* (
909
+ mapping: Mapping,
910
+ input: PasswordMutationInput,
911
+ action: PasswordAction,
912
+ now: number,
913
+ ) {
914
+ const database = yield* CurrentPasswordSql;
915
+
916
+ return yield* database.insert(mapping.command.table).values(
917
+ mapping.command.encodeInsert({
918
+ moduleId: input.moduleId,
919
+ commandId: input.commandId,
920
+ action,
921
+ bindingDigest: input.authorization.challenge.bindingDigest,
922
+ decision: "changed",
923
+ retentionUntilMillis: now + mapping.commandRetentionMillis,
924
+ }),
925
+ );
926
+ });
927
+
928
+ const mutationPostconditions = Effect.fn("DrizzlePassword.mutationPostconditions")(function* (
929
+ mapping: Mapping,
930
+ input: PasswordMutationInput,
931
+ nativeSubjectId: unknown,
932
+ subject: any,
933
+ authorityCredential: any,
934
+ now: number,
935
+ ) {
936
+ if (
937
+ subject === undefined ||
938
+ !mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
939
+ authorityCredential === undefined ||
940
+ (mapping.authorityCredential.status !== undefined &&
941
+ mapping.authorityCredential.isActiveStatus?.(
942
+ authorityCredential[mapping.authorityCredential.status],
943
+ ) !== true)
944
+ )
945
+ return false;
946
+ if (input.credential !== undefined) {
947
+ const identifier = (yield* lockIdentifier(mapping, input.credential.identifier, false))[0];
948
+
949
+ if (
950
+ identifier === undefined ||
951
+ !mapping.identifier.isCurrent(identifier) ||
952
+ !mapping.subjectId.equals(identifier[mapping.identifier.subjectId], nativeSubjectId) ||
953
+ identifier[mapping.identifier.bindingRevision] !== input.credential.identifierBindingRevision
954
+ )
955
+ return false;
956
+
957
+ const credential = (yield* readPasswordCredential(
958
+ mapping,
959
+ input.moduleId,
960
+ nativeSubjectId,
961
+ false,
962
+ ))[0];
963
+
964
+ if (credential === undefined) return false;
965
+
966
+ const decoded = yield* mapping.credential.decode({
967
+ moduleId: input.moduleId,
968
+ subject,
969
+ identifier,
970
+ credential,
971
+ });
972
+
973
+ if (decoded.identifierVerifiedAtMillis !== input.credential.identifierVerifiedAtMillis)
974
+ return false;
975
+ }
976
+ const rows = yield* commandExists(mapping, input.moduleId, input.commandId, false);
977
+ const row = rows[0];
978
+
979
+ return (
980
+ rows.length === 1 &&
981
+ row[mapping.command.action] === input.authorization.challenge.action &&
982
+ row[mapping.command.bindingDigest] === input.authorization.challenge.bindingDigest &&
983
+ row[mapping.command.decision] === "changed" &&
984
+ (yield* mapping.decodeInstant(row[mapping.command.retentionUntil])) ===
985
+ now + mapping.commandRetentionMillis
986
+ );
987
+ });
988
+
989
+ const addPasswordIn = Effect.fn("DrizzlePassword.addPasswordIn")(function* (
990
+ mapping: Mapping,
991
+ configuration: PasswordSqlConfiguration,
992
+ input: PasswordMutationInput,
993
+ revisions: {
994
+ readonly credentialId: string;
995
+ readonly credentialRevision: SecurityRevision;
996
+ readonly verifierVersion: SecurityRevision;
997
+ readonly nextSecurityRevision: SecurityRevision;
998
+ },
999
+ commandNow?: number,
1000
+ ) {
1001
+ const database = yield* CurrentPasswordSql;
1002
+
1003
+ const { credentialId, credentialRevision, verifierVersion, nextSecurityRevision } = revisions;
1004
+
1005
+ const authority = yield* validateMutationAuthority(mapping, configuration, input, "add-password");
1006
+
1007
+ if (authority === undefined) return false;
1008
+ if ((yield* commandExists(mapping, input.moduleId, input.commandId, true)).length) return false;
1009
+ if (
1010
+ (yield* readPasswordCredential(mapping, input.moduleId, authority.nativeSubjectId, true)).length
1011
+ )
1012
+ return false;
1013
+
1014
+ yield* database.insert(mapping.credential.table).values(
1015
+ mapping.credential.encodeInsert({
1016
+ moduleId: input.moduleId,
1017
+ subjectId: authority.nativeSubjectId,
1018
+ credentialId,
1019
+ credentialRevision,
1020
+ verifierVersion,
1021
+ replacement: input.replacement,
1022
+ }),
1023
+ );
1024
+ yield* database.insert(mapping.authorityCredential.table).values(
1025
+ mapping.authorityCredential.encodeInsert({
1026
+ subjectId: authority.nativeSubjectId,
1027
+ credentialId,
1028
+ revision: credentialRevision,
1029
+ }),
1030
+ );
1031
+ yield* database
1032
+ .update(mapping.subject.table)
1033
+ .set(updateValues([[mapping.subject.securityRevision, nextSecurityRevision]]))
1034
+ .where(
1035
+ and(
1036
+ eq(subjectColumns(mapping).id, authority.nativeSubjectId),
1037
+ eq(subjectColumns(mapping).securityRevision, input.expectedRevision.securityRevision),
1038
+ ),
1039
+ );
1040
+ yield* insertCommand(mapping, input, "add-password", commandNow ?? authority.now);
1041
+
1042
+ const inserted = (yield* readPasswordCredential(
1043
+ mapping,
1044
+ input.moduleId,
1045
+ authority.nativeSubjectId,
1046
+ false,
1047
+ ))[0];
1048
+
1049
+ const authorityInserted = (yield* database
1050
+ .select()
1051
+ .from(mapping.authorityCredential.table)
1052
+ .where(
1053
+ and(
1054
+ eq(authorityCredentialColumns(mapping).subjectId, authority.nativeSubjectId),
1055
+ eq(authorityCredentialColumns(mapping).credentialId, credentialId),
1056
+ eq(authorityCredentialColumns(mapping).revision, credentialRevision),
1057
+ ),
1058
+ )
1059
+ .limit(1))[0];
1060
+
1061
+ const subjectUpdated = (yield* database
1062
+ .select()
1063
+ .from(mapping.subject.table)
1064
+ .where(
1065
+ and(
1066
+ eq(subjectColumns(mapping).id, authority.nativeSubjectId),
1067
+ eq(subjectColumns(mapping).securityRevision, nextSecurityRevision),
1068
+ ),
1069
+ )
1070
+ .limit(1))[0];
1071
+
1072
+ if (
1073
+ inserted === undefined ||
1074
+ inserted[mapping.credential.credentialId] !== credentialId ||
1075
+ inserted[mapping.credential.credentialRevision] !== credentialRevision ||
1076
+ inserted[mapping.credential.verifierVersion] !== verifierVersion ||
1077
+ inserted[mapping.credential.verifier] !== Redacted.value(input.replacement.verifier) ||
1078
+ inserted[mapping.credential.normalization] !== input.replacement.normalization ||
1079
+ authorityInserted === undefined ||
1080
+ subjectUpdated === undefined ||
1081
+ !(yield* mutationPostconditions(
1082
+ mapping,
1083
+ input,
1084
+ authority.nativeSubjectId,
1085
+ subjectUpdated,
1086
+ authorityInserted,
1087
+ commandNow ?? authority.now,
1088
+ ))
1089
+ )
1090
+ return yield* unavailable();
1091
+
1092
+ return true;
1093
+ });
1094
+
1095
+ export const makeSqlPasswordPersistence = Effect.fn("makeSqlPasswordPersistence")(function* (
1096
+ database: Database,
1097
+ mapping: Mapping,
1098
+ configuration: PasswordSqlConfiguration,
1099
+ ): Effect.fn.Return<PasswordPersistence["Service"], never, LifecycleHooks> {
1100
+ const hooks = yield* LifecycleHooks;
1101
+
1102
+ return PasswordPersistence.of({
1103
+ admitAttempt: (input, prepare) =>
1104
+ Effect.gen(function* () {
1105
+ const attemptId = yield* allocate(
1106
+ configuration.mode,
1107
+ mapping.allocateAttemptId,
1108
+ mapping.allocateAttemptIdSync,
1109
+ );
1110
+
1111
+ return yield* owned(
1112
+ database,
1113
+ mapping,
1114
+ configuration,
1115
+ Effect.gen(function* () {
1116
+ const transaction = yield* CurrentPasswordSql;
1117
+ const journal = yield* CurrentCommitJournal;
1118
+
1119
+ const resolved = yield* resolveCredential(
1120
+ mapping,
1121
+ input.moduleId,
1122
+ input.identifier,
1123
+ input.subjectId,
1124
+ configuration.locking,
1125
+ );
1126
+
1127
+ const keys = mapping.scopeKeys({
1128
+ moduleId: input.moduleId,
1129
+ action: input.action,
1130
+ identifier: input.identifier,
1131
+ ...(resolved === undefined
1132
+ ? {}
1133
+ : { subjectId: resolved.snapshot?.revision.subjectId }),
1134
+ });
1135
+
1136
+ const scopes = scopeEntries(keys, input.policy);
1137
+ const admitted: ScopeEntry[] = [];
1138
+
1139
+ yield* lockScope(mapping, configuration, input.moduleId, input.action, scopes[0]!);
1140
+ let currentNow = yield* nowMillis;
1141
+
1142
+ if (
1143
+ yield* scopeAdmits(
1144
+ mapping,
1145
+ input.moduleId,
1146
+ input.action,
1147
+ scopes[0]!,
1148
+ input.policy,
1149
+ input.identifier,
1150
+ resolved?.nativeSubjectId,
1151
+ currentNow,
1152
+ )
1153
+ )
1154
+ admitted.push(scopes[0]!);
1155
+ if (admitted.length === 1) {
1156
+ for (const entry of scopes.slice(1)) {
1157
+ yield* lockScope(mapping, configuration, input.moduleId, input.action, entry);
1158
+ currentNow = yield* nowMillis;
1159
+ if (
1160
+ yield* scopeAdmits(
1161
+ mapping,
1162
+ input.moduleId,
1163
+ input.action,
1164
+ entry,
1165
+ input.policy,
1166
+ input.identifier,
1167
+ resolved?.nativeSubjectId,
1168
+ currentNow,
1169
+ )
1170
+ )
1171
+ admitted.push(entry);
1172
+ }
1173
+ }
1174
+ const now = yield* nowMillis;
1175
+
1176
+ for (const entry of admitted)
1177
+ yield* insertCharge(mapping, input.moduleId, input.action, entry, attemptId, now);
1178
+ if (admitted.length !== scopes.length)
1179
+ return prepare({ _tag: "Denied" as const }, journal);
1180
+ const snapshot = resolved?.snapshot;
1181
+ const deadline = now + input.policy.attemptLifetimeMillis;
1182
+
1183
+ const retentionUntil = Math.max(
1184
+ deadline,
1185
+ ...scopes.map((entry) => now + entry.windowMillis),
1186
+ );
1187
+
1188
+ yield* transaction.insert(mapping.attempt.table).values(
1189
+ mapping.attempt.encodeInsert(
1190
+ {
1191
+ moduleId: input.moduleId,
1192
+ action: input.action,
1193
+ attemptId,
1194
+ identifier: input.identifier,
1195
+ ...(snapshot === undefined
1196
+ ? {}
1197
+ : {
1198
+ subjectId: snapshot.revision.subjectId,
1199
+ credentialId: snapshot.credentialId,
1200
+ securityRevision: snapshot.revision.securityRevision,
1201
+ credentialRevision: snapshot.credentialRevision,
1202
+ verifierVersion: snapshot.verifierVersion,
1203
+ identifierBindingRevision: snapshot.identifierBindingRevision,
1204
+ }),
1205
+ admittedAtMillis: now,
1206
+ deadlineMillis: deadline,
1207
+ retentionUntilMillis: retentionUntil,
1208
+ },
1209
+ {
1210
+ ...(resolved?.nativeSubjectId === undefined
1211
+ ? {}
1212
+ : { nativeSubjectId: resolved.nativeSubjectId }),
1213
+ state: "pending",
1214
+ },
1215
+ ),
1216
+ );
1217
+
1218
+ return prepare(
1219
+ {
1220
+ _tag: "Admitted" as const,
1221
+ attemptId,
1222
+ ...(snapshot === undefined ? {} : { credential: snapshot }),
1223
+ },
1224
+ journal,
1225
+ );
1226
+ }),
1227
+ );
1228
+ }).pipe(
1229
+ Effect.provideService(CurrentPasswordSql, database),
1230
+ Effect.provideService(LifecycleHooks, hooks),
1231
+ translateFailure,
1232
+ ),
1233
+ settleAttempt: (uncaptured, prepare) =>
1234
+ Effect.gen(function* () {
1235
+ const captured =
1236
+ uncaptured.captured === undefined
1237
+ ? undefined
1238
+ : yield* snapshotPasswordCredential(uncaptured.captured);
1239
+
1240
+ const input = { ...uncaptured, ...(captured === undefined ? {} : { captured }) };
1241
+
1242
+ return yield* owned(
1243
+ database,
1244
+ mapping,
1245
+ configuration,
1246
+ Effect.gen(function* () {
1247
+ const transaction = yield* CurrentPasswordSql;
1248
+ const journal = yield* CurrentCommitJournal;
1249
+
1250
+ const c = attemptColumns(mapping);
1251
+
1252
+ const discovered = yield* selectRows(
1253
+ transaction
1254
+ .select()
1255
+ .from(mapping.attempt.table)
1256
+ .where(and(eq(c.moduleId, input.moduleId), eq(c.attemptId, input.attemptId)))
1257
+ .limit(1),
1258
+ false,
1259
+ );
1260
+
1261
+ let row = discovered[0];
1262
+
1263
+ if (row === undefined || row[mapping.attempt.state] !== "pending")
1264
+ return prepare("rejected", journal);
1265
+ let decision: PasswordAttemptDecision = "rejected";
1266
+ let current: any;
1267
+ let attemptMatches = false;
1268
+
1269
+ if (input.outcome === "verified" && input.captured !== undefined) {
1270
+ current = yield* resolveCredential(
1271
+ mapping,
1272
+ input.moduleId,
1273
+ input.captured.identifier,
1274
+ input.captured.revision.subjectId,
1275
+ configuration.locking,
1276
+ );
1277
+ attemptMatches =
1278
+ input.captured.moduleId === input.moduleId &&
1279
+ row[mapping.attempt.identifierNamespace] === input.captured.identifier.namespace &&
1280
+ row[mapping.attempt.identifierValue] === input.captured.identifier.value &&
1281
+ mapping.subjectId.equals(
1282
+ row[mapping.attempt.subjectId],
1283
+ current?.nativeSubjectId,
1284
+ ) &&
1285
+ row[mapping.attempt.credentialId] === input.captured.credentialId &&
1286
+ row[mapping.attempt.securityRevision] ===
1287
+ input.captured.revision.securityRevision &&
1288
+ row[mapping.attempt.credentialRevision] === input.captured.credentialRevision &&
1289
+ row[mapping.attempt.verifierVersion] === input.captured.verifierVersion &&
1290
+ row[mapping.attempt.identifierBindingRevision] ===
1291
+ input.captured.identifierBindingRevision;
1292
+ }
1293
+ row = (yield* selectRows(
1294
+ transaction
1295
+ .select()
1296
+ .from(mapping.attempt.table)
1297
+ .where(and(eq(c.moduleId, input.moduleId), eq(c.attemptId, input.attemptId)))
1298
+ .limit(1),
1299
+ configuration.locking,
1300
+ ))[0];
1301
+ if (row === undefined || row[mapping.attempt.state] !== "pending")
1302
+ return prepare("rejected", journal);
1303
+ const now = yield* nowMillis;
1304
+ const deadline = yield* mapping.decodeInstant(row[mapping.attempt.deadline]);
1305
+
1306
+ if (
1307
+ attemptMatches &&
1308
+ current?.snapshot !== undefined &&
1309
+ input.captured !== undefined &&
1310
+ deadline > now &&
1311
+ sameCredentialSnapshot(current.snapshot, input.captured)
1312
+ )
1313
+ decision = "verified";
1314
+ const prepared = prepare(decision, journal);
1315
+
1316
+ yield* transaction
1317
+ .update(mapping.attempt.table)
1318
+ .set(updateValues([[mapping.attempt.state, decision]]))
1319
+ .where(
1320
+ and(
1321
+ eq(c.moduleId, input.moduleId),
1322
+ eq(c.attemptId, input.attemptId),
1323
+ eq(c.state, "pending"),
1324
+ ),
1325
+ );
1326
+ if (
1327
+ decision === "verified" &&
1328
+ input.rehash !== undefined &&
1329
+ current?.snapshot !== undefined
1330
+ ) {
1331
+ const cc = credentialColumns(mapping);
1332
+
1333
+ const nextVersion = yield* allocate(
1334
+ configuration.mode,
1335
+ mapping.allocateRevision,
1336
+ mapping.allocateRevisionSync,
1337
+ );
1338
+
1339
+ yield* transaction
1340
+ .update(mapping.credential.table)
1341
+ .set(mapping.credential.encodeVerifier(input.rehash.nextVerifier, nextVersion))
1342
+ .where(
1343
+ and(
1344
+ eq(cc.moduleId, input.moduleId),
1345
+ eq(cc.subjectId, current.nativeSubjectId),
1346
+ eq(cc.credentialId, current.snapshot.credentialId),
1347
+ eq(cc.credentialRevision, current.snapshot.credentialRevision),
1348
+ eq(cc.verifierVersion, input.rehash.expectedVersion),
1349
+ eq(cc.verifier, Redacted.value(input.rehash.expectedVerifier)),
1350
+ ),
1351
+ );
1352
+ }
1353
+
1354
+ return prepared;
1355
+ }),
1356
+ );
1357
+ }).pipe(
1358
+ Effect.provideService(CurrentPasswordSql, database),
1359
+ Effect.provideService(LifecycleHooks, hooks),
1360
+ translateFailure,
1361
+ ),
1362
+ readForSubject: (input) =>
1363
+ safeRead(
1364
+ database,
1365
+ configuration,
1366
+ Effect.gen(function* () {
1367
+ const transaction = yield* CurrentPasswordSql;
1368
+
1369
+ const locked = yield* lockSubject(mapping, input.subjectId, false);
1370
+
1371
+ if (
1372
+ locked.row === undefined ||
1373
+ !mapping.subject.isActiveStatus(locked.row[mapping.subject.status])
1374
+ )
1375
+ return Option.none();
1376
+
1377
+ const credential = (yield* readPasswordCredential(
1378
+ mapping,
1379
+ input.moduleId,
1380
+ locked.nativeSubjectId,
1381
+ false,
1382
+ ))[0];
1383
+
1384
+ if (credential === undefined) return Option.none();
1385
+ const ic = identifierColumns(mapping);
1386
+
1387
+ const identifiers = yield* transaction
1388
+ .select()
1389
+ .from(mapping.identifier.table)
1390
+ .where(eq(ic.subjectId, locked.nativeSubjectId));
1391
+
1392
+ const identifier = identifiers.find((row: any) => mapping.identifier.isCurrent(row));
1393
+
1394
+ if (identifier === undefined) return Option.none();
1395
+
1396
+ const snapshot = yield* mapping.credential
1397
+ .decode({
1398
+ moduleId: input.moduleId,
1399
+ subject: locked.row,
1400
+ identifier,
1401
+ credential,
1402
+ })
1403
+ .pipe(Effect.flatMap(snapshotPasswordCredential));
1404
+
1405
+ return Option.some(snapshot);
1406
+ }),
1407
+ ).pipe(
1408
+ Effect.provideService(CurrentPasswordSql, database),
1409
+ Effect.provideService(LifecycleHooks, hooks),
1410
+ translateFailure,
1411
+ ),
1412
+ recoveryTarget: (input) =>
1413
+ safeRead(
1414
+ database,
1415
+ configuration,
1416
+ Effect.gen(function* () {
1417
+ const resolved = yield* resolveCredential(
1418
+ mapping,
1419
+ input.moduleId,
1420
+ input.identifier,
1421
+ undefined,
1422
+ false,
1423
+ );
1424
+
1425
+ return resolved?.snapshot === undefined ||
1426
+ resolved.snapshot.identifierVerifiedAtMillis === undefined
1427
+ ? Option.none()
1428
+ : Option.some(resolved.snapshot);
1429
+ }),
1430
+ ).pipe(
1431
+ Effect.provideService(CurrentPasswordSql, database),
1432
+ Effect.provideService(LifecycleHooks, hooks),
1433
+ translateFailure,
1434
+ ),
1435
+ addIfAbsent: (uncaptured, prepare) =>
1436
+ Effect.gen(function* () {
1437
+ const input = yield* snapshotMutationInput(uncaptured);
1438
+
1439
+ const credentialId = yield* allocate(
1440
+ configuration.mode,
1441
+ mapping.allocateCredentialId,
1442
+ mapping.allocateCredentialIdSync,
1443
+ );
1444
+
1445
+ const credentialRevision = yield* allocate(
1446
+ configuration.mode,
1447
+ mapping.allocateRevision,
1448
+ mapping.allocateRevisionSync,
1449
+ );
1450
+
1451
+ const verifierVersion = yield* allocate(
1452
+ configuration.mode,
1453
+ mapping.allocateRevision,
1454
+ mapping.allocateRevisionSync,
1455
+ );
1456
+
1457
+ const nextSecurityRevision = yield* allocateNextSecurityRevision(
1458
+ mapping,
1459
+ configuration.mode,
1460
+ input.expectedRevision.securityRevision,
1461
+ );
1462
+
1463
+ if (nextSecurityRevision === input.expectedRevision.securityRevision)
1464
+ return yield* unavailable();
1465
+
1466
+ return yield* owned(
1467
+ database,
1468
+ mapping,
1469
+ configuration,
1470
+ Effect.gen(function* () {
1471
+ const journal = yield* CurrentCommitJournal;
1472
+
1473
+ const changed = yield* addPasswordIn(mapping, configuration, input, {
1474
+ credentialId,
1475
+ credentialRevision,
1476
+ verifierVersion,
1477
+ nextSecurityRevision,
1478
+ });
1479
+
1480
+ return prepare(changed ? "changed" : "rejected", journal);
1481
+ }),
1482
+ );
1483
+ }).pipe(
1484
+ Effect.provideService(CurrentPasswordSql, database),
1485
+ Effect.provideService(LifecycleHooks, hooks),
1486
+ translateFailure,
1487
+ ),
1488
+ replaceIfCurrent: (uncaptured, prepare) =>
1489
+ Effect.gen(function* () {
1490
+ const input = yield* snapshotMutationInput(uncaptured);
1491
+
1492
+ const credentialRevision = yield* allocate(
1493
+ configuration.mode,
1494
+ mapping.allocateRevision,
1495
+ mapping.allocateRevisionSync,
1496
+ );
1497
+
1498
+ const verifierVersion = yield* allocate(
1499
+ configuration.mode,
1500
+ mapping.allocateRevision,
1501
+ mapping.allocateRevisionSync,
1502
+ );
1503
+
1504
+ const nextSecurityRevision = yield* allocateNextSecurityRevision(
1505
+ mapping,
1506
+ configuration.mode,
1507
+ input.expectedRevision.securityRevision,
1508
+ );
1509
+
1510
+ if (
1511
+ nextSecurityRevision === input.expectedRevision.securityRevision ||
1512
+ (input.credential !== undefined &&
1513
+ credentialRevision === input.credential.credentialRevision)
1514
+ )
1515
+ return yield* unavailable();
1516
+
1517
+ return yield* owned(
1518
+ database,
1519
+ mapping,
1520
+ configuration,
1521
+ Effect.gen(function* () {
1522
+ return yield* replaceIn(
1523
+ mapping,
1524
+ configuration,
1525
+ input,
1526
+ "change-password",
1527
+ { credentialRevision, verifierVersion, nextSecurityRevision },
1528
+ prepare,
1529
+ );
1530
+ }),
1531
+ );
1532
+ }).pipe(
1533
+ Effect.provideService(CurrentPasswordSql, database),
1534
+ Effect.provideService(LifecycleHooks, hooks),
1535
+ translateFailure,
1536
+ ),
1537
+ checkReset: (input) =>
1538
+ (configuration.proof === undefined
1539
+ ? Effect.fail(unavailable())
1540
+ : Effect.gen(function* () {
1541
+ if (
1542
+ input.moduleId.length <= "/reset".length ||
1543
+ !input.moduleId.endsWith("/reset") ||
1544
+ input.purpose !== "password-reset" ||
1545
+ input.binding._tag !== "Subject"
1546
+ )
1547
+ return false;
1548
+ const binding = input.binding;
1549
+ const passwordModuleId = input.moduleId.slice(0, -"/reset".length);
1550
+
1551
+ const current = yield* safeRead(
1552
+ database,
1553
+ configuration,
1554
+ Effect.gen(function* () {
1555
+ const resolved = yield* resolveCredential(
1556
+ mapping,
1557
+ passwordModuleId,
1558
+ binding.identifier,
1559
+ binding.revision.subjectId,
1560
+ false,
1561
+ );
1562
+
1563
+ return (
1564
+ resolved?.snapshot !== undefined &&
1565
+ resolved.snapshot.revision.securityRevision ===
1566
+ binding.revision.securityRevision &&
1567
+ binding.revision.credentials.every((item) =>
1568
+ resolved.snapshot!.revision.credentials.some(
1569
+ (actual) =>
1570
+ actual.credentialId === item.credentialId &&
1571
+ actual.revision === item.revision,
1572
+ ),
1573
+ )
1574
+ );
1575
+ }),
1576
+ );
1577
+
1578
+ return current ? yield* probeProofCompletion(configuration, input) : false;
1579
+ })
1580
+ ).pipe(
1581
+ Effect.provideService(CurrentPasswordSql, database),
1582
+ Effect.provideService(LifecycleHooks, hooks),
1583
+ translateFailure,
1584
+ ),
1585
+ resetWithProof: (uncaptured, prepare) =>
1586
+ (configuration.proof === undefined
1587
+ ? Effect.fail(unavailable())
1588
+ : Effect.gen(function* () {
1589
+ const input = Object.freeze({
1590
+ ...(yield* snapshotMutationInput(uncaptured)),
1591
+ completion: uncaptured.completion,
1592
+ });
1593
+
1594
+ const credentialRevision = yield* allocate(
1595
+ configuration.mode,
1596
+ mapping.allocateRevision,
1597
+ mapping.allocateRevisionSync,
1598
+ );
1599
+
1600
+ const verifierVersion = yield* allocate(
1601
+ configuration.mode,
1602
+ mapping.allocateRevision,
1603
+ mapping.allocateRevisionSync,
1604
+ );
1605
+
1606
+ const nextSecurityRevision = yield* allocateNextSecurityRevision(
1607
+ mapping,
1608
+ configuration.mode,
1609
+ input.expectedRevision.securityRevision,
1610
+ );
1611
+
1612
+ if (
1613
+ nextSecurityRevision === input.expectedRevision.securityRevision ||
1614
+ (input.credential !== undefined &&
1615
+ credentialRevision === input.credential.credentialRevision)
1616
+ )
1617
+ return yield* unavailable();
1618
+
1619
+ return yield* owned(
1620
+ database,
1621
+ mapping,
1622
+ configuration,
1623
+ Effect.gen(function* () {
1624
+ const journal = yield* CurrentCommitJournal;
1625
+
1626
+ if (!proofCompletionMatchesPassword(input)) return prepare("rejected", journal);
1627
+
1628
+ const authority = yield* validateMutationAuthority(
1629
+ mapping,
1630
+ configuration,
1631
+ input,
1632
+ "reset-password",
1633
+ );
1634
+
1635
+ if (authority === undefined) return prepare("rejected", journal);
1636
+ if ((yield* commandExists(mapping, input.moduleId, input.commandId, true)).length)
1637
+ return prepare("rejected", journal);
1638
+
1639
+ const current = yield* currentExpectedCredential(
1640
+ mapping,
1641
+ input,
1642
+ authority.nativeSubjectId,
1643
+ );
1644
+
1645
+ if (!current) return prepare("rejected", journal);
1646
+ let passwordReceipt: PreparedCommit<any> | undefined;
1647
+
1648
+ yield* completeProofPlanIn(
1649
+ configuration.proof!.mapping,
1650
+ configuration.proof!.configuration,
1651
+ input.completion,
1652
+ Effect.gen(function* () {
1653
+ return yield* writeReplacement(
1654
+ mapping,
1655
+ input,
1656
+ authority.nativeSubjectId,
1657
+ { credentialRevision, verifierVersion, nextSecurityRevision },
1658
+ authority.now,
1659
+ );
1660
+ }),
1661
+ (decision) => {
1662
+ passwordReceipt = prepare(
1663
+ decision === "completed" ? "changed" : "rejected",
1664
+ journal,
1665
+ );
1666
+
1667
+ return decision;
1668
+ },
1669
+ );
1670
+
1671
+ return passwordReceipt ?? prepare("rejected", journal);
1672
+ }),
1673
+ );
1674
+ })
1675
+ ).pipe(
1676
+ Effect.provideService(CurrentPasswordSql, database),
1677
+ Effect.provideService(LifecycleHooks, hooks),
1678
+ translateFailure,
1679
+ ),
1680
+ cleanupAttempts: (input, prepare) =>
1681
+ owned(
1682
+ database,
1683
+ mapping,
1684
+ configuration,
1685
+ Effect.gen(function* () {
1686
+ const transaction = yield* CurrentPasswordSql;
1687
+ const journal = yield* CurrentCommitJournal;
1688
+
1689
+ const now = yield* nowMillis;
1690
+ const nativeNow = mapping.encodeInstant(now);
1691
+ let remaining = input.limit;
1692
+ let hasMore = false;
1693
+ const a = attemptColumns(mapping);
1694
+ const c = chargeColumns(mapping);
1695
+
1696
+ const attempts = yield* selectRows(
1697
+ transaction
1698
+ .select({ attemptId: a.attemptId })
1699
+ .from(mapping.attempt.table)
1700
+ .where(and(eq(a.moduleId, input.moduleId), lte(a.retentionUntil, nativeNow)))
1701
+ .limit(remaining + 1),
1702
+ false,
1703
+ );
1704
+
1705
+ if (attempts.length > remaining) hasMore = true;
1706
+ const attemptCandidates = attempts.slice(0, remaining);
1707
+
1708
+ remaining -= attemptCandidates.length;
1709
+
1710
+ const charges = yield* selectRows(
1711
+ transaction
1712
+ .select({
1713
+ action: c.action,
1714
+ scopeKind: c.scopeKind,
1715
+ scopeKey: c.scopeKey,
1716
+ attemptId: c.attemptId,
1717
+ })
1718
+ .from(mapping.charge.table)
1719
+ .where(and(eq(c.moduleId, input.moduleId), lte(c.retentionUntil, nativeNow)))
1720
+ .limit(remaining + 1),
1721
+ false,
1722
+ );
1723
+
1724
+ if (charges.length > remaining) hasMore = true;
1725
+ const chargeCandidates = charges.slice(0, remaining);
1726
+
1727
+ remaining -= chargeCandidates.length;
1728
+ const sc = scopeColumns(mapping);
1729
+
1730
+ const scopes = yield* selectRows(
1731
+ transaction
1732
+ .select({ action: sc.action, scopeKind: sc.scopeKind, scopeKey: sc.scopeKey })
1733
+ .from(mapping.rateScope.table)
1734
+ .where(
1735
+ and(
1736
+ eq(sc.moduleId, input.moduleId),
1737
+ notExists(
1738
+ transaction
1739
+ .select({ one: sql`1` })
1740
+ .from(mapping.charge.table)
1741
+ .where(
1742
+ and(
1743
+ eq(c.moduleId, sc.moduleId),
1744
+ eq(c.action, sc.action),
1745
+ eq(c.scopeKind, sc.scopeKind),
1746
+ eq(c.scopeKey, sc.scopeKey),
1747
+ ),
1748
+ ),
1749
+ ),
1750
+ ),
1751
+ )
1752
+ .limit(remaining + 1),
1753
+ remaining === 0 ? false : configuration.locking,
1754
+ );
1755
+
1756
+ if (scopes.length > remaining) hasMore = true;
1757
+ const selectedScopes = scopes.slice(0, remaining);
1758
+
1759
+ remaining -= selectedScopes.length;
1760
+ const selectedCharges: typeof chargeCandidates = [];
1761
+
1762
+ for (const candidate of chargeCandidates) {
1763
+ const locked = yield* selectRows(
1764
+ transaction
1765
+ .select({
1766
+ action: c.action,
1767
+ scopeKind: c.scopeKind,
1768
+ scopeKey: c.scopeKey,
1769
+ attemptId: c.attemptId,
1770
+ })
1771
+ .from(mapping.charge.table)
1772
+ .where(
1773
+ and(
1774
+ eq(c.moduleId, input.moduleId),
1775
+ eq(c.action, candidate.action),
1776
+ eq(c.scopeKind, candidate.scopeKind),
1777
+ eq(c.scopeKey, candidate.scopeKey),
1778
+ eq(c.attemptId, candidate.attemptId),
1779
+ lte(c.retentionUntil, nativeNow),
1780
+ ),
1781
+ )
1782
+ .limit(1),
1783
+ configuration.locking,
1784
+ );
1785
+
1786
+ if (locked[0] !== undefined) selectedCharges.push(locked[0] as any);
1787
+ }
1788
+ const selectedAttempts: typeof attemptCandidates = [];
1789
+
1790
+ for (const candidate of attemptCandidates) {
1791
+ const locked = yield* selectRows(
1792
+ transaction
1793
+ .select({ attemptId: a.attemptId })
1794
+ .from(mapping.attempt.table)
1795
+ .where(
1796
+ and(
1797
+ eq(a.moduleId, input.moduleId),
1798
+ eq(a.attemptId, candidate.attemptId),
1799
+ lte(a.retentionUntil, nativeNow),
1800
+ ),
1801
+ )
1802
+ .limit(1),
1803
+ configuration.locking,
1804
+ );
1805
+
1806
+ if (locked[0] !== undefined) selectedAttempts.push(locked[0] as any);
1807
+ }
1808
+
1809
+ const prepared = prepare(
1810
+ {
1811
+ removed: selectedAttempts.length + selectedCharges.length + selectedScopes.length,
1812
+ hasMore,
1813
+ },
1814
+ journal,
1815
+ );
1816
+
1817
+ for (const row of selectedCharges)
1818
+ yield* transaction
1819
+ .delete(mapping.charge.table)
1820
+ .where(
1821
+ and(
1822
+ eq(c.moduleId, input.moduleId),
1823
+ eq(c.action, row.action),
1824
+ eq(c.scopeKind, row.scopeKind),
1825
+ eq(c.scopeKey, row.scopeKey),
1826
+ eq(c.attemptId, row.attemptId),
1827
+ lte(c.retentionUntil, nativeNow),
1828
+ ),
1829
+ );
1830
+ if (selectedAttempts.length > 0)
1831
+ yield* transaction.delete(mapping.attempt.table).where(
1832
+ and(
1833
+ eq(a.moduleId, input.moduleId),
1834
+ inArray(
1835
+ a.attemptId,
1836
+ selectedAttempts.map((row: any) => row.attemptId),
1837
+ ),
1838
+ lte(a.retentionUntil, nativeNow),
1839
+ ),
1840
+ );
1841
+ for (const row of selectedScopes)
1842
+ yield* transaction.delete(mapping.rateScope.table).where(
1843
+ and(
1844
+ eq(sc.moduleId, input.moduleId),
1845
+ eq(sc.action, row.action),
1846
+ eq(sc.scopeKind, row.scopeKind),
1847
+ eq(sc.scopeKey, row.scopeKey),
1848
+ notExists(
1849
+ transaction
1850
+ .select({ one: sql`1` })
1851
+ .from(mapping.charge.table)
1852
+ .where(
1853
+ and(
1854
+ eq(c.moduleId, sc.moduleId),
1855
+ eq(c.action, sc.action),
1856
+ eq(c.scopeKind, sc.scopeKind),
1857
+ eq(c.scopeKey, sc.scopeKey),
1858
+ ),
1859
+ ),
1860
+ ),
1861
+ ),
1862
+ );
1863
+
1864
+ return prepared;
1865
+ }),
1866
+ ).pipe(
1867
+ Effect.provideService(CurrentPasswordSql, database),
1868
+ Effect.provideService(LifecycleHooks, hooks),
1869
+ translateFailure,
1870
+ ),
1871
+ });
1872
+ });
1873
+
1874
+ const currentExpectedCredential = Effect.fn("DrizzlePassword.currentExpectedCredential")(function* (
1875
+ mapping: Mapping,
1876
+ input: PasswordMutationInput,
1877
+ nativeSubjectId: unknown,
1878
+ ) {
1879
+ if (input.credential === undefined) return false;
1880
+ const row = (yield* readPasswordCredential(mapping, input.moduleId, nativeSubjectId, true))[0];
1881
+
1882
+ if (row === undefined) return false;
1883
+
1884
+ return (
1885
+ row[mapping.credential.credentialId] === input.credential.credentialId &&
1886
+ row[mapping.credential.credentialRevision] === input.credential.credentialRevision &&
1887
+ row[mapping.credential.verifierVersion] === input.credential.verifierVersion &&
1888
+ row[mapping.credential.verifier] === Redacted.value(input.credential.verifier) &&
1889
+ row[mapping.credential.normalization] === input.credential.normalization &&
1890
+ input.authorization.challenge.targetCredentialId === input.credential.credentialId
1891
+ );
1892
+ });
1893
+
1894
+ const checkMutationApplied = Effect.fn("DrizzlePassword.checkMutationApplied")(function* (
1895
+ mapping: Mapping,
1896
+ input: PasswordMutationInput,
1897
+ nativeSubjectId: unknown,
1898
+ revisions: {
1899
+ readonly credentialId: string;
1900
+ readonly credentialRevision: SecurityRevision;
1901
+ readonly verifierVersion: SecurityRevision;
1902
+ readonly nextSecurityRevision: SecurityRevision;
1903
+ },
1904
+ now: number,
1905
+ ) {
1906
+ const database = yield* CurrentPasswordSql;
1907
+
1908
+ const c = credentialColumns(mapping),
1909
+ s = subjectColumns(mapping);
1910
+
1911
+ const credential = (yield* database
1912
+ .select()
1913
+ .from(mapping.credential.table)
1914
+ .where(
1915
+ and(
1916
+ eq(c.moduleId, input.moduleId),
1917
+ eq(c.subjectId, nativeSubjectId),
1918
+ eq(c.credentialId, revisions.credentialId),
1919
+ eq(c.credentialRevision, revisions.credentialRevision),
1920
+ eq(c.verifierVersion, revisions.verifierVersion),
1921
+ eq(c.verifier, Redacted.value(input.replacement.verifier)),
1922
+ eq(c.normalization, input.replacement.normalization),
1923
+ ),
1924
+ )
1925
+ .limit(1))[0];
1926
+
1927
+ const subject = (yield* database
1928
+ .select()
1929
+ .from(mapping.subject.table)
1930
+ .where(and(eq(s.id, nativeSubjectId), eq(s.securityRevision, revisions.nextSecurityRevision)))
1931
+ .limit(1))[0];
1932
+
1933
+ const authorityCredential = (yield* database
1934
+ .select()
1935
+ .from(mapping.authorityCredential.table)
1936
+ .where(
1937
+ and(
1938
+ eq(authorityCredentialColumns(mapping).subjectId, nativeSubjectId),
1939
+ eq(authorityCredentialColumns(mapping).credentialId, revisions.credentialId),
1940
+ eq(authorityCredentialColumns(mapping).revision, revisions.credentialRevision),
1941
+ ),
1942
+ )
1943
+ .limit(1))[0];
1944
+
1945
+ return (
1946
+ credential !== undefined &&
1947
+ (yield* mutationPostconditions(
1948
+ mapping,
1949
+ input,
1950
+ nativeSubjectId,
1951
+ subject,
1952
+ authorityCredential,
1953
+ now,
1954
+ ))
1955
+ );
1956
+ });
1957
+
1958
+ const writeReplacement = Effect.fn("DrizzlePassword.writeReplacement")(function* (
1959
+ mapping: Mapping,
1960
+ input: PasswordMutationInput,
1961
+ nativeSubjectId: unknown,
1962
+ revisions: {
1963
+ readonly credentialRevision: SecurityRevision;
1964
+ readonly verifierVersion: SecurityRevision;
1965
+ readonly nextSecurityRevision: SecurityRevision;
1966
+ },
1967
+ now: number,
1968
+ ) {
1969
+ const database = yield* CurrentPasswordSql;
1970
+
1971
+ const c = credentialColumns(mapping);
1972
+ const s = subjectColumns(mapping);
1973
+
1974
+ yield* database
1975
+ .update(mapping.credential.table)
1976
+ .set(
1977
+ mapping.credential.encodeReplacement({
1978
+ replacement: input.replacement,
1979
+ credentialRevision: revisions.credentialRevision,
1980
+ verifierVersion: revisions.verifierVersion,
1981
+ }),
1982
+ )
1983
+ .where(
1984
+ and(
1985
+ eq(c.moduleId, input.moduleId),
1986
+ eq(c.subjectId, nativeSubjectId),
1987
+ eq(c.credentialId, input.credential!.credentialId),
1988
+ eq(c.credentialRevision, input.credential!.credentialRevision),
1989
+ eq(c.verifierVersion, input.credential!.verifierVersion),
1990
+ eq(c.verifier, Redacted.value(input.credential!.verifier)),
1991
+ eq(c.normalization, input.credential!.normalization),
1992
+ ),
1993
+ );
1994
+ yield* database
1995
+ .update(mapping.subject.table)
1996
+ .set(updateValues([[mapping.subject.securityRevision, revisions.nextSecurityRevision]]))
1997
+ .where(
1998
+ and(
1999
+ eq(s.id, nativeSubjectId),
2000
+ eq(s.securityRevision, input.expectedRevision.securityRevision),
2001
+ ),
2002
+ );
2003
+ yield* database
2004
+ .update(mapping.authorityCredential.table)
2005
+ .set(mapping.authorityCredential.encodeRevision(revisions.credentialRevision))
2006
+ .where(
2007
+ and(
2008
+ eq(authorityCredentialColumns(mapping).subjectId, nativeSubjectId),
2009
+ eq(authorityCredentialColumns(mapping).credentialId, input.credential!.credentialId),
2010
+ eq(authorityCredentialColumns(mapping).revision, input.credential!.credentialRevision),
2011
+ ),
2012
+ );
2013
+ yield* insertCommand(mapping, input, input.authorization.challenge.action, now);
2014
+
2015
+ return yield* checkMutationApplied(
2016
+ mapping,
2017
+ input,
2018
+ nativeSubjectId,
2019
+ {
2020
+ ...revisions,
2021
+ credentialId: input.credential!.credentialId,
2022
+ },
2023
+ now,
2024
+ );
2025
+ });
2026
+
2027
+ const replaceIn = Effect.fn("Drizzle.replaceIn")(function* <A>(
2028
+ mapping: Mapping,
2029
+ configuration: PasswordSqlConfiguration,
2030
+ input: PasswordMutationInput,
2031
+ action: PasswordAction,
2032
+ revisions: {
2033
+ readonly credentialRevision: SecurityRevision;
2034
+ readonly verifierVersion: SecurityRevision;
2035
+ readonly nextSecurityRevision: SecurityRevision;
2036
+ },
2037
+ prepare: (value: PasswordMutationDecision, journal: CommitJournal) => PreparedCommit<A>,
2038
+ ) {
2039
+ const journal = yield* CurrentCommitJournal;
2040
+
2041
+ const authority = yield* validateMutationAuthority(mapping, configuration, input, action);
2042
+
2043
+ if (authority === undefined) return prepare("rejected", journal);
2044
+ if ((yield* commandExists(mapping, input.moduleId, input.commandId, true)).length)
2045
+ return prepare("rejected", journal);
2046
+ if (!(yield* currentExpectedCredential(mapping, input, authority.nativeSubjectId)))
2047
+ return prepare("rejected", journal);
2048
+ const prepared = prepare("changed", journal);
2049
+
2050
+ if (
2051
+ !(yield* writeReplacement(mapping, input, authority.nativeSubjectId, revisions, authority.now))
2052
+ )
2053
+ return yield* unavailable();
2054
+
2055
+ return prepared;
2056
+ });
2057
+
2058
+ /** Internal bound-owner primitives; deliberately not re-exported by driver modules. */
2059
+ export const passwordSqlKernel = {
2060
+ allocate,
2061
+ allocateNextSecurityRevision,
2062
+ owned,
2063
+ safeRead,
2064
+ snapshotMutationInput,
2065
+ lockSubject,
2066
+ lockIdentifier,
2067
+ readPasswordCredential,
2068
+ resolveCredential,
2069
+ validateMutationAuthority,
2070
+ currentExpectedCredential,
2071
+ commandExists,
2072
+ addPasswordIn,
2073
+ checkMutationApplied,
2074
+ writeReplacement,
2075
+ evidenceSatisfiedAt,
2076
+ sameCredentialSnapshot,
2077
+ subjectColumns,
2078
+ identifierColumns,
2079
+ credentialColumns,
2080
+ authorityCredentialColumns,
2081
+ proofCompletionMatchesPassword,
2082
+ };