mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-27 21:00:41 +00:00
Add Groestlcoin
This commit is contained in:
+132
-3
@@ -488,9 +488,16 @@
|
||||
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()) {
|
||||
@@ -525,6 +532,41 @@
|
||||
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) {
|
||||
@@ -595,6 +637,9 @@
|
||||
}
|
||||
|
||||
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()) {
|
||||
@@ -635,6 +680,47 @@
|
||||
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);
|
||||
@@ -745,6 +831,10 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
function isGRS() {
|
||||
return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet";
|
||||
}
|
||||
|
||||
function displayBip44Info() {
|
||||
// Get the derivation path for the account
|
||||
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
||||
@@ -888,6 +978,9 @@
|
||||
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();
|
||||
@@ -898,9 +991,14 @@
|
||||
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
|
||||
@@ -1010,6 +1108,23 @@
|
||||
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
|
||||
}
|
||||
|
||||
addAddressToList(indexText, address, pubkey, privkey);
|
||||
if (isLast) {
|
||||
hidePending();
|
||||
@@ -2191,6 +2306,20 @@
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user