Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function normalizeDecodedValue(type, value) {
if (_.isArray(value))
return _.map(value, v => normalizeDecodedValue(type, v));
const elementType = /^[a-z0-9]+/i.exec(type)[0];
assert(elementType);
// Convert addresses to checksummed addresses.
if (elementType == 'address')
return ethjs.toChecksumAddress(value);
// Convert integers to strings.
if (/^u?int/.test(elementType) && _.isObject(value))
return value.toString(10);
// Resize bytes values.
const m = /^bytes(\d+)?$/.exec(elementType);
if (m && m[1]) {
const size = parseInt(m[1]);
return ethjs.bufferToHex(ethjs.setLengthRight(value, size));
}
return value;
}
onToSelectedAddressChange = async toSelectedAddress => {
const { addressBook, network, identities } = this.props;
const networkAddressBook = addressBook[network] || {};
let [addToAddressToAddressBook, toSelectedAddressReady, toAddressName, toEnsName] = [
false,
false,
undefined,
undefined
];
if (isValidAddress(toSelectedAddress)) {
const checksummedToSelectedAddress = toChecksumAddress(toSelectedAddress);
toSelectedAddressReady = true;
const ens = await doENSReverseLookup(toSelectedAddress);
if (ens) {
toAddressName = ens;
} else if (networkAddressBook[checksummedToSelectedAddress] || identities[checksummedToSelectedAddress]) {
toAddressName =
(networkAddressBook[checksummedToSelectedAddress] &&
networkAddressBook[checksummedToSelectedAddress].name) ||
(identities[checksummedToSelectedAddress] && identities[checksummedToSelectedAddress].name);
} else {
// If not in address book nor user accounts
addToAddressToAddressBook = true;
}
} else if (isENS(toSelectedAddress)) {
toEnsName = toSelectedAddress;
const resolvedAddress = await doENSLookup(toSelectedAddress, network);
function testAddress(address) {
var officialIban = (iban.fromAddress(address))._iban;
var address = ethersAddress.getAddress(officialIban);
var officialAddress = ethereumUtil.toChecksumAddress(address)
var ethersIban = ethersAddress.getAddress(address, true);
test.equal(address, officialAddress, 'wrong address');
test.equal(ethersIban, officialIban, 'wrong ICAP address');
}
createAccountWithID,
updateSettingsAccounts,
createAssetWithID,
displayNotification
} = this.props;
const { keystore, network, accountType } = this.state;
const accountNetwork: Network | undefined = getNetworkByName(network);
if (!keystore || !accountNetwork) {
return;
}
const newAsset: Asset = getNewDefaultAssetTemplateByNetwork(accountNetwork);
const newAssetID: string = generateUUID();
const newUUID = generateUUID();
const account: Account = {
address: toChecksumAddress(addHexPrefix(keystore.address)),
networkId: network as NetworkId,
wallet: accountType,
dPath: '',
assets: [{ uuid: newAssetID, balance: '0', mtime: Date.now() }],
transactions: [],
favorite: false,
mtime: 0
};
createAccountWithID(account, newUUID);
updateSettingsAccounts([...settings.dashboardAccounts, newUUID]);
createAssetWithID(newAsset, newAssetID);
displayNotification(NotificationTemplates.walletCreated, {
address: account.address
});
history.replace(ROUTE_PATHS.DASHBOARD.path);
hd: hdAccounts.filter((item, pos) => (hdAccounts.indexOf(item) === pos)).map(address => ethUtil.toChecksumAddress(address)),
simpleKeyPair: [],
export function toChecksumAddress(address: string): string {
return EthereumjsUtil.toChecksumAddress(address)
}
getAddressString() {
const rawAddress = '0x' + this.getAddress().toString('hex');
return ethUtil.toChecksumAddress(rawAddress);
}
wallet.lockEncryptedAccountSync = ({ address }) => {
const checksumAddress = toChecksumAddress(address)
const { id, relockFunc } = wallet.relockMap[checksumAddress]
if (id) {
clearTimeout(id)
relockFunc()
delete wallet.relockMap[checksumAddress]
LOGGER.debug(`Relocked ${address}`)
}
}
receipt => {
this._address = ethjs.toChecksumAddress(receipt.contractAddress);
});
return r;
getTransactionDetails(unsignedTx: UnsignedTransaction): IAirGapTransaction {
const unsignedEthereumTx = unsignedTx as UnsignedEthereumTransaction
const ethTx = super.getTransactionDetails(unsignedEthereumTx)
const tokenTransferDetails = abiDecoder.decodeMethod(unsignedEthereumTx.transaction.data)
ethTx.to = [ethUtil.toChecksumAddress(tokenTransferDetails.params[0].value)]
ethTx.amount = new BigNumber(tokenTransferDetails.params[1].value)
return ethTx
}
}