diff --git a/.gitignore b/.gitignore index becf8a8..8bb7ffd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ node_modules/ npm-debug.log yarn-error.log -build/ +# build/ # Xcode # diff --git a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java index 00bf6ad..cb1ec4e 100644 --- a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java +++ b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java @@ -186,7 +186,7 @@ public void run() { } private PromptInfo getPromptInfo(String promptMessage, String cancelButtonText, boolean allowDeviceCredentials) { - PromptInfo.Builder builder = new PromptInfo.Builder().setTitle(promptMessage); + PromptInfo.Builder builder = new PromptInfo.Builder().setTitle(promptMessage).setConfirmationRequired(false); builder.setAllowedAuthenticators(getAllowedAuthenticators(allowDeviceCredentials)); @@ -199,9 +199,9 @@ private PromptInfo getPromptInfo(String promptMessage, String cancelButtonText, private int getAllowedAuthenticators(boolean allowDeviceCredentials) { if (allowDeviceCredentials && !isCurrentSDK29OrEarlier()) { - return BiometricManager.Authenticators.BIOMETRIC_STRONG | BiometricManager.Authenticators.DEVICE_CREDENTIAL; + return BiometricManager.Authenticators.BIOMETRIC_WEAK | BiometricManager.Authenticators.DEVICE_CREDENTIAL; } - return BiometricManager.Authenticators.BIOMETRIC_STRONG; + return BiometricManager.Authenticators.BIOMETRIC_WEAK; } private boolean isCurrentSDK29OrEarlier() { diff --git a/build/cjs/index.d.ts b/build/cjs/index.d.ts new file mode 100644 index 0000000..09146a4 --- /dev/null +++ b/build/cjs/index.d.ts @@ -0,0 +1,154 @@ +/** + * Type alias for possible biometry types + */ +export declare type BiometryType = 'TouchID' | 'FaceID' | 'Biometrics'; +interface RNBiometricsOptions { + allowDeviceCredentials?: boolean; +} +interface IsSensorAvailableResult { + available: boolean; + biometryType?: BiometryType; + error?: string; +} +interface CreateKeysResult { + publicKey: string; +} +interface BiometricKeysExistResult { + keysExist: boolean; +} +interface DeleteKeysResult { + keysDeleted: boolean; +} +interface CreateSignatureOptions { + promptMessage: string; + payload: string; + cancelButtonText?: string; +} +interface CreateSignatureResult { + success: boolean; + signature?: string; + error?: string; +} +interface SimplePromptOptions { + promptMessage: string; + fallbackPromptMessage?: string; + cancelButtonText?: string; +} +interface SimplePromptResult { + success: boolean; + error?: string; +} +/** + * Enum for touch id sensor type + */ +export declare const TouchID = "TouchID"; +/** + * Enum for face id sensor type + */ +export declare const FaceID = "FaceID"; +/** + * Enum for generic biometrics (this is the only value available on android) + */ +export declare const Biometrics = "Biometrics"; +export declare const BiometryTypes: { + TouchID: string; + FaceID: string; + Biometrics: string; +}; +export declare module ReactNativeBiometricsLegacy { + /** + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * @returns {Promise} Promise that resolves to an object with details about biometrics available + */ + function isSensorAvailable(): Promise; + /** + * Creates a public private key pair,returns promise that resolves to + * an object with object.publicKey, which is the public key of the newly generated key pair + * @returns {Promise} Promise that resolves to object with details about the newly generated public key + */ + function createKeys(): Promise; + /** + * Returns promise that resolves to an object with object.keysExists = true | false + * indicating if the keys were found to exist or not + * @returns {Promise} Promise that resolves to object with details aobut the existence of keys + */ + function biometricKeysExist(): Promise; + /** + * Returns promise that resolves to an object with true | false + * indicating if the keys were properly deleted + * @returns {Promise} Promise that resolves to an object with details about the deletion + */ + function deleteKeys(): Promise; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.signature, + * which is cryptographic signature of the payload + * @param {Object} createSignatureOptions + * @param {string} createSignatureOptions.promptMessage + * @param {string} createSignatureOptions.payload + * @returns {Promise} Promise that resolves to an object cryptographic signature details + */ + function createSignature(createSignatureOptions: CreateSignatureOptions): Promise; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.success = true if the user passes, + * object.success = false if the user cancels, and rejects if anything fails + * @param {Object} simplePromptOptions + * @param {string} simplePromptOptions.promptMessage + * @param {string} simplePromptOptions.fallbackPromptMessage + * @returns {Promise} Promise that resolves an object with details about the biometrics result + */ + function simplePrompt(simplePromptOptions: SimplePromptOptions): Promise; +} +export default class ReactNativeBiometrics { + allowDeviceCredentials: boolean; + /** + * @param {Object} rnBiometricsOptions + * @param {boolean} rnBiometricsOptions.allowDeviceCredentials + */ + constructor(rnBiometricsOptions?: RNBiometricsOptions); + /** + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * @returns {Promise} Promise that resolves to an object with details about biometrics available + */ + isSensorAvailable(): Promise; + /** + * Creates a public private key pair,returns promise that resolves to + * an object with object.publicKey, which is the public key of the newly generated key pair + * @returns {Promise} Promise that resolves to object with details about the newly generated public key + */ + createKeys(): Promise; + /** + * Returns promise that resolves to an object with object.keysExists = true | false + * indicating if the keys were found to exist or not + * @returns {Promise} Promise that resolves to object with details aobut the existence of keys + */ + biometricKeysExist(): Promise; + /** + * Returns promise that resolves to an object with true | false + * indicating if the keys were properly deleted + * @returns {Promise} Promise that resolves to an object with details about the deletion + */ + deleteKeys(): Promise; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.signature, + * which is cryptographic signature of the payload + * @param {Object} createSignatureOptions + * @param {string} createSignatureOptions.promptMessage + * @param {string} createSignatureOptions.payload + * @returns {Promise} Promise that resolves to an object cryptographic signature details + */ + createSignature(createSignatureOptions: CreateSignatureOptions): Promise; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.success = true if the user passes, + * object.success = false if the user cancels, and rejects if anything fails + * @param {Object} simplePromptOptions + * @param {string} simplePromptOptions.promptMessage + * @param {string} simplePromptOptions.fallbackPromptMessage + * @returns {Promise} Promise that resolves an object with details about the biometrics result + */ + simplePrompt(simplePromptOptions: SimplePromptOptions): Promise; +} +export {}; diff --git a/build/cjs/index.js b/build/cjs/index.js new file mode 100644 index 0000000..0626d39 --- /dev/null +++ b/build/cjs/index.js @@ -0,0 +1,175 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var react_native_1 = require("react-native"); +var bridge = react_native_1.NativeModules.ReactNativeBiometrics; +/** + * Enum for touch id sensor type + */ +exports.TouchID = 'TouchID'; +/** + * Enum for face id sensor type + */ +exports.FaceID = 'FaceID'; +/** + * Enum for generic biometrics (this is the only value available on android) + */ +exports.Biometrics = 'Biometrics'; +exports.BiometryTypes = { + TouchID: exports.TouchID, + FaceID: exports.FaceID, + Biometrics: exports.Biometrics +}; +var ReactNativeBiometricsLegacy; +(function (ReactNativeBiometricsLegacy) { + /** + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * @returns {Promise} Promise that resolves to an object with details about biometrics available + */ + function isSensorAvailable() { + return new ReactNativeBiometrics().isSensorAvailable(); + } + ReactNativeBiometricsLegacy.isSensorAvailable = isSensorAvailable; + /** + * Creates a public private key pair,returns promise that resolves to + * an object with object.publicKey, which is the public key of the newly generated key pair + * @returns {Promise} Promise that resolves to object with details about the newly generated public key + */ + function createKeys() { + return new ReactNativeBiometrics().createKeys(); + } + ReactNativeBiometricsLegacy.createKeys = createKeys; + /** + * Returns promise that resolves to an object with object.keysExists = true | false + * indicating if the keys were found to exist or not + * @returns {Promise} Promise that resolves to object with details aobut the existence of keys + */ + function biometricKeysExist() { + return new ReactNativeBiometrics().biometricKeysExist(); + } + ReactNativeBiometricsLegacy.biometricKeysExist = biometricKeysExist; + /** + * Returns promise that resolves to an object with true | false + * indicating if the keys were properly deleted + * @returns {Promise} Promise that resolves to an object with details about the deletion + */ + function deleteKeys() { + return new ReactNativeBiometrics().deleteKeys(); + } + ReactNativeBiometricsLegacy.deleteKeys = deleteKeys; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.signature, + * which is cryptographic signature of the payload + * @param {Object} createSignatureOptions + * @param {string} createSignatureOptions.promptMessage + * @param {string} createSignatureOptions.payload + * @returns {Promise} Promise that resolves to an object cryptographic signature details + */ + function createSignature(createSignatureOptions) { + return new ReactNativeBiometrics().createSignature(createSignatureOptions); + } + ReactNativeBiometricsLegacy.createSignature = createSignature; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.success = true if the user passes, + * object.success = false if the user cancels, and rejects if anything fails + * @param {Object} simplePromptOptions + * @param {string} simplePromptOptions.promptMessage + * @param {string} simplePromptOptions.fallbackPromptMessage + * @returns {Promise} Promise that resolves an object with details about the biometrics result + */ + function simplePrompt(simplePromptOptions) { + return new ReactNativeBiometrics().simplePrompt(simplePromptOptions); + } + ReactNativeBiometricsLegacy.simplePrompt = simplePrompt; +})(ReactNativeBiometricsLegacy = exports.ReactNativeBiometricsLegacy || (exports.ReactNativeBiometricsLegacy = {})); +var ReactNativeBiometrics = /** @class */ (function () { + /** + * @param {Object} rnBiometricsOptions + * @param {boolean} rnBiometricsOptions.allowDeviceCredentials + */ + function ReactNativeBiometrics(rnBiometricsOptions) { + var _a, _b; + this.allowDeviceCredentials = false; + var allowDeviceCredentials = (_b = (_a = rnBiometricsOptions) === null || _a === void 0 ? void 0 : _a.allowDeviceCredentials, (_b !== null && _b !== void 0 ? _b : false)); + this.allowDeviceCredentials = allowDeviceCredentials; + } + /** + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * @returns {Promise} Promise that resolves to an object with details about biometrics available + */ + ReactNativeBiometrics.prototype.isSensorAvailable = function () { + return bridge.isSensorAvailable({ + allowDeviceCredentials: this.allowDeviceCredentials + }); + }; + /** + * Creates a public private key pair,returns promise that resolves to + * an object with object.publicKey, which is the public key of the newly generated key pair + * @returns {Promise} Promise that resolves to object with details about the newly generated public key + */ + ReactNativeBiometrics.prototype.createKeys = function () { + return bridge.createKeys({ + allowDeviceCredentials: this.allowDeviceCredentials + }); + }; + /** + * Returns promise that resolves to an object with object.keysExists = true | false + * indicating if the keys were found to exist or not + * @returns {Promise} Promise that resolves to object with details aobut the existence of keys + */ + ReactNativeBiometrics.prototype.biometricKeysExist = function () { + return bridge.biometricKeysExist(); + }; + /** + * Returns promise that resolves to an object with true | false + * indicating if the keys were properly deleted + * @returns {Promise} Promise that resolves to an object with details about the deletion + */ + ReactNativeBiometrics.prototype.deleteKeys = function () { + return bridge.deleteKeys(); + }; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.signature, + * which is cryptographic signature of the payload + * @param {Object} createSignatureOptions + * @param {string} createSignatureOptions.promptMessage + * @param {string} createSignatureOptions.payload + * @returns {Promise} Promise that resolves to an object cryptographic signature details + */ + ReactNativeBiometrics.prototype.createSignature = function (createSignatureOptions) { + var _a; + createSignatureOptions.cancelButtonText = (_a = createSignatureOptions.cancelButtonText, (_a !== null && _a !== void 0 ? _a : 'Cancel')); + return bridge.createSignature(__assign({ allowDeviceCredentials: this.allowDeviceCredentials }, createSignatureOptions)); + }; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.success = true if the user passes, + * object.success = false if the user cancels, and rejects if anything fails + * @param {Object} simplePromptOptions + * @param {string} simplePromptOptions.promptMessage + * @param {string} simplePromptOptions.fallbackPromptMessage + * @returns {Promise} Promise that resolves an object with details about the biometrics result + */ + ReactNativeBiometrics.prototype.simplePrompt = function (simplePromptOptions) { + var _a, _b; + simplePromptOptions.cancelButtonText = (_a = simplePromptOptions.cancelButtonText, (_a !== null && _a !== void 0 ? _a : 'Cancel')); + simplePromptOptions.fallbackPromptMessage = (_b = simplePromptOptions.fallbackPromptMessage, (_b !== null && _b !== void 0 ? _b : 'Use Passcode')); + return bridge.simplePrompt(__assign({ allowDeviceCredentials: this.allowDeviceCredentials }, simplePromptOptions)); + }; + return ReactNativeBiometrics; +}()); +exports.default = ReactNativeBiometrics; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/cjs/index.js.map b/build/cjs/index.js.map new file mode 100644 index 0000000..6df3ec9 --- /dev/null +++ b/build/cjs/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6CAA4C;AAEpC,IAAA,2DAA6B,CAAkB;AAoDvD;;GAEG;AACU,QAAA,OAAO,GAAG,SAAS,CAAA;AAChC;;GAEG;AACU,QAAA,MAAM,GAAG,QAAQ,CAAA;AAC9B;;GAEG;AACU,QAAA,UAAU,GAAG,YAAY,CAAA;AAEzB,QAAA,aAAa,GAAG;IAC3B,OAAO,iBAAA;IACP,MAAM,gBAAA;IACN,UAAU,oBAAA;CACX,CAAA;AAED,IAAc,2BAA2B,CA6DxC;AA7DD,WAAc,2BAA2B;IACvC;;;OAGG;IACH,SAAgB,iBAAiB;QAC/B,OAAO,IAAI,qBAAqB,EAAE,CAAC,iBAAiB,EAAE,CAAA;IACxD,CAAC;IAFe,6CAAiB,oBAEhC,CAAA;IAED;;;;OAIG;IACH,SAAgB,UAAU;QACxB,OAAO,IAAI,qBAAqB,EAAE,CAAC,UAAU,EAAE,CAAA;IACjD,CAAC;IAFe,sCAAU,aAEzB,CAAA;IAED;;;;OAIG;IACH,SAAgB,kBAAkB;QAChC,OAAO,IAAI,qBAAqB,EAAE,CAAC,kBAAkB,EAAE,CAAA;IACzD,CAAC;IAFe,8CAAkB,qBAEjC,CAAA;IAED;;;;OAIG;IACH,SAAgB,UAAU;QACxB,OAAO,IAAI,qBAAqB,EAAE,CAAC,UAAU,EAAE,CAAA;IACjD,CAAC;IAFe,sCAAU,aAEzB,CAAA;IAED;;;;;;;;OAQG;IACH,SAAgB,eAAe,CAAC,sBAA8C;QAC5E,OAAO,IAAI,qBAAqB,EAAE,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAA;IAC5E,CAAC;IAFe,2CAAe,kBAE9B,CAAA;IAED;;;;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mB,CAAC,gBAAgB,uCAAI,QAAQ,EAAA,CAAA;QACvF,mBAAmB,CAAC,qBAAqB,SAAG,mBAAmB,CAAC,qBAAqB,uCAAI,cAAc,EAAA,CAAA;QAEvG,OAAO,MAAM,CAAC,YAAY,YACxB,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,IAChD,mBAAmB,EACtB,CAAA;IACJ,CAAC;IACH,4BAAC;AAAD,CAAC,AAvFH,IAuFG"} \ No newline at end of file diff --git a/build/esm/index.d.ts b/build/esm/index.d.ts new file mode 100644 index 0000000..09146a4 --- /dev/null +++ b/build/esm/index.d.ts @@ -0,0 +1,154 @@ +/** + * Type alias for possible biometry types + */ +export declare type BiometryType = 'TouchID' | 'FaceID' | 'Biometrics'; +interface RNBiometricsOptions { + allowDeviceCredentials?: boolean; +} +interface IsSensorAvailableResult { + available: boolean; + biometryType?: BiometryType; + error?: string; +} +interface CreateKeysResult { + publicKey: string; +} +interface BiometricKeysExistResult { + keysExist: boolean; +} +interface DeleteKeysResult { + keysDeleted: boolean; +} +interface CreateSignatureOptions { + promptMessage: string; + payload: string; + cancelButtonText?: string; +} +interface CreateSignatureResult { + success: boolean; + signature?: string; + error?: string; +} +interface SimplePromptOptions { + promptMessage: string; + fallbackPromptMessage?: string; + cancelButtonText?: string; +} +interface SimplePromptResult { + success: boolean; + error?: string; +} +/** + * Enum for touch id sensor type + */ +export declare const TouchID = "TouchID"; +/** + * Enum for face id sensor type + */ +export declare const FaceID = "FaceID"; +/** + * Enum for generic biometrics (this is the only value available on android) + */ +export declare const Biometrics = "Biometrics"; +export declare const BiometryTypes: { + TouchID: string; + FaceID: string; + Biometrics: string; +}; +export declare module ReactNativeBiometricsLegacy { + /** + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * @returns {Promise} Promise that resolves to an object with details about biometrics available + */ + function isSensorAvailable(): Promise; + /** + * Creates a public private key pair,returns promise that resolves to + * an object with object.publicKey, which is the public key of the newly generated key pair + * @returns {Promise} Promise that resolves to object with details about the newly generated public key + */ + function createKeys(): Promise; + /** + * Returns promise that resolves to an object with object.keysExists = true | false + * indicating if the keys were found to exist or not + * @returns {Promise} Promise that resolves to object with details aobut the existence of keys + */ + function biometricKeysExist(): Promise; + /** + * Returns promise that resolves to an object with true | false + * indicating if the keys were properly deleted + * @returns {Promise} Promise that resolves to an object with details about the deletion + */ + function deleteKeys(): Promise; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.signature, + * which is cryptographic signature of the payload + * @param {Object} createSignatureOptions + * @param {string} createSignatureOptions.promptMessage + * @param {string} createSignatureOptions.payload + * @returns {Promise} Promise that resolves to an object cryptographic signature details + */ + function createSignature(createSignatureOptions: CreateSignatureOptions): Promise; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.success = true if the user passes, + * object.success = false if the user cancels, and rejects if anything fails + * @param {Object} simplePromptOptions + * @param {string} simplePromptOptions.promptMessage + * @param {string} simplePromptOptions.fallbackPromptMessage + * @returns {Promise} Promise that resolves an object with details about the biometrics result + */ + function simplePrompt(simplePromptOptions: SimplePromptOptions): Promise; +} +export default class ReactNativeBiometrics { + allowDeviceCredentials: boolean; + /** + * @param {Object} rnBiometricsOptions + * @param {boolean} rnBiometricsOptions.allowDeviceCredentials + */ + constructor(rnBiometricsOptions?: RNBiometricsOptions); + /** + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * @returns {Promise} Promise that resolves to an object with details about biometrics available + */ + isSensorAvailable(): Promise; + /** + * Creates a public private key pair,returns promise that resolves to + * an object with object.publicKey, which is the public key of the newly generated key pair + * @returns {Promise} Promise that resolves to object with details about the newly generated public key + */ + createKeys(): Promise; + /** + * Returns promise that resolves to an object with object.keysExists = true | false + * indicating if the keys were found to exist or not + * @returns {Promise} Promise that resolves to object with details aobut the existence of keys + */ + biometricKeysExist(): Promise; + /** + * Returns promise that resolves to an object with true | false + * indicating if the keys were properly deleted + * @returns {Promise} Promise that resolves to an object with details about the deletion + */ + deleteKeys(): Promise; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.signature, + * which is cryptographic signature of the payload + * @param {Object} createSignatureOptions + * @param {string} createSignatureOptions.promptMessage + * @param {string} createSignatureOptions.payload + * @returns {Promise} Promise that resolves to an object cryptographic signature details + */ + createSignature(createSignatureOptions: CreateSignatureOptions): Promise; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.success = true if the user passes, + * object.success = false if the user cancels, and rejects if anything fails + * @param {Object} simplePromptOptions + * @param {string} simplePromptOptions.promptMessage + * @param {string} simplePromptOptions.fallbackPromptMessage + * @returns {Promise} Promise that resolves an object with details about the biometrics result + */ + simplePrompt(simplePromptOptions: SimplePromptOptions): Promise; +} +export {}; diff --git a/build/esm/index.js b/build/esm/index.js new file mode 100644 index 0000000..51eb812 --- /dev/null +++ b/build/esm/index.js @@ -0,0 +1,173 @@ +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +import { NativeModules } from 'react-native'; +var bridge = NativeModules.ReactNativeBiometrics; +/** + * Enum for touch id sensor type + */ +export var TouchID = 'TouchID'; +/** + * Enum for face id sensor type + */ +export var FaceID = 'FaceID'; +/** + * Enum for generic biometrics (this is the only value available on android) + */ +export var Biometrics = 'Biometrics'; +export var BiometryTypes = { + TouchID: TouchID, + FaceID: FaceID, + Biometrics: Biometrics +}; +export var ReactNativeBiometricsLegacy; +(function (ReactNativeBiometricsLegacy) { + /** + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * @returns {Promise} Promise that resolves to an object with details about biometrics available + */ + function isSensorAvailable() { + return new ReactNativeBiometrics().isSensorAvailable(); + } + ReactNativeBiometricsLegacy.isSensorAvailable = isSensorAvailable; + /** + * Creates a public private key pair,returns promise that resolves to + * an object with object.publicKey, which is the public key of the newly generated key pair + * @returns {Promise} Promise that resolves to object with details about the newly generated public key + */ + function createKeys() { + return new ReactNativeBiometrics().createKeys(); + } + ReactNativeBiometricsLegacy.createKeys = createKeys; + /** + * Returns promise that resolves to an object with object.keysExists = true | false + * indicating if the keys were found to exist or not + * @returns {Promise} Promise that resolves to object with details aobut the existence of keys + */ + function biometricKeysExist() { + return new ReactNativeBiometrics().biometricKeysExist(); + } + ReactNativeBiometricsLegacy.biometricKeysExist = biometricKeysExist; + /** + * Returns promise that resolves to an object with true | false + * indicating if the keys were properly deleted + * @returns {Promise} Promise that resolves to an object with details about the deletion + */ + function deleteKeys() { + return new ReactNativeBiometrics().deleteKeys(); + } + ReactNativeBiometricsLegacy.deleteKeys = deleteKeys; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.signature, + * which is cryptographic signature of the payload + * @param {Object} createSignatureOptions + * @param {string} createSignatureOptions.promptMessage + * @param {string} createSignatureOptions.payload + * @returns {Promise} Promise that resolves to an object cryptographic signature details + */ + function createSignature(createSignatureOptions) { + return new ReactNativeBiometrics().createSignature(createSignatureOptions); + } + ReactNativeBiometricsLegacy.createSignature = createSignature; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.success = true if the user passes, + * object.success = false if the user cancels, and rejects if anything fails + * @param {Object} simplePromptOptions + * @param {string} simplePromptOptions.promptMessage + * @param {string} simplePromptOptions.fallbackPromptMessage + * @returns {Promise} Promise that resolves an object with details about the biometrics result + */ + function simplePrompt(simplePromptOptions) { + return new ReactNativeBiometrics().simplePrompt(simplePromptOptions); + } + ReactNativeBiometricsLegacy.simplePrompt = simplePrompt; +})(ReactNativeBiometricsLegacy || (ReactNativeBiometricsLegacy = {})); +var ReactNativeBiometrics = /** @class */ (function () { + /** + * @param {Object} rnBiometricsOptions + * @param {boolean} rnBiometricsOptions.allowDeviceCredentials + */ + function ReactNativeBiometrics(rnBiometricsOptions) { + var _a, _b; + this.allowDeviceCredentials = false; + var allowDeviceCredentials = (_b = (_a = rnBiometricsOptions) === null || _a === void 0 ? void 0 : _a.allowDeviceCredentials, (_b !== null && _b !== void 0 ? _b : false)); + this.allowDeviceCredentials = allowDeviceCredentials; + } + /** + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * @returns {Promise} Promise that resolves to an object with details about biometrics available + */ + ReactNativeBiometrics.prototype.isSensorAvailable = function () { + return bridge.isSensorAvailable({ + allowDeviceCredentials: this.allowDeviceCredentials + }); + }; + /** + * Creates a public private key pair,returns promise that resolves to + * an object with object.publicKey, which is the public key of the newly generated key pair + * @returns {Promise} Promise that resolves to object with details about the newly generated public key + */ + ReactNativeBiometrics.prototype.createKeys = function () { + return bridge.createKeys({ + allowDeviceCredentials: this.allowDeviceCredentials + }); + }; + /** + * Returns promise that resolves to an object with object.keysExists = true | false + * indicating if the keys were found to exist or not + * @returns {Promise} Promise that resolves to object with details aobut the existence of keys + */ + ReactNativeBiometrics.prototype.biometricKeysExist = function () { + return bridge.biometricKeysExist(); + }; + /** + * Returns promise that resolves to an object with true | false + * indicating if the keys were properly deleted + * @returns {Promise} Promise that resolves to an object with details about the deletion + */ + ReactNativeBiometrics.prototype.deleteKeys = function () { + return bridge.deleteKeys(); + }; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.signature, + * which is cryptographic signature of the payload + * @param {Object} createSignatureOptions + * @param {string} createSignatureOptions.promptMessage + * @param {string} createSignatureOptions.payload + * @returns {Promise} Promise that resolves to an object cryptographic signature details + */ + ReactNativeBiometrics.prototype.createSignature = function (createSignatureOptions) { + var _a; + createSignatureOptions.cancelButtonText = (_a = createSignatureOptions.cancelButtonText, (_a !== null && _a !== void 0 ? _a : 'Cancel')); + return bridge.createSignature(__assign({ allowDeviceCredentials: this.allowDeviceCredentials }, createSignatureOptions)); + }; + /** + * Prompts user with biometrics dialog using the passed in prompt message and + * returns promise that resolves to an object with object.success = true if the user passes, + * object.success = false if the user cancels, and rejects if anything fails + * @param {Object} simplePromptOptions + * @param {string} simplePromptOptions.promptMessage + * @param {string} simplePromptOptions.fallbackPromptMessage + * @returns {Promise} Promise that resolves an object with details about the biometrics result + */ + ReactNativeBiometrics.prototype.simplePrompt = function (simplePromptOptions) { + var _a, _b; + simplePromptOptions.cancelButtonText = (_a = simplePromptOptions.cancelButtonText, (_a !== null && _a !== void 0 ? _a : 'Cancel')); + simplePromptOptions.fallbackPromptMessage = (_b = simplePromptOptions.fallbackPromptMessage, (_b !== null && _b !== void 0 ? _b : 'Use Passcode')); + return bridge.simplePrompt(__assign({ allowDeviceCredentials: this.allowDeviceCredentials }, simplePromptOptions)); + }; + return ReactNativeBiometrics; +}()); +export default ReactNativeBiometrics; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/esm/index.js.map b/build/esm/index.js.map new file mode 100644 index 0000000..0980bee --- /dev/null +++ b/build/esm/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEpC,IAAA,4CAA6B,CAAkB;AAoDvD;;GAEG;AACH,MAAM,CAAC,IAAM,OAAO,GAAG,SAAS,CAAA;AAChC;;GAEG;AACH,MAAM,CAAC,IAAM,MAAM,GAAG,QAAQ,CAAA;AAC9B;;GAEG;AACH,MAAM,CAAC,IAAM,UAAU,GAAG,YAAY,CAAA;AAEtC,MAAM,CAAC,IAAM,aAAa,GAAG;IAC3B,OAAO,SAAA;IACP,MAAM,QAAA;IACN,UAAU,YAAA;CACX,CAAA;AAED,MAAM,KAAQ,2BAA2B,CA6DxC;AA7DD,WAAc,2BAA2B;IACvC;;;OAGG;IACH,SAAgB,iBAAiB;QAC/B,OAAO,IAAI,qBAAqB,EAAE,CAAC,iBAAiB,EAAE,CAAA;IACxD,CAAC;IAFe,6CA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