-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (117 loc) · 3.67 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://unpkg.com/mvp.css" />
</head>
<body>
<header>
<h1>
<a href="https://github.com/dashhive/dashphrase.js">Dashphrase.js</a>
</h1>
<p>
<strong>Dash HD Wallet Recovery Phrase & Seed Generator</strong>
<br />
<small>works in Node, Bundlers, and Browsers</small>
</p>
<p>BIP-39 (Base2048) Compatible. Lightweight. Zero Dependencies.</p>
<p>
<small
>20kb with comments. 17kb minified. 7.4kb gzipped. ~150 LoC.</small
>
</p>
<br />
<code
><script
src="https://unpkg.com/[email protected]/dashphrase.js"></script>
<br /><script>Dashphrase.generate(128).then(console.log)</script></code
>
</header>
<main>
<section>
<button class="js-generate">Generate New Recovery Phrase</button>
</section>
<section>
<form>
<label
>Recovery Phrase:
<textarea
class="js-recovery-phrase"
cols="25"
rows="4"
placeholder="zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong"
>
cat swing flag economy stadium alone churn speed unique patch report train</textarea
>
</label>
<label
>Salt:
<input class="js-salt" value="TREZOR" />
</label>
<button type="submit">Derive Seed</button>
</form>
</section>
<section>
<pre>Seed: <code class="js-seed"></code></pre>
</section>
<hr />
<section>
<header>
<h3>Browser Compatibility (current browser)</h3>
</header>
<pre><code class="js-tests">Running tests... (or tests failed)</code></pre>
</section>
</main>
<script src="./dashphrase.js"></script>
<script>
// AJQuery
// See https://github.com/coolaj86/ajquery.js
function $(sel, el) {
return (el || document).querySelector(sel);
}
function $$(sel, el) {
return (el || document).querySelectorAll(sel);
}
// Dashphrase Demo & Tests
// See https://github.com/dashhive/dashphrase.js
function rethrow(err) {
window.alert(err.message);
throw err;
}
async function deriveSeed() {
let recoveryPhrase = $(".js-recovery-phrase").value;
let salt = $(".js-salt").value;
await Dashphrase.checksum(recoveryPhrase).catch(rethrow);
let seedBytes = await Dashphrase.toSeed(recoveryPhrase, salt);
$(".js-seed").innerText = DashPhraseTest.bytesToHex(seedBytes);
}
$(".js-generate").addEventListener("click", async function (ev) {
ev.preventDefault();
ev.stopPropagation();
let recoveryPhrase = await Dashphrase.generate(128).catch(rethrow);
await Dashphrase.checksum(recoveryPhrase).catch(rethrow);
$(".js-recovery-phrase").value = recoveryPhrase;
await deriveSeed();
});
$("form").addEventListener("submit", async function (ev) {
ev.preventDefault();
ev.stopPropagation();
await deriveSeed();
});
deriveSeed().catch(rethrow);
</script>
<script src="./test.js"></script>
<script>
DashPhraseTest.run()
.then(function () {
document.querySelector(".js-tests").innerText = "All Tests Pass";
})
.catch(function (err) {
console.error(err);
document.querySelector(
".js-tests",
).innerText = `Tests FAILED: ${err.message}`;
});
</script>
</body>
</html>