How to use the @zilliqa-js/util.validation.isPrivateKey function in @zilliqa-js/util

To help you get started, we’ve selected a few @zilliqa-js/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 zilpay / zil-pay / src / controllers / services / blockchain / zilliqa.js View on Github external
async singTransaction(txData, seedOrPrivateKey, index, currentNonce, msgId) {
    /**
     * @param {txData}: Object with data about transaction.
     * @param seedOrPrivateKey: type String, seed phrase or private key.
     * @param index: type Number, the index of address from seed phrase.
     * @prarm msgId: Message version network.
     */

    // importing account from private key or seed phrase. //
    if (validation.isPrivateKey(seedOrPrivateKey)) {
      this.wallet.addByPrivateKey(seedOrPrivateKey);
    } else {
      this.wallet.addByMnemonic(seedOrPrivateKey, index);
    }

    const pubKey = this.wallet.defaultAccount.publicKey;
    const balance = await this.getBalance(
      this.wallet.defaultAccount.address
    );
    let {
      amount,   // Amount of zil. type Number.
      code,     // Value contract code. type String.
      data,     // Call contract transition. type Object.
      gasLimit,
      gasPrice,
      toAddr,   // Recipient address. type String.
github zilpay / zil-pay / extension / controllers / services / blockchain / zilliqa.js View on Github external
async singTransaction(txData, seedOrPrivateKey, index, currentNonce) {
    /**
     * @param {txData}: Object with data about transaction.
     * @param seedOrPrivateKey: type String, seed phrase or private key.
     * @param index: type Number, the index of address from seed phrase.
     * @prarm msgId: Message version network.
     */

    // importing account from private key or seed phrase. //
    if (validation.isPrivateKey(seedOrPrivateKey)) {
      this.wallet.addByPrivateKey(seedOrPrivateKey);
    } else {
      this.wallet.addByMnemonic(seedOrPrivateKey, index);
    }

    const zilTxData = await this.buildTxParams(
      txData,
      this.wallet.defaultAccount.address,
      currentNonce,
      this.wallet.defaultAccount.publicKey
    );
    // Sign transaction by current account. //
    const { txParams, payload } = await this.wallet.sign(zilTxData);
    
    if (txData.isBroadcast && typeof txData.isBroadcast === 'boolean') {
      payload.Info = 'Non-broadcast';
github zilpay / zil-pay / packages / background / services / blockchain / zilliqa.js View on Github external
async singTransaction(txData, seedOrPrivateKey, index, currentNonce) {
    // importing account from private key or seed phrase. //
    if (validation.isPrivateKey(seedOrPrivateKey)) {
      this.wallet.addByPrivateKey(seedOrPrivateKey)
    } else {
      this.wallet.addByMnemonic(seedOrPrivateKey, index)
    }

    const zilTxData = await this.buildTxParams(
      txData,
      this.wallet.defaultAccount.address,
      currentNonce,
      this.wallet.defaultAccount.publicKey
    )
    // Sign transaction by current account. //
    const { txParams, payload } = await this.wallet.sign(zilTxData)

    if (new TypeChecker(txData.isBroadcast).isBoolean) {
      payload.Info = 'Non-broadcast'
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-crypto / src / util.ts View on Github external
export const normalizePrivateKey = (privateKey: string): string => {
  try {
    if (!validation.isPrivateKey(privateKey)) {
      throw new Error('Private key is not correct');
    }
    const normalized = privateKey.toLowerCase().replace('0x', '');
    if (!verifyPrivateKey(normalized)) {
      throw new Error('Private key is not correct');
    }
    return normalized;
  } catch (error) {
    throw error;
  }
};