@abstraxn/passkey-manager
Version:
@abstraxn/passkey-manager is an npm package that provides a set of utilities and classes for creating and managing WebAuthn passkeys, extracting signatures, and handling local storage formats. The package is designed with an object-oriented approach, maki
69 lines (68 loc) • 2.78 kB
TypeScript
type PasskeyCredential = {
id: 'string';
rawId: ArrayBuffer;
response: {
clientDataJSON: ArrayBuffer;
attestationObject: ArrayBuffer;
getPublicKey(): ArrayBuffer;
};
type: 'public-key';
};
type PasskeyCredentialWithPubkeyCoordinates = PasskeyCredential & {
pubkeyCoordinates: {
x: bigint;
y: bigint;
};
};
/**
* Creates a passkey for signing.
*
* @returns A promise that resolves to a PasskeyCredentialWithPubkeyCoordinates object, which includes the passkey credential information and its public key coordinates.
* @throws Throws an error if the passkey generation fails or if the credential received is null.
*/
declare function createPasskey(username: string): Promise<PasskeyCredentialWithPubkeyCoordinates>;
declare function getPassKey(challenge?: any): Promise<any>;
export type PasskeyLocalStorageFormat = {
rawId: string;
pubkeyCoordinates: {
x: bigint;
y: bigint;
};
};
export type UsernameLocalStorageFormat = {
username: string;
};
/**
* Converts a PasskeyCredentialWithPubkeyCoordinates object to a format that can be stored in the local storage.
* The rawId is required for signing and pubkey coordinates are for our convenience.
* @param passkey - The passkey to be converted.
* @returns The passkey in a format that can be stored in the local storage.
*/
declare function toLocalStorageFormat(passkey: PasskeyCredentialWithPubkeyCoordinates): PasskeyLocalStorageFormat;
declare function toLocalStorageFormatUsername(username: string): UsernameLocalStorageFormat;
/**
* Checks if the provided value is in the format of a Local Storage Passkey.
* @param x The value to check.
* @returns A boolean indicating whether the value is in the format of a Local Storage Passkey.
*/
declare function isLocalStoragePasskey(x: unknown): x is PasskeyLocalStorageFormat;
/**
* Extracts the signature into R and S values from the authenticator response.
*
* See:
* - <https://datatracker.ietf.org/doc/html/rfc3279#section-2.2.3>
* - <https://en.wikipedia.org/wiki/X.690#BER_encoding>
*/
declare function extractSignature(signature: ArrayBuffer | Uint8Array): [bigint, bigint];
/**
* Compute the additional client data JSON fields. This is the fields other than `type` and
* `challenge` (including `origin` and any other additional client data fields that may be
* added by the authenticator).
*
* See <https://w3c.github.io/webauthn/#clientdatajson-serialization>
*/
declare function extractClientDataFields(response: AuthenticatorAssertionResponse): {
field: any;
clientDataJSON: string;
};
export { createPasskey, getPassKey, toLocalStorageFormat, toLocalStorageFormatUsername, isLocalStoragePasskey, extractSignature, extractClientDataFields, };