DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning");
DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
DOM.phrase = $(".phrase");
+ DOM.phraseSplit = $(".phraseSplit");
+ DOM.phraseSplitWarn = $(".phraseSplitWarn");
DOM.passphrase = $(".passphrase");
DOM.generateContainer = $(".generate-container");
DOM.generate = $(".generate");
if (phraseChangeTimeoutEvent != null) {
clearTimeout(phraseChangeTimeoutEvent);
}
- phraseChangeTimeoutEvent = setTimeout(phraseChanged, 400);
+ phraseChangeTimeoutEvent = setTimeout(function() {
+ phraseChanged();
+ var entropy = mnemonic.toRawEntropyBin(DOM.phrase.val());
+ if (entropy !== null) {
+ DOM.entropyMnemonicLength.val("raw");
+ DOM.entropy.val(entropy);
+ }
+ }, 400);
}
function phraseChanged() {
calcForDerivationPath();
// Show the word indexes
showWordIndexes();
+ writeSplitPhrase(phrase);
}
function tabChanged() {
clearDisplay();
clearEntropyFeedback();
DOM.phrase.val("");
+ DOM.phraseSplit.val("");
showValidationError("Blank entropy");
return;
}
showPending();
// Clear existing mnemonic and passphrase
DOM.phrase.val("");
+ DOM.phraseSplit.val("");
DOM.passphrase.val("");
seed = null;
if (rootKeyChangedTimeoutEvent != null) {
function calcBip32RootKeyFromSeed(phrase, passphrase) {
seed = mnemonic.toSeed(phrase, passphrase);
bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network);
+ if(isGRS())
+ bip32RootKey = groestlcoinjs.HDNode.fromSeedHex(seed, network);
+
}
function calcBip32RootKeyFromBase58(rootKeyBase58) {
+ if(isGRS()) {
+ calcBip32RootKeyFromBase58GRS(rootKeyBase58);
+ return;
+ }
// try parsing with various segwit network params since this extended
// key may be from any one of them.
if (networkHasSegwit()) {
bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
}
+ function calcBip32RootKeyFromBase58GRS(rootKeyBase58) {
+ // try parsing with various segwit network params since this extended
+ // key may be from any one of them.
+ if (networkHasSegwit()) {
+ var n = network;
+ if ("baseNetwork" in n) {
+ n = bitcoinjs.bitcoin.networks[n.baseNetwork];
+ }
+ // try parsing using base network params
+ try {
+ bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n);
+ return;
+ }
+ catch (e) {}
+ // try parsing using p2wpkh params
+ if ("p2wpkh" in n) {
+ try {
+ bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
+ return;
+ }
+ catch (e) {}
+ }
+ // try parsing using p2wpkh-in-p2sh network params
+ if ("p2wpkhInP2sh" in n) {
+ try {
+ bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
+ return;
+ }
+ catch (e) {}
+ }
+ }
+ // try the network params as currently specified
+ bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network);
+ }
+
function calcBip32ExtendedKey(path) {
// Check there's a root key to derive from
if (!bip32RootKey) {
extendedKey = extendedKey.derive(index);
}
}
- return extendedKey
+ return extendedKey;
}
function showValidationError(errorText) {
}
function validateRootKey(rootKeyBase58) {
+ if(isGRS())
+ return validateRootKeyGRS(rootKeyBase58);
+
// try various segwit network params since this extended key may be from
// any one of them.
if (networkHasSegwit()) {
return "";
}
+ function validateRootKeyGRS(rootKeyBase58) {
+ // try various segwit network params since this extended key may be from
+ // any one of them.
+ if (networkHasSegwit()) {
+ var n = network;
+ if ("baseNetwork" in n) {
+ n = bitcoinjs.bitcoin.networks[n.baseNetwork];
+ }
+ // try parsing using base network params
+ try {
+ groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n);
+ return "";
+ }
+ catch (e) {}
+ // try parsing using p2wpkh params
+ if ("p2wpkh" in n) {
+ try {
+ groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
+ return "";
+ }
+ catch (e) {}
+ }
+ // try parsing using p2wpkh-in-p2sh network params
+ if ("p2wpkhInP2sh" in n) {
+ try {
+ groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
+ return "";
+ }
+ catch (e) {}
+ }
+ }
+ // try the network params as currently specified
+ try {
+ groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network);
+ }
+ catch (e) {
+ return "Invalid root key";
+ }
+ return "";
+ }
+
function getDerivationPath() {
if (bip44TabSelected()) {
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
return false;
}
+ function isGRS() {
+ return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet";
+ }
+
+ function isELA() {
+ return networks[DOM.network.val()].name == "ELA - Elastos"
+ }
+
function displayBip44Info() {
// Get the derivation path for the account
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
var accountExtendedKey = calcBip32ExtendedKey(path);
var accountXprv = accountExtendedKey.toBase58();
var accountXpub = accountExtendedKey.neutered().toBase58();
+
// Display the extended keys
DOM.bip44accountXprv.val(accountXprv);
DOM.bip44accountXpub.val(accountXpub);
+
+ if (isELA()) {
+ displayBip44InfoForELA();
+ }
}
function displayBip49Info() {
clearAddressesList();
var initialAddressCount = parseInt(DOM.rowsToAdd.val());
displayAddresses(0, initialAddressCount);
+
+ if (isELA()) {
+ displayBip32InfoForELA();
+ }
}
function displayAddresses(start, total) {
var useUncompressed = useBip38;
if (useUncompressed) {
keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false });
+ if(isGRS())
+ keyPair = new groestlcoinjs.ECPair(keyPair.d, null, { network: network, compressed: false });
+
}
// get address
var address = keyPair.getAddress().toString();
privkey = keyPair.toWIF();
// BIP38 encode private key if required
if (useBip38) {
- privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
- console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
- });
+ if(isGRS())
+ privkey = groestlcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
+ console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
+ }, null, networks[DOM.network.val()].name.includes("Testnet"));
+ else
+ privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
+ console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
+ });
}
}
// get pubkey
indexText = indexText + "'";
}
// Ethereum values are different
- if ((networks[DOM.network.val()].name == "ETH - Ethereum")
- || (networks[DOM.network.val()].name == "ETC - Ethereum Classic")
- || (networks[DOM.network.val()].name == "PIRL - Pirl")
- || (networks[DOM.network.val()].name == "MIX - MIX")
- || (networks[DOM.network.val()].name == "MUSIC - Musicoin")
- || (networks[DOM.network.val()].name == "POA - Poa")
- || (networks[DOM.network.val()].name == "EXP - Expanse")
- || (networks[DOM.network.val()].name == "CLO - Callisto")
- || (networks[DOM.network.val()].name == "DXN - DEXON")
- || (networks[DOM.network.val()].name == "ELLA - Ellaism")
- || (networks[DOM.network.val()].name == "ESN - Ethersocial Network")
- || (networks[DOM.network.val()].name == "VET - VeChain")
- ) {
+ if (networkIsEthereum()) {
var privKeyBuffer = keyPair.d.toBuffer(32);
privkey = privKeyBuffer.toString('hex');
var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32));
}
+ //Groestlcoin Addresses are different
+ if(isGRS()) {
+
+ if (isSegwit) {
+ if (!segwitAvailable) {
+ return;
+ }
+ if (isP2wpkh) {
+ address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
+ }
+ else if (isP2wpkhInP2sh) {
+ address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
+ }
+ }
+ //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
+ }
+
+ if (isELA()) {
+ let elaAddress = calcAddressForELA(
+ seed,
+ parseIntNoNaN(DOM.bip44coin.val(), 0),
+ parseIntNoNaN(DOM.bip44account.val(), 0),
+ parseIntNoNaN(DOM.bip44change.val(), 0),
+ index
+ );
+ address = elaAddress.address;
+ privkey = elaAddress.privateKey;
+ pubkey = elaAddress.publicKey;
+ }
+
addAddressToList(indexText, address, pubkey, privkey);
if (isLast) {
hidePending();
return phrase;
}
+ function writeSplitPhrase(phrase) {
+ var wordCount = phrase.split(/\s/g).length;
+ var left=[];
+ for (var i=0;i<wordCount;i++) left.push(i);
+ var group=[[],[],[]],
+ groupI=-1;
+ var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647;
+ while (left.length>0) {
+ groupI=(groupI+1)%3;
+ seed = seed * 16807 % 2147483647;
+ var selected=Math.floor(left.length*(seed - 1) / 2147483646);
+ group[groupI].push(left[selected]);
+ left.splice(selected,1);
+ }
+ var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];
+ for (var i=0;i<3;i++) {
+ for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX';
+ cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]);
+ }
+ DOM.phraseSplit.val(cards.join("\r\n"));
+ var triesPerSecond=10000000000;
+ var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond;
+ var displayRedText = false;
+ if (hackTime<1) {
+ hackTime="<1 second";
+ displayRedText = true;
+ } else if (hackTime<86400) {
+ hackTime=Math.floor(hackTime)+" seconds";
+ displayRedText = true;
+ } else if(hackTime<31557600) {
+ hackTime=Math.floor(hackTime/86400)+" days";
+ displayRedText = true;
+ } else {
+ hackTime=Math.floor(hackTime/31557600)+" years";
+ }
+ DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime);
+ if (displayRedText) {
+ DOM.phraseSplitWarn.addClass("text-danger");
+ } else {
+ DOM.phraseSplitWarn.removeClass("text-danger");
+ }
+ }
+
function isUsingOwnEntropy() {
return DOM.useEntropy.prop("checked");
}
var phrase = mnemonic.toMnemonic(entropyArr);
// Set the mnemonic in the UI
DOM.phrase.val(phrase);
+ writeSplitPhrase(phrase);
// Show the word indexes
showWordIndexes();
// Show the checksum
return DOM.bip32tab.hasClass("active");
}
+ function networkIsEthereum() {
+ var name = networks[DOM.network.val()].name;
+ return (name == "ETH - Ethereum")
+ || (name == "ETC - Ethereum Classic")
+ || (name == "EWT - EnergyWeb")
+ || (name == "PIRL - Pirl")
+ || (name == "MIX - MIX")
+ || (name == "MUSIC - Musicoin")
+ || (name == "POA - Poa")
+ || (name == "EXP - Expanse")
+ || (name == "CLO - Callisto")
+ || (name == "DXN - DEXON")
+ || (name == "ELLA - Ellaism")
+ || (name == "ESN - Ethersocial Network")
+ || (name == "VET - VeChain")
+ }
+
function networkHasSegwit() {
var n = network;
if ("baseNetwork" in network) {
setHdCoin(161);
},
},
+ {
+ name: "ARYA - Aryacoin",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.aryacoin;
+ setHdCoin(357);
+ },
+ },
{
name: "AUR - Auroracoin",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.axe;
setHdCoin(4242);
},
- },
- {
+ },
+ {
name: "ANON - ANON",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.anon;
setHdCoin(2941);
},
},
- {
+ {
name: "tBND - Blocknode Testnet",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.blocknode_testnet;
setHdCoin(91);
},
},
- {
+ {
name: "BST - BlockStamp",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.blockstamp;
setHdCoin(1);
},
},
- {
+ {
name: "BITG - Bitcoin Green",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.bitcoingreen;
setHdCoin(183);
},
},
+ {
+ name: "BSV - BitcoinSV",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.bitcoinsv;
+ setHdCoin(236);
+ },
+ },
{
name: "BTCZ - Bitcoinz",
onSelect: function() {
setHdCoin(71);
},
},
+ {
+ name: "CPU - CPUchain",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.cpuchain;
+ setHdCoin(363);
+ },
+ },
{
name: "CRAVE - Crave",
onSelect: function() {
setHdCoin(78);
},
},
+ {
+ name: "ELA - Elastos",
+ onSelect: function () {
+ network = bitcoinjs.bitcoin.networks.elastos;
+ setHdCoin(2305);
+ },
+ },
{
name: "ELLA - Ellaism",
segwitAvailable: false,
network = bitcoinjs.bitcoin.networks.bitcoin;
setHdCoin(60);
},
- },
+ },
+ {
+ name: "EWT - EnergyWeb",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.bitcoin;
+ setHdCoin(246);
+ },
+ },
{
name: "EXCL - Exclusivecoin",
onSelect: function() {
setHdCoin(84);
},
},
+ {
+ name: "GRS - Groestlcoin",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.groestlcoin;
+ setHdCoin(17);
+ },
+ },
+ {
+ name: "GRS - Groestlcoin Testnet",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.groestlcointestnet;
+ setHdCoin(1);
+ },
+ },
{
name: "HNC - Helleniccoin",
onSelect: function() {
setHdCoin(168);
},
},
- {
- name: "HUSH - Hush",
+ {
+ name: "HUSH - Hush (Legacy)",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.hush;
setHdCoin(197);
},
},
+ {
+ name: "HUSH - Hush3",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.hush3;
+ setHdCoin(197);
+ },
+ },
{
name: "INSN - Insane",
onSelect: function() {
setHdCoin(22);
},
},
+ {
+ name: "MONK - Monkey Project",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.monkeyproject,
+ setHdCoin(214);
+ },
+ },
{
name: "MUSIC - Musicoin",
segwitAvailable: false,
setHdCoin(174);
},
},
- {
+ {
name: "PHR - Phore",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.phore;
setHdCoin(6);
},
},
- {
+ {
name: "PRJ - ProjectCoin",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.projectcoin;
setHdCoin(122);
},
},
+ {
+ name: "RPD - Rapids",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.rapids;
+ setHdCoin(320);
+ },
+ },
{
name: "RVN - Ravencoin",
onSelect: function() {
setHdCoin(19165);
},
},
- {
+ {
name: "SLS - Salus",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.salus;
setHdCoin(113);
},
},
+ {
+ name: "THT - Thought",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.thought;
+ setHdCoin(1618);
+ },
+ },
{
name: "TOA - Toa",
onSelect: function() {
setHdCoin(28);
},
},
+ {
+ name: "WGR - Wagerr",
+ onSelect: function() {
+ network = bitcoinjs.bitcoin.networks.wagerr;
+ setHdCoin(7825266);
+ },
+ },
{
name: "WC - Wincoin",
onSelect: function() {
setHdCoin(181);
},
},
- {
+ {
name: "XAX - Artax",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.artax;
},
},
{
- name: "ZEN - Zencash",
+ name: "ZEN - Horizen",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.zencash;
setHdCoin(121);
}
]
+ // ELA - Elastos functions - begin
+ function displayBip44InfoForELA() {
+ if (!isELA()) {
+ return;
+ }
+
+ var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
+ var account = parseIntNoNaN(DOM.bip44account.val(), 0);
+
+ // Calculate the account extended keys
+ var accountXprv = elastosjs.getAccountExtendedPrivateKey(seed, coin, account);
+ var accountXpub = elastosjs.getAccountExtendedPublicKey(seed, coin, account);
+
+ // Display the extended keys
+ DOM.bip44accountXprv.val(accountXprv);
+ DOM.bip44accountXpub.val(accountXpub);
+ }
+
+ function displayBip32InfoForELA() {
+ if (!isELA()) {
+ return;
+ }
+
+ var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
+ var account = parseIntNoNaN(DOM.bip44account.val(), 0);
+ var change = parseIntNoNaN(DOM.bip44change.val(), 0);
+
+ DOM.extendedPrivKey.val(elastosjs.getBip32ExtendedPrivateKey(seed, coin, account, change));
+ DOM.extendedPubKey.val(elastosjs.getBip32ExtendedPublicKey(seed, coin, account, change));
+
+ // Display the addresses and privkeys
+ clearAddressesList();
+ var initialAddressCount = parseInt(DOM.rowsToAdd.val());
+ displayAddresses(0, initialAddressCount);
+ }
+
+ function calcAddressForELA(seed, coin, account, change, index) {
+ if (!isELA()) {
+ return;
+ }
+
+ var publicKey = elastosjs.getDerivedPublicKey(elastosjs.getMasterPublicKey(seed), change, index);
+ return {
+ privateKey: elastosjs.getDerivedPrivateKey(seed, coin, account, change, index),
+ publicKey: publicKey,
+ address: elastosjs.getAddress(publicKey.toString('hex'))
+ };
+ }
+ // ELA - Elastos functions - end
+
init();
})();