@etherplay/dev-wallet-host 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +110 -0
  2. package/bin/dev-wallet-host.js +163 -0
  3. package/config.example.json +30 -0
  4. package/lib/server.js +130 -0
  5. package/package.json +52 -2
  6. package/site/Facebook_Logo_Primary.png +0 -0
  7. package/site/README.txt +12 -0
  8. package/site/_etherplay_accounts.html +168 -0
  9. package/site/assets/App-81EXtqUY.css +495 -0
  10. package/site/assets/App-n-xKxOMT.js +21249 -0
  11. package/site/assets/App-n-xKxOMT.js.map +1 -0
  12. package/site/assets/bignumbers-tTSUAFen.js +12 -0
  13. package/site/assets/bignumbers-tTSUAFen.js.map +1 -0
  14. package/site/assets/index-BqqAh48J.js +28 -0
  15. package/site/assets/index-BqqAh48J.js.map +1 -0
  16. package/site/assets/index-CnVGoVpH.js +4020 -0
  17. package/site/assets/index-CnVGoVpH.js.map +1 -0
  18. package/site/assets/index-DqysTtwQ.js +918 -0
  19. package/site/assets/index-DqysTtwQ.js.map +1 -0
  20. package/site/assets/index-Wu-sMuYC.js +5153 -0
  21. package/site/assets/index-Wu-sMuYC.js.map +1 -0
  22. package/site/assets/index-Y5uolvJQ.js +24364 -0
  23. package/site/assets/index-Y5uolvJQ.js.map +1 -0
  24. package/site/assets/index-client-8kPxwRn_.js +1771 -0
  25. package/site/assets/index-client-8kPxwRn_.js.map +1 -0
  26. package/site/assets/index-dhS1shEX.js +6227 -0
  27. package/site/assets/index-dhS1shEX.js.map +1 -0
  28. package/site/assets/index-l0sNRNKZ.js.map +1 -0
  29. package/site/assets/login-CbHgl9FL.js +324 -0
  30. package/site/assets/login-CbHgl9FL.js.map +1 -0
  31. package/site/assets/login-bn0FJsfM.css +30 -0
  32. package/site/assets/typed-data-Xi7g-SpO.js +834 -0
  33. package/site/assets/typed-data-Xi7g-SpO.js.map +1 -0
  34. package/site/assets/utf8-B9sGmk3K.js +172 -0
  35. package/site/assets/utf8-B9sGmk3K.js.map +1 -0
  36. package/site/build-info.json +4 -0
  37. package/site/google_logo.png +0 -0
  38. package/site/index.html +12 -0
  39. package/site/login/index.html +49 -0
  40. package/site/logo.svg +104 -0
  41. package/site/x-logo-black.png +0 -0
  42. package/site/x-logo-white.png +0 -0
@@ -0,0 +1,4020 @@
1
+ import { f as BN, d as defineReadOnly, e as checkProperties, h as encode, B as BigNumber, g as getAddress, i as decode } from "./index-Wu-sMuYC.js";
2
+ import { b as getDefaultExportFromCjs, s as splitSignature, a as arrayify, h as hexlify, L as Logger, j as hexDataLength, l as hexZeroPad, n as stripZeros, i as isBytesLike, m as hexConcat, k as keccak256, e as hexDataSlice } from "./App-n-xKxOMT.js";
3
+ import { Z as Zero } from "./bignumbers-tTSUAFen.js";
4
+ var hash$1 = {};
5
+ var utils = {};
6
+ var minimalisticAssert$1;
7
+ var hasRequiredMinimalisticAssert;
8
+ function requireMinimalisticAssert() {
9
+ if (hasRequiredMinimalisticAssert) return minimalisticAssert$1;
10
+ hasRequiredMinimalisticAssert = 1;
11
+ minimalisticAssert$1 = assert2;
12
+ function assert2(val, msg) {
13
+ if (!val)
14
+ throw new Error(msg || "Assertion failed");
15
+ }
16
+ assert2.equal = function assertEqual2(l, r, msg) {
17
+ if (l != r)
18
+ throw new Error(msg || "Assertion failed: " + l + " != " + r);
19
+ };
20
+ return minimalisticAssert$1;
21
+ }
22
+ var inherits_browser$1 = { exports: {} };
23
+ var hasRequiredInherits_browser;
24
+ function requireInherits_browser() {
25
+ if (hasRequiredInherits_browser) return inherits_browser$1.exports;
26
+ hasRequiredInherits_browser = 1;
27
+ if (typeof Object.create === "function") {
28
+ inherits_browser$1.exports = function inherits(ctor, superCtor) {
29
+ if (superCtor) {
30
+ ctor.super_ = superCtor;
31
+ ctor.prototype = Object.create(superCtor.prototype, {
32
+ constructor: {
33
+ value: ctor,
34
+ enumerable: false,
35
+ writable: true,
36
+ configurable: true
37
+ }
38
+ });
39
+ }
40
+ };
41
+ } else {
42
+ inherits_browser$1.exports = function inherits(ctor, superCtor) {
43
+ if (superCtor) {
44
+ ctor.super_ = superCtor;
45
+ var TempCtor = function() {
46
+ };
47
+ TempCtor.prototype = superCtor.prototype;
48
+ ctor.prototype = new TempCtor();
49
+ ctor.prototype.constructor = ctor;
50
+ }
51
+ };
52
+ }
53
+ return inherits_browser$1.exports;
54
+ }
55
+ var hasRequiredUtils;
56
+ function requireUtils() {
57
+ if (hasRequiredUtils) return utils;
58
+ hasRequiredUtils = 1;
59
+ var assert2 = requireMinimalisticAssert();
60
+ var inherits = requireInherits_browser();
61
+ utils.inherits = inherits;
62
+ function isSurrogatePair(msg, i) {
63
+ if ((msg.charCodeAt(i) & 64512) !== 55296) {
64
+ return false;
65
+ }
66
+ if (i < 0 || i + 1 >= msg.length) {
67
+ return false;
68
+ }
69
+ return (msg.charCodeAt(i + 1) & 64512) === 56320;
70
+ }
71
+ function toArray(msg, enc) {
72
+ if (Array.isArray(msg))
73
+ return msg.slice();
74
+ if (!msg)
75
+ return [];
76
+ var res = [];
77
+ if (typeof msg === "string") {
78
+ if (!enc) {
79
+ var p = 0;
80
+ for (var i = 0; i < msg.length; i++) {
81
+ var c = msg.charCodeAt(i);
82
+ if (c < 128) {
83
+ res[p++] = c;
84
+ } else if (c < 2048) {
85
+ res[p++] = c >> 6 | 192;
86
+ res[p++] = c & 63 | 128;
87
+ } else if (isSurrogatePair(msg, i)) {
88
+ c = 65536 + ((c & 1023) << 10) + (msg.charCodeAt(++i) & 1023);
89
+ res[p++] = c >> 18 | 240;
90
+ res[p++] = c >> 12 & 63 | 128;
91
+ res[p++] = c >> 6 & 63 | 128;
92
+ res[p++] = c & 63 | 128;
93
+ } else {
94
+ res[p++] = c >> 12 | 224;
95
+ res[p++] = c >> 6 & 63 | 128;
96
+ res[p++] = c & 63 | 128;
97
+ }
98
+ }
99
+ } else if (enc === "hex") {
100
+ msg = msg.replace(/[^a-z0-9]+/ig, "");
101
+ if (msg.length % 2 !== 0)
102
+ msg = "0" + msg;
103
+ for (i = 0; i < msg.length; i += 2)
104
+ res.push(parseInt(msg[i] + msg[i + 1], 16));
105
+ }
106
+ } else {
107
+ for (i = 0; i < msg.length; i++)
108
+ res[i] = msg[i] | 0;
109
+ }
110
+ return res;
111
+ }
112
+ utils.toArray = toArray;
113
+ function toHex(msg) {
114
+ var res = "";
115
+ for (var i = 0; i < msg.length; i++)
116
+ res += zero2(msg[i].toString(16));
117
+ return res;
118
+ }
119
+ utils.toHex = toHex;
120
+ function htonl(w) {
121
+ var res = w >>> 24 | w >>> 8 & 65280 | w << 8 & 16711680 | (w & 255) << 24;
122
+ return res >>> 0;
123
+ }
124
+ utils.htonl = htonl;
125
+ function toHex32(msg, endian) {
126
+ var res = "";
127
+ for (var i = 0; i < msg.length; i++) {
128
+ var w = msg[i];
129
+ if (endian === "little")
130
+ w = htonl(w);
131
+ res += zero8(w.toString(16));
132
+ }
133
+ return res;
134
+ }
135
+ utils.toHex32 = toHex32;
136
+ function zero2(word) {
137
+ if (word.length === 1)
138
+ return "0" + word;
139
+ else
140
+ return word;
141
+ }
142
+ utils.zero2 = zero2;
143
+ function zero8(word) {
144
+ if (word.length === 7)
145
+ return "0" + word;
146
+ else if (word.length === 6)
147
+ return "00" + word;
148
+ else if (word.length === 5)
149
+ return "000" + word;
150
+ else if (word.length === 4)
151
+ return "0000" + word;
152
+ else if (word.length === 3)
153
+ return "00000" + word;
154
+ else if (word.length === 2)
155
+ return "000000" + word;
156
+ else if (word.length === 1)
157
+ return "0000000" + word;
158
+ else
159
+ return word;
160
+ }
161
+ utils.zero8 = zero8;
162
+ function join32(msg, start, end, endian) {
163
+ var len = end - start;
164
+ assert2(len % 4 === 0);
165
+ var res = new Array(len / 4);
166
+ for (var i = 0, k = start; i < res.length; i++, k += 4) {
167
+ var w;
168
+ if (endian === "big")
169
+ w = msg[k] << 24 | msg[k + 1] << 16 | msg[k + 2] << 8 | msg[k + 3];
170
+ else
171
+ w = msg[k + 3] << 24 | msg[k + 2] << 16 | msg[k + 1] << 8 | msg[k];
172
+ res[i] = w >>> 0;
173
+ }
174
+ return res;
175
+ }
176
+ utils.join32 = join32;
177
+ function split32(msg, endian) {
178
+ var res = new Array(msg.length * 4);
179
+ for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
180
+ var m = msg[i];
181
+ if (endian === "big") {
182
+ res[k] = m >>> 24;
183
+ res[k + 1] = m >>> 16 & 255;
184
+ res[k + 2] = m >>> 8 & 255;
185
+ res[k + 3] = m & 255;
186
+ } else {
187
+ res[k + 3] = m >>> 24;
188
+ res[k + 2] = m >>> 16 & 255;
189
+ res[k + 1] = m >>> 8 & 255;
190
+ res[k] = m & 255;
191
+ }
192
+ }
193
+ return res;
194
+ }
195
+ utils.split32 = split32;
196
+ function rotr32(w, b) {
197
+ return w >>> b | w << 32 - b;
198
+ }
199
+ utils.rotr32 = rotr32;
200
+ function rotl32(w, b) {
201
+ return w << b | w >>> 32 - b;
202
+ }
203
+ utils.rotl32 = rotl32;
204
+ function sum32(a, b) {
205
+ return a + b >>> 0;
206
+ }
207
+ utils.sum32 = sum32;
208
+ function sum32_3(a, b, c) {
209
+ return a + b + c >>> 0;
210
+ }
211
+ utils.sum32_3 = sum32_3;
212
+ function sum32_4(a, b, c, d) {
213
+ return a + b + c + d >>> 0;
214
+ }
215
+ utils.sum32_4 = sum32_4;
216
+ function sum32_5(a, b, c, d, e) {
217
+ return a + b + c + d + e >>> 0;
218
+ }
219
+ utils.sum32_5 = sum32_5;
220
+ function sum64(buf, pos, ah, al) {
221
+ var bh = buf[pos];
222
+ var bl = buf[pos + 1];
223
+ var lo = al + bl >>> 0;
224
+ var hi = (lo < al ? 1 : 0) + ah + bh;
225
+ buf[pos] = hi >>> 0;
226
+ buf[pos + 1] = lo;
227
+ }
228
+ utils.sum64 = sum64;
229
+ function sum64_hi(ah, al, bh, bl) {
230
+ var lo = al + bl >>> 0;
231
+ var hi = (lo < al ? 1 : 0) + ah + bh;
232
+ return hi >>> 0;
233
+ }
234
+ utils.sum64_hi = sum64_hi;
235
+ function sum64_lo(ah, al, bh, bl) {
236
+ var lo = al + bl;
237
+ return lo >>> 0;
238
+ }
239
+ utils.sum64_lo = sum64_lo;
240
+ function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
241
+ var carry = 0;
242
+ var lo = al;
243
+ lo = lo + bl >>> 0;
244
+ carry += lo < al ? 1 : 0;
245
+ lo = lo + cl >>> 0;
246
+ carry += lo < cl ? 1 : 0;
247
+ lo = lo + dl >>> 0;
248
+ carry += lo < dl ? 1 : 0;
249
+ var hi = ah + bh + ch + dh + carry;
250
+ return hi >>> 0;
251
+ }
252
+ utils.sum64_4_hi = sum64_4_hi;
253
+ function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
254
+ var lo = al + bl + cl + dl;
255
+ return lo >>> 0;
256
+ }
257
+ utils.sum64_4_lo = sum64_4_lo;
258
+ function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
259
+ var carry = 0;
260
+ var lo = al;
261
+ lo = lo + bl >>> 0;
262
+ carry += lo < al ? 1 : 0;
263
+ lo = lo + cl >>> 0;
264
+ carry += lo < cl ? 1 : 0;
265
+ lo = lo + dl >>> 0;
266
+ carry += lo < dl ? 1 : 0;
267
+ lo = lo + el >>> 0;
268
+ carry += lo < el ? 1 : 0;
269
+ var hi = ah + bh + ch + dh + eh + carry;
270
+ return hi >>> 0;
271
+ }
272
+ utils.sum64_5_hi = sum64_5_hi;
273
+ function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
274
+ var lo = al + bl + cl + dl + el;
275
+ return lo >>> 0;
276
+ }
277
+ utils.sum64_5_lo = sum64_5_lo;
278
+ function rotr64_hi(ah, al, num) {
279
+ var r = al << 32 - num | ah >>> num;
280
+ return r >>> 0;
281
+ }
282
+ utils.rotr64_hi = rotr64_hi;
283
+ function rotr64_lo(ah, al, num) {
284
+ var r = ah << 32 - num | al >>> num;
285
+ return r >>> 0;
286
+ }
287
+ utils.rotr64_lo = rotr64_lo;
288
+ function shr64_hi(ah, al, num) {
289
+ return ah >>> num;
290
+ }
291
+ utils.shr64_hi = shr64_hi;
292
+ function shr64_lo(ah, al, num) {
293
+ var r = ah << 32 - num | al >>> num;
294
+ return r >>> 0;
295
+ }
296
+ utils.shr64_lo = shr64_lo;
297
+ return utils;
298
+ }
299
+ var common$1 = {};
300
+ var hasRequiredCommon$1;
301
+ function requireCommon$1() {
302
+ if (hasRequiredCommon$1) return common$1;
303
+ hasRequiredCommon$1 = 1;
304
+ var utils2 = requireUtils();
305
+ var assert2 = requireMinimalisticAssert();
306
+ function BlockHash() {
307
+ this.pending = null;
308
+ this.pendingTotal = 0;
309
+ this.blockSize = this.constructor.blockSize;
310
+ this.outSize = this.constructor.outSize;
311
+ this.hmacStrength = this.constructor.hmacStrength;
312
+ this.padLength = this.constructor.padLength / 8;
313
+ this.endian = "big";
314
+ this._delta8 = this.blockSize / 8;
315
+ this._delta32 = this.blockSize / 32;
316
+ }
317
+ common$1.BlockHash = BlockHash;
318
+ BlockHash.prototype.update = function update2(msg, enc) {
319
+ msg = utils2.toArray(msg, enc);
320
+ if (!this.pending)
321
+ this.pending = msg;
322
+ else
323
+ this.pending = this.pending.concat(msg);
324
+ this.pendingTotal += msg.length;
325
+ if (this.pending.length >= this._delta8) {
326
+ msg = this.pending;
327
+ var r = msg.length % this._delta8;
328
+ this.pending = msg.slice(msg.length - r, msg.length);
329
+ if (this.pending.length === 0)
330
+ this.pending = null;
331
+ msg = utils2.join32(msg, 0, msg.length - r, this.endian);
332
+ for (var i = 0; i < msg.length; i += this._delta32)
333
+ this._update(msg, i, i + this._delta32);
334
+ }
335
+ return this;
336
+ };
337
+ BlockHash.prototype.digest = function digest(enc) {
338
+ this.update(this._pad());
339
+ assert2(this.pending === null);
340
+ return this._digest(enc);
341
+ };
342
+ BlockHash.prototype._pad = function pad() {
343
+ var len = this.pendingTotal;
344
+ var bytes = this._delta8;
345
+ var k = bytes - (len + this.padLength) % bytes;
346
+ var res = new Array(k + this.padLength);
347
+ res[0] = 128;
348
+ for (var i = 1; i < k; i++)
349
+ res[i] = 0;
350
+ len <<= 3;
351
+ if (this.endian === "big") {
352
+ for (var t = 8; t < this.padLength; t++)
353
+ res[i++] = 0;
354
+ res[i++] = 0;
355
+ res[i++] = 0;
356
+ res[i++] = 0;
357
+ res[i++] = 0;
358
+ res[i++] = len >>> 24 & 255;
359
+ res[i++] = len >>> 16 & 255;
360
+ res[i++] = len >>> 8 & 255;
361
+ res[i++] = len & 255;
362
+ } else {
363
+ res[i++] = len & 255;
364
+ res[i++] = len >>> 8 & 255;
365
+ res[i++] = len >>> 16 & 255;
366
+ res[i++] = len >>> 24 & 255;
367
+ res[i++] = 0;
368
+ res[i++] = 0;
369
+ res[i++] = 0;
370
+ res[i++] = 0;
371
+ for (t = 8; t < this.padLength; t++)
372
+ res[i++] = 0;
373
+ }
374
+ return res;
375
+ };
376
+ return common$1;
377
+ }
378
+ var sha = {};
379
+ var common = {};
380
+ var hasRequiredCommon;
381
+ function requireCommon() {
382
+ if (hasRequiredCommon) return common;
383
+ hasRequiredCommon = 1;
384
+ var utils2 = requireUtils();
385
+ var rotr32 = utils2.rotr32;
386
+ function ft_1(s, x, y, z) {
387
+ if (s === 0)
388
+ return ch32(x, y, z);
389
+ if (s === 1 || s === 3)
390
+ return p32(x, y, z);
391
+ if (s === 2)
392
+ return maj32(x, y, z);
393
+ }
394
+ common.ft_1 = ft_1;
395
+ function ch32(x, y, z) {
396
+ return x & y ^ ~x & z;
397
+ }
398
+ common.ch32 = ch32;
399
+ function maj32(x, y, z) {
400
+ return x & y ^ x & z ^ y & z;
401
+ }
402
+ common.maj32 = maj32;
403
+ function p32(x, y, z) {
404
+ return x ^ y ^ z;
405
+ }
406
+ common.p32 = p32;
407
+ function s0_256(x) {
408
+ return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
409
+ }
410
+ common.s0_256 = s0_256;
411
+ function s1_256(x) {
412
+ return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
413
+ }
414
+ common.s1_256 = s1_256;
415
+ function g0_256(x) {
416
+ return rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3;
417
+ }
418
+ common.g0_256 = g0_256;
419
+ function g1_256(x) {
420
+ return rotr32(x, 17) ^ rotr32(x, 19) ^ x >>> 10;
421
+ }
422
+ common.g1_256 = g1_256;
423
+ return common;
424
+ }
425
+ var _1;
426
+ var hasRequired_1;
427
+ function require_1() {
428
+ if (hasRequired_1) return _1;
429
+ hasRequired_1 = 1;
430
+ var utils2 = requireUtils();
431
+ var common2 = requireCommon$1();
432
+ var shaCommon = requireCommon();
433
+ var rotl32 = utils2.rotl32;
434
+ var sum32 = utils2.sum32;
435
+ var sum32_5 = utils2.sum32_5;
436
+ var ft_1 = shaCommon.ft_1;
437
+ var BlockHash = common2.BlockHash;
438
+ var sha1_K = [
439
+ 1518500249,
440
+ 1859775393,
441
+ 2400959708,
442
+ 3395469782
443
+ ];
444
+ function SHA1() {
445
+ if (!(this instanceof SHA1))
446
+ return new SHA1();
447
+ BlockHash.call(this);
448
+ this.h = [
449
+ 1732584193,
450
+ 4023233417,
451
+ 2562383102,
452
+ 271733878,
453
+ 3285377520
454
+ ];
455
+ this.W = new Array(80);
456
+ }
457
+ utils2.inherits(SHA1, BlockHash);
458
+ _1 = SHA1;
459
+ SHA1.blockSize = 512;
460
+ SHA1.outSize = 160;
461
+ SHA1.hmacStrength = 80;
462
+ SHA1.padLength = 64;
463
+ SHA1.prototype._update = function _update(msg, start) {
464
+ var W = this.W;
465
+ for (var i = 0; i < 16; i++)
466
+ W[i] = msg[start + i];
467
+ for (; i < W.length; i++)
468
+ W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
469
+ var a = this.h[0];
470
+ var b = this.h[1];
471
+ var c = this.h[2];
472
+ var d = this.h[3];
473
+ var e = this.h[4];
474
+ for (i = 0; i < W.length; i++) {
475
+ var s = ~~(i / 20);
476
+ var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
477
+ e = d;
478
+ d = c;
479
+ c = rotl32(b, 30);
480
+ b = a;
481
+ a = t;
482
+ }
483
+ this.h[0] = sum32(this.h[0], a);
484
+ this.h[1] = sum32(this.h[1], b);
485
+ this.h[2] = sum32(this.h[2], c);
486
+ this.h[3] = sum32(this.h[3], d);
487
+ this.h[4] = sum32(this.h[4], e);
488
+ };
489
+ SHA1.prototype._digest = function digest(enc) {
490
+ if (enc === "hex")
491
+ return utils2.toHex32(this.h, "big");
492
+ else
493
+ return utils2.split32(this.h, "big");
494
+ };
495
+ return _1;
496
+ }
497
+ var _256;
498
+ var hasRequired_256;
499
+ function require_256() {
500
+ if (hasRequired_256) return _256;
501
+ hasRequired_256 = 1;
502
+ var utils2 = requireUtils();
503
+ var common2 = requireCommon$1();
504
+ var shaCommon = requireCommon();
505
+ var assert2 = requireMinimalisticAssert();
506
+ var sum32 = utils2.sum32;
507
+ var sum32_4 = utils2.sum32_4;
508
+ var sum32_5 = utils2.sum32_5;
509
+ var ch32 = shaCommon.ch32;
510
+ var maj32 = shaCommon.maj32;
511
+ var s0_256 = shaCommon.s0_256;
512
+ var s1_256 = shaCommon.s1_256;
513
+ var g0_256 = shaCommon.g0_256;
514
+ var g1_256 = shaCommon.g1_256;
515
+ var BlockHash = common2.BlockHash;
516
+ var sha256_K = [
517
+ 1116352408,
518
+ 1899447441,
519
+ 3049323471,
520
+ 3921009573,
521
+ 961987163,
522
+ 1508970993,
523
+ 2453635748,
524
+ 2870763221,
525
+ 3624381080,
526
+ 310598401,
527
+ 607225278,
528
+ 1426881987,
529
+ 1925078388,
530
+ 2162078206,
531
+ 2614888103,
532
+ 3248222580,
533
+ 3835390401,
534
+ 4022224774,
535
+ 264347078,
536
+ 604807628,
537
+ 770255983,
538
+ 1249150122,
539
+ 1555081692,
540
+ 1996064986,
541
+ 2554220882,
542
+ 2821834349,
543
+ 2952996808,
544
+ 3210313671,
545
+ 3336571891,
546
+ 3584528711,
547
+ 113926993,
548
+ 338241895,
549
+ 666307205,
550
+ 773529912,
551
+ 1294757372,
552
+ 1396182291,
553
+ 1695183700,
554
+ 1986661051,
555
+ 2177026350,
556
+ 2456956037,
557
+ 2730485921,
558
+ 2820302411,
559
+ 3259730800,
560
+ 3345764771,
561
+ 3516065817,
562
+ 3600352804,
563
+ 4094571909,
564
+ 275423344,
565
+ 430227734,
566
+ 506948616,
567
+ 659060556,
568
+ 883997877,
569
+ 958139571,
570
+ 1322822218,
571
+ 1537002063,
572
+ 1747873779,
573
+ 1955562222,
574
+ 2024104815,
575
+ 2227730452,
576
+ 2361852424,
577
+ 2428436474,
578
+ 2756734187,
579
+ 3204031479,
580
+ 3329325298
581
+ ];
582
+ function SHA256() {
583
+ if (!(this instanceof SHA256))
584
+ return new SHA256();
585
+ BlockHash.call(this);
586
+ this.h = [
587
+ 1779033703,
588
+ 3144134277,
589
+ 1013904242,
590
+ 2773480762,
591
+ 1359893119,
592
+ 2600822924,
593
+ 528734635,
594
+ 1541459225
595
+ ];
596
+ this.k = sha256_K;
597
+ this.W = new Array(64);
598
+ }
599
+ utils2.inherits(SHA256, BlockHash);
600
+ _256 = SHA256;
601
+ SHA256.blockSize = 512;
602
+ SHA256.outSize = 256;
603
+ SHA256.hmacStrength = 192;
604
+ SHA256.padLength = 64;
605
+ SHA256.prototype._update = function _update(msg, start) {
606
+ var W = this.W;
607
+ for (var i = 0; i < 16; i++)
608
+ W[i] = msg[start + i];
609
+ for (; i < W.length; i++)
610
+ W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
611
+ var a = this.h[0];
612
+ var b = this.h[1];
613
+ var c = this.h[2];
614
+ var d = this.h[3];
615
+ var e = this.h[4];
616
+ var f = this.h[5];
617
+ var g = this.h[6];
618
+ var h = this.h[7];
619
+ assert2(this.k.length === W.length);
620
+ for (i = 0; i < W.length; i++) {
621
+ var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
622
+ var T2 = sum32(s0_256(a), maj32(a, b, c));
623
+ h = g;
624
+ g = f;
625
+ f = e;
626
+ e = sum32(d, T1);
627
+ d = c;
628
+ c = b;
629
+ b = a;
630
+ a = sum32(T1, T2);
631
+ }
632
+ this.h[0] = sum32(this.h[0], a);
633
+ this.h[1] = sum32(this.h[1], b);
634
+ this.h[2] = sum32(this.h[2], c);
635
+ this.h[3] = sum32(this.h[3], d);
636
+ this.h[4] = sum32(this.h[4], e);
637
+ this.h[5] = sum32(this.h[5], f);
638
+ this.h[6] = sum32(this.h[6], g);
639
+ this.h[7] = sum32(this.h[7], h);
640
+ };
641
+ SHA256.prototype._digest = function digest(enc) {
642
+ if (enc === "hex")
643
+ return utils2.toHex32(this.h, "big");
644
+ else
645
+ return utils2.split32(this.h, "big");
646
+ };
647
+ return _256;
648
+ }
649
+ var _224;
650
+ var hasRequired_224;
651
+ function require_224() {
652
+ if (hasRequired_224) return _224;
653
+ hasRequired_224 = 1;
654
+ var utils2 = requireUtils();
655
+ var SHA256 = require_256();
656
+ function SHA224() {
657
+ if (!(this instanceof SHA224))
658
+ return new SHA224();
659
+ SHA256.call(this);
660
+ this.h = [
661
+ 3238371032,
662
+ 914150663,
663
+ 812702999,
664
+ 4144912697,
665
+ 4290775857,
666
+ 1750603025,
667
+ 1694076839,
668
+ 3204075428
669
+ ];
670
+ }
671
+ utils2.inherits(SHA224, SHA256);
672
+ _224 = SHA224;
673
+ SHA224.blockSize = 512;
674
+ SHA224.outSize = 224;
675
+ SHA224.hmacStrength = 192;
676
+ SHA224.padLength = 64;
677
+ SHA224.prototype._digest = function digest(enc) {
678
+ if (enc === "hex")
679
+ return utils2.toHex32(this.h.slice(0, 7), "big");
680
+ else
681
+ return utils2.split32(this.h.slice(0, 7), "big");
682
+ };
683
+ return _224;
684
+ }
685
+ var _512;
686
+ var hasRequired_512;
687
+ function require_512() {
688
+ if (hasRequired_512) return _512;
689
+ hasRequired_512 = 1;
690
+ var utils2 = requireUtils();
691
+ var common2 = requireCommon$1();
692
+ var assert2 = requireMinimalisticAssert();
693
+ var rotr64_hi = utils2.rotr64_hi;
694
+ var rotr64_lo = utils2.rotr64_lo;
695
+ var shr64_hi = utils2.shr64_hi;
696
+ var shr64_lo = utils2.shr64_lo;
697
+ var sum64 = utils2.sum64;
698
+ var sum64_hi = utils2.sum64_hi;
699
+ var sum64_lo = utils2.sum64_lo;
700
+ var sum64_4_hi = utils2.sum64_4_hi;
701
+ var sum64_4_lo = utils2.sum64_4_lo;
702
+ var sum64_5_hi = utils2.sum64_5_hi;
703
+ var sum64_5_lo = utils2.sum64_5_lo;
704
+ var BlockHash = common2.BlockHash;
705
+ var sha512_K = [
706
+ 1116352408,
707
+ 3609767458,
708
+ 1899447441,
709
+ 602891725,
710
+ 3049323471,
711
+ 3964484399,
712
+ 3921009573,
713
+ 2173295548,
714
+ 961987163,
715
+ 4081628472,
716
+ 1508970993,
717
+ 3053834265,
718
+ 2453635748,
719
+ 2937671579,
720
+ 2870763221,
721
+ 3664609560,
722
+ 3624381080,
723
+ 2734883394,
724
+ 310598401,
725
+ 1164996542,
726
+ 607225278,
727
+ 1323610764,
728
+ 1426881987,
729
+ 3590304994,
730
+ 1925078388,
731
+ 4068182383,
732
+ 2162078206,
733
+ 991336113,
734
+ 2614888103,
735
+ 633803317,
736
+ 3248222580,
737
+ 3479774868,
738
+ 3835390401,
739
+ 2666613458,
740
+ 4022224774,
741
+ 944711139,
742
+ 264347078,
743
+ 2341262773,
744
+ 604807628,
745
+ 2007800933,
746
+ 770255983,
747
+ 1495990901,
748
+ 1249150122,
749
+ 1856431235,
750
+ 1555081692,
751
+ 3175218132,
752
+ 1996064986,
753
+ 2198950837,
754
+ 2554220882,
755
+ 3999719339,
756
+ 2821834349,
757
+ 766784016,
758
+ 2952996808,
759
+ 2566594879,
760
+ 3210313671,
761
+ 3203337956,
762
+ 3336571891,
763
+ 1034457026,
764
+ 3584528711,
765
+ 2466948901,
766
+ 113926993,
767
+ 3758326383,
768
+ 338241895,
769
+ 168717936,
770
+ 666307205,
771
+ 1188179964,
772
+ 773529912,
773
+ 1546045734,
774
+ 1294757372,
775
+ 1522805485,
776
+ 1396182291,
777
+ 2643833823,
778
+ 1695183700,
779
+ 2343527390,
780
+ 1986661051,
781
+ 1014477480,
782
+ 2177026350,
783
+ 1206759142,
784
+ 2456956037,
785
+ 344077627,
786
+ 2730485921,
787
+ 1290863460,
788
+ 2820302411,
789
+ 3158454273,
790
+ 3259730800,
791
+ 3505952657,
792
+ 3345764771,
793
+ 106217008,
794
+ 3516065817,
795
+ 3606008344,
796
+ 3600352804,
797
+ 1432725776,
798
+ 4094571909,
799
+ 1467031594,
800
+ 275423344,
801
+ 851169720,
802
+ 430227734,
803
+ 3100823752,
804
+ 506948616,
805
+ 1363258195,
806
+ 659060556,
807
+ 3750685593,
808
+ 883997877,
809
+ 3785050280,
810
+ 958139571,
811
+ 3318307427,
812
+ 1322822218,
813
+ 3812723403,
814
+ 1537002063,
815
+ 2003034995,
816
+ 1747873779,
817
+ 3602036899,
818
+ 1955562222,
819
+ 1575990012,
820
+ 2024104815,
821
+ 1125592928,
822
+ 2227730452,
823
+ 2716904306,
824
+ 2361852424,
825
+ 442776044,
826
+ 2428436474,
827
+ 593698344,
828
+ 2756734187,
829
+ 3733110249,
830
+ 3204031479,
831
+ 2999351573,
832
+ 3329325298,
833
+ 3815920427,
834
+ 3391569614,
835
+ 3928383900,
836
+ 3515267271,
837
+ 566280711,
838
+ 3940187606,
839
+ 3454069534,
840
+ 4118630271,
841
+ 4000239992,
842
+ 116418474,
843
+ 1914138554,
844
+ 174292421,
845
+ 2731055270,
846
+ 289380356,
847
+ 3203993006,
848
+ 460393269,
849
+ 320620315,
850
+ 685471733,
851
+ 587496836,
852
+ 852142971,
853
+ 1086792851,
854
+ 1017036298,
855
+ 365543100,
856
+ 1126000580,
857
+ 2618297676,
858
+ 1288033470,
859
+ 3409855158,
860
+ 1501505948,
861
+ 4234509866,
862
+ 1607167915,
863
+ 987167468,
864
+ 1816402316,
865
+ 1246189591
866
+ ];
867
+ function SHA512() {
868
+ if (!(this instanceof SHA512))
869
+ return new SHA512();
870
+ BlockHash.call(this);
871
+ this.h = [
872
+ 1779033703,
873
+ 4089235720,
874
+ 3144134277,
875
+ 2227873595,
876
+ 1013904242,
877
+ 4271175723,
878
+ 2773480762,
879
+ 1595750129,
880
+ 1359893119,
881
+ 2917565137,
882
+ 2600822924,
883
+ 725511199,
884
+ 528734635,
885
+ 4215389547,
886
+ 1541459225,
887
+ 327033209
888
+ ];
889
+ this.k = sha512_K;
890
+ this.W = new Array(160);
891
+ }
892
+ utils2.inherits(SHA512, BlockHash);
893
+ _512 = SHA512;
894
+ SHA512.blockSize = 1024;
895
+ SHA512.outSize = 512;
896
+ SHA512.hmacStrength = 192;
897
+ SHA512.padLength = 128;
898
+ SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
899
+ var W = this.W;
900
+ for (var i = 0; i < 32; i++)
901
+ W[i] = msg[start + i];
902
+ for (; i < W.length; i += 2) {
903
+ var c0_hi = g1_512_hi(W[i - 4], W[i - 3]);
904
+ var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
905
+ var c1_hi = W[i - 14];
906
+ var c1_lo = W[i - 13];
907
+ var c2_hi = g0_512_hi(W[i - 30], W[i - 29]);
908
+ var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
909
+ var c3_hi = W[i - 32];
910
+ var c3_lo = W[i - 31];
911
+ W[i] = sum64_4_hi(
912
+ c0_hi,
913
+ c0_lo,
914
+ c1_hi,
915
+ c1_lo,
916
+ c2_hi,
917
+ c2_lo,
918
+ c3_hi,
919
+ c3_lo
920
+ );
921
+ W[i + 1] = sum64_4_lo(
922
+ c0_hi,
923
+ c0_lo,
924
+ c1_hi,
925
+ c1_lo,
926
+ c2_hi,
927
+ c2_lo,
928
+ c3_hi,
929
+ c3_lo
930
+ );
931
+ }
932
+ };
933
+ SHA512.prototype._update = function _update(msg, start) {
934
+ this._prepareBlock(msg, start);
935
+ var W = this.W;
936
+ var ah = this.h[0];
937
+ var al = this.h[1];
938
+ var bh = this.h[2];
939
+ var bl = this.h[3];
940
+ var ch = this.h[4];
941
+ var cl = this.h[5];
942
+ var dh = this.h[6];
943
+ var dl = this.h[7];
944
+ var eh = this.h[8];
945
+ var el = this.h[9];
946
+ var fh = this.h[10];
947
+ var fl = this.h[11];
948
+ var gh = this.h[12];
949
+ var gl = this.h[13];
950
+ var hh = this.h[14];
951
+ var hl = this.h[15];
952
+ assert2(this.k.length === W.length);
953
+ for (var i = 0; i < W.length; i += 2) {
954
+ var c0_hi = hh;
955
+ var c0_lo = hl;
956
+ var c1_hi = s1_512_hi(eh, el);
957
+ var c1_lo = s1_512_lo(eh, el);
958
+ var c2_hi = ch64_hi(eh, el, fh, fl, gh);
959
+ var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
960
+ var c3_hi = this.k[i];
961
+ var c3_lo = this.k[i + 1];
962
+ var c4_hi = W[i];
963
+ var c4_lo = W[i + 1];
964
+ var T1_hi = sum64_5_hi(
965
+ c0_hi,
966
+ c0_lo,
967
+ c1_hi,
968
+ c1_lo,
969
+ c2_hi,
970
+ c2_lo,
971
+ c3_hi,
972
+ c3_lo,
973
+ c4_hi,
974
+ c4_lo
975
+ );
976
+ var T1_lo = sum64_5_lo(
977
+ c0_hi,
978
+ c0_lo,
979
+ c1_hi,
980
+ c1_lo,
981
+ c2_hi,
982
+ c2_lo,
983
+ c3_hi,
984
+ c3_lo,
985
+ c4_hi,
986
+ c4_lo
987
+ );
988
+ c0_hi = s0_512_hi(ah, al);
989
+ c0_lo = s0_512_lo(ah, al);
990
+ c1_hi = maj64_hi(ah, al, bh, bl, ch);
991
+ c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
992
+ var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
993
+ var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
994
+ hh = gh;
995
+ hl = gl;
996
+ gh = fh;
997
+ gl = fl;
998
+ fh = eh;
999
+ fl = el;
1000
+ eh = sum64_hi(dh, dl, T1_hi, T1_lo);
1001
+ el = sum64_lo(dl, dl, T1_hi, T1_lo);
1002
+ dh = ch;
1003
+ dl = cl;
1004
+ ch = bh;
1005
+ cl = bl;
1006
+ bh = ah;
1007
+ bl = al;
1008
+ ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
1009
+ al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
1010
+ }
1011
+ sum64(this.h, 0, ah, al);
1012
+ sum64(this.h, 2, bh, bl);
1013
+ sum64(this.h, 4, ch, cl);
1014
+ sum64(this.h, 6, dh, dl);
1015
+ sum64(this.h, 8, eh, el);
1016
+ sum64(this.h, 10, fh, fl);
1017
+ sum64(this.h, 12, gh, gl);
1018
+ sum64(this.h, 14, hh, hl);
1019
+ };
1020
+ SHA512.prototype._digest = function digest(enc) {
1021
+ if (enc === "hex")
1022
+ return utils2.toHex32(this.h, "big");
1023
+ else
1024
+ return utils2.split32(this.h, "big");
1025
+ };
1026
+ function ch64_hi(xh, xl, yh, yl, zh) {
1027
+ var r = xh & yh ^ ~xh & zh;
1028
+ if (r < 0)
1029
+ r += 4294967296;
1030
+ return r;
1031
+ }
1032
+ function ch64_lo(xh, xl, yh, yl, zh, zl) {
1033
+ var r = xl & yl ^ ~xl & zl;
1034
+ if (r < 0)
1035
+ r += 4294967296;
1036
+ return r;
1037
+ }
1038
+ function maj64_hi(xh, xl, yh, yl, zh) {
1039
+ var r = xh & yh ^ xh & zh ^ yh & zh;
1040
+ if (r < 0)
1041
+ r += 4294967296;
1042
+ return r;
1043
+ }
1044
+ function maj64_lo(xh, xl, yh, yl, zh, zl) {
1045
+ var r = xl & yl ^ xl & zl ^ yl & zl;
1046
+ if (r < 0)
1047
+ r += 4294967296;
1048
+ return r;
1049
+ }
1050
+ function s0_512_hi(xh, xl) {
1051
+ var c0_hi = rotr64_hi(xh, xl, 28);
1052
+ var c1_hi = rotr64_hi(xl, xh, 2);
1053
+ var c2_hi = rotr64_hi(xl, xh, 7);
1054
+ var r = c0_hi ^ c1_hi ^ c2_hi;
1055
+ if (r < 0)
1056
+ r += 4294967296;
1057
+ return r;
1058
+ }
1059
+ function s0_512_lo(xh, xl) {
1060
+ var c0_lo = rotr64_lo(xh, xl, 28);
1061
+ var c1_lo = rotr64_lo(xl, xh, 2);
1062
+ var c2_lo = rotr64_lo(xl, xh, 7);
1063
+ var r = c0_lo ^ c1_lo ^ c2_lo;
1064
+ if (r < 0)
1065
+ r += 4294967296;
1066
+ return r;
1067
+ }
1068
+ function s1_512_hi(xh, xl) {
1069
+ var c0_hi = rotr64_hi(xh, xl, 14);
1070
+ var c1_hi = rotr64_hi(xh, xl, 18);
1071
+ var c2_hi = rotr64_hi(xl, xh, 9);
1072
+ var r = c0_hi ^ c1_hi ^ c2_hi;
1073
+ if (r < 0)
1074
+ r += 4294967296;
1075
+ return r;
1076
+ }
1077
+ function s1_512_lo(xh, xl) {
1078
+ var c0_lo = rotr64_lo(xh, xl, 14);
1079
+ var c1_lo = rotr64_lo(xh, xl, 18);
1080
+ var c2_lo = rotr64_lo(xl, xh, 9);
1081
+ var r = c0_lo ^ c1_lo ^ c2_lo;
1082
+ if (r < 0)
1083
+ r += 4294967296;
1084
+ return r;
1085
+ }
1086
+ function g0_512_hi(xh, xl) {
1087
+ var c0_hi = rotr64_hi(xh, xl, 1);
1088
+ var c1_hi = rotr64_hi(xh, xl, 8);
1089
+ var c2_hi = shr64_hi(xh, xl, 7);
1090
+ var r = c0_hi ^ c1_hi ^ c2_hi;
1091
+ if (r < 0)
1092
+ r += 4294967296;
1093
+ return r;
1094
+ }
1095
+ function g0_512_lo(xh, xl) {
1096
+ var c0_lo = rotr64_lo(xh, xl, 1);
1097
+ var c1_lo = rotr64_lo(xh, xl, 8);
1098
+ var c2_lo = shr64_lo(xh, xl, 7);
1099
+ var r = c0_lo ^ c1_lo ^ c2_lo;
1100
+ if (r < 0)
1101
+ r += 4294967296;
1102
+ return r;
1103
+ }
1104
+ function g1_512_hi(xh, xl) {
1105
+ var c0_hi = rotr64_hi(xh, xl, 19);
1106
+ var c1_hi = rotr64_hi(xl, xh, 29);
1107
+ var c2_hi = shr64_hi(xh, xl, 6);
1108
+ var r = c0_hi ^ c1_hi ^ c2_hi;
1109
+ if (r < 0)
1110
+ r += 4294967296;
1111
+ return r;
1112
+ }
1113
+ function g1_512_lo(xh, xl) {
1114
+ var c0_lo = rotr64_lo(xh, xl, 19);
1115
+ var c1_lo = rotr64_lo(xl, xh, 29);
1116
+ var c2_lo = shr64_lo(xh, xl, 6);
1117
+ var r = c0_lo ^ c1_lo ^ c2_lo;
1118
+ if (r < 0)
1119
+ r += 4294967296;
1120
+ return r;
1121
+ }
1122
+ return _512;
1123
+ }
1124
+ var _384;
1125
+ var hasRequired_384;
1126
+ function require_384() {
1127
+ if (hasRequired_384) return _384;
1128
+ hasRequired_384 = 1;
1129
+ var utils2 = requireUtils();
1130
+ var SHA512 = require_512();
1131
+ function SHA384() {
1132
+ if (!(this instanceof SHA384))
1133
+ return new SHA384();
1134
+ SHA512.call(this);
1135
+ this.h = [
1136
+ 3418070365,
1137
+ 3238371032,
1138
+ 1654270250,
1139
+ 914150663,
1140
+ 2438529370,
1141
+ 812702999,
1142
+ 355462360,
1143
+ 4144912697,
1144
+ 1731405415,
1145
+ 4290775857,
1146
+ 2394180231,
1147
+ 1750603025,
1148
+ 3675008525,
1149
+ 1694076839,
1150
+ 1203062813,
1151
+ 3204075428
1152
+ ];
1153
+ }
1154
+ utils2.inherits(SHA384, SHA512);
1155
+ _384 = SHA384;
1156
+ SHA384.blockSize = 1024;
1157
+ SHA384.outSize = 384;
1158
+ SHA384.hmacStrength = 192;
1159
+ SHA384.padLength = 128;
1160
+ SHA384.prototype._digest = function digest(enc) {
1161
+ if (enc === "hex")
1162
+ return utils2.toHex32(this.h.slice(0, 12), "big");
1163
+ else
1164
+ return utils2.split32(this.h.slice(0, 12), "big");
1165
+ };
1166
+ return _384;
1167
+ }
1168
+ var hasRequiredSha;
1169
+ function requireSha() {
1170
+ if (hasRequiredSha) return sha;
1171
+ hasRequiredSha = 1;
1172
+ sha.sha1 = require_1();
1173
+ sha.sha224 = require_224();
1174
+ sha.sha256 = require_256();
1175
+ sha.sha384 = require_384();
1176
+ sha.sha512 = require_512();
1177
+ return sha;
1178
+ }
1179
+ var ripemd = {};
1180
+ var hasRequiredRipemd;
1181
+ function requireRipemd() {
1182
+ if (hasRequiredRipemd) return ripemd;
1183
+ hasRequiredRipemd = 1;
1184
+ var utils2 = requireUtils();
1185
+ var common2 = requireCommon$1();
1186
+ var rotl32 = utils2.rotl32;
1187
+ var sum32 = utils2.sum32;
1188
+ var sum32_3 = utils2.sum32_3;
1189
+ var sum32_4 = utils2.sum32_4;
1190
+ var BlockHash = common2.BlockHash;
1191
+ function RIPEMD160() {
1192
+ if (!(this instanceof RIPEMD160))
1193
+ return new RIPEMD160();
1194
+ BlockHash.call(this);
1195
+ this.h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
1196
+ this.endian = "little";
1197
+ }
1198
+ utils2.inherits(RIPEMD160, BlockHash);
1199
+ ripemd.ripemd160 = RIPEMD160;
1200
+ RIPEMD160.blockSize = 512;
1201
+ RIPEMD160.outSize = 160;
1202
+ RIPEMD160.hmacStrength = 192;
1203
+ RIPEMD160.padLength = 64;
1204
+ RIPEMD160.prototype._update = function update2(msg, start) {
1205
+ var A = this.h[0];
1206
+ var B = this.h[1];
1207
+ var C = this.h[2];
1208
+ var D = this.h[3];
1209
+ var E = this.h[4];
1210
+ var Ah = A;
1211
+ var Bh = B;
1212
+ var Ch = C;
1213
+ var Dh = D;
1214
+ var Eh = E;
1215
+ for (var j = 0; j < 80; j++) {
1216
+ var T = sum32(
1217
+ rotl32(
1218
+ sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
1219
+ s[j]
1220
+ ),
1221
+ E
1222
+ );
1223
+ A = E;
1224
+ E = D;
1225
+ D = rotl32(C, 10);
1226
+ C = B;
1227
+ B = T;
1228
+ T = sum32(
1229
+ rotl32(
1230
+ sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
1231
+ sh[j]
1232
+ ),
1233
+ Eh
1234
+ );
1235
+ Ah = Eh;
1236
+ Eh = Dh;
1237
+ Dh = rotl32(Ch, 10);
1238
+ Ch = Bh;
1239
+ Bh = T;
1240
+ }
1241
+ T = sum32_3(this.h[1], C, Dh);
1242
+ this.h[1] = sum32_3(this.h[2], D, Eh);
1243
+ this.h[2] = sum32_3(this.h[3], E, Ah);
1244
+ this.h[3] = sum32_3(this.h[4], A, Bh);
1245
+ this.h[4] = sum32_3(this.h[0], B, Ch);
1246
+ this.h[0] = T;
1247
+ };
1248
+ RIPEMD160.prototype._digest = function digest(enc) {
1249
+ if (enc === "hex")
1250
+ return utils2.toHex32(this.h, "little");
1251
+ else
1252
+ return utils2.split32(this.h, "little");
1253
+ };
1254
+ function f(j, x, y, z) {
1255
+ if (j <= 15)
1256
+ return x ^ y ^ z;
1257
+ else if (j <= 31)
1258
+ return x & y | ~x & z;
1259
+ else if (j <= 47)
1260
+ return (x | ~y) ^ z;
1261
+ else if (j <= 63)
1262
+ return x & z | y & ~z;
1263
+ else
1264
+ return x ^ (y | ~z);
1265
+ }
1266
+ function K(j) {
1267
+ if (j <= 15)
1268
+ return 0;
1269
+ else if (j <= 31)
1270
+ return 1518500249;
1271
+ else if (j <= 47)
1272
+ return 1859775393;
1273
+ else if (j <= 63)
1274
+ return 2400959708;
1275
+ else
1276
+ return 2840853838;
1277
+ }
1278
+ function Kh(j) {
1279
+ if (j <= 15)
1280
+ return 1352829926;
1281
+ else if (j <= 31)
1282
+ return 1548603684;
1283
+ else if (j <= 47)
1284
+ return 1836072691;
1285
+ else if (j <= 63)
1286
+ return 2053994217;
1287
+ else
1288
+ return 0;
1289
+ }
1290
+ var r = [
1291
+ 0,
1292
+ 1,
1293
+ 2,
1294
+ 3,
1295
+ 4,
1296
+ 5,
1297
+ 6,
1298
+ 7,
1299
+ 8,
1300
+ 9,
1301
+ 10,
1302
+ 11,
1303
+ 12,
1304
+ 13,
1305
+ 14,
1306
+ 15,
1307
+ 7,
1308
+ 4,
1309
+ 13,
1310
+ 1,
1311
+ 10,
1312
+ 6,
1313
+ 15,
1314
+ 3,
1315
+ 12,
1316
+ 0,
1317
+ 9,
1318
+ 5,
1319
+ 2,
1320
+ 14,
1321
+ 11,
1322
+ 8,
1323
+ 3,
1324
+ 10,
1325
+ 14,
1326
+ 4,
1327
+ 9,
1328
+ 15,
1329
+ 8,
1330
+ 1,
1331
+ 2,
1332
+ 7,
1333
+ 0,
1334
+ 6,
1335
+ 13,
1336
+ 11,
1337
+ 5,
1338
+ 12,
1339
+ 1,
1340
+ 9,
1341
+ 11,
1342
+ 10,
1343
+ 0,
1344
+ 8,
1345
+ 12,
1346
+ 4,
1347
+ 13,
1348
+ 3,
1349
+ 7,
1350
+ 15,
1351
+ 14,
1352
+ 5,
1353
+ 6,
1354
+ 2,
1355
+ 4,
1356
+ 0,
1357
+ 5,
1358
+ 9,
1359
+ 7,
1360
+ 12,
1361
+ 2,
1362
+ 10,
1363
+ 14,
1364
+ 1,
1365
+ 3,
1366
+ 8,
1367
+ 11,
1368
+ 6,
1369
+ 15,
1370
+ 13
1371
+ ];
1372
+ var rh = [
1373
+ 5,
1374
+ 14,
1375
+ 7,
1376
+ 0,
1377
+ 9,
1378
+ 2,
1379
+ 11,
1380
+ 4,
1381
+ 13,
1382
+ 6,
1383
+ 15,
1384
+ 8,
1385
+ 1,
1386
+ 10,
1387
+ 3,
1388
+ 12,
1389
+ 6,
1390
+ 11,
1391
+ 3,
1392
+ 7,
1393
+ 0,
1394
+ 13,
1395
+ 5,
1396
+ 10,
1397
+ 14,
1398
+ 15,
1399
+ 8,
1400
+ 12,
1401
+ 4,
1402
+ 9,
1403
+ 1,
1404
+ 2,
1405
+ 15,
1406
+ 5,
1407
+ 1,
1408
+ 3,
1409
+ 7,
1410
+ 14,
1411
+ 6,
1412
+ 9,
1413
+ 11,
1414
+ 8,
1415
+ 12,
1416
+ 2,
1417
+ 10,
1418
+ 0,
1419
+ 4,
1420
+ 13,
1421
+ 8,
1422
+ 6,
1423
+ 4,
1424
+ 1,
1425
+ 3,
1426
+ 11,
1427
+ 15,
1428
+ 0,
1429
+ 5,
1430
+ 12,
1431
+ 2,
1432
+ 13,
1433
+ 9,
1434
+ 7,
1435
+ 10,
1436
+ 14,
1437
+ 12,
1438
+ 15,
1439
+ 10,
1440
+ 4,
1441
+ 1,
1442
+ 5,
1443
+ 8,
1444
+ 7,
1445
+ 6,
1446
+ 2,
1447
+ 13,
1448
+ 14,
1449
+ 0,
1450
+ 3,
1451
+ 9,
1452
+ 11
1453
+ ];
1454
+ var s = [
1455
+ 11,
1456
+ 14,
1457
+ 15,
1458
+ 12,
1459
+ 5,
1460
+ 8,
1461
+ 7,
1462
+ 9,
1463
+ 11,
1464
+ 13,
1465
+ 14,
1466
+ 15,
1467
+ 6,
1468
+ 7,
1469
+ 9,
1470
+ 8,
1471
+ 7,
1472
+ 6,
1473
+ 8,
1474
+ 13,
1475
+ 11,
1476
+ 9,
1477
+ 7,
1478
+ 15,
1479
+ 7,
1480
+ 12,
1481
+ 15,
1482
+ 9,
1483
+ 11,
1484
+ 7,
1485
+ 13,
1486
+ 12,
1487
+ 11,
1488
+ 13,
1489
+ 6,
1490
+ 7,
1491
+ 14,
1492
+ 9,
1493
+ 13,
1494
+ 15,
1495
+ 14,
1496
+ 8,
1497
+ 13,
1498
+ 6,
1499
+ 5,
1500
+ 12,
1501
+ 7,
1502
+ 5,
1503
+ 11,
1504
+ 12,
1505
+ 14,
1506
+ 15,
1507
+ 14,
1508
+ 15,
1509
+ 9,
1510
+ 8,
1511
+ 9,
1512
+ 14,
1513
+ 5,
1514
+ 6,
1515
+ 8,
1516
+ 6,
1517
+ 5,
1518
+ 12,
1519
+ 9,
1520
+ 15,
1521
+ 5,
1522
+ 11,
1523
+ 6,
1524
+ 8,
1525
+ 13,
1526
+ 12,
1527
+ 5,
1528
+ 12,
1529
+ 13,
1530
+ 14,
1531
+ 11,
1532
+ 8,
1533
+ 5,
1534
+ 6
1535
+ ];
1536
+ var sh = [
1537
+ 8,
1538
+ 9,
1539
+ 9,
1540
+ 11,
1541
+ 13,
1542
+ 15,
1543
+ 15,
1544
+ 5,
1545
+ 7,
1546
+ 7,
1547
+ 8,
1548
+ 11,
1549
+ 14,
1550
+ 14,
1551
+ 12,
1552
+ 6,
1553
+ 9,
1554
+ 13,
1555
+ 15,
1556
+ 7,
1557
+ 12,
1558
+ 8,
1559
+ 9,
1560
+ 11,
1561
+ 7,
1562
+ 7,
1563
+ 12,
1564
+ 7,
1565
+ 6,
1566
+ 15,
1567
+ 13,
1568
+ 11,
1569
+ 9,
1570
+ 7,
1571
+ 15,
1572
+ 11,
1573
+ 8,
1574
+ 6,
1575
+ 6,
1576
+ 14,
1577
+ 12,
1578
+ 13,
1579
+ 5,
1580
+ 14,
1581
+ 13,
1582
+ 13,
1583
+ 7,
1584
+ 5,
1585
+ 15,
1586
+ 5,
1587
+ 8,
1588
+ 11,
1589
+ 14,
1590
+ 14,
1591
+ 6,
1592
+ 14,
1593
+ 6,
1594
+ 9,
1595
+ 12,
1596
+ 9,
1597
+ 12,
1598
+ 5,
1599
+ 15,
1600
+ 8,
1601
+ 8,
1602
+ 5,
1603
+ 12,
1604
+ 9,
1605
+ 12,
1606
+ 5,
1607
+ 14,
1608
+ 6,
1609
+ 8,
1610
+ 13,
1611
+ 6,
1612
+ 5,
1613
+ 15,
1614
+ 13,
1615
+ 11,
1616
+ 11
1617
+ ];
1618
+ return ripemd;
1619
+ }
1620
+ var hmac;
1621
+ var hasRequiredHmac;
1622
+ function requireHmac() {
1623
+ if (hasRequiredHmac) return hmac;
1624
+ hasRequiredHmac = 1;
1625
+ var utils2 = requireUtils();
1626
+ var assert2 = requireMinimalisticAssert();
1627
+ function Hmac(hash2, key2, enc) {
1628
+ if (!(this instanceof Hmac))
1629
+ return new Hmac(hash2, key2, enc);
1630
+ this.Hash = hash2;
1631
+ this.blockSize = hash2.blockSize / 8;
1632
+ this.outSize = hash2.outSize / 8;
1633
+ this.inner = null;
1634
+ this.outer = null;
1635
+ this._init(utils2.toArray(key2, enc));
1636
+ }
1637
+ hmac = Hmac;
1638
+ Hmac.prototype._init = function init2(key2) {
1639
+ if (key2.length > this.blockSize)
1640
+ key2 = new this.Hash().update(key2).digest();
1641
+ assert2(key2.length <= this.blockSize);
1642
+ for (var i = key2.length; i < this.blockSize; i++)
1643
+ key2.push(0);
1644
+ for (i = 0; i < key2.length; i++)
1645
+ key2[i] ^= 54;
1646
+ this.inner = new this.Hash().update(key2);
1647
+ for (i = 0; i < key2.length; i++)
1648
+ key2[i] ^= 106;
1649
+ this.outer = new this.Hash().update(key2);
1650
+ };
1651
+ Hmac.prototype.update = function update2(msg, enc) {
1652
+ this.inner.update(msg, enc);
1653
+ return this;
1654
+ };
1655
+ Hmac.prototype.digest = function digest(enc) {
1656
+ this.outer.update(this.inner.digest());
1657
+ return this.outer.digest(enc);
1658
+ };
1659
+ return hmac;
1660
+ }
1661
+ var hasRequiredHash;
1662
+ function requireHash() {
1663
+ if (hasRequiredHash) return hash$1;
1664
+ hasRequiredHash = 1;
1665
+ (function(exports) {
1666
+ var hash2 = exports;
1667
+ hash2.utils = requireUtils();
1668
+ hash2.common = requireCommon$1();
1669
+ hash2.sha = requireSha();
1670
+ hash2.ripemd = requireRipemd();
1671
+ hash2.hmac = requireHmac();
1672
+ hash2.sha1 = hash2.sha.sha1;
1673
+ hash2.sha256 = hash2.sha.sha256;
1674
+ hash2.sha224 = hash2.sha.sha224;
1675
+ hash2.sha384 = hash2.sha.sha384;
1676
+ hash2.sha512 = hash2.sha.sha512;
1677
+ hash2.ripemd160 = hash2.ripemd.ripemd160;
1678
+ })(hash$1);
1679
+ return hash$1;
1680
+ }
1681
+ var hashExports = requireHash();
1682
+ const hash = /* @__PURE__ */ getDefaultExportFromCjs(hashExports);
1683
+ function createCommonjsModule(fn, basedir, module) {
1684
+ return module = {
1685
+ path: basedir,
1686
+ exports: {},
1687
+ require: function(path, base2) {
1688
+ return commonjsRequire(path, base2 === void 0 || base2 === null ? module.path : base2);
1689
+ }
1690
+ }, fn(module, module.exports), module.exports;
1691
+ }
1692
+ function commonjsRequire() {
1693
+ throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs");
1694
+ }
1695
+ var minimalisticAssert = assert;
1696
+ function assert(val, msg) {
1697
+ if (!val)
1698
+ throw new Error(msg || "Assertion failed");
1699
+ }
1700
+ assert.equal = function assertEqual(l, r, msg) {
1701
+ if (l != r)
1702
+ throw new Error(msg || "Assertion failed: " + l + " != " + r);
1703
+ };
1704
+ var utils_1 = createCommonjsModule(function(module, exports) {
1705
+ var utils2 = exports;
1706
+ function toArray(msg, enc) {
1707
+ if (Array.isArray(msg))
1708
+ return msg.slice();
1709
+ if (!msg)
1710
+ return [];
1711
+ var res = [];
1712
+ if (typeof msg !== "string") {
1713
+ for (var i = 0; i < msg.length; i++)
1714
+ res[i] = msg[i] | 0;
1715
+ return res;
1716
+ }
1717
+ if (enc === "hex") {
1718
+ msg = msg.replace(/[^a-z0-9]+/ig, "");
1719
+ if (msg.length % 2 !== 0)
1720
+ msg = "0" + msg;
1721
+ for (var i = 0; i < msg.length; i += 2)
1722
+ res.push(parseInt(msg[i] + msg[i + 1], 16));
1723
+ } else {
1724
+ for (var i = 0; i < msg.length; i++) {
1725
+ var c = msg.charCodeAt(i);
1726
+ var hi = c >> 8;
1727
+ var lo = c & 255;
1728
+ if (hi)
1729
+ res.push(hi, lo);
1730
+ else
1731
+ res.push(lo);
1732
+ }
1733
+ }
1734
+ return res;
1735
+ }
1736
+ utils2.toArray = toArray;
1737
+ function zero2(word) {
1738
+ if (word.length === 1)
1739
+ return "0" + word;
1740
+ else
1741
+ return word;
1742
+ }
1743
+ utils2.zero2 = zero2;
1744
+ function toHex(msg) {
1745
+ var res = "";
1746
+ for (var i = 0; i < msg.length; i++)
1747
+ res += zero2(msg[i].toString(16));
1748
+ return res;
1749
+ }
1750
+ utils2.toHex = toHex;
1751
+ utils2.encode = function encode3(arr, enc) {
1752
+ if (enc === "hex")
1753
+ return toHex(arr);
1754
+ else
1755
+ return arr;
1756
+ };
1757
+ });
1758
+ var utils_1$1 = createCommonjsModule(function(module, exports) {
1759
+ var utils2 = exports;
1760
+ utils2.assert = minimalisticAssert;
1761
+ utils2.toArray = utils_1.toArray;
1762
+ utils2.zero2 = utils_1.zero2;
1763
+ utils2.toHex = utils_1.toHex;
1764
+ utils2.encode = utils_1.encode;
1765
+ function getNAF2(num, w, bits) {
1766
+ var naf = new Array(Math.max(num.bitLength(), bits) + 1);
1767
+ var i;
1768
+ for (i = 0; i < naf.length; i += 1) {
1769
+ naf[i] = 0;
1770
+ }
1771
+ var ws = 1 << w + 1;
1772
+ var k = num.clone();
1773
+ for (i = 0; i < naf.length; i++) {
1774
+ var z;
1775
+ var mod = k.andln(ws - 1);
1776
+ if (k.isOdd()) {
1777
+ if (mod > (ws >> 1) - 1)
1778
+ z = (ws >> 1) - mod;
1779
+ else
1780
+ z = mod;
1781
+ k.isubn(z);
1782
+ } else {
1783
+ z = 0;
1784
+ }
1785
+ naf[i] = z;
1786
+ k.iushrn(1);
1787
+ }
1788
+ return naf;
1789
+ }
1790
+ utils2.getNAF = getNAF2;
1791
+ function getJSF2(k1, k2) {
1792
+ var jsf = [
1793
+ [],
1794
+ []
1795
+ ];
1796
+ k1 = k1.clone();
1797
+ k2 = k2.clone();
1798
+ var d1 = 0;
1799
+ var d2 = 0;
1800
+ var m8;
1801
+ while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
1802
+ var m14 = k1.andln(3) + d1 & 3;
1803
+ var m24 = k2.andln(3) + d2 & 3;
1804
+ if (m14 === 3)
1805
+ m14 = -1;
1806
+ if (m24 === 3)
1807
+ m24 = -1;
1808
+ var u1;
1809
+ if ((m14 & 1) === 0) {
1810
+ u1 = 0;
1811
+ } else {
1812
+ m8 = k1.andln(7) + d1 & 7;
1813
+ if ((m8 === 3 || m8 === 5) && m24 === 2)
1814
+ u1 = -m14;
1815
+ else
1816
+ u1 = m14;
1817
+ }
1818
+ jsf[0].push(u1);
1819
+ var u2;
1820
+ if ((m24 & 1) === 0) {
1821
+ u2 = 0;
1822
+ } else {
1823
+ m8 = k2.andln(7) + d2 & 7;
1824
+ if ((m8 === 3 || m8 === 5) && m14 === 2)
1825
+ u2 = -m24;
1826
+ else
1827
+ u2 = m24;
1828
+ }
1829
+ jsf[1].push(u2);
1830
+ if (2 * d1 === u1 + 1)
1831
+ d1 = 1 - d1;
1832
+ if (2 * d2 === u2 + 1)
1833
+ d2 = 1 - d2;
1834
+ k1.iushrn(1);
1835
+ k2.iushrn(1);
1836
+ }
1837
+ return jsf;
1838
+ }
1839
+ utils2.getJSF = getJSF2;
1840
+ function cachedProperty(obj, name, computer) {
1841
+ var key2 = "_" + name;
1842
+ obj.prototype[name] = function cachedProperty2() {
1843
+ return this[key2] !== void 0 ? this[key2] : this[key2] = computer.call(this);
1844
+ };
1845
+ }
1846
+ utils2.cachedProperty = cachedProperty;
1847
+ function parseBytes(bytes) {
1848
+ return typeof bytes === "string" ? utils2.toArray(bytes, "hex") : bytes;
1849
+ }
1850
+ utils2.parseBytes = parseBytes;
1851
+ function intFromLE(bytes) {
1852
+ return new BN(bytes, "hex", "le");
1853
+ }
1854
+ utils2.intFromLE = intFromLE;
1855
+ });
1856
+ var getNAF = utils_1$1.getNAF;
1857
+ var getJSF = utils_1$1.getJSF;
1858
+ var assert$1 = utils_1$1.assert;
1859
+ function BaseCurve(type, conf) {
1860
+ this.type = type;
1861
+ this.p = new BN(conf.p, 16);
1862
+ this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
1863
+ this.zero = new BN(0).toRed(this.red);
1864
+ this.one = new BN(1).toRed(this.red);
1865
+ this.two = new BN(2).toRed(this.red);
1866
+ this.n = conf.n && new BN(conf.n, 16);
1867
+ this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
1868
+ this._wnafT1 = new Array(4);
1869
+ this._wnafT2 = new Array(4);
1870
+ this._wnafT3 = new Array(4);
1871
+ this._wnafT4 = new Array(4);
1872
+ this._bitLength = this.n ? this.n.bitLength() : 0;
1873
+ var adjustCount = this.n && this.p.div(this.n);
1874
+ if (!adjustCount || adjustCount.cmpn(100) > 0) {
1875
+ this.redN = null;
1876
+ } else {
1877
+ this._maxwellTrick = true;
1878
+ this.redN = this.n.toRed(this.red);
1879
+ }
1880
+ }
1881
+ var base = BaseCurve;
1882
+ BaseCurve.prototype.point = function point() {
1883
+ throw new Error("Not implemented");
1884
+ };
1885
+ BaseCurve.prototype.validate = function validate() {
1886
+ throw new Error("Not implemented");
1887
+ };
1888
+ BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
1889
+ assert$1(p.precomputed);
1890
+ var doubles = p._getDoubles();
1891
+ var naf = getNAF(k, 1, this._bitLength);
1892
+ var I = (1 << doubles.step + 1) - (doubles.step % 2 === 0 ? 2 : 1);
1893
+ I /= 3;
1894
+ var repr = [];
1895
+ var j;
1896
+ var nafW;
1897
+ for (j = 0; j < naf.length; j += doubles.step) {
1898
+ nafW = 0;
1899
+ for (var l = j + doubles.step - 1; l >= j; l--)
1900
+ nafW = (nafW << 1) + naf[l];
1901
+ repr.push(nafW);
1902
+ }
1903
+ var a = this.jpoint(null, null, null);
1904
+ var b = this.jpoint(null, null, null);
1905
+ for (var i = I; i > 0; i--) {
1906
+ for (j = 0; j < repr.length; j++) {
1907
+ nafW = repr[j];
1908
+ if (nafW === i)
1909
+ b = b.mixedAdd(doubles.points[j]);
1910
+ else if (nafW === -i)
1911
+ b = b.mixedAdd(doubles.points[j].neg());
1912
+ }
1913
+ a = a.add(b);
1914
+ }
1915
+ return a.toP();
1916
+ };
1917
+ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
1918
+ var w = 4;
1919
+ var nafPoints = p._getNAFPoints(w);
1920
+ w = nafPoints.wnd;
1921
+ var wnd = nafPoints.points;
1922
+ var naf = getNAF(k, w, this._bitLength);
1923
+ var acc = this.jpoint(null, null, null);
1924
+ for (var i = naf.length - 1; i >= 0; i--) {
1925
+ for (var l = 0; i >= 0 && naf[i] === 0; i--)
1926
+ l++;
1927
+ if (i >= 0)
1928
+ l++;
1929
+ acc = acc.dblp(l);
1930
+ if (i < 0)
1931
+ break;
1932
+ var z = naf[i];
1933
+ assert$1(z !== 0);
1934
+ if (p.type === "affine") {
1935
+ if (z > 0)
1936
+ acc = acc.mixedAdd(wnd[z - 1 >> 1]);
1937
+ else
1938
+ acc = acc.mixedAdd(wnd[-z - 1 >> 1].neg());
1939
+ } else {
1940
+ if (z > 0)
1941
+ acc = acc.add(wnd[z - 1 >> 1]);
1942
+ else
1943
+ acc = acc.add(wnd[-z - 1 >> 1].neg());
1944
+ }
1945
+ }
1946
+ return p.type === "affine" ? acc.toP() : acc;
1947
+ };
1948
+ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, points, coeffs, len, jacobianResult) {
1949
+ var wndWidth = this._wnafT1;
1950
+ var wnd = this._wnafT2;
1951
+ var naf = this._wnafT3;
1952
+ var max = 0;
1953
+ var i;
1954
+ var j;
1955
+ var p;
1956
+ for (i = 0; i < len; i++) {
1957
+ p = points[i];
1958
+ var nafPoints = p._getNAFPoints(defW);
1959
+ wndWidth[i] = nafPoints.wnd;
1960
+ wnd[i] = nafPoints.points;
1961
+ }
1962
+ for (i = len - 1; i >= 1; i -= 2) {
1963
+ var a = i - 1;
1964
+ var b = i;
1965
+ if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
1966
+ naf[a] = getNAF(coeffs[a], wndWidth[a], this._bitLength);
1967
+ naf[b] = getNAF(coeffs[b], wndWidth[b], this._bitLength);
1968
+ max = Math.max(naf[a].length, max);
1969
+ max = Math.max(naf[b].length, max);
1970
+ continue;
1971
+ }
1972
+ var comb = [
1973
+ points[a],
1974
+ /* 1 */
1975
+ null,
1976
+ /* 3 */
1977
+ null,
1978
+ /* 5 */
1979
+ points[b]
1980
+ /* 7 */
1981
+ ];
1982
+ if (points[a].y.cmp(points[b].y) === 0) {
1983
+ comb[1] = points[a].add(points[b]);
1984
+ comb[2] = points[a].toJ().mixedAdd(points[b].neg());
1985
+ } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
1986
+ comb[1] = points[a].toJ().mixedAdd(points[b]);
1987
+ comb[2] = points[a].add(points[b].neg());
1988
+ } else {
1989
+ comb[1] = points[a].toJ().mixedAdd(points[b]);
1990
+ comb[2] = points[a].toJ().mixedAdd(points[b].neg());
1991
+ }
1992
+ var index2 = [
1993
+ -3,
1994
+ /* -1 -1 */
1995
+ -1,
1996
+ /* -1 0 */
1997
+ -5,
1998
+ /* -1 1 */
1999
+ -7,
2000
+ /* 0 -1 */
2001
+ 0,
2002
+ /* 0 0 */
2003
+ 7,
2004
+ /* 0 1 */
2005
+ 5,
2006
+ /* 1 -1 */
2007
+ 1,
2008
+ /* 1 0 */
2009
+ 3
2010
+ /* 1 1 */
2011
+ ];
2012
+ var jsf = getJSF(coeffs[a], coeffs[b]);
2013
+ max = Math.max(jsf[0].length, max);
2014
+ naf[a] = new Array(max);
2015
+ naf[b] = new Array(max);
2016
+ for (j = 0; j < max; j++) {
2017
+ var ja = jsf[0][j] | 0;
2018
+ var jb = jsf[1][j] | 0;
2019
+ naf[a][j] = index2[(ja + 1) * 3 + (jb + 1)];
2020
+ naf[b][j] = 0;
2021
+ wnd[a] = comb;
2022
+ }
2023
+ }
2024
+ var acc = this.jpoint(null, null, null);
2025
+ var tmp = this._wnafT4;
2026
+ for (i = max; i >= 0; i--) {
2027
+ var k = 0;
2028
+ while (i >= 0) {
2029
+ var zero = true;
2030
+ for (j = 0; j < len; j++) {
2031
+ tmp[j] = naf[j][i] | 0;
2032
+ if (tmp[j] !== 0)
2033
+ zero = false;
2034
+ }
2035
+ if (!zero)
2036
+ break;
2037
+ k++;
2038
+ i--;
2039
+ }
2040
+ if (i >= 0)
2041
+ k++;
2042
+ acc = acc.dblp(k);
2043
+ if (i < 0)
2044
+ break;
2045
+ for (j = 0; j < len; j++) {
2046
+ var z = tmp[j];
2047
+ if (z === 0)
2048
+ continue;
2049
+ else if (z > 0)
2050
+ p = wnd[j][z - 1 >> 1];
2051
+ else if (z < 0)
2052
+ p = wnd[j][-z - 1 >> 1].neg();
2053
+ if (p.type === "affine")
2054
+ acc = acc.mixedAdd(p);
2055
+ else
2056
+ acc = acc.add(p);
2057
+ }
2058
+ }
2059
+ for (i = 0; i < len; i++)
2060
+ wnd[i] = null;
2061
+ if (jacobianResult)
2062
+ return acc;
2063
+ else
2064
+ return acc.toP();
2065
+ };
2066
+ function BasePoint(curve, type) {
2067
+ this.curve = curve;
2068
+ this.type = type;
2069
+ this.precomputed = null;
2070
+ }
2071
+ BaseCurve.BasePoint = BasePoint;
2072
+ BasePoint.prototype.eq = function eq() {
2073
+ throw new Error("Not implemented");
2074
+ };
2075
+ BasePoint.prototype.validate = function validate2() {
2076
+ return this.curve.validate(this);
2077
+ };
2078
+ BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
2079
+ bytes = utils_1$1.toArray(bytes, enc);
2080
+ var len = this.p.byteLength();
2081
+ if ((bytes[0] === 4 || bytes[0] === 6 || bytes[0] === 7) && bytes.length - 1 === 2 * len) {
2082
+ if (bytes[0] === 6)
2083
+ assert$1(bytes[bytes.length - 1] % 2 === 0);
2084
+ else if (bytes[0] === 7)
2085
+ assert$1(bytes[bytes.length - 1] % 2 === 1);
2086
+ var res = this.point(
2087
+ bytes.slice(1, 1 + len),
2088
+ bytes.slice(1 + len, 1 + 2 * len)
2089
+ );
2090
+ return res;
2091
+ } else if ((bytes[0] === 2 || bytes[0] === 3) && bytes.length - 1 === len) {
2092
+ return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 3);
2093
+ }
2094
+ throw new Error("Unknown point format");
2095
+ };
2096
+ BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
2097
+ return this.encode(enc, true);
2098
+ };
2099
+ BasePoint.prototype._encode = function _encode(compact) {
2100
+ var len = this.curve.p.byteLength();
2101
+ var x = this.getX().toArray("be", len);
2102
+ if (compact)
2103
+ return [this.getY().isEven() ? 2 : 3].concat(x);
2104
+ return [4].concat(x, this.getY().toArray("be", len));
2105
+ };
2106
+ BasePoint.prototype.encode = function encode2(enc, compact) {
2107
+ return utils_1$1.encode(this._encode(compact), enc);
2108
+ };
2109
+ BasePoint.prototype.precompute = function precompute(power) {
2110
+ if (this.precomputed)
2111
+ return this;
2112
+ var precomputed = {
2113
+ doubles: null,
2114
+ naf: null,
2115
+ beta: null
2116
+ };
2117
+ precomputed.naf = this._getNAFPoints(8);
2118
+ precomputed.doubles = this._getDoubles(4, power);
2119
+ precomputed.beta = this._getBeta();
2120
+ this.precomputed = precomputed;
2121
+ return this;
2122
+ };
2123
+ BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
2124
+ if (!this.precomputed)
2125
+ return false;
2126
+ var doubles = this.precomputed.doubles;
2127
+ if (!doubles)
2128
+ return false;
2129
+ return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
2130
+ };
2131
+ BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
2132
+ if (this.precomputed && this.precomputed.doubles)
2133
+ return this.precomputed.doubles;
2134
+ var doubles = [this];
2135
+ var acc = this;
2136
+ for (var i = 0; i < power; i += step) {
2137
+ for (var j = 0; j < step; j++)
2138
+ acc = acc.dbl();
2139
+ doubles.push(acc);
2140
+ }
2141
+ return {
2142
+ step,
2143
+ points: doubles
2144
+ };
2145
+ };
2146
+ BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
2147
+ if (this.precomputed && this.precomputed.naf)
2148
+ return this.precomputed.naf;
2149
+ var res = [this];
2150
+ var max = (1 << wnd) - 1;
2151
+ var dbl3 = max === 1 ? null : this.dbl();
2152
+ for (var i = 1; i < max; i++)
2153
+ res[i] = res[i - 1].add(dbl3);
2154
+ return {
2155
+ wnd,
2156
+ points: res
2157
+ };
2158
+ };
2159
+ BasePoint.prototype._getBeta = function _getBeta() {
2160
+ return null;
2161
+ };
2162
+ BasePoint.prototype.dblp = function dblp(k) {
2163
+ var r = this;
2164
+ for (var i = 0; i < k; i++)
2165
+ r = r.dbl();
2166
+ return r;
2167
+ };
2168
+ var inherits_browser = createCommonjsModule(function(module) {
2169
+ if (typeof Object.create === "function") {
2170
+ module.exports = function inherits(ctor, superCtor) {
2171
+ if (superCtor) {
2172
+ ctor.super_ = superCtor;
2173
+ ctor.prototype = Object.create(superCtor.prototype, {
2174
+ constructor: {
2175
+ value: ctor,
2176
+ enumerable: false,
2177
+ writable: true,
2178
+ configurable: true
2179
+ }
2180
+ });
2181
+ }
2182
+ };
2183
+ } else {
2184
+ module.exports = function inherits(ctor, superCtor) {
2185
+ if (superCtor) {
2186
+ ctor.super_ = superCtor;
2187
+ var TempCtor = function() {
2188
+ };
2189
+ TempCtor.prototype = superCtor.prototype;
2190
+ ctor.prototype = new TempCtor();
2191
+ ctor.prototype.constructor = ctor;
2192
+ }
2193
+ };
2194
+ }
2195
+ });
2196
+ var assert$2 = utils_1$1.assert;
2197
+ function ShortCurve(conf) {
2198
+ base.call(this, "short", conf);
2199
+ this.a = new BN(conf.a, 16).toRed(this.red);
2200
+ this.b = new BN(conf.b, 16).toRed(this.red);
2201
+ this.tinv = this.two.redInvm();
2202
+ this.zeroA = this.a.fromRed().cmpn(0) === 0;
2203
+ this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
2204
+ this.endo = this._getEndomorphism(conf);
2205
+ this._endoWnafT1 = new Array(4);
2206
+ this._endoWnafT2 = new Array(4);
2207
+ }
2208
+ inherits_browser(ShortCurve, base);
2209
+ var short_1 = ShortCurve;
2210
+ ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
2211
+ if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1)
2212
+ return;
2213
+ var beta;
2214
+ var lambda;
2215
+ if (conf.beta) {
2216
+ beta = new BN(conf.beta, 16).toRed(this.red);
2217
+ } else {
2218
+ var betas = this._getEndoRoots(this.p);
2219
+ beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
2220
+ beta = beta.toRed(this.red);
2221
+ }
2222
+ if (conf.lambda) {
2223
+ lambda = new BN(conf.lambda, 16);
2224
+ } else {
2225
+ var lambdas = this._getEndoRoots(this.n);
2226
+ if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
2227
+ lambda = lambdas[0];
2228
+ } else {
2229
+ lambda = lambdas[1];
2230
+ assert$2(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
2231
+ }
2232
+ }
2233
+ var basis;
2234
+ if (conf.basis) {
2235
+ basis = conf.basis.map(function(vec) {
2236
+ return {
2237
+ a: new BN(vec.a, 16),
2238
+ b: new BN(vec.b, 16)
2239
+ };
2240
+ });
2241
+ } else {
2242
+ basis = this._getEndoBasis(lambda);
2243
+ }
2244
+ return {
2245
+ beta,
2246
+ lambda,
2247
+ basis
2248
+ };
2249
+ };
2250
+ ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
2251
+ var red = num === this.p ? this.red : BN.mont(num);
2252
+ var tinv = new BN(2).toRed(red).redInvm();
2253
+ var ntinv = tinv.redNeg();
2254
+ var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
2255
+ var l1 = ntinv.redAdd(s).fromRed();
2256
+ var l2 = ntinv.redSub(s).fromRed();
2257
+ return [l1, l2];
2258
+ };
2259
+ ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
2260
+ var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
2261
+ var u = lambda;
2262
+ var v = this.n.clone();
2263
+ var x1 = new BN(1);
2264
+ var y1 = new BN(0);
2265
+ var x2 = new BN(0);
2266
+ var y2 = new BN(1);
2267
+ var a0;
2268
+ var b0;
2269
+ var a1;
2270
+ var b1;
2271
+ var a2;
2272
+ var b2;
2273
+ var prevR;
2274
+ var i = 0;
2275
+ var r;
2276
+ var x;
2277
+ while (u.cmpn(0) !== 0) {
2278
+ var q = v.div(u);
2279
+ r = v.sub(q.mul(u));
2280
+ x = x2.sub(q.mul(x1));
2281
+ var y = y2.sub(q.mul(y1));
2282
+ if (!a1 && r.cmp(aprxSqrt) < 0) {
2283
+ a0 = prevR.neg();
2284
+ b0 = x1;
2285
+ a1 = r.neg();
2286
+ b1 = x;
2287
+ } else if (a1 && ++i === 2) {
2288
+ break;
2289
+ }
2290
+ prevR = r;
2291
+ v = u;
2292
+ u = r;
2293
+ x2 = x1;
2294
+ x1 = x;
2295
+ y2 = y1;
2296
+ y1 = y;
2297
+ }
2298
+ a2 = r.neg();
2299
+ b2 = x;
2300
+ var len1 = a1.sqr().add(b1.sqr());
2301
+ var len2 = a2.sqr().add(b2.sqr());
2302
+ if (len2.cmp(len1) >= 0) {
2303
+ a2 = a0;
2304
+ b2 = b0;
2305
+ }
2306
+ if (a1.negative) {
2307
+ a1 = a1.neg();
2308
+ b1 = b1.neg();
2309
+ }
2310
+ if (a2.negative) {
2311
+ a2 = a2.neg();
2312
+ b2 = b2.neg();
2313
+ }
2314
+ return [
2315
+ { a: a1, b: b1 },
2316
+ { a: a2, b: b2 }
2317
+ ];
2318
+ };
2319
+ ShortCurve.prototype._endoSplit = function _endoSplit(k) {
2320
+ var basis = this.endo.basis;
2321
+ var v1 = basis[0];
2322
+ var v2 = basis[1];
2323
+ var c1 = v2.b.mul(k).divRound(this.n);
2324
+ var c2 = v1.b.neg().mul(k).divRound(this.n);
2325
+ var p1 = c1.mul(v1.a);
2326
+ var p2 = c2.mul(v2.a);
2327
+ var q1 = c1.mul(v1.b);
2328
+ var q2 = c2.mul(v2.b);
2329
+ var k1 = k.sub(p1).sub(p2);
2330
+ var k2 = q1.add(q2).neg();
2331
+ return { k1, k2 };
2332
+ };
2333
+ ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
2334
+ x = new BN(x, 16);
2335
+ if (!x.red)
2336
+ x = x.toRed(this.red);
2337
+ var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
2338
+ var y = y2.redSqrt();
2339
+ if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
2340
+ throw new Error("invalid point");
2341
+ var isOdd = y.fromRed().isOdd();
2342
+ if (odd && !isOdd || !odd && isOdd)
2343
+ y = y.redNeg();
2344
+ return this.point(x, y);
2345
+ };
2346
+ ShortCurve.prototype.validate = function validate3(point3) {
2347
+ if (point3.inf)
2348
+ return true;
2349
+ var x = point3.x;
2350
+ var y = point3.y;
2351
+ var ax = this.a.redMul(x);
2352
+ var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
2353
+ return y.redSqr().redISub(rhs).cmpn(0) === 0;
2354
+ };
2355
+ ShortCurve.prototype._endoWnafMulAdd = function _endoWnafMulAdd(points, coeffs, jacobianResult) {
2356
+ var npoints = this._endoWnafT1;
2357
+ var ncoeffs = this._endoWnafT2;
2358
+ for (var i = 0; i < points.length; i++) {
2359
+ var split = this._endoSplit(coeffs[i]);
2360
+ var p = points[i];
2361
+ var beta = p._getBeta();
2362
+ if (split.k1.negative) {
2363
+ split.k1.ineg();
2364
+ p = p.neg(true);
2365
+ }
2366
+ if (split.k2.negative) {
2367
+ split.k2.ineg();
2368
+ beta = beta.neg(true);
2369
+ }
2370
+ npoints[i * 2] = p;
2371
+ npoints[i * 2 + 1] = beta;
2372
+ ncoeffs[i * 2] = split.k1;
2373
+ ncoeffs[i * 2 + 1] = split.k2;
2374
+ }
2375
+ var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult);
2376
+ for (var j = 0; j < i * 2; j++) {
2377
+ npoints[j] = null;
2378
+ ncoeffs[j] = null;
2379
+ }
2380
+ return res;
2381
+ };
2382
+ function Point(curve, x, y, isRed) {
2383
+ base.BasePoint.call(this, curve, "affine");
2384
+ if (x === null && y === null) {
2385
+ this.x = null;
2386
+ this.y = null;
2387
+ this.inf = true;
2388
+ } else {
2389
+ this.x = new BN(x, 16);
2390
+ this.y = new BN(y, 16);
2391
+ if (isRed) {
2392
+ this.x.forceRed(this.curve.red);
2393
+ this.y.forceRed(this.curve.red);
2394
+ }
2395
+ if (!this.x.red)
2396
+ this.x = this.x.toRed(this.curve.red);
2397
+ if (!this.y.red)
2398
+ this.y = this.y.toRed(this.curve.red);
2399
+ this.inf = false;
2400
+ }
2401
+ }
2402
+ inherits_browser(Point, base.BasePoint);
2403
+ ShortCurve.prototype.point = function point2(x, y, isRed) {
2404
+ return new Point(this, x, y, isRed);
2405
+ };
2406
+ ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
2407
+ return Point.fromJSON(this, obj, red);
2408
+ };
2409
+ Point.prototype._getBeta = function _getBeta2() {
2410
+ if (!this.curve.endo)
2411
+ return;
2412
+ var pre = this.precomputed;
2413
+ if (pre && pre.beta)
2414
+ return pre.beta;
2415
+ var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
2416
+ if (pre) {
2417
+ var curve = this.curve;
2418
+ var endoMul = function(p) {
2419
+ return curve.point(p.x.redMul(curve.endo.beta), p.y);
2420
+ };
2421
+ pre.beta = beta;
2422
+ beta.precomputed = {
2423
+ beta: null,
2424
+ naf: pre.naf && {
2425
+ wnd: pre.naf.wnd,
2426
+ points: pre.naf.points.map(endoMul)
2427
+ },
2428
+ doubles: pre.doubles && {
2429
+ step: pre.doubles.step,
2430
+ points: pre.doubles.points.map(endoMul)
2431
+ }
2432
+ };
2433
+ }
2434
+ return beta;
2435
+ };
2436
+ Point.prototype.toJSON = function toJSON() {
2437
+ if (!this.precomputed)
2438
+ return [this.x, this.y];
2439
+ return [this.x, this.y, this.precomputed && {
2440
+ doubles: this.precomputed.doubles && {
2441
+ step: this.precomputed.doubles.step,
2442
+ points: this.precomputed.doubles.points.slice(1)
2443
+ },
2444
+ naf: this.precomputed.naf && {
2445
+ wnd: this.precomputed.naf.wnd,
2446
+ points: this.precomputed.naf.points.slice(1)
2447
+ }
2448
+ }];
2449
+ };
2450
+ Point.fromJSON = function fromJSON(curve, obj, red) {
2451
+ if (typeof obj === "string")
2452
+ obj = JSON.parse(obj);
2453
+ var res = curve.point(obj[0], obj[1], red);
2454
+ if (!obj[2])
2455
+ return res;
2456
+ function obj2point(obj2) {
2457
+ return curve.point(obj2[0], obj2[1], red);
2458
+ }
2459
+ var pre = obj[2];
2460
+ res.precomputed = {
2461
+ beta: null,
2462
+ doubles: pre.doubles && {
2463
+ step: pre.doubles.step,
2464
+ points: [res].concat(pre.doubles.points.map(obj2point))
2465
+ },
2466
+ naf: pre.naf && {
2467
+ wnd: pre.naf.wnd,
2468
+ points: [res].concat(pre.naf.points.map(obj2point))
2469
+ }
2470
+ };
2471
+ return res;
2472
+ };
2473
+ Point.prototype.inspect = function inspect() {
2474
+ if (this.isInfinity())
2475
+ return "<EC Point Infinity>";
2476
+ return "<EC Point x: " + this.x.fromRed().toString(16, 2) + " y: " + this.y.fromRed().toString(16, 2) + ">";
2477
+ };
2478
+ Point.prototype.isInfinity = function isInfinity() {
2479
+ return this.inf;
2480
+ };
2481
+ Point.prototype.add = function add(p) {
2482
+ if (this.inf)
2483
+ return p;
2484
+ if (p.inf)
2485
+ return this;
2486
+ if (this.eq(p))
2487
+ return this.dbl();
2488
+ if (this.neg().eq(p))
2489
+ return this.curve.point(null, null);
2490
+ if (this.x.cmp(p.x) === 0)
2491
+ return this.curve.point(null, null);
2492
+ var c = this.y.redSub(p.y);
2493
+ if (c.cmpn(0) !== 0)
2494
+ c = c.redMul(this.x.redSub(p.x).redInvm());
2495
+ var nx = c.redSqr().redISub(this.x).redISub(p.x);
2496
+ var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
2497
+ return this.curve.point(nx, ny);
2498
+ };
2499
+ Point.prototype.dbl = function dbl() {
2500
+ if (this.inf)
2501
+ return this;
2502
+ var ys1 = this.y.redAdd(this.y);
2503
+ if (ys1.cmpn(0) === 0)
2504
+ return this.curve.point(null, null);
2505
+ var a = this.curve.a;
2506
+ var x2 = this.x.redSqr();
2507
+ var dyinv = ys1.redInvm();
2508
+ var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
2509
+ var nx = c.redSqr().redISub(this.x.redAdd(this.x));
2510
+ var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
2511
+ return this.curve.point(nx, ny);
2512
+ };
2513
+ Point.prototype.getX = function getX() {
2514
+ return this.x.fromRed();
2515
+ };
2516
+ Point.prototype.getY = function getY() {
2517
+ return this.y.fromRed();
2518
+ };
2519
+ Point.prototype.mul = function mul(k) {
2520
+ k = new BN(k, 16);
2521
+ if (this.isInfinity())
2522
+ return this;
2523
+ else if (this._hasDoubles(k))
2524
+ return this.curve._fixedNafMul(this, k);
2525
+ else if (this.curve.endo)
2526
+ return this.curve._endoWnafMulAdd([this], [k]);
2527
+ else
2528
+ return this.curve._wnafMul(this, k);
2529
+ };
2530
+ Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
2531
+ var points = [this, p2];
2532
+ var coeffs = [k1, k2];
2533
+ if (this.curve.endo)
2534
+ return this.curve._endoWnafMulAdd(points, coeffs);
2535
+ else
2536
+ return this.curve._wnafMulAdd(1, points, coeffs, 2);
2537
+ };
2538
+ Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
2539
+ var points = [this, p2];
2540
+ var coeffs = [k1, k2];
2541
+ if (this.curve.endo)
2542
+ return this.curve._endoWnafMulAdd(points, coeffs, true);
2543
+ else
2544
+ return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
2545
+ };
2546
+ Point.prototype.eq = function eq2(p) {
2547
+ return this === p || this.inf === p.inf && (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
2548
+ };
2549
+ Point.prototype.neg = function neg(_precompute) {
2550
+ if (this.inf)
2551
+ return this;
2552
+ var res = this.curve.point(this.x, this.y.redNeg());
2553
+ if (_precompute && this.precomputed) {
2554
+ var pre = this.precomputed;
2555
+ var negate = function(p) {
2556
+ return p.neg();
2557
+ };
2558
+ res.precomputed = {
2559
+ naf: pre.naf && {
2560
+ wnd: pre.naf.wnd,
2561
+ points: pre.naf.points.map(negate)
2562
+ },
2563
+ doubles: pre.doubles && {
2564
+ step: pre.doubles.step,
2565
+ points: pre.doubles.points.map(negate)
2566
+ }
2567
+ };
2568
+ }
2569
+ return res;
2570
+ };
2571
+ Point.prototype.toJ = function toJ() {
2572
+ if (this.inf)
2573
+ return this.curve.jpoint(null, null, null);
2574
+ var res = this.curve.jpoint(this.x, this.y, this.curve.one);
2575
+ return res;
2576
+ };
2577
+ function JPoint(curve, x, y, z) {
2578
+ base.BasePoint.call(this, curve, "jacobian");
2579
+ if (x === null && y === null && z === null) {
2580
+ this.x = this.curve.one;
2581
+ this.y = this.curve.one;
2582
+ this.z = new BN(0);
2583
+ } else {
2584
+ this.x = new BN(x, 16);
2585
+ this.y = new BN(y, 16);
2586
+ this.z = new BN(z, 16);
2587
+ }
2588
+ if (!this.x.red)
2589
+ this.x = this.x.toRed(this.curve.red);
2590
+ if (!this.y.red)
2591
+ this.y = this.y.toRed(this.curve.red);
2592
+ if (!this.z.red)
2593
+ this.z = this.z.toRed(this.curve.red);
2594
+ this.zOne = this.z === this.curve.one;
2595
+ }
2596
+ inherits_browser(JPoint, base.BasePoint);
2597
+ ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
2598
+ return new JPoint(this, x, y, z);
2599
+ };
2600
+ JPoint.prototype.toP = function toP() {
2601
+ if (this.isInfinity())
2602
+ return this.curve.point(null, null);
2603
+ var zinv = this.z.redInvm();
2604
+ var zinv2 = zinv.redSqr();
2605
+ var ax = this.x.redMul(zinv2);
2606
+ var ay = this.y.redMul(zinv2).redMul(zinv);
2607
+ return this.curve.point(ax, ay);
2608
+ };
2609
+ JPoint.prototype.neg = function neg2() {
2610
+ return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
2611
+ };
2612
+ JPoint.prototype.add = function add2(p) {
2613
+ if (this.isInfinity())
2614
+ return p;
2615
+ if (p.isInfinity())
2616
+ return this;
2617
+ var pz2 = p.z.redSqr();
2618
+ var z2 = this.z.redSqr();
2619
+ var u1 = this.x.redMul(pz2);
2620
+ var u2 = p.x.redMul(z2);
2621
+ var s1 = this.y.redMul(pz2.redMul(p.z));
2622
+ var s2 = p.y.redMul(z2.redMul(this.z));
2623
+ var h = u1.redSub(u2);
2624
+ var r = s1.redSub(s2);
2625
+ if (h.cmpn(0) === 0) {
2626
+ if (r.cmpn(0) !== 0)
2627
+ return this.curve.jpoint(null, null, null);
2628
+ else
2629
+ return this.dbl();
2630
+ }
2631
+ var h2 = h.redSqr();
2632
+ var h3 = h2.redMul(h);
2633
+ var v = u1.redMul(h2);
2634
+ var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
2635
+ var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
2636
+ var nz = this.z.redMul(p.z).redMul(h);
2637
+ return this.curve.jpoint(nx, ny, nz);
2638
+ };
2639
+ JPoint.prototype.mixedAdd = function mixedAdd(p) {
2640
+ if (this.isInfinity())
2641
+ return p.toJ();
2642
+ if (p.isInfinity())
2643
+ return this;
2644
+ var z2 = this.z.redSqr();
2645
+ var u1 = this.x;
2646
+ var u2 = p.x.redMul(z2);
2647
+ var s1 = this.y;
2648
+ var s2 = p.y.redMul(z2).redMul(this.z);
2649
+ var h = u1.redSub(u2);
2650
+ var r = s1.redSub(s2);
2651
+ if (h.cmpn(0) === 0) {
2652
+ if (r.cmpn(0) !== 0)
2653
+ return this.curve.jpoint(null, null, null);
2654
+ else
2655
+ return this.dbl();
2656
+ }
2657
+ var h2 = h.redSqr();
2658
+ var h3 = h2.redMul(h);
2659
+ var v = u1.redMul(h2);
2660
+ var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
2661
+ var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
2662
+ var nz = this.z.redMul(h);
2663
+ return this.curve.jpoint(nx, ny, nz);
2664
+ };
2665
+ JPoint.prototype.dblp = function dblp2(pow) {
2666
+ if (pow === 0)
2667
+ return this;
2668
+ if (this.isInfinity())
2669
+ return this;
2670
+ if (!pow)
2671
+ return this.dbl();
2672
+ var i;
2673
+ if (this.curve.zeroA || this.curve.threeA) {
2674
+ var r = this;
2675
+ for (i = 0; i < pow; i++)
2676
+ r = r.dbl();
2677
+ return r;
2678
+ }
2679
+ var a = this.curve.a;
2680
+ var tinv = this.curve.tinv;
2681
+ var jx = this.x;
2682
+ var jy = this.y;
2683
+ var jz = this.z;
2684
+ var jz4 = jz.redSqr().redSqr();
2685
+ var jyd = jy.redAdd(jy);
2686
+ for (i = 0; i < pow; i++) {
2687
+ var jx2 = jx.redSqr();
2688
+ var jyd2 = jyd.redSqr();
2689
+ var jyd4 = jyd2.redSqr();
2690
+ var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
2691
+ var t1 = jx.redMul(jyd2);
2692
+ var nx = c.redSqr().redISub(t1.redAdd(t1));
2693
+ var t2 = t1.redISub(nx);
2694
+ var dny = c.redMul(t2);
2695
+ dny = dny.redIAdd(dny).redISub(jyd4);
2696
+ var nz = jyd.redMul(jz);
2697
+ if (i + 1 < pow)
2698
+ jz4 = jz4.redMul(jyd4);
2699
+ jx = nx;
2700
+ jz = nz;
2701
+ jyd = dny;
2702
+ }
2703
+ return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
2704
+ };
2705
+ JPoint.prototype.dbl = function dbl2() {
2706
+ if (this.isInfinity())
2707
+ return this;
2708
+ if (this.curve.zeroA)
2709
+ return this._zeroDbl();
2710
+ else if (this.curve.threeA)
2711
+ return this._threeDbl();
2712
+ else
2713
+ return this._dbl();
2714
+ };
2715
+ JPoint.prototype._zeroDbl = function _zeroDbl() {
2716
+ var nx;
2717
+ var ny;
2718
+ var nz;
2719
+ if (this.zOne) {
2720
+ var xx = this.x.redSqr();
2721
+ var yy = this.y.redSqr();
2722
+ var yyyy = yy.redSqr();
2723
+ var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
2724
+ s = s.redIAdd(s);
2725
+ var m = xx.redAdd(xx).redIAdd(xx);
2726
+ var t = m.redSqr().redISub(s).redISub(s);
2727
+ var yyyy8 = yyyy.redIAdd(yyyy);
2728
+ yyyy8 = yyyy8.redIAdd(yyyy8);
2729
+ yyyy8 = yyyy8.redIAdd(yyyy8);
2730
+ nx = t;
2731
+ ny = m.redMul(s.redISub(t)).redISub(yyyy8);
2732
+ nz = this.y.redAdd(this.y);
2733
+ } else {
2734
+ var a = this.x.redSqr();
2735
+ var b = this.y.redSqr();
2736
+ var c = b.redSqr();
2737
+ var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
2738
+ d = d.redIAdd(d);
2739
+ var e = a.redAdd(a).redIAdd(a);
2740
+ var f = e.redSqr();
2741
+ var c8 = c.redIAdd(c);
2742
+ c8 = c8.redIAdd(c8);
2743
+ c8 = c8.redIAdd(c8);
2744
+ nx = f.redISub(d).redISub(d);
2745
+ ny = e.redMul(d.redISub(nx)).redISub(c8);
2746
+ nz = this.y.redMul(this.z);
2747
+ nz = nz.redIAdd(nz);
2748
+ }
2749
+ return this.curve.jpoint(nx, ny, nz);
2750
+ };
2751
+ JPoint.prototype._threeDbl = function _threeDbl() {
2752
+ var nx;
2753
+ var ny;
2754
+ var nz;
2755
+ if (this.zOne) {
2756
+ var xx = this.x.redSqr();
2757
+ var yy = this.y.redSqr();
2758
+ var yyyy = yy.redSqr();
2759
+ var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
2760
+ s = s.redIAdd(s);
2761
+ var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
2762
+ var t = m.redSqr().redISub(s).redISub(s);
2763
+ nx = t;
2764
+ var yyyy8 = yyyy.redIAdd(yyyy);
2765
+ yyyy8 = yyyy8.redIAdd(yyyy8);
2766
+ yyyy8 = yyyy8.redIAdd(yyyy8);
2767
+ ny = m.redMul(s.redISub(t)).redISub(yyyy8);
2768
+ nz = this.y.redAdd(this.y);
2769
+ } else {
2770
+ var delta = this.z.redSqr();
2771
+ var gamma = this.y.redSqr();
2772
+ var beta = this.x.redMul(gamma);
2773
+ var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
2774
+ alpha = alpha.redAdd(alpha).redIAdd(alpha);
2775
+ var beta4 = beta.redIAdd(beta);
2776
+ beta4 = beta4.redIAdd(beta4);
2777
+ var beta8 = beta4.redAdd(beta4);
2778
+ nx = alpha.redSqr().redISub(beta8);
2779
+ nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
2780
+ var ggamma8 = gamma.redSqr();
2781
+ ggamma8 = ggamma8.redIAdd(ggamma8);
2782
+ ggamma8 = ggamma8.redIAdd(ggamma8);
2783
+ ggamma8 = ggamma8.redIAdd(ggamma8);
2784
+ ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
2785
+ }
2786
+ return this.curve.jpoint(nx, ny, nz);
2787
+ };
2788
+ JPoint.prototype._dbl = function _dbl() {
2789
+ var a = this.curve.a;
2790
+ var jx = this.x;
2791
+ var jy = this.y;
2792
+ var jz = this.z;
2793
+ var jz4 = jz.redSqr().redSqr();
2794
+ var jx2 = jx.redSqr();
2795
+ var jy2 = jy.redSqr();
2796
+ var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
2797
+ var jxd4 = jx.redAdd(jx);
2798
+ jxd4 = jxd4.redIAdd(jxd4);
2799
+ var t1 = jxd4.redMul(jy2);
2800
+ var nx = c.redSqr().redISub(t1.redAdd(t1));
2801
+ var t2 = t1.redISub(nx);
2802
+ var jyd8 = jy2.redSqr();
2803
+ jyd8 = jyd8.redIAdd(jyd8);
2804
+ jyd8 = jyd8.redIAdd(jyd8);
2805
+ jyd8 = jyd8.redIAdd(jyd8);
2806
+ var ny = c.redMul(t2).redISub(jyd8);
2807
+ var nz = jy.redAdd(jy).redMul(jz);
2808
+ return this.curve.jpoint(nx, ny, nz);
2809
+ };
2810
+ JPoint.prototype.trpl = function trpl() {
2811
+ if (!this.curve.zeroA)
2812
+ return this.dbl().add(this);
2813
+ var xx = this.x.redSqr();
2814
+ var yy = this.y.redSqr();
2815
+ var zz = this.z.redSqr();
2816
+ var yyyy = yy.redSqr();
2817
+ var m = xx.redAdd(xx).redIAdd(xx);
2818
+ var mm = m.redSqr();
2819
+ var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
2820
+ e = e.redIAdd(e);
2821
+ e = e.redAdd(e).redIAdd(e);
2822
+ e = e.redISub(mm);
2823
+ var ee = e.redSqr();
2824
+ var t = yyyy.redIAdd(yyyy);
2825
+ t = t.redIAdd(t);
2826
+ t = t.redIAdd(t);
2827
+ t = t.redIAdd(t);
2828
+ var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
2829
+ var yyu4 = yy.redMul(u);
2830
+ yyu4 = yyu4.redIAdd(yyu4);
2831
+ yyu4 = yyu4.redIAdd(yyu4);
2832
+ var nx = this.x.redMul(ee).redISub(yyu4);
2833
+ nx = nx.redIAdd(nx);
2834
+ nx = nx.redIAdd(nx);
2835
+ var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
2836
+ ny = ny.redIAdd(ny);
2837
+ ny = ny.redIAdd(ny);
2838
+ ny = ny.redIAdd(ny);
2839
+ var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
2840
+ return this.curve.jpoint(nx, ny, nz);
2841
+ };
2842
+ JPoint.prototype.mul = function mul2(k, kbase) {
2843
+ k = new BN(k, kbase);
2844
+ return this.curve._wnafMul(this, k);
2845
+ };
2846
+ JPoint.prototype.eq = function eq3(p) {
2847
+ if (p.type === "affine")
2848
+ return this.eq(p.toJ());
2849
+ if (this === p)
2850
+ return true;
2851
+ var z2 = this.z.redSqr();
2852
+ var pz2 = p.z.redSqr();
2853
+ if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0)
2854
+ return false;
2855
+ var z3 = z2.redMul(this.z);
2856
+ var pz3 = pz2.redMul(p.z);
2857
+ return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
2858
+ };
2859
+ JPoint.prototype.eqXToP = function eqXToP(x) {
2860
+ var zs = this.z.redSqr();
2861
+ var rx = x.toRed(this.curve.red).redMul(zs);
2862
+ if (this.x.cmp(rx) === 0)
2863
+ return true;
2864
+ var xc = x.clone();
2865
+ var t = this.curve.redN.redMul(zs);
2866
+ for (; ; ) {
2867
+ xc.iadd(this.curve.n);
2868
+ if (xc.cmp(this.curve.p) >= 0)
2869
+ return false;
2870
+ rx.redIAdd(t);
2871
+ if (this.x.cmp(rx) === 0)
2872
+ return true;
2873
+ }
2874
+ };
2875
+ JPoint.prototype.inspect = function inspect2() {
2876
+ if (this.isInfinity())
2877
+ return "<EC JPoint Infinity>";
2878
+ return "<EC JPoint x: " + this.x.toString(16, 2) + " y: " + this.y.toString(16, 2) + " z: " + this.z.toString(16, 2) + ">";
2879
+ };
2880
+ JPoint.prototype.isInfinity = function isInfinity2() {
2881
+ return this.z.cmpn(0) === 0;
2882
+ };
2883
+ var curve_1 = createCommonjsModule(function(module, exports) {
2884
+ var curve = exports;
2885
+ curve.base = base;
2886
+ curve.short = short_1;
2887
+ curve.mont = /*RicMoo:ethers:require(./mont)*/
2888
+ null;
2889
+ curve.edwards = /*RicMoo:ethers:require(./edwards)*/
2890
+ null;
2891
+ });
2892
+ var curves_1 = createCommonjsModule(function(module, exports) {
2893
+ var curves = exports;
2894
+ var assert2 = utils_1$1.assert;
2895
+ function PresetCurve(options) {
2896
+ if (options.type === "short")
2897
+ this.curve = new curve_1.short(options);
2898
+ else if (options.type === "edwards")
2899
+ this.curve = new curve_1.edwards(options);
2900
+ else
2901
+ this.curve = new curve_1.mont(options);
2902
+ this.g = this.curve.g;
2903
+ this.n = this.curve.n;
2904
+ this.hash = options.hash;
2905
+ assert2(this.g.validate(), "Invalid curve");
2906
+ assert2(this.g.mul(this.n).isInfinity(), "Invalid curve, G*N != O");
2907
+ }
2908
+ curves.PresetCurve = PresetCurve;
2909
+ function defineCurve(name, options) {
2910
+ Object.defineProperty(curves, name, {
2911
+ configurable: true,
2912
+ enumerable: true,
2913
+ get: function() {
2914
+ var curve = new PresetCurve(options);
2915
+ Object.defineProperty(curves, name, {
2916
+ configurable: true,
2917
+ enumerable: true,
2918
+ value: curve
2919
+ });
2920
+ return curve;
2921
+ }
2922
+ });
2923
+ }
2924
+ defineCurve("p192", {
2925
+ type: "short",
2926
+ prime: "p192",
2927
+ p: "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",
2928
+ a: "ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",
2929
+ b: "64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",
2930
+ n: "ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",
2931
+ hash: hash.sha256,
2932
+ gRed: false,
2933
+ g: [
2934
+ "188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012",
2935
+ "07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"
2936
+ ]
2937
+ });
2938
+ defineCurve("p224", {
2939
+ type: "short",
2940
+ prime: "p224",
2941
+ p: "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",
2942
+ a: "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",
2943
+ b: "b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",
2944
+ n: "ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",
2945
+ hash: hash.sha256,
2946
+ gRed: false,
2947
+ g: [
2948
+ "b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21",
2949
+ "bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"
2950
+ ]
2951
+ });
2952
+ defineCurve("p256", {
2953
+ type: "short",
2954
+ prime: null,
2955
+ p: "ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",
2956
+ a: "ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",
2957
+ b: "5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",
2958
+ n: "ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",
2959
+ hash: hash.sha256,
2960
+ gRed: false,
2961
+ g: [
2962
+ "6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296",
2963
+ "4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"
2964
+ ]
2965
+ });
2966
+ defineCurve("p384", {
2967
+ type: "short",
2968
+ prime: null,
2969
+ p: "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",
2970
+ a: "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",
2971
+ b: "b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",
2972
+ n: "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",
2973
+ hash: hash.sha384,
2974
+ gRed: false,
2975
+ g: [
2976
+ "aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7",
2977
+ "3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"
2978
+ ]
2979
+ });
2980
+ defineCurve("p521", {
2981
+ type: "short",
2982
+ prime: null,
2983
+ p: "000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",
2984
+ a: "000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",
2985
+ b: "00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",
2986
+ n: "000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",
2987
+ hash: hash.sha512,
2988
+ gRed: false,
2989
+ g: [
2990
+ "000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66",
2991
+ "00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"
2992
+ ]
2993
+ });
2994
+ defineCurve("curve25519", {
2995
+ type: "mont",
2996
+ prime: "p25519",
2997
+ p: "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",
2998
+ a: "76d06",
2999
+ b: "1",
3000
+ n: "1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",
3001
+ hash: hash.sha256,
3002
+ gRed: false,
3003
+ g: [
3004
+ "9"
3005
+ ]
3006
+ });
3007
+ defineCurve("ed25519", {
3008
+ type: "edwards",
3009
+ prime: "p25519",
3010
+ p: "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",
3011
+ a: "-1",
3012
+ c: "1",
3013
+ // -121665 * (121666^(-1)) (mod P)
3014
+ d: "52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",
3015
+ n: "1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",
3016
+ hash: hash.sha256,
3017
+ gRed: false,
3018
+ g: [
3019
+ "216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a",
3020
+ // 4/5
3021
+ "6666666666666666666666666666666666666666666666666666666666666658"
3022
+ ]
3023
+ });
3024
+ var pre;
3025
+ try {
3026
+ pre = /*RicMoo:ethers:require(./precomputed/secp256k1)*/
3027
+ null.crash();
3028
+ } catch (e) {
3029
+ pre = void 0;
3030
+ }
3031
+ defineCurve("secp256k1", {
3032
+ type: "short",
3033
+ prime: "k256",
3034
+ p: "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",
3035
+ a: "0",
3036
+ b: "7",
3037
+ n: "ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",
3038
+ h: "1",
3039
+ hash: hash.sha256,
3040
+ // Precomputed endomorphism
3041
+ beta: "7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",
3042
+ lambda: "5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",
3043
+ basis: [
3044
+ {
3045
+ a: "3086d221a7d46bcde86c90e49284eb15",
3046
+ b: "-e4437ed6010e88286f547fa90abfe4c3"
3047
+ },
3048
+ {
3049
+ a: "114ca50f7a8e2f3f657c1108d9d44cfd8",
3050
+ b: "3086d221a7d46bcde86c90e49284eb15"
3051
+ }
3052
+ ],
3053
+ gRed: false,
3054
+ g: [
3055
+ "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
3056
+ "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",
3057
+ pre
3058
+ ]
3059
+ });
3060
+ });
3061
+ function HmacDRBG(options) {
3062
+ if (!(this instanceof HmacDRBG))
3063
+ return new HmacDRBG(options);
3064
+ this.hash = options.hash;
3065
+ this.predResist = !!options.predResist;
3066
+ this.outLen = this.hash.outSize;
3067
+ this.minEntropy = options.minEntropy || this.hash.hmacStrength;
3068
+ this._reseed = null;
3069
+ this.reseedInterval = null;
3070
+ this.K = null;
3071
+ this.V = null;
3072
+ var entropy = utils_1.toArray(options.entropy, options.entropyEnc || "hex");
3073
+ var nonce = utils_1.toArray(options.nonce, options.nonceEnc || "hex");
3074
+ var pers = utils_1.toArray(options.pers, options.persEnc || "hex");
3075
+ minimalisticAssert(
3076
+ entropy.length >= this.minEntropy / 8,
3077
+ "Not enough entropy. Minimum is: " + this.minEntropy + " bits"
3078
+ );
3079
+ this._init(entropy, nonce, pers);
3080
+ }
3081
+ var hmacDrbg = HmacDRBG;
3082
+ HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
3083
+ var seed = entropy.concat(nonce).concat(pers);
3084
+ this.K = new Array(this.outLen / 8);
3085
+ this.V = new Array(this.outLen / 8);
3086
+ for (var i = 0; i < this.V.length; i++) {
3087
+ this.K[i] = 0;
3088
+ this.V[i] = 1;
3089
+ }
3090
+ this._update(seed);
3091
+ this._reseed = 1;
3092
+ this.reseedInterval = 281474976710656;
3093
+ };
3094
+ HmacDRBG.prototype._hmac = function hmac2() {
3095
+ return new hash.hmac(this.hash, this.K);
3096
+ };
3097
+ HmacDRBG.prototype._update = function update(seed) {
3098
+ var kmac = this._hmac().update(this.V).update([0]);
3099
+ if (seed)
3100
+ kmac = kmac.update(seed);
3101
+ this.K = kmac.digest();
3102
+ this.V = this._hmac().update(this.V).digest();
3103
+ if (!seed)
3104
+ return;
3105
+ this.K = this._hmac().update(this.V).update([1]).update(seed).digest();
3106
+ this.V = this._hmac().update(this.V).digest();
3107
+ };
3108
+ HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add3, addEnc) {
3109
+ if (typeof entropyEnc !== "string") {
3110
+ addEnc = add3;
3111
+ add3 = entropyEnc;
3112
+ entropyEnc = null;
3113
+ }
3114
+ entropy = utils_1.toArray(entropy, entropyEnc);
3115
+ add3 = utils_1.toArray(add3, addEnc);
3116
+ minimalisticAssert(
3117
+ entropy.length >= this.minEntropy / 8,
3118
+ "Not enough entropy. Minimum is: " + this.minEntropy + " bits"
3119
+ );
3120
+ this._update(entropy.concat(add3 || []));
3121
+ this._reseed = 1;
3122
+ };
3123
+ HmacDRBG.prototype.generate = function generate(len, enc, add3, addEnc) {
3124
+ if (this._reseed > this.reseedInterval)
3125
+ throw new Error("Reseed is required");
3126
+ if (typeof enc !== "string") {
3127
+ addEnc = add3;
3128
+ add3 = enc;
3129
+ enc = null;
3130
+ }
3131
+ if (add3) {
3132
+ add3 = utils_1.toArray(add3, addEnc || "hex");
3133
+ this._update(add3);
3134
+ }
3135
+ var temp = [];
3136
+ while (temp.length < len) {
3137
+ this.V = this._hmac().update(this.V).digest();
3138
+ temp = temp.concat(this.V);
3139
+ }
3140
+ var res = temp.slice(0, len);
3141
+ this._update(add3);
3142
+ this._reseed++;
3143
+ return utils_1.encode(res, enc);
3144
+ };
3145
+ var assert$3 = utils_1$1.assert;
3146
+ function KeyPair(ec2, options) {
3147
+ this.ec = ec2;
3148
+ this.priv = null;
3149
+ this.pub = null;
3150
+ if (options.priv)
3151
+ this._importPrivate(options.priv, options.privEnc);
3152
+ if (options.pub)
3153
+ this._importPublic(options.pub, options.pubEnc);
3154
+ }
3155
+ var key = KeyPair;
3156
+ KeyPair.fromPublic = function fromPublic(ec2, pub, enc) {
3157
+ if (pub instanceof KeyPair)
3158
+ return pub;
3159
+ return new KeyPair(ec2, {
3160
+ pub,
3161
+ pubEnc: enc
3162
+ });
3163
+ };
3164
+ KeyPair.fromPrivate = function fromPrivate(ec2, priv, enc) {
3165
+ if (priv instanceof KeyPair)
3166
+ return priv;
3167
+ return new KeyPair(ec2, {
3168
+ priv,
3169
+ privEnc: enc
3170
+ });
3171
+ };
3172
+ KeyPair.prototype.validate = function validate4() {
3173
+ var pub = this.getPublic();
3174
+ if (pub.isInfinity())
3175
+ return { result: false, reason: "Invalid public key" };
3176
+ if (!pub.validate())
3177
+ return { result: false, reason: "Public key is not a point" };
3178
+ if (!pub.mul(this.ec.curve.n).isInfinity())
3179
+ return { result: false, reason: "Public key * N != O" };
3180
+ return { result: true, reason: null };
3181
+ };
3182
+ KeyPair.prototype.getPublic = function getPublic(compact, enc) {
3183
+ if (typeof compact === "string") {
3184
+ enc = compact;
3185
+ compact = null;
3186
+ }
3187
+ if (!this.pub)
3188
+ this.pub = this.ec.g.mul(this.priv);
3189
+ if (!enc)
3190
+ return this.pub;
3191
+ return this.pub.encode(enc, compact);
3192
+ };
3193
+ KeyPair.prototype.getPrivate = function getPrivate(enc) {
3194
+ if (enc === "hex")
3195
+ return this.priv.toString(16, 2);
3196
+ else
3197
+ return this.priv;
3198
+ };
3199
+ KeyPair.prototype._importPrivate = function _importPrivate(key2, enc) {
3200
+ this.priv = new BN(key2, enc || 16);
3201
+ this.priv = this.priv.umod(this.ec.curve.n);
3202
+ };
3203
+ KeyPair.prototype._importPublic = function _importPublic(key2, enc) {
3204
+ if (key2.x || key2.y) {
3205
+ if (this.ec.curve.type === "mont") {
3206
+ assert$3(key2.x, "Need x coordinate");
3207
+ } else if (this.ec.curve.type === "short" || this.ec.curve.type === "edwards") {
3208
+ assert$3(key2.x && key2.y, "Need both x and y coordinate");
3209
+ }
3210
+ this.pub = this.ec.curve.point(key2.x, key2.y);
3211
+ return;
3212
+ }
3213
+ this.pub = this.ec.curve.decodePoint(key2, enc);
3214
+ };
3215
+ KeyPair.prototype.derive = function derive(pub) {
3216
+ if (!pub.validate()) {
3217
+ assert$3(pub.validate(), "public point not validated");
3218
+ }
3219
+ return pub.mul(this.priv).getX();
3220
+ };
3221
+ KeyPair.prototype.sign = function sign(msg, enc, options) {
3222
+ return this.ec.sign(msg, this, enc, options);
3223
+ };
3224
+ KeyPair.prototype.verify = function verify(msg, signature2, options) {
3225
+ return this.ec.verify(msg, signature2, this, void 0, options);
3226
+ };
3227
+ KeyPair.prototype.inspect = function inspect3() {
3228
+ return "<Key priv: " + (this.priv && this.priv.toString(16, 2)) + " pub: " + (this.pub && this.pub.inspect()) + " >";
3229
+ };
3230
+ var assert$4 = utils_1$1.assert;
3231
+ function Signature(options, enc) {
3232
+ if (options instanceof Signature)
3233
+ return options;
3234
+ if (this._importDER(options, enc))
3235
+ return;
3236
+ assert$4(options.r && options.s, "Signature without r or s");
3237
+ this.r = new BN(options.r, 16);
3238
+ this.s = new BN(options.s, 16);
3239
+ if (options.recoveryParam === void 0)
3240
+ this.recoveryParam = null;
3241
+ else
3242
+ this.recoveryParam = options.recoveryParam;
3243
+ }
3244
+ var signature = Signature;
3245
+ function Position() {
3246
+ this.place = 0;
3247
+ }
3248
+ function getLength(buf, p) {
3249
+ var initial = buf[p.place++];
3250
+ if (!(initial & 128)) {
3251
+ return initial;
3252
+ }
3253
+ var octetLen = initial & 15;
3254
+ if (octetLen === 0 || octetLen > 4) {
3255
+ return false;
3256
+ }
3257
+ if (buf[p.place] === 0) {
3258
+ return false;
3259
+ }
3260
+ var val = 0;
3261
+ for (var i = 0, off = p.place; i < octetLen; i++, off++) {
3262
+ val <<= 8;
3263
+ val |= buf[off];
3264
+ val >>>= 0;
3265
+ }
3266
+ if (val <= 127) {
3267
+ return false;
3268
+ }
3269
+ p.place = off;
3270
+ return val;
3271
+ }
3272
+ function rmPadding(buf) {
3273
+ var i = 0;
3274
+ var len = buf.length - 1;
3275
+ while (!buf[i] && !(buf[i + 1] & 128) && i < len) {
3276
+ i++;
3277
+ }
3278
+ if (i === 0) {
3279
+ return buf;
3280
+ }
3281
+ return buf.slice(i);
3282
+ }
3283
+ Signature.prototype._importDER = function _importDER(data, enc) {
3284
+ data = utils_1$1.toArray(data, enc);
3285
+ var p = new Position();
3286
+ if (data[p.place++] !== 48) {
3287
+ return false;
3288
+ }
3289
+ var len = getLength(data, p);
3290
+ if (len === false) {
3291
+ return false;
3292
+ }
3293
+ if (len + p.place !== data.length) {
3294
+ return false;
3295
+ }
3296
+ if (data[p.place++] !== 2) {
3297
+ return false;
3298
+ }
3299
+ var rlen = getLength(data, p);
3300
+ if (rlen === false) {
3301
+ return false;
3302
+ }
3303
+ if ((data[p.place] & 128) !== 0) {
3304
+ return false;
3305
+ }
3306
+ var r = data.slice(p.place, rlen + p.place);
3307
+ p.place += rlen;
3308
+ if (data[p.place++] !== 2) {
3309
+ return false;
3310
+ }
3311
+ var slen = getLength(data, p);
3312
+ if (slen === false) {
3313
+ return false;
3314
+ }
3315
+ if (data.length !== slen + p.place) {
3316
+ return false;
3317
+ }
3318
+ if ((data[p.place] & 128) !== 0) {
3319
+ return false;
3320
+ }
3321
+ var s = data.slice(p.place, slen + p.place);
3322
+ if (r[0] === 0) {
3323
+ if (r[1] & 128) {
3324
+ r = r.slice(1);
3325
+ } else {
3326
+ return false;
3327
+ }
3328
+ }
3329
+ if (s[0] === 0) {
3330
+ if (s[1] & 128) {
3331
+ s = s.slice(1);
3332
+ } else {
3333
+ return false;
3334
+ }
3335
+ }
3336
+ this.r = new BN(r);
3337
+ this.s = new BN(s);
3338
+ this.recoveryParam = null;
3339
+ return true;
3340
+ };
3341
+ function constructLength(arr, len) {
3342
+ if (len < 128) {
3343
+ arr.push(len);
3344
+ return;
3345
+ }
3346
+ var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
3347
+ arr.push(octets | 128);
3348
+ while (--octets) {
3349
+ arr.push(len >>> (octets << 3) & 255);
3350
+ }
3351
+ arr.push(len);
3352
+ }
3353
+ Signature.prototype.toDER = function toDER(enc) {
3354
+ var r = this.r.toArray();
3355
+ var s = this.s.toArray();
3356
+ if (r[0] & 128)
3357
+ r = [0].concat(r);
3358
+ if (s[0] & 128)
3359
+ s = [0].concat(s);
3360
+ r = rmPadding(r);
3361
+ s = rmPadding(s);
3362
+ while (!s[0] && !(s[1] & 128)) {
3363
+ s = s.slice(1);
3364
+ }
3365
+ var arr = [2];
3366
+ constructLength(arr, r.length);
3367
+ arr = arr.concat(r);
3368
+ arr.push(2);
3369
+ constructLength(arr, s.length);
3370
+ var backHalf = arr.concat(s);
3371
+ var res = [48];
3372
+ constructLength(res, backHalf.length);
3373
+ res = res.concat(backHalf);
3374
+ return utils_1$1.encode(res, enc);
3375
+ };
3376
+ var rand = (
3377
+ /*RicMoo:ethers:require(brorand)*/
3378
+ function() {
3379
+ throw new Error("unsupported");
3380
+ }
3381
+ );
3382
+ var assert$5 = utils_1$1.assert;
3383
+ function EC(options) {
3384
+ if (!(this instanceof EC))
3385
+ return new EC(options);
3386
+ if (typeof options === "string") {
3387
+ assert$5(
3388
+ Object.prototype.hasOwnProperty.call(curves_1, options),
3389
+ "Unknown curve " + options
3390
+ );
3391
+ options = curves_1[options];
3392
+ }
3393
+ if (options instanceof curves_1.PresetCurve)
3394
+ options = { curve: options };
3395
+ this.curve = options.curve.curve;
3396
+ this.n = this.curve.n;
3397
+ this.nh = this.n.ushrn(1);
3398
+ this.g = this.curve.g;
3399
+ this.g = options.curve.g;
3400
+ this.g.precompute(options.curve.n.bitLength() + 1);
3401
+ this.hash = options.hash || options.curve.hash;
3402
+ }
3403
+ var ec = EC;
3404
+ EC.prototype.keyPair = function keyPair(options) {
3405
+ return new key(this, options);
3406
+ };
3407
+ EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
3408
+ return key.fromPrivate(this, priv, enc);
3409
+ };
3410
+ EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
3411
+ return key.fromPublic(this, pub, enc);
3412
+ };
3413
+ EC.prototype.genKeyPair = function genKeyPair(options) {
3414
+ if (!options)
3415
+ options = {};
3416
+ var drbg = new hmacDrbg({
3417
+ hash: this.hash,
3418
+ pers: options.pers,
3419
+ persEnc: options.persEnc || "utf8",
3420
+ entropy: options.entropy || rand(this.hash.hmacStrength),
3421
+ entropyEnc: options.entropy && options.entropyEnc || "utf8",
3422
+ nonce: this.n.toArray()
3423
+ });
3424
+ var bytes = this.n.byteLength();
3425
+ var ns2 = this.n.sub(new BN(2));
3426
+ for (; ; ) {
3427
+ var priv = new BN(drbg.generate(bytes));
3428
+ if (priv.cmp(ns2) > 0)
3429
+ continue;
3430
+ priv.iaddn(1);
3431
+ return this.keyFromPrivate(priv);
3432
+ }
3433
+ };
3434
+ EC.prototype._truncateToN = function _truncateToN(msg, truncOnly, bitLength) {
3435
+ var byteLength;
3436
+ if (BN.isBN(msg) || typeof msg === "number") {
3437
+ msg = new BN(msg, 16);
3438
+ byteLength = msg.byteLength();
3439
+ } else if (typeof msg === "object") {
3440
+ byteLength = msg.length;
3441
+ msg = new BN(msg, 16);
3442
+ } else {
3443
+ var str = msg.toString();
3444
+ byteLength = str.length + 1 >>> 1;
3445
+ msg = new BN(str, 16);
3446
+ }
3447
+ if (typeof bitLength !== "number") {
3448
+ bitLength = byteLength * 8;
3449
+ }
3450
+ var delta = bitLength - this.n.bitLength();
3451
+ if (delta > 0)
3452
+ msg = msg.ushrn(delta);
3453
+ if (!truncOnly && msg.cmp(this.n) >= 0)
3454
+ return msg.sub(this.n);
3455
+ else
3456
+ return msg;
3457
+ };
3458
+ EC.prototype.sign = function sign2(msg, key2, enc, options) {
3459
+ if (typeof enc === "object") {
3460
+ options = enc;
3461
+ enc = null;
3462
+ }
3463
+ if (!options)
3464
+ options = {};
3465
+ if (typeof msg !== "string" && typeof msg !== "number" && !BN.isBN(msg)) {
3466
+ assert$5(
3467
+ typeof msg === "object" && msg && typeof msg.length === "number",
3468
+ "Expected message to be an array-like, a hex string, or a BN instance"
3469
+ );
3470
+ assert$5(msg.length >>> 0 === msg.length);
3471
+ for (var i = 0; i < msg.length; i++) assert$5((msg[i] & 255) === msg[i]);
3472
+ }
3473
+ key2 = this.keyFromPrivate(key2, enc);
3474
+ msg = this._truncateToN(msg, false, options.msgBitLength);
3475
+ assert$5(!msg.isNeg(), "Can not sign a negative message");
3476
+ var bytes = this.n.byteLength();
3477
+ var bkey = key2.getPrivate().toArray("be", bytes);
3478
+ var nonce = msg.toArray("be", bytes);
3479
+ assert$5(new BN(nonce).eq(msg), "Can not sign message");
3480
+ var drbg = new hmacDrbg({
3481
+ hash: this.hash,
3482
+ entropy: bkey,
3483
+ nonce,
3484
+ pers: options.pers,
3485
+ persEnc: options.persEnc || "utf8"
3486
+ });
3487
+ var ns1 = this.n.sub(new BN(1));
3488
+ for (var iter = 0; ; iter++) {
3489
+ var k = options.k ? options.k(iter) : new BN(drbg.generate(this.n.byteLength()));
3490
+ k = this._truncateToN(k, true);
3491
+ if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0)
3492
+ continue;
3493
+ var kp = this.g.mul(k);
3494
+ if (kp.isInfinity())
3495
+ continue;
3496
+ var kpX = kp.getX();
3497
+ var r = kpX.umod(this.n);
3498
+ if (r.cmpn(0) === 0)
3499
+ continue;
3500
+ var s = k.invm(this.n).mul(r.mul(key2.getPrivate()).iadd(msg));
3501
+ s = s.umod(this.n);
3502
+ if (s.cmpn(0) === 0)
3503
+ continue;
3504
+ var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | (kpX.cmp(r) !== 0 ? 2 : 0);
3505
+ if (options.canonical && s.cmp(this.nh) > 0) {
3506
+ s = this.n.sub(s);
3507
+ recoveryParam ^= 1;
3508
+ }
3509
+ return new signature({ r, s, recoveryParam });
3510
+ }
3511
+ };
3512
+ EC.prototype.verify = function verify2(msg, signature$1, key2, enc, options) {
3513
+ if (!options)
3514
+ options = {};
3515
+ msg = this._truncateToN(msg, false, options.msgBitLength);
3516
+ key2 = this.keyFromPublic(key2, enc);
3517
+ signature$1 = new signature(signature$1, "hex");
3518
+ var r = signature$1.r;
3519
+ var s = signature$1.s;
3520
+ if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0)
3521
+ return false;
3522
+ if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0)
3523
+ return false;
3524
+ var sinv = s.invm(this.n);
3525
+ var u1 = sinv.mul(msg).umod(this.n);
3526
+ var u2 = sinv.mul(r).umod(this.n);
3527
+ var p;
3528
+ if (!this.curve._maxwellTrick) {
3529
+ p = this.g.mulAdd(u1, key2.getPublic(), u2);
3530
+ if (p.isInfinity())
3531
+ return false;
3532
+ return p.getX().umod(this.n).cmp(r) === 0;
3533
+ }
3534
+ p = this.g.jmulAdd(u1, key2.getPublic(), u2);
3535
+ if (p.isInfinity())
3536
+ return false;
3537
+ return p.eqXToP(r);
3538
+ };
3539
+ EC.prototype.recoverPubKey = function(msg, signature$1, j, enc) {
3540
+ assert$5((3 & j) === j, "The recovery param is more than two bits");
3541
+ signature$1 = new signature(signature$1, enc);
3542
+ var n = this.n;
3543
+ var e = new BN(msg);
3544
+ var r = signature$1.r;
3545
+ var s = signature$1.s;
3546
+ var isYOdd = j & 1;
3547
+ var isSecondKey = j >> 1;
3548
+ if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey)
3549
+ throw new Error("Unable to find sencond key candinate");
3550
+ if (isSecondKey)
3551
+ r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);
3552
+ else
3553
+ r = this.curve.pointFromX(r, isYOdd);
3554
+ var rInv = signature$1.r.invm(n);
3555
+ var s1 = n.sub(e).mul(rInv).umod(n);
3556
+ var s2 = s.mul(rInv).umod(n);
3557
+ return this.g.mulAdd(s1, r, s2);
3558
+ };
3559
+ EC.prototype.getKeyRecoveryParam = function(e, signature$1, Q, enc) {
3560
+ signature$1 = new signature(signature$1, enc);
3561
+ if (signature$1.recoveryParam !== null)
3562
+ return signature$1.recoveryParam;
3563
+ for (var i = 0; i < 4; i++) {
3564
+ var Qprime;
3565
+ try {
3566
+ Qprime = this.recoverPubKey(e, signature$1, i);
3567
+ } catch (e2) {
3568
+ continue;
3569
+ }
3570
+ if (Qprime.eq(Q))
3571
+ return i;
3572
+ }
3573
+ throw new Error("Unable to find valid recovery factor");
3574
+ };
3575
+ var elliptic_1 = createCommonjsModule(function(module, exports) {
3576
+ var elliptic = exports;
3577
+ elliptic.version = /*RicMoo:ethers*/
3578
+ { version: "6.6.1" }.version;
3579
+ elliptic.utils = utils_1$1;
3580
+ elliptic.rand = /*RicMoo:ethers:require(brorand)*/
3581
+ function() {
3582
+ throw new Error("unsupported");
3583
+ };
3584
+ elliptic.curve = curve_1;
3585
+ elliptic.curves = curves_1;
3586
+ elliptic.ec = ec;
3587
+ elliptic.eddsa = /*RicMoo:ethers:require(./elliptic/eddsa)*/
3588
+ null;
3589
+ });
3590
+ var EC$1 = elliptic_1.ec;
3591
+ const version$1 = "signing-key/5.8.0";
3592
+ const logger$1 = new Logger(version$1);
3593
+ let _curve = null;
3594
+ function getCurve() {
3595
+ if (!_curve) {
3596
+ _curve = new EC$1("secp256k1");
3597
+ }
3598
+ return _curve;
3599
+ }
3600
+ class SigningKey {
3601
+ constructor(privateKey) {
3602
+ defineReadOnly(this, "curve", "secp256k1");
3603
+ defineReadOnly(this, "privateKey", hexlify(privateKey));
3604
+ if (hexDataLength(this.privateKey) !== 32) {
3605
+ logger$1.throwArgumentError("invalid private key", "privateKey", "[[ REDACTED ]]");
3606
+ }
3607
+ const keyPair2 = getCurve().keyFromPrivate(arrayify(this.privateKey));
3608
+ defineReadOnly(this, "publicKey", "0x" + keyPair2.getPublic(false, "hex"));
3609
+ defineReadOnly(this, "compressedPublicKey", "0x" + keyPair2.getPublic(true, "hex"));
3610
+ defineReadOnly(this, "_isSigningKey", true);
3611
+ }
3612
+ _addPoint(other) {
3613
+ const p0 = getCurve().keyFromPublic(arrayify(this.publicKey));
3614
+ const p1 = getCurve().keyFromPublic(arrayify(other));
3615
+ return "0x" + p0.pub.add(p1.pub).encodeCompressed("hex");
3616
+ }
3617
+ signDigest(digest) {
3618
+ const keyPair2 = getCurve().keyFromPrivate(arrayify(this.privateKey));
3619
+ const digestBytes = arrayify(digest);
3620
+ if (digestBytes.length !== 32) {
3621
+ logger$1.throwArgumentError("bad digest length", "digest", digest);
3622
+ }
3623
+ const signature2 = keyPair2.sign(digestBytes, { canonical: true });
3624
+ return splitSignature({
3625
+ recoveryParam: signature2.recoveryParam,
3626
+ r: hexZeroPad("0x" + signature2.r.toString(16), 32),
3627
+ s: hexZeroPad("0x" + signature2.s.toString(16), 32)
3628
+ });
3629
+ }
3630
+ computeSharedSecret(otherKey) {
3631
+ const keyPair2 = getCurve().keyFromPrivate(arrayify(this.privateKey));
3632
+ const otherKeyPair = getCurve().keyFromPublic(arrayify(computePublicKey(otherKey)));
3633
+ return hexZeroPad("0x" + keyPair2.derive(otherKeyPair.getPublic()).toString(16), 32);
3634
+ }
3635
+ static isSigningKey(value) {
3636
+ return !!(value && value._isSigningKey);
3637
+ }
3638
+ }
3639
+ function recoverPublicKey(digest, signature2) {
3640
+ const sig = splitSignature(signature2);
3641
+ const rs = { r: arrayify(sig.r), s: arrayify(sig.s) };
3642
+ return "0x" + getCurve().recoverPubKey(arrayify(digest), rs, sig.recoveryParam).encode("hex", false);
3643
+ }
3644
+ function computePublicKey(key2, compressed) {
3645
+ const bytes = arrayify(key2);
3646
+ if (bytes.length === 32) {
3647
+ const signingKey = new SigningKey(bytes);
3648
+ return signingKey.publicKey;
3649
+ } else if (bytes.length === 33) {
3650
+ return "0x" + getCurve().keyFromPublic(bytes).getPublic(false, "hex");
3651
+ } else if (bytes.length === 65) {
3652
+ {
3653
+ return hexlify(bytes);
3654
+ }
3655
+ }
3656
+ return logger$1.throwArgumentError("invalid public or private key", "key", "[REDACTED]");
3657
+ }
3658
+ const version = "transactions/5.8.0";
3659
+ const logger = new Logger(version);
3660
+ var TransactionTypes;
3661
+ (function(TransactionTypes2) {
3662
+ TransactionTypes2[TransactionTypes2["legacy"] = 0] = "legacy";
3663
+ TransactionTypes2[TransactionTypes2["eip2930"] = 1] = "eip2930";
3664
+ TransactionTypes2[TransactionTypes2["eip1559"] = 2] = "eip1559";
3665
+ })(TransactionTypes || (TransactionTypes = {}));
3666
+ function handleAddress(value) {
3667
+ if (value === "0x") {
3668
+ return null;
3669
+ }
3670
+ return getAddress(value);
3671
+ }
3672
+ function handleNumber(value) {
3673
+ if (value === "0x") {
3674
+ return Zero;
3675
+ }
3676
+ return BigNumber.from(value);
3677
+ }
3678
+ const transactionFields = [
3679
+ { name: "nonce", maxLength: 32, numeric: true },
3680
+ { name: "gasPrice", maxLength: 32, numeric: true },
3681
+ { name: "gasLimit", maxLength: 32, numeric: true },
3682
+ { name: "to", length: 20 },
3683
+ { name: "value", maxLength: 32, numeric: true },
3684
+ { name: "data" }
3685
+ ];
3686
+ const allowedTransactionKeys = {
3687
+ chainId: true,
3688
+ data: true,
3689
+ gasLimit: true,
3690
+ gasPrice: true,
3691
+ nonce: true,
3692
+ to: true,
3693
+ type: true,
3694
+ value: true
3695
+ };
3696
+ function computeAddress(key2) {
3697
+ const publicKey = computePublicKey(key2);
3698
+ return getAddress(hexDataSlice(keccak256(hexDataSlice(publicKey, 1)), 12));
3699
+ }
3700
+ function recoverAddress(digest, signature2) {
3701
+ return computeAddress(recoverPublicKey(arrayify(digest), signature2));
3702
+ }
3703
+ function formatNumber(value, name) {
3704
+ const result = stripZeros(BigNumber.from(value).toHexString());
3705
+ if (result.length > 32) {
3706
+ logger.throwArgumentError("invalid length for " + name, "transaction:" + name, value);
3707
+ }
3708
+ return result;
3709
+ }
3710
+ function accessSetify(addr, storageKeys) {
3711
+ return {
3712
+ address: getAddress(addr),
3713
+ storageKeys: (storageKeys || []).map((storageKey, index2) => {
3714
+ if (hexDataLength(storageKey) !== 32) {
3715
+ logger.throwArgumentError("invalid access list storageKey", `accessList[${addr}:${index2}]`, storageKey);
3716
+ }
3717
+ return storageKey.toLowerCase();
3718
+ })
3719
+ };
3720
+ }
3721
+ function accessListify(value) {
3722
+ if (Array.isArray(value)) {
3723
+ return value.map((set, index2) => {
3724
+ if (Array.isArray(set)) {
3725
+ if (set.length > 2) {
3726
+ logger.throwArgumentError("access list expected to be [ address, storageKeys[] ]", `value[${index2}]`, set);
3727
+ }
3728
+ return accessSetify(set[0], set[1]);
3729
+ }
3730
+ return accessSetify(set.address, set.storageKeys);
3731
+ });
3732
+ }
3733
+ const result = Object.keys(value).map((addr) => {
3734
+ const storageKeys = value[addr].reduce((accum, storageKey) => {
3735
+ accum[storageKey] = true;
3736
+ return accum;
3737
+ }, {});
3738
+ return accessSetify(addr, Object.keys(storageKeys).sort());
3739
+ });
3740
+ result.sort((a, b) => a.address.localeCompare(b.address));
3741
+ return result;
3742
+ }
3743
+ function formatAccessList(value) {
3744
+ return accessListify(value).map((set) => [set.address, set.storageKeys]);
3745
+ }
3746
+ function _serializeEip1559(transaction, signature2) {
3747
+ if (transaction.gasPrice != null) {
3748
+ const gasPrice = BigNumber.from(transaction.gasPrice);
3749
+ const maxFeePerGas = BigNumber.from(transaction.maxFeePerGas || 0);
3750
+ if (!gasPrice.eq(maxFeePerGas)) {
3751
+ logger.throwArgumentError("mismatch EIP-1559 gasPrice != maxFeePerGas", "tx", {
3752
+ gasPrice,
3753
+ maxFeePerGas
3754
+ });
3755
+ }
3756
+ }
3757
+ const fields = [
3758
+ formatNumber(transaction.chainId || 0, "chainId"),
3759
+ formatNumber(transaction.nonce || 0, "nonce"),
3760
+ formatNumber(transaction.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
3761
+ formatNumber(transaction.maxFeePerGas || 0, "maxFeePerGas"),
3762
+ formatNumber(transaction.gasLimit || 0, "gasLimit"),
3763
+ transaction.to != null ? getAddress(transaction.to) : "0x",
3764
+ formatNumber(transaction.value || 0, "value"),
3765
+ transaction.data || "0x",
3766
+ formatAccessList(transaction.accessList || [])
3767
+ ];
3768
+ if (signature2) {
3769
+ const sig = splitSignature(signature2);
3770
+ fields.push(formatNumber(sig.recoveryParam, "recoveryParam"));
3771
+ fields.push(stripZeros(sig.r));
3772
+ fields.push(stripZeros(sig.s));
3773
+ }
3774
+ return hexConcat(["0x02", encode(fields)]);
3775
+ }
3776
+ function _serializeEip2930(transaction, signature2) {
3777
+ const fields = [
3778
+ formatNumber(transaction.chainId || 0, "chainId"),
3779
+ formatNumber(transaction.nonce || 0, "nonce"),
3780
+ formatNumber(transaction.gasPrice || 0, "gasPrice"),
3781
+ formatNumber(transaction.gasLimit || 0, "gasLimit"),
3782
+ transaction.to != null ? getAddress(transaction.to) : "0x",
3783
+ formatNumber(transaction.value || 0, "value"),
3784
+ transaction.data || "0x",
3785
+ formatAccessList(transaction.accessList || [])
3786
+ ];
3787
+ if (signature2) {
3788
+ const sig = splitSignature(signature2);
3789
+ fields.push(formatNumber(sig.recoveryParam, "recoveryParam"));
3790
+ fields.push(stripZeros(sig.r));
3791
+ fields.push(stripZeros(sig.s));
3792
+ }
3793
+ return hexConcat(["0x01", encode(fields)]);
3794
+ }
3795
+ function _serialize(transaction, signature2) {
3796
+ checkProperties(transaction, allowedTransactionKeys);
3797
+ const raw = [];
3798
+ transactionFields.forEach(function(fieldInfo) {
3799
+ let value = transaction[fieldInfo.name] || [];
3800
+ const options = {};
3801
+ if (fieldInfo.numeric) {
3802
+ options.hexPad = "left";
3803
+ }
3804
+ value = arrayify(hexlify(value, options));
3805
+ if (fieldInfo.length && value.length !== fieldInfo.length && value.length > 0) {
3806
+ logger.throwArgumentError("invalid length for " + fieldInfo.name, "transaction:" + fieldInfo.name, value);
3807
+ }
3808
+ if (fieldInfo.maxLength) {
3809
+ value = stripZeros(value);
3810
+ if (value.length > fieldInfo.maxLength) {
3811
+ logger.throwArgumentError("invalid length for " + fieldInfo.name, "transaction:" + fieldInfo.name, value);
3812
+ }
3813
+ }
3814
+ raw.push(hexlify(value));
3815
+ });
3816
+ let chainId = 0;
3817
+ if (transaction.chainId != null) {
3818
+ chainId = transaction.chainId;
3819
+ if (typeof chainId !== "number") {
3820
+ logger.throwArgumentError("invalid transaction.chainId", "transaction", transaction);
3821
+ }
3822
+ } else if (signature2 && !isBytesLike(signature2) && signature2.v > 28) {
3823
+ chainId = Math.floor((signature2.v - 35) / 2);
3824
+ }
3825
+ if (chainId !== 0) {
3826
+ raw.push(hexlify(chainId));
3827
+ raw.push("0x");
3828
+ raw.push("0x");
3829
+ }
3830
+ if (!signature2) {
3831
+ return encode(raw);
3832
+ }
3833
+ const sig = splitSignature(signature2);
3834
+ let v = 27 + sig.recoveryParam;
3835
+ if (chainId !== 0) {
3836
+ raw.pop();
3837
+ raw.pop();
3838
+ raw.pop();
3839
+ v += chainId * 2 + 8;
3840
+ if (sig.v > 28 && sig.v !== v) {
3841
+ logger.throwArgumentError("transaction.chainId/signature.v mismatch", "signature", signature2);
3842
+ }
3843
+ } else if (sig.v !== v) {
3844
+ logger.throwArgumentError("transaction.chainId/signature.v mismatch", "signature", signature2);
3845
+ }
3846
+ raw.push(hexlify(v));
3847
+ raw.push(stripZeros(arrayify(sig.r)));
3848
+ raw.push(stripZeros(arrayify(sig.s)));
3849
+ return encode(raw);
3850
+ }
3851
+ function serialize(transaction, signature2) {
3852
+ if (transaction.type == null || transaction.type === 0) {
3853
+ if (transaction.accessList != null) {
3854
+ logger.throwArgumentError("untyped transactions do not support accessList; include type: 1", "transaction", transaction);
3855
+ }
3856
+ return _serialize(transaction, signature2);
3857
+ }
3858
+ switch (transaction.type) {
3859
+ case 1:
3860
+ return _serializeEip2930(transaction, signature2);
3861
+ case 2:
3862
+ return _serializeEip1559(transaction, signature2);
3863
+ }
3864
+ return logger.throwError(`unsupported transaction type: ${transaction.type}`, Logger.errors.UNSUPPORTED_OPERATION, {
3865
+ operation: "serializeTransaction",
3866
+ transactionType: transaction.type
3867
+ });
3868
+ }
3869
+ function _parseEipSignature(tx, fields, serialize2) {
3870
+ try {
3871
+ const recid = handleNumber(fields[0]).toNumber();
3872
+ if (recid !== 0 && recid !== 1) {
3873
+ throw new Error("bad recid");
3874
+ }
3875
+ tx.v = recid;
3876
+ } catch (error) {
3877
+ logger.throwArgumentError("invalid v for transaction type: 1", "v", fields[0]);
3878
+ }
3879
+ tx.r = hexZeroPad(fields[1], 32);
3880
+ tx.s = hexZeroPad(fields[2], 32);
3881
+ try {
3882
+ const digest = keccak256(serialize2(tx));
3883
+ tx.from = recoverAddress(digest, { r: tx.r, s: tx.s, recoveryParam: tx.v });
3884
+ } catch (error) {
3885
+ }
3886
+ }
3887
+ function _parseEip1559(payload) {
3888
+ const transaction = decode(payload.slice(1));
3889
+ if (transaction.length !== 9 && transaction.length !== 12) {
3890
+ logger.throwArgumentError("invalid component count for transaction type: 2", "payload", hexlify(payload));
3891
+ }
3892
+ const maxPriorityFeePerGas = handleNumber(transaction[2]);
3893
+ const maxFeePerGas = handleNumber(transaction[3]);
3894
+ const tx = {
3895
+ type: 2,
3896
+ chainId: handleNumber(transaction[0]).toNumber(),
3897
+ nonce: handleNumber(transaction[1]).toNumber(),
3898
+ maxPriorityFeePerGas,
3899
+ maxFeePerGas,
3900
+ gasPrice: null,
3901
+ gasLimit: handleNumber(transaction[4]),
3902
+ to: handleAddress(transaction[5]),
3903
+ value: handleNumber(transaction[6]),
3904
+ data: transaction[7],
3905
+ accessList: accessListify(transaction[8])
3906
+ };
3907
+ if (transaction.length === 9) {
3908
+ return tx;
3909
+ }
3910
+ tx.hash = keccak256(payload);
3911
+ _parseEipSignature(tx, transaction.slice(9), _serializeEip1559);
3912
+ return tx;
3913
+ }
3914
+ function _parseEip2930(payload) {
3915
+ const transaction = decode(payload.slice(1));
3916
+ if (transaction.length !== 8 && transaction.length !== 11) {
3917
+ logger.throwArgumentError("invalid component count for transaction type: 1", "payload", hexlify(payload));
3918
+ }
3919
+ const tx = {
3920
+ type: 1,
3921
+ chainId: handleNumber(transaction[0]).toNumber(),
3922
+ nonce: handleNumber(transaction[1]).toNumber(),
3923
+ gasPrice: handleNumber(transaction[2]),
3924
+ gasLimit: handleNumber(transaction[3]),
3925
+ to: handleAddress(transaction[4]),
3926
+ value: handleNumber(transaction[5]),
3927
+ data: transaction[6],
3928
+ accessList: accessListify(transaction[7])
3929
+ };
3930
+ if (transaction.length === 8) {
3931
+ return tx;
3932
+ }
3933
+ tx.hash = keccak256(payload);
3934
+ _parseEipSignature(tx, transaction.slice(8), _serializeEip2930);
3935
+ return tx;
3936
+ }
3937
+ function _parse(rawTransaction) {
3938
+ const transaction = decode(rawTransaction);
3939
+ if (transaction.length !== 9 && transaction.length !== 6) {
3940
+ logger.throwArgumentError("invalid raw transaction", "rawTransaction", rawTransaction);
3941
+ }
3942
+ const tx = {
3943
+ nonce: handleNumber(transaction[0]).toNumber(),
3944
+ gasPrice: handleNumber(transaction[1]),
3945
+ gasLimit: handleNumber(transaction[2]),
3946
+ to: handleAddress(transaction[3]),
3947
+ value: handleNumber(transaction[4]),
3948
+ data: transaction[5],
3949
+ chainId: 0
3950
+ };
3951
+ if (transaction.length === 6) {
3952
+ return tx;
3953
+ }
3954
+ try {
3955
+ tx.v = BigNumber.from(transaction[6]).toNumber();
3956
+ } catch (error) {
3957
+ return tx;
3958
+ }
3959
+ tx.r = hexZeroPad(transaction[7], 32);
3960
+ tx.s = hexZeroPad(transaction[8], 32);
3961
+ if (BigNumber.from(tx.r).isZero() && BigNumber.from(tx.s).isZero()) {
3962
+ tx.chainId = tx.v;
3963
+ tx.v = 0;
3964
+ } else {
3965
+ tx.chainId = Math.floor((tx.v - 35) / 2);
3966
+ if (tx.chainId < 0) {
3967
+ tx.chainId = 0;
3968
+ }
3969
+ let recoveryParam = tx.v - 27;
3970
+ const raw = transaction.slice(0, 6);
3971
+ if (tx.chainId !== 0) {
3972
+ raw.push(hexlify(tx.chainId));
3973
+ raw.push("0x");
3974
+ raw.push("0x");
3975
+ recoveryParam -= tx.chainId * 2 + 8;
3976
+ }
3977
+ const digest = keccak256(encode(raw));
3978
+ try {
3979
+ tx.from = recoverAddress(digest, { r: hexlify(tx.r), s: hexlify(tx.s), recoveryParam });
3980
+ } catch (error) {
3981
+ }
3982
+ tx.hash = keccak256(rawTransaction);
3983
+ }
3984
+ tx.type = null;
3985
+ return tx;
3986
+ }
3987
+ function parse(rawTransaction) {
3988
+ const payload = arrayify(rawTransaction);
3989
+ if (payload[0] > 127) {
3990
+ return _parse(payload);
3991
+ }
3992
+ switch (payload[0]) {
3993
+ case 1:
3994
+ return _parseEip2930(payload);
3995
+ case 2:
3996
+ return _parseEip1559(payload);
3997
+ }
3998
+ return logger.throwError(`unsupported transaction type: ${payload[0]}`, Logger.errors.UNSUPPORTED_OPERATION, {
3999
+ operation: "parseTransaction",
4000
+ transactionType: payload[0]
4001
+ });
4002
+ }
4003
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4004
+ __proto__: null,
4005
+ get TransactionTypes() {
4006
+ return TransactionTypes;
4007
+ },
4008
+ accessListify,
4009
+ computeAddress,
4010
+ parse,
4011
+ recoverAddress,
4012
+ serialize
4013
+ }, Symbol.toStringTag, { value: "Module" }));
4014
+ export {
4015
+ accessListify as a,
4016
+ hash as h,
4017
+ index as i,
4018
+ parse as p
4019
+ };
4020
+ //# sourceMappingURL=index-CnVGoVpH.js.map