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