-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
216 lines (190 loc) · 8.47 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bip39 Shamir</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="js/bundle.js"></script>
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<div class="container">
<h1 class="display-4 text-center mt-5">Bip39 Splitter</h1>
<p class="lead text-center">
Securely split your Bip39 seed in <strong>N</strong> different mnemonics. Any <strong>K</strong> of the new mnemonics are sufficient to reconstruct the original mnemonic.<br />
Based on <a href="https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing">Shamir's Secret Sharing.</a>
</p>
<!-- Navigation -->
<ul class="nav nav-tabs mt-5" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="create-tab" data-toggle="tab" href="#create" role="tab" aria-controls="create" aria-selected="true">Create Shares</a>
</li>
<li class="nav-item">
<a class="nav-link" id="recover-tab" data-toggle="tab" href="#recover" role="tab" aria-controls="recover" aria-selected="false">Recover Bip39 Seed</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active mt-2" id="create" role="tabpanel" aria-labelledby="create-tab">
<!-- Create Tab -->
<form>
<div class="card mt-4">
<div class="card-body">
<div class="form-group">
<label for="mnemonic-input">Bip39 Seed:</label>
<div class="input-group">
<input type="text" id="mnemonic-input" class="form-control" placeholder="mnemonic" aria-label="Bip39 Seed" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary" id="random" type="button">Random</button>
</div>
<div class="invalid-feedback">
Invalid Bip39 Seed.
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">N</span>
</div>
<input id="n-input" type="text" class="form-control" value="3" aria-label="N" aria-describedby="basic-addon1">
<div class="invalid-feedback">
Must be a value between 2 and 255.
</div>
</div>
<small class="form-text text-muted">
The number of shares to be generated.
</small>
</div>
<div class="col-6">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">K</span>
</div>
<input id="k-input" type="text" class="form-control" value="2" aria-label="K" aria-describedby="basic-addon1">
<div class="invalid-feedback">
Must be a value between 2 and N.
</div>
</div>
<small class="form-text text-muted">
The number of shares needed to recover the secret.
</small>
</div>
</div>
</div>
</div>
<div class="mt-3 text-center">
<button id="refresh" type="button" class="btn btn-dark btn-sm">New Random Shares</button>
</div>
<div class="mt-4">
<label for="shares-output">Shares:</label>
<ul id="shares-output" class="list-group">
</ul>
</div>
</form>
</div>
<div class="tab-pane mt-2" id="recover" role="tabpanel" aria-labelledby="recover-tab">
<!-- Recover Tab -->
<form>
<div class="form-group">
<label for="shares-input">Shares:</label>
<textarea class="form-control" id="shares-input" rows="6"></textarea>
<div id="shares-input-error" class="invalid-feedback"></div>
<small class="form-text text-muted">
Enter K of your shares separated by newlines to recover your Bip39 Seed.
</small>
</div>
<div class="form-group mt-3">
<label for="menmonic-output">Bip39 Seed:</label>
<input id="menmonic-output" class="form-control" type="text" readonly="readonly">
</div>
</form>
</div>
</div>
<div class="text-center mt-5 mb-5">
<hr class="col-xs-12">
<p>
Check out the code on <a href="https://github.com/jkandzi/bip39shamir-web">github</a> or download the <a href="https://github.com/jkandzi/bip39shamir-web/archive/master.zip">archive</a> to run locally.<br />
Follow me on twitter at <a href="https://twitter.com/jkandzi">@jkandzi</a>.
</p>
</div>
</div>
<script>
setValid = function(x, valid) {
if (valid) {
x.addClass('is-valid').removeClass('is-invalid');
} else {
x.addClass('is-invalid').removeClass('is-valid');
}
}
validateCreate = function() {
var n = parseInt($('#n-input').val());
var k = parseInt($('#k-input').val());
var mnemonic = $('#mnemonic-input').val();
var isNValid = n >= 2 && n <= 255;
var isKValid = k >= 2 && k <= n;
var isMnemonicValid = validateMnemonic(mnemonic);
setValid($('#n-input'), isNValid);
setValid($('#k-input'), isKValid);
setValid($('#mnemonic-input'), isMnemonicValid);
if (!isNValid || !isKValid || !isMnemonicValid) {
var list = $('#shares-output');
list.empty();
$('<li/>')
.addClass('list-group-item')
.appendTo(list);
}
}
createShares = function() {
var n = parseInt($('#n-input').val());
var k = parseInt($('#k-input').val());
var mnemonic = $('#mnemonic-input').val();
var s = shares(mnemonic, n, k);
var list = $('#shares-output');
list.empty();
$.each(s, function(i) {
$('<li/>')
.addClass('list-group-item')
.text(s[i])
.appendTo(list);
});
}
randomMnemonic = function() {
$('#mnemonic-input').val(random());
createShares();
}
$("#random").click(function() {
randomMnemonic();
});
$('#mnemonic-input, #n-input, #k-input').on('input', function(e) {
validateCreate();
createShares();
});
$('#refresh').on('click', function(e) {
createShares();
});
$('#shares-input').on('input', function(e){
var s = $('#shares-input').val().split('\n');
s = s.filter(function(x) {
return x !== "";
});
try {
var mnemonic = combine(s)
$('#menmonic-output').val(mnemonic);
setValid($('#shares-input'), true);
}
catch(error) {
$('#menmonic-output').val("");
$('#shares-input-error').html(error.message)
setValid($('#shares-input'), false);
}
});
randomMnemonic();
</script>
</body>
</html>