Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Resulting line will be
let offsetStr = '';
let valueStr = '';
let nameStr = '';
let lineStr = '';
if (size === emptySize) {
// This is a Set block with no header.
// For example, a tuple or an array with a defined length.
offsetStr = ' '.repeat(offsetPadding);
valueStr = ' '.repeat(valuePadding);
nameStr = `### ${prettyName.padEnd(namePadding)}`;
lineStr = `\n${offsetStr}${valueStr}${nameStr}`;
} else {
// This block has at least one word of value.
offsetStr = `0x${offset.toString(constants.HEX_BASE)}`.padEnd(offsetPadding);
valueStr = ethUtil
.stripHexPrefix(
ethUtil.bufferToHex(
block.toBuffer().slice(evmWordStartIndex, constants.EVM_WORD_WIDTH_IN_BYTES),
),
)
.padEnd(valuePadding);
if (block instanceof SetCalldataBlock) {
nameStr = `### ${prettyName.padEnd(namePadding)}`;
lineStr = `\n${offsetStr}${valueStr}${nameStr}`;
} else {
nameStr = ` ${prettyName.padEnd(namePadding)}`;
lineStr = `${offsetStr}${valueStr}${nameStr}`;
}
}
// This block has a value that is more than 1 word.
for (let j = constants.EVM_WORD_WIDTH_IN_BYTES; j < size; j += constants.EVM_WORD_WIDTH_IN_BYTES) {
function (cb2) {
account.stateRoot = storageTrie.root
if (testData.exec && key === testData.exec.address) {
testData.root = storageTrie.root
}
state.put(Buffer.from(utils.stripHexPrefix(key), 'hex'), account.serialize(), function () {
cb2()
})
}
], callback)
Helpers.isEtherAddress = function (address) {
return (
ethUtil.isValidChecksumAddress(address) ||
(
ethUtil.isValidAddress(address) &&
ethUtil.stripHexPrefix(address).toLowerCase() === ethUtil.stripHexPrefix(address)
) ||
(
ethUtil.isValidAddress(address) &&
ethUtil.stripHexPrefix(address).toUpperCase() === ethUtil.stripHexPrefix(address)
)
);
};
getProof(tokenId, returnhex) {
if (!this.merkle) {
this.buildTree();
}
if (!(tokenId instanceof Buffer)) {
tokenId = ethUtil.toBuffer(ethUtil.stripHexPrefix(tokenId));
}
return this.merkle.getProof(tokenId, returnhex);
}
function (cb2) {
account.stateRoot = storageTrie.root
if (testData.exec && key === testData.exec.address) {
testData.root = storageTrie.root
}
state.put(Buffer.from(utils.stripHexPrefix(key), 'hex'), account.serialize(), function () {
cb2()
})
}
], callback)
function concatSig (v, r, s) {
const rSig = ethUtil.fromSigned(r)
const sSig = ethUtil.fromSigned(s)
const vSig = ethUtil.bufferToInt(v)
const rStr = padWithZeroes(ethUtil.toUnsigned(rSig).toString('hex'), 64)
const sStr = padWithZeroes(ethUtil.toUnsigned(sSig).toString('hex'), 64)
const vStr = ethUtil.stripHexPrefix(ethUtil.intToHex(vSig))
return ethUtil.addHexPrefix(rStr.concat(sStr, vStr)).toString('hex')
}
async importAccountWithStrategy(strategy: string, args: any[]): Promise {
let privateKey;
const preferences = this.context.PreferencesController as PreferencesController;
switch (strategy) {
case 'privateKey':
const [importedKey] = args;
if (!importedKey) {
throw new Error('Cannot import an empty key.');
}
const prefixed = ethUtil.addHexPrefix(importedKey);
if (!ethUtil.isValidPrivate(ethUtil.toBuffer(prefixed))) {
throw new Error('Cannot import invalid private key.');
}
privateKey = ethUtil.stripHexPrefix(prefixed);
break;
case 'json':
let wallet;
const [input, password] = args;
try {
wallet = importers.fromEtherWallet(input, password);
} catch (e) {
wallet = wallet || Wallet.fromV3(input, password, true);
}
privateKey = ethUtil.bufferToHex(wallet.getPrivateKey());
break;
}
const newKeyring = await privates.get(this).keyring.addNewKeyring(KeyringTypes.simple, [privateKey]);
const accounts = await newKeyring.getAccounts();
const allAccounts = await privates.get(this).keyring.getAccounts();
preferences.updateIdentities(allAccounts);
decryptMessage (withAccount, encryptedData) {
const wallet = this._getWalletForAccount(withAccount)
const privKey = ethUtil.stripHexPrefix(wallet.getPrivateKey())
const privKeyBuffer = new Buffer(privKey, 'hex')
const sig = sigUtil.decrypt(encryptedData, privKey)
return Promise.resolve(sig)
}
PTXP.calculateGas = function () {
const txMeta = this.gatherParams()
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
var txParams = txMeta.txParams
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
var txFee = gasCost.mul(gasPrice)
var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
var maxCost = txValue.add(txFee)
const txFeeHex = '0x' + txFee.toString('hex')
const maxCostHex = '0x' + maxCost.toString('hex')
const gasPriceHex = '0x' + gasPrice.toString('hex')
txMeta.txFee = txFeeHex
txMeta.maxCost = maxCostHex
txMeta.txParams.gasPrice = gasPriceHex
this.setState({
txFee: '0x' + txFee.toString('hex'),
maxCost: '0x' + maxCost.toString('hex'),
function decode(type, data) {
data = utils.stripHexPrefix(data);
var decodedData = abi.rawDecode([type], new Buffer(data, 'hex'));
return decodedData;
}