@solana/web3.js 1.53.0 → 1.55.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 (39) hide show
  1. package/lib/index.browser.cjs.js +459 -1825
  2. package/lib/index.browser.cjs.js.map +1 -1
  3. package/lib/index.browser.esm.js +455 -1826
  4. package/lib/index.browser.esm.js.map +1 -1
  5. package/lib/index.cjs.js +462 -1847
  6. package/lib/index.cjs.js.map +1 -1
  7. package/lib/index.d.ts +114 -12
  8. package/lib/index.esm.js +458 -1848
  9. package/lib/index.esm.js.map +1 -1
  10. package/lib/index.iife.js +19272 -25771
  11. package/lib/index.iife.js.map +1 -1
  12. package/lib/index.iife.min.js +8 -5
  13. package/lib/index.iife.min.js.map +1 -1
  14. package/lib/index.native.js +459 -1824
  15. package/lib/index.native.js.map +1 -1
  16. package/package.json +5 -7
  17. package/src/account.ts +18 -9
  18. package/src/connection.ts +11 -9
  19. package/src/keypair.ts +19 -24
  20. package/src/layout.ts +7 -0
  21. package/src/message/index.ts +19 -6
  22. package/src/message/legacy.ts +58 -9
  23. package/src/message/v0.ts +324 -0
  24. package/src/message/versioned.ts +36 -0
  25. package/src/programs/ed25519.ts +2 -2
  26. package/src/programs/secp256k1.ts +6 -5
  27. package/src/programs/vote.ts +21 -0
  28. package/src/publickey.ts +14 -73
  29. package/src/transaction/constants.ts +2 -0
  30. package/src/transaction/index.ts +1 -0
  31. package/src/transaction/legacy.ts +3 -5
  32. package/src/transaction/versioned.ts +105 -0
  33. package/src/utils/ed25519.ts +46 -0
  34. package/src/utils/index.ts +1 -0
  35. package/src/utils/makeWebsocketUrl.ts +22 -16
  36. package/src/utils/secp256k1.ts +18 -0
  37. package/src/validator-info.ts +3 -5
  38. package/src/utils/__forks__/react-native/url-impl.ts +0 -2
  39. package/src/utils/url-impl.ts +0 -2
@@ -1,1732 +1,64 @@
1
- import nacl from 'tweetnacl';
2
1
  import { Buffer } from 'buffer';
2
+ import { sha512 } from '@noble/hashes/sha512';
3
+ import * as ed25519 from '@noble/ed25519';
3
4
  import BN from 'bn.js';
4
5
  import bs58 from 'bs58';
6
+ import { sha256 } from '@noble/hashes/sha256';
5
7
  import { serialize, deserialize, deserializeUnchecked } from 'borsh';
6
8
  import * as BufferLayout from '@solana/buffer-layout';
7
9
  import { blob } from '@solana/buffer-layout';
8
10
  import { toBigIntLE, toBufferLE } from 'bigint-buffer';
9
- import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
11
+ import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$1 } from 'superstruct';
10
12
  import { Client } from 'rpc-websockets';
11
13
  import RpcClient from 'jayson/lib/client/browser';
12
- import secp256k1 from 'secp256k1';
13
14
  import sha3 from 'js-sha3';
15
+ import { hmac } from '@noble/hashes/hmac';
16
+ import * as secp256k1 from '@noble/secp256k1';
14
17
 
15
- const toBuffer = arr => {
16
- if (Buffer.isBuffer(arr)) {
17
- return arr;
18
- } else if (arr instanceof Uint8Array) {
19
- return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
20
- } else {
21
- return Buffer.from(arr);
22
- }
23
- };
24
-
25
- var hash$1 = {};
26
-
27
- var utils$9 = {};
28
-
29
- var minimalisticAssert = assert$6;
18
+ /**
19
+ * A 64 byte secret key, the first 32 bytes of which is the
20
+ * private scalar and the last 32 bytes is the public key.
21
+ * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
22
+ */
30
23
 
31
- function assert$6(val, msg) {
32
- if (!val)
33
- throw new Error(msg || 'Assertion failed');
34
- }
24
+ ed25519.utils.sha512Sync = (...m) => sha512(ed25519.utils.concatBytes(...m));
35
25
 
36
- assert$6.equal = function assertEqual(l, r, msg) {
37
- if (l != r)
38
- throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
39
- };
40
-
41
- var inherits_browser = {exports: {}};
42
-
43
- if (typeof Object.create === 'function') {
44
- // implementation from standard node.js 'util' module
45
- inherits_browser.exports = function inherits(ctor, superCtor) {
46
- if (superCtor) {
47
- ctor.super_ = superCtor;
48
- ctor.prototype = Object.create(superCtor.prototype, {
49
- constructor: {
50
- value: ctor,
51
- enumerable: false,
52
- writable: true,
53
- configurable: true
54
- }
55
- });
56
- }
57
- };
58
- } else {
59
- // old school shim for old browsers
60
- inherits_browser.exports = function inherits(ctor, superCtor) {
61
- if (superCtor) {
62
- ctor.super_ = superCtor;
63
- var TempCtor = function () {};
64
- TempCtor.prototype = superCtor.prototype;
65
- ctor.prototype = new TempCtor();
66
- ctor.prototype.constructor = ctor;
67
- }
26
+ const generatePrivateKey = ed25519.utils.randomPrivateKey;
27
+ const generateKeypair = () => {
28
+ const privateScalar = ed25519.utils.randomPrivateKey();
29
+ const publicKey = getPublicKey(privateScalar);
30
+ const secretKey = new Uint8Array(64);
31
+ secretKey.set(privateScalar);
32
+ secretKey.set(publicKey, 32);
33
+ return {
34
+ publicKey,
35
+ secretKey
68
36
  };
69
- }
70
-
71
- var assert$5 = minimalisticAssert;
72
- var inherits = inherits_browser.exports;
73
-
74
- utils$9.inherits = inherits;
75
-
76
- function isSurrogatePair(msg, i) {
77
- if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
78
- return false;
79
- }
80
- if (i < 0 || i + 1 >= msg.length) {
37
+ };
38
+ const getPublicKey = ed25519.sync.getPublicKey;
39
+ function isOnCurve(publicKey) {
40
+ try {
41
+ ed25519.Point.fromHex(publicKey, true
42
+ /* strict */
43
+ );
44
+ return true;
45
+ } catch {
81
46
  return false;
82
47
  }
83
- return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
84
- }
85
-
86
- function toArray(msg, enc) {
87
- if (Array.isArray(msg))
88
- return msg.slice();
89
- if (!msg)
90
- return [];
91
- var res = [];
92
- if (typeof msg === 'string') {
93
- if (!enc) {
94
- // Inspired by stringToUtf8ByteArray() in closure-library by Google
95
- // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
96
- // Apache License 2.0
97
- // https://github.com/google/closure-library/blob/master/LICENSE
98
- var p = 0;
99
- for (var i = 0; i < msg.length; i++) {
100
- var c = msg.charCodeAt(i);
101
- if (c < 128) {
102
- res[p++] = c;
103
- } else if (c < 2048) {
104
- res[p++] = (c >> 6) | 192;
105
- res[p++] = (c & 63) | 128;
106
- } else if (isSurrogatePair(msg, i)) {
107
- c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
108
- res[p++] = (c >> 18) | 240;
109
- res[p++] = ((c >> 12) & 63) | 128;
110
- res[p++] = ((c >> 6) & 63) | 128;
111
- res[p++] = (c & 63) | 128;
112
- } else {
113
- res[p++] = (c >> 12) | 224;
114
- res[p++] = ((c >> 6) & 63) | 128;
115
- res[p++] = (c & 63) | 128;
116
- }
117
- }
118
- } else if (enc === 'hex') {
119
- msg = msg.replace(/[^a-z0-9]+/ig, '');
120
- if (msg.length % 2 !== 0)
121
- msg = '0' + msg;
122
- for (i = 0; i < msg.length; i += 2)
123
- res.push(parseInt(msg[i] + msg[i + 1], 16));
124
- }
125
- } else {
126
- for (i = 0; i < msg.length; i++)
127
- res[i] = msg[i] | 0;
128
- }
129
- return res;
130
- }
131
- utils$9.toArray = toArray;
132
-
133
- function toHex(msg) {
134
- var res = '';
135
- for (var i = 0; i < msg.length; i++)
136
- res += zero2(msg[i].toString(16));
137
- return res;
138
- }
139
- utils$9.toHex = toHex;
140
-
141
- function htonl(w) {
142
- var res = (w >>> 24) |
143
- ((w >>> 8) & 0xff00) |
144
- ((w << 8) & 0xff0000) |
145
- ((w & 0xff) << 24);
146
- return res >>> 0;
147
- }
148
- utils$9.htonl = htonl;
149
-
150
- function toHex32(msg, endian) {
151
- var res = '';
152
- for (var i = 0; i < msg.length; i++) {
153
- var w = msg[i];
154
- if (endian === 'little')
155
- w = htonl(w);
156
- res += zero8(w.toString(16));
157
- }
158
- return res;
159
- }
160
- utils$9.toHex32 = toHex32;
161
-
162
- function zero2(word) {
163
- if (word.length === 1)
164
- return '0' + word;
165
- else
166
- return word;
167
- }
168
- utils$9.zero2 = zero2;
169
-
170
- function zero8(word) {
171
- if (word.length === 7)
172
- return '0' + word;
173
- else if (word.length === 6)
174
- return '00' + word;
175
- else if (word.length === 5)
176
- return '000' + word;
177
- else if (word.length === 4)
178
- return '0000' + word;
179
- else if (word.length === 3)
180
- return '00000' + word;
181
- else if (word.length === 2)
182
- return '000000' + word;
183
- else if (word.length === 1)
184
- return '0000000' + word;
185
- else
186
- return word;
187
- }
188
- utils$9.zero8 = zero8;
189
-
190
- function join32(msg, start, end, endian) {
191
- var len = end - start;
192
- assert$5(len % 4 === 0);
193
- var res = new Array(len / 4);
194
- for (var i = 0, k = start; i < res.length; i++, k += 4) {
195
- var w;
196
- if (endian === 'big')
197
- w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
198
- else
199
- w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
200
- res[i] = w >>> 0;
201
- }
202
- return res;
203
- }
204
- utils$9.join32 = join32;
205
-
206
- function split32(msg, endian) {
207
- var res = new Array(msg.length * 4);
208
- for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
209
- var m = msg[i];
210
- if (endian === 'big') {
211
- res[k] = m >>> 24;
212
- res[k + 1] = (m >>> 16) & 0xff;
213
- res[k + 2] = (m >>> 8) & 0xff;
214
- res[k + 3] = m & 0xff;
215
- } else {
216
- res[k + 3] = m >>> 24;
217
- res[k + 2] = (m >>> 16) & 0xff;
218
- res[k + 1] = (m >>> 8) & 0xff;
219
- res[k] = m & 0xff;
220
- }
221
- }
222
- return res;
223
- }
224
- utils$9.split32 = split32;
225
-
226
- function rotr32$1(w, b) {
227
- return (w >>> b) | (w << (32 - b));
228
- }
229
- utils$9.rotr32 = rotr32$1;
230
-
231
- function rotl32$2(w, b) {
232
- return (w << b) | (w >>> (32 - b));
233
- }
234
- utils$9.rotl32 = rotl32$2;
235
-
236
- function sum32$3(a, b) {
237
- return (a + b) >>> 0;
238
48
  }
239
- utils$9.sum32 = sum32$3;
49
+ const sign = (message, secretKey) => ed25519.sync.sign(message, secretKey.slice(0, 32));
50
+ const verify = ed25519.sync.verify;
240
51
 
241
- function sum32_3$1(a, b, c) {
242
- return (a + b + c) >>> 0;
243
- }
244
- utils$9.sum32_3 = sum32_3$1;
245
-
246
- function sum32_4$2(a, b, c, d) {
247
- return (a + b + c + d) >>> 0;
248
- }
249
- utils$9.sum32_4 = sum32_4$2;
250
-
251
- function sum32_5$2(a, b, c, d, e) {
252
- return (a + b + c + d + e) >>> 0;
253
- }
254
- utils$9.sum32_5 = sum32_5$2;
255
-
256
- function sum64$1(buf, pos, ah, al) {
257
- var bh = buf[pos];
258
- var bl = buf[pos + 1];
259
-
260
- var lo = (al + bl) >>> 0;
261
- var hi = (lo < al ? 1 : 0) + ah + bh;
262
- buf[pos] = hi >>> 0;
263
- buf[pos + 1] = lo;
264
- }
265
- utils$9.sum64 = sum64$1;
266
-
267
- function sum64_hi$1(ah, al, bh, bl) {
268
- var lo = (al + bl) >>> 0;
269
- var hi = (lo < al ? 1 : 0) + ah + bh;
270
- return hi >>> 0;
271
- }
272
- utils$9.sum64_hi = sum64_hi$1;
273
-
274
- function sum64_lo$1(ah, al, bh, bl) {
275
- var lo = al + bl;
276
- return lo >>> 0;
277
- }
278
- utils$9.sum64_lo = sum64_lo$1;
279
-
280
- function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
281
- var carry = 0;
282
- var lo = al;
283
- lo = (lo + bl) >>> 0;
284
- carry += lo < al ? 1 : 0;
285
- lo = (lo + cl) >>> 0;
286
- carry += lo < cl ? 1 : 0;
287
- lo = (lo + dl) >>> 0;
288
- carry += lo < dl ? 1 : 0;
289
-
290
- var hi = ah + bh + ch + dh + carry;
291
- return hi >>> 0;
292
- }
293
- utils$9.sum64_4_hi = sum64_4_hi$1;
294
-
295
- function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
296
- var lo = al + bl + cl + dl;
297
- return lo >>> 0;
298
- }
299
- utils$9.sum64_4_lo = sum64_4_lo$1;
300
-
301
- function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
302
- var carry = 0;
303
- var lo = al;
304
- lo = (lo + bl) >>> 0;
305
- carry += lo < al ? 1 : 0;
306
- lo = (lo + cl) >>> 0;
307
- carry += lo < cl ? 1 : 0;
308
- lo = (lo + dl) >>> 0;
309
- carry += lo < dl ? 1 : 0;
310
- lo = (lo + el) >>> 0;
311
- carry += lo < el ? 1 : 0;
312
-
313
- var hi = ah + bh + ch + dh + eh + carry;
314
- return hi >>> 0;
315
- }
316
- utils$9.sum64_5_hi = sum64_5_hi$1;
317
-
318
- function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
319
- var lo = al + bl + cl + dl + el;
320
-
321
- return lo >>> 0;
322
- }
323
- utils$9.sum64_5_lo = sum64_5_lo$1;
324
-
325
- function rotr64_hi$1(ah, al, num) {
326
- var r = (al << (32 - num)) | (ah >>> num);
327
- return r >>> 0;
328
- }
329
- utils$9.rotr64_hi = rotr64_hi$1;
330
-
331
- function rotr64_lo$1(ah, al, num) {
332
- var r = (ah << (32 - num)) | (al >>> num);
333
- return r >>> 0;
334
- }
335
- utils$9.rotr64_lo = rotr64_lo$1;
336
-
337
- function shr64_hi$1(ah, al, num) {
338
- return ah >>> num;
339
- }
340
- utils$9.shr64_hi = shr64_hi$1;
341
-
342
- function shr64_lo$1(ah, al, num) {
343
- var r = (ah << (32 - num)) | (al >>> num);
344
- return r >>> 0;
345
- }
346
- utils$9.shr64_lo = shr64_lo$1;
347
-
348
- var common$5 = {};
349
-
350
- var utils$8 = utils$9;
351
- var assert$4 = minimalisticAssert;
352
-
353
- function BlockHash$4() {
354
- this.pending = null;
355
- this.pendingTotal = 0;
356
- this.blockSize = this.constructor.blockSize;
357
- this.outSize = this.constructor.outSize;
358
- this.hmacStrength = this.constructor.hmacStrength;
359
- this.padLength = this.constructor.padLength / 8;
360
- this.endian = 'big';
361
-
362
- this._delta8 = this.blockSize / 8;
363
- this._delta32 = this.blockSize / 32;
364
- }
365
- common$5.BlockHash = BlockHash$4;
366
-
367
- BlockHash$4.prototype.update = function update(msg, enc) {
368
- // Convert message to array, pad it, and join into 32bit blocks
369
- msg = utils$8.toArray(msg, enc);
370
- if (!this.pending)
371
- this.pending = msg;
372
- else
373
- this.pending = this.pending.concat(msg);
374
- this.pendingTotal += msg.length;
375
-
376
- // Enough data, try updating
377
- if (this.pending.length >= this._delta8) {
378
- msg = this.pending;
379
-
380
- // Process pending data in blocks
381
- var r = msg.length % this._delta8;
382
- this.pending = msg.slice(msg.length - r, msg.length);
383
- if (this.pending.length === 0)
384
- this.pending = null;
385
-
386
- msg = utils$8.join32(msg, 0, msg.length - r, this.endian);
387
- for (var i = 0; i < msg.length; i += this._delta32)
388
- this._update(msg, i, i + this._delta32);
389
- }
390
-
391
- return this;
392
- };
393
-
394
- BlockHash$4.prototype.digest = function digest(enc) {
395
- this.update(this._pad());
396
- assert$4(this.pending === null);
397
-
398
- return this._digest(enc);
399
- };
400
-
401
- BlockHash$4.prototype._pad = function pad() {
402
- var len = this.pendingTotal;
403
- var bytes = this._delta8;
404
- var k = bytes - ((len + this.padLength) % bytes);
405
- var res = new Array(k + this.padLength);
406
- res[0] = 0x80;
407
- for (var i = 1; i < k; i++)
408
- res[i] = 0;
409
-
410
- // Append length
411
- len <<= 3;
412
- if (this.endian === 'big') {
413
- for (var t = 8; t < this.padLength; t++)
414
- res[i++] = 0;
415
-
416
- res[i++] = 0;
417
- res[i++] = 0;
418
- res[i++] = 0;
419
- res[i++] = 0;
420
- res[i++] = (len >>> 24) & 0xff;
421
- res[i++] = (len >>> 16) & 0xff;
422
- res[i++] = (len >>> 8) & 0xff;
423
- res[i++] = len & 0xff;
52
+ const toBuffer = arr => {
53
+ if (Buffer.isBuffer(arr)) {
54
+ return arr;
55
+ } else if (arr instanceof Uint8Array) {
56
+ return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
424
57
  } else {
425
- res[i++] = len & 0xff;
426
- res[i++] = (len >>> 8) & 0xff;
427
- res[i++] = (len >>> 16) & 0xff;
428
- res[i++] = (len >>> 24) & 0xff;
429
- res[i++] = 0;
430
- res[i++] = 0;
431
- res[i++] = 0;
432
- res[i++] = 0;
433
-
434
- for (t = 8; t < this.padLength; t++)
435
- res[i++] = 0;
436
- }
437
-
438
- return res;
439
- };
440
-
441
- var sha = {};
442
-
443
- var common$4 = {};
444
-
445
- var utils$7 = utils$9;
446
- var rotr32 = utils$7.rotr32;
447
-
448
- function ft_1$1(s, x, y, z) {
449
- if (s === 0)
450
- return ch32$1(x, y, z);
451
- if (s === 1 || s === 3)
452
- return p32(x, y, z);
453
- if (s === 2)
454
- return maj32$1(x, y, z);
455
- }
456
- common$4.ft_1 = ft_1$1;
457
-
458
- function ch32$1(x, y, z) {
459
- return (x & y) ^ ((~x) & z);
460
- }
461
- common$4.ch32 = ch32$1;
462
-
463
- function maj32$1(x, y, z) {
464
- return (x & y) ^ (x & z) ^ (y & z);
465
- }
466
- common$4.maj32 = maj32$1;
467
-
468
- function p32(x, y, z) {
469
- return x ^ y ^ z;
470
- }
471
- common$4.p32 = p32;
472
-
473
- function s0_256$1(x) {
474
- return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
475
- }
476
- common$4.s0_256 = s0_256$1;
477
-
478
- function s1_256$1(x) {
479
- return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
480
- }
481
- common$4.s1_256 = s1_256$1;
482
-
483
- function g0_256$1(x) {
484
- return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
485
- }
486
- common$4.g0_256 = g0_256$1;
487
-
488
- function g1_256$1(x) {
489
- return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
490
- }
491
- common$4.g1_256 = g1_256$1;
492
-
493
- var utils$6 = utils$9;
494
- var common$3 = common$5;
495
- var shaCommon$1 = common$4;
496
-
497
- var rotl32$1 = utils$6.rotl32;
498
- var sum32$2 = utils$6.sum32;
499
- var sum32_5$1 = utils$6.sum32_5;
500
- var ft_1 = shaCommon$1.ft_1;
501
- var BlockHash$3 = common$3.BlockHash;
502
-
503
- var sha1_K = [
504
- 0x5A827999, 0x6ED9EBA1,
505
- 0x8F1BBCDC, 0xCA62C1D6
506
- ];
507
-
508
- function SHA1() {
509
- if (!(this instanceof SHA1))
510
- return new SHA1();
511
-
512
- BlockHash$3.call(this);
513
- this.h = [
514
- 0x67452301, 0xefcdab89, 0x98badcfe,
515
- 0x10325476, 0xc3d2e1f0 ];
516
- this.W = new Array(80);
517
- }
518
-
519
- utils$6.inherits(SHA1, BlockHash$3);
520
- var _1 = SHA1;
521
-
522
- SHA1.blockSize = 512;
523
- SHA1.outSize = 160;
524
- SHA1.hmacStrength = 80;
525
- SHA1.padLength = 64;
526
-
527
- SHA1.prototype._update = function _update(msg, start) {
528
- var W = this.W;
529
-
530
- for (var i = 0; i < 16; i++)
531
- W[i] = msg[start + i];
532
-
533
- for(; i < W.length; i++)
534
- W[i] = rotl32$1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
535
-
536
- var a = this.h[0];
537
- var b = this.h[1];
538
- var c = this.h[2];
539
- var d = this.h[3];
540
- var e = this.h[4];
541
-
542
- for (i = 0; i < W.length; i++) {
543
- var s = ~~(i / 20);
544
- var t = sum32_5$1(rotl32$1(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
545
- e = d;
546
- d = c;
547
- c = rotl32$1(b, 30);
548
- b = a;
549
- a = t;
550
- }
551
-
552
- this.h[0] = sum32$2(this.h[0], a);
553
- this.h[1] = sum32$2(this.h[1], b);
554
- this.h[2] = sum32$2(this.h[2], c);
555
- this.h[3] = sum32$2(this.h[3], d);
556
- this.h[4] = sum32$2(this.h[4], e);
557
- };
558
-
559
- SHA1.prototype._digest = function digest(enc) {
560
- if (enc === 'hex')
561
- return utils$6.toHex32(this.h, 'big');
562
- else
563
- return utils$6.split32(this.h, 'big');
564
- };
565
-
566
- var utils$5 = utils$9;
567
- var common$2 = common$5;
568
- var shaCommon = common$4;
569
- var assert$3 = minimalisticAssert;
570
-
571
- var sum32$1 = utils$5.sum32;
572
- var sum32_4$1 = utils$5.sum32_4;
573
- var sum32_5 = utils$5.sum32_5;
574
- var ch32 = shaCommon.ch32;
575
- var maj32 = shaCommon.maj32;
576
- var s0_256 = shaCommon.s0_256;
577
- var s1_256 = shaCommon.s1_256;
578
- var g0_256 = shaCommon.g0_256;
579
- var g1_256 = shaCommon.g1_256;
580
-
581
- var BlockHash$2 = common$2.BlockHash;
582
-
583
- var sha256_K = [
584
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
585
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
586
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
587
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
588
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
589
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
590
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
591
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
592
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
593
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
594
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
595
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
596
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
597
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
598
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
599
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
600
- ];
601
-
602
- function SHA256$1() {
603
- if (!(this instanceof SHA256$1))
604
- return new SHA256$1();
605
-
606
- BlockHash$2.call(this);
607
- this.h = [
608
- 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
609
- 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
610
- ];
611
- this.k = sha256_K;
612
- this.W = new Array(64);
613
- }
614
- utils$5.inherits(SHA256$1, BlockHash$2);
615
- var _256 = SHA256$1;
616
-
617
- SHA256$1.blockSize = 512;
618
- SHA256$1.outSize = 256;
619
- SHA256$1.hmacStrength = 192;
620
- SHA256$1.padLength = 64;
621
-
622
- SHA256$1.prototype._update = function _update(msg, start) {
623
- var W = this.W;
624
-
625
- for (var i = 0; i < 16; i++)
626
- W[i] = msg[start + i];
627
- for (; i < W.length; i++)
628
- W[i] = sum32_4$1(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
629
-
630
- var a = this.h[0];
631
- var b = this.h[1];
632
- var c = this.h[2];
633
- var d = this.h[3];
634
- var e = this.h[4];
635
- var f = this.h[5];
636
- var g = this.h[6];
637
- var h = this.h[7];
638
-
639
- assert$3(this.k.length === W.length);
640
- for (i = 0; i < W.length; i++) {
641
- var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
642
- var T2 = sum32$1(s0_256(a), maj32(a, b, c));
643
- h = g;
644
- g = f;
645
- f = e;
646
- e = sum32$1(d, T1);
647
- d = c;
648
- c = b;
649
- b = a;
650
- a = sum32$1(T1, T2);
651
- }
652
-
653
- this.h[0] = sum32$1(this.h[0], a);
654
- this.h[1] = sum32$1(this.h[1], b);
655
- this.h[2] = sum32$1(this.h[2], c);
656
- this.h[3] = sum32$1(this.h[3], d);
657
- this.h[4] = sum32$1(this.h[4], e);
658
- this.h[5] = sum32$1(this.h[5], f);
659
- this.h[6] = sum32$1(this.h[6], g);
660
- this.h[7] = sum32$1(this.h[7], h);
661
- };
662
-
663
- SHA256$1.prototype._digest = function digest(enc) {
664
- if (enc === 'hex')
665
- return utils$5.toHex32(this.h, 'big');
666
- else
667
- return utils$5.split32(this.h, 'big');
668
- };
669
-
670
- var utils$4 = utils$9;
671
- var SHA256 = _256;
672
-
673
- function SHA224() {
674
- if (!(this instanceof SHA224))
675
- return new SHA224();
676
-
677
- SHA256.call(this);
678
- this.h = [
679
- 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
680
- 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
681
- }
682
- utils$4.inherits(SHA224, SHA256);
683
- var _224 = SHA224;
684
-
685
- SHA224.blockSize = 512;
686
- SHA224.outSize = 224;
687
- SHA224.hmacStrength = 192;
688
- SHA224.padLength = 64;
689
-
690
- SHA224.prototype._digest = function digest(enc) {
691
- // Just truncate output
692
- if (enc === 'hex')
693
- return utils$4.toHex32(this.h.slice(0, 7), 'big');
694
- else
695
- return utils$4.split32(this.h.slice(0, 7), 'big');
696
- };
697
-
698
- var utils$3 = utils$9;
699
- var common$1 = common$5;
700
- var assert$2 = minimalisticAssert;
701
-
702
- var rotr64_hi = utils$3.rotr64_hi;
703
- var rotr64_lo = utils$3.rotr64_lo;
704
- var shr64_hi = utils$3.shr64_hi;
705
- var shr64_lo = utils$3.shr64_lo;
706
- var sum64 = utils$3.sum64;
707
- var sum64_hi = utils$3.sum64_hi;
708
- var sum64_lo = utils$3.sum64_lo;
709
- var sum64_4_hi = utils$3.sum64_4_hi;
710
- var sum64_4_lo = utils$3.sum64_4_lo;
711
- var sum64_5_hi = utils$3.sum64_5_hi;
712
- var sum64_5_lo = utils$3.sum64_5_lo;
713
-
714
- var BlockHash$1 = common$1.BlockHash;
715
-
716
- var sha512_K = [
717
- 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
718
- 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
719
- 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
720
- 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
721
- 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
722
- 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
723
- 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
724
- 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
725
- 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
726
- 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
727
- 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
728
- 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
729
- 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
730
- 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
731
- 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
732
- 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
733
- 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
734
- 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
735
- 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
736
- 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
737
- 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
738
- 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
739
- 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
740
- 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
741
- 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
742
- 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
743
- 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
744
- 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
745
- 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
746
- 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
747
- 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
748
- 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
749
- 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
750
- 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
751
- 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
752
- 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
753
- 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
754
- 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
755
- 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
756
- 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
757
- ];
758
-
759
- function SHA512$1() {
760
- if (!(this instanceof SHA512$1))
761
- return new SHA512$1();
762
-
763
- BlockHash$1.call(this);
764
- this.h = [
765
- 0x6a09e667, 0xf3bcc908,
766
- 0xbb67ae85, 0x84caa73b,
767
- 0x3c6ef372, 0xfe94f82b,
768
- 0xa54ff53a, 0x5f1d36f1,
769
- 0x510e527f, 0xade682d1,
770
- 0x9b05688c, 0x2b3e6c1f,
771
- 0x1f83d9ab, 0xfb41bd6b,
772
- 0x5be0cd19, 0x137e2179 ];
773
- this.k = sha512_K;
774
- this.W = new Array(160);
775
- }
776
- utils$3.inherits(SHA512$1, BlockHash$1);
777
- var _512 = SHA512$1;
778
-
779
- SHA512$1.blockSize = 1024;
780
- SHA512$1.outSize = 512;
781
- SHA512$1.hmacStrength = 192;
782
- SHA512$1.padLength = 128;
783
-
784
- SHA512$1.prototype._prepareBlock = function _prepareBlock(msg, start) {
785
- var W = this.W;
786
-
787
- // 32 x 32bit words
788
- for (var i = 0; i < 32; i++)
789
- W[i] = msg[start + i];
790
- for (; i < W.length; i += 2) {
791
- var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
792
- var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
793
- var c1_hi = W[i - 14]; // i - 7
794
- var c1_lo = W[i - 13];
795
- var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
796
- var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
797
- var c3_hi = W[i - 32]; // i - 16
798
- var c3_lo = W[i - 31];
799
-
800
- W[i] = sum64_4_hi(
801
- c0_hi, c0_lo,
802
- c1_hi, c1_lo,
803
- c2_hi, c2_lo,
804
- c3_hi, c3_lo);
805
- W[i + 1] = sum64_4_lo(
806
- c0_hi, c0_lo,
807
- c1_hi, c1_lo,
808
- c2_hi, c2_lo,
809
- c3_hi, c3_lo);
58
+ return Buffer.from(arr);
810
59
  }
811
60
  };
812
61
 
813
- SHA512$1.prototype._update = function _update(msg, start) {
814
- this._prepareBlock(msg, start);
815
-
816
- var W = this.W;
817
-
818
- var ah = this.h[0];
819
- var al = this.h[1];
820
- var bh = this.h[2];
821
- var bl = this.h[3];
822
- var ch = this.h[4];
823
- var cl = this.h[5];
824
- var dh = this.h[6];
825
- var dl = this.h[7];
826
- var eh = this.h[8];
827
- var el = this.h[9];
828
- var fh = this.h[10];
829
- var fl = this.h[11];
830
- var gh = this.h[12];
831
- var gl = this.h[13];
832
- var hh = this.h[14];
833
- var hl = this.h[15];
834
-
835
- assert$2(this.k.length === W.length);
836
- for (var i = 0; i < W.length; i += 2) {
837
- var c0_hi = hh;
838
- var c0_lo = hl;
839
- var c1_hi = s1_512_hi(eh, el);
840
- var c1_lo = s1_512_lo(eh, el);
841
- var c2_hi = ch64_hi(eh, el, fh, fl, gh);
842
- var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
843
- var c3_hi = this.k[i];
844
- var c3_lo = this.k[i + 1];
845
- var c4_hi = W[i];
846
- var c4_lo = W[i + 1];
847
-
848
- var T1_hi = sum64_5_hi(
849
- c0_hi, c0_lo,
850
- c1_hi, c1_lo,
851
- c2_hi, c2_lo,
852
- c3_hi, c3_lo,
853
- c4_hi, c4_lo);
854
- var T1_lo = sum64_5_lo(
855
- c0_hi, c0_lo,
856
- c1_hi, c1_lo,
857
- c2_hi, c2_lo,
858
- c3_hi, c3_lo,
859
- c4_hi, c4_lo);
860
-
861
- c0_hi = s0_512_hi(ah, al);
862
- c0_lo = s0_512_lo(ah, al);
863
- c1_hi = maj64_hi(ah, al, bh, bl, ch);
864
- c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
865
-
866
- var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
867
- var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
868
-
869
- hh = gh;
870
- hl = gl;
871
-
872
- gh = fh;
873
- gl = fl;
874
-
875
- fh = eh;
876
- fl = el;
877
-
878
- eh = sum64_hi(dh, dl, T1_hi, T1_lo);
879
- el = sum64_lo(dl, dl, T1_hi, T1_lo);
880
-
881
- dh = ch;
882
- dl = cl;
883
-
884
- ch = bh;
885
- cl = bl;
886
-
887
- bh = ah;
888
- bl = al;
889
-
890
- ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
891
- al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
892
- }
893
-
894
- sum64(this.h, 0, ah, al);
895
- sum64(this.h, 2, bh, bl);
896
- sum64(this.h, 4, ch, cl);
897
- sum64(this.h, 6, dh, dl);
898
- sum64(this.h, 8, eh, el);
899
- sum64(this.h, 10, fh, fl);
900
- sum64(this.h, 12, gh, gl);
901
- sum64(this.h, 14, hh, hl);
902
- };
903
-
904
- SHA512$1.prototype._digest = function digest(enc) {
905
- if (enc === 'hex')
906
- return utils$3.toHex32(this.h, 'big');
907
- else
908
- return utils$3.split32(this.h, 'big');
909
- };
910
-
911
- function ch64_hi(xh, xl, yh, yl, zh) {
912
- var r = (xh & yh) ^ ((~xh) & zh);
913
- if (r < 0)
914
- r += 0x100000000;
915
- return r;
916
- }
917
-
918
- function ch64_lo(xh, xl, yh, yl, zh, zl) {
919
- var r = (xl & yl) ^ ((~xl) & zl);
920
- if (r < 0)
921
- r += 0x100000000;
922
- return r;
923
- }
924
-
925
- function maj64_hi(xh, xl, yh, yl, zh) {
926
- var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
927
- if (r < 0)
928
- r += 0x100000000;
929
- return r;
930
- }
931
-
932
- function maj64_lo(xh, xl, yh, yl, zh, zl) {
933
- var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
934
- if (r < 0)
935
- r += 0x100000000;
936
- return r;
937
- }
938
-
939
- function s0_512_hi(xh, xl) {
940
- var c0_hi = rotr64_hi(xh, xl, 28);
941
- var c1_hi = rotr64_hi(xl, xh, 2); // 34
942
- var c2_hi = rotr64_hi(xl, xh, 7); // 39
943
-
944
- var r = c0_hi ^ c1_hi ^ c2_hi;
945
- if (r < 0)
946
- r += 0x100000000;
947
- return r;
948
- }
949
-
950
- function s0_512_lo(xh, xl) {
951
- var c0_lo = rotr64_lo(xh, xl, 28);
952
- var c1_lo = rotr64_lo(xl, xh, 2); // 34
953
- var c2_lo = rotr64_lo(xl, xh, 7); // 39
954
-
955
- var r = c0_lo ^ c1_lo ^ c2_lo;
956
- if (r < 0)
957
- r += 0x100000000;
958
- return r;
959
- }
960
-
961
- function s1_512_hi(xh, xl) {
962
- var c0_hi = rotr64_hi(xh, xl, 14);
963
- var c1_hi = rotr64_hi(xh, xl, 18);
964
- var c2_hi = rotr64_hi(xl, xh, 9); // 41
965
-
966
- var r = c0_hi ^ c1_hi ^ c2_hi;
967
- if (r < 0)
968
- r += 0x100000000;
969
- return r;
970
- }
971
-
972
- function s1_512_lo(xh, xl) {
973
- var c0_lo = rotr64_lo(xh, xl, 14);
974
- var c1_lo = rotr64_lo(xh, xl, 18);
975
- var c2_lo = rotr64_lo(xl, xh, 9); // 41
976
-
977
- var r = c0_lo ^ c1_lo ^ c2_lo;
978
- if (r < 0)
979
- r += 0x100000000;
980
- return r;
981
- }
982
-
983
- function g0_512_hi(xh, xl) {
984
- var c0_hi = rotr64_hi(xh, xl, 1);
985
- var c1_hi = rotr64_hi(xh, xl, 8);
986
- var c2_hi = shr64_hi(xh, xl, 7);
987
-
988
- var r = c0_hi ^ c1_hi ^ c2_hi;
989
- if (r < 0)
990
- r += 0x100000000;
991
- return r;
992
- }
993
-
994
- function g0_512_lo(xh, xl) {
995
- var c0_lo = rotr64_lo(xh, xl, 1);
996
- var c1_lo = rotr64_lo(xh, xl, 8);
997
- var c2_lo = shr64_lo(xh, xl, 7);
998
-
999
- var r = c0_lo ^ c1_lo ^ c2_lo;
1000
- if (r < 0)
1001
- r += 0x100000000;
1002
- return r;
1003
- }
1004
-
1005
- function g1_512_hi(xh, xl) {
1006
- var c0_hi = rotr64_hi(xh, xl, 19);
1007
- var c1_hi = rotr64_hi(xl, xh, 29); // 61
1008
- var c2_hi = shr64_hi(xh, xl, 6);
1009
-
1010
- var r = c0_hi ^ c1_hi ^ c2_hi;
1011
- if (r < 0)
1012
- r += 0x100000000;
1013
- return r;
1014
- }
1015
-
1016
- function g1_512_lo(xh, xl) {
1017
- var c0_lo = rotr64_lo(xh, xl, 19);
1018
- var c1_lo = rotr64_lo(xl, xh, 29); // 61
1019
- var c2_lo = shr64_lo(xh, xl, 6);
1020
-
1021
- var r = c0_lo ^ c1_lo ^ c2_lo;
1022
- if (r < 0)
1023
- r += 0x100000000;
1024
- return r;
1025
- }
1026
-
1027
- var utils$2 = utils$9;
1028
-
1029
- var SHA512 = _512;
1030
-
1031
- function SHA384() {
1032
- if (!(this instanceof SHA384))
1033
- return new SHA384();
1034
-
1035
- SHA512.call(this);
1036
- this.h = [
1037
- 0xcbbb9d5d, 0xc1059ed8,
1038
- 0x629a292a, 0x367cd507,
1039
- 0x9159015a, 0x3070dd17,
1040
- 0x152fecd8, 0xf70e5939,
1041
- 0x67332667, 0xffc00b31,
1042
- 0x8eb44a87, 0x68581511,
1043
- 0xdb0c2e0d, 0x64f98fa7,
1044
- 0x47b5481d, 0xbefa4fa4 ];
1045
- }
1046
- utils$2.inherits(SHA384, SHA512);
1047
- var _384 = SHA384;
1048
-
1049
- SHA384.blockSize = 1024;
1050
- SHA384.outSize = 384;
1051
- SHA384.hmacStrength = 192;
1052
- SHA384.padLength = 128;
1053
-
1054
- SHA384.prototype._digest = function digest(enc) {
1055
- if (enc === 'hex')
1056
- return utils$2.toHex32(this.h.slice(0, 12), 'big');
1057
- else
1058
- return utils$2.split32(this.h.slice(0, 12), 'big');
1059
- };
1060
-
1061
- sha.sha1 = _1;
1062
- sha.sha224 = _224;
1063
- sha.sha256 = _256;
1064
- sha.sha384 = _384;
1065
- sha.sha512 = _512;
1066
-
1067
- var ripemd = {};
1068
-
1069
- var utils$1 = utils$9;
1070
- var common = common$5;
1071
-
1072
- var rotl32 = utils$1.rotl32;
1073
- var sum32 = utils$1.sum32;
1074
- var sum32_3 = utils$1.sum32_3;
1075
- var sum32_4 = utils$1.sum32_4;
1076
- var BlockHash = common.BlockHash;
1077
-
1078
- function RIPEMD160() {
1079
- if (!(this instanceof RIPEMD160))
1080
- return new RIPEMD160();
1081
-
1082
- BlockHash.call(this);
1083
-
1084
- this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
1085
- this.endian = 'little';
1086
- }
1087
- utils$1.inherits(RIPEMD160, BlockHash);
1088
- ripemd.ripemd160 = RIPEMD160;
1089
-
1090
- RIPEMD160.blockSize = 512;
1091
- RIPEMD160.outSize = 160;
1092
- RIPEMD160.hmacStrength = 192;
1093
- RIPEMD160.padLength = 64;
1094
-
1095
- RIPEMD160.prototype._update = function update(msg, start) {
1096
- var A = this.h[0];
1097
- var B = this.h[1];
1098
- var C = this.h[2];
1099
- var D = this.h[3];
1100
- var E = this.h[4];
1101
- var Ah = A;
1102
- var Bh = B;
1103
- var Ch = C;
1104
- var Dh = D;
1105
- var Eh = E;
1106
- for (var j = 0; j < 80; j++) {
1107
- var T = sum32(
1108
- rotl32(
1109
- sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
1110
- s[j]),
1111
- E);
1112
- A = E;
1113
- E = D;
1114
- D = rotl32(C, 10);
1115
- C = B;
1116
- B = T;
1117
- T = sum32(
1118
- rotl32(
1119
- sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
1120
- sh[j]),
1121
- Eh);
1122
- Ah = Eh;
1123
- Eh = Dh;
1124
- Dh = rotl32(Ch, 10);
1125
- Ch = Bh;
1126
- Bh = T;
1127
- }
1128
- T = sum32_3(this.h[1], C, Dh);
1129
- this.h[1] = sum32_3(this.h[2], D, Eh);
1130
- this.h[2] = sum32_3(this.h[3], E, Ah);
1131
- this.h[3] = sum32_3(this.h[4], A, Bh);
1132
- this.h[4] = sum32_3(this.h[0], B, Ch);
1133
- this.h[0] = T;
1134
- };
1135
-
1136
- RIPEMD160.prototype._digest = function digest(enc) {
1137
- if (enc === 'hex')
1138
- return utils$1.toHex32(this.h, 'little');
1139
- else
1140
- return utils$1.split32(this.h, 'little');
1141
- };
1142
-
1143
- function f(j, x, y, z) {
1144
- if (j <= 15)
1145
- return x ^ y ^ z;
1146
- else if (j <= 31)
1147
- return (x & y) | ((~x) & z);
1148
- else if (j <= 47)
1149
- return (x | (~y)) ^ z;
1150
- else if (j <= 63)
1151
- return (x & z) | (y & (~z));
1152
- else
1153
- return x ^ (y | (~z));
1154
- }
1155
-
1156
- function K(j) {
1157
- if (j <= 15)
1158
- return 0x00000000;
1159
- else if (j <= 31)
1160
- return 0x5a827999;
1161
- else if (j <= 47)
1162
- return 0x6ed9eba1;
1163
- else if (j <= 63)
1164
- return 0x8f1bbcdc;
1165
- else
1166
- return 0xa953fd4e;
1167
- }
1168
-
1169
- function Kh(j) {
1170
- if (j <= 15)
1171
- return 0x50a28be6;
1172
- else if (j <= 31)
1173
- return 0x5c4dd124;
1174
- else if (j <= 47)
1175
- return 0x6d703ef3;
1176
- else if (j <= 63)
1177
- return 0x7a6d76e9;
1178
- else
1179
- return 0x00000000;
1180
- }
1181
-
1182
- var r = [
1183
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
1184
- 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
1185
- 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
1186
- 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
1187
- 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
1188
- ];
1189
-
1190
- var rh = [
1191
- 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
1192
- 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
1193
- 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
1194
- 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
1195
- 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
1196
- ];
1197
-
1198
- var s = [
1199
- 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
1200
- 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
1201
- 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
1202
- 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
1203
- 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
1204
- ];
1205
-
1206
- var sh = [
1207
- 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
1208
- 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
1209
- 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
1210
- 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
1211
- 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
1212
- ];
1213
-
1214
- var utils = utils$9;
1215
- var assert$1 = minimalisticAssert;
1216
-
1217
- function Hmac(hash, key, enc) {
1218
- if (!(this instanceof Hmac))
1219
- return new Hmac(hash, key, enc);
1220
- this.Hash = hash;
1221
- this.blockSize = hash.blockSize / 8;
1222
- this.outSize = hash.outSize / 8;
1223
- this.inner = null;
1224
- this.outer = null;
1225
-
1226
- this._init(utils.toArray(key, enc));
1227
- }
1228
- var hmac = Hmac;
1229
-
1230
- Hmac.prototype._init = function init(key) {
1231
- // Shorten key, if needed
1232
- if (key.length > this.blockSize)
1233
- key = new this.Hash().update(key).digest();
1234
- assert$1(key.length <= this.blockSize);
1235
-
1236
- // Add padding to key
1237
- for (var i = key.length; i < this.blockSize; i++)
1238
- key.push(0);
1239
-
1240
- for (i = 0; i < key.length; i++)
1241
- key[i] ^= 0x36;
1242
- this.inner = new this.Hash().update(key);
1243
-
1244
- // 0x36 ^ 0x5c = 0x6a
1245
- for (i = 0; i < key.length; i++)
1246
- key[i] ^= 0x6a;
1247
- this.outer = new this.Hash().update(key);
1248
- };
1249
-
1250
- Hmac.prototype.update = function update(msg, enc) {
1251
- this.inner.update(msg, enc);
1252
- return this;
1253
- };
1254
-
1255
- Hmac.prototype.digest = function digest(enc) {
1256
- this.outer.update(this.inner.digest());
1257
- return this.outer.digest(enc);
1258
- };
1259
-
1260
- (function (exports) {
1261
- var hash = exports;
1262
-
1263
- hash.utils = utils$9;
1264
- hash.common = common$5;
1265
- hash.sha = sha;
1266
- hash.ripemd = ripemd;
1267
- hash.hmac = hmac;
1268
-
1269
- // Proxy hash functions to the main object
1270
- hash.sha1 = hash.sha.sha1;
1271
- hash.sha256 = hash.sha.sha256;
1272
- hash.sha224 = hash.sha.sha224;
1273
- hash.sha384 = hash.sha.sha384;
1274
- hash.sha512 = hash.sha.sha512;
1275
- hash.ripemd160 = hash.ripemd.ripemd160;
1276
- } (hash$1));
1277
-
1278
- var hash = hash$1;
1279
-
1280
- const version$2 = "logger/5.6.0";
1281
-
1282
- let _permanentCensorErrors = false;
1283
- let _censorErrors = false;
1284
- const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
1285
- let _logLevel = LogLevels["default"];
1286
- let _globalLogger = null;
1287
- function _checkNormalize() {
1288
- try {
1289
- const missing = [];
1290
- // Make sure all forms of normalization are supported
1291
- ["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
1292
- try {
1293
- if ("test".normalize(form) !== "test") {
1294
- throw new Error("bad normalize");
1295
- }
1296
- ;
1297
- }
1298
- catch (error) {
1299
- missing.push(form);
1300
- }
1301
- });
1302
- if (missing.length) {
1303
- throw new Error("missing " + missing.join(", "));
1304
- }
1305
- if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
1306
- throw new Error("broken implementation");
1307
- }
1308
- }
1309
- catch (error) {
1310
- return error.message;
1311
- }
1312
- return null;
1313
- }
1314
- const _normalizeError = _checkNormalize();
1315
- var LogLevel;
1316
- (function (LogLevel) {
1317
- LogLevel["DEBUG"] = "DEBUG";
1318
- LogLevel["INFO"] = "INFO";
1319
- LogLevel["WARNING"] = "WARNING";
1320
- LogLevel["ERROR"] = "ERROR";
1321
- LogLevel["OFF"] = "OFF";
1322
- })(LogLevel || (LogLevel = {}));
1323
- var ErrorCode;
1324
- (function (ErrorCode) {
1325
- ///////////////////
1326
- // Generic Errors
1327
- // Unknown Error
1328
- ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
1329
- // Not Implemented
1330
- ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
1331
- // Unsupported Operation
1332
- // - operation
1333
- ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
1334
- // Network Error (i.e. Ethereum Network, such as an invalid chain ID)
1335
- // - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
1336
- ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
1337
- // Some sort of bad response from the server
1338
- ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
1339
- // Timeout
1340
- ErrorCode["TIMEOUT"] = "TIMEOUT";
1341
- ///////////////////
1342
- // Operational Errors
1343
- // Buffer Overrun
1344
- ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
1345
- // Numeric Fault
1346
- // - operation: the operation being executed
1347
- // - fault: the reason this faulted
1348
- ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
1349
- ///////////////////
1350
- // Argument Errors
1351
- // Missing new operator to an object
1352
- // - name: The name of the class
1353
- ErrorCode["MISSING_NEW"] = "MISSING_NEW";
1354
- // Invalid argument (e.g. value is incompatible with type) to a function:
1355
- // - argument: The argument name that was invalid
1356
- // - value: The value of the argument
1357
- ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
1358
- // Missing argument to a function:
1359
- // - count: The number of arguments received
1360
- // - expectedCount: The number of arguments expected
1361
- ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
1362
- // Too many arguments
1363
- // - count: The number of arguments received
1364
- // - expectedCount: The number of arguments expected
1365
- ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
1366
- ///////////////////
1367
- // Blockchain Errors
1368
- // Call exception
1369
- // - transaction: the transaction
1370
- // - address?: the contract address
1371
- // - args?: The arguments passed into the function
1372
- // - method?: The Solidity method signature
1373
- // - errorSignature?: The EIP848 error signature
1374
- // - errorArgs?: The EIP848 error parameters
1375
- // - reason: The reason (only for EIP848 "Error(string)")
1376
- ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
1377
- // Insufficient funds (< value + gasLimit * gasPrice)
1378
- // - transaction: the transaction attempted
1379
- ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
1380
- // Nonce has already been used
1381
- // - transaction: the transaction attempted
1382
- ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
1383
- // The replacement fee for the transaction is too low
1384
- // - transaction: the transaction attempted
1385
- ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
1386
- // The gas limit could not be estimated
1387
- // - transaction: the transaction passed to estimateGas
1388
- ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
1389
- // The transaction was replaced by one with a higher gas price
1390
- // - reason: "cancelled", "replaced" or "repriced"
1391
- // - cancelled: true if reason == "cancelled" or reason == "replaced")
1392
- // - hash: original transaction hash
1393
- // - replacement: the full TransactionsResponse for the replacement
1394
- // - receipt: the receipt of the replacement
1395
- ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
1396
- })(ErrorCode || (ErrorCode = {}));
1397
- const HEX = "0123456789abcdef";
1398
- class Logger {
1399
- constructor(version) {
1400
- Object.defineProperty(this, "version", {
1401
- enumerable: true,
1402
- value: version,
1403
- writable: false
1404
- });
1405
- }
1406
- _log(logLevel, args) {
1407
- const level = logLevel.toLowerCase();
1408
- if (LogLevels[level] == null) {
1409
- this.throwArgumentError("invalid log level name", "logLevel", logLevel);
1410
- }
1411
- if (_logLevel > LogLevels[level]) {
1412
- return;
1413
- }
1414
- console.log.apply(console, args);
1415
- }
1416
- debug(...args) {
1417
- this._log(Logger.levels.DEBUG, args);
1418
- }
1419
- info(...args) {
1420
- this._log(Logger.levels.INFO, args);
1421
- }
1422
- warn(...args) {
1423
- this._log(Logger.levels.WARNING, args);
1424
- }
1425
- makeError(message, code, params) {
1426
- // Errors are being censored
1427
- if (_censorErrors) {
1428
- return this.makeError("censored error", code, {});
1429
- }
1430
- if (!code) {
1431
- code = Logger.errors.UNKNOWN_ERROR;
1432
- }
1433
- if (!params) {
1434
- params = {};
1435
- }
1436
- const messageDetails = [];
1437
- Object.keys(params).forEach((key) => {
1438
- const value = params[key];
1439
- try {
1440
- if (value instanceof Uint8Array) {
1441
- let hex = "";
1442
- for (let i = 0; i < value.length; i++) {
1443
- hex += HEX[value[i] >> 4];
1444
- hex += HEX[value[i] & 0x0f];
1445
- }
1446
- messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
1447
- }
1448
- else {
1449
- messageDetails.push(key + "=" + JSON.stringify(value));
1450
- }
1451
- }
1452
- catch (error) {
1453
- messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
1454
- }
1455
- });
1456
- messageDetails.push(`code=${code}`);
1457
- messageDetails.push(`version=${this.version}`);
1458
- const reason = message;
1459
- let url = "";
1460
- switch (code) {
1461
- case ErrorCode.NUMERIC_FAULT: {
1462
- url = "NUMERIC_FAULT";
1463
- const fault = message;
1464
- switch (fault) {
1465
- case "overflow":
1466
- case "underflow":
1467
- case "division-by-zero":
1468
- url += "-" + fault;
1469
- break;
1470
- case "negative-power":
1471
- case "negative-width":
1472
- url += "-unsupported";
1473
- break;
1474
- case "unbound-bitwise-result":
1475
- url += "-unbound-result";
1476
- break;
1477
- }
1478
- break;
1479
- }
1480
- case ErrorCode.CALL_EXCEPTION:
1481
- case ErrorCode.INSUFFICIENT_FUNDS:
1482
- case ErrorCode.MISSING_NEW:
1483
- case ErrorCode.NONCE_EXPIRED:
1484
- case ErrorCode.REPLACEMENT_UNDERPRICED:
1485
- case ErrorCode.TRANSACTION_REPLACED:
1486
- case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
1487
- url = code;
1488
- break;
1489
- }
1490
- if (url) {
1491
- message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
1492
- }
1493
- if (messageDetails.length) {
1494
- message += " (" + messageDetails.join(", ") + ")";
1495
- }
1496
- // @TODO: Any??
1497
- const error = new Error(message);
1498
- error.reason = reason;
1499
- error.code = code;
1500
- Object.keys(params).forEach(function (key) {
1501
- error[key] = params[key];
1502
- });
1503
- return error;
1504
- }
1505
- throwError(message, code, params) {
1506
- throw this.makeError(message, code, params);
1507
- }
1508
- throwArgumentError(message, name, value) {
1509
- return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
1510
- argument: name,
1511
- value: value
1512
- });
1513
- }
1514
- assert(condition, message, code, params) {
1515
- if (!!condition) {
1516
- return;
1517
- }
1518
- this.throwError(message, code, params);
1519
- }
1520
- assertArgument(condition, message, name, value) {
1521
- if (!!condition) {
1522
- return;
1523
- }
1524
- this.throwArgumentError(message, name, value);
1525
- }
1526
- checkNormalize(message) {
1527
- if (_normalizeError) {
1528
- this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
1529
- operation: "String.prototype.normalize", form: _normalizeError
1530
- });
1531
- }
1532
- }
1533
- checkSafeUint53(value, message) {
1534
- if (typeof (value) !== "number") {
1535
- return;
1536
- }
1537
- if (message == null) {
1538
- message = "value not safe";
1539
- }
1540
- if (value < 0 || value >= 0x1fffffffffffff) {
1541
- this.throwError(message, Logger.errors.NUMERIC_FAULT, {
1542
- operation: "checkSafeInteger",
1543
- fault: "out-of-safe-range",
1544
- value: value
1545
- });
1546
- }
1547
- if (value % 1) {
1548
- this.throwError(message, Logger.errors.NUMERIC_FAULT, {
1549
- operation: "checkSafeInteger",
1550
- fault: "non-integer",
1551
- value: value
1552
- });
1553
- }
1554
- }
1555
- checkArgumentCount(count, expectedCount, message) {
1556
- if (message) {
1557
- message = ": " + message;
1558
- }
1559
- else {
1560
- message = "";
1561
- }
1562
- if (count < expectedCount) {
1563
- this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
1564
- count: count,
1565
- expectedCount: expectedCount
1566
- });
1567
- }
1568
- if (count > expectedCount) {
1569
- this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
1570
- count: count,
1571
- expectedCount: expectedCount
1572
- });
1573
- }
1574
- }
1575
- checkNew(target, kind) {
1576
- if (target === Object || target == null) {
1577
- this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
1578
- }
1579
- }
1580
- checkAbstract(target, kind) {
1581
- if (target === kind) {
1582
- this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
1583
- }
1584
- else if (target === Object || target == null) {
1585
- this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
1586
- }
1587
- }
1588
- static globalLogger() {
1589
- if (!_globalLogger) {
1590
- _globalLogger = new Logger(version$2);
1591
- }
1592
- return _globalLogger;
1593
- }
1594
- static setCensorship(censorship, permanent) {
1595
- if (!censorship && permanent) {
1596
- this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
1597
- operation: "setCensorship"
1598
- });
1599
- }
1600
- if (_permanentCensorErrors) {
1601
- if (!censorship) {
1602
- return;
1603
- }
1604
- this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
1605
- operation: "setCensorship"
1606
- });
1607
- }
1608
- _censorErrors = !!censorship;
1609
- _permanentCensorErrors = !!permanent;
1610
- }
1611
- static setLogLevel(logLevel) {
1612
- const level = LogLevels[logLevel.toLowerCase()];
1613
- if (level == null) {
1614
- Logger.globalLogger().warn("invalid log level - " + logLevel);
1615
- return;
1616
- }
1617
- _logLevel = level;
1618
- }
1619
- static from(version) {
1620
- return new Logger(version);
1621
- }
1622
- }
1623
- Logger.errors = ErrorCode;
1624
- Logger.levels = LogLevel;
1625
-
1626
- const version$1 = "bytes/5.6.0";
1627
-
1628
- const logger = new Logger(version$1);
1629
- ///////////////////////////////
1630
- function isHexable(value) {
1631
- return !!(value.toHexString);
1632
- }
1633
- function addSlice(array) {
1634
- if (array.slice) {
1635
- return array;
1636
- }
1637
- array.slice = function () {
1638
- const args = Array.prototype.slice.call(arguments);
1639
- return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
1640
- };
1641
- return array;
1642
- }
1643
- function isInteger(value) {
1644
- return (typeof (value) === "number" && value == value && (value % 1) === 0);
1645
- }
1646
- function isBytes(value) {
1647
- if (value == null) {
1648
- return false;
1649
- }
1650
- if (value.constructor === Uint8Array) {
1651
- return true;
1652
- }
1653
- if (typeof (value) === "string") {
1654
- return false;
1655
- }
1656
- if (!isInteger(value.length) || value.length < 0) {
1657
- return false;
1658
- }
1659
- for (let i = 0; i < value.length; i++) {
1660
- const v = value[i];
1661
- if (!isInteger(v) || v < 0 || v >= 256) {
1662
- return false;
1663
- }
1664
- }
1665
- return true;
1666
- }
1667
- function arrayify(value, options) {
1668
- if (!options) {
1669
- options = {};
1670
- }
1671
- if (typeof (value) === "number") {
1672
- logger.checkSafeUint53(value, "invalid arrayify value");
1673
- const result = [];
1674
- while (value) {
1675
- result.unshift(value & 0xff);
1676
- value = parseInt(String(value / 256));
1677
- }
1678
- if (result.length === 0) {
1679
- result.push(0);
1680
- }
1681
- return addSlice(new Uint8Array(result));
1682
- }
1683
- if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
1684
- value = "0x" + value;
1685
- }
1686
- if (isHexable(value)) {
1687
- value = value.toHexString();
1688
- }
1689
- if (isHexString(value)) {
1690
- let hex = value.substring(2);
1691
- if (hex.length % 2) {
1692
- if (options.hexPad === "left") {
1693
- hex = "0x0" + hex.substring(2);
1694
- }
1695
- else if (options.hexPad === "right") {
1696
- hex += "0";
1697
- }
1698
- else {
1699
- logger.throwArgumentError("hex data is odd-length", "value", value);
1700
- }
1701
- }
1702
- const result = [];
1703
- for (let i = 0; i < hex.length; i += 2) {
1704
- result.push(parseInt(hex.substring(i, i + 2), 16));
1705
- }
1706
- return addSlice(new Uint8Array(result));
1707
- }
1708
- if (isBytes(value)) {
1709
- return addSlice(new Uint8Array(value));
1710
- }
1711
- return logger.throwArgumentError("invalid arrayify value", "value", value);
1712
- }
1713
- function isHexString(value, length) {
1714
- if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
1715
- return false;
1716
- }
1717
- if (length && value.length !== 2 + 2 * length) {
1718
- return false;
1719
- }
1720
- return true;
1721
- }
1722
-
1723
- const version = "sha2/5.6.0";
1724
-
1725
- new Logger(version);
1726
- function sha256(data) {
1727
- return "0x" + (hash.sha256().update(arrayify(data)).digest("hex"));
1728
- }
1729
-
1730
62
  class Struct {
1731
63
  constructor(properties) {
1732
64
  Object.assign(this, properties);
@@ -1769,6 +101,11 @@ const SOLANA_SCHEMA = new Map();
1769
101
  */
1770
102
 
1771
103
  const MAX_SEED_LENGTH = 32;
104
+ /**
105
+ * Size of public key in bytes
106
+ */
107
+
108
+ const PUBLIC_KEY_LENGTH = 32;
1772
109
  /**
1773
110
  * Value to be converted into public key
1774
111
  */
@@ -1799,7 +136,7 @@ class PublicKey extends Struct {
1799
136
  // assume base 58 encoding by default
1800
137
  const decoded = bs58.decode(value);
1801
138
 
1802
- if (decoded.length != 32) {
139
+ if (decoded.length != PUBLIC_KEY_LENGTH) {
1803
140
  throw new Error(`Invalid public key input`);
1804
141
  }
1805
142
 
@@ -1852,7 +189,7 @@ class PublicKey extends Struct {
1852
189
  toBuffer() {
1853
190
  const b = this._bn.toArrayLike(Buffer);
1854
191
 
1855
- if (b.length === 32) {
192
+ if (b.length === PUBLIC_KEY_LENGTH) {
1856
193
  return b;
1857
194
  }
1858
195
 
@@ -1879,8 +216,8 @@ class PublicKey extends Struct {
1879
216
 
1880
217
  static async createWithSeed(fromPublicKey, seed, programId) {
1881
218
  const buffer = Buffer.concat([fromPublicKey.toBuffer(), Buffer.from(seed), programId.toBuffer()]);
1882
- const hash = sha256(new Uint8Array(buffer)).slice(2);
1883
- return new PublicKey(Buffer.from(hash, 'hex'));
219
+ const publicKeyBytes = sha256(buffer);
220
+ return new PublicKey(publicKeyBytes);
1884
221
  }
1885
222
  /**
1886
223
  * Derive a program address from seeds and a program ID.
@@ -1899,10 +236,9 @@ class PublicKey extends Struct {
1899
236
  buffer = Buffer.concat([buffer, toBuffer(seed)]);
1900
237
  });
1901
238
  buffer = Buffer.concat([buffer, programId.toBuffer(), Buffer.from('ProgramDerivedAddress')]);
1902
- let hash = sha256(new Uint8Array(buffer)).slice(2);
1903
- let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
239
+ const publicKeyBytes = sha256(buffer);
1904
240
 
1905
- if (is_on_curve(publicKeyBytes)) {
241
+ if (isOnCurve(publicKeyBytes)) {
1906
242
  throw new Error(`Invalid seeds, address must fall off the curve`);
1907
243
  }
1908
244
 
@@ -1966,7 +302,7 @@ class PublicKey extends Struct {
1966
302
 
1967
303
  static isOnCurve(pubkeyData) {
1968
304
  const pubkey = new PublicKey(pubkeyData);
1969
- return is_on_curve(pubkey.toBytes()) == 1;
305
+ return isOnCurve(pubkey.toBytes());
1970
306
  }
1971
307
 
1972
308
  }
@@ -1974,56 +310,7 @@ PublicKey.default = new PublicKey('11111111111111111111111111111111');
1974
310
  SOLANA_SCHEMA.set(PublicKey, {
1975
311
  kind: 'struct',
1976
312
  fields: [['_bn', 'u256']]
1977
- }); // @ts-ignore
1978
-
1979
- let naclLowLevel = nacl.lowlevel; // Check that a pubkey is on the curve.
1980
- // This function and its dependents were sourced from:
1981
- // https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
1982
-
1983
- function is_on_curve(p) {
1984
- var r = [naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf()];
1985
- var t = naclLowLevel.gf(),
1986
- chk = naclLowLevel.gf(),
1987
- num = naclLowLevel.gf(),
1988
- den = naclLowLevel.gf(),
1989
- den2 = naclLowLevel.gf(),
1990
- den4 = naclLowLevel.gf(),
1991
- den6 = naclLowLevel.gf();
1992
- naclLowLevel.set25519(r[2], gf1);
1993
- naclLowLevel.unpack25519(r[1], p);
1994
- naclLowLevel.S(num, r[1]);
1995
- naclLowLevel.M(den, num, naclLowLevel.D);
1996
- naclLowLevel.Z(num, num, r[2]);
1997
- naclLowLevel.A(den, r[2], den);
1998
- naclLowLevel.S(den2, den);
1999
- naclLowLevel.S(den4, den2);
2000
- naclLowLevel.M(den6, den4, den2);
2001
- naclLowLevel.M(t, den6, num);
2002
- naclLowLevel.M(t, t, den);
2003
- naclLowLevel.pow2523(t, t);
2004
- naclLowLevel.M(t, t, num);
2005
- naclLowLevel.M(t, t, den);
2006
- naclLowLevel.M(t, t, den);
2007
- naclLowLevel.M(r[0], t, den);
2008
- naclLowLevel.S(chk, r[0]);
2009
- naclLowLevel.M(chk, chk, den);
2010
- if (neq25519(chk, num)) naclLowLevel.M(r[0], r[0], I);
2011
- naclLowLevel.S(chk, r[0]);
2012
- naclLowLevel.M(chk, chk, den);
2013
- if (neq25519(chk, num)) return 0;
2014
- return 1;
2015
- }
2016
-
2017
- let gf1 = naclLowLevel.gf([1]);
2018
- let I = naclLowLevel.gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
2019
-
2020
- function neq25519(a, b) {
2021
- var c = new Uint8Array(32),
2022
- d = new Uint8Array(32);
2023
- naclLowLevel.pack25519(c, a);
2024
- naclLowLevel.pack25519(d, b);
2025
- return naclLowLevel.crypto_verify_32(c, 0, d, 0);
2026
- }
313
+ });
2027
314
 
2028
315
  /**
2029
316
  * An account key pair (public and secret keys).
@@ -2034,6 +321,8 @@ function neq25519(a, b) {
2034
321
  class Account {
2035
322
  /** @internal */
2036
323
 
324
+ /** @internal */
325
+
2037
326
  /**
2038
327
  * Create a new Account object
2039
328
  *
@@ -2043,12 +332,21 @@ class Account {
2043
332
  * @param secretKey Secret key for the account
2044
333
  */
2045
334
  constructor(secretKey) {
2046
- this._keypair = void 0;
335
+ this._publicKey = void 0;
336
+ this._secretKey = void 0;
2047
337
 
2048
338
  if (secretKey) {
2049
- this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
339
+ const secretKeyBuffer = toBuffer(secretKey);
340
+
341
+ if (secretKey.length !== 64) {
342
+ throw new Error('bad secret key size');
343
+ }
344
+
345
+ this._publicKey = secretKeyBuffer.slice(32, 64);
346
+ this._secretKey = secretKeyBuffer.slice(0, 32);
2050
347
  } else {
2051
- this._keypair = nacl.sign.keyPair();
348
+ this._secretKey = toBuffer(generatePrivateKey());
349
+ this._publicKey = toBuffer(getPublicKey(this._secretKey));
2052
350
  }
2053
351
  }
2054
352
  /**
@@ -2057,15 +355,17 @@ class Account {
2057
355
 
2058
356
 
2059
357
  get publicKey() {
2060
- return new PublicKey(this._keypair.publicKey);
358
+ return new PublicKey(this._publicKey);
2061
359
  }
2062
360
  /**
2063
- * The **unencrypted** secret key for this account
361
+ * The **unencrypted** secret key for this account. The first 32 bytes
362
+ * is the private scalar and the last 32 bytes is the public key.
363
+ * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
2064
364
  */
2065
365
 
2066
366
 
2067
367
  get secretKey() {
2068
- return toBuffer(this._keypair.secretKey);
368
+ return Buffer.concat([this._secretKey, this._publicKey], 64);
2069
369
  }
2070
370
 
2071
371
  }
@@ -2080,6 +380,7 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
2080
380
  * 8 bytes is the size of the fragment header
2081
381
  */
2082
382
  const PACKET_DATA_SIZE = 1280 - 40 - 8;
383
+ const VERSION_PREFIX_MASK = 0x7f;
2083
384
  const SIGNATURE_LENGTH_IN_BYTES = 64;
2084
385
 
2085
386
  class TransactionExpiredBlockheightExceededError extends Error {
@@ -2112,6 +413,13 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
2112
413
  const publicKey = (property = 'publicKey') => {
2113
414
  return BufferLayout.blob(32, property);
2114
415
  };
416
+ /**
417
+ * Layout for a signature
418
+ */
419
+
420
+ const signature = (property = 'signature') => {
421
+ return BufferLayout.blob(64, property);
422
+ };
2115
423
 
2116
424
  /**
2117
425
  * Layout for a Rust String type
@@ -2223,11 +531,9 @@ function encodeLength(bytes, len) {
2223
531
  }
2224
532
  }
2225
533
 
2226
- const PUBKEY_LENGTH = 32;
2227
534
  /**
2228
535
  * List of instructions to be processed atomically
2229
536
  */
2230
-
2231
537
  class Message {
2232
538
  constructor(args) {
2233
539
  this.header = void 0;
@@ -2242,6 +548,26 @@ class Message {
2242
548
  this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
2243
549
  }
2244
550
 
551
+ get version() {
552
+ return 'legacy';
553
+ }
554
+
555
+ get staticAccountKeys() {
556
+ return this.accountKeys;
557
+ }
558
+
559
+ get compiledInstructions() {
560
+ return this.instructions.map(ix => ({
561
+ programIdIndex: ix.programIdIndex,
562
+ accountKeyIndexes: ix.accounts,
563
+ data: bs58.decode(ix.data)
564
+ }));
565
+ }
566
+
567
+ get addressTableLookups() {
568
+ return [];
569
+ }
570
+
2245
571
  isAccountSigner(index) {
2246
572
  return index < this.header.numRequiredSignatures;
2247
573
  }
@@ -2318,19 +644,24 @@ class Message {
2318
644
  // Slice up wire data
2319
645
  let byteArray = [...buffer];
2320
646
  const numRequiredSignatures = byteArray.shift();
647
+
648
+ if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
649
+ throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
650
+ }
651
+
2321
652
  const numReadonlySignedAccounts = byteArray.shift();
2322
653
  const numReadonlyUnsignedAccounts = byteArray.shift();
2323
654
  const accountCount = decodeLength(byteArray);
2324
655
  let accountKeys = [];
2325
656
 
2326
657
  for (let i = 0; i < accountCount; i++) {
2327
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2328
- byteArray = byteArray.slice(PUBKEY_LENGTH);
658
+ const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
659
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2329
660
  accountKeys.push(bs58.encode(Buffer.from(account)));
2330
661
  }
2331
662
 
2332
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2333
- byteArray = byteArray.slice(PUBKEY_LENGTH);
663
+ const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
664
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2334
665
  const instructionCount = decodeLength(byteArray);
2335
666
  let instructions = [];
2336
667
 
@@ -2371,6 +702,194 @@ function assert (condition, message) {
2371
702
  }
2372
703
  }
2373
704
 
705
+ /**
706
+ * Message constructor arguments
707
+ */
708
+
709
+ class MessageV0 {
710
+ constructor(args) {
711
+ this.header = void 0;
712
+ this.staticAccountKeys = void 0;
713
+ this.recentBlockhash = void 0;
714
+ this.compiledInstructions = void 0;
715
+ this.addressTableLookups = void 0;
716
+ this.header = args.header;
717
+ this.staticAccountKeys = args.staticAccountKeys;
718
+ this.recentBlockhash = args.recentBlockhash;
719
+ this.compiledInstructions = args.compiledInstructions;
720
+ this.addressTableLookups = args.addressTableLookups;
721
+ }
722
+
723
+ get version() {
724
+ return 0;
725
+ }
726
+
727
+ serialize() {
728
+ const encodedStaticAccountKeysLength = Array();
729
+ encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
730
+ const serializedInstructions = this.serializeInstructions();
731
+ const encodedInstructionsLength = Array();
732
+ encodeLength(encodedInstructionsLength, this.compiledInstructions.length);
733
+ const serializedAddressTableLookups = this.serializeAddressTableLookups();
734
+ const encodedAddressTableLookupsLength = Array();
735
+ encodeLength(encodedAddressTableLookupsLength, this.addressTableLookups.length);
736
+ const messageLayout = BufferLayout.struct([BufferLayout.u8('prefix'), BufferLayout.struct([BufferLayout.u8('numRequiredSignatures'), BufferLayout.u8('numReadonlySignedAccounts'), BufferLayout.u8('numReadonlyUnsignedAccounts')], 'header'), BufferLayout.blob(encodedStaticAccountKeysLength.length, 'staticAccountKeysLength'), BufferLayout.seq(publicKey(), this.staticAccountKeys.length, 'staticAccountKeys'), publicKey('recentBlockhash'), BufferLayout.blob(encodedInstructionsLength.length, 'instructionsLength'), BufferLayout.blob(serializedInstructions.length, 'serializedInstructions'), BufferLayout.blob(encodedAddressTableLookupsLength.length, 'addressTableLookupsLength'), BufferLayout.blob(serializedAddressTableLookups.length, 'serializedAddressTableLookups')]);
737
+ const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
738
+ const MESSAGE_VERSION_0_PREFIX = 1 << 7;
739
+ const serializedMessageLength = messageLayout.encode({
740
+ prefix: MESSAGE_VERSION_0_PREFIX,
741
+ header: this.header,
742
+ staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
743
+ staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
744
+ recentBlockhash: bs58.decode(this.recentBlockhash),
745
+ instructionsLength: new Uint8Array(encodedInstructionsLength),
746
+ serializedInstructions,
747
+ addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
748
+ serializedAddressTableLookups
749
+ }, serializedMessage);
750
+ return serializedMessage.slice(0, serializedMessageLength);
751
+ }
752
+
753
+ serializeInstructions() {
754
+ let serializedLength = 0;
755
+ const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
756
+
757
+ for (const instruction of this.compiledInstructions) {
758
+ const encodedAccountKeyIndexesLength = Array();
759
+ encodeLength(encodedAccountKeyIndexesLength, instruction.accountKeyIndexes.length);
760
+ const encodedDataLength = Array();
761
+ encodeLength(encodedDataLength, instruction.data.length);
762
+ const instructionLayout = BufferLayout.struct([BufferLayout.u8('programIdIndex'), BufferLayout.blob(encodedAccountKeyIndexesLength.length, 'encodedAccountKeyIndexesLength'), BufferLayout.seq(BufferLayout.u8(), instruction.accountKeyIndexes.length, 'accountKeyIndexes'), BufferLayout.blob(encodedDataLength.length, 'encodedDataLength'), BufferLayout.blob(instruction.data.length, 'data')]);
763
+ serializedLength += instructionLayout.encode({
764
+ programIdIndex: instruction.programIdIndex,
765
+ encodedAccountKeyIndexesLength: new Uint8Array(encodedAccountKeyIndexesLength),
766
+ accountKeyIndexes: instruction.accountKeyIndexes,
767
+ encodedDataLength: new Uint8Array(encodedDataLength),
768
+ data: instruction.data
769
+ }, serializedInstructions, serializedLength);
770
+ }
771
+
772
+ return serializedInstructions.slice(0, serializedLength);
773
+ }
774
+
775
+ serializeAddressTableLookups() {
776
+ let serializedLength = 0;
777
+ const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
778
+
779
+ for (const lookup of this.addressTableLookups) {
780
+ const encodedWritableIndexesLength = Array();
781
+ encodeLength(encodedWritableIndexesLength, lookup.writableIndexes.length);
782
+ const encodedReadonlyIndexesLength = Array();
783
+ encodeLength(encodedReadonlyIndexesLength, lookup.readonlyIndexes.length);
784
+ const addressTableLookupLayout = BufferLayout.struct([publicKey('accountKey'), BufferLayout.blob(encodedWritableIndexesLength.length, 'encodedWritableIndexesLength'), BufferLayout.seq(BufferLayout.u8(), lookup.writableIndexes.length, 'writableIndexes'), BufferLayout.blob(encodedReadonlyIndexesLength.length, 'encodedReadonlyIndexesLength'), BufferLayout.seq(BufferLayout.u8(), lookup.readonlyIndexes.length, 'readonlyIndexes')]);
785
+ serializedLength += addressTableLookupLayout.encode({
786
+ accountKey: lookup.accountKey.toBytes(),
787
+ encodedWritableIndexesLength: new Uint8Array(encodedWritableIndexesLength),
788
+ writableIndexes: lookup.writableIndexes,
789
+ encodedReadonlyIndexesLength: new Uint8Array(encodedReadonlyIndexesLength),
790
+ readonlyIndexes: lookup.readonlyIndexes
791
+ }, serializedAddressTableLookups, serializedLength);
792
+ }
793
+
794
+ return serializedAddressTableLookups.slice(0, serializedLength);
795
+ }
796
+
797
+ static deserialize(serializedMessage) {
798
+ let byteArray = [...serializedMessage];
799
+ const prefix = byteArray.shift();
800
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK;
801
+ assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
802
+ const version = maskedPrefix;
803
+ assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
804
+ const header = {
805
+ numRequiredSignatures: byteArray.shift(),
806
+ numReadonlySignedAccounts: byteArray.shift(),
807
+ numReadonlyUnsignedAccounts: byteArray.shift()
808
+ };
809
+ const staticAccountKeys = [];
810
+ const staticAccountKeysLength = decodeLength(byteArray);
811
+
812
+ for (let i = 0; i < staticAccountKeysLength; i++) {
813
+ staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
814
+ }
815
+
816
+ const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
817
+ const instructionCount = decodeLength(byteArray);
818
+ const compiledInstructions = [];
819
+
820
+ for (let i = 0; i < instructionCount; i++) {
821
+ const programIdIndex = byteArray.shift();
822
+ const accountKeyIndexesLength = decodeLength(byteArray);
823
+ const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
824
+ const dataLength = decodeLength(byteArray);
825
+ const data = new Uint8Array(byteArray.splice(0, dataLength));
826
+ compiledInstructions.push({
827
+ programIdIndex,
828
+ accountKeyIndexes,
829
+ data
830
+ });
831
+ }
832
+
833
+ const addressTableLookupsCount = decodeLength(byteArray);
834
+ const addressTableLookups = [];
835
+
836
+ for (let i = 0; i < addressTableLookupsCount; i++) {
837
+ const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
838
+ const writableIndexesLength = decodeLength(byteArray);
839
+ const writableIndexes = byteArray.splice(0, writableIndexesLength);
840
+ const readonlyIndexesLength = decodeLength(byteArray);
841
+ const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
842
+ addressTableLookups.push({
843
+ accountKey,
844
+ writableIndexes,
845
+ readonlyIndexes
846
+ });
847
+ }
848
+
849
+ return new MessageV0({
850
+ header,
851
+ staticAccountKeys,
852
+ recentBlockhash,
853
+ compiledInstructions,
854
+ addressTableLookups
855
+ });
856
+ }
857
+
858
+ }
859
+
860
+ // eslint-disable-next-line no-redeclare
861
+ const VersionedMessage = {
862
+ deserializeMessageVersion(serializedMessage) {
863
+ const prefix = serializedMessage[0];
864
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
865
+
866
+ if (maskedPrefix === prefix) {
867
+ return 'legacy';
868
+ } // the lower 7 bits of the prefix indicate the message version
869
+
870
+
871
+ return maskedPrefix;
872
+ },
873
+
874
+ deserialize: serializedMessage => {
875
+ const version = VersionedMessage.deserializeMessageVersion(serializedMessage);
876
+
877
+ if (version === 'legacy') {
878
+ return Message.from(serializedMessage);
879
+ }
880
+
881
+ if (version === 0) {
882
+ return MessageV0.deserialize(serializedMessage);
883
+ } else {
884
+ throw new Error(`Transaction message version ${version} deserialization is not supported`);
885
+ }
886
+ }
887
+ };
888
+
889
+ /**
890
+ * Transaction signature as base-58 encoded string
891
+ */
892
+
2374
893
  let TransactionStatus;
2375
894
  /**
2376
895
  * Default (empty) signature
@@ -2896,7 +1415,7 @@ class Transaction {
2896
1415
  _partialSign(message, ...signers) {
2897
1416
  const signData = message.serialize();
2898
1417
  signers.forEach(signer => {
2899
- const signature = nacl.sign.detached(signData, signer.secretKey);
1418
+ const signature = sign(signData, signer.secretKey);
2900
1419
 
2901
1420
  this._addSignature(signer.publicKey, toBuffer(signature));
2902
1421
  });
@@ -2952,7 +1471,7 @@ class Transaction {
2952
1471
  return false;
2953
1472
  }
2954
1473
  } else {
2955
- if (!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
1474
+ if (!verify(signature, signData, publicKey.toBuffer())) {
2956
1475
  return false;
2957
1476
  }
2958
1477
  }
@@ -3099,6 +1618,70 @@ class Transaction {
3099
1618
 
3100
1619
  }
3101
1620
 
1621
+ /**
1622
+ * Versioned transaction class
1623
+ */
1624
+ class VersionedTransaction {
1625
+ constructor(message, signatures) {
1626
+ this.signatures = void 0;
1627
+ this.message = void 0;
1628
+
1629
+ if (signatures !== undefined) {
1630
+ assert(signatures.length === message.header.numRequiredSignatures, 'Expected signatures length to be equal to the number of required signatures');
1631
+ this.signatures = signatures;
1632
+ } else {
1633
+ const defaultSignatures = [];
1634
+
1635
+ for (let i = 0; i < message.header.numRequiredSignatures; i++) {
1636
+ defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
1637
+ }
1638
+
1639
+ this.signatures = defaultSignatures;
1640
+ }
1641
+
1642
+ this.message = message;
1643
+ }
1644
+
1645
+ serialize() {
1646
+ const serializedMessage = this.message.serialize();
1647
+ const encodedSignaturesLength = Array();
1648
+ encodeLength(encodedSignaturesLength, this.signatures.length);
1649
+ const transactionLayout = BufferLayout.struct([BufferLayout.blob(encodedSignaturesLength.length, 'encodedSignaturesLength'), BufferLayout.seq(signature(), this.signatures.length, 'signatures'), BufferLayout.blob(serializedMessage.length, 'serializedMessage')]);
1650
+ const serializedTransaction = new Uint8Array(2048);
1651
+ const serializedTransactionLength = transactionLayout.encode({
1652
+ encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
1653
+ signatures: this.signatures,
1654
+ serializedMessage
1655
+ }, serializedTransaction);
1656
+ return serializedTransaction.slice(0, serializedTransactionLength);
1657
+ }
1658
+
1659
+ static deserialize(serializedTransaction) {
1660
+ let byteArray = [...serializedTransaction];
1661
+ const signatures = [];
1662
+ const signaturesLength = decodeLength(byteArray);
1663
+
1664
+ for (let i = 0; i < signaturesLength; i++) {
1665
+ signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1666
+ }
1667
+
1668
+ const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
1669
+ return new VersionedTransaction(message, signatures);
1670
+ }
1671
+
1672
+ sign(signers) {
1673
+ const messageData = this.message.serialize();
1674
+ const signerPubkeys = this.message.staticAccountKeys.slice(0, this.message.header.numRequiredSignatures);
1675
+
1676
+ for (const signer of signers) {
1677
+ const signerIndex = signerPubkeys.findIndex(pubkey => pubkey.equals(signer.publicKey));
1678
+ assert(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
1679
+ this.signatures[signerIndex] = sign(messageData, signer.secretKey);
1680
+ }
1681
+ }
1682
+
1683
+ }
1684
+
3102
1685
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3103
1686
  const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3104
1687
  const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
@@ -4492,24 +3075,26 @@ const LookupTableMetaLayout = {
4492
3075
  BufferLayout.seq(publicKey(), BufferLayout.offset(BufferLayout.u8(), -1), 'authority')])
4493
3076
  };
4494
3077
 
4495
- const URL = globalThis.URL;
4496
-
3078
+ const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
4497
3079
  function makeWebsocketUrl(endpoint) {
4498
- let url = new URL(endpoint);
4499
- const useHttps = url.protocol === 'https:';
4500
- url.protocol = useHttps ? 'wss:' : 'ws:';
4501
- url.host = ''; // Only shift the port by +1 as a convention for ws(s) only if given endpoint
3080
+ const matches = endpoint.match(URL_RE);
3081
+
3082
+ if (matches == null) {
3083
+ throw TypeError(`Failed to validate endpoint URL \`${endpoint}\``);
3084
+ }
3085
+
3086
+ const [_, // eslint-disable-line @typescript-eslint/no-unused-vars
3087
+ hostish, portWithColon, rest] = matches;
3088
+ const protocol = endpoint.startsWith('https:') ? 'wss:' : 'ws:';
3089
+ const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
3090
+ const websocketPort = // Only shift the port by +1 as a convention for ws(s) only if given endpoint
4502
3091
  // is explictly specifying the endpoint port (HTTP-based RPC), assuming
4503
3092
  // we're directly trying to connect to solana-validator's ws listening port.
4504
3093
  // When the endpoint omits the port, we're connecting to the protocol
4505
3094
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
4506
3095
  // proxy which manages WebSocket upgrade and backend port redirection.
4507
-
4508
- if (url.port !== '') {
4509
- url.port = String(Number(url.port) + 1);
4510
- }
4511
-
4512
- return url.toString();
3096
+ startPort == null ? '' : `:${startPort + 1}`;
3097
+ return `${protocol}//${hostish}${websocketPort}${rest}`;
4513
3098
  }
4514
3099
 
4515
3100
  var _process$env$npm_pack;
@@ -4529,7 +3114,17 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4529
3114
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4530
3115
  */
4531
3116
 
3117
+ /* @internal */
3118
+ function assertEndpointUrl(putativeUrl) {
3119
+ if (/^https?:/.test(putativeUrl) === false) {
3120
+ throw new TypeError('Endpoint URL must start with `http:` or `https:`.');
3121
+ }
3122
+
3123
+ return putativeUrl;
3124
+ }
4532
3125
  /** @internal */
3126
+
3127
+
4533
3128
  function extractCommitmentFromConfig(commitmentOrConfig) {
4534
3129
  let commitment;
4535
3130
  let config;
@@ -4724,7 +3319,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
4724
3319
  * A performance sample
4725
3320
  */
4726
3321
 
4727
- function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
3322
+ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4728
3323
  const fetch = customFetch ? customFetch : fetchImpl;
4729
3324
 
4730
3325
  let fetchWithMiddleware;
@@ -5530,8 +4125,6 @@ class Connection {
5530
4125
  this._subscriptionCallbacksByServerSubscriptionId = {};
5531
4126
  this._subscriptionsByHash = {};
5532
4127
  this._subscriptionsAutoDisposedByRpc = new Set();
5533
- let url = new URL(endpoint);
5534
- const useHttps = url.protocol === 'https:';
5535
4128
  let wsEndpoint;
5536
4129
  let httpHeaders;
5537
4130
  let fetch;
@@ -5550,9 +4143,9 @@ class Connection {
5550
4143
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
5551
4144
  }
5552
4145
 
5553
- this._rpcEndpoint = endpoint;
4146
+ this._rpcEndpoint = assertEndpointUrl(endpoint);
5554
4147
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
5555
- this._rpcClient = createRpcClient(url.toString(), useHttps, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
4148
+ this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5556
4149
  this._rpcRequest = createRpcRequest(this._rpcClient);
5557
4150
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
5558
4151
  this._rpcWebSocket = new Client(this._rpcWsEndpoint, {
@@ -8229,12 +6822,7 @@ class Keypair {
8229
6822
  */
8230
6823
  constructor(keypair) {
8231
6824
  this._keypair = void 0;
8232
-
8233
- if (keypair) {
8234
- this._keypair = keypair;
8235
- } else {
8236
- this._keypair = nacl.sign.keyPair();
8237
- }
6825
+ this._keypair = keypair !== null && keypair !== void 0 ? keypair : generateKeypair();
8238
6826
  }
8239
6827
  /**
8240
6828
  * Generate a new random keypair
@@ -8242,7 +6830,7 @@ class Keypair {
8242
6830
 
8243
6831
 
8244
6832
  static generate() {
8245
- return new Keypair(nacl.sign.keyPair());
6833
+ return new Keypair(generateKeypair());
8246
6834
  }
8247
6835
  /**
8248
6836
  * Create a keypair from a raw secret key byte array.
@@ -8259,19 +6847,27 @@ class Keypair {
8259
6847
 
8260
6848
 
8261
6849
  static fromSecretKey(secretKey, options) {
8262
- const keypair = nacl.sign.keyPair.fromSecretKey(secretKey);
6850
+ if (secretKey.byteLength !== 64) {
6851
+ throw new Error('bad secret key size');
6852
+ }
6853
+
6854
+ const publicKey = secretKey.slice(32, 64);
8263
6855
 
8264
6856
  if (!options || !options.skipValidation) {
8265
- const encoder = new TextEncoder();
8266
- const signData = encoder.encode('@solana/web3.js-validation-v1');
8267
- const signature = nacl.sign.detached(signData, keypair.secretKey);
6857
+ const privateScalar = secretKey.slice(0, 32);
6858
+ const computedPublicKey = getPublicKey(privateScalar);
8268
6859
 
8269
- if (!nacl.sign.detached.verify(signData, signature, keypair.publicKey)) {
8270
- throw new Error('provided secretKey is invalid');
6860
+ for (let ii = 0; ii < 32; ii++) {
6861
+ if (publicKey[ii] !== computedPublicKey[ii]) {
6862
+ throw new Error('provided secretKey is invalid');
6863
+ }
8271
6864
  }
8272
6865
  }
8273
6866
 
8274
- return new Keypair(keypair);
6867
+ return new Keypair({
6868
+ publicKey,
6869
+ secretKey
6870
+ });
8275
6871
  }
8276
6872
  /**
8277
6873
  * Generate a keypair from a 32 byte seed.
@@ -8281,7 +6877,14 @@ class Keypair {
8281
6877
 
8282
6878
 
8283
6879
  static fromSeed(seed) {
8284
- return new Keypair(nacl.sign.keyPair.fromSeed(seed));
6880
+ const publicKey = getPublicKey(seed);
6881
+ const secretKey = new Uint8Array(64);
6882
+ secretKey.set(seed);
6883
+ secretKey.set(publicKey, 32);
6884
+ return new Keypair({
6885
+ publicKey,
6886
+ secretKey
6887
+ });
8285
6888
  }
8286
6889
  /**
8287
6890
  * The public key for this keypair
@@ -8833,7 +7436,7 @@ class Ed25519Program {
8833
7436
  try {
8834
7437
  const keypair = Keypair.fromSecretKey(privateKey);
8835
7438
  const publicKey = keypair.publicKey.toBytes();
8836
- const signature = nacl.sign.detached(message, keypair.secretKey);
7439
+ const signature = sign(message, keypair.secretKey);
8837
7440
  return this.createInstructionWithPublicKey({
8838
7441
  publicKey,
8839
7442
  message,
@@ -8848,10 +7451,21 @@ class Ed25519Program {
8848
7451
  }
8849
7452
  Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
8850
7453
 
8851
- const {
8852
- publicKeyCreate,
8853
- ecdsaSign
8854
- } = secp256k1;
7454
+ // library interoperable with the synchronous APIs in web3.js.
7455
+
7456
+ secp256k1.utils.hmacSha256Sync = (key, ...msgs) => {
7457
+ const h = hmac.create(sha256, key);
7458
+ msgs.forEach(msg => h.update(msg));
7459
+ return h.digest();
7460
+ };
7461
+
7462
+ const ecdsaSign = (msgHash, privKey) => secp256k1.signSync(msgHash, privKey, {
7463
+ der: false,
7464
+ recovered: true
7465
+ });
7466
+ secp256k1.utils.isValidPrivateKey;
7467
+ const publicKeyCreate = secp256k1.getPublicKey;
7468
+
8855
7469
  const PRIVATE_KEY_BYTES = 32;
8856
7470
  const ETHEREUM_ADDRESS_BYTES = 20;
8857
7471
  const PUBLIC_KEY_BYTES = 64;
@@ -8975,13 +7589,12 @@ class Secp256k1Program {
8975
7589
 
8976
7590
  try {
8977
7591
  const privateKey = toBuffer(pkey);
8978
- const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
7592
+ const publicKey = publicKeyCreate(privateKey, false
7593
+ /* isCompressed */
7594
+ ).slice(1); // throw away leading byte
8979
7595
 
8980
7596
  const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
8981
- const {
8982
- signature,
8983
- recid: recoveryId
8984
- } = ecdsaSign(messageHash, privateKey);
7597
+ const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
8985
7598
  return this.createInstructionWithPublicKey({
8986
7599
  publicKey,
8987
7600
  message,
@@ -10093,6 +8706,23 @@ class VoteProgram {
10093
8706
  data
10094
8707
  });
10095
8708
  }
8709
+ /**
8710
+ * Generate a transaction to withdraw safely from a Vote account.
8711
+ *
8712
+ * This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
8713
+ * checks that the withdraw amount will not exceed the specified balance while leaving enough left
8714
+ * to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
8715
+ * `withdraw` method directly.
8716
+ */
8717
+
8718
+
8719
+ static safeWithdraw(params, currentVoteAccountBalance, rentExemptMinimum) {
8720
+ if (params.lamports > currentVoteAccountBalance - rentExemptMinimum) {
8721
+ throw new Error('Withdraw will leave vote account with insuffcient funds.');
8722
+ }
8723
+
8724
+ return VoteProgram.withdraw(params);
8725
+ }
10096
8726
 
10097
8727
  }
10098
8728
  VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
@@ -10144,15 +8774,14 @@ class ValidatorInfo {
10144
8774
 
10145
8775
 
10146
8776
  static fromConfigData(buffer) {
10147
- const PUBKEY_LENGTH = 32;
10148
8777
  let byteArray = [...buffer];
10149
8778
  const configKeyCount = decodeLength(byteArray);
10150
8779
  if (configKeyCount !== 2) return null;
10151
8780
  const configKeys = [];
10152
8781
 
10153
8782
  for (let i = 0; i < 2; i++) {
10154
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
10155
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8783
+ const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
8784
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10156
8785
  const isSigner = byteArray.slice(0, 1)[0] === 1;
10157
8786
  byteArray = byteArray.slice(1);
10158
8787
  configKeys.push({
@@ -10165,7 +8794,7 @@ class ValidatorInfo {
10165
8794
  if (configKeys[1].isSigner) {
10166
8795
  const rawInfo = rustString().decode(Buffer.from(byteArray));
10167
8796
  const info = JSON.parse(rawInfo);
10168
- assert$7(info, InfoString);
8797
+ assert$1(info, InfoString);
10169
8798
  return new ValidatorInfo(configKeys[1].publicKey, info);
10170
8799
  }
10171
8800
  }
@@ -10364,5 +8993,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
10364
8993
 
10365
8994
  const LAMPORTS_PER_SOL = 1000000000;
10366
8995
 
10367
- export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
8996
+ export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, MessageV0, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PUBLIC_KEY_LENGTH, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
10368
8997
  //# sourceMappingURL=index.browser.esm.js.map