-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
126 lines (110 loc) · 3.38 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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/mvp.css" />
</head>
<body>
<header>
<h1>
<a href="https://github.com/therootcompany/passphrase.js"
>Passphrase.js</a
>
</h1>
<p>
<strong>Passphrase & Key Generator</strong> for Browser JavaScript.
</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/@root/passphrase"></script>
<br /><script>Passphrase.generate(128).then(console.log)</script></code
>
</header>
<main>
<section>
<button class="js-generate">Generate New Passphrase</button>
</section>
<section>
<form>
<label
>Passphrase:
<textarea class="js-passphrase" cols="25" rows="4">
ozone drill grab fiber curtain grace pudding thank cruise elder eight picnic</textarea
>
</label>
<label
>Salt:
<input class="js-salt" value="TREZOR" />
</label>
<button type="submit">Derive Key</button>
</form>
</section>
<section>
<pre>Key: <code class="js-key"></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="./passphrase.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);
}
// Passphrase Demo & Tests
// See https://github.com/therootcompany/passphrase.js
function rethrow(err) {
window.alert(err.message);
throw err;
}
async function deriveKey() {
let passphrase = $(".js-passphrase").value;
let salt = $(".js-salt").value;
await Passphrase.checksum(passphrase).catch(rethrow);
let key = await Passphrase.pbkdf2(passphrase, salt);
$(".js-key").innerText = PassphraseTest.bytesToHex(key);
}
$(".js-generate").addEventListener("click", async function (ev) {
ev.preventDefault();
ev.stopPropagation();
let passphrase = await Passphrase.generate(128).catch(rethrow);
await Passphrase.checksum(passphrase).catch(rethrow);
$(".js-passphrase").value = passphrase;
await deriveKey();
});
$("form").addEventListener("submit", async function (ev) {
ev.preventDefault();
ev.stopPropagation();
await deriveKey();
});
deriveKey().catch(rethrow);
</script>
<script src="./test.js"></script>
<script>
PassphraseTest.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>