@sharadox/account-web-library 0.1.0-development.3 → 0.1.0-development.30
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 +267 -8
- package/distribution/account-activity/index.d.ts +16 -0
- package/distribution/account-activity/index.d.ts.map +1 -0
- package/distribution/account-activity/index.js +18 -0
- package/distribution/account-activity/index.js.map +1 -0
- package/distribution/account-activity/type.d.ts +15 -0
- package/distribution/account-activity/type.d.ts.map +1 -0
- package/distribution/account-activity/type.js.map +1 -0
- package/distribution/account-ban/index.d.ts +67 -0
- package/distribution/account-ban/index.d.ts.map +1 -0
- package/distribution/account-ban/index.js +233 -0
- package/distribution/account-ban/index.js.map +1 -0
- package/distribution/account-ban/type.d.ts +44 -0
- package/distribution/account-ban/type.d.ts.map +1 -0
- package/distribution/account-ban/type.js +2 -0
- package/distribution/account-ban/type.js.map +1 -0
- package/distribution/account-database/type.d.ts +264 -0
- package/distribution/account-database/type.d.ts.map +1 -0
- package/distribution/account-database/type.js +2 -0
- package/distribution/account-database/type.js.map +1 -0
- package/distribution/account-deletion/index.d.ts +21 -0
- package/distribution/account-deletion/index.d.ts.map +1 -0
- package/distribution/account-deletion/index.js +66 -0
- package/distribution/account-deletion/index.js.map +1 -0
- package/distribution/account-export/index.d.ts +17 -0
- package/distribution/account-export/index.d.ts.map +1 -0
- package/distribution/account-export/index.js +87 -0
- package/distribution/account-export/index.js.map +1 -0
- package/distribution/account-export/type.d.ts +40 -0
- package/distribution/account-export/type.d.ts.map +1 -0
- package/distribution/account-export/type.js +2 -0
- package/distribution/account-export/type.js.map +1 -0
- package/distribution/account-inactivity/index.d.ts +25 -0
- package/distribution/account-inactivity/index.d.ts.map +1 -0
- package/distribution/account-inactivity/index.js +100 -0
- package/distribution/account-inactivity/index.js.map +1 -0
- package/distribution/account-migration/index.d.ts +18 -0
- package/distribution/account-migration/index.d.ts.map +1 -0
- package/distribution/account-migration/index.js +376 -0
- package/distribution/account-migration/index.js.map +1 -0
- package/distribution/account-name/index.d.ts +13 -0
- package/distribution/account-name/index.d.ts.map +1 -0
- package/distribution/account-name/index.js +22 -0
- package/distribution/account-name/index.js.map +1 -0
- package/distribution/account-name/type.d.ts +9 -0
- package/distribution/account-name/type.d.ts.map +1 -0
- package/distribution/account-name/type.js +2 -0
- package/distribution/account-name/type.js.map +1 -0
- package/distribution/account-name-change/index.d.ts +15 -0
- package/distribution/account-name-change/index.d.ts.map +1 -0
- package/distribution/account-name-change/index.js +26 -0
- package/distribution/account-name-change/index.js.map +1 -0
- package/distribution/account-name-change/type.d.ts +7 -0
- package/distribution/account-name-change/type.d.ts.map +1 -0
- package/distribution/account-name-change/type.js +2 -0
- package/distribution/account-name-change/type.js.map +1 -0
- package/distribution/account-notice/index.d.ts +15 -0
- package/distribution/account-notice/index.d.ts.map +1 -0
- package/distribution/account-notice/index.js +41 -0
- package/distribution/account-notice/index.js.map +1 -0
- package/distribution/account-permission/index.d.ts +14 -0
- package/distribution/account-permission/index.d.ts.map +1 -0
- package/distribution/account-permission/index.js +91 -0
- package/distribution/account-permission/index.js.map +1 -0
- package/distribution/account-permission/type.d.ts +12 -0
- package/distribution/account-permission/type.d.ts.map +1 -0
- package/distribution/account-permission/type.js +2 -0
- package/distribution/account-permission/type.js.map +1 -0
- package/distribution/account-picture-change/index.d.ts +30 -0
- package/distribution/account-picture-change/index.d.ts.map +1 -0
- package/distribution/account-picture-change/index.js +70 -0
- package/distribution/account-picture-change/index.js.map +1 -0
- package/distribution/account-picture-change/type.d.ts +11 -0
- package/distribution/account-picture-change/type.d.ts.map +1 -0
- package/distribution/account-picture-change/type.js +2 -0
- package/distribution/account-picture-change/type.js.map +1 -0
- package/distribution/account-server/index.d.ts +25 -0
- package/distribution/account-server/index.d.ts.map +1 -0
- package/distribution/account-server/index.js +34 -0
- package/distribution/account-server/index.js.map +1 -0
- package/distribution/account-server/type.d.ts +30 -0
- package/distribution/account-server/type.d.ts.map +1 -0
- package/distribution/account-server/type.js +2 -0
- package/distribution/account-server/type.js.map +1 -0
- package/distribution/account-session-end/index.d.ts +15 -0
- package/distribution/account-session-end/index.d.ts.map +1 -0
- package/distribution/account-session-end/index.js +21 -0
- package/distribution/account-session-end/index.js.map +1 -0
- package/distribution/account-session-list/index.d.ts +16 -0
- package/distribution/account-session-list/index.d.ts.map +1 -0
- package/distribution/account-session-list/index.js +33 -0
- package/distribution/account-session-list/index.js.map +1 -0
- package/distribution/account-session-list/type.d.ts +13 -0
- package/distribution/account-session-list/type.d.ts.map +1 -0
- package/distribution/account-session-list/type.js +2 -0
- package/distribution/account-session-list/type.js.map +1 -0
- package/distribution/account-session-revocation/index.d.ts +14 -0
- package/distribution/account-session-revocation/index.d.ts.map +1 -0
- package/distribution/account-session-revocation/index.js +25 -0
- package/distribution/account-session-revocation/index.js.map +1 -0
- package/distribution/account-sign-in/index.d.ts +15 -0
- package/distribution/account-sign-in/index.d.ts.map +1 -0
- package/distribution/account-sign-in/index.js +78 -0
- package/distribution/account-sign-in/index.js.map +1 -0
- package/distribution/account-sign-in/type.d.ts +22 -0
- package/distribution/account-sign-in/type.d.ts.map +1 -0
- package/distribution/account-sign-in/type.js +2 -0
- package/distribution/account-sign-in/type.js.map +1 -0
- package/distribution/account-sign-out/index.d.ts +16 -0
- package/distribution/account-sign-out/index.d.ts.map +1 -0
- package/distribution/account-sign-out/index.js +34 -0
- package/distribution/account-sign-out/index.js.map +1 -0
- package/distribution/application-sync/index.d.ts +14 -0
- package/distribution/application-sync/index.d.ts.map +1 -0
- package/distribution/application-sync/index.js +96 -0
- package/distribution/application-sync/index.js.map +1 -0
- package/distribution/application-sync/type.d.ts +29 -0
- package/distribution/application-sync/type.d.ts.map +1 -0
- package/distribution/application-sync/type.js +2 -0
- package/distribution/application-sync/type.js.map +1 -0
- package/distribution/audit-event/index.d.ts +12 -0
- package/distribution/audit-event/index.d.ts.map +1 -0
- package/distribution/audit-event/index.js +36 -0
- package/distribution/audit-event/index.js.map +1 -0
- package/distribution/audit-event/type.d.ts +16 -0
- package/distribution/audit-event/type.d.ts.map +1 -0
- package/distribution/audit-event/type.js +2 -0
- package/distribution/audit-event/type.js.map +1 -0
- package/distribution/banned-contact/index.d.ts +34 -0
- package/distribution/banned-contact/index.d.ts.map +1 -0
- package/distribution/banned-contact/index.js +52 -0
- package/distribution/banned-contact/index.js.map +1 -0
- package/distribution/browser-session-read/index.d.ts +17 -0
- package/distribution/browser-session-read/index.d.ts.map +1 -0
- package/distribution/browser-session-read/index.js +52 -0
- package/distribution/browser-session-read/index.js.map +1 -0
- package/distribution/browser-session-read/type.d.ts +18 -0
- package/distribution/browser-session-read/type.d.ts.map +1 -0
- package/distribution/browser-session-read/type.js +2 -0
- package/distribution/browser-session-read/type.js.map +1 -0
- package/distribution/challenge-issue/index.d.ts +13 -0
- package/distribution/challenge-issue/index.d.ts.map +1 -0
- package/distribution/challenge-issue/index.js +18 -0
- package/distribution/challenge-issue/index.js.map +1 -0
- package/distribution/code-request/index.d.ts +16 -0
- package/distribution/code-request/index.d.ts.map +1 -0
- package/distribution/code-request/index.js +52 -0
- package/distribution/code-request/index.js.map +1 -0
- package/distribution/code-request/type.d.ts +25 -0
- package/distribution/code-request/type.d.ts.map +1 -0
- package/distribution/code-request/type.js +2 -0
- package/distribution/code-request/type.js.map +1 -0
- package/distribution/code-request-prune/index.d.ts +13 -0
- package/distribution/code-request-prune/index.d.ts.map +1 -0
- package/distribution/code-request-prune/index.js +12 -0
- package/distribution/code-request-prune/index.js.map +1 -0
- package/distribution/code-sending/index.d.ts +14 -0
- package/distribution/code-sending/index.d.ts.map +1 -0
- package/distribution/code-sending/index.js +65 -0
- package/distribution/code-sending/index.js.map +1 -0
- package/distribution/code-sending/type.d.ts +31 -0
- package/distribution/code-sending/type.d.ts.map +1 -0
- package/distribution/code-sending/type.js +2 -0
- package/distribution/code-sending/type.js.map +1 -0
- package/distribution/code-verification/index.d.ts +14 -0
- package/distribution/code-verification/index.d.ts.map +1 -0
- package/distribution/code-verification/index.js +43 -0
- package/distribution/code-verification/index.js.map +1 -0
- package/distribution/code-verification/type.d.ts +22 -0
- package/distribution/code-verification/type.d.ts.map +1 -0
- package/distribution/code-verification/type.js +2 -0
- package/distribution/code-verification/type.js.map +1 -0
- package/distribution/contact-addition/index.d.ts +13 -0
- package/distribution/contact-addition/index.d.ts.map +1 -0
- package/distribution/contact-addition/index.js +48 -0
- package/distribution/contact-addition/index.js.map +1 -0
- package/distribution/contact-addition/type.d.ts +15 -0
- package/distribution/contact-addition/type.d.ts.map +1 -0
- package/distribution/contact-addition/type.js +2 -0
- package/distribution/contact-addition/type.js.map +1 -0
- package/distribution/contact-addition-flow/index.d.ts +32 -0
- package/distribution/contact-addition-flow/index.d.ts.map +1 -0
- package/distribution/contact-addition-flow/index.js +96 -0
- package/distribution/contact-addition-flow/index.js.map +1 -0
- package/distribution/contact-addition-flow/type.d.ts +25 -0
- package/distribution/contact-addition-flow/type.d.ts.map +1 -0
- package/distribution/contact-addition-flow/type.js +2 -0
- package/distribution/contact-addition-flow/type.js.map +1 -0
- package/distribution/contact-channel/type.d.ts +44 -0
- package/distribution/contact-channel/type.d.ts.map +1 -0
- package/distribution/contact-channel/type.js +2 -0
- package/distribution/contact-channel/type.js.map +1 -0
- package/distribution/contact-kind/index.d.ts +12 -0
- package/distribution/contact-kind/index.d.ts.map +1 -0
- package/distribution/contact-kind/index.js +18 -0
- package/distribution/contact-kind/index.js.map +1 -0
- package/distribution/contact-kind/type.d.ts +6 -0
- package/distribution/contact-kind/type.d.ts.map +1 -0
- package/distribution/contact-kind/type.js +2 -0
- package/distribution/contact-kind/type.js.map +1 -0
- package/distribution/contact-lookup/index.d.ts +16 -0
- package/distribution/contact-lookup/index.d.ts.map +1 -0
- package/distribution/contact-lookup/index.js +20 -0
- package/distribution/contact-lookup/index.js.map +1 -0
- package/distribution/contact-removal/index.d.ts +19 -0
- package/distribution/contact-removal/index.d.ts.map +1 -0
- package/distribution/contact-removal/index.js +35 -0
- package/distribution/contact-removal/index.js.map +1 -0
- package/distribution/contact-verification/index.d.ts +20 -0
- package/distribution/contact-verification/index.d.ts.map +1 -0
- package/distribution/contact-verification/index.js +37 -0
- package/distribution/contact-verification/index.js.map +1 -0
- package/distribution/database-error/index.d.ts +12 -0
- package/distribution/database-error/index.d.ts.map +1 -0
- package/distribution/database-error/index.js +14 -0
- package/distribution/database-error/index.js.map +1 -0
- package/distribution/email-channel/index.d.ts +13 -0
- package/distribution/email-channel/index.d.ts.map +1 -0
- package/distribution/email-channel/index.js +168 -0
- package/distribution/email-channel/index.js.map +1 -0
- package/distribution/email-channel/type.d.ts +17 -0
- package/distribution/email-channel/type.d.ts.map +1 -0
- package/distribution/email-channel/type.js +2 -0
- package/distribution/email-channel/type.js.map +1 -0
- package/distribution/identifier/index.d.ts +23 -0
- package/distribution/identifier/index.d.ts.map +1 -0
- package/distribution/identifier/index.js +32 -0
- package/distribution/identifier/index.js.map +1 -0
- package/distribution/identifier/type.d.ts +10 -0
- package/distribution/identifier/type.d.ts.map +1 -0
- package/distribution/identifier/type.js +2 -0
- package/distribution/identifier/type.js.map +1 -0
- package/distribution/identifier-availability/index.d.ts +11 -0
- package/distribution/identifier-availability/index.d.ts.map +1 -0
- package/distribution/identifier-availability/index.js +21 -0
- package/distribution/identifier-availability/index.js.map +1 -0
- package/distribution/identifier-change/index.d.ts +15 -0
- package/distribution/identifier-change/index.d.ts.map +1 -0
- package/distribution/identifier-change/index.js +43 -0
- package/distribution/identifier-change/index.js.map +1 -0
- package/distribution/identifier-change/type.d.ts +7 -0
- package/distribution/identifier-change/type.d.ts.map +1 -0
- package/distribution/identifier-change/type.js +2 -0
- package/distribution/identifier-change/type.js.map +1 -0
- package/distribution/memory-picture-storage/index.d.ts +15 -0
- package/distribution/memory-picture-storage/index.d.ts.map +1 -0
- package/distribution/memory-picture-storage/index.js +16 -0
- package/distribution/memory-picture-storage/index.js.map +1 -0
- package/distribution/one-time-code/index.d.ts +2 -2
- package/distribution/one-time-code/index.js +3 -3
- package/distribution/person-account/index.d.ts +18 -0
- package/distribution/person-account/index.d.ts.map +1 -0
- package/distribution/person-account/index.js +65 -0
- package/distribution/person-account/index.js.map +1 -0
- package/distribution/person-account/type.d.ts +22 -0
- package/distribution/person-account/type.d.ts.map +1 -0
- package/distribution/person-account/type.js +2 -0
- package/distribution/person-account/type.js.map +1 -0
- package/distribution/picture-key/index.d.ts +8 -0
- package/distribution/picture-key/index.d.ts.map +1 -0
- package/distribution/picture-key/index.js +10 -0
- package/distribution/picture-key/index.js.map +1 -0
- package/distribution/picture-preparation/index.d.ts +18 -0
- package/distribution/picture-preparation/index.d.ts.map +1 -0
- package/distribution/picture-preparation/index.js +86 -0
- package/distribution/picture-preparation/index.js.map +1 -0
- package/distribution/picture-preparation/type.d.ts +18 -0
- package/distribution/picture-preparation/type.d.ts.map +1 -0
- package/distribution/picture-preparation/type.js +2 -0
- package/distribution/picture-preparation/type.js.map +1 -0
- package/distribution/picture-storage/type.d.ts +11 -0
- package/distribution/picture-storage/type.d.ts.map +1 -0
- package/distribution/picture-storage/type.js +2 -0
- package/distribution/picture-storage/type.js.map +1 -0
- package/distribution/recovery-code-regeneration/index.d.ts +19 -0
- package/distribution/recovery-code-regeneration/index.d.ts.map +1 -0
- package/distribution/recovery-code-regeneration/index.js +34 -0
- package/distribution/recovery-code-regeneration/index.js.map +1 -0
- package/distribution/recovery-code-store/index.d.ts +25 -0
- package/distribution/recovery-code-store/index.d.ts.map +1 -0
- package/distribution/recovery-code-store/index.js +34 -0
- package/distribution/recovery-code-store/index.js.map +1 -0
- package/distribution/role-grant/index.d.ts +38 -0
- package/distribution/role-grant/index.d.ts.map +1 -0
- package/distribution/role-grant/index.js +142 -0
- package/distribution/role-grant/index.js.map +1 -0
- package/distribution/role-grant/type.d.ts +40 -0
- package/distribution/role-grant/type.d.ts.map +1 -0
- package/distribution/role-grant/type.js +2 -0
- package/distribution/role-grant/type.js.map +1 -0
- package/distribution/rule-sync/index.d.ts +28 -0
- package/distribution/rule-sync/index.d.ts.map +1 -0
- package/distribution/rule-sync/index.js +80 -0
- package/distribution/rule-sync/index.js.map +1 -0
- package/distribution/rule-sync/type.d.ts +17 -0
- package/distribution/rule-sync/type.d.ts.map +1 -0
- package/distribution/rule-sync/type.js +2 -0
- package/distribution/rule-sync/type.js.map +1 -0
- package/distribution/second-factor-finish/index.d.ts +13 -0
- package/distribution/second-factor-finish/index.d.ts.map +1 -0
- package/distribution/second-factor-finish/index.js +83 -0
- package/distribution/second-factor-finish/index.js.map +1 -0
- package/distribution/second-factor-finish/type.d.ts +30 -0
- package/distribution/second-factor-finish/type.d.ts.map +1 -0
- package/distribution/second-factor-finish/type.js +2 -0
- package/distribution/second-factor-finish/type.js.map +1 -0
- package/distribution/secret-derivation/index.d.ts +10 -0
- package/distribution/secret-derivation/index.d.ts.map +1 -0
- package/distribution/secret-derivation/index.js +15 -0
- package/distribution/secret-derivation/index.js.map +1 -0
- package/distribution/secret-encryption/index.d.ts +17 -0
- package/distribution/secret-encryption/index.d.ts.map +1 -0
- package/distribution/secret-encryption/index.js +37 -0
- package/distribution/secret-encryption/index.js.map +1 -0
- package/distribution/session-prune/index.d.ts +17 -0
- package/distribution/session-prune/index.d.ts.map +1 -0
- package/distribution/session-prune/index.js +30 -0
- package/distribution/session-prune/index.js.map +1 -0
- package/distribution/session-token/index.d.ts +19 -0
- package/distribution/session-token/index.d.ts.map +1 -0
- package/distribution/session-token/index.js +22 -0
- package/distribution/session-token/index.js.map +1 -0
- package/distribution/sign-in-finish/index.d.ts +12 -0
- package/distribution/sign-in-finish/index.d.ts.map +1 -0
- package/distribution/sign-in-finish/index.js +64 -0
- package/distribution/sign-in-finish/index.js.map +1 -0
- package/distribution/sign-in-finish/type.d.ts +41 -0
- package/distribution/sign-in-finish/type.d.ts.map +1 -0
- package/distribution/sign-in-finish/type.js +2 -0
- package/distribution/sign-in-finish/type.js.map +1 -0
- package/distribution/sign-in-start/index.d.ts +17 -0
- package/distribution/sign-in-start/index.d.ts.map +1 -0
- package/distribution/sign-in-start/index.js +45 -0
- package/distribution/sign-in-start/index.js.map +1 -0
- package/distribution/sign-in-start/type.d.ts +34 -0
- package/distribution/sign-in-start/type.d.ts.map +1 -0
- package/distribution/sign-in-start/type.js +2 -0
- package/distribution/sign-in-start/type.js.map +1 -0
- package/distribution/sign-up-finish/index.d.ts +13 -0
- package/distribution/sign-up-finish/index.d.ts.map +1 -0
- package/distribution/sign-up-finish/index.js +38 -0
- package/distribution/sign-up-finish/index.js.map +1 -0
- package/distribution/sign-up-finish/type.d.ts +28 -0
- package/distribution/sign-up-finish/type.d.ts.map +1 -0
- package/distribution/sign-up-finish/type.js +2 -0
- package/distribution/sign-up-finish/type.js.map +1 -0
- package/distribution/signed-ticket/index.d.ts +19 -0
- package/distribution/signed-ticket/index.d.ts.map +1 -0
- package/distribution/signed-ticket/index.js +35 -0
- package/distribution/signed-ticket/index.js.map +1 -0
- package/distribution/signed-ticket/type.d.ts +16 -0
- package/distribution/signed-ticket/type.d.ts.map +1 -0
- package/distribution/signed-ticket/type.js +2 -0
- package/distribution/signed-ticket/type.js.map +1 -0
- package/distribution/step-up/index.d.ts +48 -0
- package/distribution/step-up/index.d.ts.map +1 -0
- package/distribution/step-up/index.js +83 -0
- package/distribution/step-up/index.js.map +1 -0
- package/distribution/step-up/type.d.ts +15 -0
- package/distribution/step-up/type.d.ts.map +1 -0
- package/distribution/step-up/type.js +2 -0
- package/distribution/{username → step-up}/type.js.map +1 -1
- package/distribution/test-database/index.d.ts +13 -0
- package/distribution/test-database/index.d.ts.map +1 -0
- package/distribution/test-database/index.js +17 -0
- package/distribution/test-database/index.js.map +1 -0
- package/distribution/test-person/index.d.ts +14 -0
- package/distribution/test-person/index.d.ts.map +1 -0
- package/distribution/test-person/index.js +20 -0
- package/distribution/test-person/index.js.map +1 -0
- package/distribution/test-server/index.d.ts +10 -0
- package/distribution/test-server/index.d.ts.map +1 -0
- package/distribution/test-server/index.js +16 -0
- package/distribution/test-server/index.js.map +1 -0
- package/distribution/totp/type.d.ts +1 -1
- package/distribution/totp/type.d.ts.map +1 -1
- package/distribution/totp-setup/index.d.ts +50 -0
- package/distribution/totp-setup/index.d.ts.map +1 -0
- package/distribution/totp-setup/index.js +136 -0
- package/distribution/totp-setup/index.js.map +1 -0
- package/distribution/totp-setup/type.d.ts +24 -0
- package/distribution/totp-setup/type.d.ts.map +1 -0
- package/distribution/totp-setup/type.js +2 -0
- package/distribution/totp-setup/type.js.map +1 -0
- package/package.json +9 -2
- package/distribution/username/index.d.ts +0 -23
- package/distribution/username/index.d.ts.map +0 -1
- package/distribution/username/index.js +0 -32
- package/distribution/username/index.js.map +0 -1
- package/distribution/username/type.d.ts +0 -10
- package/distribution/username/type.d.ts.map +0 -1
- /package/distribution/{username → account-activity}/type.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/rule-sync/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAUnG;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,eAAe,EAAE,CAAA;CAAE,GAC/E,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC,CA8B7D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GACvC,OAAO,CAAC,aAAa,EAAE,CAAC,CA2B1B"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
|
|
2
|
+
const same = (first, second) => JSON.stringify(first) === JSON.stringify(second);
|
|
3
|
+
/** The application's id; null for global rules; undefined when it doesn't exist. */
|
|
4
|
+
async function applicationId(database, key) {
|
|
5
|
+
if (key === null)
|
|
6
|
+
return null;
|
|
7
|
+
return (await database.selectFrom("application").select("id").where("key", "=", key).executeTakeFirst())?.id;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Publishes an application's rules (or global ones, `application: null`). A rule whose words or penalties changed gets
|
|
11
|
+
* a new version, and earlier bans keep citing the version they broke. Returns the codes given a new version.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* await syncRules(database, { application: "platform", rules: [{ code: "spam", title, description, schedule }] });
|
|
15
|
+
*/
|
|
16
|
+
export async function syncRules(database, { application, rules }) {
|
|
17
|
+
const id = await applicationId(database, application);
|
|
18
|
+
if (id === undefined)
|
|
19
|
+
return { versioned: [], unknownApplication: true };
|
|
20
|
+
const versioned = [];
|
|
21
|
+
for (const rule of rules) {
|
|
22
|
+
let latest = database.selectFrom("rule").selectAll().where("code", "=", rule.code);
|
|
23
|
+
latest = id === null ? latest.where("application_id", "is", null) : latest.where("application_id", "=", id);
|
|
24
|
+
const current = await latest.orderBy("version", "desc").executeTakeFirst();
|
|
25
|
+
if (current &&
|
|
26
|
+
same(current.title, rule.title) &&
|
|
27
|
+
same(current.description, rule.description) &&
|
|
28
|
+
same(current.schedule, rule.schedule))
|
|
29
|
+
continue;
|
|
30
|
+
await database
|
|
31
|
+
.insertInto("rule")
|
|
32
|
+
.values({
|
|
33
|
+
id: uuidVersion7(),
|
|
34
|
+
application_id: id,
|
|
35
|
+
code: rule.code,
|
|
36
|
+
version: (current?.version ?? 0) + 1,
|
|
37
|
+
title: JSON.stringify(rule.title),
|
|
38
|
+
description: JSON.stringify(rule.description),
|
|
39
|
+
schedule: JSON.stringify(rule.schedule),
|
|
40
|
+
})
|
|
41
|
+
.execute();
|
|
42
|
+
versioned.push(rule.code);
|
|
43
|
+
}
|
|
44
|
+
return { versioned };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The rules in force for an application, newest versions, global ones first then its own, by code: what the public
|
|
48
|
+
* rules page and `GET /api/rules` show.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const rules = await listRules(database, { application: "platform" });
|
|
52
|
+
*/
|
|
53
|
+
export async function listRules(database, { application }) {
|
|
54
|
+
const id = await applicationId(database, application);
|
|
55
|
+
const rows = await database
|
|
56
|
+
.selectFrom("rule")
|
|
57
|
+
.selectAll()
|
|
58
|
+
.where((where) => id
|
|
59
|
+
? where.or([where("application_id", "is", null), where("application_id", "=", id)])
|
|
60
|
+
: where("application_id", "is", null))
|
|
61
|
+
.orderBy("version", "desc")
|
|
62
|
+
.execute();
|
|
63
|
+
const newest = new Map();
|
|
64
|
+
for (const row of rows) {
|
|
65
|
+
const key = `${row.application_id === null ? "0" : "1"}:${row.code}`;
|
|
66
|
+
if (!newest.has(key))
|
|
67
|
+
newest.set(key, row);
|
|
68
|
+
}
|
|
69
|
+
return [...newest.entries()]
|
|
70
|
+
.sort(([first], [second]) => first.localeCompare(second))
|
|
71
|
+
.map(([, row]) => ({
|
|
72
|
+
code: row.code,
|
|
73
|
+
version: row.version,
|
|
74
|
+
title: row.title,
|
|
75
|
+
description: row.description,
|
|
76
|
+
schedule: row.schedule,
|
|
77
|
+
global: row.application_id === null,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/rule-sync/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAI/E,MA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
/** A public rule as an application declares it. */
|
|
3
|
+
export interface RuleDeclaration {
|
|
4
|
+
code: string;
|
|
5
|
+
/** In each language: `{ en, pt }`. */
|
|
6
|
+
title: Record<string, string>;
|
|
7
|
+
description: Record<string, string>;
|
|
8
|
+
/** Penalties for the 1st, 2nd… offense: seconds, or "permanent"; the last repeats. */
|
|
9
|
+
schedule: PenaltySchedule;
|
|
10
|
+
}
|
|
11
|
+
/** A rule's newest version, as `/rules` shows it. */
|
|
12
|
+
export interface PublishedRule extends RuleDeclaration {
|
|
13
|
+
version: number;
|
|
14
|
+
/** For every application. */
|
|
15
|
+
global: boolean;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/rule-sync/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAErF,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,sFAAsF;IACtF,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,MAAM,EAAE,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/rule-sync/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
2
|
+
import type { SecondFactorFinish, SecondFactorFinishResult } from "@sharadox/account-web-library/second-factor-finish/type";
|
|
3
|
+
/**
|
|
4
|
+
* The two-factor step of signing in: the authenticator app's code (never the same step twice) or a single-use
|
|
5
|
+
* recovery code, after the emailed code passed (`finishSignIn` gave the ticket). Guesses are limited per account and
|
|
6
|
+
* per address group. The session is marked as having passed two-factor. After a recovery code, call `notify` after
|
|
7
|
+
* answering, to tell every contact.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = await finishSecondFactor(server, { ticket, code, address, token: cookie });
|
|
11
|
+
*/
|
|
12
|
+
export declare function finishSecondFactor(server: AccountServer, { ticket, code, address, token, userAgent, now }: SecondFactorFinish): Promise<SecondFactorFinishResult>;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/second-factor-finish/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAOvF,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,yDAAyD,CAAC;AAIjE;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,aAAa,EACrB,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAgB,EAAE,GAAgB,EAAE,EAAE,kBAAkB,GACvF,OAAO,CAAC,wBAAwB,CAAC,CA+DnC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { addressGroup } from "@sharadox/protection-web-library/address-group";
|
|
2
|
+
import { limitRate } from "@sharadox/protection-web-library/rate-limit";
|
|
3
|
+
import { accountTables, signInLimits } from "@sharadox/account-web-library/account-server";
|
|
4
|
+
import { signIn } from "@sharadox/account-web-library/account-sign-in";
|
|
5
|
+
import { notifyAccount } from "@sharadox/account-web-library/account-notice";
|
|
6
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
7
|
+
import { recoveryCodeHash } from "@sharadox/account-web-library/recovery-code-store";
|
|
8
|
+
import { decryptSecret } from "@sharadox/account-web-library/secret-encryption";
|
|
9
|
+
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
10
|
+
import { readTicket } from "@sharadox/account-web-library/signed-ticket";
|
|
11
|
+
import { verifyTotp } from "@sharadox/account-web-library/totp";
|
|
12
|
+
/**
|
|
13
|
+
* The two-factor step of signing in: the authenticator app's code (never the same step twice) or a single-use
|
|
14
|
+
* recovery code, after the emailed code passed (`finishSignIn` gave the ticket). Guesses are limited per account and
|
|
15
|
+
* per address group. The session is marked as having passed two-factor. After a recovery code, call `notify` after
|
|
16
|
+
* answering, to tell every contact.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const result = await finishSecondFactor(server, { ticket, code, address, token: cookie });
|
|
20
|
+
*/
|
|
21
|
+
export async function finishSecondFactor(server, { ticket, code, address, token, userAgent = null, now = Date.now() }) {
|
|
22
|
+
const reading = readTicket(ticket, {
|
|
23
|
+
secret: deriveSecret(server.secret, "second-factor-ticket"),
|
|
24
|
+
purpose: "second-factor",
|
|
25
|
+
now,
|
|
26
|
+
});
|
|
27
|
+
if (!reading.valid)
|
|
28
|
+
return { status: "refused", reason: "ticket" };
|
|
29
|
+
const { accountId } = reading.data;
|
|
30
|
+
const limits = signInLimits(server);
|
|
31
|
+
const rate = await limitRate(server.database, [
|
|
32
|
+
{ key: `second-factor:${accountId}`, rule: limits.secondFactorPerAccount },
|
|
33
|
+
{ key: `verification:${addressGroup(address)}`, rule: limits.verificationsPerAddress },
|
|
34
|
+
], { secret: deriveSecret(server.secret, "rate-limit"), now });
|
|
35
|
+
if (!rate.allowed)
|
|
36
|
+
return { status: "refused", reason: "rate-limit", retryAfterSeconds: rate.retryAfterSeconds };
|
|
37
|
+
const passed = await accountTables(server)
|
|
38
|
+
.transaction()
|
|
39
|
+
.execute(async (transaction) => {
|
|
40
|
+
const credential = await transaction
|
|
41
|
+
.selectFrom("totp_credential")
|
|
42
|
+
.select(["id", "secret_ciphertext", "last_used_step"])
|
|
43
|
+
.where("account_id", "=", accountId)
|
|
44
|
+
.where("confirmed_at", "is not", null)
|
|
45
|
+
.forUpdate()
|
|
46
|
+
.executeTakeFirst();
|
|
47
|
+
// Two-factor was turned off since the emailed code passed: that code is the proof.
|
|
48
|
+
if (!credential)
|
|
49
|
+
return "passed";
|
|
50
|
+
const typed = code.replace(/\s/g, "");
|
|
51
|
+
const secret = decryptSecret(credential.secret_ciphertext, deriveSecret(server.secret, "totp-encryption"));
|
|
52
|
+
// Confirming the setup stored a step, so a confirmed credential always has one.
|
|
53
|
+
const lastUsedStep = Number(credential.last_used_step);
|
|
54
|
+
const verification = verifyTotp(secret, typed, now, { lastUsedStep });
|
|
55
|
+
if (verification.valid) {
|
|
56
|
+
await transaction
|
|
57
|
+
.updateTable("totp_credential")
|
|
58
|
+
.set({ last_used_step: verification.step })
|
|
59
|
+
.where("id", "=", credential.id)
|
|
60
|
+
.execute();
|
|
61
|
+
return "passed";
|
|
62
|
+
}
|
|
63
|
+
const used = await transaction
|
|
64
|
+
.updateTable("recovery_code")
|
|
65
|
+
.set({ used_at: new Date(now) })
|
|
66
|
+
.where("account_id", "=", accountId)
|
|
67
|
+
.where("code_hash", "=", recoveryCodeHash(code, { accountId, pepper: deriveSecret(server.secret, "recovery-code") }))
|
|
68
|
+
.where("used_at", "is", null)
|
|
69
|
+
.executeTakeFirst();
|
|
70
|
+
if (used.numUpdatedRows === 0n)
|
|
71
|
+
return "wrong";
|
|
72
|
+
await recordAuditEvent(transaction, { accountId, action: "second-factor.recovery-code-used", now });
|
|
73
|
+
return "recovery";
|
|
74
|
+
});
|
|
75
|
+
if (passed === "wrong")
|
|
76
|
+
return { status: "refused", reason: "wrong" };
|
|
77
|
+
const session = await signIn(server.database, { accountId, token, secondFactor: true, userAgent, now });
|
|
78
|
+
if (passed === "passed")
|
|
79
|
+
return { status: "signed-in", accountId, token: session.token };
|
|
80
|
+
const notify = () => notifyAccount(server, { accountId, notice: { kind: "recovery-code-used" } });
|
|
81
|
+
return { status: "signed-in", accountId, token: session.token, notify };
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/second-factor-finish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE3F,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAK/E,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAqB,EACrB,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAsB;IAExF,MAAM,OAAO,GAAG,UAAU,CAAwB,MAAM,EAAE;QACxD,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC;QAC3D,OAAO,EAAE,eAAe;QACxB,GAAG;KACJ,CAAC,CAAC;IACH,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,OAAO,EAAE,M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;QACpG,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;IACL,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IACtE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IACxG,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IACzF,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,EAAE,CAAC,CAAC;IAClG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface SecondFactorFinish {
|
|
2
|
+
/** From `finishSignIn`'s `second-factor` answer. */
|
|
3
|
+
ticket: string;
|
|
4
|
+
/** The authenticator app's code, or a recovery code. */
|
|
5
|
+
code: string;
|
|
6
|
+
/** The client's IP address. */
|
|
7
|
+
address: string;
|
|
8
|
+
/** The browser's current session cookie, if any. */
|
|
9
|
+
token: string | undefined;
|
|
10
|
+
/** The browser's User-Agent, for the list of devices. */
|
|
11
|
+
userAgent?: string | null;
|
|
12
|
+
/** Milliseconds since 1970 (now by default). */
|
|
13
|
+
now?: number;
|
|
14
|
+
}
|
|
15
|
+
export type SecondFactorFinishResult =
|
|
16
|
+
/** `notify`, after a recovery code: tells every contact (call it after answering). */
|
|
17
|
+
{
|
|
18
|
+
status: "signed-in";
|
|
19
|
+
accountId: string;
|
|
20
|
+
token: string;
|
|
21
|
+
notify?: () => Promise<void>;
|
|
22
|
+
} | {
|
|
23
|
+
status: "refused";
|
|
24
|
+
reason: "ticket" | "wrong";
|
|
25
|
+
} | {
|
|
26
|
+
status: "refused";
|
|
27
|
+
reason: "rate-limit";
|
|
28
|
+
retryAfterSeconds: number;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/second-factor-finish/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,wBAAwB;AAClC,sFAAsF;AACpF;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GACvF;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAA;CAAE,GACjD;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/second-factor-finish/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A separate 256-bit key for one purpose (`one-time-code`, `rate-limit`, `proof-of-work`, `sign-up-ticket`…),
|
|
3
|
+
* derived from the account server's one root secret with HKDF-SHA-256: one secret to keep, and a key leaked from one
|
|
4
|
+
* use reveals nothing about the others.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const pepper = deriveSecret(process.env.ACCOUNT_SECRET!, "one-time-code");
|
|
8
|
+
*/
|
|
9
|
+
export declare function deriveSecret(root: string, purpose: string): string;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/secret-derivation/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGlE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { hkdfSync } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* A separate 256-bit key for one purpose (`one-time-code`, `rate-limit`, `proof-of-work`, `sign-up-ticket`…),
|
|
4
|
+
* derived from the account server's one root secret with HKDF-SHA-256: one secret to keep, and a key leaked from one
|
|
5
|
+
* use reveals nothing about the others.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const pepper = deriveSecret(process.env.ACCOUNT_SECRET!, "one-time-code");
|
|
9
|
+
*/
|
|
10
|
+
export function deriveSecret(root, purpose) {
|
|
11
|
+
if (root.length < 32)
|
|
12
|
+
throw new Error("the account secret must have at least 32 characters");
|
|
13
|
+
return Buffer.from(hkdfSync("sha256", root, "", `sharadox-account:${purpose}`, 32)).toString("base64url");
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/secret-derivation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,OAAe;IACxD,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAC7F,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,oBAAoB,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC5G,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts a secret for storing in the database (a TOTP secret) with AES-256-GCM under a key kept outside it
|
|
3
|
+
* (`deriveSecret(ACCOUNT_SECRET, "totp-encryption")`), so a leaked database dump reveals nothing. A fresh random IV
|
|
4
|
+
* every time; the result is text: `v1.<iv>.<ciphertext and tag>`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const sealed = encryptSecret(secret, deriveSecret(server.secret, "totp-encryption"));
|
|
8
|
+
*/
|
|
9
|
+
export declare function encryptSecret(secret: Uint8Array, key: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Decrypts what `encryptSecret` made; throws for a wrong key or anything changed.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const secret = decryptSecret(row.secret_ciphertext, key);
|
|
15
|
+
*/
|
|
16
|
+
export declare function decryptSecret(sealed: string, key: string): Uint8Array;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/secret-encryption/index.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAOrE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
|
|
2
|
+
const VERSION = "v1";
|
|
3
|
+
const keyBytes = (key) => {
|
|
4
|
+
if (key.length < 32)
|
|
5
|
+
throw new Error("the encryption key must have at least 32 characters");
|
|
6
|
+
return createHash("sha256").update(key).digest();
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Encrypts a secret for storing in the database (a TOTP secret) with AES-256-GCM under a key kept outside it
|
|
10
|
+
* (`deriveSecret(ACCOUNT_SECRET, "totp-encryption")`), so a leaked database dump reveals nothing. A fresh random IV
|
|
11
|
+
* every time; the result is text: `v1.<iv>.<ciphertext and tag>`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const sealed = encryptSecret(secret, deriveSecret(server.secret, "totp-encryption"));
|
|
15
|
+
*/
|
|
16
|
+
export function encryptSecret(secret, key) {
|
|
17
|
+
const iv = randomBytes(12);
|
|
18
|
+
const cipher = createCipheriv("aes-256-gcm", keyBytes(key), iv);
|
|
19
|
+
const body = Buffer.concat([cipher.update(secret), cipher.final(), cipher.getAuthTag()]);
|
|
20
|
+
return `${VERSION}.${iv.toString("base64url")}.${body.toString("base64url")}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Decrypts what `encryptSecret` made; throws for a wrong key or anything changed.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const secret = decryptSecret(row.secret_ciphertext, key);
|
|
27
|
+
*/
|
|
28
|
+
export function decryptSecret(sealed, key) {
|
|
29
|
+
const [version, iv, body] = sealed.split(".");
|
|
30
|
+
if (version !== VERSION || !iv || !body)
|
|
31
|
+
throw new Error("unknown encrypted secret format");
|
|
32
|
+
const bytes = Buffer.from(body, "base64url");
|
|
33
|
+
const decipher = createDecipheriv("aes-256-gcm", keyBytes(key), Buffer.from(iv, "base64url"));
|
|
34
|
+
decipher.setAuthTag(bytes.subarray(-16));
|
|
35
|
+
return new Uint8Array(Buffer.concat([decipher.update(bytes.subarray(0, -16)), decipher.final()]));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/secret-encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAExF,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,EAAE;IAC/B,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAC5F,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;AACnD,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,MAAkB,EAAE,GAAW;IAC3D,MAAM,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC3B,MAAM,MAAM,GAAG,cAAc,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACzF,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;AAChF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,GAAW;IACvD,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,OAAO,KAAK,OAAO,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC5F,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC;IAC9F,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
/**
|
|
4
|
+
* Deletes account sessions past their end or idle longer than `idleSeconds` (7 days by default, as
|
|
5
|
+
* `readBrowserSession`), then browser sessions that ended or hold no account; from a daily job. Returns the counts.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* await pruneSessions(database);
|
|
9
|
+
*/
|
|
10
|
+
export declare function pruneSessions(database: Kysely<AccountDatabase>, { idleSeconds, now }?: {
|
|
11
|
+
idleSeconds?: number;
|
|
12
|
+
now?: number;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
accountSessions: number;
|
|
15
|
+
browserSessions: number;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/session-prune/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,WAAwB,EAAE,GAAgB,EAAE,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC1F,OAAO,CAAC;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC,CA4B/D"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
/**
|
|
3
|
+
* Deletes account sessions past their end or idle longer than `idleSeconds` (7 days by default, as
|
|
4
|
+
* `readBrowserSession`), then browser sessions that ended or hold no account; from a daily job. Returns the counts.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* await pruneSessions(database);
|
|
8
|
+
*/
|
|
9
|
+
export async function pruneSessions(database, { idleSeconds = 7 * 86_400, now = Date.now() } = {}) {
|
|
10
|
+
const at = new Date(now);
|
|
11
|
+
const accountSessions = await database
|
|
12
|
+
.deleteFrom("account_session")
|
|
13
|
+
.where((where) => where.or([where("expires_at", "<=", at), where("last_seen_at", "<=", new Date(now - idleSeconds * 1000))]))
|
|
14
|
+
.executeTakeFirst();
|
|
15
|
+
const browserSessions = await database
|
|
16
|
+
.deleteFrom("browser_session")
|
|
17
|
+
.where((where) => where.or([
|
|
18
|
+
where("expires_at", "<=", at),
|
|
19
|
+
where.not(where.exists(where
|
|
20
|
+
.selectFrom("account_session")
|
|
21
|
+
.select(sql `1`.as("one"))
|
|
22
|
+
.whereRef("account_session.browser_session_id", "=", "browser_session.id"))),
|
|
23
|
+
]))
|
|
24
|
+
.executeTakeFirst();
|
|
25
|
+
return {
|
|
26
|
+
accountSessions: Number(accountSessions.numDeletedRows),
|
|
27
|
+
browserSessions: Number(browserSessions.numDeletedRows),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/session-prune/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAC;AAG1C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAiC,EACjC,EAAE,WAAW,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,KAA6C,EAAE;IAE3F,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,eAAe,GAAG,MAAM,QAAQ;SACnC,UAAU,CAAC,iBAAiB,CAAC;SAC7B,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACf,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,GAAG,GAAG,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAC3G;SACA,gBAAgB,EAAE,CAAC;IACtB,MAAM,eAAe,GAAG,MAAM,QAAQ;SACnC,UAAU,CAAC,iBAAiB,CAAC;SAC7B,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACf,KAAK,CAAC,EAAE,CAAC;QACP,KAAK,CAAC,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;QAC7B,KAAK,CAAC,GAAG,CACP,KAAK,CAAC,MAAM,CACV,KAAK;aACF,UAAU,CAAC,iBAAiB,CAAC;aAC7B,MAAM,CAAC,GAAG,CAAA,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;aACxB,QAAQ,CAAC,oCAAoC,EAAE,GAAG,EAAE,oBAAoB,CAAC,CAC7E,CACF;KACF,CAAC,CACH;SACA,gBAAgB,EAAE,CAAC;IACtB,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,eAAe,CAAC,cAAc,CAAC;QACvD,eAAe,EAAE,MAAM,CAAC,eAAe,CAAC,cAAc,CAAC;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A new session token (256 random bits, base64url) for a cookie, and the hash to store instead: a leaked table gives
|
|
3
|
+
* no sessions. A plain SHA-256 is enough for tokens this random.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const { token, hash } = createSessionToken();
|
|
7
|
+
*/
|
|
8
|
+
export declare function createSessionToken(): {
|
|
9
|
+
token: string;
|
|
10
|
+
hash: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The stored form of a session token.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* hashSessionToken(cookie); // compare with browser_session.token_hash
|
|
17
|
+
*/
|
|
18
|
+
export declare function hashSessionToken(token: string): string;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/session-token/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAGpE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* A new session token (256 random bits, base64url) for a cookie, and the hash to store instead: a leaked table gives
|
|
4
|
+
* no sessions. A plain SHA-256 is enough for tokens this random.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const { token, hash } = createSessionToken();
|
|
8
|
+
*/
|
|
9
|
+
export function createSessionToken() {
|
|
10
|
+
const token = randomBytes(32).toString("base64url");
|
|
11
|
+
return { token, hash: hashSessionToken(token) };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The stored form of a session token.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* hashSessionToken(cookie); // compare with browser_session.token_hash
|
|
18
|
+
*/
|
|
19
|
+
export function hashSessionToken(token) {
|
|
20
|
+
return createHash("sha256").update(token).digest("base64url");
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/session-token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACpD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
2
|
+
import type { SignInFinish, SignInFinishResult } from "@sharadox/account-web-library/sign-in-finish/type";
|
|
3
|
+
/**
|
|
4
|
+
* The second step: the typed code. Guesses are limited per address group (and per request by `verifyCode`). With the
|
|
5
|
+
* right code, an account with that contact is signed in (or, with two-factor on, gets a ticket for that step) on the browser (the new token goes in its cookie); a contact
|
|
6
|
+
* with no account gets a sign-up ticket for choosing an identifier.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const result = await finishSignIn(server, { requestId, code, address, token: cookie });
|
|
10
|
+
*/
|
|
11
|
+
export declare function finishSignIn(server: AccountServer, { requestId, code, address, token, userAgent, now }: SignInFinish): Promise<SignInFinishResult>;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/sign-in-finish/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAKvF,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAO1G;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAgB,EAAE,GAAgB,EAAE,EAAE,YAAY,GACpF,OAAO,CAAC,kBAAkB,CAAC,CAiD7B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { addressGroup } from "@sharadox/protection-web-library/address-group";
|
|
2
|
+
import { limitRate } from "@sharadox/protection-web-library/rate-limit";
|
|
3
|
+
import { signIn } from "@sharadox/account-web-library/account-sign-in";
|
|
4
|
+
import { signInLimits } from "@sharadox/account-web-library/account-server";
|
|
5
|
+
import { verifyCode } from "@sharadox/account-web-library/code-verification";
|
|
6
|
+
import { findAccountByContact } from "@sharadox/account-web-library/contact-lookup";
|
|
7
|
+
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
8
|
+
import { createTicket } from "@sharadox/account-web-library/signed-ticket";
|
|
9
|
+
/** How long a sign-up ticket lasts: time to choose an identifier. */
|
|
10
|
+
const SIGN_UP_SECONDS = 900;
|
|
11
|
+
/** How long the two-factor step may take once the emailed code passed. */
|
|
12
|
+
const SECOND_FACTOR_SECONDS = 600;
|
|
13
|
+
/**
|
|
14
|
+
* The second step: the typed code. Guesses are limited per address group (and per request by `verifyCode`). With the
|
|
15
|
+
* right code, an account with that contact is signed in (or, with two-factor on, gets a ticket for that step) on the browser (the new token goes in its cookie); a contact
|
|
16
|
+
* with no account gets a sign-up ticket for choosing an identifier.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const result = await finishSignIn(server, { requestId, code, address, token: cookie });
|
|
20
|
+
*/
|
|
21
|
+
export async function finishSignIn(server, { requestId, code, address, token, userAgent = null, now = Date.now() }) {
|
|
22
|
+
const rate = await limitRate(server.database, [{ key: `verification:${addressGroup(address)}`, rule: signInLimits(server).verificationsPerAddress }], { secret: deriveSecret(server.secret, "rate-limit"), now });
|
|
23
|
+
if (!rate.allowed)
|
|
24
|
+
return { status: "refused", reason: "rate-limit", retryAfterSeconds: rate.retryAfterSeconds };
|
|
25
|
+
const verification = await verifyCode(server.database, {
|
|
26
|
+
requestId,
|
|
27
|
+
code,
|
|
28
|
+
purpose: "sign-in",
|
|
29
|
+
pepper: deriveSecret(server.secret, "one-time-code"),
|
|
30
|
+
now,
|
|
31
|
+
});
|
|
32
|
+
if (!verification.valid)
|
|
33
|
+
return { status: "refused", reason: verification.reason };
|
|
34
|
+
const found = await findAccountByContact(server.database, verification.contact);
|
|
35
|
+
if (!found) {
|
|
36
|
+
const ticket = createTicket({ contact: verification.contact }, {
|
|
37
|
+
secret: deriveSecret(server.secret, "sign-up-ticket"),
|
|
38
|
+
purpose: "sign-up",
|
|
39
|
+
lifetimeSeconds: SIGN_UP_SECONDS,
|
|
40
|
+
now,
|
|
41
|
+
});
|
|
42
|
+
return { status: "sign-up", ticket };
|
|
43
|
+
}
|
|
44
|
+
if (!found.signIn)
|
|
45
|
+
return { status: "refused", reason: "unknown" };
|
|
46
|
+
const secondFactor = await server.database
|
|
47
|
+
.selectFrom("totp_credential")
|
|
48
|
+
.select("id")
|
|
49
|
+
.where("account_id", "=", found.accountId)
|
|
50
|
+
.where("confirmed_at", "is not", null)
|
|
51
|
+
.executeTakeFirst();
|
|
52
|
+
if (secondFactor) {
|
|
53
|
+
const ticket = createTicket({ accountId: found.accountId }, {
|
|
54
|
+
secret: deriveSecret(server.secret, "second-factor-ticket"),
|
|
55
|
+
purpose: "second-factor",
|
|
56
|
+
lifetimeSeconds: SECOND_FACTOR_SECONDS,
|
|
57
|
+
now,
|
|
58
|
+
});
|
|
59
|
+
return { status: "second-factor", ticket };
|
|
60
|
+
}
|
|
61
|
+
const session = await signIn(server.database, { accountId: found.accountId, token, userAgent, now });
|
|
62
|
+
return { status: "signed-in", accountId: found.accountId, token: session.token };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/sign-in-finish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,6CAA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KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CodeVerificationResult } from "@sharadox/account-web-library/code-verification/type";
|
|
2
|
+
export interface SignInFinish {
|
|
3
|
+
requestId: string;
|
|
4
|
+
/** As typed. */
|
|
5
|
+
code: string;
|
|
6
|
+
/** The client's IP address. */
|
|
7
|
+
address: string;
|
|
8
|
+
/** The browser's current session cookie, if any: the account joins its accounts. */
|
|
9
|
+
token: string | undefined;
|
|
10
|
+
/** The browser's User-Agent, for the list of devices. */
|
|
11
|
+
userAgent?: string | null;
|
|
12
|
+
/** Milliseconds since 1970 (now by default). */
|
|
13
|
+
now?: number;
|
|
14
|
+
}
|
|
15
|
+
type Refusal = Extract<CodeVerificationResult, {
|
|
16
|
+
valid: false;
|
|
17
|
+
}>["reason"];
|
|
18
|
+
export type SignInFinishResult = {
|
|
19
|
+
status: "signed-in";
|
|
20
|
+
accountId: string;
|
|
21
|
+
token: string;
|
|
22
|
+
}
|
|
23
|
+
/** The account has two-factor on: ask for its authenticator's code (or a recovery code), then `finishSecondFactor`. */
|
|
24
|
+
| {
|
|
25
|
+
status: "second-factor";
|
|
26
|
+
ticket: string;
|
|
27
|
+
}
|
|
28
|
+
/** No account has this contact yet: ask for an identifier, then `finishSignUp` with the ticket. */
|
|
29
|
+
| {
|
|
30
|
+
status: "sign-up";
|
|
31
|
+
ticket: string;
|
|
32
|
+
} | {
|
|
33
|
+
status: "refused";
|
|
34
|
+
reason: Refusal;
|
|
35
|
+
} | {
|
|
36
|
+
status: "refused";
|
|
37
|
+
reason: "rate-limit";
|
|
38
|
+
retryAfterSeconds: number;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=type.d.ts.map
|