@yielded/auth-persistence 0.1.0-beta.24 → 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 +16 -82
- 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 +28 -148
- 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 -346
- 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 -1555
- package/src/internal/oauth/accounts.ts +0 -838
- 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 -678
- 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 -1522
- 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,1522 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
coordinateCommit,
|
|
3
|
-
CurrentCommitJournal,
|
|
4
|
-
hasCommitScope,
|
|
5
|
-
type CommitJournal,
|
|
6
|
-
type PreparedCommit,
|
|
7
|
-
LifecycleHooks,
|
|
8
|
-
HookConfigurationError,
|
|
9
|
-
} from "@yielded/auth/Hooks";
|
|
10
|
-
import type { LoginIdentifier } from "@yielded/auth/Identity";
|
|
11
|
-
import {
|
|
12
|
-
PasswordUnavailable,
|
|
13
|
-
PasswordPersistence,
|
|
14
|
-
type PasswordMutationInput,
|
|
15
|
-
snapshotPasswordCredential,
|
|
16
|
-
snapshotPasswordRequirement,
|
|
17
|
-
snapshotPasswordRevision,
|
|
18
|
-
type PasswordAction,
|
|
19
|
-
type PasswordMutationDecision,
|
|
20
|
-
} from "@yielded/auth/Password";
|
|
21
|
-
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
22
|
-
import {
|
|
23
|
-
type ProofCompletionPlan,
|
|
24
|
-
type ProofCompletionInput,
|
|
25
|
-
ProofUnavailable,
|
|
26
|
-
} from "@yielded/auth/Proofs";
|
|
27
|
-
import {
|
|
28
|
-
snapshotAuthenticationEvidence,
|
|
29
|
-
type AuthenticationEvidence,
|
|
30
|
-
type AuthenticationRequirement,
|
|
31
|
-
type SecurityRevision,
|
|
32
|
-
} from "@yielded/auth/Sessions";
|
|
33
|
-
import { Cause, Context, DateTime, Effect, Option, Redacted, Schema } from "effect";
|
|
34
|
-
import type { SqlClient } from "effect/sql/SqlClient";
|
|
35
|
-
import type * as SqlError from "effect/sql/SqlError";
|
|
36
|
-
|
|
37
|
-
import { PersistenceMappingError } from "./mapping-error";
|
|
38
|
-
import {
|
|
39
|
-
type AnyPasswordPersistenceMapping,
|
|
40
|
-
requiredPasswordConstraints,
|
|
41
|
-
} from "./models/password-model";
|
|
42
|
-
import { makeNativeSqlTables, sqlMapping, type NativeSqlTables } from "./native-sql-table";
|
|
43
|
-
import {
|
|
44
|
-
makePasswordCredentials,
|
|
45
|
-
samePasswordCredentialSnapshot as sameCredentialSnapshot,
|
|
46
|
-
} from "./password-credentials";
|
|
47
|
-
import {
|
|
48
|
-
CurrentPasswordPreparedTransaction,
|
|
49
|
-
PasswordPreparedPostconditions,
|
|
50
|
-
} from "./PasswordPreparedPostconditions";
|
|
51
|
-
import {
|
|
52
|
-
CurrentProofSql,
|
|
53
|
-
type ProofSqlConfiguration,
|
|
54
|
-
type ProofSqlDatabase,
|
|
55
|
-
type makeProofKernel,
|
|
56
|
-
} from "./proof-kernel";
|
|
57
|
-
/* oxlint-disable no-explicit-any -- existing storage kernels erase foreign table shapes; domain errors remain typed. */
|
|
58
|
-
import type { QueryFailure } from "./query-operations";
|
|
59
|
-
import type { QueryOperations, SqlFragment, SqlColumn } from "./query-operations";
|
|
60
|
-
import { NativeDatabase } from "./transaction-kernel";
|
|
61
|
-
|
|
62
|
-
type AdapterFailure = QueryFailure | PersistenceMappingError | SqlError.SqlError;
|
|
63
|
-
|
|
64
|
-
export interface PasswordSqlQuery<A = ReadonlyArray<any>> extends Effect.Effect<A, AdapterFailure> {
|
|
65
|
-
readonly getSQL: () => ReturnType<QueryOperations["sql"]>;
|
|
66
|
-
readonly from: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
67
|
-
readonly where: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
68
|
-
readonly limit: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
69
|
-
readonly orderBy: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
70
|
-
readonly for: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
71
|
-
readonly set: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
72
|
-
readonly values: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
73
|
-
readonly returning: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
74
|
-
readonly $returningId: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
75
|
-
readonly onConflictDoNothing: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
76
|
-
readonly onDuplicateKeyUpdate: (...args: ReadonlyArray<any>) => PasswordSqlQuery<A>;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface PasswordSqlDatabase {
|
|
80
|
-
readonly select: (...args: ReadonlyArray<any>) => PasswordSqlQuery;
|
|
81
|
-
readonly insert: (...args: ReadonlyArray<any>) => PasswordSqlQuery;
|
|
82
|
-
readonly update: (...args: ReadonlyArray<any>) => PasswordSqlQuery;
|
|
83
|
-
readonly delete: (...args: ReadonlyArray<any>) => PasswordSqlQuery;
|
|
84
|
-
readonly transaction: <A, E, R>(
|
|
85
|
-
body: (transaction: PasswordSqlDatabase) => Effect.Effect<A, E, R>,
|
|
86
|
-
) => Effect.Effect<A, E | SqlError.SqlError, R>;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export class CurrentPasswordSql extends Context.Service<CurrentPasswordSql, PasswordSqlDatabase>()(
|
|
90
|
-
"effect-auth/CurrentPasswordSql",
|
|
91
|
-
) {}
|
|
92
|
-
|
|
93
|
-
export interface PasswordSqlConfiguration {
|
|
94
|
-
readonly mode: "interactive" | "synchronous";
|
|
95
|
-
readonly locking: boolean;
|
|
96
|
-
readonly standaloneGuard: Effect.Effect<void, PasswordUnavailable>;
|
|
97
|
-
readonly coordinated?: boolean;
|
|
98
|
-
readonly insertIfAbsent: (
|
|
99
|
-
query: PasswordSqlQuery,
|
|
100
|
-
selfKey: string,
|
|
101
|
-
selfValue: unknown,
|
|
102
|
-
) => PasswordSqlQuery;
|
|
103
|
-
readonly proof?: {
|
|
104
|
-
readonly mapping: any;
|
|
105
|
-
readonly configuration: ProofSqlConfiguration;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
type Database = PasswordSqlDatabase;
|
|
110
|
-
|
|
111
|
-
export const makePasswordKernel = <
|
|
112
|
-
Fragment extends SqlFragment = SqlFragment,
|
|
113
|
-
Column extends SqlColumn = SqlColumn,
|
|
114
|
-
>(
|
|
115
|
-
operations: QueryOperations<Fragment, Column>,
|
|
116
|
-
proofs: Pick<ReturnType<typeof makeProofKernel>, "completeProofPlanIn">,
|
|
117
|
-
nativeTables: (client: SqlClient, database: object) => NativeSqlTables = (client) =>
|
|
118
|
-
makeNativeSqlTables(client),
|
|
119
|
-
) => {
|
|
120
|
-
type Mapping = AnyPasswordPersistenceMapping<Fragment>;
|
|
121
|
-
|
|
122
|
-
const { and, eq, inArray, column, updateValues } = operations;
|
|
123
|
-
const { completeProofPlanIn } = proofs;
|
|
124
|
-
const unavailable = () => PasswordUnavailable.make({});
|
|
125
|
-
|
|
126
|
-
const translateFailure = <A, E, R>(
|
|
127
|
-
effect: Effect.Effect<A, E, R>,
|
|
128
|
-
): Effect.Effect<A, PasswordUnavailable, R> =>
|
|
129
|
-
reportPersistenceFailure(
|
|
130
|
-
effect,
|
|
131
|
-
(error) =>
|
|
132
|
-
Schema.is(PasswordUnavailable)(error) ||
|
|
133
|
-
Schema.is(ProofUnavailable)(error) ||
|
|
134
|
-
Schema.is(HookConfigurationError)(error),
|
|
135
|
-
).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
|
|
136
|
-
|
|
137
|
-
const nowMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));
|
|
138
|
-
|
|
139
|
-
const validConstraints = (mapping: Mapping) =>
|
|
140
|
-
Object.entries(requiredPasswordConstraints).every(
|
|
141
|
-
([key, value]) =>
|
|
142
|
-
mapping.constraints[key as keyof typeof requiredPasswordConstraints] === value,
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const selectRows = (query: PasswordSqlQuery, locking: boolean) =>
|
|
146
|
-
locking && typeof query.for === "function" ? query.for("update") : query;
|
|
147
|
-
|
|
148
|
-
const subjectColumns = (mapping: Mapping) => ({
|
|
149
|
-
id: column(mapping.subject.table, mapping.subject.id),
|
|
150
|
-
status: column(mapping.subject.table, mapping.subject.status),
|
|
151
|
-
securityRevision: column(mapping.subject.table, mapping.subject.securityRevision),
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
const identifierColumns = (mapping: Mapping) => ({
|
|
155
|
-
namespace: column(mapping.identifier.table, mapping.identifier.namespace),
|
|
156
|
-
value: column(mapping.identifier.table, mapping.identifier.value),
|
|
157
|
-
subjectId: column(mapping.identifier.table, mapping.identifier.subjectId),
|
|
158
|
-
verifiedAt: column(mapping.identifier.table, mapping.identifier.verifiedAt),
|
|
159
|
-
bindingRevision: column(mapping.identifier.table, mapping.identifier.bindingRevision),
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const credentialColumns = (mapping: Mapping) => ({
|
|
163
|
-
moduleId: column(mapping.credential.table, mapping.credential.moduleId),
|
|
164
|
-
subjectId: column(mapping.credential.table, mapping.credential.subjectId),
|
|
165
|
-
credentialId: column(mapping.credential.table, mapping.credential.credentialId),
|
|
166
|
-
credentialRevision: column(mapping.credential.table, mapping.credential.credentialRevision),
|
|
167
|
-
verifierVersion: column(mapping.credential.table, mapping.credential.verifierVersion),
|
|
168
|
-
verifier: column(mapping.credential.table, mapping.credential.verifier),
|
|
169
|
-
normalization: column(mapping.credential.table, mapping.credential.normalization),
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const authorityCredentialColumns = (mapping: Mapping) => ({
|
|
173
|
-
subjectId: column(mapping.authorityCredential.table, mapping.authorityCredential.subjectId),
|
|
174
|
-
credentialId: column(
|
|
175
|
-
mapping.authorityCredential.table,
|
|
176
|
-
mapping.authorityCredential.credentialId,
|
|
177
|
-
),
|
|
178
|
-
revision: column(mapping.authorityCredential.table, mapping.authorityCredential.revision),
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const commandColumns = (mapping: Mapping) => ({
|
|
182
|
-
moduleId: column(mapping.command.table, mapping.command.moduleId),
|
|
183
|
-
commandId: column(mapping.command.table, mapping.command.commandId),
|
|
184
|
-
action: column(mapping.command.table, mapping.command.action),
|
|
185
|
-
bindingDigest: column(mapping.command.table, mapping.command.bindingDigest),
|
|
186
|
-
decision: column(mapping.command.table, mapping.command.decision),
|
|
187
|
-
retentionUntil: column(mapping.command.table, mapping.command.retentionUntil),
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
const allocate = <A>(
|
|
191
|
-
mode: PasswordSqlConfiguration["mode"],
|
|
192
|
-
asyncValue: Effect.Effect<A, PersistenceMappingError> | undefined,
|
|
193
|
-
syncValue: (() => A) | undefined,
|
|
194
|
-
): Effect.Effect<A, PasswordUnavailable | PersistenceMappingError> => {
|
|
195
|
-
if (mode === "synchronous")
|
|
196
|
-
return syncValue === undefined
|
|
197
|
-
? Effect.fail(unavailable())
|
|
198
|
-
: Effect.try({
|
|
199
|
-
try: syncValue,
|
|
200
|
-
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
201
|
-
});
|
|
202
|
-
if (asyncValue !== undefined) return asyncValue;
|
|
203
|
-
|
|
204
|
-
return syncValue === undefined
|
|
205
|
-
? Effect.fail(unavailable())
|
|
206
|
-
: Effect.try({
|
|
207
|
-
try: syncValue,
|
|
208
|
-
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
209
|
-
});
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
const allocateNextSecurityRevision = (
|
|
213
|
-
mapping: Mapping,
|
|
214
|
-
mode: PasswordSqlConfiguration["mode"],
|
|
215
|
-
current: SecurityRevision,
|
|
216
|
-
) => {
|
|
217
|
-
const asyncValue = mapping.subject.nextSecurityRevision?.(current);
|
|
218
|
-
|
|
219
|
-
const syncValue =
|
|
220
|
-
mapping.subject.nextSecurityRevisionSync === undefined
|
|
221
|
-
? undefined
|
|
222
|
-
: () => mapping.subject.nextSecurityRevisionSync!(current);
|
|
223
|
-
|
|
224
|
-
return allocate(
|
|
225
|
-
mode,
|
|
226
|
-
asyncValue ?? mapping.allocateRevision,
|
|
227
|
-
syncValue ?? mapping.allocateRevisionSync,
|
|
228
|
-
);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const sameIdentifier = (left: LoginIdentifier, right: LoginIdentifier) =>
|
|
232
|
-
left.namespace === right.namespace && left.value === right.value;
|
|
233
|
-
|
|
234
|
-
const evidenceSatisfiedAt = (
|
|
235
|
-
evidence: AuthenticationEvidence,
|
|
236
|
-
requirement: AuthenticationRequirement,
|
|
237
|
-
now: number,
|
|
238
|
-
): boolean => {
|
|
239
|
-
if (evidence.proofs.length > 64 || evidence.revision.credentials.length > 64) return false;
|
|
240
|
-
const revisions = new Map<string, string>();
|
|
241
|
-
|
|
242
|
-
for (const item of evidence.revision.credentials) {
|
|
243
|
-
if (revisions.has(item.credentialId)) return false;
|
|
244
|
-
revisions.set(item.credentialId, item.revision);
|
|
245
|
-
}
|
|
246
|
-
if (evidence.proofs.some((proof) => !revisions.has(proof.credentialId))) return false;
|
|
247
|
-
if (evidence.proofs.some((proof) => now < DateTime.toEpochMillis(proof.verifiedAt)))
|
|
248
|
-
return false;
|
|
249
|
-
|
|
250
|
-
const eligible = evidence.proofs.filter((proof) => {
|
|
251
|
-
const age = now - DateTime.toEpochMillis(proof.verifiedAt);
|
|
252
|
-
|
|
253
|
-
return age >= 0 && age < requirement.maximumAgeMillis;
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
const factors = new Set(eligible.flatMap((proof) => proof.factors));
|
|
257
|
-
const credentials = new Set(eligible.map((proof) => proof.credentialId));
|
|
258
|
-
|
|
259
|
-
return requirement.alternatives.some(
|
|
260
|
-
(alternative) =>
|
|
261
|
-
alternative.factors.every((factor) => factors.has(factor)) &&
|
|
262
|
-
credentials.size >= alternative.minimumCredentials &&
|
|
263
|
-
eligible.some(
|
|
264
|
-
(proof) =>
|
|
265
|
-
(!alternative.userVerified || proof.userVerified) &&
|
|
266
|
-
(!alternative.phishingResistant || proof.phishingResistant),
|
|
267
|
-
),
|
|
268
|
-
);
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const snapshotMutationInput = Effect.fn("DrizzlePassword.snapshotMutationInput")(function* (
|
|
272
|
-
input: PasswordMutationInput,
|
|
273
|
-
) {
|
|
274
|
-
const expectedRevision = snapshotPasswordRevision(input.expectedRevision);
|
|
275
|
-
|
|
276
|
-
const evidence = yield* snapshotAuthenticationEvidence(input.authorization.evidence).pipe(
|
|
277
|
-
Effect.mapError(unavailable),
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
const requirement = yield* snapshotPasswordRequirement(input.authorization.requirement);
|
|
281
|
-
|
|
282
|
-
const credential =
|
|
283
|
-
input.credential === undefined
|
|
284
|
-
? undefined
|
|
285
|
-
: yield* snapshotPasswordCredential(input.credential);
|
|
286
|
-
|
|
287
|
-
return Object.freeze({
|
|
288
|
-
...input,
|
|
289
|
-
expectedRevision,
|
|
290
|
-
replacement: Object.freeze({
|
|
291
|
-
verifier: Redacted.make(Redacted.value(input.replacement.verifier)),
|
|
292
|
-
normalization: input.replacement.normalization,
|
|
293
|
-
}),
|
|
294
|
-
invalidation: Object.freeze({ ...input.invalidation }),
|
|
295
|
-
...(credential === undefined ? {} : { credential }),
|
|
296
|
-
authorization: Object.freeze({
|
|
297
|
-
challenge: Object.freeze({
|
|
298
|
-
...input.authorization.challenge,
|
|
299
|
-
revision: snapshotPasswordRevision(input.authorization.challenge.revision),
|
|
300
|
-
}),
|
|
301
|
-
evidence,
|
|
302
|
-
requirement,
|
|
303
|
-
}),
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const lockSubject = Effect.fn("DrizzlePassword.lockSubject")(function* (
|
|
308
|
-
mapping: Mapping,
|
|
309
|
-
subjectId: string,
|
|
310
|
-
locking: boolean,
|
|
311
|
-
) {
|
|
312
|
-
const database = yield* CurrentPasswordSql;
|
|
313
|
-
|
|
314
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(subjectId as any);
|
|
315
|
-
const c = subjectColumns(mapping);
|
|
316
|
-
|
|
317
|
-
const rows = yield* selectRows(
|
|
318
|
-
database.select().from(mapping.subject.table).where(eq(c.id, nativeSubjectId)).limit(1),
|
|
319
|
-
locking,
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
return { nativeSubjectId, row: rows[0] };
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
const lockIdentifier = Effect.fn("Drizzle.lockIdentifier")(function* (
|
|
326
|
-
mapping: Mapping,
|
|
327
|
-
identifier: LoginIdentifier,
|
|
328
|
-
locking: boolean,
|
|
329
|
-
) {
|
|
330
|
-
const database = yield* CurrentPasswordSql;
|
|
331
|
-
|
|
332
|
-
const c = identifierColumns(mapping);
|
|
333
|
-
|
|
334
|
-
return yield* selectRows(
|
|
335
|
-
database
|
|
336
|
-
.select()
|
|
337
|
-
.from(mapping.identifier.table)
|
|
338
|
-
.where(and(eq(c.namespace, identifier.namespace), eq(c.value, identifier.value)))
|
|
339
|
-
.limit(1),
|
|
340
|
-
locking,
|
|
341
|
-
);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
const readPasswordCredential = Effect.fn("Drizzle.readPasswordCredential")(function* (
|
|
345
|
-
mapping: Mapping,
|
|
346
|
-
moduleId: string,
|
|
347
|
-
nativeSubjectId: unknown,
|
|
348
|
-
locking: boolean,
|
|
349
|
-
) {
|
|
350
|
-
const database = yield* CurrentPasswordSql;
|
|
351
|
-
|
|
352
|
-
const c = credentialColumns(mapping);
|
|
353
|
-
|
|
354
|
-
return yield* selectRows(
|
|
355
|
-
database
|
|
356
|
-
.select()
|
|
357
|
-
.from(mapping.credential.table)
|
|
358
|
-
.where(and(eq(c.moduleId, moduleId), eq(c.subjectId, nativeSubjectId)))
|
|
359
|
-
.limit(1),
|
|
360
|
-
locking,
|
|
361
|
-
);
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
const resolveCredential = Effect.fn("DrizzlePassword.resolveCredential")(function* (
|
|
365
|
-
mapping: Mapping,
|
|
366
|
-
moduleId: string,
|
|
367
|
-
identifier: LoginIdentifier,
|
|
368
|
-
requestedSubjectId: string | undefined,
|
|
369
|
-
locking: boolean,
|
|
370
|
-
) {
|
|
371
|
-
const database = yield* CurrentPasswordSql;
|
|
372
|
-
|
|
373
|
-
// The unlocked lookup only discovers the prospective subject. The canonical
|
|
374
|
-
// protected order starts with the subject and then rechecks the identifier.
|
|
375
|
-
const discovered = (yield* lockIdentifier(mapping, identifier, false))[0];
|
|
376
|
-
|
|
377
|
-
if (discovered === undefined || !mapping.identifier.isCurrent(discovered)) return undefined;
|
|
378
|
-
const discoveredNative = discovered[mapping.identifier.subjectId];
|
|
379
|
-
|
|
380
|
-
const subjectRows = yield* selectRows(
|
|
381
|
-
database
|
|
382
|
-
.select()
|
|
383
|
-
.from(mapping.subject.table)
|
|
384
|
-
.where(eq(subjectColumns(mapping).id, discoveredNative))
|
|
385
|
-
.limit(1),
|
|
386
|
-
locking,
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
const subject = subjectRows[0];
|
|
390
|
-
|
|
391
|
-
if (subject === undefined || !mapping.subject.isActiveStatus(subject[mapping.subject.status]))
|
|
392
|
-
return undefined;
|
|
393
|
-
const identifiers = yield* lockIdentifier(mapping, identifier, locking);
|
|
394
|
-
const identifierRow = identifiers[0];
|
|
395
|
-
|
|
396
|
-
if (
|
|
397
|
-
identifierRow === undefined ||
|
|
398
|
-
!mapping.identifier.isCurrent(identifierRow) ||
|
|
399
|
-
!mapping.subjectId.equals(discoveredNative, identifierRow[mapping.identifier.subjectId])
|
|
400
|
-
)
|
|
401
|
-
return undefined;
|
|
402
|
-
const subjectId = yield* mapping.subjectId.toSubject(discoveredNative);
|
|
403
|
-
|
|
404
|
-
if (requestedSubjectId !== undefined && requestedSubjectId !== subjectId) return undefined;
|
|
405
|
-
const credentials = yield* readPasswordCredential(mapping, moduleId, discoveredNative, locking);
|
|
406
|
-
const credential = credentials[0];
|
|
407
|
-
|
|
408
|
-
if (credential === undefined)
|
|
409
|
-
return { nativeSubjectId: discoveredNative, subject, identifier: identifierRow };
|
|
410
|
-
|
|
411
|
-
const snapshot = yield* mapping.credential
|
|
412
|
-
.decode({ moduleId, subject, identifier: identifierRow, credential })
|
|
413
|
-
.pipe(Effect.flatMap(snapshotPasswordCredential));
|
|
414
|
-
|
|
415
|
-
return {
|
|
416
|
-
nativeSubjectId: discoveredNative,
|
|
417
|
-
subject,
|
|
418
|
-
identifier: identifierRow,
|
|
419
|
-
credential,
|
|
420
|
-
snapshot,
|
|
421
|
-
};
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
const owned = <A, E, R>(
|
|
425
|
-
database: Database,
|
|
426
|
-
mapping: Mapping,
|
|
427
|
-
configuration: PasswordSqlConfiguration,
|
|
428
|
-
body: Effect.Effect<A, E, R>,
|
|
429
|
-
) => {
|
|
430
|
-
if (!validConstraints(mapping)) return Effect.fail(unavailable());
|
|
431
|
-
|
|
432
|
-
const run = coordinateCommit(
|
|
433
|
-
() =>
|
|
434
|
-
database.transaction((transaction) =>
|
|
435
|
-
body.pipe(
|
|
436
|
-
Effect.provideService(CurrentPasswordSql, transaction),
|
|
437
|
-
Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),
|
|
438
|
-
),
|
|
439
|
-
),
|
|
440
|
-
{ mode: configuration.mode },
|
|
441
|
-
).pipe(Effect.map((result) => result.value));
|
|
442
|
-
|
|
443
|
-
return configuration.coordinated !== true
|
|
444
|
-
? Effect.gen(function* () {
|
|
445
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
446
|
-
yield* configuration.standaloneGuard;
|
|
447
|
-
|
|
448
|
-
return yield* run;
|
|
449
|
-
})
|
|
450
|
-
: run;
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
// A coordinator that accepts postconditions re-runs this check against its
|
|
454
|
-
// current transaction after application work, before commit.
|
|
455
|
-
const registerFinal = Effect.fnUntraced(function* <E>(
|
|
456
|
-
check: Effect.Effect<boolean, E, CurrentPasswordSql>,
|
|
457
|
-
) {
|
|
458
|
-
const postconditions = yield* Effect.serviceOption(PasswordPreparedPostconditions);
|
|
459
|
-
|
|
460
|
-
if (Option.isNone(postconditions)) return;
|
|
461
|
-
|
|
462
|
-
const postcondition = Effect.gen(function* () {
|
|
463
|
-
const transaction = yield* CurrentPasswordPreparedTransaction;
|
|
464
|
-
|
|
465
|
-
if (!(yield* check.pipe(Effect.provideService(CurrentPasswordSql, transaction))))
|
|
466
|
-
return yield* unavailable();
|
|
467
|
-
}).pipe(translateFailure);
|
|
468
|
-
|
|
469
|
-
if (!postconditions.value.register(postcondition)) return yield* unavailable();
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
const safeRead = <A, E, R>(
|
|
473
|
-
database: Database,
|
|
474
|
-
configuration: PasswordSqlConfiguration,
|
|
475
|
-
body: Effect.Effect<A, E, R>,
|
|
476
|
-
) =>
|
|
477
|
-
Effect.gen(function* () {
|
|
478
|
-
if (configuration.coordinated !== true) {
|
|
479
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
480
|
-
yield* configuration.standaloneGuard;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
return yield* database.transaction((transaction) =>
|
|
484
|
-
body.pipe(
|
|
485
|
-
Effect.provideService(CurrentPasswordSql, transaction),
|
|
486
|
-
Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),
|
|
487
|
-
),
|
|
488
|
-
);
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
const proofCompletionMatchesPassword = (
|
|
492
|
-
input: PasswordMutationInput & { readonly completion: ProofCompletionPlan },
|
|
493
|
-
) => {
|
|
494
|
-
const completion = input.completion.input;
|
|
495
|
-
const binding = completion.binding;
|
|
496
|
-
|
|
497
|
-
if (
|
|
498
|
-
completion.moduleId !== `${input.moduleId}/reset` ||
|
|
499
|
-
completion.purpose !== "password-reset" ||
|
|
500
|
-
binding._tag !== "Subject" ||
|
|
501
|
-
input.credential === undefined ||
|
|
502
|
-
binding.revision.subjectId !== input.expectedRevision.subjectId ||
|
|
503
|
-
binding.revision.securityRevision !== input.expectedRevision.securityRevision ||
|
|
504
|
-
!sameIdentifier(binding.identifier, input.credential.identifier)
|
|
505
|
-
)
|
|
506
|
-
return false;
|
|
507
|
-
|
|
508
|
-
const expected = [...input.expectedRevision.credentials].sort((left, right) =>
|
|
509
|
-
left.credentialId.localeCompare(right.credentialId),
|
|
510
|
-
);
|
|
511
|
-
|
|
512
|
-
const actual = [...binding.revision.credentials].sort((left, right) =>
|
|
513
|
-
left.credentialId.localeCompare(right.credentialId),
|
|
514
|
-
);
|
|
515
|
-
|
|
516
|
-
return (
|
|
517
|
-
expected.length === actual.length &&
|
|
518
|
-
expected.every(
|
|
519
|
-
(item, index) =>
|
|
520
|
-
item.credentialId === actual[index]!.credentialId &&
|
|
521
|
-
item.revision === actual[index]!.revision,
|
|
522
|
-
)
|
|
523
|
-
);
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
const probeProofCompletion = Effect.fn("Drizzle.probeProofCompletion")(function* (
|
|
527
|
-
configuration: PasswordSqlConfiguration,
|
|
528
|
-
input: ProofCompletionInput,
|
|
529
|
-
) {
|
|
530
|
-
const database = yield* CurrentPasswordSql;
|
|
531
|
-
|
|
532
|
-
if (configuration.proof === undefined) return yield* Effect.fail(unavailable());
|
|
533
|
-
const validProbe = { _tag: "PasswordProofCompletionValid" } as const;
|
|
534
|
-
|
|
535
|
-
const plan: ProofCompletionPlan = {
|
|
536
|
-
input,
|
|
537
|
-
prepare: (decision, journal, project) => journal.prepare(project(decision)),
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
const probe = coordinateCommit(
|
|
541
|
-
() =>
|
|
542
|
-
database.transaction((transaction) =>
|
|
543
|
-
completeProofPlanIn(
|
|
544
|
-
configuration.proof!.mapping,
|
|
545
|
-
configuration.proof!.configuration,
|
|
546
|
-
plan,
|
|
547
|
-
Effect.fail(validProbe),
|
|
548
|
-
() => false,
|
|
549
|
-
).pipe(
|
|
550
|
-
Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),
|
|
551
|
-
),
|
|
552
|
-
),
|
|
553
|
-
{ mode: configuration.mode },
|
|
554
|
-
);
|
|
555
|
-
|
|
556
|
-
if (configuration.coordinated === true || (yield* hasCommitScope)) return yield* unavailable();
|
|
557
|
-
yield* configuration.standaloneGuard;
|
|
558
|
-
|
|
559
|
-
return yield* probe.pipe(
|
|
560
|
-
Effect.as(false),
|
|
561
|
-
Effect.catchCause((cause) => {
|
|
562
|
-
const reason = cause.reasons[0];
|
|
563
|
-
|
|
564
|
-
return cause.reasons.length === 1 &&
|
|
565
|
-
reason !== undefined &&
|
|
566
|
-
Cause.isFailReason(reason) &&
|
|
567
|
-
reason.error === validProbe
|
|
568
|
-
? Effect.succeed(true)
|
|
569
|
-
: Effect.failCause(cause);
|
|
570
|
-
}),
|
|
571
|
-
);
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
const validateMutationAuthority = Effect.fn("DrizzlePassword.validateMutationAuthority")(
|
|
575
|
-
function* (
|
|
576
|
-
mapping: Mapping,
|
|
577
|
-
configuration: PasswordSqlConfiguration,
|
|
578
|
-
input: PasswordMutationInput,
|
|
579
|
-
action: PasswordAction,
|
|
580
|
-
) {
|
|
581
|
-
const database = yield* CurrentPasswordSql;
|
|
582
|
-
|
|
583
|
-
const locked = yield* lockSubject(
|
|
584
|
-
mapping,
|
|
585
|
-
input.expectedRevision.subjectId,
|
|
586
|
-
configuration.locking,
|
|
587
|
-
);
|
|
588
|
-
|
|
589
|
-
const row = locked.row;
|
|
590
|
-
|
|
591
|
-
if (
|
|
592
|
-
row === undefined ||
|
|
593
|
-
!mapping.subject.isActiveStatus(row[mapping.subject.status]) ||
|
|
594
|
-
row[mapping.subject.securityRevision] !== input.expectedRevision.securityRevision
|
|
595
|
-
)
|
|
596
|
-
return undefined;
|
|
597
|
-
if (
|
|
598
|
-
input.authorization.challenge.moduleId !== input.moduleId ||
|
|
599
|
-
input.authorization.challenge.action !== action ||
|
|
600
|
-
input.authorization.challenge.commandId !== input.commandId ||
|
|
601
|
-
input.authorization.challenge.revision.subjectId !== input.expectedRevision.subjectId ||
|
|
602
|
-
input.authorization.challenge.revision.securityRevision !==
|
|
603
|
-
input.expectedRevision.securityRevision ||
|
|
604
|
-
(input.authorization.evidence.flowId as string) !== (input.commandId as string) ||
|
|
605
|
-
input.authorization.evidence.bindingDigest !==
|
|
606
|
-
input.authorization.challenge.bindingDigest ||
|
|
607
|
-
input.authorization.evidence.revision.subjectId !== input.expectedRevision.subjectId ||
|
|
608
|
-
input.authorization.evidence.revision.securityRevision !==
|
|
609
|
-
input.expectedRevision.securityRevision ||
|
|
610
|
-
(action === "add-password" &&
|
|
611
|
-
(input.credential !== undefined ||
|
|
612
|
-
input.authorization.challenge.targetCredentialId !== undefined))
|
|
613
|
-
)
|
|
614
|
-
return undefined;
|
|
615
|
-
if (
|
|
616
|
-
input.expectedRevision.credentials.some(
|
|
617
|
-
(expected) =>
|
|
618
|
-
!input.authorization.evidence.revision.credentials.some(
|
|
619
|
-
(actual) =>
|
|
620
|
-
actual.credentialId === expected.credentialId &&
|
|
621
|
-
actual.revision === expected.revision,
|
|
622
|
-
),
|
|
623
|
-
)
|
|
624
|
-
)
|
|
625
|
-
return undefined;
|
|
626
|
-
if (input.credential !== undefined) {
|
|
627
|
-
const identifier = (yield* lockIdentifier(
|
|
628
|
-
mapping,
|
|
629
|
-
input.credential.identifier,
|
|
630
|
-
configuration.locking,
|
|
631
|
-
))[0];
|
|
632
|
-
|
|
633
|
-
if (
|
|
634
|
-
identifier === undefined ||
|
|
635
|
-
!mapping.identifier.isCurrent(identifier) ||
|
|
636
|
-
!mapping.subjectId.equals(
|
|
637
|
-
identifier[mapping.identifier.subjectId],
|
|
638
|
-
locked.nativeSubjectId,
|
|
639
|
-
) ||
|
|
640
|
-
identifier[mapping.identifier.bindingRevision] !==
|
|
641
|
-
input.credential.identifierBindingRevision
|
|
642
|
-
)
|
|
643
|
-
return undefined;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
const allExpected = [
|
|
647
|
-
...input.expectedRevision.credentials,
|
|
648
|
-
...input.authorization.evidence.revision.credentials,
|
|
649
|
-
];
|
|
650
|
-
|
|
651
|
-
const expected = new Map(allExpected.map((item) => [item.credentialId, item]));
|
|
652
|
-
|
|
653
|
-
const ac = authorityCredentialColumns(mapping);
|
|
654
|
-
|
|
655
|
-
const credentialRows =
|
|
656
|
-
expected.size === 0
|
|
657
|
-
? []
|
|
658
|
-
: yield* selectRows(
|
|
659
|
-
database
|
|
660
|
-
.select()
|
|
661
|
-
.from(mapping.authorityCredential.table)
|
|
662
|
-
.where(
|
|
663
|
-
and(
|
|
664
|
-
eq(ac.subjectId, locked.nativeSubjectId),
|
|
665
|
-
inArray(ac.credentialId, [...expected.keys()]),
|
|
666
|
-
),
|
|
667
|
-
)
|
|
668
|
-
.orderBy(ac.credentialId),
|
|
669
|
-
configuration.locking,
|
|
670
|
-
);
|
|
671
|
-
|
|
672
|
-
if (credentialRows.length !== expected.size) return undefined;
|
|
673
|
-
// Database collation need not match JavaScript locale ordering.
|
|
674
|
-
for (const actual of credentialRows) {
|
|
675
|
-
const wanted = expected.get(actual[mapping.authorityCredential.credentialId]);
|
|
676
|
-
|
|
677
|
-
if (
|
|
678
|
-
wanted === undefined ||
|
|
679
|
-
actual[mapping.authorityCredential.revision] !== wanted.revision ||
|
|
680
|
-
(mapping.authorityCredential.status !== undefined &&
|
|
681
|
-
mapping.authorityCredential.isActiveStatus?.(
|
|
682
|
-
actual[mapping.authorityCredential.status],
|
|
683
|
-
) !== true)
|
|
684
|
-
)
|
|
685
|
-
return undefined;
|
|
686
|
-
expected.delete(wanted.credentialId);
|
|
687
|
-
}
|
|
688
|
-
if (expected.size !== 0) return undefined;
|
|
689
|
-
if (input.credential !== undefined) {
|
|
690
|
-
const identifier = (yield* lockIdentifier(mapping, input.credential.identifier, false))[0];
|
|
691
|
-
|
|
692
|
-
const credential = (yield* readPasswordCredential(
|
|
693
|
-
mapping,
|
|
694
|
-
input.moduleId,
|
|
695
|
-
locked.nativeSubjectId,
|
|
696
|
-
configuration.locking,
|
|
697
|
-
))[0];
|
|
698
|
-
|
|
699
|
-
if (identifier === undefined || credential === undefined) return undefined;
|
|
700
|
-
|
|
701
|
-
const snapshot = yield* mapping.credential.decode({
|
|
702
|
-
moduleId: input.moduleId,
|
|
703
|
-
subject: row,
|
|
704
|
-
identifier,
|
|
705
|
-
credential,
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
if (!sameCredentialSnapshot(snapshot, input.credential)) return undefined;
|
|
709
|
-
}
|
|
710
|
-
const currentRequirement = yield* mapping.subject.decodeActionRequirement(row, action);
|
|
711
|
-
const now = yield* nowMillis;
|
|
712
|
-
|
|
713
|
-
if (
|
|
714
|
-
!evidenceSatisfiedAt(input.authorization.evidence, input.authorization.requirement, now) ||
|
|
715
|
-
!evidenceSatisfiedAt(input.authorization.evidence, currentRequirement, now)
|
|
716
|
-
)
|
|
717
|
-
return undefined;
|
|
718
|
-
if (
|
|
719
|
-
input.invalidation.existingSessions === "immediate" &&
|
|
720
|
-
mapping.sessionInvalidation !== "same-authority-immediate"
|
|
721
|
-
)
|
|
722
|
-
return undefined;
|
|
723
|
-
|
|
724
|
-
return { ...locked, now };
|
|
725
|
-
},
|
|
726
|
-
);
|
|
727
|
-
|
|
728
|
-
const commandExists = Effect.fn("Drizzle.commandExists")(function* (
|
|
729
|
-
mapping: Mapping,
|
|
730
|
-
moduleId: string,
|
|
731
|
-
commandId: string,
|
|
732
|
-
locking: boolean,
|
|
733
|
-
) {
|
|
734
|
-
const database = yield* CurrentPasswordSql;
|
|
735
|
-
|
|
736
|
-
const c = commandColumns(mapping);
|
|
737
|
-
|
|
738
|
-
return yield* selectRows(
|
|
739
|
-
database
|
|
740
|
-
.select()
|
|
741
|
-
.from(mapping.command.table)
|
|
742
|
-
.where(and(eq(c.moduleId, moduleId), eq(c.commandId, commandId)))
|
|
743
|
-
.limit(1),
|
|
744
|
-
locking,
|
|
745
|
-
);
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
const insertCommand = Effect.fn("Drizzle.insertCommand")(function* (
|
|
749
|
-
mapping: Mapping,
|
|
750
|
-
input: PasswordMutationInput,
|
|
751
|
-
action: PasswordAction,
|
|
752
|
-
now: number,
|
|
753
|
-
) {
|
|
754
|
-
const database = yield* CurrentPasswordSql;
|
|
755
|
-
|
|
756
|
-
return yield* database.insert(mapping.command.table).values(
|
|
757
|
-
mapping.command.encodeInsert({
|
|
758
|
-
moduleId: input.moduleId,
|
|
759
|
-
commandId: input.commandId,
|
|
760
|
-
action,
|
|
761
|
-
bindingDigest: input.authorization.challenge.bindingDigest,
|
|
762
|
-
decision: "changed",
|
|
763
|
-
retentionUntilMillis: now + mapping.commandRetentionMillis,
|
|
764
|
-
}),
|
|
765
|
-
);
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
const mutationPostconditions = Effect.fn("DrizzlePassword.mutationPostconditions")(function* (
|
|
769
|
-
mapping: Mapping,
|
|
770
|
-
input: PasswordMutationInput,
|
|
771
|
-
nativeSubjectId: unknown,
|
|
772
|
-
subject: any,
|
|
773
|
-
authorityCredential: any,
|
|
774
|
-
now: number,
|
|
775
|
-
) {
|
|
776
|
-
if (
|
|
777
|
-
subject === undefined ||
|
|
778
|
-
!mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
|
|
779
|
-
authorityCredential === undefined ||
|
|
780
|
-
(mapping.authorityCredential.status !== undefined &&
|
|
781
|
-
mapping.authorityCredential.isActiveStatus?.(
|
|
782
|
-
authorityCredential[mapping.authorityCredential.status],
|
|
783
|
-
) !== true)
|
|
784
|
-
)
|
|
785
|
-
return false;
|
|
786
|
-
if (input.credential !== undefined) {
|
|
787
|
-
const identifier = (yield* lockIdentifier(mapping, input.credential.identifier, false))[0];
|
|
788
|
-
|
|
789
|
-
if (
|
|
790
|
-
identifier === undefined ||
|
|
791
|
-
!mapping.identifier.isCurrent(identifier) ||
|
|
792
|
-
!mapping.subjectId.equals(identifier[mapping.identifier.subjectId], nativeSubjectId) ||
|
|
793
|
-
identifier[mapping.identifier.bindingRevision] !==
|
|
794
|
-
input.credential.identifierBindingRevision
|
|
795
|
-
)
|
|
796
|
-
return false;
|
|
797
|
-
|
|
798
|
-
const credential = (yield* readPasswordCredential(
|
|
799
|
-
mapping,
|
|
800
|
-
input.moduleId,
|
|
801
|
-
nativeSubjectId,
|
|
802
|
-
false,
|
|
803
|
-
))[0];
|
|
804
|
-
|
|
805
|
-
if (credential === undefined) return false;
|
|
806
|
-
|
|
807
|
-
const decoded = yield* mapping.credential.decode({
|
|
808
|
-
moduleId: input.moduleId,
|
|
809
|
-
subject,
|
|
810
|
-
identifier,
|
|
811
|
-
credential,
|
|
812
|
-
});
|
|
813
|
-
|
|
814
|
-
if (decoded.identifierVerifiedAtMillis !== input.credential.identifierVerifiedAtMillis)
|
|
815
|
-
return false;
|
|
816
|
-
}
|
|
817
|
-
const rows = yield* commandExists(mapping, input.moduleId, input.commandId, false);
|
|
818
|
-
const row = rows[0];
|
|
819
|
-
|
|
820
|
-
return (
|
|
821
|
-
rows.length === 1 &&
|
|
822
|
-
row[mapping.command.action] === input.authorization.challenge.action &&
|
|
823
|
-
row[mapping.command.bindingDigest] === input.authorization.challenge.bindingDigest &&
|
|
824
|
-
row[mapping.command.decision] === "changed" &&
|
|
825
|
-
(yield* mapping.decodeInstant(row[mapping.command.retentionUntil])) ===
|
|
826
|
-
now + mapping.commandRetentionMillis
|
|
827
|
-
);
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
const addPasswordIn = Effect.fn("DrizzlePassword.addPasswordIn")(function* (
|
|
831
|
-
mapping: Mapping,
|
|
832
|
-
configuration: PasswordSqlConfiguration,
|
|
833
|
-
input: PasswordMutationInput,
|
|
834
|
-
revisions: {
|
|
835
|
-
readonly credentialId: string;
|
|
836
|
-
readonly credentialRevision: SecurityRevision;
|
|
837
|
-
readonly verifierVersion: SecurityRevision;
|
|
838
|
-
readonly nextSecurityRevision: SecurityRevision;
|
|
839
|
-
},
|
|
840
|
-
commandNow?: number,
|
|
841
|
-
) {
|
|
842
|
-
const database = yield* CurrentPasswordSql;
|
|
843
|
-
|
|
844
|
-
const { credentialId, credentialRevision, verifierVersion, nextSecurityRevision } = revisions;
|
|
845
|
-
|
|
846
|
-
const authority = yield* validateMutationAuthority(
|
|
847
|
-
mapping,
|
|
848
|
-
configuration,
|
|
849
|
-
input,
|
|
850
|
-
"add-password",
|
|
851
|
-
);
|
|
852
|
-
|
|
853
|
-
if (authority === undefined) return false;
|
|
854
|
-
if ((yield* commandExists(mapping, input.moduleId, input.commandId, true)).length) return false;
|
|
855
|
-
if (
|
|
856
|
-
(yield* readPasswordCredential(mapping, input.moduleId, authority.nativeSubjectId, true))
|
|
857
|
-
.length
|
|
858
|
-
)
|
|
859
|
-
return false;
|
|
860
|
-
|
|
861
|
-
yield* database.insert(mapping.credential.table).values(
|
|
862
|
-
mapping.credential.encodeInsert({
|
|
863
|
-
moduleId: input.moduleId,
|
|
864
|
-
subjectId: authority.nativeSubjectId,
|
|
865
|
-
credentialId,
|
|
866
|
-
credentialRevision,
|
|
867
|
-
verifierVersion,
|
|
868
|
-
replacement: input.replacement,
|
|
869
|
-
}),
|
|
870
|
-
);
|
|
871
|
-
yield* database.insert(mapping.authorityCredential.table).values(
|
|
872
|
-
mapping.authorityCredential.encodeInsert({
|
|
873
|
-
subjectId: authority.nativeSubjectId,
|
|
874
|
-
credentialId,
|
|
875
|
-
revision: credentialRevision,
|
|
876
|
-
}),
|
|
877
|
-
);
|
|
878
|
-
yield* database
|
|
879
|
-
.update(mapping.subject.table)
|
|
880
|
-
.set(updateValues([[mapping.subject.securityRevision, nextSecurityRevision]]))
|
|
881
|
-
.where(
|
|
882
|
-
and(
|
|
883
|
-
eq(subjectColumns(mapping).id, authority.nativeSubjectId),
|
|
884
|
-
eq(subjectColumns(mapping).securityRevision, input.expectedRevision.securityRevision),
|
|
885
|
-
),
|
|
886
|
-
);
|
|
887
|
-
yield* insertCommand(mapping, input, "add-password", commandNow ?? authority.now);
|
|
888
|
-
|
|
889
|
-
const applied = checkMutationApplied(
|
|
890
|
-
mapping,
|
|
891
|
-
input,
|
|
892
|
-
authority.nativeSubjectId,
|
|
893
|
-
revisions,
|
|
894
|
-
commandNow ?? authority.now,
|
|
895
|
-
);
|
|
896
|
-
|
|
897
|
-
if (!(yield* applied)) return yield* unavailable();
|
|
898
|
-
yield* registerFinal(applied);
|
|
899
|
-
|
|
900
|
-
return true;
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
const makeSqlPasswordPersistence = Effect.fn("makeSqlPasswordPersistence")(function* (
|
|
904
|
-
mapping: Mapping,
|
|
905
|
-
configuration: PasswordSqlConfiguration,
|
|
906
|
-
): Effect.fn.Return<
|
|
907
|
-
PasswordPersistence["Service"],
|
|
908
|
-
PasswordUnavailable,
|
|
909
|
-
LifecycleHooks | CurrentPasswordSql | NativeDatabase
|
|
910
|
-
> {
|
|
911
|
-
const database = yield* CurrentPasswordSql;
|
|
912
|
-
|
|
913
|
-
if (!configuration.coordinated)
|
|
914
|
-
yield* (
|
|
915
|
-
operations.validateStorage?.({
|
|
916
|
-
...mapping,
|
|
917
|
-
proof: configuration.proof?.mapping,
|
|
918
|
-
}) ?? Effect.void
|
|
919
|
-
).pipe(Effect.mapError(unavailable));
|
|
920
|
-
const hooks = yield* LifecycleHooks;
|
|
921
|
-
|
|
922
|
-
if (!validConstraints(mapping)) return yield* unavailable();
|
|
923
|
-
const root = yield* NativeDatabase;
|
|
924
|
-
|
|
925
|
-
const credentials = yield* makePasswordCredentials(
|
|
926
|
-
yield* sqlMapping(() => nativeTables(root.$client.withoutTransforms(), root)).pipe(
|
|
927
|
-
translateFailure,
|
|
928
|
-
),
|
|
929
|
-
mapping,
|
|
930
|
-
configuration,
|
|
931
|
-
);
|
|
932
|
-
|
|
933
|
-
return PasswordPersistence.of({
|
|
934
|
-
...credentials,
|
|
935
|
-
readForSubject: (input) =>
|
|
936
|
-
safeRead(
|
|
937
|
-
database,
|
|
938
|
-
configuration,
|
|
939
|
-
Effect.gen(function* () {
|
|
940
|
-
const transaction = yield* CurrentPasswordSql;
|
|
941
|
-
|
|
942
|
-
const locked = yield* lockSubject(mapping, input.subjectId, false);
|
|
943
|
-
|
|
944
|
-
if (
|
|
945
|
-
locked.row === undefined ||
|
|
946
|
-
!mapping.subject.isActiveStatus(locked.row[mapping.subject.status])
|
|
947
|
-
)
|
|
948
|
-
return Option.none();
|
|
949
|
-
|
|
950
|
-
const credential = (yield* readPasswordCredential(
|
|
951
|
-
mapping,
|
|
952
|
-
input.moduleId,
|
|
953
|
-
locked.nativeSubjectId,
|
|
954
|
-
false,
|
|
955
|
-
))[0];
|
|
956
|
-
|
|
957
|
-
if (credential === undefined) return Option.none();
|
|
958
|
-
const ic = identifierColumns(mapping);
|
|
959
|
-
|
|
960
|
-
const identifiers = yield* transaction
|
|
961
|
-
.select()
|
|
962
|
-
.from(mapping.identifier.table)
|
|
963
|
-
.where(eq(ic.subjectId, locked.nativeSubjectId));
|
|
964
|
-
|
|
965
|
-
const identifier = identifiers.find((row: any) => mapping.identifier.isCurrent(row));
|
|
966
|
-
|
|
967
|
-
if (identifier === undefined) return Option.none();
|
|
968
|
-
|
|
969
|
-
const snapshot = yield* mapping.credential
|
|
970
|
-
.decode({
|
|
971
|
-
moduleId: input.moduleId,
|
|
972
|
-
subject: locked.row,
|
|
973
|
-
identifier,
|
|
974
|
-
credential,
|
|
975
|
-
})
|
|
976
|
-
.pipe(Effect.flatMap(snapshotPasswordCredential));
|
|
977
|
-
|
|
978
|
-
return Option.some(snapshot);
|
|
979
|
-
}),
|
|
980
|
-
).pipe(
|
|
981
|
-
Effect.provideService(CurrentPasswordSql, database),
|
|
982
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
983
|
-
translateFailure,
|
|
984
|
-
),
|
|
985
|
-
recoveryTarget: (input) =>
|
|
986
|
-
safeRead(
|
|
987
|
-
database,
|
|
988
|
-
configuration,
|
|
989
|
-
Effect.gen(function* () {
|
|
990
|
-
const resolved = yield* resolveCredential(
|
|
991
|
-
mapping,
|
|
992
|
-
input.moduleId,
|
|
993
|
-
input.identifier,
|
|
994
|
-
undefined,
|
|
995
|
-
false,
|
|
996
|
-
);
|
|
997
|
-
|
|
998
|
-
return resolved?.snapshot === undefined ||
|
|
999
|
-
resolved.snapshot.identifierVerifiedAtMillis === undefined
|
|
1000
|
-
? Option.none()
|
|
1001
|
-
: Option.some(resolved.snapshot);
|
|
1002
|
-
}),
|
|
1003
|
-
).pipe(
|
|
1004
|
-
Effect.provideService(CurrentPasswordSql, database),
|
|
1005
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
1006
|
-
translateFailure,
|
|
1007
|
-
),
|
|
1008
|
-
addIfAbsent: (uncaptured, prepare) =>
|
|
1009
|
-
Effect.gen(function* () {
|
|
1010
|
-
const input = yield* snapshotMutationInput(uncaptured);
|
|
1011
|
-
|
|
1012
|
-
const credentialId = yield* allocate(
|
|
1013
|
-
configuration.mode,
|
|
1014
|
-
mapping.allocateCredentialId,
|
|
1015
|
-
mapping.allocateCredentialIdSync,
|
|
1016
|
-
);
|
|
1017
|
-
|
|
1018
|
-
const credentialRevision = yield* allocate(
|
|
1019
|
-
configuration.mode,
|
|
1020
|
-
mapping.allocateRevision,
|
|
1021
|
-
mapping.allocateRevisionSync,
|
|
1022
|
-
);
|
|
1023
|
-
|
|
1024
|
-
const verifierVersion = yield* allocate(
|
|
1025
|
-
configuration.mode,
|
|
1026
|
-
mapping.allocateRevision,
|
|
1027
|
-
mapping.allocateRevisionSync,
|
|
1028
|
-
);
|
|
1029
|
-
|
|
1030
|
-
const nextSecurityRevision = yield* allocateNextSecurityRevision(
|
|
1031
|
-
mapping,
|
|
1032
|
-
configuration.mode,
|
|
1033
|
-
input.expectedRevision.securityRevision,
|
|
1034
|
-
);
|
|
1035
|
-
|
|
1036
|
-
if (nextSecurityRevision === input.expectedRevision.securityRevision)
|
|
1037
|
-
return yield* unavailable();
|
|
1038
|
-
|
|
1039
|
-
return yield* owned(
|
|
1040
|
-
database,
|
|
1041
|
-
mapping,
|
|
1042
|
-
configuration,
|
|
1043
|
-
Effect.gen(function* () {
|
|
1044
|
-
const journal = yield* CurrentCommitJournal;
|
|
1045
|
-
|
|
1046
|
-
const changed = yield* addPasswordIn(mapping, configuration, input, {
|
|
1047
|
-
credentialId,
|
|
1048
|
-
credentialRevision,
|
|
1049
|
-
verifierVersion,
|
|
1050
|
-
nextSecurityRevision,
|
|
1051
|
-
});
|
|
1052
|
-
|
|
1053
|
-
return prepare(changed ? "changed" : "rejected", journal);
|
|
1054
|
-
}),
|
|
1055
|
-
);
|
|
1056
|
-
}).pipe(
|
|
1057
|
-
Effect.provideService(CurrentPasswordSql, database),
|
|
1058
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
1059
|
-
translateFailure,
|
|
1060
|
-
),
|
|
1061
|
-
replaceIfCurrent: (uncaptured, prepare) =>
|
|
1062
|
-
Effect.gen(function* () {
|
|
1063
|
-
const input = yield* snapshotMutationInput(uncaptured);
|
|
1064
|
-
|
|
1065
|
-
const credentialRevision = yield* allocate(
|
|
1066
|
-
configuration.mode,
|
|
1067
|
-
mapping.allocateRevision,
|
|
1068
|
-
mapping.allocateRevisionSync,
|
|
1069
|
-
);
|
|
1070
|
-
|
|
1071
|
-
const verifierVersion = yield* allocate(
|
|
1072
|
-
configuration.mode,
|
|
1073
|
-
mapping.allocateRevision,
|
|
1074
|
-
mapping.allocateRevisionSync,
|
|
1075
|
-
);
|
|
1076
|
-
|
|
1077
|
-
const nextSecurityRevision = yield* allocateNextSecurityRevision(
|
|
1078
|
-
mapping,
|
|
1079
|
-
configuration.mode,
|
|
1080
|
-
input.expectedRevision.securityRevision,
|
|
1081
|
-
);
|
|
1082
|
-
|
|
1083
|
-
if (
|
|
1084
|
-
nextSecurityRevision === input.expectedRevision.securityRevision ||
|
|
1085
|
-
(input.credential !== undefined &&
|
|
1086
|
-
credentialRevision === input.credential.credentialRevision)
|
|
1087
|
-
)
|
|
1088
|
-
return yield* unavailable();
|
|
1089
|
-
|
|
1090
|
-
return yield* owned(
|
|
1091
|
-
database,
|
|
1092
|
-
mapping,
|
|
1093
|
-
configuration,
|
|
1094
|
-
Effect.gen(function* () {
|
|
1095
|
-
return yield* replaceIn(
|
|
1096
|
-
mapping,
|
|
1097
|
-
configuration,
|
|
1098
|
-
input,
|
|
1099
|
-
"change-password",
|
|
1100
|
-
{ credentialRevision, verifierVersion, nextSecurityRevision },
|
|
1101
|
-
prepare,
|
|
1102
|
-
);
|
|
1103
|
-
}),
|
|
1104
|
-
);
|
|
1105
|
-
}).pipe(
|
|
1106
|
-
Effect.provideService(CurrentPasswordSql, database),
|
|
1107
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
1108
|
-
translateFailure,
|
|
1109
|
-
),
|
|
1110
|
-
checkReset: (input) =>
|
|
1111
|
-
(configuration.proof === undefined
|
|
1112
|
-
? Effect.fail(unavailable())
|
|
1113
|
-
: Effect.gen(function* () {
|
|
1114
|
-
if (
|
|
1115
|
-
input.moduleId.length <= "/reset".length ||
|
|
1116
|
-
!input.moduleId.endsWith("/reset") ||
|
|
1117
|
-
input.purpose !== "password-reset" ||
|
|
1118
|
-
input.binding._tag !== "Subject"
|
|
1119
|
-
)
|
|
1120
|
-
return false;
|
|
1121
|
-
const binding = input.binding;
|
|
1122
|
-
const passwordModuleId = input.moduleId.slice(0, -"/reset".length);
|
|
1123
|
-
|
|
1124
|
-
const current = yield* safeRead(
|
|
1125
|
-
database,
|
|
1126
|
-
configuration,
|
|
1127
|
-
Effect.gen(function* () {
|
|
1128
|
-
const resolved = yield* resolveCredential(
|
|
1129
|
-
mapping,
|
|
1130
|
-
passwordModuleId,
|
|
1131
|
-
binding.identifier,
|
|
1132
|
-
binding.revision.subjectId,
|
|
1133
|
-
false,
|
|
1134
|
-
);
|
|
1135
|
-
|
|
1136
|
-
return (
|
|
1137
|
-
resolved?.snapshot !== undefined &&
|
|
1138
|
-
resolved.snapshot.revision.securityRevision ===
|
|
1139
|
-
binding.revision.securityRevision &&
|
|
1140
|
-
binding.revision.credentials.every((item) =>
|
|
1141
|
-
resolved.snapshot!.revision.credentials.some(
|
|
1142
|
-
(actual) =>
|
|
1143
|
-
actual.credentialId === item.credentialId &&
|
|
1144
|
-
actual.revision === item.revision,
|
|
1145
|
-
),
|
|
1146
|
-
)
|
|
1147
|
-
);
|
|
1148
|
-
}),
|
|
1149
|
-
);
|
|
1150
|
-
|
|
1151
|
-
return current ? yield* probeProofCompletion(configuration, input) : false;
|
|
1152
|
-
})
|
|
1153
|
-
).pipe(
|
|
1154
|
-
Effect.provideService(CurrentPasswordSql, database),
|
|
1155
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
1156
|
-
translateFailure,
|
|
1157
|
-
),
|
|
1158
|
-
resetWithProof: (uncaptured, prepare) =>
|
|
1159
|
-
(configuration.proof === undefined
|
|
1160
|
-
? Effect.fail(unavailable())
|
|
1161
|
-
: Effect.gen(function* () {
|
|
1162
|
-
const input = Object.freeze({
|
|
1163
|
-
...(yield* snapshotMutationInput(uncaptured)),
|
|
1164
|
-
completion: uncaptured.completion,
|
|
1165
|
-
});
|
|
1166
|
-
|
|
1167
|
-
const credentialRevision = yield* allocate(
|
|
1168
|
-
configuration.mode,
|
|
1169
|
-
mapping.allocateRevision,
|
|
1170
|
-
mapping.allocateRevisionSync,
|
|
1171
|
-
);
|
|
1172
|
-
|
|
1173
|
-
const verifierVersion = yield* allocate(
|
|
1174
|
-
configuration.mode,
|
|
1175
|
-
mapping.allocateRevision,
|
|
1176
|
-
mapping.allocateRevisionSync,
|
|
1177
|
-
);
|
|
1178
|
-
|
|
1179
|
-
const nextSecurityRevision = yield* allocateNextSecurityRevision(
|
|
1180
|
-
mapping,
|
|
1181
|
-
configuration.mode,
|
|
1182
|
-
input.expectedRevision.securityRevision,
|
|
1183
|
-
);
|
|
1184
|
-
|
|
1185
|
-
if (
|
|
1186
|
-
nextSecurityRevision === input.expectedRevision.securityRevision ||
|
|
1187
|
-
(input.credential !== undefined &&
|
|
1188
|
-
credentialRevision === input.credential.credentialRevision)
|
|
1189
|
-
)
|
|
1190
|
-
return yield* unavailable();
|
|
1191
|
-
|
|
1192
|
-
return yield* owned(
|
|
1193
|
-
database,
|
|
1194
|
-
mapping,
|
|
1195
|
-
configuration,
|
|
1196
|
-
Effect.gen(function* () {
|
|
1197
|
-
const journal = yield* CurrentCommitJournal;
|
|
1198
|
-
|
|
1199
|
-
if (!proofCompletionMatchesPassword(input)) return prepare("rejected", journal);
|
|
1200
|
-
|
|
1201
|
-
const authority = yield* validateMutationAuthority(
|
|
1202
|
-
mapping,
|
|
1203
|
-
configuration,
|
|
1204
|
-
input,
|
|
1205
|
-
"reset-password",
|
|
1206
|
-
);
|
|
1207
|
-
|
|
1208
|
-
if (authority === undefined) return prepare("rejected", journal);
|
|
1209
|
-
if ((yield* commandExists(mapping, input.moduleId, input.commandId, true)).length)
|
|
1210
|
-
return prepare("rejected", journal);
|
|
1211
|
-
|
|
1212
|
-
const current = yield* currentExpectedCredential(
|
|
1213
|
-
mapping,
|
|
1214
|
-
input,
|
|
1215
|
-
authority.nativeSubjectId,
|
|
1216
|
-
);
|
|
1217
|
-
|
|
1218
|
-
if (!current) return prepare("rejected", journal);
|
|
1219
|
-
let passwordReceipt: PreparedCommit<any> | undefined;
|
|
1220
|
-
|
|
1221
|
-
yield* completeProofPlanIn(
|
|
1222
|
-
configuration.proof!.mapping,
|
|
1223
|
-
configuration.proof!.configuration,
|
|
1224
|
-
input.completion,
|
|
1225
|
-
Effect.gen(function* () {
|
|
1226
|
-
const revisions = {
|
|
1227
|
-
credentialRevision,
|
|
1228
|
-
verifierVersion,
|
|
1229
|
-
nextSecurityRevision,
|
|
1230
|
-
};
|
|
1231
|
-
|
|
1232
|
-
const applied = yield* writeReplacement(
|
|
1233
|
-
mapping,
|
|
1234
|
-
input,
|
|
1235
|
-
authority.nativeSubjectId,
|
|
1236
|
-
revisions,
|
|
1237
|
-
authority.now,
|
|
1238
|
-
);
|
|
1239
|
-
|
|
1240
|
-
if (applied)
|
|
1241
|
-
yield* registerReplacement(
|
|
1242
|
-
mapping,
|
|
1243
|
-
input,
|
|
1244
|
-
authority.nativeSubjectId,
|
|
1245
|
-
revisions,
|
|
1246
|
-
authority.now,
|
|
1247
|
-
);
|
|
1248
|
-
|
|
1249
|
-
return applied;
|
|
1250
|
-
}),
|
|
1251
|
-
(decision) => {
|
|
1252
|
-
passwordReceipt = prepare(
|
|
1253
|
-
decision === "completed" ? "changed" : "rejected",
|
|
1254
|
-
journal,
|
|
1255
|
-
);
|
|
1256
|
-
|
|
1257
|
-
return decision;
|
|
1258
|
-
},
|
|
1259
|
-
);
|
|
1260
|
-
|
|
1261
|
-
return passwordReceipt ?? prepare("rejected", journal);
|
|
1262
|
-
}),
|
|
1263
|
-
);
|
|
1264
|
-
})
|
|
1265
|
-
).pipe(
|
|
1266
|
-
Effect.provideService(CurrentPasswordSql, database),
|
|
1267
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
1268
|
-
translateFailure,
|
|
1269
|
-
),
|
|
1270
|
-
});
|
|
1271
|
-
});
|
|
1272
|
-
|
|
1273
|
-
const currentExpectedCredential = Effect.fn("DrizzlePassword.currentExpectedCredential")(
|
|
1274
|
-
function* (mapping: Mapping, input: PasswordMutationInput, nativeSubjectId: unknown) {
|
|
1275
|
-
if (input.credential === undefined) return false;
|
|
1276
|
-
|
|
1277
|
-
const row = (yield* readPasswordCredential(
|
|
1278
|
-
mapping,
|
|
1279
|
-
input.moduleId,
|
|
1280
|
-
nativeSubjectId,
|
|
1281
|
-
true,
|
|
1282
|
-
))[0];
|
|
1283
|
-
|
|
1284
|
-
if (row === undefined) return false;
|
|
1285
|
-
|
|
1286
|
-
return (
|
|
1287
|
-
row[mapping.credential.credentialId] === input.credential.credentialId &&
|
|
1288
|
-
row[mapping.credential.credentialRevision] === input.credential.credentialRevision &&
|
|
1289
|
-
row[mapping.credential.verifierVersion] === input.credential.verifierVersion &&
|
|
1290
|
-
row[mapping.credential.verifier] === Redacted.value(input.credential.verifier) &&
|
|
1291
|
-
row[mapping.credential.normalization] === input.credential.normalization &&
|
|
1292
|
-
input.authorization.challenge.targetCredentialId === input.credential.credentialId
|
|
1293
|
-
);
|
|
1294
|
-
},
|
|
1295
|
-
);
|
|
1296
|
-
|
|
1297
|
-
const checkMutationApplied = Effect.fn("DrizzlePassword.checkMutationApplied")(function* (
|
|
1298
|
-
mapping: Mapping,
|
|
1299
|
-
input: PasswordMutationInput,
|
|
1300
|
-
nativeSubjectId: unknown,
|
|
1301
|
-
revisions: {
|
|
1302
|
-
readonly credentialId: string;
|
|
1303
|
-
readonly credentialRevision: SecurityRevision;
|
|
1304
|
-
readonly verifierVersion: SecurityRevision;
|
|
1305
|
-
readonly nextSecurityRevision: SecurityRevision;
|
|
1306
|
-
},
|
|
1307
|
-
now: number,
|
|
1308
|
-
) {
|
|
1309
|
-
const database = yield* CurrentPasswordSql;
|
|
1310
|
-
|
|
1311
|
-
const c = credentialColumns(mapping),
|
|
1312
|
-
s = subjectColumns(mapping);
|
|
1313
|
-
|
|
1314
|
-
const credential = (yield* database
|
|
1315
|
-
.select()
|
|
1316
|
-
.from(mapping.credential.table)
|
|
1317
|
-
.where(
|
|
1318
|
-
and(
|
|
1319
|
-
eq(c.moduleId, input.moduleId),
|
|
1320
|
-
eq(c.subjectId, nativeSubjectId),
|
|
1321
|
-
eq(c.credentialId, revisions.credentialId),
|
|
1322
|
-
eq(c.credentialRevision, revisions.credentialRevision),
|
|
1323
|
-
eq(c.verifierVersion, revisions.verifierVersion),
|
|
1324
|
-
eq(c.verifier, Redacted.value(input.replacement.verifier)),
|
|
1325
|
-
eq(c.normalization, input.replacement.normalization),
|
|
1326
|
-
),
|
|
1327
|
-
)
|
|
1328
|
-
.limit(1))[0];
|
|
1329
|
-
|
|
1330
|
-
const subject = (yield* database
|
|
1331
|
-
.select()
|
|
1332
|
-
.from(mapping.subject.table)
|
|
1333
|
-
.where(and(eq(s.id, nativeSubjectId), eq(s.securityRevision, revisions.nextSecurityRevision)))
|
|
1334
|
-
.limit(1))[0];
|
|
1335
|
-
|
|
1336
|
-
const authorityCredential = (yield* database
|
|
1337
|
-
.select()
|
|
1338
|
-
.from(mapping.authorityCredential.table)
|
|
1339
|
-
.where(
|
|
1340
|
-
and(
|
|
1341
|
-
eq(authorityCredentialColumns(mapping).subjectId, nativeSubjectId),
|
|
1342
|
-
eq(authorityCredentialColumns(mapping).credentialId, revisions.credentialId),
|
|
1343
|
-
eq(authorityCredentialColumns(mapping).revision, revisions.credentialRevision),
|
|
1344
|
-
),
|
|
1345
|
-
)
|
|
1346
|
-
.limit(1))[0];
|
|
1347
|
-
|
|
1348
|
-
// SQL equality follows column collation; compare the persisted values exactly.
|
|
1349
|
-
return (
|
|
1350
|
-
credential !== undefined &&
|
|
1351
|
-
credential[mapping.credential.credentialId] === revisions.credentialId &&
|
|
1352
|
-
credential[mapping.credential.credentialRevision] === revisions.credentialRevision &&
|
|
1353
|
-
credential[mapping.credential.verifierVersion] === revisions.verifierVersion &&
|
|
1354
|
-
credential[mapping.credential.verifier] === Redacted.value(input.replacement.verifier) &&
|
|
1355
|
-
credential[mapping.credential.normalization] === input.replacement.normalization &&
|
|
1356
|
-
(yield* mutationPostconditions(
|
|
1357
|
-
mapping,
|
|
1358
|
-
input,
|
|
1359
|
-
nativeSubjectId,
|
|
1360
|
-
subject,
|
|
1361
|
-
authorityCredential,
|
|
1362
|
-
now,
|
|
1363
|
-
))
|
|
1364
|
-
);
|
|
1365
|
-
});
|
|
1366
|
-
|
|
1367
|
-
const writeReplacement = Effect.fn("DrizzlePassword.writeReplacement")(function* (
|
|
1368
|
-
mapping: Mapping,
|
|
1369
|
-
input: PasswordMutationInput,
|
|
1370
|
-
nativeSubjectId: unknown,
|
|
1371
|
-
revisions: {
|
|
1372
|
-
readonly credentialRevision: SecurityRevision;
|
|
1373
|
-
readonly verifierVersion: SecurityRevision;
|
|
1374
|
-
readonly nextSecurityRevision: SecurityRevision;
|
|
1375
|
-
},
|
|
1376
|
-
now: number,
|
|
1377
|
-
) {
|
|
1378
|
-
const database = yield* CurrentPasswordSql;
|
|
1379
|
-
|
|
1380
|
-
const c = credentialColumns(mapping);
|
|
1381
|
-
const s = subjectColumns(mapping);
|
|
1382
|
-
|
|
1383
|
-
yield* database
|
|
1384
|
-
.update(mapping.credential.table)
|
|
1385
|
-
.set(
|
|
1386
|
-
mapping.credential.encodeReplacement({
|
|
1387
|
-
replacement: input.replacement,
|
|
1388
|
-
credentialRevision: revisions.credentialRevision,
|
|
1389
|
-
verifierVersion: revisions.verifierVersion,
|
|
1390
|
-
}),
|
|
1391
|
-
)
|
|
1392
|
-
.where(
|
|
1393
|
-
and(
|
|
1394
|
-
eq(c.moduleId, input.moduleId),
|
|
1395
|
-
eq(c.subjectId, nativeSubjectId),
|
|
1396
|
-
eq(c.credentialId, input.credential!.credentialId),
|
|
1397
|
-
eq(c.credentialRevision, input.credential!.credentialRevision),
|
|
1398
|
-
eq(c.verifierVersion, input.credential!.verifierVersion),
|
|
1399
|
-
eq(c.verifier, Redacted.value(input.credential!.verifier)),
|
|
1400
|
-
eq(c.normalization, input.credential!.normalization),
|
|
1401
|
-
),
|
|
1402
|
-
);
|
|
1403
|
-
yield* database
|
|
1404
|
-
.update(mapping.subject.table)
|
|
1405
|
-
.set(updateValues([[mapping.subject.securityRevision, revisions.nextSecurityRevision]]))
|
|
1406
|
-
.where(
|
|
1407
|
-
and(
|
|
1408
|
-
eq(s.id, nativeSubjectId),
|
|
1409
|
-
eq(s.securityRevision, input.expectedRevision.securityRevision),
|
|
1410
|
-
),
|
|
1411
|
-
);
|
|
1412
|
-
yield* database
|
|
1413
|
-
.update(mapping.authorityCredential.table)
|
|
1414
|
-
.set(mapping.authorityCredential.encodeRevision(revisions.credentialRevision))
|
|
1415
|
-
.where(
|
|
1416
|
-
and(
|
|
1417
|
-
eq(authorityCredentialColumns(mapping).subjectId, nativeSubjectId),
|
|
1418
|
-
eq(authorityCredentialColumns(mapping).credentialId, input.credential!.credentialId),
|
|
1419
|
-
eq(authorityCredentialColumns(mapping).revision, input.credential!.credentialRevision),
|
|
1420
|
-
),
|
|
1421
|
-
);
|
|
1422
|
-
yield* insertCommand(mapping, input, input.authorization.challenge.action, now);
|
|
1423
|
-
|
|
1424
|
-
return yield* checkMutationApplied(
|
|
1425
|
-
mapping,
|
|
1426
|
-
input,
|
|
1427
|
-
nativeSubjectId,
|
|
1428
|
-
{
|
|
1429
|
-
...revisions,
|
|
1430
|
-
credentialId: input.credential!.credentialId,
|
|
1431
|
-
},
|
|
1432
|
-
now,
|
|
1433
|
-
);
|
|
1434
|
-
});
|
|
1435
|
-
|
|
1436
|
-
const registerReplacement = (
|
|
1437
|
-
mapping: Mapping,
|
|
1438
|
-
input: PasswordMutationInput,
|
|
1439
|
-
nativeSubjectId: unknown,
|
|
1440
|
-
revisions: {
|
|
1441
|
-
readonly credentialRevision: SecurityRevision;
|
|
1442
|
-
readonly verifierVersion: SecurityRevision;
|
|
1443
|
-
readonly nextSecurityRevision: SecurityRevision;
|
|
1444
|
-
},
|
|
1445
|
-
now: number,
|
|
1446
|
-
) =>
|
|
1447
|
-
registerFinal(
|
|
1448
|
-
checkMutationApplied(
|
|
1449
|
-
mapping,
|
|
1450
|
-
input,
|
|
1451
|
-
nativeSubjectId,
|
|
1452
|
-
{ ...revisions, credentialId: input.credential!.credentialId },
|
|
1453
|
-
now,
|
|
1454
|
-
),
|
|
1455
|
-
);
|
|
1456
|
-
|
|
1457
|
-
const replaceIn = Effect.fn("Drizzle.replaceIn")(function* <A>(
|
|
1458
|
-
mapping: Mapping,
|
|
1459
|
-
configuration: PasswordSqlConfiguration,
|
|
1460
|
-
input: PasswordMutationInput,
|
|
1461
|
-
action: PasswordAction,
|
|
1462
|
-
revisions: {
|
|
1463
|
-
readonly credentialRevision: SecurityRevision;
|
|
1464
|
-
readonly verifierVersion: SecurityRevision;
|
|
1465
|
-
readonly nextSecurityRevision: SecurityRevision;
|
|
1466
|
-
},
|
|
1467
|
-
prepare: (value: PasswordMutationDecision, journal: CommitJournal) => PreparedCommit<A>,
|
|
1468
|
-
) {
|
|
1469
|
-
const journal = yield* CurrentCommitJournal;
|
|
1470
|
-
|
|
1471
|
-
const authority = yield* validateMutationAuthority(mapping, configuration, input, action);
|
|
1472
|
-
|
|
1473
|
-
if (authority === undefined) return prepare("rejected", journal);
|
|
1474
|
-
if ((yield* commandExists(mapping, input.moduleId, input.commandId, true)).length)
|
|
1475
|
-
return prepare("rejected", journal);
|
|
1476
|
-
if (!(yield* currentExpectedCredential(mapping, input, authority.nativeSubjectId)))
|
|
1477
|
-
return prepare("rejected", journal);
|
|
1478
|
-
const prepared = prepare("changed", journal);
|
|
1479
|
-
|
|
1480
|
-
if (
|
|
1481
|
-
!(yield* writeReplacement(
|
|
1482
|
-
mapping,
|
|
1483
|
-
input,
|
|
1484
|
-
authority.nativeSubjectId,
|
|
1485
|
-
revisions,
|
|
1486
|
-
authority.now,
|
|
1487
|
-
))
|
|
1488
|
-
)
|
|
1489
|
-
return yield* unavailable();
|
|
1490
|
-
yield* registerReplacement(mapping, input, authority.nativeSubjectId, revisions, authority.now);
|
|
1491
|
-
|
|
1492
|
-
return prepared;
|
|
1493
|
-
});
|
|
1494
|
-
|
|
1495
|
-
/** Internal bound-owner primitives; deliberately not re-exported by driver modules. */
|
|
1496
|
-
const passwordSqlKernel = {
|
|
1497
|
-
allocate,
|
|
1498
|
-
allocateNextSecurityRevision,
|
|
1499
|
-
owned,
|
|
1500
|
-
safeRead,
|
|
1501
|
-
snapshotMutationInput,
|
|
1502
|
-
lockSubject,
|
|
1503
|
-
lockIdentifier,
|
|
1504
|
-
readPasswordCredential,
|
|
1505
|
-
resolveCredential,
|
|
1506
|
-
validateMutationAuthority,
|
|
1507
|
-
currentExpectedCredential,
|
|
1508
|
-
commandExists,
|
|
1509
|
-
addPasswordIn,
|
|
1510
|
-
checkMutationApplied,
|
|
1511
|
-
writeReplacement,
|
|
1512
|
-
evidenceSatisfiedAt,
|
|
1513
|
-
sameCredentialSnapshot,
|
|
1514
|
-
subjectColumns,
|
|
1515
|
-
identifierColumns,
|
|
1516
|
-
credentialColumns,
|
|
1517
|
-
authorityCredentialColumns,
|
|
1518
|
-
proofCompletionMatchesPassword,
|
|
1519
|
-
};
|
|
1520
|
-
|
|
1521
|
-
return { makeSqlPasswordPersistence, passwordSqlKernel };
|
|
1522
|
-
};
|