Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getAddress(walletObj, network=null, cashAddress=false) {
if (network == null) {
network = bitcoin.networks.mainnet;
}
if (cashAddress == true) {
var publicKey = bitcoreCash.PublicKey(walletObj.publicKey);
var address = new bitcoreCash.Address(publicKey, network);
return (address.toString());
} else {
return (bitcoin.payments.p2pkh({pubkey:walletObj.publicKey, network:network}).address);
}
}
getAddress(walletObj, network="main", cashAddress=false) {
network = network.toLowerCase();
if (cashAddress == true) {
var publicKey = bitcoreCash.PublicKey(walletObj.publicKey);
switch (network) {
case "main":
var address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "mainnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "livenet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "test":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "test3":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "testnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "regtest":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.regtest);
break;
getAddress(walletObj, network="main", cashAddress=false) {
network = network.toLowerCase();
if (cashAddress == true) {
var publicKey = bitcoreCash.PublicKey(walletObj.publicKey);
switch (network) {
case "main":
var address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "mainnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "livenet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "test":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "test3":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "testnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "livenet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "test":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "test3":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "testnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "regtest":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.regtest);
break;
default:
throw (new Error("Unrecognized network \""+network+"\"."));
break;
}
return (address.toString());
} else {
if ((network == "main") || (network == "mainnet") || (network == "livenet")) {
return (this.server.bitcoincash.payments.p2pkh({pubkey:walletObj.publicKey}).address);
} else {
var subNet = this.server.bitcoincash.networks.testnet;
return (this.server.bitcoincash.payments.p2pkh({pubkey:walletObj.publicKey, network:subNet}).address);
}
}
}
var address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "mainnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "livenet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "test":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "test3":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "testnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "regtest":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.regtest);
break;
default:
throw (new Error("Unrecognized network \""+network+"\"."));
break;
}
return (address.toString());
} else {
if ((network == "main") || (network == "mainnet") || (network == "livenet")) {
return (this.server.bitcoincash.payments.p2pkh({pubkey:walletObj.publicKey}).address);
} else {
var subNet = this.server.bitcoincash.networks.testnet;
return (this.server.bitcoincash.payments.p2pkh({pubkey:walletObj.publicKey, network:subNet}).address);
}
export const addrToBCHFormat = address => {
const bchAdr = new bch.Address(address);
const format = bch.Address.CashAddrFormat;
return bchAdr.toString(format);
};