-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsacred.html
More file actions
285 lines (244 loc) · 10 KB
/
sacred.html
File metadata and controls
285 lines (244 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html>
<html lang="en">
<head>
<title>D++</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--link rel="shortcut icon" type="image/jpg" href="taproot.ico"/-->
<base target="_blank"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=PT+Sans+Narrow:wght@400;700&family=Roboto:wght@300;400;500&display=swap');
</style>
<link rel="stylesheet" href="files/style.css">
<script src="files/words.js"></script>
</head>
<script>
var fullWords = "";
var checksumType;
var checksum;
function binString2buf(string) {
var result = new Uint8Array(16);
for (var i = 0; i < 16; i++) {
// taking 8 bytes and putting it into 8 bits
// console.log("loop #" + i);
result[i] = 0;
for (var c = 0; c < 8; c++) {
if (Number(string[i*8 + c]) === 1) {
result[i] |= 1 << (7 - c);
}
}
}
return result;
}
function buf2bin(buffer) {
var view = new Uint8Array(buffer);
var result = "";
for (var i = 0; i < view.length; i++) {
var binary = view[i].toString(2);
binary = "00000000".substr(binary.length) + binary;
result += binary;
}
return result;
}
function buf2hex(buffer) {
// buffer is an ArrayBuffer
return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
}
async function shaMe(inputString) {
console.log("inputstring is " + inputString);
var inputBytes = binString2buf(inputString);
console.log("inputBytes is " + inputBytes);
var hashBytes = await window.crypto.subtle.digest("SHA-256", inputBytes);
return buf2bin(hashBytes);
}
function convertBin() {
var binary = document.getElementById("binary").value;
if (binary == "")
$("#result").html("Please input a binary number.");
else {
binary = parseInt(binary, 2);
console.log(binary);
console.log();
$("#result").html("<center><b>Result:</b><br>" + wordlist[binary] + "<br><br><b>Decimal:</b><br>" + binary);
}
}
function isNumberKey(evt, element, max) {
var charCode = (evt.which) ? evt.which : event.keyCode;
var len = $(element).val().length;
if (len >= max)
return false;
if (charCode != 48 && charCode != 49)
return false;
}
function searchStringInArray(str, strArray, addToList) {
str = str.toLowerCase();
for (var j = 0; j < strArray.length; j++) {
if (strArray[j].startsWith(str)) {
// console.log('we found a match, it is ' + strArray[j]);
if (addToList)
fullWords += strArray[j] + " ";
return j;
}
}
console.log("No match was found for " + str);
return -1;
}
function hex2bin(hex){
return ("00000000" + (parseInt(hex, 16)).toString(2)).substr(-8);
}
function getChecksumType() {
// check to see if checksum type is binary, words, or dice rolls
if (/^\d{2}$/.test(checksum)) {
checksumType = "dice";
}
else if (/^[01]+$/.test(checksum)) {
checksumType = "binary";
}
else if (/^[a-z]+$/.test(checksum)) {
checksumType = "word";
}
else {
checksumType = "unknown";
}
}
async function getChecksum() {
var key = "";
var wallet = "";
fullWords = "";
checksum = $('#checksum').val();
getChecksumType();
var words = document.getElementsByClassName("bip-input");
for (var i = 0; i < words.length; i++) {
var binary = words[i].value;
console.log(binary);
if (binary == "") {
$("#checksum-result").html("Please enter valid seed words.");
document.getElementById("qrcode-container").style.display = "none";
return false;
}
wallet = wallet + binary + " ";
binary = searchStringInArray(binary, wordlist, true);
if (binary < 0) {
console.log("word not found in list");
$("#checksum-result").html("Invalid seed words.");
document.getElementById("qrcode-container").style.display = "none";
return false;
}
binary = binary.toString(2);
binary = "00000000000".substr(binary.length) + binary;
key += binary;
}
console.log("wallet is " + wallet);
if (checksum == "") {
$("#checksum-result").html("Please enter the first seven bits of the checksum.");
document.getElementById("qrcode-container").style.display = "none";
return false;
}
// CHECKSUM TIME
// they can type in the binary, dice rolls, or word to 'repair'
if (checksumType == "word") {
checksum = searchStringInArray(checksum, wordlist, false);
console.log("checksum is: " + checksum);
checksum = checksum.toString(2);
checksum = "00000000000".substr(checksum.length) + checksum;
console.log("checksum in binary is: " + checksum);
// now take the first 7 bits
checksum = checksum.substring(0, 7);
console.log("truncated: " + checksum);
}
key += checksum;
console.log("key is " + key);
console.log("key length is " + key.length);
var result = await shaMe(key);
var hash = result.substring(0, 4);
hash = Number(checksum + hash);
var twentyFour = wordlist[parseInt(hash, 2)];
wallet += twentyFour;
fullWords += twentyFour;
generateQRCode(wallet);
console.log(wallet);
$("#checksum-result").html("<b>Checksum:</b><br>" + twentyFour + "<br><br><b>Binary:</b><br>" + key + "<br><br><b>Hash:</b><br>" + result + "<br><br><b>Seed Phrase:</b><br>" + fullWords);
}
function autofill(word, checksum) {
$(".bip-input").val(word);
$('#checksum').val(checksum);
}
function generateQRCode(string) {
let qrcodeContainer = document.getElementById("qrcode");
qrcodeContainer.innerHTML = "";
new QRCode(qrcodeContainer, string);
document.getElementById("qrcode-container").style.display = "block";
}
</script>
<body>
<header>
<!--img src=images/Title.png style="width:500px; max-width:95%"-->
</header>
<br>
<!-- <h3>Convert Binary to BIP 39 word</h3>
<input class="button-class" placeholder="11 Bit Binary Number" id="binary" onkeypress="return isNumberKey(event,this, 11)"><br>
<button class="button-class" onclick="convertBin()">Convert</button>
<br><br>
<div id="result"></div>
<br><br> -->
<h3>Calculate Hash of Seed Phrase</h3>
<center>
<button onclick="autofill('abandon', '0000000')">Autofill (All Zeros)</button>
<button onclick="autofill('zoo', '1111111')">Autofill (All Ones)</button><br>
<button onclick="autofill('bacon', '0000000')" style="margin-top:5px">Autofill (All Bacons)</button>
<br><br>
<div class="container">
<div class="row">
<div class="col-sm-6 text-center"><span class="number">1.</span><input class="bip-input"></div>
<div class="col-sm-6 text-center"><span class="number">2.</span><input class="bip-input"></div>
</div>
<div class="row">
<div class="col-sm-6 text-center"><span class="number">3.</span><input class="bip-input"></div>
<div class="col-sm-6 text-center"><span class="number">4.</span><input class="bip-input"></div>
</div>
<div class="row">
<div class="col-sm-6 text-center"><span class="number">5.</span><input class="bip-input"></div>
<div class="col-sm-6 text-center"><span class="number">6.</span><input class="bip-input"></div>
</div>
<div class="row">
<div class="col-sm-6 text-center"><span class="number">7.</span><input class="bip-input"></div>
<div class="col-sm-6 text-center"><span class="number">8.</span><input class="bip-input"></div>
</div>
<div class="row">
<div class="col-sm-6 text-center"><span class="number">9.</span><input class="bip-input"></div>
<div class="col-sm-6 text-center"><span class="number">10.</span><input class="bip-input"></div>
</div>
<div class="row">
<div class="col-sm-6 text-center"><span class="number">11.</span><input class="bip-input"></div>
<!-- checksum -->
<!-- <div class="col-sm-6 text-center">
<span class="number" style="margin-left:-18px;">12.</span>
<select id="checksum-selector" class="bip-input" style="padding: 2px 1px; width:calc(80% + 16px);
margin-left:-4px;">
<option value="default-value">Checksum</option>
<option value="input-binary">Input binary</option>
<option value="input-8d-8d-8d">Input 3d8</option>
<option value="input-16d-8d">Input 1d16 1d8</option>
<option value="generate-random">Generate Random</option>
</select>
</div> -->
<div class="col-sm-6 text-center"><span class="number">12.</span><input id="checksum"></div>
<!-- <div class="col-sm-6 text-center"><span class="number">12.</span><input id="checksum-8-8-8" class="input" placeholder="checksum word to 'repair'"></div> -->
<!-- <div class="col-sm-6 text-center"><span class="number">12.</span><input id="checksum-8-8-8" class="input" placeholder="First 7 bits of checksum" onkeypress="return isNumberKey(event,this, 7)"></div>
<div class="col-sm-6 text-center"><span class="number">12.</span><input id="checksum-16-8" class="input" placeholder="First 7 bits of checksum" onkeypress="return isNumberKey(event,this, 7)"></div>
<div class="col-sm-6 text-center"><span class="number">12.</span><input id="checksum" class="input" placeholder="First 7 bits of checksum" onkeypress="return isNumberKey(event,this, 7)"></div> -->
</div>
</div>
<button onclick="getChecksum()" class="button-class">Calculate Checksum</button>
<div id="possible-checksums-result"></div>
<div id="checksum-result"></div>
<div id="qrcode-container" style="margin-top:25px;">
<div id="qrcode" class="qrcode"></div>
</div>
<script src="files/footer.js"></script>
</html>