Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const genQrData = () => async (dispatch: dispatch) => {
try {
var ipAddress = await api.ip();
try {
const b64Ip = Buffer.from(
ipAddress.split('.').map((octet) => parseInt(octet, 10)),
)
.toString('base64')
.substring(0, 6);
const aesKey = randomBytes(16).toString('base64');
const uuid = b64ToUrlSafeB64(randomBytes(9).toString('base64'));
const qrString = `${aesKey}${uuid}${b64Ip}`;
const user = '1';
const dataObj = { aesKey, uuid, ipAddress, user, qrString };
dispatch(setConnectQrData(dataObj));
} catch (e) {
Alert.alert(e.message || 'Error', e.stack);
}
} catch (e) {
Alert.alert(`Bad ip address (${ipAddress || ''}) from server ${api.baseUrl}`, e.stack);
}
};
async getPrivateLink() {
if (Platform.OS === 'ios') {
await PushNotificationIOS.requestPermissions()
}
const stored_link_id = await loadData(WALLET_LINK)
if (stored_link_id)
{
const links = await this.doFetch(this.API_WALLET_GET_LINKS + this.getWalletToken(), "GET")
for (const link of links) {
if (stored_link_id == link.link_id)
{
return randomBytes(4).toString('hex') + stored_link_id
}
}
}
const priv_key = randomBytes(32)
const current_rpc = localfy(this.providerUrl)
const current_accounts = [this.state.ethAddress]
const pub_key = this.getPublicKey(priv_key)
const priv_data = this.getPrivData(pub_key)
const {code, link_id} = await this.doFetch(this.API_WALLET_LINKER_PRELINK + this.getWalletToken(),
'POST', {
pub_key,
current_rpc,
current_accounts,
priv_data
})
if (Platform.OS === 'ios') {
await PushNotificationIOS.requestPermissions()
}
const stored_link_id = await loadData(WALLET_LINK)
if (stored_link_id)
{
const links = await this.doFetch(this.API_WALLET_GET_LINKS + this.getWalletToken(), "GET")
for (const link of links) {
if (stored_link_id == link.link_id)
{
return randomBytes(4).toString('hex') + stored_link_id
}
}
}
const priv_key = randomBytes(32)
const current_rpc = localfy(this.providerUrl)
const current_accounts = [this.state.ethAddress]
const pub_key = this.getPublicKey(priv_key)
const priv_data = this.getPrivData(pub_key)
const {code, link_id} = await this.doFetch(this.API_WALLET_LINKER_PRELINK + this.getWalletToken(),
'POST', {
pub_key,
current_rpc,
current_accounts,
priv_data
})
await storeData(WALLET_LINK, link_id)
return `${link_id}-${code}-${priv_key.toString('hex')}`
}
getRandomKeyFromKeychain = async (pinCode, iv) => {
const credentials = await Keychain.getGenericPassword()
if (!(credentials && credentials.username)) {
const randomStr = randomBytes(16).toString('hex').slice(0, 16)
const randomStrEncrypted = encryptString(randomStr, pinCode, iv, 'aes-256-cbc')
Keychain.setGenericPassword(KeyLocal.IV_CODE, randomStrEncrypted)
return randomStrEncrypted
}
let randomKey = credentials.password
if (randomKey.length === 16) {
randomKey = encryptString(randomKey, pinCode, iv, 'aes-256-cbc')
Keychain.setGenericPassword(KeyLocal.IV_CODE, randomKey)
}
return randomKey
}
onItemPress(sectionID) {
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ9';
randomBytes(5, (error, bytes) => {
if (!error) {
let i = 0;
let seed = this.props.iota.seed;
Object.keys(bytes).map((key, index) => {
if (bytes[key] < 243 && i < 1) {
const randomNumber = bytes[key] % 27;
const randomLetter = charset.charAt(randomNumber);
const substr1 = seed.substr(0, sectionID);
sectionID++;
const substr2 = seed.substr(sectionID, 80);
seed = substr1 + randomLetter + substr2;
i++;
}
});
this.props.setSeed(seed);
} else {
export function* setPincode({ pincodeType, pin }: SetPincodeAction) {
try {
if (pincodeType === PincodeType.PhoneAuth) {
Logger.debug(TAG + '@setPincode', 'Setting pincode with using system auth')
pin = randomBytes(10).toString('hex')
yield call(setPinInKeystore, pin)
} else if (pincodeType === PincodeType.CustomPin && pin) {
Logger.debug(TAG + '@setPincode', 'Pincode set using user provided pin')
setCachedPincode(pin)
} else {
throw new Error('Pincode type must be phone auth or must provide pin')
}
yield put(setPincodeSuccess(pincodeType))
Logger.info(TAG + '@setPincode', 'Pincode set successfully')
} catch (error) {
Logger.error(TAG + '@setPincode', 'Failed to set pincode', error)
yield put(showError(ErrorMessages.SET_PIN_FAILED))
yield put(setPincodeFailure())
}
}
export function randomBytes(size: number) {
return RNRandomBytes.randomBytes(size);
}
import { randomBytes } from 'react-native-randombytes';
import DeviceInfo from 'react-native-device-info';
import jwt from 'jwt-simple';
import { JWT_SECRET_FUND_WALLET } from 'react-native-dotenv';
import { isDev } from './env';
const uniqueId = isDev
? `random-${randomBytes(20).toString('hex')}`
: DeviceInfo.getUniqueID();
export function encodeFundToken(address) {
const payload = {
sub: address,
jti: uniqueId,
};
return jwt.encode(payload, JWT_SECRET_FUND_WALLET, 'HS512');
}