How to use the zencashjs.address 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 / 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 / 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 / arizen / app / main.js View on Github external
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);
    }
}
github ZencashOfficial / arizen / app / zenextra.js View on Github external
function isPK(pk) {
    let isPK = true;
    try {
        let pktmp = zencashjs.address.privKeyToPubKey(pk);
    } catch (err) {
        isPK = false;
    }
    return isPK
}
github ZencashOfficial / arizen / app / zenextra.js View on Github external
function isWif(pk) {
    let isWif = true;
    try {
        let pktmp = zencashjs.address.WIFToPrivKey(pk);
    } catch (err) {
        isWif = false;
    }
    return isWif
}
github ZencashOfficial / arizen / app / main.js View on Github external
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]};
}

zencashjs

Dead easy to use Horizen JavaScript based library

MIT
Latest version published 10 months ago

Package Health Score

53 / 100
Full package analysis