How to use zencashjs - 10 common examples

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 / zcommon.js View on Github external
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;
github ZencashOfficial / arizen / app / main.js View on Github external
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);
    }
github ZencashOfficial / arizen / app / zcommon.js View on Github external
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;
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 / arizen / app / main.js View on Github external
});
                }
            }

            // Create transaction
            let txObj = zencashjs.transaction.createRawTx(history, recipients, blockHeight, blockHash);

            // Sign each history transcation
            let index;
            for (let i = 0; i < history.length; i++) {
                index = fromAddresses.indexOf(belongToAddress[i]);
                txObj = zencashjs.transaction.signTx(txObj, i, privateKeys[index], true);
            }

            // Convert it to hex string
            const txHexString = zencashjs.transaction.serializeTx(txObj);
            const txRespData = await apiPost(sendRawTxURL, {rawtx: txHexString});

            finalMessage += `<small><a class="walletListItemDetails transactionExplorer monospace">${txRespData.txid}</a>`;
            finalMessage += "</small><br>\n\n";

            txFinished += 1;
            if (txFinished === chunks.length) {
                event.sender.send("send-finish", "ok", finalMessage);
            }
        }
    }
    catch(e) {
        event.sender.send("send-finish", "error", e.message);
        console.log(e);
    }
});
github ZencashOfficial / zencash-mobile / src / utils / wallet.js View on Github external
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
    }
  })
github ZencashOfficial / zencash-mobile / src / containers / SendPage.js View on Github external
}

    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)
github ZencashOfficial / arizen / app / rpc.js View on Github external
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
    }
}
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)
}

zencashjs

Dead easy to use Horizen JavaScript based library

MIT
Latest version published 11 months ago

Package Health Score

53 / 100
Full package analysis