pgkiln 0.64.0 → 0.65.0

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 (44) hide show
  1. package/db/migrations/133_app_user_passkeys_stepup.sql +54 -0
  2. package/docs/apex-feature-parity.md +5 -3
  3. package/docs/guide/08-security.md +41 -6
  4. package/docs/guide/12-development.md +10 -4
  5. package/docs/guide/13-rest-api.md +4 -0
  6. package/package.json +1 -1
  7. package/public/app.js +63 -0
  8. package/public/builder.js +1 -62
  9. package/src/account-mfa.ts +94 -3
  10. package/src/api.ts +9 -2
  11. package/src/builder/api.ts +3 -1
  12. package/src/builder/components.ts +1 -0
  13. package/src/builder/login-page.ts +10 -5
  14. package/src/builder/rest-modules.ts +1 -1
  15. package/src/builder/security.ts +3 -19
  16. package/src/builder/shared.ts +5 -3
  17. package/src/i18n/ar.ts +31 -0
  18. package/src/i18n/cs.ts +31 -0
  19. package/src/i18n/da.ts +31 -0
  20. package/src/i18n/de.ts +31 -0
  21. package/src/i18n/el.ts +31 -0
  22. package/src/i18n/es.ts +31 -0
  23. package/src/i18n/fi.ts +31 -0
  24. package/src/i18n/fr.ts +31 -0
  25. package/src/i18n/he.ts +31 -0
  26. package/src/i18n/it.ts +31 -0
  27. package/src/i18n/ja.ts +31 -0
  28. package/src/i18n/ko.ts +31 -0
  29. package/src/i18n/nb.ts +31 -0
  30. package/src/i18n/pl.ts +31 -0
  31. package/src/i18n/pt.ts +31 -0
  32. package/src/i18n/ru.ts +31 -0
  33. package/src/i18n/sv.ts +31 -0
  34. package/src/i18n/tr.ts +31 -0
  35. package/src/i18n/uk.ts +31 -0
  36. package/src/i18n/zh.ts +31 -0
  37. package/src/i18n.ts +62 -0
  38. package/src/metadata.ts +8 -2
  39. package/src/mfa.ts +18 -13
  40. package/src/runtime/account.ts +6 -3
  41. package/src/runtime/authz.ts +23 -4
  42. package/src/runtime/routes.ts +11 -1
  43. package/src/runtime/two-step.ts +379 -72
  44. package/src/webauthn.ts +20 -0
package/src/webauthn.ts CHANGED
@@ -16,6 +16,26 @@ export const b64url = (b: Buffer | Uint8Array) => Buffer.from(b).toString('base6
16
16
  export const unb64url = (s: string) => Buffer.from(String(s ?? ''), 'base64url');
17
17
  export const newChallenge = () => b64url(randomBytes(32));
18
18
 
19
+ const CHALLENGE_SECONDS = 300;
20
+ type WithState = { state: Record<string, unknown> };
21
+
22
+ /** A one-time challenge kept in the session (for this purpose only), or null when there is none or it expired. */
23
+ export function takeChallenge(s: WithState, purpose: 'create' | 'get'): string | null {
24
+ try {
25
+ const p = JSON.parse(String(s.state.__PK ?? ''));
26
+ delete s.state.__PK;
27
+ return p && p.purpose === purpose && Date.now() - Number(p.at) < CHALLENGE_SECONDS * 1000 && typeof p.c === 'string' ? p.c : null;
28
+ } catch {
29
+ delete s.state.__PK;
30
+ return null;
31
+ }
32
+ }
33
+ export function giveChallenge(s: WithState, purpose: 'create' | 'get'): string {
34
+ const c = newChallenge();
35
+ s.state.__PK = JSON.stringify({ c, purpose, at: Date.now() });
36
+ return c;
37
+ }
38
+
19
39
  // ------------------------------------------------------------------ CBOR (RFC 8949), only what WebAuthn uses
20
40
 
21
41
  type Cbor = number | bigint | string | Buffer | boolean | null | undefined | Cbor[] | Map<Cbor, Cbor>;