mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-05 18:43:47 +00:00
Merge branch 'enable-segwit' of https://github.com/PavlosTze/bip39 into enable-segwit
This commit is contained in:
@@ -945,5 +945,7 @@
|
|||||||
<script src="js/entropy.js"></script>
|
<script src="js/entropy.js"></script>
|
||||||
<script src="js/stellar-util.js"></script>
|
<script src="js/stellar-util.js"></script>
|
||||||
<script src="js/index.js"></script>
|
<script src="js/index.js"></script>
|
||||||
|
<script src="js/groestlcoinjs-3.3.2.js"></script>
|
||||||
|
<script src="js/groestlcoinjs-bip38-2.0.2.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -801,6 +801,28 @@ bitcoinjs.bitcoin.networks.gridcoin = {
|
|||||||
wif: 0xbe,
|
wif: 0xbe,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.groestlcoin = {
|
||||||
|
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488b21e,
|
||||||
|
private: 0x0488ade4
|
||||||
|
},
|
||||||
|
pubKeyHash: 36,
|
||||||
|
scriptHash: 5,
|
||||||
|
wif: 128,
|
||||||
|
}
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.groestlcointestnet = {
|
||||||
|
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||||
|
bip32: {
|
||||||
|
public: 0x043587cf,
|
||||||
|
private: 0x04358394
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x6f,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xef,
|
||||||
|
}
|
||||||
|
|
||||||
bitcoinjs.bitcoin.networks.gulden = {
|
bitcoinjs.bitcoin.networks.gulden = {
|
||||||
messagePrefix: '\x18Guldencoin Signed Message:\n',
|
messagePrefix: '\x18Guldencoin Signed Message:\n',
|
||||||
bip32: {
|
bip32: {
|
||||||
|
|||||||
17951
src/js/groestlcoinjs-3.3.2.js
Normal file
17951
src/js/groestlcoinjs-3.3.2.js
Normal file
File diff suppressed because it is too large
Load Diff
28732
src/js/groestlcoinjs-bip38-2.0.2.js
Normal file
28732
src/js/groestlcoinjs-bip38-2.0.2.js
Normal file
File diff suppressed because it is too large
Load Diff
135
src/js/index.js
135
src/js/index.js
@@ -488,9 +488,16 @@
|
|||||||
function calcBip32RootKeyFromSeed(phrase, passphrase) {
|
function calcBip32RootKeyFromSeed(phrase, passphrase) {
|
||||||
seed = mnemonic.toSeed(phrase, passphrase);
|
seed = mnemonic.toSeed(phrase, passphrase);
|
||||||
bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network);
|
bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network);
|
||||||
|
if(isGRS())
|
||||||
|
bip32RootKey = groestlcoinjs.HDNode.fromSeedHex(seed, network);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcBip32RootKeyFromBase58(rootKeyBase58) {
|
function calcBip32RootKeyFromBase58(rootKeyBase58) {
|
||||||
|
if(isGRS()) {
|
||||||
|
calcBip32RootKeyFromBase58GRS(rootKeyBase58);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// try parsing with various segwit network params since this extended
|
// try parsing with various segwit network params since this extended
|
||||||
// key may be from any one of them.
|
// key may be from any one of them.
|
||||||
if (networkHasSegwit()) {
|
if (networkHasSegwit()) {
|
||||||
@@ -525,6 +532,41 @@
|
|||||||
bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
|
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) {
|
function calcBip32ExtendedKey(path) {
|
||||||
// Check there's a root key to derive from
|
// Check there's a root key to derive from
|
||||||
if (!bip32RootKey) {
|
if (!bip32RootKey) {
|
||||||
@@ -595,6 +637,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function validateRootKey(rootKeyBase58) {
|
function validateRootKey(rootKeyBase58) {
|
||||||
|
if(isGRS())
|
||||||
|
return validateRootKeyGRS(rootKeyBase58);
|
||||||
|
|
||||||
// try various segwit network params since this extended key may be from
|
// try various segwit network params since this extended key may be from
|
||||||
// any one of them.
|
// any one of them.
|
||||||
if (networkHasSegwit()) {
|
if (networkHasSegwit()) {
|
||||||
@@ -635,6 +680,47 @@
|
|||||||
return "";
|
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() {
|
function getDerivationPath() {
|
||||||
if (bip44TabSelected()) {
|
if (bip44TabSelected()) {
|
||||||
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
||||||
@@ -745,6 +831,10 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isGRS() {
|
||||||
|
return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet";
|
||||||
|
}
|
||||||
|
|
||||||
function displayBip44Info() {
|
function displayBip44Info() {
|
||||||
// Get the derivation path for the account
|
// Get the derivation path for the account
|
||||||
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
||||||
@@ -888,6 +978,9 @@
|
|||||||
var useUncompressed = useBip38;
|
var useUncompressed = useBip38;
|
||||||
if (useUncompressed) {
|
if (useUncompressed) {
|
||||||
keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false });
|
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
|
// get address
|
||||||
var address = keyPair.getAddress().toString();
|
var address = keyPair.getAddress().toString();
|
||||||
@@ -898,9 +991,14 @@
|
|||||||
privkey = keyPair.toWIF();
|
privkey = keyPair.toWIF();
|
||||||
// BIP38 encode private key if required
|
// BIP38 encode private key if required
|
||||||
if (useBip38) {
|
if (useBip38) {
|
||||||
privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
|
if(isGRS())
|
||||||
console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
|
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
|
// get pubkey
|
||||||
@@ -1010,6 +1108,23 @@
|
|||||||
privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32));
|
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);
|
addAddressToList(indexText, address, pubkey, privkey);
|
||||||
if (isLast) {
|
if (isLast) {
|
||||||
hidePending();
|
hidePending();
|
||||||
@@ -2191,6 +2306,20 @@
|
|||||||
setHdCoin(84);
|
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",
|
name: "HNC - Helleniccoin",
|
||||||
onSelect: function() {
|
onSelect: function() {
|
||||||
|
|||||||
@@ -496,4 +496,57 @@ bitcoinjs.bitcoin.networks.litecointestnet.p2wpkhInP2sh = {
|
|||||||
scriptHash: 0xc4,
|
scriptHash: 0xc4,
|
||||||
wif: 0xef
|
wif: 0xef
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.groestlcoin.p2wpkh = {
|
||||||
|
baseNetwork: "groestlcoin",
|
||||||
|
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||||
|
bech32: 'grs',
|
||||||
|
bip32: {
|
||||||
|
public: 0x04b24746,
|
||||||
|
private: 0x04b2430c
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x24,
|
||||||
|
scriptHash: 0x05,
|
||||||
|
wif: 0x80,
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.groestlcointestnet.p2wpkh = {
|
||||||
|
baseNetwork: "groestlcointestnet",
|
||||||
|
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||||
|
bech32: 'tgrs',
|
||||||
|
bip32: {
|
||||||
|
public: 0x045f1cf6,
|
||||||
|
private: 0x045f18bc
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x6f,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xef
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.groestlcoin.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "groestlcoin",
|
||||||
|
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||||
|
bech32: 'grs',
|
||||||
|
bip32: {
|
||||||
|
public: 0x049d7cb2,
|
||||||
|
private: 0x049d7878
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x24,
|
||||||
|
scriptHash: 0x05,
|
||||||
|
wif: 0x80,
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.groestlcointestnet.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "groestlcointestnet",
|
||||||
|
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||||
|
bech32: 'tgrs',
|
||||||
|
bip32: {
|
||||||
|
public: 0x044a5262,
|
||||||
|
private: 0x044a4e28
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x6f,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xef
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1594,6 +1594,20 @@ it('Allows selection of Wagerr', function(done) {
|
|||||||
};
|
};
|
||||||
testNetwork(done, params);
|
testNetwork(done, params);
|
||||||
});
|
});
|
||||||
|
it('Allows selection of Groestlcoin', function(done) {
|
||||||
|
var params = {
|
||||||
|
selectText: "GRS - Groestlcoin",
|
||||||
|
firstAddress: "FZycsFvZ1eH1hbtyjBpAgJSukVw1bN6PBN",
|
||||||
|
};
|
||||||
|
testNetwork(done, params);
|
||||||
|
});
|
||||||
|
it('Allows selection of Groestlcoin Testnet', function(done) {
|
||||||
|
var params = {
|
||||||
|
selectText: "GRS - Groestlcoin Testnet",
|
||||||
|
firstAddress: "mucaU5iiDaJDb69BHLeDv8JFfGiygRPne9",
|
||||||
|
};
|
||||||
|
testNetwork(done, params);
|
||||||
|
});
|
||||||
|
|
||||||
// BIP39 seed is set from phrase
|
// BIP39 seed is set from phrase
|
||||||
it('Sets the bip39 seed from the prhase', function(done) {
|
it('Sets the bip39 seed from the prhase', function(done) {
|
||||||
@@ -4057,6 +4071,27 @@ it('Shows litecoin BIP49 addresses', function(done) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Shows Groestlcoin BIP49 addresses', function(done) {
|
||||||
|
driver.findElement(By.css('.phrase'))
|
||||||
|
.sendKeys('abandon abandon ability');
|
||||||
|
selectNetwork("GRS - Groestlcoin");
|
||||||
|
driver.findElement(By.css('#bip49-tab a'))
|
||||||
|
.click()
|
||||||
|
// bip49 addresses are shown
|
||||||
|
driver.sleep(generateDelay).then(function() {
|
||||||
|
driver.findElement(By.css('#bip49 .available'))
|
||||||
|
.getAttribute("class")
|
||||||
|
.then(function(classes) {
|
||||||
|
expect(classes).not.toContain("hidden");
|
||||||
|
// check first address
|
||||||
|
getFirstAddress(function(address) {
|
||||||
|
expect(address).toBe("3HXSCZwCypLyixMsF4Z1sN49noJtrm8gnX");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Can use root keys to generate segwit table rows', function(done) {
|
it('Can use root keys to generate segwit table rows', function(done) {
|
||||||
// segwit uses ypub / zpub instead of xpub but the root key should still
|
// segwit uses ypub / zpub instead of xpub but the root key should still
|
||||||
// be valid regardless of the encoding used to import that key.
|
// be valid regardless of the encoding used to import that key.
|
||||||
|
|||||||
Reference in New Issue
Block a user