Skip to content

Commit

Permalink
added types
Browse files Browse the repository at this point in the history
  • Loading branch information
dagnelies committed Nov 14, 2022
1 parent d6f34d0 commit 49b2d7b
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/.vscode
/dist/esm
4 changes: 4 additions & 0 deletions dist/types/authenticators.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare function parseAuthBuffer(authData: ArrayBuffer): any;
export declare function extractAaguid(authData: ArrayBuffer): string;
export declare function resolveAuthenticatorName(aaguid: string): string;
export declare function updateDevicesMetadata(): Promise<void>;
4 changes: 4 additions & 0 deletions dist/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './types';
export * from './webauthn';
export * from './parsers';
export * from './validation';
4 changes: 4 additions & 0 deletions dist/types/parsers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { AuthenticatorInfo, ClientInfo } from './types';
export declare function parseClient(data: string | ArrayBuffer): ClientInfo;
export declare function parseAuthenticator(data: string | ArrayBuffer): AuthenticatorInfo;
export declare function parseAttestation(data: string | ArrayBuffer): unknown;
55 changes: 55 additions & 0 deletions dist/types/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export declare type AuthType = 'auto' | 'local' | 'extern' | 'both';
export declare type NumAlgo = -7 | -257;
export declare type NamedAlgo = 'RS256' | 'ES256';
export interface LoginOptions {
userVerification?: UserVerificationRequirement;
authenticatorType?: AuthType;
timeout?: number;
debug?: boolean;
}
export interface LoginResult {
credentialId: string;
authenticatorData: string;
clientData: string;
signature: string;
debug?: object;
}
export interface RegisterOptions extends LoginOptions {
attestation?: boolean;
}
export interface RegisterResult {
username: string;
credential: {
id: string;
publicKey: string;
algorithm: 'RS256' | 'ES256';
};
authenticatorData: string;
clientData: string;
attestationData?: string;
debug?: object;
}
export interface ClientInfo {
type: "webauthn.create" | "webauthn.get";
challenge: string;
origin: string;
crossOrigin: boolean;
tokenBindingId?: {
id: string;
status: string;
};
}
export interface AuthenticatorInfo {
rpIdHash: string;
flags: {
userPresent: boolean;
userVerified: boolean;
backupEligibility: boolean;
backupState: boolean;
attestedData: boolean;
extensionsIncluded: boolean;
};
counter: number;
aaguid: string;
name: string;
}
11 changes: 11 additions & 0 deletions dist/types/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/********************************
Encoding/Decoding Utils
********************************/
export declare function toBuffer(txt: string): ArrayBuffer;
export declare function parseBuffer(buffer: ArrayBuffer): string;
export declare function isBase64url(txt: string): boolean;
export declare function toBase64url(buffer: ArrayBuffer): string;
export declare function parseBase64url(txt: string): ArrayBuffer;
export declare function sha256(buffer: ArrayBuffer): Promise<ArrayBuffer>;
export declare function bufferToHex(buffer: ArrayBuffer): string;
export declare function concatenateBuffers(buffer1: ArrayBuffer, buffer2: ArrayBuffer): Uint8Array;
10 changes: 10 additions & 0 deletions dist/types/validation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NamedAlgo } from './types';
declare type VerifyParams = {
algorithm: NamedAlgo;
publicKey: string;
authenticatorData: string;
clientData: string;
signature: string;
};
export declare function verify({ algorithm, publicKey, authenticatorData, clientData, signature }: VerifyParams): Promise<boolean>;
export {};
36 changes: 36 additions & 0 deletions dist/types/webauthn.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { LoginOptions, LoginResult, RegisterOptions, RegisterResult } from './types';
/**
* Returns whether passwordless authentication is available on this browser/platform or not.
*/
export declare function isAvailable(): boolean;
/**
* Returns whether the device itself can be used as authenticator.
*/
export declare function isLocalAuthenticator(): Promise<boolean>;
/**
* Creates a cryptographic key pair, in order to register the public key for later passwordless authentication.
*
* @param {string} username
* @param {string} challenge A server-side randomly generated string.
* @param {Object} [options] Optional parameters.
* @param {number} [options.timeout=60000] Number of milliseconds the user has to respond to the biometric/PIN check.
* @param {'required'|'preferred'|'discouraged'} [options.userVerification='required'] Whether to prompt for biometric/PIN check or not.
* @param {'auto'|'local'|'extern'|'both'} [options.authenticatorType='auto'] Which device to use as authenticator.
* 'auto': if the local device can be used as authenticator it will be preferred. Otherwise it will prompt for an external device.
* 'local': use the local device (using TouchID, FaceID, Windows Hello or PIN)
* 'extern': use an external device (security key or connected phone)
* 'both': prompt the user to choose between local or external device. The UI and user interaction in this case is platform specific.
* @param {boolean} [attestation=false] If enabled, the device attestation and clientData will be provided as Base64url encoded binary data.
* Note that this is not available on some platforms.
*/
export declare function register(username: string, challenge: string, options?: RegisterOptions): Promise<RegisterResult>;
/**
* Signs a challenge using one of the provided credentials IDs in order to authenticate the user.
*
* @param {string[]} credentialIds The list of credential IDs that can be used for signing.
* @param {string} challenge A server-side randomly generated string, the base64 encoded version will be signed.
* @param {Object} [options] Optional parameters.
* @param {number} [options.timeout=60000] Number of milliseconds the user has to respond to the biometric/PIN check.
* @param {'required'|'preferred'|'discouraged'} [options.userVerification='required'] Whether to prompt for biometric/PIN check or not.
*/
export declare function login(credentialIds: string[], challenge: string, options?: LoginOptions): Promise<LoginResult>;
2 changes: 1 addition & 1 deletion dist/webauthn.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/webauthn.min.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"name": "@passwordless-id/webauthn",
"version": "0.0.11",
"version": "0.0.12",
"description": "A small wrapper around the webauthn protocol to make one's life easier.",

"type": "module",
"main": "dist/webauthn.min.js",
"types": "dist/types/index.d.ts",

"scripts": {
"build": "esbuild src/index.ts --platform=neutral --bundle --sourcemap --minify --target=es2022 --outfile=dist/webauthn.min.js",
"build": "tsc && esbuild src/index.ts --platform=neutral --bundle --sourcemap --minify --target=es2022 --outfile=dist/webauthn.min.js",
"dev": "http-server"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/authenticators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import authenticatorMetadata from './authenticatorMetadata.json'
import authenticatorMetadata from './authenticatorMetadata.json' assert {type: 'json'}
import * as utils from './utils'


Expand Down
8 changes: 7 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"compilerOptions": {
"target": "es2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"module": "esnext",
"strict": true, /* Enable all strict type-checking options. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */

"moduleResolution": "node",
"resolveJsonModule": true,

"outDir": "dist/esm",
"declaration": true,
"declarationDir": "dist/types"
}
}

0 comments on commit 49b2d7b

Please sign in to comment.