How to use blakejs - 10 common examples

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 vitorcremonez / nano-paper-wallet / src / helpers / RaiBlocksGenerator.js View on Github external
_generatePair(seed, accountIndex = 0) {
        if (!this._isValidSeed(seed)) {
            alert("This is not a valid SEED!");
            return null;
        }

        if(!this._isValidIndexAccount(accountIndex)) {
            alert("Invalid account index!");
            return null;
        }

        let index = hex_uint8(dec2hex(accountIndex, 4)); // 00000000 - FFFFFFFF
        let context = blake.blake2bInit(32);
        blake.blake2bUpdate(context, hex_uint8(seed));
        blake.blake2bUpdate(context, index);
        let key = blake.blake2bFinal(context);

        return {
            public_key: accountFromHexKey(uint8_hex(nacl.sign.keyPair.fromSecretKey(key).publicKey)),
            private_key: uint8_hex(key),
        }
    }
github vitorcremonez / nano-paper-wallet / src / helpers / RaiBlocksGenerator.js View on Github external
_generatePair(seed, accountIndex = 0) {
        if (!this._isValidSeed(seed)) {
            alert("This is not a valid SEED!");
            return null;
        }

        if(!this._isValidIndexAccount(accountIndex)) {
            alert("Invalid account index!");
            return null;
        }

        let index = hex_uint8(dec2hex(accountIndex, 4)); // 00000000 - FFFFFFFF
        let context = blake.blake2bInit(32);
        blake.blake2bUpdate(context, hex_uint8(seed));
        blake.blake2bUpdate(context, index);
        let key = blake.blake2bFinal(context);

        return {
            public_key: accountFromHexKey(uint8_hex(nacl.sign.keyPair.fromSecretKey(key).publicKey)),
            private_key: uint8_hex(key),
        }
    }
github vitorcremonez / nano-paper-wallet / src / helpers / RaiBlocksGenerator.js View on Github external
_generatePair(seed, accountIndex = 0) {
        if (!this._isValidSeed(seed)) {
            alert("This is not a valid SEED!");
            return null;
        }

        if(!this._isValidIndexAccount(accountIndex)) {
            alert("Invalid account index!");
            return null;
        }

        let index = hex_uint8(dec2hex(accountIndex, 4)); // 00000000 - FFFFFFFF
        let context = blake.blake2bInit(32);
        blake.blake2bUpdate(context, hex_uint8(seed));
        blake.blake2bUpdate(context, index);
        let key = blake.blake2bFinal(context);

        return {
            public_key: accountFromHexKey(uint8_hex(nacl.sign.keyPair.fromSecretKey(key).publicKey)),
            private_key: uint8_hex(key),
        }
    }
github chriscohoat / rai-wallet / src / Wallet.js View on Github external
label: key.label,
          color: key.color,
          secretKey: uint8_hex(key.priv),
        });
        break;
      default: throw "Unsupported key type"
      }
    }

    pack = JSON.stringify(pack);
    pack = stringToHex(pack);
    pack = new Buffer(pack, 'hex');

    var context = blake.blake2bInit(32);
    blake.blake2bUpdate(context, pack);
    var checksum = blake.blake2bFinal(context);

    var salt = new Buffer(nacl.randomBytes(16));
    var key = pbkdf2.pbkdf2Sync(passPhrase, salt, iterations, 32, 'sha1');


    var options = { mode: AES.CBC, padding: Iso10126 };
    var encryptedBytes = AES.encrypt(pack, key, salt, options);


    var payload = Buffer.concat([new Buffer(checksum), salt, encryptedBytes]);

    // decrypt to check if wallet was corrupted during ecryption somehow
    if(api.decryptAndCheck(payload).toString('hex') === false)
      return api.pack(); // try again, shouldnt happen often
    return payload.toString('hex');
  }
github vacuumlabs / adalite / utils.js View on Github external
exports.addressHash = function(input) {
  const serializedInput = cbor.encode(input)

  const firstHash = new Buffer(sha3256(serializedInput), 'hex')

  const context = blake2.blake2bInit(28) // blake2b-224
  blake2.blake2bUpdate(context, firstHash)

  return new Buffer(blake2.blake2bFinal(context)).toString('hex')
}
github vitorcremonez / nano-paper-wallet / src / helpers / RaiBlocksGenerator.js View on Github external
_generatePair(seed, accountIndex = 0) {
        if (!this._isValidSeed(seed)) {
            alert("This is not a valid SEED!");
            return null;
        }

        if(!this._isValidIndexAccount(accountIndex)) {
            alert("Invalid account index!");
            return null;
        }

        let index = hex_uint8(dec2hex(accountIndex, 4)); // 00000000 - FFFFFFFF
        let context = blake.blake2bInit(32);
        blake.blake2bUpdate(context, hex_uint8(seed));
        blake.blake2bUpdate(context, index);
        let key = blake.blake2bFinal(context);

        return {
            public_key: accountFromHexKey(uint8_hex(nacl.sign.keyPair.fromSecretKey(key).publicKey)),
            private_key: uint8_hex(key),
        }
    }
github multiformats / js-multihashing-async / src / blake.js View on Github external
const { Buffer } = require('buffer')
const blake = require('blakejs')

const minB = 0xb201
const minS = 0xb241

const blake2b = {
  init: blake.blake2bInit,
  update: blake.blake2bUpdate,
  digest: blake.blake2bFinal
}

const blake2s = {
  init: blake.blake2sInit,
  update: blake.blake2sUpdate,
  digest: blake.blake2sFinal
}

// Note that although this function doesn't do any asynchronous work, we mark
// the function as async because it must return a Promise to match the API
// for other functions that do perform asynchronous work (see sha.browser.js)
// eslint-disable-next-line
const makeB2Hash = (size, hf) => async (data) => {
  const ctx = hf.init(size, null)
  hf.update(ctx, data)
  return Buffer.from(hf.digest(ctx))
}

module.exports = (table) => {
  for (let i = 0; i < 64; i++) {
    table[minB + i] = makeB2Hash(i + 1, blake2b)
  }
github multiformats / js-multihashing-async / src / blake.js View on Github external
'use strict'

const { Buffer } = require('buffer')
const blake = require('blakejs')

const minB = 0xb201
const minS = 0xb241

const blake2b = {
  init: blake.blake2bInit,
  update: blake.blake2bUpdate,
  digest: blake.blake2bFinal
}

const blake2s = {
  init: blake.blake2sInit,
  update: blake.blake2sUpdate,
  digest: blake.blake2sFinal
}

// Note that although this function doesn't do any asynchronous work, we mark
// the function as async because it must return a Promise to match the API
// for other functions that do perform asynchronous work (see sha.browser.js)
// eslint-disable-next-line
const makeB2Hash = (size, hf) => async (data) => {
  const ctx = hf.init(size, null)
  hf.update(ctx, data)
  return Buffer.from(hf.digest(ctx))
}

module.exports = (table) => {
  for (let i = 0; i < 64; i++) {
github multiformats / js-multihashing-async / src / blake.js View on Github external
const { Buffer } = require('buffer')
const blake = require('blakejs')

const minB = 0xb201
const minS = 0xb241

const blake2b = {
  init: blake.blake2bInit,
  update: blake.blake2bUpdate,
  digest: blake.blake2bFinal
}

const blake2s = {
  init: blake.blake2sInit,
  update: blake.blake2sUpdate,
  digest: blake.blake2sFinal
}

// Note that although this function doesn't do any asynchronous work, we mark
// the function as async because it must return a Promise to match the API
// for other functions that do perform asynchronous work (see sha.browser.js)
// eslint-disable-next-line
const makeB2Hash = (size, hf) => async (data) => {
  const ctx = hf.init(size, null)
  hf.update(ctx, data)
  return Buffer.from(hf.digest(ctx))
}

module.exports = (table) => {
  for (let i = 0; i < 64; i++) {
    table[minB + i] = makeB2Hash(i + 1, blake2b)

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