axiam-sdk 1.0.0-alpha28 → 1.0.0-alpha34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanich/axiam) — Access eXtended Identity and Authorization Management.
10
10
 
11
+ **Platform documentation:** <https://ilpanich.github.io/axiam/> — getting started, the authorization model, the OAuth2/OIDC surface, and the operations guides. This README covers the SDK; the site covers the server it talks to.
12
+
11
13
  ## Package identity
12
14
 
13
15
  - **npm package:** `axiam-sdk`
@@ -17,7 +19,7 @@ Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanic
17
19
 
18
20
  ## Contract conformance
19
21
 
20
- This SDK conforms to CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19, §20, §21, §22 (including §6.1 mTLS
22
+ This SDK conforms to CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19, §20, §21, §22, §23 (including §6.1 mTLS
21
23
  client certificates, the §10.1 minimum local-verification set, the §12 OIDC/SSO
22
24
  relying-party helpers, and the §13 `verifyWebhook` signature verifier).
23
25
 
@@ -707,6 +709,117 @@ strings.
707
709
 
708
710
  See `examples/express-oidc-login.ts` for a complete, runnable example.
709
711
 
712
+ ## OPAQUE (CONTRACT.md §23)
713
+
714
+ `loginOpaque` proves the password without sending it. What crosses the wire is
715
+ a blinded group element and a MAC, neither useful without the account's
716
+ registration record **and** the tenant's OPRF seed.
717
+
718
+ ```ts
719
+ const result = await client.loginOpaque('alice', 'correct horse battery staple');
720
+ ```
721
+
722
+ It takes the same arguments as `login` and returns the same `LoginResult`, MFA
723
+ branch included, so switching a tenant to OPAQUE needs no change to how the
724
+ result is handled.
725
+
726
+ ### Falling back — and when not to
727
+
728
+ Fall back to `login()` when the tenant does not offer OPAQUE, or when this
729
+ installation cannot perform it. Both are a `NetworkError`, deliberately **not**
730
+ an `AuthError`, so neither can be mistaken for a bad password:
731
+
732
+ ```ts
733
+ let result;
734
+ try {
735
+ result = await client.loginOpaque(user, password);
736
+ } catch (err) {
737
+ if (!(err instanceof NetworkError)) throw err; // <- not a fallback case
738
+ result = await client.login(user, password);
739
+ }
740
+ ```
741
+
742
+ The `if` is the important line. **Any other error is a failed login**, and
743
+ retrying it over `login()` would hand the plaintext to a server that just
744
+ failed to prove it holds the record.
745
+
746
+ ### What this buys, and what it does not
747
+
748
+ OPAQUE closes holes TLS 1.3 does not:
749
+
750
+ - a TLS-terminating reverse proxy, ingress controller, CDN or service mesh sees
751
+ every plaintext password today; under OPAQUE it sees a blinded group element;
752
+ - an accidental request-body log, a heap dump or a crash reporter can no longer
753
+ capture a plaintext password, because the server never has one;
754
+ - **a stolen record database is not offline-crackable on its own.** Recovering a
755
+ password additionally requires the tenant's OPRF seed, encrypted at rest
756
+ separately. This is the property SRP could not offer, and the main reason
757
+ AXIAM replaced it.
758
+
759
+ It does **not** protect against a compromised AXIAM server, and in a browser it
760
+ does not protect against AXIAM serving malicious JavaScript.
761
+
762
+ ### Enrolment
763
+
764
+ The server cannot build a record — it never sees the plaintext — so one has to
765
+ be sent with any request that sets a password:
766
+
767
+ ```ts
768
+ const opaque = await client.opaqueEnrollment(newPassword);
769
+ // send `opaque` as the request body's `opaque` field
770
+ ```
771
+
772
+ One argument, where the SRP verifier this replaces took four. There is no
773
+ `identity` — a record binds to a credential identifier the server chooses, so
774
+ enrolling against an email can no longer produce something no login can satisfy,
775
+ and a later rename cannot invalidate it — and no group or KDF, because the
776
+ server names them in its `register/start` response and this call honours what
777
+ it names.
778
+
779
+ It is `async` because that response has to be fetched: OPAQUE's envelope is
780
+ sealed under the server's oblivious PRF, so there is no offline computation that
781
+ produces a valid record. The SRP verifier needed no network at all.
782
+
783
+ ### This SDK does not implement OPAQUE
784
+
785
+ CONTRACT.md §23.1 forbids it. SRP was hand-written eleven times because it is
786
+ modular arithmetic every language has; OPAQUE needs an oblivious PRF,
787
+ `hash_to_curve`, `expand_message_xmd`, an envelope construction and a
788
+ three-message AKE. `core/srp.ts` — 419 lines of it — is replaced by a loader
789
+ around `@axiam/opaque-wasm`, the WebAssembly build of the same implementation
790
+ the AXIAM server links and every other SDK binds.
791
+
792
+ ### Runtime requirements
793
+
794
+ `@axiam/opaque-wasm` is an **optional peer dependency**:
795
+
796
+ ```bash
797
+ npm install @axiam/opaque-wasm
798
+ ```
799
+
800
+ Optional, because an installation that never touches the OPAQUE path should not
801
+ be made to carry a WebAssembly module. When it is absent, `opaqueAvailable()`
802
+ resolves to `false` and `loginOpaque` rejects with a `NetworkError` — reporting
803
+ rather than throwing at login time is what §23.1 asks of an SDK whose native
804
+ artifact did not load, and it is why the fallback above works unchanged.
805
+
806
+ ```ts
807
+ if (!(await client.opaqueAvailable())) {
808
+ // use login() — this installation cannot do OPAQUE
809
+ }
810
+ ```
811
+
812
+ It is imported lazily and memoized, so a consumer who never calls OPAQUE does
813
+ not pay the wasm payload at module-load time, and two concurrent logins do not
814
+ instantiate it twice.
815
+
816
+ ### Cost
817
+
818
+ `loginOpaque` runs the tenant's key-stretching function: Argon2id at 19 MiB and
819
+ t=2 by default, tens to hundreds of milliseconds of synchronous work. That cost
820
+ is the point — it is what makes a stolen record expensive to attack even by
821
+ someone holding the OPRF seed. In a browser, consider a Web Worker.
822
+
710
823
  ## Device authorization grant (`axiam-sdk/node`, CONTRACT.md §14)
711
824
 
712
825
  RFC 8628 — signing in a device that cannot show a browser: a TV, a CLI, a headless
@@ -176,6 +176,43 @@ declare function delayMs(attempt: number, retryAfterMs: number | undefined, frac
176
176
  */
177
177
  declare function withRetry<T>(fn: (attempt: number) => Promise<T>, options: RetryOptions): Promise<T>;
178
178
 
179
+ /**
180
+ * A completed enrolment, to send with any request that sets a password.
181
+ *
182
+ * Two fields, where the SRP verifier it replaces had seven. The server chose
183
+ * the credential identifier, the ciphersuite and the costs and sealed them into
184
+ * `opaque_session` — which is why a client cannot name any of them, and why it
185
+ * cannot enrol a record against somebody else's account.
186
+ */
187
+ interface OpaqueEnrollment {
188
+ /**
189
+ * The `opaque_session` from `register/start`, echoed **verbatim**.
190
+ *
191
+ * Opaque sealed server state carrying the credential identifier, the
192
+ * ciphersuite and the costs. Do not parse, cache, or reuse it across
193
+ * exchanges (§23.4 rule 8) — it is valid for 120 seconds.
194
+ */
195
+ opaque_session: string;
196
+ /** Lowercase-hex serialized RFC 9807 `RegistrationRecord`. */
197
+ registration_record: string;
198
+ }
199
+ /**
200
+ * Build a registration record for `password`, to send with any request that
201
+ * sets one (user creation, change-password, reset completion).
202
+ *
203
+ * This performs a `register/start` round trip, which the SRP verifier it
204
+ * replaces did not need: OPAQUE's envelope is sealed under the server's
205
+ * oblivious PRF, so there is no offline computation that produces a valid
206
+ * record.
207
+ *
208
+ * Note the absence of an `identity` argument. The SRP version required the
209
+ * account's canonical username, and passing an email produced a verifier no
210
+ * login could ever satisfy. A record binds to a credential identifier the
211
+ * server chooses, so there is nothing here to get wrong — and a later rename
212
+ * cannot invalidate it.
213
+ */
214
+ declare function opaqueEnrollment(client: AxiamClient, password: string): Promise<OpaqueEnrollment>;
215
+
179
216
  /**
180
217
  * The main entry point for the AXIAM TypeScript/JavaScript SDK — an
181
218
  * isomorphic (browser + Node) REST client for authentication and
@@ -267,6 +304,37 @@ declare class AxiamClient {
267
304
  retryOptions(operation: string): RetryOptions;
268
305
  /** `POST /api/v1/auth/login` (§1, D-18). */
269
306
  login(email: string, password: string): Promise<LoginResult>;
307
+ /**
308
+ * OPAQUE login (§23) — the password never leaves this process.
309
+ *
310
+ * Returns the same `LoginResult` as {@link login}, including the
311
+ * `mfa_required` branch, so one result handler serves both. Rejects with a
312
+ * `NetworkError` naming OPAQUE when the tenant has it disabled, so a caller
313
+ * can fall back to {@link login} rather than mistaking it for a bad password.
314
+ *
315
+ * **Only that case may fall back.** Any other rejection is a failed login,
316
+ * and retrying it over {@link login} would hand the plaintext to a server
317
+ * that just failed to prove it holds the record.
318
+ */
319
+ loginOpaque(usernameOrEmail: string, password: string): Promise<LoginResult>;
320
+ /**
321
+ * Build an OPAQUE registration record to send with any request that sets a
322
+ * password (§23). The server cannot build one — it never sees the plaintext.
323
+ *
324
+ * Asynchronous because it performs a `register/start` round trip: the
325
+ * envelope is sealed under the server's oblivious PRF, so unlike the SRP
326
+ * verifier this replaces there is no offline computation that produces a
327
+ * valid record.
328
+ */
329
+ opaqueEnrollment(password: string): Promise<OpaqueEnrollment>;
330
+ /**
331
+ * Whether this installation can perform OPAQUE (§23.2).
332
+ *
333
+ * Asynchronous, and genuinely able to answer `false`: `@axiam/opaque-wasm` is
334
+ * an optional peer dependency, so an installation that skipped it reports
335
+ * rather than throwing at login time.
336
+ */
337
+ opaqueAvailable(): Promise<boolean>;
270
338
  /** `POST /api/v1/auth/mfa/verify` (§1, D-18). Completes the two-phase flow started by login(). */
271
339
  verifyMfa(mfaToken: string, code: string): Promise<LoginResult>;
272
340
  /** `POST /api/v1/auth/refresh` (§1). Usually driven reactively by the response interceptor (D-07). */
@@ -281,4 +349,4 @@ declare class AxiamClient {
281
349
  batchCheck(checks: AccessCheck[]): Promise<AccessDecision[]>;
282
350
  }
283
351
 
284
- export { AxiamClient as A, BASE_DELAY_MS as B, DecisionMemo as D, type FinishRequest as F, MAX_ATTEMPTS as M, type RetryOptions as R, TelemetryReporter as T, MAX_DELAY_MS as a, MAX_TTL_MS as b, backoffMs as c, delayMs as d, memoKey as m, withRetry as w };
352
+ export { AxiamClient as A, BASE_DELAY_MS as B, DecisionMemo as D, type FinishRequest as F, MAX_ATTEMPTS as M, type OpaqueEnrollment as O, type RetryOptions as R, TelemetryReporter as T, MAX_DELAY_MS as a, MAX_TTL_MS as b, backoffMs as c, delayMs as d, memoKey as m, opaqueEnrollment as o, withRetry as w };
@@ -176,6 +176,43 @@ declare function delayMs(attempt: number, retryAfterMs: number | undefined, frac
176
176
  */
177
177
  declare function withRetry<T>(fn: (attempt: number) => Promise<T>, options: RetryOptions): Promise<T>;
178
178
 
179
+ /**
180
+ * A completed enrolment, to send with any request that sets a password.
181
+ *
182
+ * Two fields, where the SRP verifier it replaces had seven. The server chose
183
+ * the credential identifier, the ciphersuite and the costs and sealed them into
184
+ * `opaque_session` — which is why a client cannot name any of them, and why it
185
+ * cannot enrol a record against somebody else's account.
186
+ */
187
+ interface OpaqueEnrollment {
188
+ /**
189
+ * The `opaque_session` from `register/start`, echoed **verbatim**.
190
+ *
191
+ * Opaque sealed server state carrying the credential identifier, the
192
+ * ciphersuite and the costs. Do not parse, cache, or reuse it across
193
+ * exchanges (§23.4 rule 8) — it is valid for 120 seconds.
194
+ */
195
+ opaque_session: string;
196
+ /** Lowercase-hex serialized RFC 9807 `RegistrationRecord`. */
197
+ registration_record: string;
198
+ }
199
+ /**
200
+ * Build a registration record for `password`, to send with any request that
201
+ * sets one (user creation, change-password, reset completion).
202
+ *
203
+ * This performs a `register/start` round trip, which the SRP verifier it
204
+ * replaces did not need: OPAQUE's envelope is sealed under the server's
205
+ * oblivious PRF, so there is no offline computation that produces a valid
206
+ * record.
207
+ *
208
+ * Note the absence of an `identity` argument. The SRP version required the
209
+ * account's canonical username, and passing an email produced a verifier no
210
+ * login could ever satisfy. A record binds to a credential identifier the
211
+ * server chooses, so there is nothing here to get wrong — and a later rename
212
+ * cannot invalidate it.
213
+ */
214
+ declare function opaqueEnrollment(client: AxiamClient, password: string): Promise<OpaqueEnrollment>;
215
+
179
216
  /**
180
217
  * The main entry point for the AXIAM TypeScript/JavaScript SDK — an
181
218
  * isomorphic (browser + Node) REST client for authentication and
@@ -267,6 +304,37 @@ declare class AxiamClient {
267
304
  retryOptions(operation: string): RetryOptions;
268
305
  /** `POST /api/v1/auth/login` (§1, D-18). */
269
306
  login(email: string, password: string): Promise<LoginResult>;
307
+ /**
308
+ * OPAQUE login (§23) — the password never leaves this process.
309
+ *
310
+ * Returns the same `LoginResult` as {@link login}, including the
311
+ * `mfa_required` branch, so one result handler serves both. Rejects with a
312
+ * `NetworkError` naming OPAQUE when the tenant has it disabled, so a caller
313
+ * can fall back to {@link login} rather than mistaking it for a bad password.
314
+ *
315
+ * **Only that case may fall back.** Any other rejection is a failed login,
316
+ * and retrying it over {@link login} would hand the plaintext to a server
317
+ * that just failed to prove it holds the record.
318
+ */
319
+ loginOpaque(usernameOrEmail: string, password: string): Promise<LoginResult>;
320
+ /**
321
+ * Build an OPAQUE registration record to send with any request that sets a
322
+ * password (§23). The server cannot build one — it never sees the plaintext.
323
+ *
324
+ * Asynchronous because it performs a `register/start` round trip: the
325
+ * envelope is sealed under the server's oblivious PRF, so unlike the SRP
326
+ * verifier this replaces there is no offline computation that produces a
327
+ * valid record.
328
+ */
329
+ opaqueEnrollment(password: string): Promise<OpaqueEnrollment>;
330
+ /**
331
+ * Whether this installation can perform OPAQUE (§23.2).
332
+ *
333
+ * Asynchronous, and genuinely able to answer `false`: `@axiam/opaque-wasm` is
334
+ * an optional peer dependency, so an installation that skipped it reports
335
+ * rather than throwing at login time.
336
+ */
337
+ opaqueAvailable(): Promise<boolean>;
270
338
  /** `POST /api/v1/auth/mfa/verify` (§1, D-18). Completes the two-phase flow started by login(). */
271
339
  verifyMfa(mfaToken: string, code: string): Promise<LoginResult>;
272
340
  /** `POST /api/v1/auth/refresh` (§1). Usually driven reactively by the response interceptor (D-07). */
@@ -281,4 +349,4 @@ declare class AxiamClient {
281
349
  batchCheck(checks: AccessCheck[]): Promise<AccessDecision[]>;
282
350
  }
283
351
 
284
- export { AxiamClient as A, BASE_DELAY_MS as B, DecisionMemo as D, type FinishRequest as F, MAX_ATTEMPTS as M, type RetryOptions as R, TelemetryReporter as T, MAX_DELAY_MS as a, MAX_TTL_MS as b, backoffMs as c, delayMs as d, memoKey as m, withRetry as w };
352
+ export { AxiamClient as A, BASE_DELAY_MS as B, DecisionMemo as D, type FinishRequest as F, MAX_ATTEMPTS as M, type OpaqueEnrollment as O, type RetryOptions as R, TelemetryReporter as T, MAX_DELAY_MS as a, MAX_TTL_MS as b, backoffMs as c, delayMs as d, memoKey as m, opaqueEnrollment as o, withRetry as w };
@@ -1,6 +1,6 @@
1
1
  import { CookieJar } from 'tough-cookie';
2
2
  import { S as SharedSession, A as AxiamClientOptions, N as NodeTlsOptions } from './session-CMgYRxLP.cjs';
3
- import { A as AxiamClient } from './client-C2MEcxjG.cjs';
3
+ import { A as AxiamClient } from './client-BI8psWTI.cjs';
4
4
  import { S as Sensitive } from './sensitive-BC_s7Rrd.cjs';
5
5
  import { V as Verifier } from './jwks-CSXHo3DS.cjs';
6
6
  import { AxiosInstance } from 'axios';
@@ -1,6 +1,6 @@
1
1
  import { CookieJar } from 'tough-cookie';
2
2
  import { S as SharedSession, A as AxiamClientOptions, N as NodeTlsOptions } from './session-BJHqprWm.js';
3
- import { A as AxiamClient } from './client-YQQcFDTy.js';
3
+ import { A as AxiamClient } from './client-BLxvE44W.js';
4
4
  import { S as Sensitive } from './sensitive-BC_s7Rrd.js';
5
5
  import { V as Verifier } from './jwks-CSXHo3DS.js';
6
6
  import { AxiosInstance } from 'axios';
@@ -1,14 +1,14 @@
1
1
  import * as grpc from '@grpc/grpc-js';
2
2
  import { Interceptor } from '@grpc/grpc-js';
3
- import { N as NodeSession } from '../cookieJar-C8YixLEs.cjs';
4
- export { A as ACCESS_COOKIE, C as CSRF_COOKIE, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-C8YixLEs.cjs';
3
+ import { N as NodeSession } from '../cookieJar-CtSD0jwR.cjs';
4
+ export { A as ACCESS_COOKIE, C as CSRF_COOKIE, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-CtSD0jwR.cjs';
5
5
  import { a as AccessDecision } from '../types-CO10Ainw.cjs';
6
6
  export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, c as createVerifier } from '../jwks-CSXHo3DS.cjs';
7
7
  import 'tough-cookie';
8
8
  import '../session-CMgYRxLP.cjs';
9
9
  import 'axios';
10
10
  import '../telemetry-DrGqL4kb.cjs';
11
- import '../client-C2MEcxjG.cjs';
11
+ import '../client-BI8psWTI.cjs';
12
12
  import '../sensitive-BC_s7Rrd.cjs';
13
13
 
14
14
  /**
@@ -1,14 +1,14 @@
1
1
  import * as grpc from '@grpc/grpc-js';
2
2
  import { Interceptor } from '@grpc/grpc-js';
3
- import { N as NodeSession } from '../cookieJar-BDeX40ZG.js';
4
- export { A as ACCESS_COOKIE, C as CSRF_COOKIE, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-BDeX40ZG.js';
3
+ import { N as NodeSession } from '../cookieJar-b1B10RCK.js';
4
+ export { A as ACCESS_COOKIE, C as CSRF_COOKIE, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-b1B10RCK.js';
5
5
  import { a as AccessDecision } from '../types-CO10Ainw.js';
6
6
  export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, c as createVerifier } from '../jwks-CSXHo3DS.js';
7
7
  import 'tough-cookie';
8
8
  import '../session-BJHqprWm.js';
9
9
  import 'axios';
10
10
  import '../telemetry-DrGqL4kb.js';
11
- import '../client-YQQcFDTy.js';
11
+ import '../client-BLxvE44W.js';
12
12
  import '../sensitive-BC_s7Rrd.js';
13
13
 
14
14
  /**
@@ -1083,6 +1083,209 @@ function extractAxiosData(err) {
1083
1083
  return void 0;
1084
1084
  }
1085
1085
 
1086
+ // src/core/opaque.ts
1087
+ var modulePromise = null;
1088
+ var WASM_PACKAGE = "@axiam/opaque-wasm";
1089
+ async function loadModule() {
1090
+ modulePromise ??= (async () => {
1091
+ try {
1092
+ const mod = await import(
1093
+ /* @vite-ignore */
1094
+ WASM_PACKAGE
1095
+ );
1096
+ await mod.default();
1097
+ return mod;
1098
+ } catch {
1099
+ return null;
1100
+ }
1101
+ })();
1102
+ return modulePromise;
1103
+ }
1104
+ async function opaqueAvailable() {
1105
+ const mod = await loadModule();
1106
+ return mod !== null && mod.opaqueAvailable();
1107
+ }
1108
+ var BOUNDS = {
1109
+ memory_kib: [8192, 1048576],
1110
+ iterations: [1, 10],
1111
+ parallelism: [1, 16],
1112
+ log_n: [14, 20],
1113
+ r: [1, 16],
1114
+ p: [1, 16]
1115
+ };
1116
+ function requireInBand(name, value, ksf) {
1117
+ if (value === void 0) {
1118
+ throw new NetworkError(`OPAQUE: the server named ksf \`${ksf}\` without \`${name}\``);
1119
+ }
1120
+ const [min, max] = BOUNDS[name];
1121
+ if (!Number.isInteger(value) || value < min || value > max) {
1122
+ throw new NetworkError(
1123
+ `OPAQUE: the server named ${name}=${value} for \`${ksf}\`, outside the accepted ${min}..${max}`
1124
+ );
1125
+ }
1126
+ return value;
1127
+ }
1128
+ function buildKsf(mod, fields) {
1129
+ switch (fields.ksf) {
1130
+ case "argon2id":
1131
+ return mod.OpaqueKsf.argon2id(
1132
+ requireInBand("memory_kib", fields.memory_kib, fields.ksf),
1133
+ requireInBand("iterations", fields.iterations, fields.ksf),
1134
+ requireInBand("parallelism", fields.parallelism, fields.ksf)
1135
+ );
1136
+ case "scrypt":
1137
+ return mod.OpaqueKsf.scrypt(
1138
+ requireInBand("log_n", fields.log_n, fields.ksf),
1139
+ requireInBand("r", fields.r, fields.ksf),
1140
+ requireInBand("p", fields.p, fields.ksf)
1141
+ );
1142
+ default:
1143
+ throw new NetworkError(
1144
+ `OPAQUE: this SDK cannot perform the key-stretching function the server named (\`${fields.ksf}\`)`
1145
+ );
1146
+ }
1147
+ }
1148
+ var OpaqueUnavailableError = class _OpaqueUnavailableError extends NetworkError {
1149
+ constructor() {
1150
+ super("OPAQUE is not available: install the optional peer dependency `@axiam/opaque-wasm`");
1151
+ this.name = "OpaqueUnavailableError";
1152
+ Object.setPrototypeOf(this, _OpaqueUnavailableError.prototype);
1153
+ }
1154
+ };
1155
+ async function requireModule() {
1156
+ const mod = await loadModule();
1157
+ if (mod === null) throw new OpaqueUnavailableError();
1158
+ return mod;
1159
+ }
1160
+ async function startRegistration(password) {
1161
+ const mod = await requireModule();
1162
+ const state = new mod.OpaqueRegistration(password);
1163
+ return {
1164
+ request: state.request,
1165
+ finish(registrationResponse, ksfFields) {
1166
+ return state.finish(password, registrationResponse, buildKsf(mod, ksfFields)).record;
1167
+ }
1168
+ };
1169
+ }
1170
+ async function startLogin(password) {
1171
+ const mod = await requireModule();
1172
+ const state = new mod.OpaqueLogin(password);
1173
+ return {
1174
+ ke1: state.ke1,
1175
+ finish(ke2, ksfFields) {
1176
+ return state.finish(password, ke2, buildKsf(mod, ksfFields)).ke3;
1177
+ }
1178
+ };
1179
+ }
1180
+
1181
+ // src/rest/opaque.ts
1182
+ var OPAQUE_REGISTER_START_PATH = "/api/v1/auth/opaque/register/start";
1183
+ var OPAQUE_LOGIN_START_PATH = "/api/v1/auth/opaque/login/start";
1184
+ var OPAQUE_LOGIN_FINISH_PATH = "/api/v1/auth/opaque/login/finish";
1185
+ function axiosStatus(err) {
1186
+ return err?.response?.status;
1187
+ }
1188
+ function axiosMessage(err) {
1189
+ return err?.message ?? "request failed";
1190
+ }
1191
+ async function loginOpaque(client, usernameOrEmail, password) {
1192
+ client.ensureOpen();
1193
+ client.decisionMemo.clear();
1194
+ const exchange = await startLogin(password);
1195
+ const body = {
1196
+ ...client.session.buildLoginBody(usernameOrEmail, ""),
1197
+ ke1: exchange.ke1
1198
+ };
1199
+ delete body.password;
1200
+ let started;
1201
+ try {
1202
+ const response2 = await client.session.axios.post(
1203
+ OPAQUE_LOGIN_START_PATH,
1204
+ body
1205
+ );
1206
+ started = response2.data;
1207
+ } catch (err) {
1208
+ const status = axiosStatus(err);
1209
+ if (status === 404) {
1210
+ throw new NetworkError(
1211
+ "this tenant does not offer OPAQUE (opaque_mode is disabled); use login() instead"
1212
+ );
1213
+ }
1214
+ if (status !== void 0) {
1215
+ throw mapHttpStatusToError(status, axiosMessage(err), { cause: err });
1216
+ }
1217
+ throw new NetworkError("OPAQUE login/start request failed", sanitizeAxiosError(err));
1218
+ }
1219
+ let ke3;
1220
+ try {
1221
+ ke3 = exchange.finish(started.ke2, started);
1222
+ } catch (err) {
1223
+ if (err instanceof NetworkError) throw err;
1224
+ throw mapHttpStatusToError(401, "invalid credentials", { cause: err });
1225
+ }
1226
+ let response;
1227
+ try {
1228
+ response = await client.session.axios.post(
1229
+ OPAQUE_LOGIN_FINISH_PATH,
1230
+ { opaque_session: started.opaque_session, ke3 }
1231
+ );
1232
+ } catch (err) {
1233
+ const status = axiosStatus(err);
1234
+ if (status !== void 0) {
1235
+ throw mapHttpStatusToError(status, axiosMessage(err), { cause: err });
1236
+ }
1237
+ throw new NetworkError("OPAQUE login/finish request failed", sanitizeAxiosError(err));
1238
+ }
1239
+ if (response.status === 202) {
1240
+ const wire2 = response.data;
1241
+ return {
1242
+ status: "mfa_required",
1243
+ mfaToken: wire2.challenge_token,
1244
+ availableMethods: wire2.available_methods
1245
+ };
1246
+ }
1247
+ const wire = response.data;
1248
+ client.session.authenticated = true;
1249
+ await client.session.onAuthenticated?.();
1250
+ return {
1251
+ status: "authenticated",
1252
+ user: { id: wire.user.id, username: wire.user.username, email: wire.user.email },
1253
+ sessionId: wire.session_id,
1254
+ expiresIn: wire.expires_in
1255
+ };
1256
+ }
1257
+ async function opaqueEnrollment(client, password) {
1258
+ client.ensureOpen();
1259
+ const exchange = await startRegistration(password);
1260
+ const body = {
1261
+ ...client.session.buildLoginBody("", ""),
1262
+ registration_request: exchange.request
1263
+ };
1264
+ delete body.password;
1265
+ delete body.username_or_email;
1266
+ let started;
1267
+ try {
1268
+ const response = await client.session.axios.post(
1269
+ OPAQUE_REGISTER_START_PATH,
1270
+ body
1271
+ );
1272
+ started = response.data;
1273
+ } catch (err) {
1274
+ const status = axiosStatus(err);
1275
+ if (status === 404) {
1276
+ throw new NetworkError("this tenant does not offer OPAQUE (opaque_mode is disabled)");
1277
+ }
1278
+ if (status !== void 0) {
1279
+ throw mapHttpStatusToError(status, axiosMessage(err), { cause: err });
1280
+ }
1281
+ throw new NetworkError("OPAQUE register/start request failed", sanitizeAxiosError(err));
1282
+ }
1283
+ return {
1284
+ opaque_session: started.opaque_session,
1285
+ registration_record: exchange.finish(started.registration_response, started)
1286
+ };
1287
+ }
1288
+
1086
1289
  // src/rest/retry.ts
1087
1290
  var MAX_ATTEMPTS = 3;
1088
1291
  var BASE_DELAY_MS = 200;
@@ -1291,6 +1494,43 @@ var AxiamClient = class {
1291
1494
  login(email, password) {
1292
1495
  return login(this, email, password);
1293
1496
  }
1497
+ /**
1498
+ * OPAQUE login (§23) — the password never leaves this process.
1499
+ *
1500
+ * Returns the same `LoginResult` as {@link login}, including the
1501
+ * `mfa_required` branch, so one result handler serves both. Rejects with a
1502
+ * `NetworkError` naming OPAQUE when the tenant has it disabled, so a caller
1503
+ * can fall back to {@link login} rather than mistaking it for a bad password.
1504
+ *
1505
+ * **Only that case may fall back.** Any other rejection is a failed login,
1506
+ * and retrying it over {@link login} would hand the plaintext to a server
1507
+ * that just failed to prove it holds the record.
1508
+ */
1509
+ loginOpaque(usernameOrEmail, password) {
1510
+ return loginOpaque(this, usernameOrEmail, password);
1511
+ }
1512
+ /**
1513
+ * Build an OPAQUE registration record to send with any request that sets a
1514
+ * password (§23). The server cannot build one — it never sees the plaintext.
1515
+ *
1516
+ * Asynchronous because it performs a `register/start` round trip: the
1517
+ * envelope is sealed under the server's oblivious PRF, so unlike the SRP
1518
+ * verifier this replaces there is no offline computation that produces a
1519
+ * valid record.
1520
+ */
1521
+ opaqueEnrollment(password) {
1522
+ return opaqueEnrollment(this, password);
1523
+ }
1524
+ /**
1525
+ * Whether this installation can perform OPAQUE (§23.2).
1526
+ *
1527
+ * Asynchronous, and genuinely able to answer `false`: `@axiam/opaque-wasm` is
1528
+ * an optional peer dependency, so an installation that skipped it reports
1529
+ * rather than throwing at login time.
1530
+ */
1531
+ opaqueAvailable() {
1532
+ return opaqueAvailable();
1533
+ }
1294
1534
  /** `POST /api/v1/auth/mfa/verify` (§1, D-18). Completes the two-phase flow started by login(). */
1295
1535
  verifyMfa(mfaToken, code) {
1296
1536
  return verifyMfa(this, mfaToken, code);