From c707d9c02bab395141fb053bdcd7f26460cc7366 Mon Sep 17 00:00:00 2001 From: Jonathan Stewmon Date: Wed, 4 Nov 2020 08:45:40 -0600 Subject: chore: remove dom lib reference from server package The dom lib is incompatible with node, which can result in inaccurate type checking. Packages which reference types provided by a lib require package consumers to either include the lib or use skipLibCheck which disables all type declaration checks. So instead of referencing the dom lib, define the types needed by the server package locally and import them where needed. --- packages/typescript-types/src/dom.ts | 126 +++++++++++++++++++++++++++++++++ packages/typescript-types/src/index.ts | 15 ++++ 2 files changed, 141 insertions(+) create mode 100644 packages/typescript-types/src/dom.ts (limited to 'packages/typescript-types/src') diff --git a/packages/typescript-types/src/dom.ts b/packages/typescript-types/src/dom.ts new file mode 100644 index 0000000..8369427 --- /dev/null +++ b/packages/typescript-types/src/dom.ts @@ -0,0 +1,126 @@ +export interface txAuthGenericArg { + content: ArrayBuffer; + contentType: string; +} + +export interface AuthenticationExtensionsClientInputs { + appid?: string; + authnSel?: AuthenticatorSelectionList; + exts?: boolean; + loc?: boolean; + txAuthGeneric?: txAuthGenericArg; + txAuthSimple?: string; + uvi?: boolean; + uvm?: boolean; +} + +export interface AuthenticationExtensionsClientOutputs { + appid?: boolean; + authnSel?: boolean; + exts?: AuthenticationExtensionsSupported; + loc?: Coordinates; + txAuthGeneric?: ArrayBuffer; + txAuthSimple?: string; + uvi?: ArrayBuffer; + uvm?: UvmEntries; +} + +export interface AuthenticatorAssertionResponse extends AuthenticatorResponse { + readonly authenticatorData: ArrayBuffer; + readonly signature: ArrayBuffer; + readonly userHandle: ArrayBuffer | null; +} + +export interface AuthenticatorAttestationResponse extends AuthenticatorResponse { + readonly attestationObject: ArrayBuffer; +} + +export interface AuthenticatorResponse { + readonly clientDataJSON: ArrayBuffer; +} + +export interface AuthenticatorSelectionCriteria { + authenticatorAttachment?: AuthenticatorAttachment; + requireResidentKey?: boolean; + userVerification?: UserVerificationRequirement; +} + +export interface Coordinates { + readonly accuracy: number; + readonly altitude: number | null; + readonly altitudeAccuracy: number | null; + readonly heading: number | null; + readonly latitude: number; + readonly longitude: number; + readonly speed: number | null; +} + +export interface Credential { + readonly id: string; + readonly type: string; +} + +export interface PublicKeyCredential extends Credential { + readonly rawId: ArrayBuffer; + readonly response: AuthenticatorResponse; + getClientExtensionResults(): AuthenticationExtensionsClientOutputs; +} + +export interface PublicKeyCredentialCreationOptions { + attestation?: AttestationConveyancePreference; + authenticatorSelection?: AuthenticatorSelectionCriteria; + challenge: BufferSource; + excludeCredentials?: PublicKeyCredentialDescriptor[]; + extensions?: AuthenticationExtensionsClientInputs; + pubKeyCredParams: PublicKeyCredentialParameters[]; + rp: PublicKeyCredentialRpEntity; + timeout?: number; + user: PublicKeyCredentialUserEntity; +} + +export interface PublicKeyCredentialDescriptor { + id: BufferSource; + transports?: AuthenticatorTransport[]; + type: PublicKeyCredentialType; +} + +export interface PublicKeyCredentialEntity { + icon?: string; + name: string; +} + +export interface PublicKeyCredentialParameters { + alg: COSEAlgorithmIdentifier; + type: PublicKeyCredentialType; +} + +export interface PublicKeyCredentialRequestOptions { + allowCredentials?: PublicKeyCredentialDescriptor[]; + challenge: BufferSource; + extensions?: AuthenticationExtensionsClientInputs; + rpId?: string; + timeout?: number; + userVerification?: UserVerificationRequirement; +} + +export interface PublicKeyCredentialRpEntity extends PublicKeyCredentialEntity { + id?: string; +} + +export interface PublicKeyCredentialUserEntity extends PublicKeyCredentialEntity { + displayName: string; + id: BufferSource; +} + +export type AAGUID = BufferSource; +export type AttestationConveyancePreference = 'direct' | 'indirect' | 'none'; +export type AuthenticationExtensionsSupported = string[]; +export type AuthenticatorAttachment = 'cross-platform' | 'platform'; +export type AuthenticatorSelectionList = AAGUID[]; +export type AuthenticatorTransport = 'ble' | 'internal' | 'nfc' | 'usb'; +export type BufferSource = ArrayBuffer | ArrayBufferView; +export type COSEAlgorithmIdentifier = number; +export type PublicKeyCredentialType = 'public-key'; +export type UserVerificationRequirement = 'discouraged' | 'preferred' | 'required'; +export type UvmEntry = number[]; +export type UvmEntries = UvmEntry[]; diff --git a/packages/typescript-types/src/index.ts b/packages/typescript-types/src/index.ts index 4f238d7..954615b 100644 --- a/packages/typescript-types/src/index.ts +++ b/packages/typescript-types/src/index.ts @@ -2,6 +2,21 @@ * @packageDocumentation * @module @simplewebauthn/typescript-types */ + +import type { + AuthenticatorAssertionResponse, + AuthenticatorAttestationResponse, + AuthenticatorTransport, + COSEAlgorithmIdentifier, + PublicKeyCredential, + PublicKeyCredentialCreationOptions, + PublicKeyCredentialDescriptor, + PublicKeyCredentialRequestOptions, + PublicKeyCredentialUserEntity, +} from './dom'; + +export * from './dom'; + /** * A variant of PublicKeyCredentialCreationOptions suitable for JSON transmission to the browser to * (eventually) get passed into navigator.credentials.create(...) in the browser. -- cgit v1.2.3