Merge pull request #1 from prusnak/master

add support for optional passphrase
This commit is contained in:
iancoleman
2014-09-25 09:21:17 +10:00
2 changed files with 13 additions and 4 deletions

View File

@@ -49,7 +49,7 @@
<p>For more info see the <a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki" target="_blank">BIP39 spec</a></p> <p>For more info see the <a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki" target="_blank">BIP39 spec</a></p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="phrase" class="col-sm-2 control-label">BIP39 Phrase</label> <label for="phrase" class="col-sm-2 control-label">BIP39 Mnemonic</label>
<div class="col-sm-10"> <div class="col-sm-10">
<textarea id="phrase" class="phrase form-control"></textarea> <textarea id="phrase" class="phrase form-control"></textarea>
</div> </div>
@@ -65,6 +65,12 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group">
<label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label>
<div class="col-sm-10">
<textarea id="passphrase" class="passphrase form-control"></textarea>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="root-key" class="col-sm-2 control-label">BIP32 Root Key</label> <label for="root-key" class="col-sm-2 control-label">BIP32 Root Key</label>
<div class="col-sm-10"> <div class="col-sm-10">

View File

@@ -10,6 +10,7 @@
var DOM = {}; var DOM = {};
DOM.phrase = $(".phrase"); DOM.phrase = $(".phrase");
DOM.passphrase = $(".passphrase");
DOM.generate = $(".generate"); DOM.generate = $(".generate");
DOM.rootKey = $(".root-key"); DOM.rootKey = $(".root-key");
DOM.extendedPrivKey = $(".extended-priv-key"); DOM.extendedPrivKey = $(".extended-priv-key");
@@ -35,6 +36,7 @@
function init() { function init() {
// Events // Events
DOM.phrase.on("keyup", delayedPhraseChanged); DOM.phrase.on("keyup", delayedPhraseChanged);
DOM.passphrase.on("keyup", delayedPhraseChanged);
DOM.generate.on("click", generateClicked); DOM.generate.on("click", generateClicked);
DOM.more.on("click", showMore); DOM.more.on("click", showMore);
DOM.bip32path.on("keyup", bip32Changed); DOM.bip32path.on("keyup", bip32Changed);
@@ -67,6 +69,7 @@
hideValidationError(); hideValidationError();
// Get the mnemonic phrase // Get the mnemonic phrase
var phrase = DOM.phrase.val(); var phrase = DOM.phrase.val();
var passphrase = DOM.passphrase.val();
var errorText = findPhraseErrors(phrase); var errorText = findPhraseErrors(phrase);
if (errorText) { if (errorText) {
showValidationError(errorText); showValidationError(errorText);
@@ -79,7 +82,7 @@
return; return;
} }
// Calculate and display // Calculate and display
calcBip32Seed(phrase, derivationPath); calcBip32Seed(phrase, passphrase, derivationPath);
displayBip32Info(); displayBip32Info();
hidePending(); hidePending();
} }
@@ -159,8 +162,8 @@
return words; return words;
} }
function calcBip32Seed(phrase, path) { function calcBip32Seed(phrase, passphrase, path) {
var seed = mnemonic.toSeed(phrase); var seed = mnemonic.toSeed(phrase, passphrase);
var seedHash = Bitcoin.crypto.sha256(seed).toString("hex"); var seedHash = Bitcoin.crypto.sha256(seed).toString("hex");
bip32RootKey = Bitcoin.HDNode.fromSeedHex(seedHash, network); bip32RootKey = Bitcoin.HDNode.fromSeedHex(seedHash, network);
bip32ExtendedKey = bip32RootKey; bip32ExtendedKey = bip32RootKey;