Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 });
}
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
}
}
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);
}
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);
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 });
}
};