How to use the js-sha3.sha3_256.update 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 icon-project / icon-sdk-js / lib / data / Serializer.js View on Github external
export default function (trasaction) {
	const phraseToSign = generateHashKey(trasaction);
	const hashcode = sha3256.update(phraseToSign).hex();
	// const serialized = new Buffer(hashcode, 'hex');
	const serialized = Buffer.alloc(hashcode, 'hex');
	return serialized;
}
github Emurgo / tangata-manu / src / entities / shelley-validator.js View on Github external
throw new Error(`No UTxO is found for tx ${inputTxId}! Maybe the blockchain is still syncing? If not - something is wrong.`)
      }
      const { address: inputAddress, amount: inputAmount } = txOutputs[inputIdx]
      this.logger.debug(`Validating witness for input: ${inputTxId}.${inputIdx} (${inputAmount} coin from ${inputAddress})`)
      const {
        addressRoot,
        addrAttr,
        addressType,
      } = ShelleyValidator.deconstructAddress(inputAddress)
      if (addressType !== 0) {
        this.logger.debug(`Unsupported address type: ${addressType}. Skipping witness validation for this input.`)
        return
      }
      const addressRootHex = addressRoot.toString('hex')
      const expectedStruct = [0, [0, sign[0]], addrAttr]
      const encodedStruct = Buffer.from(sha3_256.update(
        cbor.encodeCanonical(expectedStruct)).digest())
      const expectedRootHex = blake.blake2bHex(encodedStruct, undefined, 28)
      if (addressRootHex !== expectedRootHex) {
        throw new Error(`Witness does not match! ${JSON.stringify({ addressRootHex, expectedRoot: expectedRootHex })}`)
      }
    })
  }
github icon-project / icon-sdk-js / lib / data / Util.js View on Github external
export function makeTxHash(rawTrasaction) {
	const phraseToSign = generateHashKey(rawTrasaction);
	return sha3256.update(phraseToSign).hex();
}
github Emurgo / tangata-manu / src / entities / byron-validator.js View on Github external
}`)
      }
      const txOutputs = fullOutputs[inputTxId]
      if (!txOutputs) {
        throw new Error(`No UTxO is found for tx ${inputTxId}! Maybe the blockchain is still syncing? If not - something is wrong.`)
      }
      const { address: inputAddress, amount: inputAmount } = txOutputs[inputIdx]
      this.logger.debug(`Validating witness for input: ${inputTxId}.${inputIdx} (${inputAmount} coin from ${inputAddress})`)
      const { addressRoot, addrAttr, addressType } = ByronValidator.deconstructAddress(inputAddress)
      if (addressType !== 0) {
        this.logger.debug(`Unsupported address type: ${addressType}. Skipping witness validation for this input.`)
        return
      }
      const addressRootHex = addressRoot.toString('hex')
      const expectedStruct = [0, [0, sign[0]], addrAttr]
      const encodedStruct = Buffer.from(sha3_256.update(
        cbor.encodeCanonical(expectedStruct)).digest())
      const expectedRootHex = blake.blake2bHex(encodedStruct, undefined, 28)
      if (addressRootHex !== expectedRootHex) {
        throw new Error(`Witness does not match! ${JSON.stringify({ addressRootHex, expectedRoot: expectedRootHex })}`)
      }
    })
  }
github icon-project / icon-sdk-js / lib / data / Util.js View on Github external
export function serialize(trasaction) {
	const phraseToSign = generateHashKey(trasaction);
	const hashcode = sha3256.update(phraseToSign).hex();
	return hashcode;
}