From ec4993382244b1153df3d92dd14280a252db4bde Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Wed, 20 May 2020 22:58:00 -0700 Subject: Add new types for credentials as JSON --- packages/typescript-types/src/index.ts | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'packages/typescript-types/src') diff --git a/packages/typescript-types/src/index.ts b/packages/typescript-types/src/index.ts index 58cc90c..2d9f8d2 100644 --- a/packages/typescript-types/src/index.ts +++ b/packages/typescript-types/src/index.ts @@ -5,6 +5,36 @@ export type AttestationCredentials = { publicKey: PublicKeyCredentialCreationOptions, }; +/** + * A variant of AttestationCredentials suitable for JSON transmission to the browser + * + * Noteworthy values: + * @param challenge A random string of characters. Will be converted to a Uint8Array in the browser + * @param user.id Your unique, internal ID for the user. Will be converted to a Uint8Array in the + * browser + */ +export type AttestationCredentialsJSON = { + publicKey: { + challenge: string, + // The organization registering and authenticating the user + rp: { + name: string, + id: string, + }, + user: { + id: string, + name: string, + displayName: string, + }, + pubKeyCredParams: [{ + alg: -7, + type: 'public-key', + }], + timeout?: number, + attestation: 'direct' | 'indirect', + }, +}; + /** * An object that can be passed into navigator.credentials.get(...) in the browser */ @@ -12,6 +42,31 @@ export type AssertionCredentials = { publicKey: PublicKeyCredentialRequestOptions, }; +/** + * A variant of AssertionCredentials suitable for JSON transmission to the browser + * + * Noteworthy values: + * @param challenge A random string of characters. Will be converted to a Uint8Array in the browser + * @param allowCredentials.id Base64-encoded credentialId. Will be converted to a Uint8Array in the + * browser + */ +export type AssertionCredentialsJSON = { + publicKey: { + // + challenge: string, + allowCredentials: { + // Will be converted to a Uint8Array in the browser + id: string, + type: 'public-key', + transports?: AuthenticatorTransport[], + }[], + // extensions?: AuthenticationExtensionsClientInputs, + rpId?: string, + timeout?: number, + userVerification?: UserVerificationRequirement, + }, +}; + /** * A slightly-modified AuthenticatorAttestationResponse to simplify working with ArrayBuffers that * are base64-encoded in the browser so that they can be sent as JSON to the server. @@ -33,6 +88,7 @@ AuthenticatorAssertionResponse, 'clientDataJSON' | 'authenticatorData' | 'signat base64AuthenticatorData: string; base64ClientDataJSON: string; base64Signature: string; + base64UserHandle: string; } export enum ATTESTATION_FORMATS { -- cgit v1.2.3