Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
importButton.addEventListener("click", () => {
const name = nameInput.value ? nameInput.value : "";
let pk = privateKeyInput.value;
let importT = dialog.querySelector(".importTorZgetT").checked;
let importZ = dialog.querySelector(".importTorZgetZ").checked;
let checkAddr;
if ((zenextra.isPKorWif(pk) === true && importT) || (zenextra.isPKorSpendingKey(pk) === true && importZ)) {
console.log(name);
console.log(pk);
if (importT) {
if (zenextra.isWif(pk) === true) {
pk = zencashjs.address.WIFToPrivKey(pk);
}
let pubKey = zencashjs.address.privKeyToPubKey(pk, true);
checkAddr = zencashjs.address.pubKeyToAddr(pubKey);
}
if (importZ) {
let secretKey = pk;
if (zenextra.isSpendingKey(pk) === true) {
// pk = spendingKey
secretKey = zenextra.spendingKeyToSecretKey(pk);
pk = secretKey;
}
let a_pk = zencashjs.zaddress.zSecretKeyToPayingKey(secretKey);
let pk_enc = zencashjs.zaddress.zSecretKeyToTransmissionKey(secretKey);
checkAddr = zencashjs.zaddress.mkZAddress(a_pk, pk_enc);
}
let resp = ipcRenderer.sendSync("check-if-address-in-wallet", checkAddr);
let addrExists = resp.exist;
function importOnePK(pk, name = "", isT = true) {
try {
let addr;
if (isT) {
if (pk.length !== 64) {
pk = zencashjs.address.WIFToPrivKey(pk);
}
const pub = zencashjs.address.privKeyToPubKey(pk, true);
addr = zencashjs.address.pubKeyToAddr(pub);
} else {
if (pk.length !== 64) {
pk = zenextra.spendingKeyToSecretKey(pk); // pk = spendingKey
}
let secretKey = pk;
let aPk = zencashjs.zaddress.zSecretKeyToPayingKey(secretKey);
let encPk = zencashjs.zaddress.zSecretKeyToTransmissionKey(secretKey);
addr = zencashjs.zaddress.mkZAddress(aPk, encPk);
}
sqlRun("insert or ignore into wallet (pk, addr, lastbalance, name) values (?, ?, 0, ?)", pk, addr, name);
} catch (err) {
console.log(`Invalid private key on line in private keys file : `, err);
}
importButton.addEventListener("click", () => {
const name = nameInput.value ? nameInput.value : "";
let pk = privateKeyInput.value;
let importT = dialog.querySelector(".importTorZgetT").checked;
let importZ = dialog.querySelector(".importTorZgetZ").checked;
let checkAddr;
if ((zenextra.isPKorWif(pk) === true && importT) || (zenextra.isPKorSpendingKey(pk) === true && importZ)) {
console.log(name);
console.log(pk);
if (importT) {
if (zenextra.isWif(pk) === true) {
pk = zencashjs.address.WIFToPrivKey(pk);
}
let pubKey = zencashjs.address.privKeyToPubKey(pk, true);
checkAddr = zencashjs.address.pubKeyToAddr(pubKey);
}
if (importZ) {
let secretKey = pk;
if (zenextra.isSpendingKey(pk) === true) {
// pk = spendingKey
secretKey = zenextra.spendingKeyToSecretKey(pk);
pk = secretKey;
}
let a_pk = zencashjs.zaddress.zSecretKeyToPayingKey(secretKey);
let pk_enc = zencashjs.zaddress.zSecretKeyToTransmissionKey(secretKey);
checkAddr = zencashjs.zaddress.mkZAddress(a_pk, pk_enc);
}
let resp = ipcRenderer.sendSync("check-if-address-in-wallet", checkAddr);
let addrExists = resp.exist;
var secretItems = chain.getAll().map(function (x) {
// Get private key (WIF)
const pkWIF = chain.derive(x).keyPair.toWIF()
// Private key
const privKey = zencashjs.address.WIFToPrivKey(pkWIF)
// Public key
const pubKey = zencashjs.address.privKeyToPubKey(privKey, true)
// Address
const address = zencashjs.address.pubKeyToAddr(pubKey)
return {
address,
privateKey: pkWIF
}
})
}
if (typeof parseInt(fee) !== 'number' || fee === '') {
errString += TRANSLATIONS[CUR_LANG].SendPage.invalidFee
errString += '\n\n'
}
// Alert errors
if (errString !== '') {
alert(errString)
this.setProgressValue(0)
return
}
// Private key
const senderPrivateKey = zencashjs.address.WIFToPrivKey(this.props.context.privateKey)
// Get previous transactions
const prevTxURL = urlAppend(this.props.settings.insightAPI, 'addr/') + senderAddress + '/utxo'
const infoURL = urlAppend(this.props.settings.insightAPI, 'status?q=getInfo')
const sendRawTxURL = urlAppend(this.props.settings.insightAPI, 'tx/send')
// Building our transaction TXOBJ
// How many satoshis do we have so far
var satoshisSoFar = 0
var history = []
var recipients = [{ address: recipientAddress, satoshis: satoshisToSend }]
// Get previous unspent transactions
axios.get(prevTxURL)
.then((txResp) => {
this.setProgressValue(25)
async function getNewTaddressPK(nameAddress) {
let resp = await rpcCallResultSync("getnewaddress", []);
let tAddress = resp.output;
let newResp = await rpcCallResultSync("dumpprivkey", [tAddress]); // let wif = newResp.output;
if (newResp.isOK) {
let pkTaddress = zencashjs.address.WIFToPrivKey(newResp.output);
ipcRenderer.send("DB-insert-address", nameAddress, pkTaddress, tAddress);
return tAddress
}
}
function importOnePK(pk, name = "") {
try {
if (pk.length !== 64) {
pk = zencashjs.address.WIFToPrivKey(pk);
}
const pub = zencashjs.address.privKeyToPubKey(pk, true);
const addr = zencashjs.address.pubKeyToAddr(pub);
sqlRun("insert or ignore into wallet (pk, addr, lastbalance, name) values (?, ?, 0, ?)", pk, addr, name);
} catch (err) {
console.log(`Invalid private key on line in private keys file : `, err);
}
}
function isPK(pk) {
let isPK = true;
try {
let pktmp = zencashjs.address.privKeyToPubKey(pk);
} catch (err) {
isPK = false;
}
return isPK
}
function isWif(pk) {
let isWif = true;
try {
let pktmp = zencashjs.address.WIFToPrivKey(pk);
} catch (err) {
isWif = false;
}
return isWif
}
function getNewAddress(name) {
let pk;
let addr;
let privateKeys = generateNewAddress(1, userInfo.pass);
pk = zencashjs.address.WIFToPrivKey(privateKeys[0]);
addr = zencashjs.address.pubKeyToAddr(zencashjs.address.privKeyToPubKey(pk, true));
userInfo.walletDb.run("INSERT INTO wallet VALUES (?,?,?,?,?)", [null, pk, addr, 0, name]);
saveWallet();
return {addr: addr, name: name, lastbalance: 0, pk: pk, wif: privateKeys[0]};
}