@sharadox/account-web-library 0.1.0-development.21 → 0.1.0-development.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -21
- 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-database/type.d.ts +57 -4
- package/distribution/account-database/type.d.ts.map +1 -1
- package/distribution/account-deletion/index.d.ts +18 -0
- package/distribution/account-deletion/index.d.ts.map +1 -0
- package/distribution/account-deletion/index.js +28 -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/{username-change → account-export}/type.js.map +1 -1
- package/distribution/account-migration/index.d.ts.map +1 -1
- package/distribution/account-migration/index.js +110 -0
- package/distribution/account-migration/index.js.map +1 -1
- 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-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 +11 -1
- package/distribution/account-server/index.d.ts.map +1 -1
- package/distribution/account-server/index.js +12 -1
- package/distribution/account-server/index.js.map +1 -1
- package/distribution/account-server/type.d.ts +2 -0
- package/distribution/account-server/type.d.ts.map +1 -1
- 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-sign-in/index.d.ts +1 -1
- package/distribution/account-sign-in/index.d.ts.map +1 -1
- package/distribution/account-sign-in/index.js +4 -2
- package/distribution/account-sign-in/index.js.map +1 -1
- package/distribution/account-sign-in/type.d.ts +2 -0
- package/distribution/account-sign-in/type.d.ts.map +1 -1
- package/distribution/audit-event/index.d.ts.map +1 -1
- package/distribution/audit-event/index.js +12 -1
- package/distribution/audit-event/index.js.map +1 -1
- package/distribution/audit-event/type.d.ts +1 -0
- package/distribution/audit-event/type.d.ts.map +1 -1
- package/distribution/browser-session-read/index.d.ts.map +1 -1
- package/distribution/browser-session-read/index.js +5 -1
- package/distribution/browser-session-read/index.js.map +1 -1
- package/distribution/browser-session-read/type.d.ts +5 -1
- package/distribution/browser-session-read/type.d.ts.map +1 -1
- package/distribution/code-request/index.js +1 -1
- package/distribution/code-request/type.d.ts +1 -1
- 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/contact-addition-flow/index.d.ts +31 -0
- package/distribution/contact-addition-flow/index.d.ts.map +1 -0
- package/distribution/contact-addition-flow/index.js +85 -0
- package/distribution/contact-addition-flow/index.js.map +1 -0
- package/distribution/contact-addition-flow/type.d.ts +22 -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/database-error/index.d.ts +1 -1
- package/distribution/database-error/index.js +1 -1
- package/distribution/email-channel/index.js +1 -1
- 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 +7 -3
- package/distribution/person-account/index.d.ts.map +1 -1
- package/distribution/person-account/index.js +21 -9
- package/distribution/person-account/index.js.map +1 -1
- package/distribution/person-account/type.d.ts +5 -2
- package/distribution/person-account/type.d.ts.map +1 -1
- 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/second-factor-finish/index.d.ts +12 -0
- package/distribution/second-factor-finish/index.d.ts.map +1 -0
- package/distribution/second-factor-finish/index.js +78 -0
- package/distribution/second-factor-finish/index.js.map +1 -0
- package/distribution/second-factor-finish/type.d.ts +27 -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-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/sign-in-finish/index.d.ts +3 -3
- package/distribution/sign-in-finish/index.d.ts.map +1 -1
- package/distribution/sign-in-finish/index.js +22 -5
- package/distribution/sign-in-finish/index.js.map +1 -1
- package/distribution/sign-in-finish/type.d.ts +8 -1
- package/distribution/sign-in-finish/type.d.ts.map +1 -1
- package/distribution/sign-in-start/index.d.ts +4 -6
- package/distribution/sign-in-start/index.d.ts.map +1 -1
- package/distribution/sign-in-start/index.js +14 -58
- package/distribution/sign-in-start/index.js.map +1 -1
- package/distribution/sign-in-start/type.d.ts +7 -0
- package/distribution/sign-in-start/type.d.ts.map +1 -1
- package/distribution/sign-up-finish/index.d.ts +4 -4
- package/distribution/sign-up-finish/index.d.ts.map +1 -1
- package/distribution/sign-up-finish/index.js +11 -6
- package/distribution/sign-up-finish/index.js.map +1 -1
- package/distribution/sign-up-finish/type.d.ts +6 -1
- package/distribution/sign-up-finish/type.d.ts.map +1 -1
- package/distribution/signed-ticket/index.d.ts +1 -1
- package/distribution/signed-ticket/index.js +1 -1
- 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-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/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 +4 -3
- 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-availability/index.d.ts +0 -11
- package/distribution/username-availability/index.d.ts.map +0 -1
- package/distribution/username-availability/index.js +0 -21
- package/distribution/username-availability/index.js.map +0 -1
- package/distribution/username-change/index.d.ts +0 -15
- package/distribution/username-change/index.d.ts.map +0 -1
- package/distribution/username-change/index.js +0 -39
- package/distribution/username-change/index.js.map +0 -1
- package/distribution/username-change/type.d.ts +0 -7
- package/distribution/username-change/type.d.ts.map +0 -1
- /package/distribution/{username-change → account-activity}/type.js +0 -0
- /package/distribution/{username → account-export}/type.js +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
2
2
|
import type { SignUpFinish, SignUpFinishResult } from "@sharadox/account-web-library/sign-up-finish/type";
|
|
3
3
|
/**
|
|
4
|
-
* The last step for a new person: the
|
|
5
|
-
* account with that contact verified and signs it in. A
|
|
4
|
+
* The last step for a new person: the name and identifier they chose, with the ticket proving their contact. Creates the
|
|
5
|
+
* account with that contact verified and signs it in. A refused name or identifier can be tried again with the same
|
|
6
6
|
* ticket while it lasts; a ticket can't make two accounts (the contact is then taken).
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* const result = await finishSignUp(server, { ticket,
|
|
9
|
+
* const result = await finishSignUp(server, { ticket, name, identifier, token: cookie });
|
|
10
10
|
*/
|
|
11
|
-
export declare function finishSignUp(server: AccountServer, { ticket,
|
|
11
|
+
export declare function finishSignUp(server: AccountServer, { ticket, name, identifier, token, userAgent, now }: SignUpFinish): Promise<SignUpFinishResult>;
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/sign-up-finish/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAKvF,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAE1G;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/sign-up-finish/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAKvF,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAE1G;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAgB,EAAE,GAAgB,EAAE,EAAE,YAAY,GACpF,OAAO,CAAC,kBAAkB,CAAC,CAgB7B"}
|
|
@@ -3,14 +3,14 @@ import { createPersonAccount } from "@sharadox/account-web-library/person-accoun
|
|
|
3
3
|
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
4
4
|
import { readTicket } from "@sharadox/account-web-library/signed-ticket";
|
|
5
5
|
/**
|
|
6
|
-
* The last step for a new person: the
|
|
7
|
-
* account with that contact verified and signs it in. A
|
|
6
|
+
* The last step for a new person: the name and identifier they chose, with the ticket proving their contact. Creates the
|
|
7
|
+
* account with that contact verified and signs it in. A refused name or identifier can be tried again with the same
|
|
8
8
|
* ticket while it lasts; a ticket can't make two accounts (the contact is then taken).
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* const result = await finishSignUp(server, { ticket,
|
|
11
|
+
* const result = await finishSignUp(server, { ticket, name, identifier, token: cookie });
|
|
12
12
|
*/
|
|
13
|
-
export async function finishSignUp(server, { ticket,
|
|
13
|
+
export async function finishSignUp(server, { ticket, name, identifier, token, userAgent = null, now = Date.now() }) {
|
|
14
14
|
const reading = readTicket(ticket, {
|
|
15
15
|
secret: deriveSecret(server.secret, "sign-up-ticket"),
|
|
16
16
|
purpose: "sign-up",
|
|
@@ -18,10 +18,15 @@ export async function finishSignUp(server, { ticket, username, token, now = Date
|
|
|
18
18
|
});
|
|
19
19
|
if (!reading.valid)
|
|
20
20
|
return { status: "refused", reason: "ticket" };
|
|
21
|
-
const created = await createPersonAccount(server.database, {
|
|
21
|
+
const created = await createPersonAccount(server.database, {
|
|
22
|
+
name,
|
|
23
|
+
identifier,
|
|
24
|
+
contact: reading.data.contact,
|
|
25
|
+
now,
|
|
26
|
+
});
|
|
22
27
|
if (!created.created)
|
|
23
28
|
return { status: "refused", reason: created.reason };
|
|
24
|
-
const session = await signIn(server.database, { accountId: created.accountId, token, now });
|
|
29
|
+
const session = await signIn(server.database, { accountId: created.accountId, token, userAgent, now });
|
|
25
30
|
return { status: "signed-in", accountId: created.accountId, token: session.token };
|
|
26
31
|
}
|
|
27
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/sign-up-finish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AAGvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAC/E,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AC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IACvG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;AACrF,CAAC"}
|
|
@@ -2,9 +2,14 @@ import type { PersonAccountResult } from "@sharadox/account-web-library/person-a
|
|
|
2
2
|
export interface SignUpFinish {
|
|
3
3
|
/** From `finishSignIn`'s `sign-up` answer. */
|
|
4
4
|
ticket: string;
|
|
5
|
-
|
|
5
|
+
/** What the account shows, 1 to 50 characters (`checkAccountName`). */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Without the `@`. */
|
|
8
|
+
identifier: string;
|
|
6
9
|
/** The browser's current session cookie, if any. */
|
|
7
10
|
token: string | undefined;
|
|
11
|
+
/** The browser's User-Agent, for the list of devices. */
|
|
12
|
+
userAgent?: string | null;
|
|
8
13
|
/** Milliseconds since 1970 (now by default). */
|
|
9
14
|
now?: number;
|
|
10
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/sign-up-finish/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAE7F,MAAM,WAAW,YAAY;IAC3B,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/sign-up-finish/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAE7F,MAAM,WAAW,YAAY;IAC3B,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,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,kBAAkB,GAC1B;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,EAAE;QAAE,OAAO,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TicketOptions, TicketReading } from "@sharadox/account-web-library/signed-ticket/type";
|
|
2
2
|
/**
|
|
3
3
|
* A short-lived, signed ticket carrying data between two steps (a proved contact from the code step to the
|
|
4
|
-
*
|
|
4
|
+
* identifier step) without storing anything: the data can be read, but not changed or used for another purpose.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* const ticket = createTicket({ contact }, { secret, purpose: "sign-up", lifetimeSeconds: 900 });
|
|
@@ -2,7 +2,7 @@ import { createHmac, timingSafeEqual } from "node:crypto";
|
|
|
2
2
|
const sign = (secret, body) => createHmac("sha256", secret).update(body).digest("base64url");
|
|
3
3
|
/**
|
|
4
4
|
* A short-lived, signed ticket carrying data between two steps (a proved contact from the code step to the
|
|
5
|
-
*
|
|
5
|
+
* identifier step) without storing anything: the data can be read, but not changed or used for another purpose.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* const ticket = createTicket({ contact }, { secret, purpose: "sign-up", lifetimeSeconds: 900 });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
4
|
+
import type { StepUpFinish, StepUpStart } from "@sharadox/account-web-library/step-up/type";
|
|
5
|
+
/** How long a step-up lasts: 10 minutes. */
|
|
6
|
+
export declare const STEP_UP_SECONDS = 600;
|
|
7
|
+
/**
|
|
8
|
+
* Before a sensitive change (a contact, two-factor, recovery codes, keys, deletion), sends a fresh code to one of the
|
|
9
|
+
* account's own verified contacts, through `sendCode` (rate limits and spending caps).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const result = await startStepUp(server, { accountId, contactId, address, language });
|
|
13
|
+
* if (result.status === "sent") after(result.deliver);
|
|
14
|
+
*/
|
|
15
|
+
export declare function startStepUp(server: AccountServer, { accountId, contactId, address, language, now, }: {
|
|
16
|
+
accountId: string;
|
|
17
|
+
contactId: string;
|
|
18
|
+
address: string;
|
|
19
|
+
language: string;
|
|
20
|
+
now?: number;
|
|
21
|
+
}): Promise<StepUpStart>;
|
|
22
|
+
/**
|
|
23
|
+
* Checks the step-up code and marks this browser's session of the account as confirmed for 10 minutes
|
|
24
|
+
* (`hasFreshStepUp`).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const result = await finishStepUp(server, { accountId, requestId, code, token: cookie });
|
|
28
|
+
*/
|
|
29
|
+
export declare function finishStepUp(server: AccountServer, { accountId, requestId, code, token, now, }: {
|
|
30
|
+
accountId: string;
|
|
31
|
+
requestId: string;
|
|
32
|
+
code: string;
|
|
33
|
+
token: string | undefined;
|
|
34
|
+
now?: number;
|
|
35
|
+
}): Promise<StepUpFinish>;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the account confirmed it is them on this browser in the last 10 minutes: check it before every sensitive
|
|
38
|
+
* change, and ask for a step-up when it is false.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* if (!(await hasFreshStepUp(database, { accountId, token: cookie }))) return askForStepUp();
|
|
42
|
+
*/
|
|
43
|
+
export declare function hasFreshStepUp(database: Kysely<AccountDatabase>, { accountId, token, now }: {
|
|
44
|
+
accountId: string;
|
|
45
|
+
token: string | undefined;
|
|
46
|
+
now?: number;
|
|
47
|
+
}): Promise<boolean>;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/step-up/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAMvF,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AAE5F,4CAA4C;AAC5C,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,aAAa,EACrB,EACE,SAAS,EACT,SAAS,EACT,OAAO,EACP,QAAQ,EACR,GAAgB,GACjB,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3F,OAAO,CAAC,WAAW,CAAC,CAWtB;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,EACE,SAAS,EACT,SAAS,EACT,IAAI,EACJ,KAAK,EACL,GAAgB,GACjB,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACjG,OAAO,CAAC,YAAY,CAAC,CAmBvB;AAkBD;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,KAAK,EAAE,GAAgB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACrG,OAAO,CAAC,OAAO,CAAC,CAGlB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
2
|
+
import { sendCode } from "@sharadox/account-web-library/code-sending";
|
|
3
|
+
import { verifyCode } from "@sharadox/account-web-library/code-verification";
|
|
4
|
+
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
5
|
+
import { hashSessionToken } from "@sharadox/account-web-library/session-token";
|
|
6
|
+
/** How long a step-up lasts: 10 minutes. */
|
|
7
|
+
export const STEP_UP_SECONDS = 600;
|
|
8
|
+
/**
|
|
9
|
+
* Before a sensitive change (a contact, two-factor, recovery codes, keys, deletion), sends a fresh code to one of the
|
|
10
|
+
* account's own verified contacts, through `sendCode` (rate limits and spending caps).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const result = await startStepUp(server, { accountId, contactId, address, language });
|
|
14
|
+
* if (result.status === "sent") after(result.deliver);
|
|
15
|
+
*/
|
|
16
|
+
export async function startStepUp(server, { accountId, contactId, address, language, now = Date.now(), }) {
|
|
17
|
+
const contact = await server.database
|
|
18
|
+
.selectFrom("contact")
|
|
19
|
+
.select(["kind", "value"])
|
|
20
|
+
.where("id", "=", contactId)
|
|
21
|
+
.where("account_id", "=", accountId)
|
|
22
|
+
.where("verified_at", "is not", null)
|
|
23
|
+
.executeTakeFirst();
|
|
24
|
+
const channel = contact && server.channels.find(({ kind }) => kind === contact.kind);
|
|
25
|
+
if (!contact || !channel)
|
|
26
|
+
return { status: "refused", reason: "contact" };
|
|
27
|
+
return sendCode(server, { purpose: "step-up", contact, channel, accountId, address, language, now });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks the step-up code and marks this browser's session of the account as confirmed for 10 minutes
|
|
31
|
+
* (`hasFreshStepUp`).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const result = await finishStepUp(server, { accountId, requestId, code, token: cookie });
|
|
35
|
+
*/
|
|
36
|
+
export async function finishStepUp(server, { accountId, requestId, code, token, now = Date.now(), }) {
|
|
37
|
+
const verification = await verifyCode(server.database, {
|
|
38
|
+
requestId,
|
|
39
|
+
code,
|
|
40
|
+
purpose: "step-up",
|
|
41
|
+
pepper: deriveSecret(server.secret, "one-time-code"),
|
|
42
|
+
now,
|
|
43
|
+
});
|
|
44
|
+
if (!verification.valid)
|
|
45
|
+
return { status: "refused", reason: verification.reason };
|
|
46
|
+
if (verification.accountId !== accountId)
|
|
47
|
+
return { status: "refused", reason: "unknown" };
|
|
48
|
+
const session = await sessionOf(server.database, { accountId, token, now });
|
|
49
|
+
if (!session)
|
|
50
|
+
return { status: "refused", reason: "session" };
|
|
51
|
+
await server.database
|
|
52
|
+
.updateTable("account_session")
|
|
53
|
+
.set({ step_up_at: new Date(now) })
|
|
54
|
+
.where("id", "=", session.id)
|
|
55
|
+
.execute();
|
|
56
|
+
await recordAuditEvent(server.database, { accountId, action: "session.stepped-up", now });
|
|
57
|
+
return { status: "confirmed" };
|
|
58
|
+
}
|
|
59
|
+
/** The account's live session on the browser holding `token`. */
|
|
60
|
+
async function sessionOf(database, { accountId, token, now }) {
|
|
61
|
+
if (!token)
|
|
62
|
+
return undefined;
|
|
63
|
+
return database
|
|
64
|
+
.selectFrom("account_session")
|
|
65
|
+
.innerJoin("browser_session", "browser_session.id", "account_session.browser_session_id")
|
|
66
|
+
.select(["account_session.id", "account_session.step_up_at"])
|
|
67
|
+
.where("browser_session.token_hash", "=", hashSessionToken(token))
|
|
68
|
+
.where("account_session.account_id", "=", accountId)
|
|
69
|
+
.where("account_session.expires_at", ">", new Date(now))
|
|
70
|
+
.executeTakeFirst();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Whether the account confirmed it is them on this browser in the last 10 minutes: check it before every sensitive
|
|
74
|
+
* change, and ask for a step-up when it is false.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* if (!(await hasFreshStepUp(database, { accountId, token: cookie }))) return askForStepUp();
|
|
78
|
+
*/
|
|
79
|
+
export async function hasFreshStepUp(database, { accountId, token, now = Date.now() }) {
|
|
80
|
+
const session = await sessionOf(database, { accountId, token, now });
|
|
81
|
+
return !!session?.step_up_at && now - session.step_up_at.getTime() <= STEP_UP_SECONDS * 1000;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/step-up/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAG/E,4CAA4C;AAC5C,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAqB,EACrB,EACE,SAAS,EACT,SAAS,EACT,OAAO,EACP,QAAQ,EACR,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAC0E;IAE5F,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,QAAQ;SAClC,UAAU,CAAC,SAAS,CAAC;SAC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vD,gBAAgB,EAAE,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,QAAiC,EACjC,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAkE;IAEtG,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACrE,OAAO,CAAC,CAAC,OAAO,EAAE,UAAU,IAAI,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,eAAe,GAAG,IAAI,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CodeSendingResult } from "@sharadox/account-web-library/code-sending/type";
|
|
2
|
+
import type { CodeVerificationResult } from "@sharadox/account-web-library/code-verification/type";
|
|
3
|
+
export type StepUpStart = CodeSendingResult | {
|
|
4
|
+
status: "refused";
|
|
5
|
+
reason: "contact";
|
|
6
|
+
};
|
|
7
|
+
export type StepUpFinish = {
|
|
8
|
+
status: "confirmed";
|
|
9
|
+
} | {
|
|
10
|
+
status: "refused";
|
|
11
|
+
reason: Extract<CodeVerificationResult, {
|
|
12
|
+
valid: false;
|
|
13
|
+
}>["reason"] | "session";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/step-up/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AAEnG,MAAM,MAAM,WAAW,GAAG,iBAAiB,GAAG;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAEvF,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,GACvB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC,sBAAsB,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;CAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/step-up/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
/**
|
|
4
|
+
* For tests: a person named after their identifier, with `<identifier>@example.com` verified. Returns the account
|
|
5
|
+
* and contact ids.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const { accountId } = await createTestPerson(memory.database, "ana");
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTestPerson(database: Kysely<AccountDatabase>, identifier: string, now?: number): Promise<{
|
|
11
|
+
accountId: string;
|
|
12
|
+
contactId: string;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/test-person/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAG3F;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,UAAU,EAAE,MAAM,EAClB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CASnD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createPersonAccount } from "@sharadox/account-web-library/person-account";
|
|
2
|
+
/**
|
|
3
|
+
* For tests: a person named after their identifier, with `<identifier>@example.com` verified. Returns the account
|
|
4
|
+
* and contact ids.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const { accountId } = await createTestPerson(memory.database, "ana");
|
|
8
|
+
*/
|
|
9
|
+
export async function createTestPerson(database, identifier, now) {
|
|
10
|
+
const result = await createPersonAccount(database, {
|
|
11
|
+
name: identifier,
|
|
12
|
+
identifier,
|
|
13
|
+
contact: { kind: "email", value: `${identifier.toLowerCase()}@example.com` },
|
|
14
|
+
...(now === undefined ? {} : { now }),
|
|
15
|
+
});
|
|
16
|
+
if (!result.created)
|
|
17
|
+
throw new Error(`test person "${identifier}" not created: ${result.reason}`);
|
|
18
|
+
return { accountId: result.accountId, contactId: result.contactId };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/test-person/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AAEnF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAiC,EACjC,UAAkB,EAClB,GAAY;IAEZ,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,QAAQ,EAAE;QACjD,IAAI,EAAE,UAAU;QAChB,UAAU;QACV,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC,WAAW,EAAE,cAAc,EAAE;QAC5E,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;KACtC,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,UAAU,kBAAkB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAClG,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;AACtE,CAAC"}
|
|
@@ -18,7 +18,7 @@ export type TotpVerification = {
|
|
|
18
18
|
export interface TotpUriOptions {
|
|
19
19
|
/** The company, shown above the code. */
|
|
20
20
|
issuer: string;
|
|
21
|
-
/** Which account: the
|
|
21
|
+
/** Which account: the identifier. */
|
|
22
22
|
account: string;
|
|
23
23
|
secret: Uint8Array;
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/totp/type.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,6FAA6F;AAC7F,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEhF,+DAA+D;AAC/D,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/totp/type.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,6FAA6F;AAC7F,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEhF,+DAA+D;AAC/D,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;CACpB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
4
|
+
import type { TotpSetupConfirmation, TotpSetupStart, TotpStatus } from "@sharadox/account-web-library/totp-setup/type";
|
|
5
|
+
/**
|
|
6
|
+
* Starts setting up an authenticator app (two-factor): a new secret, stored encrypted and not yet on, to show as a
|
|
7
|
+
* QR code (`uri`) or to type in (`secret`). Starting again replaces an unfinished setup. Ask for a fresh code first
|
|
8
|
+
* (step-up).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const setup = await startTotpSetup(server, { accountId, issuer: "Luis Pires Decor" });
|
|
12
|
+
*/
|
|
13
|
+
export declare function startTotpSetup(server: AccountServer, { accountId, issuer, now }: {
|
|
14
|
+
accountId: string;
|
|
15
|
+
issuer: string;
|
|
16
|
+
now?: number;
|
|
17
|
+
}): Promise<TotpSetupStart>;
|
|
18
|
+
/**
|
|
19
|
+
* Turns two-factor on once the authenticator app shows a right code, and makes 10 recovery codes to show once.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const result = await confirmTotpSetup(server, { accountId, code });
|
|
23
|
+
* if (result.confirmed) show(result.recoveryCodes);
|
|
24
|
+
*/
|
|
25
|
+
export declare function confirmTotpSetup(server: AccountServer, { accountId, code, now }: {
|
|
26
|
+
accountId: string;
|
|
27
|
+
code: string;
|
|
28
|
+
now?: number;
|
|
29
|
+
}): Promise<TotpSetupConfirmation>;
|
|
30
|
+
/**
|
|
31
|
+
* Turns two-factor off: the authenticator app and the recovery codes. Ask for a fresh code first (step-up).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* await removeTotp(database, { accountId }); // { removed: true }
|
|
35
|
+
*/
|
|
36
|
+
export declare function removeTotp(database: Kysely<AccountDatabase>, { accountId }: {
|
|
37
|
+
accountId: string;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
removed: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether an account has two-factor on, and how many recovery codes it has left.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const { on, recoveryCodesLeft } = await totpStatus(database, { accountId });
|
|
46
|
+
*/
|
|
47
|
+
export declare function totpStatus(database: Kysely<AccountDatabase>, { accountId }: {
|
|
48
|
+
accountId: string;
|
|
49
|
+
}): Promise<TotpStatus>;
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/totp-setup/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAOvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,+CAA+C,CAAC;AAEvH;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,aAAa,EACrB,EAAE,SAAS,EAAE,MAAM,EAAE,GAAgB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3F,OAAO,CAAC,cAAc,CAAC,CAkCzB;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,aAAa,EACrB,EAAE,SAAS,EAAE,IAAI,EAAE,GAAgB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACvF,OAAO,CAAC,qBAAqB,CAAC,CA4BhC;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACnC,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAY/B;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACnC,OAAO,CAAC,UAAU,CAAC,CAgBrB"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
|
|
2
|
+
import { accountTables } from "@sharadox/account-web-library/account-server";
|
|
3
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
4
|
+
import { encodeBase32 } from "@sharadox/account-web-library/base-32";
|
|
5
|
+
import { replaceRecoveryCodes } from "@sharadox/account-web-library/recovery-code-store";
|
|
6
|
+
import { decryptSecret, encryptSecret } from "@sharadox/account-web-library/secret-encryption";
|
|
7
|
+
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
8
|
+
import { createTotpSecret, totpUri, verifyTotp } from "@sharadox/account-web-library/totp";
|
|
9
|
+
/**
|
|
10
|
+
* Starts setting up an authenticator app (two-factor): a new secret, stored encrypted and not yet on, to show as a
|
|
11
|
+
* QR code (`uri`) or to type in (`secret`). Starting again replaces an unfinished setup. Ask for a fresh code first
|
|
12
|
+
* (step-up).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const setup = await startTotpSetup(server, { accountId, issuer: "Luis Pires Decor" });
|
|
16
|
+
*/
|
|
17
|
+
export async function startTotpSetup(server, { accountId, issuer, now = Date.now() }) {
|
|
18
|
+
const account = await server.database
|
|
19
|
+
.selectFrom("identifier")
|
|
20
|
+
.select("value")
|
|
21
|
+
.where("account_id", "=", accountId)
|
|
22
|
+
.executeTakeFirst();
|
|
23
|
+
if (!account)
|
|
24
|
+
return { status: "no-account" };
|
|
25
|
+
const secret = createTotpSecret();
|
|
26
|
+
return accountTables(server)
|
|
27
|
+
.transaction()
|
|
28
|
+
.execute(async (transaction) => {
|
|
29
|
+
const existing = await transaction
|
|
30
|
+
.selectFrom("totp_credential")
|
|
31
|
+
.select(["id", "confirmed_at"])
|
|
32
|
+
.where("account_id", "=", accountId)
|
|
33
|
+
.forUpdate()
|
|
34
|
+
.executeTakeFirst();
|
|
35
|
+
if (existing?.confirmed_at)
|
|
36
|
+
return { status: "already-on" };
|
|
37
|
+
if (existing)
|
|
38
|
+
await transaction.deleteFrom("totp_credential").where("id", "=", existing.id).execute();
|
|
39
|
+
await transaction
|
|
40
|
+
.insertInto("totp_credential")
|
|
41
|
+
.values({
|
|
42
|
+
id: uuidVersion7({ now }),
|
|
43
|
+
account_id: accountId,
|
|
44
|
+
secret_ciphertext: encryptSecret(secret, deriveSecret(server.secret, "totp-encryption")),
|
|
45
|
+
created_at: new Date(now),
|
|
46
|
+
})
|
|
47
|
+
.execute();
|
|
48
|
+
return {
|
|
49
|
+
status: "started",
|
|
50
|
+
uri: totpUri({ issuer, account: account.value, secret }),
|
|
51
|
+
secret: encodeBase32(secret),
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Turns two-factor on once the authenticator app shows a right code, and makes 10 recovery codes to show once.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const result = await confirmTotpSetup(server, { accountId, code });
|
|
60
|
+
* if (result.confirmed) show(result.recoveryCodes);
|
|
61
|
+
*/
|
|
62
|
+
export async function confirmTotpSetup(server, { accountId, code, now = Date.now() }) {
|
|
63
|
+
return accountTables(server)
|
|
64
|
+
.transaction()
|
|
65
|
+
.execute(async (transaction) => {
|
|
66
|
+
const pending = await transaction
|
|
67
|
+
.selectFrom("totp_credential")
|
|
68
|
+
.select(["id", "secret_ciphertext"])
|
|
69
|
+
.where("account_id", "=", accountId)
|
|
70
|
+
.where("confirmed_at", "is", null)
|
|
71
|
+
.forUpdate()
|
|
72
|
+
.executeTakeFirst();
|
|
73
|
+
if (!pending)
|
|
74
|
+
return { confirmed: false, reason: "none" };
|
|
75
|
+
const secret = decryptSecret(pending.secret_ciphertext, deriveSecret(server.secret, "totp-encryption"));
|
|
76
|
+
const verification = verifyTotp(secret, code.replace(/\s/g, ""), now);
|
|
77
|
+
if (!verification.valid)
|
|
78
|
+
return { confirmed: false, reason: "wrong" };
|
|
79
|
+
await transaction
|
|
80
|
+
.updateTable("totp_credential")
|
|
81
|
+
.set({ confirmed_at: new Date(now), last_used_step: verification.step })
|
|
82
|
+
.where("id", "=", pending.id)
|
|
83
|
+
.execute();
|
|
84
|
+
const recoveryCodes = await replaceRecoveryCodes(transaction, {
|
|
85
|
+
accountId,
|
|
86
|
+
pepper: deriveSecret(server.secret, "recovery-code"),
|
|
87
|
+
now,
|
|
88
|
+
});
|
|
89
|
+
await recordAuditEvent(transaction, { accountId, action: "second-factor.turned-on", now });
|
|
90
|
+
return { confirmed: true, recoveryCodes };
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Turns two-factor off: the authenticator app and the recovery codes. Ask for a fresh code first (step-up).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* await removeTotp(database, { accountId }); // { removed: true }
|
|
98
|
+
*/
|
|
99
|
+
export async function removeTotp(database, { accountId }) {
|
|
100
|
+
return database.transaction().execute(async (transaction) => {
|
|
101
|
+
const removed = await transaction
|
|
102
|
+
.deleteFrom("totp_credential")
|
|
103
|
+
.where("account_id", "=", accountId)
|
|
104
|
+
.where("confirmed_at", "is not", null)
|
|
105
|
+
.executeTakeFirst();
|
|
106
|
+
if (removed.numDeletedRows === 0n)
|
|
107
|
+
return { removed: false };
|
|
108
|
+
await transaction.deleteFrom("recovery_code").where("account_id", "=", accountId).execute();
|
|
109
|
+
await recordAuditEvent(transaction, { accountId, action: "second-factor.turned-off" });
|
|
110
|
+
return { removed: true };
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Whether an account has two-factor on, and how many recovery codes it has left.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* const { on, recoveryCodesLeft } = await totpStatus(database, { accountId });
|
|
118
|
+
*/
|
|
119
|
+
export async function totpStatus(database, { accountId }) {
|
|
120
|
+
const [credential, codes] = await Promise.all([
|
|
121
|
+
database
|
|
122
|
+
.selectFrom("totp_credential")
|
|
123
|
+
.select("id")
|
|
124
|
+
.where("account_id", "=", accountId)
|
|
125
|
+
.where("confirmed_at", "is not", null)
|
|
126
|
+
.executeTakeFirst(),
|
|
127
|
+
database
|
|
128
|
+
.selectFrom("recovery_code")
|
|
129
|
+
.select("id")
|
|
130
|
+
.where("account_id", "=", accountId)
|
|
131
|
+
.where("used_at", "is", null)
|
|
132
|
+
.execute(),
|
|
133
|
+
]);
|
|
134
|
+
return { on: credential !== undefined, recoveryCodesLeft: codes.length };
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/totp-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AG,EAAE,SAAS,CAAC;aACnC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC;aAC5B,OAAO,EAAE;KACb,CAAC,CAAC;IACH,OAAO,EAAE,EAAE,EAAE,UAAU,KAAK,SAAS,EAAE,iBAAiB,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TotpSetupStart =
|
|
2
|
+
/** Show `uri` as a QR code, and `secret` (base 32) for typing in by hand. */
|
|
3
|
+
{
|
|
4
|
+
status: "started";
|
|
5
|
+
uri: string;
|
|
6
|
+
secret: string;
|
|
7
|
+
} | {
|
|
8
|
+
status: "already-on" | "no-account";
|
|
9
|
+
};
|
|
10
|
+
export type TotpSetupConfirmation =
|
|
11
|
+
/** Two-factor is on: show the recovery codes once, and recommend keeping them somewhere safe. */
|
|
12
|
+
{
|
|
13
|
+
confirmed: true;
|
|
14
|
+
recoveryCodes: string[];
|
|
15
|
+
} | {
|
|
16
|
+
confirmed: false;
|
|
17
|
+
reason: "wrong" | "none";
|
|
18
|
+
};
|
|
19
|
+
export interface TotpStatus {
|
|
20
|
+
/** Whether an authenticator app is needed to sign in. */
|
|
21
|
+
on: boolean;
|
|
22
|
+
recoveryCodesLeft: number;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/totp-setup/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc;AACxB,6EAA6E;AAC7E;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,YAAY,GAAG,YAAY,CAAA;CAAE,CAAC;AAE/F,MAAM,MAAM,qBAAqB;AAC/B,iGAAiG;AACjG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,aAAa,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAA;CAAE,CAAC;AAEhG,MAAM,WAAW,UAAU;IACzB,yDAAyD;IACzD,EAAE,EAAE,OAAO,CAAC;IACZ,iBAAiB,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/totp-setup/type.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/account-web-library",
|
|
3
|
-
"version": "0.1.0-development.
|
|
3
|
+
"version": "0.1.0-development.27",
|
|
4
4
|
"description": "Passwordless accounts for web applications: one-time codes, two-factor, roles, bans and OpenID Connect for people and agents.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|
|
@@ -40,11 +40,12 @@
|
|
|
40
40
|
"*.{json,md,yml,yaml}": "prettier --write"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@sharadox/database-web-library": "0.1.0-development.
|
|
43
|
+
"@sharadox/database-web-library": "0.1.0-development.9",
|
|
44
44
|
"@sharadox/email-web-library": "^0.7.1",
|
|
45
|
-
"@sharadox/protection-web-library": "0.1.0-development.
|
|
45
|
+
"@sharadox/protection-web-library": "0.1.0-development.12",
|
|
46
46
|
"@sharadox/web-library": "^0.11.1",
|
|
47
47
|
"kysely": "^0.28.20",
|
|
48
|
+
"sharp": "0.34.5",
|
|
48
49
|
"zod": "^4.6.7"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|