mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-29 13:36:01 +00:00
Merge branch 'master' into master
This commit is contained in:
+146
-7
@@ -45,6 +45,8 @@
|
||||
DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning");
|
||||
DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
|
||||
DOM.phrase = $(".phrase");
|
||||
DOM.splitPhrase = $(".phraseSplit");
|
||||
DOM.phraseSplitWarn = $(".phraseSplitWarn");
|
||||
DOM.passphrase = $(".passphrase");
|
||||
DOM.generateContainer = $(".generate-container");
|
||||
DOM.generate = $(".generate");
|
||||
@@ -236,7 +238,14 @@
|
||||
if (phraseChangeTimeoutEvent != null) {
|
||||
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() {
|
||||
@@ -301,6 +310,7 @@
|
||||
clearDisplay();
|
||||
clearEntropyFeedback();
|
||||
DOM.phrase.val("");
|
||||
DOM.phraseSplit.val("");
|
||||
showValidationError("Blank entropy");
|
||||
return;
|
||||
}
|
||||
@@ -335,6 +345,7 @@
|
||||
showPending();
|
||||
// Clear existing mnemonic and passphrase
|
||||
DOM.phrase.val("");
|
||||
DOM.phraseSplit.val("");
|
||||
DOM.passphrase.val("");
|
||||
seed = null;
|
||||
if (rootKeyChangedTimeoutEvent != null) {
|
||||
@@ -421,6 +432,7 @@
|
||||
if (DOM.phrase.val().length > 0) {
|
||||
var newPhrase = convertPhraseToNewLanguage();
|
||||
DOM.phrase.val(newPhrase);
|
||||
writeSplitPhrase(newPhrase);
|
||||
phraseChanged();
|
||||
}
|
||||
else {
|
||||
@@ -481,6 +493,7 @@
|
||||
// show the words
|
||||
var words = mnemonic.toMnemonic(data);
|
||||
DOM.phrase.val(words);
|
||||
writeSplitPhrase(words);
|
||||
// show the entropy
|
||||
var entropyHex = uint8ArrayToHex(data);
|
||||
DOM.entropy.val(entropyHex);
|
||||
@@ -598,7 +611,7 @@
|
||||
extendedKey = extendedKey.derive(index);
|
||||
}
|
||||
}
|
||||
return extendedKey
|
||||
return extendedKey;
|
||||
}
|
||||
|
||||
function showValidationError(errorText) {
|
||||
@@ -641,9 +654,9 @@
|
||||
}
|
||||
|
||||
function validateRootKey(rootKeyBase58) {
|
||||
if(isGRS())
|
||||
if(isGRS())
|
||||
return validateRootKeyGRS(rootKeyBase58);
|
||||
|
||||
|
||||
// try various segwit network params since this extended key may be from
|
||||
// any one of them.
|
||||
if (networkHasSegwit()) {
|
||||
@@ -841,6 +854,10 @@
|
||||
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);
|
||||
@@ -854,9 +871,14 @@
|
||||
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() {
|
||||
@@ -912,6 +934,10 @@
|
||||
clearAddressesList();
|
||||
var initialAddressCount = parseInt(DOM.rowsToAdd.val());
|
||||
displayAddresses(0, initialAddressCount);
|
||||
|
||||
if (isELA()) {
|
||||
displayBip32InfoForELA();
|
||||
}
|
||||
}
|
||||
|
||||
function displayAddresses(start, total) {
|
||||
@@ -997,7 +1023,7 @@
|
||||
privkey = keyPair.toWIF();
|
||||
// BIP38 encode private key if required
|
||||
if (useBip38) {
|
||||
if(isGRS())
|
||||
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"));
|
||||
@@ -1115,10 +1141,23 @@
|
||||
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();
|
||||
@@ -1409,6 +1448,40 @@
|
||||
}
|
||||
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() {
|
||||
return DOM.useEntropy.prop("checked");
|
||||
@@ -1467,6 +1540,7 @@
|
||||
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
|
||||
@@ -1634,6 +1708,7 @@
|
||||
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")
|
||||
@@ -2192,6 +2267,13 @@
|
||||
setHdCoin(78);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ELA - Elastos",
|
||||
onSelect: function () {
|
||||
network = bitcoinjs.bitcoin.networks.elastos;
|
||||
setHdCoin(2305);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ELLA - Ellaism",
|
||||
segwitAvailable: false,
|
||||
@@ -2243,7 +2325,14 @@
|
||||
network = bitcoinjs.bitcoin.networks.bitcoin;
|
||||
setHdCoin(60);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "EWT - EnergyWeb",
|
||||
onSelect: function() {
|
||||
network = bitcoinjs.bitcoin.networks.bitcoin;
|
||||
setHdCoin(246);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "EXCL - Exclusivecoin",
|
||||
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();
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user