@simplewebauthn/server 9.0.3 → 10.0.1

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.
Files changed (52) hide show
  1. package/README.md +2 -2
  2. package/esm/authentication/generateAuthenticationOptions.d.ts +16 -14
  3. package/esm/authentication/generateAuthenticationOptions.js +21 -16
  4. package/esm/authentication/verifyAuthenticationResponse.d.ts +13 -18
  5. package/esm/authentication/verifyAuthenticationResponse.js +12 -17
  6. package/esm/deps.d.ts +1 -1
  7. package/esm/helpers/convertCertBufferToPEM.js +1 -1
  8. package/esm/helpers/decodeClientDataJSON.d.ts +2 -1
  9. package/esm/helpers/decodeClientDataJSON.js +1 -1
  10. package/esm/helpers/generateUserID.d.ts +7 -0
  11. package/esm/helpers/generateUserID.js +17 -0
  12. package/esm/helpers/index.d.ts +2 -1
  13. package/esm/helpers/index.js +2 -1
  14. package/esm/helpers/iso/isoBase64URL.d.ts +10 -5
  15. package/esm/helpers/iso/isoBase64URL.js +13 -7
  16. package/esm/helpers/iso/isoCrypto/getWebCrypto.d.ts +0 -289
  17. package/esm/helpers/iso/isoCrypto/getWebCrypto.js +26 -41
  18. package/esm/helpers/iso/isoCrypto/unwrapEC2Signature.d.ts +2 -1
  19. package/esm/helpers/iso/isoCrypto/unwrapEC2Signature.js +58 -16
  20. package/esm/helpers/iso/isoCrypto/verify.js +6 -2
  21. package/esm/metadata/parseJWT.js +2 -2
  22. package/esm/registration/generateRegistrationOptions.d.ts +19 -19
  23. package/esm/registration/generateRegistrationOptions.js +40 -22
  24. package/esm/registration/verifications/verifyAttestationAndroidSafetyNet.js +2 -2
  25. package/esm/registration/verifyRegistrationResponse.d.ts +9 -12
  26. package/esm/registration/verifyRegistrationResponse.js +8 -11
  27. package/package.json +3 -3
  28. package/script/authentication/generateAuthenticationOptions.d.ts +16 -14
  29. package/script/authentication/generateAuthenticationOptions.js +21 -16
  30. package/script/authentication/verifyAuthenticationResponse.d.ts +13 -18
  31. package/script/authentication/verifyAuthenticationResponse.js +12 -17
  32. package/script/deps.d.ts +1 -1
  33. package/script/helpers/convertCertBufferToPEM.js +1 -1
  34. package/script/helpers/decodeClientDataJSON.d.ts +2 -1
  35. package/script/helpers/decodeClientDataJSON.js +1 -1
  36. package/script/helpers/generateUserID.d.ts +7 -0
  37. package/script/helpers/generateUserID.js +21 -0
  38. package/script/helpers/index.d.ts +2 -1
  39. package/script/helpers/index.js +3 -1
  40. package/script/helpers/iso/isoBase64URL.d.ts +10 -5
  41. package/script/helpers/iso/isoBase64URL.js +18 -11
  42. package/script/helpers/iso/isoCrypto/getWebCrypto.d.ts +0 -288
  43. package/script/helpers/iso/isoCrypto/getWebCrypto.js +26 -64
  44. package/script/helpers/iso/isoCrypto/unwrapEC2Signature.d.ts +2 -1
  45. package/script/helpers/iso/isoCrypto/unwrapEC2Signature.js +58 -16
  46. package/script/helpers/iso/isoCrypto/verify.js +5 -1
  47. package/script/metadata/parseJWT.js +2 -2
  48. package/script/registration/generateRegistrationOptions.d.ts +19 -19
  49. package/script/registration/generateRegistrationOptions.js +40 -22
  50. package/script/registration/verifications/verifyAttestationAndroidSafetyNet.js +2 -2
  51. package/script/registration/verifyRegistrationResponse.d.ts +9 -12
  52. package/script/registration/verifyRegistrationResponse.js +8 -11
package/README.md CHANGED
@@ -4,14 +4,14 @@
4
4
  [![npm (scoped)](https://img.shields.io/npm/v/@simplewebauthn/server?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@simplewebauthn/server)
5
5
 
6
6
  - [Installation](#installation)
7
- - [Node LTS 16.x or higher](#node-lts-16x-or-higher)
7
+ - [Node LTS 20.x or higher](#node-lts-20x-or-higher)
8
8
  - [Deno v1.33.x or higher](#deno-v133x-or-higher)
9
9
  - [Usage](#usage)
10
10
  - [Supported Attestation Formats](#supported-attestation-formats)
11
11
 
12
12
  ## Installation
13
13
 
14
- ### Node LTS 16.x or higher
14
+ ### Node LTS 20.x or higher
15
15
 
16
16
  This package is available on **npm** and supports **both CommonJS and
17
17
  [ECMAScript modules (ESM)](https://nodejs.org/api/esm.html#enabling)** projects:
@@ -1,23 +1,25 @@
1
- import type { AuthenticationExtensionsClientInputs, PublicKeyCredentialDescriptorFuture, PublicKeyCredentialRequestOptionsJSON, UserVerificationRequirement } from '../deps.js';
1
+ import type { AuthenticationExtensionsClientInputs, AuthenticatorTransportFuture, Base64URLString, PublicKeyCredentialRequestOptionsJSON, UserVerificationRequirement } from '../deps.js';
2
2
  export type GenerateAuthenticationOptionsOpts = {
3
- allowCredentials?: PublicKeyCredentialDescriptorFuture[];
3
+ rpID: string;
4
+ allowCredentials?: {
5
+ id: Base64URLString;
6
+ transports?: AuthenticatorTransportFuture[];
7
+ }[];
4
8
  challenge?: string | Uint8Array;
5
9
  timeout?: number;
6
10
  userVerification?: UserVerificationRequirement;
7
11
  extensions?: AuthenticationExtensionsClientInputs;
8
- rpID?: string;
9
12
  };
10
13
  /**
11
- * Prepare a value to pass into navigator.credentials.get(...) for authenticator "login"
14
+ * Prepare a value to pass into navigator.credentials.get(...) for authenticator authentication
12
15
  *
13
- * @param allowCredentials Authenticators previously registered by the user, if any. If undefined
14
- * the client will ask the user which credential they want to use
15
- * @param challenge Random value the authenticator needs to sign and pass back
16
- * user for authentication
17
- * @param timeout How long (in ms) the user can take to complete authentication
18
- * @param userVerification Set to `'discouraged'` when asserting as part of a 2FA flow, otherwise
19
- * set to `'preferred'` or `'required'` as desired.
20
- * @param extensions Additional plugins the authenticator or browser should use during authentication
21
- * @param rpID Valid domain name (after `https://`)
16
+ * **Options:**
17
+ *
18
+ * @param rpID - Valid domain name (after `https://`)
19
+ * @param allowCredentials **(Optional)** - Authenticators previously registered by the user, if any. If undefined the client will ask the user which credential they want to use
20
+ * @param challenge **(Optional)** - Random value the authenticator needs to sign and pass back user for authentication. Defaults to generating a random value
21
+ * @param timeout **(Optional)** - How long (in ms) the user can take to complete authentication. Defaults to `60000`
22
+ * @param userVerification **(Optional)** - Set to `'discouraged'` when asserting as part of a 2FA flow, otherwise set to `'preferred'` or `'required'` as desired. Defaults to `"preferred"`
23
+ * @param extensions **(Optional)** - Additional plugins the authenticator or browser should use during authentication
22
24
  */
23
- export declare function generateAuthenticationOptions(options?: GenerateAuthenticationOptionsOpts): Promise<PublicKeyCredentialRequestOptionsJSON>;
25
+ export declare function generateAuthenticationOptions(options: GenerateAuthenticationOptionsOpts): Promise<PublicKeyCredentialRequestOptionsJSON>;
@@ -1,19 +1,18 @@
1
1
  import { isoBase64URL, isoUint8Array } from '../helpers/iso/index.js';
2
2
  import { generateChallenge } from '../helpers/generateChallenge.js';
3
3
  /**
4
- * Prepare a value to pass into navigator.credentials.get(...) for authenticator "login"
4
+ * Prepare a value to pass into navigator.credentials.get(...) for authenticator authentication
5
5
  *
6
- * @param allowCredentials Authenticators previously registered by the user, if any. If undefined
7
- * the client will ask the user which credential they want to use
8
- * @param challenge Random value the authenticator needs to sign and pass back
9
- * user for authentication
10
- * @param timeout How long (in ms) the user can take to complete authentication
11
- * @param userVerification Set to `'discouraged'` when asserting as part of a 2FA flow, otherwise
12
- * set to `'preferred'` or `'required'` as desired.
13
- * @param extensions Additional plugins the authenticator or browser should use during authentication
14
- * @param rpID Valid domain name (after `https://`)
6
+ * **Options:**
7
+ *
8
+ * @param rpID - Valid domain name (after `https://`)
9
+ * @param allowCredentials **(Optional)** - Authenticators previously registered by the user, if any. If undefined the client will ask the user which credential they want to use
10
+ * @param challenge **(Optional)** - Random value the authenticator needs to sign and pass back user for authentication. Defaults to generating a random value
11
+ * @param timeout **(Optional)** - How long (in ms) the user can take to complete authentication. Defaults to `60000`
12
+ * @param userVerification **(Optional)** - Set to `'discouraged'` when asserting as part of a 2FA flow, otherwise set to `'preferred'` or `'required'` as desired. Defaults to `"preferred"`
13
+ * @param extensions **(Optional)** - Additional plugins the authenticator or browser should use during authentication
15
14
  */
16
- export async function generateAuthenticationOptions(options = {}) {
15
+ export async function generateAuthenticationOptions(options) {
17
16
  const { allowCredentials, challenge = await generateChallenge(), timeout = 60000, userVerification = 'preferred', extensions, rpID, } = options;
18
17
  /**
19
18
  * Preserve ability to specify `string` values for challenges
@@ -23,14 +22,20 @@ export async function generateAuthenticationOptions(options = {}) {
23
22
  _challenge = isoUint8Array.fromUTF8String(_challenge);
24
23
  }
25
24
  return {
25
+ rpId: rpID,
26
26
  challenge: isoBase64URL.fromBuffer(_challenge),
27
- allowCredentials: allowCredentials?.map((cred) => ({
28
- ...cred,
29
- id: isoBase64URL.fromBuffer(cred.id),
30
- })),
27
+ allowCredentials: allowCredentials?.map((cred) => {
28
+ if (!isoBase64URL.isBase64URL(cred.id)) {
29
+ throw new Error(`excludeCredential id "${cred.id}" is not a valid base64url string`);
30
+ }
31
+ return {
32
+ ...cred,
33
+ id: isoBase64URL.trimPadding(cred.id),
34
+ type: 'public-key',
35
+ };
36
+ }),
31
37
  timeout,
32
38
  userVerification,
33
39
  extensions,
34
- rpId: rpID,
35
40
  };
36
41
  }
@@ -1,36 +1,31 @@
1
- import type { AuthenticationResponseJSON, AuthenticatorDevice, CredentialDeviceType, UserVerificationRequirement } from '../deps.js';
1
+ import type { AuthenticationResponseJSON, AuthenticatorDevice, Base64URLString, CredentialDeviceType, UserVerificationRequirement } from '../deps.js';
2
2
  import { AuthenticationExtensionsAuthenticatorOutputs } from '../helpers/decodeAuthenticatorExtensions.js';
3
3
  export type VerifyAuthenticationResponseOpts = {
4
4
  response: AuthenticationResponseJSON;
5
5
  expectedChallenge: string | ((challenge: string) => boolean | Promise<boolean>);
6
6
  expectedOrigin: string | string[];
7
7
  expectedRPID: string | string[];
8
- expectedType?: string | string[];
9
8
  authenticator: AuthenticatorDevice;
9
+ expectedType?: string | string[];
10
10
  requireUserVerification?: boolean;
11
11
  advancedFIDOConfig?: {
12
12
  userVerification?: UserVerificationRequirement;
13
13
  };
14
14
  };
15
15
  /**
16
- * Verify that the user has legitimately completed the login process
16
+ * Verify that the user has legitimately completed the authentication process
17
17
  *
18
18
  * **Options:**
19
19
  *
20
- * @param response Response returned by **@simplewebauthn/browser**'s `startAssertion()`
21
- * @param expectedChallenge The base64url-encoded `options.challenge` returned by
22
- * `generateAuthenticationOptions()`
23
- * @param expectedOrigin Website URL (or array of URLs) that the registration should have occurred on
24
- * @param expectedRPID RP ID (or array of IDs) that was specified in the registration options
25
- * @param expectedType (Optional) The response type expected ('webauthn.get')
26
- * @param authenticator An internal {@link AuthenticatorDevice} matching the credential's ID
27
- * @param requireUserVerification (Optional) Enforce user verification by the authenticator
28
- * (via PIN, fingerprint, etc...)
29
- * @param advancedFIDOConfig (Optional) Options for satisfying more stringent FIDO RP feature
30
- * requirements
31
- * @param advancedFIDOConfig.userVerification (Optional) Enable alternative rules for evaluating the
32
- * User Presence and User Verified flags in authenticator data: UV (and UP) flags are optional
33
- * unless this value is `"required"`
20
+ * @param response - Response returned by **@simplewebauthn/browser**'s `startAssertion()`
21
+ * @param expectedChallenge - The base64url-encoded `options.challenge` returned by `generateAuthenticationOptions()`
22
+ * @param expectedOrigin - Website URL (or array of URLs) that the registration should have occurred on
23
+ * @param expectedRPID - RP ID (or array of IDs) that was specified in the registration options
24
+ * @param authenticator - An internal {@link AuthenticatorDevice} matching the credential's ID
25
+ * @param expectedType **(Optional)** - The response type expected ('webauthn.get')
26
+ * @param requireUserVerification **(Optional)** - Enforce user verification by the authenticator (via PIN, fingerprint, etc...) Defaults to `true`
27
+ * @param advancedFIDOConfig **(Optional)** - Options for satisfying more stringent FIDO RP feature requirements
28
+ * @param advancedFIDOConfig.userVerification **(Optional)** - Enable alternative rules for evaluating the User Presence and User Verified flags in authenticator data: UV (and UP) flags are optional unless this value is `"required"`
34
29
  */
35
30
  export declare function verifyAuthenticationResponse(options: VerifyAuthenticationResponseOpts): Promise<VerifiedAuthenticationResponse>;
36
31
  /**
@@ -56,7 +51,7 @@ export declare function verifyAuthenticationResponse(options: VerifyAuthenticati
56
51
  export type VerifiedAuthenticationResponse = {
57
52
  verified: boolean;
58
53
  authenticationInfo: {
59
- credentialID: Uint8Array;
54
+ credentialID: Base64URLString;
60
55
  newCounter: number;
61
56
  userVerified: boolean;
62
57
  credentialDeviceType: CredentialDeviceType;
@@ -6,24 +6,19 @@ import { parseBackupFlags } from '../helpers/parseBackupFlags.js';
6
6
  import { matchExpectedRPID } from '../helpers/matchExpectedRPID.js';
7
7
  import { isoBase64URL, isoUint8Array } from '../helpers/iso/index.js';
8
8
  /**
9
- * Verify that the user has legitimately completed the login process
9
+ * Verify that the user has legitimately completed the authentication process
10
10
  *
11
11
  * **Options:**
12
12
  *
13
- * @param response Response returned by **@simplewebauthn/browser**'s `startAssertion()`
14
- * @param expectedChallenge The base64url-encoded `options.challenge` returned by
15
- * `generateAuthenticationOptions()`
16
- * @param expectedOrigin Website URL (or array of URLs) that the registration should have occurred on
17
- * @param expectedRPID RP ID (or array of IDs) that was specified in the registration options
18
- * @param expectedType (Optional) The response type expected ('webauthn.get')
19
- * @param authenticator An internal {@link AuthenticatorDevice} matching the credential's ID
20
- * @param requireUserVerification (Optional) Enforce user verification by the authenticator
21
- * (via PIN, fingerprint, etc...)
22
- * @param advancedFIDOConfig (Optional) Options for satisfying more stringent FIDO RP feature
23
- * requirements
24
- * @param advancedFIDOConfig.userVerification (Optional) Enable alternative rules for evaluating the
25
- * User Presence and User Verified flags in authenticator data: UV (and UP) flags are optional
26
- * unless this value is `"required"`
13
+ * @param response - Response returned by **@simplewebauthn/browser**'s `startAssertion()`
14
+ * @param expectedChallenge - The base64url-encoded `options.challenge` returned by `generateAuthenticationOptions()`
15
+ * @param expectedOrigin - Website URL (or array of URLs) that the registration should have occurred on
16
+ * @param expectedRPID - RP ID (or array of IDs) that was specified in the registration options
17
+ * @param authenticator - An internal {@link AuthenticatorDevice} matching the credential's ID
18
+ * @param expectedType **(Optional)** - The response type expected ('webauthn.get')
19
+ * @param requireUserVerification **(Optional)** - Enforce user verification by the authenticator (via PIN, fingerprint, etc...) Defaults to `true`
20
+ * @param advancedFIDOConfig **(Optional)** - Options for satisfying more stringent FIDO RP feature requirements
21
+ * @param advancedFIDOConfig.userVerification **(Optional)** - Enable alternative rules for evaluating the User Presence and User Verified flags in authenticator data: UV (and UP) flags are optional unless this value is `"required"`
27
22
  */
28
23
  export async function verifyAuthenticationResponse(options) {
29
24
  const { response, expectedChallenge, expectedOrigin, expectedRPID, expectedType, authenticator, requireUserVerification = true, advancedFIDOConfig, } = options;
@@ -84,10 +79,10 @@ export async function verifyAuthenticationResponse(options) {
84
79
  throw new Error(`Unexpected authentication response origin "${origin}", expected "${expectedOrigin}"`);
85
80
  }
86
81
  }
87
- if (!isoBase64URL.isBase64url(assertionResponse.authenticatorData)) {
82
+ if (!isoBase64URL.isBase64URL(assertionResponse.authenticatorData)) {
88
83
  throw new Error('Credential response authenticatorData was not a base64url string');
89
84
  }
90
- if (!isoBase64URL.isBase64url(assertionResponse.signature)) {
85
+ if (!isoBase64URL.isBase64URL(assertionResponse.signature)) {
91
86
  throw new Error('Credential response signature was not a base64url string');
92
87
  }
93
88
  if (assertionResponse.userHandle &&
package/esm/deps.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { AttestationConveyancePreference, AuthenticationExtensionsClientInputs, AuthenticationResponseJSON, AuthenticatorDevice, AuthenticatorSelectionCriteria, Base64URLString, COSEAlgorithmIdentifier, CredentialDeviceType, Crypto, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialDescriptorFuture, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptionsJSON, RegistrationResponseJSON, UserVerificationRequirement, } from '@simplewebauthn/types';
1
+ export type { AttestationConveyancePreference, AuthenticationExtensionsClientInputs, AuthenticationResponseJSON, AuthenticatorDevice, AuthenticatorSelectionCriteria, AuthenticatorTransportFuture, Base64URLString, COSEAlgorithmIdentifier, CredentialDeviceType, Crypto, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptionsJSON, RegistrationResponseJSON, UserVerificationRequirement, } from '@simplewebauthn/types';
2
2
  export * as tinyCbor from '@levischuck/tiny-cbor';
3
3
  export { default as base64 } from '@hexagon/base64';
4
4
  export { fetch as crossFetch } from 'cross-fetch';
@@ -8,7 +8,7 @@ export function convertCertBufferToPEM(certBuffer) {
8
8
  * Get certBuffer to a base64 representation
9
9
  */
10
10
  if (typeof certBuffer === 'string') {
11
- if (isoBase64URL.isBase64url(certBuffer)) {
11
+ if (isoBase64URL.isBase64URL(certBuffer)) {
12
12
  b64cert = isoBase64URL.toBase64(certBuffer);
13
13
  }
14
14
  else if (isoBase64URL.isBase64(certBuffer)) {
@@ -1,7 +1,8 @@
1
+ import type { Base64URLString } from '../deps.js';
1
2
  /**
2
3
  * Decode an authenticator's base64url-encoded clientDataJSON to JSON
3
4
  */
4
- export declare function decodeClientDataJSON(data: string): ClientDataJSON;
5
+ export declare function decodeClientDataJSON(data: Base64URLString): ClientDataJSON;
5
6
  export type ClientDataJSON = {
6
7
  type: string;
7
8
  challenge: string;
@@ -3,7 +3,7 @@ import { isoBase64URL } from './iso/index.js';
3
3
  * Decode an authenticator's base64url-encoded clientDataJSON to JSON
4
4
  */
5
5
  export function decodeClientDataJSON(data) {
6
- const toString = isoBase64URL.toString(data);
6
+ const toString = isoBase64URL.toUTF8String(data);
7
7
  const clientData = JSON.parse(toString);
8
8
  return _decodeClientDataJSONInternals.stubThis(clientData);
9
9
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generate a suitably random value to be used as user ID
3
+ */
4
+ export declare function generateUserID(): Promise<Uint8Array>;
5
+ export declare const _generateUserIDInternals: {
6
+ stubThis: (value: Uint8Array) => Uint8Array;
7
+ };
@@ -0,0 +1,17 @@
1
+ import { isoCrypto } from './iso/index.js';
2
+ /**
3
+ * Generate a suitably random value to be used as user ID
4
+ */
5
+ export async function generateUserID() {
6
+ /**
7
+ * WebAuthn spec says user.id has a max length of 64 bytes. I prefer how 32 random bytes look
8
+ * after they're base64url-encoded so I'm choosing to go with that here.
9
+ */
10
+ const newUserID = new Uint8Array(32);
11
+ await isoCrypto.getRandomValues(newUserID);
12
+ return _generateUserIDInternals.stubThis(newUserID);
13
+ }
14
+ // Make it possible to stub the return value during testing
15
+ export const _generateUserIDInternals = {
16
+ stubThis: (value) => value,
17
+ };
@@ -5,6 +5,7 @@ import { decodeAttestationObject } from './decodeAttestationObject.js';
5
5
  import { decodeClientDataJSON } from './decodeClientDataJSON.js';
6
6
  import { decodeCredentialPublicKey } from './decodeCredentialPublicKey.js';
7
7
  import { generateChallenge } from './generateChallenge.js';
8
+ import { generateUserID } from './generateUserID.js';
8
9
  import { getCertificateInfo } from './getCertificateInfo.js';
9
10
  import { isCertRevoked } from './isCertRevoked.js';
10
11
  import { parseAuthenticatorData } from './parseAuthenticatorData.js';
@@ -13,7 +14,7 @@ import { validateCertificatePath } from './validateCertificatePath.js';
13
14
  import { verifySignature } from './verifySignature.js';
14
15
  import { isoBase64URL, isoCBOR, isoCrypto, isoUint8Array } from './iso/index.js';
15
16
  import * as cose from './cose.js';
16
- export { convertAAGUIDToString, convertCertBufferToPEM, convertCOSEtoPKCS, cose, decodeAttestationObject, decodeClientDataJSON, decodeCredentialPublicKey, generateChallenge, getCertificateInfo, isCertRevoked, isoBase64URL, isoCBOR, isoCrypto, isoUint8Array, parseAuthenticatorData, toHash, validateCertificatePath, verifySignature, };
17
+ export { convertAAGUIDToString, convertCertBufferToPEM, convertCOSEtoPKCS, cose, decodeAttestationObject, decodeClientDataJSON, decodeCredentialPublicKey, generateChallenge, generateUserID, getCertificateInfo, isCertRevoked, isoBase64URL, isoCBOR, isoCrypto, isoUint8Array, parseAuthenticatorData, toHash, validateCertificatePath, verifySignature, };
17
18
  import type { AttestationFormat, AttestationObject, AttestationStatement } from './decodeAttestationObject.js';
18
19
  import type { CertificateInfo } from './getCertificateInfo.js';
19
20
  import type { ClientDataJSON } from './decodeClientDataJSON.js';
@@ -5,6 +5,7 @@ import { decodeAttestationObject } from './decodeAttestationObject.js';
5
5
  import { decodeClientDataJSON } from './decodeClientDataJSON.js';
6
6
  import { decodeCredentialPublicKey } from './decodeCredentialPublicKey.js';
7
7
  import { generateChallenge } from './generateChallenge.js';
8
+ import { generateUserID } from './generateUserID.js';
8
9
  import { getCertificateInfo } from './getCertificateInfo.js';
9
10
  import { isCertRevoked } from './isCertRevoked.js';
10
11
  import { parseAuthenticatorData } from './parseAuthenticatorData.js';
@@ -13,4 +14,4 @@ import { validateCertificatePath } from './validateCertificatePath.js';
13
14
  import { verifySignature } from './verifySignature.js';
14
15
  import { isoBase64URL, isoCBOR, isoCrypto, isoUint8Array } from './iso/index.js';
15
16
  import * as cose from './cose.js';
16
- export { convertAAGUIDToString, convertCertBufferToPEM, convertCOSEtoPKCS, cose, decodeAttestationObject, decodeClientDataJSON, decodeCredentialPublicKey, generateChallenge, getCertificateInfo, isCertRevoked, isoBase64URL, isoCBOR, isoCrypto, isoUint8Array, parseAuthenticatorData, toHash, validateCertificatePath, verifySignature, };
17
+ export { convertAAGUIDToString, convertCertBufferToPEM, convertCOSEtoPKCS, cose, decodeAttestationObject, decodeClientDataJSON, decodeCredentialPublicKey, generateChallenge, generateUserID, getCertificateInfo, isCertRevoked, isoBase64URL, isoCBOR, isoCrypto, isoUint8Array, parseAuthenticatorData, toHash, validateCertificatePath, verifySignature, };
@@ -1,3 +1,4 @@
1
+ import type { Base64URLString } from '../../deps.js';
1
2
  /**
2
3
  * Decode from a Base64URL-encoded string to an ArrayBuffer. Best used when converting a
3
4
  * credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
@@ -20,13 +21,13 @@ export declare function fromBuffer(buffer: Uint8Array, to?: 'base64' | 'base64ur
20
21
  */
21
22
  export declare function toBase64(base64urlString: string): string;
22
23
  /**
23
- * Encode a string to base64url
24
+ * Encode a UTF-8 string to base64url
24
25
  */
25
- export declare function fromString(ascii: string): string;
26
+ export declare function fromUTF8String(utf8String: string): string;
26
27
  /**
27
- * Decode a base64url string into its original string
28
+ * Decode a base64url string into its original UTF-8 string
28
29
  */
29
- export declare function toString(base64urlString: string): string;
30
+ export declare function toUTF8String(base64urlString: string): string;
30
31
  /**
31
32
  * Confirm that the string is encoded into base64
32
33
  */
@@ -34,4 +35,8 @@ export declare function isBase64(input: string): boolean;
34
35
  /**
35
36
  * Confirm that the string is encoded into base64url, with support for optional padding
36
37
  */
37
- export declare function isBase64url(input: string): boolean;
38
+ export declare function isBase64URL(input: string): boolean;
39
+ /**
40
+ * Remove optional padding from a base64url-encoded string
41
+ */
42
+ export declare function trimPadding(input: Base64URLString): Base64URLString;
@@ -30,15 +30,15 @@ export function toBase64(base64urlString) {
30
30
  return toBase64;
31
31
  }
32
32
  /**
33
- * Encode a string to base64url
33
+ * Encode a UTF-8 string to base64url
34
34
  */
35
- export function fromString(ascii) {
36
- return base64.fromString(ascii, true);
35
+ export function fromUTF8String(utf8String) {
36
+ return base64.fromString(utf8String, true);
37
37
  }
38
38
  /**
39
- * Decode a base64url string into its original string
39
+ * Decode a base64url string into its original UTF-8 string
40
40
  */
41
- export function toString(base64urlString) {
41
+ export function toUTF8String(base64urlString) {
42
42
  return base64.toString(base64urlString, true);
43
43
  }
44
44
  /**
@@ -50,8 +50,14 @@ export function isBase64(input) {
50
50
  /**
51
51
  * Confirm that the string is encoded into base64url, with support for optional padding
52
52
  */
53
- export function isBase64url(input) {
53
+ export function isBase64URL(input) {
54
54
  // Trim padding characters from the string if present
55
- input = input.replace(/=/g, '');
55
+ input = trimPadding(input);
56
56
  return base64.validate(input, true);
57
57
  }
58
+ /**
59
+ * Remove optional padding from a base64url-encoded string
60
+ */
61
+ export function trimPadding(input) {
62
+ return input.replace(/=/g, '');
63
+ }