How to use the js-sha3.sha3_256.create 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 nemtech / nem2-sdk-typescript-javascript / test / infrastructure / SerializeTransactionToJSON.spec.ts View on Github external
it('should create SecretLockTransaction', () => {
        const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7';
        const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL');
        const secretLockTransaction = SecretLockTransaction.create(
            Deadline.create(),
            NetworkCurrencyMosaic.createAbsolute(10),
            UInt64.fromUint(100),
            HashType.Op_Sha3_256,
            sha3_256.create().update(convert.hexToUint8(proof)).hex(),
            recipientAddress,
            NetworkType.MIJIN_TEST,
        );

        const json = secretLockTransaction.toJSON();

        expect(json.transaction.type).to.be.equal(TransactionType.SECRET_LOCK);
        expect(json.transaction.hashAlgorithm).to.be.equal(HashType.Op_Sha3_256);

    });
github nemtech / nem2-sdk-typescript-javascript / test / model / transaction / SecretProofTransaction.spec.ts View on Github external
it('should be created with HashType: Op_Sha3_256 secret', () => {
        const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7';
        const secretProofTransaction = SecretProofTransaction.create(
            Deadline.create(),
            HashType.Op_Sha3_256,
            sha3_256.create().update(convert.hexToUint8(proof)).hex(),
            account.address,
            proof,
            NetworkType.MIJIN_TEST,
        );
        expect(secretProofTransaction.hashType).to.be.equal(0);
        expect(secretProofTransaction.secret).to.be.equal('9b3155b37159da50aa52d5967c509b410f5a36a3b1e31ecb5ac76675d79b4a5e' );
        expect(secretProofTransaction.proof).to.be.equal(proof);
    });
github airgap-it / airgap-vault / src / app / models / BIP39Signer.ts View on Github external
public recoverKey(shares: any): string {
    const offset = this.getOffsetMapping(shares[0])
    const translatedShares = []
    for (let i = 0; i < shares.length; i++) {
      const words = shares[i].split(' ')
      const firstHalf = words.slice(0, 24)
      const secondHalf = words.slice(24, words.length)
      translatedShares[i] = `${bip39.mnemonicToEntropy(firstHalf.join(' '))}${bip39.mnemonicToEntropy(secondHalf.join(' '))}`.substr(
        0,
        offset.offset
      )
    }
    const secretDigester = sha3_256.create()
    const combine = secretJS.combine(translatedShares)
    const seed = combine.slice(0, -this.checkSumLength)

    secretDigester.update(seed)

    const checksum = secretDigester.hex().slice(0, this.checkSumLength)
    const checksum2 = combine.substr(-this.checkSumLength)
    if (checksum !== checksum2) {
      throw new Error(
        'Checksum error, either the passed shares were generated for different secrets or the amount of shares is below the threshold'
      )
    }

    return bip39.entropyToMnemonic(seed)
  }
}
github medibloc / panacea-js-old / src / cryptography / hash.js View on Github external
const hashData = (msg) => {
  let message = '';
  switch (typeof msg) {
    case 'string':
      message = msg;
      break;
    case 'object':
    case 'number':
      message = msg.toString();
      break;
    default:
      throw new Error('Invalid msg type');
  }
  const hash = SHA3256.create();
  return hash.update(message).hex();
};
github airgap-it / airgap-vault / src / providers / entropy / entropy.service.ts View on Github external
hashWorker.onmessage = event => {
        const secureRandomArray = new Uint8Array(this.ENTROPY_SIZE)
        window.crypto.getRandomValues(secureRandomArray)

        const hash = sha3_256.create()
        hash.update(event.data.hash)
        hash.update(secureRandomArray)

        resolve(hash.hex())
      }
github medibloc / panacea-js-old / src / local / transaction / utils / hashTx.js View on Github external
from: genHexBuf(tx.from, BYTESIZES.ADDRESS),
    to: genHexBuf(tx.to ? tx.to : '', BYTESIZES.ADDRESS),
    value: genHexBuf(tx.value ? BigNumber(tx.value).toString(16) : '', BYTESIZES.VALUE),
    nonce: tx.nonce,
    chainId: tx.chain_id,
    payload: (tx.payload === undefined || tx.payload === '') ? null : binary.from(tx.payload, 'hex'),
  };

  const root = protobuf.Root.fromJSON(jsonDescriptor);
  const TxHashTarget = root.lookupType('TransactionHashTarget');
  const errMsg = TxHashTarget.verify(txHashTarget);
  if (errMsg) throw Error(errMsg);

  const message = TxHashTarget.create(txHashTarget);
  const buf = TxHashTarget.encode(message).finish();
  const hash = SHA3256.create();
  return hash.update(buf).hex();
};
github evias / nem2-sandbox / src / commands / transaction / accountLinkInvalidRemote.ts View on Github external
const isValidAddressDecoded = (decoded): boolean => {
    const hash = sha3_256.create();
    const checksumBegin = 25 - 4;
    hash.update(decoded.subarray(0, checksumBegin));
    const checksum = new Uint8Array(4);
    arrayCopy(checksum, uint8View(hash.arrayBuffer()), 4);
    return deepEqual(checksum, decoded.subarray(checksumBegin), 4);
}
github nemtech / catapult-rest / catapult-sdk / src / model / idGenerator.js View on Github external
const generateId = (parentId, name) => {
	const hash = sha3_256.create();
	hash.update(Uint32Array.from(parentId).buffer);
	hash.update(name);
	const result = new Uint32Array(hash.arrayBuffer());
	return [result[0], result[1]];
};