-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
1006 lines (867 loc) · 29.1 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
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
<html>
<head><title>loading...</title></head>
<body><div id="_mo" style="font-family: monospace; font-size: 18px; padding: 20px; white-space: pre;"></div>
<script>(function(global) {
'use strict';
var RootMultihash = "QmQ8xQybT8magdxC6Krjk2yezAn7GVTcYQKFZZ8VtCBVJ9";
var ErrorMultihash = "QmeSCtz2QWZQn3yhHKC5921Q5Aurv715thMjJzrpb6SEDq";
// Configure this to change the loading animation
var Spinner = "\u25CF\u2219";
var allowRawMultihash = true;
// Configure this to change Meeseeks App behavious
// - Return an ENS name (cannot be a tld); or
// - Return a multihash
function mapHostname(hostname) {
function getPrefix(suffix) {
var offset = hostname.length - suffix.length;
if (hostname.substring(offset) === suffix) {
return hostname.substring(0, offset);
}
return null;
}
// Adds the ENS suffix (.eth) or converts invalid ENS names to IPFS multihash
function addSuffix(prefix) {
// IPFS raw multihash (our flavour to prevent collisions with ENS names)
if (allowRawMultihash && prefix.substring(0, 3) === '0xg') {
return base58.encode(concat([[ 0x12, 0x20 ], base32.decode(prefix.substring(3)) ]));
}
return prefix + ".eth";
}
// *.meeseeks.app
var prefix = getPrefix(".meeseeks.app");
if (prefix) { return addSuffix(prefix); }
// *.meeseeks-local (for testing and debugging)
prefix = getPrefix(".meeseeks-local");
if (prefix) { return addSuffix(prefix); }
// Root
if (hostname === "meeseeks.app" || hostname === "meeseeks-local") {
return RootMultihash;
}
// Error
return ErrorMultihash;
}
function now() {
return (new Date()).getTime();
}
var bumps = '';
var t0 = now();
function drawBumps() {
document.getElementById('_mo').textContent = "loading secure content... (meeseeks.app bootstrap)\n" +
bumps + Spinner[parseInt(String((now() - t0) / 500)) % Spinner.length];
}
var bumpTimer = setInterval(function() {
drawBumps();
}, 250);
function bump() {
bumps += '\u25CF';
if ((bumps.length % 40) === 0) { bumps += '\n'; }
drawBumps();
}
function concat(array) {
var size = 0;
array.forEach(function(block) { size += block.length; });
var result = new Uint8Array(size);
var offset = 0;
array.forEach(function(block) {
result.set(block, offset);
offset += block.length;
});
return result
}
function fill(array, length, value, left) {
while (array.length < length) {
array[left ? "unshift": "push"](value);
}
return array;
}
/**
* var keccak256 = require('js-sha3');
*
* This implementation is heavily based on js-sha3.
* See: https://www.npmjs.com/package/js-sha3
*
* Copyright 2015-2016 Chen, Yi-Cyuan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var keccak256 = (function() {
var roundConstantInfo = "10J0NP`PO0Q0iPEP>0<0e0V0o0?PMPCPBP8PF0VPiPHPQ0dP";
function getRoundConstant(index) {
var rc = roundConstantInfo.charCodeAt(index) - 48;
var result = 0;
for (var i = 0; i < 7; i++) {
if (rc & (1 << i)) {
result += Math.pow(2, (1 << i) - 1);
}
}
return result;
}
var RC = [];
for (var i = 0; i < 48; i++) {
RC.push(getRoundConstant(i));
}
var KECCAK_PADDING = [1, 256, 1<<16, 1<<24];
var SHIFT = [0, 8, 16, 24];
function Keccak(bits, padding, outputBits) {
this.blocks = [];
this.s = [];
this.padding = padding;
this.outputBits = outputBits;
this.reset = true;
this.block = 0;
this.start = 0;
this.blockCount = (1600 - (bits << 1)) >> 5;
this.byteCount = this.blockCount << 2;
this.outputBlocks = outputBits >> 5;
this.extraBytes = (outputBits & 31) >> 3;
for (var i = 0; i < 50; ++i) {
this.s[i] = 0;
}
}
Keccak.prototype.update = function (message) {
if (message.constructor !== Uint8Array) {
throw new Error('bad message');
}
var length = message.length, blocks = this.blocks, byteCount = this.byteCount,
blockCount = this.blockCount, index = 0, s = this.s, i, code;
while (index < length) {
if (this.reset) {
this.reset = false;
blocks[0] = this.block;
for (i = 1; i < blockCount + 1; ++i) {
blocks[i] = 0;
}
}
for (i = this.start; index < length && i < byteCount; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
this.lastByteIndex = i;
if (i >= byteCount) {
this.start = i - byteCount;
this.block = blocks[blockCount];
for (i = 0; i < blockCount; ++i) {
s[i] ^= blocks[i];
}
f(s);
this.reset = true;
} else {
this.start = i;
}
}
return this;
};
Keccak.prototype.finalize = function () {
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
blocks[i >> 2] |= this.padding[i & 3];
if (this.lastByteIndex === this.byteCount) {
blocks[0] = blocks[blockCount];
for (i = 1; i < blockCount + 1; ++i) {
blocks[i] = 0;
}
}
blocks[blockCount - 1] |= 0x80000000;
for (i = 0; i < blockCount; ++i) {
s[i] ^= blocks[i];
}
f(s);
};
Keccak.prototype.digest = Keccak.prototype.array = function () {
this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
extraBytes = this.extraBytes, i = 0, j = 0;
var array = [], offset, block;
while (j < outputBlocks) {
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
offset = j << 2;
block = s[i];
array[offset] = block & 0xFF;
array[offset + 1] = (block >> 8) & 0xFF;
array[offset + 2] = (block >> 16) & 0xFF;
array[offset + 3] = (block >> 24) & 0xFF;
}
if (j % blockCount === 0) {
f(s);
}
}
if (extraBytes) {
offset = j << 2;
block = s[i];
if (extraBytes > 0) {
array[offset] = block & 0xFF;
}
if (extraBytes > 1) {
array[offset + 1] = (block >> 8) & 0xFF;
}
if (extraBytes > 2) {
array[offset + 2] = (block >> 16) & 0xFF;
}
}
return array;
};
var f = function (s) {
for (var n = 0; n < 48; n += 2) {
var c = [];
for (var i = 0; i < 10; i++) {
c[i] = 0;
for (var j = i; j < 50; j += 10) { c[i] ^= s[j]; }
}
for (var i = 0; i < 10; i++) {
var v = c[(8 + i) % 10] ^ ((c[(2 + i) % 10] << 1) | (c[(2 + ((i % 2) ? (i - 1): (i + 1))) % 10] >>> 31));
for (var j = i; j < 50; j += 10) {
s[j] ^= v;
}
}
var bs = "34c31430c35464b61560b65591594b95590bc0ec52c4ec1219c1c41dc1844944cc4d448c50355d54351d84d81380d853b5db03b1db430810df0c109f3863da3c639a6996c76d96879889d89c8998a12a4ea52a0e21b24525b2052c429c2842dc58a5d65ca59688f8d18cf891bd8b88b98bc815e10211e1424574094174497477197077597c97977897d7a82adeac2a9e";
var gb = function(i, j) {
return (parseInt(bs.substring(i * 6, i * 6 + 6), 16) >> (j * 6)) & 63;
}
var b = [ s[0], s[1] ]
for (var i = 0; i < 48; i++) {
b.push((s[gb(i, 3)] << gb(i, 2)) | (s[gb(i, 1)] >>> gb(i, 0)));
}
for (var i = 0; i < 50; i++) {
var j = i - (i % 10);
s[i] = b[i] ^ (~b[j + ((i + 2) % 10)] & b[j + ((i + 4) % 10)]);
}
s[0] ^= RC[n];
s[1] ^= RC[n + 1];
}
};
return function (message) {
return new Keccak(256, KECCAK_PADDING, 256).update(message).digest();
};
})();
/***** END OF require('js-sha3'); */
/**
* var sha256 = require('hash.js').sha256;
*
* This implementation is heavily based on hash.js.
*
* This software is licensed under the MIT License.
*
* Copyright Fedor Indutny, 2014.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sha256 = (function() {
function isPrime(value) {
if (value === 2) { return false; }
for (var i = 3; i < value; i += 2) {
if ((value % i) === 0) { return false; }
}
return true;
}
function getPrime(index) {
if (index <= 1) { return 2 + index; }
index -= 2;
for (var i = 6; i <= 312; i += 6) {
if (isPrime(i - 1)) {
if (index === 0) { return i - 1; }
index--;
}
if (isPrime(i + 1)) {
if (index === 0) { return i + 1; }
index--;
}
}
return 0;
}
function getConstant(primeIndex, cubeRoot) {
var v = Math.pow(getPrime(primeIndex), cubeRoot ? (1.0 / 3.0): 0.5);
v -= parseInt(String(v));
v *= 0x100000000;
return v >>> 0;
}
function join32(msg, start, end) {
var len = end - start;
var res = new Array(len / 4);
for (var i = 0, k = start; i < res.length; i++, k += 4) {
var w =(msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
res[i] = w >>> 0;
}
return res;
}
function split32(msg) {
var res = new Array(msg.length * 4);
for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
var m = msg[i];
res[k] = m >>> 24;
res[k + 1] = (m >>> 16) & 0xff;
res[k + 2] = (m >>> 8) & 0xff;
res[k + 3] = m & 0xff;
}
return res;
}
function rotr32(w, b) {
return (w >>> b) | (w << (32 - b));
}
function sum32() {
var o = 0;
for (var i = 0; i < arguments.length; i++) { o += arguments[i]; }
return o >>> 0;
}
function s0_256(x) {
return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
}
function s1_256(x) {
return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
}
function g0_256(x) {
return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
}
function g1_256(x) {
return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
}
var K = [];
for (var i = 0; i < 64; i++) {
K.push(getConstant(i, true));
}
function SHA256() {
this.pending = null;
this.pendingTotal = 0;
this.blockSize = 512;
this.padLength = 64 / 8;
this._delta8 = this.blockSize / 8;
this._delta32 = this.blockSize / 32;
this.h = [ ];
for (var i = 0; i < 8; i++) { this.h.push(getConstant(i, false)); }
this.k = K
this.W = new Array(64);
}
SHA256.prototype.update = function update(msg, enc) {
if (!this.pending)
this.pending = msg;
else
this.pending = concat([ this.pending, msg ]);
this.pendingTotal += msg.length;
// Enough data, try updating
if (this.pending.length >= this._delta8) {
msg = this.pending;
// Process pending data in blocks
var r = msg.length % this._delta8;
this.pending = msg.slice(msg.length - r, msg.length);
if (this.pending.length === 0)
this.pending = null;
msg = join32(msg, 0, msg.length - r);
for (var i = 0; i < msg.length; i += this._delta32)
this._update(msg, i, i + this._delta32);
}
return this;
};
SHA256.prototype.digest = function digest() {
this.update(this._pad());
return split32(this.h);
};
SHA256.prototype._pad = function pad() {
var len = this.pendingTotal;
var bytes = this._delta8;
var k = bytes - ((len + this.padLength) % bytes);
var res = new Array(k + this.padLength);
res[0] = 0x80;
for (var i = 1; i < k; i++) { res[i] = 0; }
// Append length
len <<= 3;
for (var t = 8; t < this.padLength; t++)
res[i++] = 0;
res[i++] = 0;
res[i++] = 0;
res[i++] = 0;
res[i++] = 0;
res[i++] = (len >>> 24) & 0xff;
res[i++] = (len >>> 16) & 0xff;
res[i++] = (len >>> 8) & 0xff;
res[i++] = len & 0xff;
return res;
};
SHA256.prototype._update = function _update(msg, start) {
var W = this.W;
for (var i = 0; i < 16; i++) { W[i] = msg[start + i]; }
for (; i < W.length; i++) {
W[i] = sum32(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
}
var a = this.h[0];
var b = this.h[1];
var c = this.h[2];
var d = this.h[3];
var e = this.h[4];
var f = this.h[5];
var g = this.h[6];
var h = this.h[7];
for (i = 0; i < W.length; i++) {
var T1 = sum32(h, s1_256(e), (e & f) ^ ((~e) & g), this.k[i], W[i]);
var T2 = sum32(s0_256(a), (a & b) ^ (a & c) ^ (b & c));
h = g;
g = f;
f = e;
e = sum32(d, T1);
d = c;
c = b;
b = a;
a = sum32(T1, T2);
}
this.h[0] = sum32(this.h[0], a);
this.h[1] = sum32(this.h[1], b);
this.h[2] = sum32(this.h[2], c);
this.h[3] = sum32(this.h[3], d);
this.h[4] = sum32(this.h[4], e);
this.h[5] = sum32(this.h[5], f);
this.h[6] = sum32(this.h[6], g);
this.h[7] = sum32(this.h[7], h);
};
return function(message) {
return (new SHA256()).update(message).digest('hex');
}
})();
/***** END OF require('hash.js'); */
/**
* var basex = require('base-x');
*
* This implementation is heavily based on base-x.
*
* Contributors:
*
* base-x encoding
* Forked from https://github.com/cryptocoinjs/bs58
* Originally written by Mike Hearn for BitcoinJ
* Copyright (c) 2011 Google Inc
* Ported to JavaScript by Stefan Thomas
* Merged Buffer refactorings from base58-native by Stephen Pair
* Copyright (c) 2013 BitPay Inc
*
* The MIT License (MIT)
*
* Copyright base-x contributors (c) 2016
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
var basex = function(ALPHABET) {
var ALPHABET_MAP = {}
var BASE = ALPHABET.length
var LEADER = ALPHABET.charAt(0)
// pre-compute lookup table
for (var i = 0; i < ALPHABET.length; i++) {
ALPHABET_MAP[ALPHABET.charAt(i)] = i;
}
function encode(source) {
if (source.length === 0) return ''
var digits = [0]
for (var i = 0; i < source.length; ++i) {
for (var j = 0, carry = source[i]; j < digits.length; ++j) {
carry += digits[j] << 8
digits[j] = carry % BASE
carry = (carry / BASE) | 0
}
while (carry > 0) {
digits.push(carry % BASE)
carry = (carry / BASE) | 0
}
}
var string = ''
// deal with leading zeros
for (var k = 0; source[k] === 0 && k < source.length - 1; ++k) string += LEADER
// convert digits to a string
for (var q = digits.length - 1; q >= 0; --q) string += ALPHABET[digits[q]]
return string
}
function decodeUnsafe (string) {
if (typeof string !== 'string') throw new TypeError('Expected String')
var bytes = [];
if (string.length === 0) { return new Uint8Array(bytes); }
bytes.push(0);
for (var i = 0; i < string.length; i++) {
var value = ALPHABET_MAP[string[i]]
if (value === undefined) return
for (var j = 0, carry = value; j < bytes.length; ++j) {
carry += bytes[j] * BASE
bytes[j] = carry & 0xff
carry >>= 8
}
while (carry > 0) {
bytes.push(carry & 0xff)
carry >>= 8
}
}
// deal with leading zeros
for (var k = 0; string[k] === LEADER && k < string.length - 1; ++k) {
bytes.push(0)
}
return new Uint8Array(bytes.reverse())
}
function decode (string) {
var buffer = decodeUnsafe(string)
if (buffer) return buffer
throw new Error('Non-base' + BASE + ' character')
}
return {
encode: encode,
decode: decode
}
}
var base32 = basex("abcdefghijklmnopqrstuvwxyz234567");
var base58 = basex("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
/***** END OF require('base-x'); */
/**
* This implementation is heavily based on utf.js.
*
* See: http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt
*
* Note: We do not care about overlong or otherwise invalid sequences; that's
* the browsers problem and we don't want to make any assumptions.
*
* utf.js
*
* UTF-8 <=> UTF-16 convertion
*
* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
function toUtf8String(array) {
var out, i, len, c;
var char2, char3;
out = "";
len = array.length;
i = 0;
while (i < len) {
c = array[i++];
switch (c >> 4)
{
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
// 0xxxxxxx
out += String.fromCharCode(c);
break;
case 12: case 13:
// 110x xxxx 10xx xxxx
char2 = array[i++];
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
}
}
return out;
}
/***** END OF utf.js */
/**
* Meeseeks Bootstrap
*
* Copyright 2018 Richard Moore <me@ricmoo.com>
* Yuet Loo Wong <yuet.wong@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var TYPE_PBNODE = 1;
var TYPE_LINK = 2;
var TYPE_UNIXFS = 3;
function parseProtoBuf(data, type) {
var result = {};
var offset = 0;
var names = null;
var repeated = {};
switch(type) {
case TYPE_PBNODE: names = [ 'data', 'links' ]; repeated = { links: true }; break;
case TYPE_LINK: names = [ 'hash', 'n', 'ts' ]; break;
case TYPE_UNIXFS: names = [ 'type', 'data', 'fs', 'bs', 'ht', 'fo' ]; break;
default: throw new Error('bad type');
}
var readVarInt = function() {
var v = [ data[offset] & 0x7f ];
while (data[offset++] & 0x80) {
if (offset === data.length) { throw new Error('buffer overrun'); }
v.unshift(data[offset] & 0x7f);
}
var result = 0;
v.forEach(function(v) { result = result * 128 + v; });
return result;
}
while (offset < data.length) {
var v = readVarInt();
var tag = names[(v >>> 3) - 1];
if (!tag) { throw new Error('unknown field - ' + v); }
switch (v & 7) {
// varint
case 0:
result[tag] = readVarInt();
break;
// bytes
case 2: {
var length = readVarInt();
if (offset + length > data.length) { throw new Error("buffer overrun"); }
if (repeated[tag]) {
if (result[tag]) {
result[tag].push(data.slice(offset, offset + length));
} else {
result[tag] = [ data.slice(offset, offset + length) ];
}
} else {
result[tag] = data.slice(offset, offset + length);
}
offset += length;
break;
}
default:
console.log('unsupported type - ' + tag);
throw new Error('unsupported type - ' + tag);
}
}
return result;
}
function parseData(data, type) {
var result = parseProtoBuf(data, type);
switch (type) {
case TYPE_PBNODE: {
if (result.links) {
var promises = [];
result.links.forEach(function(hash) {
promises.push(parseData(hash, TYPE_LINK));
});
return Promise.all(promises).then(function(blocks) {
return concat(blocks);
});
}
if (result.data && result.data.constructor === Uint8Array) {
return Promise.resolve(parseData(result.data, TYPE_UNIXFS));
}
}
case TYPE_LINK:
if (result.hash.length !== 34) { throw new Error('unsupported hash', result.hash); }
return fetchIpfs(base58.encode(result.hash));
case TYPE_UNIXFS:
if (result.type !== 2) { throw new Error('unsupported type'); }
if (!result.data) { return new Uint8Array([]); }
if (result.data.constructor !== Uint8Array) { throw new Error('bad Data'); }
return Promise.resolve(result.data);
}
throw new Error('unsupported type');
}
function fetchIpfs(multihash) {
var url = "https://ipfs.infura.io:5001/api/v0/block/get?arg=" + multihash;
//var url = "https://ipfs.io/api/v0/block/get?arg=" + multihash;
console.log("Fetching: " + url);
return fetch(url).then(function(block) {
bump();
return block.arrayBuffer().then(function(data) {
data = new Uint8Array(data);
var hash = hexlify(sha256(data));
if (hash !== hexlify(base58.decode(multihash).slice(2))) {
throw new Error('hash mismatch');
}
console.log("Verified: " + multihash + " => 0x" + hash);
return parseData(data, TYPE_PBNODE);
});
});
}
var readyPromise = new Promise(function(resolve) {
window.addEventListener('DOMContentLoaded', resolve, false);
});
function loadHtml(htmlCode) {
return readyPromise.then(function() {
document.open("text/html", "replace");
document.write(htmlCode);
document.close();
if (window.app) { setTimeout(function() { window.app.emit('ready'); }, 0); }
});
};
var Zeros = new Uint8Array(fill([], 32, 0));;
var Partition = new RegExp("^((.*)\\.)?([^.]+)$");
var UseSTD3ASCIIRules = new RegExp("^[a-z0-9.-]*$");
function arrayify(value) {
var result = [];
for (var i = 0; i < value.length; i += 2) {
result.push(parseInt(value.substr(i, 2), 16));
}
return result;
}
var HexCharacters = '0123456789abcdef';
function hexlify(value) {
var result = [];
for (var i = 0; i < value.length; i++) {
var v = value[i];
result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f];
}
return result;
}
function toBytes(string) {
var result = [];
for (var i = 0; i < string.length; i++) {
result.push(string.charCodeAt(i));
}
return new Uint8Array(result);
}
function namehash(name) {
name = name.toLowerCase();
// Supporting the full UTF-8 space requires additional (and large)
// libraries, so for now we simply do not support them.
// It should be fairly easy in the future to support systems with
// String.normalize, but that is future work.
if (!name.match(UseSTD3ASCIIRules) || name.substring(0, 2) === '0x') {
throw new Error('contains invalid UseSTD3ASCIIRules characters');
}
var result = Zeros;
while (name.length) {
var partition = name.match(Partition);
var label = toBytes(partition[3]);
result = keccak256(concat([result, keccak256(label)]));
name = partition[2] || '';
}
return result;
}
function callEtherscan(address, data) {
var url = "https://api.etherscan.io/api?module=proxy&action=eth_call&to=" + address + "&data=" + data + "&tag=latest&apikey=9D13ZE7XSBTJ94N9BNJ2MA33VMAY2YPIRB";
return fetch(url).then(function(body) {
return body.text().then(function(body) {
var result = JSON.parse(body);
return result.result;
});
});
}
function getMeeseeks(name) {
var hash = hexlify(namehash(name));
// ENS.resolver(hash)
return Promise.all([
callEtherscan("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", "0x0178b8bf" + hash)
]).then(function(results) {
bump();
// @TODO: Check all results match
var result = results[0];
if (result.match(/^0x0{64}$/) || !result.match(/^0x0{24}/)) {
throw new Error('no ENS entry found');
}
// Get the resolver address from the response
var resolver = '0x' + result.substring(26);
// getContenthash(bytes32)
// See: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1577.md
var data = '0xbc1c58d1' + hash;
return Promise.all([
callEtherscan(resolver, data),
// content(bytes32 nodehash) - How do I fetch bzz content?
//callEtherscan(resolver, "0x2dff6941" + hash),
// multihash(bytes32 nodehash) - EIP 1062
//callEtherscan(resolver, "0xe89401a1" + hash),
]).then(function(results) {
bump();
var match = results[0].match(/^0x0{62}200{62}([0-9a-f]{2})([0-9a-f]*)$/i);
if (!match || (parseInt(match[1], 16) * 2) > match[2].length) { return null; }
var result = arrayify(match[2].substring(0, 2 * parseInt(match[1], 16)));
if (result[0] === 0x01 && result.length === 35) {
// Legacy - from a typo in the early EIP-1577
// e.g. 0x011220e08ea2458249e8f26aee72b95b39c33849a992a3eff40bd06d26c12197adef16
return base58.encode(result.slice(1));
} else if (hexlify(result.slice(0, 4)) === "e3010170" && result.length === 38) {
// e.g. 0xe3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f
return base58.encode(result.slice(4));
}
throw new error('unsupported origin');
});
});
}
bump();
console.log("Look at me! I'm Meeseeks.app!");
(function() {
var hostname = location.host.split(':')[0];
console.log("Hostname: " + hostname);
var name = mapHostname(hostname);
if (name.indexOf(".") === -1) {
console.log("Found IPFS multihash: " + name);
return Promise.resolve(name);
} else {
console.log("Found ENS name: " + name);
return getMeeseeks(name).then(function(multihash) {
console.log('Found ENS.contenthash: ' + multihash);
return multihash;
});
}
})().then(function(multihash) {
return fetchIpfs(multihash, TYPE_PBNODE).then(function(data) {
console.log("Existance is pain! Good-Bye!");
setTimeout(function() {
clearInterval(bumpTimer);
loadHtml(toUtf8String(data));
}, 0);
});
}).catch(function(error) {
console.log("Error: " + error.message);
return fetchIpfs(ErrorMultihash, TYPE_PBNODE).then(function(data) {
setTimeout(function() {
clearInterval(bumpTimer);
loadHtml(toUtf8String(data));
}, 0);