@yielded/auth-persistence 0.1.0-beta.25 → 0.1.0-beta.27
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.
- package/README.md +6 -8
- package/dist/Adapter.d.mts +47 -33
- package/dist/Adapter.mjs +36 -23
- package/dist/OAuthPersistence.d.mts +35 -51
- package/dist/OAuthPersistence.mjs +60 -68
- package/dist/OAuthPersistence.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/internal/browser-login.d.mts +1 -1
- package/dist/internal/browser-login.mjs +29 -9
- package/dist/internal/browser-login.mjs.map +1 -1
- package/dist/internal/configuration.d.mts +13 -8
- package/dist/internal/configuration.mjs.map +1 -1
- package/dist/internal/crypto.d.mts +1 -0
- package/dist/internal/crypto.mjs +1 -1
- package/dist/internal/d1-planning.mjs +8 -0
- package/dist/internal/d1-planning.mjs.map +1 -0
- package/dist/internal/email-native-state.mjs +135 -0
- package/dist/internal/email-native-state.mjs.map +1 -0
- package/dist/internal/email-native.d.mts +17 -0
- package/dist/internal/email-native.mjs +245 -0
- package/dist/internal/email-native.mjs.map +1 -0
- package/dist/internal/email-policy.mjs +92 -0
- package/dist/internal/email-policy.mjs.map +1 -0
- package/dist/internal/email-registration-native.d.mts +38 -0
- package/dist/internal/email-registration-native.mjs +171 -0
- package/dist/internal/email-registration-native.mjs.map +1 -0
- package/dist/internal/models/email-model.d.mts +40 -104
- package/dist/internal/models/email-model.mjs +3 -5
- package/dist/internal/models/email-model.mjs.map +1 -1
- package/dist/internal/models/oauth-connected-model.d.mts +44 -213
- package/dist/internal/models/oauth-connected-model.mjs +6 -14
- package/dist/internal/models/oauth-connected-model.mjs.map +1 -1
- package/dist/internal/models/oauth-model.d.mts +95 -244
- package/dist/internal/models/oauth-model.mjs +28 -22
- package/dist/internal/models/oauth-model.mjs.map +1 -1
- package/dist/internal/models/passkey-model.d.mts +11 -147
- package/dist/internal/models/passkey-model.mjs +5 -24
- package/dist/internal/models/passkey-model.mjs.map +1 -1
- package/dist/internal/models/passkey-registration-ceremony-model.d.mts +5 -39
- package/dist/internal/models/passkey-write-model.d.mts +17 -75
- package/dist/internal/models/passkey-write-model.mjs +1 -7
- package/dist/internal/models/passkey-write-model.mjs.map +1 -1
- package/dist/internal/models/password-model.d.mts +14 -81
- package/dist/internal/models/password-model.mjs +1 -4
- package/dist/internal/models/password-model.mjs.map +1 -1
- package/dist/internal/models/phone-model.d.mts +86 -0
- package/dist/internal/models/phone-model.mjs +10 -0
- package/dist/internal/models/phone-model.mjs.map +1 -0
- package/dist/internal/models/proof-model.d.mts +43 -272
- package/dist/internal/models/proof-model.mjs +2 -10
- package/dist/internal/models/proof-model.mjs.map +1 -1
- package/dist/internal/models/session-model.d.mts +74 -93
- package/dist/internal/models/session-model.mjs +3 -11
- package/dist/internal/models/session-model.mjs.map +1 -1
- package/dist/internal/models/step-up-model.d.mts +12 -50
- package/dist/internal/models/step-up-model.mjs +2 -4
- package/dist/internal/models/step-up-model.mjs.map +1 -1
- package/dist/internal/models/totp-model.d.mts +76 -0
- package/dist/internal/models/totp-model.mjs +10 -0
- package/dist/internal/models/totp-model.mjs.map +1 -0
- package/dist/internal/native-sql-table.d.mts +21 -4
- package/dist/internal/native-sql-table.mjs +9 -5
- package/dist/internal/native-sql-table.mjs.map +1 -1
- package/dist/internal/oauth/native-accounts.d.mts +17 -0
- package/dist/internal/oauth/native-accounts.mjs +290 -0
- package/dist/internal/oauth/native-accounts.mjs.map +1 -0
- package/dist/internal/oauth/native-connected-state.d.mts +11 -0
- package/dist/internal/oauth/native-connected-state.mjs +146 -0
- package/dist/internal/oauth/native-connected-state.mjs.map +1 -0
- package/dist/internal/oauth/native-connected.d.mts +15 -0
- package/dist/internal/oauth/native-connected.mjs +462 -0
- package/dist/internal/oauth/native-connected.mjs.map +1 -0
- package/dist/internal/oauth/native-flow.mjs +138 -0
- package/dist/internal/oauth/native-flow.mjs.map +1 -0
- package/dist/internal/oauth/native-layers.d.mts +24 -0
- package/dist/internal/oauth/native-layers.mjs +13 -0
- package/dist/internal/oauth/native-layers.mjs.map +1 -0
- package/dist/internal/oauth/native-mutation.mjs +122 -0
- package/dist/internal/oauth/native-mutation.mjs.map +1 -0
- package/dist/internal/oauth/native-registration.d.mts +24 -0
- package/dist/internal/oauth/native-registration.mjs +328 -0
- package/dist/internal/oauth/native-registration.mjs.map +1 -0
- package/dist/internal/oauth/native-revocations.d.mts +17 -0
- package/dist/internal/oauth/native-revocations.mjs +106 -0
- package/dist/internal/oauth/native-revocations.mjs.map +1 -0
- package/dist/internal/oauth/native-sign-in.d.mts +17 -0
- package/dist/internal/oauth/native-sign-in.mjs +50 -0
- package/dist/internal/oauth/native-sign-in.mjs.map +1 -0
- package/dist/internal/oauth/native-state.d.mts +10 -0
- package/dist/internal/oauth/native-state.mjs +214 -0
- package/dist/internal/oauth/native-state.mjs.map +1 -0
- package/dist/internal/oauth/state.d.mts +10 -0
- package/dist/internal/oauth/state.mjs +3 -27
- package/dist/internal/oauth/state.mjs.map +1 -1
- package/dist/internal/passkey-actions.mjs +55 -0
- package/dist/internal/passkey-actions.mjs.map +1 -0
- package/dist/internal/passkey-inputs.mjs +73 -0
- package/dist/internal/passkey-inputs.mjs.map +1 -0
- package/dist/internal/passkey-managed.mjs +224 -0
- package/dist/internal/passkey-managed.mjs.map +1 -0
- package/dist/internal/passkey-native-ceremony.d.mts +35 -0
- package/dist/internal/passkey-native-ceremony.mjs +38 -0
- package/dist/internal/passkey-native-ceremony.mjs.map +1 -0
- package/dist/internal/passkey-native-flow.mjs +91 -0
- package/dist/internal/passkey-native-flow.mjs.map +1 -0
- package/dist/internal/passkey-native-registration.d.mts +10 -0
- package/dist/internal/passkey-native-registration.mjs +114 -0
- package/dist/internal/passkey-native-registration.mjs.map +1 -0
- package/dist/internal/passkey-native-state.d.mts +15 -0
- package/dist/internal/passkey-native-state.mjs +186 -0
- package/dist/internal/passkey-native-state.mjs.map +1 -0
- package/dist/internal/passkey-native-write.d.mts +82 -0
- package/dist/internal/passkey-native-write.mjs +330 -0
- package/dist/internal/passkey-native-write.mjs.map +1 -0
- package/dist/internal/passkey-native.d.mts +835 -0
- package/dist/internal/passkey-native.mjs +175 -0
- package/dist/internal/passkey-native.mjs.map +1 -0
- package/dist/internal/passkey-policy.mjs +115 -0
- package/dist/internal/passkey-policy.mjs.map +1 -0
- package/dist/internal/password-credentials.mjs +38 -9
- package/dist/internal/password-credentials.mjs.map +1 -1
- package/dist/internal/password-native.d.mts +14 -0
- package/dist/internal/password-native.mjs +292 -0
- package/dist/internal/password-native.mjs.map +1 -0
- package/dist/internal/password-policy.mjs +93 -0
- package/dist/internal/password-policy.mjs.map +1 -0
- package/dist/internal/password-registration-native.d.mts +22 -0
- package/dist/internal/password-registration-native.mjs +142 -0
- package/dist/internal/password-registration-native.mjs.map +1 -0
- package/dist/internal/persistence.d.mts +6 -19
- package/dist/internal/persistence.mjs +199 -166
- package/dist/internal/persistence.mjs.map +1 -1
- package/dist/internal/phone-composed.mjs +79 -0
- package/dist/internal/phone-composed.mjs.map +1 -0
- package/dist/internal/phone-native.d.mts +15 -0
- package/dist/internal/phone-native.mjs +354 -0
- package/dist/internal/phone-native.mjs.map +1 -0
- package/dist/internal/proof-native.d.mts +15 -0
- package/dist/internal/proof-native.mjs +289 -0
- package/dist/internal/proof-native.mjs.map +1 -0
- package/dist/internal/registration.mjs +50 -60
- package/dist/internal/registration.mjs.map +1 -1
- package/dist/internal/session-native-authority.d.mts +15 -0
- package/dist/internal/session-native-authority.mjs +91 -0
- package/dist/internal/session-native-authority.mjs.map +1 -0
- package/dist/internal/session-native-cleanup.d.mts +14 -0
- package/dist/internal/session-native-cleanup.mjs +48 -0
- package/dist/internal/session-native-cleanup.mjs.map +1 -0
- package/dist/internal/session-native-login.d.mts +15 -0
- package/dist/internal/session-native-login.mjs +87 -0
- package/dist/internal/session-native-login.mjs.map +1 -0
- package/dist/internal/session-native-pending-read.mjs +42 -0
- package/dist/internal/session-native-pending-read.mjs.map +1 -0
- package/dist/internal/session-native-pending.mjs +134 -0
- package/dist/internal/session-native-pending.mjs.map +1 -0
- package/dist/internal/session-native-record.mjs +79 -0
- package/dist/internal/session-native-record.mjs.map +1 -0
- package/dist/internal/session-native-state.mjs +130 -0
- package/dist/internal/session-native-state.mjs.map +1 -0
- package/dist/internal/session-native-stateful.d.mts +16 -0
- package/dist/internal/session-native-stateful.mjs +225 -0
- package/dist/internal/session-native-stateful.mjs.map +1 -0
- package/dist/internal/session-native-step-up.d.mts +15 -0
- package/dist/internal/session-native-step-up.mjs +212 -0
- package/dist/internal/session-native-step-up.mjs.map +1 -0
- package/dist/internal/session-native-validity.d.mts +15 -0
- package/dist/internal/session-native-validity.mjs +97 -0
- package/dist/internal/session-native-validity.mjs.map +1 -0
- package/dist/internal/session-policy.mjs +29 -0
- package/dist/internal/session-policy.mjs.map +1 -0
- package/dist/internal/sql-authority.d.mts +16 -0
- package/dist/internal/sql-authority.mjs +32 -0
- package/dist/internal/sql-authority.mjs.map +1 -0
- package/dist/internal/sql-change.mjs +21 -0
- package/dist/internal/sql-change.mjs.map +1 -0
- package/dist/internal/sql-cleanup.mjs +35 -0
- package/dist/internal/sql-cleanup.mjs.map +1 -0
- package/dist/internal/sql-commit.d.mts +72 -0
- package/dist/internal/sql-commit.mjs +176 -0
- package/dist/internal/sql-commit.mjs.map +1 -0
- package/dist/internal/sql-expression.d.mts +17 -0
- package/dist/internal/sql-expression.mjs +49 -0
- package/dist/internal/sql-expression.mjs.map +1 -0
- package/dist/internal/sql-oauth-connected-model.d.mts +7 -23
- package/dist/internal/sql-oauth-model.d.mts +27 -52
- package/dist/internal/sql-oauth-model.mjs +3 -4
- package/dist/internal/sql-oauth-model.mjs.map +1 -1
- package/dist/internal/sql-persistence.mjs +5 -9
- package/dist/internal/sql-persistence.mjs.map +1 -1
- package/dist/internal/sql-storage-validation.mjs +1 -2
- package/dist/internal/sql-storage-validation.mjs.map +1 -1
- package/dist/internal/sql-table.d.mts +3 -16
- package/dist/internal/sql-table.mjs +21 -42
- package/dist/internal/sql-table.mjs.map +1 -1
- package/dist/internal/standalone.mjs +2 -3
- package/dist/internal/standalone.mjs.map +1 -1
- package/dist/internal/step-up-state.mjs +5 -8
- package/dist/internal/step-up-state.mjs.map +1 -1
- package/dist/internal/storage-clock.mjs +44 -0
- package/dist/internal/storage-clock.mjs.map +1 -0
- package/dist/internal/storage-mapping.d.mts +11 -8
- package/dist/internal/storage-mapping.mjs +88 -302
- package/dist/internal/storage-mapping.mjs.map +1 -1
- package/dist/internal/storage-plans.mjs +15 -73
- package/dist/internal/storage-plans.mjs.map +1 -1
- package/dist/internal/storage-tables.d.mts +37 -520
- package/dist/internal/storage-tables.mjs +31 -211
- package/dist/internal/storage-tables.mjs.map +1 -1
- package/dist/internal/storage-validation.d.mts +1 -6
- package/dist/internal/storage-validation.mjs +1 -42
- package/dist/internal/storage-validation.mjs.map +1 -1
- package/dist/internal/table-model.d.mts +21 -0
- package/dist/internal/totp-native.d.mts +15 -0
- package/dist/internal/totp-native.mjs +401 -0
- package/dist/internal/totp-native.mjs.map +1 -0
- package/package.json +1 -1
- package/src/Adapter.ts +143 -199
- package/src/OAuthPersistence.ts +128 -271
- package/src/index.ts +1 -1
- package/src/internal/browser-login.ts +54 -24
- package/src/internal/configuration.ts +16 -31
- package/src/internal/d1-planning.ts +7 -0
- package/src/internal/email-native-state.ts +247 -0
- package/src/internal/email-native.ts +514 -0
- package/src/internal/email-policy.ts +235 -0
- package/src/internal/email-registration-native.ts +386 -0
- package/src/internal/models/email-model.ts +76 -214
- package/src/internal/models/oauth-connected-model.ts +50 -288
- package/src/internal/models/oauth-model.ts +147 -368
- package/src/internal/models/passkey-model.ts +11 -208
- package/src/internal/models/passkey-registration-ceremony-model.ts +6 -60
- package/src/internal/models/passkey-write-model.ts +14 -95
- package/src/internal/models/password-model.ts +26 -147
- package/src/internal/models/phone-model.ts +110 -0
- package/src/internal/models/proof-model.ts +48 -404
- package/src/internal/models/session-model.ts +102 -200
- package/src/internal/models/step-up-model.ts +17 -96
- package/src/internal/models/totp-model.ts +82 -0
- package/src/internal/native-sql-table.ts +32 -11
- package/src/internal/oauth/native-accounts.ts +576 -0
- package/src/internal/oauth/native-connected-state.ts +288 -0
- package/src/internal/oauth/native-connected.ts +888 -0
- package/src/internal/oauth/native-flow.ts +253 -0
- package/src/internal/oauth/native-layers.ts +83 -0
- package/src/internal/oauth/native-mutation.ts +222 -0
- package/src/internal/oauth/native-registration.ts +545 -0
- package/src/internal/oauth/native-revocations.ts +190 -0
- package/src/internal/oauth/native-sign-in.ts +111 -0
- package/src/internal/oauth/native-state.ts +346 -0
- package/src/internal/oauth/state.ts +2 -70
- package/src/internal/passkey-actions.ts +70 -0
- package/src/internal/passkey-inputs.ts +56 -0
- package/src/internal/passkey-managed.ts +360 -0
- package/src/internal/passkey-native-ceremony.ts +66 -0
- package/src/internal/passkey-native-flow.ts +140 -0
- package/src/internal/passkey-native-registration.ts +221 -0
- package/src/internal/passkey-native-state.ts +335 -0
- package/src/internal/passkey-native-write.ts +611 -0
- package/src/internal/passkey-native.ts +372 -0
- package/src/internal/passkey-policy.ts +246 -0
- package/src/internal/password-credentials.ts +52 -10
- package/src/internal/password-native.ts +571 -0
- package/src/internal/password-policy.ts +307 -0
- package/src/internal/password-registration-native.ts +322 -0
- package/src/internal/persistence.ts +336 -290
- package/src/internal/phone-composed.ts +86 -0
- package/src/internal/phone-native.ts +659 -0
- package/src/internal/proof-native.ts +448 -0
- package/src/internal/registration.ts +96 -143
- package/src/internal/session-native-authority.ts +247 -0
- package/src/internal/session-native-cleanup.ts +65 -0
- package/src/internal/session-native-login.ts +205 -0
- package/src/internal/session-native-pending-read.ts +68 -0
- package/src/internal/session-native-pending.ts +223 -0
- package/src/internal/session-native-record.ts +141 -0
- package/src/internal/session-native-state.ts +259 -0
- package/src/internal/session-native-stateful.ts +512 -0
- package/src/internal/session-native-step-up.ts +450 -0
- package/src/internal/session-native-validity.ts +208 -0
- package/src/internal/session-policy.ts +59 -0
- package/src/internal/sql-authority.ts +56 -0
- package/src/internal/sql-change.ts +38 -0
- package/src/internal/sql-cleanup.ts +56 -0
- package/src/internal/sql-commit.ts +435 -0
- package/src/internal/sql-expression.ts +94 -0
- package/src/internal/sql-metadata.ts +100 -0
- package/src/internal/sql-oauth-connected-model.ts +6 -95
- package/src/internal/sql-oauth-model.ts +31 -134
- package/src/internal/sql-persistence.ts +2 -6
- package/src/internal/sql-storage-validation.ts +1 -2
- package/src/internal/sql-table.ts +19 -52
- package/src/internal/standalone.ts +2 -11
- package/src/internal/step-up-state.ts +4 -17
- package/src/internal/storage-clock.ts +58 -0
- package/src/internal/storage-mapping.ts +125 -340
- package/src/internal/storage-plans.ts +14 -80
- package/src/internal/storage-tables.ts +28 -212
- package/src/internal/storage-validation.ts +0 -58
- package/src/internal/table-model.ts +24 -0
- package/src/internal/totp-native.ts +701 -0
- package/dist/internal/PasswordPreparedPostconditions.d.mts +0 -22
- package/dist/internal/PasswordPreparedPostconditions.mjs +0 -12
- package/dist/internal/PasswordPreparedPostconditions.mjs.map +0 -1
- package/dist/internal/authority-snapshot.mjs +0 -53
- package/dist/internal/authority-snapshot.mjs.map +0 -1
- package/dist/internal/email-kernel.d.mts +0 -276
- package/dist/internal/email-kernel.mjs +0 -497
- package/dist/internal/email-kernel.mjs.map +0 -1
- package/dist/internal/models/passkey-registration-ceremony-model.mjs +0 -18
- package/dist/internal/models/passkey-registration-ceremony-model.mjs.map +0 -1
- package/dist/internal/oauth/accounts.d.mts +0 -8
- package/dist/internal/oauth/accounts.mjs +0 -379
- package/dist/internal/oauth/accounts.mjs.map +0 -1
- package/dist/internal/oauth/connected-access.d.mts +0 -9
- package/dist/internal/oauth/connected-access.mjs +0 -229
- package/dist/internal/oauth/connected-access.mjs.map +0 -1
- package/dist/internal/oauth/connected-collection.d.mts +0 -7
- package/dist/internal/oauth/connected-collection.mjs +0 -214
- package/dist/internal/oauth/connected-collection.mjs.map +0 -1
- package/dist/internal/oauth/connected-custody.d.mts +0 -6
- package/dist/internal/oauth/connected-custody.mjs +0 -165
- package/dist/internal/oauth/connected-custody.mjs.map +0 -1
- package/dist/internal/oauth/connected-flow.d.mts +0 -7
- package/dist/internal/oauth/connected-flow.mjs +0 -324
- package/dist/internal/oauth/connected-flow.mjs.map +0 -1
- package/dist/internal/oauth/connected-input.mjs +0 -122
- package/dist/internal/oauth/connected-input.mjs.map +0 -1
- package/dist/internal/oauth/connected-keys.d.mts +0 -2
- package/dist/internal/oauth/connected-keys.mjs +0 -22
- package/dist/internal/oauth/connected-keys.mjs.map +0 -1
- package/dist/internal/oauth/connected-maintenance.d.mts +0 -9
- package/dist/internal/oauth/connected-maintenance.mjs +0 -226
- package/dist/internal/oauth/connected-maintenance.mjs.map +0 -1
- package/dist/internal/oauth/connected-management.d.mts +0 -9
- package/dist/internal/oauth/connected-management.mjs +0 -243
- package/dist/internal/oauth/connected-management.mjs.map +0 -1
- package/dist/internal/oauth/connected-reference.mjs +0 -63
- package/dist/internal/oauth/connected-reference.mjs.map +0 -1
- package/dist/internal/oauth/connected-settlement.d.mts +0 -8
- package/dist/internal/oauth/connected-settlement.mjs +0 -141
- package/dist/internal/oauth/connected-settlement.mjs.map +0 -1
- package/dist/internal/oauth/connected-sign-in.d.mts +0 -10
- package/dist/internal/oauth/connected-sign-in.mjs +0 -281
- package/dist/internal/oauth/connected-sign-in.mjs.map +0 -1
- package/dist/internal/oauth/connected-state.d.mts +0 -14
- package/dist/internal/oauth/connected-state.mjs +0 -469
- package/dist/internal/oauth/connected-state.mjs.map +0 -1
- package/dist/internal/oauth/connected-target.d.mts +0 -21
- package/dist/internal/oauth/connected-target.mjs +0 -117
- package/dist/internal/oauth/connected-target.mjs.map +0 -1
- package/dist/internal/oauth/flow.d.mts +0 -5
- package/dist/internal/oauth/flow.mjs +0 -279
- package/dist/internal/oauth/flow.mjs.map +0 -1
- package/dist/internal/oauth/input.mjs +0 -127
- package/dist/internal/oauth/input.mjs.map +0 -1
- package/dist/internal/oauth/owner.d.mts +0 -10
- package/dist/internal/oauth/owner.mjs +0 -10
- package/dist/internal/oauth/owner.mjs.map +0 -1
- package/dist/internal/oauth/query-compiler.d.mts +0 -7
- package/dist/internal/oauth/query-compiler.mjs +0 -9
- package/dist/internal/oauth/query-compiler.mjs.map +0 -1
- package/dist/internal/oauth/registration.d.mts +0 -7
- package/dist/internal/oauth/registration.mjs +0 -393
- package/dist/internal/oauth/registration.mjs.map +0 -1
- package/dist/internal/oauth/target.d.mts +0 -31
- package/dist/internal/oauth/target.mjs +0 -273
- package/dist/internal/oauth/target.mjs.map +0 -1
- package/dist/internal/oauth-kernel.d.mts +0 -1423
- package/dist/internal/oauth-kernel.mjs +0 -187
- package/dist/internal/oauth-kernel.mjs.map +0 -1
- package/dist/internal/passkey/admission.d.mts +0 -6
- package/dist/internal/passkey/admission.mjs +0 -220
- package/dist/internal/passkey/admission.mjs.map +0 -1
- package/dist/internal/passkey/credentials.d.mts +0 -14
- package/dist/internal/passkey/credentials.mjs +0 -249
- package/dist/internal/passkey/credentials.mjs.map +0 -1
- package/dist/internal/passkey/enrollment.mjs +0 -138
- package/dist/internal/passkey/enrollment.mjs.map +0 -1
- package/dist/internal/passkey/flow.d.mts +0 -21
- package/dist/internal/passkey/flow.mjs +0 -452
- package/dist/internal/passkey/flow.mjs.map +0 -1
- package/dist/internal/passkey/management.mjs +0 -231
- package/dist/internal/passkey/management.mjs.map +0 -1
- package/dist/internal/passkey/registration-ceremony.d.mts +0 -9
- package/dist/internal/passkey/registration-ceremony.mjs +0 -129
- package/dist/internal/passkey/registration-ceremony.mjs.map +0 -1
- package/dist/internal/passkey/registration-custody.d.mts +0 -2
- package/dist/internal/passkey/registration-custody.mjs +0 -52
- package/dist/internal/passkey/registration-custody.mjs.map +0 -1
- package/dist/internal/passkey/registration-write.mjs +0 -211
- package/dist/internal/passkey/registration-write.mjs.map +0 -1
- package/dist/internal/passkey/state.d.mts +0 -10
- package/dist/internal/passkey/state.mjs +0 -234
- package/dist/internal/passkey/state.mjs.map +0 -1
- package/dist/internal/passkey/target.d.mts +0 -20
- package/dist/internal/passkey/target.mjs +0 -200
- package/dist/internal/passkey/target.mjs.map +0 -1
- package/dist/internal/passkey/write-state.d.mts +0 -17
- package/dist/internal/passkey/write-state.mjs +0 -354
- package/dist/internal/passkey/write-state.mjs.map +0 -1
- package/dist/internal/passkey/write-target.mjs +0 -192
- package/dist/internal/passkey/write-target.mjs.map +0 -1
- package/dist/internal/passkey-kernel.d.mts +0 -6045
- package/dist/internal/passkey-kernel.mjs +0 -49
- package/dist/internal/passkey-kernel.mjs.map +0 -1
- package/dist/internal/passkeys.d.mts +0 -7
- package/dist/internal/passkeys.mjs +0 -387
- package/dist/internal/passkeys.mjs.map +0 -1
- package/dist/internal/password-credentials.d.mts +0 -11
- package/dist/internal/password-kernel.d.mts +0 -278
- package/dist/internal/password-kernel.mjs +0 -508
- package/dist/internal/password-kernel.mjs.map +0 -1
- package/dist/internal/phone-kernel.d.mts +0 -162
- package/dist/internal/phone-kernel.mjs +0 -437
- package/dist/internal/phone-kernel.mjs.map +0 -1
- package/dist/internal/proof-kernel.d.mts +0 -94
- package/dist/internal/proof-kernel.mjs +0 -624
- package/dist/internal/proof-kernel.mjs.map +0 -1
- package/dist/internal/query-operations.d.mts +0 -68
- package/dist/internal/session-kernel.d.mts +0 -62
- package/dist/internal/session-kernel.mjs +0 -820
- package/dist/internal/session-kernel.mjs.map +0 -1
- package/dist/internal/sql-oauth-connected-model.mjs +0 -7
- package/dist/internal/sql-oauth-connected-model.mjs.map +0 -1
- package/dist/internal/sql-query.d.mts +0 -12
- package/dist/internal/sql-query.mjs +0 -206
- package/dist/internal/sql-query.mjs.map +0 -1
- package/dist/internal/step-up-state.d.mts +0 -49
- package/dist/internal/transaction-execution-kernel.d.mts +0 -37
- package/dist/internal/transaction-execution-kernel.mjs +0 -120
- package/dist/internal/transaction-execution-kernel.mjs.map +0 -1
- package/dist/internal/transaction-kernel.d.mts +0 -81
- package/dist/internal/transaction-kernel.mjs +0 -264
- package/dist/internal/transaction-kernel.mjs.map +0 -1
- package/src/internal/PasswordPreparedPostconditions.ts +0 -30
- package/src/internal/authority-snapshot.ts +0 -91
- package/src/internal/email-kernel.ts +0 -1556
- package/src/internal/oauth/accounts.ts +0 -839
- package/src/internal/oauth/connected-access.ts +0 -388
- package/src/internal/oauth/connected-collection.ts +0 -345
- package/src/internal/oauth/connected-custody.ts +0 -308
- package/src/internal/oauth/connected-flow.ts +0 -562
- package/src/internal/oauth/connected-input.ts +0 -147
- package/src/internal/oauth/connected-keys.ts +0 -31
- package/src/internal/oauth/connected-maintenance.ts +0 -379
- package/src/internal/oauth/connected-management.ts +0 -391
- package/src/internal/oauth/connected-reference.ts +0 -135
- package/src/internal/oauth/connected-settlement.ts +0 -278
- package/src/internal/oauth/connected-sign-in.ts +0 -472
- package/src/internal/oauth/connected-state.ts +0 -924
- package/src/internal/oauth/connected-target.ts +0 -307
- package/src/internal/oauth/flow.ts +0 -505
- package/src/internal/oauth/input.ts +0 -201
- package/src/internal/oauth/owner.ts +0 -22
- package/src/internal/oauth/query-compiler.ts +0 -15
- package/src/internal/oauth/registration.ts +0 -676
- package/src/internal/oauth/target.ts +0 -803
- package/src/internal/oauth-kernel.ts +0 -294
- package/src/internal/passkey/admission.ts +0 -368
- package/src/internal/passkey/credentials.ts +0 -511
- package/src/internal/passkey/enrollment.ts +0 -326
- package/src/internal/passkey/flow.ts +0 -1062
- package/src/internal/passkey/management.ts +0 -426
- package/src/internal/passkey/registration-ceremony.ts +0 -283
- package/src/internal/passkey/registration-custody.ts +0 -91
- package/src/internal/passkey/registration-write.ts +0 -426
- package/src/internal/passkey/state.ts +0 -351
- package/src/internal/passkey/target.ts +0 -598
- package/src/internal/passkey/write-state.ts +0 -692
- package/src/internal/passkey/write-target.ts +0 -450
- package/src/internal/passkey-kernel.ts +0 -112
- package/src/internal/passkeys.ts +0 -652
- package/src/internal/password-kernel.ts +0 -1523
- package/src/internal/phone-kernel.ts +0 -872
- package/src/internal/proof-kernel.ts +0 -1992
- package/src/internal/query-operations.ts +0 -91
- package/src/internal/session-kernel.ts +0 -2406
- package/src/internal/sql-query.ts +0 -304
- package/src/internal/transaction-execution-kernel.ts +0 -335
- package/src/internal/transaction-kernel.ts +0 -603
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as M from "@yielded/auth/Passkey";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import type { Fragment } from "effect/sql/Statement";
|
|
5
|
+
|
|
6
|
+
import { sqlBatchAssertion } from "./d1-planning";
|
|
7
|
+
import type { PasskeyCeremonyMapping } from "./models/passkey-model";
|
|
8
|
+
import type { NativeSqlTables } from "./native-sql-table";
|
|
9
|
+
import { passkeyMatchesAccess, validPasskeyCeremony } from "./passkey-policy";
|
|
10
|
+
import { exactSqlText, executeSqlChange } from "./sql-change";
|
|
11
|
+
import { cleanupSqlRows } from "./sql-cleanup";
|
|
12
|
+
import { appendSqlBatchStatement } from "./sql-commit";
|
|
13
|
+
import type { TableModel } from "./table-model";
|
|
14
|
+
|
|
15
|
+
export const passkeyCeremonyJson = Schema.fromJsonString(M.PasskeyCeremony);
|
|
16
|
+
|
|
17
|
+
// The physical expression compiler validates this adapter boundary.
|
|
18
|
+
// oxlint-disable-next-line no-explicit-any
|
|
19
|
+
export type PasskeyNativeCeremonyMapping = PasskeyCeremonyMapping<TableModel, any>;
|
|
20
|
+
|
|
21
|
+
/** One set of challenge statements serves native transactions and fixed D1 plans. */
|
|
22
|
+
export const makePasskeyNativeFlow = Effect.fnUntraced(function* (
|
|
23
|
+
tables: NativeSqlTables,
|
|
24
|
+
mapping: PasskeyNativeCeremonyMapping,
|
|
25
|
+
) {
|
|
26
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
27
|
+
const flow = tables(mapping.flow.table);
|
|
28
|
+
const now = tables.expression(mapping.clock.engineNowMillis);
|
|
29
|
+
const millis = (expression: Fragment) => tables.expression(mapping.clock.toMillis(expression));
|
|
30
|
+
|
|
31
|
+
const exact = (key: string, value: unknown) =>
|
|
32
|
+
exactSqlText(sql, flow.column(key), flow.value(key, value));
|
|
33
|
+
|
|
34
|
+
const module = (moduleId: string) => exact(mapping.flow.moduleId, moduleId);
|
|
35
|
+
const validModule = (moduleId: string) => moduleId === mapping.moduleId;
|
|
36
|
+
|
|
37
|
+
const access = (input: M.PasskeyAccess, ceremony?: M.PasskeyCeremony) =>
|
|
38
|
+
sql.and([
|
|
39
|
+
module(input.moduleId),
|
|
40
|
+
exact(mapping.flow.purpose, input.purpose),
|
|
41
|
+
exact(mapping.flow.flowId, input.flowId),
|
|
42
|
+
exact(mapping.flow.requestBindingVerifier, input.requestBindingVerifier),
|
|
43
|
+
sql`${flow.column(mapping.flow.requestBindingExpiresAt)} = ${flow.value(mapping.flow.requestBindingExpiresAt, mapping.clock.encodeInstant(input.requestBindingExpiresAtMillis))}`,
|
|
44
|
+
sql`${millis(flow.column(mapping.flow.expiresAt))} > ${now}`,
|
|
45
|
+
sql`${millis(flow.column(mapping.flow.requestBindingExpiresAt))} > ${now}`,
|
|
46
|
+
...(ceremony === undefined
|
|
47
|
+
? []
|
|
48
|
+
: [
|
|
49
|
+
exact(mapping.flow.snapshot, Schema.encodeSync(passkeyCeremonyJson)(ceremony)),
|
|
50
|
+
sql`${flow.column(mapping.flow.issuedAt)} = ${flow.value(mapping.flow.issuedAt, mapping.clock.encodeInstant(ceremony.issuedAtMillis))}`,
|
|
51
|
+
sql`${flow.column(mapping.flow.expiresAt)} = ${flow.value(mapping.flow.expiresAt, mapping.clock.encodeInstant(ceremony.expiresAtMillis))}`,
|
|
52
|
+
]),
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
const insert = (ceremony: M.PasskeyCeremony, extra: Readonly<Record<string, unknown>> = {}) => {
|
|
56
|
+
const values = {
|
|
57
|
+
...mapping.flow.encodeInsert({ ceremony }),
|
|
58
|
+
...extra,
|
|
59
|
+
[mapping.flow.moduleId]: ceremony.moduleId,
|
|
60
|
+
[mapping.flow.flowId]: ceremony.flowId,
|
|
61
|
+
[mapping.flow.purpose]: ceremony.purpose,
|
|
62
|
+
[mapping.flow.snapshot]: Schema.encodeSync(passkeyCeremonyJson)(ceremony),
|
|
63
|
+
[mapping.flow.requestBindingVerifier]: ceremony.requestBindingVerifier,
|
|
64
|
+
[mapping.flow.requestBindingExpiresAt]: mapping.clock.encodeInstant(
|
|
65
|
+
ceremony.requestBindingExpiresAtMillis,
|
|
66
|
+
),
|
|
67
|
+
[mapping.flow.issuedAt]: mapping.clock.encodeInstant(ceremony.issuedAtMillis),
|
|
68
|
+
[mapping.flow.expiresAt]: mapping.clock.encodeInstant(ceremony.expiresAtMillis),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return sql`${flow.insert(values)} ${sql.onDialectOrElse({ mysql: () => sql``, orElse: () => sql`on conflict do nothing` })}`;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const consume = (
|
|
75
|
+
input: M.PasskeyAccess,
|
|
76
|
+
ceremony: M.PasskeyCeremony,
|
|
77
|
+
condition: Fragment = sql`true`,
|
|
78
|
+
) => sql`delete from ${flow.name} where ${access(input, ceremony)} and ${condition}`;
|
|
79
|
+
|
|
80
|
+
const context = Effect.fnUntraced(function* (input: M.PasskeyAccess) {
|
|
81
|
+
if (!validModule(input.moduleId)) return undefined;
|
|
82
|
+
|
|
83
|
+
const rows =
|
|
84
|
+
yield* sql`select ${flow.fields("flow_")} from ${flow.name} where ${access(input)}`;
|
|
85
|
+
|
|
86
|
+
if (rows.length !== 1) return undefined;
|
|
87
|
+
const row = flow.decode(rows[0]!, "flow_");
|
|
88
|
+
|
|
89
|
+
const ceremony = yield* Schema.decodeUnknownEffect(passkeyCeremonyJson)(
|
|
90
|
+
row[mapping.flow.snapshot],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return validPasskeyCeremony(ceremony) &&
|
|
94
|
+
passkeyMatchesAccess(ceremony, input) &&
|
|
95
|
+
mapping.clock.decodeInstant(row[mapping.flow.issuedAt]) === ceremony.issuedAtMillis &&
|
|
96
|
+
mapping.clock.decodeInstant(row[mapping.flow.expiresAt]) === ceremony.expiresAtMillis
|
|
97
|
+
? ceremony
|
|
98
|
+
: undefined;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const cleanup = (moduleId: string, limit: number, batch = false) =>
|
|
102
|
+
cleanupSqlRows(
|
|
103
|
+
[
|
|
104
|
+
{
|
|
105
|
+
table: flow,
|
|
106
|
+
keys: [mapping.flow.moduleId, mapping.flow.flowId],
|
|
107
|
+
due: sql`${module(moduleId)} and ${millis(flow.column(mapping.flow.expiresAt))} <= ${now}`,
|
|
108
|
+
order: [flow.column(mapping.flow.expiresAt), flow.column(mapping.flow.flowId)],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
limit,
|
|
112
|
+
batch,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const stage = Effect.fnUntraced(function* (statement: Fragment, count: number) {
|
|
116
|
+
yield* appendSqlBatchStatement(sql`${statement}`);
|
|
117
|
+
yield* appendSqlBatchStatement(sqlBatchAssertion(sql, sql`changes() = ${count}`));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
sql,
|
|
122
|
+
flow,
|
|
123
|
+
now,
|
|
124
|
+
millis,
|
|
125
|
+
exact,
|
|
126
|
+
module,
|
|
127
|
+
validModule,
|
|
128
|
+
access,
|
|
129
|
+
insert,
|
|
130
|
+
consume,
|
|
131
|
+
absent: (input: M.PasskeyAccess) =>
|
|
132
|
+
sql`not exists(select 1 from ${flow.name} where ${module(input.moduleId)} and ${exact(mapping.flow.flowId, input.flowId)})`,
|
|
133
|
+
context,
|
|
134
|
+
cleanup,
|
|
135
|
+
stage,
|
|
136
|
+
change: (statement: Fragment) => executeSqlChange(sql, statement),
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
export type PasskeyNativeFlow = Effect.Success<ReturnType<typeof makePasskeyNativeFlow>>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/* oxlint-disable no-explicit-any -- physical mapping generics are erased only at this shared adapter boundary. */
|
|
2
|
+
import * as M from "@yielded/auth/Passkey";
|
|
3
|
+
import { Effect, Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
import { randomId } from "./crypto";
|
|
6
|
+
import { sqlBatchAssertion } from "./d1-planning";
|
|
7
|
+
import type {
|
|
8
|
+
PasskeyRegistrationMapping,
|
|
9
|
+
PasskeyRegistrationWriter,
|
|
10
|
+
} from "./models/passkey-write-model";
|
|
11
|
+
import { passkeyCanonicalJson, passkeyDigest } from "./passkey-actions";
|
|
12
|
+
import { preparePasskeyNative, type NativePasskeyServices } from "./passkey-native";
|
|
13
|
+
import { passkeyNativeInvariant } from "./passkey-native-state";
|
|
14
|
+
import { makePasskeyNativeWrites } from "./passkey-native-write";
|
|
15
|
+
import { passkeyMatchesAccess, validPasskeyCeremony } from "./passkey-policy";
|
|
16
|
+
import { appendSqlBatchStatement } from "./sql-commit";
|
|
17
|
+
import type { TableModel } from "./table-model";
|
|
18
|
+
|
|
19
|
+
// Foreign mapping expressions are compiled at the NativeSqlTables boundary.
|
|
20
|
+
export type NativePasskeyRegistrationMapping<R> = PasskeyRegistrationMapping<
|
|
21
|
+
TableModel,
|
|
22
|
+
TableModel,
|
|
23
|
+
TableModel,
|
|
24
|
+
TableModel,
|
|
25
|
+
unknown,
|
|
26
|
+
R,
|
|
27
|
+
any
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
export const makePasskeyNativeRegistration = <R>(
|
|
31
|
+
base: NativePasskeyServices,
|
|
32
|
+
mapping: NativePasskeyRegistrationMapping<R>,
|
|
33
|
+
) => {
|
|
34
|
+
const { state, run, advisory } = base;
|
|
35
|
+
const { sql, tables, subject, credential, ceremony: flow } = state;
|
|
36
|
+
|
|
37
|
+
const { write, postcondition, check, insertCredential, subjectCondition, owned } =
|
|
38
|
+
makePasskeyNativeWrites(base, mapping);
|
|
39
|
+
|
|
40
|
+
const invariant: typeof passkeyNativeInvariant = passkeyNativeInvariant;
|
|
41
|
+
const codec = passkeyCanonicalJson(mapping.registration.schema);
|
|
42
|
+
|
|
43
|
+
const describe = Effect.fnUntraced(function* (original: R) {
|
|
44
|
+
const encoded = codec.encode(original);
|
|
45
|
+
|
|
46
|
+
invariant(new TextEncoder().encode(encoded).length <= 1048576);
|
|
47
|
+
const registration = codec.decode(encoded);
|
|
48
|
+
|
|
49
|
+
const labels = yield* Schema.decodeEffect(
|
|
50
|
+
Schema.Struct({ name: M.PasskeyLabel, displayName: M.PasskeyLabel }),
|
|
51
|
+
)(mapping.registration.describe(registration));
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
encoded,
|
|
55
|
+
registration,
|
|
56
|
+
...labels,
|
|
57
|
+
fingerprint: yield* passkeyDigest(mapping.registration.schema, registration),
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const writer: PasskeyRegistrationWriter<R> = {
|
|
62
|
+
inspect: (original) =>
|
|
63
|
+
advisory(
|
|
64
|
+
Effect.gen(function* () {
|
|
65
|
+
const value = yield* describe(original);
|
|
66
|
+
|
|
67
|
+
const rows =
|
|
68
|
+
yield* sql`select case when ${tables.expression(mapping.registration.eligible(value.registration))} then 1 else 0 end as eligible`;
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
fingerprint: value.fingerprint,
|
|
72
|
+
name: value.name,
|
|
73
|
+
displayName: value.displayName,
|
|
74
|
+
eligible: rows.length === 1 && Number(rows[0]!.eligible) === 1,
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
issueRegistration: (input, prepare) =>
|
|
79
|
+
run(
|
|
80
|
+
Effect.gen(function* () {
|
|
81
|
+
const ceremony = M.snapshotPasskeySync(M.PasskeyCeremony, input.ceremony);
|
|
82
|
+
const value = yield* describe(input.registration);
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
!flow.validModule(ceremony.moduleId) ||
|
|
86
|
+
!validPasskeyCeremony(ceremony) ||
|
|
87
|
+
ceremony.purpose !== "registration" ||
|
|
88
|
+
ceremony.context._tag !== "Registration" ||
|
|
89
|
+
!ceremony.profile.primarySignIn ||
|
|
90
|
+
ceremony.profile.residentKey !== "required" ||
|
|
91
|
+
ceremony.profile.userVerification !== "required" ||
|
|
92
|
+
ceremony.allowedCredentials.length !== 0 ||
|
|
93
|
+
ceremony.context.fingerprint !== value.fingerprint ||
|
|
94
|
+
ceremony.context.name !== value.name ||
|
|
95
|
+
ceremony.context.displayName !== value.displayName
|
|
96
|
+
)
|
|
97
|
+
return yield* preparePasskeyNative({ _tag: "Rejected" }, prepare);
|
|
98
|
+
const statement = flow.insert(ceremony, { [mapping.applicationSnapshot]: value.encoded });
|
|
99
|
+
|
|
100
|
+
if (base.batch) yield* flow.stage(statement, 1);
|
|
101
|
+
else if ((yield* flow.change(statement)) !== 1)
|
|
102
|
+
return yield* preparePasskeyNative({ _tag: "Rejected" }, prepare);
|
|
103
|
+
|
|
104
|
+
return yield* preparePasskeyNative({ _tag: "Issued", ceremony }, prepare);
|
|
105
|
+
}),
|
|
106
|
+
"statement",
|
|
107
|
+
),
|
|
108
|
+
completeRegistration: (input, prepare) =>
|
|
109
|
+
run(
|
|
110
|
+
Effect.gen(function* () {
|
|
111
|
+
const ceremony = M.snapshotPasskeySync(M.PasskeyCeremony, input.ceremony);
|
|
112
|
+
const access = M.snapshotPasskeySync(M.PasskeyAccess, input.access);
|
|
113
|
+
const verified = M.snapshotPasskeySync(M.PasskeyRegistrationVerified, input.verified);
|
|
114
|
+
|
|
115
|
+
if (
|
|
116
|
+
!flow.validModule(ceremony.moduleId) ||
|
|
117
|
+
ceremony.context._tag !== "Registration" ||
|
|
118
|
+
ceremony.purpose !== "registration" ||
|
|
119
|
+
!passkeyMatchesAccess(ceremony, access) ||
|
|
120
|
+
!verified.userVerified
|
|
121
|
+
)
|
|
122
|
+
return yield* preparePasskeyNative({ _tag: "Rejected" }, prepare);
|
|
123
|
+
|
|
124
|
+
const rows =
|
|
125
|
+
yield* sql`select ${flow.flow.fields("flow_")}, ${flow.now} as "engineNow" from ${flow.flow.name} where ${flow.access(access, ceremony)}`;
|
|
126
|
+
|
|
127
|
+
if (rows.length !== 1) return yield* preparePasskeyNative({ _tag: "Rejected" }, prepare);
|
|
128
|
+
const row = flow.flow.decode(rows[0]!, "flow_");
|
|
129
|
+
|
|
130
|
+
const encoded = yield* Schema.decodeUnknownEffect(Schema.String)(
|
|
131
|
+
row[mapping.applicationSnapshot],
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const registration = codec.decode(encoded);
|
|
135
|
+
const value = yield* describe(registration);
|
|
136
|
+
|
|
137
|
+
if (
|
|
138
|
+
value.fingerprint !== ceremony.context.fingerprint ||
|
|
139
|
+
value.name !== ceremony.context.name ||
|
|
140
|
+
value.displayName !== ceremony.context.displayName
|
|
141
|
+
)
|
|
142
|
+
return yield* preparePasskeyNative({ _tag: "Rejected" }, prepare);
|
|
143
|
+
const eligible = tables.expression(mapping.registration.eligible(registration));
|
|
144
|
+
const marker = yield* randomId;
|
|
145
|
+
const provision = mapping.registration.subject({ registration, ceremony, marker });
|
|
146
|
+
const nativeId = provision.subjectId;
|
|
147
|
+
const subjectId = mapping.read.subjectIds.toSubject(nativeId);
|
|
148
|
+
|
|
149
|
+
invariant(
|
|
150
|
+
mapping.read.subjectIds.equals(mapping.read.subjectIds.toNative(subjectId), nativeId),
|
|
151
|
+
);
|
|
152
|
+
if (base.batch) yield* appendSqlBatchStatement(sqlBatchAssertion(sql, eligible));
|
|
153
|
+
else yield* check(eligible);
|
|
154
|
+
// Inserting the new subject acquires its lock before the challenge or
|
|
155
|
+
// credential is mutated. A failed consume rolls this insertion back.
|
|
156
|
+
yield* write(subject.insert(provision.values), 1);
|
|
157
|
+
let revision: M.PasskeyCredential["revision"];
|
|
158
|
+
let nowMillis: number;
|
|
159
|
+
let subjectRow: Readonly<Record<string, unknown>> = provision.values;
|
|
160
|
+
|
|
161
|
+
if (base.batch) {
|
|
162
|
+
invariant(
|
|
163
|
+
mapping.read.subject.isActiveStatus(provision.values[mapping.read.subject.status]),
|
|
164
|
+
);
|
|
165
|
+
revision = yield* Schema.decodeUnknownEffect(M.PasskeyRevision)({
|
|
166
|
+
subjectId,
|
|
167
|
+
securityRevision: provision.values[mapping.read.subject.securityRevision],
|
|
168
|
+
credentials: [],
|
|
169
|
+
});
|
|
170
|
+
nowMillis = yield* Schema.decodeEffect(Schema.Int)(Number(rows[0]!.engineNow));
|
|
171
|
+
} else {
|
|
172
|
+
const current = yield* state.readAuthority(nativeId, true);
|
|
173
|
+
|
|
174
|
+
invariant(current !== undefined);
|
|
175
|
+
subjectRow = current.row;
|
|
176
|
+
revision = current.revision;
|
|
177
|
+
nowMillis = current.nowMillis;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const cap = M.snapshotPasskeySync(
|
|
181
|
+
M.PasskeyManagementPolicy,
|
|
182
|
+
mapping.write.policy.management(subjectRow),
|
|
183
|
+
).maximumCredentials;
|
|
184
|
+
|
|
185
|
+
const count = sql`(select count(*) from ${credential.name} where ${owned(nativeId)})`;
|
|
186
|
+
|
|
187
|
+
const finalEligibility = tables.expression(
|
|
188
|
+
mapping.registration.finalEligibility({ registration, subjectId: nativeId }),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
yield* write(
|
|
192
|
+
flow.consume(
|
|
193
|
+
access,
|
|
194
|
+
ceremony,
|
|
195
|
+
sql`${flow.exact(mapping.applicationSnapshot, encoded)} and ${subjectCondition(revision)} and ${count} < ${cap} and ${finalEligibility}`,
|
|
196
|
+
),
|
|
197
|
+
1,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const inserted = yield* insertCredential(
|
|
201
|
+
nativeId,
|
|
202
|
+
ceremony,
|
|
203
|
+
verified,
|
|
204
|
+
revision,
|
|
205
|
+
value.displayName,
|
|
206
|
+
nowMillis,
|
|
207
|
+
subjectRow,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
yield* postcondition(
|
|
211
|
+
"passkey-registration-subject",
|
|
212
|
+
sql`${inserted.condition} and ${flow.absent(access)} and ${subjectCondition(revision)} and ${count} <= ${cap} and ${finalEligibility} and ${state.now} < ${ceremony.expiresAtMillis}`,
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
return yield* preparePasskeyNative({ _tag: "RegistrationAccepted" }, prepare);
|
|
216
|
+
}),
|
|
217
|
+
),
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return { passkeyRegistrationAuthority: writer };
|
|
221
|
+
};
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/* oxlint-disable no-explicit-any -- physical mapping generics are erased only at this shared adapter boundary. */
|
|
2
|
+
import * as M from "@yielded/auth/Passkey";
|
|
3
|
+
import { Effect, Schema } from "effect";
|
|
4
|
+
import { SqlClient } from "effect/sql";
|
|
5
|
+
import type { Fragment } from "effect/sql/Statement";
|
|
6
|
+
|
|
7
|
+
import type { PasskeyCredentialMapping, PasskeyPersistenceMapping } from "./models/passkey-model";
|
|
8
|
+
import { sqlMapping, type NativeSqlTables } from "./native-sql-table";
|
|
9
|
+
import { makePasskeyNativeFlow } from "./passkey-native-flow";
|
|
10
|
+
import { passkeyCredentialKey } from "./passkey-policy";
|
|
11
|
+
import { exactSqlText } from "./sql-change";
|
|
12
|
+
import type { TableModel } from "./table-model";
|
|
13
|
+
|
|
14
|
+
// Physical expression types are validated by NativeSqlTables at this boundary.
|
|
15
|
+
export type PasskeyNativeRead = PasskeyCredentialMapping<
|
|
16
|
+
TableModel,
|
|
17
|
+
TableModel,
|
|
18
|
+
TableModel,
|
|
19
|
+
unknown,
|
|
20
|
+
any
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
export type PasskeyNativeMapping = PasskeyPersistenceMapping<
|
|
24
|
+
PasskeyNativeRead,
|
|
25
|
+
TableModel,
|
|
26
|
+
unknown,
|
|
27
|
+
any
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
export type PasskeyNativeRow = Readonly<Record<string, unknown>>;
|
|
31
|
+
|
|
32
|
+
export const passkeyNativeInvariant: (value: unknown) => asserts value = (value) => {
|
|
33
|
+
if (!value) throw M.PasskeyUnavailable.make({});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const makePasskeyNativeReadState = Effect.fnUntraced(function* (
|
|
37
|
+
tables: NativeSqlTables,
|
|
38
|
+
read: PasskeyNativeRead,
|
|
39
|
+
clock?: PasskeyNativeMapping["clock"],
|
|
40
|
+
) {
|
|
41
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
42
|
+
const subject = tables(read.subject.table);
|
|
43
|
+
const credential = tables(read.credential.table);
|
|
44
|
+
const factor = tables(read.authority.table);
|
|
45
|
+
const now = clock === undefined ? sql`0` : tables.expression(clock.engineNowMillis);
|
|
46
|
+
|
|
47
|
+
const millis = (expression: Fragment) =>
|
|
48
|
+
clock === undefined ? expression : tables.expression(clock.toMillis(expression));
|
|
49
|
+
|
|
50
|
+
const storedNow =
|
|
51
|
+
clock === undefined ? sql`0` : tables.expression(clock.fromMillis(clock.engineNowMillis));
|
|
52
|
+
|
|
53
|
+
const active = (table: "subject" | "credential" | "authority") =>
|
|
54
|
+
tables.expression(read[table].activeCondition);
|
|
55
|
+
|
|
56
|
+
const invariant: typeof passkeyNativeInvariant = passkeyNativeInvariant;
|
|
57
|
+
const sameId = (nativeId: unknown, value: unknown) => read.subjectIds.equals(nativeId, value);
|
|
58
|
+
|
|
59
|
+
const native = (id: M.PasskeyCredential["revision"]["subjectId"]) => {
|
|
60
|
+
const value = read.subjectIds.toNative(id);
|
|
61
|
+
|
|
62
|
+
invariant(read.subjectIds.toSubject(value) === id);
|
|
63
|
+
|
|
64
|
+
return value;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const revisions = (nativeId: unknown, rows: ReadonlyArray<PasskeyNativeRow>) => {
|
|
68
|
+
const entries = new Map<string, M.PasskeyCredential["revision"]["securityRevision"]>();
|
|
69
|
+
|
|
70
|
+
for (const row of rows) {
|
|
71
|
+
if (row[read.authority.credentialId] === null) continue;
|
|
72
|
+
invariant(sameId(nativeId, row[read.authority.subjectId]));
|
|
73
|
+
if (!read.authority.isActiveStatus(row[read.authority.status])) continue;
|
|
74
|
+
|
|
75
|
+
const decoded = Schema.decodeUnknownSync(M.PasskeyRevision.fields.credentials)([
|
|
76
|
+
{
|
|
77
|
+
credentialId: row[read.authority.credentialId],
|
|
78
|
+
revision: row[read.authority.revision],
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
const entry = decoded[0];
|
|
83
|
+
|
|
84
|
+
invariant(entry !== undefined);
|
|
85
|
+
const previous = entries.get(entry.credentialId);
|
|
86
|
+
|
|
87
|
+
invariant(previous === undefined || previous === entry.revision);
|
|
88
|
+
entries.set(entry.credentialId, entry.revision);
|
|
89
|
+
}
|
|
90
|
+
invariant(entries.size <= 64);
|
|
91
|
+
|
|
92
|
+
return [...entries]
|
|
93
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
94
|
+
.map(([credentialId, revision]) => ({ credentialId, revision }));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const revision = (row: PasskeyNativeRow, factors: ReadonlyArray<PasskeyNativeRow>) => {
|
|
98
|
+
const id = read.subject.decodeId(row);
|
|
99
|
+
const subjectId = read.subjectIds.toSubject(id);
|
|
100
|
+
|
|
101
|
+
invariant(sameId(native(subjectId), id));
|
|
102
|
+
|
|
103
|
+
return Schema.decodeUnknownSync(M.PasskeyRevision)({
|
|
104
|
+
subjectId,
|
|
105
|
+
securityRevision: row[read.subject.securityRevision],
|
|
106
|
+
credentials: revisions(id, factors),
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const decodeCredential = Effect.fnUntraced(function* (
|
|
111
|
+
row: PasskeyNativeRow,
|
|
112
|
+
current: M.PasskeyCredential["revision"],
|
|
113
|
+
subjectRow: PasskeyNativeRow,
|
|
114
|
+
) {
|
|
115
|
+
const value = read.credential.decode(row);
|
|
116
|
+
const owned = current.credentials.find((entry) => entry.credentialId === value.credentialId);
|
|
117
|
+
|
|
118
|
+
if (
|
|
119
|
+
!read.credential.isActiveStatus(row[read.credential.status]) ||
|
|
120
|
+
owned?.revision !== row[read.credential.credentialRevision]
|
|
121
|
+
)
|
|
122
|
+
return undefined;
|
|
123
|
+
invariant(
|
|
124
|
+
read.subjectIds.toSubject(read.credential.decodeSubjectId(row)) === current.subjectId,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return M.snapshotPasskeySync(M.PasskeyCredential, {
|
|
128
|
+
...value,
|
|
129
|
+
revision: current,
|
|
130
|
+
requirement: yield* read.subject.decodeRequirement(subjectRow),
|
|
131
|
+
active: true,
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const readAuthority = Effect.fnUntraced(function* (
|
|
136
|
+
nativeId: unknown,
|
|
137
|
+
lock: boolean,
|
|
138
|
+
credentialId?: string,
|
|
139
|
+
) {
|
|
140
|
+
// The subject lock is a distinct first statement; joined FOR UPDATE cannot
|
|
141
|
+
// establish the lock order required by coordinated application transactions.
|
|
142
|
+
if (lock) {
|
|
143
|
+
const locked =
|
|
144
|
+
yield* sql<PasskeyNativeRow>`select ${subject.fields("s_")}, ${now} as "engineNow" from ${subject.name} where ${subject.column(read.subject.id)} = ${subject.value(read.subject.id, nativeId)} and ${active("subject")} ${sql.onDialectOrElse({ pg: () => sql`for update`, mysql: () => sql`for update`, orElse: () => sql`` })}`;
|
|
145
|
+
|
|
146
|
+
if (locked.length !== 1) return undefined;
|
|
147
|
+
const row = subject.decode(locked[0]!, "s_");
|
|
148
|
+
|
|
149
|
+
if (
|
|
150
|
+
!sameId(read.subject.decodeId(row), nativeId) ||
|
|
151
|
+
!read.subject.isActiveStatus(row[read.subject.status])
|
|
152
|
+
)
|
|
153
|
+
return undefined;
|
|
154
|
+
|
|
155
|
+
const lockedFactors = sql`select ${factor.fields("f_")} from ${factor.name} where ${factor.column(read.authority.subjectId)} = ${factor.value(read.authority.subjectId, nativeId)} and ${active("authority")} order by ${factor.column(read.authority.credentialId)} limit 65 ${sql.onDialectOrElse({ pg: () => sql`for update`, mysql: () => sql`for update`, orElse: () => sql`` })}`;
|
|
156
|
+
|
|
157
|
+
const rows =
|
|
158
|
+
credentialId === undefined
|
|
159
|
+
? yield* sql<PasskeyNativeRow>`${lockedFactors}`
|
|
160
|
+
: yield* sql<PasskeyNativeRow>`with locked_factors as ${sql.onDialectOrElse({ pg: () => sql`materialized`, orElse: () => sql`` })} (${lockedFactors})
|
|
161
|
+
select locked_factors.*, ${credential.fields("c_")} from ${credential.name} left join locked_factors on 1 = 1
|
|
162
|
+
where ${credential.column(read.credential.subjectId)} = ${credential.value(read.credential.subjectId, nativeId)} and ${exactSqlText(sql, credential.column(read.credential.credentialId), credential.value(read.credential.credentialId, credentialId))} and ${active("credential")}`;
|
|
163
|
+
|
|
164
|
+
invariant(rows.length <= 64);
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
row,
|
|
168
|
+
credential:
|
|
169
|
+
credentialId === undefined || rows[0] === undefined
|
|
170
|
+
? undefined
|
|
171
|
+
: credential.decode(rows[0], "c_"),
|
|
172
|
+
revision: revision(
|
|
173
|
+
row,
|
|
174
|
+
rows.map((row) => factor.decode(row, "f_")),
|
|
175
|
+
),
|
|
176
|
+
nowMillis: yield* Schema.decodeEffect(Schema.Int)(Number(locked[0]!.engineNow)),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const observedSubject = joinedSubject,
|
|
181
|
+
observedFactor = joinedFactor;
|
|
182
|
+
|
|
183
|
+
const rows =
|
|
184
|
+
yield* sql<PasskeyNativeRow>`select ${observedSubject.fields("s_")}, ${observedFactor.fields("f_")}, ${now} as "engineNow" ${credentialId === undefined ? sql`` : sql`, ${joinedCredential.fields("c_")}`} from ${selected("subject", "passkey_subject")} left join ${selected("authority", "passkey_factor")} on ${observedFactor.column(read.authority.subjectId)} = ${observedFactor.value(read.authority.subjectId, nativeId)} ${credentialId === undefined ? sql`` : sql`join ${selected("credential", "passkey_credential")} on ${joinedCredential.column(read.credential.subjectId)} = ${joinedCredential.value(read.credential.subjectId, nativeId)} and ${exactSqlText(sql, joinedCredential.column(read.credential.credentialId), joinedCredential.value(read.credential.credentialId, credentialId))}`} where ${observedSubject.column(read.subject.id)} = ${observedSubject.value(read.subject.id, nativeId)} limit 65`;
|
|
185
|
+
|
|
186
|
+
if (rows.length === 0 || rows.length > 64) return undefined;
|
|
187
|
+
const row = observedSubject.decode(rows[0]!, "s_");
|
|
188
|
+
|
|
189
|
+
if (
|
|
190
|
+
!sameId(read.subject.decodeId(row), nativeId) ||
|
|
191
|
+
!read.subject.isActiveStatus(row[read.subject.status])
|
|
192
|
+
)
|
|
193
|
+
return undefined;
|
|
194
|
+
invariant(
|
|
195
|
+
rows.every((selected) => {
|
|
196
|
+
const other = observedSubject.decode(selected, "s_");
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
sameId(read.subject.decodeId(other), nativeId) &&
|
|
200
|
+
other[read.subject.securityRevision] === row[read.subject.securityRevision] &&
|
|
201
|
+
read.subject.isActiveStatus(other[read.subject.status])
|
|
202
|
+
);
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
row,
|
|
208
|
+
credential: credentialId === undefined ? undefined : joinedCredential.decode(rows[0]!, "c_"),
|
|
209
|
+
revision: revision(
|
|
210
|
+
row,
|
|
211
|
+
rows.map((selected) => observedFactor.decode(selected, "f_")),
|
|
212
|
+
),
|
|
213
|
+
nowMillis: yield* Schema.decodeEffect(Schema.Int)(Number(rows[0]!.engineNow)),
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Active predicates retain their original table qualification inside each
|
|
218
|
+
// subquery; aliases allow applications to map several roles to one table.
|
|
219
|
+
const joinedSubject = subject.as("passkey_subject");
|
|
220
|
+
const joinedFactor = factor.as("passkey_factor");
|
|
221
|
+
const joinedCredential = credential.as("passkey_credential");
|
|
222
|
+
|
|
223
|
+
const selected = (kind: "subject" | "authority" | "credential", alias: string) => {
|
|
224
|
+
const table = kind === "subject" ? subject : kind === "authority" ? factor : credential;
|
|
225
|
+
|
|
226
|
+
return sql`(select * from ${table.name} where ${active(kind)}) as ${sql(alias)}`;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const lookup = Effect.fnUntraced(function* (rpId: string, protocolCredentialId: string) {
|
|
230
|
+
const key = yield* passkeyCredentialKey(rpId, protocolCredentialId);
|
|
231
|
+
|
|
232
|
+
if (
|
|
233
|
+
subject.unencodedTextColumn?.(read.subject.id) !== undefined &&
|
|
234
|
+
credential.unencodedTextColumn?.(read.credential.subjectId) !== undefined &&
|
|
235
|
+
factor.unencodedTextColumn?.(read.authority.subjectId) !== undefined
|
|
236
|
+
) {
|
|
237
|
+
const s = joinedSubject,
|
|
238
|
+
c = joinedCredential,
|
|
239
|
+
f = joinedFactor;
|
|
240
|
+
|
|
241
|
+
const rows =
|
|
242
|
+
yield* sql<PasskeyNativeRow>`select ${s.fields("s_")}, ${c.fields("c_")}, ${f.fields("f_")}
|
|
243
|
+
from ${selected("credential", "passkey_credential")}
|
|
244
|
+
join ${selected("subject", "passkey_subject")} on ${exactSqlText(sql, s.column(read.subject.id), c.column(read.credential.subjectId))}
|
|
245
|
+
left join ${selected("authority", "passkey_factor")} on ${exactSqlText(sql, f.column(read.authority.subjectId), c.column(read.credential.subjectId))}
|
|
246
|
+
where ${exactSqlText(sql, c.column(read.credential.credentialKey), c.value(read.credential.credentialKey, key))} limit 65`;
|
|
247
|
+
|
|
248
|
+
if (rows.length === 0 || rows.length > 64) return undefined;
|
|
249
|
+
const row = c.decode(rows[0]!, "c_");
|
|
250
|
+
const subjectRow = s.decode(rows[0]!, "s_");
|
|
251
|
+
const owner = read.credential.decodeSubjectId(row);
|
|
252
|
+
|
|
253
|
+
invariant(
|
|
254
|
+
row[read.credential.rpId] === rpId &&
|
|
255
|
+
row[read.credential.protocolCredentialId] === protocolCredentialId,
|
|
256
|
+
);
|
|
257
|
+
invariant(
|
|
258
|
+
rows.every((selected) => {
|
|
259
|
+
const other = c.decode(selected, "c_");
|
|
260
|
+
const subjectValue = s.decode(selected, "s_");
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
sameId(owner, read.credential.decodeSubjectId(other)) &&
|
|
264
|
+
sameId(owner, read.subject.decodeId(subjectValue)) &&
|
|
265
|
+
other[read.credential.credentialId] === row[read.credential.credentialId] &&
|
|
266
|
+
other[read.credential.credentialRevision] === row[read.credential.credentialRevision] &&
|
|
267
|
+
subjectValue[read.subject.securityRevision] ===
|
|
268
|
+
subjectRow[read.subject.securityRevision]
|
|
269
|
+
);
|
|
270
|
+
}),
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
return yield* decodeCredential(
|
|
274
|
+
row,
|
|
275
|
+
revision(
|
|
276
|
+
subjectRow,
|
|
277
|
+
rows.map((row) => f.decode(row, "f_")),
|
|
278
|
+
),
|
|
279
|
+
subjectRow,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const rows =
|
|
284
|
+
yield* sql<PasskeyNativeRow>`select ${credential.fields("c_")} from ${credential.name} where ${credential.column(read.credential.credentialKey)} = ${credential.value(read.credential.credentialKey, key)} and ${active("credential")}`;
|
|
285
|
+
|
|
286
|
+
if (rows.length !== 1) return undefined;
|
|
287
|
+
const row = credential.decode(rows[0]!, "c_");
|
|
288
|
+
|
|
289
|
+
invariant(
|
|
290
|
+
row[read.credential.rpId] === rpId &&
|
|
291
|
+
row[read.credential.protocolCredentialId] === protocolCredentialId,
|
|
292
|
+
);
|
|
293
|
+
const current = yield* readAuthority(read.credential.decodeSubjectId(row), false);
|
|
294
|
+
|
|
295
|
+
return current === undefined
|
|
296
|
+
? undefined
|
|
297
|
+
: yield* decodeCredential(row, current.revision, current.row);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
sql,
|
|
302
|
+
tables,
|
|
303
|
+
subject,
|
|
304
|
+
credential,
|
|
305
|
+
factor,
|
|
306
|
+
now,
|
|
307
|
+
storedNow,
|
|
308
|
+
millis,
|
|
309
|
+
active,
|
|
310
|
+
native,
|
|
311
|
+
sameId,
|
|
312
|
+
revision,
|
|
313
|
+
decodeCredential,
|
|
314
|
+
readAuthority,
|
|
315
|
+
lookup,
|
|
316
|
+
joinedSubject,
|
|
317
|
+
joinedFactor,
|
|
318
|
+
joinedCredential,
|
|
319
|
+
selected,
|
|
320
|
+
mapped: sqlMapping,
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
export const makePasskeyNativeState = Effect.fnUntraced(function* (
|
|
325
|
+
tables: NativeSqlTables,
|
|
326
|
+
mapping: PasskeyNativeMapping,
|
|
327
|
+
) {
|
|
328
|
+
const state = yield* makePasskeyNativeReadState(tables, mapping.read, mapping.clock);
|
|
329
|
+
const ceremony = yield* makePasskeyNativeFlow(tables, mapping);
|
|
330
|
+
|
|
331
|
+
return { ...state, mapping, ceremony, flow: ceremony.flow, access: ceremony.access };
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
export type PasskeyNativeReadState = Effect.Success<ReturnType<typeof makePasskeyNativeReadState>>;
|
|
335
|
+
export type PasskeyNativeState = Effect.Success<ReturnType<typeof makePasskeyNativeState>>;
|