How to use the ethereumjs-util.pubToAddress 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 iden3 / iden3js / src / identity / identity.js View on Github external
static create(db, passphrase, seed) {
    const keyContainer = new KeyContainer(db);
    keyContainer.unlock(passphrase);

    if (seed === undefined) {
      seed = bip39.generateMnemonic();
    }
    keyContainer.setMasterSeed(seed);
    // seed = keyContainer.getMasterSeed();
    const keys = keyContainer.createKeys();

    const keyOperationalPub = keys.kOp;
    db.insert('keyOperationalPub', keyOperationalPub);

    const keyDisablePub = keys.kDis;
    const keyDisable = `0x${ethUtil.pubToAddress(keyDisablePub, true).toString('hex')}`;
    db.insert('keyDisable', keyDisable);
    const keyReenablePub = keys.kReen;
    const keyReenable = `0x${ethUtil.pubToAddress(keyReenablePub, true).toString('hex')}`;
    db.insert('keyReenable', keyReenable);
    const keyUpdateRootPub = keys.kUpdateRoot;
    const keyUpdateRoot = `0x${ethUtil.pubToAddress(keyUpdateRootPub, true).toString('hex')}`;
    db.insert('keyUpdateRoot', keyUpdateRoot);

    const {
      id, proofClaimKeyOperationalPub, proofClaimKeyDisable, proofClaimKeyReenable, proofClaimKeyUpdateRoot,
    } = identityUtils.calculateIdGenesis(keyOperationalPub, keyReenable, keyDisable, keyUpdateRoot);
    db.insert('id', id);
    db.insert(id, true);

    db.insert('proofClaimKeyOperationalPub', JSON.stringify(proofClaimKeyOperationalPub));
    db.insert('proofClaimKeyDisable', JSON.stringify(proofClaimKeyDisable));
github floating / frame / main / signers / hot / Seed / index.js View on Github external
this.signMessage(index, message, (err, signed) => {
      if (err) return cb(err)
      // Verify
      const signature = Buffer.from(signed.replace('0x', ''), 'hex')
      if (signature.length !== 65) cb(new Error(`Frame verifyAddress signature has incorrect length`))
      let v = signature[64]
      v = v === 0 || v === 1 ? v + 27 : v
      let r = toBuffer(signature.slice(0, 32))
      let s = toBuffer(signature.slice(32, 64))
      const hash = hashPersonalMessage(toBuffer(message))
      const verifiedAddress = '0x' + pubToAddress(ecrecover(hash, v, r, s)).toString('hex')
      cb(null, verifiedAddress.toLowerCase() === address.toLowerCase())
    })
  }
github iden3 / iden3js / src / identity / identity.js View on Github external
if (seed === undefined) {
      seed = bip39.generateMnemonic();
    }
    keyContainer.setMasterSeed(seed);
    // seed = keyContainer.getMasterSeed();
    const keys = keyContainer.createKeys();

    const keyOperationalPub = keys.kOp;
    db.insert('keyOperationalPub', keyOperationalPub);

    const keyDisablePub = keys.kDis;
    const keyDisable = `0x${ethUtil.pubToAddress(keyDisablePub, true).toString('hex')}`;
    db.insert('keyDisable', keyDisable);
    const keyReenablePub = keys.kReen;
    const keyReenable = `0x${ethUtil.pubToAddress(keyReenablePub, true).toString('hex')}`;
    db.insert('keyReenable', keyReenable);
    const keyUpdateRootPub = keys.kUpdateRoot;
    const keyUpdateRoot = `0x${ethUtil.pubToAddress(keyUpdateRootPub, true).toString('hex')}`;
    db.insert('keyUpdateRoot', keyUpdateRoot);

    const {
      id, proofClaimKeyOperationalPub, proofClaimKeyDisable, proofClaimKeyReenable, proofClaimKeyUpdateRoot,
    } = identityUtils.calculateIdGenesis(keyOperationalPub, keyReenable, keyDisable, keyUpdateRoot);
    db.insert('id', id);
    db.insert(id, true);

    db.insert('proofClaimKeyOperationalPub', JSON.stringify(proofClaimKeyOperationalPub));
    db.insert('proofClaimKeyDisable', JSON.stringify(proofClaimKeyDisable));
    db.insert('proofClaimKeyReenable', JSON.stringify(proofClaimKeyReenable));
    db.insert('proofClaimKeyUpdateRoot', JSON.stringify(proofClaimKeyUpdateRoot));
github mitmedialab / medrec / UserClient / src / Ethereum.js View on Github external
return new Promise((resolve, reject) => {
      let address = Utils.pubToAddress('0x' + pubKey);
      resolve(address.toString('hex'));
    });
  }
github floating / frame / main / provider / index.js View on Github external
getSignedAddress (signed, message, cb) {
    const signature = Buffer.from(signed.replace('0x', ''), 'hex')
    if (signature.length !== 65) cb(new Error(`Frame verifySignature: Signature has incorrect length`))
    let v = signature[64]
    v = v === 0 || v === 1 ? v + 27 : v
    const r = toBuffer(signature.slice(0, 32))
    const s = toBuffer(signature.slice(32, 64))
    const hash = hashPersonalMessage(toBuffer(message))
    const verifiedAddress = '0x' + pubToAddress(ecrecover(hash, v, r, s)).toString('hex')
    cb(null, verifiedAddress)
  }
github opporty-com / Plasma-Cash / plasma-core / child-chain / validator / transactions / utils.js View on Github external
const getSignatureOwner = async (transaction) => {
  let tokenOwner = ''
  try {
    let sig = ethUtil.fromRpcSig(ethUtil.
      addHexPrefix(transaction.signature.toString('hex')))
    let msgHash = ethUtil.hashPersonalMessage(transaction.getHash(true))
    let pubKey = ethUtil.ecrecover(msgHash, sig.v, sig.r, sig.s)
    tokenOwner = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey))
  } catch (error) {
    throw new Error(rejectCauses.invalidSignature)
  }
  return tokenOwner
}
github MyCryptoHQ / MyCrypto / common / libs / signing.ts View on Github external
export function verifySignedMessage({ address, msg, sig, version }: ISignedMessage) {
  const sigb = new Buffer(stripHexPrefixAndLower(sig), 'hex');
  if (sigb.length !== 65) {
    return false;
  }
  //TODO: explain what's going on here
  sigb[64] = sigb[64] === 0 || sigb[64] === 1 ? sigb[64] + 27 : sigb[64];
  const hash = version === '2' ? hashPersonalMessage(toBuffer(msg)) : sha3(msg);
  const pubKey = ecrecover(hash, sigb[64], sigb.slice(0, 32), sigb.slice(32, 64));

  return stripHexPrefixAndLower(address) === pubToAddress(pubKey).toString('hex');
}
github zbo14 / constellate / lib / secp256k1.js View on Github external
function publicKeyToAddress(publicKey) {
    const buf = secp256k1.publicKeyConvert(publicKey, false).slice(1);
    return '0x' + ethjsUtil.pubToAddress(buf).toString('hex');
}
github MyCryptoHQ / MyCrypto / common / v2 / services / EthService / utils / signing.ts View on Github external
export function verifySignedMessage({ address, msg, sig, version }: ISignedMessage) {
  const sigb = new Buffer(stripHexPrefixAndLower(sig), 'hex');
  if (sigb.length !== 65) {
    return false;
  }
  //TODO: explain what's going on here
  sigb[64] = sigb[64] === 0 || sigb[64] === 1 ? sigb[64] + 27 : sigb[64];
  const hash = version === '2' ? hashPersonalMessage(toBuffer(msg)) : sha3(msg);
  const pubKey = ecrecover(hash, sigb[64], sigb.slice(0, 32), sigb.slice(32, 64));

  return stripHexPrefixAndLower(address) === pubToAddress(pubKey).toString('hex');
}