@sharadox/account-web-library 0.1.0-development.12 → 0.1.0-development.18

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.
Files changed (68) hide show
  1. package/README.md +49 -0
  2. package/distribution/account-database/type.d.ts +3 -0
  3. package/distribution/account-database/type.d.ts.map +1 -1
  4. package/distribution/account-server/index.d.ts +15 -0
  5. package/distribution/account-server/index.d.ts.map +1 -0
  6. package/distribution/account-server/index.js +23 -0
  7. package/distribution/account-server/index.js.map +1 -0
  8. package/distribution/account-server/type.d.ts +28 -0
  9. package/distribution/account-server/type.d.ts.map +1 -0
  10. package/distribution/account-server/type.js +2 -0
  11. package/distribution/account-server/type.js.map +1 -0
  12. package/distribution/challenge-issue/index.d.ts +13 -0
  13. package/distribution/challenge-issue/index.d.ts.map +1 -0
  14. package/distribution/challenge-issue/index.js +18 -0
  15. package/distribution/challenge-issue/index.js.map +1 -0
  16. package/distribution/contact-channel/type.d.ts +20 -0
  17. package/distribution/contact-channel/type.d.ts.map +1 -0
  18. package/distribution/contact-channel/type.js +2 -0
  19. package/distribution/contact-channel/type.js.map +1 -0
  20. package/distribution/email-channel/index.d.ts +13 -0
  21. package/distribution/email-channel/index.d.ts.map +1 -0
  22. package/distribution/email-channel/index.js +90 -0
  23. package/distribution/email-channel/index.js.map +1 -0
  24. package/distribution/email-channel/type.d.ts +17 -0
  25. package/distribution/email-channel/type.d.ts.map +1 -0
  26. package/distribution/email-channel/type.js +2 -0
  27. package/distribution/email-channel/type.js.map +1 -0
  28. package/distribution/secret-derivation/index.d.ts +10 -0
  29. package/distribution/secret-derivation/index.d.ts.map +1 -0
  30. package/distribution/secret-derivation/index.js +15 -0
  31. package/distribution/secret-derivation/index.js.map +1 -0
  32. package/distribution/sign-in-finish/index.d.ts +12 -0
  33. package/distribution/sign-in-finish/index.d.ts.map +1 -0
  34. package/distribution/sign-in-finish/index.js +47 -0
  35. package/distribution/sign-in-finish/index.js.map +1 -0
  36. package/distribution/sign-in-finish/type.d.ts +34 -0
  37. package/distribution/sign-in-finish/type.d.ts.map +1 -0
  38. package/distribution/sign-in-finish/type.js +2 -0
  39. package/distribution/sign-in-finish/type.js.map +1 -0
  40. package/distribution/sign-in-start/index.d.ts +18 -0
  41. package/distribution/sign-in-start/index.d.ts.map +1 -0
  42. package/distribution/sign-in-start/index.js +69 -0
  43. package/distribution/sign-in-start/index.js.map +1 -0
  44. package/distribution/sign-in-start/type.d.ts +27 -0
  45. package/distribution/sign-in-start/type.d.ts.map +1 -0
  46. package/distribution/sign-in-start/type.js +2 -0
  47. package/distribution/sign-in-start/type.js.map +1 -0
  48. package/distribution/sign-up-finish/index.d.ts +12 -0
  49. package/distribution/sign-up-finish/index.d.ts.map +1 -0
  50. package/distribution/sign-up-finish/index.js +27 -0
  51. package/distribution/sign-up-finish/index.js.map +1 -0
  52. package/distribution/sign-up-finish/type.d.ts +21 -0
  53. package/distribution/sign-up-finish/type.d.ts.map +1 -0
  54. package/distribution/sign-up-finish/type.js +2 -0
  55. package/distribution/sign-up-finish/type.js.map +1 -0
  56. package/distribution/signed-ticket/index.d.ts +19 -0
  57. package/distribution/signed-ticket/index.d.ts.map +1 -0
  58. package/distribution/signed-ticket/index.js +35 -0
  59. package/distribution/signed-ticket/index.js.map +1 -0
  60. package/distribution/signed-ticket/type.d.ts +16 -0
  61. package/distribution/signed-ticket/type.d.ts.map +1 -0
  62. package/distribution/signed-ticket/type.js +2 -0
  63. package/distribution/signed-ticket/type.js.map +1 -0
  64. package/distribution/test-server/index.d.ts +10 -0
  65. package/distribution/test-server/index.d.ts.map +1 -0
  66. package/distribution/test-server/index.js +16 -0
  67. package/distribution/test-server/index.js.map +1 -0
  68. package/package.json +5 -2
package/README.md CHANGED
@@ -19,6 +19,44 @@ Sign-in codes, sessions and the OpenID Connect server come next (see `CHANGELOG.
19
19
  pnpm add @sharadox/account-web-library
20
20
  ```
21
21
 
22
+ ## The sign-in flow
23
+
24
+ Signing up and signing in are the same three steps, on one `AccountServer`:
25
+ `{ database, channels, secret, limits? }`. The database holds the account tables and protection-web-library's
26
+ (`migrateProtection` and `migrateAccount`). `secret` is `ACCOUNT_SECRET`: at least 32 random characters, server only.
27
+ Every key is derived from it with `deriveSecret`.
28
+
29
+ 1. `issueChallenge(server)` gives the page a proof-of-work challenge, which the browser solves in the background.
30
+ 2. `startSignIn(server, { contact, solution, address, language, now? })` checks, in this order:
31
+ - the proof of work (single use);
32
+ - the contact and its channel;
33
+ - rate limits per contact, per address group and for everyone;
34
+ - the channel's daily spending cap.
35
+
36
+ It answers `{ status: "sent", requestId, deliver }`, and you call `deliver` after answering (Next.js `after()`).
37
+ Otherwise it answers `refused` with `proof`, `contact`, `unavailable` (the cap is reached: sending pauses), or
38
+ `rate-limit` with `retryAfterSeconds`. The answer never depends on whether an account exists.
39
+
40
+ 3. `finishSignIn(server, { requestId, code, address, token, now? })` limits guesses per address group. It answers:
41
+ - `signed-in`, with `{ accountId, token }`: set `token` as the cookie;
42
+ - `sign-up`, with `{ ticket }`, for a contact with no account;
43
+ - `refused`, with the code's reason or `rate-limit`.
44
+ 4. `finishSignUp(server, { ticket, username, token, now? })` creates the account and signs it in. A refused
45
+ username can be tried again with the same ticket, which lasts 15 minutes.
46
+
47
+ `DEFAULT_SIGN_IN_LIMITS` (`account-server`):
48
+
49
+ | Limit | Default |
50
+ | ------------------------- | --------------------------------- |
51
+ | `perContact` | 3 codes, then 1 every 5 minutes |
52
+ | `perAddress` | 10, then 1 a minute |
53
+ | `global` | 200, then 1 a second |
54
+ | `verificationsPerAddress` | 20 typed codes, then 1 every 30 s |
55
+ | `dailySendsPerChannel` | 2,000 |
56
+ | `difficulty` | 14 bits |
57
+
58
+ `createTicket` and `readTicket` (`signed-ticket`) carry signed, short-lived data between steps.
59
+
22
60
  ## Storage
23
61
 
24
62
  Postgres through Kysely (`@sharadox/database-web-library`). Run `migrateAccount(database)` when the application
@@ -168,6 +206,17 @@ points to any number of account sessions, so the selector has no limit and the c
168
206
  - `pruneSessions(database, { idleSeconds?, now? })` → `{ accountSessions, browserSessions }`, for a daily job.
169
207
  - `createSessionToken()`, `hashSessionToken(token)` (`session-token`).
170
208
 
209
+ ### `email-channel`: `createEmailChannel({ sender, from, design, logos?, now? })` → `ContactChannel`
210
+
211
+ Sends codes by email through email-web-library's sender, in the shared email layout.
212
+
213
+ - English, or European Portuguese for any `pt` reader.
214
+ - The code is in the body only, never in the subject (lock screens show subjects).
215
+ - No link to click: nothing for a phishing email to imitate.
216
+
217
+ A `ContactChannel` (`contact-channel/type`) is `{ kind, send({ contact, code, purpose, language, expiresAt }) }`:
218
+ phone, WhatsApp, Messenger and Instagram channels will have the same shape.
219
+
171
220
  ### `contact-kind`: `normalizeContact({ kind, value })`, `CONTACT_KINDS`
172
221
 
173
222
  `email` in this version; unknown kinds and invalid values throw.
@@ -1,3 +1,4 @@
1
+ import type { ProtectionDatabase } from "@sharadox/protection-web-library/protection-database/type";
1
2
  import type { ColumnType, Generated } from "kysely";
2
3
  /** A timestamp the database fills in when not given. */
3
4
  type DefaultTime = ColumnType<Date, Date | undefined, Date>;
@@ -90,5 +91,7 @@ export interface AccountDatabase {
90
91
  browser_session: BrowserSessionTable;
91
92
  account_session: AccountSessionTable;
92
93
  }
94
+ /** The account tables and the protection tables (rate limits, spending caps, used challenges) the server needs. */
95
+ export type AccountServerDatabase = AccountDatabase & ProtectionDatabase;
93
96
  export {};
94
97
  //# sourceMappingURL=type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-database/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEpD,wDAAwD;AACxD,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,CAAC,CAAC;AAE5D,sFAAsF;AACtF,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CA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IACtB,OAAO,EAAE,YAAY,CAAC;IACtB,WAAW,EAAE,eAAe,CAAC;IAC7B,YAAY,EAAE,gBAAgB,CAAC;IAC/B,eAAe,EAAE,mBAAmB,CAAC;IACrC,eAAe,EAAE,mBAAmB,CAAC;CACtC;AAED,mHAAmH;AACnH,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { AccountServer, SignInLimits } from "@sharadox/account-web-library/account-server/type";
2
+ /**
3
+ * The limits used when a company's configuration doesn't set them: 3 codes per contact then one per 5 minutes; 10
4
+ * per address group then one a minute; 200 for everyone then one a second; 20 typed codes per address group then
5
+ * one per 30 seconds; 2,000 sends per channel per UTC day; proof of work of 14 bits.
6
+ */
7
+ export declare const DEFAULT_SIGN_IN_LIMITS: SignInLimits;
8
+ /**
9
+ * A server's limits: its own where set, the defaults elsewhere.
10
+ *
11
+ * @example
12
+ * const { perContact } = signInLimits(server);
13
+ */
14
+ export declare function signInLimits(server: AccountServer): SignInLimits;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mDAAmD,CAAC;AAErG;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,YAOpC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,CAEhE"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The limits used when a company's configuration doesn't set them: 3 codes per contact then one per 5 minutes; 10
3
+ * per address group then one a minute; 200 for everyone then one a second; 20 typed codes per address group then
4
+ * one per 30 seconds; 2,000 sends per channel per UTC day; proof of work of 14 bits.
5
+ */
6
+ export const DEFAULT_SIGN_IN_LIMITS = {
7
+ perContact: { capacity: 3, refillPerSecond: 1 / 300 },
8
+ perAddress: { capacity: 10, refillPerSecond: 1 / 60 },
9
+ global: { capacity: 200, refillPerSecond: 1 },
10
+ verificationsPerAddress: { capacity: 20, refillPerSecond: 1 / 30 },
11
+ dailySendsPerChannel: 2_000,
12
+ difficulty: 14,
13
+ };
14
+ /**
15
+ * A server's limits: its own where set, the defaults elsewhere.
16
+ *
17
+ * @example
18
+ * const { perContact } = signInLimits(server);
19
+ */
20
+ export function signInLimits(server) {
21
+ return { ...DEFAULT_SIGN_IN_LIMITS, ...server.limits };
22
+ }
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-server/index.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAiB;IAClD,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,GAAG,GAAG,EAAE;IACrD,UAAU,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE;IACrD,MAAM,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE,CAAC,EAAE;IAC7C,uBAAuB,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE;IAClE,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE,EAAE;CACf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAqB;IAChD,OAAO,EAAE,GAAG,sBAAsB,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;AACzD,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { TokenBucketRule } from "@sharadox/protection-web-library/token-bucket/type";
3
+ import type { AccountServerDatabase } from "@sharadox/account-web-library/account-database/type";
4
+ import type { ContactChannel } from "@sharadox/account-web-library/contact-channel/type";
5
+ /** How fast each kind of visitor may go. Every field has a default (see `DEFAULT_SIGN_IN_LIMITS`). */
6
+ export interface SignInLimits {
7
+ /** Codes sent to one contact. */
8
+ perContact: TokenBucketRule;
9
+ /** Codes requested from one address group (an IPv4 address, an IPv6 /64). */
10
+ perAddress: TokenBucketRule;
11
+ /** Codes requested by everyone together. */
12
+ global: TokenBucketRule;
13
+ /** Codes typed from one address group. */
14
+ verificationsPerAddress: TokenBucketRule;
15
+ /** The most codes each channel may send in a UTC day; past it, sending pauses (never spends). */
16
+ dailySendsPerChannel: number;
17
+ /** Leading zero bits of the proof of work. */
18
+ difficulty: number;
19
+ }
20
+ /** What every sign-in step needs: the database, the channels, and one root secret every key is derived from. */
21
+ export interface AccountServer {
22
+ database: Kysely<AccountServerDatabase>;
23
+ channels: ContactChannel[];
24
+ /** At least 32 random characters, server only (`ACCOUNT_SECRET`). */
25
+ secret: string;
26
+ limits?: Partial<SignInLimits>;
27
+ }
28
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-server/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAC1F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AACjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAEzF,sGAAsG;AACtG,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,UAAU,EAAE,eAAe,CAAC;IAC5B,6EAA6E;IAC7E,UAAU,EAAE,eAAe,CAAC;IAC5B,4CAA4C;IAC5C,MAAM,EAAE,eAAe,CAAC;IACxB,0CAA0C;IAC1C,uBAAuB,EAAE,eAAe,CAAC;IACzC,iGAAiG;IACjG,oBAAoB,EAAE,MAAM,CAAC;IAC7B,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,gHAAgH;AAChH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACxC,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/account-server/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { Challenge } from "@sharadox/protection-web-library/proof-of-work/type";
2
+ import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
3
+ /**
4
+ * A proof-of-work challenge for the sign-in form, at the server's difficulty: the browser solves it in the
5
+ * background (protection-web-library's `solveChallenge`) and sends the solution with the contact.
6
+ *
7
+ * @example
8
+ * const challenge = issueChallenge(server); // give it to the page
9
+ */
10
+ export declare function issueChallenge(server: AccountServer, { now }?: {
11
+ now?: number;
12
+ }): Challenge;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/challenge-issue/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qDAAqD,CAAC;AAErF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAGvF;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,GAAgB,EAAE,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,SAAS,CAM5G"}
@@ -0,0 +1,18 @@
1
+ import { createChallenge } from "@sharadox/protection-web-library/proof-of-work";
2
+ import { signInLimits } from "@sharadox/account-web-library/account-server";
3
+ import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
4
+ /**
5
+ * A proof-of-work challenge for the sign-in form, at the server's difficulty: the browser solves it in the
6
+ * background (protection-web-library's `solveChallenge`) and sends the solution with the contact.
7
+ *
8
+ * @example
9
+ * const challenge = issueChallenge(server); // give it to the page
10
+ */
11
+ export function issueChallenge(server, { now = Date.now() } = {}) {
12
+ return createChallenge({
13
+ secret: deriveSecret(server.secret, "proof-of-work"),
14
+ difficulty: signInLimits(server).difficulty,
15
+ now,
16
+ });
17
+ }
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/challenge-issue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAqB,EAAE,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,KAAuB,EAAE;IAC/F,OAAO,eAAe,CAAC;QACrB,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;QACpD,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,UAAU;QAC3C,GAAG;KACJ,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { CodePurpose } from "@sharadox/account-web-library/code-request/type";
2
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
3
+ /** A one-time code to deliver to a contact. */
4
+ export interface CodeDelivery {
5
+ contact: Contact;
6
+ code: string;
7
+ purpose: CodePurpose;
8
+ /** The reader's language (`en`, `pt-PT`…); channels fall back to English. */
9
+ language: string;
10
+ expiresAt: Date;
11
+ }
12
+ /**
13
+ * How codes reach one kind of contact (email now; phone, WhatsApp, Messenger, Instagram later). Cap the sends of paid
14
+ * channels before calling `send` (protection-web-library's `spendFromCap`).
15
+ */
16
+ export interface ContactChannel {
17
+ kind: string;
18
+ send(delivery: CodeDelivery): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/contact-channel/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AACnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;IACrB,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/contact-channel/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { ContactChannel } from "@sharadox/account-web-library/contact-channel/type";
2
+ import type { EmailChannelOptions } from "@sharadox/account-web-library/email-channel/type";
3
+ /**
4
+ * Sends one-time codes by email, in the shared Sharadox email layout (email-web-library), in English or European
5
+ * Portuguese (any `pt` reader). The code is in the body only, never the subject (lock screens show subjects), with
6
+ * no link to click: nothing to imitate in a phishing email.
7
+ *
8
+ * @example
9
+ * const channel = createEmailChannel({ sender: createAmazonSesSender(configuration), from, design });
10
+ * await channel.send({ contact, code, purpose: "sign-in", language: "pt-PT", expiresAt });
11
+ */
12
+ export declare function createEmailChannel({ sender, from, design, logos, now, }: EmailChannelOptions): ContactChannel;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/email-channel/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,cAAc,EAAE,MAAM,oDAAoD,CAAC;AACvG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AAsD5F;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,IAAI,EACJ,MAAM,EACN,KAAU,EACV,GAAc,GACf,EAAE,mBAAmB,GAAG,cAAc,CA2CtC"}
@@ -0,0 +1,90 @@
1
+ import { emailLayout } from "@sharadox/email-web-library/email-layout";
2
+ const ENGLISH = {
3
+ language: "en",
4
+ subject: {
5
+ "sign-in": (company) => `Your ${company} sign-in code`,
6
+ "contact-verification": (company) => `Confirm your address for ${company}`,
7
+ "step-up": (company) => `Your ${company} confirmation code`,
8
+ },
9
+ eyebrow: { "sign-in": "Sign in", "contact-verification": "Confirm address", "step-up": "Confirmation" },
10
+ heading: {
11
+ "sign-in": "Your sign-in code",
12
+ "contact-verification": "Confirm this address",
13
+ "step-up": "Confirm it's you",
14
+ },
15
+ label: "Code",
16
+ lifetime: (minutes) => `It works once, for ${minutes} ${minutes === 1 ? "minute" : "minutes"}.`,
17
+ ignore: "If you didn't ask for it, you can ignore this email: without the code, nobody gets in.",
18
+ never: "We will never ask you for this code.",
19
+ closing: "Best regards,",
20
+ };
21
+ const PORTUGUESE = {
22
+ language: "pt-PT",
23
+ subject: {
24
+ "sign-in": (company) => `O seu código para entrar em ${company}`,
25
+ "contact-verification": (company) => `Confirme o seu endereço em ${company}`,
26
+ "step-up": (company) => `O seu código de confirmação de ${company}`,
27
+ },
28
+ eyebrow: { "sign-in": "Entrar", "contact-verification": "Confirmar endereço", "step-up": "Confirmação" },
29
+ heading: {
30
+ "sign-in": "O seu código para entrar",
31
+ "contact-verification": "Confirme este endereço",
32
+ "step-up": "Confirme que é você",
33
+ },
34
+ label: "Código",
35
+ lifetime: (minutes) => `Funciona uma vez, durante ${minutes} ${minutes === 1 ? "minuto" : "minutos"}.`,
36
+ ignore: "Se não o pediu, pode ignorar este email: sem o código, ninguém entra.",
37
+ never: "Nunca lhe pediremos este código.",
38
+ closing: "Com os melhores cumprimentos,",
39
+ };
40
+ /**
41
+ * Sends one-time codes by email, in the shared Sharadox email layout (email-web-library), in English or European
42
+ * Portuguese (any `pt` reader). The code is in the body only, never the subject (lock screens show subjects), with
43
+ * no link to click: nothing to imitate in a phishing email.
44
+ *
45
+ * @example
46
+ * const channel = createEmailChannel({ sender: createAmazonSesSender(configuration), from, design });
47
+ * await channel.send({ contact, code, purpose: "sign-in", language: "pt-PT", expiresAt });
48
+ */
49
+ export function createEmailChannel({ sender, from, design, logos = [], now = Date.now, }) {
50
+ const carried = { light: logos.some(({ id }) => id === "logo"), dark: logos.some(({ id }) => id === "logo-dark") };
51
+ return {
52
+ kind: "email",
53
+ async send({ contact, code, purpose, language, expiresAt }) {
54
+ if (contact.kind !== "email")
55
+ throw new Error(`the email channel can't send to a "${contact.kind}" contact`);
56
+ const words = language.toLowerCase().startsWith("pt") ? PORTUGUESE : ENGLISH;
57
+ const shown = code.replace(/(.{4})(?=.)/g, "$1 ");
58
+ const minutes = Math.max(1, Math.ceil((expiresAt.getTime() - now()) / 60_000));
59
+ const paragraphs = [words.lifetime(minutes), words.ignore, words.never];
60
+ const html = emailLayout({
61
+ language: words.language,
62
+ preview: words.heading[purpose],
63
+ eyebrow: words.eyebrow[purpose],
64
+ heading: words.heading[purpose],
65
+ rows: [{ label: words.label, value: shown }],
66
+ paragraphs,
67
+ closing: words.closing,
68
+ }, design, carried);
69
+ const text = [
70
+ words.heading[purpose],
71
+ "",
72
+ `${words.label}: ${shown}`,
73
+ "",
74
+ ...paragraphs,
75
+ "",
76
+ words.closing,
77
+ design.name,
78
+ ].join("\n");
79
+ await sender.send({
80
+ from,
81
+ to: contact.value,
82
+ subject: words.subject[purpose](design.name),
83
+ html,
84
+ text,
85
+ ...(logos.length > 0 ? { inlineImages: logos } : {}),
86
+ });
87
+ },
88
+ };
89
+ }
90
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/email-channel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAiBvE,MAAM,OAAO,GAAU;IACrB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE;QACP,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,OAAO,eAAe;QACtD,sBAAsB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,4BAA4B,OAAO,EAAE;QAC1E,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,OAAO,oBAAoB;KAC5D;IACD,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,SAAS,EAAE,cAAc,EAAE;IACvG,OAAO,EAAE;QACP,SAAS,EAAE,mBAAmB;QAC9B,sBAAsB,EAAE,sBAAsB;QAC9C,SAAS,EAAE,kBAAkB;KAC9B;IACD,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,sBAAsB,OAAO,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG;IAC/F,MAAM,EAAE,wFAAwF;IAChG,KAAK,EAAE,sCAAsC;IAC7C,OAAO,EAAE,eAAe;CACzB,CAAC;AAEF,MAAM,UAAU,GAAU;IACxB,QAAQ,EAAE,OAAO;IACjB,OAAO,EAAE;QACP,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,+BAA+B,OAAO,EAAE;QAChE,sBAAsB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,8BAA8B,OA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E,EAAE,OAAO,CAAC,KAAK;gBACjB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;gBAC5C,IAAI;gBACJ,IAAI;gBACJ,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACrD,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { EmailAddress } from "@sharadox/email-web-library/email-address/type";
2
+ import type { EmailDesign } from "@sharadox/email-web-library/email-layout/type";
3
+ import type { InlineImage } from "@sharadox/email-web-library/email-message/type";
4
+ import type { EmailSender } from "@sharadox/email-web-library/email-sender/type";
5
+ export interface EmailChannelOptions {
6
+ /** From email-web-library (`createAmazonSesSender`…). */
7
+ sender: EmailSender;
8
+ /** The sending address, for example `"Luis Pires Decor" <account@web.luispiresdecor.com>`. */
9
+ from: EmailAddress;
10
+ /** The company's name, logo size and signature (email-web-library's layout). */
11
+ design: EmailDesign;
12
+ /** The inline images "logo" and "logo-dark", when the design shows a logo. */
13
+ logos?: InlineImage[];
14
+ /** The clock, for how long the code still works (Date.now by default). */
15
+ now?: () => number;
16
+ }
17
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/email-channel/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEjF,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,MAAM,EAAE,WAAW,CAAC;IACpB,8FAA8F;IAC9F,IAAI,EAAE,YAAY,CAAC;IACnB,gFAAgF;IAChF,MAAM,EAAE,WAAW,CAAC;IACpB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,0EAA0E;IAC1E,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/email-channel/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,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 on the browser (the new token goes in its cookie); a contact
6
+ * with no account gets a sign-up ticket for choosing a username.
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, 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;AAK1G;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAgB,EAAE,EAAE,YAAY,GAClE,OAAO,CAAC,kBAAkB,CAAC,CA+B7B"}
@@ -0,0 +1,47 @@
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 a username. */
10
+ const SIGN_UP_SECONDS = 900;
11
+ /**
12
+ * The second step: the typed code. Guesses are limited per address group (and per request by `verifyCode`). With the
13
+ * right code, an account with that contact is signed in on the browser (the new token goes in its cookie); a contact
14
+ * with no account gets a sign-up ticket for choosing a username.
15
+ *
16
+ * @example
17
+ * const result = await finishSignIn(server, { requestId, code, address, token: cookie });
18
+ */
19
+ export async function finishSignIn(server, { requestId, code, address, token, now = Date.now() }) {
20
+ const rate = await limitRate(server.database, [{ key: `verification:${addressGroup(address)}`, rule: signInLimits(server).verificationsPerAddress }], { secret: deriveSecret(server.secret, "rate-limit"), now });
21
+ if (!rate.allowed)
22
+ return { status: "refused", reason: "rate-limit", retryAfterSeconds: rate.retryAfterSeconds };
23
+ const verification = await verifyCode(server.database, {
24
+ requestId,
25
+ code,
26
+ purpose: "sign-in",
27
+ pepper: deriveSecret(server.secret, "one-time-code"),
28
+ now,
29
+ });
30
+ if (!verification.valid)
31
+ return { status: "refused", reason: verification.reason };
32
+ const found = await findAccountByContact(server.database, verification.contact);
33
+ if (!found) {
34
+ const ticket = createTicket({ contact: verification.contact }, {
35
+ secret: deriveSecret(server.secret, "sign-up-ticket"),
36
+ purpose: "sign-up",
37
+ lifetimeSeconds: SIGN_UP_SECONDS,
38
+ now,
39
+ });
40
+ return { status: "sign-up", ticket };
41
+ }
42
+ if (!found.signIn)
43
+ return { status: "refused", reason: "unknown" };
44
+ const session = await signIn(server.database, { accountId: found.accountId, token, now });
45
+ return { status: "signed-in", accountId: found.accountId, token: session.token };
46
+ }
47
+ //# 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,6CAA6C,CAAC;AAG3E,kEAAkE;AAClE,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAqB,EACrB,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAgB;IAEnE,MAAM,IAAI,GAAG,MAAM,SAAS,CAC1B,MAAM,CAAC,QAAQ,EACf,CAAC,EAAE,GAAG,EAAE,gBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,uBAAuB,EAAE,CAAC,EACtG,EAAE,MAAM,EAAE,YAAY,CAAC,MA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C1F,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;AACnF,CAAC"}
@@ -0,0 +1,34 @@
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
+ /** Milliseconds since 1970 (now by default). */
11
+ now?: number;
12
+ }
13
+ type Refusal = Extract<CodeVerificationResult, {
14
+ valid: false;
15
+ }>["reason"];
16
+ export type SignInFinishResult = {
17
+ status: "signed-in";
18
+ accountId: string;
19
+ token: string;
20
+ }
21
+ /** No account has this contact yet: ask for a username, then `finishSignUp` with the ticket. */
22
+ | {
23
+ status: "sign-up";
24
+ ticket: string;
25
+ } | {
26
+ status: "refused";
27
+ reason: Refusal;
28
+ } | {
29
+ status: "refused";
30
+ reason: "rate-limit";
31
+ retryAfterSeconds: number;
32
+ };
33
+ export {};
34
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/sign-in-finish/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AAEnG,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,KAAK,OAAO,GAAG,OAAO,CAAC,sBAAsB,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;AAE3E,MAAM,MAAM,kBAAkB,GAC1B;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAC3D,gGAAgG;GAC9F;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACtC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/sign-in-finish/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
2
+ import type { SignInStart, SignInStartResult } from "@sharadox/account-web-library/sign-in-start/type";
3
+ /**
4
+ * The first step of signing in (and of signing up: they are the same): a code to the contact. In order, each check
5
+ * cheaper than what it protects:
6
+ * 1. a single-use proof of work;
7
+ * 2. a valid contact with a channel;
8
+ * 3. rate limits per contact, per address group (an IPv6 /64 is one visitor) and for everyone;
9
+ * 4. the channel's daily spending cap (past it, sending pauses: it never spends);
10
+ * 5. a new code, sent by `deliver` after answering.
11
+ * The answer never depends on whether an account exists, so nobody can probe for accounts.
12
+ *
13
+ * @example
14
+ * const result = await startSignIn(server, { contact, solution, address: clientAddress(request), language });
15
+ * if (result.status === "sent") after(result.deliver);
16
+ */
17
+ export declare function startSignIn(server: AccountServer, { contact, solution, address, language, now }: SignInStart): Promise<SignInStartResult>;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/sign-in-start/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAKvF,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kDAAkD,CAAC;AAEvG;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,aAAa,EACrB,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAgB,EAAE,EAAE,WAAW,GACtE,OAAO,CAAC,iBAAiB,CAAC,CAiD5B"}
@@ -0,0 +1,69 @@
1
+ import { addressGroup } from "@sharadox/protection-web-library/address-group";
2
+ import { limitRate } from "@sharadox/protection-web-library/rate-limit";
3
+ import { redeemSolution } from "@sharadox/protection-web-library/solution-redemption";
4
+ import { spendFromCap } from "@sharadox/protection-web-library/spending-cap";
5
+ import { signInLimits } from "@sharadox/account-web-library/account-server";
6
+ import { requestCode } from "@sharadox/account-web-library/code-request";
7
+ import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
8
+ import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
9
+ /**
10
+ * The first step of signing in (and of signing up: they are the same): a code to the contact. In order, each check
11
+ * cheaper than what it protects:
12
+ * 1. a single-use proof of work;
13
+ * 2. a valid contact with a channel;
14
+ * 3. rate limits per contact, per address group (an IPv6 /64 is one visitor) and for everyone;
15
+ * 4. the channel's daily spending cap (past it, sending pauses: it never spends);
16
+ * 5. a new code, sent by `deliver` after answering.
17
+ * The answer never depends on whether an account exists, so nobody can probe for accounts.
18
+ *
19
+ * @example
20
+ * const result = await startSignIn(server, { contact, solution, address: clientAddress(request), language });
21
+ * if (result.status === "sent") after(result.deliver);
22
+ */
23
+ export async function startSignIn(server, { contact, solution, address, language, now = Date.now() }) {
24
+ const limits = signInLimits(server);
25
+ const proof = await redeemSolution(server.database, solution, {
26
+ secret: deriveSecret(server.secret, "proof-of-work"),
27
+ now,
28
+ });
29
+ if (!proof.valid)
30
+ return { status: "refused", reason: "proof" };
31
+ let normalized;
32
+ try {
33
+ normalized = normalizeContact(contact);
34
+ }
35
+ catch {
36
+ return { status: "refused", reason: "contact" };
37
+ }
38
+ const channel = server.channels.find(({ kind }) => kind === normalized.kind);
39
+ if (!channel)
40
+ return { status: "refused", reason: "contact" };
41
+ const rate = await limitRate(server.database, [
42
+ { key: `contact:${normalized.kind}:${normalized.value}`, rule: limits.perContact },
43
+ { key: `address:${addressGroup(address)}`, rule: limits.perAddress },
44
+ { key: "global:sign-in", rule: limits.global },
45
+ ], { secret: deriveSecret(server.secret, "rate-limit"), now });
46
+ if (!rate.allowed)
47
+ return { status: "refused", reason: "rate-limit", retryAfterSeconds: rate.retryAfterSeconds };
48
+ const cap = await spendFromCap(server.database, { name: `${normalized.kind}-send`, limit: limits.dailySendsPerChannel, period: "day" }, { now });
49
+ if (!cap.allowed)
50
+ return { status: "refused", reason: "unavailable" };
51
+ const request = await requestCode(server.database, {
52
+ purpose: "sign-in",
53
+ contact: normalized,
54
+ pepper: deriveSecret(server.secret, "one-time-code"),
55
+ now,
56
+ });
57
+ return {
58
+ status: "sent",
59
+ requestId: request.requestId,
60
+ deliver: () => channel.send({
61
+ contact: request.contact,
62
+ code: request.code,
63
+ purpose: "sign-in",
64
+ language,
65
+ expiresAt: request.expiresAt,
66
+ }),
67
+ };
68
+ }
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/sign-in-start/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE5E,OAAO,EAAE,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AI;YAClB,OAAO,EAAE,SAAS;YAClB,QAAQ;YACR,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC;KACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Solution } from "@sharadox/protection-web-library/proof-of-work/type";
2
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
3
+ export interface SignInStart {
4
+ contact: Contact;
5
+ /** The browser's answer to `issueChallenge`. */
6
+ solution: Solution;
7
+ /** The client's IP address (web-library's `clientAddress`). */
8
+ address: string;
9
+ /** For the code's message. */
10
+ language: string;
11
+ /** Milliseconds since 1970 (now by default). */
12
+ now?: number;
13
+ }
14
+ export type SignInStartResult = {
15
+ status: "sent";
16
+ requestId: string;
17
+ /** Sends the code: call it after answering (Next.js `after()`), so the answer's timing reveals nothing. */
18
+ deliver: () => Promise<void>;
19
+ } | {
20
+ status: "refused";
21
+ reason: "proof" | "contact" | "unavailable";
22
+ } | {
23
+ status: "refused";
24
+ reason: "rate-limit";
25
+ retryAfterSeconds: number;
26
+ };
27
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/sign-in-start/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qDAAqD,CAAC;AACpF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,QAAQ,EAAE,QAAQ,CAAC;IACnB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,iBAAiB,GACzB;IACE,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,2GAA2G;IAC3G,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,GACD;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,aAAa,CAAA;CAAE,GAClE;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/sign-in-start/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
2
+ import type { SignUpFinish, SignUpFinishResult } from "@sharadox/account-web-library/sign-up-finish/type";
3
+ /**
4
+ * The last step for a new person: the username they chose, with the ticket proving their contact. Creates the
5
+ * account with that contact verified and signs it in. A taken or invalid username can be tried again with the same
6
+ * ticket while it lasts; a ticket can't make two accounts (the contact is then taken).
7
+ *
8
+ * @example
9
+ * const result = await finishSignUp(server, { ticket, username, token: cookie });
10
+ */
11
+ export declare function finishSignUp(server: AccountServer, { ticket, username, token, now }: SignUpFinish): Promise<SignUpFinishResult>;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,QAAQ,EAAE,KAAK,EAAE,GAAgB,EAAE,EAAE,YAAY,GAC1D,OAAO,CAAC,kBAAkB,CAAC,CAW7B"}
@@ -0,0 +1,27 @@
1
+ import { signIn } from "@sharadox/account-web-library/account-sign-in";
2
+ import { createPersonAccount } from "@sharadox/account-web-library/person-account";
3
+ import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
4
+ import { readTicket } from "@sharadox/account-web-library/signed-ticket";
5
+ /**
6
+ * The last step for a new person: the username they chose, with the ticket proving their contact. Creates the
7
+ * account with that contact verified and signs it in. A taken or invalid username can be tried again with the same
8
+ * ticket while it lasts; a ticket can't make two accounts (the contact is then taken).
9
+ *
10
+ * @example
11
+ * const result = await finishSignUp(server, { ticket, username, token: cookie });
12
+ */
13
+ export async function finishSignUp(server, { ticket, username, token, now = Date.now() }) {
14
+ const reading = readTicket(ticket, {
15
+ secret: deriveSecret(server.secret, "sign-up-ticket"),
16
+ purpose: "sign-up",
17
+ now,
18
+ });
19
+ if (!reading.valid)
20
+ return { status: "refused", reason: "ticket" };
21
+ const created = await createPersonAccount(server.database, { username, contact: reading.data.contact, now });
22
+ if (!created.created)
23
+ return { status: "refused", reason: created.reason };
24
+ const session = await signIn(server.database, { accountId: created.accountId, token, now });
25
+ return { status: "signed-in", accountId: created.accountId, token: session.token };
26
+ }
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AAGzE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAqB,EACrB,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAgB;IAE3D,MAAM,OAAO,GAAG,UAAU,CAAuB,MAAM,EAAE;QACvD,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC;QACrD,OAAO,EAAE,SAAS;QAClB,GAAG;KACJ,CAAC,CAAC;IACH,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnE,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7G,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IAC3E,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5F,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;AACrF,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { PersonAccountResult } from "@sharadox/account-web-library/person-account/type";
2
+ export interface SignUpFinish {
3
+ /** From `finishSignIn`'s `sign-up` answer. */
4
+ ticket: string;
5
+ username: string;
6
+ /** The browser's current session cookie, if any. */
7
+ token: string | undefined;
8
+ /** Milliseconds since 1970 (now by default). */
9
+ now?: number;
10
+ }
11
+ export type SignUpFinishResult = {
12
+ status: "signed-in";
13
+ accountId: string;
14
+ token: string;
15
+ } | {
16
+ status: "refused";
17
+ reason: "ticket" | Extract<PersonAccountResult, {
18
+ created: false;
19
+ }>["reason"];
20
+ };
21
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +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,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,KAAK,EAAE,MAAM,GAAG,SAAS,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/sign-up-finish/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import type { TicketOptions, TicketReading } from "@sharadox/account-web-library/signed-ticket/type";
2
+ /**
3
+ * A short-lived, signed ticket carrying data between two steps (a proved contact from the code step to the
4
+ * username step) without storing anything: the data can be read, but not changed or used for another purpose.
5
+ *
6
+ * @example
7
+ * const ticket = createTicket({ contact }, { secret, purpose: "sign-up", lifetimeSeconds: 900 });
8
+ */
9
+ export declare function createTicket(data: unknown, { secret, purpose, lifetimeSeconds, now }: TicketOptions & {
10
+ lifetimeSeconds: number;
11
+ }): string;
12
+ /**
13
+ * The data of a ticket made by `createTicket`, if it is intact, for this purpose, and not expired.
14
+ *
15
+ * @example
16
+ * const reading = readTicket<{ contact: Contact }>(ticket, { secret, purpose: "sign-up" });
17
+ */
18
+ export declare function readTicket<Data>(ticket: string, { secret, purpose, now }: TicketOptions): TicketReading<Data>;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/signed-ticket/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AAIrG;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,OAAO,EACb,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAgB,EAAE,EAAE,aAAa,GAAG;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,GAClG,MAAM,CAKR;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAC7B,MAAM,EAAE,MAAM,EACd,EAAE,MAAM,EAAE,OAAO,EAAE,GAAgB,EAAE,EAAE,aAAa,GACnD,aAAa,CAAC,IAAI,CAAC,CAerB"}
@@ -0,0 +1,35 @@
1
+ import { createHmac, timingSafeEqual } from "node:crypto";
2
+ const sign = (secret, body) => createHmac("sha256", secret).update(body).digest("base64url");
3
+ /**
4
+ * A short-lived, signed ticket carrying data between two steps (a proved contact from the code step to the
5
+ * username step) without storing anything: the data can be read, but not changed or used for another purpose.
6
+ *
7
+ * @example
8
+ * const ticket = createTicket({ contact }, { secret, purpose: "sign-up", lifetimeSeconds: 900 });
9
+ */
10
+ export function createTicket(data, { secret, purpose, lifetimeSeconds, now = Date.now() }) {
11
+ const body = Buffer.from(JSON.stringify({ data, purpose, expiresAt: now + lifetimeSeconds * 1000 })).toString("base64url");
12
+ return `${body}.${sign(secret, body)}`;
13
+ }
14
+ /**
15
+ * The data of a ticket made by `createTicket`, if it is intact, for this purpose, and not expired.
16
+ *
17
+ * @example
18
+ * const reading = readTicket<{ contact: Contact }>(ticket, { secret, purpose: "sign-up" });
19
+ */
20
+ export function readTicket(ticket, { secret, purpose, now = Date.now() }) {
21
+ const [body, signature, ...rest] = ticket.split(".");
22
+ if (!body || !signature || rest.length > 0)
23
+ return { valid: false, reason: "signature" };
24
+ const expected = Buffer.from(sign(secret, body));
25
+ const given = Buffer.from(signature);
26
+ if (expected.length !== given.length || !timingSafeEqual(expected, given))
27
+ return { valid: false, reason: "signature" };
28
+ const content = JSON.parse(Buffer.from(body, "base64url").toString());
29
+ if (content.purpose !== purpose)
30
+ return { valid: false, reason: "signature" };
31
+ if (content.expiresAt <= now)
32
+ return { valid: false, reason: "expired" };
33
+ return { valid: true, data: content.data };
34
+ }
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/signed-ticket/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG1D,MAAM,IAAI,GAAG,CAAC,MAAc,EAAE,IAAY,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAE7G;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAa,EACb,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAA+C;IAEnG,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,GAAG,eAAe,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAC3G,WAAW,CACZ,CAAC;IACF,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAA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ticket is for: a ticket for one purpose is refused for any other. */
5
+ purpose: string;
6
+ /** Milliseconds since 1970 (now by default). */
7
+ now?: number;
8
+ }
9
+ export type TicketReading<Data> = {
10
+ valid: true;
11
+ data: Data;
12
+ } | {
13
+ valid: false;
14
+ reason: "signature" | "expired";
15
+ };
16
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/signed-ticket/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,aAAa,CAAC,IAAI,IAAI;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/signed-ticket/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { MemoryDatabase } from "@sharadox/database-web-library/memory-database/type";
2
+ import type { AccountServerDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * A migrated account server database (account and protection tables) in memory, for tests of the sign-in flow.
5
+ *
6
+ * @example
7
+ * const memory = await createTestServerDatabase();
8
+ */
9
+ export declare function createTestServerDatabase(): Promise<MemoryDatabase<AccountServerDatabase>>;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/test-server/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAE1F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAGjG;;;;;GAKG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC,CAK/F"}
@@ -0,0 +1,16 @@
1
+ import { createMemoryDatabase } from "@sharadox/database-web-library/memory-database";
2
+ import { migrateProtection } from "@sharadox/protection-web-library/protection-migration";
3
+ import { migrateAccount } from "@sharadox/account-web-library/account-migration";
4
+ /**
5
+ * A migrated account server database (account and protection tables) in memory, for tests of the sign-in flow.
6
+ *
7
+ * @example
8
+ * const memory = await createTestServerDatabase();
9
+ */
10
+ export async function createTestServerDatabase() {
11
+ const memory = await createMemoryDatabase();
12
+ await migrateProtection(memory.database);
13
+ await migrateAccount(memory.database);
14
+ return memory;
15
+ }
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/test-server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AAEtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uDAAuD,CAAC;AAE1F,OAAO,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB;IAC5C,MAAM,MAAM,GAAG,MAAM,oBAAoB,EAAyB,CAAC;IACnE,MAAM,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sharadox/account-web-library",
3
- "version": "0.1.0-development.12",
3
+ "version": "0.1.0-development.18",
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",
@@ -41,8 +41,11 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@sharadox/database-web-library": "0.1.0-development.6",
44
+ "@sharadox/email-web-library": "^0.7.1",
45
+ "@sharadox/protection-web-library": "0.1.0-development.9",
44
46
  "@sharadox/web-library": "^0.11.1",
45
- "kysely": "^0.28.20"
47
+ "kysely": "^0.28.20",
48
+ "zod": "^4.6.7"
46
49
  },
47
50
  "devDependencies": {
48
51
  "@electric-sql/pglite": "0.5.16",