mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-06 02:43:49 +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/stellar-util.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>
|
||||
</html>
|
||||
|
||||
@@ -801,6 +801,28 @@ bitcoinjs.bitcoin.networks.gridcoin = {
|
||||
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 = {
|
||||
messagePrefix: '\x18Guldencoin Signed Message:\n',
|
||||
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) {
|
||||
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() {
|
||||
|
||||
@@ -496,4 +496,57 @@ bitcoinjs.bitcoin.networks.litecointestnet.p2wpkhInP2sh = {
|
||||
scriptHash: 0xc4,
|
||||
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
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user