How to use the sha3.SHA3Hash function in sha3

To help you get started, we’ve selected a few sha3 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 UnSciPreneur / e2eBridge / lib / contractParser.js View on Github external
gethClient.post(codeQueryString, function (codeQueryResponse) {
        responseCounter++;
        var parsedCodeQueryResponse = JSON.parse(codeQueryResponse);
        if (parsedCodeQueryResponse.error) {
          logger.warn('Could not fetch code from geth due to: %s', parsedCodeQueryResponse.error.message);
        } else {
          var code = parsedCodeQueryResponse.result;
          contracts[ind]._source.code = code;
          var sha3 = new SHA3.SHA3Hash(256);
          sha3.update(code, 'ascii');
          contracts[ind]._source.codeHash = sha3.digest('hex').substr(0, 16);
          contracts[ind]._source.codeLength = code.length / 2 - 1;
          // do not update balances!
          delete contracts[ind]._source.balance;
        }

        if (responseCounter === responseCounterTarget) {
          return updateContractCode(contracts, blockNumber, maxBlockNumber);
        }
      });
    })(i, responseCounterTarget, blockNumber, maxBlockNumber, contracts);
github UnSciPreneur / e2eBridge / lib / elasticClient.js View on Github external
function enrichContractData(contract) {
  // see https://github.com/ethereum/pyethereum/blob/782842758e219e40739531a5e56fff6e63ca567b/ethereum/utils.py
  // for contract address calculation
  var sha3 = new SHA3.SHA3Hash(256);
  sha3.update(contract.input, 'ascii');
  contract.inputHash = sha3.digest('hex').substr(0, 16);
  contract.inputLength = contract.input.length / 2 - 1;

  var nonce = contract.nonce;
  // nonce should be hex encoded but not start with '0x'
  if (nonce.substr(0, 2) === '0x') {
    nonce = nonce.substr(2);
  }
  // nonce might have odd length
  if (nonce.length % 2) {
    nonce = '0' + nonce;
  }
  contract.contractAddress = ethUtil.bufferToHex(ethUtil.generateAddress(Buffer.from(contract.from.substr(2), 'hex'), Buffer.from(nonce, 'hex')));

  // delete some unwanted attributes from contract object
github martindale / hashcasher / contrib / middleware.js View on Github external
function isValid (input) {
    console.log('is input valid?', input);

    var parts = input.split(':');
    var claim = parts[1];
    
    if (claim < difficulty) {
      return false;
    }
    
    var hash = new crypto.SHA3Hash();
    hash.update(input);
    var digest = hash.digest('hex');
    var match = digest.match(/^(0+)/);
    var bits = (match) ? match[0].length : 0;
    
    if (bits < difficulty) {
      return false;
    }
    
    return true;
  }
github austintgriffith / cryptogs / backend / index.js View on Github external
redis.get("commit_"+commit,async function (err, commitData) {
    commitData=JSON.parse(commitData)
    console.log(commitData);
    let token1 = await getToken(request.body.finalArray[0])
    let token2 = await getToken(request.body.finalArray[1])
    let token3 = await getToken(request.body.finalArray[2])
    let token4 = await getToken(request.body.finalArray[3])
    let token5 = await getToken(request.body.finalArray[4])
    var d = new SHA3.SHA3Hash(224);
    d.update(Math.random()+Date.now()+""+JSON.stringify(request.body));
    let id = d.digest('hex');
    let counterStack = {
      _counterStack:id,
      block:-1,
      commit: commit,
      owner: request.body.account,
      token1: token1.id,
      token2: token2.id,
      token3: token3.id,
      token4: token4.id,
      token5: token5.id,
      token1Image: token1.image,
      token2Image: token2.image,
      token3Image: token3.image,
      token4Image: token4.image,
github blockmason / lndr-mobile / packages / auth / generate-token.js View on Github external
${Buffer.from(`308184020100301006072a8648ce3d020106052b8104000a046d306b0201010420${keyPair.getPrivateKey('hex')}a144034200${keyPair.getPublicKey('hex')}`, 'hex').toString('base64')}
-----END PRIVATE KEY-----`;
  },
  encodePublicKey: (keyPair) => {
    return `-----BEGIN PUBLIC KEY-----
${Buffer.from(`3056301006072a8648ce3d020106052b8104000a034200${keyPair.getPublicKey('hex')}`, 'hex').toString('base64')}
-----END PUBLIC KEY-----`;
  }
};

const keyPair = crypto.createECDH('secp256k1');

keyPair.generateKeys();

const publicKeyBuffer = Buffer.from(keyPair.getPublicKey('hex').substring(2), 'hex');
const publicKeyHash = new SHA3.SHA3Hash(256).update(publicKeyBuffer).digest('hex');
const address = `0x${publicKeyHash.substring(publicKeyHash.length - 40)}`;

const token = jwt.sign({
  pub: keyPair.getPublicKey('base64')
}, PEM.encodePrivateKey(keyPair), {
  algorithm: 'ES256',
  audience: 'https://friends.blockmason.app',
  issuer: keyPair.getPublicKey('base64'),
  subject: address
});

console.log(token, address);
github austintgriffith / cryptogs / backend / src / index.js View on Github external
redis.get("commit_"+commit,async function (err, commitData) {
    commitData=JSON.parse(commitData)
    console.log(commitData);

    let token1 = await getToken(request.body.finalArray[0])
    let token2 = await getToken(request.body.finalArray[1])
    let token3 = await getToken(request.body.finalArray[2])
    let token4 = await getToken(request.body.finalArray[3])
    let token5 = await getToken(request.body.finalArray[4])

    var d = new SHA3.SHA3Hash(224);
    d.update(Math.random()+Date.now()+""+JSON.stringify(request.body));
    let id = d.digest('hex');

    let counterStack = {
      _counterStack:id,
      block:-1,
      commit: commit,
      owner: request.body.account,
      token1: token1.id,
      token2: token2.id,
      token3: token3.id,
      token4: token4.id,
      token5: token5.id,
      token1Image: token1.image,
      token2Image: token2.image,
      token3Image: token3.image,

sha3

The Keccak family of hashing algorithms.

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis