How to use the blakejs.blake2bHex function in blakejs

To help you get started, we’ve selected a few blakejs 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 paritytech / srml-contracts-waterfall / tests / utils.ts View on Github external
export async function getContractStorage(
  api: ApiPromise,
  contractAddress: Address,
  storageKey: Uint8Array
): Promise {
  const contractInfo = await api.query.contracts.contractInfoOf(
    contractAddress
  );
  // Return the value of the contracts storage
  const storageKeyBlake2b = blake.blake2bHex(storageKey, null, 32);
  return await api.rpc.state.getChildStorage(
    (contractInfo as Option).unwrap().asAlive.trieId,
    '0x' + storageKeyBlake2b
  );
}
github Emurgo / yoroi-frontend / app / api / utilityKey / index.js View on Github external
_setRootKeyFromPublicKey = async (
    publicKey: string
  ): Promise => {
    try {
      const blakeHash = blakejs.blake2bHex(publicKey, null, 32);
      const mnemonicFromSeed = entropyToMnemonic(blakeHash);
      const entropy = RustModule.Wallet.Entropy.from_english_mnemonics(mnemonicFromSeed);
      this.rootKey = RustModule.Wallet.PrivateKey.new(entropy, '');
    } catch (error) {
      Logger.error('UtilityKeyApi::rootKeyFromPublicKey error: ' + stringifyError(error));
      throw new GenericApiError();
    }
  };
github Emurgo / yoroi-frontend / app / api / ada / lib / cardanoCrypto / plate.js View on Github external
export function createAccountPlate(accountPubHash: string): WalletAccountNumberPlate {
  const hash = blakejs.blake2bHex(accountPubHash);
  const [a, b, c, d] = crc32(hash);
  const alpha = `ABCDEJHKLNOPSTXZ`;
  const letters = x => `${alpha[Math.floor(x / 16)]}${alpha[x % 16]}`;
  const numbers = `${((c << 8) + d) % 10000}`.padStart(4, '0');
  const id = `${letters(a)}${letters(b)}-${numbers}`;
  return { hash, id };
}
github Emurgo / tangata-manu / src / blockchain / utils.js View on Github external
const packRawTxIdAndBody = (decodedTxBody): [TxIdHexType, TxBodyHexType] => {
  if (!decodedTxBody) {
    throw new Error('Cannot decode inputs from undefined transaction!')
  }
  try {
    const [inputs, outputs, attributes] = decodedTxToBase(decodedTxBody)
    const cborEncoder: CborEncoder = selectCborEncoder(outputs)
    const enc = cborEncoder.encode([
      new CborIndefiniteLengthArray(inputs, cborEncoder),
      new CborIndefiniteLengthArray(outputs, cborEncoder),
      attributes,
    ])
    const txId = blake.blake2bHex(enc, null, 32)
    const txBody = enc.toString('hex')
    return [txId, txBody]
  } catch (e) {
    throw new Error(`Failed to convert raw transaction to ID! ${JSON.stringify(e)}`)
  }
}
github Emurgo / tangata-manu / src / entities / shelley-validator.js View on Github external
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 vechain / thorify / src / utils / crypto.ts View on Github external
export const hash = function(input: string | Buffer): string {
  return "0x" + blake.blake2bHex(input, null, 32);
};
github Emurgo / tangata-manu / src / blockchain / utils.js View on Github external
const headerToId = (header, type: number) => {
  const headerData = cbor.encode([type, header])
  const id = blake.blake2bHex(headerData, null, 32)
  return id
}
github Emurgo / tangata-manu / src / entities / github-loader.js View on Github external
const grouped = _.chain(mapped).groupBy('key').mapValues((vs, key) => {
      const { json: jsonEntry, sig: sigEntry } = _.keyBy(vs, 'ext')
      if (!jsonEntry) {
        this.logger.warn(`[GitHubLoader] No JSON found for key: ${key}! Ignoring`)
        return null
      } else if (!sigEntry) {
        this.logger.warn(`[GitHubLoader] No SIG found for key: ${key} (JSON=${jsonEntry.text})! Ignoring`)
        return null
      }
      const [json, sig] = [jsonEntry.text, sigEntry.text]
      try {
        const hash = blake.blake2bHex(`${json}:${sig}`, null, 32)
        return  { json: JSON.parse(json), sig, hash }
      } catch (e) {
        this.logger.warn(`[GitHubLoader] Failed to parse json from: ${json}`, e)
        return null
      }
    }).pickBy(Boolean).value()
    const entries = Object.entries(grouped).map(([owner, { json, sig, hash }]) => {

blakejs

Pure Javascript implementation of the BLAKE2b and BLAKE2s hash functions

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis