How to use the zencashjs.zaddress function in zencashjs

To help you get started, we’ve selected a few zencashjs 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 ZencashOfficial / arizen / app / main.js View on Github external
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);
    }
}
github ZencashOfficial / arizen / app / zcommon.js View on Github external
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;

                    if (addrExists === true) {
                        alert(tr("wallet.importSinglePrivateKey.warningNotValidAddress", "Address exist in your wallet"))
                    } else {
                        ipcRenderer.send("import-single-key", name, pk, importT);
                        alert(tr("warmingMessages.userWarningImportPK", userWarningImportPK));
                        if (importZ) {
                            alert(tr("warmingMessages.userWarningImportPkUserZendRescan", userWarningImportPkUserZendRescan));
                        }
                        dialog.close();
github ZencashOfficial / zenchat / src / utils / zaddress.js View on Github external
function secretCodeToZAddr (secretCode) {
  var z_secretKey = zencashjs.zaddress.mkZSecretKey(secretCode)

  // spending key (wif)
  var spending_key = zencashjs.zaddress.zSecretKeyToSpendingKey(z_secretKey)

  // paying key
  var a_pk = zencashjs.zaddress.zSecretKeyToPayingKey(z_secretKey)

  var pk_enc = zencashjs.zaddress.zSecretKeyToTransmissionKey(z_secretKey)

  // z address
  return zencashjs.zaddress.mkZAddress(a_pk, pk_enc)
}
github ZencashOfficial / arizen / app / zcommon.js View on Github external
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;

                    if (addrExists === true) {
                        alert(tr("wallet.importSinglePrivateKey.warningNotValidAddress", "Address exist in your wallet"))
                    } else {
                        ipcRenderer.send("import-single-key", name, pk, importT);
                        alert(tr("warmingMessages.userWarningImportPK", userWarningImportPK));
                        if (importZ) {
                            alert(tr("warmingMessages.userWarningImportPkUserZendRescan", userWarningImportPkUserZendRescan));
                        }
                        dialog.close();
                    }
github ZencashOfficial / arizen / app / main.js View on Github external
fs.open(filename, "w", 0o600, (err, fd) => {
            if (err) {
                console.error(`Couldn't open "${filename}" for writing: `, err);
            } else {
                const keys = sqlSelectObjects("select pk, addr from wallet where length(addr)=35");
                for (let k of keys) {
                    if (zenextra.isPK(k.pk)) {
                        const wif = zencashjs.address.privKeyToWIF(k.pk, true);
                        fs.write(fd, wif + " " + k.addr + "\n");
                    }
                }
                const zkeys = sqlSelectObjects("select pk, addr from wallet where length(addr)=95");
                for (let k of zkeys) {
                    if (zenextra.isPK(k.pk)) {
                        const spendingKey = zencashjs.zaddress.zSecretKeyToSpendingKey(k.pk);
                        fs.write(fd, spendingKey + " " + k.addr + "\n");
                    }
                }
            }
        });
    }
github ZencashOfficial / zenchat / src / utils / zaddress.js View on Github external
function secretCodeToWIFKey (secretCode) {
  var z_secretKey = zencashjs.zaddress.mkZSecretKey(secretCode)
  return zencashjs.zaddress.zSecretKeyToSpendingKey(z_secretKey)
}
github ZencashOfficial / arizen / app / rpc.js View on Github external
async function importPKinSN(pk, address) {
    if (pk === undefined) {
        return {output: "No PK given.", status: "ok"}
    } else {
        let cmd;
        if (zenextra.isZeroAddr(address)) {
            cmd = "z_importkey";
            if (zenextra.isPK(pk)) {
                pk = zencashjs.zaddress.zSecretKeyToSpendingKey(pk);
            }
        }
        if (zenextra.isTransaparentAddr(address)) {
            cmd = "importprivkey";
            if (!zenextra.isWif(pk)) {
                pk = zencashjs.address.privKeyToWIF(pk);
            }
        }
        return await rpcCallResultSync(cmd, [pk, "no"]);
    }
}

zencashjs

Dead easy to use Horizen JavaScript based library

MIT
Latest version published 10 months ago

Package Health Score

53 / 100
Full package analysis