How to use the web3-utils.keccak256 function in web3-utils

To help you get started, we’ve selected a few web3-utils 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 aragon / radspec / test / examples / examples.js View on Github external
source: "With value: Send `@tokenAmount(token, msg.value)` from `msg.sender` to `receiver`",
    bindings: { token: address(ETH), receiver:  address('0x8401Eb5ff34cc943f096A32EF3d5113FEbE8D4Eb') },
    options: { from: '0xb4124cEB3451635DAcedd11767f004d8a28c6eE7', value: '1000000000000000000' },
  }, 'With value: Send 1 ETH from 0xb4124cEB3451635DAcedd11767f004d8a28c6eE7 to 0x8401Eb5ff34cc943f096A32EF3d5113FEbE8D4Eb'],

  [{
    source: "Sending tx with data `msg.data` to contract at `contract`",
    bindings: { contract: address('0x960b236A07cf122663c4303350609A66A7B288C0') },
    options: { data: '0xabcdef'}
  }, "Sending tx with data 0xabcdef to contract at 0x960b236A07cf122663c4303350609A66A7B288C0"],
  
  // using msg.data on a helper
  [{
    source: "Performs a call to `@radspec(contract, msg.data)`",
    bindings: { contract: address('0x960b236A07cf122663c4303350609A66A7B288C0') },
    options: { data: keccak256(Object.keys(knownFunctions)[3]).slice(0,10) }
  }, `Performs a call to ${Object.values(knownFunctions)[3]}`],

  ...comparisonCases,
  ...helperCases,
  ...dataDecodeCases
]

cases.forEach(([input, expected], index) => {
  test(`${index} - ${input.source}`, async (t) => {
    const { userHelpers } = input.options || {}
    const actual = await evaluateRaw(
      input.source,
      input.bindings,
      {
        ...input.options,
        availableHelpers: { ...defaultHelpers, ...userHelpers }
github AztecProtocol / AZTEC / packages / aztec.js / src / proof / proofs / BALANCED / epoch0 / joinSplit / index.js View on Github external
constructOutputs() {
        const proofOutput = {
            inputNotes: this.inputNotes,
            outputNotes: this.outputNotes,
            publicValue: this.publicValue,
            publicOwner: this.publicOwner,
            challenge: this.challengeHex,
        };
        this.output = outputCoder.encodeProofOutput(proofOutput);
        this.outputs = outputCoder.encodeProofOutputs([proofOutput]);
        this.hash = outputCoder.hashProofOutput(this.output);
        this.validatedProofHash = keccak256(
            AbiCoder.encodeParameters(['bytes32', 'uint24', 'address'], [this.hash, proofs.JOIN_SPLIT_PROOF, this.sender]),
        );
    }
github AztecProtocol / AZTEC / packages / aztec.js / src / proof / proofs / UTILITY / epoch0 / publicRange / index.js View on Github external
constructOutputs() {
        const proofOutput = {
            inputNotes: this.inputNotes,
            outputNotes: this.outputNotes,
            publicValue: this.publicValue,
            publicOwner: this.publicOwner,
            challenge: this.challengeHex,
        };
        this.output = outputCoder.encodeProofOutput(proofOutput);
        this.outputs = outputCoder.encodeProofOutputs([proofOutput]);
        this.hash = outputCoder.hashProofOutput(this.output);
        this.validatedProofHash = keccak256(
            AbiCoder.encodeParameters(['bytes32', 'uint24', 'address'], [this.hash, proofs.PUBLIC_RANGE_PROOF, this.sender]),
        );
    }
github AztecProtocol / AZTEC / packages / aztec.js / src / proof / proofs / BALANCED / epoch0 / swap / index.js View on Github external
constructOutputs() {
        this.output = '';
        this.outputs = outputCoder.encodeProofOutputs([
            {
                inputNotes: [this.inputNotes[0]],
                outputNotes: [this.outputNotes[0]],
                publicValue: this.publicValue,
                publicOwner: this.publicOwner,
                challenge: this.challengeHex,
            },
            {
                inputNotes: [this.outputNotes[1]],
                outputNotes: [this.inputNotes[1]],
                publicValue: this.publicValue,
                publicOwner: this.publicOwner,
                challenge: `0x${keccak256(this.challengeHex).slice(2)}`,
            },
        ]);
        this.hash = outputCoder.hashProofOutput(this.outputs);
        this.validatedProofHash = keccak256(
            AbiCoder.encodeParameters(['bytes32', 'uint24', 'address'], [this.hash, proofs.SWAP_PROOF, this.sender]),
        );
    }
github OriginProtocol / origin / infra / notifications / src / dupeTools.js View on Github external
function getMessageFingerprint(messageObject) {
  return web3Utils.keccak256(JSON.stringify(messageObject))
}
github d-ost / dost-heiswap / src / components / VerifyPin.js View on Github external
getPinHash() {
    let pin = this.pin;
    for(let i = 0;i < HASHNUMBER; i++){
      pin = web3Utils.keccak256(pin);
    }
    return pin;
  }
github ethereum / web3.js / packages / web3-eth-accounts / src / index.js View on Github external
privateKey = privateKey.substring(2);
            }

            var ethTx = new Transaction(transaction, transactionOptions);

            ethTx.sign(Buffer.from(privateKey, 'hex'));

            var validationResult = ethTx.validate(true);

            if (validationResult !== '') {
                throw new Error('Signer Error: ' + validationResult);
            }

            var rlpEncoded = ethTx.serialize().toString('hex');
            var rawTransaction = '0x' + rlpEncoded;
            var transactionHash = utils.keccak256(rawTransaction);

            return {
                messageHash: '0x' + Buffer.from(ethTx.hash(false)).toString('hex'),
                v: '0x' + Buffer.from(ethTx.v).toString('hex'),
                r: '0x' + Buffer.from(ethTx.r).toString('hex'),
                s: '0x' + Buffer.from(ethTx.s).toString('hex'),
                rawTransaction: rawTransaction,
                transactionHash: transactionHash
            };

        } catch (e) {
            callback(e);
            return Promise.reject(e);
        }

        callback(null, result);
github d-ost / dost-heiswap / src / components / CreatePin.js View on Github external
getPinHash() {
    let noOfTimeToHash = 3;
    let pin = this.pin;

    for(let i = 0;i < noOfTimeToHash; i++){
      pin = web3Utils.keccak256(pin);
    }

    return pin;
  }
github sc-forks / solidity-coverage / lib / injector.js View on Github external
_getHash(fileName) {
    this.hashCounter++;
    return web3Utils.keccak256(`${fileName}:${this.hashCounter}`);
  }