-
Notifications
You must be signed in to change notification settings - Fork 12
/
memwallet_0.1_SHA256_0852b3d886ac5df6e4b34f2224019b96620aa6619b61660801d88f7c38d07dbb.html
18075 lines (15298 loc) · 496 KB
/
memwallet_0.1_SHA256_0852b3d886ac5df6e4b34f2224019b96620aa6619b61660801d88f7c38d07dbb.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>MemWallet - deterministic bitcoin wallet generator for Ethereum, Monero, Litecoin and Bitcoin</title>
<style>
body {
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
font-size: 17px;
}
p {
line-height: 24px;
}
.content {
max-width: 800px;
width: 800px;
margin: 0 auto;
}
.form {
border: 1px solid #ccc;
padding: 20px;
border-radius: 4px;
background-color: #fff;
}
.alert {
background-color: #f2dede;
border-radius: 4px;
border: solid 0.75px #ebcccc;
color: #a94442;
padding: 12px 20px;
}
.info {
background-color: #d9edf7;
color: #31708f;
border-radius: 4px;
border: solid 0.75px #bcdff1;
padding: 12px 20px;
}
h2 {
text-align: center;
font-size:
}
h1 {
font-size: 40px;
letter-spacing: 2px;
margin: 20px 0;
}
.header {
margin: 0 0 50px 0;
text-align: center;
background-color: #222;
color: #fff;
padding: 20px;
}
.header h2 {
margin: 0 0 10px 0;
font-size: 20px;
}
.header h3 {
margin-top: 0;
font-size: 18px;
}
.form-label {
width: 300px;
float: left;
text-align: right;
padding-right: 10px;
}
.form-field {
width: 400px;
float: left;
}
.form-group {
padding-bottom: 15px;
overflow: hidden;
}
.form {
overflow: hidden;
}
input[type="text"], input[type="password"] {
color:#464a4c;
border-radius:4px;
width: 300px;
border: .75px solid #0003;
margin:0;
padding:8px 12px
}
input:focus {
border-color: #5cb3fd;
}
.currency-selector {
text-align: center;
margin-bottom: 20px;
}
a {
text-decoration: none;
color: #0275d8;
}
a:hover {
background-color: #ccc;
}
.progress {
display: flex;
overflow: hidden;
font-size: .75rem;
line-height: 1rem;
text-align: center;
background-color: #eceeef;
border-radius: 4px;
}
.progress-bar {
height: 1rem;
background-color: #0275d8;
background-image: -webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);
background-image: -o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);
background-image: linear-gradient(45deg,#fff3 25%,transparent 25%,transparent 50%,#fff3 50%,#fff3 75%,transparent 75%,transparent);
-webkit-background-size: 1rem 1rem;
background-size: 1rem 1rem;
}
.btn {
color: #fff;
background-color: #0275d8;
border-color: #0275d8;
display: block;
font-weight: 400;
line-height: 1.25;
text-align: center;
vertical-align: middle;
border: 1px solid transparent;
padding: .5rem 1rem;
font-size: 1rem;
border-radius: 4px;
margin: 10px auto;
cursor: pointer;
}
.btn:disabled {
background-color: #0275d8;
border-color: #0275d8;
cursor: not-allowed;
opacity: .65;
}
.brand {
font-size: 1.1em;
}
</style>
</head>
<body>
<div class="header">
<h1>MemWallet</h1>
<h2>Like WrapWallet but for Altcoins</h2>
<h3>No external assets, to use offline just save this page</h3>
</div>
<div class="content">
<form class="form" autocomplete="off" onsubmit="return false;">
<div class="form-group currency-selector">
<label> <input name="coin" onclick="resetState()" checked value="bitcoin" type="radio"/> Bitcoin </label>
<label> <input name="coin" onclick="resetState()" value="ethereum" type="radio"/> Ethereum </label>
<label> <input name="coin" onclick="resetState()" value="litecoin" type="radio"/> Litecoin </label>
<label> <input name="coin" onclick="resetState()" value="monero" type="radio"/> Monero </label>
</div>
<div class="form-group">
<div class="form-label">Passphrase </div>
<div class="form-field">
<input type="password" id="passphrase" oninput="updateButton()" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
</div>
</div>
<div class="form-group">
<div class="form-label">Salt: (optional) <a href="#" onclick="toggle('info')">[?]</a></div>
<div class="form-field">
<input type="text" id="salt" oninput="resetState();" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
</div>
</div>
<div class="info" id="info" style="display: none">
<span class="brand">MemWallet</span> can use a salt to make your wallet stronger. Use, for example, your e-mail or phone number.
If you're unsure, please do it. <a href="#" onclick="toggle('info')">[Close]</a>
</div>
<div id="progress" style="display: none">
<center>Running scrypt...</center>
<div class="progress">
<div id="progress-bar" class="progress-bar" style="width: 50%"> </div>
</div>
</div>
<button id="btn" class="btn" disabled="" onclick="generate()">Generate</button>
<h2 style="display: none" id="wallet-title"></h2>
<div class="form-group" id="cnt-public" style="display: none">
<div class="form-label" id="label-public" ></div>
<div class="form-field"><input type="text" id="result-public" /></div>
</div>
<div class="form-group" id="cnt-private" style="display: none">
<div class="form-label" id="label-private"></div>
<div class="form-field"><input type="text" id="result-private" /></div>
</div>
<div class="form-group" id="cnt-public-view" style="display: none">
<div class="form-label" id="label-public-view" ></div>
<div class="form-field"><input type="text" id="result-public-view" /></div>
</div>
<div class="form-group" id="cnt-private-view" style="display: none">
<div class="form-label" id="label-private-view" ></div>
<div class="form-field"><input type="text" id="result-private-view" /></div>
</div>
<div class="form-group" id="cnt-public-spend" style="display: none">
<div class="form-label" id="label-public-spend" ></div>
<div class="form-field"><input type="text" id="result-public-spend" /></div>
</div>
<div class="form-group" id="cnt-private-spend" style="display: none">
<div class="form-label" id="label-private-spend" ></div>
<div class="form-field"><input type="text" id="result-private-spend" /></div>
</div>
</form>
<p id="online-alert" class="alert"><strong>You are online.</strong> For maximum security is better that you save this page and generate the address in a computer disconnected from the internet.</p>
<p id="js-alert" class="alert">Javascript is disabled. <span class="brand">MemWallet</span> needs javascript to work </p>
<script> document.getElementById('js-alert').style.display = 'none'; </script>
<p>
<span class="brand">MemWallet</span> is a deterministic cryptocurrency address generator, like <a href="https://keybase.io/warp/">WrapWallet</a>, but it works for Ethereum, Litecoin, Monero and Bitcoin.
You never have to save or store your private key anywhere. Just pick a really good password - many random words, for example - and never use it for anything else.
</p>
<p>Given the same Passphrase and Salt, <span class="brand">MemWallet</span> will always generate the same address and private key, so if you only need to remember your password to access your funds.</p>
<p>
For more information on why this is safer than a regular brainwallet, see <a href="https://keybase.io/warp/">WrapWallet</a>'s help,
<span class="brand">MemWallet</span> is a re-implementation of WarpWallet, but it works for other currencies.
WarpWallet and <span class="brand">MemWallet</span> use the same algorithm, so WarpWallet and <span class="brand">MemWallet</span> will generate
the same Bitcoin address for a given Passphrase and salt.
</p>
The algorithm behind <span class="brand">MemWallet</span>:
<table class="table table-condensed" style="font-size: 0.7em; font-family: mono;">
<tr><td valign="top" align="right">b</td><td align="center" valign="top" width="20">=</td><td valign="top" align="left">1 for Bitcoin, 2 for Litecoin, 3 for Ethereum and 4 for Monero</td></tr>
<tr><td valign="top" align="right">seed<sub>1</sub></td><td align="center" valign="top" width="20">=</td><td valign="top" align="left">scrypt(key=(passphrase||b), salt=(salt||b), N=2<sup>18</sup>, r=8, p=1, dkLen=32)</td></tr>
<tr><td valign="top" align="right">seed<sub>2</sub></td><td align="center" valign="top">=</td><td valign="top" align="left">pbkdf2(key=(passphrase||(b+1)), salt=(salt||(b+1)), c=2<sup>16</sup>, dkLen=32, prf=SHA256)</td></tr>
<tr><td valign="top" align="right">wallet</td><td align="center" valign="top">=</td><td valign="top" align="left">generate_wallet(seed=(seed<sub>1</sub> ⊕ seed<sub>2</sub>))</td></tr>
</table>
<p> </p>
<hr/>
<p> </p>
<center>
<p><span class="brand">MemWallet</span> Was made with ♥ By <a href="https://github.com/dvdbng">David Bengoa</a></p>
<p>Source code is in <a href="https://github.com/dvdbng/memwallet">Github</a>, and so is a go implementation of the same algorithm.</p>
</center>
<p> </p>
<!--
Javascript is left un-minimized so it's easy to audit it offline
-->
<script>
function setKeyResult(name, show, label, value){
i('cnt-' + name).style.display = show ? 'block' : 'none';
i('label-' + name).textContent = show ? label : '';
i('result-' + name).value = show ? value : '';
}
function titleCase(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function generate() {
var passphrase = document.getElementById('passphrase').value;
var salt = document.getElementById('salt').value;
var currency = document.querySelector('[name=coin]:checked').value;
var progress_blk = i('progress');
var progress_bar = i('progress-bar');
for(var el of document.querySelectorAll('.form input')) el.disabled = true;
i('btn').style.display = 'none';
mw.generateWallet(passphrase, salt, currency, function(progress, result) {
progress_blk.style.display = !result ? 'block' : 'none';
progress_bar.style.width = progress*100 + '%';
if(result){
for(var el of document.querySelectorAll('.form input')) el.disabled = false;
i('wallet-title').style.display = 'block';
i('wallet-title').textContent = 'Your ' + titleCase(currency) + ' wallet',
setKeyResult('public', true, 'Public ' + titleCase(currency) + ' address', result.public);
setKeyResult('private', currency != 'monero', 'Private key', result.private);
setKeyResult('private-spend', currency == 'monero', 'Private Spend key', result.private_spend);
setKeyResult('public-spend', currency == 'monero', 'Public Spend key', result.public_spend);
setKeyResult('public-view', currency == 'monero', 'Public View key', result.public_view);
setKeyResult('private-view', currency == 'monero', 'Private View key', result.private_view);
}
});
}
function i(id){
return document.getElementById(id);
}
function updateButton(){
var passphrase = i('passphrase').value;
var button = i('btn');
resetState();
if(passphrase.length == 0) {
button.disabled = true;
button.textContent = 'Generate';
} else if (passphrase.length < 12) {
button.disabled = false;
button.textContent = 'Consider a larger passpharase';
} else {
button.disabled = false;
button.textContent = 'Generate';
}
}
function resetState(){
setKeyResult('public', false);
setKeyResult('private', false);
setKeyResult('private-spend', false);
setKeyResult('public-spend', false);
setKeyResult('public-view', false);
setKeyResult('private-view', false);
i('btn').style.display = 'block';
i('wallet-title').style.display = 'none';
}
function toggle(id) {
var el = i(id);
el.style.display = el.style.display == 'block' ? 'none' : 'block';
}
function updateOnline() {
document.getElementById('online-alert').style.display = navigator.onLine ? 'block' : 'none';
}
function init() {
window.addEventListener('online', updateOnline);
window.addEventListener('offline', updateOnline);
updateOnline();
if(location.hash.length > 3) {
var check = document.querySelector('input[name="coin"][value="' + location.hash.replace(/\W/g, '') + '"]');
if(check) check.checked = true;
}
}
init();
var mw =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 38);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
if (typeof Object.create === 'function') {
// implementation from standard node.js 'util' module
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
};
} else {
// old school shim for old browsers
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor
var TempCtor = function () {}
TempCtor.prototype = superCtor.prototype
ctor.prototype = new TempCtor()
ctor.prototype.constructor = ctor
}
}
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
/* eslint-disable node/no-deprecated-api */
var buffer = __webpack_require__(5)
var Buffer = buffer.Buffer
// alternative to using Object.keys for old browsers
function copyProps (src, dst) {
for (var key in src) {
dst[key] = src[key]
}
}
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
module.exports = buffer
} else {
// Copy properties from require('buffer')
copyProps(buffer, exports)
exports.Buffer = SafeBuffer
}
function SafeBuffer (arg, encodingOrOffset, length) {
return Buffer(arg, encodingOrOffset, length)
}
// Copy static methods from Buffer
copyProps(Buffer, SafeBuffer)
SafeBuffer.from = function (arg, encodingOrOffset, length) {
if (typeof arg === 'number') {
throw new TypeError('Argument must not be a number')
}
return Buffer(arg, encodingOrOffset, length)
}
SafeBuffer.alloc = function (size, fill, encoding) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
var buf = Buffer(size)
if (fill !== undefined) {
if (typeof encoding === 'string') {
buf.fill(fill, encoding)
} else {
buf.fill(fill)
}
} else {
buf.fill(0)
}
return buf
}
SafeBuffer.allocUnsafe = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return Buffer(size)
}
SafeBuffer.allocUnsafeSlow = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return buffer.SlowBuffer(size)
}
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var elliptic = exports;
elliptic.version = __webpack_require__(41).version;
elliptic.utils = __webpack_require__(42);
elliptic.rand = __webpack_require__(45);
elliptic.curve = __webpack_require__(13);
elliptic.curves = __webpack_require__(51);
// Protocols
elliptic.ec = __webpack_require__(59);
elliptic.eddsa = __webpack_require__(63);
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {(function (module, exports) {
'use strict';
// Utils
function assert (val, msg) {
if (!val) throw new Error(msg || 'Assertion failed');
}
// Could use `inherits` module, but don't want to move from single file
// architecture yet.
function inherits (ctor, superCtor) {
ctor.super_ = superCtor;
var TempCtor = function () {};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
}
// BN
function BN (number, base, endian) {
if (BN.isBN(number)) {
return number;
}
this.negative = 0;
this.words = null;
this.length = 0;
// Reduction context
this.red = null;
if (number !== null) {
if (base === 'le' || base === 'be') {
endian = base;
base = 10;
}
this._init(number || 0, base || 10, endian || 'be');
}
}
if (typeof module === 'object') {
module.exports = BN;
} else {
exports.BN = BN;
}
BN.BN = BN;
BN.wordSize = 26;
var Buffer;
try {
Buffer = __webpack_require__(44).Buffer;
} catch (e) {
}
BN.isBN = function isBN (num) {
if (num instanceof BN) {
return true;
}
return num !== null && typeof num === 'object' &&
num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
};
BN.max = function max (left, right) {
if (left.cmp(right) > 0) return left;
return right;
};
BN.min = function min (left, right) {
if (left.cmp(right) < 0) return left;
return right;
};
BN.prototype._init = function init (number, base, endian) {
if (typeof number === 'number') {
return this._initNumber(number, base, endian);
}
if (typeof number === 'object') {
return this._initArray(number, base, endian);
}
if (base === 'hex') {
base = 16;
}
assert(base === (base | 0) && base >= 2 && base <= 36);
number = number.toString().replace(/\s+/g, '');
var start = 0;
if (number[0] === '-') {
start++;
}
if (base === 16) {
this._parseHex(number, start);
} else {
this._parseBase(number, base, start);
}
if (number[0] === '-') {
this.negative = 1;
}
this.strip();
if (endian !== 'le') return;
this._initArray(this.toArray(), base, endian);
};
BN.prototype._initNumber = function _initNumber (number, base, endian) {
if (number < 0) {
this.negative = 1;
number = -number;
}
if (number < 0x4000000) {
this.words = [ number & 0x3ffffff ];
this.length = 1;
} else if (number < 0x10000000000000) {
this.words = [
number & 0x3ffffff,
(number / 0x4000000) & 0x3ffffff
];
this.length = 2;
} else {
assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
this.words = [
number & 0x3ffffff,
(number / 0x4000000) & 0x3ffffff,
1
];
this.length = 3;
}
if (endian !== 'le') return;
// Reverse the bytes
this._initArray(this.toArray(), base, endian);
};
BN.prototype._initArray = function _initArray (number, base, endian) {
// Perhaps a Uint8Array
assert(typeof number.length === 'number');
if (number.length <= 0) {
this.words = [ 0 ];
this.length = 1;
return this;
}
this.length = Math.ceil(number.length / 3);
this.words = new Array(this.length);
for (var i = 0; i < this.length; i++) {
this.words[i] = 0;
}
var j, w;
var off = 0;
if (endian === 'be') {
for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
this.words[j] |= (w << off) & 0x3ffffff;
this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
off += 24;
if (off >= 26) {
off -= 26;
j++;
}
}
} else if (endian === 'le') {
for (i = 0, j = 0; i < number.length; i += 3) {
w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
this.words[j] |= (w << off) & 0x3ffffff;
this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
off += 24;
if (off >= 26) {
off -= 26;
j++;
}
}
}
return this.strip();
};
function parseHex (str, start, end) {
var r = 0;
var len = Math.min(str.length, end);
for (var i = start; i < len; i++) {
var c = str.charCodeAt(i) - 48;
r <<= 4;
// 'a' - 'f'
if (c >= 49 && c <= 54) {
r |= c - 49 + 0xa;
// 'A' - 'F'
} else if (c >= 17 && c <= 22) {
r |= c - 17 + 0xa;
// '0' - '9'
} else {
r |= c & 0xf;
}
}
return r;
}
BN.prototype._parseHex = function _parseHex (number, start) {
// Create possibly bigger array to ensure that it fits the number
this.length = Math.ceil((number.length - start) / 6);
this.words = new Array(this.length);
for (var i = 0; i < this.length; i++) {
this.words[i] = 0;
}
var j, w;
// Scan 24-bit chunks and add them to the number
var off = 0;
for (i = number.length - 6, j = 0; i >= start; i -= 6) {
w = parseHex(number, i, i + 6);
this.words[j] |= (w << off) & 0x3ffffff;
// NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
off += 24;
if (off >= 26) {
off -= 26;
j++;
}
}
if (i + 6 !== start) {
w = parseHex(number, start, i + 6);
this.words[j] |= (w << off) & 0x3ffffff;
this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
}
this.strip();
};
function parseBase (str, start, end, mul) {
var r = 0;
var len = Math.min(str.length, end);
for (var i = start; i < len; i++) {
var c = str.charCodeAt(i) - 48;
r *= mul;
// 'a'
if (c >= 49) {
r += c - 49 + 0xa;
// 'A'
} else if (c >= 17) {
r += c - 17 + 0xa;
// '0' - '9'
} else {
r += c;
}
}
return r;
}
BN.prototype._parseBase = function _parseBase (number, base, start) {
// Initialize as zero
this.words = [ 0 ];
this.length = 1;
// Find length of limb in base
for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
limbLen++;
}
limbLen--;
limbPow = (limbPow / base) | 0;
var total = number.length - start;
var mod = total % limbLen;
var end = Math.min(total, total - mod) + start;
var word = 0;
for (var i = start; i < end; i += limbLen) {
word = parseBase(number, i, i + limbLen, base);
this.imuln(limbPow);
if (this.words[0] + word < 0x4000000) {
this.words[0] += word;
} else {
this._iaddn(word);
}
}
if (mod !== 0) {
var pow = 1;
word = parseBase(number, i, number.length, base);
for (i = 0; i < mod; i++) {
pow *= base;
}
this.imuln(pow);
if (this.words[0] + word < 0x4000000) {
this.words[0] += word;
} else {
this._iaddn(word);
}
}
};
BN.prototype.copy = function copy (dest) {
dest.words = new Array(this.length);
for (var i = 0; i < this.length; i++) {
dest.words[i] = this.words[i];
}
dest.length = this.length;
dest.negative = this.negative;
dest.red = this.red;
};
BN.prototype.clone = function clone () {
var r = new BN(null);
this.copy(r);
return r;
};
BN.prototype._expand = function _expand (size) {
while (this.length < size) {
this.words[this.length++] = 0;
}
return this;
};
// Remove leading `0` from `this`
BN.prototype.strip = function strip () {
while (this.length > 1 && this.words[this.length - 1] === 0) {
this.length--;
}
return this._normSign();
};
BN.prototype._normSign = function _normSign () {
// -0 = 0
if (this.length === 1 && this.words[0] === 0) {
this.negative = 0;
}
return this;
};
BN.prototype.inspect = function inspect () {
return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
};
/*
var zeros = [];
var groupSizes = [];
var groupBases = [];
var s = '';
var i = -1;
while (++i < BN.wordSize) {
zeros[i] = s;
s += '0';
}
groupSizes[0] = 0;
groupSizes[1] = 0;
groupBases[0] = 0;
groupBases[1] = 0;
var base = 2 - 1;
while (++base < 36 + 1) {
var groupSize = 0;
var groupBase = 1;
while (groupBase < (1 << BN.wordSize) / base) {
groupBase *= base;
groupSize += 1;
}
groupSizes[base] = groupSize;
groupBases[base] = groupBase;
}
*/
var zeros = [
'',
'0',
'00',
'000',
'0000',
'00000',
'000000',
'0000000',
'00000000',
'000000000',
'0000000000',
'00000000000',
'000000000000',
'0000000000000',
'00000000000000',
'000000000000000',
'0000000000000000',
'00000000000000000',
'000000000000000000',
'0000000000000000000',
'00000000000000000000',
'000000000000000000000',
'0000000000000000000000',
'00000000000000000000000',
'000000000000000000000000',
'0000000000000000000000000'
];
var groupSizes = [
0, 0,
25, 16, 12, 11, 10, 9, 8,
8, 7, 7, 7, 7, 6, 6,
6, 6, 6, 6, 6, 5, 5,
5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5
];
var groupBases = [
0, 0,
33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
];
BN.prototype.toString = function toString (base, padding) {
base = base || 10;
padding = padding | 0 || 1;
var out;
if (base === 16 || base === 'hex') {
out = '';
var off = 0;
var carry = 0;
for (var i = 0; i < this.length; i++) {
var w = this.words[i];
var word = (((w << off) | carry) & 0xffffff).toString(16);
carry = (w >>> (24 - off)) & 0xffffff;
if (carry !== 0 || i !== this.length - 1) {
out = zeros[6 - word.length] + word + out;
} else {
out = word + out;
}
off += 2;
if (off >= 26) {
off -= 26;
i--;
}
}
if (carry !== 0) {
out = carry.toString(16) + out;
}