Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to allow custom mnemonic #683

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ <h2>Mnemonic</h2>
<div class="form-group">
<div class="col-sm-2"></div>
<div class="col-sm-10">
<p>You can enter an existing BIP39 mnemonic, or generate a new random one. Typing your own twelve words will probably not work how you expect, since the words require a particular structure (the last word contains a checksum).</p>
<p>
For more info see the
<p>You can enter an existing mnemonic, or generate a new random one.</p>
<p>Typing your own twelve words will probably not work how you expect, since BIP39 requires the words to have a particular structure (the last word contains a checksum). For more info see the
<a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki" target="_blank">BIP39 spec</a>.
</p>

<p>
<span class="text-danger">
If you share the information generated by this page with anyone, they can steal your assets.
Expand Down Expand Up @@ -211,6 +209,15 @@ <h2>Mnemonic</h2>
</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-2"></div>
<div class="col-sm-10 checkbox">
<label>
<input type="checkbox" class="allowCustomMnemonic">
<span>Allow custom mnemonic</span>
</label>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Mnemonic Language</label>
<div class="col-sm-10 languages">
Expand Down
10 changes: 8 additions & 2 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
DOM.phrase = $(".phrase");
DOM.autoCompute = $(".autoCompute");
DOM.allowCustomMnemonic = $(".allowCustomMnemonic");
DOM.splitMnemonic = $(".splitMnemonic");
DOM.showSplitMnemonic = $(".showSplitMnemonic");
DOM.phraseSplit = $(".phraseSplit");
Expand Down Expand Up @@ -148,6 +149,7 @@
DOM.bip32Client.on("change", bip32ClientChanged);
DOM.useEntropy.on("change", setEntropyVisibility);
DOM.autoCompute.on("change", delayedPhraseChanged);
DOM.allowCustomMnemonic.on("change", delayedPhraseChanged);
DOM.entropy.on("input", delayedEntropyChanged);
DOM.entropyMnemonicLength.on("change", entropyChanged);
DOM.pbkdf2Rounds.on("change", pbkdf2RoundsChanged);
Expand Down Expand Up @@ -240,6 +242,10 @@
return DOM.autoCompute.prop("checked");
}

function isCustomMnemonicAllowed() {
return DOM.allowCustomMnemonic.prop("checked");
}

function setEntropyVisibility() {
if (isUsingOwnEntropy()) {
DOM.entropyContainer.removeClass("hidden");
Expand Down Expand Up @@ -862,7 +868,7 @@
// Check the words are valid
var properPhrase = wordArrayToPhrase(words);
var isValid = mnemonic.check(properPhrase);
if (!isValid) {
if (!isValid && !isCustomMnemonicAllowed()) {
return "Invalid mnemonic";
}
return false;
Expand Down Expand Up @@ -2987,7 +2993,7 @@
},
},
{
name: "LBC - Library Credits",
name: "LBC - LBRY Credits",
onSelect: function() {
network = libs.bitcoin.networks.lbry;
setHdCoin(140);
Expand Down
4 changes: 2 additions & 2 deletions tests/spec/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,9 +1438,9 @@ it('Allows selection of Landcoin', function(done) {
};
testNetwork(done, params);
});
it('Allows selection of Library Credits', function(done) {
it('Allows selection of LBRY Credits', function(done) {
var params = {
selectText: "LBC - Library Credits",
selectText: "LBC - LBRY Credits",
phrase: "abandon abandon ability",
firstAddress: "bQJEQrHDJyHdqycB32uysh1SWn8Ln8LMdg",
firstPubKey: "02abd5018c033f59f49f28ee76d93c41323890928e25c171ccc7c61ed753cde8ad",
Expand Down