axiam-sdk 1.0.0-alpha27 → 1.0.0-alpha31

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
@@ -17,7 +17,7 @@ Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanic
17
17
 
18
18
  ## Contract conformance
19
19
 
20
- This SDK conforms to CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19, §20, §21, §22 (including §6.1 mTLS
20
+ This SDK conforms to CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19, §20, §21, §22, §23 (including §6.1 mTLS
21
21
  client certificates, the §10.1 minimum local-verification set, the §12 OIDC/SSO
22
22
  relying-party helpers, and the §13 `verifyWebhook` signature verifier).
23
23
 
@@ -707,6 +707,79 @@ strings.
707
707
 
708
708
  See `examples/express-oidc-login.ts` for a complete, runnable example.
709
709
 
710
+ ## Secure Remote Password (CONTRACT.md §23)
711
+
712
+ `loginSrp` proves the password without sending it. What crosses the wire is `A`
713
+ and a proof, neither of which is useful to anyone who does not already hold the
714
+ account's verifier.
715
+
716
+ ```ts
717
+ // Same LoginResult as login(), including the mfa_required branch.
718
+ const result = await client.loginSrp('alice', 'correct horse battery staple');
719
+ ```
720
+
721
+ Fall back to `login()` when the tenant does not offer SRP. That case is a
722
+ `NetworkError` naming SRP, deliberately **not** an `AuthError`, so it cannot be
723
+ mistaken for a bad password:
724
+
725
+ ```ts
726
+ let result;
727
+ try {
728
+ result = await client.loginSrp(user, password);
729
+ } catch (err) {
730
+ if (err instanceof NetworkError && err.message.includes('does not offer Secure Remote Password')) {
731
+ result = await client.login(user, password);
732
+ } else {
733
+ throw err;
734
+ }
735
+ }
736
+ ```
737
+
738
+ ### Enrolment
739
+
740
+ The server cannot compute a verifier — it never sees the plaintext — so one has
741
+ to be sent with any request that sets a password:
742
+
743
+ ```ts
744
+ const srp = await client.srpEnrollment({
745
+ identity: 'alice', // the USERNAME — see below
746
+ password: 'new password',
747
+ group: 'rfc5054_4096',
748
+ kdf: 'argon2id',
749
+ });
750
+ // send `srp` as the request's `srp` field
751
+ ```
752
+
753
+ The tenant's group and KDF come from `GET /api/v1/auth/me` for an authenticated
754
+ caller, or `GET /api/v1/auth/reset/context` for a reset-token holder.
755
+
756
+ ### Three things that will bite you
757
+
758
+ **The identity is the username, always.** `x` is derived over
759
+ `username ":" password`. A user may sign in with their email, but only the
760
+ username is inside the KDF — which is why the challenge response carries an
761
+ `identity` field and why `loginSrp` uses that rather than what was typed.
762
+ Enrolling against an email produces a verifier no login can satisfy.
763
+
764
+ **`loginSrp` is slow, on purpose.** It runs the tenant's KDF: Argon2id at
765
+ 19 MiB by default, tens to hundreds of milliseconds. That cost is what makes a
766
+ stolen verifier expensive to attack offline. In a browser, consider a Web
767
+ Worker.
768
+
769
+ **What it protects, and what it does not.** A TLS-terminating proxy, an
770
+ accidentally verbose request log, or a heap dump on the server can no longer
771
+ capture a plaintext password, because the server never has one. It does **not**
772
+ protect against a compromised AXIAM server, and in a browser it does not protect
773
+ against AXIAM serving malicious JavaScript.
774
+
775
+ ### Runtime requirements
776
+
777
+ WebCrypto (`globalThis.crypto.subtle`) — present in Node 18+, Deno, Bun and
778
+ every browser — plus `hash-wasm` for Argon2id, which is a dependency rather than
779
+ optional because §23.3 rule 4 makes both KDFs mandatory and `argon2id` is what
780
+ AXIAM's default policy asks for. It is imported lazily, so a consumer who never
781
+ calls SRP does not pay the wasm payload at module-load time.
782
+
710
783
  ## Device authorization grant (`axiam-sdk/node`, CONTRACT.md §14)
711
784
 
712
785
  RFC 8628 — signing in a device that cannot show a browser: a TV, a CLI, a headless
@@ -176,6 +176,70 @@ 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
+ /** The verifier and its parameters, for any endpoint that sets a password. */
180
+ interface SrpEnrollment {
181
+ /** RFC 5054 group name the verifier lives in, e.g. `rfc5054_4096`. */
182
+ group: string;
183
+ /** KDF used to derive `x`: `argon2id` or `pbkdf2_sha256`. */
184
+ kdf: string;
185
+ /** Argon2id memory cost in KiB; absent for PBKDF2. */
186
+ memory_kib?: number;
187
+ /** KDF iteration (PBKDF2) or time (Argon2id) cost. */
188
+ iterations: number;
189
+ /** Argon2id lane count; absent for PBKDF2. */
190
+ parallelism?: number;
191
+ /**
192
+ * The 32-byte enrolment salt, lowercase hex. Freshly generated per enrolment
193
+ * (§23.3 rule 11): a reused salt would make every verifier in a tenant
194
+ * attackable with one precomputation.
195
+ */
196
+ salt: string;
197
+ /**
198
+ * `v = g^x mod N`, lowercase hex. The only password-derived value the server
199
+ * ever receives, and computationally infeasible to invert.
200
+ */
201
+ verifier: string;
202
+ }
203
+ /** Options for {@link srpEnrollment}. */
204
+ interface SrpEnrollmentOptions {
205
+ /**
206
+ * The account's **username** — the canonical identity the challenge endpoint
207
+ * hands back. Passing an email produces a verifier no login can ever satisfy.
208
+ */
209
+ identity: string;
210
+ /** The plaintext password being set. It never leaves this process. */
211
+ password: string;
212
+ /** From the tenant's policy (`GET /api/v1/auth/me`, or the reset context). */
213
+ group: string;
214
+ /** The KDF the tenant enrols under: `argon2id` or `pbkdf2_sha256`. */
215
+ kdf: string;
216
+ /** KDF cost; defaults to AXIAM's own for the chosen KDF when omitted. */
217
+ iterations?: number;
218
+ /** Argon2id memory cost in KiB; ignored for PBKDF2. */
219
+ memoryKib?: number;
220
+ /** Argon2id lane count; ignored for PBKDF2. */
221
+ parallelism?: number;
222
+ }
223
+ /**
224
+ * Compute a verifier for `password`, to send with any request that sets one
225
+ * (user creation, change-password, reset completion).
226
+ *
227
+ * The server cannot compute this — it never sees the plaintext — so it has to
228
+ * arrive with the request or not at all. The salt is 32 fresh bytes from the
229
+ * platform CSPRNG (§23.3 rule 11).
230
+ */
231
+ declare function srpEnrollment(options: SrpEnrollmentOptions): Promise<SrpEnrollment>;
232
+ /**
233
+ * Whether this SDK build can perform SRP.
234
+ *
235
+ * Always `true` for TypeScript: `BigInt` is native and both KDFs are available
236
+ * (`hash-wasm` for Argon2id, WebCrypto for PBKDF2). It exists because §23.1
237
+ * puts it in the locked method vocabulary for every SDK, and in PHP — which
238
+ * needs `ext-gmp` or `ext-bcmath` and is guaranteed neither — it genuinely
239
+ * answers `false`.
240
+ */
241
+ declare function srpAvailable(): boolean;
242
+
179
243
  /**
180
244
  * The main entry point for the AXIAM TypeScript/JavaScript SDK — an
181
245
  * isomorphic (browser + Node) REST client for authentication and
@@ -267,6 +331,22 @@ declare class AxiamClient {
267
331
  retryOptions(operation: string): RetryOptions;
268
332
  /** `POST /api/v1/auth/login` (§1, D-18). */
269
333
  login(email: string, password: string): Promise<LoginResult>;
334
+ /**
335
+ * SRP-6a login (§23) — the password never leaves this process.
336
+ *
337
+ * Returns the same `LoginResult` as {@link login}, including the
338
+ * `mfa_required` branch, so one result handler serves both. Rejects with a
339
+ * `NetworkError` naming SRP when the tenant has it disabled, so a caller can
340
+ * fall back to {@link login} rather than mistaking it for a bad password.
341
+ */
342
+ loginSrp(usernameOrEmail: string, password: string): Promise<LoginResult>;
343
+ /**
344
+ * Compute an SRP verifier to send with any request that sets a password
345
+ * (§23). The server cannot derive one — it never sees the plaintext.
346
+ */
347
+ srpEnrollment(options: SrpEnrollmentOptions): Promise<SrpEnrollment>;
348
+ /** Whether this runtime can perform SRP (§23.1). Always true here. */
349
+ srpAvailable(): boolean;
270
350
  /** `POST /api/v1/auth/mfa/verify` (§1, D-18). Completes the two-phase flow started by login(). */
271
351
  verifyMfa(mfaToken: string, code: string): Promise<LoginResult>;
272
352
  /** `POST /api/v1/auth/refresh` (§1). Usually driven reactively by the response interceptor (D-07). */
@@ -281,4 +361,4 @@ declare class AxiamClient {
281
361
  batchCheck(checks: AccessCheck[]): Promise<AccessDecision[]>;
282
362
  }
283
363
 
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 };
364
+ export { AxiamClient as A, BASE_DELAY_MS as B, DecisionMemo as D, type FinishRequest as F, MAX_ATTEMPTS as M, type RetryOptions as R, type SrpEnrollment as S, TelemetryReporter as T, MAX_DELAY_MS as a, MAX_TTL_MS as b, type SrpEnrollmentOptions as c, backoffMs as d, delayMs as e, srpEnrollment as f, memoKey as m, srpAvailable as s, withRetry as w };
@@ -176,6 +176,70 @@ 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
+ /** The verifier and its parameters, for any endpoint that sets a password. */
180
+ interface SrpEnrollment {
181
+ /** RFC 5054 group name the verifier lives in, e.g. `rfc5054_4096`. */
182
+ group: string;
183
+ /** KDF used to derive `x`: `argon2id` or `pbkdf2_sha256`. */
184
+ kdf: string;
185
+ /** Argon2id memory cost in KiB; absent for PBKDF2. */
186
+ memory_kib?: number;
187
+ /** KDF iteration (PBKDF2) or time (Argon2id) cost. */
188
+ iterations: number;
189
+ /** Argon2id lane count; absent for PBKDF2. */
190
+ parallelism?: number;
191
+ /**
192
+ * The 32-byte enrolment salt, lowercase hex. Freshly generated per enrolment
193
+ * (§23.3 rule 11): a reused salt would make every verifier in a tenant
194
+ * attackable with one precomputation.
195
+ */
196
+ salt: string;
197
+ /**
198
+ * `v = g^x mod N`, lowercase hex. The only password-derived value the server
199
+ * ever receives, and computationally infeasible to invert.
200
+ */
201
+ verifier: string;
202
+ }
203
+ /** Options for {@link srpEnrollment}. */
204
+ interface SrpEnrollmentOptions {
205
+ /**
206
+ * The account's **username** — the canonical identity the challenge endpoint
207
+ * hands back. Passing an email produces a verifier no login can ever satisfy.
208
+ */
209
+ identity: string;
210
+ /** The plaintext password being set. It never leaves this process. */
211
+ password: string;
212
+ /** From the tenant's policy (`GET /api/v1/auth/me`, or the reset context). */
213
+ group: string;
214
+ /** The KDF the tenant enrols under: `argon2id` or `pbkdf2_sha256`. */
215
+ kdf: string;
216
+ /** KDF cost; defaults to AXIAM's own for the chosen KDF when omitted. */
217
+ iterations?: number;
218
+ /** Argon2id memory cost in KiB; ignored for PBKDF2. */
219
+ memoryKib?: number;
220
+ /** Argon2id lane count; ignored for PBKDF2. */
221
+ parallelism?: number;
222
+ }
223
+ /**
224
+ * Compute a verifier for `password`, to send with any request that sets one
225
+ * (user creation, change-password, reset completion).
226
+ *
227
+ * The server cannot compute this — it never sees the plaintext — so it has to
228
+ * arrive with the request or not at all. The salt is 32 fresh bytes from the
229
+ * platform CSPRNG (§23.3 rule 11).
230
+ */
231
+ declare function srpEnrollment(options: SrpEnrollmentOptions): Promise<SrpEnrollment>;
232
+ /**
233
+ * Whether this SDK build can perform SRP.
234
+ *
235
+ * Always `true` for TypeScript: `BigInt` is native and both KDFs are available
236
+ * (`hash-wasm` for Argon2id, WebCrypto for PBKDF2). It exists because §23.1
237
+ * puts it in the locked method vocabulary for every SDK, and in PHP — which
238
+ * needs `ext-gmp` or `ext-bcmath` and is guaranteed neither — it genuinely
239
+ * answers `false`.
240
+ */
241
+ declare function srpAvailable(): boolean;
242
+
179
243
  /**
180
244
  * The main entry point for the AXIAM TypeScript/JavaScript SDK — an
181
245
  * isomorphic (browser + Node) REST client for authentication and
@@ -267,6 +331,22 @@ declare class AxiamClient {
267
331
  retryOptions(operation: string): RetryOptions;
268
332
  /** `POST /api/v1/auth/login` (§1, D-18). */
269
333
  login(email: string, password: string): Promise<LoginResult>;
334
+ /**
335
+ * SRP-6a login (§23) — the password never leaves this process.
336
+ *
337
+ * Returns the same `LoginResult` as {@link login}, including the
338
+ * `mfa_required` branch, so one result handler serves both. Rejects with a
339
+ * `NetworkError` naming SRP when the tenant has it disabled, so a caller can
340
+ * fall back to {@link login} rather than mistaking it for a bad password.
341
+ */
342
+ loginSrp(usernameOrEmail: string, password: string): Promise<LoginResult>;
343
+ /**
344
+ * Compute an SRP verifier to send with any request that sets a password
345
+ * (§23). The server cannot derive one — it never sees the plaintext.
346
+ */
347
+ srpEnrollment(options: SrpEnrollmentOptions): Promise<SrpEnrollment>;
348
+ /** Whether this runtime can perform SRP (§23.1). Always true here. */
349
+ srpAvailable(): boolean;
270
350
  /** `POST /api/v1/auth/mfa/verify` (§1, D-18). Completes the two-phase flow started by login(). */
271
351
  verifyMfa(mfaToken: string, code: string): Promise<LoginResult>;
272
352
  /** `POST /api/v1/auth/refresh` (§1). Usually driven reactively by the response interceptor (D-07). */
@@ -281,4 +361,4 @@ declare class AxiamClient {
281
361
  batchCheck(checks: AccessCheck[]): Promise<AccessDecision[]>;
282
362
  }
283
363
 
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 };
364
+ export { AxiamClient as A, BASE_DELAY_MS as B, DecisionMemo as D, type FinishRequest as F, MAX_ATTEMPTS as M, type RetryOptions as R, type SrpEnrollment as S, TelemetryReporter as T, MAX_DELAY_MS as a, MAX_TTL_MS as b, type SrpEnrollmentOptions as c, backoffMs as d, delayMs as e, srpEnrollment as f, memoKey as m, srpAvailable as s, 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-Dz_AJfW7.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-Cai8IhUV.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-Dk9eqU4i.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-Dk9eqU4i.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-Dz_AJfW7.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-z_5x601f.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-z_5x601f.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-Cai8IhUV.js';
12
12
  import '../sensitive-BC_s7Rrd.js';
13
13
 
14
14
  /**
@@ -1083,6 +1083,287 @@ function extractAxiosData(err) {
1083
1083
  return void 0;
1084
1084
  }
1085
1085
 
1086
+ // src/core/srp.ts
1087
+ var GROUPS = {
1088
+ rfc5054_2048: {
1089
+ N: "AC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC3192943DB56050A37329CBB4A099ED8193E0757767A13DD52312AB4B03310DCD7F48A9DA04FD50E8083969EDB767B0CF6095179A163AB3661A05FBD5FAAAE82918A9962F0B93B855F97993EC975EEAA80D740ADBF4FF747359D041D5C33EA71D281E446B14773BCA97B43A23FB801676BD207A436C6481F1D2B9078717461A5B9D32E688F87748544523B524B0D57D5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6AF874E7303CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB694B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F9E4AFF73",
1090
+ g: 2n,
1091
+ byteLen: 256
1092
+ },
1093
+ rfc5054_3072: {
1094
+ N: "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF",
1095
+ g: 5n,
1096
+ byteLen: 384
1097
+ },
1098
+ rfc5054_4096: {
1099
+ N: "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF",
1100
+ g: 5n,
1101
+ byteLen: 512
1102
+ }
1103
+ };
1104
+ function isKnownGroup(name) {
1105
+ return Object.prototype.hasOwnProperty.call(GROUPS, name);
1106
+ }
1107
+ function parseGroup(name) {
1108
+ if (!isKnownGroup(name)) {
1109
+ throw new NetworkError(`this SDK does not implement the SRP group this tenant requires (${name})`);
1110
+ }
1111
+ return name;
1112
+ }
1113
+ function bytesToHex(bytes) {
1114
+ let out = "";
1115
+ for (const b of bytes) out += b.toString(16).padStart(2, "0");
1116
+ return out;
1117
+ }
1118
+ function hexToBytes(hex) {
1119
+ if (hex.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(hex)) {
1120
+ throw new NetworkError("SRP: expected hex");
1121
+ }
1122
+ const out = new Uint8Array(hex.length / 2);
1123
+ for (let i = 0; i < out.length; i++) out[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
1124
+ return out;
1125
+ }
1126
+ function bytesToBigInt(bytes) {
1127
+ return bytes.length === 0 ? 0n : BigInt("0x" + bytesToHex(bytes));
1128
+ }
1129
+ function pad(value, byteLen) {
1130
+ let hex = value.toString(16);
1131
+ if (hex.length % 2 !== 0) hex = "0" + hex;
1132
+ const raw = hexToBytes(hex);
1133
+ if (raw.length >= byteLen) return raw;
1134
+ const out = new Uint8Array(byteLen);
1135
+ out.set(raw, byteLen - raw.length);
1136
+ return out;
1137
+ }
1138
+ function concat(parts) {
1139
+ const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
1140
+ let offset = 0;
1141
+ for (const p of parts) {
1142
+ out.set(p, offset);
1143
+ offset += p.length;
1144
+ }
1145
+ return out;
1146
+ }
1147
+ function buf(bytes) {
1148
+ return bytes.slice().buffer;
1149
+ }
1150
+ async function sha256(parts) {
1151
+ return new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", buf(concat(parts))));
1152
+ }
1153
+ function modPow(base, exp, mod) {
1154
+ let result = 1n;
1155
+ let b = base % mod;
1156
+ let e = exp;
1157
+ while (e > 0n) {
1158
+ if (e & 1n) result = result * b % mod;
1159
+ b = b * b % mod;
1160
+ e >>= 1n;
1161
+ }
1162
+ return result;
1163
+ }
1164
+ var utf8 = new TextEncoder();
1165
+ async function deriveX(identity, password, saltHex, params) {
1166
+ const salt = hexToBytes(saltHex);
1167
+ const secret = utf8.encode(`${identity}:${password}`);
1168
+ if (params.kdf === "argon2id") {
1169
+ const { argon2id } = await import('hash-wasm');
1170
+ const hex = await argon2id({
1171
+ password: secret,
1172
+ salt,
1173
+ parallelism: params.parallelism ?? 1,
1174
+ iterations: params.iterations,
1175
+ memorySize: params.memoryKib ?? 19456,
1176
+ hashLength: 32,
1177
+ outputType: "hex"
1178
+ });
1179
+ return hexToBytes(hex);
1180
+ }
1181
+ if (params.kdf === "pbkdf2_sha256") {
1182
+ const key = await globalThis.crypto.subtle.importKey("raw", buf(secret), "PBKDF2", false, ["deriveBits"]);
1183
+ const bits = await globalThis.crypto.subtle.deriveBits(
1184
+ { name: "PBKDF2", hash: "SHA-256", salt: buf(salt), iterations: params.iterations },
1185
+ key,
1186
+ 256
1187
+ );
1188
+ return new Uint8Array(bits);
1189
+ }
1190
+ throw new NetworkError(
1191
+ `this SDK cannot perform the key-derivation function this tenant requires (${params.kdf})`
1192
+ );
1193
+ }
1194
+ async function multiplier(group) {
1195
+ const N = BigInt("0x" + group.N);
1196
+ return bytesToBigInt(await sha256([pad(N, group.byteLen), pad(group.g, group.byteLen)]));
1197
+ }
1198
+ async function computeVerifier(group, x) {
1199
+ const params = GROUPS[group];
1200
+ const N = BigInt("0x" + params.N);
1201
+ return bytesToHex(pad(modPow(params.g, bytesToBigInt(x) % N, N), params.byteLen));
1202
+ }
1203
+ async function beginClientSession(group) {
1204
+ return beginWithEphemeral(group, (bytes) => globalThis.crypto.getRandomValues(bytes));
1205
+ }
1206
+ async function beginWithEphemeral(groupName, fill) {
1207
+ const group = GROUPS[groupName];
1208
+ const N = BigInt("0x" + group.N);
1209
+ const aBytes = fill(new Uint8Array(32));
1210
+ const a = bytesToBigInt(aBytes);
1211
+ const A = modPow(group.g, a, N);
1212
+ return {
1213
+ clientPublic: bytesToHex(pad(A, group.byteLen)),
1214
+ async finish({ identity, saltHex, serverPublicHex, x }) {
1215
+ const B = BigInt("0x" + serverPublicHex);
1216
+ if (B % N === 0n) {
1217
+ throw new NetworkError("SRP: the server returned an invalid public value (B \u2261 0 mod N)");
1218
+ }
1219
+ const k = await multiplier(group);
1220
+ const xInt = bytesToBigInt(x) % N;
1221
+ const salt = hexToBytes(saltHex);
1222
+ const u = bytesToBigInt(await sha256([pad(A, group.byteLen), pad(B, group.byteLen)]));
1223
+ if (u === 0n) {
1224
+ throw new NetworkError("SRP: the server returned an invalid scrambling parameter (u = 0)");
1225
+ }
1226
+ const kgx = k * modPow(group.g, xInt, N) % N;
1227
+ const base = (B % N + N - kgx) % N;
1228
+ const S = modPow(base, a + u * xInt, N);
1229
+ const K = await sha256([pad(S, group.byteLen)]);
1230
+ const hN = await sha256([pad(N, group.byteLen)]);
1231
+ const hg = await sha256([pad(group.g, group.byteLen)]);
1232
+ const xored = new Uint8Array(32);
1233
+ for (let i = 0; i < 32; i++) xored[i] = hN[i] ^ hg[i];
1234
+ const hI = await sha256([utf8.encode(identity)]);
1235
+ const M1 = await sha256([xored, hI, salt, pad(A, group.byteLen), pad(B, group.byteLen), K]);
1236
+ const M2 = await sha256([pad(A, group.byteLen), M1, K]);
1237
+ return { clientProof: bytesToHex(M1), expectedServerProof: bytesToHex(M2) };
1238
+ }
1239
+ };
1240
+ }
1241
+ function verifyServerProof(expected, actual) {
1242
+ if (!actual || expected.length !== actual.length) return false;
1243
+ let diff = 0;
1244
+ for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ actual.charCodeAt(i);
1245
+ return diff === 0;
1246
+ }
1247
+ function generateSalt() {
1248
+ return bytesToHex(globalThis.crypto.getRandomValues(new Uint8Array(32)));
1249
+ }
1250
+
1251
+ // src/rest/srp.ts
1252
+ var SRP_CHALLENGE_PATH = "/api/v1/auth/srp/challenge";
1253
+ var SRP_VERIFY_PATH = "/api/v1/auth/srp/verify";
1254
+ var OPENING_GROUP = "rfc5054_4096";
1255
+ function axiosStatus(err) {
1256
+ const response = err?.response;
1257
+ return response?.status;
1258
+ }
1259
+ function axiosMessage(err) {
1260
+ const data = err?.response?.data;
1261
+ return data?.message ?? "request failed";
1262
+ }
1263
+ async function loginSrp(client, usernameOrEmail, password) {
1264
+ client.ensureOpen();
1265
+ client.decisionMemo.clear();
1266
+ let { session, challenge } = await requestChallenge(client, usernameOrEmail, OPENING_GROUP);
1267
+ const group = parseGroup(challenge.group);
1268
+ if (group !== OPENING_GROUP) {
1269
+ ({ session, challenge } = await requestChallenge(client, usernameOrEmail, group));
1270
+ }
1271
+ const x = await deriveX(challenge.identity, password, challenge.salt, {
1272
+ kdf: challenge.kdf,
1273
+ iterations: challenge.iterations,
1274
+ memoryKib: challenge.memory_kib,
1275
+ parallelism: challenge.parallelism
1276
+ });
1277
+ const { clientProof, expectedServerProof } = await session.finish({
1278
+ identity: challenge.identity,
1279
+ saltHex: challenge.salt,
1280
+ serverPublicHex: challenge.b_pub,
1281
+ x
1282
+ });
1283
+ let response;
1284
+ try {
1285
+ response = await client.session.axios.post(SRP_VERIFY_PATH, {
1286
+ srp_session: challenge.srp_session,
1287
+ client_proof: clientProof
1288
+ });
1289
+ } catch (err) {
1290
+ const status = axiosStatus(err);
1291
+ if (status !== void 0) {
1292
+ throw mapHttpStatusToError(status, axiosMessage(err), { cause: err });
1293
+ }
1294
+ throw new NetworkError("SRP verify request failed", sanitizeAxiosError(err));
1295
+ }
1296
+ if (!verifyServerProof(expectedServerProof, response.data.server_proof)) {
1297
+ throw new AuthError("SRP: the server failed to prove it holds this account's verifier");
1298
+ }
1299
+ if (response.status === 202) {
1300
+ const wire2 = response.data;
1301
+ return {
1302
+ status: "mfa_required",
1303
+ mfaToken: wire2.challenge_token,
1304
+ availableMethods: wire2.available_methods
1305
+ };
1306
+ }
1307
+ const wire = response.data;
1308
+ client.session.authenticated = true;
1309
+ await client.session.onAuthenticated?.();
1310
+ return {
1311
+ status: "authenticated",
1312
+ user: { id: wire.user.id, username: wire.user.username, email: wire.user.email },
1313
+ sessionId: wire.session_id,
1314
+ expiresIn: wire.expires_in
1315
+ };
1316
+ }
1317
+ async function requestChallenge(client, usernameOrEmail, group) {
1318
+ const session = await beginClientSession(group);
1319
+ const body = {
1320
+ ...client.session.buildLoginBody(usernameOrEmail, ""),
1321
+ client_public: session.clientPublic
1322
+ };
1323
+ delete body.password;
1324
+ try {
1325
+ const response = await client.session.axios.post(SRP_CHALLENGE_PATH, body);
1326
+ return { session, challenge: response.data };
1327
+ } catch (err) {
1328
+ if (axiosStatus(err) === 404) {
1329
+ throw new NetworkError(
1330
+ "this tenant does not offer Secure Remote Password (srp_mode is disabled); use login() instead"
1331
+ );
1332
+ }
1333
+ const status = axiosStatus(err);
1334
+ if (status !== void 0) {
1335
+ throw mapHttpStatusToError(status, axiosMessage(err), { cause: err });
1336
+ }
1337
+ throw new NetworkError("SRP challenge request failed", sanitizeAxiosError(err));
1338
+ }
1339
+ }
1340
+ async function srpEnrollment(options) {
1341
+ const group = parseGroup(options.group);
1342
+ const kdf = options.kdf === "pbkdf2_sha256" ? "pbkdf2_sha256" : "argon2id";
1343
+ const iterations = options.iterations ?? (kdf === "argon2id" ? 2 : 6e5);
1344
+ const memoryKib = kdf === "argon2id" ? options.memoryKib ?? 19456 : void 0;
1345
+ const parallelism = kdf === "argon2id" ? options.parallelism ?? 1 : void 0;
1346
+ const salt = generateSalt();
1347
+ const x = await deriveX(options.identity, options.password, salt, {
1348
+ kdf,
1349
+ iterations,
1350
+ memoryKib,
1351
+ parallelism
1352
+ });
1353
+ return {
1354
+ group,
1355
+ kdf,
1356
+ ...memoryKib !== void 0 ? { memory_kib: memoryKib } : {},
1357
+ iterations,
1358
+ ...parallelism !== void 0 ? { parallelism } : {},
1359
+ salt,
1360
+ verifier: await computeVerifier(group, x)
1361
+ };
1362
+ }
1363
+ function srpAvailable() {
1364
+ return typeof globalThis.crypto?.subtle?.digest === "function" && typeof BigInt === "function";
1365
+ }
1366
+
1086
1367
  // src/rest/retry.ts
1087
1368
  var MAX_ATTEMPTS = 3;
1088
1369
  var BASE_DELAY_MS = 200;
@@ -1291,6 +1572,28 @@ var AxiamClient = class {
1291
1572
  login(email, password) {
1292
1573
  return login(this, email, password);
1293
1574
  }
1575
+ /**
1576
+ * SRP-6a login (§23) — the password never leaves this process.
1577
+ *
1578
+ * Returns the same `LoginResult` as {@link login}, including the
1579
+ * `mfa_required` branch, so one result handler serves both. Rejects with a
1580
+ * `NetworkError` naming SRP when the tenant has it disabled, so a caller can
1581
+ * fall back to {@link login} rather than mistaking it for a bad password.
1582
+ */
1583
+ loginSrp(usernameOrEmail, password) {
1584
+ return loginSrp(this, usernameOrEmail, password);
1585
+ }
1586
+ /**
1587
+ * Compute an SRP verifier to send with any request that sets a password
1588
+ * (§23). The server cannot derive one — it never sees the plaintext.
1589
+ */
1590
+ srpEnrollment(options) {
1591
+ return srpEnrollment(options);
1592
+ }
1593
+ /** Whether this runtime can perform SRP (§23.1). Always true here. */
1594
+ srpAvailable() {
1595
+ return srpAvailable();
1596
+ }
1294
1597
  /** `POST /api/v1/auth/mfa/verify` (§1, D-18). Completes the two-phase flow started by login(). */
1295
1598
  verifyMfa(mfaToken, code) {
1296
1599
  return verifyMfa(this, mfaToken, code);