Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AITU-24905 Add isBiometryAvailable, check UserBiometry methods #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@btsd/aitu-bridge",
"version": "0.3.55",
"version": "0.3.56",
"description": "",
"source": "src/index.ts",
"main": "dist/index.js",
Expand Down
66 changes: 63 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,27 @@ export interface UserStepInfoResponse {
steps: UserStepsPerDay[];
}

export class PermissionDeniedError extends Error {
export class BiometryFailedError extends Error {
constructor() {
super("No permission");
super("Biometry failed");
}
}

export class BiometryCanceledError extends Error {
constructor() {
super("Biometry cancelled");
}
}

export class BiometryUnavailableError extends Error {
constructor() {
super("Biometry is unavailable");
}
}

export class BiometryOtherError extends Error {
constructor() {
super("Biometry error");
}
}

Expand Down Expand Up @@ -173,13 +191,19 @@ export interface AituBridge {
setCustomBackArrowVisible: (visible: boolean) => Promise<ResponseType>;
openPayment: (transactionId: string) => Promise<ResponseType>;
setCustomBackArrowOnClickHandler: (handler: BackArrowClickHandlerType) => void;
/**
* @deprecated, use checkUserBiometry method
*/
checkBiometry: () => Promise<ResponseType>;
openExternalUrl: (url: string) => Promise<ResponseType>;
enableSwipeBack: () => Promise<ResponseType>;
disableSwipeBack: () => Promise<ResponseType>;
setNavigationItemMode: (mode: NavigationItemMode) => Promise<void>;
getNavigationItemMode: () => Promise<NavigationItemMode>;
getUserStepInfo: () => Promise<UserStepInfoResponse>;

isBiometryAvailable: () => Promise<boolean>;
checkUserBiometry: () => Promise<void>;
}

const invokeMethod = 'invoke';
Expand Down Expand Up @@ -213,7 +237,9 @@ const enableSwipeBackMethod = 'enableSwipeBack';
const disableSwipeBackMethod = 'disableSwipeBack';
const setNavigationItemModeMethod = 'setNavigationItemMode';
const getNavigationItemModeMethod = 'getNavigationItemMode';
const getUserStepInfoMethod = 'getUserStepInfo'
const getUserStepInfoMethod = 'getUserStepInfo';
const isBiometryAvailableMethod = 'isBiometryAvailable';
const checkUserBiometryMethod = 'checkUserBiometry';

const android = typeof window !== 'undefined' && (window as any).AndroidBridge;
const ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;
Expand Down Expand Up @@ -757,6 +783,36 @@ const buildBridge = (): AituBridge => {
}
}

const isBiometryAvailable = (reqId) => {
const isAndroid = android && android[isBiometryAvailableMethod];
const isIos = ios && ios[isBiometryAvailableMethod];

if (isAndroid) {
android[isBiometryAvailableMethod](reqId);
} else if (isIos) {
ios[isBiometryAvailableMethod].postMessage({ reqId });
} else if (web) {
web.execute(isBiometryAvailableMethod, reqId);
} else if (typeof window !== 'undefined') {
console.log('--isBiometryAvailable-isUnknown');
}
}

const checkUserBiometry = (reqId) => {
const isAndroid = android && android[checkUserBiometryMethod];
const isIos = ios && ios[checkUserBiometryMethod];

if (isAndroid) {
android[checkUserBiometryMethod](reqId);
} else if (isIos) {
ios[checkUserBiometryMethod].postMessage({ reqId });
} else if (web) {
web.execute(checkUserBiometryMethod, reqId);
} else if (typeof window !== 'undefined') {
console.log('--checkUserBiometry-isUnknown');
}
}


const invokePromise = promisifyInvoke(invoke, sub);
const storagePromise = promisifyStorage(storage, sub);
Expand Down Expand Up @@ -786,6 +842,8 @@ const buildBridge = (): AituBridge => {
const setNavigationItemModePromise = promisifyMethod(setNavigationItemMode, setNavigationItemModeMethod, sub);
const getNavigationItemModePromise = promisifyMethod(getNavigationItemMode, getNavigationItemModeMethod, sub);
const getUserStepInfoPromise = promisifyMethod(getUserStepInfo, getUserStepInfoMethod, sub);
const isBiometryAvailablePromise = promisifyMethod(isBiometryAvailable, isBiometryAvailableMethod, sub);
const checkUserBiometryPromise = promisifyMethod(checkUserBiometry, checkUserBiometryMethod, sub);

return {
version: String(LIB_VERSION),
Expand Down Expand Up @@ -835,6 +893,8 @@ const buildBridge = (): AituBridge => {
setNavigationItemMode: setNavigationItemModePromise,
getNavigationItemMode: getNavigationItemModePromise,
getUserStepInfo: getUserStepInfoPromise,
isBiometryAvailable: isBiometryAvailablePromise,
checkUserBiometry: checkUserBiometryPromise,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const LIB_VERSION = "0.3.55";
export const LIB_VERSION = "0.3.56";