UNPKG

@nevis-security/nevis-mobile-authentication-sdk-react

Version:

React Native plugin for Nevis Mobile Authentication SDK. Supports only mobile.

140 lines (125 loc) 5.13 kB
/** * Copyright © 2025 Nevis Security AG. All rights reserved. */ enum FidoUafAttestationInformationType { OnlySurrogateBasicSupported, OnlyDefaultMode, StrictMode, } /** * The object that can be used to know whether the device supports {@link https://docs.nevis.net/configurationguide/mobile-auth-concept-and-integration-guide/use-cases-and-best-practices/uaf-surrogate-full-basic-comparison | Full Basic Attestations}. * * If full basic is required by the backend during registration, and this device does not support it, * registration will fail. This information can be used to preemptively inform the user that the device * is not supported. * * Note that it is guaranteed that the only type of instances that the {@link AndroidDeviceCapabilities.fidoUafAttestationInformationGetter} * returns are either {@link OnlySurrogateBasicSupported}, {@link OnlyDefaultMode} or {@link StrictMode}. * * @see {@link MobileAuthenticationClient.deviceCapabilities}, {@link AndroidDeviceCapabilities.fidoUafAttestationInformationGetter}, {@link FidoUafAttestationInformationGetter} */ export abstract class FidoUafAttestationInformation { /** * Alternate constructor that creates a {@link FidoUafAttestationInformation} from a json. * * @param json contains the source for instance creation. * @returns a {@link FidoUafAttestationInformation} instance. */ static fromJson(json: any): FidoUafAttestationInformation { const subtype = FidoUafAttestationInformationType[ json.type as keyof typeof FidoUafAttestationInformationType ]; switch (subtype) { case FidoUafAttestationInformationType.OnlySurrogateBasicSupported: return OnlySurrogateBasicSupported.fromJson(json.data); case FidoUafAttestationInformationType.OnlyDefaultMode: return OnlyDefaultMode.fromJson(json.data); case FidoUafAttestationInformationType.StrictMode: return StrictMode.create(); default: throw new Error(`Unknown FIDO UAF attestation information (${json.type}).`); } } } /** * Only the surrogate basic attestation is supported. So, neither the default nor the strict mode of * full basic attestation are supported (see the {@link https://docs.nevis.net/configurationguide/patterns-reference#basic-full-attestation | nevisFIDO documentation} * for details regarding the different modes). */ export abstract class OnlySurrogateBasicSupported extends FidoUafAttestationInformation { /** * The error that occurred while checking if the full basic attestation is supported. * * Its message provides information about why the device does not support full basic attestation. */ abstract cause?: string; /** * Alternate constructor that creates an {@link OnlySurrogateBasicSupported} from a json. * * @param json contains the source for instance creation. * @returns the created {@link OnlySurrogateBasicSupported} instance. */ static fromJson(json: any): OnlySurrogateBasicSupported { return OnlySurrogateBasicSupportedImpl.fromJson(json); } } export class OnlySurrogateBasicSupportedImpl extends OnlySurrogateBasicSupported { cause: string | undefined; constructor(cause: string | undefined) { super(); this.cause = cause; } static fromJson(json: any): OnlySurrogateBasicSupportedImpl { return new OnlySurrogateBasicSupportedImpl(json.cause); } } /** * The device supports the default full basic attestation mode as described in the {@link https://docs.nevis.net/configurationguide/patterns-reference#basic-full-attestation | nevisFIDO documentation}. * However, it supports surrogate basic attestation, but it does not support the strict mode. */ export abstract class OnlyDefaultMode extends FidoUafAttestationInformation { /** * The error that occurred while checking if the strict mode of the full basic attestation is * supported. * * Its message provides information about why the device does not support the full basic attestation * strict mode. */ abstract cause?: string; /** * Alternate constructor that creates an {@link OnlyDefaultMode} from a json. * * @param json contains the source for instance creation. * @returns the created {@link OnlyDefaultMode} instance. */ static fromJson(json: any): OnlyDefaultMode { return OnlyDefaultModeImpl.fromJson(json); } } export class OnlyDefaultModeImpl extends OnlyDefaultMode { cause: string | undefined; constructor(cause: string | undefined) { super(); this.cause = cause; } static fromJson(json: any): OnlyDefaultModeImpl { return new OnlyDefaultModeImpl(json.cause); } } /** * The device supports both the strict and the default full basic attestation mode as described in * the {@link https://docs.nevis.net/configurationguide/patterns-reference#basic-full-attestation | nevisFIDO documentation}. * It also supports surrogate basic. */ export abstract class StrictMode extends FidoUafAttestationInformation { /** * Default constructor for {@link StrictMode}. * * @returns the created {@link StrictMode} instance. */ static create(): StrictMode { return new StrictModeImpl(); } } export class StrictModeImpl extends StrictMode {}