-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
12203 lines (11954 loc) · 337 KB
/
Copy pathindex.html
File metadata and controls
12203 lines (11954 loc) · 337 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--
Everything this page is allowed to do is listed here, and nothing in the list reaches the
network. `default-src 'none'` denies every resource the page could load; `connect-src 'none'`
denies every outbound connection it could open - requests, sockets and beacons alike - so the
keys you decode below cannot leave this tab even if some future edit tried to send them
anywhere. The two 'unsafe-inline' entries are what
lets the single-file page carry its own script and stylesheet; there is deliberately no
'unsafe-eval', no external origin, and no CDN.
-->
<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src 'none'; connect-src 'none'; form-action 'none'; base-uri 'none'">
<title>StaticBit Wallet Backup Decoder</title>
<style>
/*
* The wallet's palette, copied here by hand.
*
* This page has to stay a single file that opens from a USB stick, so it cannot pull in the
* wallet's stylesheets; the values are therefore written out as numbers. This block is the
* only place in the page where a literal colour appears - everything below refers to these
* variables, so the next change of palette is a change of this block alone.
*
* Taken from, and to be kept in step with:
* src/[Clients]/SB.MobileApp/wwwroot/scss/common/var-colors.scss
* src/[Clients]/SB.MobileApp/wwwroot/scss/components/buttons.scss (.btn-success)
*
* There is no light theme, deliberately: the wallet has none either. The brightest thing on
* the page is #F9F9F9 text on #0D0D0D, and nothing is allowed to go brighter than that pair.
*/
:root {
color-scheme: dark;
--bg: #0D0D0D; /* $bg-color - the page itself */
--box: #1A1A1A; /* $box-bg-color - card, panel, message */
--sunken: #1C1C1C; /* $third-color - inset block inside a card */
--border: #282828; /* $dark-gray-color - field borders, separators */
--secondary-surface: #202222;/* $secondary-dark-color - secondary button */
--ink: #F9F9F9; /* $primary-color - body text */
--muted: #A8A8A8; /* $secondary-color - captions, labels, detail */
--positive: #64CF95; /* $positive-color - success */
--green: #5ECEAB; /* $green-color - accent, focus ring */
--negative: #D6776A; /* $negative-color - danger, failure */
--danger-light: #DBB6A2; /* $danger-light-color - soft warning, work in progress */
/*
* The one value that deliberately departs from the wallet. components/input.scss uses #555
* for a placeholder, but there the field sits on $box-bg-color (#1A1A1A); here every field
* sits on the page itself (#0D0D0D), and #555 against that is 2.6:1 - too faint to read on a
* laptop screen in a lit room, which is the situation this page is for. #808080 against the
* same ground is 4.9:1, past the 4.5:1 line, while staying well below the 8.9:1 of --muted -
* so a placeholder still reads as a placeholder and not as text somebody typed.
*/
--placeholder: #808080;
/* .btn-success: the wallet's primary button is this gradient with dark text on it. */
--accent: linear-gradient(90deg, #79D2CC 0%, #5ECEAB 100%);
--accent-ink: #1C1C1C;
--radius: 10px; /* the radius of every card in the wallet */
--radius-sm: 8px;
--sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body {
margin: 0;
padding: 24px 16px 64px;
background: var(--bg);
color: var(--ink);
font: 15px/1.55 var(--sans);
-webkit-text-size-adjust: 100%;
}
main { max-width: 720px; margin: 0 auto; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 6px; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 14px; }
p { margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
/*
* position: relative has no visual effect here. It is the containing block for the off-screen
* file inputs below, so that focusing one - which is what clicking its label does - cannot
* scroll the page to a 1px box parked at the top-left corner of the document.
*/
.panel {
position: relative;
background: var(--box);
border-radius: var(--radius);
padding: 16px;
margin-bottom: 16px;
}
/*
* The wallet has no yellow "warning" plate anywhere. A dangerous thing there is an ordinary
* card whose text is written in the negative colour - see the secret key screen,
* Pages/Settings/Account/RevealSecret.razor.
*
* Note what carries the colour there, though: one short line. Three paragraphs set in #D6776A
* is not that screen's pattern - it is a wall of red, and a wall of red is read as decoration
* and skipped. So the heading is the warning and the body is ordinary secondary text.
*/
.notice { font-size: 14px; color: var(--muted); }
.notice strong { display: block; margin-bottom: 10px; color: var(--negative); }
.notice ul { margin: 0; padding-left: 20px; }
.notice li { margin-bottom: 8px; }
.notice li:last-child { margin-bottom: 0; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.choice { display: flex; gap: 20px; margin-bottom: 16px; flex-wrap: wrap; }
.choice label { color: var(--ink); margin: 0; display: flex; gap: 8px; align-items: center; }
input[type="radio"] { accent-color: var(--green); width: 16px; height: 16px; margin: 0; }
input[type="password"], input[type="text"], textarea {
width: 100%;
font: inherit;
color: var(--ink);
background: var(--bg);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 11px 12px;
}
input::placeholder, textarea::placeholder { color: var(--placeholder); }
textarea {
min-height: 110px;
resize: vertical;
font-family: var(--mono);
font-size: 13px;
}
/*
* Both file pickers are off screen. The drop zone below is what the reader clicks, and a
* second, differently shaped OS control standing next to it would only raise the question of
* which of the two to use. The input stays in the layout rather than display:none, because
* display:none takes it out of the tab order and stops its <label> from reaching it - and the
* label is how somebody on a screen reader gets to the picker at all.
*/
.offscreen {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
border: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1 1 240px; }
/*
* The upload zone. A file arrives here by click and by drag; a picture also arrives by Ctrl+V.
*
* This is the one dashed border on the page, and the wallet has none. The block used to be the
* wallet's plain inset card carrying a sentence - "Drop a picture here, paste one with Ctrl+V,
* or choose a file" - and read as a sentence it stayed a sentence: an instruction, not a place
* you press. The dashed rectangle with an arrow in it is the one shape every upload control on
* the web shares, so a reader recognises it before reading a word of it. The exception buys
* that recognition and nothing else: the colours, the radius and the type are still the
* wallet's.
*
* It is a real <button>, so Enter, Space, the focus ring and the screen-reader role come from
* the browser rather than from ARIA attributes that have to be kept honest by hand.
*/
.drop {
display: block;
width: 100%;
font: inherit;
text-align: center;
color: var(--ink);
background: var(--sunken);
border: 1px dashed var(--border);
border-radius: var(--radius-sm);
padding: 22px 16px;
cursor: pointer;
transition: border-color .12s ease, background-color .12s ease;
}
.drop:hover { border-color: var(--green); }
/* The answer to "will it take this if I let go here?" has to be visible while dragging. */
.drop.over { border-color: var(--green); background: var(--secondary-surface); }
.drop-icon {
display: block;
width: 34px;
height: 34px;
margin: 0 auto 12px;
fill: none;
stroke: var(--muted);
stroke-width: 1.6;
stroke-linecap: round;
stroke-linejoin: round;
transition: stroke .12s ease;
}
.drop:hover .drop-icon, .drop.over .drop-icon { stroke: var(--green); }
.drop-title { display: block; font-size: 15px; font-weight: 500; }
.drop-note {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
/*
* The line that says what the page just read.
*
* It used to be an ordinary grey caption and it was missed - the reader pasted a screenshot
* and could not tell whether anything had happened. The owner settled the colour: the wallet's
* green, #5ECEAB, with something drawn around it.
*
* It is an outlined chip and not a filled green plate on purpose. The page's primary button is
* a solid #79D2CC -> #5ECEAB gradient; a second solid green rectangle in the same column would
* read as a second button. Sharing the colour while keeping the opposite shape - hairline
* outline, sunken ground, green text and a tick - makes it unmistakable without making it look
* pressable. It also sits in a different card from the button, with the whole "2. Password"
* heading in between.
*/
.accepted {
display: flex;
align-items: center;
gap: 10px;
margin: 12px 0 0;
padding: 10px 12px;
background: var(--sunken);
border: 1px solid var(--green);
border-radius: var(--radius-sm);
color: var(--green);
font-family: var(--mono);
font-size: 13px;
}
/* An author rule beats the browser's [hidden], so display:none has to be said again here. */
.accepted[hidden] { display: none; }
.accepted-icon {
flex: none;
width: 18px;
height: 18px;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
.accepted-text { min-width: 0; word-break: break-word; }
/* The same chip, saying the opposite thing: what arrived was not something we can read. */
.accepted.rejected { border-color: var(--negative); color: var(--negative); }
button {
font: inherit;
font-weight: 500;
min-height: 44px;
padding: 10px 20px;
border: 0;
border-radius: var(--radius);
background: var(--secondary-surface);
color: var(--ink);
cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button[disabled] { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.actions { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.actions button { flex: 1 1 160px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; word-break: break-word; }
/* A result, a warning and a failure are all the same card; only the title carries the colour. */
.msg {
background: var(--box);
border-radius: var(--radius);
padding: 16px;
margin-bottom: 16px;
}
.msg strong { display: block; font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.msg p { color: var(--muted); font-size: 14px; margin: 0; }
.msg p + p { margin-top: 8px; }
.msg.ok strong { color: var(--positive); }
.msg.warn strong { color: var(--danger-light); }
.msg.error strong { color: var(--negative); }
/*
* "Working..." is not a warning, and giving it the warning colour told the reader something had
* gone wrong at the exact moment nothing had. It is a plain card with a plain heading.
*/
.msg.busy strong { color: var(--ink); }
.wallet {
background: var(--box);
border-radius: var(--radius);
padding: 16px;
margin-bottom: 16px;
}
.wallet h3 {
margin: 0 0 14px;
font-size: 14px;
font-weight: 500;
font-family: var(--mono);
word-break: break-all;
}
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field .name { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.field .value {
font-family: var(--mono);
font-size: 13px;
margin-top: 4px;
word-break: break-word;
white-space: pre-wrap;
}
/* A secret sits in its own inset block, so it is never mistaken for an ordinary field. */
.secret {
background: var(--sunken);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 12px;
}
.secret .value { user-select: all; }
.secret .masked { color: var(--muted); letter-spacing: .18em; }
.secret button {
margin-top: 12px;
min-height: 36px;
padding: 6px 16px;
font-size: 13px;
border-radius: var(--radius-sm);
}
/*
* "Or do not trust this page at all - here is where it comes from."
*
* It sits inside the same plate that asks for the password, below the list rather than in it.
* A reader who came to open their own backup skims that plate once and moves on, exactly as
* before; a reader who came to check first finds the way out of the page at the one point
* where trust is actually being asked for, which is above the password field and not in a
* footer they would reach after typing into it. The hairline is what marks the change of
* subject: the bullets above are things to do here, this is how to stop reading and go look.
*/
.verify { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.verify p { margin: 0; }
.verify p + p { margin-top: 10px; }
/*
* The only link in the page. It takes the wallet's green rather than the browser's blue, and
* the arrow says it leaves for a new tab before the reader has to find that out by pressing
* it. The underline is kept for hover only: at rest this is one line of monospace among the
* page's several, and a permanent underline inside a paragraph of grey warnings pulls harder
* than a way out of the page needs to.
*/
.repo {
display: inline-flex;
align-items: flex-start;
gap: 8px;
margin-top: 10px;
color: var(--green);
font-family: var(--mono);
font-size: 13px;
text-decoration: none;
border-bottom: 1px solid transparent;
/*
* anywhere, not break-all: on a phone this address does not fit on one line, and the two
* spellings differ in where it gives way. break-all splits at whatever character lands on
* the edge - "wallet-backup-dec / oder" - while anywhere still prefers the breaks the URL
* already has, so it comes apart at a slash and stays readable as an address.
*/
overflow-wrap: anywhere;
}
.repo:hover { border-bottom-color: var(--green); }
.repo-icon {
flex: none;
width: 15px;
height: 15px;
/* Sits on the first line when the address wraps, not floating beside the middle of two. */
margin-top: 2px;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
/*
* The clone line borrows the click-to-select of a decoded secret above: one click puts the
* whole command on the clipboard's doorstep. No script, no clipboard permission, and no button
* that could report having copied something it did not - on a page whose whole claim is that
* it does nothing behind the reader's back, a copy button would be the one part of it they
* would have to take on trust.
*/
.clone {
display: block;
margin: 10px 0;
padding: 10px 12px;
background: var(--sunken);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
color: var(--ink);
font-size: 13px;
line-height: 1.5;
user-select: all;
overflow-wrap: anywhere;
}
footer { color: var(--muted); font-size: 13px; margin-top: 28px; }
footer p:last-child { margin-bottom: 0; }
footer strong { font-weight: 600; color: var(--ink); }
code {
font-family: var(--mono);
font-size: 92%;
background: var(--secondary-surface);
border-radius: 4px;
padding: 1px 5px;
}
/* A phone is a plausible place to open this, so nothing may depend on a wide viewport. */
@media (max-width: 560px) {
body { padding: 16px 12px 48px; }
h1 { font-size: 20px; }
.panel, .msg, .wallet { padding: 14px; }
.row > input { flex: 1 1 100%; }
.row > button, .actions button { flex: 1 1 100%; width: 100%; }
/*
* The zone keeps its shape on a phone; only the air around the text is taken back. Its two
* lines wrap on their own, and it is full-width at every size, so nothing here has to widen
* it the way the buttons above have to be widened.
*/
.drop { padding: 18px 12px; }
.drop-icon { width: 30px; height: 30px; margin-bottom: 10px; }
}
</style>
</head>
<body>
<main>
<h1>StaticBit Wallet Backup Decoder</h1>
<p class="sub">Opens a StaticBit wallet backup — the <code>.sbwallet</code> file, a picture of the backup QR code, or the text of that code — and shows the keys inside it.</p>
<section class="panel notice">
<strong>Read this before you type your password.</strong>
<ul>
<li>Save this page to a USB stick and open it on a computer with no network connection. That is the safest way to use it, and this page is a single file with no external fonts, stylesheets or scripts precisely so that it still works there.</li>
<li>Nothing you enter here is sent anywhere. Everything happens inside this browser tab; the page keeps no cookies and writes nothing to browser storage. You do not have to take that on trust — use "View source" (or open the file in any text editor): the code is not minified, and the Content-Security-Policy in the page header forbids every kind of network request, including <code>connect-src</code>.</li>
<li>Close the tab when you are done, and clear anything you copied out of it.</li>
</ul>
<div class="verify">
<p>If you would rather not trust this website at all, take the source and open your own copy. The site is published straight from the repository below — no build step, no minifier, nothing generated — so the file served here is the file committed there, byte for byte, and what you clone is what you have been reading.</p>
<a class="repo" href="https://github.com/StaticBit-io/wallet-backup-decoder" target="_blank" rel="noopener noreferrer">
<svg class="repo-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M14 4h6v6"/>
<path d="M20 4 11 13"/>
<path d="M18 14v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4"/>
</svg>
<span>github.com/StaticBit-io/wallet-backup-decoder</span>
<span class="offscreen">(opens in a new tab)</span>
</a>
<code class="clone">git clone https://github.com/StaticBit-io/wallet-backup-decoder.git</code>
<p>That address is the only one written anywhere in this page, and it stays a link: going there is a step you take, in a new tab, not a request this page makes. Nothing is fetched from GitHub while you read this, and nothing you have typed is carried along when you leave. Follow it or ignore it — either way, what you enter above stays in this tab. Click the command to select the whole of it.</p>
</div>
</section>
<section class="panel">
<h2>1. Load the backup</h2>
<div class="choice">
<label><input type="radio" name="source" value="file" id="source-file" checked> Backup file</label>
<label><input type="radio" name="source" value="image" id="source-image"> QR code picture</label>
<label><input type="radio" name="source" value="code" id="source-code"> QR code text</label>
</div>
<div id="file-block">
<label for="file-input">Backup file (<code>.sbwallet</code>)</label>
<button type="button" class="drop" id="file-drop">
<svg class="drop-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M12 15.5V3.5"/>
<path d="M7.5 8 12 3.5 16.5 8"/>
<path d="M3.5 15.5v3a2 2 0 0 0 2 2h13a2 2 0 0 0 2-2v-3"/>
</svg>
<span class="drop-title">Drag or click to upload a file</span>
<span class="drop-note">The <code>.sbwallet</code> file the wallet wrote when you saved the backup.</span>
</button>
<input type="file" id="file-input" class="offscreen">
<p class="accepted" id="file-hint" aria-live="polite" hidden>
<svg class="accepted-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="accepted-mark" d="M20 6 9 17l-5-5"/></svg>
<span class="accepted-text"></span>
</p>
</div>
<div id="image-block" hidden>
<label for="image-input">Photo or screenshot of the backup QR code</label>
<button type="button" class="drop" id="image-drop">
<svg class="drop-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M12 15.5V3.5"/>
<path d="M7.5 8 12 3.5 16.5 8"/>
<path d="M3.5 15.5v3a2 2 0 0 0 2 2h13a2 2 0 0 0 2-2v-3"/>
</svg>
<span class="drop-title">Drag or click to upload a file</span>
<span class="drop-note">PNG, JPEG, WebP or GIF. You can also paste a picture straight from the clipboard with <code>Ctrl</code>+<code>V</code>.</span>
</button>
<input type="file" id="image-input" accept="image/*" class="offscreen">
<p class="accepted" id="image-hint" aria-live="polite" hidden>
<svg class="accepted-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="accepted-mark" d="M20 6 9 17l-5-5"/></svg>
<span class="accepted-text"></span>
</p>
<p class="hint">The picture is read inside this tab and is never uploaded. A screenshot of the wallet's QR screen is the easiest thing to read; a photograph works too if the whole code is in frame, in focus, and not at a steep angle.</p>
</div>
<div id="code-block" hidden>
<label for="code-input">Text scanned from the backup QR code</label>
<textarea id="code-input" spellcheck="false" autocapitalize="off" autocomplete="off" placeholder="TNA11B..."></textarea>
<p class="hint">Every StaticBit backup code starts with <code>TNA11B</code>. Line breaks introduced by copying are ignored.</p>
</div>
</section>
<section class="panel">
<h2>2. Password</h2>
<div class="row">
<input type="password" id="password-input" autocomplete="off" spellcheck="false" placeholder="Backup password">
<button type="button" id="password-toggle">Show</button>
</div>
<p class="hint">Leave empty for a backup that was made without a password. Those exist only as an on-screen QR code.</p>
<div class="actions">
<button type="button" class="primary" id="decode-button">Decode</button>
<button type="button" id="clear-button">Clear</button>
</div>
</section>
<div id="status" aria-live="polite"></div>
<div id="results"></div>
<footer>
<p>Reads the container format used by the StaticBit wallet: <code>SBW1</code> header, PBKDF2-HMAC-SHA256, AES-256-GCM, raw DEFLATE, Base45 for QR codes. Decrypting and decompressing use only the browser's own WebCrypto and DecompressionStream.</p>
<p>Reading a QR code out of a picture uses the browser's own <code>BarcodeDetector</code> where it exists. Where it does not — Firefox and Safari — the page falls back to a copy of <strong>jsQR 1.4.0</strong> (Apache License 2.0, <code>github.com/cozmo/jsQR</code>) carried inside this file, unminified, with its licence, its provenance and the checksum of the published file it was copied from written out above it in the source.</p>
</footer>
</main>
<script id="backup-decoder-core">
/*
* StaticBit wallet backup - format core.
*
* This block is pure format code: it never touches the DOM and never performs I/O, so the test
* runner in run-tests.mjs extracts these exact bytes out of this file and executes them under
* Node. What is tested is therefore what is shipped, not a second copy of the same logic.
*
* Container layout, all multi-byte integers big-endian:
*
* "SBW1" (4) | version (1) | kdfId (1) | iterations (4) | salt (16) | nonce (12) | ciphertext (N) | tag (16)
*
* `iterations` and `salt` are present only when kdfId != 0. Everything up to the nonce - 26 bytes
* for a password-protected container - is fed to AES-GCM as associated data, which is what makes a
* tampered version byte, kdfId or salt byte detectable at all.
*
* When kdfId == 0 the payload was never encrypted: the header is just "SBW1" | version | 0 and the
* deflate-compressed plaintext follows immediately, with no salt, nonce or tag. The wallet only
* ever produces that form as an on-screen QR code.
*/
(function (root) {
'use strict';
var MAGIC = [0x53, 0x42, 0x57, 0x31]; // "SBW1"
var MAGIC_LENGTH = 4;
var SUPPORTED_VERSION = 1;
// magic + version + kdfId
var HEADER_PREFIX_LENGTH = MAGIC_LENGTH + 1 + 1;
var ITERATIONS_FIELD_LENGTH = 4;
var SALT_SIZE = 16;
var NONCE_SIZE = 12;
var TAG_SIZE = 16;
var KEY_BITS = 256;
// header used when kdfId != 0: prefix + iterations + salt
var PASSWORD_HEADER_LENGTH = HEADER_PREFIX_LENGTH + ITERATIONS_FIELD_LENGTH + SALT_SIZE;
var NO_PASSWORD_KDF_ID = 0;
// The same arithmetic the wallet uses: 1000 wallets of at most 4 KiB each, plus 4 KiB for the
// {"wallets":[...]} envelope. A deflate stream that wants to expand past this is refused rather
// than inflated, because a hostile "backup file" can otherwise turn a few kilobytes into
// gigabytes of memory.
var MAX_INFLATED_SIZE = (1000 * 4 * 1024) + (4 * 1024);
// What a container of ours can legitimately weigh on the wire: the password header, nonce and
// tag, the inflated ceiling above, and 64 KiB of slack because deflate is allowed to make
// incompressible input slightly larger rather than smaller.
var MAX_CONTAINER_SIZE =
PASSWORD_HEADER_LENGTH + NONCE_SIZE + TAG_SIZE + MAX_INFLATED_SIZE + (64 * 1024);
// The highest iteration count the wallet's own importer will run. Above it this page warns and
// proceeds anyway rather than refusing: the wallet refuses because a count chosen on a fast
// phone must not hang an import on a slow one, and this page exists for the case where the
// wallet is gone, which is the wrong moment to inherit that refusal.
var WALLET_ITERATIONS_CEILING = 1000000;
// A bound that only exists so a hostile 4-byte field cannot wedge the tab forever. Roughly a
// minute of PBKDF2 in a browser, and fifty times what the wallet has ever written.
var ABSOLUTE_ITERATIONS_LIMIT = 50000000;
// RFC 9285. Index equals value; 36 is the space.
var BASE45_ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';
var BASE45_BASE = 45;
var BASE45_BASE_SQUARED = BASE45_BASE * BASE45_BASE;
// Base45 of the "SBW1" magic, and therefore the first six characters of every backup code. It
// holds because Base45 encodes two-byte groups aligned to the start of the data, which makes the
// encoding of the first four bytes a genuine prefix of the encoding of the whole container.
var CODE_PREFIX = 'TNA11B';
// Alphanumeric capacity of the largest QR code the standard defines (version 40, level L).
// Nothing longer can be the contents of a QR code, so refusing it costs nothing and keeps a
// pasted megabyte from being expanded into one integer per character.
var MAX_CODE_LENGTH = 4296;
var KEY_TYPE_NAMES = {
0: 'None',
1: 'Seed',
2: 'Xumm numbers',
3: 'Mnemonic',
4: 'Text'
};
function fail(code, title, detail) {
return { ok: false, code: code, title: title, detail: detail };
}
function readUint32BE(bytes, offset) {
return (
(bytes[offset] * 16777216) +
(bytes[offset + 1] * 65536) +
(bytes[offset + 2] * 256) +
bytes[offset + 3]
);
}
function hasMagic(bytes) {
if (bytes.length < MAGIC_LENGTH) {
return false;
}
for (var i = 0; i < MAGIC_LENGTH; i++) {
if (bytes[i] !== MAGIC[i]) {
return false;
}
}
return true;
}
/**
* Whether these bytes begin with a header this page can read: our magic and a version it knows.
* Says nothing about whether the payload can be opened.
*/
function hasSupportedHeader(bytes) {
return bytes.length >= HEADER_PREFIX_LENGTH && hasMagic(bytes) && bytes[MAGIC_LENGTH] === SUPPORTED_VERSION;
}
/**
* Base45 decoding, RFC 9285. Three characters carry two bytes, two characters carry one; the
* least significant digit comes first. A length that leaves a single character over is not a
* valid encoding of anything.
*/
function base45Decode(text) {
if (typeof text !== 'string' || text.length % 3 === 1) {
return null;
}
var values = new Array(text.length);
for (var i = 0; i < text.length; i++) {
var position = BASE45_ALPHABET.indexOf(text.charAt(i));
if (position < 0) {
return null;
}
values[i] = position;
}
var output = [];
var index = 0;
while (index + 2 < values.length) {
var pair = values[index] + (values[index + 1] * BASE45_BASE) + (values[index + 2] * BASE45_BASE_SQUARED);
if (pair > 0xFFFF) {
return null;
}
output.push((pair >> 8) & 0xFF);
output.push(pair & 0xFF);
index += 3;
}
if (index < values.length) {
var single = values[index] + (values[index + 1] * BASE45_BASE);
if (single > 0xFF) {
return null;
}
output.push(single);
}
return new Uint8Array(output);
}
/**
* Turns the text a QR scanner (or the clipboard) hands back into container bytes.
*
* Carriage returns and newlines are stripped before decoding. They are not characters of the
* Base45 alphabet, so they cannot be part of a real code; they are, however, exactly what a
* copy-paste through a chat window or an email adds. Spaces are left alone, because a space IS a
* Base45 character and removing one would corrupt a valid code.
*/
function decodeBackupCode(text) {
if (typeof text !== 'string') {
return fail('NOT_A_BACKUP_CODE', 'Nothing to read', 'No text was given.');
}
var cleaned = text.replace(/[\r\n]/g, '').trim();
if (cleaned.length === 0) {
return fail('NOT_A_BACKUP_CODE', 'Nothing to read', 'The text box is empty.');
}
if (cleaned.length > MAX_CODE_LENGTH) {
return fail(
'NOT_A_BACKUP_CODE',
'This text is not a backup code',
'It is ' + cleaned.length + ' characters long. The largest QR code the standard defines holds ' +
MAX_CODE_LENGTH + ', so this cannot be the contents of one.');
}
var bytes = base45Decode(cleaned);
if (bytes === null) {
return fail(
'NOT_A_BACKUP_CODE',
'This text is not a backup code',
'It is not valid Base45. A backup code uses only digits, capital letters, space and the ' +
'characters $%*+-./: and it starts with ' + CODE_PREFIX + '. Check that you copied the whole ' +
'code and that nothing lower-case crept in.');
}
return { ok: true, bytes: bytes };
}
function requireDecompression() {
return typeof root.DecompressionStream === 'function';
}
/**
* WebCrypto is only handed to a "secure context". Opening this file straight from disk is one
* (browsers treat file:// as trustworthy), and so is https://. Plain http:// from a remote host
* is not, and there the whole crypto.subtle object is simply absent - which would otherwise
* surface as a stray TypeError halfway through a decode instead of an explanation.
*/
function requireWebCrypto() {
return !!(root.crypto && root.crypto.subtle && typeof root.crypto.subtle.importKey === 'function');
}
/**
* Raw DEFLATE (RFC 1951), no zlib wrapper - what .NET's DeflateStream writes, and what
* 'deflate-raw' reads. Plain 'deflate' expects a zlib header and would fail on every container
* we produce.
*
* The output is bounded while it is produced rather than measured afterwards, because measuring
* afterwards is the very allocation being prevented.
*/
function inflateRaw(compressed) {
var stream = new root.Blob([compressed]).stream().pipeThrough(new root.DecompressionStream('deflate-raw'));
var reader = stream.getReader();
var chunks = [];
var total = 0;
function pump() {
return reader.read().then(function (result) {
if (result.done) {
var out = new Uint8Array(total);
var offset = 0;
for (var i = 0; i < chunks.length; i++) {
out.set(chunks[i], offset);
offset += chunks[i].length;
}
return out;
}
if (total + result.value.length > MAX_INFLATED_SIZE) {
return reader.cancel().then(function () {
var error = new Error('The backup payload expands past the ' + MAX_INFLATED_SIZE + '-byte ceiling.');
error.payloadTooLarge = true;
throw error;
});
}
chunks.push(result.value);
total += result.value.length;
return pump();
});
}
return pump();
}
/**
* Reads the plaintext and refuses anything that is not a whole payload. The four fields checked
* here are the ones the wallet itself treats as mandatory; the rest are allowed to be null.
*/
function parsePayload(plaintext) {
var text = new TextDecoder('utf-8', { fatal: true }).decode(plaintext);
var payload = JSON.parse(text);
if (payload === null || typeof payload !== 'object' || !Array.isArray(payload.wallets)) {
throw new Error('Backup payload has no wallet list.');
}
var wallets = [];
for (var i = 0; i < payload.wallets.length; i++) {
var entry = payload.wallets[i];
if (entry === null || typeof entry !== 'object') {
throw new Error('Backup wallet ' + i + ' is null.');
}
if (typeof entry.keyValue !== 'string') {
throw new Error('Backup wallet ' + i + ' has no key value.');
}
if (typeof entry.classicAddress !== 'string') {
throw new Error('Backup wallet ' + i + ' has no classic address.');
}
if (typeof entry.algorithm !== 'string') {
throw new Error('Backup wallet ' + i + ' has no signing algorithm.');
}
wallets.push({
keyValue: entry.keyValue,
mnemonicPassphrase: typeof entry.mnemonicPassphrase === 'string' ? entry.mnemonicPassphrase : null,
classicAddress: entry.classicAddress,
keyType: typeof entry.keyType === 'number' ? entry.keyType : null,
keyTypeName: Object.prototype.hasOwnProperty.call(KEY_TYPE_NAMES, entry.keyType)
? KEY_TYPE_NAMES[entry.keyType]
: null,
algorithm: entry.algorithm,
derivationPath: typeof entry.derivationPath === 'string' ? entry.derivationPath : null,
masterAddress: typeof entry.masterAddress === 'string' ? entry.masterAddress : null,
description: typeof entry.description === 'string' ? entry.description : null,
folder: typeof entry.folder === 'string' ? entry.folder : null,
destinationTag: typeof entry.destinationTag === 'string' ? entry.destinationTag : null
});
}
return wallets;
}
function inflateAndParse(compressed, warnings, meta) {
return inflateRaw(compressed).then(function (plaintext) {
var wallets = parsePayload(plaintext);
return {
ok: true,
version: meta.version,
kdfId: meta.kdfId,
iterations: meta.iterations,
passwordless: meta.passwordless,
warnings: warnings,
wallets: wallets
};
}, function (error) {
if (error && error.payloadTooLarge) {
return fail(
'PAYLOAD_TOO_LARGE',
'This container is not one this page will open',
'Its payload expands past ' + MAX_INFLATED_SIZE + ' bytes, far more than any wallet list ' +
'reaches. Note what this is not: if you supplied a password, that password was accepted - ' +
'the contents are simply not a wallet backup. Do not go looking for a typo.');
}
return fail(
'MALFORMED_PAYLOAD',
'The contents are damaged',
meta.passwordless
? 'The container has our header, but what follows is not the compressed wallet list it ' +
'should be. A container without a password carries no signature of any kind, so there ' +
'is nothing here to tell a damaged file from one somebody wrote by hand.'
: 'The password was accepted - the authentication tag verified, so the bytes are exactly ' +
'the ones that were encrypted - but they are not a wallet list this page understands. ' +
'Your password is not the problem.');
});
}
function decodeWithoutPassword(bytes) {
var warnings = [{
code: 'NO_PASSWORD',
title: 'This backup carries no password',
detail: 'Its contents were never encrypted and nothing about it is signed, so anyone could ' +
'have written it - treat the addresses below as unverified until you recognise them. The ' +
'wallet only ever produces this form as an on-screen QR code shown to a second device; it ' +
'never writes one to a file.'
}];
return inflateAndParse(bytes.subarray(HEADER_PREFIX_LENGTH), warnings, {
version: bytes[MAGIC_LENGTH],
kdfId: NO_PASSWORD_KDF_ID,
iterations: 0,
passwordless: true
});
}
function decodeWithPassword(bytes, password) {
var minimumLength = PASSWORD_HEADER_LENGTH + NONCE_SIZE + TAG_SIZE;
if (bytes.length < minimumLength) {
return Promise.resolve(fail(
'TRUNCATED',
'This backup is incomplete',
'The header says it is password-protected, but the file holds only ' + bytes.length +
' bytes - too few for the salt, nonce, contents and authentication tag a container of ' +
'ours needs. It has been cut short somewhere between the wallet and here.'));
}
var iterations = readUint32BE(bytes, HEADER_PREFIX_LENGTH);
if (iterations === 0) {
return Promise.resolve(fail(
'ITERATIONS_INVALID',
'The header is damaged',
'It asks for zero rounds of key derivation, which the wallet never writes. One of the ' +
'four bytes holding that number has been changed or lost.'));
}
if (iterations > ABSOLUTE_ITERATIONS_LIMIT) {
return Promise.resolve(fail(
'ITERATIONS_INVALID',
'The header is damaged',
'It asks for ' + iterations + ' rounds of key derivation. That is far beyond anything the ' +
'wallet has ever written, and running it would leave this page unresponsive for hours, so ' +
'it is refused before the first round rather than after.'));
}
var warnings = [];
if (iterations > WALLET_ITERATIONS_CEILING) {
warnings.push({
code: 'ITERATIONS_ABOVE_CEILING',
title: 'Unusual key-derivation cost',
detail: 'This container asks for ' + iterations + ' rounds, more than the ' +
WALLET_ITERATIONS_CEILING + ' the wallet app itself accepts on import. This page ran it ' +
'anyway - it exists for the case where the app is gone - but the count is not one this ' +
'version of the wallet writes.'
});
}
if (!requireWebCrypto()) {
return Promise.resolve(fail(
'UNSUPPORTED_CONTEXT',
'This browser will not hand the page its crypto',
'Decrypting needs WebCrypto, and a browser only offers it to a page in a "secure ' +
'context". Save this file to disk and open it directly - a file:// address counts as ' +
'one - or serve it over https://. A page delivered over plain http:// from a remote ' +
'host, or embedded in another page, does not get WebCrypto at all. A backup with no ' +
'password still opens here, because that form is never encrypted.'));
}
if (password === null || password === undefined) {
return Promise.resolve(fail(
'PASSWORD_REQUIRED',
'This backup needs a password',
'Its header says the contents are encrypted. Enter the password that was set when the ' +
'backup was made.'));
}
var header = bytes.subarray(0, PASSWORD_HEADER_LENGTH);
var salt = bytes.subarray(HEADER_PREFIX_LENGTH + ITERATIONS_FIELD_LENGTH, PASSWORD_HEADER_LENGTH);
var nonce = bytes.subarray(PASSWORD_HEADER_LENGTH, PASSWORD_HEADER_LENGTH + NONCE_SIZE);
// WebCrypto wants the tag appended to the ciphertext, which is exactly how it sits on the
// wire, so this is one slice to the end of the buffer rather than two.
var sealed = bytes.subarray(PASSWORD_HEADER_LENGTH + NONCE_SIZE);
var subtle = root.crypto.subtle;
var passwordBytes = new TextEncoder().encode(password);
return subtle.importKey('raw', passwordBytes, 'PBKDF2', false, ['deriveBits'])
.then(function (baseKey) {
return subtle.deriveBits(
{ name: 'PBKDF2', salt: salt, iterations: iterations, hash: 'SHA-256' },
baseKey,
KEY_BITS);
})
.then(function (keyBits) {
return subtle.importKey('raw', keyBits, 'AES-GCM', false, ['decrypt']);
})
.then(function (key) {
return subtle.decrypt(
{ name: 'AES-GCM', iv: nonce, additionalData: header, tagLength: TAG_SIZE * 8 },
key,
sealed);
})
.then(function (compressed) {
return inflateAndParse(new Uint8Array(compressed), warnings, {
version: bytes[MAGIC_LENGTH],
kdfId: bytes[MAGIC_LENGTH + 1],
iterations: iterations,
passwordless: false
});
}, function () {
return fail(
'WRONG_PASSWORD',
'That password did not open this backup',
'This IS a StaticBit backup - the header parsed - so the file itself is the right kind ' +
'of thing. Either the password is wrong, or a byte of the file has been altered: the ' +
'whole header, salt and iteration count included, is authenticated together with the ' +
'contents, so a single changed byte anywhere fails in exactly this way. Try the ' +
'password again before you suspect the file.');
});
}