How to use the ethereumjs-util.stripHexPrefix function in ethereumjs-util

To help you get started, we’ve selected a few ethereumjs-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / abi-encoder / src / abi_encoder / calldata / calldata.ts View on Github external
// 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) {
github ethereumjs / ethereumjs-vm / tests / util.js View on Github external
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)
github blockchain / My-Wallet-V3 / src / helpers.js View on Github external
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)
    )
  );
};
github opporty-com / Plasma-Cash / plasma-core / cli / models / block.js View on Github external
getProof(tokenId, returnhex) {  
    if (!this.merkle) {
      this.buildTree();
    }

    if (!(tokenId instanceof Buffer)) {
      tokenId = ethUtil.toBuffer(ethUtil.stripHexPrefix(tokenId));
    }
    
    return this.merkle.getProof(tokenId, returnhex);
  }
github ethereumjs / ethereumjs-vm / examples / run-blockchain / index.js View on Github external
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)
github brave / ethereum-remote-client / app / scripts / lib / id-management.js View on Github external
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')
}
github MetaMask / gaba / src / keyring / KeyringController.ts View on Github external
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);
github MetaMask / eth-simple-keyring / index.js View on Github external
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)
  }
github brave / ethereum-remote-client / ui / app / components / pending-tx-details.js View on Github external
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'),
github SuperblocksHQ / ethereum-studio / packages / editor / src / services / evm / src / evm.js View on Github external
function decode(type, data) {
    data = utils.stripHexPrefix(data);
    var decodedData = abi.rawDecode([type], new Buffer(data, 'hex'));
    return decodedData;
}