How to use the sha3 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 kulapio / libra-core / lib / client.ts View on Github external
});
    program.setArgumentsList(transactionArguments);
    program.setModulesList(transaction.program.modules);
    const rawTransaction = new RawTransaction();
    rawTransaction.setExpirationTime(transaction.expirationTime.toNumber());
    rawTransaction.setGasUnitPrice(transaction.gasContraint.gasUnitPrice.toNumber());
    rawTransaction.setMaxGasAmount(transaction.gasContraint.maxGasAmount.toNumber());
    rawTransaction.setSequenceNumber(sequenceNumber.toNumber());
    rawTransaction.setProgram(program);
    rawTransaction.setSenderAccount(senderAddress.toBytes());

    const signedTransaction = new SignedTransaction();

    const request = new SubmitTransactionRequest();
    const rawTxnBytes = rawTransaction.serializeBinary();
    const hash = new SHA3(256)
      .update(Buffer.from(HashSaltValues.rawTransactionHashSalt, 'hex'))
      .update(Buffer.from(rawTxnBytes.buffer))
      .digest();
    const senderSignature = sender.keyPair.sign(hash);
    signedTransaction.setRawTxnBytes(rawTxnBytes);
    signedTransaction.setSenderPublicKey(sender.keyPair.getPublicKey());
    signedTransaction.setSenderSignature(senderSignature);

    request.setSignedTxn(signedTransaction);
    return new Promise((resolve, reject) => {
      this.client.submitTransaction(request, (error: ServiceError | null, response: SubmitTransactionResponse) => {
        if (error) {
          // TBD: should this fail with only service error
          // or should it fail if transaction is not acknowledged
          return reject(error);
        }
github kulapio / libra-core / lib / client / index.ts View on Github external
private signRawTransaction(rawTransaction: Uint8Array, keyPair: KeyPair): Signature {
    const saltHash = new SHA3(256)
      .update(HashSaltValues.rawTransactionHashSalt, 'utf-8')
      .digest();
    const data = BufferUtil.concat(saltHash, rawTransaction)
    const hash = new SHA3(256)
      .update(BufferUtil.toHex(data), 'hex')
      .digest();

    return keyPair.sign(hash);
  }
}
github kulapio / libra-core / lib / client / index.ts View on Github external
private signRawTransaction(rawTransaction: Uint8Array, keyPair: KeyPair): Signature {
    const saltHash = new SHA3(256)
      .update(HashSaltValues.rawTransactionHashSalt, 'utf-8')
      .digest();
    const data = BufferUtil.concat(saltHash, rawTransaction)
    const hash = new SHA3(256)
      .update(BufferUtil.toHex(data), 'hex')
      .digest();

    return keyPair.sign(hash);
  }
}

sha3

The Keccak family of hashing algorithms.

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis