@polkadot/util-crypto#keccakAsU8a TypeScript Examples

The following examples show how to use @polkadot/util-crypto#keccakAsU8a. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts    From crust-apps with Apache License 2.0 6 votes vote down vote up
// hash a message for use in signature recovery, adding the standard Ethereum header
export function hashMessage (message: string): Buffer {
  const expanded = stringToU8a(`\x19Ethereum Signed Message:\n${message.length.toString()}${message}`);
  const hashed = keccakAsU8a(expanded);

  return u8aToBuffer(hashed);
}
Example #2
Source File: identity.ts    From contracts-ui with GNU General Public License v3.0 6 votes vote down vote up
export function getPrivateKeyFromPair(pair: KeyringPair, secretText = 'asdf'): PrivateKey {
  // avoid sending the raw secret by hashing it first
  const secret = bcrypt.hashSync(secretText, 10);
  const message = generateMessageForEntropy(pair.address, 'contracts-ui', secret);
  const signedText = pair.sign(message);
  const hash = keccakAsU8a(signedText);

  if (hash === null) {
    throw new Error('No account is provided. Please provide an account to this application.');
  }

  if (hash.length !== 32) {
    throw new Error('Hash of signature is not the correct size! Something went wrong!');
  }
  const identity = PrivateKey.fromRawEd25519Seed(hash);

  // Your app can now use this identity for generating a user Mailbox, Threads, Buckets, etc
  return identity;
}
Example #3
Source File: customHashers.ts    From parity-bridges-ui with GNU General Public License v3.0 5 votes vote down vote up
function blake2Keccak256Hasher(data: Uint8Array) {
  return u8aConcat(blake2AsU8a(data), keccakAsU8a(data));
}