How to use the @zilliqa-js/crypto.getPubKeyFromPrivateKey function in @zilliqa-js/crypto

To help you get started, we’ve selected a few @zilliqa-js/crypto 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 Zilliqa / nucleus-wallet / src / redux / zil / sagas.ts View on Github external
export function* accessWalletSaga(action) {
  // debounce by 500ms
  yield delay(500);
  try {
    const { payload } = action;
    const privateKey: string = payload.privateKey;
    const address = getAddressFromPrivateKey(privateKey);
    const publicKey = getPubKeyFromPrivateKey(privateKey);

    const { zilliqa } = yield select(getZilState);
    zilliqa.wallet.addByPrivateKey(privateKey);

    yield put({
      type: consts.ACCESS_WALLET_SUCCEEDED,
      payload: {
        address,
        publicKey,
        privateKey
      }
    });
  } catch (error) {
    console.log(error);
    yield put({ type: consts.ACCESS_WALLET_FAILED });
  }
github zilpay / zil-pay / packages / background / services / blockchain / zilliqa.js View on Github external
async getAccountByPrivateKey(importPrivateKey, index = 0) {
    if (!verifyPrivateKey(importPrivateKey)) {
      throw new Error(errorsCode.WrongPrivateKey)
    }

    const account = {
      privateKey: importPrivateKey,
      publicKey: getPubKeyFromPrivateKey(importPrivateKey),
      address: getAddressFromPrivateKey(importPrivateKey)
    }
    const { result } = await this.getBalance(account.address)

    account.address = toChecksumAddress(account.address)

    return {
      ...account,
      index,
      balance: result
    }
  }
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-account / src / account.ts View on Github external
constructor(privateKey: string) {
    this.privateKey = this.normalizePrivateKey(privateKey);
    this.publicKey = zcrypto.getPubKeyFromPrivateKey(this.privateKey);
    this.address = zcrypto.getAddressFromPublicKey(this.publicKey);
    this.bech32Address = zcrypto.toBech32Address(this.address);
  }
github Zilliqa / nucleus-wallet / functions / src / index.ts View on Github external
const { Long, bytes, units, BN } = require('@zilliqa-js/util');
const {
  getAddressFromPrivateKey,
  getPubKeyFromPrivateKey,
  isValidChecksumAddress
} = require('@zilliqa-js/crypto');
const { Transaction } = require('@zilliqa-js/account');
const { HTTPProvider, RPCMethod } = require('@zilliqa-js/core');

const DEFAULT_TRANSFER_AMOUNT: number = 300;
const PENALTY_TRANSFER_AMOUNT: number = 10;
const PENALTY_TIME: number = 1000 * 60 * 60 * 2;

const RECAPTCHA_SECRET = functions.config().faucet.recaptcha_secret;
const PRIVATE_KEY = functions.config().faucet.private_key;
const PUBLIC_KEY = getPubKeyFromPrivateKey(PRIVATE_KEY);
const ADDRESS = getAddressFromPrivateKey(PRIVATE_KEY);

const CHAIN_ID: number =
  process.env.REACT_APP_CHAIN_ID !== undefined ? parseInt(process.env.REACT_APP_CHAIN_ID, 10) : 0;
const MSG_VERSION: number =
  process.env.REACT_APP_MSG_VERSION !== undefined
    ? parseInt(process.env.REACT_APP_MSG_VERSION, 10)
    : 0;
const VERSION = bytes.pack(CHAIN_ID, MSG_VERSION);
const NODE_URL: string = process.env.REACT_APP_NODE_URL || '';

const provider = new HTTPProvider(NODE_URL);
const zilliqa = new Zilliqa(NODE_URL, provider);

zilliqa.wallet.addByPrivateKey(PRIVATE_KEY);
github Zilliqa / nucleus-wallet / src / contexts / zil-context / index.tsx View on Github external
public accessWallet = (privateKey: string) => {
    try {
      const address = getAddressFromPrivateKey(privateKey);
      const publicKey = getPubKeyFromPrivateKey(privateKey);
      const { wallet } = this.state;
      wallet.addByPrivateKey(privateKey);

      this.setState({
        isAuth: true,
        privateKey,
        address,
        publicKey,
        wallet
      });
    } catch (error) {
      this.setState({ isAuth: false });
    }
  };