Files
inji-wallet/shared/commonUtil.ts
Swati Goel 142228b0db INJI-473) Code clean up and fixing metro errors/warnings (#947)
* feat(INJI-473) - Removed unused injiTourGuide action.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - Removed unused logKey action.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - Removed unused backendInfo api and state.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - simplify isPasscodeSet logic.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - Move logState to commonUtil to remove cyclic dependency.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - Delete unused code.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - Refactor code to use util function for iOS or isAndroid.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - Move Issuers_Key_Ref into utils.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - Remove profile related resource from setting screen

Signed-off-by: Swati Goel <meet2swati@gmail.com>

* feat(INJI-473) - Remove unused code for locales.

Signed-off-by: Swati Goel <meet2swati@gmail.com>

---------

Signed-off-by: Swati Goel <meet2swati@gmail.com>
2023-10-20 12:50:39 +05:30

55 lines
1.3 KiB
TypeScript

import {Platform} from 'react-native';
import argon2 from 'react-native-argon2';
import {AnyState} from 'xstate';
import {getDeviceNameSync} from 'react-native-device-info';
import {isAndroid} from './constants';
export const hashData = async (
data: string,
salt: string,
config: Argon2iConfig,
): Promise<string> => {
const result = await argon2(data, salt, config);
return result.rawHash as string;
};
export interface Argon2iConfig {
iterations: number;
memory: number;
parallelism: number;
hashLength: number;
mode: string;
}
export default function testIDProps(id) {
return isAndroid()
? {accessible: true, accessibilityLabel: id}
: {testID: id};
}
export const removeWhiteSpace = (str: string) => {
return str ? str.replace(/\s/g, '') : str;
};
export function logState(state: AnyState) {
const data = JSON.stringify(
state.event,
(key, value) => {
if (key === 'type') return undefined;
if (typeof value === 'string' && value.length >= 100) {
return value.slice(0, 100) + '...';
}
return value;
},
2,
);
console.log(
`[${getDeviceNameSync()}] ${state.machine.id}: ${
state.event.type
} -> ${state.toStrings().pop()}\n${
data.length > 300 ? data.slice(0, 300) + '...' : data
}
`,
);
}