How to use @cennznet/util - 4 common examples

To help you get started, we’ve selected a few @cennznet/util 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 cennznet / runanode / app / renderer / api / api.js View on Github external
getSeedFromWalletAccount = async (
    wallet: TheWallet,
    address: string,
    passphrase: string
  ): Promise => {
    try {
      const originalWallet = this.reloadWallet(wallet);
      await originalWallet.unlock(passphrase);
      assert(wallet.accounts, `missing accounts`);
      assert(address, `missing address`);
      const json = await originalWallet.exportAccount(address, passphrase);
      const decodeMsg = decode(passphrase, hexToU8a(json.encoded));
      let publicKey = null;
      let secretKey = null;
      if (decodeMsg.secretKey.length === 64) {
        publicKey = decodeMsg.publicKey;
        secretKey = decodeMsg.secretKey;
        Logger.debug(`api::getSeedFromWalletAccount decoded length: ${decodeMsg.secretKey.length}`);
      } else {
        // default is sr
        const pair = naclFromSeed(decodeMsg.secretKey);

        publicKey = pair.publicKey;
        secretKey = pair.secretKey;
        Logger.debug(`api::getSeedFromWalletAccount ed : ${pair}`);
      }

      // const { publicKey, secretKey } = decodeMsg;
github cennznet / runanode / app / renderer / api / api.js View on Github external
try {
      const originalWallet = this.reloadWallet(wallet);
      await originalWallet.unlock(passphrase);
      assert(wallet.accounts, `missing accounts`);
      assert(address, `missing address`);
      const json = await originalWallet.exportAccount(address, passphrase);
      const decodeMsg = decode(passphrase, hexToU8a(json.encoded));
      let publicKey = null;
      let secretKey = null;
      if (decodeMsg.secretKey.length === 64) {
        publicKey = decodeMsg.publicKey;
        secretKey = decodeMsg.secretKey;
        Logger.debug(`api::getSeedFromWalletAccount decoded length: ${decodeMsg.secretKey.length}`);
      } else {
        // default is sr
        const pair = naclFromSeed(decodeMsg.secretKey);

        publicKey = pair.publicKey;
        secretKey = pair.secretKey;
        Logger.debug(`api::getSeedFromWalletAccount ed : ${pair}`);
      }

      // const { publicKey, secretKey } = decodeMsg;
      const SEC_LENGTH = 64;
      const SEED_LENGTH = 32;
      const ZERO_STR = '0x00';
      const seedU8a = secretKey.subarray(0, SEC_LENGTH - SEED_LENGTH);
      const seed = u8aToHex(seedU8a);
      assert(publicKey && publicKey.length === 32, 'Expected valid publicKey, 32-bytes');
      assert(secretKey && secretKey.length === 64, 'Expected valid secretKey, 64-bytes');
      assert(seed && seed.length > ZERO_STR.length, 'Expected valid seed, 32-bytes');
      Logger.debug(`api::getSeedFromWalletAccount seed: ${seed.length}`);
github cennznet / runanode / app / renderer / api / api.js View on Github external
Logger.debug(`api::getSeedFromWalletAccount decoded length: ${decodeMsg.secretKey.length}`);
      } else {
        // default is sr
        const pair = naclFromSeed(decodeMsg.secretKey);

        publicKey = pair.publicKey;
        secretKey = pair.secretKey;
        Logger.debug(`api::getSeedFromWalletAccount ed : ${pair}`);
      }

      // const { publicKey, secretKey } = decodeMsg;
      const SEC_LENGTH = 64;
      const SEED_LENGTH = 32;
      const ZERO_STR = '0x00';
      const seedU8a = secretKey.subarray(0, SEC_LENGTH - SEED_LENGTH);
      const seed = u8aToHex(seedU8a);
      assert(publicKey && publicKey.length === 32, 'Expected valid publicKey, 32-bytes');
      assert(secretKey && secretKey.length === 64, 'Expected valid secretKey, 64-bytes');
      assert(seed && seed.length > ZERO_STR.length, 'Expected valid seed, 32-bytes');
      Logger.debug(`api::getSeedFromWalletAccount seed: ${seed.length}`);
      return seed;
    } catch (error) {
      Logger.error('api::getSeedFromWalletAccount error: ' + stringifyError(error));
      throw new GenericApiError();
    }
  };
github cennznet / runanode / app / renderer / api / api.js View on Github external
getAddressFromSeed = async (seed, keyType = 'ed25519') => {
    try {
      const keyring = new SimpleKeyring();
      Logger.debug(`api::getAddressFromSeed seed: ${seed}`);

      const seedHex = hexToU8a(seed);
      const account = await keyring.addFromSeed(seedHex, {}, keyType);
      const address = account.address();
      Logger.debug(`api::getAddressFromSeed: ${address}`);

      return address;
    } catch (error) {
      Logger.error('api::getAddressFromSeed error: ' + stringifyError(error));
      throw new GenericApiError();
    }
  };

@cennznet/util

utils for CENNZnet api

Apache-2.0
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis