How to use the js-sha3.keccak_256 function in js-sha3

To help you get started, we’ve selected a few js-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 fairDataSociety / fds.js / migrations / 1563788331_ens.js View on Github external
await deployer.deploy(ENS);

            const ens = await ENS.deployed();

            await deployer.deploy(TestRegistrar, ens.address, namehash.hash('eth'));
            await deployer.deploy(PublicResolver, ens.address);

            await ens.setSubnodeOwner('0x0', '0x' + sha3('eth'), accounts[0]);
            await ens.setSubnodeOwner(namehash.hash('eth'), '0x' + sha3('datafund'), accounts[0]);

            const resolver = await PublicResolver.deployed();
            await ens.setResolver(namehash.hash('datafund.eth'), resolver.address);

            const dhr = await TestRegistrar.deployed();
            await ens.setSubnodeOwner('0x0', '0x' + sha3('eth'), accounts[0]);

            await deployer.deploy(SubdomainRegistrar, ens.address, namehash.hash('datafund.eth'));

            const registrar = await SubdomainRegistrar.deployed();
            await ens.setSubnodeOwner(namehash.hash('eth'), '0x' + sha3('datafund'), registrar.address);
            
        } else {
            // const ens = ENS.deployed();
            // await deployer.deploy(SubdomainRegistrar, ens.address);
        }
    });
};
github paritytech / js-libs / packages / abi / src / util / signature.ts View on Github external
export const eventSignature = (
  eventName: string | undefined,
  params: ParamType[] = []
) => {
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
  const { strName, name } = parseName(eventName);
  const types = (params || []).map(fromParamType).join(',');
  const id = `${strName}(${types})`;
  const signature = strName ? keccak_256(id) : '';

  return { id, name, signature };
};
github paritytech / js-libs / packages / api / src / transport / ws / ws.js View on Github external
this._ws.onerror = null;
      this._ws.onopen = null;
      this._ws.onclose = null;
      this._ws.onmessage = null;
      this._ws.close();
      this._ws = null;
      this._sessionHash = null;
    }
    this._connecting = true;
    this._connected = false;
    this._lastError = null;

    // rpc secure API
    if (this._token) {
      const time = parseInt(new Date().getTime() / 1000, 10);
      const sha3 = keccak_256(`${this._token}:${time}`);
      const hash = `${sha3}_${time}`;

      this._sessionHash = sha3;
      this._ws = new WebSocket(this._url, hash);
    // non-secure API
    } else {
      this._ws = new WebSocket(this._url);
    }

    this._ws.onerror = this._onError;
    this._ws.onopen = this._onOpen;
    this._ws.onclose = this._onClose;
    this._ws.onmessage = this._onMessage;

    // Get counts in dev mode only
    if (process.env.NODE_ENV === 'development') {
github clearmatics / asset-token / test / AssetTokenOperator.js View on Github external
context("New operators", () => {
      let authorizedEvent = null;
      let authorizedOperatorSignature =
        "0x" + sha3("AuthorizedOperator(address,address)");
      let revokedOperatorSignature =
        "0x" + sha3("RevokedOperator(address,address)");

      beforeEach(async () => {
        const res = await CONTRACT.authorizeOperator(newOperator).send({
          from: tokenHolder
        });

        const rec = await web3.eth.getTransactionReceipt(res.transactionHash);

        authorizedEvent = rec.logs[0].topics;
      });

      it("AuthorizedOperator event is emitted correctly", async () => {
        assert.notEqual(authorizedEvent, null);
        assert.equal(authorizedEvent[0], authorizedOperatorSignature);
github ukd1 / toshi-testnet-faucet / src / lib / Wallet.js View on Github external
sign(data) {
    let datahash = keccak256(data);
    let sig = this.keypair.sign(datahash, { canonical: true });
    return "0x" +
      hash.utils.toHex(bnToBuffer(sig.r, 32)) +
      hash.utils.toHex(bnToBuffer(sig.s, 32)) +
      hash.utils.toHex([sig.recoveryParam]);
  }
}
github ethers-io / ethers.objc / tools / extract-mnemonic / index.js View on Github external
scrypt(password, salt, N, r, p, 64, function(error, progress, key) {
            if (error) {
                reject(error);

            } else if (key) {
                var aes = new aesjs.ModeOfOperation.ctr(new Buffer(key.slice(32)), new aesjs.Counter(counter));
                var mnemonic = bip39.entropyToMnemonic(aes.decrypt(cipherText))
                var root = HDNode.fromSeedBuffer(bip39.mnemonicToSeed(mnemonic));
                var node = root.derivePath("m/44'/60'/0'/0/0");
                var privateKey = node.keyPair.d.toBuffer(32);
                var publicKey = node.keyPair.Q.getEncoded(false);
                var computedAddress = keccak256(publicKey.slice(1)).substring(24);
                if (computedAddress !== address) {
                    reject(new Error('wrong password'));
                    return;
                }
                //console.log('Mnemonic Phrase: ' + mnemonic);
                //console.log('Private Key:     0x' + privateKey.toString('hex'));
                //console.log('Public Key:      0x' + publicKey.toString('hex'));
                //console.log('Address:         0x' + address);
                resolve(mnemonic);
            }
        });
    });
github paritytech / js-libs / packages / api / src / util / sha3.ts View on Github external
export const sha3 = (
  value: string | Bytes,
  options?: { encoding: Encoding }
): string => {
  const forceHex = options && options.encoding === 'hex';

  if (forceHex || (!options && isHex(value))) {
    const bytes = hexToBytes(value as string);

    return sha3(bytes);
  }

  const hash = keccak_256(value);

  return `0x${hash}`;
};
github unstoppabledomains / resolution / src / cns / contract / namehash.ts View on Github external
export function childhash(parent, child) {
  const childHash = sha3(child);
  const mynode = sha3(Buffer.from(parent + childHash, 'hex'));
  return mynode;
}