mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-18 08:22:16 +00:00
Entropy changes compiled into standalone
This commit is contained in:
@@ -47,7 +47,7 @@
|
|||||||
.phrase {
|
.phrase {
|
||||||
word-break: keep-all;
|
word-break: keep-all;
|
||||||
}
|
}
|
||||||
.strength {
|
.generate-container .strength {
|
||||||
/* override mobile width from bootstrap */
|
/* override mobile width from bootstrap */
|
||||||
width: auto!important;
|
width: auto!important;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@@ -58,6 +58,29 @@
|
|||||||
.monospace {
|
.monospace {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
|
.entropy-container .filtered,
|
||||||
|
.entropy-container .binary {
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
.entropy-container li {
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
.card-suit {
|
||||||
|
font-size: 19px;
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
|
.card-suit.club {
|
||||||
|
color: #009F00;
|
||||||
|
}
|
||||||
|
.card-suit.diamond {
|
||||||
|
color: #3D5DC4;
|
||||||
|
}
|
||||||
|
.card-suit.heart {
|
||||||
|
color: #F00;
|
||||||
|
}
|
||||||
|
.card-suit.spade {
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -99,58 +122,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="entropy-container hidden">
|
<div class="entropy-container hidden">
|
||||||
<div class="form-group">
|
<div class="form-group text-danger">
|
||||||
<label for="entropy" class="col-sm-2 control-label">Entropy</label>
|
<label class="col-sm-2 control-label">Warning</label>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-10 form-control-static">
|
||||||
<textarea id="entropy" rows="6" class="entropy form-control" placeholder="Accepts binary, base 6, 6-sided dice, base 10, hexadecimal, cards"></textarea>
|
Entropy is an advanced feature.
|
||||||
<span class="help-block">
|
Your mnemonic may be insecure if this feature is used incorrectly.
|
||||||
<div class="text-danger">
|
<a href="#entropy-notes">Read more</a>
|
||||||
This is an advanced feature.
|
|
||||||
Your mnemonic may be insecure if this feature is used incorrectly.
|
|
||||||
<a href="#entropy-notes">Read more</a>
|
|
||||||
</div>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="pull-right col-sm-4">
|
|
||||||
<p>Valid entropy values include:</p>
|
|
||||||
<ul>
|
|
||||||
<li>Binary: [0-1] eg 101010011</li>
|
|
||||||
<li>Base 6: [0-5] eg 123434014</li>
|
|
||||||
<li>Dice: [1-6] eg 62535634</li>
|
|
||||||
<li>Base 10: [0-9] eg 90834528</li>
|
|
||||||
<li>Hex: [0-9A-F] eg 4187a8bfd9</li>
|
|
||||||
<li>Card: [A2-9TJQK][CDHS] eg AHQS9DTC</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="entropy-feedback">
|
<div class="form-group">
|
||||||
<div class="form-group">
|
<label for="entropy" class="col-sm-2 control-label">Entropy</label>
|
||||||
<label class="col-sm-2 control-label">Filtered</label>
|
<div class="col-sm-7">
|
||||||
<div class="filtered col-sm-10 form-control-static"></div>
|
<textarea id="entropy" rows="2" class="entropy form-control" placeholder="Accepts binary, base 6, 6-sided dice, base 10, hexadecimal, cards"></textarea>
|
||||||
</div>
|
<label class="col-sm-3 control-label">Strength</label>
|
||||||
<div class="form-group">
|
<div class="strength col-sm-3 form-control-static"></div>
|
||||||
<label class="col-sm-2 control-label">Type</label>
|
<label class="col-sm-3 control-label">Event Count</label>
|
||||||
<div class="type col-sm-10 form-control-static"></div>
|
<div class="event-count col-sm-3 form-control-static"></div>
|
||||||
</div>
|
<label class="col-sm-3 control-label">Entropy Type</label>
|
||||||
<div class="form-group">
|
<div class="type col-sm-3 form-control-static"></div>
|
||||||
<label class="col-sm-2 control-label">Strength</label>
|
<label class="col-sm-3 control-label">Bits Per Event</label>
|
||||||
<div class="strength col-sm-10 form-control-static"></div>
|
<div class="bits-per-event col-sm-3 form-control-static"></div>
|
||||||
</div>
|
<label class="col-sm-3 control-label">Word Count</label>
|
||||||
<div class="form-group">
|
<div class="word-count col-sm-3 form-control-static"></div>
|
||||||
<label class="col-sm-2 control-label">Event Count</label>
|
<label class="col-sm-3 control-label">Total Bits</label>
|
||||||
<div class="event-count col-sm-10 form-control-static"></div>
|
<div class="bits col-sm-3 form-control-static"></div>
|
||||||
</div>
|
<label class="col-sm-3 control-label">Filtered Entropy</label>
|
||||||
<div class="form-group">
|
<div class="filtered col-sm-9 form-control-static"></div>
|
||||||
<label class="col-sm-2 control-label">Bits Per Event</label>
|
<label class="col-sm-3 control-label">Raw Binary</label>
|
||||||
<div class="bits-per-event col-sm-10 form-control-static"></div>
|
<div class="binary col-sm-9 form-control-static"></div>
|
||||||
</div>
|
<label class="col-sm-3 control-label">Mnemonic Length</label>
|
||||||
<div class="form-group">
|
<div class="col-sm-9">
|
||||||
<label class="col-sm-2 control-label">Bits</label>
|
|
||||||
<div class="bits col-sm-10 form-control-static"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-2 control-label">Mnemonic Length</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<select class="mnemonic-length form-control">
|
<select class="mnemonic-length form-control">
|
||||||
<option value="raw">From entropy length (3 words per 32 bits)</option>
|
<option value="raw">From entropy length (3 words per 32 bits)</option>
|
||||||
<option value="12">12 Words</option>
|
<option value="12">12 Words</option>
|
||||||
@@ -161,6 +162,17 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<p>Valid entropy values include:</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Binary</strong> [0-1]<br>101010011</li>
|
||||||
|
<li><strong>Base 6</strong> [0-5]<br>123434014</li>
|
||||||
|
<li><strong>Dice</strong> [1-6]<br>62535634</li>
|
||||||
|
<li><strong>Base 10</strong> [0-9]<br>90834528</li>
|
||||||
|
<li><strong>Hex</strong> [0-9A-F]<br>4187a8bfd9</li>
|
||||||
|
<li><strong>Card</strong> [A2-9TJQK][CDHS]<br>ahqs9dtc</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -16387,6 +16399,7 @@ window.Entropy = new (function() {
|
|||||||
return {
|
return {
|
||||||
binaryStr: "",
|
binaryStr: "",
|
||||||
cleanStr: "",
|
cleanStr: "",
|
||||||
|
cleanHtml: "",
|
||||||
base: base,
|
base: base,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -16412,16 +16425,23 @@ window.Entropy = new (function() {
|
|||||||
}
|
}
|
||||||
// Supply a 'filtered' entropy string for display purposes
|
// Supply a 'filtered' entropy string for display purposes
|
||||||
var entropyClean = base.parts.join("");
|
var entropyClean = base.parts.join("");
|
||||||
|
var entropyHtml = base.parts.join("");
|
||||||
if (base.asInt == 52) {
|
if (base.asInt == 52) {
|
||||||
entropyClean = base.parts.join(" ").toUpperCase();
|
entropyClean = base.parts.join(" ").toUpperCase();
|
||||||
entropyClean = entropyClean.replace(/C/g, "\u2663");
|
entropyClean = entropyClean.replace(/C/g, "\u2663");
|
||||||
entropyClean = entropyClean.replace(/D/g, "\u2666");
|
entropyClean = entropyClean.replace(/D/g, "\u2666");
|
||||||
entropyClean = entropyClean.replace(/H/g, "\u2665");
|
entropyClean = entropyClean.replace(/H/g, "\u2665");
|
||||||
entropyClean = entropyClean.replace(/S/g, "\u2660");
|
entropyClean = entropyClean.replace(/S/g, "\u2660");
|
||||||
|
entropyHtml = base.parts.join(" ").toUpperCase();
|
||||||
|
entropyHtml = entropyHtml.replace(/C/g, "<span class='card-suit club'>\u2663</span>");
|
||||||
|
entropyHtml = entropyHtml.replace(/D/g, "<span class='card-suit diamond'>\u2666</span>");
|
||||||
|
entropyHtml = entropyHtml.replace(/H/g, "<span class='card-suit heart'>\u2665</span>");
|
||||||
|
entropyHtml = entropyHtml.replace(/S/g, "<span class='card-suit spade'>\u2660</span>");
|
||||||
}
|
}
|
||||||
var e = {
|
var e = {
|
||||||
binaryStr: entropyBin,
|
binaryStr: entropyBin,
|
||||||
cleanStr: entropyClean,
|
cleanStr: entropyClean,
|
||||||
|
cleanHtml: entropyHtml,
|
||||||
base: base,
|
base: base,
|
||||||
}
|
}
|
||||||
return e;
|
return e;
|
||||||
@@ -18162,14 +18182,15 @@ exports.BigInteger = BigInteger;
|
|||||||
DOM.useEntropy = $(".use-entropy");
|
DOM.useEntropy = $(".use-entropy");
|
||||||
DOM.entropyContainer = $(".entropy-container");
|
DOM.entropyContainer = $(".entropy-container");
|
||||||
DOM.entropy = $(".entropy");
|
DOM.entropy = $(".entropy");
|
||||||
DOM.entropyFeedback = $(".entropy-feedback");
|
DOM.entropyFiltered = DOM.entropyContainer.find(".filtered");
|
||||||
DOM.entropyFiltered = DOM.entropyFeedback.find(".filtered");
|
DOM.entropyType = DOM.entropyContainer.find(".type");
|
||||||
DOM.entropyType = DOM.entropyFeedback.find(".type");
|
DOM.entropyStrength = DOM.entropyContainer.find(".strength");
|
||||||
DOM.entropyStrength = DOM.entropyFeedback.find(".strength");
|
DOM.entropyEventCount = DOM.entropyContainer.find(".event-count");
|
||||||
DOM.entropyEventCount = DOM.entropyFeedback.find(".event-count");
|
DOM.entropyBits = DOM.entropyContainer.find(".bits");
|
||||||
DOM.entropyBits = DOM.entropyFeedback.find(".bits");
|
DOM.entropyBitsPerEvent = DOM.entropyContainer.find(".bits-per-event");
|
||||||
DOM.entropyBitsPerEvent = DOM.entropyFeedback.find(".bits-per-event");
|
DOM.entropyWordCount = DOM.entropyContainer.find(".word-count");
|
||||||
DOM.entropyMnemonicLength = DOM.entropyFeedback.find(".mnemonic-length");
|
DOM.entropyBinary = DOM.entropyContainer.find(".binary");
|
||||||
|
DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length");
|
||||||
DOM.phrase = $(".phrase");
|
DOM.phrase = $(".phrase");
|
||||||
DOM.passphrase = $(".passphrase");
|
DOM.passphrase = $(".passphrase");
|
||||||
DOM.generateContainer = $(".generate-container");
|
DOM.generateContainer = $(".generate-container");
|
||||||
@@ -18299,7 +18320,7 @@ exports.BigInteger = BigInteger;
|
|||||||
// If blank entropy, clear mnemonic, addresses, errors
|
// If blank entropy, clear mnemonic, addresses, errors
|
||||||
if (DOM.entropy.val().trim().length == 0) {
|
if (DOM.entropy.val().trim().length == 0) {
|
||||||
clearDisplay();
|
clearDisplay();
|
||||||
hideEntropyFeedback();
|
clearEntropyFeedback();
|
||||||
DOM.phrase.val("");
|
DOM.phrase.val("");
|
||||||
showValidationError("Blank entropy");
|
showValidationError("Blank entropy");
|
||||||
return;
|
return;
|
||||||
@@ -18873,7 +18894,7 @@ exports.BigInteger = BigInteger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setMnemonicFromEntropy() {
|
function setMnemonicFromEntropy() {
|
||||||
hideEntropyFeedback();
|
clearEntropyFeedback();
|
||||||
// Get entropy value
|
// Get entropy value
|
||||||
var entropyStr = DOM.entropy.val();
|
var entropyStr = DOM.entropy.val();
|
||||||
// Work out minimum base for entropy
|
// Work out minimum base for entropy
|
||||||
@@ -18901,7 +18922,8 @@ exports.BigInteger = BigInteger;
|
|||||||
}
|
}
|
||||||
// Discard trailing entropy
|
// Discard trailing entropy
|
||||||
var bitsToUse = Math.floor(bits.length / 32) * 32;
|
var bitsToUse = Math.floor(bits.length / 32) * 32;
|
||||||
var binaryStr = bits.substring(0, bitsToUse);
|
var start = bits.length - bitsToUse;
|
||||||
|
var binaryStr = bits.substring(start);
|
||||||
// Convert entropy string to numeric array
|
// Convert entropy string to numeric array
|
||||||
var entropyArr = [];
|
var entropyArr = [];
|
||||||
for (var i=0; i<binaryStr.length / 8; i++) {
|
for (var i=0; i<binaryStr.length / 8; i++) {
|
||||||
@@ -18915,14 +18937,15 @@ exports.BigInteger = BigInteger;
|
|||||||
DOM.phrase.val(phrase);
|
DOM.phrase.val(phrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideEntropyFeedback() {
|
function clearEntropyFeedback() {
|
||||||
DOM.entropyFeedback.addClass("hidden");
|
DOM.entropyStrength.text("...");
|
||||||
DOM.entropyFiltered.text("");
|
|
||||||
DOM.entropyType.text("");
|
DOM.entropyType.text("");
|
||||||
DOM.entropyStrength.text("");
|
DOM.entropyWordCount.text("0");
|
||||||
DOM.entropyEventCount.text("");
|
DOM.entropyEventCount.text("0");
|
||||||
DOM.entropyBits.text("");
|
DOM.entropyBitsPerEvent.text("0");
|
||||||
DOM.entropyBitsPerEvent.text("");
|
DOM.entropyBits.text("0");
|
||||||
|
DOM.entropyFiltered.html(" ");
|
||||||
|
DOM.entropyBinary.html(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function showEntropyFeedback(entropy) {
|
function showEntropyFeedback(entropy) {
|
||||||
@@ -18954,16 +18977,15 @@ exports.BigInteger = BigInteger;
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
var bitsStr = entropy.binaryStr.length;
|
var bitsStr = entropy.binaryStr.length;
|
||||||
if (entropy.base.asInt != 2) {
|
var wordCount = Math.floor(entropy.binaryStr.length / 32) * 3;
|
||||||
bitsStr += " (" + entropy.binaryStr + ")";
|
DOM.entropyFiltered.html(entropy.cleanHtml);
|
||||||
}
|
|
||||||
DOM.entropyFiltered.text(entropy.cleanStr);
|
|
||||||
DOM.entropyType.text(entropy.base.str);
|
DOM.entropyType.text(entropy.base.str);
|
||||||
DOM.entropyStrength.text(strength);
|
DOM.entropyStrength.text(strength);
|
||||||
DOM.entropyEventCount.text(entropy.base.ints.length);
|
DOM.entropyEventCount.text(entropy.base.ints.length);
|
||||||
DOM.entropyBits.text(bitsStr);
|
DOM.entropyBits.text(bitsStr);
|
||||||
|
DOM.entropyWordCount.text(wordCount);
|
||||||
|
DOM.entropyBinary.text(entropy.binaryStr);
|
||||||
DOM.entropyBitsPerEvent.text(Math.log2(entropy.base.asInt).toFixed(2));
|
DOM.entropyBitsPerEvent.text(Math.log2(entropy.base.asInt).toFixed(2));
|
||||||
DOM.entropyFeedback.removeClass("hidden");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var networks = [
|
var networks = [
|
||||||
|
|||||||
Reference in New Issue
Block a user