@pk-auth/passkeys-browser 2.0.0 → 2.3.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/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # `@pk-auth/passkeys-browser`
2
2
 
3
- Zero-dependency TypeScript SDK for the pk-auth wire contract.
4
- Published to npm as [`@pk-auth/passkeys-browser`](https://www.npmjs.com/package/@pk-auth/passkeys-browser);
5
- its version tracks the pk-auth server release it speaks to. The example apps in
6
- this repo consume it via a relative `dist/` import (built by Gradle) rather than
7
- the published package. See [`RELEASE.md`](../../RELEASE.md) for the publish steps.
3
+ Zero-dependency TypeScript SDK for the pk-auth wire contract. It is published to npm as
4
+ [`@pk-auth/passkeys-browser`](https://www.npmjs.com/package/@pk-auth/passkeys-browser), and its
5
+ version tracks the pk-auth server release it speaks to. The example apps in this repository consume
6
+ it through a relative `dist/` import (built by Gradle) instead of the published package. The
7
+ publish steps are in [`RELEASE.md`](../../RELEASE.md).
8
8
 
9
9
  ```sh
10
10
  npm install @pk-auth/passkeys-browser
@@ -27,18 +27,19 @@ await pk.ceremonies.register({ username: "alice", label: "MacBook" });
27
27
  const { token } = await pk.ceremonies.authenticate({ username: "alice" });
28
28
  localStorage.setItem("pk-jwt", token);
29
29
 
30
- // Admin (require a token)
30
+ // Admin (requires a token)
31
31
  await pk.admin.listCredentials();
32
32
  await pk.admin.regenerateBackupCodes();
33
33
  ```
34
34
 
35
- Two clients are exposed independently if a host only needs one half:
35
+ The clients are also exported individually, for hosts that need only part of the surface:
36
36
 
37
- - `PkAuthCeremonyClient` — `startRegistration`, `register`, `startAuthentication`, `authenticate`.
38
- - `PkAuthAdminClient` — `listCredentials`, `renameCredential`, `removeCredential`,
37
+ - `PkAuthCeremonyClient`: `startRegistration`, `register`, `startAuthentication`, `authenticate`.
38
+ - `PkAuthAdminClient`: `listCredentials`, `renameCredential`, `removeCredential`,
39
39
  `regenerateBackupCodes`, `remainingBackupCodes`, `startEmailVerification`,
40
40
  `completeEmailVerification`, `startPhoneVerification`, `completePhoneVerification`,
41
41
  `getAccount`.
42
+ - `PkAuthRefreshClient`: `refresh`.
42
43
 
43
44
  ### Conditional UI
44
45
 
@@ -46,15 +47,15 @@ Two clients are exposed independently if a host only needs one half:
46
47
  await pk.ceremonies.authenticate({ conditional: true });
47
48
  ```
48
49
 
49
- Wires `mediation: "conditional"` into the underlying `navigator.credentials.get` call,
50
- so the browser can offer passkeys via autofill UI before the user clicks "Sign in."
50
+ This passes `mediation: "conditional"` to the underlying `navigator.credentials.get` call, so the
51
+ browser can offer passkeys through the autofill UI before the user selects "Sign in".
51
52
 
52
- ### Overriding ceremony paths
53
+ ### Ceremony path overrides
53
54
 
54
55
  All three adapters (Spring Boot, Dropwizard, Micronaut) mount the ceremony endpoints at the
55
- same `/auth/passkeys/...` paths, which are the SDK defaults — no per-adapter override is
56
- needed. The `paths` option remains an escape hatch for hosts that remount the endpoints under
57
- a custom prefix:
56
+ same `/auth/passkeys/...` paths, which are the SDK defaults, so no per-adapter override is
57
+ needed. The `paths` option is an escape hatch for hosts that remount the endpoints under a custom
58
+ prefix:
58
59
 
59
60
  ```ts
60
61
  new PkAuthCeremonyClient(options, {
@@ -67,7 +68,7 @@ new PkAuthCeremonyClient(options, {
67
68
  });
68
69
  ```
69
70
 
70
- ## Build / test
71
+ ## Build and test
71
72
 
72
73
  ```sh
73
74
  npm install
@@ -75,7 +76,7 @@ npm test # vitest, jsdom env
75
76
  npm run build # tsup → dist/index.{js,cjs,d.ts}
76
77
  ```
77
78
 
78
- `dist/` is gitignored — Gradle's `:buildPasskeysBrowserSdk` task (defined in the root
79
- `build.gradle.kts`) runs `npm ci && npm run build` before each demo's `processResources`,
80
- so the bundle is regenerated from source on every fresh clone. Run the npm commands above
81
- directly when iterating on the SDK in isolation.
79
+ `dist/` is gitignored. Gradle's `:buildPasskeysBrowserSdk` task (defined in the root
80
+ `build.gradle.kts`) runs `npm ci && npm run build` before each demo's `processResources`, so the
81
+ bundle is regenerated from source on every fresh clone. Iterating on the SDK in isolation uses the
82
+ npm commands above directly.
package/dist/index.cjs CHANGED
@@ -40,7 +40,9 @@ function decodeToArrayBuffer(input) {
40
40
  }
41
41
  function toUint8Array(input) {
42
42
  if (input instanceof Uint8Array) return input;
43
- if (input instanceof ArrayBuffer) return new Uint8Array(input);
43
+ if (input instanceof ArrayBuffer || Object.prototype.toString.call(input) === "[object ArrayBuffer]") {
44
+ return new Uint8Array(input);
45
+ }
44
46
  return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
45
47
  }
46
48
 
@@ -149,7 +151,7 @@ var PkAuthCeremonyClient = class {
149
151
  }
150
152
  /**
151
153
  * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →
152
- * server-finish. Returns the JWT (consumer is responsible for storage).
154
+ * server-finish. Returns the JWT; the caller stores it.
153
155
  */
154
156
  async authenticate(params = {}) {
155
157
  const start = await this.startAuthentication({
@@ -371,7 +373,7 @@ var PkAuthClient = class {
371
373
  }
372
374
  /**
373
375
  * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed
374
- * {@link RefreshResult} sum — does not throw on 401.
376
+ * {@link RefreshResult} sum and does not throw on 401.
375
377
  *
376
378
  * @since 1.1.0
377
379
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base64url.ts","../src/http.ts","../src/results.ts","../src/ceremonies.ts","../src/admin.ts","../src/refresh.ts","../src/index.ts"],"names":["request","PATHS"],"mappings":";;;;;;;;;AAAA,IAAA,iBAAA,GAAA;AAAA,QAAA,CAAA,iBAAA,EAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,MAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAWO,SAAS,OAAO,KAAA,EAA8D;AACnF,EAAA,MAAM,KAAA,GAAQ,aAAa,KAAK,CAAA;AAChC,EAAA,IAAI,CAAA,GAAI,EAAA;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eAAe,CAAA;AACnE,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,iBAAA,CAAkB,OAAO,CAAA;AAC1C,IAAA,IAAA,CAAK,aAAA,GAAgB,IAAI,mBAAA,CAAoB,OAAO,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAQ,YAAA,EAA8C;AACpD,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,OAAA,CAAQ,YAAY,CAAA;AAAA,EAChD;AACF","file":"index.cjs","sourcesContent":["// SPDX-License-Identifier: MIT\n\n/**\n * Base64url (RFC 4648 §5) without padding — matches pk-auth's wire format.\n * The server's Jackson module emits unpadded base64url; browsers can mix\n * Uint8Array, ArrayBuffer, or already-base64url strings, so encode handles\n * all three.\n */\n\nexport type Base64Url = string;\n\nexport function encode(input: ArrayBuffer | Uint8Array | ArrayBufferView): Base64Url {\n const bytes = toUint8Array(input);\n let s = \"\";\n for (let i = 0; i < bytes.length; i++) {\n s += String.fromCharCode(bytes[i]!);\n }\n // base64url per RFC 4648 §5: map +/ to -_ and strip padding. Using replaceAll with\n // string literals (no regexes) keeps this linear — it avoids the ReDoS shape\n // SonarQube flags on `/=+$/`. `=` only ever appears as trailing base64 padding, so\n // removing all of it is equivalent to stripping the trailing run.\n return btoa(s).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\n\nexport function decode(input: Base64Url): Uint8Array {\n const pad = \"=\".repeat((4 - (input.length % 4)) % 4);\n const normalized = input.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + pad;\n const binary = atob(normalized);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\nexport function decodeToArrayBuffer(input: Base64Url): ArrayBuffer {\n const bytes = decode(input);\n return bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n ) as ArrayBuffer;\n}\n\nfunction toUint8Array(input: ArrayBuffer | Uint8Array | ArrayBufferView): Uint8Array {\n if (input instanceof Uint8Array) return input;\n if (input instanceof ArrayBuffer) return new Uint8Array(input);\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n}\n","// SPDX-License-Identifier: MIT\n\nimport type { ClientOptions } from \"./types\";\n\nexport class PkAuthHttpError extends Error {\n readonly status: number;\n readonly body: string;\n readonly data: Record<string, unknown> | undefined;\n\n constructor(status: number, body: string) {\n super(`HTTP ${status}: ${body}`);\n this.name = \"PkAuthHttpError\";\n this.status = status;\n this.body = body;\n try {\n const parsed = JSON.parse(body);\n this.data = parsed !== null && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : undefined;\n } catch {\n this.data = undefined;\n }\n }\n\n /** The `error` field from the parsed response body, if present. */\n get error(): string | undefined {\n return typeof this.data?.[\"error\"] === \"string\" ? (this.data[\"error\"] as string) : undefined;\n }\n\n /** The `detail` field from the parsed response body, if present. */\n get detail(): string | undefined {\n return typeof this.data?.[\"detail\"] === \"string\" ? (this.data[\"detail\"] as string) : undefined;\n }\n\n /** The `outcome` field from the parsed response body, if present. */\n get outcome(): string | undefined {\n return typeof this.data?.[\"outcome\"] === \"string\" ? (this.data[\"outcome\"] as string) : undefined;\n }\n}\n\n/** Internal request wrapper. `authenticated: true` adds the bearer header from `getToken`. */\nexport async function request<T>(\n options: ClientOptions,\n method: string,\n path: string,\n body: unknown,\n authenticated: boolean,\n): Promise<T> {\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const base = options.apiBase.endsWith(\"/\")\n ? options.apiBase.slice(0, -1)\n : options.apiBase;\n const url = `${base}${path}`;\n\n const headers: Record<string, string> = { accept: \"application/json\" };\n let payload: BodyInit | undefined;\n if (body !== undefined) {\n headers[\"content-type\"] = \"application/json\";\n payload = JSON.stringify(body);\n }\n if (authenticated) {\n const token = options.getToken?.();\n if (!token) {\n throw new Error(\"pk-auth: authenticated request requires getToken() to return a bearer token\");\n }\n headers[\"authorization\"] = `Bearer ${token}`;\n }\n\n const init: RequestInit = { method, headers };\n if (payload !== undefined) init.body = payload;\n const response = await fetchImpl(url, init);\n\n const text = await response.text();\n if (!response.ok) {\n throw new PkAuthHttpError(response.status, text);\n }\n if (!text.length) {\n return undefined as unknown as T;\n }\n return JSON.parse(text) as T;\n}\n","// SPDX-License-Identifier: MIT\n\n/**\n * Discriminated union mirroring the Java sealed result hierarchies\n * (AuthenticationResult / RegistrationResult) as returned by the pk-auth HTTP adapters.\n *\n * Authentication outcomes: success | challenge_invalid | origin_mismatch |\n * signature_invalid | unknown_credential | failed\n *\n * Registration outcomes: success | challenge_invalid | origin_mismatch |\n * attestation_rejected | duplicate_credential | invalid_payload | failed\n */\nexport type CeremonyResult =\n | { outcome: 'success'; token: string; credentialId?: string }\n | { outcome: 'challenge_invalid'; detail?: string }\n | { outcome: 'origin_mismatch'; detail?: string }\n | { outcome: 'signature_invalid'; detail?: string }\n | { outcome: 'unknown_credential'; detail?: string }\n | { outcome: 'attestation_rejected'; detail?: string }\n | { outcome: 'duplicate_credential'; detail?: string }\n | { outcome: 'invalid_payload'; detail?: string }\n | { outcome: 'failed'; detail?: string };\n\n/** Type guard: narrows a CeremonyResult to the success variant. */\nexport function isCeremonySuccess(\n result: CeremonyResult,\n): result is { outcome: 'success'; token: string; credentialId?: string } {\n return result.outcome === 'success';\n}\n\n/** Type guard: narrows a CeremonyResult to any failure variant. */\nexport function isCeremonyFailure(\n result: CeremonyResult,\n): result is Exclude<CeremonyResult, { outcome: 'success' }> {\n return result.outcome !== 'success';\n}\n","// SPDX-License-Identifier: MIT\n\nimport * as b64u from \"./base64url\";\nimport { request } from \"./http\";\nimport type {\n ClientOptions,\n FinishAuthenticationRequest,\n FinishAuthenticationResponse,\n FinishRegistrationRequest,\n FinishRegistrationResponse,\n PublicKeyCredentialCreationOptionsJson,\n PublicKeyCredentialRequestOptionsJson,\n RegistrationResponseJson,\n AuthenticationResponseJson,\n StartAuthenticationRequest,\n StartAuthenticationResponse,\n StartRegistrationRequest,\n StartRegistrationResponse,\n} from \"./types\";\n\nconst PATHS = {\n startReg: \"/auth/passkeys/registration/start\",\n finishReg: \"/auth/passkeys/registration/finish\",\n startAuth: \"/auth/passkeys/authentication/start\",\n finishAuth: \"/auth/passkeys/authentication/finish\",\n} as const;\n\n// All three adapters (Spring, Dropwizard, Micronaut) now mount ceremony endpoints at\n// /auth/passkeys/<phase>/<step>. The `paths` override remains an escape hatch for hosts that\n// remap the routes but is no longer needed for any pk-auth-provided adapter.\n\nexport interface CeremonyOptions {\n /** Path overrides — kept as an escape hatch for hosts that remap pk-auth's default routes. */\n paths?: Partial<typeof PATHS>;\n /** Optional override for navigator.credentials (tests / non-browser callers). */\n credentials?: CredentialsContainer;\n}\n\nexport interface StartRegistrationParams {\n username: string;\n displayName?: string;\n label?: string;\n}\n\nexport interface FinishRegistrationParams extends StartRegistrationResponse {\n username: string;\n label?: string;\n}\n\nexport interface StartAuthenticationParams {\n username?: string;\n /** When true, hands the call to `navigator.credentials.get` with `mediation: \"conditional\"`. */\n conditional?: boolean;\n}\n\nexport class PkAuthCeremonyClient {\n private readonly client: ClientOptions;\n private readonly paths: typeof PATHS;\n private readonly credentials?: CredentialsContainer;\n\n constructor(client: ClientOptions, options: CeremonyOptions = {}) {\n this.client = client;\n this.paths = { ...PATHS, ...options.paths };\n this.credentials = options.credentials;\n }\n\n /**\n * Runs the full registration ceremony: server-start → `navigator.credentials.create` →\n * server-finish. Returns the finish payload (registered credential metadata).\n */\n async register(params: StartRegistrationParams): Promise<FinishRegistrationResponse> {\n const start = await this.startRegistration({\n username: params.username,\n displayName: params.displayName ?? params.username,\n label: params.label ?? null,\n challenge: null,\n });\n const created = await this.createCredential(start.publicKey);\n return this.finishRegistration({\n challengeId: start.challengeId,\n username: params.username,\n label: params.label ?? null,\n response: encodeRegistrationResponse(created),\n });\n }\n\n /**\n * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →\n * server-finish. Returns the JWT (consumer is responsible for storage).\n */\n async authenticate(params: StartAuthenticationParams = {}): Promise<FinishAuthenticationResponse> {\n const start = await this.startAuthentication({\n username: params.username ?? null,\n challenge: null,\n });\n const got = await this.getCredential(start.publicKey, params.conditional ?? false);\n return this.finishAuthentication({\n challengeId: start.challengeId,\n response: encodeAuthenticationResponse(got),\n });\n }\n\n startRegistration(body: StartRegistrationRequest): Promise<StartRegistrationResponse> {\n return request(this.client, \"POST\", this.paths.startReg, body, false);\n }\n\n finishRegistration(body: FinishRegistrationRequest): Promise<FinishRegistrationResponse> {\n return request(this.client, \"POST\", this.paths.finishReg, body, false);\n }\n\n startAuthentication(body: StartAuthenticationRequest): Promise<StartAuthenticationResponse> {\n return request(this.client, \"POST\", this.paths.startAuth, body, false);\n }\n\n finishAuthentication(body: FinishAuthenticationRequest): Promise<FinishAuthenticationResponse> {\n return request(this.client, \"POST\", this.paths.finishAuth, body, false);\n }\n\n private get credentialsImpl(): CredentialsContainer {\n if (this.credentials) return this.credentials;\n if (typeof navigator === \"undefined\" || !navigator.credentials) {\n throw new Error(\"pk-auth: navigator.credentials is not available in this environment\");\n }\n return navigator.credentials;\n }\n\n private async createCredential(\n options: PublicKeyCredentialCreationOptionsJson,\n ): Promise<PublicKeyCredential> {\n const publicKey = decodeCreationOptions(options);\n const credential = (await this.credentialsImpl.create({ publicKey })) as PublicKeyCredential | null;\n if (!credential) {\n throw new Error(\"pk-auth: credential creation was cancelled\");\n }\n return credential;\n }\n\n private async getCredential(\n options: PublicKeyCredentialRequestOptionsJson,\n conditional: boolean,\n ): Promise<PublicKeyCredential> {\n const publicKey = decodeRequestOptions(options);\n const request: CredentialRequestOptions = { publicKey };\n if (conditional) {\n (request as CredentialRequestOptions & { mediation?: string }).mediation = \"conditional\";\n }\n const credential = (await this.credentialsImpl.get(request)) as PublicKeyCredential | null;\n if (!credential) {\n throw new Error(\"pk-auth: authentication was cancelled\");\n }\n return credential;\n }\n}\n\nexport function decodeCreationOptions(\n options: PublicKeyCredentialCreationOptionsJson,\n): PublicKeyCredentialCreationOptions {\n return {\n rp: options.rp,\n user: {\n id: b64u.decodeToArrayBuffer(options.user.id),\n name: options.user.name,\n displayName: options.user.displayName,\n },\n challenge: b64u.decodeToArrayBuffer(options.challenge),\n pubKeyCredParams: options.pubKeyCredParams,\n timeout: options.timeout,\n attestation: options.attestation,\n authenticatorSelection: options.authenticatorSelection,\n excludeCredentials: (options.excludeCredentials ?? []).map((c) => ({\n id: b64u.decodeToArrayBuffer(c.id),\n type: c.type,\n transports: c.transports as AuthenticatorTransport[] | undefined,\n })),\n };\n}\n\nexport function decodeRequestOptions(\n options: PublicKeyCredentialRequestOptionsJson,\n): PublicKeyCredentialRequestOptions {\n return {\n challenge: b64u.decodeToArrayBuffer(options.challenge),\n timeout: options.timeout,\n rpId: options.rpId,\n userVerification: options.userVerification,\n allowCredentials: (options.allowCredentials ?? []).map((c) => ({\n id: b64u.decodeToArrayBuffer(c.id),\n type: c.type,\n transports: c.transports as AuthenticatorTransport[] | undefined,\n })),\n };\n}\n\nexport function encodeRegistrationResponse(credential: PublicKeyCredential): RegistrationResponseJson {\n const response = credential.response as AuthenticatorAttestationResponse;\n const transports =\n typeof (response as AuthenticatorAttestationResponse & {\n getTransports?: () => string[];\n }).getTransports === \"function\"\n ? (response as AuthenticatorAttestationResponse & {\n getTransports: () => string[];\n }).getTransports()\n : [];\n return {\n id: b64u.encode(credential.rawId),\n rawId: b64u.encode(credential.rawId),\n type: \"public-key\",\n response: {\n clientDataJSON: b64u.encode(response.clientDataJSON),\n attestationObject: b64u.encode(response.attestationObject),\n transports,\n },\n };\n}\n\nexport function encodeAuthenticationResponse(\n credential: PublicKeyCredential,\n): AuthenticationResponseJson {\n const response = credential.response as AuthenticatorAssertionResponse;\n return {\n id: b64u.encode(credential.rawId),\n rawId: b64u.encode(credential.rawId),\n type: \"public-key\",\n response: {\n clientDataJSON: b64u.encode(response.clientDataJSON),\n authenticatorData: b64u.encode(response.authenticatorData),\n signature: b64u.encode(response.signature),\n userHandle: response.userHandle ? b64u.encode(response.userHandle) : null,\n },\n };\n}\n","// SPDX-License-Identifier: MIT\n\nimport { request } from \"./http\";\nimport type {\n AccountSummary,\n BackupCodeBatch,\n BackupCodeCount,\n ClientOptions,\n CredentialSummary,\n EmailDispatchResult,\n EmailVerificationResult,\n PhoneDispatchResult,\n PhoneVerificationResult,\n} from \"./types\";\n\nconst PATHS = {\n account: \"/auth/admin/account\",\n credentials: \"/auth/admin/credentials\",\n credentialById: (id: string) => `/auth/admin/credentials/${encodeURIComponent(id)}`,\n backupRegen: \"/auth/admin/backup-codes/regenerate\",\n backupCount: \"/auth/admin/backup-codes/count\",\n emailStart: \"/auth/admin/email/start-verification\",\n emailComplete: \"/auth/admin/email/complete-verification\",\n phoneStart: \"/auth/admin/phone/start-verification\",\n phoneComplete: \"/auth/admin/phone/complete-verification\",\n} as const;\n\nexport class PkAuthAdminClient {\n private readonly client: ClientOptions;\n\n constructor(client: ClientOptions) {\n if (!client.getToken) {\n throw new Error(\"pk-auth: admin client requires `getToken` in ClientOptions\");\n }\n this.client = client;\n }\n\n getAccount(): Promise<AccountSummary> {\n return request(this.client, \"GET\", PATHS.account, undefined, true);\n }\n\n listCredentials(): Promise<CredentialSummary[]> {\n return request(this.client, \"GET\", PATHS.credentials, undefined, true);\n }\n\n renameCredential(credentialId: string, label: string): Promise<CredentialSummary> {\n return request(this.client, \"PATCH\", PATHS.credentialById(credentialId), { label }, true);\n }\n\n removeCredential(credentialId: string): Promise<void> {\n return request(this.client, \"DELETE\", PATHS.credentialById(credentialId), undefined, true);\n }\n\n regenerateBackupCodes(): Promise<BackupCodeBatch> {\n return request(this.client, \"POST\", PATHS.backupRegen, \"\", true);\n }\n\n remainingBackupCodes(): Promise<BackupCodeCount> {\n return request(this.client, \"GET\", PATHS.backupCount, undefined, true);\n }\n\n startEmailVerification(email: string): Promise<EmailDispatchResult> {\n return request(this.client, \"POST\", PATHS.emailStart, { email }, true);\n }\n\n completeEmailVerification(token: string): Promise<EmailVerificationResult> {\n return request(this.client, \"POST\", PATHS.emailComplete, { token }, true);\n }\n\n startPhoneVerification(phone: string): Promise<PhoneDispatchResult> {\n return request(this.client, \"POST\", PATHS.phoneStart, { phone }, true);\n }\n\n completePhoneVerification(phone: string, code: string): Promise<PhoneVerificationResult> {\n return request(this.client, \"POST\", PATHS.phoneComplete, { phone, code }, true);\n }\n}\n","// SPDX-License-Identifier: MIT\n\nimport { PkAuthHttpError, request } from \"./http\";\nimport type { ClientOptions } from \"./types\";\n\n/** Typed success: a fresh refresh + access token pair to swap in. */\nexport interface RefreshSuccess {\n readonly kind: \"success\";\n readonly accessToken: string;\n readonly refreshToken: string;\n readonly expiresAt: string;\n}\n\n/** Typed failure mirroring the {@code detail} field on the server's 401 body. */\nexport type RefreshFailureReason = \"expired\" | \"unknown\" | \"replayed\" | \"revoked\";\n\nexport interface RefreshFailure {\n readonly kind: \"failure\";\n readonly reason: RefreshFailureReason;\n /** Categorical revoke reason when `reason === \"revoked\"`. */\n readonly revokeReason?: string;\n}\n\n/** Sealed sum of refresh outcomes. */\nexport type RefreshResult = RefreshSuccess | RefreshFailure;\n\n/** Type guard for {@link RefreshSuccess}. */\nexport function isRefreshSuccess(r: RefreshResult): r is RefreshSuccess {\n return r.kind === \"success\";\n}\n\n/** Type guard for {@link RefreshFailure}. */\nexport function isRefreshFailure(r: RefreshResult): r is RefreshFailure {\n return r.kind === \"failure\";\n}\n\ninterface RawRefreshResponse {\n refreshToken: string;\n accessToken: string;\n expiresAt: string;\n}\n\ninterface RawErrorResponse {\n detail?: string;\n reason?: string;\n}\n\n/**\n * Client for the {@code POST /auth/refresh} endpoint shipped by every pk-auth adapter. Returns\n * a typed {@link RefreshResult} rather than throwing on 401 — the bearer's expected response to\n * an Unknown / Expired / Replayed / Revoked outcome is to redirect to login, not to handle an\n * exception.\n *\n * @since 1.1.0\n */\nexport class PkAuthRefreshClient {\n private readonly options: ClientOptions;\n private readonly path: string;\n\n constructor(options: ClientOptions, path: string = \"/auth/refresh\") {\n this.options = options;\n this.path = path;\n }\n\n async refresh(refreshToken: string): Promise<RefreshResult> {\n try {\n const response = await request<RawRefreshResponse>(\n this.options,\n \"POST\",\n this.path,\n { refreshToken },\n false,\n );\n return {\n kind: \"success\",\n accessToken: response.accessToken,\n refreshToken: response.refreshToken,\n expiresAt: response.expiresAt,\n };\n } catch (e: unknown) {\n if (e instanceof PkAuthHttpError && e.status === 401) {\n const data = e.data as RawErrorResponse | undefined;\n const detail = data?.detail;\n if (\n detail === \"expired\" ||\n detail === \"unknown\" ||\n detail === \"replayed\" ||\n detail === \"revoked\"\n ) {\n return { kind: \"failure\", reason: detail, revokeReason: data?.reason };\n }\n // Server returned a 401 we don't recognise — surface it as the most conservative failure.\n return { kind: \"failure\", reason: \"unknown\" };\n }\n throw e;\n }\n }\n}\n","// SPDX-License-Identifier: MIT\n\nexport * as base64url from \"./base64url\";\nexport { PkAuthHttpError } from \"./http\";\nexport type { CeremonyResult } from \"./results\";\nexport { isCeremonySuccess, isCeremonyFailure } from \"./results\";\nexport {\n PkAuthCeremonyClient,\n decodeCreationOptions,\n decodeRequestOptions,\n encodeAuthenticationResponse,\n encodeRegistrationResponse,\n} from \"./ceremonies\";\nexport type {\n CeremonyOptions,\n FinishRegistrationParams,\n StartAuthenticationParams,\n StartRegistrationParams,\n} from \"./ceremonies\";\nexport { PkAuthAdminClient } from \"./admin\";\nexport { PkAuthRefreshClient, isRefreshSuccess, isRefreshFailure } from \"./refresh\";\nexport type {\n RefreshResult,\n RefreshSuccess,\n RefreshFailure,\n RefreshFailureReason,\n} from \"./refresh\";\nexport type * from \"./types\";\n\nimport { PkAuthAdminClient } from \"./admin\";\nimport { PkAuthCeremonyClient } from \"./ceremonies\";\nimport type { CeremonyOptions } from \"./ceremonies\";\nimport { PkAuthRefreshClient, type RefreshResult } from \"./refresh\";\nimport type { ClientOptions } from \"./types\";\n\n/** Convenience facade: a single object exposing ceremony, admin, and refresh clients. */\nexport class PkAuthClient {\n readonly ceremonies: PkAuthCeremonyClient;\n readonly admin: PkAuthAdminClient;\n readonly refreshClient: PkAuthRefreshClient;\n\n constructor(options: ClientOptions, ceremonyOptions: CeremonyOptions = {}) {\n this.ceremonies = new PkAuthCeremonyClient(options, ceremonyOptions);\n this.admin = new PkAuthAdminClient(options);\n this.refreshClient = new PkAuthRefreshClient(options);\n }\n\n /**\n * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed\n * {@link RefreshResult} sum — does not throw on 401.\n *\n * @since 1.1.0\n */\n refresh(refreshToken: string): Promise<RefreshResult> {\n return this.refreshClient.refresh(refreshToken);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/base64url.ts","../src/http.ts","../src/results.ts","../src/ceremonies.ts","../src/admin.ts","../src/refresh.ts","../src/index.ts"],"names":["request","PATHS"],"mappings":";;;;;;;;;AAAA,IAAA,iBAAA,GAAA;AAAA,QAAA,CAAA,iBAAA,EAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,MAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAWO,SAAS,OAAO,KAAA,EAA8D;AACnF,EAAA,MAAM,KAAA,GAAQ,aAAa,KAAK,CAAA;AAChC,EAAA,IAAI,CAAA,GAAI,EAAA;AACR,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,QAAQ,CAAA,EAAA,EAAK;AACrC,IAAA,CAAA,IAAK,MAAA,CAAO,YAAA,CAAa,KAAA,CAAM,CAAC,CAAE,CAAA;AAAA,EACpC;AAKA,EAAA,OAAO,IAAA,CAAK,CAAC,CAAA,CAAE,UAAA,CAAW,GAAA,EAAK,GAAG,CAAA,CAAE,UAAA,CAAW,GAAA,EAAK,GAAG,CAAA,CAAE,UAAA,CAAW,KAAK,EAAE,CAAA;AAC7E;AAEO,SAAS,OAAO,KAAA,EAA2C;AAChE,EAAA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;AACF","file":"index.cjs","sourcesContent":["// SPDX-License-Identifier: MIT\n\n/**\n * Base64url (RFC 4648 §5) without padding, matching pk-auth's wire format.\n * The server's Jackson module emits unpadded base64url; browsers can mix\n * Uint8Array, ArrayBuffer, or already-base64url strings, so `encode` handles\n * all three.\n */\n\nexport type Base64Url = string;\n\nexport function encode(input: ArrayBuffer | Uint8Array | ArrayBufferView): Base64Url {\n const bytes = toUint8Array(input);\n let s = \"\";\n for (let i = 0; i < bytes.length; i++) {\n s += String.fromCharCode(bytes[i]!);\n }\n // base64url per RFC 4648 §5: map +/ to -_ and strip padding. Using replaceAll with\n // string literals (no regexes) keeps this linear; it avoids the ReDoS shape\n // SonarQube flags on `/=+$/`. `=` only ever appears as trailing base64 padding, so\n // removing all of it is equivalent to stripping the trailing run.\n return btoa(s).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\n\nexport function decode(input: Base64Url): Uint8Array<ArrayBuffer> {\n const pad = \"=\".repeat((4 - (input.length % 4)) % 4);\n const normalized = input.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + pad;\n const binary = atob(normalized);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\nexport function decodeToArrayBuffer(input: Base64Url): ArrayBuffer {\n const bytes = decode(input);\n return bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n ) as ArrayBuffer;\n}\n\nfunction toUint8Array(input: ArrayBuffer | Uint8Array | ArrayBufferView): Uint8Array {\n if (input instanceof Uint8Array) return input;\n // A toString-based check handles cross-realm ArrayBuffers (e.g. from TextEncoder in jsdom).\n // jsdom's TextEncoder creates an ArrayBuffer that is different from NodeJs ArrayBuffer so \"instanceof\"\n // does not work. The string tag for the type does work.\n if (input instanceof ArrayBuffer || Object.prototype.toString.call(input) === \"[object ArrayBuffer]\") {\n return new Uint8Array(input as ArrayBuffer);\n }\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n}\n","// SPDX-License-Identifier: MIT\n\nimport type { ClientOptions } from \"./types\";\n\nexport class PkAuthHttpError extends Error {\n readonly status: number;\n readonly body: string;\n readonly data: Record<string, unknown> | undefined;\n\n constructor(status: number, body: string) {\n super(`HTTP ${status}: ${body}`);\n this.name = \"PkAuthHttpError\";\n this.status = status;\n this.body = body;\n try {\n const parsed = JSON.parse(body);\n this.data = parsed !== null && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : undefined;\n } catch {\n this.data = undefined;\n }\n }\n\n /** The `error` field from the parsed response body, if present. */\n get error(): string | undefined {\n return typeof this.data?.[\"error\"] === \"string\" ? (this.data[\"error\"] as string) : undefined;\n }\n\n /** The `detail` field from the parsed response body, if present. */\n get detail(): string | undefined {\n return typeof this.data?.[\"detail\"] === \"string\" ? (this.data[\"detail\"] as string) : undefined;\n }\n\n /** The `outcome` field from the parsed response body, if present. */\n get outcome(): string | undefined {\n return typeof this.data?.[\"outcome\"] === \"string\" ? (this.data[\"outcome\"] as string) : undefined;\n }\n}\n\n/** Internal request wrapper. `authenticated: true` adds the bearer header from `getToken`. */\nexport async function request<T>(\n options: ClientOptions,\n method: string,\n path: string,\n body: unknown,\n authenticated: boolean,\n): Promise<T> {\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const base = options.apiBase.endsWith(\"/\")\n ? options.apiBase.slice(0, -1)\n : options.apiBase;\n const url = `${base}${path}`;\n\n const headers: Record<string, string> = { accept: \"application/json\" };\n let payload: BodyInit | undefined;\n if (body !== undefined) {\n headers[\"content-type\"] = \"application/json\";\n payload = JSON.stringify(body);\n }\n if (authenticated) {\n const token = options.getToken?.();\n if (!token) {\n throw new Error(\"pk-auth: authenticated request requires getToken() to return a bearer token\");\n }\n headers[\"authorization\"] = `Bearer ${token}`;\n }\n\n const init: RequestInit = { method, headers };\n if (payload !== undefined) init.body = payload;\n const response = await fetchImpl(url, init);\n\n const text = await response.text();\n if (!response.ok) {\n throw new PkAuthHttpError(response.status, text);\n }\n if (!text.length) {\n return undefined as unknown as T;\n }\n return JSON.parse(text) as T;\n}\n","// SPDX-License-Identifier: MIT\n\n/**\n * Discriminated union mirroring the Java sealed result hierarchies\n * (AuthenticationResult / RegistrationResult) as returned by the pk-auth HTTP adapters.\n *\n * Authentication outcomes: success | challenge_invalid | origin_mismatch |\n * signature_invalid | unknown_credential | failed\n *\n * Registration outcomes: success | challenge_invalid | origin_mismatch |\n * attestation_rejected | duplicate_credential | invalid_payload | failed\n */\nexport type CeremonyResult =\n | { outcome: 'success'; token: string; credentialId?: string }\n | { outcome: 'challenge_invalid'; detail?: string }\n | { outcome: 'origin_mismatch'; detail?: string }\n | { outcome: 'signature_invalid'; detail?: string }\n | { outcome: 'unknown_credential'; detail?: string }\n | { outcome: 'attestation_rejected'; detail?: string }\n | { outcome: 'duplicate_credential'; detail?: string }\n | { outcome: 'invalid_payload'; detail?: string }\n | { outcome: 'failed'; detail?: string };\n\n/** Type guard: narrows a CeremonyResult to the success variant. */\nexport function isCeremonySuccess(\n result: CeremonyResult,\n): result is { outcome: 'success'; token: string; credentialId?: string } {\n return result.outcome === 'success';\n}\n\n/** Type guard: narrows a CeremonyResult to any failure variant. */\nexport function isCeremonyFailure(\n result: CeremonyResult,\n): result is Exclude<CeremonyResult, { outcome: 'success' }> {\n return result.outcome !== 'success';\n}\n","// SPDX-License-Identifier: MIT\n\nimport * as b64u from \"./base64url\";\nimport { request } from \"./http\";\nimport type {\n ClientOptions,\n FinishAuthenticationRequest,\n FinishAuthenticationResponse,\n FinishRegistrationRequest,\n FinishRegistrationResponse,\n PublicKeyCredentialCreationOptionsJson,\n PublicKeyCredentialRequestOptionsJson,\n RegistrationResponseJson,\n AuthenticationResponseJson,\n StartAuthenticationRequest,\n StartAuthenticationResponse,\n StartRegistrationRequest,\n StartRegistrationResponse,\n} from \"./types\";\n\nconst PATHS = {\n startReg: \"/auth/passkeys/registration/start\",\n finishReg: \"/auth/passkeys/registration/finish\",\n startAuth: \"/auth/passkeys/authentication/start\",\n finishAuth: \"/auth/passkeys/authentication/finish\",\n} as const;\n\n// All three adapters (Spring, Dropwizard, Micronaut) mount ceremony endpoints at\n// /auth/passkeys/<phase>/<step>. The `paths` override is an escape hatch for hosts that\n// remap the routes; no pk-auth-provided adapter needs it.\n\nexport interface CeremonyOptions {\n /** Path overrides, an escape hatch for hosts that remap pk-auth's default routes. */\n paths?: Partial<typeof PATHS>;\n /** Replacement for `navigator.credentials`, for tests and non-browser callers. */\n credentials?: CredentialsContainer;\n}\n\nexport interface StartRegistrationParams {\n username: string;\n displayName?: string;\n label?: string;\n}\n\nexport interface FinishRegistrationParams extends StartRegistrationResponse {\n username: string;\n label?: string;\n}\n\nexport interface StartAuthenticationParams {\n username?: string;\n /** When true, hands the call to `navigator.credentials.get` with `mediation: \"conditional\"`. */\n conditional?: boolean;\n}\n\nexport class PkAuthCeremonyClient {\n private readonly client: ClientOptions;\n private readonly paths: typeof PATHS;\n private readonly credentials?: CredentialsContainer;\n\n constructor(client: ClientOptions, options: CeremonyOptions = {}) {\n this.client = client;\n this.paths = { ...PATHS, ...options.paths };\n this.credentials = options.credentials;\n }\n\n /**\n * Runs the full registration ceremony: server-start → `navigator.credentials.create` →\n * server-finish. Returns the finish payload (registered credential metadata).\n */\n async register(params: StartRegistrationParams): Promise<FinishRegistrationResponse> {\n const start = await this.startRegistration({\n username: params.username,\n displayName: params.displayName ?? params.username,\n label: params.label ?? null,\n challenge: null,\n });\n const created = await this.createCredential(start.publicKey);\n return this.finishRegistration({\n challengeId: start.challengeId,\n username: params.username,\n label: params.label ?? null,\n response: encodeRegistrationResponse(created),\n });\n }\n\n /**\n * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →\n * server-finish. Returns the JWT; the caller stores it.\n */\n async authenticate(params: StartAuthenticationParams = {}): Promise<FinishAuthenticationResponse> {\n const start = await this.startAuthentication({\n username: params.username ?? null,\n challenge: null,\n });\n const got = await this.getCredential(start.publicKey, params.conditional ?? false);\n return this.finishAuthentication({\n challengeId: start.challengeId,\n response: encodeAuthenticationResponse(got),\n });\n }\n\n startRegistration(body: StartRegistrationRequest): Promise<StartRegistrationResponse> {\n return request(this.client, \"POST\", this.paths.startReg, body, false);\n }\n\n finishRegistration(body: FinishRegistrationRequest): Promise<FinishRegistrationResponse> {\n return request(this.client, \"POST\", this.paths.finishReg, body, false);\n }\n\n startAuthentication(body: StartAuthenticationRequest): Promise<StartAuthenticationResponse> {\n return request(this.client, \"POST\", this.paths.startAuth, body, false);\n }\n\n finishAuthentication(body: FinishAuthenticationRequest): Promise<FinishAuthenticationResponse> {\n return request(this.client, \"POST\", this.paths.finishAuth, body, false);\n }\n\n private get credentialsImpl(): CredentialsContainer {\n if (this.credentials) return this.credentials;\n if (typeof navigator === \"undefined\" || !navigator.credentials) {\n throw new Error(\"pk-auth: navigator.credentials is not available in this environment\");\n }\n return navigator.credentials;\n }\n\n private async createCredential(\n options: PublicKeyCredentialCreationOptionsJson,\n ): Promise<PublicKeyCredential> {\n const publicKey = decodeCreationOptions(options);\n const credential = (await this.credentialsImpl.create({ publicKey })) as PublicKeyCredential | null;\n if (!credential) {\n throw new Error(\"pk-auth: credential creation was cancelled\");\n }\n return credential;\n }\n\n private async getCredential(\n options: PublicKeyCredentialRequestOptionsJson,\n conditional: boolean,\n ): Promise<PublicKeyCredential> {\n const publicKey = decodeRequestOptions(options);\n const request: CredentialRequestOptions = { publicKey };\n if (conditional) {\n (request as CredentialRequestOptions & { mediation?: string }).mediation = \"conditional\";\n }\n const credential = (await this.credentialsImpl.get(request)) as PublicKeyCredential | null;\n if (!credential) {\n throw new Error(\"pk-auth: authentication was cancelled\");\n }\n return credential;\n }\n}\n\nexport function decodeCreationOptions(\n options: PublicKeyCredentialCreationOptionsJson,\n): PublicKeyCredentialCreationOptions {\n return {\n rp: options.rp,\n user: {\n id: b64u.decodeToArrayBuffer(options.user.id),\n name: options.user.name,\n displayName: options.user.displayName,\n },\n challenge: b64u.decodeToArrayBuffer(options.challenge),\n pubKeyCredParams: options.pubKeyCredParams,\n timeout: options.timeout,\n attestation: options.attestation,\n authenticatorSelection: options.authenticatorSelection,\n excludeCredentials: (options.excludeCredentials ?? []).map((c) => ({\n id: b64u.decodeToArrayBuffer(c.id),\n type: c.type,\n transports: c.transports as AuthenticatorTransport[] | undefined,\n })),\n };\n}\n\nexport function decodeRequestOptions(\n options: PublicKeyCredentialRequestOptionsJson,\n): PublicKeyCredentialRequestOptions {\n return {\n challenge: b64u.decodeToArrayBuffer(options.challenge),\n timeout: options.timeout,\n rpId: options.rpId,\n userVerification: options.userVerification,\n allowCredentials: (options.allowCredentials ?? []).map((c) => ({\n id: b64u.decodeToArrayBuffer(c.id),\n type: c.type,\n transports: c.transports as AuthenticatorTransport[] | undefined,\n })),\n };\n}\n\nexport function encodeRegistrationResponse(credential: PublicKeyCredential): RegistrationResponseJson {\n const response = credential.response as AuthenticatorAttestationResponse;\n const transports =\n typeof (response as AuthenticatorAttestationResponse & {\n getTransports?: () => string[];\n }).getTransports === \"function\"\n ? (response as AuthenticatorAttestationResponse & {\n getTransports: () => string[];\n }).getTransports()\n : [];\n return {\n id: b64u.encode(credential.rawId),\n rawId: b64u.encode(credential.rawId),\n type: \"public-key\",\n response: {\n clientDataJSON: b64u.encode(response.clientDataJSON),\n attestationObject: b64u.encode(response.attestationObject),\n transports,\n },\n };\n}\n\nexport function encodeAuthenticationResponse(\n credential: PublicKeyCredential,\n): AuthenticationResponseJson {\n const response = credential.response as AuthenticatorAssertionResponse;\n return {\n id: b64u.encode(credential.rawId),\n rawId: b64u.encode(credential.rawId),\n type: \"public-key\",\n response: {\n clientDataJSON: b64u.encode(response.clientDataJSON),\n authenticatorData: b64u.encode(response.authenticatorData),\n signature: b64u.encode(response.signature),\n userHandle: response.userHandle ? b64u.encode(response.userHandle) : null,\n },\n };\n}\n","// SPDX-License-Identifier: MIT\n\nimport { request } from \"./http\";\nimport type {\n AccountSummary,\n BackupCodeBatch,\n BackupCodeCount,\n ClientOptions,\n CredentialSummary,\n EmailDispatchResult,\n EmailVerificationResult,\n PhoneDispatchResult,\n PhoneVerificationResult,\n} from \"./types\";\n\nconst PATHS = {\n account: \"/auth/admin/account\",\n credentials: \"/auth/admin/credentials\",\n credentialById: (id: string) => `/auth/admin/credentials/${encodeURIComponent(id)}`,\n backupRegen: \"/auth/admin/backup-codes/regenerate\",\n backupCount: \"/auth/admin/backup-codes/count\",\n emailStart: \"/auth/admin/email/start-verification\",\n emailComplete: \"/auth/admin/email/complete-verification\",\n phoneStart: \"/auth/admin/phone/start-verification\",\n phoneComplete: \"/auth/admin/phone/complete-verification\",\n} as const;\n\nexport class PkAuthAdminClient {\n private readonly client: ClientOptions;\n\n constructor(client: ClientOptions) {\n if (!client.getToken) {\n throw new Error(\"pk-auth: admin client requires `getToken` in ClientOptions\");\n }\n this.client = client;\n }\n\n getAccount(): Promise<AccountSummary> {\n return request(this.client, \"GET\", PATHS.account, undefined, true);\n }\n\n listCredentials(): Promise<CredentialSummary[]> {\n return request(this.client, \"GET\", PATHS.credentials, undefined, true);\n }\n\n renameCredential(credentialId: string, label: string): Promise<CredentialSummary> {\n return request(this.client, \"PATCH\", PATHS.credentialById(credentialId), { label }, true);\n }\n\n removeCredential(credentialId: string): Promise<void> {\n return request(this.client, \"DELETE\", PATHS.credentialById(credentialId), undefined, true);\n }\n\n regenerateBackupCodes(): Promise<BackupCodeBatch> {\n return request(this.client, \"POST\", PATHS.backupRegen, \"\", true);\n }\n\n remainingBackupCodes(): Promise<BackupCodeCount> {\n return request(this.client, \"GET\", PATHS.backupCount, undefined, true);\n }\n\n startEmailVerification(email: string): Promise<EmailDispatchResult> {\n return request(this.client, \"POST\", PATHS.emailStart, { email }, true);\n }\n\n completeEmailVerification(token: string): Promise<EmailVerificationResult> {\n return request(this.client, \"POST\", PATHS.emailComplete, { token }, true);\n }\n\n startPhoneVerification(phone: string): Promise<PhoneDispatchResult> {\n return request(this.client, \"POST\", PATHS.phoneStart, { phone }, true);\n }\n\n completePhoneVerification(phone: string, code: string): Promise<PhoneVerificationResult> {\n return request(this.client, \"POST\", PATHS.phoneComplete, { phone, code }, true);\n }\n}\n","// SPDX-License-Identifier: MIT\n\nimport { PkAuthHttpError, request } from \"./http\";\nimport type { ClientOptions } from \"./types\";\n\n/** Typed success: a fresh refresh and access token pair. */\nexport interface RefreshSuccess {\n readonly kind: \"success\";\n readonly accessToken: string;\n readonly refreshToken: string;\n readonly expiresAt: string;\n}\n\n/** Typed failure mirroring the {@code detail} field on the server's 401 body. */\nexport type RefreshFailureReason = \"expired\" | \"unknown\" | \"replayed\" | \"revoked\";\n\nexport interface RefreshFailure {\n readonly kind: \"failure\";\n readonly reason: RefreshFailureReason;\n /** Categorical revoke reason when `reason === \"revoked\"`. */\n readonly revokeReason?: string;\n}\n\n/** Sealed sum of refresh outcomes. */\nexport type RefreshResult = RefreshSuccess | RefreshFailure;\n\n/** Type guard for {@link RefreshSuccess}. */\nexport function isRefreshSuccess(r: RefreshResult): r is RefreshSuccess {\n return r.kind === \"success\";\n}\n\n/** Type guard for {@link RefreshFailure}. */\nexport function isRefreshFailure(r: RefreshResult): r is RefreshFailure {\n return r.kind === \"failure\";\n}\n\ninterface RawRefreshResponse {\n refreshToken: string;\n accessToken: string;\n expiresAt: string;\n}\n\ninterface RawErrorResponse {\n detail?: string;\n reason?: string;\n}\n\n/**\n * Client for the {@code POST /auth/refresh} endpoint shipped by every pk-auth adapter. Returns\n * a typed {@link RefreshResult} rather than throwing on 401. The bearer's expected response to\n * an unknown, expired, replayed, or revoked outcome is to redirect to login, not to handle an\n * exception.\n *\n * @since 1.1.0\n */\nexport class PkAuthRefreshClient {\n private readonly options: ClientOptions;\n private readonly path: string;\n\n constructor(options: ClientOptions, path: string = \"/auth/refresh\") {\n this.options = options;\n this.path = path;\n }\n\n async refresh(refreshToken: string): Promise<RefreshResult> {\n try {\n const response = await request<RawRefreshResponse>(\n this.options,\n \"POST\",\n this.path,\n { refreshToken },\n false,\n );\n return {\n kind: \"success\",\n accessToken: response.accessToken,\n refreshToken: response.refreshToken,\n expiresAt: response.expiresAt,\n };\n } catch (e: unknown) {\n if (e instanceof PkAuthHttpError && e.status === 401) {\n const data = e.data as RawErrorResponse | undefined;\n const detail = data?.detail;\n if (\n detail === \"expired\" ||\n detail === \"unknown\" ||\n detail === \"replayed\" ||\n detail === \"revoked\"\n ) {\n return { kind: \"failure\", reason: detail, revokeReason: data?.reason };\n }\n // A 401 the client does not recognise surfaces as the most conservative failure.\n return { kind: \"failure\", reason: \"unknown\" };\n }\n throw e;\n }\n }\n}\n","// SPDX-License-Identifier: MIT\n\nexport * as base64url from \"./base64url\";\nexport { PkAuthHttpError } from \"./http\";\nexport type { CeremonyResult } from \"./results\";\nexport { isCeremonySuccess, isCeremonyFailure } from \"./results\";\nexport {\n PkAuthCeremonyClient,\n decodeCreationOptions,\n decodeRequestOptions,\n encodeAuthenticationResponse,\n encodeRegistrationResponse,\n} from \"./ceremonies\";\nexport type {\n CeremonyOptions,\n FinishRegistrationParams,\n StartAuthenticationParams,\n StartRegistrationParams,\n} from \"./ceremonies\";\nexport { PkAuthAdminClient } from \"./admin\";\nexport { PkAuthRefreshClient, isRefreshSuccess, isRefreshFailure } from \"./refresh\";\nexport type {\n RefreshResult,\n RefreshSuccess,\n RefreshFailure,\n RefreshFailureReason,\n} from \"./refresh\";\nexport type * from \"./types\";\n\nimport { PkAuthAdminClient } from \"./admin\";\nimport { PkAuthCeremonyClient } from \"./ceremonies\";\nimport type { CeremonyOptions } from \"./ceremonies\";\nimport { PkAuthRefreshClient, type RefreshResult } from \"./refresh\";\nimport type { ClientOptions } from \"./types\";\n\n/** Convenience facade: a single object exposing ceremony, admin, and refresh clients. */\nexport class PkAuthClient {\n readonly ceremonies: PkAuthCeremonyClient;\n readonly admin: PkAuthAdminClient;\n readonly refreshClient: PkAuthRefreshClient;\n\n constructor(options: ClientOptions, ceremonyOptions: CeremonyOptions = {}) {\n this.ceremonies = new PkAuthCeremonyClient(options, ceremonyOptions);\n this.admin = new PkAuthAdminClient(options);\n this.refreshClient = new PkAuthRefreshClient(options);\n }\n\n /**\n * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed\n * {@link RefreshResult} sum and does not throw on 401.\n *\n * @since 1.1.0\n */\n refresh(refreshToken: string): Promise<RefreshResult> {\n return this.refreshClient.refresh(refreshToken);\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Base64url (RFC 4648 §5) without padding — matches pk-auth's wire format.
2
+ * Base64url (RFC 4648 §5) without padding, matching pk-auth's wire format.
3
3
  * The server's Jackson module emits unpadded base64url; browsers can mix
4
- * Uint8Array, ArrayBuffer, or already-base64url strings, so encode handles
4
+ * Uint8Array, ArrayBuffer, or already-base64url strings, so `encode` handles
5
5
  * all three.
6
6
  */
7
7
  type Base64Url = string;
8
8
  declare function encode(input: ArrayBuffer | Uint8Array | ArrayBufferView): Base64Url;
9
- declare function decode(input: Base64Url): Uint8Array;
9
+ declare function decode(input: Base64Url): Uint8Array<ArrayBuffer>;
10
10
  declare function decodeToArrayBuffer(input: Base64Url): ArrayBuffer;
11
11
 
12
12
  type base64url_Base64Url = Base64Url;
@@ -17,7 +17,7 @@ declare namespace base64url {
17
17
  export { type base64url_Base64Url as Base64Url, base64url_decode as decode, base64url_decodeToArrayBuffer as decodeToArrayBuffer, base64url_encode as encode };
18
18
  }
19
19
 
20
- /** Caller-supplied bearer-token accessor. Returns null when there's no session yet. */
20
+ /** Caller-supplied bearer-token accessor. Returns null when no session exists. */
21
21
  type TokenAccessor = () => string | null;
22
22
  /** Construction options shared by the ceremony and admin clients. */
23
23
  interface ClientOptions {
@@ -28,7 +28,7 @@ interface ClientOptions {
28
28
  * ceremony operations are anonymous and will not call it.
29
29
  */
30
30
  getToken?: TokenAccessor;
31
- /** Override the global fetch (handy for tests). */
31
+ /** Replacement for the global `fetch`, used in tests. */
32
32
  fetch?: typeof fetch;
33
33
  }
34
34
  interface RpEntity {
@@ -119,7 +119,7 @@ interface FinishAuthenticationRequest {
119
119
  challengeId: string;
120
120
  response: AuthenticationResponseJson;
121
121
  }
122
- /** Server returns the wrapped RegistrationResult; relevant fields are surfaced here. */
122
+ /** The server returns the wrapped RegistrationResult; the relevant fields are surfaced here. */
123
123
  interface FinishRegistrationResponse {
124
124
  credential: {
125
125
  credentialId: Base64Url;
@@ -164,12 +164,12 @@ interface BackupCodeCount {
164
164
  interface EmailDispatchResult {
165
165
  /** Implementation-defined token / link reference returned by the dispatcher. */
166
166
  dispatchId?: string;
167
- /** Magic-link token (testkit / dev only — real dispatchers send it out of band). */
167
+ /** Magic-link token (testkit and development only; real dispatchers send it out of band). */
168
168
  token?: string;
169
169
  }
170
170
  interface PhoneDispatchResult {
171
171
  dispatchId?: string;
172
- /** OTP code (testkit / dev only — real dispatchers send it via SMS). */
172
+ /** OTP code (testkit and development only; real dispatchers send it via SMS). */
173
173
  code?: string;
174
174
  }
175
175
  interface EmailVerificationResult {
@@ -251,9 +251,9 @@ declare const PATHS: {
251
251
  readonly finishAuth: "/auth/passkeys/authentication/finish";
252
252
  };
253
253
  interface CeremonyOptions {
254
- /** Path overrides — kept as an escape hatch for hosts that remap pk-auth's default routes. */
254
+ /** Path overrides, an escape hatch for hosts that remap pk-auth's default routes. */
255
255
  paths?: Partial<typeof PATHS>;
256
- /** Optional override for navigator.credentials (tests / non-browser callers). */
256
+ /** Replacement for `navigator.credentials`, for tests and non-browser callers. */
257
257
  credentials?: CredentialsContainer;
258
258
  }
259
259
  interface StartRegistrationParams {
@@ -282,7 +282,7 @@ declare class PkAuthCeremonyClient {
282
282
  register(params: StartRegistrationParams): Promise<FinishRegistrationResponse>;
283
283
  /**
284
284
  * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →
285
- * server-finish. Returns the JWT (consumer is responsible for storage).
285
+ * server-finish. Returns the JWT; the caller stores it.
286
286
  */
287
287
  authenticate(params?: StartAuthenticationParams): Promise<FinishAuthenticationResponse>;
288
288
  startRegistration(body: StartRegistrationRequest): Promise<StartRegistrationResponse>;
@@ -313,7 +313,7 @@ declare class PkAuthAdminClient {
313
313
  completePhoneVerification(phone: string, code: string): Promise<PhoneVerificationResult>;
314
314
  }
315
315
 
316
- /** Typed success: a fresh refresh + access token pair to swap in. */
316
+ /** Typed success: a fresh refresh and access token pair. */
317
317
  interface RefreshSuccess {
318
318
  readonly kind: "success";
319
319
  readonly accessToken: string;
@@ -336,8 +336,8 @@ declare function isRefreshSuccess(r: RefreshResult): r is RefreshSuccess;
336
336
  declare function isRefreshFailure(r: RefreshResult): r is RefreshFailure;
337
337
  /**
338
338
  * Client for the {@code POST /auth/refresh} endpoint shipped by every pk-auth adapter. Returns
339
- * a typed {@link RefreshResult} rather than throwing on 401 — the bearer's expected response to
340
- * an Unknown / Expired / Replayed / Revoked outcome is to redirect to login, not to handle an
339
+ * a typed {@link RefreshResult} rather than throwing on 401. The bearer's expected response to
340
+ * an unknown, expired, replayed, or revoked outcome is to redirect to login, not to handle an
341
341
  * exception.
342
342
  *
343
343
  * @since 1.1.0
@@ -357,7 +357,7 @@ declare class PkAuthClient {
357
357
  constructor(options: ClientOptions, ceremonyOptions?: CeremonyOptions);
358
358
  /**
359
359
  * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed
360
- * {@link RefreshResult} sum — does not throw on 401.
360
+ * {@link RefreshResult} sum and does not throw on 401.
361
361
  *
362
362
  * @since 1.1.0
363
363
  */
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Base64url (RFC 4648 §5) without padding — matches pk-auth's wire format.
2
+ * Base64url (RFC 4648 §5) without padding, matching pk-auth's wire format.
3
3
  * The server's Jackson module emits unpadded base64url; browsers can mix
4
- * Uint8Array, ArrayBuffer, or already-base64url strings, so encode handles
4
+ * Uint8Array, ArrayBuffer, or already-base64url strings, so `encode` handles
5
5
  * all three.
6
6
  */
7
7
  type Base64Url = string;
8
8
  declare function encode(input: ArrayBuffer | Uint8Array | ArrayBufferView): Base64Url;
9
- declare function decode(input: Base64Url): Uint8Array;
9
+ declare function decode(input: Base64Url): Uint8Array<ArrayBuffer>;
10
10
  declare function decodeToArrayBuffer(input: Base64Url): ArrayBuffer;
11
11
 
12
12
  type base64url_Base64Url = Base64Url;
@@ -17,7 +17,7 @@ declare namespace base64url {
17
17
  export { type base64url_Base64Url as Base64Url, base64url_decode as decode, base64url_decodeToArrayBuffer as decodeToArrayBuffer, base64url_encode as encode };
18
18
  }
19
19
 
20
- /** Caller-supplied bearer-token accessor. Returns null when there's no session yet. */
20
+ /** Caller-supplied bearer-token accessor. Returns null when no session exists. */
21
21
  type TokenAccessor = () => string | null;
22
22
  /** Construction options shared by the ceremony and admin clients. */
23
23
  interface ClientOptions {
@@ -28,7 +28,7 @@ interface ClientOptions {
28
28
  * ceremony operations are anonymous and will not call it.
29
29
  */
30
30
  getToken?: TokenAccessor;
31
- /** Override the global fetch (handy for tests). */
31
+ /** Replacement for the global `fetch`, used in tests. */
32
32
  fetch?: typeof fetch;
33
33
  }
34
34
  interface RpEntity {
@@ -119,7 +119,7 @@ interface FinishAuthenticationRequest {
119
119
  challengeId: string;
120
120
  response: AuthenticationResponseJson;
121
121
  }
122
- /** Server returns the wrapped RegistrationResult; relevant fields are surfaced here. */
122
+ /** The server returns the wrapped RegistrationResult; the relevant fields are surfaced here. */
123
123
  interface FinishRegistrationResponse {
124
124
  credential: {
125
125
  credentialId: Base64Url;
@@ -164,12 +164,12 @@ interface BackupCodeCount {
164
164
  interface EmailDispatchResult {
165
165
  /** Implementation-defined token / link reference returned by the dispatcher. */
166
166
  dispatchId?: string;
167
- /** Magic-link token (testkit / dev only — real dispatchers send it out of band). */
167
+ /** Magic-link token (testkit and development only; real dispatchers send it out of band). */
168
168
  token?: string;
169
169
  }
170
170
  interface PhoneDispatchResult {
171
171
  dispatchId?: string;
172
- /** OTP code (testkit / dev only — real dispatchers send it via SMS). */
172
+ /** OTP code (testkit and development only; real dispatchers send it via SMS). */
173
173
  code?: string;
174
174
  }
175
175
  interface EmailVerificationResult {
@@ -251,9 +251,9 @@ declare const PATHS: {
251
251
  readonly finishAuth: "/auth/passkeys/authentication/finish";
252
252
  };
253
253
  interface CeremonyOptions {
254
- /** Path overrides — kept as an escape hatch for hosts that remap pk-auth's default routes. */
254
+ /** Path overrides, an escape hatch for hosts that remap pk-auth's default routes. */
255
255
  paths?: Partial<typeof PATHS>;
256
- /** Optional override for navigator.credentials (tests / non-browser callers). */
256
+ /** Replacement for `navigator.credentials`, for tests and non-browser callers. */
257
257
  credentials?: CredentialsContainer;
258
258
  }
259
259
  interface StartRegistrationParams {
@@ -282,7 +282,7 @@ declare class PkAuthCeremonyClient {
282
282
  register(params: StartRegistrationParams): Promise<FinishRegistrationResponse>;
283
283
  /**
284
284
  * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →
285
- * server-finish. Returns the JWT (consumer is responsible for storage).
285
+ * server-finish. Returns the JWT; the caller stores it.
286
286
  */
287
287
  authenticate(params?: StartAuthenticationParams): Promise<FinishAuthenticationResponse>;
288
288
  startRegistration(body: StartRegistrationRequest): Promise<StartRegistrationResponse>;
@@ -313,7 +313,7 @@ declare class PkAuthAdminClient {
313
313
  completePhoneVerification(phone: string, code: string): Promise<PhoneVerificationResult>;
314
314
  }
315
315
 
316
- /** Typed success: a fresh refresh + access token pair to swap in. */
316
+ /** Typed success: a fresh refresh and access token pair. */
317
317
  interface RefreshSuccess {
318
318
  readonly kind: "success";
319
319
  readonly accessToken: string;
@@ -336,8 +336,8 @@ declare function isRefreshSuccess(r: RefreshResult): r is RefreshSuccess;
336
336
  declare function isRefreshFailure(r: RefreshResult): r is RefreshFailure;
337
337
  /**
338
338
  * Client for the {@code POST /auth/refresh} endpoint shipped by every pk-auth adapter. Returns
339
- * a typed {@link RefreshResult} rather than throwing on 401 — the bearer's expected response to
340
- * an Unknown / Expired / Replayed / Revoked outcome is to redirect to login, not to handle an
339
+ * a typed {@link RefreshResult} rather than throwing on 401. The bearer's expected response to
340
+ * an unknown, expired, replayed, or revoked outcome is to redirect to login, not to handle an
341
341
  * exception.
342
342
  *
343
343
  * @since 1.1.0
@@ -357,7 +357,7 @@ declare class PkAuthClient {
357
357
  constructor(options: ClientOptions, ceremonyOptions?: CeremonyOptions);
358
358
  /**
359
359
  * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed
360
- * {@link RefreshResult} sum — does not throw on 401.
360
+ * {@link RefreshResult} sum and does not throw on 401.
361
361
  *
362
362
  * @since 1.1.0
363
363
  */
package/dist/index.js CHANGED
@@ -38,7 +38,9 @@ function decodeToArrayBuffer(input) {
38
38
  }
39
39
  function toUint8Array(input) {
40
40
  if (input instanceof Uint8Array) return input;
41
- if (input instanceof ArrayBuffer) return new Uint8Array(input);
41
+ if (input instanceof ArrayBuffer || Object.prototype.toString.call(input) === "[object ArrayBuffer]") {
42
+ return new Uint8Array(input);
43
+ }
42
44
  return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
43
45
  }
44
46
 
@@ -147,7 +149,7 @@ var PkAuthCeremonyClient = class {
147
149
  }
148
150
  /**
149
151
  * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →
150
- * server-finish. Returns the JWT (consumer is responsible for storage).
152
+ * server-finish. Returns the JWT; the caller stores it.
151
153
  */
152
154
  async authenticate(params = {}) {
153
155
  const start = await this.startAuthentication({
@@ -369,7 +371,7 @@ var PkAuthClient = class {
369
371
  }
370
372
  /**
371
373
  * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed
372
- * {@link RefreshResult} sum — does not throw on 401.
374
+ * {@link RefreshResult} sum and does not throw on 401.
373
375
  *
374
376
  * @since 1.1.0
375
377
  */
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base64url.ts","../src/http.ts","../src/results.ts","../src/ceremonies.ts","../src/admin.ts","../src/refresh.ts","../src/index.ts"],"names":["request","PATHS"],"mappings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A,EAAW,MAAA,EAAQ,SAAA,EAAU;AAAA,MAC9C;AACA,MAAA,MAAM,CAAA;AAAA,IACR;AAAA,EACF;AACF;;;AC7DO,IAAM,eAAN,MAAmB;AAAA,EACf,UAAA;AAAA,EACA,KAAA;AAAA,EACA,aAAA;AAAA,EAET,WAAA,CAAY,OAAA,EAAwB,eAAA,GAAmC,EAAC,EAAG;AACzE,IAAA,IAAA,CAAK,UAAA,GAAa,IAAI,oBAAA,CAAqB,OAAA,EAAS,eAAe,CAAA;AACnE,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,iBAAA,CAAkB,OAAO,CAAA;AAC1C,IAAA,IAAA,CAAK,aAAA,GAAgB,IAAI,mBAAA,CAAoB,OAAO,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAQ,YAAA,EAA8C;AACpD,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,OAAA,CAAQ,YAAY,CAAA;AAAA,EAChD;AACF","file":"index.js","sourcesContent":["// SPDX-License-Identifier: MIT\n\n/**\n * Base64url (RFC 4648 §5) without padding — matches pk-auth's wire format.\n * The server's Jackson module emits unpadded base64url; browsers can mix\n * Uint8Array, ArrayBuffer, or already-base64url strings, so encode handles\n * all three.\n */\n\nexport type Base64Url = string;\n\nexport function encode(input: ArrayBuffer | Uint8Array | ArrayBufferView): Base64Url {\n const bytes = toUint8Array(input);\n let s = \"\";\n for (let i = 0; i < bytes.length; i++) {\n s += String.fromCharCode(bytes[i]!);\n }\n // base64url per RFC 4648 §5: map +/ to -_ and strip padding. Using replaceAll with\n // string literals (no regexes) keeps this linear — it avoids the ReDoS shape\n // SonarQube flags on `/=+$/`. `=` only ever appears as trailing base64 padding, so\n // removing all of it is equivalent to stripping the trailing run.\n return btoa(s).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\n\nexport function decode(input: Base64Url): Uint8Array {\n const pad = \"=\".repeat((4 - (input.length % 4)) % 4);\n const normalized = input.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + pad;\n const binary = atob(normalized);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\nexport function decodeToArrayBuffer(input: Base64Url): ArrayBuffer {\n const bytes = decode(input);\n return bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n ) as ArrayBuffer;\n}\n\nfunction toUint8Array(input: ArrayBuffer | Uint8Array | ArrayBufferView): Uint8Array {\n if (input instanceof Uint8Array) return input;\n if (input instanceof ArrayBuffer) return new Uint8Array(input);\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n}\n","// SPDX-License-Identifier: MIT\n\nimport type { ClientOptions } from \"./types\";\n\nexport class PkAuthHttpError extends Error {\n readonly status: number;\n readonly body: string;\n readonly data: Record<string, unknown> | undefined;\n\n constructor(status: number, body: string) {\n super(`HTTP ${status}: ${body}`);\n this.name = \"PkAuthHttpError\";\n this.status = status;\n this.body = body;\n try {\n const parsed = JSON.parse(body);\n this.data = parsed !== null && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : undefined;\n } catch {\n this.data = undefined;\n }\n }\n\n /** The `error` field from the parsed response body, if present. */\n get error(): string | undefined {\n return typeof this.data?.[\"error\"] === \"string\" ? (this.data[\"error\"] as string) : undefined;\n }\n\n /** The `detail` field from the parsed response body, if present. */\n get detail(): string | undefined {\n return typeof this.data?.[\"detail\"] === \"string\" ? (this.data[\"detail\"] as string) : undefined;\n }\n\n /** The `outcome` field from the parsed response body, if present. */\n get outcome(): string | undefined {\n return typeof this.data?.[\"outcome\"] === \"string\" ? (this.data[\"outcome\"] as string) : undefined;\n }\n}\n\n/** Internal request wrapper. `authenticated: true` adds the bearer header from `getToken`. */\nexport async function request<T>(\n options: ClientOptions,\n method: string,\n path: string,\n body: unknown,\n authenticated: boolean,\n): Promise<T> {\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const base = options.apiBase.endsWith(\"/\")\n ? options.apiBase.slice(0, -1)\n : options.apiBase;\n const url = `${base}${path}`;\n\n const headers: Record<string, string> = { accept: \"application/json\" };\n let payload: BodyInit | undefined;\n if (body !== undefined) {\n headers[\"content-type\"] = \"application/json\";\n payload = JSON.stringify(body);\n }\n if (authenticated) {\n const token = options.getToken?.();\n if (!token) {\n throw new Error(\"pk-auth: authenticated request requires getToken() to return a bearer token\");\n }\n headers[\"authorization\"] = `Bearer ${token}`;\n }\n\n const init: RequestInit = { method, headers };\n if (payload !== undefined) init.body = payload;\n const response = await fetchImpl(url, init);\n\n const text = await response.text();\n if (!response.ok) {\n throw new PkAuthHttpError(response.status, text);\n }\n if (!text.length) {\n return undefined as unknown as T;\n }\n return JSON.parse(text) as T;\n}\n","// SPDX-License-Identifier: MIT\n\n/**\n * Discriminated union mirroring the Java sealed result hierarchies\n * (AuthenticationResult / RegistrationResult) as returned by the pk-auth HTTP adapters.\n *\n * Authentication outcomes: success | challenge_invalid | origin_mismatch |\n * signature_invalid | unknown_credential | failed\n *\n * Registration outcomes: success | challenge_invalid | origin_mismatch |\n * attestation_rejected | duplicate_credential | invalid_payload | failed\n */\nexport type CeremonyResult =\n | { outcome: 'success'; token: string; credentialId?: string }\n | { outcome: 'challenge_invalid'; detail?: string }\n | { outcome: 'origin_mismatch'; detail?: string }\n | { outcome: 'signature_invalid'; detail?: string }\n | { outcome: 'unknown_credential'; detail?: string }\n | { outcome: 'attestation_rejected'; detail?: string }\n | { outcome: 'duplicate_credential'; detail?: string }\n | { outcome: 'invalid_payload'; detail?: string }\n | { outcome: 'failed'; detail?: string };\n\n/** Type guard: narrows a CeremonyResult to the success variant. */\nexport function isCeremonySuccess(\n result: CeremonyResult,\n): result is { outcome: 'success'; token: string; credentialId?: string } {\n return result.outcome === 'success';\n}\n\n/** Type guard: narrows a CeremonyResult to any failure variant. */\nexport function isCeremonyFailure(\n result: CeremonyResult,\n): result is Exclude<CeremonyResult, { outcome: 'success' }> {\n return result.outcome !== 'success';\n}\n","// SPDX-License-Identifier: MIT\n\nimport * as b64u from \"./base64url\";\nimport { request } from \"./http\";\nimport type {\n ClientOptions,\n FinishAuthenticationRequest,\n FinishAuthenticationResponse,\n FinishRegistrationRequest,\n FinishRegistrationResponse,\n PublicKeyCredentialCreationOptionsJson,\n PublicKeyCredentialRequestOptionsJson,\n RegistrationResponseJson,\n AuthenticationResponseJson,\n StartAuthenticationRequest,\n StartAuthenticationResponse,\n StartRegistrationRequest,\n StartRegistrationResponse,\n} from \"./types\";\n\nconst PATHS = {\n startReg: \"/auth/passkeys/registration/start\",\n finishReg: \"/auth/passkeys/registration/finish\",\n startAuth: \"/auth/passkeys/authentication/start\",\n finishAuth: \"/auth/passkeys/authentication/finish\",\n} as const;\n\n// All three adapters (Spring, Dropwizard, Micronaut) now mount ceremony endpoints at\n// /auth/passkeys/<phase>/<step>. The `paths` override remains an escape hatch for hosts that\n// remap the routes but is no longer needed for any pk-auth-provided adapter.\n\nexport interface CeremonyOptions {\n /** Path overrides — kept as an escape hatch for hosts that remap pk-auth's default routes. */\n paths?: Partial<typeof PATHS>;\n /** Optional override for navigator.credentials (tests / non-browser callers). */\n credentials?: CredentialsContainer;\n}\n\nexport interface StartRegistrationParams {\n username: string;\n displayName?: string;\n label?: string;\n}\n\nexport interface FinishRegistrationParams extends StartRegistrationResponse {\n username: string;\n label?: string;\n}\n\nexport interface StartAuthenticationParams {\n username?: string;\n /** When true, hands the call to `navigator.credentials.get` with `mediation: \"conditional\"`. */\n conditional?: boolean;\n}\n\nexport class PkAuthCeremonyClient {\n private readonly client: ClientOptions;\n private readonly paths: typeof PATHS;\n private readonly credentials?: CredentialsContainer;\n\n constructor(client: ClientOptions, options: CeremonyOptions = {}) {\n this.client = client;\n this.paths = { ...PATHS, ...options.paths };\n this.credentials = options.credentials;\n }\n\n /**\n * Runs the full registration ceremony: server-start → `navigator.credentials.create` →\n * server-finish. Returns the finish payload (registered credential metadata).\n */\n async register(params: StartRegistrationParams): Promise<FinishRegistrationResponse> {\n const start = await this.startRegistration({\n username: params.username,\n displayName: params.displayName ?? params.username,\n label: params.label ?? null,\n challenge: null,\n });\n const created = await this.createCredential(start.publicKey);\n return this.finishRegistration({\n challengeId: start.challengeId,\n username: params.username,\n label: params.label ?? null,\n response: encodeRegistrationResponse(created),\n });\n }\n\n /**\n * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →\n * server-finish. Returns the JWT (consumer is responsible for storage).\n */\n async authenticate(params: StartAuthenticationParams = {}): Promise<FinishAuthenticationResponse> {\n const start = await this.startAuthentication({\n username: params.username ?? null,\n challenge: null,\n });\n const got = await this.getCredential(start.publicKey, params.conditional ?? false);\n return this.finishAuthentication({\n challengeId: start.challengeId,\n response: encodeAuthenticationResponse(got),\n });\n }\n\n startRegistration(body: StartRegistrationRequest): Promise<StartRegistrationResponse> {\n return request(this.client, \"POST\", this.paths.startReg, body, false);\n }\n\n finishRegistration(body: FinishRegistrationRequest): Promise<FinishRegistrationResponse> {\n return request(this.client, \"POST\", this.paths.finishReg, body, false);\n }\n\n startAuthentication(body: StartAuthenticationRequest): Promise<StartAuthenticationResponse> {\n return request(this.client, \"POST\", this.paths.startAuth, body, false);\n }\n\n finishAuthentication(body: FinishAuthenticationRequest): Promise<FinishAuthenticationResponse> {\n return request(this.client, \"POST\", this.paths.finishAuth, body, false);\n }\n\n private get credentialsImpl(): CredentialsContainer {\n if (this.credentials) return this.credentials;\n if (typeof navigator === \"undefined\" || !navigator.credentials) {\n throw new Error(\"pk-auth: navigator.credentials is not available in this environment\");\n }\n return navigator.credentials;\n }\n\n private async createCredential(\n options: PublicKeyCredentialCreationOptionsJson,\n ): Promise<PublicKeyCredential> {\n const publicKey = decodeCreationOptions(options);\n const credential = (await this.credentialsImpl.create({ publicKey })) as PublicKeyCredential | null;\n if (!credential) {\n throw new Error(\"pk-auth: credential creation was cancelled\");\n }\n return credential;\n }\n\n private async getCredential(\n options: PublicKeyCredentialRequestOptionsJson,\n conditional: boolean,\n ): Promise<PublicKeyCredential> {\n const publicKey = decodeRequestOptions(options);\n const request: CredentialRequestOptions = { publicKey };\n if (conditional) {\n (request as CredentialRequestOptions & { mediation?: string }).mediation = \"conditional\";\n }\n const credential = (await this.credentialsImpl.get(request)) as PublicKeyCredential | null;\n if (!credential) {\n throw new Error(\"pk-auth: authentication was cancelled\");\n }\n return credential;\n }\n}\n\nexport function decodeCreationOptions(\n options: PublicKeyCredentialCreationOptionsJson,\n): PublicKeyCredentialCreationOptions {\n return {\n rp: options.rp,\n user: {\n id: b64u.decodeToArrayBuffer(options.user.id),\n name: options.user.name,\n displayName: options.user.displayName,\n },\n challenge: b64u.decodeToArrayBuffer(options.challenge),\n pubKeyCredParams: options.pubKeyCredParams,\n timeout: options.timeout,\n attestation: options.attestation,\n authenticatorSelection: options.authenticatorSelection,\n excludeCredentials: (options.excludeCredentials ?? []).map((c) => ({\n id: b64u.decodeToArrayBuffer(c.id),\n type: c.type,\n transports: c.transports as AuthenticatorTransport[] | undefined,\n })),\n };\n}\n\nexport function decodeRequestOptions(\n options: PublicKeyCredentialRequestOptionsJson,\n): PublicKeyCredentialRequestOptions {\n return {\n challenge: b64u.decodeToArrayBuffer(options.challenge),\n timeout: options.timeout,\n rpId: options.rpId,\n userVerification: options.userVerification,\n allowCredentials: (options.allowCredentials ?? []).map((c) => ({\n id: b64u.decodeToArrayBuffer(c.id),\n type: c.type,\n transports: c.transports as AuthenticatorTransport[] | undefined,\n })),\n };\n}\n\nexport function encodeRegistrationResponse(credential: PublicKeyCredential): RegistrationResponseJson {\n const response = credential.response as AuthenticatorAttestationResponse;\n const transports =\n typeof (response as AuthenticatorAttestationResponse & {\n getTransports?: () => string[];\n }).getTransports === \"function\"\n ? (response as AuthenticatorAttestationResponse & {\n getTransports: () => string[];\n }).getTransports()\n : [];\n return {\n id: b64u.encode(credential.rawId),\n rawId: b64u.encode(credential.rawId),\n type: \"public-key\",\n response: {\n clientDataJSON: b64u.encode(response.clientDataJSON),\n attestationObject: b64u.encode(response.attestationObject),\n transports,\n },\n };\n}\n\nexport function encodeAuthenticationResponse(\n credential: PublicKeyCredential,\n): AuthenticationResponseJson {\n const response = credential.response as AuthenticatorAssertionResponse;\n return {\n id: b64u.encode(credential.rawId),\n rawId: b64u.encode(credential.rawId),\n type: \"public-key\",\n response: {\n clientDataJSON: b64u.encode(response.clientDataJSON),\n authenticatorData: b64u.encode(response.authenticatorData),\n signature: b64u.encode(response.signature),\n userHandle: response.userHandle ? b64u.encode(response.userHandle) : null,\n },\n };\n}\n","// SPDX-License-Identifier: MIT\n\nimport { request } from \"./http\";\nimport type {\n AccountSummary,\n BackupCodeBatch,\n BackupCodeCount,\n ClientOptions,\n CredentialSummary,\n EmailDispatchResult,\n EmailVerificationResult,\n PhoneDispatchResult,\n PhoneVerificationResult,\n} from \"./types\";\n\nconst PATHS = {\n account: \"/auth/admin/account\",\n credentials: \"/auth/admin/credentials\",\n credentialById: (id: string) => `/auth/admin/credentials/${encodeURIComponent(id)}`,\n backupRegen: \"/auth/admin/backup-codes/regenerate\",\n backupCount: \"/auth/admin/backup-codes/count\",\n emailStart: \"/auth/admin/email/start-verification\",\n emailComplete: \"/auth/admin/email/complete-verification\",\n phoneStart: \"/auth/admin/phone/start-verification\",\n phoneComplete: \"/auth/admin/phone/complete-verification\",\n} as const;\n\nexport class PkAuthAdminClient {\n private readonly client: ClientOptions;\n\n constructor(client: ClientOptions) {\n if (!client.getToken) {\n throw new Error(\"pk-auth: admin client requires `getToken` in ClientOptions\");\n }\n this.client = client;\n }\n\n getAccount(): Promise<AccountSummary> {\n return request(this.client, \"GET\", PATHS.account, undefined, true);\n }\n\n listCredentials(): Promise<CredentialSummary[]> {\n return request(this.client, \"GET\", PATHS.credentials, undefined, true);\n }\n\n renameCredential(credentialId: string, label: string): Promise<CredentialSummary> {\n return request(this.client, \"PATCH\", PATHS.credentialById(credentialId), { label }, true);\n }\n\n removeCredential(credentialId: string): Promise<void> {\n return request(this.client, \"DELETE\", PATHS.credentialById(credentialId), undefined, true);\n }\n\n regenerateBackupCodes(): Promise<BackupCodeBatch> {\n return request(this.client, \"POST\", PATHS.backupRegen, \"\", true);\n }\n\n remainingBackupCodes(): Promise<BackupCodeCount> {\n return request(this.client, \"GET\", PATHS.backupCount, undefined, true);\n }\n\n startEmailVerification(email: string): Promise<EmailDispatchResult> {\n return request(this.client, \"POST\", PATHS.emailStart, { email }, true);\n }\n\n completeEmailVerification(token: string): Promise<EmailVerificationResult> {\n return request(this.client, \"POST\", PATHS.emailComplete, { token }, true);\n }\n\n startPhoneVerification(phone: string): Promise<PhoneDispatchResult> {\n return request(this.client, \"POST\", PATHS.phoneStart, { phone }, true);\n }\n\n completePhoneVerification(phone: string, code: string): Promise<PhoneVerificationResult> {\n return request(this.client, \"POST\", PATHS.phoneComplete, { phone, code }, true);\n }\n}\n","// SPDX-License-Identifier: MIT\n\nimport { PkAuthHttpError, request } from \"./http\";\nimport type { ClientOptions } from \"./types\";\n\n/** Typed success: a fresh refresh + access token pair to swap in. */\nexport interface RefreshSuccess {\n readonly kind: \"success\";\n readonly accessToken: string;\n readonly refreshToken: string;\n readonly expiresAt: string;\n}\n\n/** Typed failure mirroring the {@code detail} field on the server's 401 body. */\nexport type RefreshFailureReason = \"expired\" | \"unknown\" | \"replayed\" | \"revoked\";\n\nexport interface RefreshFailure {\n readonly kind: \"failure\";\n readonly reason: RefreshFailureReason;\n /** Categorical revoke reason when `reason === \"revoked\"`. */\n readonly revokeReason?: string;\n}\n\n/** Sealed sum of refresh outcomes. */\nexport type RefreshResult = RefreshSuccess | RefreshFailure;\n\n/** Type guard for {@link RefreshSuccess}. */\nexport function isRefreshSuccess(r: RefreshResult): r is RefreshSuccess {\n return r.kind === \"success\";\n}\n\n/** Type guard for {@link RefreshFailure}. */\nexport function isRefreshFailure(r: RefreshResult): r is RefreshFailure {\n return r.kind === \"failure\";\n}\n\ninterface RawRefreshResponse {\n refreshToken: string;\n accessToken: string;\n expiresAt: string;\n}\n\ninterface RawErrorResponse {\n detail?: string;\n reason?: string;\n}\n\n/**\n * Client for the {@code POST /auth/refresh} endpoint shipped by every pk-auth adapter. Returns\n * a typed {@link RefreshResult} rather than throwing on 401 — the bearer's expected response to\n * an Unknown / Expired / Replayed / Revoked outcome is to redirect to login, not to handle an\n * exception.\n *\n * @since 1.1.0\n */\nexport class PkAuthRefreshClient {\n private readonly options: ClientOptions;\n private readonly path: string;\n\n constructor(options: ClientOptions, path: string = \"/auth/refresh\") {\n this.options = options;\n this.path = path;\n }\n\n async refresh(refreshToken: string): Promise<RefreshResult> {\n try {\n const response = await request<RawRefreshResponse>(\n this.options,\n \"POST\",\n this.path,\n { refreshToken },\n false,\n );\n return {\n kind: \"success\",\n accessToken: response.accessToken,\n refreshToken: response.refreshToken,\n expiresAt: response.expiresAt,\n };\n } catch (e: unknown) {\n if (e instanceof PkAuthHttpError && e.status === 401) {\n const data = e.data as RawErrorResponse | undefined;\n const detail = data?.detail;\n if (\n detail === \"expired\" ||\n detail === \"unknown\" ||\n detail === \"replayed\" ||\n detail === \"revoked\"\n ) {\n return { kind: \"failure\", reason: detail, revokeReason: data?.reason };\n }\n // Server returned a 401 we don't recognise — surface it as the most conservative failure.\n return { kind: \"failure\", reason: \"unknown\" };\n }\n throw e;\n }\n }\n}\n","// SPDX-License-Identifier: MIT\n\nexport * as base64url from \"./base64url\";\nexport { PkAuthHttpError } from \"./http\";\nexport type { CeremonyResult } from \"./results\";\nexport { isCeremonySuccess, isCeremonyFailure } from \"./results\";\nexport {\n PkAuthCeremonyClient,\n decodeCreationOptions,\n decodeRequestOptions,\n encodeAuthenticationResponse,\n encodeRegistrationResponse,\n} from \"./ceremonies\";\nexport type {\n CeremonyOptions,\n FinishRegistrationParams,\n StartAuthenticationParams,\n StartRegistrationParams,\n} from \"./ceremonies\";\nexport { PkAuthAdminClient } from \"./admin\";\nexport { PkAuthRefreshClient, isRefreshSuccess, isRefreshFailure } from \"./refresh\";\nexport type {\n RefreshResult,\n RefreshSuccess,\n RefreshFailure,\n RefreshFailureReason,\n} from \"./refresh\";\nexport type * from \"./types\";\n\nimport { PkAuthAdminClient } from \"./admin\";\nimport { PkAuthCeremonyClient } from \"./ceremonies\";\nimport type { CeremonyOptions } from \"./ceremonies\";\nimport { PkAuthRefreshClient, type RefreshResult } from \"./refresh\";\nimport type { ClientOptions } from \"./types\";\n\n/** Convenience facade: a single object exposing ceremony, admin, and refresh clients. */\nexport class PkAuthClient {\n readonly ceremonies: PkAuthCeremonyClient;\n readonly admin: PkAuthAdminClient;\n readonly refreshClient: PkAuthRefreshClient;\n\n constructor(options: ClientOptions, ceremonyOptions: CeremonyOptions = {}) {\n this.ceremonies = new PkAuthCeremonyClient(options, ceremonyOptions);\n this.admin = new PkAuthAdminClient(options);\n this.refreshClient = new PkAuthRefreshClient(options);\n }\n\n /**\n * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed\n * {@link RefreshResult} sum — does not throw on 401.\n *\n * @since 1.1.0\n */\n refresh(refreshToken: string): Promise<RefreshResult> {\n return this.refreshClient.refresh(refreshToken);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/base64url.ts","../src/http.ts","../src/results.ts","../src/ceremonies.ts","../src/admin.ts","../src/refresh.ts","../src/index.ts"],"names":["request","PATHS"],"mappings":";;;;;;;AAAA,IAAA,iBAAA,GAAA;AAAA,QAAA,CAAA,iBAAA,EAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,MAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAWO,SAAS,OAAO,KAAA,EAA8D;AACnF,EAAA,MAAM,KAAA,GAAQ,aAAa,KAAK,CAAA;AAChC,EAAA,IAAI,CAAA,GAAI,EAAA;AACR,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,QAAQ,CAAA,EAAA,EAAK;A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;AACnE,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,iBAAA,CAAkB,OAAO,CAAA;AAC1C,IAAA,IAAA,CAAK,aAAA,GAAgB,IAAI,mBAAA,CAAoB,OAAO,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAQ,YAAA,EAA8C;AACpD,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,OAAA,CAAQ,YAAY,CAAA;AAAA,EAChD;AACF","file":"index.js","sourcesContent":["// SPDX-License-Identifier: MIT\n\n/**\n * Base64url (RFC 4648 §5) without padding, matching pk-auth's wire format.\n * The server's Jackson module emits unpadded base64url; browsers can mix\n * Uint8Array, ArrayBuffer, or already-base64url strings, so `encode` handles\n * all three.\n */\n\nexport type Base64Url = string;\n\nexport function encode(input: ArrayBuffer | Uint8Array | ArrayBufferView): Base64Url {\n const bytes = toUint8Array(input);\n let s = \"\";\n for (let i = 0; i < bytes.length; i++) {\n s += String.fromCharCode(bytes[i]!);\n }\n // base64url per RFC 4648 §5: map +/ to -_ and strip padding. Using replaceAll with\n // string literals (no regexes) keeps this linear; it avoids the ReDoS shape\n // SonarQube flags on `/=+$/`. `=` only ever appears as trailing base64 padding, so\n // removing all of it is equivalent to stripping the trailing run.\n return btoa(s).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\n\nexport function decode(input: Base64Url): Uint8Array<ArrayBuffer> {\n const pad = \"=\".repeat((4 - (input.length % 4)) % 4);\n const normalized = input.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + pad;\n const binary = atob(normalized);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\nexport function decodeToArrayBuffer(input: Base64Url): ArrayBuffer {\n const bytes = decode(input);\n return bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n ) as ArrayBuffer;\n}\n\nfunction toUint8Array(input: ArrayBuffer | Uint8Array | ArrayBufferView): Uint8Array {\n if (input instanceof Uint8Array) return input;\n // A toString-based check handles cross-realm ArrayBuffers (e.g. from TextEncoder in jsdom).\n // jsdom's TextEncoder creates an ArrayBuffer that is different from NodeJs ArrayBuffer so \"instanceof\"\n // does not work. The string tag for the type does work.\n if (input instanceof ArrayBuffer || Object.prototype.toString.call(input) === \"[object ArrayBuffer]\") {\n return new Uint8Array(input as ArrayBuffer);\n }\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n}\n","// SPDX-License-Identifier: MIT\n\nimport type { ClientOptions } from \"./types\";\n\nexport class PkAuthHttpError extends Error {\n readonly status: number;\n readonly body: string;\n readonly data: Record<string, unknown> | undefined;\n\n constructor(status: number, body: string) {\n super(`HTTP ${status}: ${body}`);\n this.name = \"PkAuthHttpError\";\n this.status = status;\n this.body = body;\n try {\n const parsed = JSON.parse(body);\n this.data = parsed !== null && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : undefined;\n } catch {\n this.data = undefined;\n }\n }\n\n /** The `error` field from the parsed response body, if present. */\n get error(): string | undefined {\n return typeof this.data?.[\"error\"] === \"string\" ? (this.data[\"error\"] as string) : undefined;\n }\n\n /** The `detail` field from the parsed response body, if present. */\n get detail(): string | undefined {\n return typeof this.data?.[\"detail\"] === \"string\" ? (this.data[\"detail\"] as string) : undefined;\n }\n\n /** The `outcome` field from the parsed response body, if present. */\n get outcome(): string | undefined {\n return typeof this.data?.[\"outcome\"] === \"string\" ? (this.data[\"outcome\"] as string) : undefined;\n }\n}\n\n/** Internal request wrapper. `authenticated: true` adds the bearer header from `getToken`. */\nexport async function request<T>(\n options: ClientOptions,\n method: string,\n path: string,\n body: unknown,\n authenticated: boolean,\n): Promise<T> {\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const base = options.apiBase.endsWith(\"/\")\n ? options.apiBase.slice(0, -1)\n : options.apiBase;\n const url = `${base}${path}`;\n\n const headers: Record<string, string> = { accept: \"application/json\" };\n let payload: BodyInit | undefined;\n if (body !== undefined) {\n headers[\"content-type\"] = \"application/json\";\n payload = JSON.stringify(body);\n }\n if (authenticated) {\n const token = options.getToken?.();\n if (!token) {\n throw new Error(\"pk-auth: authenticated request requires getToken() to return a bearer token\");\n }\n headers[\"authorization\"] = `Bearer ${token}`;\n }\n\n const init: RequestInit = { method, headers };\n if (payload !== undefined) init.body = payload;\n const response = await fetchImpl(url, init);\n\n const text = await response.text();\n if (!response.ok) {\n throw new PkAuthHttpError(response.status, text);\n }\n if (!text.length) {\n return undefined as unknown as T;\n }\n return JSON.parse(text) as T;\n}\n","// SPDX-License-Identifier: MIT\n\n/**\n * Discriminated union mirroring the Java sealed result hierarchies\n * (AuthenticationResult / RegistrationResult) as returned by the pk-auth HTTP adapters.\n *\n * Authentication outcomes: success | challenge_invalid | origin_mismatch |\n * signature_invalid | unknown_credential | failed\n *\n * Registration outcomes: success | challenge_invalid | origin_mismatch |\n * attestation_rejected | duplicate_credential | invalid_payload | failed\n */\nexport type CeremonyResult =\n | { outcome: 'success'; token: string; credentialId?: string }\n | { outcome: 'challenge_invalid'; detail?: string }\n | { outcome: 'origin_mismatch'; detail?: string }\n | { outcome: 'signature_invalid'; detail?: string }\n | { outcome: 'unknown_credential'; detail?: string }\n | { outcome: 'attestation_rejected'; detail?: string }\n | { outcome: 'duplicate_credential'; detail?: string }\n | { outcome: 'invalid_payload'; detail?: string }\n | { outcome: 'failed'; detail?: string };\n\n/** Type guard: narrows a CeremonyResult to the success variant. */\nexport function isCeremonySuccess(\n result: CeremonyResult,\n): result is { outcome: 'success'; token: string; credentialId?: string } {\n return result.outcome === 'success';\n}\n\n/** Type guard: narrows a CeremonyResult to any failure variant. */\nexport function isCeremonyFailure(\n result: CeremonyResult,\n): result is Exclude<CeremonyResult, { outcome: 'success' }> {\n return result.outcome !== 'success';\n}\n","// SPDX-License-Identifier: MIT\n\nimport * as b64u from \"./base64url\";\nimport { request } from \"./http\";\nimport type {\n ClientOptions,\n FinishAuthenticationRequest,\n FinishAuthenticationResponse,\n FinishRegistrationRequest,\n FinishRegistrationResponse,\n PublicKeyCredentialCreationOptionsJson,\n PublicKeyCredentialRequestOptionsJson,\n RegistrationResponseJson,\n AuthenticationResponseJson,\n StartAuthenticationRequest,\n StartAuthenticationResponse,\n StartRegistrationRequest,\n StartRegistrationResponse,\n} from \"./types\";\n\nconst PATHS = {\n startReg: \"/auth/passkeys/registration/start\",\n finishReg: \"/auth/passkeys/registration/finish\",\n startAuth: \"/auth/passkeys/authentication/start\",\n finishAuth: \"/auth/passkeys/authentication/finish\",\n} as const;\n\n// All three adapters (Spring, Dropwizard, Micronaut) mount ceremony endpoints at\n// /auth/passkeys/<phase>/<step>. The `paths` override is an escape hatch for hosts that\n// remap the routes; no pk-auth-provided adapter needs it.\n\nexport interface CeremonyOptions {\n /** Path overrides, an escape hatch for hosts that remap pk-auth's default routes. */\n paths?: Partial<typeof PATHS>;\n /** Replacement for `navigator.credentials`, for tests and non-browser callers. */\n credentials?: CredentialsContainer;\n}\n\nexport interface StartRegistrationParams {\n username: string;\n displayName?: string;\n label?: string;\n}\n\nexport interface FinishRegistrationParams extends StartRegistrationResponse {\n username: string;\n label?: string;\n}\n\nexport interface StartAuthenticationParams {\n username?: string;\n /** When true, hands the call to `navigator.credentials.get` with `mediation: \"conditional\"`. */\n conditional?: boolean;\n}\n\nexport class PkAuthCeremonyClient {\n private readonly client: ClientOptions;\n private readonly paths: typeof PATHS;\n private readonly credentials?: CredentialsContainer;\n\n constructor(client: ClientOptions, options: CeremonyOptions = {}) {\n this.client = client;\n this.paths = { ...PATHS, ...options.paths };\n this.credentials = options.credentials;\n }\n\n /**\n * Runs the full registration ceremony: server-start → `navigator.credentials.create` →\n * server-finish. Returns the finish payload (registered credential metadata).\n */\n async register(params: StartRegistrationParams): Promise<FinishRegistrationResponse> {\n const start = await this.startRegistration({\n username: params.username,\n displayName: params.displayName ?? params.username,\n label: params.label ?? null,\n challenge: null,\n });\n const created = await this.createCredential(start.publicKey);\n return this.finishRegistration({\n challengeId: start.challengeId,\n username: params.username,\n label: params.label ?? null,\n response: encodeRegistrationResponse(created),\n });\n }\n\n /**\n * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →\n * server-finish. Returns the JWT; the caller stores it.\n */\n async authenticate(params: StartAuthenticationParams = {}): Promise<FinishAuthenticationResponse> {\n const start = await this.startAuthentication({\n username: params.username ?? null,\n challenge: null,\n });\n const got = await this.getCredential(start.publicKey, params.conditional ?? false);\n return this.finishAuthentication({\n challengeId: start.challengeId,\n response: encodeAuthenticationResponse(got),\n });\n }\n\n startRegistration(body: StartRegistrationRequest): Promise<StartRegistrationResponse> {\n return request(this.client, \"POST\", this.paths.startReg, body, false);\n }\n\n finishRegistration(body: FinishRegistrationRequest): Promise<FinishRegistrationResponse> {\n return request(this.client, \"POST\", this.paths.finishReg, body, false);\n }\n\n startAuthentication(body: StartAuthenticationRequest): Promise<StartAuthenticationResponse> {\n return request(this.client, \"POST\", this.paths.startAuth, body, false);\n }\n\n finishAuthentication(body: FinishAuthenticationRequest): Promise<FinishAuthenticationResponse> {\n return request(this.client, \"POST\", this.paths.finishAuth, body, false);\n }\n\n private get credentialsImpl(): CredentialsContainer {\n if (this.credentials) return this.credentials;\n if (typeof navigator === \"undefined\" || !navigator.credentials) {\n throw new Error(\"pk-auth: navigator.credentials is not available in this environment\");\n }\n return navigator.credentials;\n }\n\n private async createCredential(\n options: PublicKeyCredentialCreationOptionsJson,\n ): Promise<PublicKeyCredential> {\n const publicKey = decodeCreationOptions(options);\n const credential = (await this.credentialsImpl.create({ publicKey })) as PublicKeyCredential | null;\n if (!credential) {\n throw new Error(\"pk-auth: credential creation was cancelled\");\n }\n return credential;\n }\n\n private async getCredential(\n options: PublicKeyCredentialRequestOptionsJson,\n conditional: boolean,\n ): Promise<PublicKeyCredential> {\n const publicKey = decodeRequestOptions(options);\n const request: CredentialRequestOptions = { publicKey };\n if (conditional) {\n (request as CredentialRequestOptions & { mediation?: string }).mediation = \"conditional\";\n }\n const credential = (await this.credentialsImpl.get(request)) as PublicKeyCredential | null;\n if (!credential) {\n throw new Error(\"pk-auth: authentication was cancelled\");\n }\n return credential;\n }\n}\n\nexport function decodeCreationOptions(\n options: PublicKeyCredentialCreationOptionsJson,\n): PublicKeyCredentialCreationOptions {\n return {\n rp: options.rp,\n user: {\n id: b64u.decodeToArrayBuffer(options.user.id),\n name: options.user.name,\n displayName: options.user.displayName,\n },\n challenge: b64u.decodeToArrayBuffer(options.challenge),\n pubKeyCredParams: options.pubKeyCredParams,\n timeout: options.timeout,\n attestation: options.attestation,\n authenticatorSelection: options.authenticatorSelection,\n excludeCredentials: (options.excludeCredentials ?? []).map((c) => ({\n id: b64u.decodeToArrayBuffer(c.id),\n type: c.type,\n transports: c.transports as AuthenticatorTransport[] | undefined,\n })),\n };\n}\n\nexport function decodeRequestOptions(\n options: PublicKeyCredentialRequestOptionsJson,\n): PublicKeyCredentialRequestOptions {\n return {\n challenge: b64u.decodeToArrayBuffer(options.challenge),\n timeout: options.timeout,\n rpId: options.rpId,\n userVerification: options.userVerification,\n allowCredentials: (options.allowCredentials ?? []).map((c) => ({\n id: b64u.decodeToArrayBuffer(c.id),\n type: c.type,\n transports: c.transports as AuthenticatorTransport[] | undefined,\n })),\n };\n}\n\nexport function encodeRegistrationResponse(credential: PublicKeyCredential): RegistrationResponseJson {\n const response = credential.response as AuthenticatorAttestationResponse;\n const transports =\n typeof (response as AuthenticatorAttestationResponse & {\n getTransports?: () => string[];\n }).getTransports === \"function\"\n ? (response as AuthenticatorAttestationResponse & {\n getTransports: () => string[];\n }).getTransports()\n : [];\n return {\n id: b64u.encode(credential.rawId),\n rawId: b64u.encode(credential.rawId),\n type: \"public-key\",\n response: {\n clientDataJSON: b64u.encode(response.clientDataJSON),\n attestationObject: b64u.encode(response.attestationObject),\n transports,\n },\n };\n}\n\nexport function encodeAuthenticationResponse(\n credential: PublicKeyCredential,\n): AuthenticationResponseJson {\n const response = credential.response as AuthenticatorAssertionResponse;\n return {\n id: b64u.encode(credential.rawId),\n rawId: b64u.encode(credential.rawId),\n type: \"public-key\",\n response: {\n clientDataJSON: b64u.encode(response.clientDataJSON),\n authenticatorData: b64u.encode(response.authenticatorData),\n signature: b64u.encode(response.signature),\n userHandle: response.userHandle ? b64u.encode(response.userHandle) : null,\n },\n };\n}\n","// SPDX-License-Identifier: MIT\n\nimport { request } from \"./http\";\nimport type {\n AccountSummary,\n BackupCodeBatch,\n BackupCodeCount,\n ClientOptions,\n CredentialSummary,\n EmailDispatchResult,\n EmailVerificationResult,\n PhoneDispatchResult,\n PhoneVerificationResult,\n} from \"./types\";\n\nconst PATHS = {\n account: \"/auth/admin/account\",\n credentials: \"/auth/admin/credentials\",\n credentialById: (id: string) => `/auth/admin/credentials/${encodeURIComponent(id)}`,\n backupRegen: \"/auth/admin/backup-codes/regenerate\",\n backupCount: \"/auth/admin/backup-codes/count\",\n emailStart: \"/auth/admin/email/start-verification\",\n emailComplete: \"/auth/admin/email/complete-verification\",\n phoneStart: \"/auth/admin/phone/start-verification\",\n phoneComplete: \"/auth/admin/phone/complete-verification\",\n} as const;\n\nexport class PkAuthAdminClient {\n private readonly client: ClientOptions;\n\n constructor(client: ClientOptions) {\n if (!client.getToken) {\n throw new Error(\"pk-auth: admin client requires `getToken` in ClientOptions\");\n }\n this.client = client;\n }\n\n getAccount(): Promise<AccountSummary> {\n return request(this.client, \"GET\", PATHS.account, undefined, true);\n }\n\n listCredentials(): Promise<CredentialSummary[]> {\n return request(this.client, \"GET\", PATHS.credentials, undefined, true);\n }\n\n renameCredential(credentialId: string, label: string): Promise<CredentialSummary> {\n return request(this.client, \"PATCH\", PATHS.credentialById(credentialId), { label }, true);\n }\n\n removeCredential(credentialId: string): Promise<void> {\n return request(this.client, \"DELETE\", PATHS.credentialById(credentialId), undefined, true);\n }\n\n regenerateBackupCodes(): Promise<BackupCodeBatch> {\n return request(this.client, \"POST\", PATHS.backupRegen, \"\", true);\n }\n\n remainingBackupCodes(): Promise<BackupCodeCount> {\n return request(this.client, \"GET\", PATHS.backupCount, undefined, true);\n }\n\n startEmailVerification(email: string): Promise<EmailDispatchResult> {\n return request(this.client, \"POST\", PATHS.emailStart, { email }, true);\n }\n\n completeEmailVerification(token: string): Promise<EmailVerificationResult> {\n return request(this.client, \"POST\", PATHS.emailComplete, { token }, true);\n }\n\n startPhoneVerification(phone: string): Promise<PhoneDispatchResult> {\n return request(this.client, \"POST\", PATHS.phoneStart, { phone }, true);\n }\n\n completePhoneVerification(phone: string, code: string): Promise<PhoneVerificationResult> {\n return request(this.client, \"POST\", PATHS.phoneComplete, { phone, code }, true);\n }\n}\n","// SPDX-License-Identifier: MIT\n\nimport { PkAuthHttpError, request } from \"./http\";\nimport type { ClientOptions } from \"./types\";\n\n/** Typed success: a fresh refresh and access token pair. */\nexport interface RefreshSuccess {\n readonly kind: \"success\";\n readonly accessToken: string;\n readonly refreshToken: string;\n readonly expiresAt: string;\n}\n\n/** Typed failure mirroring the {@code detail} field on the server's 401 body. */\nexport type RefreshFailureReason = \"expired\" | \"unknown\" | \"replayed\" | \"revoked\";\n\nexport interface RefreshFailure {\n readonly kind: \"failure\";\n readonly reason: RefreshFailureReason;\n /** Categorical revoke reason when `reason === \"revoked\"`. */\n readonly revokeReason?: string;\n}\n\n/** Sealed sum of refresh outcomes. */\nexport type RefreshResult = RefreshSuccess | RefreshFailure;\n\n/** Type guard for {@link RefreshSuccess}. */\nexport function isRefreshSuccess(r: RefreshResult): r is RefreshSuccess {\n return r.kind === \"success\";\n}\n\n/** Type guard for {@link RefreshFailure}. */\nexport function isRefreshFailure(r: RefreshResult): r is RefreshFailure {\n return r.kind === \"failure\";\n}\n\ninterface RawRefreshResponse {\n refreshToken: string;\n accessToken: string;\n expiresAt: string;\n}\n\ninterface RawErrorResponse {\n detail?: string;\n reason?: string;\n}\n\n/**\n * Client for the {@code POST /auth/refresh} endpoint shipped by every pk-auth adapter. Returns\n * a typed {@link RefreshResult} rather than throwing on 401. The bearer's expected response to\n * an unknown, expired, replayed, or revoked outcome is to redirect to login, not to handle an\n * exception.\n *\n * @since 1.1.0\n */\nexport class PkAuthRefreshClient {\n private readonly options: ClientOptions;\n private readonly path: string;\n\n constructor(options: ClientOptions, path: string = \"/auth/refresh\") {\n this.options = options;\n this.path = path;\n }\n\n async refresh(refreshToken: string): Promise<RefreshResult> {\n try {\n const response = await request<RawRefreshResponse>(\n this.options,\n \"POST\",\n this.path,\n { refreshToken },\n false,\n );\n return {\n kind: \"success\",\n accessToken: response.accessToken,\n refreshToken: response.refreshToken,\n expiresAt: response.expiresAt,\n };\n } catch (e: unknown) {\n if (e instanceof PkAuthHttpError && e.status === 401) {\n const data = e.data as RawErrorResponse | undefined;\n const detail = data?.detail;\n if (\n detail === \"expired\" ||\n detail === \"unknown\" ||\n detail === \"replayed\" ||\n detail === \"revoked\"\n ) {\n return { kind: \"failure\", reason: detail, revokeReason: data?.reason };\n }\n // A 401 the client does not recognise surfaces as the most conservative failure.\n return { kind: \"failure\", reason: \"unknown\" };\n }\n throw e;\n }\n }\n}\n","// SPDX-License-Identifier: MIT\n\nexport * as base64url from \"./base64url\";\nexport { PkAuthHttpError } from \"./http\";\nexport type { CeremonyResult } from \"./results\";\nexport { isCeremonySuccess, isCeremonyFailure } from \"./results\";\nexport {\n PkAuthCeremonyClient,\n decodeCreationOptions,\n decodeRequestOptions,\n encodeAuthenticationResponse,\n encodeRegistrationResponse,\n} from \"./ceremonies\";\nexport type {\n CeremonyOptions,\n FinishRegistrationParams,\n StartAuthenticationParams,\n StartRegistrationParams,\n} from \"./ceremonies\";\nexport { PkAuthAdminClient } from \"./admin\";\nexport { PkAuthRefreshClient, isRefreshSuccess, isRefreshFailure } from \"./refresh\";\nexport type {\n RefreshResult,\n RefreshSuccess,\n RefreshFailure,\n RefreshFailureReason,\n} from \"./refresh\";\nexport type * from \"./types\";\n\nimport { PkAuthAdminClient } from \"./admin\";\nimport { PkAuthCeremonyClient } from \"./ceremonies\";\nimport type { CeremonyOptions } from \"./ceremonies\";\nimport { PkAuthRefreshClient, type RefreshResult } from \"./refresh\";\nimport type { ClientOptions } from \"./types\";\n\n/** Convenience facade: a single object exposing ceremony, admin, and refresh clients. */\nexport class PkAuthClient {\n readonly ceremonies: PkAuthCeremonyClient;\n readonly admin: PkAuthAdminClient;\n readonly refreshClient: PkAuthRefreshClient;\n\n constructor(options: ClientOptions, ceremonyOptions: CeremonyOptions = {}) {\n this.ceremonies = new PkAuthCeremonyClient(options, ceremonyOptions);\n this.admin = new PkAuthAdminClient(options);\n this.refreshClient = new PkAuthRefreshClient(options);\n }\n\n /**\n * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed\n * {@link RefreshResult} sum and does not throw on 401.\n *\n * @since 1.1.0\n */\n refresh(refreshToken: string): Promise<RefreshResult> {\n return this.refreshClient.refresh(refreshToken);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pk-auth/passkeys-browser",
3
- "version": "2.0.0",
3
+ "version": "2.3.0",
4
4
  "description": "pk-auth browser SDK: WebAuthn ceremonies + admin operations against the pk-auth wire contract.",
5
5
  "license": "MIT",
6
6
  "author": "Ned Wolpert",
@@ -42,7 +42,7 @@
42
42
  "access": "public"
43
43
  },
44
44
  "engines": {
45
- "node": ">=20"
45
+ "node": ">=22.22.2"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsup",
@@ -52,17 +52,18 @@
52
52
  "prepublishOnly": "npm run typecheck && npm test && npm run build"
53
53
  },
54
54
  "devDependencies": {
55
- "@stryker-mutator/core": "^9.6.1",
56
- "@stryker-mutator/vitest-runner": "^9.6.1",
57
- "@types/node": "^25.9.2",
58
- "@vitest/coverage-v8": "^4.1.8",
55
+ "@stryker-mutator/core": "^10.0.0",
56
+ "@stryker-mutator/vitest-runner": "^10.0.0",
57
+ "@types/node": "^26.0.0",
58
+ "@vitest/coverage-v8": "^5.0.0",
59
59
  "cbor-x": "^1.6.4",
60
- "jsdom": "^29.1.1",
60
+ "jsdom": "^30.0.1",
61
61
  "tsup": "^8.3.0",
62
62
  "typescript": "^6.0.3",
63
- "vitest": "^4.1.6"
63
+ "vitest": "^5.0.0"
64
64
  },
65
65
  "overrides": {
66
- "esbuild": "^0.28.1"
66
+ "esbuild": "^0.28.1",
67
+ "qs": "^6.15.2"
67
68
  }
68
69
  }
package/src/base64url.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
 
3
3
  /**
4
- * Base64url (RFC 4648 §5) without padding — matches pk-auth's wire format.
4
+ * Base64url (RFC 4648 §5) without padding, matching pk-auth's wire format.
5
5
  * The server's Jackson module emits unpadded base64url; browsers can mix
6
- * Uint8Array, ArrayBuffer, or already-base64url strings, so encode handles
6
+ * Uint8Array, ArrayBuffer, or already-base64url strings, so `encode` handles
7
7
  * all three.
8
8
  */
9
9
 
@@ -16,13 +16,13 @@ export function encode(input: ArrayBuffer | Uint8Array | ArrayBufferView): Base6
16
16
  s += String.fromCharCode(bytes[i]!);
17
17
  }
18
18
  // base64url per RFC 4648 §5: map +/ to -_ and strip padding. Using replaceAll with
19
- // string literals (no regexes) keeps this linear — it avoids the ReDoS shape
19
+ // string literals (no regexes) keeps this linear; it avoids the ReDoS shape
20
20
  // SonarQube flags on `/=+$/`. `=` only ever appears as trailing base64 padding, so
21
21
  // removing all of it is equivalent to stripping the trailing run.
22
22
  return btoa(s).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
23
23
  }
24
24
 
25
- export function decode(input: Base64Url): Uint8Array {
25
+ export function decode(input: Base64Url): Uint8Array<ArrayBuffer> {
26
26
  const pad = "=".repeat((4 - (input.length % 4)) % 4);
27
27
  const normalized = input.replaceAll("-", "+").replaceAll("_", "/") + pad;
28
28
  const binary = atob(normalized);
@@ -43,6 +43,11 @@ export function decodeToArrayBuffer(input: Base64Url): ArrayBuffer {
43
43
 
44
44
  function toUint8Array(input: ArrayBuffer | Uint8Array | ArrayBufferView): Uint8Array {
45
45
  if (input instanceof Uint8Array) return input;
46
- if (input instanceof ArrayBuffer) return new Uint8Array(input);
46
+ // A toString-based check handles cross-realm ArrayBuffers (e.g. from TextEncoder in jsdom).
47
+ // jsdom's TextEncoder creates an ArrayBuffer that is different from NodeJs ArrayBuffer so "instanceof"
48
+ // does not work. The string tag for the type does work.
49
+ if (input instanceof ArrayBuffer || Object.prototype.toString.call(input) === "[object ArrayBuffer]") {
50
+ return new Uint8Array(input as ArrayBuffer);
51
+ }
47
52
  return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
48
53
  }
package/src/ceremonies.ts CHANGED
@@ -25,14 +25,14 @@ const PATHS = {
25
25
  finishAuth: "/auth/passkeys/authentication/finish",
26
26
  } as const;
27
27
 
28
- // All three adapters (Spring, Dropwizard, Micronaut) now mount ceremony endpoints at
29
- // /auth/passkeys/<phase>/<step>. The `paths` override remains an escape hatch for hosts that
30
- // remap the routes but is no longer needed for any pk-auth-provided adapter.
28
+ // All three adapters (Spring, Dropwizard, Micronaut) mount ceremony endpoints at
29
+ // /auth/passkeys/<phase>/<step>. The `paths` override is an escape hatch for hosts that
30
+ // remap the routes; no pk-auth-provided adapter needs it.
31
31
 
32
32
  export interface CeremonyOptions {
33
- /** Path overrides — kept as an escape hatch for hosts that remap pk-auth's default routes. */
33
+ /** Path overrides, an escape hatch for hosts that remap pk-auth's default routes. */
34
34
  paths?: Partial<typeof PATHS>;
35
- /** Optional override for navigator.credentials (tests / non-browser callers). */
35
+ /** Replacement for `navigator.credentials`, for tests and non-browser callers. */
36
36
  credentials?: CredentialsContainer;
37
37
  }
38
38
 
@@ -86,7 +86,7 @@ export class PkAuthCeremonyClient {
86
86
 
87
87
  /**
88
88
  * Runs the full sign-in ceremony: server-start → `navigator.credentials.get` →
89
- * server-finish. Returns the JWT (consumer is responsible for storage).
89
+ * server-finish. Returns the JWT; the caller stores it.
90
90
  */
91
91
  async authenticate(params: StartAuthenticationParams = {}): Promise<FinishAuthenticationResponse> {
92
92
  const start = await this.startAuthentication({
package/src/index.ts CHANGED
@@ -47,7 +47,7 @@ export class PkAuthClient {
47
47
 
48
48
  /**
49
49
  * Convenience shortcut to {@link PkAuthRefreshClient#refresh}. Returns a typed
50
- * {@link RefreshResult} sum — does not throw on 401.
50
+ * {@link RefreshResult} sum and does not throw on 401.
51
51
  *
52
52
  * @since 1.1.0
53
53
  */
package/src/refresh.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import { PkAuthHttpError, request } from "./http";
4
4
  import type { ClientOptions } from "./types";
5
5
 
6
- /** Typed success: a fresh refresh + access token pair to swap in. */
6
+ /** Typed success: a fresh refresh and access token pair. */
7
7
  export interface RefreshSuccess {
8
8
  readonly kind: "success";
9
9
  readonly accessToken: string;
@@ -47,8 +47,8 @@ interface RawErrorResponse {
47
47
 
48
48
  /**
49
49
  * Client for the {@code POST /auth/refresh} endpoint shipped by every pk-auth adapter. Returns
50
- * a typed {@link RefreshResult} rather than throwing on 401 — the bearer's expected response to
51
- * an Unknown / Expired / Replayed / Revoked outcome is to redirect to login, not to handle an
50
+ * a typed {@link RefreshResult} rather than throwing on 401. The bearer's expected response to
51
+ * an unknown, expired, replayed, or revoked outcome is to redirect to login, not to handle an
52
52
  * exception.
53
53
  *
54
54
  * @since 1.1.0
@@ -89,7 +89,7 @@ export class PkAuthRefreshClient {
89
89
  ) {
90
90
  return { kind: "failure", reason: detail, revokeReason: data?.reason };
91
91
  }
92
- // Server returned a 401 we don't recognise — surface it as the most conservative failure.
92
+ // A 401 the client does not recognise surfaces as the most conservative failure.
93
93
  return { kind: "failure", reason: "unknown" };
94
94
  }
95
95
  throw e;
package/src/types.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type { Base64Url } from "./base64url";
4
4
 
5
- /** Caller-supplied bearer-token accessor. Returns null when there's no session yet. */
5
+ /** Caller-supplied bearer-token accessor. Returns null when no session exists. */
6
6
  export type TokenAccessor = () => string | null;
7
7
 
8
8
  /** Construction options shared by the ceremony and admin clients. */
@@ -14,11 +14,11 @@ export interface ClientOptions {
14
14
  * ceremony operations are anonymous and will not call it.
15
15
  */
16
16
  getToken?: TokenAccessor;
17
- /** Override the global fetch (handy for tests). */
17
+ /** Replacement for the global `fetch`, used in tests. */
18
18
  fetch?: typeof fetch;
19
19
  }
20
20
 
21
- // -- Ceremony wire shapes ----------------------------------------------------
21
+ // Ceremony wire shapes
22
22
 
23
23
  export interface RpEntity {
24
24
  id: string;
@@ -118,7 +118,7 @@ export interface FinishAuthenticationRequest {
118
118
  response: AuthenticationResponseJson;
119
119
  }
120
120
 
121
- /** Server returns the wrapped RegistrationResult; relevant fields are surfaced here. */
121
+ /** The server returns the wrapped RegistrationResult; the relevant fields are surfaced here. */
122
122
  export interface FinishRegistrationResponse {
123
123
  credential: {
124
124
  credentialId: Base64Url;
@@ -137,7 +137,7 @@ export interface FinishAuthenticationResponse {
137
137
  token: string;
138
138
  }
139
139
 
140
- // -- Admin wire shapes --------------------------------------------------------
140
+ // Admin wire shapes
141
141
 
142
142
  export interface CredentialSummary {
143
143
  credentialId: Base64Url;
@@ -171,13 +171,13 @@ export interface BackupCodeCount {
171
171
  export interface EmailDispatchResult {
172
172
  /** Implementation-defined token / link reference returned by the dispatcher. */
173
173
  dispatchId?: string;
174
- /** Magic-link token (testkit / dev only — real dispatchers send it out of band). */
174
+ /** Magic-link token (testkit and development only; real dispatchers send it out of band). */
175
175
  token?: string;
176
176
  }
177
177
 
178
178
  export interface PhoneDispatchResult {
179
179
  dispatchId?: string;
180
- /** OTP code (testkit / dev only — real dispatchers send it via SMS). */
180
+ /** OTP code (testkit and development only; real dispatchers send it via SMS). */
181
181
  code?: string;
182
182
  }
183
183