@atol-sh/js 0.4.3 → 0.5.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/index.d.cts CHANGED
@@ -164,7 +164,7 @@ declare function backoffDelay(attempt: number, rand?: () => number): number;
164
164
  /**
165
165
  * DPoP (RFC 9449) client implementation.
166
166
  *
167
- * This module owns the per-tab ES256 keypair used for sender-constrained
167
+ * This module owns the per-tab proof keypair used for sender-constrained
168
168
  * tokens, plus the proof-JWT builder used for token-endpoint and protected
169
169
  * resource requests.
170
170
  *
@@ -174,11 +174,10 @@ declare function backoffDelay(attempt: number, rand?: () => number): number;
174
174
  * - Every authorization gets a new key. A full redirect stages only its
175
175
  * opaque CryptoKey handles in IndexedDB until the matching callback
176
176
  * consumes them; iframe grants keep the key in memory.
177
- * - ES256 / P-256 only. Universal WebCrypto support, matches what the
178
- * server's DPoP validator accepts first.
177
+ * - ML-DSA-87 uses native WebCrypto. Explicit ES256 uses the same
178
+ * private-key custody for legacy issuers.
179
179
  *
180
- * The module is a no-op fallback when WebCrypto is unavailable (SSR,
181
- * extremely old browsers). Callers treat a null manager as "Bearer mode".
180
+ * A null manager means WebCrypto could not generate the requested key.
182
181
  */
183
182
  /** Optional per-proof inputs (RFC 9449 resource access + server nonce). */
184
183
  interface DPoPProofOptions {
@@ -196,20 +195,28 @@ interface DPoPProofOptions {
196
195
  */
197
196
  nonce?: string;
198
197
  }
198
+ /** The RFC 9964 ML-DSA-87 algorithm identifier. */
199
+ declare const ML_DSA_87 = "ML-DSA-87";
200
+ /** Proof signature algorithms available through the browser's WebCrypto implementation. */
201
+ type DPoPAlgorithm = "ES256" | typeof ML_DSA_87;
202
+ interface DPoPPublicJWK extends JsonWebKey {
203
+ /** RFC 9964 public-key byte string (base64url), present for AKP. */
204
+ pub?: string;
205
+ }
199
206
  interface DPoPKeyManager {
200
207
  /** Sign a proof for a specific (method, url) pair, plus optional ath/nonce. */
201
208
  signProof(method: string, url: string, options?: DPoPProofOptions): Promise<string>;
202
209
  /** Public JWK -- used by the server to compute `cnf.jkt`. */
203
- publicJWK(): Promise<JsonWebKey>;
210
+ publicJWK(): Promise<DPoPPublicJWK>;
204
211
  /** RFC 7638 SHA-256 thumbprint expected in a bound token's `cnf.jkt`. */
205
212
  thumbprint(): Promise<string>;
206
213
  }
207
214
  /**
208
215
  * Create a per-tab DPoP key manager. Returns null when WebCrypto is not
209
- * available. The caller decides whether that means Bearer fallback or a
210
- * fatal error according to its public configuration.
216
+ * available for the requested algorithm. The browser auth client treats
217
+ * creation failure as fatal under its default ML-DSA-87 policy.
211
218
  */
212
- declare function createDPoPKeyManager(): Promise<DPoPKeyManager | null>;
219
+ declare function createDPoPKeyManager(algorithm?: DPoPAlgorithm): Promise<DPoPKeyManager | null>;
213
220
 
214
221
  interface TokenResponse {
215
222
  access_token: string;
@@ -304,13 +311,21 @@ interface AtolBrowserAuthConfig {
304
311
  responseVault?: boolean;
305
312
  /**
306
313
  * Request DPoP-bound tokens (RFC 9449). `true` (or `{ required: true }`)
307
- * generates a per-tab non-exportable ES256 keypair on init and attaches a
308
- * proof to every token-endpoint call. `{ required: true }` also makes key
309
- * creation failure fatal; boolean `true` retains a Bearer fallback where
310
- * WebCrypto is unavailable. `false` (default) uses Bearer for ordinary
311
- * clients. Response-vault mode always requires DPoP and rejects `false`.
314
+ * generates a per-tab non-exportable proof keypair and attaches a
315
+ * proof to every token-endpoint call. The default signature policy
316
+ * requires ML-DSA-87 and treats key creation failure as fatal. Explicit
317
+ * legacy mode uses ES256 and `{ required: true }` makes key creation
318
+ * failure fatal there. `false` (default) uses Bearer for ordinary clients.
319
+ * Response-vault mode always requires DPoP and rejects `false`.
312
320
  */
313
321
  dpop?: DPoPConfig;
322
+ /**
323
+ * Defaults to true. Require RFC 9964 ML-DSA-87 signatures on ID and
324
+ * access tokens, and non-exportable WebCrypto ML-DSA-87 proof keys when
325
+ * DPoP is enabled. Unsupported crypto terminates authentication. Set
326
+ * explicitly to false only for legacy issuer and browser compatibility.
327
+ */
328
+ requireMLDSA87?: boolean;
314
329
  /**
315
330
  * Silent renewal strategy. Default (false): hidden-iframe silent
316
331
  * authentication against the IdP session cookie (prompt=none) - no
@@ -366,7 +381,8 @@ interface AtolBrowserAuthConfig {
366
381
  * in-memory storage is that persisted tokens are unreadable after an XSS,
367
382
  * and this flag must not reopen that surface. When enabled, the client logs
368
383
  * a one-time `console.warn` at construction as a guard against accidental
369
- * production enablement.
384
+ * production enablement. Synthetic tests must explicitly configure
385
+ * `requireMLDSA87: false`.
370
386
  */
371
387
  allowTestSessions?: boolean;
372
388
  /**
@@ -717,6 +733,7 @@ declare function verifyIdToken(idToken: string, opts: {
717
733
  authority: string;
718
734
  clientId: string;
719
735
  nonce?: string;
736
+ requireMLDSA87?: boolean;
720
737
  }): Promise<JWTPayload>;
721
738
  /**
722
739
  * Verify an Atol JWT access token before any proof-binding, subject, or
@@ -726,6 +743,7 @@ declare function verifyIdToken(idToken: string, opts: {
726
743
  declare function verifyAccessToken(accessToken: string, opts: {
727
744
  authority: string;
728
745
  audience: string;
746
+ requireMLDSA87?: boolean;
729
747
  }): Promise<JWTPayload>;
730
748
  /** Test-only: drop the discovery cache so a test can re-stub the IdP. */
731
749
  declare function _resetDiscoveryCache(): void;
@@ -915,8 +933,8 @@ declare function extractKEKFromFragment(): string | null;
915
933
  declare function kekBase64ToBytes(b64: string): Uint8Array;
916
934
  /**
917
935
  * Unwrap a DEK using the KEK via AES-256-GCM (Web Crypto API). The
918
- * `wrappedDEK` format is `base64(nonce12bytes || ciphertext || tag)`,
919
- * matching the wire format the Atol authorize endpoint emits.
936
+ * v2 wire format is `v2.base64url(nonce || ciphertext || tag)`.
937
+ * Historical unversioned blobs retain their original decoding path.
920
938
  *
921
939
  * Kept as a public utility so callers that prefer to own DEK lifetime
922
940
  * themselves (e.g. tests, or frontends that intentionally avoid
@@ -950,4 +968,4 @@ declare function stringToBase64Url(input: string): string;
950
968
  */
951
969
  declare function base64ToBytes(b64: string): Uint8Array;
952
970
 
953
- export { type AtolBrowserAuth, AtolBrowserAuthCleanupError, type AtolBrowserAuthConfig, type AtolSession, type AtolUser, type AuthorizationCodeCallback, AuthorizationCodeExchangeUncertainError, type BeginLoginOptions, type BroadcastMessage, type CredentialsInvalidatedMessage, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, type DPoPConfig, type DPoPKeyManager, type DPoPProofOptions, type DPoPProofResult, type DPoPSigner, type GetAccessTokenOptions, KEKVault, type LoadPermissionsOptions, LoginRequiredError, NetworkError, OAuthProtocolError, OrdinaryAuthorizationIntentConflictError, OrdinaryAuthorizationPendingError, type PermissionCheck, type PermissionResult, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, type SessionEndedMessage, type StepUpOptions, type TokenBroadcast, type TokenResponse, _resetDiscoveryCache, backoffDelay, base64ToBytes, bytesToBase64Url, classifyRenewalError, createAtolBrowserAuth, createDPoPKeyManager, createTokenBroadcast, createUserManager, decodeJWTPayload, exchangeCode, extractKEKFromFragment, getAccessToken, getIdToken, getTokenExpiry, hasBroadcastSupport, hasTabLockSupport, kekBase64ToBytes, loadPermissions, parseAtolUser, permissionKey, readAuthorizationCodeCallback, refreshTokenGrant, revokeToken, stringToBase64Url, unwrapDEK, userFromTokenResponse, verifyAccessToken, verifyIdToken, withTabLock };
971
+ export { type AtolBrowserAuth, AtolBrowserAuthCleanupError, type AtolBrowserAuthConfig, type AtolSession, type AtolUser, type AuthorizationCodeCallback, AuthorizationCodeExchangeUncertainError, type BeginLoginOptions, type BroadcastMessage, type CredentialsInvalidatedMessage, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, type DPoPAlgorithm, type DPoPConfig, type DPoPKeyManager, type DPoPProofOptions, type DPoPProofResult, type DPoPPublicJWK, type DPoPSigner, type GetAccessTokenOptions, KEKVault, type LoadPermissionsOptions, LoginRequiredError, ML_DSA_87, NetworkError, OAuthProtocolError, OrdinaryAuthorizationIntentConflictError, OrdinaryAuthorizationPendingError, type PermissionCheck, type PermissionResult, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, type SessionEndedMessage, type StepUpOptions, type TokenBroadcast, type TokenResponse, _resetDiscoveryCache, backoffDelay, base64ToBytes, bytesToBase64Url, classifyRenewalError, createAtolBrowserAuth, createDPoPKeyManager, createTokenBroadcast, createUserManager, decodeJWTPayload, exchangeCode, extractKEKFromFragment, getAccessToken, getIdToken, getTokenExpiry, hasBroadcastSupport, hasTabLockSupport, kekBase64ToBytes, loadPermissions, parseAtolUser, permissionKey, readAuthorizationCodeCallback, refreshTokenGrant, revokeToken, stringToBase64Url, unwrapDEK, userFromTokenResponse, verifyAccessToken, verifyIdToken, withTabLock };
package/dist/index.d.ts CHANGED
@@ -164,7 +164,7 @@ declare function backoffDelay(attempt: number, rand?: () => number): number;
164
164
  /**
165
165
  * DPoP (RFC 9449) client implementation.
166
166
  *
167
- * This module owns the per-tab ES256 keypair used for sender-constrained
167
+ * This module owns the per-tab proof keypair used for sender-constrained
168
168
  * tokens, plus the proof-JWT builder used for token-endpoint and protected
169
169
  * resource requests.
170
170
  *
@@ -174,11 +174,10 @@ declare function backoffDelay(attempt: number, rand?: () => number): number;
174
174
  * - Every authorization gets a new key. A full redirect stages only its
175
175
  * opaque CryptoKey handles in IndexedDB until the matching callback
176
176
  * consumes them; iframe grants keep the key in memory.
177
- * - ES256 / P-256 only. Universal WebCrypto support, matches what the
178
- * server's DPoP validator accepts first.
177
+ * - ML-DSA-87 uses native WebCrypto. Explicit ES256 uses the same
178
+ * private-key custody for legacy issuers.
179
179
  *
180
- * The module is a no-op fallback when WebCrypto is unavailable (SSR,
181
- * extremely old browsers). Callers treat a null manager as "Bearer mode".
180
+ * A null manager means WebCrypto could not generate the requested key.
182
181
  */
183
182
  /** Optional per-proof inputs (RFC 9449 resource access + server nonce). */
184
183
  interface DPoPProofOptions {
@@ -196,20 +195,28 @@ interface DPoPProofOptions {
196
195
  */
197
196
  nonce?: string;
198
197
  }
198
+ /** The RFC 9964 ML-DSA-87 algorithm identifier. */
199
+ declare const ML_DSA_87 = "ML-DSA-87";
200
+ /** Proof signature algorithms available through the browser's WebCrypto implementation. */
201
+ type DPoPAlgorithm = "ES256" | typeof ML_DSA_87;
202
+ interface DPoPPublicJWK extends JsonWebKey {
203
+ /** RFC 9964 public-key byte string (base64url), present for AKP. */
204
+ pub?: string;
205
+ }
199
206
  interface DPoPKeyManager {
200
207
  /** Sign a proof for a specific (method, url) pair, plus optional ath/nonce. */
201
208
  signProof(method: string, url: string, options?: DPoPProofOptions): Promise<string>;
202
209
  /** Public JWK -- used by the server to compute `cnf.jkt`. */
203
- publicJWK(): Promise<JsonWebKey>;
210
+ publicJWK(): Promise<DPoPPublicJWK>;
204
211
  /** RFC 7638 SHA-256 thumbprint expected in a bound token's `cnf.jkt`. */
205
212
  thumbprint(): Promise<string>;
206
213
  }
207
214
  /**
208
215
  * Create a per-tab DPoP key manager. Returns null when WebCrypto is not
209
- * available. The caller decides whether that means Bearer fallback or a
210
- * fatal error according to its public configuration.
216
+ * available for the requested algorithm. The browser auth client treats
217
+ * creation failure as fatal under its default ML-DSA-87 policy.
211
218
  */
212
- declare function createDPoPKeyManager(): Promise<DPoPKeyManager | null>;
219
+ declare function createDPoPKeyManager(algorithm?: DPoPAlgorithm): Promise<DPoPKeyManager | null>;
213
220
 
214
221
  interface TokenResponse {
215
222
  access_token: string;
@@ -304,13 +311,21 @@ interface AtolBrowserAuthConfig {
304
311
  responseVault?: boolean;
305
312
  /**
306
313
  * Request DPoP-bound tokens (RFC 9449). `true` (or `{ required: true }`)
307
- * generates a per-tab non-exportable ES256 keypair on init and attaches a
308
- * proof to every token-endpoint call. `{ required: true }` also makes key
309
- * creation failure fatal; boolean `true` retains a Bearer fallback where
310
- * WebCrypto is unavailable. `false` (default) uses Bearer for ordinary
311
- * clients. Response-vault mode always requires DPoP and rejects `false`.
314
+ * generates a per-tab non-exportable proof keypair and attaches a
315
+ * proof to every token-endpoint call. The default signature policy
316
+ * requires ML-DSA-87 and treats key creation failure as fatal. Explicit
317
+ * legacy mode uses ES256 and `{ required: true }` makes key creation
318
+ * failure fatal there. `false` (default) uses Bearer for ordinary clients.
319
+ * Response-vault mode always requires DPoP and rejects `false`.
312
320
  */
313
321
  dpop?: DPoPConfig;
322
+ /**
323
+ * Defaults to true. Require RFC 9964 ML-DSA-87 signatures on ID and
324
+ * access tokens, and non-exportable WebCrypto ML-DSA-87 proof keys when
325
+ * DPoP is enabled. Unsupported crypto terminates authentication. Set
326
+ * explicitly to false only for legacy issuer and browser compatibility.
327
+ */
328
+ requireMLDSA87?: boolean;
314
329
  /**
315
330
  * Silent renewal strategy. Default (false): hidden-iframe silent
316
331
  * authentication against the IdP session cookie (prompt=none) - no
@@ -366,7 +381,8 @@ interface AtolBrowserAuthConfig {
366
381
  * in-memory storage is that persisted tokens are unreadable after an XSS,
367
382
  * and this flag must not reopen that surface. When enabled, the client logs
368
383
  * a one-time `console.warn` at construction as a guard against accidental
369
- * production enablement.
384
+ * production enablement. Synthetic tests must explicitly configure
385
+ * `requireMLDSA87: false`.
370
386
  */
371
387
  allowTestSessions?: boolean;
372
388
  /**
@@ -717,6 +733,7 @@ declare function verifyIdToken(idToken: string, opts: {
717
733
  authority: string;
718
734
  clientId: string;
719
735
  nonce?: string;
736
+ requireMLDSA87?: boolean;
720
737
  }): Promise<JWTPayload>;
721
738
  /**
722
739
  * Verify an Atol JWT access token before any proof-binding, subject, or
@@ -726,6 +743,7 @@ declare function verifyIdToken(idToken: string, opts: {
726
743
  declare function verifyAccessToken(accessToken: string, opts: {
727
744
  authority: string;
728
745
  audience: string;
746
+ requireMLDSA87?: boolean;
729
747
  }): Promise<JWTPayload>;
730
748
  /** Test-only: drop the discovery cache so a test can re-stub the IdP. */
731
749
  declare function _resetDiscoveryCache(): void;
@@ -915,8 +933,8 @@ declare function extractKEKFromFragment(): string | null;
915
933
  declare function kekBase64ToBytes(b64: string): Uint8Array;
916
934
  /**
917
935
  * Unwrap a DEK using the KEK via AES-256-GCM (Web Crypto API). The
918
- * `wrappedDEK` format is `base64(nonce12bytes || ciphertext || tag)`,
919
- * matching the wire format the Atol authorize endpoint emits.
936
+ * v2 wire format is `v2.base64url(nonce || ciphertext || tag)`.
937
+ * Historical unversioned blobs retain their original decoding path.
920
938
  *
921
939
  * Kept as a public utility so callers that prefer to own DEK lifetime
922
940
  * themselves (e.g. tests, or frontends that intentionally avoid
@@ -950,4 +968,4 @@ declare function stringToBase64Url(input: string): string;
950
968
  */
951
969
  declare function base64ToBytes(b64: string): Uint8Array;
952
970
 
953
- export { type AtolBrowserAuth, AtolBrowserAuthCleanupError, type AtolBrowserAuthConfig, type AtolSession, type AtolUser, type AuthorizationCodeCallback, AuthorizationCodeExchangeUncertainError, type BeginLoginOptions, type BroadcastMessage, type CredentialsInvalidatedMessage, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, type DPoPConfig, type DPoPKeyManager, type DPoPProofOptions, type DPoPProofResult, type DPoPSigner, type GetAccessTokenOptions, KEKVault, type LoadPermissionsOptions, LoginRequiredError, NetworkError, OAuthProtocolError, OrdinaryAuthorizationIntentConflictError, OrdinaryAuthorizationPendingError, type PermissionCheck, type PermissionResult, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, type SessionEndedMessage, type StepUpOptions, type TokenBroadcast, type TokenResponse, _resetDiscoveryCache, backoffDelay, base64ToBytes, bytesToBase64Url, classifyRenewalError, createAtolBrowserAuth, createDPoPKeyManager, createTokenBroadcast, createUserManager, decodeJWTPayload, exchangeCode, extractKEKFromFragment, getAccessToken, getIdToken, getTokenExpiry, hasBroadcastSupport, hasTabLockSupport, kekBase64ToBytes, loadPermissions, parseAtolUser, permissionKey, readAuthorizationCodeCallback, refreshTokenGrant, revokeToken, stringToBase64Url, unwrapDEK, userFromTokenResponse, verifyAccessToken, verifyIdToken, withTabLock };
971
+ export { type AtolBrowserAuth, AtolBrowserAuthCleanupError, type AtolBrowserAuthConfig, type AtolSession, type AtolUser, type AuthorizationCodeCallback, AuthorizationCodeExchangeUncertainError, type BeginLoginOptions, type BroadcastMessage, type CredentialsInvalidatedMessage, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, type DPoPAlgorithm, type DPoPConfig, type DPoPKeyManager, type DPoPProofOptions, type DPoPProofResult, type DPoPPublicJWK, type DPoPSigner, type GetAccessTokenOptions, KEKVault, type LoadPermissionsOptions, LoginRequiredError, ML_DSA_87, NetworkError, OAuthProtocolError, OrdinaryAuthorizationIntentConflictError, OrdinaryAuthorizationPendingError, type PermissionCheck, type PermissionResult, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, type SessionEndedMessage, type StepUpOptions, type TokenBroadcast, type TokenResponse, _resetDiscoveryCache, backoffDelay, base64ToBytes, bytesToBase64Url, classifyRenewalError, createAtolBrowserAuth, createDPoPKeyManager, createTokenBroadcast, createUserManager, decodeJWTPayload, exchangeCode, extractKEKFromFragment, getAccessToken, getIdToken, getTokenExpiry, hasBroadcastSupport, hasTabLockSupport, kekBase64ToBytes, loadPermissions, parseAtolUser, permissionKey, readAuthorizationCodeCallback, refreshTokenGrant, revokeToken, stringToBase64Url, unwrapDEK, userFromTokenResponse, verifyAccessToken, verifyIdToken, withTabLock };