ox
Version:
77 lines • 3.12 kB
TypeScript
import * as Base64 from '../core/Base64.js';
import type * as Errors from '../core/Errors.js';
import type * as Hex from '../core/Hex.js';
import type { Compute } from '../core/internal/types.js';
import * as PublicKey from '../core/PublicKey.js';
import type * as Types from './Types.js';
/** A WebAuthn-flavored P256 credential. */
export type Credential<serialized extends boolean = false> = {
attestationObject: serialized extends true ? string : ArrayBuffer;
clientDataJSON: serialized extends true ? string : ArrayBuffer;
id: string;
publicKey: serialized extends true ? Hex.Hex : PublicKey.PublicKey;
raw: Types.PublicKeyCredential<serialized>;
};
/** Metadata for a WebAuthn P256 signature. */
export type SignMetadata = Compute<{
authenticatorData: Hex.Hex;
challengeIndex?: number | undefined;
clientDataJSON: string;
typeIndex?: number | undefined;
userVerificationRequired?: boolean | undefined;
}>;
/**
* Serializes a credential into a JSON-serializable
* format.
*
* @example
* ```ts twoslash
* import { Registration, Credential } from 'ox/webauthn'
*
* const credential = await Registration.create({ name: 'Example' })
*
* const serialized = Credential.serialize(credential) // [!code focus]
*
* // `serialized` is JSON-serializable — send it to a server, store it, etc.
* const json = JSON.stringify(serialized)
* ```
*
* @param credential - The credential to serialize.
* @returns The serialized credential.
*/
export declare function serialize(credential: Credential): Credential<true>;
export declare namespace serialize {
type ErrorType = Base64.fromBytes.ErrorType | PublicKey.toHex.ErrorType | Errors.GlobalErrorType;
}
/**
* Deserializes a serialized credential.
*
* @example
* ```ts twoslash
* import { Credential } from 'ox/webauthn'
*
* const credential = Credential.deserialize({ // [!code focus]
* attestationObject: 'o2NmbXRkbm9uZQ...', // [!code focus]
* clientDataJSON: 'eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIn0', // [!code focus]
* id: 'm1-bMPuAqpWhCxHZQZTT6e-lSPntQbh3opIoGe7g4Qs', // [!code focus]
* publicKey: '0x04ab891400140fc4f8e941ce0ff90e419de9470acaca613bbd717a4775435031a7d884318e919fd3b3e5a631d866d8a380b44063e70f0c381ee16e0652f7f97554', // [!code focus]
* raw: { // [!code focus]
* id: 'm1-bMPuAqpWhCxHZQZTT6e-lSPntQbh3opIoGe7g4Qs', // [!code focus]
* type: 'public-key', // [!code focus]
* authenticatorAttachment: 'platform', // [!code focus]
* rawId: 'm1-bMPuAqpWhCxHZQZTT6e-lSPntQbh3opIoGe7g4Qs', // [!code focus]
* response: { // [!code focus]
* clientDataJSON: 'eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIn0', // [!code focus]
* }, // [!code focus]
* }, // [!code focus]
* }) // [!code focus]
* ```
*
* @param credential - The serialized credential.
* @returns The deserialized credential.
*/
export declare function deserialize(credential: Credential<true>): Credential;
export declare namespace deserialize {
type ErrorType = Base64.toBytes.ErrorType | PublicKey.from.ErrorType | Errors.GlobalErrorType;
}
//# sourceMappingURL=Credential.d.ts.map