Skip to content

Commit

Permalink
Merge pull request #146 from savelichalex/types
Browse files Browse the repository at this point in the history
Change TS types to use string literals instead enums, and added missing methods
  • Loading branch information
mCodex authored Apr 24, 2019
2 parents abf6b3e + 0bf9eac commit 2b585e4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 30 deletions.
22 changes: 20 additions & 2 deletions RNSensitiveInfo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
import { NativeModules } from 'react-native';
import { NativeModules } from "react-native";

module.exports = NativeModules.RNSensitiveInfo;
const RNSensitiveInfo = NativeModules.RNSensitiveInfo;

module.exports = {
...RNSensitiveInfo,
setInvalidatedByBiometricEnrollment() {
if (RNSensitiveInfo.setInvalidatedByBiometricEnrollment == null) {
return;
}

return RNSensitiveInfo.setInvalidatedByBiometricEnrollment();
},
cancelFingerprintAuth() {
if (RNSensitiveInfo.cancelFingerprintAuth == null) {
return;
}

return RNSensitiveInfo.cancelFingerprintAuth();
}
};
78 changes: 50 additions & 28 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,65 @@
export enum RNSensitiveInfoBiometryType {
"Touch ID",
"Face ID",
}
type RNSensitiveInfoBiometryType = "Touch ID" | "Face ID";

export enum RNSensitiveInfoAccessControlOptions {
'kSecAccessControlApplicationPassword',
'kSecAccessControlPrivateKeyUsage',
'kSecAccessControlDevicePasscode',
'kSecAccessControlTouchIDAny',
'kSecAccessControlTouchIDCurrentSet',
'kSecAccessControlUserPresence',
'kSecAccessControlBiometryAny',
'kSecAccessControlBiometryCurrentSet',
}
type RNSensitiveInfoAccessControlOptions =
| "kSecAccessControlApplicationPassword"
| "kSecAccessControlPrivateKeyUsage"
| "kSecAccessControlDevicePasscode"
| "kSecAccessControlTouchIDAny"
| "kSecAccessControlTouchIDCurrentSet"
| "kSecAccessControlUserPresence"
| "kSecAccessControlBiometryAny"
| "kSecAccessControlBiometryCurrentSet";

type RNSensitiveInfoAttrAccessibleOptions =
| "kSecAttrAccessibleAfterFirstUnlock"
| "kSecAttrAccessibleAlways"
| "kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly"
| "kSecAttrAccessibleWhenUnlockedThisDeviceOnly"
| "kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly"
| "kSecAttrAccessibleAlwaysThisDeviceOnly"
| "kSecAttrAccessibleWhenUnlocked";

export enum RNSensitiveInfoAttrAccessibleOptions {
'kSecAttrAccessibleAfterFirstUnlock',
'kSecAttrAccessibleAlways',
'kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly',
'kSecAttrAccessibleWhenUnlockedThisDeviceOnly',
'kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly',
'kSecAttrAccessibleAlwaysThisDeviceOnly',
'kSecAttrAccessibleWhenUnlocked',
interface RNSensitiveInfoAndroidDialogStrings {
header?: string;
description?: string;
hint?: string;
success?: string;
notRecognized?: string;
cancel?: string;
cancelled?: string;
}

export interface RNSensitiveInfoOptions {
kSecAccessControl?: RNSensitiveInfoAccessControlOptions;
kSecAttrAccessible?: RNSensitiveInfoAttrAccessibleOptions;
keychainService?: string;
kSecUseOperationPrompt?: string;
sharedPreferencesName?: string;
touchID?: boolean;
showModal?: boolean;
kSecUseOperationPrompt?: string;
strings?: RNSensitiveInfoAndroidDialogStrings;
}

export declare function setItem(key: string, value: string, options: RNSensitiveInfoOptions): Promise<null>;
export declare function getItem(key: string, options: RNSensitiveInfoOptions): Promise<string>;
export declare function getAllItems(options: RNSensitiveInfoOptions): Promise<Object>;
export declare function deleteItem(key: string, options: RNSensitiveInfoOptions): Promise<null>;
export declare function isSensorAvailable(): Promise<RNSensitiveInfoBiometryType | boolean>;
export declare function setItem(
key: string,
value: string,
options: RNSensitiveInfoOptions
): Promise<null>;
export declare function getItem(
key: string,
options: RNSensitiveInfoOptions
): Promise<string>;
export declare function getAllItems(
options: RNSensitiveInfoOptions
): Promise<Object>;
export declare function deleteItem(
key: string,
options: RNSensitiveInfoOptions
): Promise<null>;
export declare function isSensorAvailable(): Promise<
RNSensitiveInfoBiometryType | boolean
>;
export declare function isHardwareDetected(): Promise<boolean>;
export declare function hasEnrolledFingerprints(): Promise<boolean>;
export declare function cancelFingerprintAuth(): void;
export declare function setInvalidatedByBiometricEnrollment(boolean): void;

0 comments on commit 2b585e4

Please sign in to comment.