@yielded/auth-persistence 0.1.0-beta.25 → 0.1.0-beta.26
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
|
@@ -1,1062 +0,0 @@
|
|
|
1
|
-
/* oxlint-disable no-explicit-any -- existing mapped-row bridge; public adapters preserve table, ID, and Effect types. */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
PasskeyClaim,
|
|
5
|
-
type PasskeyAccess,
|
|
6
|
-
type PasskeyAssertionVerified,
|
|
7
|
-
type PasskeyCeremony,
|
|
8
|
-
type PasskeyCredential,
|
|
9
|
-
type PasskeyEvidence,
|
|
10
|
-
type PasskeyMethodPolicy,
|
|
11
|
-
snapshotPasskeySync,
|
|
12
|
-
} from "@yielded/auth/Passkey";
|
|
13
|
-
import type { SubjectId } from "@yielded/auth/Schema";
|
|
14
|
-
import { DateTime, Effect } from "effect";
|
|
15
|
-
|
|
16
|
-
import type { PasskeyFlowState } from "../models/passkey-model";
|
|
17
|
-
import type { QueryOperations } from "../query-operations";
|
|
18
|
-
import type { makeTransactionKernel } from "../transaction-kernel";
|
|
19
|
-
import type { makePasskeyAdmissionKernel } from "./admission";
|
|
20
|
-
import type { CredentialRead, SubjectRead, makePasskeyCredentialsKernel } from "./credentials";
|
|
21
|
-
import type { makePasskeyRegistrationCustodyKernel } from "./registration-custody";
|
|
22
|
-
import { CurrentPasskeyTransaction } from "./state";
|
|
23
|
-
import type { makePasskeyStateKernel } from "./state";
|
|
24
|
-
|
|
25
|
-
export interface FlowRead {
|
|
26
|
-
readonly row: Record<string, any>;
|
|
27
|
-
readonly ceremony: PasskeyCeremony;
|
|
28
|
-
readonly policy: PasskeyMethodPolicy;
|
|
29
|
-
readonly state: PasskeyFlowState;
|
|
30
|
-
readonly claim?: PasskeyClaim;
|
|
31
|
-
readonly credential?: PasskeyCredential;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const makePasskeyFlowKernel = (
|
|
35
|
-
operations: QueryOperations,
|
|
36
|
-
admission: Pick<
|
|
37
|
-
ReturnType<typeof makePasskeyAdmissionKernel>,
|
|
38
|
-
| "admissionCondition"
|
|
39
|
-
| "chargeScopes"
|
|
40
|
-
| "guardAdmission"
|
|
41
|
-
| "guardChargeSet"
|
|
42
|
-
| "insertCharges"
|
|
43
|
-
| "lockAdmission"
|
|
44
|
-
| "readCharges"
|
|
45
|
-
>,
|
|
46
|
-
credentials: Pick<
|
|
47
|
-
ReturnType<typeof makePasskeyCredentialsKernel>,
|
|
48
|
-
"readCredential" | "readModule" | "readPolicyGuards" | "readRevision" | "readSubject"
|
|
49
|
-
>,
|
|
50
|
-
registrationCustody: Pick<
|
|
51
|
-
ReturnType<typeof makePasskeyRegistrationCustodyKernel>,
|
|
52
|
-
"releaseRegistrationCustody" | "scrubRegistrationIntent"
|
|
53
|
-
>,
|
|
54
|
-
state: Pick<
|
|
55
|
-
ReturnType<typeof makePasskeyStateKernel>,
|
|
56
|
-
| "ceremonyStorage"
|
|
57
|
-
| "col"
|
|
58
|
-
| "credentialStorage"
|
|
59
|
-
| "equal"
|
|
60
|
-
| "existsExact"
|
|
61
|
-
| "invariant"
|
|
62
|
-
| "mappedColumns"
|
|
63
|
-
| "policyStorage"
|
|
64
|
-
| "profileStorage"
|
|
65
|
-
| "sameCredential"
|
|
66
|
-
| "sameRevision"
|
|
67
|
-
| "semanticCredentialColumns"
|
|
68
|
-
| "subjectScope"
|
|
69
|
-
| "targetScope"
|
|
70
|
-
>,
|
|
71
|
-
transactions: Pick<ReturnType<typeof makeTransactionKernel>, "both">,
|
|
72
|
-
) => {
|
|
73
|
-
const { sql } = operations;
|
|
74
|
-
|
|
75
|
-
const {
|
|
76
|
-
admissionCondition,
|
|
77
|
-
chargeScopes,
|
|
78
|
-
guardAdmission,
|
|
79
|
-
guardChargeSet,
|
|
80
|
-
insertCharges,
|
|
81
|
-
lockAdmission,
|
|
82
|
-
readCharges,
|
|
83
|
-
} = admission;
|
|
84
|
-
|
|
85
|
-
const { readCredential, readModule, readPolicyGuards, readRevision, readSubject } = credentials;
|
|
86
|
-
const { releaseRegistrationCustody, scrubRegistrationIntent } = registrationCustody;
|
|
87
|
-
|
|
88
|
-
const {
|
|
89
|
-
ceremonyStorage,
|
|
90
|
-
col,
|
|
91
|
-
credentialStorage,
|
|
92
|
-
equal,
|
|
93
|
-
existsExact,
|
|
94
|
-
mappedColumns,
|
|
95
|
-
policyStorage,
|
|
96
|
-
profileStorage,
|
|
97
|
-
sameCredential,
|
|
98
|
-
sameRevision,
|
|
99
|
-
semanticCredentialColumns,
|
|
100
|
-
subjectScope,
|
|
101
|
-
targetScope,
|
|
102
|
-
} = state;
|
|
103
|
-
|
|
104
|
-
const invariant: (value: unknown) => asserts value = state.invariant;
|
|
105
|
-
const { both } = transactions;
|
|
106
|
-
|
|
107
|
-
const assertionPurposes = ["sign-in", "pending", "step-up", "action"] as const;
|
|
108
|
-
|
|
109
|
-
const contextPurpose = {
|
|
110
|
-
SignIn: "sign-in",
|
|
111
|
-
Pending: "pending",
|
|
112
|
-
StepUp: "step-up",
|
|
113
|
-
Action: "action",
|
|
114
|
-
Enrollment: "enrollment",
|
|
115
|
-
Registration: "registration",
|
|
116
|
-
} as const;
|
|
117
|
-
|
|
118
|
-
const knownSubject = (ceremony: PasskeyCeremony): SubjectId | undefined =>
|
|
119
|
-
"target" in ceremony.context
|
|
120
|
-
? ceremony.context.target.revision.subjectId
|
|
121
|
-
: ceremony.context._tag === "Enrollment"
|
|
122
|
-
? ceremony.context.revision.subjectId
|
|
123
|
-
: undefined;
|
|
124
|
-
|
|
125
|
-
const compatiblePolicy = (
|
|
126
|
-
ceremony: PasskeyCeremony,
|
|
127
|
-
original: PasskeyMethodPolicy,
|
|
128
|
-
current: PasskeyMethodPolicy,
|
|
129
|
-
) => {
|
|
130
|
-
const selected = current.profiles.find(
|
|
131
|
-
(profile) => profile.profileId === ceremony.profile.profileId,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
const issued = original.profiles.find(
|
|
135
|
-
(profile) => profile.profileId === ceremony.profile.profileId,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
ceremony.generation === current.generation &&
|
|
140
|
-
ceremony.generation === original.generation &&
|
|
141
|
-
selected !== undefined &&
|
|
142
|
-
issued !== undefined &&
|
|
143
|
-
profileStorage.encode(selected) === profileStorage.encode(ceremony.profile) &&
|
|
144
|
-
profileStorage.encode(issued) === profileStorage.encode(ceremony.profile) &&
|
|
145
|
-
ceremony.claimLifetimeMillis === original.claimLifetimeMillis &&
|
|
146
|
-
ceremony.expiresAtMillis > ceremony.issuedAtMillis &&
|
|
147
|
-
ceremony.expiresAtMillis <= ceremony.requestBindingExpiresAtMillis &&
|
|
148
|
-
ceremony.expiresAtMillis - ceremony.issuedAtMillis <= original.lifetimeMillis &&
|
|
149
|
-
ceremony.expiresAtMillis - ceremony.issuedAtMillis <= current.lifetimeMillis &&
|
|
150
|
-
ceremony.retentionUntilMillis === ceremony.issuedAtMillis + original.retentionMillis &&
|
|
151
|
-
contextPurpose[ceremony.context._tag] === ceremony.purpose &&
|
|
152
|
-
new Set(ceremony.allowedCredentials.map((item) => item.id)).size ===
|
|
153
|
-
ceremony.allowedCredentials.length
|
|
154
|
-
);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const liveCondition = (mapping: any, ceremony: PasskeyCeremony, claim?: PasskeyClaim) => {
|
|
158
|
-
const now = mapping.clock.engineNowMillis;
|
|
159
|
-
|
|
160
|
-
return both(
|
|
161
|
-
sql`${now} >= ${ceremony.issuedAtMillis}`,
|
|
162
|
-
sql`${now} < ${ceremony.expiresAtMillis}`,
|
|
163
|
-
sql`${now} < ${ceremony.requestBindingExpiresAtMillis}`,
|
|
164
|
-
"target" in ceremony.context
|
|
165
|
-
? sql`${now} < ${ceremony.context.target.expiresAtMillis}`
|
|
166
|
-
: undefined,
|
|
167
|
-
claim === undefined
|
|
168
|
-
? undefined
|
|
169
|
-
: both(
|
|
170
|
-
sql`${now} >= ${claim.claimedAtMillis}`,
|
|
171
|
-
sql`${now} < ${claim.claimExpiresAtMillis}`,
|
|
172
|
-
),
|
|
173
|
-
);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const matchesAccess = (ceremony: PasskeyCeremony, access: PasskeyAccess) =>
|
|
177
|
-
ceremony.moduleId === access.moduleId &&
|
|
178
|
-
ceremony.generation === access.generation &&
|
|
179
|
-
ceremony.purpose === access.purpose &&
|
|
180
|
-
ceremony.flowId === access.flowId &&
|
|
181
|
-
ceremony.requestBindingVerifier === access.requestBindingVerifier &&
|
|
182
|
-
ceremony.requestBindingExpiresAtMillis === access.requestBindingExpiresAtMillis;
|
|
183
|
-
|
|
184
|
-
const readFlow = Effect.fn("passkey.readFlow")(function* (mapping: any, flowId: string) {
|
|
185
|
-
const owner = yield* CurrentPasskeyTransaction;
|
|
186
|
-
const table = mapping.flow;
|
|
187
|
-
|
|
188
|
-
const row = (yield* owner.read(
|
|
189
|
-
table.table,
|
|
190
|
-
equal(table.table, {
|
|
191
|
-
[table.moduleId]: mapping.moduleId,
|
|
192
|
-
[table.flowId]: flowId,
|
|
193
|
-
}),
|
|
194
|
-
{ limit: 1, columns: mappedColumns(table) },
|
|
195
|
-
)).rows[0];
|
|
196
|
-
|
|
197
|
-
if (row === undefined) return undefined;
|
|
198
|
-
const ceremony = ceremonyStorage.decode(row[table.snapshot]);
|
|
199
|
-
const policy = policyStorage.decode(row[table.policySnapshot]);
|
|
200
|
-
|
|
201
|
-
const state = Object.keys(table.states).find(
|
|
202
|
-
(name) => table.states[name] === row[table.state],
|
|
203
|
-
) as PasskeyFlowState | undefined;
|
|
204
|
-
|
|
205
|
-
invariant(
|
|
206
|
-
state !== undefined && ceremony.moduleId === mapping.moduleId && ceremony.flowId === flowId,
|
|
207
|
-
);
|
|
208
|
-
invariant(
|
|
209
|
-
row[table.moduleId] === ceremony.moduleId &&
|
|
210
|
-
row[table.flowId] === ceremony.flowId &&
|
|
211
|
-
row[table.commandId] === ceremony.commandId,
|
|
212
|
-
);
|
|
213
|
-
invariant(
|
|
214
|
-
row[table.purpose] === ceremony.purpose && row[table.generation] === ceremony.generation,
|
|
215
|
-
);
|
|
216
|
-
invariant(
|
|
217
|
-
row[table.requestBindingVerifier] === ceremony.requestBindingVerifier &&
|
|
218
|
-
mapping.clock.decodeInstant(row[table.requestBindingExpiresAt]) ===
|
|
219
|
-
ceremony.requestBindingExpiresAtMillis,
|
|
220
|
-
);
|
|
221
|
-
invariant(
|
|
222
|
-
mapping.clock.decodeInstant(row[table.issuedAt]) === ceremony.issuedAtMillis &&
|
|
223
|
-
mapping.clock.decodeInstant(row[table.expiresAt]) === ceremony.expiresAtMillis &&
|
|
224
|
-
mapping.clock.decodeInstant(row[table.retentionUntil]) === ceremony.retentionUntilMillis,
|
|
225
|
-
);
|
|
226
|
-
invariant(compatiblePolicy(ceremony, policy, policy));
|
|
227
|
-
|
|
228
|
-
const credential =
|
|
229
|
-
row[table.credentialSnapshot] === null
|
|
230
|
-
? undefined
|
|
231
|
-
: credentialStorage.decode(row[table.credentialSnapshot]);
|
|
232
|
-
|
|
233
|
-
const subject = credential?.revision.subjectId ?? knownSubject(ceremony);
|
|
234
|
-
|
|
235
|
-
invariant(
|
|
236
|
-
row[table.subjectScope] === (subject === undefined ? null : yield* subjectScope(subject)) &&
|
|
237
|
-
row[table.targetScope] === (yield* targetScope(ceremony)),
|
|
238
|
-
);
|
|
239
|
-
if (state === "Pending") {
|
|
240
|
-
invariant(
|
|
241
|
-
row[table.claimId] === null &&
|
|
242
|
-
row[table.claimedAt] === null &&
|
|
243
|
-
row[table.claimExpiresAt] === null &&
|
|
244
|
-
credential === undefined,
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
return { row, ceremony, policy, state };
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const claim =
|
|
251
|
-
row[table.claimId] === null
|
|
252
|
-
? undefined
|
|
253
|
-
: snapshotPasskeySync(PasskeyClaim, {
|
|
254
|
-
ceremony,
|
|
255
|
-
claimId: row[table.claimId],
|
|
256
|
-
claimedAtMillis: mapping.clock.decodeInstant(row[table.claimedAt]),
|
|
257
|
-
claimExpiresAtMillis: mapping.clock.decodeInstant(row[table.claimExpiresAt]),
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
invariant(state !== "Claimed" || claim !== undefined);
|
|
261
|
-
if (claim !== undefined)
|
|
262
|
-
invariant(
|
|
263
|
-
claim.claimExpiresAtMillis ===
|
|
264
|
-
Math.min(claim.claimedAtMillis + ceremony.claimLifetimeMillis, ceremony.expiresAtMillis),
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
return {
|
|
268
|
-
row,
|
|
269
|
-
ceremony,
|
|
270
|
-
policy,
|
|
271
|
-
state,
|
|
272
|
-
...(claim === undefined ? {} : { claim }),
|
|
273
|
-
...(credential === undefined ? {} : { credential }),
|
|
274
|
-
};
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
const terminalFlow = Effect.fn("passkey.terminalFlow")(function* (
|
|
278
|
-
mapping: any,
|
|
279
|
-
read: FlowRead,
|
|
280
|
-
state: "Verified" | "Rejected" | "Ambiguous",
|
|
281
|
-
) {
|
|
282
|
-
const owner = yield* CurrentPasskeyTransaction;
|
|
283
|
-
const table = mapping.flow;
|
|
284
|
-
|
|
285
|
-
yield* owner.update(
|
|
286
|
-
table.table,
|
|
287
|
-
{ [table.moduleId]: mapping.moduleId, [table.flowId]: read.ceremony.flowId },
|
|
288
|
-
{
|
|
289
|
-
[table.state]: table.states[state],
|
|
290
|
-
[table.version]: owner.marker,
|
|
291
|
-
},
|
|
292
|
-
);
|
|
293
|
-
owner.postconditions.push(
|
|
294
|
-
yield* existsExact(table.table, {
|
|
295
|
-
[table.moduleId]: mapping.moduleId,
|
|
296
|
-
[table.flowId]: read.ceremony.flowId,
|
|
297
|
-
[table.state]: table.states[state],
|
|
298
|
-
[table.version]: owner.marker,
|
|
299
|
-
}),
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
return state;
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
const targetRevision = (ceremony: PasskeyCeremony) =>
|
|
306
|
-
"target" in ceremony.context
|
|
307
|
-
? ceremony.context.target.revision
|
|
308
|
-
: ceremony.context._tag === "Enrollment"
|
|
309
|
-
? ceremony.context.revision
|
|
310
|
-
: undefined;
|
|
311
|
-
|
|
312
|
-
const currentTarget = Effect.fn("passkey.currentTarget")(function* (
|
|
313
|
-
mapping: any,
|
|
314
|
-
subject: SubjectRead | undefined,
|
|
315
|
-
ceremony: PasskeyCeremony,
|
|
316
|
-
) {
|
|
317
|
-
const target = targetRevision(ceremony);
|
|
318
|
-
|
|
319
|
-
if (target === undefined) return true;
|
|
320
|
-
if (
|
|
321
|
-
subject === undefined ||
|
|
322
|
-
subject.subjectId !== target.subjectId ||
|
|
323
|
-
subject.securityRevision !== target.securityRevision
|
|
324
|
-
)
|
|
325
|
-
return false;
|
|
326
|
-
|
|
327
|
-
const current = yield* readRevision(
|
|
328
|
-
mapping.read,
|
|
329
|
-
subject,
|
|
330
|
-
target.credentials.map((item) => item.credentialId),
|
|
331
|
-
);
|
|
332
|
-
|
|
333
|
-
return current !== undefined && sameRevision(current, target);
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
const issueAssertion = Effect.fn("passkey.issueAssertion")(function* (
|
|
337
|
-
mapping: any,
|
|
338
|
-
ceremony: PasskeyCeremony,
|
|
339
|
-
suppliedPolicy: PasskeyMethodPolicy,
|
|
340
|
-
) {
|
|
341
|
-
const owner = yield* CurrentPasskeyTransaction;
|
|
342
|
-
const current = yield* readModule(mapping);
|
|
343
|
-
|
|
344
|
-
if (
|
|
345
|
-
current === undefined ||
|
|
346
|
-
ceremony.moduleId !== mapping.moduleId ||
|
|
347
|
-
!compatiblePolicy(ceremony, suppliedPolicy, current) ||
|
|
348
|
-
policyStorage.encode(suppliedPolicy) !== policyStorage.encode(current)
|
|
349
|
-
)
|
|
350
|
-
return { _tag: "Rejected" } as const;
|
|
351
|
-
yield* lockAdmission(mapping);
|
|
352
|
-
const subjectId = knownSubject(ceremony);
|
|
353
|
-
|
|
354
|
-
const subject =
|
|
355
|
-
subjectId === undefined ? undefined : yield* readSubject(mapping.read, subjectId);
|
|
356
|
-
|
|
357
|
-
yield* readPolicyGuards(mapping);
|
|
358
|
-
if (!(yield* currentTarget(mapping, subject, ceremony))) return { _tag: "Rejected" } as const;
|
|
359
|
-
if (
|
|
360
|
-
ceremony.context._tag === "SignIn" &&
|
|
361
|
-
(!ceremony.profile.primarySignIn ||
|
|
362
|
-
ceremony.profile.userVerification !== "required" ||
|
|
363
|
-
ceremony.profile.residentKey !== "required")
|
|
364
|
-
)
|
|
365
|
-
return { _tag: "Rejected" } as const;
|
|
366
|
-
const table = mapping.flow;
|
|
367
|
-
|
|
368
|
-
const sameCommand = yield* owner.read(
|
|
369
|
-
table.table,
|
|
370
|
-
equal(table.table, {
|
|
371
|
-
[table.moduleId]: mapping.moduleId,
|
|
372
|
-
[table.commandId]: ceremony.commandId,
|
|
373
|
-
}),
|
|
374
|
-
{ limit: 1 },
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
const sameFlow = yield* readFlow(mapping, ceremony.flowId);
|
|
378
|
-
|
|
379
|
-
if (sameCommand.rows.length !== 0 || sameFlow !== undefined)
|
|
380
|
-
return { _tag: "Rejected" } as const;
|
|
381
|
-
const kinds = (yield* chargeScopes(ceremony, subjectId)).map((item) => item.kind);
|
|
382
|
-
|
|
383
|
-
if (
|
|
384
|
-
!(yield* owner.check(liveCondition(mapping, ceremony))) ||
|
|
385
|
-
!(yield* owner.check(
|
|
386
|
-
yield* admissionCondition(mapping, [current], ceremony, subjectId, kinds, true, false),
|
|
387
|
-
))
|
|
388
|
-
)
|
|
389
|
-
return { _tag: "Rejected" } as const;
|
|
390
|
-
|
|
391
|
-
const values = {
|
|
392
|
-
...table.encodeInsert({ ceremony, policy: suppliedPolicy, marker: owner.marker }),
|
|
393
|
-
[table.moduleId]: ceremony.moduleId,
|
|
394
|
-
[table.flowId]: ceremony.flowId,
|
|
395
|
-
[table.commandId]: ceremony.commandId,
|
|
396
|
-
[table.purpose]: ceremony.purpose,
|
|
397
|
-
[table.state]: table.states.Pending,
|
|
398
|
-
[table.version]: owner.marker,
|
|
399
|
-
[table.generation]: ceremony.generation,
|
|
400
|
-
[table.snapshot]: ceremonyStorage.encode(ceremony),
|
|
401
|
-
[table.policySnapshot]: policyStorage.encode(suppliedPolicy),
|
|
402
|
-
[table.requestBindingVerifier]: ceremony.requestBindingVerifier,
|
|
403
|
-
[table.requestBindingExpiresAt]: mapping.clock.encodeInstant(
|
|
404
|
-
ceremony.requestBindingExpiresAtMillis,
|
|
405
|
-
),
|
|
406
|
-
[table.issuedAt]: mapping.clock.encodeInstant(ceremony.issuedAtMillis),
|
|
407
|
-
[table.expiresAt]: mapping.clock.encodeInstant(ceremony.expiresAtMillis),
|
|
408
|
-
[table.retentionUntil]: mapping.clock.encodeInstant(ceremony.retentionUntilMillis),
|
|
409
|
-
[table.claimId]: null,
|
|
410
|
-
[table.claimedAt]: null,
|
|
411
|
-
[table.claimExpiresAt]: null,
|
|
412
|
-
[table.credentialSnapshot]: null,
|
|
413
|
-
[table.subjectScope]: subjectId === undefined ? null : yield* subjectScope(subjectId),
|
|
414
|
-
[table.targetScope]: yield* targetScope(ceremony),
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
// Empty-key observations now expect this exact inserted row as well.
|
|
418
|
-
const inserted = yield* owner.insert(table.table, values, {
|
|
419
|
-
[table.moduleId]: mapping.moduleId,
|
|
420
|
-
[table.flowId]: ceremony.flowId,
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
sameCommand.rows = inserted.rows;
|
|
424
|
-
for (const observation of owner.observations)
|
|
425
|
-
if (observation.table === table.table && observation.rows.length === 0)
|
|
426
|
-
observation.rows = inserted.rows;
|
|
427
|
-
yield* insertCharges(mapping, ceremony, suppliedPolicy, kinds, subjectId);
|
|
428
|
-
yield* guardChargeSet(mapping, ceremony, subjectId);
|
|
429
|
-
yield* guardAdmission(mapping, [current], ceremony, subjectId);
|
|
430
|
-
owner.postconditions.push(liveCondition(mapping, ceremony));
|
|
431
|
-
|
|
432
|
-
return { _tag: "Issued", ceremony } as const;
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
const contextAssertion = Effect.fn("passkey.contextAssertion")(function* (
|
|
436
|
-
mapping: any,
|
|
437
|
-
access: PasskeyAccess,
|
|
438
|
-
) {
|
|
439
|
-
const owner = yield* CurrentPasskeyTransaction;
|
|
440
|
-
|
|
441
|
-
if (access.moduleId !== mapping.moduleId) return undefined;
|
|
442
|
-
const current = yield* readModule(mapping);
|
|
443
|
-
|
|
444
|
-
if (current === undefined) return undefined;
|
|
445
|
-
yield* readPolicyGuards(mapping);
|
|
446
|
-
const read = yield* readFlow(mapping, access.flowId);
|
|
447
|
-
|
|
448
|
-
if (
|
|
449
|
-
read === undefined ||
|
|
450
|
-
read.state !== "Pending" ||
|
|
451
|
-
!matchesAccess(read.ceremony, access) ||
|
|
452
|
-
!compatiblePolicy(read.ceremony, read.policy, current)
|
|
453
|
-
)
|
|
454
|
-
return undefined;
|
|
455
|
-
if (!(yield* owner.check(liveCondition(mapping, read.ceremony)))) return undefined;
|
|
456
|
-
owner.postconditions.push(liveCondition(mapping, read.ceremony));
|
|
457
|
-
|
|
458
|
-
return read.ceremony;
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
const claimAssertion = Effect.fn("passkey.claimAssertion")(function* (
|
|
462
|
-
mapping: any,
|
|
463
|
-
input: {
|
|
464
|
-
readonly access: PasskeyAccess;
|
|
465
|
-
readonly policy: PasskeyMethodPolicy;
|
|
466
|
-
readonly ceremony: PasskeyCeremony;
|
|
467
|
-
readonly claimId: string;
|
|
468
|
-
readonly credential?: PasskeyCredential;
|
|
469
|
-
},
|
|
470
|
-
) {
|
|
471
|
-
const owner = yield* CurrentPasskeyTransaction;
|
|
472
|
-
const current = yield* readModule(mapping);
|
|
473
|
-
|
|
474
|
-
if (current === undefined || input.access.moduleId !== mapping.moduleId)
|
|
475
|
-
return { _tag: "Rejected" } as const;
|
|
476
|
-
yield* lockAdmission(mapping);
|
|
477
|
-
const expectedSubject = knownSubject(input.ceremony);
|
|
478
|
-
const subjectId = expectedSubject ?? input.credential?.revision.subjectId;
|
|
479
|
-
|
|
480
|
-
const subject =
|
|
481
|
-
subjectId === undefined ? undefined : yield* readSubject(mapping.read, subjectId);
|
|
482
|
-
|
|
483
|
-
yield* readPolicyGuards(mapping);
|
|
484
|
-
|
|
485
|
-
const requested =
|
|
486
|
-
targetRevision(input.ceremony)?.credentials.map((item) => item.credentialId) ??
|
|
487
|
-
input.credential?.revision.credentials.map((item) => item.credentialId);
|
|
488
|
-
|
|
489
|
-
const credential =
|
|
490
|
-
input.credential === undefined || subject === undefined
|
|
491
|
-
? undefined
|
|
492
|
-
: yield* readCredential(
|
|
493
|
-
mapping.read,
|
|
494
|
-
subject,
|
|
495
|
-
input.ceremony.profile.rpId,
|
|
496
|
-
input.credential.protocolCredentialId,
|
|
497
|
-
requested,
|
|
498
|
-
);
|
|
499
|
-
|
|
500
|
-
const read = yield* readFlow(mapping, input.access.flowId);
|
|
501
|
-
|
|
502
|
-
if (
|
|
503
|
-
read === undefined ||
|
|
504
|
-
read.state !== "Pending" ||
|
|
505
|
-
!matchesAccess(read.ceremony, input.access)
|
|
506
|
-
)
|
|
507
|
-
return { _tag: "Rejected" } as const;
|
|
508
|
-
invariant(ceremonyStorage.encode(read.ceremony) === ceremonyStorage.encode(input.ceremony));
|
|
509
|
-
|
|
510
|
-
const reject = Effect.gen(function* () {
|
|
511
|
-
yield* terminalFlow(mapping, read, "Rejected");
|
|
512
|
-
|
|
513
|
-
return { _tag: "Rejected" } as const;
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
if (
|
|
517
|
-
!compatiblePolicy(read.ceremony, read.policy, current) ||
|
|
518
|
-
policyStorage.encode(input.policy) !== policyStorage.encode(current) ||
|
|
519
|
-
!(yield* currentTarget(mapping, subject, read.ceremony))
|
|
520
|
-
)
|
|
521
|
-
return yield* reject;
|
|
522
|
-
if (
|
|
523
|
-
input.credential !== undefined &&
|
|
524
|
-
(credential === undefined || !sameCredential(input.credential, credential.credential))
|
|
525
|
-
)
|
|
526
|
-
return yield* reject;
|
|
527
|
-
if (input.credential !== undefined && credential !== undefined) {
|
|
528
|
-
const original = input.credential.revision;
|
|
529
|
-
const actual = credential.credential.revision;
|
|
530
|
-
const ids = [...new Set([...(requested ?? []), input.credential.credentialId])];
|
|
531
|
-
|
|
532
|
-
if (
|
|
533
|
-
original.subjectId !== actual.subjectId ||
|
|
534
|
-
original.securityRevision !== actual.securityRevision ||
|
|
535
|
-
ids.some((id) => {
|
|
536
|
-
const before = original.credentials.find((item) => item.credentialId === id);
|
|
537
|
-
const after = actual.credentials.find((item) => item.credentialId === id);
|
|
538
|
-
|
|
539
|
-
// A target can include non-passkey factors absent from the minimum
|
|
540
|
-
// lookup snapshot; currentTarget independently checks those originals.
|
|
541
|
-
return (
|
|
542
|
-
after === undefined ||
|
|
543
|
-
(before === undefined
|
|
544
|
-
? id === input.credential?.credentialId || targetRevision(read.ceremony) === undefined
|
|
545
|
-
: before.revision !== after.revision)
|
|
546
|
-
);
|
|
547
|
-
})
|
|
548
|
-
)
|
|
549
|
-
return yield* reject;
|
|
550
|
-
}
|
|
551
|
-
if (!(yield* owner.check(liveCondition(mapping, read.ceremony)))) return yield* reject;
|
|
552
|
-
yield* readCharges(mapping, read.ceremony, read.policy, expectedSubject);
|
|
553
|
-
const resolved = expectedSubject === undefined && subjectId !== undefined;
|
|
554
|
-
|
|
555
|
-
if (
|
|
556
|
-
!(yield* owner.check(
|
|
557
|
-
yield* admissionCondition(
|
|
558
|
-
mapping,
|
|
559
|
-
[read.policy, current],
|
|
560
|
-
read.ceremony,
|
|
561
|
-
subjectId,
|
|
562
|
-
resolved ? ["subject"] : [],
|
|
563
|
-
false,
|
|
564
|
-
resolved,
|
|
565
|
-
),
|
|
566
|
-
))
|
|
567
|
-
)
|
|
568
|
-
return yield* reject;
|
|
569
|
-
const claimedAtMillis = yield* owner.now(mapping.clock);
|
|
570
|
-
|
|
571
|
-
const claim = snapshotPasskeySync(PasskeyClaim, {
|
|
572
|
-
ceremony: read.ceremony,
|
|
573
|
-
claimId: input.claimId,
|
|
574
|
-
claimedAtMillis,
|
|
575
|
-
claimExpiresAtMillis: Math.min(
|
|
576
|
-
claimedAtMillis + read.ceremony.claimLifetimeMillis,
|
|
577
|
-
read.ceremony.expiresAtMillis,
|
|
578
|
-
),
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
const table = mapping.flow;
|
|
582
|
-
|
|
583
|
-
yield* owner.update(
|
|
584
|
-
table.table,
|
|
585
|
-
{ [table.moduleId]: mapping.moduleId, [table.flowId]: read.ceremony.flowId },
|
|
586
|
-
{
|
|
587
|
-
[table.state]: table.states.Claimed,
|
|
588
|
-
[table.version]: owner.marker,
|
|
589
|
-
[table.claimId]: claim.claimId,
|
|
590
|
-
[table.claimedAt]: mapping.clock.encodeInstant(claim.claimedAtMillis),
|
|
591
|
-
[table.claimExpiresAt]: mapping.clock.encodeInstant(claim.claimExpiresAtMillis),
|
|
592
|
-
[table.credentialSnapshot]:
|
|
593
|
-
input.credential === undefined ? null : credentialStorage.encode(input.credential),
|
|
594
|
-
[table.subjectScope]: subjectId === undefined ? null : yield* subjectScope(subjectId),
|
|
595
|
-
},
|
|
596
|
-
);
|
|
597
|
-
if (resolved) yield* insertCharges(mapping, read.ceremony, read.policy, ["subject"], subjectId);
|
|
598
|
-
yield* guardChargeSet(mapping, read.ceremony, subjectId);
|
|
599
|
-
yield* guardAdmission(mapping, [read.policy, current], read.ceremony, subjectId);
|
|
600
|
-
owner.postconditions.push(liveCondition(mapping, read.ceremony, claim));
|
|
601
|
-
|
|
602
|
-
return { _tag: "Claimed", claim } as const;
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
const exactClaim = (read: FlowRead, claim: PasskeyClaim) =>
|
|
606
|
-
read.state === "Claimed" &&
|
|
607
|
-
read.claim !== undefined &&
|
|
608
|
-
read.claim.claimId === claim.claimId &&
|
|
609
|
-
read.claim.claimedAtMillis === claim.claimedAtMillis &&
|
|
610
|
-
read.claim.claimExpiresAtMillis === claim.claimExpiresAtMillis &&
|
|
611
|
-
ceremonyStorage.encode(read.ceremony) === ceremonyStorage.encode(claim.ceremony);
|
|
612
|
-
|
|
613
|
-
const evidenceMatches = (
|
|
614
|
-
ceremony: PasskeyCeremony,
|
|
615
|
-
captured: PasskeyCredential,
|
|
616
|
-
credential: PasskeyCredential,
|
|
617
|
-
assertion: PasskeyAssertionVerified,
|
|
618
|
-
evidence: typeof PasskeyEvidence.Type,
|
|
619
|
-
) => {
|
|
620
|
-
const proof = evidence.proofs[0];
|
|
621
|
-
const target = targetRevision(ceremony);
|
|
622
|
-
const original = target ?? captured.revision;
|
|
623
|
-
|
|
624
|
-
const ids = [
|
|
625
|
-
...new Set([
|
|
626
|
-
...original.credentials.map((item) => item.credentialId),
|
|
627
|
-
credential.credentialId,
|
|
628
|
-
]),
|
|
629
|
-
];
|
|
630
|
-
|
|
631
|
-
const expected = {
|
|
632
|
-
...credential.revision,
|
|
633
|
-
credentials: credential.revision.credentials.filter((item) =>
|
|
634
|
-
ids.includes(item.credentialId),
|
|
635
|
-
),
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
const selected = captured.revision.credentials.find(
|
|
639
|
-
(item) => item.credentialId === credential.credentialId,
|
|
640
|
-
);
|
|
641
|
-
|
|
642
|
-
return (
|
|
643
|
-
evidence.proofs.length === 1 &&
|
|
644
|
-
proof !== undefined &&
|
|
645
|
-
proof.method === "passkey" &&
|
|
646
|
-
proof.credentialId === credential.credentialId &&
|
|
647
|
-
proof.factors.length === 1 &&
|
|
648
|
-
proof.factors[0] === "possession" &&
|
|
649
|
-
proof.userVerified === assertion.userVerified &&
|
|
650
|
-
proof.phishingResistant &&
|
|
651
|
-
DateTime.toEpochMillis(proof.verifiedAt) === ceremony.issuedAtMillis &&
|
|
652
|
-
evidence.flowId ===
|
|
653
|
-
("target" in ceremony.context ? ceremony.context.target.flowId : ceremony.flowId) &&
|
|
654
|
-
evidence.bindingDigest ===
|
|
655
|
-
("target" in ceremony.context
|
|
656
|
-
? ceremony.context.target.bindingDigest
|
|
657
|
-
: ceremony.requestBindingVerifier) &&
|
|
658
|
-
expected.credentials.length === ids.length &&
|
|
659
|
-
sameRevision(evidence.revision, expected) &&
|
|
660
|
-
original.subjectId === expected.subjectId &&
|
|
661
|
-
original.securityRevision === expected.securityRevision &&
|
|
662
|
-
original.credentials.every((item) =>
|
|
663
|
-
expected.credentials.some(
|
|
664
|
-
(current) =>
|
|
665
|
-
current.credentialId === item.credentialId && current.revision === item.revision,
|
|
666
|
-
),
|
|
667
|
-
) &&
|
|
668
|
-
selected !== undefined &&
|
|
669
|
-
expected.credentials.some(
|
|
670
|
-
(item) =>
|
|
671
|
-
item.credentialId === selected.credentialId && item.revision === selected.revision,
|
|
672
|
-
)
|
|
673
|
-
);
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
const updateTelemetry = Effect.fn("passkey.updateTelemetry")(function* (
|
|
677
|
-
mapping: any,
|
|
678
|
-
found: CredentialRead,
|
|
679
|
-
assertion: PasskeyAssertionVerified,
|
|
680
|
-
dialect: "pg" | "mysql" | "sqlite",
|
|
681
|
-
) {
|
|
682
|
-
const owner = yield* CurrentPasskeyTransaction;
|
|
683
|
-
const table = mapping.read.credential;
|
|
684
|
-
const counter = sql`${col(table.table, table.counter)}`;
|
|
685
|
-
const maximum = sql`${col(table.table, table.maximumCounter)}`;
|
|
686
|
-
|
|
687
|
-
const max = (...values: ReadonlyArray<ReturnType<QueryOperations["sql"]>>) =>
|
|
688
|
-
dialect === "sqlite"
|
|
689
|
-
? sql`max(${sql.join([...values], sql`, `)})`
|
|
690
|
-
: sql`greatest(${sql.join([...values], sql`, `)})`;
|
|
691
|
-
|
|
692
|
-
const semantic = Object.fromEntries(
|
|
693
|
-
semanticCredentialColumns(table).map((column) => [column, found.row[column]]),
|
|
694
|
-
);
|
|
695
|
-
|
|
696
|
-
const bs = mapping.telemetry.encodeBackupState(assertion.backupState);
|
|
697
|
-
const synced = found.credential.backupEligible;
|
|
698
|
-
const merged = max(counter, maximum, sql`${assertion.counter}`);
|
|
699
|
-
|
|
700
|
-
const currentCounter = synced
|
|
701
|
-
? sql`1 = 1`
|
|
702
|
-
: sql`((${counter} = 0 and ${assertion.counter} = 0) or ${counter} < ${assertion.counter})`;
|
|
703
|
-
|
|
704
|
-
yield* owner.updateGuarded(
|
|
705
|
-
table.table,
|
|
706
|
-
both(owner.exact(table.table, semantic), table.activeCondition, currentCounter),
|
|
707
|
-
{
|
|
708
|
-
[table.counter]: synced ? merged : assertion.counter,
|
|
709
|
-
[table.maximumCounter]: merged,
|
|
710
|
-
[table.backupState]: bs,
|
|
711
|
-
},
|
|
712
|
-
{
|
|
713
|
-
rows: 1,
|
|
714
|
-
postcondition: yield* existsExact(
|
|
715
|
-
table.table,
|
|
716
|
-
{ ...semantic, [table.backupState]: bs },
|
|
717
|
-
both(
|
|
718
|
-
synced ? sql`${counter} = ${maximum}` : sql`${counter} = ${assertion.counter}`,
|
|
719
|
-
sql`${maximum} >= ${assertion.counter}`,
|
|
720
|
-
),
|
|
721
|
-
),
|
|
722
|
-
},
|
|
723
|
-
);
|
|
724
|
-
const earliest = yield* owner.now(mapping.clock);
|
|
725
|
-
const lastUsed = sql`${col(table.table, mapping.telemetry.lastUsedAt)}`;
|
|
726
|
-
const millis = mapping.clock.toMillis(lastUsed);
|
|
727
|
-
|
|
728
|
-
yield* owner.finalUpdate(
|
|
729
|
-
table.table,
|
|
730
|
-
owner.exact(table.table, semantic),
|
|
731
|
-
{
|
|
732
|
-
[mapping.telemetry.lastUsedAt]: mapping.clock.fromMillis(
|
|
733
|
-
max(sql`coalesce(${millis}, 0)`, mapping.clock.engineNowMillis),
|
|
734
|
-
),
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
rows: 1,
|
|
738
|
-
postcondition: yield* existsExact(
|
|
739
|
-
table.table,
|
|
740
|
-
semantic,
|
|
741
|
-
both(sql`${millis} >= ${earliest}`, sql`${millis} <= ${mapping.clock.engineNowMillis}`),
|
|
742
|
-
),
|
|
743
|
-
},
|
|
744
|
-
);
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
const settleAssertion = Effect.fn("passkey.settleAssertion")(function* (
|
|
748
|
-
mapping: any,
|
|
749
|
-
claim: PasskeyClaim,
|
|
750
|
-
outcome:
|
|
751
|
-
| { readonly _tag: "Rejected" | "Ambiguous" }
|
|
752
|
-
| {
|
|
753
|
-
readonly _tag: "Assertion";
|
|
754
|
-
readonly credential: PasskeyCredential;
|
|
755
|
-
readonly assertion: PasskeyAssertionVerified;
|
|
756
|
-
readonly evidence: typeof PasskeyEvidence.Type;
|
|
757
|
-
},
|
|
758
|
-
dialect: "pg" | "mysql" | "sqlite",
|
|
759
|
-
) {
|
|
760
|
-
const owner = yield* CurrentPasskeyTransaction;
|
|
761
|
-
const assertedCredential = outcome._tag === "Assertion" ? outcome.credential : undefined;
|
|
762
|
-
const current = yield* readModule(mapping);
|
|
763
|
-
|
|
764
|
-
if (current === undefined || claim.ceremony.moduleId !== mapping.moduleId)
|
|
765
|
-
return "Rejected" as const;
|
|
766
|
-
yield* lockAdmission(mapping);
|
|
767
|
-
|
|
768
|
-
const originalIds =
|
|
769
|
-
targetRevision(claim.ceremony)?.credentials.map((item) => item.credentialId) ??
|
|
770
|
-
(outcome._tag === "Assertion"
|
|
771
|
-
? outcome.credential.revision.credentials.map((item) => item.credentialId)
|
|
772
|
-
: undefined);
|
|
773
|
-
|
|
774
|
-
const subjectId =
|
|
775
|
-
outcome._tag === "Assertion"
|
|
776
|
-
? outcome.credential.revision.subjectId
|
|
777
|
-
: knownSubject(claim.ceremony);
|
|
778
|
-
|
|
779
|
-
const subject =
|
|
780
|
-
subjectId === undefined ? undefined : yield* readSubject(mapping.read, subjectId);
|
|
781
|
-
|
|
782
|
-
yield* readPolicyGuards(mapping);
|
|
783
|
-
|
|
784
|
-
const found =
|
|
785
|
-
outcome._tag !== "Assertion" || subject === undefined
|
|
786
|
-
? undefined
|
|
787
|
-
: yield* readCredential(
|
|
788
|
-
mapping.read,
|
|
789
|
-
subject,
|
|
790
|
-
claim.ceremony.profile.rpId,
|
|
791
|
-
outcome.credential.protocolCredentialId,
|
|
792
|
-
originalIds,
|
|
793
|
-
);
|
|
794
|
-
|
|
795
|
-
const read = yield* readFlow(mapping, claim.ceremony.flowId);
|
|
796
|
-
|
|
797
|
-
if (read === undefined || !exactClaim(read, claim)) return "Rejected" as const;
|
|
798
|
-
if (outcome._tag !== "Assertion") return yield* terminalFlow(mapping, read, outcome._tag);
|
|
799
|
-
invariant(assertedCredential !== undefined);
|
|
800
|
-
const captured = "credential" in read ? read.credential : undefined;
|
|
801
|
-
const assertion = outcome.assertion;
|
|
802
|
-
|
|
803
|
-
if (
|
|
804
|
-
captured === undefined ||
|
|
805
|
-
found === undefined ||
|
|
806
|
-
!compatiblePolicy(read.ceremony, read.policy, current) ||
|
|
807
|
-
!sameCredential(captured, assertedCredential) ||
|
|
808
|
-
!sameCredential(captured, found.credential)
|
|
809
|
-
)
|
|
810
|
-
return yield* terminalFlow(mapping, read, "Rejected");
|
|
811
|
-
const credential = found.credential;
|
|
812
|
-
const profile = read.ceremony.profile;
|
|
813
|
-
|
|
814
|
-
if (
|
|
815
|
-
assertion.protocolCredentialId !== credential.protocolCredentialId ||
|
|
816
|
-
(assertion.userHandle !== undefined && assertion.userHandle !== credential.userHandle) ||
|
|
817
|
-
assertion.backupEligible !== credential.backupEligible ||
|
|
818
|
-
(assertion.backupState && !assertion.backupEligible) ||
|
|
819
|
-
(profile.userVerification === "required" && !assertion.userVerified) ||
|
|
820
|
-
!profile.algorithms.includes(credential.algorithm) ||
|
|
821
|
-
(read.ceremony.allowedCredentials.length !== 0 &&
|
|
822
|
-
!read.ceremony.allowedCredentials.some(
|
|
823
|
-
(item) => item.id === credential.protocolCredentialId,
|
|
824
|
-
)) ||
|
|
825
|
-
(read.ceremony.purpose === "sign-in" &&
|
|
826
|
-
(assertion.userHandle !== credential.userHandle ||
|
|
827
|
-
!credential.primarySignIn ||
|
|
828
|
-
!credential.enrollmentUserVerified ||
|
|
829
|
-
!credential.profile.primarySignIn ||
|
|
830
|
-
credential.profile.userVerification !== "required" ||
|
|
831
|
-
!assertion.userVerified)) ||
|
|
832
|
-
!evidenceMatches(read.ceremony, captured, credential, assertion, outcome.evidence) ||
|
|
833
|
-
!(yield* owner.check(liveCondition(mapping, read.ceremony, claim)))
|
|
834
|
-
)
|
|
835
|
-
return yield* terminalFlow(mapping, read, "Rejected");
|
|
836
|
-
yield* readCharges(mapping, read.ceremony, read.policy, credential.revision.subjectId);
|
|
837
|
-
yield* guardChargeSet(mapping, read.ceremony, credential.revision.subjectId);
|
|
838
|
-
yield* updateTelemetry(mapping, found, assertion, dialect);
|
|
839
|
-
yield* terminalFlow(mapping, read, "Verified");
|
|
840
|
-
owner.postconditions.push(liveCondition(mapping, read.ceremony, claim));
|
|
841
|
-
|
|
842
|
-
return "Verified" as const;
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
const purposeCondition = (table: any, purposes: ReadonlyArray<string>) =>
|
|
846
|
-
sql`${col(table.table, table.purpose)} in (${sql.join(
|
|
847
|
-
purposes.map((purpose) => sql`${purpose}`),
|
|
848
|
-
sql`, `,
|
|
849
|
-
)})`;
|
|
850
|
-
|
|
851
|
-
const custodyFree = (mapping: any, flowExpression: ReturnType<QueryOperations["sql"]>) => {
|
|
852
|
-
if (mapping.intent === undefined) return sql`1 = 1`;
|
|
853
|
-
const intent = mapping.intent;
|
|
854
|
-
|
|
855
|
-
return sql`not exists (select 1 from ${intent.table} where ${both(
|
|
856
|
-
equal(intent.table, { [intent.moduleId]: mapping.moduleId }),
|
|
857
|
-
sql`${col(intent.table, intent.flowId)} = ${flowExpression}`,
|
|
858
|
-
intent.custodyCondition,
|
|
859
|
-
)})`;
|
|
860
|
-
};
|
|
861
|
-
|
|
862
|
-
const flowDue = (mapping: any, purposes: ReadonlyArray<string>) => {
|
|
863
|
-
const flow = mapping.flow,
|
|
864
|
-
charge = mapping.charge,
|
|
865
|
-
now = mapping.clock.engineNowMillis;
|
|
866
|
-
|
|
867
|
-
const state = sql`${col(flow.table, flow.state)}`;
|
|
868
|
-
const retained = sql`${mapping.clock.toMillis(sql`${col(flow.table, flow.retentionUntil)}`)} <= ${now}`;
|
|
869
|
-
|
|
870
|
-
const chargeLive = sql`exists (select 1 from ${charge.table} where ${both(
|
|
871
|
-
equal(charge.table, { [charge.moduleId]: mapping.moduleId }),
|
|
872
|
-
sql`${col(charge.table, charge.flowId)} = ${col(flow.table, flow.flowId)}`,
|
|
873
|
-
sql`(${col(charge.table, charge.retainUntil)} is null or ${mapping.clock.toMillis(sql`${col(charge.table, charge.retainUntil)}`)} > ${now})`,
|
|
874
|
-
)})`;
|
|
875
|
-
|
|
876
|
-
return both(
|
|
877
|
-
equal(flow.table, { [flow.moduleId]: mapping.moduleId }),
|
|
878
|
-
purposeCondition(flow, purposes),
|
|
879
|
-
sql`((${state} = ${flow.states.Pending} and ${mapping.clock.toMillis(sql`${col(flow.table, flow.expiresAt)}`)} <= ${now}) or
|
|
880
|
-
(${state} = ${flow.states.Claimed} and ${mapping.clock.toMillis(sql`${col(flow.table, flow.claimExpiresAt)}`)} <= ${now}) or
|
|
881
|
-
(${state} in (${flow.states.Verified}, ${flow.states.Rejected}, ${flow.states.Ambiguous}, ${flow.states.RegistrationAccepted}) and ${retained} and not (${chargeLive}) and ${custodyFree(mapping, sql`${col(flow.table, flow.flowId)}`)}))`,
|
|
882
|
-
);
|
|
883
|
-
};
|
|
884
|
-
|
|
885
|
-
const chargeDue = (mapping: any, purposes: ReadonlyArray<string>) => {
|
|
886
|
-
const charge = mapping.charge;
|
|
887
|
-
|
|
888
|
-
return both(
|
|
889
|
-
equal(charge.table, { [charge.moduleId]: mapping.moduleId }),
|
|
890
|
-
purposeCondition(charge, purposes),
|
|
891
|
-
sql`${col(charge.table, charge.admittedAt)} is not null and ${mapping.clock.toMillis(sql`${col(charge.table, charge.retainUntil)}`)} <= ${mapping.clock.engineNowMillis}`,
|
|
892
|
-
custodyFree(mapping, sql`${col(charge.table, charge.flowId)}`),
|
|
893
|
-
);
|
|
894
|
-
};
|
|
895
|
-
|
|
896
|
-
/** Flow transitions and row removals share one bound. Prepared hasMore is
|
|
897
|
-
* predicted from this owner's staged changes, then asserted after final writes. */
|
|
898
|
-
const cleanupCeremonies = Effect.fn("passkey.cleanupCeremonies")(function* (
|
|
899
|
-
mapping: any,
|
|
900
|
-
input: { readonly moduleId: string; readonly nowMillis: number; readonly limit: number },
|
|
901
|
-
purposes: ReadonlyArray<string>,
|
|
902
|
-
) {
|
|
903
|
-
const owner = yield* CurrentPasskeyTransaction;
|
|
904
|
-
|
|
905
|
-
invariant(
|
|
906
|
-
input.moduleId === mapping.moduleId &&
|
|
907
|
-
Number.isSafeInteger(input.nowMillis) &&
|
|
908
|
-
input.nowMillis >= 0 &&
|
|
909
|
-
Number.isSafeInteger(input.limit) &&
|
|
910
|
-
input.limit >= 1 &&
|
|
911
|
-
input.limit <= 1000,
|
|
912
|
-
);
|
|
913
|
-
yield* readModule(mapping);
|
|
914
|
-
yield* lockAdmission(mapping);
|
|
915
|
-
yield* readPolicyGuards(mapping);
|
|
916
|
-
|
|
917
|
-
const flow = mapping.flow,
|
|
918
|
-
charge = mapping.charge;
|
|
919
|
-
|
|
920
|
-
const rows = (yield* owner.read(flow.table, flowDue(mapping, purposes), {
|
|
921
|
-
limit: input.limit,
|
|
922
|
-
takeOnly: true,
|
|
923
|
-
observe: false,
|
|
924
|
-
orderBy: sql`${col(flow.table, flow.flowId)}`,
|
|
925
|
-
})).rows;
|
|
926
|
-
|
|
927
|
-
const touched: string[] = [];
|
|
928
|
-
const transitioned: FlowRead[] = [];
|
|
929
|
-
|
|
930
|
-
let terminalized = 0,
|
|
931
|
-
removed = 0;
|
|
932
|
-
|
|
933
|
-
for (const candidate of rows) {
|
|
934
|
-
const read = yield* readFlow(mapping, candidate[flow.flowId]);
|
|
935
|
-
|
|
936
|
-
if (read === undefined) continue;
|
|
937
|
-
invariant(
|
|
938
|
-
yield* owner.check(
|
|
939
|
-
sql`exists (select 1 from ${flow.table} where ${both(equal(flow.table, { [flow.moduleId]: mapping.moduleId, [flow.flowId]: read.ceremony.flowId }), flowDue(mapping, purposes))})`,
|
|
940
|
-
),
|
|
941
|
-
);
|
|
942
|
-
touched.push(read.ceremony.flowId);
|
|
943
|
-
if (read.state === "Pending" || read.state === "Claimed") {
|
|
944
|
-
const deadline =
|
|
945
|
-
read.state === "Pending"
|
|
946
|
-
? read.ceremony.expiresAtMillis
|
|
947
|
-
: read.claim!.claimExpiresAtMillis;
|
|
948
|
-
|
|
949
|
-
if (read.state === "Pending") yield* releaseRegistrationCustody(mapping, read.ceremony);
|
|
950
|
-
yield* terminalFlow(mapping, read, read.state === "Pending" ? "Rejected" : "Ambiguous");
|
|
951
|
-
owner.postconditions.push(sql`${mapping.clock.engineNowMillis} >= ${deadline}`);
|
|
952
|
-
transitioned.push(read);
|
|
953
|
-
terminalized++;
|
|
954
|
-
} else {
|
|
955
|
-
yield* scrubRegistrationIntent(mapping, read.ceremony);
|
|
956
|
-
yield* owner.remove(flow.table, {
|
|
957
|
-
[flow.moduleId]: mapping.moduleId,
|
|
958
|
-
[flow.flowId]: read.ceremony.flowId,
|
|
959
|
-
});
|
|
960
|
-
owner.postconditions.push(
|
|
961
|
-
sql`${mapping.clock.engineNowMillis} >= ${read.ceremony.retentionUntilMillis}`,
|
|
962
|
-
custodyFree(mapping, sql`${read.ceremony.flowId}`),
|
|
963
|
-
sql`not exists (select 1 from ${charge.table} where ${both(
|
|
964
|
-
equal(charge.table, {
|
|
965
|
-
[charge.moduleId]: mapping.moduleId,
|
|
966
|
-
[charge.flowId]: read.ceremony.flowId,
|
|
967
|
-
}),
|
|
968
|
-
sql`(${col(charge.table, charge.retainUntil)} is null or ${mapping.clock.toMillis(sql`${col(charge.table, charge.retainUntil)}`)} > ${mapping.clock.engineNowMillis})`,
|
|
969
|
-
)})`,
|
|
970
|
-
);
|
|
971
|
-
removed++;
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
const removedCharges: Array<{ flowId: string; kind: string }> = [];
|
|
975
|
-
const remaining = input.limit - terminalized - removed;
|
|
976
|
-
|
|
977
|
-
if (remaining > 0) {
|
|
978
|
-
const charges = (yield* owner.read(charge.table, chargeDue(mapping, purposes), {
|
|
979
|
-
limit: remaining,
|
|
980
|
-
takeOnly: true,
|
|
981
|
-
observe: false,
|
|
982
|
-
orderBy: sql`${col(charge.table, charge.flowId)}, ${col(charge.table, charge.kind)}`,
|
|
983
|
-
})).rows;
|
|
984
|
-
|
|
985
|
-
for (const candidate of charges) {
|
|
986
|
-
const identity = {
|
|
987
|
-
[charge.moduleId]: mapping.moduleId,
|
|
988
|
-
[charge.flowId]: candidate[charge.flowId],
|
|
989
|
-
[charge.kind]: candidate[charge.kind],
|
|
990
|
-
};
|
|
991
|
-
|
|
992
|
-
const selected = (yield* owner.read(charge.table, equal(charge.table, identity), {
|
|
993
|
-
limit: 1,
|
|
994
|
-
})).rows[0];
|
|
995
|
-
|
|
996
|
-
invariant(selected !== undefined);
|
|
997
|
-
const horizon = mapping.clock.decodeInstant(selected[charge.retainUntil]);
|
|
998
|
-
|
|
999
|
-
invariant(Number.isSafeInteger(horizon));
|
|
1000
|
-
yield* owner.remove(charge.table, identity);
|
|
1001
|
-
owner.postconditions.push(
|
|
1002
|
-
sql`${mapping.clock.engineNowMillis} >= ${horizon}`,
|
|
1003
|
-
custodyFree(mapping, sql`${candidate[charge.flowId]}`),
|
|
1004
|
-
);
|
|
1005
|
-
removedCharges.push({ flowId: candidate[charge.flowId], kind: candidate[charge.kind] });
|
|
1006
|
-
removed++;
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
const excludeFlows =
|
|
1011
|
-
touched.length === 0
|
|
1012
|
-
? undefined
|
|
1013
|
-
: sql`${col(flow.table, flow.flowId)} not in (${sql.join(
|
|
1014
|
-
touched.map((id) => sql`${id}`),
|
|
1015
|
-
sql`, `,
|
|
1016
|
-
)})`;
|
|
1017
|
-
|
|
1018
|
-
const excludeCharges = removedCharges.map(
|
|
1019
|
-
(item) =>
|
|
1020
|
-
sql`not (${equal(charge.table, { [charge.flowId]: item.flowId, [charge.kind]: item.kind })})`,
|
|
1021
|
-
);
|
|
1022
|
-
|
|
1023
|
-
const predicted = sql`exists (select 1 from ${flow.table} where ${both(flowDue(mapping, purposes), excludeFlows)}) or exists (select 1 from ${charge.table} where ${both(chargeDue(mapping, purposes), ...excludeCharges)})`;
|
|
1024
|
-
// A transitioned row cannot also be removed by this call, but may be due now.
|
|
1025
|
-
// Read through check only for unchanged rows; D1's prebatch assertion must use
|
|
1026
|
-
// this predictive predicate, while the final assertion uses actual states.
|
|
1027
|
-
let hasMore = yield* owner.check(predicted);
|
|
1028
|
-
|
|
1029
|
-
for (const read of transitioned) {
|
|
1030
|
-
if (read.ceremony.retentionUntilMillis > (yield* owner.now(mapping.clock))) continue;
|
|
1031
|
-
const liveCharges = sql`exists (select 1 from ${charge.table} where ${both(equal(charge.table, { [charge.moduleId]: mapping.moduleId, [charge.flowId]: read.ceremony.flowId }), sql`${mapping.clock.toMillis(sql`${col(charge.table, charge.retainUntil)}`)} > ${mapping.clock.engineNowMillis}`, ...excludeCharges)})`;
|
|
1032
|
-
|
|
1033
|
-
if (
|
|
1034
|
-
!(yield* owner.check(liveCharges)) &&
|
|
1035
|
-
(yield* owner.check(custodyFree(mapping, sql`${read.ceremony.flowId}`)))
|
|
1036
|
-
)
|
|
1037
|
-
hasMore = true;
|
|
1038
|
-
}
|
|
1039
|
-
const actual = sql`exists (select 1 from ${flow.table} where ${flowDue(mapping, purposes)}) or exists (select 1 from ${charge.table} where ${chargeDue(mapping, purposes)})`;
|
|
1040
|
-
|
|
1041
|
-
owner.postconditions.push(hasMore ? actual : sql`not (${actual})`);
|
|
1042
|
-
|
|
1043
|
-
return { terminalized, removed, hasMore };
|
|
1044
|
-
});
|
|
1045
|
-
|
|
1046
|
-
return {
|
|
1047
|
-
assertionPurposes,
|
|
1048
|
-
contextPurpose,
|
|
1049
|
-
knownSubject,
|
|
1050
|
-
compatiblePolicy,
|
|
1051
|
-
liveCondition,
|
|
1052
|
-
matchesAccess,
|
|
1053
|
-
readFlow,
|
|
1054
|
-
terminalFlow,
|
|
1055
|
-
issueAssertion,
|
|
1056
|
-
contextAssertion,
|
|
1057
|
-
claimAssertion,
|
|
1058
|
-
exactClaim,
|
|
1059
|
-
settleAssertion,
|
|
1060
|
-
cleanupCeremonies,
|
|
1061
|
-
};
|
|
1062
|
-
};
|