@tstdl/base 0.93.178 → 0.93.180

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 (207) hide show
  1. package/api/response.js +4 -3
  2. package/api/server/gateway.js +9 -3
  3. package/audit/auditor.d.ts +1 -2
  4. package/audit/drizzle/{0000_lumpy_thunderball.sql → 0000_shallow_elektra.sql} +1 -1
  5. package/audit/drizzle/meta/0000_snapshot.json +2 -2
  6. package/audit/drizzle/meta/_journal.json +2 -2
  7. package/authentication/README.md +87 -42
  8. package/authentication/authentication.api.d.ts +392 -53
  9. package/authentication/authentication.api.js +133 -28
  10. package/authentication/client/api.client.d.ts +3 -3
  11. package/authentication/client/api.client.js +4 -4
  12. package/authentication/client/authentication.service.d.ts +93 -23
  13. package/authentication/client/authentication.service.js +113 -28
  14. package/authentication/client/http-client.middleware.d.ts +1 -1
  15. package/authentication/client/http-client.middleware.js +5 -4
  16. package/authentication/client/module.d.ts +1 -1
  17. package/authentication/client/module.js +2 -2
  18. package/authentication/errors/index.d.ts +1 -1
  19. package/authentication/errors/index.js +1 -1
  20. package/authentication/errors/password-requirements.error.d.ts +5 -0
  21. package/authentication/errors/{secret-requirements.error.js → password-requirements.error.js} +2 -2
  22. package/authentication/models/authentication-password.model.d.ts +8 -0
  23. package/authentication/models/{authentication-credentials.model.js → authentication-password.model.js} +11 -17
  24. package/authentication/models/authentication-session.model.d.ts +0 -2
  25. package/authentication/models/authentication-session.model.js +1 -7
  26. package/authentication/models/authentication-totp-recovery-code.model.d.ts +6 -0
  27. package/authentication/models/authentication-totp-recovery-code.model.js +34 -0
  28. package/authentication/models/authentication-totp.model.d.ts +19 -0
  29. package/authentication/models/authentication-totp.model.js +51 -0
  30. package/authentication/models/authentication-used-totp-token.model.d.ts +5 -0
  31. package/authentication/models/authentication-used-totp-token.model.js +32 -0
  32. package/authentication/models/index.d.ts +6 -3
  33. package/authentication/models/index.js +6 -3
  34. package/authentication/models/{init-secret-reset-data.model.d.ts → init-password-reset-data.model.d.ts} +3 -3
  35. package/authentication/models/{init-secret-reset-data.model.js → init-password-reset-data.model.js} +5 -5
  36. package/authentication/models/password-check-result.model.d.ts +3 -0
  37. package/authentication/models/{secret-check-result.model.js → password-check-result.model.js} +6 -6
  38. package/authentication/models/subject.model.d.ts +0 -6
  39. package/authentication/models/subject.model.js +0 -6
  40. package/authentication/models/token.model.d.ts +16 -2
  41. package/authentication/server/authentication-ancillary.service.d.ts +6 -6
  42. package/authentication/server/authentication-ancillary.service.js +1 -1
  43. package/authentication/server/authentication-password-requirements.validator.d.ts +55 -0
  44. package/authentication/server/{authentication-secret-requirements.validator.js → authentication-password-requirements.validator.js} +22 -22
  45. package/authentication/server/authentication.api-controller.d.ts +55 -27
  46. package/authentication/server/authentication.api-controller.js +214 -39
  47. package/authentication/server/authentication.audit.d.ts +42 -5
  48. package/authentication/server/authentication.service.d.ts +182 -93
  49. package/authentication/server/authentication.service.js +628 -206
  50. package/authentication/server/drizzle/{0000_soft_tag.sql → 0000_odd_echo.sql} +59 -13
  51. package/authentication/server/drizzle/meta/0000_snapshot.json +345 -32
  52. package/authentication/server/drizzle/meta/_journal.json +2 -2
  53. package/authentication/server/helper.d.ts +16 -16
  54. package/authentication/server/helper.js +33 -34
  55. package/authentication/server/index.d.ts +1 -1
  56. package/authentication/server/index.js +1 -1
  57. package/authentication/server/module.d.ts +2 -2
  58. package/authentication/server/module.js +4 -2
  59. package/authentication/server/schemas.d.ts +11 -7
  60. package/authentication/server/schemas.js +7 -3
  61. package/authentication/tests/authentication-password-requirements.validator.test.js +29 -0
  62. package/authentication/tests/authentication.api-controller.test.js +49 -15
  63. package/authentication/tests/authentication.client-error-handling.test.js +3 -2
  64. package/authentication/tests/authentication.client-middleware.test.js +5 -5
  65. package/authentication/tests/authentication.client-service-methods.test.js +28 -14
  66. package/authentication/tests/authentication.client-service-refresh.test.js +7 -6
  67. package/authentication/tests/authentication.client-service.test.js +10 -8
  68. package/authentication/tests/authentication.service.test.js +37 -29
  69. package/authentication/tests/authentication.test-ancillary-service.d.ts +1 -1
  70. package/authentication/tests/authentication.test-ancillary-service.js +1 -1
  71. package/authentication/tests/brute-force-protection.test.js +211 -0
  72. package/authentication/tests/helper.test.js +25 -21
  73. package/authentication/tests/password-requirements.error.test.js +14 -0
  74. package/authentication/tests/remember.api.test.js +22 -14
  75. package/authentication/tests/remember.service.test.js +23 -16
  76. package/authentication/tests/subject.service.test.js +2 -2
  77. package/authentication/tests/suspended-subject.test.d.ts +1 -0
  78. package/authentication/tests/suspended-subject.test.js +120 -0
  79. package/authentication/tests/totp.enrollment.test.d.ts +1 -0
  80. package/authentication/tests/totp.enrollment.test.js +123 -0
  81. package/authentication/tests/totp.login.test.d.ts +1 -0
  82. package/authentication/tests/totp.login.test.js +213 -0
  83. package/authentication/tests/totp.recovery-codes.test.d.ts +1 -0
  84. package/authentication/tests/totp.recovery-codes.test.js +97 -0
  85. package/authentication/tests/totp.status.test.d.ts +1 -0
  86. package/authentication/tests/totp.status.test.js +72 -0
  87. package/circuit-breaker/postgres/drizzle/{0000_cooing_korath.sql → 0000_same_captain_cross.sql} +1 -1
  88. package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +2 -2
  89. package/circuit-breaker/postgres/drizzle/meta/_journal.json +2 -2
  90. package/cryptography/cryptography.d.ts +336 -0
  91. package/cryptography/cryptography.js +328 -0
  92. package/cryptography/index.d.ts +4 -0
  93. package/cryptography/index.js +4 -0
  94. package/{utils → cryptography}/jwt.d.ts +22 -4
  95. package/{utils → cryptography}/jwt.js +36 -18
  96. package/cryptography/module.d.ts +35 -0
  97. package/cryptography/module.js +148 -0
  98. package/cryptography/tests/cryptography.test.d.ts +1 -0
  99. package/cryptography/tests/cryptography.test.js +175 -0
  100. package/cryptography/tests/jwt.test.d.ts +1 -0
  101. package/cryptography/tests/jwt.test.js +54 -0
  102. package/cryptography/tests/modern.test.d.ts +1 -0
  103. package/cryptography/tests/modern.test.js +105 -0
  104. package/cryptography/tests/module.test.d.ts +1 -0
  105. package/cryptography/tests/module.test.js +100 -0
  106. package/cryptography/tests/totp.test.d.ts +1 -0
  107. package/cryptography/tests/totp.test.js +108 -0
  108. package/cryptography/totp.d.ts +96 -0
  109. package/cryptography/totp.js +123 -0
  110. package/document-management/server/drizzle/{0000_curious_nighthawk.sql → 0000_sharp_scream.sql} +21 -21
  111. package/document-management/server/drizzle/meta/0000_snapshot.json +22 -22
  112. package/document-management/server/drizzle/meta/_journal.json +2 -2
  113. package/document-management/server/services/document-file.service.js +1 -1
  114. package/errors/errors.localization.d.ts +2 -2
  115. package/errors/errors.localization.js +2 -2
  116. package/errors/index.d.ts +1 -0
  117. package/errors/index.js +1 -0
  118. package/errors/too-many-requests.error.d.ts +5 -0
  119. package/errors/too-many-requests.error.js +7 -0
  120. package/examples/api/authentication.js +5 -5
  121. package/examples/api/custom-authentication.js +4 -3
  122. package/file/server/mime-type.js +1 -1
  123. package/http/http-body.d.ts +1 -0
  124. package/http/http-body.js +3 -0
  125. package/image-service/imgproxy/imgproxy-image-service.d.ts +0 -1
  126. package/image-service/imgproxy/imgproxy-image-service.js +9 -27
  127. package/key-value-store/postgres/drizzle/{0000_shocking_slipstream.sql → 0000_moaning_calypso.sql} +1 -1
  128. package/key-value-store/postgres/drizzle/meta/0000_snapshot.json +2 -2
  129. package/key-value-store/postgres/drizzle/meta/_journal.json +2 -2
  130. package/lock/postgres/drizzle/{0000_busy_tattoo.sql → 0000_nappy_wraith.sql} +1 -1
  131. package/lock/postgres/drizzle/meta/0000_snapshot.json +2 -2
  132. package/lock/postgres/drizzle/meta/_journal.json +2 -2
  133. package/logger/formatters/json.js +1 -1
  134. package/logger/formatters/pretty-print.js +1 -1
  135. package/mail/drizzle/{0000_numerous_the_watchers.sql → 0000_cultured_quicksilver.sql} +2 -2
  136. package/mail/drizzle/meta/0000_snapshot.json +4 -4
  137. package/mail/drizzle/meta/_journal.json +2 -9
  138. package/notification/server/drizzle/{0000_wise_pyro.sql → 0000_new_tenebrous.sql} +6 -6
  139. package/notification/server/drizzle/meta/0000_snapshot.json +7 -7
  140. package/notification/server/drizzle/meta/_journal.json +2 -2
  141. package/notification/tests/notification-flow.test.js +1 -8
  142. package/notification/tests/notification-type.service.test.js +3 -3
  143. package/openid-connect/oidc.service.js +2 -3
  144. package/orm/data-types/common.js +1 -1
  145. package/orm/server/drizzle/schema-converter.js +9 -4
  146. package/orm/server/encryption.js +1 -1
  147. package/orm/server/module.d.ts +0 -1
  148. package/orm/server/module.js +0 -4
  149. package/orm/server/repository.d.ts +2 -1
  150. package/orm/server/repository.js +7 -10
  151. package/orm/tests/encryption.test.js +4 -6
  152. package/orm/tests/repository-extra-coverage.test.js +0 -2
  153. package/orm/tests/repository-regression.test.js +0 -3
  154. package/package.json +9 -8
  155. package/password/README.md +1 -1
  156. package/password/have-i-been-pwned.js +1 -1
  157. package/rate-limit/postgres/drizzle/{0000_watery_rage.sql → 0000_serious_sauron.sql} +1 -1
  158. package/rate-limit/postgres/drizzle/meta/0000_snapshot.json +2 -2
  159. package/rate-limit/postgres/drizzle/meta/_journal.json +2 -2
  160. package/rate-limit/postgres/postgres-rate-limiter.d.ts +1 -1
  161. package/rate-limit/postgres/postgres-rate-limiter.js +1 -1
  162. package/rate-limit/rate-limiter.d.ts +1 -1
  163. package/rpc/tests/rpc.integration.test.js +25 -31
  164. package/supports.d.ts +1 -0
  165. package/supports.js +1 -0
  166. package/task-queue/postgres/drizzle/{0000_faithful_daimon_hellstrom.sql → 0000_dark_ronan.sql} +5 -5
  167. package/task-queue/postgres/drizzle/meta/0000_snapshot.json +10 -10
  168. package/task-queue/postgres/drizzle/meta/_journal.json +2 -9
  169. package/task-queue/postgres/task-queue.js +2 -2
  170. package/task-queue/tests/coverage-enhancement.test.js +2 -2
  171. package/test/drizzle/{0000_natural_cannonball.sql → 0000_organic_gamora.sql} +2 -2
  172. package/test/drizzle/meta/0000_snapshot.json +3 -4
  173. package/test/drizzle/meta/_journal.json +2 -9
  174. package/testing/integration-setup.d.ts +7 -3
  175. package/testing/integration-setup.js +119 -96
  176. package/utils/alphabet.d.ts +1 -0
  177. package/utils/alphabet.js +1 -0
  178. package/utils/base32.d.ts +4 -0
  179. package/utils/base32.js +49 -0
  180. package/utils/base64.d.ts +0 -2
  181. package/utils/base64.js +6 -70
  182. package/utils/equals.d.ts +13 -3
  183. package/utils/equals.js +29 -9
  184. package/utils/index.d.ts +1 -2
  185. package/utils/index.js +1 -2
  186. package/utils/random.d.ts +1 -0
  187. package/utils/random.js +14 -8
  188. package/authentication/errors/secret-requirements.error.d.ts +0 -5
  189. package/authentication/models/authentication-credentials.model.d.ts +0 -10
  190. package/authentication/models/secret-check-result.model.d.ts +0 -3
  191. package/authentication/server/authentication-secret-requirements.validator.d.ts +0 -55
  192. package/authentication/tests/authentication-ancillary.service.test.js +0 -13
  193. package/authentication/tests/authentication-secret-requirements.validator.test.js +0 -29
  194. package/authentication/tests/secret-requirements.error.test.js +0 -14
  195. package/mail/drizzle/0001_married_tarantula.sql +0 -12
  196. package/mail/drizzle/meta/0001_snapshot.json +0 -69
  197. package/orm/server/tokens.d.ts +0 -1
  198. package/orm/server/tokens.js +0 -2
  199. package/task-queue/postgres/drizzle/0001_rapid_infant_terrible.sql +0 -16
  200. package/task-queue/postgres/drizzle/meta/0001_snapshot.json +0 -753
  201. package/test/drizzle/0001_closed_the_captain.sql +0 -2
  202. package/test/drizzle/meta/0001_snapshot.json +0 -117
  203. package/utils/cryptography.d.ts +0 -137
  204. package/utils/cryptography.js +0 -201
  205. /package/authentication/tests/{authentication-ancillary.service.test.d.ts → authentication-password-requirements.validator.test.d.ts} +0 -0
  206. /package/authentication/tests/{authentication-secret-requirements.validator.test.d.ts → brute-force-protection.test.d.ts} +0 -0
  207. /package/authentication/tests/{secret-requirements.error.test.d.ts → password-requirements.error.test.d.ts} +0 -0
@@ -26,15 +26,52 @@ export type AuthenticationAuditEvents = {
26
26
  impersonatedSubjectId: string;
27
27
  };
28
28
  'unimpersonate-success': {};
29
- 'change-secret-success': {};
30
- 'change-secret-failure': {
29
+ 'change-password-success': {};
30
+ 'change-password-failure': {
31
31
  subjectInput: SubjectInput;
32
32
  resolvedSubjectId: string | null;
33
33
  };
34
- 'init-secret-reset': {};
35
- 'reset-secret-success': {};
36
- 'reset-secret-failure': {
34
+ 'init-password-reset': {};
35
+ 'reset-password-success': {};
36
+ 'reset-password-failure': {
37
37
  reason: string;
38
38
  };
39
+ 'rate-limit-exceeded': {
40
+ type: 'ip' | 'subject';
41
+ resource: string;
42
+ action: string;
43
+ };
39
44
  'invalidate-all-sessions': {};
45
+ 'invalidate-all-other-sessions': {
46
+ currentSessionId: string;
47
+ };
48
+ 'totp-enroll-init': {
49
+ subjectId: string;
50
+ };
51
+ 'totp-enroll-success': {};
52
+ 'totp-enroll-failure': {
53
+ reason: string;
54
+ };
55
+ 'totp-disable-success': {};
56
+ 'totp-disable-failure': {
57
+ reason: string;
58
+ };
59
+ 'totp-verify-failure': {
60
+ reason: string;
61
+ };
62
+ 'totp-token-reused': {
63
+ token: string;
64
+ };
65
+ 'totp-recovery-code-used': {};
66
+ 'recovery-codes-regenerated': {
67
+ count: number;
68
+ };
69
+ 'recovery-login-success': {
70
+ sessionId: string;
71
+ remember: boolean;
72
+ };
73
+ 'recovery-login-failure': {
74
+ subjectInput: SubjectInput;
75
+ resolvedSubjectId: string | null;
76
+ };
40
77
  };
@@ -1,10 +1,10 @@
1
1
  /** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
2
2
  import { Auditor } from '../../audit/index.js';
3
- import { afterResolve, type AfterResolve } from '../../injector/index.js';
4
- import type { BinaryData, Record } from '../../types/index.js';
5
- import { AuthenticationSession, Subject, type RefreshToken, type SecretCheckResult, type SecretResetToken, type Token } from '../models/index.js';
3
+ import { type Argon2Params, type TotpHashAlgorithm } from '../../cryptography/index.js';
4
+ import type { Record, TypedOmit } from '../../types/index.js';
5
+ import { AuthenticationSession, AuthenticationTotp, Subject, type PasswordCheckResult, type PasswordResetToken, type RefreshToken, type Token, type TotpChallengeToken } from '../models/index.js';
6
6
  import type { SubjectInput } from '../types.js';
7
- import { type SecretTestResult } from './authentication-secret-requirements.validator.js';
7
+ import { type PasswordTestResult } from './authentication-password-requirements.validator.js';
8
8
  /**
9
9
  * Data for creating a token.
10
10
  *
@@ -33,15 +33,6 @@ export type CreateTokenData<AdditionalTokenPayload extends Record> = {
33
33
  timestamp?: number;
34
34
  };
35
35
  export declare class AuthenticationServiceOptions {
36
- /**
37
- * Secrets used for signing tokens and refreshTokens.
38
- * If single secret is provided, multiple secrets are derived internally.
39
- */
40
- secret: string | BinaryData<ArrayBuffer> | {
41
- tokenSigningSecret: Uint8Array<ArrayBuffer>;
42
- refreshTokenSigningSecret: Uint8Array<ArrayBuffer>;
43
- secretResetTokenSigningSecret: Uint8Array<ArrayBuffer>;
44
- };
45
36
  /**
46
37
  * Token version, forces refresh on mismatch (useful if payload changes).
47
38
  *
@@ -67,24 +58,79 @@ export declare class AuthenticationServiceOptions {
67
58
  */
68
59
  rememberRefreshTokenTimeToLive?: number;
69
60
  /**
70
- * How long a secret reset token is valid in milliseconds.
61
+ * How long a password reset token is valid in milliseconds.
71
62
  *
72
63
  * @default 10 minutes
73
64
  */
74
- secretResetTokenTimeToLive?: number;
65
+ passwordResetTokenTimeToLive?: number;
75
66
  /**
76
- * Number of iterations for password hashing.
67
+ * How long a TOTP challenge token is valid in milliseconds.
77
68
  *
78
- * @default 250000
69
+ * @default 5 minutes
79
70
  */
80
- hashIterations?: number;
71
+ totpChallengeTokenTimeToLive?: number;
81
72
  /**
82
- * Number of iterations for signing secrets derivation.
83
- *
84
- * @default 500000
73
+ * Options for brute force protection.
74
+ */
75
+ bruteForceProtection?: BruteForceProtectionOptions;
76
+ /**
77
+ * TOTP issuer name.
85
78
  */
86
- signingSecretsDerivationIterations?: number;
79
+ totpIssuer?: string;
80
+ /**
81
+ * Options for password hashing.
82
+ */
83
+ passwordHashing?: PasswordHashingOptions;
84
+ /**
85
+ * Options for TOTP.
86
+ */
87
+ totp?: TotpHashingOptions;
87
88
  }
89
+ /**
90
+ * Options for password hashing.
91
+ */
92
+ export type PasswordHashingOptions = {
93
+ algorithm: TypedOmit<Argon2Params, 'nonce'>;
94
+ };
95
+ /**
96
+ * Options for TOTP.
97
+ */
98
+ export type TotpHashingOptions = {
99
+ codeHashAlgorithm: TotpHashAlgorithm;
100
+ recoveryCodeHashOptions: {
101
+ algorithm: TypedOmit<Argon2Params, 'nonce'>;
102
+ length: number;
103
+ };
104
+ };
105
+ /**
106
+ * Options for brute force protection.
107
+ */
108
+ export type BruteForceProtectionOptions = {
109
+ /**
110
+ * Burst capacity for subject rate limit.
111
+ *
112
+ * @default 10
113
+ */
114
+ subjectBurstCapacity?: number;
115
+ /**
116
+ * Refill interval for subject rate limit in milliseconds.
117
+ *
118
+ * @default 1800000 (30 minutes)
119
+ */
120
+ subjectRefillInterval?: number;
121
+ /**
122
+ * Burst capacity for ip rate limit.
123
+ *
124
+ * @default 20
125
+ */
126
+ ipBurstCapacity?: number;
127
+ /**
128
+ * Refill interval for ip rate limit in milliseconds.
129
+ *
130
+ * @default 300000 (5 minutes)
131
+ */
132
+ ipRefillInterval?: number;
133
+ };
88
134
  /**
89
135
  * Result of an authentication attempt.
90
136
  */
@@ -109,7 +155,17 @@ export type TokenResult<AdditionalTokenPayload extends Record> = {
109
155
  impersonatorRefreshToken?: string;
110
156
  impersonatorRefreshTokenExpiration?: number;
111
157
  };
112
- export type SetCredentialsOptions = {
158
+ export type LoginSuccessResult<AdditionalTokenPayload extends Record> = {
159
+ type: 'success';
160
+ result: TokenResult<AdditionalTokenPayload>;
161
+ lowRecoveryCodesWarning?: boolean;
162
+ };
163
+ export type LoginTotpResult = {
164
+ type: 'totp';
165
+ challengeToken: string;
166
+ };
167
+ export type LoginResult<AdditionalTokenPayload extends Record> = LoginSuccessResult<AdditionalTokenPayload> | LoginTotpResult;
168
+ export type SetPasswordOptions = {
113
169
  /**
114
170
  * Skip validation for password strength.
115
171
  *
@@ -133,24 +189,15 @@ type CreateRefreshTokenResult = {
133
189
  salt: Uint8Array<ArrayBuffer>;
134
190
  hash: Uint8Array<ArrayBuffer>;
135
191
  };
192
+ export declare const DEFAULT_TOTP_OPTIONS: TotpHashingOptions;
136
193
  /**
137
194
  * Handles authentication on server side.
138
195
  *
139
- * Can be used to:
140
- * - Set credentials
141
- * - Authenticate
142
- * - Get token
143
- * - End session
144
- * - Refresh token
145
- * - Impersonate/unimpersonate
146
- * - Reset secret
147
- * - Check secret
148
- *
149
196
  * @template AdditionalTokenPayload Type of additional token payload
150
197
  * @template AuthenticationData Type of additional authentication data
151
- * @template AdditionalInitSecretResetData Type of additional secret reset data
198
+ * @template AdditionalInitPasswordResetData Type of additional password reset data
152
199
  */
153
- export declare class AuthenticationService<AdditionalTokenPayload extends Record = Record<never>, AuthenticationData = void, AdditionalInitSecretResetData = void> implements AfterResolve {
200
+ export declare class AuthenticationService<AdditionalTokenPayload extends Record = Record<never>, AuthenticationData = void, AdditionalInitPasswordResetData = void> {
154
201
  #private;
155
202
  readonly hooks: {
156
203
  beforeLogin: import("../../utils/async-hook/async-hook.js").AsyncHook<{
@@ -159,10 +206,10 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
159
206
  afterLogin: import("../../utils/async-hook/async-hook.js").AsyncHook<{
160
207
  subject: Subject;
161
208
  }, never, unknown>;
162
- beforeChangeSecret: import("../../utils/async-hook/async-hook.js").AsyncHook<{
209
+ beforeChangePassword: import("../../utils/async-hook/async-hook.js").AsyncHook<{
163
210
  subject: Subject;
164
211
  }, never, unknown>;
165
- afterChangeSecret: import("../../utils/async-hook/async-hook.js").AsyncHook<{
212
+ afterChangePassword: import("../../utils/async-hook/async-hook.js").AsyncHook<{
166
213
  subject: Subject;
167
214
  }, never, unknown>;
168
215
  };
@@ -170,34 +217,31 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
170
217
  private readonly tokenTimeToLive;
171
218
  private readonly refreshTokenTimeToLive;
172
219
  private readonly rememberRefreshTokenTimeToLive;
173
- private readonly secretResetTokenTimeToLive;
174
- private derivedTokenSigningSecret;
175
- private derivedRefreshTokenSigningSecret;
176
- private derivedSecretResetTokenSigningSecret;
177
- /** @internal */
178
- [afterResolve](): Promise<void>;
179
- /**
180
- * Initializes the service.
181
- * Derives signing secrets if necessary.
182
- *
183
- * @internal
184
- */
185
- initialize(): Promise<void>;
220
+ private readonly passwordResetTokenTimeToLive;
221
+ private readonly totpOptions;
222
+ private readonly hashDeriveOptions;
223
+ getTotpOptions(): TotpHashingOptions;
186
224
  /**
187
- * Sets the credentials for a subject.
188
- * This method should not be exposed to the public API without an authenticated current password or secret reset token check.
189
- * @param subject The subject to set the credentials for.
190
- * @param secret The secret to set.
191
- * @param options Options for setting the credentials.
225
+ * Sets the password for a subject.
226
+ * This method should not be exposed to the public API without an authenticated current password or password reset token check.
227
+ * @param subject The subject to set the password for.
228
+ * @param password The password to set.
229
+ * @param options Options for setting the password.
192
230
  */
193
- setCredentials(subject: Subject, secret: string, options?: SetCredentialsOptions): Promise<void>;
231
+ setPassword(subject: Subject, password: string, options?: SetPasswordOptions): Promise<void>;
194
232
  /**
195
- * Authenticates a subject with a secret.
233
+ * Authenticates a subject with a password.
196
234
  * @param subject The subject to authenticate.
197
- * @param secret The secret to authenticate with.
235
+ * @param password The password to authenticate with.
198
236
  * @returns The result of the authentication.
199
237
  */
200
- authenticate(subject: SubjectInput, secret: string): Promise<AuthenticationResult>;
238
+ authenticateWithPassword(subject: SubjectInput, password: string): Promise<AuthenticationResult>;
239
+ /**
240
+ * Ensures that a subject is not suspended.
241
+ * @param subject The subject to check.
242
+ * @throws {ForbiddenError} If the subject is suspended.
243
+ */
244
+ ensureNotSuspended(subject: Subject): void;
201
245
  /**
202
246
  * Gets a token for a subject.
203
247
  * @param subject The subject to get the token for.
@@ -212,13 +256,14 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
212
256
  /**
213
257
  * Logs in a subject.
214
258
  * @param subjectInput The subject to log in.
215
- * @param secret The secret to log in with.
259
+ * @param password The password to log in with.
216
260
  * @param data Additional authentication data.
217
261
  * @param auditor Auditor for auditing.
218
262
  * @param remember Whether to remember the session.
219
- * @returns Token
263
+ * @returns Token or TOTP challenge.
220
264
  */
221
- login(subjectInput: SubjectInput, secret: string, data: AuthenticationData, auditor: Auditor, remember?: boolean): Promise<TokenResult<AdditionalTokenPayload>>;
265
+ login(subjectInput: SubjectInput, password: string, data: AuthenticationData, auditor: Auditor, remember?: boolean): Promise<LoginResult<AdditionalTokenPayload>>;
266
+ loginAlreadyValidatedSubject(subject: Subject, data: AuthenticationData, auditor: Auditor, remember: boolean): Promise<LoginSuccessResult<AdditionalTokenPayload>>;
222
267
  /**
223
268
  * Ends a session.
224
269
  * @param sessionId The id of the session to end.
@@ -232,6 +277,14 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
232
277
  * @param auditor Auditor for auditing.
233
278
  */
234
279
  invalidateAllSessions(tenantId: string, subjectId: string, auditor: Auditor): Promise<void>;
280
+ /**
281
+ * Invalidates all sessions for a subject except the current one.
282
+ * @param tenantId The tenant id of the subject.
283
+ * @param subjectId The id of the subject.
284
+ * @param currentSessionId The id of the current session to keep.
285
+ * @param auditor Auditor for auditing.
286
+ */
287
+ invalidateAllOtherSessions(tenantId: string, subjectId: string, currentSessionId: string, auditor: Auditor): Promise<void>;
235
288
  /**
236
289
  * Lists all sessions for a subject.
237
290
  * @param tenantId The tenant id of the subject.
@@ -263,6 +316,18 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
263
316
  refresh(refreshToken: string, authenticationData: AuthenticationData, options: {
264
317
  omitImpersonator?: boolean;
265
318
  } | undefined, auditor: Auditor): Promise<TokenResult<AdditionalTokenPayload>>;
319
+ /**
320
+ * Refreshes a token.
321
+ * @param refreshToken The refresh token to use.
322
+ * @param authenticationData Additional authentication data.
323
+ * @param options Options for refreshing the token.
324
+ * @param auditor Auditor for auditing.
325
+ * @returns The token result.
326
+ * @throws {InvalidTokenError} If the refresh token is invalid.
327
+ */
328
+ refreshAlreadyValidatedToken(validatedRefreshToken: RefreshToken, authenticationData: AuthenticationData, options: {
329
+ omitImpersonator?: boolean;
330
+ } | undefined, auditor: Auditor): Promise<TokenResult<AdditionalTokenPayload>>;
266
331
  /**
267
332
  * Impersonates a subject.
268
333
  * @param impersonatorToken The token of the impersonator.
@@ -277,53 +342,54 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
277
342
  /**
278
343
  * Unimpersonates a subject.
279
344
  * @param impersonatorRefreshToken The refresh token of the impersonator.
345
+ * @param tokenString The token of the impersonated subject to end the session.
280
346
  * @param authenticationData Additional authentication data.
281
347
  * @param auditor Auditor for auditing.
282
348
  * @returns The token result.
283
349
  */
284
- unimpersonate(impersonatorRefreshToken: string, authenticationData: AuthenticationData, auditor: Auditor): Promise<TokenResult<AdditionalTokenPayload>>;
350
+ unimpersonate(impersonatorRefreshToken: string, tokenString: string, authenticationData: AuthenticationData, auditor: Auditor): Promise<TokenResult<AdditionalTokenPayload>>;
285
351
  /**
286
- * Initializes a secret reset. This usually involves sending an email for verification.
287
- * @param subject The subject to reset the secret for.
288
- * @param data Additional data for the secret reset.
352
+ * Initializes a password reset. This usually involves sending an email for verification.
353
+ * @param subject The subject to reset the password for.
354
+ * @param data Additional data for the password reset.
289
355
  * @param auditor Auditor for auditing.
290
356
  * @throws {NotImplementedError} If no ancillary service is registered.
291
357
  */
292
- initSecretReset(subject: SubjectInput, data: AdditionalInitSecretResetData, auditor: Auditor): Promise<void>;
358
+ initPasswordReset(subject: SubjectInput, data: AdditionalInitPasswordResetData, auditor: Auditor): Promise<void>;
293
359
  /**
294
- * Changes a subject's secret.
295
- * @param subjectInput The subject to change the secret for.
296
- * @param currentSecret The current secret.
297
- * @param newSecret The new secret.
360
+ * Changes a subject's password.
361
+ * @param subjectInput The subject to change the password for.
362
+ * @param currentPassword The current password.
363
+ * @param newPassword The new password.
298
364
  * @param auditor Auditor for auditing.
299
365
  */
300
- changeSecret(subjectInput: SubjectInput, currentSecret: string, newSecret: string, auditor: Auditor): Promise<void>;
366
+ changePassword(subjectInput: SubjectInput, currentPassword: string, newPassword: string, auditor: Auditor): Promise<void>;
301
367
  /**
302
- * Resets a secret.
303
- * @param tokenString The secret reset token.
304
- * @param newSecret The new secret.
368
+ * Resets a password.
369
+ * @param tokenString The password reset token.
370
+ * @param newPassword The new password.
305
371
  * @param auditor Auditor for auditing.
306
372
  * @throws {InvalidTokenError} If the token is invalid.
307
373
  */
308
- resetSecret(tokenString: string, newSecret: string, auditor: Auditor): Promise<void>;
374
+ resetPassword(tokenString: string, newPassword: string, auditor: Auditor): Promise<void>;
309
375
  /**
310
- * Checks a secret against the requirements.
311
- * @param secret The secret to check.
376
+ * Checks a password against the requirements.
377
+ * @param password The password to check.
312
378
  * @returns The result of the check.
313
379
  */
314
- checkSecret(secret: string): Promise<SecretCheckResult>;
380
+ checkPassword(password: string): Promise<PasswordCheckResult>;
315
381
  /**
316
- * Tests a secret against the requirements.
317
- * @param secret The secret to test.
382
+ * Tests a password against the requirements.
383
+ * @param password The password to test.
318
384
  * @returns The result of the test.
319
385
  */
320
- testSecret(secret: string): Promise<SecretTestResult>;
386
+ testPassword(password: string): Promise<PasswordTestResult>;
321
387
  /**
322
- * Validates a secret against the requirements. Throws an error if the requirements are not met.
323
- * @param secret The secret to validate.
324
- * @throws {SecretRequirementsError} If the secret does not meet the requirements.
388
+ * Validates a password against the requirements. Throws an error if the requirements are not met.
389
+ * @param password The password to validate.
390
+ * @throws {PasswordRequirementsError} If the password does not meet the requirements.
325
391
  */
326
- validateSecret(secret: string): Promise<void>;
392
+ validatePassword(password: string): Promise<void>;
327
393
  /**
328
394
  * Validates a token.
329
395
  * @param token The token to validate.
@@ -339,12 +405,12 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
339
405
  */
340
406
  validateRefreshToken(token: string): Promise<RefreshToken>;
341
407
  /**
342
- * Validates a secret reset token.
343
- * @param token The secret reset token to validate.
344
- * @returns The validated secret reset token.
345
- * @throws {InvalidTokenError} If the secret reset token is invalid.
408
+ * Validates a password reset token.
409
+ * @param token The password reset token to validate.
410
+ * @returns The validated password reset token.
411
+ * @throws {InvalidTokenError} If the password reset token is invalid.
346
412
  */
347
- validateSecretResetToken(token: string): Promise<SecretResetToken>;
413
+ validatePasswordResetToken(token: string): Promise<PasswordResetToken>;
348
414
  /**
349
415
  * Tries to resolve a subject.
350
416
  * @param subject The subject to resolve.
@@ -387,8 +453,31 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
387
453
  tenantId?: string;
388
454
  subject: string;
389
455
  }): Promise<Subject>;
390
- private createSecretResetToken;
391
- private deriveSigningSecrets;
456
+ private createPasswordResetToken;
392
457
  private getHash;
458
+ tryGetTotp(tenantId: string, subjectId: string): Promise<AuthenticationTotp | undefined>;
459
+ getTotpStatus(tenantId: string, subjectId: string): Promise<{
460
+ active: boolean;
461
+ }>;
462
+ initEnrollTotp(tenantId: string, subjectId: string, auditor: Auditor): Promise<{
463
+ secret: string;
464
+ uri: string;
465
+ }>;
466
+ completeEnrollTotp(tenantId: string, subjectId: string, token: string, auditor: Auditor): Promise<{
467
+ recoveryCodes: string[];
468
+ }>;
469
+ disableTotp(tenantId: string, subjectId: string, token: string, auditor: Auditor): Promise<void>;
470
+ disableTotpWithRecoveryCode(tenantId: string, subjectId: string, recoveryCode: string, auditor: Auditor): Promise<void>;
471
+ regenerateRecoveryCodes(tenantId: string, subjectId: string, token: string, auditor: Auditor, options?: {
472
+ invalidateOtherSessions?: boolean;
473
+ }): Promise<{
474
+ recoveryCodes: string[];
475
+ }>;
476
+ loginVerifyTotp(challengeTokenString: string, token: string, auditor: Auditor): Promise<LoginSuccessResult<AdditionalTokenPayload>>;
477
+ loginRecovery(challengeTokenString: string, recoveryCode: string, auditor: Auditor): Promise<LoginSuccessResult<AdditionalTokenPayload>>;
478
+ validateTotpChallengeToken(tokenString: string): Promise<TotpChallengeToken<AuthenticationData>>;
479
+ private createTotpChallengeToken;
480
+ private verifyAndUseRecoveryCode;
481
+ private verifyAndRecordTotpToken;
393
482
  }
394
483
  export {};