import { NativeModules, Platform } from 'react-native'; const LINKING_ERROR = `The package 'react-native-device-binding' doesn't seem to be linked. Make sure:\n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const DeviceBindingNative = NativeModules.DeviceBinding ? NativeModules.DeviceBinding : new Proxy( {}, { get() { throw new Error(LINKING_ERROR); }, } ); export interface KeyPair { publicKey: string; keyAttestation: string; } export interface DeviceBindingModule { generateKeyPair(alias: string): Promise; getPublicKey(alias: string): Promise; signChallenge(alias: string, challenge: string): Promise; deleteKeyPair(alias: string): Promise; hasKeyPair(alias: string): Promise; isStrongBoxAvailable(): Promise; getDeviceId(): Promise; resetDeviceId(): Promise; } const DeviceBinding: DeviceBindingModule = { generateKeyPair(alias: string): Promise { return DeviceBindingNative.generateKeyPair(alias); }, getPublicKey(alias: string): Promise { return DeviceBindingNative.getPublicKey(alias); }, signChallenge(alias: string, challenge: string): Promise { return DeviceBindingNative.signChallenge(alias, challenge); }, deleteKeyPair(alias: string): Promise { return DeviceBindingNative.deleteKeyPair(alias); }, hasKeyPair(alias: string): Promise { return DeviceBindingNative.hasKeyPair(alias); }, isStrongBoxAvailable(): Promise { return DeviceBindingNative.isStrongBoxAvailable(); }, getDeviceId(): Promise { return DeviceBindingNative.getDeviceId(); }, resetDeviceId(): Promise { return DeviceBindingNative.resetDeviceId(); }, }; export default DeviceBinding;