mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-18 08:22:16 +00:00
Merge branch 'master' into master
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,5 @@
|
|||||||
node_modules
|
node_modules
|
||||||
bip39-standalone.html
|
bip39-standalone.html
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
package-lock.json
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ body {
|
|||||||
.phrase {
|
.phrase {
|
||||||
word-break: keep-all;
|
word-break: keep-all;
|
||||||
}
|
}
|
||||||
|
.phraseSplitWarn {
|
||||||
|
text-align: right;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
.generate-container .strength {
|
.generate-container .strength {
|
||||||
/* override mobile width from bootstrap */
|
/* override mobile width from bootstrap */
|
||||||
width: auto!important;
|
width: auto!important;
|
||||||
|
|||||||
@@ -172,6 +172,13 @@
|
|||||||
<textarea id="phrase" class="phrase private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
<textarea id="phrase" class="phrase private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="phrase" class="col-sm-2 control-label">BIP39 Split Mnemonic</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<textarea id="phraseSplit" class="phraseSplit private-data form-control" title="Only 2 of 3 cards needed to recover."></textarea>
|
||||||
|
</div>
|
||||||
|
<div id="phraseSplitWarn" class="phraseSplitWarn"></div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label>
|
<label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
@@ -926,6 +933,9 @@
|
|||||||
<script src="js/bitcoinjs-3.3.2.js"></script>
|
<script src="js/bitcoinjs-3.3.2.js"></script>
|
||||||
<script src="js/bitcoinjs-extensions.js"></script>
|
<script src="js/bitcoinjs-extensions.js"></script>
|
||||||
<script src="js/bitcoinjs-bip38-2.0.2.js"></script>
|
<script src="js/bitcoinjs-bip38-2.0.2.js"></script>
|
||||||
|
<script src="js/groestlcoinjs-3.3.2.js"></script>
|
||||||
|
<script src="js/groestlcoinjs-bip38-2.0.2.js"></script>
|
||||||
|
<script src="js/elastos-1.0.9.min.js"></script>
|
||||||
<script src="js/segwit-parameters.js"></script>
|
<script src="js/segwit-parameters.js"></script>
|
||||||
<script src="js/ethereumjs-util.js"></script>
|
<script src="js/ethereumjs-util.js"></script>
|
||||||
<script src="js/ripple-util.js"></script>
|
<script src="js/ripple-util.js"></script>
|
||||||
@@ -948,7 +958,5 @@
|
|||||||
<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>
|
||||||
|
|||||||
@@ -1716,3 +1716,14 @@ bitcoinjs.bitcoin.networks.aryacoin = {
|
|||||||
scriptHash: 0x6f,
|
scriptHash: 0x6f,
|
||||||
wif: 0x97
|
wif: 0x97
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.elastos = {
|
||||||
|
messagePrefix: 'unused',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488B21E,
|
||||||
|
private: 0x0488ADE4,
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x21,
|
||||||
|
scriptHash: 0xc4, // TODO set this correctly, same as BTC for now
|
||||||
|
wif: 0xef // TODO set this correctly, same as BTC for now
|
||||||
|
};
|
||||||
|
|||||||
69
src/js/elastos-1.0.9.min.js
vendored
Normal file
69
src/js/elastos-1.0.9.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
153
src/js/index.js
153
src/js/index.js
@@ -45,6 +45,8 @@
|
|||||||
DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning");
|
DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning");
|
||||||
DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
|
DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
|
||||||
DOM.phrase = $(".phrase");
|
DOM.phrase = $(".phrase");
|
||||||
|
DOM.splitPhrase = $(".phraseSplit");
|
||||||
|
DOM.phraseSplitWarn = $(".phraseSplitWarn");
|
||||||
DOM.passphrase = $(".passphrase");
|
DOM.passphrase = $(".passphrase");
|
||||||
DOM.generateContainer = $(".generate-container");
|
DOM.generateContainer = $(".generate-container");
|
||||||
DOM.generate = $(".generate");
|
DOM.generate = $(".generate");
|
||||||
@@ -236,7 +238,14 @@
|
|||||||
if (phraseChangeTimeoutEvent != null) {
|
if (phraseChangeTimeoutEvent != null) {
|
||||||
clearTimeout(phraseChangeTimeoutEvent);
|
clearTimeout(phraseChangeTimeoutEvent);
|
||||||
}
|
}
|
||||||
phraseChangeTimeoutEvent = setTimeout(phraseChanged, 400);
|
phraseChangeTimeoutEvent = setTimeout(function() {
|
||||||
|
phraseChanged();
|
||||||
|
var entropy = mnemonic.toRawEntropyHex(DOM.phrase.val());
|
||||||
|
if (entropy !== null) {
|
||||||
|
DOM.entropyMnemonicLength.val("raw");
|
||||||
|
DOM.entropy.val(entropy);
|
||||||
|
}
|
||||||
|
}, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
function phraseChanged() {
|
function phraseChanged() {
|
||||||
@@ -301,6 +310,7 @@
|
|||||||
clearDisplay();
|
clearDisplay();
|
||||||
clearEntropyFeedback();
|
clearEntropyFeedback();
|
||||||
DOM.phrase.val("");
|
DOM.phrase.val("");
|
||||||
|
DOM.phraseSplit.val("");
|
||||||
showValidationError("Blank entropy");
|
showValidationError("Blank entropy");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -335,6 +345,7 @@
|
|||||||
showPending();
|
showPending();
|
||||||
// Clear existing mnemonic and passphrase
|
// Clear existing mnemonic and passphrase
|
||||||
DOM.phrase.val("");
|
DOM.phrase.val("");
|
||||||
|
DOM.phraseSplit.val("");
|
||||||
DOM.passphrase.val("");
|
DOM.passphrase.val("");
|
||||||
seed = null;
|
seed = null;
|
||||||
if (rootKeyChangedTimeoutEvent != null) {
|
if (rootKeyChangedTimeoutEvent != null) {
|
||||||
@@ -421,6 +432,7 @@
|
|||||||
if (DOM.phrase.val().length > 0) {
|
if (DOM.phrase.val().length > 0) {
|
||||||
var newPhrase = convertPhraseToNewLanguage();
|
var newPhrase = convertPhraseToNewLanguage();
|
||||||
DOM.phrase.val(newPhrase);
|
DOM.phrase.val(newPhrase);
|
||||||
|
writeSplitPhrase(newPhrase);
|
||||||
phraseChanged();
|
phraseChanged();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -481,6 +493,7 @@
|
|||||||
// show the words
|
// show the words
|
||||||
var words = mnemonic.toMnemonic(data);
|
var words = mnemonic.toMnemonic(data);
|
||||||
DOM.phrase.val(words);
|
DOM.phrase.val(words);
|
||||||
|
writeSplitPhrase(words);
|
||||||
// show the entropy
|
// show the entropy
|
||||||
var entropyHex = uint8ArrayToHex(data);
|
var entropyHex = uint8ArrayToHex(data);
|
||||||
DOM.entropy.val(entropyHex);
|
DOM.entropy.val(entropyHex);
|
||||||
@@ -598,7 +611,7 @@
|
|||||||
extendedKey = extendedKey.derive(index);
|
extendedKey = extendedKey.derive(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return extendedKey
|
return extendedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showValidationError(errorText) {
|
function showValidationError(errorText) {
|
||||||
@@ -641,9 +654,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function validateRootKey(rootKeyBase58) {
|
function validateRootKey(rootKeyBase58) {
|
||||||
if(isGRS())
|
if(isGRS())
|
||||||
return validateRootKeyGRS(rootKeyBase58);
|
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()) {
|
||||||
@@ -841,6 +854,10 @@
|
|||||||
return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet";
|
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() {
|
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);
|
||||||
@@ -854,9 +871,14 @@
|
|||||||
var accountExtendedKey = calcBip32ExtendedKey(path);
|
var accountExtendedKey = calcBip32ExtendedKey(path);
|
||||||
var accountXprv = accountExtendedKey.toBase58();
|
var accountXprv = accountExtendedKey.toBase58();
|
||||||
var accountXpub = accountExtendedKey.neutered().toBase58();
|
var accountXpub = accountExtendedKey.neutered().toBase58();
|
||||||
|
|
||||||
// Display the extended keys
|
// Display the extended keys
|
||||||
DOM.bip44accountXprv.val(accountXprv);
|
DOM.bip44accountXprv.val(accountXprv);
|
||||||
DOM.bip44accountXpub.val(accountXpub);
|
DOM.bip44accountXpub.val(accountXpub);
|
||||||
|
|
||||||
|
if (isELA()) {
|
||||||
|
displayBip44InfoForELA();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayBip49Info() {
|
function displayBip49Info() {
|
||||||
@@ -912,6 +934,10 @@
|
|||||||
clearAddressesList();
|
clearAddressesList();
|
||||||
var initialAddressCount = parseInt(DOM.rowsToAdd.val());
|
var initialAddressCount = parseInt(DOM.rowsToAdd.val());
|
||||||
displayAddresses(0, initialAddressCount);
|
displayAddresses(0, initialAddressCount);
|
||||||
|
|
||||||
|
if (isELA()) {
|
||||||
|
displayBip32InfoForELA();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayAddresses(start, total) {
|
function displayAddresses(start, total) {
|
||||||
@@ -997,7 +1023,7 @@
|
|||||||
privkey = keyPair.toWIF();
|
privkey = keyPair.toWIF();
|
||||||
// BIP38 encode private key if required
|
// BIP38 encode private key if required
|
||||||
if (useBip38) {
|
if (useBip38) {
|
||||||
if(isGRS())
|
if(isGRS())
|
||||||
privkey = groestlcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
|
privkey = groestlcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
|
||||||
console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
|
console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
|
||||||
}, null, networks[DOM.network.val()].name.includes("Testnet"));
|
}, null, networks[DOM.network.val()].name.includes("Testnet"));
|
||||||
@@ -1115,10 +1141,23 @@
|
|||||||
else if (isP2wpkhInP2sh) {
|
else if (isP2wpkhInP2sh) {
|
||||||
address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
|
address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
|
//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);
|
addAddressToList(indexText, address, pubkey, privkey);
|
||||||
if (isLast) {
|
if (isLast) {
|
||||||
hidePending();
|
hidePending();
|
||||||
@@ -1409,6 +1448,40 @@
|
|||||||
}
|
}
|
||||||
return phrase;
|
return phrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeSplitPhrase(phrase) {
|
||||||
|
var wordCount = phrase.split(/\s/g).length; //get number of words in phrase
|
||||||
|
var left=[]; //initialize array of indexs
|
||||||
|
for (var i=0;i<wordCount;i++) left.push(i); //add all indexs to array
|
||||||
|
var group=[[],[],[]], //make array for 3 groups
|
||||||
|
groupI=-1; //initialize group index
|
||||||
|
var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647; //start seed at sudo random value based on hash of words
|
||||||
|
while (left.length>0) { //while indexs left
|
||||||
|
groupI=(groupI+1)%3; //get next group to insert index into
|
||||||
|
seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use)
|
||||||
|
var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group
|
||||||
|
group[groupI].push(left[selected]); //add index to group
|
||||||
|
left.splice(selected,1); //remove selected index
|
||||||
|
}
|
||||||
|
var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards
|
||||||
|
for (var i=0;i<3;i++) { //go through each card
|
||||||
|
for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX'; //erase words listed in the group
|
||||||
|
cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]); //combine words on card back to string
|
||||||
|
}
|
||||||
|
DOM.splitPhrase.val(cards.join("\r\n")); //make words visible
|
||||||
|
var triesPerSecond=10000000000; //assumed number of tries per second
|
||||||
|
var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond; //get number of bits of unknown data per card
|
||||||
|
if (hackTime<1) {
|
||||||
|
hackTime="<1 second";
|
||||||
|
} else if (hackTime<86400) {
|
||||||
|
hackTime=Math.floor(hackTime)+" seconds";
|
||||||
|
} else if(hackTime<31557600) {
|
||||||
|
hackTime=Math.floor(hackTime/86400)+" days";
|
||||||
|
} else {
|
||||||
|
hackTime=Math.floor(hackTime/31557600)+" years";
|
||||||
|
}
|
||||||
|
DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime);
|
||||||
|
}
|
||||||
|
|
||||||
function isUsingOwnEntropy() {
|
function isUsingOwnEntropy() {
|
||||||
return DOM.useEntropy.prop("checked");
|
return DOM.useEntropy.prop("checked");
|
||||||
@@ -1467,6 +1540,7 @@
|
|||||||
var phrase = mnemonic.toMnemonic(entropyArr);
|
var phrase = mnemonic.toMnemonic(entropyArr);
|
||||||
// Set the mnemonic in the UI
|
// Set the mnemonic in the UI
|
||||||
DOM.phrase.val(phrase);
|
DOM.phrase.val(phrase);
|
||||||
|
writeSplitPhrase(phrase);
|
||||||
// Show the word indexes
|
// Show the word indexes
|
||||||
showWordIndexes();
|
showWordIndexes();
|
||||||
// Show the checksum
|
// Show the checksum
|
||||||
@@ -1634,6 +1708,7 @@
|
|||||||
var name = networks[DOM.network.val()].name;
|
var name = networks[DOM.network.val()].name;
|
||||||
return (name == "ETH - Ethereum")
|
return (name == "ETH - Ethereum")
|
||||||
|| (name == "ETC - Ethereum Classic")
|
|| (name == "ETC - Ethereum Classic")
|
||||||
|
|| (name == "EWT - EnergyWeb")
|
||||||
|| (name == "PIRL - Pirl")
|
|| (name == "PIRL - Pirl")
|
||||||
|| (name == "MIX - MIX")
|
|| (name == "MIX - MIX")
|
||||||
|| (name == "MUSIC - Musicoin")
|
|| (name == "MUSIC - Musicoin")
|
||||||
@@ -2192,6 +2267,13 @@
|
|||||||
setHdCoin(78);
|
setHdCoin(78);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "ELA - Elastos",
|
||||||
|
onSelect: function () {
|
||||||
|
network = bitcoinjs.bitcoin.networks.elastos;
|
||||||
|
setHdCoin(2305);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "ELLA - Ellaism",
|
name: "ELLA - Ellaism",
|
||||||
segwitAvailable: false,
|
segwitAvailable: false,
|
||||||
@@ -2243,7 +2325,14 @@
|
|||||||
network = bitcoinjs.bitcoin.networks.bitcoin;
|
network = bitcoinjs.bitcoin.networks.bitcoin;
|
||||||
setHdCoin(60);
|
setHdCoin(60);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "EWT - EnergyWeb",
|
||||||
|
onSelect: function() {
|
||||||
|
network = bitcoinjs.bitcoin.networks.bitcoin;
|
||||||
|
setHdCoin(246);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "EXCL - Exclusivecoin",
|
name: "EXCL - Exclusivecoin",
|
||||||
onSelect: function() {
|
onSelect: function() {
|
||||||
@@ -3093,6 +3182,56 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// 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();
|
init();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -97,22 +97,10 @@ var Mnemonic = function(language) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.check = function(mnemonic) {
|
self.check = function(mnemonic) {
|
||||||
var mnemonic = self.splitWords(mnemonic);
|
var b = mnemonicToBinaryString(mnemonic);
|
||||||
if (mnemonic.length == 0 || mnemonic.length % 3 > 0) {
|
if (b === null) {
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
// idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
|
|
||||||
var idx = [];
|
|
||||||
for (var i=0; i<mnemonic.length; i++) {
|
|
||||||
var word = mnemonic[i];
|
|
||||||
var wordIndex = wordlist.indexOf(word);
|
|
||||||
if (wordIndex == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var binaryIndex = zfill(wordIndex.toString(2), 11);
|
|
||||||
idx.push(binaryIndex);
|
|
||||||
}
|
|
||||||
var b = idx.join('');
|
|
||||||
var l = b.length;
|
var l = b.length;
|
||||||
//d = b[:l / 33 * 32]
|
//d = b[:l / 33 * 32]
|
||||||
//h = b[-l / 33:]
|
//h = b[-l / 33:]
|
||||||
@@ -128,6 +116,20 @@ var Mnemonic = function(language) {
|
|||||||
return h == nh;
|
return h == nh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.toRawEntropyHex = function(mnemonic) {
|
||||||
|
var b = mnemonicToBinaryString(mnemonic);
|
||||||
|
if (b === null)
|
||||||
|
return null;
|
||||||
|
var d = b.substring(0, b.length / 33 * 32);
|
||||||
|
var nd = binaryStringToWordArray(d);
|
||||||
|
|
||||||
|
var h = "";
|
||||||
|
for (var i=0; i<nd.length; i++) {
|
||||||
|
h += ('0000000' + nd[i].toString(16)).slice(-8);
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
self.toSeed = function(mnemonic, passphrase) {
|
self.toSeed = function(mnemonic, passphrase) {
|
||||||
passphrase = passphrase || '';
|
passphrase = passphrase || '';
|
||||||
mnemonic = self.joinWords(self.splitWords(mnemonic)); // removes duplicate blanks
|
mnemonic = self.joinWords(self.splitWords(mnemonic)); // removes duplicate blanks
|
||||||
@@ -200,6 +202,25 @@ var Mnemonic = function(language) {
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mnemonicToBinaryString(mnemonic) {
|
||||||
|
var mnemonic = self.splitWords(mnemonic);
|
||||||
|
if (mnemonic.length == 0 || mnemonic.length % 3 > 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
|
||||||
|
var idx = [];
|
||||||
|
for (var i=0; i<mnemonic.length; i++) {
|
||||||
|
var word = mnemonic[i];
|
||||||
|
var wordIndex = wordlist.indexOf(word);
|
||||||
|
if (wordIndex == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var binaryIndex = zfill(wordIndex.toString(2), 11);
|
||||||
|
idx.push(binaryIndex);
|
||||||
|
}
|
||||||
|
return idx.join('');
|
||||||
|
}
|
||||||
|
|
||||||
// Pad a numeric string on the left with zero digits until the given width
|
// Pad a numeric string on the left with zero digits until the given width
|
||||||
// is reached.
|
// is reached.
|
||||||
// Note this differs to the python implementation because it does not
|
// Note this differs to the python implementation because it does not
|
||||||
|
|||||||
@@ -263,6 +263,240 @@ bitcoinjs.bitcoin.networks.cpuchain.p2wpkhInP2sh = {
|
|||||||
wif: 0x80,
|
wif: 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.monkeyproject.p2wpkh = {
|
||||||
|
baseNetwork: "monkeyproject",
|
||||||
|
messagePrefix: 'Monkey Signed Message:\n',
|
||||||
|
bech32: 'monkey',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488b21e,
|
||||||
|
private: 0x0488dde4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x33,
|
||||||
|
scriptHash: 0x1c,
|
||||||
|
wif: 0x37
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.monkeyproject.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "monkeyproject",
|
||||||
|
messagePrefix: 'Monkey Signed Message:\n',
|
||||||
|
bech32: 'monkey',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488b21e,
|
||||||
|
private: 0x0488dde4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x33,
|
||||||
|
scriptHash: 0x1c,
|
||||||
|
wif: 0x37
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.atom.p2wpkh = {
|
||||||
|
baseNetwork: "atom",
|
||||||
|
messagePrefix: '\x18Bitcoin Atom Signed Message:\n',
|
||||||
|
bech32: 'atom',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488B21E,
|
||||||
|
private: 0x0488ADE4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x17,
|
||||||
|
scriptHash: 0x0a,
|
||||||
|
wif: 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.atom.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "atom",
|
||||||
|
messagePrefix: '\x18Bitcoin Atom Signed Message:\n',
|
||||||
|
bech32: 'atom',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488B21E,
|
||||||
|
private: 0x0488ADE4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x17,
|
||||||
|
scriptHash: 0x0a,
|
||||||
|
wif: 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.bitcore.p2wpkh = {
|
||||||
|
baseNetwork: "bitcore",
|
||||||
|
messagePrefix: '\x18BitCore Signed Message:\n',
|
||||||
|
bech32: 'bitcore',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488B21E,
|
||||||
|
private: 0x0488ADE4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x03,
|
||||||
|
scriptHash: 0x7D,
|
||||||
|
wif: 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.bitcore.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "bitcore",
|
||||||
|
messagePrefix: '\x18BitCore Signed Message:\n',
|
||||||
|
bech32: 'bitcore',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488B21E,
|
||||||
|
private: 0x0488ADE4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x03,
|
||||||
|
scriptHash: 0x7D,
|
||||||
|
wif: 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.monacoin.p2wpkh = {
|
||||||
|
baseNetwork: "monacoin",
|
||||||
|
messagePrefix: '\x18Monacoin Signed Message:\n',
|
||||||
|
bech32: 'monacoin',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488b21e,
|
||||||
|
private: 0x0488ade4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x32,
|
||||||
|
scriptHash: 0x37,
|
||||||
|
wif: 0xb0
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.monacoin.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "monacoin",
|
||||||
|
messagePrefix: '\x18Monacoin Signed Message:\n',
|
||||||
|
bech32: 'monacoin',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488b21e,
|
||||||
|
private: 0x0488ade4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x32,
|
||||||
|
scriptHash: 0x37,
|
||||||
|
wif: 0xb0
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.syscoin.p2wpkh = {
|
||||||
|
baseNetwork: "syscoin",
|
||||||
|
messagePrefix: '\x18Syscoin Signed Message:\n',
|
||||||
|
bech32: 'sys',
|
||||||
|
bip32: {
|
||||||
|
public: 0x04b24746,
|
||||||
|
private: 0x04b2430c
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x3f,
|
||||||
|
scriptHash: 0x05,
|
||||||
|
wif: 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.syscoin.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "syscoin",
|
||||||
|
messagePrefix: '\x18Syscoin Signed Message:\n',
|
||||||
|
bech32: 'sys',
|
||||||
|
bip32: {
|
||||||
|
public: 0x049d7cb2,
|
||||||
|
private: 0x049d7878
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x3f,
|
||||||
|
scriptHash: 0x05,
|
||||||
|
wif: 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.viacoin.p2wpkh = {
|
||||||
|
baseNetwork: "viacoin",
|
||||||
|
messagePrefix: '\x18Viacoin Signed Message:\n',
|
||||||
|
bech32: 'viacoin',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488b21e,
|
||||||
|
private: 0x0488ade4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x47,
|
||||||
|
scriptHash: 0x21,
|
||||||
|
wif: 0xc7
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.viacoin.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "viacoin",
|
||||||
|
messagePrefix: '\x18Viacoin Signed Message:\n',
|
||||||
|
bech32: 'viacoin',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488b21e,
|
||||||
|
private: 0x0488ade4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x47,
|
||||||
|
scriptHash: 0x21,
|
||||||
|
wif: 0xc7
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkh = {
|
||||||
|
baseNetwork: "dogecointestnet",
|
||||||
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
||||||
|
bech32: 'dogecointestnet',
|
||||||
|
bip32: {
|
||||||
|
public: 0x043587cf,
|
||||||
|
private: 0x04358394
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x71,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xf1
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "dogecointestnet",
|
||||||
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
||||||
|
bech32: 'dogecointestnet',
|
||||||
|
bip32: {
|
||||||
|
public: 0x043587cf,
|
||||||
|
private: 0x04358394
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x71,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xf1
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkh = {
|
||||||
|
baseNetwork: "dogecointestnet",
|
||||||
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
||||||
|
bech32: 'dogecointestnet',
|
||||||
|
bip32: {
|
||||||
|
public: 0x043587cf,
|
||||||
|
private: 0x04358394
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x71,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xf1
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "dogecointestnet",
|
||||||
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
||||||
|
bech32: 'dogecointestnet',
|
||||||
|
bip32: {
|
||||||
|
public: 0x043587cf,
|
||||||
|
private: 0x04358394
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x71,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xf1
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.litecointestnet.p2wpkh = {
|
||||||
|
baseNetwork: "litecointestnet",
|
||||||
|
messagePrefix: '\x18Litecoin Signed Message:\n',
|
||||||
|
bech32: 'litecointestnet',
|
||||||
|
bip32: {
|
||||||
|
public: 0x043587cf,
|
||||||
|
private: 0x04358394
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x6f,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xef
|
||||||
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.litecointestnet.p2wpkhInP2sh = {
|
||||||
|
baseNetwork: "litecointestnet",
|
||||||
|
messagePrefix: '\x18Litecoin Signed Message:\n',
|
||||||
|
bech32: 'litecointestnet',
|
||||||
|
bip32: {
|
||||||
|
public: 0x043587cf,
|
||||||
|
private: 0x04358394
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x6f,
|
||||||
|
scriptHash: 0xc4,
|
||||||
|
wif: 0xef
|
||||||
|
};
|
||||||
|
|
||||||
bitcoinjs.bitcoin.networks.groestlcoin.p2wpkh = {
|
bitcoinjs.bitcoin.networks.groestlcoin.p2wpkh = {
|
||||||
baseNetwork: "groestlcoin",
|
baseNetwork: "groestlcoin",
|
||||||
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||||
|
|||||||
@@ -1608,6 +1608,13 @@ it('Allows selection of Groestlcoin Testnet', function(done) {
|
|||||||
};
|
};
|
||||||
testNetwork(done, params);
|
testNetwork(done, params);
|
||||||
});
|
});
|
||||||
|
it('Allows selection of Elastos', function(done) {
|
||||||
|
var params = {
|
||||||
|
selectText: "ELA - Elastos",
|
||||||
|
firstAddress: "EYmqntM99tr4NJJs2G5Nr93pqsh9cdTCkS",
|
||||||
|
};
|
||||||
|
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user