@nacre.work/api 0.17.5 → 0.19.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.
package/dist/errors.d.ts CHANGED
@@ -58,5 +58,24 @@ export declare function forbidden(instance: string, requestId: string, detail: s
58
58
  */
59
59
  export declare function notAdministeredHere(instance: string, requestId: string): Problem;
60
60
  export declare function badRequest(instance: string, requestId: string, detail: string): Problem;
61
+ /**
62
+ * The password gate is full.
63
+ *
64
+ * `core/passwords.ts` bounds how many scrypt calls run at once — the pool is
65
+ * libuv's and is shared with DNS and file I/O, so an unbounded one stops the
66
+ * rest of the API on a name lookup — and past its queue bound it raises rather
67
+ * than queueing further. Its own header says the caller answers 503, "the
68
+ * honest response to 'this process cannot verify a password right now'".
69
+ *
70
+ * **503 and never 401.** Nothing was decided about the credential, and
71
+ * answering "not valid" to a request that was never checked is a lie the client
72
+ * will act on — a person told their password is wrong changes it. It is not an
73
+ * oracle either: it depends on how loaded the process is and not at all on
74
+ * whether the account exists.
75
+ *
76
+ * One builder because four routes hash and each would otherwise have its own
77
+ * wording, and the wording is what a client matches on.
78
+ */
79
+ export declare function tooBusy(instance: string, requestId: string): Problem;
61
80
  export declare function internal(instance: string, requestId: string): Problem;
62
81
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B;AAED,qBAAa,OAAQ,SAAQ,K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pE;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAWrE"}
package/dist/errors.js CHANGED
@@ -109,6 +109,34 @@ export function badRequest(instance, requestId, detail) {
109
109
  requestId,
110
110
  });
111
111
  }
112
+ /**
113
+ * The password gate is full.
114
+ *
115
+ * `core/passwords.ts` bounds how many scrypt calls run at once — the pool is
116
+ * libuv's and is shared with DNS and file I/O, so an unbounded one stops the
117
+ * rest of the API on a name lookup — and past its queue bound it raises rather
118
+ * than queueing further. Its own header says the caller answers 503, "the
119
+ * honest response to 'this process cannot verify a password right now'".
120
+ *
121
+ * **503 and never 401.** Nothing was decided about the credential, and
122
+ * answering "not valid" to a request that was never checked is a lie the client
123
+ * will act on — a person told their password is wrong changes it. It is not an
124
+ * oracle either: it depends on how loaded the process is and not at all on
125
+ * whether the account exists.
126
+ *
127
+ * One builder because four routes hash and each would otherwise have its own
128
+ * wording, and the wording is what a client matches on.
129
+ */
130
+ export function tooBusy(instance, requestId) {
131
+ return new Problem({
132
+ type: uri('unavailable'),
133
+ title: 'Service unavailable',
134
+ status: 503,
135
+ detail: 'Too many passwords are being verified at once. Try again shortly.',
136
+ instance,
137
+ requestId,
138
+ });
139
+ }
112
140
  export function internal(instance, requestId) {
113
141
  return new Problem({
114
142
  type: uri('internal'),
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,MAAM,OAAO,OAAQ,SAAQ,KAAK;IACvB,IAAI,CAAQ;IACZ,KAAK,CAAQ;IACb,MAAM,CAAQ;IACd,MAAM,CAAQ;IACd,QAAQ,CAAQ;IAChB,SAAS,CAAQ;IAE1B,YAAY,IAAiB;QAC3B,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;QACrC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA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AA0E;QAC1E,qCAAqC;QACrC,MAAM,EAAE,qCAAqC;QAC7C,QAAQ;QACR,SAAS;KACV,CAAC,CAAA;AACJ,CAAC"}
package/dist/login.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { KeyObject } from 'node:crypto';
2
2
  import type { Pool } from 'pg';
3
+ import type { WebAuthnAssertionOptions } from './second-factor.js';
3
4
  export interface LoginRequest {
4
5
  readonly email: string;
5
6
  readonly password: string;
@@ -41,9 +42,84 @@ export interface LoginDeps {
41
42
  readonly accessTokenTtl: number;
42
43
  readonly refreshTokenTtl: number;
43
44
  readonly role?: string;
45
+ /**
46
+ * The second factor, when the deployment has a key to seal one with.
47
+ *
48
+ * Absent, `login` issues tokens as it always did — which is what every
49
+ * existing installation gets, and why this is optional rather than a
50
+ * constructor argument every caller had to learn about.
51
+ */
52
+ readonly secondFactors?: SecondFactorGate;
44
53
  /** Injected so tests are not asked to wait for wall-clock expiry. */
45
54
  readonly now?: () => Date;
46
55
  }
56
+ /**
57
+ * What `login` needs from the second factor, and no more.
58
+ *
59
+ * A narrow port rather than the class: this file is the sign-in path and has no
60
+ * business being able to enrol anything. It also keeps the cycle out — the
61
+ * store imports nothing from here.
62
+ */
63
+ export interface SecondFactorGate {
64
+ required(orgId: string, userId: string): Promise<boolean>;
65
+ verify(orgId: string, userId: string, code: string): Promise<boolean>;
66
+ beginWebAuthnAssertion(orgId: string, userId: string): Promise<WebAuthnAssertionOptions | undefined>;
67
+ verifyWebAuthnAssertion(orgId: string, userId: string, response: WebAuthnProof): Promise<boolean>;
68
+ }
69
+ /** What a browser hands back from `navigator.credentials.get`. */
70
+ export interface WebAuthnProof {
71
+ readonly credentialId: string;
72
+ readonly authenticatorData: Uint8Array;
73
+ readonly clientDataJSON: Uint8Array;
74
+ readonly signature: Uint8Array;
75
+ readonly challenge: string;
76
+ }
77
+ /**
78
+ * The proof the second half of a sign-in takes, and it is a union on purpose.
79
+ *
80
+ * A six-digit code and an assertion are not two spellings of one argument: the
81
+ * first is a string a person read off a screen and the second is a signature
82
+ * over an origin. Making the parameter a union means a caller has to say which
83
+ * it holds, and a handler that forgot the new kind is a compile error rather
84
+ * than a route that silently only ever accepts the old one.
85
+ */
86
+ export type SecondFactorProof = {
87
+ readonly kind: 'code';
88
+ readonly code: string;
89
+ } | {
90
+ readonly kind: 'webauthn';
91
+ readonly response: WebAuthnProof;
92
+ };
93
+ /**
94
+ * Sign-in has three outcomes now, and a union rather than a nullable pair.
95
+ *
96
+ * Making it a union turns every existing call site into a compile error until
97
+ * it says which one it means — the alternative is a second optional field that
98
+ * a caller can ignore, and ignoring it here means issuing a session to somebody
99
+ * who has not produced their second factor.
100
+ */
101
+ export type LoginOutcome = {
102
+ readonly kind: 'tokens';
103
+ readonly tokens: Tokens;
104
+ } | {
105
+ readonly kind: 'second-factor';
106
+ /** Short-lived, single-purpose, and useless as an access token. */
107
+ readonly challenge: string;
108
+ readonly expiresIn: number;
109
+ };
110
+ /**
111
+ * What `changePassword` answers.
112
+ *
113
+ * A union rather than a boolean for the same reason `LoginOutcome` is one: a
114
+ * caller that cannot tell "the current password was wrong" from "there is no
115
+ * such account" answers both the same way, and only one of those is something
116
+ * a person can act on.
117
+ */
118
+ export type ChangePasswordOutcome = {
119
+ readonly kind: 'changed';
120
+ readonly tokens: Tokens;
121
+ readonly email: string;
122
+ } | 'wrong-password' | 'no-user';
47
123
  export declare class Login {
48
124
  private readonly deps;
49
125
  constructor(deps: LoginDeps);
@@ -55,7 +131,96 @@ export declare class Login {
55
131
  * `undefined` for every reason it can fail. The caller turns it into one
56
132
  * `401` with one message.
57
133
  */
58
- login(request: LoginRequest): Promise<Tokens | undefined>;
134
+ login(request: LoginRequest): Promise<LoginOutcome | undefined>;
135
+ /**
136
+ * The token that says "this password was correct", and nothing else.
137
+ *
138
+ * Its audience is not the API's, so it is refused everywhere an access token
139
+ * is accepted — a challenge that could be presented as a bearer token would
140
+ * be a way past the factor it exists to demand. Five minutes, which is longer
141
+ * than reading a phone and shorter than walking away from one.
142
+ *
143
+ * Not stored, and it does not need to be: replaying it needs the *code* as
144
+ * well, the code is single-use through `last_step`, and a person holding both
145
+ * has finished signing in anyway.
146
+ */
147
+ private challenge;
148
+ /**
149
+ * The second half of a sign-in: a challenge and a code, for a session.
150
+ *
151
+ * `undefined` for every reason it can fail — an expired challenge, one signed
152
+ * for something else, a wrong code, a disabled account — and the caller turns
153
+ * all of them into one refusal. Which of the four it was is not something a
154
+ * client needs and is something an attacker would use.
155
+ */
156
+ completeSecondFactor(challenge: string, proof: SecondFactorProof): Promise<Tokens | undefined>;
157
+ /**
158
+ * The options a browser needs for the assertion half of a sign-in.
159
+ *
160
+ * It takes the same challenge `login` handed back, and that is the whole
161
+ * reason this method is here rather than on the store: the JWT is what says
162
+ * who is signing in, and it is signed by a key the store does not have. An
163
+ * endpoint that took a user id instead would answer "which authenticators
164
+ * does this person hold" to anybody who asked.
165
+ *
166
+ * `undefined` where the challenge is not one of ours, where it has expired,
167
+ * and where the person has no key enrolled — one refusal, for the reason
168
+ * every refusal on this path is one.
169
+ */
170
+ beginSecondFactorWebAuthn(challenge: string): Promise<WebAuthnAssertionOptions | undefined>;
171
+ /**
172
+ * Who a sign-in challenge names, or nothing.
173
+ *
174
+ * One reader for the two halves that consult it, because a challenge whose
175
+ * audience is checked on one path and not the other is an access token
176
+ * accepted as a challenge — which is exactly what `challengeAudience` exists
177
+ * to stop.
178
+ */
179
+ private readChallenge;
180
+ /**
181
+ * A person changes their own password, having proved the current one.
182
+ *
183
+ * ## Why this is not `POST /v1/users/{id}/password`
184
+ *
185
+ * That one is an **administrator** setting somebody else's, and it returns
186
+ * the plaintext because a generated password has to be shown once. This is
187
+ * the person themselves choosing one, so nothing is returned and nothing is
188
+ * generated — and it needs no administrator at all, which on a
189
+ * single-administrator installation is the whole point. Recovery closed the
190
+ * case where the password is *forgotten*; this closes the ordinary one, where
191
+ * it is merely known to somebody else.
192
+ *
193
+ * ## What it costs to get in
194
+ *
195
+ * The current password, always, and that is the only proof this takes. A
196
+ * session is not enough: changing the password is the first thing somebody
197
+ * with a stolen session does, and it is what locks the owner out. It is the
198
+ * same reasoning that makes removing a second factor take a current code.
199
+ *
200
+ * A second factor is deliberately *not* asked for here. It bounds sign-in,
201
+ * and this caller has already signed in and just produced the password
202
+ * besides; demanding a code would mean somebody whose phone is lost cannot
203
+ * change a password they know is compromised.
204
+ *
205
+ * ## Every other session ends, and this one is replaced
206
+ *
207
+ * The reason to change a password is usually that somebody else knows it, and
208
+ * leaving their refresh token alive would leave them signed in. So all of them
209
+ * are revoked — including this caller's, since there is no way to tell one
210
+ * refresh token from another with only an access token in hand — and a fresh
211
+ * pair comes back with the answer. Signing the person out of the browser they
212
+ * did it in would read as a failure.
213
+ */
214
+ changePassword(orgId: string, userId: string, current: string, next: string): Promise<ChangePasswordOutcome>;
215
+ private userById;
216
+ /**
217
+ * What verifies the challenge this same object signed.
218
+ *
219
+ * With a shared secret the key is its own verifier; with Ed25519 the public
220
+ * half comes out of the private one, so nothing new has to be configured for
221
+ * a round trip that never leaves this process.
222
+ */
223
+ private get verificationKey();
59
224
  /**
60
225
  * Find the one user this login is about, without saying how many nearly were.
61
226
  *
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,IAAI,CAAA;AAyC1C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,oDAAoD;IACpD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAA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gBtB;;;;;;OAMG;IACH,OAAO,KAAK,eAAe,GAG1B;IAED;;;;;;;;OAQG;YACW,IAAI;YAuBJ,YAAY;YAaZ,SAAS;YAYT,MAAM;IAgBpB;;;;;;;;OAQG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA+FzD,sDAAsD;IAChD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAkB7C;;;;;;;;;;;OAWG;YACW,YAAY;IAe1B;;;;;;OAMG;YACW,KAAK;CAoDpB"}
package/dist/login.js CHANGED
@@ -1,6 +1,6 @@
1
- import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
1
+ import { createHash, createPublicKey, randomBytes, timingSafeEqual } from 'node:crypto';
2
2
  import { hashPassword, needsRehash, spendVerificationTime, verifyPassword, whileAuthenticating, withOrg, } from '@nacre.work/core';
3
- import { SignJWT } from 'jose';
3
+ import { jwtVerify, SignJWT } from 'jose';
4
4
  /**
5
5
  * Email and password sign-in.
6
6
  *
@@ -38,6 +38,16 @@ import { SignJWT } from 'jose';
38
38
  * exists.
39
39
  */
40
40
  const ACCESS_MIN_SECONDS = 60;
41
+ /** Long enough to read a phone, short enough not to survive walking away. */
42
+ const CHALLENGE_SECONDS = 300;
43
+ /**
44
+ * The challenge's audience, which is deliberately not the API's.
45
+ *
46
+ * An access token and a challenge are both JWTs signed by the same key, so the
47
+ * only thing keeping one from being presented as the other is what they claim
48
+ * to be for.
49
+ */
50
+ const challengeAudience = (audience) => `${audience}/second-factor`;
41
51
  const digest = (token) => createHash('sha256').update(token).digest('hex');
42
52
  /** 32 bytes from the CSPRNG. Opaque — it is looked up, never parsed. */
43
53
  const mint = () => randomBytes(32).toString('base64url');
@@ -79,7 +89,204 @@ export class Login {
79
89
  const rehashed = await hashPassword(request.password);
80
90
  await withOrg(this.deps.pool, candidate.org_id, (client) => client.query('UPDATE users SET password_hash = $1 WHERE id = $2', [rehashed, candidate.id]), this.scope).catch(() => undefined);
81
91
  }
82
- return this.issue(candidate, undefined);
92
+ /*
93
+ * The password was right. Whether that is a session depends on the factor.
94
+ *
95
+ * The check is here rather than in the handler because there is exactly one
96
+ * path from a correct password to a token, and a check beside it is a check
97
+ * the next path forgets. `required` answers false for an installation with
98
+ * no key configured, so nothing changes for a deployment that has not asked
99
+ * for this.
100
+ */
101
+ if (this.deps.secondFactors !== undefined && (await this.deps.secondFactors.required(candidate.org_id, candidate.id))) {
102
+ return { kind: 'second-factor', challenge: await this.challenge(candidate), expiresIn: CHALLENGE_SECONDS };
103
+ }
104
+ return { kind: 'tokens', tokens: await this.issue(candidate, undefined) };
105
+ }
106
+ /**
107
+ * The token that says "this password was correct", and nothing else.
108
+ *
109
+ * Its audience is not the API's, so it is refused everywhere an access token
110
+ * is accepted — a challenge that could be presented as a bearer token would
111
+ * be a way past the factor it exists to demand. Five minutes, which is longer
112
+ * than reading a phone and shorter than walking away from one.
113
+ *
114
+ * Not stored, and it does not need to be: replaying it needs the *code* as
115
+ * well, the code is single-use through `last_step`, and a person holding both
116
+ * has finished signing in anyway.
117
+ */
118
+ async challenge(user) {
119
+ const now = this.clock;
120
+ return new SignJWT({ org: user.org_id, purpose: 'second-factor' })
121
+ .setProtectedHeader({
122
+ alg: this.deps.algorithm ?? 'HS256',
123
+ ...(this.deps.keyId === undefined ? {} : { kid: this.deps.keyId }),
124
+ })
125
+ .setSubject(user.id)
126
+ .setIssuer(this.deps.issuer)
127
+ .setAudience(challengeAudience(this.deps.audience))
128
+ .setIssuedAt(Math.floor(now.getTime() / 1000))
129
+ .setExpirationTime(Math.floor(now.getTime() / 1000) + CHALLENGE_SECONDS)
130
+ .sign(this.deps.key);
131
+ }
132
+ /**
133
+ * The second half of a sign-in: a challenge and a code, for a session.
134
+ *
135
+ * `undefined` for every reason it can fail — an expired challenge, one signed
136
+ * for something else, a wrong code, a disabled account — and the caller turns
137
+ * all of them into one refusal. Which of the four it was is not something a
138
+ * client needs and is something an attacker would use.
139
+ */
140
+ async completeSecondFactor(challenge, proof) {
141
+ const gate = this.deps.secondFactors;
142
+ if (gate === undefined)
143
+ return undefined;
144
+ const who = await this.readChallenge(challenge);
145
+ if (who === undefined)
146
+ return undefined;
147
+ const { orgId, userId } = who;
148
+ const proved = proof.kind === 'code'
149
+ ? await gate.verify(orgId, userId, proof.code)
150
+ : await gate.verifyWebAuthnAssertion(orgId, userId, proof.response);
151
+ if (!proved)
152
+ return undefined;
153
+ // Re-read the row rather than trusting the challenge for anything but
154
+ // identity: five minutes is long enough to be disabled, and the role in the
155
+ // token has to be the one the database holds now.
156
+ const user = await this.userById(orgId, userId);
157
+ if (user === undefined || user.disabled_at !== null)
158
+ return undefined;
159
+ return this.issue(user, undefined);
160
+ }
161
+ /**
162
+ * The options a browser needs for the assertion half of a sign-in.
163
+ *
164
+ * It takes the same challenge `login` handed back, and that is the whole
165
+ * reason this method is here rather than on the store: the JWT is what says
166
+ * who is signing in, and it is signed by a key the store does not have. An
167
+ * endpoint that took a user id instead would answer "which authenticators
168
+ * does this person hold" to anybody who asked.
169
+ *
170
+ * `undefined` where the challenge is not one of ours, where it has expired,
171
+ * and where the person has no key enrolled — one refusal, for the reason
172
+ * every refusal on this path is one.
173
+ */
174
+ async beginSecondFactorWebAuthn(challenge) {
175
+ const gate = this.deps.secondFactors;
176
+ if (gate === undefined)
177
+ return undefined;
178
+ const who = await this.readChallenge(challenge);
179
+ if (who === undefined)
180
+ return undefined;
181
+ return gate.beginWebAuthnAssertion(who.orgId, who.userId);
182
+ }
183
+ /**
184
+ * Who a sign-in challenge names, or nothing.
185
+ *
186
+ * One reader for the two halves that consult it, because a challenge whose
187
+ * audience is checked on one path and not the other is an access token
188
+ * accepted as a challenge — which is exactly what `challengeAudience` exists
189
+ * to stop.
190
+ */
191
+ async readChallenge(challenge) {
192
+ try {
193
+ const { payload } = await jwtVerify(challenge, this.verificationKey, {
194
+ issuer: this.deps.issuer,
195
+ audience: challengeAudience(this.deps.audience),
196
+ algorithms: [this.deps.algorithm ?? 'HS256'],
197
+ currentDate: this.clock,
198
+ });
199
+ if (payload.purpose !== 'second-factor' || typeof payload.sub !== 'string' || typeof payload.org !== 'string') {
200
+ return undefined;
201
+ }
202
+ return { orgId: payload.org, userId: payload.sub };
203
+ }
204
+ catch {
205
+ return undefined;
206
+ }
207
+ }
208
+ /**
209
+ * A person changes their own password, having proved the current one.
210
+ *
211
+ * ## Why this is not `POST /v1/users/{id}/password`
212
+ *
213
+ * That one is an **administrator** setting somebody else's, and it returns
214
+ * the plaintext because a generated password has to be shown once. This is
215
+ * the person themselves choosing one, so nothing is returned and nothing is
216
+ * generated — and it needs no administrator at all, which on a
217
+ * single-administrator installation is the whole point. Recovery closed the
218
+ * case where the password is *forgotten*; this closes the ordinary one, where
219
+ * it is merely known to somebody else.
220
+ *
221
+ * ## What it costs to get in
222
+ *
223
+ * The current password, always, and that is the only proof this takes. A
224
+ * session is not enough: changing the password is the first thing somebody
225
+ * with a stolen session does, and it is what locks the owner out. It is the
226
+ * same reasoning that makes removing a second factor take a current code.
227
+ *
228
+ * A second factor is deliberately *not* asked for here. It bounds sign-in,
229
+ * and this caller has already signed in and just produced the password
230
+ * besides; demanding a code would mean somebody whose phone is lost cannot
231
+ * change a password they know is compromised.
232
+ *
233
+ * ## Every other session ends, and this one is replaced
234
+ *
235
+ * The reason to change a password is usually that somebody else knows it, and
236
+ * leaving their refresh token alive would leave them signed in. So all of them
237
+ * are revoked — including this caller's, since there is no way to tell one
238
+ * refresh token from another with only an access token in hand — and a fresh
239
+ * pair comes back with the answer. Signing the person out of the browser they
240
+ * did it in would read as a failure.
241
+ */
242
+ async changePassword(orgId, userId, current, next) {
243
+ const row = await withOrg(this.deps.pool, orgId, async (client) => {
244
+ const { rows } = await client.query(`SELECT id, org_id, role, email, password_hash, disabled_at
245
+ FROM users WHERE org_id = $1 AND id = $2`, [orgId, userId]);
246
+ return rows[0];
247
+ }, this.scope);
248
+ // A disabled account and one with no password set are the same answer as an
249
+ // account that is not there. Nobody reaching here is any of the three —
250
+ // they hold a token this row issued — so this is a guard rather than a
251
+ // branch anybody sees.
252
+ if (row === undefined || row.disabled_at !== null || row.password_hash === null)
253
+ return 'no-user';
254
+ // Outside the transaction on purpose: scrypt at OWASP's minimum takes long
255
+ // enough that holding a row lock across it is a lock held on arithmetic.
256
+ if (!(await verifyPassword(current, row.password_hash)))
257
+ return 'wrong-password';
258
+ const hash = await hashPassword(next);
259
+ const tokens = await withOrg(this.deps.pool, orgId, async (client) => {
260
+ await client.query('UPDATE users SET password_hash = $3 WHERE org_id = $1 AND id = $2', [orgId, userId, hash]);
261
+ // Every one, and before the new pair is inserted so the pair this
262
+ // returns is not revoked by the statement that ends the old sessions.
263
+ await client.query(`UPDATE refresh_tokens SET revoked_at = now()
264
+ WHERE org_id = $1 AND user_id = $2 AND revoked_at IS NULL`, [orgId, userId]);
265
+ // A new family. Carrying the old one would put the session that
266
+ // replaces every other one in the same chain as the tokens just
267
+ // revoked.
268
+ return this.issue(row, undefined, client);
269
+ }, this.scope);
270
+ return { kind: 'changed', tokens, email: row.email };
271
+ }
272
+ async userById(orgId, userId) {
273
+ return withOrg(this.deps.pool, orgId, async (client) => {
274
+ const { rows } = await client.query(`SELECT id, org_id, role, password_hash, disabled_at
275
+ FROM users WHERE org_id = $1 AND id = $2`, [orgId, userId]);
276
+ return rows[0];
277
+ }, this.scope);
278
+ }
279
+ /**
280
+ * What verifies the challenge this same object signed.
281
+ *
282
+ * With a shared secret the key is its own verifier; with Ed25519 the public
283
+ * half comes out of the private one, so nothing new has to be configured for
284
+ * a round trip that never leaves this process.
285
+ */
286
+ get verificationKey() {
287
+ if (this.deps.key instanceof Uint8Array)
288
+ return this.deps.key;
289
+ return createPublicKey(this.deps.key);
83
290
  }
84
291
  /**
85
292
  * Find the one user this login is about, without saying how many nearly were.
package/dist/login.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"login.js","sourceRoot":"","sources":["../src/login.ts"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