@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
@@ -2,19 +2,21 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var nacl = require('tweetnacl');
6
5
  var buffer = require('buffer');
6
+ var sha512 = require('@noble/hashes/sha512');
7
+ var ed25519 = require('@noble/ed25519');
7
8
  var BN = require('bn.js');
8
9
  var bs58 = require('bs58');
10
+ var sha256 = require('@noble/hashes/sha256');
9
11
  var borsh = require('borsh');
10
12
  var BufferLayout = require('@solana/buffer-layout');
11
13
  var bigintBuffer = require('bigint-buffer');
12
14
  var superstruct = require('superstruct');
13
15
  var rpcWebsockets = require('rpc-websockets');
14
16
  var RpcClient = require('jayson/lib/client/browser');
15
- var reactNativeUrlPolyfill = require('react-native-url-polyfill');
16
- var secp256k1 = require('secp256k1');
17
17
  var sha3 = require('js-sha3');
18
+ var hmac = require('@noble/hashes/hmac');
19
+ var secp256k1 = require('@noble/secp256k1');
18
20
 
19
21
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
22
 
@@ -36,1729 +38,58 @@ function _interopNamespace(e) {
36
38
  return Object.freeze(n);
37
39
  }
38
40
 
39
- var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
41
+ var ed25519__namespace = /*#__PURE__*/_interopNamespace(ed25519);
40
42
  var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
41
43
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
42
44
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
43
45
  var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
44
- var secp256k1__default = /*#__PURE__*/_interopDefaultLegacy(secp256k1);
45
46
  var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
47
+ var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
46
48
 
47
- const toBuffer = arr => {
48
- if (buffer.Buffer.isBuffer(arr)) {
49
- return arr;
50
- } else if (arr instanceof Uint8Array) {
51
- return buffer.Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
52
- } else {
53
- return buffer.Buffer.from(arr);
54
- }
55
- };
56
-
57
- var hash$1 = {};
58
-
59
- var utils$9 = {};
60
-
61
- var minimalisticAssert = assert$6;
49
+ /**
50
+ * A 64 byte secret key, the first 32 bytes of which is the
51
+ * private scalar and the last 32 bytes is the public key.
52
+ * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
53
+ */
62
54
 
63
- function assert$6(val, msg) {
64
- if (!val)
65
- throw new Error(msg || 'Assertion failed');
66
- }
55
+ ed25519__namespace.utils.sha512Sync = (...m) => sha512.sha512(ed25519__namespace.utils.concatBytes(...m));
67
56
 
68
- assert$6.equal = function assertEqual(l, r, msg) {
69
- if (l != r)
70
- throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
71
- };
72
-
73
- var inherits_browser = {exports: {}};
74
-
75
- if (typeof Object.create === 'function') {
76
- // implementation from standard node.js 'util' module
77
- inherits_browser.exports = function inherits(ctor, superCtor) {
78
- if (superCtor) {
79
- ctor.super_ = superCtor;
80
- ctor.prototype = Object.create(superCtor.prototype, {
81
- constructor: {
82
- value: ctor,
83
- enumerable: false,
84
- writable: true,
85
- configurable: true
86
- }
87
- });
88
- }
89
- };
90
- } else {
91
- // old school shim for old browsers
92
- inherits_browser.exports = function inherits(ctor, superCtor) {
93
- if (superCtor) {
94
- ctor.super_ = superCtor;
95
- var TempCtor = function () {};
96
- TempCtor.prototype = superCtor.prototype;
97
- ctor.prototype = new TempCtor();
98
- ctor.prototype.constructor = ctor;
99
- }
57
+ const generatePrivateKey = ed25519__namespace.utils.randomPrivateKey;
58
+ const generateKeypair = () => {
59
+ const privateScalar = ed25519__namespace.utils.randomPrivateKey();
60
+ const publicKey = getPublicKey(privateScalar);
61
+ const secretKey = new Uint8Array(64);
62
+ secretKey.set(privateScalar);
63
+ secretKey.set(publicKey, 32);
64
+ return {
65
+ publicKey,
66
+ secretKey
100
67
  };
101
- }
102
-
103
- var assert$5 = minimalisticAssert;
104
- var inherits = inherits_browser.exports;
105
-
106
- utils$9.inherits = inherits;
107
-
108
- function isSurrogatePair(msg, i) {
109
- if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
110
- return false;
111
- }
112
- if (i < 0 || i + 1 >= msg.length) {
68
+ };
69
+ const getPublicKey = ed25519__namespace.sync.getPublicKey;
70
+ function isOnCurve(publicKey) {
71
+ try {
72
+ ed25519__namespace.Point.fromHex(publicKey, true
73
+ /* strict */
74
+ );
75
+ return true;
76
+ } catch {
113
77
  return false;
114
78
  }
115
- return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
116
- }
117
-
118
- function toArray(msg, enc) {
119
- if (Array.isArray(msg))
120
- return msg.slice();
121
- if (!msg)
122
- return [];
123
- var res = [];
124
- if (typeof msg === 'string') {
125
- if (!enc) {
126
- // Inspired by stringToUtf8ByteArray() in closure-library by Google
127
- // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
128
- // Apache License 2.0
129
- // https://github.com/google/closure-library/blob/master/LICENSE
130
- var p = 0;
131
- for (var i = 0; i < msg.length; i++) {
132
- var c = msg.charCodeAt(i);
133
- if (c < 128) {
134
- res[p++] = c;
135
- } else if (c < 2048) {
136
- res[p++] = (c >> 6) | 192;
137
- res[p++] = (c & 63) | 128;
138
- } else if (isSurrogatePair(msg, i)) {
139
- c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
140
- res[p++] = (c >> 18) | 240;
141
- res[p++] = ((c >> 12) & 63) | 128;
142
- res[p++] = ((c >> 6) & 63) | 128;
143
- res[p++] = (c & 63) | 128;
144
- } else {
145
- res[p++] = (c >> 12) | 224;
146
- res[p++] = ((c >> 6) & 63) | 128;
147
- res[p++] = (c & 63) | 128;
148
- }
149
- }
150
- } else if (enc === 'hex') {
151
- msg = msg.replace(/[^a-z0-9]+/ig, '');
152
- if (msg.length % 2 !== 0)
153
- msg = '0' + msg;
154
- for (i = 0; i < msg.length; i += 2)
155
- res.push(parseInt(msg[i] + msg[i + 1], 16));
156
- }
157
- } else {
158
- for (i = 0; i < msg.length; i++)
159
- res[i] = msg[i] | 0;
160
- }
161
- return res;
162
- }
163
- utils$9.toArray = toArray;
164
-
165
- function toHex(msg) {
166
- var res = '';
167
- for (var i = 0; i < msg.length; i++)
168
- res += zero2(msg[i].toString(16));
169
- return res;
170
- }
171
- utils$9.toHex = toHex;
172
-
173
- function htonl(w) {
174
- var res = (w >>> 24) |
175
- ((w >>> 8) & 0xff00) |
176
- ((w << 8) & 0xff0000) |
177
- ((w & 0xff) << 24);
178
- return res >>> 0;
179
- }
180
- utils$9.htonl = htonl;
181
-
182
- function toHex32(msg, endian) {
183
- var res = '';
184
- for (var i = 0; i < msg.length; i++) {
185
- var w = msg[i];
186
- if (endian === 'little')
187
- w = htonl(w);
188
- res += zero8(w.toString(16));
189
- }
190
- return res;
191
- }
192
- utils$9.toHex32 = toHex32;
193
-
194
- function zero2(word) {
195
- if (word.length === 1)
196
- return '0' + word;
197
- else
198
- return word;
199
- }
200
- utils$9.zero2 = zero2;
201
-
202
- function zero8(word) {
203
- if (word.length === 7)
204
- return '0' + word;
205
- else if (word.length === 6)
206
- return '00' + word;
207
- else if (word.length === 5)
208
- return '000' + word;
209
- else if (word.length === 4)
210
- return '0000' + word;
211
- else if (word.length === 3)
212
- return '00000' + word;
213
- else if (word.length === 2)
214
- return '000000' + word;
215
- else if (word.length === 1)
216
- return '0000000' + word;
217
- else
218
- return word;
219
- }
220
- utils$9.zero8 = zero8;
221
-
222
- function join32(msg, start, end, endian) {
223
- var len = end - start;
224
- assert$5(len % 4 === 0);
225
- var res = new Array(len / 4);
226
- for (var i = 0, k = start; i < res.length; i++, k += 4) {
227
- var w;
228
- if (endian === 'big')
229
- w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
230
- else
231
- w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
232
- res[i] = w >>> 0;
233
- }
234
- return res;
235
- }
236
- utils$9.join32 = join32;
237
-
238
- function split32(msg, endian) {
239
- var res = new Array(msg.length * 4);
240
- for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
241
- var m = msg[i];
242
- if (endian === 'big') {
243
- res[k] = m >>> 24;
244
- res[k + 1] = (m >>> 16) & 0xff;
245
- res[k + 2] = (m >>> 8) & 0xff;
246
- res[k + 3] = m & 0xff;
247
- } else {
248
- res[k + 3] = m >>> 24;
249
- res[k + 2] = (m >>> 16) & 0xff;
250
- res[k + 1] = (m >>> 8) & 0xff;
251
- res[k] = m & 0xff;
252
- }
253
- }
254
- return res;
255
- }
256
- utils$9.split32 = split32;
257
-
258
- function rotr32$1(w, b) {
259
- return (w >>> b) | (w << (32 - b));
260
- }
261
- utils$9.rotr32 = rotr32$1;
262
-
263
- function rotl32$2(w, b) {
264
- return (w << b) | (w >>> (32 - b));
265
- }
266
- utils$9.rotl32 = rotl32$2;
267
-
268
- function sum32$3(a, b) {
269
- return (a + b) >>> 0;
270
79
  }
271
- utils$9.sum32 = sum32$3;
80
+ const sign = (message, secretKey) => ed25519__namespace.sync.sign(message, secretKey.slice(0, 32));
81
+ const verify = ed25519__namespace.sync.verify;
272
82
 
273
- function sum32_3$1(a, b, c) {
274
- return (a + b + c) >>> 0;
275
- }
276
- utils$9.sum32_3 = sum32_3$1;
277
-
278
- function sum32_4$2(a, b, c, d) {
279
- return (a + b + c + d) >>> 0;
280
- }
281
- utils$9.sum32_4 = sum32_4$2;
282
-
283
- function sum32_5$2(a, b, c, d, e) {
284
- return (a + b + c + d + e) >>> 0;
285
- }
286
- utils$9.sum32_5 = sum32_5$2;
287
-
288
- function sum64$1(buf, pos, ah, al) {
289
- var bh = buf[pos];
290
- var bl = buf[pos + 1];
291
-
292
- var lo = (al + bl) >>> 0;
293
- var hi = (lo < al ? 1 : 0) + ah + bh;
294
- buf[pos] = hi >>> 0;
295
- buf[pos + 1] = lo;
296
- }
297
- utils$9.sum64 = sum64$1;
298
-
299
- function sum64_hi$1(ah, al, bh, bl) {
300
- var lo = (al + bl) >>> 0;
301
- var hi = (lo < al ? 1 : 0) + ah + bh;
302
- return hi >>> 0;
303
- }
304
- utils$9.sum64_hi = sum64_hi$1;
305
-
306
- function sum64_lo$1(ah, al, bh, bl) {
307
- var lo = al + bl;
308
- return lo >>> 0;
309
- }
310
- utils$9.sum64_lo = sum64_lo$1;
311
-
312
- function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
313
- var carry = 0;
314
- var lo = al;
315
- lo = (lo + bl) >>> 0;
316
- carry += lo < al ? 1 : 0;
317
- lo = (lo + cl) >>> 0;
318
- carry += lo < cl ? 1 : 0;
319
- lo = (lo + dl) >>> 0;
320
- carry += lo < dl ? 1 : 0;
321
-
322
- var hi = ah + bh + ch + dh + carry;
323
- return hi >>> 0;
324
- }
325
- utils$9.sum64_4_hi = sum64_4_hi$1;
326
-
327
- function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
328
- var lo = al + bl + cl + dl;
329
- return lo >>> 0;
330
- }
331
- utils$9.sum64_4_lo = sum64_4_lo$1;
332
-
333
- function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
334
- var carry = 0;
335
- var lo = al;
336
- lo = (lo + bl) >>> 0;
337
- carry += lo < al ? 1 : 0;
338
- lo = (lo + cl) >>> 0;
339
- carry += lo < cl ? 1 : 0;
340
- lo = (lo + dl) >>> 0;
341
- carry += lo < dl ? 1 : 0;
342
- lo = (lo + el) >>> 0;
343
- carry += lo < el ? 1 : 0;
344
-
345
- var hi = ah + bh + ch + dh + eh + carry;
346
- return hi >>> 0;
347
- }
348
- utils$9.sum64_5_hi = sum64_5_hi$1;
349
-
350
- function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
351
- var lo = al + bl + cl + dl + el;
352
-
353
- return lo >>> 0;
354
- }
355
- utils$9.sum64_5_lo = sum64_5_lo$1;
356
-
357
- function rotr64_hi$1(ah, al, num) {
358
- var r = (al << (32 - num)) | (ah >>> num);
359
- return r >>> 0;
360
- }
361
- utils$9.rotr64_hi = rotr64_hi$1;
362
-
363
- function rotr64_lo$1(ah, al, num) {
364
- var r = (ah << (32 - num)) | (al >>> num);
365
- return r >>> 0;
366
- }
367
- utils$9.rotr64_lo = rotr64_lo$1;
368
-
369
- function shr64_hi$1(ah, al, num) {
370
- return ah >>> num;
371
- }
372
- utils$9.shr64_hi = shr64_hi$1;
373
-
374
- function shr64_lo$1(ah, al, num) {
375
- var r = (ah << (32 - num)) | (al >>> num);
376
- return r >>> 0;
377
- }
378
- utils$9.shr64_lo = shr64_lo$1;
379
-
380
- var common$5 = {};
381
-
382
- var utils$8 = utils$9;
383
- var assert$4 = minimalisticAssert;
384
-
385
- function BlockHash$4() {
386
- this.pending = null;
387
- this.pendingTotal = 0;
388
- this.blockSize = this.constructor.blockSize;
389
- this.outSize = this.constructor.outSize;
390
- this.hmacStrength = this.constructor.hmacStrength;
391
- this.padLength = this.constructor.padLength / 8;
392
- this.endian = 'big';
393
-
394
- this._delta8 = this.blockSize / 8;
395
- this._delta32 = this.blockSize / 32;
396
- }
397
- common$5.BlockHash = BlockHash$4;
398
-
399
- BlockHash$4.prototype.update = function update(msg, enc) {
400
- // Convert message to array, pad it, and join into 32bit blocks
401
- msg = utils$8.toArray(msg, enc);
402
- if (!this.pending)
403
- this.pending = msg;
404
- else
405
- this.pending = this.pending.concat(msg);
406
- this.pendingTotal += msg.length;
407
-
408
- // Enough data, try updating
409
- if (this.pending.length >= this._delta8) {
410
- msg = this.pending;
411
-
412
- // Process pending data in blocks
413
- var r = msg.length % this._delta8;
414
- this.pending = msg.slice(msg.length - r, msg.length);
415
- if (this.pending.length === 0)
416
- this.pending = null;
417
-
418
- msg = utils$8.join32(msg, 0, msg.length - r, this.endian);
419
- for (var i = 0; i < msg.length; i += this._delta32)
420
- this._update(msg, i, i + this._delta32);
421
- }
422
-
423
- return this;
424
- };
425
-
426
- BlockHash$4.prototype.digest = function digest(enc) {
427
- this.update(this._pad());
428
- assert$4(this.pending === null);
429
-
430
- return this._digest(enc);
431
- };
432
-
433
- BlockHash$4.prototype._pad = function pad() {
434
- var len = this.pendingTotal;
435
- var bytes = this._delta8;
436
- var k = bytes - ((len + this.padLength) % bytes);
437
- var res = new Array(k + this.padLength);
438
- res[0] = 0x80;
439
- for (var i = 1; i < k; i++)
440
- res[i] = 0;
441
-
442
- // Append length
443
- len <<= 3;
444
- if (this.endian === 'big') {
445
- for (var t = 8; t < this.padLength; t++)
446
- res[i++] = 0;
447
-
448
- res[i++] = 0;
449
- res[i++] = 0;
450
- res[i++] = 0;
451
- res[i++] = 0;
452
- res[i++] = (len >>> 24) & 0xff;
453
- res[i++] = (len >>> 16) & 0xff;
454
- res[i++] = (len >>> 8) & 0xff;
455
- res[i++] = len & 0xff;
83
+ const toBuffer = arr => {
84
+ if (buffer.Buffer.isBuffer(arr)) {
85
+ return arr;
86
+ } else if (arr instanceof Uint8Array) {
87
+ return buffer.Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
456
88
  } else {
457
- res[i++] = len & 0xff;
458
- res[i++] = (len >>> 8) & 0xff;
459
- res[i++] = (len >>> 16) & 0xff;
460
- res[i++] = (len >>> 24) & 0xff;
461
- res[i++] = 0;
462
- res[i++] = 0;
463
- res[i++] = 0;
464
- res[i++] = 0;
465
-
466
- for (t = 8; t < this.padLength; t++)
467
- res[i++] = 0;
468
- }
469
-
470
- return res;
471
- };
472
-
473
- var sha = {};
474
-
475
- var common$4 = {};
476
-
477
- var utils$7 = utils$9;
478
- var rotr32 = utils$7.rotr32;
479
-
480
- function ft_1$1(s, x, y, z) {
481
- if (s === 0)
482
- return ch32$1(x, y, z);
483
- if (s === 1 || s === 3)
484
- return p32(x, y, z);
485
- if (s === 2)
486
- return maj32$1(x, y, z);
487
- }
488
- common$4.ft_1 = ft_1$1;
489
-
490
- function ch32$1(x, y, z) {
491
- return (x & y) ^ ((~x) & z);
492
- }
493
- common$4.ch32 = ch32$1;
494
-
495
- function maj32$1(x, y, z) {
496
- return (x & y) ^ (x & z) ^ (y & z);
497
- }
498
- common$4.maj32 = maj32$1;
499
-
500
- function p32(x, y, z) {
501
- return x ^ y ^ z;
502
- }
503
- common$4.p32 = p32;
504
-
505
- function s0_256$1(x) {
506
- return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
507
- }
508
- common$4.s0_256 = s0_256$1;
509
-
510
- function s1_256$1(x) {
511
- return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
512
- }
513
- common$4.s1_256 = s1_256$1;
514
-
515
- function g0_256$1(x) {
516
- return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
517
- }
518
- common$4.g0_256 = g0_256$1;
519
-
520
- function g1_256$1(x) {
521
- return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
522
- }
523
- common$4.g1_256 = g1_256$1;
524
-
525
- var utils$6 = utils$9;
526
- var common$3 = common$5;
527
- var shaCommon$1 = common$4;
528
-
529
- var rotl32$1 = utils$6.rotl32;
530
- var sum32$2 = utils$6.sum32;
531
- var sum32_5$1 = utils$6.sum32_5;
532
- var ft_1 = shaCommon$1.ft_1;
533
- var BlockHash$3 = common$3.BlockHash;
534
-
535
- var sha1_K = [
536
- 0x5A827999, 0x6ED9EBA1,
537
- 0x8F1BBCDC, 0xCA62C1D6
538
- ];
539
-
540
- function SHA1() {
541
- if (!(this instanceof SHA1))
542
- return new SHA1();
543
-
544
- BlockHash$3.call(this);
545
- this.h = [
546
- 0x67452301, 0xefcdab89, 0x98badcfe,
547
- 0x10325476, 0xc3d2e1f0 ];
548
- this.W = new Array(80);
549
- }
550
-
551
- utils$6.inherits(SHA1, BlockHash$3);
552
- var _1 = SHA1;
553
-
554
- SHA1.blockSize = 512;
555
- SHA1.outSize = 160;
556
- SHA1.hmacStrength = 80;
557
- SHA1.padLength = 64;
558
-
559
- SHA1.prototype._update = function _update(msg, start) {
560
- var W = this.W;
561
-
562
- for (var i = 0; i < 16; i++)
563
- W[i] = msg[start + i];
564
-
565
- for(; i < W.length; i++)
566
- W[i] = rotl32$1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
567
-
568
- var a = this.h[0];
569
- var b = this.h[1];
570
- var c = this.h[2];
571
- var d = this.h[3];
572
- var e = this.h[4];
573
-
574
- for (i = 0; i < W.length; i++) {
575
- var s = ~~(i / 20);
576
- var t = sum32_5$1(rotl32$1(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
577
- e = d;
578
- d = c;
579
- c = rotl32$1(b, 30);
580
- b = a;
581
- a = t;
582
- }
583
-
584
- this.h[0] = sum32$2(this.h[0], a);
585
- this.h[1] = sum32$2(this.h[1], b);
586
- this.h[2] = sum32$2(this.h[2], c);
587
- this.h[3] = sum32$2(this.h[3], d);
588
- this.h[4] = sum32$2(this.h[4], e);
589
- };
590
-
591
- SHA1.prototype._digest = function digest(enc) {
592
- if (enc === 'hex')
593
- return utils$6.toHex32(this.h, 'big');
594
- else
595
- return utils$6.split32(this.h, 'big');
596
- };
597
-
598
- var utils$5 = utils$9;
599
- var common$2 = common$5;
600
- var shaCommon = common$4;
601
- var assert$3 = minimalisticAssert;
602
-
603
- var sum32$1 = utils$5.sum32;
604
- var sum32_4$1 = utils$5.sum32_4;
605
- var sum32_5 = utils$5.sum32_5;
606
- var ch32 = shaCommon.ch32;
607
- var maj32 = shaCommon.maj32;
608
- var s0_256 = shaCommon.s0_256;
609
- var s1_256 = shaCommon.s1_256;
610
- var g0_256 = shaCommon.g0_256;
611
- var g1_256 = shaCommon.g1_256;
612
-
613
- var BlockHash$2 = common$2.BlockHash;
614
-
615
- var sha256_K = [
616
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
617
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
618
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
619
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
620
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
621
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
622
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
623
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
624
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
625
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
626
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
627
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
628
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
629
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
630
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
631
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
632
- ];
633
-
634
- function SHA256$1() {
635
- if (!(this instanceof SHA256$1))
636
- return new SHA256$1();
637
-
638
- BlockHash$2.call(this);
639
- this.h = [
640
- 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
641
- 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
642
- ];
643
- this.k = sha256_K;
644
- this.W = new Array(64);
645
- }
646
- utils$5.inherits(SHA256$1, BlockHash$2);
647
- var _256 = SHA256$1;
648
-
649
- SHA256$1.blockSize = 512;
650
- SHA256$1.outSize = 256;
651
- SHA256$1.hmacStrength = 192;
652
- SHA256$1.padLength = 64;
653
-
654
- SHA256$1.prototype._update = function _update(msg, start) {
655
- var W = this.W;
656
-
657
- for (var i = 0; i < 16; i++)
658
- W[i] = msg[start + i];
659
- for (; i < W.length; i++)
660
- W[i] = sum32_4$1(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
661
-
662
- var a = this.h[0];
663
- var b = this.h[1];
664
- var c = this.h[2];
665
- var d = this.h[3];
666
- var e = this.h[4];
667
- var f = this.h[5];
668
- var g = this.h[6];
669
- var h = this.h[7];
670
-
671
- assert$3(this.k.length === W.length);
672
- for (i = 0; i < W.length; i++) {
673
- var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
674
- var T2 = sum32$1(s0_256(a), maj32(a, b, c));
675
- h = g;
676
- g = f;
677
- f = e;
678
- e = sum32$1(d, T1);
679
- d = c;
680
- c = b;
681
- b = a;
682
- a = sum32$1(T1, T2);
683
- }
684
-
685
- this.h[0] = sum32$1(this.h[0], a);
686
- this.h[1] = sum32$1(this.h[1], b);
687
- this.h[2] = sum32$1(this.h[2], c);
688
- this.h[3] = sum32$1(this.h[3], d);
689
- this.h[4] = sum32$1(this.h[4], e);
690
- this.h[5] = sum32$1(this.h[5], f);
691
- this.h[6] = sum32$1(this.h[6], g);
692
- this.h[7] = sum32$1(this.h[7], h);
693
- };
694
-
695
- SHA256$1.prototype._digest = function digest(enc) {
696
- if (enc === 'hex')
697
- return utils$5.toHex32(this.h, 'big');
698
- else
699
- return utils$5.split32(this.h, 'big');
700
- };
701
-
702
- var utils$4 = utils$9;
703
- var SHA256 = _256;
704
-
705
- function SHA224() {
706
- if (!(this instanceof SHA224))
707
- return new SHA224();
708
-
709
- SHA256.call(this);
710
- this.h = [
711
- 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
712
- 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
713
- }
714
- utils$4.inherits(SHA224, SHA256);
715
- var _224 = SHA224;
716
-
717
- SHA224.blockSize = 512;
718
- SHA224.outSize = 224;
719
- SHA224.hmacStrength = 192;
720
- SHA224.padLength = 64;
721
-
722
- SHA224.prototype._digest = function digest(enc) {
723
- // Just truncate output
724
- if (enc === 'hex')
725
- return utils$4.toHex32(this.h.slice(0, 7), 'big');
726
- else
727
- return utils$4.split32(this.h.slice(0, 7), 'big');
728
- };
729
-
730
- var utils$3 = utils$9;
731
- var common$1 = common$5;
732
- var assert$2 = minimalisticAssert;
733
-
734
- var rotr64_hi = utils$3.rotr64_hi;
735
- var rotr64_lo = utils$3.rotr64_lo;
736
- var shr64_hi = utils$3.shr64_hi;
737
- var shr64_lo = utils$3.shr64_lo;
738
- var sum64 = utils$3.sum64;
739
- var sum64_hi = utils$3.sum64_hi;
740
- var sum64_lo = utils$3.sum64_lo;
741
- var sum64_4_hi = utils$3.sum64_4_hi;
742
- var sum64_4_lo = utils$3.sum64_4_lo;
743
- var sum64_5_hi = utils$3.sum64_5_hi;
744
- var sum64_5_lo = utils$3.sum64_5_lo;
745
-
746
- var BlockHash$1 = common$1.BlockHash;
747
-
748
- var sha512_K = [
749
- 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
750
- 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
751
- 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
752
- 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
753
- 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
754
- 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
755
- 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
756
- 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
757
- 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
758
- 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
759
- 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
760
- 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
761
- 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
762
- 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
763
- 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
764
- 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
765
- 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
766
- 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
767
- 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
768
- 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
769
- 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
770
- 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
771
- 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
772
- 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
773
- 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
774
- 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
775
- 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
776
- 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
777
- 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
778
- 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
779
- 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
780
- 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
781
- 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
782
- 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
783
- 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
784
- 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
785
- 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
786
- 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
787
- 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
788
- 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
789
- ];
790
-
791
- function SHA512$1() {
792
- if (!(this instanceof SHA512$1))
793
- return new SHA512$1();
794
-
795
- BlockHash$1.call(this);
796
- this.h = [
797
- 0x6a09e667, 0xf3bcc908,
798
- 0xbb67ae85, 0x84caa73b,
799
- 0x3c6ef372, 0xfe94f82b,
800
- 0xa54ff53a, 0x5f1d36f1,
801
- 0x510e527f, 0xade682d1,
802
- 0x9b05688c, 0x2b3e6c1f,
803
- 0x1f83d9ab, 0xfb41bd6b,
804
- 0x5be0cd19, 0x137e2179 ];
805
- this.k = sha512_K;
806
- this.W = new Array(160);
807
- }
808
- utils$3.inherits(SHA512$1, BlockHash$1);
809
- var _512 = SHA512$1;
810
-
811
- SHA512$1.blockSize = 1024;
812
- SHA512$1.outSize = 512;
813
- SHA512$1.hmacStrength = 192;
814
- SHA512$1.padLength = 128;
815
-
816
- SHA512$1.prototype._prepareBlock = function _prepareBlock(msg, start) {
817
- var W = this.W;
818
-
819
- // 32 x 32bit words
820
- for (var i = 0; i < 32; i++)
821
- W[i] = msg[start + i];
822
- for (; i < W.length; i += 2) {
823
- var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
824
- var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
825
- var c1_hi = W[i - 14]; // i - 7
826
- var c1_lo = W[i - 13];
827
- var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
828
- var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
829
- var c3_hi = W[i - 32]; // i - 16
830
- var c3_lo = W[i - 31];
831
-
832
- W[i] = sum64_4_hi(
833
- c0_hi, c0_lo,
834
- c1_hi, c1_lo,
835
- c2_hi, c2_lo,
836
- c3_hi, c3_lo);
837
- W[i + 1] = sum64_4_lo(
838
- c0_hi, c0_lo,
839
- c1_hi, c1_lo,
840
- c2_hi, c2_lo,
841
- c3_hi, c3_lo);
89
+ return buffer.Buffer.from(arr);
842
90
  }
843
91
  };
844
92
 
845
- SHA512$1.prototype._update = function _update(msg, start) {
846
- this._prepareBlock(msg, start);
847
-
848
- var W = this.W;
849
-
850
- var ah = this.h[0];
851
- var al = this.h[1];
852
- var bh = this.h[2];
853
- var bl = this.h[3];
854
- var ch = this.h[4];
855
- var cl = this.h[5];
856
- var dh = this.h[6];
857
- var dl = this.h[7];
858
- var eh = this.h[8];
859
- var el = this.h[9];
860
- var fh = this.h[10];
861
- var fl = this.h[11];
862
- var gh = this.h[12];
863
- var gl = this.h[13];
864
- var hh = this.h[14];
865
- var hl = this.h[15];
866
-
867
- assert$2(this.k.length === W.length);
868
- for (var i = 0; i < W.length; i += 2) {
869
- var c0_hi = hh;
870
- var c0_lo = hl;
871
- var c1_hi = s1_512_hi(eh, el);
872
- var c1_lo = s1_512_lo(eh, el);
873
- var c2_hi = ch64_hi(eh, el, fh, fl, gh);
874
- var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
875
- var c3_hi = this.k[i];
876
- var c3_lo = this.k[i + 1];
877
- var c4_hi = W[i];
878
- var c4_lo = W[i + 1];
879
-
880
- var T1_hi = sum64_5_hi(
881
- c0_hi, c0_lo,
882
- c1_hi, c1_lo,
883
- c2_hi, c2_lo,
884
- c3_hi, c3_lo,
885
- c4_hi, c4_lo);
886
- var T1_lo = sum64_5_lo(
887
- c0_hi, c0_lo,
888
- c1_hi, c1_lo,
889
- c2_hi, c2_lo,
890
- c3_hi, c3_lo,
891
- c4_hi, c4_lo);
892
-
893
- c0_hi = s0_512_hi(ah, al);
894
- c0_lo = s0_512_lo(ah, al);
895
- c1_hi = maj64_hi(ah, al, bh, bl, ch);
896
- c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
897
-
898
- var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
899
- var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
900
-
901
- hh = gh;
902
- hl = gl;
903
-
904
- gh = fh;
905
- gl = fl;
906
-
907
- fh = eh;
908
- fl = el;
909
-
910
- eh = sum64_hi(dh, dl, T1_hi, T1_lo);
911
- el = sum64_lo(dl, dl, T1_hi, T1_lo);
912
-
913
- dh = ch;
914
- dl = cl;
915
-
916
- ch = bh;
917
- cl = bl;
918
-
919
- bh = ah;
920
- bl = al;
921
-
922
- ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
923
- al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
924
- }
925
-
926
- sum64(this.h, 0, ah, al);
927
- sum64(this.h, 2, bh, bl);
928
- sum64(this.h, 4, ch, cl);
929
- sum64(this.h, 6, dh, dl);
930
- sum64(this.h, 8, eh, el);
931
- sum64(this.h, 10, fh, fl);
932
- sum64(this.h, 12, gh, gl);
933
- sum64(this.h, 14, hh, hl);
934
- };
935
-
936
- SHA512$1.prototype._digest = function digest(enc) {
937
- if (enc === 'hex')
938
- return utils$3.toHex32(this.h, 'big');
939
- else
940
- return utils$3.split32(this.h, 'big');
941
- };
942
-
943
- function ch64_hi(xh, xl, yh, yl, zh) {
944
- var r = (xh & yh) ^ ((~xh) & zh);
945
- if (r < 0)
946
- r += 0x100000000;
947
- return r;
948
- }
949
-
950
- function ch64_lo(xh, xl, yh, yl, zh, zl) {
951
- var r = (xl & yl) ^ ((~xl) & zl);
952
- if (r < 0)
953
- r += 0x100000000;
954
- return r;
955
- }
956
-
957
- function maj64_hi(xh, xl, yh, yl, zh) {
958
- var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
959
- if (r < 0)
960
- r += 0x100000000;
961
- return r;
962
- }
963
-
964
- function maj64_lo(xh, xl, yh, yl, zh, zl) {
965
- var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
966
- if (r < 0)
967
- r += 0x100000000;
968
- return r;
969
- }
970
-
971
- function s0_512_hi(xh, xl) {
972
- var c0_hi = rotr64_hi(xh, xl, 28);
973
- var c1_hi = rotr64_hi(xl, xh, 2); // 34
974
- var c2_hi = rotr64_hi(xl, xh, 7); // 39
975
-
976
- var r = c0_hi ^ c1_hi ^ c2_hi;
977
- if (r < 0)
978
- r += 0x100000000;
979
- return r;
980
- }
981
-
982
- function s0_512_lo(xh, xl) {
983
- var c0_lo = rotr64_lo(xh, xl, 28);
984
- var c1_lo = rotr64_lo(xl, xh, 2); // 34
985
- var c2_lo = rotr64_lo(xl, xh, 7); // 39
986
-
987
- var r = c0_lo ^ c1_lo ^ c2_lo;
988
- if (r < 0)
989
- r += 0x100000000;
990
- return r;
991
- }
992
-
993
- function s1_512_hi(xh, xl) {
994
- var c0_hi = rotr64_hi(xh, xl, 14);
995
- var c1_hi = rotr64_hi(xh, xl, 18);
996
- var c2_hi = rotr64_hi(xl, xh, 9); // 41
997
-
998
- var r = c0_hi ^ c1_hi ^ c2_hi;
999
- if (r < 0)
1000
- r += 0x100000000;
1001
- return r;
1002
- }
1003
-
1004
- function s1_512_lo(xh, xl) {
1005
- var c0_lo = rotr64_lo(xh, xl, 14);
1006
- var c1_lo = rotr64_lo(xh, xl, 18);
1007
- var c2_lo = rotr64_lo(xl, xh, 9); // 41
1008
-
1009
- var r = c0_lo ^ c1_lo ^ c2_lo;
1010
- if (r < 0)
1011
- r += 0x100000000;
1012
- return r;
1013
- }
1014
-
1015
- function g0_512_hi(xh, xl) {
1016
- var c0_hi = rotr64_hi(xh, xl, 1);
1017
- var c1_hi = rotr64_hi(xh, xl, 8);
1018
- var c2_hi = shr64_hi(xh, xl, 7);
1019
-
1020
- var r = c0_hi ^ c1_hi ^ c2_hi;
1021
- if (r < 0)
1022
- r += 0x100000000;
1023
- return r;
1024
- }
1025
-
1026
- function g0_512_lo(xh, xl) {
1027
- var c0_lo = rotr64_lo(xh, xl, 1);
1028
- var c1_lo = rotr64_lo(xh, xl, 8);
1029
- var c2_lo = shr64_lo(xh, xl, 7);
1030
-
1031
- var r = c0_lo ^ c1_lo ^ c2_lo;
1032
- if (r < 0)
1033
- r += 0x100000000;
1034
- return r;
1035
- }
1036
-
1037
- function g1_512_hi(xh, xl) {
1038
- var c0_hi = rotr64_hi(xh, xl, 19);
1039
- var c1_hi = rotr64_hi(xl, xh, 29); // 61
1040
- var c2_hi = shr64_hi(xh, xl, 6);
1041
-
1042
- var r = c0_hi ^ c1_hi ^ c2_hi;
1043
- if (r < 0)
1044
- r += 0x100000000;
1045
- return r;
1046
- }
1047
-
1048
- function g1_512_lo(xh, xl) {
1049
- var c0_lo = rotr64_lo(xh, xl, 19);
1050
- var c1_lo = rotr64_lo(xl, xh, 29); // 61
1051
- var c2_lo = shr64_lo(xh, xl, 6);
1052
-
1053
- var r = c0_lo ^ c1_lo ^ c2_lo;
1054
- if (r < 0)
1055
- r += 0x100000000;
1056
- return r;
1057
- }
1058
-
1059
- var utils$2 = utils$9;
1060
-
1061
- var SHA512 = _512;
1062
-
1063
- function SHA384() {
1064
- if (!(this instanceof SHA384))
1065
- return new SHA384();
1066
-
1067
- SHA512.call(this);
1068
- this.h = [
1069
- 0xcbbb9d5d, 0xc1059ed8,
1070
- 0x629a292a, 0x367cd507,
1071
- 0x9159015a, 0x3070dd17,
1072
- 0x152fecd8, 0xf70e5939,
1073
- 0x67332667, 0xffc00b31,
1074
- 0x8eb44a87, 0x68581511,
1075
- 0xdb0c2e0d, 0x64f98fa7,
1076
- 0x47b5481d, 0xbefa4fa4 ];
1077
- }
1078
- utils$2.inherits(SHA384, SHA512);
1079
- var _384 = SHA384;
1080
-
1081
- SHA384.blockSize = 1024;
1082
- SHA384.outSize = 384;
1083
- SHA384.hmacStrength = 192;
1084
- SHA384.padLength = 128;
1085
-
1086
- SHA384.prototype._digest = function digest(enc) {
1087
- if (enc === 'hex')
1088
- return utils$2.toHex32(this.h.slice(0, 12), 'big');
1089
- else
1090
- return utils$2.split32(this.h.slice(0, 12), 'big');
1091
- };
1092
-
1093
- sha.sha1 = _1;
1094
- sha.sha224 = _224;
1095
- sha.sha256 = _256;
1096
- sha.sha384 = _384;
1097
- sha.sha512 = _512;
1098
-
1099
- var ripemd = {};
1100
-
1101
- var utils$1 = utils$9;
1102
- var common = common$5;
1103
-
1104
- var rotl32 = utils$1.rotl32;
1105
- var sum32 = utils$1.sum32;
1106
- var sum32_3 = utils$1.sum32_3;
1107
- var sum32_4 = utils$1.sum32_4;
1108
- var BlockHash = common.BlockHash;
1109
-
1110
- function RIPEMD160() {
1111
- if (!(this instanceof RIPEMD160))
1112
- return new RIPEMD160();
1113
-
1114
- BlockHash.call(this);
1115
-
1116
- this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
1117
- this.endian = 'little';
1118
- }
1119
- utils$1.inherits(RIPEMD160, BlockHash);
1120
- ripemd.ripemd160 = RIPEMD160;
1121
-
1122
- RIPEMD160.blockSize = 512;
1123
- RIPEMD160.outSize = 160;
1124
- RIPEMD160.hmacStrength = 192;
1125
- RIPEMD160.padLength = 64;
1126
-
1127
- RIPEMD160.prototype._update = function update(msg, start) {
1128
- var A = this.h[0];
1129
- var B = this.h[1];
1130
- var C = this.h[2];
1131
- var D = this.h[3];
1132
- var E = this.h[4];
1133
- var Ah = A;
1134
- var Bh = B;
1135
- var Ch = C;
1136
- var Dh = D;
1137
- var Eh = E;
1138
- for (var j = 0; j < 80; j++) {
1139
- var T = sum32(
1140
- rotl32(
1141
- sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
1142
- s[j]),
1143
- E);
1144
- A = E;
1145
- E = D;
1146
- D = rotl32(C, 10);
1147
- C = B;
1148
- B = T;
1149
- T = sum32(
1150
- rotl32(
1151
- sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
1152
- sh[j]),
1153
- Eh);
1154
- Ah = Eh;
1155
- Eh = Dh;
1156
- Dh = rotl32(Ch, 10);
1157
- Ch = Bh;
1158
- Bh = T;
1159
- }
1160
- T = sum32_3(this.h[1], C, Dh);
1161
- this.h[1] = sum32_3(this.h[2], D, Eh);
1162
- this.h[2] = sum32_3(this.h[3], E, Ah);
1163
- this.h[3] = sum32_3(this.h[4], A, Bh);
1164
- this.h[4] = sum32_3(this.h[0], B, Ch);
1165
- this.h[0] = T;
1166
- };
1167
-
1168
- RIPEMD160.prototype._digest = function digest(enc) {
1169
- if (enc === 'hex')
1170
- return utils$1.toHex32(this.h, 'little');
1171
- else
1172
- return utils$1.split32(this.h, 'little');
1173
- };
1174
-
1175
- function f(j, x, y, z) {
1176
- if (j <= 15)
1177
- return x ^ y ^ z;
1178
- else if (j <= 31)
1179
- return (x & y) | ((~x) & z);
1180
- else if (j <= 47)
1181
- return (x | (~y)) ^ z;
1182
- else if (j <= 63)
1183
- return (x & z) | (y & (~z));
1184
- else
1185
- return x ^ (y | (~z));
1186
- }
1187
-
1188
- function K(j) {
1189
- if (j <= 15)
1190
- return 0x00000000;
1191
- else if (j <= 31)
1192
- return 0x5a827999;
1193
- else if (j <= 47)
1194
- return 0x6ed9eba1;
1195
- else if (j <= 63)
1196
- return 0x8f1bbcdc;
1197
- else
1198
- return 0xa953fd4e;
1199
- }
1200
-
1201
- function Kh(j) {
1202
- if (j <= 15)
1203
- return 0x50a28be6;
1204
- else if (j <= 31)
1205
- return 0x5c4dd124;
1206
- else if (j <= 47)
1207
- return 0x6d703ef3;
1208
- else if (j <= 63)
1209
- return 0x7a6d76e9;
1210
- else
1211
- return 0x00000000;
1212
- }
1213
-
1214
- var r = [
1215
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
1216
- 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
1217
- 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
1218
- 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
1219
- 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
1220
- ];
1221
-
1222
- var rh = [
1223
- 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
1224
- 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
1225
- 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
1226
- 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
1227
- 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
1228
- ];
1229
-
1230
- var s = [
1231
- 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
1232
- 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
1233
- 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
1234
- 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
1235
- 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
1236
- ];
1237
-
1238
- var sh = [
1239
- 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
1240
- 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
1241
- 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
1242
- 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
1243
- 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
1244
- ];
1245
-
1246
- var utils = utils$9;
1247
- var assert$1 = minimalisticAssert;
1248
-
1249
- function Hmac(hash, key, enc) {
1250
- if (!(this instanceof Hmac))
1251
- return new Hmac(hash, key, enc);
1252
- this.Hash = hash;
1253
- this.blockSize = hash.blockSize / 8;
1254
- this.outSize = hash.outSize / 8;
1255
- this.inner = null;
1256
- this.outer = null;
1257
-
1258
- this._init(utils.toArray(key, enc));
1259
- }
1260
- var hmac = Hmac;
1261
-
1262
- Hmac.prototype._init = function init(key) {
1263
- // Shorten key, if needed
1264
- if (key.length > this.blockSize)
1265
- key = new this.Hash().update(key).digest();
1266
- assert$1(key.length <= this.blockSize);
1267
-
1268
- // Add padding to key
1269
- for (var i = key.length; i < this.blockSize; i++)
1270
- key.push(0);
1271
-
1272
- for (i = 0; i < key.length; i++)
1273
- key[i] ^= 0x36;
1274
- this.inner = new this.Hash().update(key);
1275
-
1276
- // 0x36 ^ 0x5c = 0x6a
1277
- for (i = 0; i < key.length; i++)
1278
- key[i] ^= 0x6a;
1279
- this.outer = new this.Hash().update(key);
1280
- };
1281
-
1282
- Hmac.prototype.update = function update(msg, enc) {
1283
- this.inner.update(msg, enc);
1284
- return this;
1285
- };
1286
-
1287
- Hmac.prototype.digest = function digest(enc) {
1288
- this.outer.update(this.inner.digest());
1289
- return this.outer.digest(enc);
1290
- };
1291
-
1292
- (function (exports) {
1293
- var hash = exports;
1294
-
1295
- hash.utils = utils$9;
1296
- hash.common = common$5;
1297
- hash.sha = sha;
1298
- hash.ripemd = ripemd;
1299
- hash.hmac = hmac;
1300
-
1301
- // Proxy hash functions to the main object
1302
- hash.sha1 = hash.sha.sha1;
1303
- hash.sha256 = hash.sha.sha256;
1304
- hash.sha224 = hash.sha.sha224;
1305
- hash.sha384 = hash.sha.sha384;
1306
- hash.sha512 = hash.sha.sha512;
1307
- hash.ripemd160 = hash.ripemd.ripemd160;
1308
- } (hash$1));
1309
-
1310
- var hash = hash$1;
1311
-
1312
- const version$2 = "logger/5.6.0";
1313
-
1314
- let _permanentCensorErrors = false;
1315
- let _censorErrors = false;
1316
- const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
1317
- let _logLevel = LogLevels["default"];
1318
- let _globalLogger = null;
1319
- function _checkNormalize() {
1320
- try {
1321
- const missing = [];
1322
- // Make sure all forms of normalization are supported
1323
- ["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
1324
- try {
1325
- if ("test".normalize(form) !== "test") {
1326
- throw new Error("bad normalize");
1327
- }
1328
- ;
1329
- }
1330
- catch (error) {
1331
- missing.push(form);
1332
- }
1333
- });
1334
- if (missing.length) {
1335
- throw new Error("missing " + missing.join(", "));
1336
- }
1337
- if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
1338
- throw new Error("broken implementation");
1339
- }
1340
- }
1341
- catch (error) {
1342
- return error.message;
1343
- }
1344
- return null;
1345
- }
1346
- const _normalizeError = _checkNormalize();
1347
- var LogLevel;
1348
- (function (LogLevel) {
1349
- LogLevel["DEBUG"] = "DEBUG";
1350
- LogLevel["INFO"] = "INFO";
1351
- LogLevel["WARNING"] = "WARNING";
1352
- LogLevel["ERROR"] = "ERROR";
1353
- LogLevel["OFF"] = "OFF";
1354
- })(LogLevel || (LogLevel = {}));
1355
- var ErrorCode;
1356
- (function (ErrorCode) {
1357
- ///////////////////
1358
- // Generic Errors
1359
- // Unknown Error
1360
- ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
1361
- // Not Implemented
1362
- ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
1363
- // Unsupported Operation
1364
- // - operation
1365
- ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
1366
- // Network Error (i.e. Ethereum Network, such as an invalid chain ID)
1367
- // - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
1368
- ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
1369
- // Some sort of bad response from the server
1370
- ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
1371
- // Timeout
1372
- ErrorCode["TIMEOUT"] = "TIMEOUT";
1373
- ///////////////////
1374
- // Operational Errors
1375
- // Buffer Overrun
1376
- ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
1377
- // Numeric Fault
1378
- // - operation: the operation being executed
1379
- // - fault: the reason this faulted
1380
- ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
1381
- ///////////////////
1382
- // Argument Errors
1383
- // Missing new operator to an object
1384
- // - name: The name of the class
1385
- ErrorCode["MISSING_NEW"] = "MISSING_NEW";
1386
- // Invalid argument (e.g. value is incompatible with type) to a function:
1387
- // - argument: The argument name that was invalid
1388
- // - value: The value of the argument
1389
- ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
1390
- // Missing argument to a function:
1391
- // - count: The number of arguments received
1392
- // - expectedCount: The number of arguments expected
1393
- ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
1394
- // Too many arguments
1395
- // - count: The number of arguments received
1396
- // - expectedCount: The number of arguments expected
1397
- ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
1398
- ///////////////////
1399
- // Blockchain Errors
1400
- // Call exception
1401
- // - transaction: the transaction
1402
- // - address?: the contract address
1403
- // - args?: The arguments passed into the function
1404
- // - method?: The Solidity method signature
1405
- // - errorSignature?: The EIP848 error signature
1406
- // - errorArgs?: The EIP848 error parameters
1407
- // - reason: The reason (only for EIP848 "Error(string)")
1408
- ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
1409
- // Insufficient funds (< value + gasLimit * gasPrice)
1410
- // - transaction: the transaction attempted
1411
- ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
1412
- // Nonce has already been used
1413
- // - transaction: the transaction attempted
1414
- ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
1415
- // The replacement fee for the transaction is too low
1416
- // - transaction: the transaction attempted
1417
- ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
1418
- // The gas limit could not be estimated
1419
- // - transaction: the transaction passed to estimateGas
1420
- ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
1421
- // The transaction was replaced by one with a higher gas price
1422
- // - reason: "cancelled", "replaced" or "repriced"
1423
- // - cancelled: true if reason == "cancelled" or reason == "replaced")
1424
- // - hash: original transaction hash
1425
- // - replacement: the full TransactionsResponse for the replacement
1426
- // - receipt: the receipt of the replacement
1427
- ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
1428
- })(ErrorCode || (ErrorCode = {}));
1429
- const HEX = "0123456789abcdef";
1430
- class Logger {
1431
- constructor(version) {
1432
- Object.defineProperty(this, "version", {
1433
- enumerable: true,
1434
- value: version,
1435
- writable: false
1436
- });
1437
- }
1438
- _log(logLevel, args) {
1439
- const level = logLevel.toLowerCase();
1440
- if (LogLevels[level] == null) {
1441
- this.throwArgumentError("invalid log level name", "logLevel", logLevel);
1442
- }
1443
- if (_logLevel > LogLevels[level]) {
1444
- return;
1445
- }
1446
- console.log.apply(console, args);
1447
- }
1448
- debug(...args) {
1449
- this._log(Logger.levels.DEBUG, args);
1450
- }
1451
- info(...args) {
1452
- this._log(Logger.levels.INFO, args);
1453
- }
1454
- warn(...args) {
1455
- this._log(Logger.levels.WARNING, args);
1456
- }
1457
- makeError(message, code, params) {
1458
- // Errors are being censored
1459
- if (_censorErrors) {
1460
- return this.makeError("censored error", code, {});
1461
- }
1462
- if (!code) {
1463
- code = Logger.errors.UNKNOWN_ERROR;
1464
- }
1465
- if (!params) {
1466
- params = {};
1467
- }
1468
- const messageDetails = [];
1469
- Object.keys(params).forEach((key) => {
1470
- const value = params[key];
1471
- try {
1472
- if (value instanceof Uint8Array) {
1473
- let hex = "";
1474
- for (let i = 0; i < value.length; i++) {
1475
- hex += HEX[value[i] >> 4];
1476
- hex += HEX[value[i] & 0x0f];
1477
- }
1478
- messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
1479
- }
1480
- else {
1481
- messageDetails.push(key + "=" + JSON.stringify(value));
1482
- }
1483
- }
1484
- catch (error) {
1485
- messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
1486
- }
1487
- });
1488
- messageDetails.push(`code=${code}`);
1489
- messageDetails.push(`version=${this.version}`);
1490
- const reason = message;
1491
- let url = "";
1492
- switch (code) {
1493
- case ErrorCode.NUMERIC_FAULT: {
1494
- url = "NUMERIC_FAULT";
1495
- const fault = message;
1496
- switch (fault) {
1497
- case "overflow":
1498
- case "underflow":
1499
- case "division-by-zero":
1500
- url += "-" + fault;
1501
- break;
1502
- case "negative-power":
1503
- case "negative-width":
1504
- url += "-unsupported";
1505
- break;
1506
- case "unbound-bitwise-result":
1507
- url += "-unbound-result";
1508
- break;
1509
- }
1510
- break;
1511
- }
1512
- case ErrorCode.CALL_EXCEPTION:
1513
- case ErrorCode.INSUFFICIENT_FUNDS:
1514
- case ErrorCode.MISSING_NEW:
1515
- case ErrorCode.NONCE_EXPIRED:
1516
- case ErrorCode.REPLACEMENT_UNDERPRICED:
1517
- case ErrorCode.TRANSACTION_REPLACED:
1518
- case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
1519
- url = code;
1520
- break;
1521
- }
1522
- if (url) {
1523
- message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
1524
- }
1525
- if (messageDetails.length) {
1526
- message += " (" + messageDetails.join(", ") + ")";
1527
- }
1528
- // @TODO: Any??
1529
- const error = new Error(message);
1530
- error.reason = reason;
1531
- error.code = code;
1532
- Object.keys(params).forEach(function (key) {
1533
- error[key] = params[key];
1534
- });
1535
- return error;
1536
- }
1537
- throwError(message, code, params) {
1538
- throw this.makeError(message, code, params);
1539
- }
1540
- throwArgumentError(message, name, value) {
1541
- return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
1542
- argument: name,
1543
- value: value
1544
- });
1545
- }
1546
- assert(condition, message, code, params) {
1547
- if (!!condition) {
1548
- return;
1549
- }
1550
- this.throwError(message, code, params);
1551
- }
1552
- assertArgument(condition, message, name, value) {
1553
- if (!!condition) {
1554
- return;
1555
- }
1556
- this.throwArgumentError(message, name, value);
1557
- }
1558
- checkNormalize(message) {
1559
- if (_normalizeError) {
1560
- this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
1561
- operation: "String.prototype.normalize", form: _normalizeError
1562
- });
1563
- }
1564
- }
1565
- checkSafeUint53(value, message) {
1566
- if (typeof (value) !== "number") {
1567
- return;
1568
- }
1569
- if (message == null) {
1570
- message = "value not safe";
1571
- }
1572
- if (value < 0 || value >= 0x1fffffffffffff) {
1573
- this.throwError(message, Logger.errors.NUMERIC_FAULT, {
1574
- operation: "checkSafeInteger",
1575
- fault: "out-of-safe-range",
1576
- value: value
1577
- });
1578
- }
1579
- if (value % 1) {
1580
- this.throwError(message, Logger.errors.NUMERIC_FAULT, {
1581
- operation: "checkSafeInteger",
1582
- fault: "non-integer",
1583
- value: value
1584
- });
1585
- }
1586
- }
1587
- checkArgumentCount(count, expectedCount, message) {
1588
- if (message) {
1589
- message = ": " + message;
1590
- }
1591
- else {
1592
- message = "";
1593
- }
1594
- if (count < expectedCount) {
1595
- this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
1596
- count: count,
1597
- expectedCount: expectedCount
1598
- });
1599
- }
1600
- if (count > expectedCount) {
1601
- this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
1602
- count: count,
1603
- expectedCount: expectedCount
1604
- });
1605
- }
1606
- }
1607
- checkNew(target, kind) {
1608
- if (target === Object || target == null) {
1609
- this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
1610
- }
1611
- }
1612
- checkAbstract(target, kind) {
1613
- if (target === kind) {
1614
- this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
1615
- }
1616
- else if (target === Object || target == null) {
1617
- this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
1618
- }
1619
- }
1620
- static globalLogger() {
1621
- if (!_globalLogger) {
1622
- _globalLogger = new Logger(version$2);
1623
- }
1624
- return _globalLogger;
1625
- }
1626
- static setCensorship(censorship, permanent) {
1627
- if (!censorship && permanent) {
1628
- this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
1629
- operation: "setCensorship"
1630
- });
1631
- }
1632
- if (_permanentCensorErrors) {
1633
- if (!censorship) {
1634
- return;
1635
- }
1636
- this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
1637
- operation: "setCensorship"
1638
- });
1639
- }
1640
- _censorErrors = !!censorship;
1641
- _permanentCensorErrors = !!permanent;
1642
- }
1643
- static setLogLevel(logLevel) {
1644
- const level = LogLevels[logLevel.toLowerCase()];
1645
- if (level == null) {
1646
- Logger.globalLogger().warn("invalid log level - " + logLevel);
1647
- return;
1648
- }
1649
- _logLevel = level;
1650
- }
1651
- static from(version) {
1652
- return new Logger(version);
1653
- }
1654
- }
1655
- Logger.errors = ErrorCode;
1656
- Logger.levels = LogLevel;
1657
-
1658
- const version$1 = "bytes/5.6.0";
1659
-
1660
- const logger = new Logger(version$1);
1661
- ///////////////////////////////
1662
- function isHexable(value) {
1663
- return !!(value.toHexString);
1664
- }
1665
- function addSlice(array) {
1666
- if (array.slice) {
1667
- return array;
1668
- }
1669
- array.slice = function () {
1670
- const args = Array.prototype.slice.call(arguments);
1671
- return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
1672
- };
1673
- return array;
1674
- }
1675
- function isInteger(value) {
1676
- return (typeof (value) === "number" && value == value && (value % 1) === 0);
1677
- }
1678
- function isBytes(value) {
1679
- if (value == null) {
1680
- return false;
1681
- }
1682
- if (value.constructor === Uint8Array) {
1683
- return true;
1684
- }
1685
- if (typeof (value) === "string") {
1686
- return false;
1687
- }
1688
- if (!isInteger(value.length) || value.length < 0) {
1689
- return false;
1690
- }
1691
- for (let i = 0; i < value.length; i++) {
1692
- const v = value[i];
1693
- if (!isInteger(v) || v < 0 || v >= 256) {
1694
- return false;
1695
- }
1696
- }
1697
- return true;
1698
- }
1699
- function arrayify(value, options) {
1700
- if (!options) {
1701
- options = {};
1702
- }
1703
- if (typeof (value) === "number") {
1704
- logger.checkSafeUint53(value, "invalid arrayify value");
1705
- const result = [];
1706
- while (value) {
1707
- result.unshift(value & 0xff);
1708
- value = parseInt(String(value / 256));
1709
- }
1710
- if (result.length === 0) {
1711
- result.push(0);
1712
- }
1713
- return addSlice(new Uint8Array(result));
1714
- }
1715
- if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
1716
- value = "0x" + value;
1717
- }
1718
- if (isHexable(value)) {
1719
- value = value.toHexString();
1720
- }
1721
- if (isHexString(value)) {
1722
- let hex = value.substring(2);
1723
- if (hex.length % 2) {
1724
- if (options.hexPad === "left") {
1725
- hex = "0x0" + hex.substring(2);
1726
- }
1727
- else if (options.hexPad === "right") {
1728
- hex += "0";
1729
- }
1730
- else {
1731
- logger.throwArgumentError("hex data is odd-length", "value", value);
1732
- }
1733
- }
1734
- const result = [];
1735
- for (let i = 0; i < hex.length; i += 2) {
1736
- result.push(parseInt(hex.substring(i, i + 2), 16));
1737
- }
1738
- return addSlice(new Uint8Array(result));
1739
- }
1740
- if (isBytes(value)) {
1741
- return addSlice(new Uint8Array(value));
1742
- }
1743
- return logger.throwArgumentError("invalid arrayify value", "value", value);
1744
- }
1745
- function isHexString(value, length) {
1746
- if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
1747
- return false;
1748
- }
1749
- if (length && value.length !== 2 + 2 * length) {
1750
- return false;
1751
- }
1752
- return true;
1753
- }
1754
-
1755
- const version = "sha2/5.6.0";
1756
-
1757
- new Logger(version);
1758
- function sha256(data) {
1759
- return "0x" + (hash.sha256().update(arrayify(data)).digest("hex"));
1760
- }
1761
-
1762
93
  class Struct {
1763
94
  constructor(properties) {
1764
95
  Object.assign(this, properties);
@@ -1801,6 +132,11 @@ const SOLANA_SCHEMA = new Map();
1801
132
  */
1802
133
 
1803
134
  const MAX_SEED_LENGTH = 32;
135
+ /**
136
+ * Size of public key in bytes
137
+ */
138
+
139
+ const PUBLIC_KEY_LENGTH = 32;
1804
140
  /**
1805
141
  * Value to be converted into public key
1806
142
  */
@@ -1831,7 +167,7 @@ class PublicKey extends Struct {
1831
167
  // assume base 58 encoding by default
1832
168
  const decoded = bs58__default["default"].decode(value);
1833
169
 
1834
- if (decoded.length != 32) {
170
+ if (decoded.length != PUBLIC_KEY_LENGTH) {
1835
171
  throw new Error(`Invalid public key input`);
1836
172
  }
1837
173
 
@@ -1884,7 +220,7 @@ class PublicKey extends Struct {
1884
220
  toBuffer() {
1885
221
  const b = this._bn.toArrayLike(buffer.Buffer);
1886
222
 
1887
- if (b.length === 32) {
223
+ if (b.length === PUBLIC_KEY_LENGTH) {
1888
224
  return b;
1889
225
  }
1890
226
 
@@ -1911,8 +247,8 @@ class PublicKey extends Struct {
1911
247
 
1912
248
  static async createWithSeed(fromPublicKey, seed, programId) {
1913
249
  const buffer$1 = buffer.Buffer.concat([fromPublicKey.toBuffer(), buffer.Buffer.from(seed), programId.toBuffer()]);
1914
- const hash = sha256(new Uint8Array(buffer$1)).slice(2);
1915
- return new PublicKey(buffer.Buffer.from(hash, 'hex'));
250
+ const publicKeyBytes = sha256.sha256(buffer$1);
251
+ return new PublicKey(publicKeyBytes);
1916
252
  }
1917
253
  /**
1918
254
  * Derive a program address from seeds and a program ID.
@@ -1931,10 +267,9 @@ class PublicKey extends Struct {
1931
267
  buffer$1 = buffer.Buffer.concat([buffer$1, toBuffer(seed)]);
1932
268
  });
1933
269
  buffer$1 = buffer.Buffer.concat([buffer$1, programId.toBuffer(), buffer.Buffer.from('ProgramDerivedAddress')]);
1934
- let hash = sha256(new Uint8Array(buffer$1)).slice(2);
1935
- let publicKeyBytes = new BN__default["default"](hash, 16).toArray(undefined, 32);
270
+ const publicKeyBytes = sha256.sha256(buffer$1);
1936
271
 
1937
- if (is_on_curve(publicKeyBytes)) {
272
+ if (isOnCurve(publicKeyBytes)) {
1938
273
  throw new Error(`Invalid seeds, address must fall off the curve`);
1939
274
  }
1940
275
 
@@ -1998,7 +333,7 @@ class PublicKey extends Struct {
1998
333
 
1999
334
  static isOnCurve(pubkeyData) {
2000
335
  const pubkey = new PublicKey(pubkeyData);
2001
- return is_on_curve(pubkey.toBytes()) == 1;
336
+ return isOnCurve(pubkey.toBytes());
2002
337
  }
2003
338
 
2004
339
  }
@@ -2006,56 +341,7 @@ PublicKey.default = new PublicKey('11111111111111111111111111111111');
2006
341
  SOLANA_SCHEMA.set(PublicKey, {
2007
342
  kind: 'struct',
2008
343
  fields: [['_bn', 'u256']]
2009
- }); // @ts-ignore
2010
-
2011
- let naclLowLevel = nacl__default["default"].lowlevel; // Check that a pubkey is on the curve.
2012
- // This function and its dependents were sourced from:
2013
- // https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
2014
-
2015
- function is_on_curve(p) {
2016
- var r = [naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf()];
2017
- var t = naclLowLevel.gf(),
2018
- chk = naclLowLevel.gf(),
2019
- num = naclLowLevel.gf(),
2020
- den = naclLowLevel.gf(),
2021
- den2 = naclLowLevel.gf(),
2022
- den4 = naclLowLevel.gf(),
2023
- den6 = naclLowLevel.gf();
2024
- naclLowLevel.set25519(r[2], gf1);
2025
- naclLowLevel.unpack25519(r[1], p);
2026
- naclLowLevel.S(num, r[1]);
2027
- naclLowLevel.M(den, num, naclLowLevel.D);
2028
- naclLowLevel.Z(num, num, r[2]);
2029
- naclLowLevel.A(den, r[2], den);
2030
- naclLowLevel.S(den2, den);
2031
- naclLowLevel.S(den4, den2);
2032
- naclLowLevel.M(den6, den4, den2);
2033
- naclLowLevel.M(t, den6, num);
2034
- naclLowLevel.M(t, t, den);
2035
- naclLowLevel.pow2523(t, t);
2036
- naclLowLevel.M(t, t, num);
2037
- naclLowLevel.M(t, t, den);
2038
- naclLowLevel.M(t, t, den);
2039
- naclLowLevel.M(r[0], t, den);
2040
- naclLowLevel.S(chk, r[0]);
2041
- naclLowLevel.M(chk, chk, den);
2042
- if (neq25519(chk, num)) naclLowLevel.M(r[0], r[0], I);
2043
- naclLowLevel.S(chk, r[0]);
2044
- naclLowLevel.M(chk, chk, den);
2045
- if (neq25519(chk, num)) return 0;
2046
- return 1;
2047
- }
2048
-
2049
- let gf1 = naclLowLevel.gf([1]);
2050
- let I = naclLowLevel.gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
2051
-
2052
- function neq25519(a, b) {
2053
- var c = new Uint8Array(32),
2054
- d = new Uint8Array(32);
2055
- naclLowLevel.pack25519(c, a);
2056
- naclLowLevel.pack25519(d, b);
2057
- return naclLowLevel.crypto_verify_32(c, 0, d, 0);
2058
- }
344
+ });
2059
345
 
2060
346
  /**
2061
347
  * An account key pair (public and secret keys).
@@ -2066,6 +352,8 @@ function neq25519(a, b) {
2066
352
  class Account {
2067
353
  /** @internal */
2068
354
 
355
+ /** @internal */
356
+
2069
357
  /**
2070
358
  * Create a new Account object
2071
359
  *
@@ -2075,12 +363,21 @@ class Account {
2075
363
  * @param secretKey Secret key for the account
2076
364
  */
2077
365
  constructor(secretKey) {
2078
- this._keypair = void 0;
366
+ this._publicKey = void 0;
367
+ this._secretKey = void 0;
2079
368
 
2080
369
  if (secretKey) {
2081
- this._keypair = nacl__default["default"].sign.keyPair.fromSecretKey(toBuffer(secretKey));
370
+ const secretKeyBuffer = toBuffer(secretKey);
371
+
372
+ if (secretKey.length !== 64) {
373
+ throw new Error('bad secret key size');
374
+ }
375
+
376
+ this._publicKey = secretKeyBuffer.slice(32, 64);
377
+ this._secretKey = secretKeyBuffer.slice(0, 32);
2082
378
  } else {
2083
- this._keypair = nacl__default["default"].sign.keyPair();
379
+ this._secretKey = toBuffer(generatePrivateKey());
380
+ this._publicKey = toBuffer(getPublicKey(this._secretKey));
2084
381
  }
2085
382
  }
2086
383
  /**
@@ -2089,15 +386,17 @@ class Account {
2089
386
 
2090
387
 
2091
388
  get publicKey() {
2092
- return new PublicKey(this._keypair.publicKey);
389
+ return new PublicKey(this._publicKey);
2093
390
  }
2094
391
  /**
2095
- * The **unencrypted** secret key for this account
392
+ * The **unencrypted** secret key for this account. The first 32 bytes
393
+ * is the private scalar and the last 32 bytes is the public key.
394
+ * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
2096
395
  */
2097
396
 
2098
397
 
2099
398
  get secretKey() {
2100
- return toBuffer(this._keypair.secretKey);
399
+ return buffer.Buffer.concat([this._secretKey, this._publicKey], 64);
2101
400
  }
2102
401
 
2103
402
  }
@@ -2112,6 +411,7 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
2112
411
  * 8 bytes is the size of the fragment header
2113
412
  */
2114
413
  const PACKET_DATA_SIZE = 1280 - 40 - 8;
414
+ const VERSION_PREFIX_MASK = 0x7f;
2115
415
  const SIGNATURE_LENGTH_IN_BYTES = 64;
2116
416
 
2117
417
  class TransactionExpiredBlockheightExceededError extends Error {
@@ -2144,6 +444,13 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
2144
444
  const publicKey = (property = 'publicKey') => {
2145
445
  return BufferLayout__namespace.blob(32, property);
2146
446
  };
447
+ /**
448
+ * Layout for a signature
449
+ */
450
+
451
+ const signature = (property = 'signature') => {
452
+ return BufferLayout__namespace.blob(64, property);
453
+ };
2147
454
 
2148
455
  /**
2149
456
  * Layout for a Rust String type
@@ -2255,11 +562,9 @@ function encodeLength(bytes, len) {
2255
562
  }
2256
563
  }
2257
564
 
2258
- const PUBKEY_LENGTH = 32;
2259
565
  /**
2260
566
  * List of instructions to be processed atomically
2261
567
  */
2262
-
2263
568
  class Message {
2264
569
  constructor(args) {
2265
570
  this.header = void 0;
@@ -2274,6 +579,26 @@ class Message {
2274
579
  this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
2275
580
  }
2276
581
 
582
+ get version() {
583
+ return 'legacy';
584
+ }
585
+
586
+ get staticAccountKeys() {
587
+ return this.accountKeys;
588
+ }
589
+
590
+ get compiledInstructions() {
591
+ return this.instructions.map(ix => ({
592
+ programIdIndex: ix.programIdIndex,
593
+ accountKeyIndexes: ix.accounts,
594
+ data: bs58__default["default"].decode(ix.data)
595
+ }));
596
+ }
597
+
598
+ get addressTableLookups() {
599
+ return [];
600
+ }
601
+
2277
602
  isAccountSigner(index) {
2278
603
  return index < this.header.numRequiredSignatures;
2279
604
  }
@@ -2350,19 +675,24 @@ class Message {
2350
675
  // Slice up wire data
2351
676
  let byteArray = [...buffer$1];
2352
677
  const numRequiredSignatures = byteArray.shift();
678
+
679
+ if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
680
+ throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
681
+ }
682
+
2353
683
  const numReadonlySignedAccounts = byteArray.shift();
2354
684
  const numReadonlyUnsignedAccounts = byteArray.shift();
2355
685
  const accountCount = decodeLength(byteArray);
2356
686
  let accountKeys = [];
2357
687
 
2358
688
  for (let i = 0; i < accountCount; i++) {
2359
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2360
- byteArray = byteArray.slice(PUBKEY_LENGTH);
689
+ const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
690
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2361
691
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2362
692
  }
2363
693
 
2364
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2365
- byteArray = byteArray.slice(PUBKEY_LENGTH);
694
+ const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
695
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2366
696
  const instructionCount = decodeLength(byteArray);
2367
697
  let instructions = [];
2368
698
 
@@ -2403,6 +733,194 @@ function assert (condition, message) {
2403
733
  }
2404
734
  }
2405
735
 
736
+ /**
737
+ * Message constructor arguments
738
+ */
739
+
740
+ class MessageV0 {
741
+ constructor(args) {
742
+ this.header = void 0;
743
+ this.staticAccountKeys = void 0;
744
+ this.recentBlockhash = void 0;
745
+ this.compiledInstructions = void 0;
746
+ this.addressTableLookups = void 0;
747
+ this.header = args.header;
748
+ this.staticAccountKeys = args.staticAccountKeys;
749
+ this.recentBlockhash = args.recentBlockhash;
750
+ this.compiledInstructions = args.compiledInstructions;
751
+ this.addressTableLookups = args.addressTableLookups;
752
+ }
753
+
754
+ get version() {
755
+ return 0;
756
+ }
757
+
758
+ serialize() {
759
+ const encodedStaticAccountKeysLength = Array();
760
+ encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
761
+ const serializedInstructions = this.serializeInstructions();
762
+ const encodedInstructionsLength = Array();
763
+ encodeLength(encodedInstructionsLength, this.compiledInstructions.length);
764
+ const serializedAddressTableLookups = this.serializeAddressTableLookups();
765
+ const encodedAddressTableLookupsLength = Array();
766
+ encodeLength(encodedAddressTableLookupsLength, this.addressTableLookups.length);
767
+ const messageLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u8('prefix'), BufferLayout__namespace.struct([BufferLayout__namespace.u8('numRequiredSignatures'), BufferLayout__namespace.u8('numReadonlySignedAccounts'), BufferLayout__namespace.u8('numReadonlyUnsignedAccounts')], 'header'), BufferLayout__namespace.blob(encodedStaticAccountKeysLength.length, 'staticAccountKeysLength'), BufferLayout__namespace.seq(publicKey(), this.staticAccountKeys.length, 'staticAccountKeys'), publicKey('recentBlockhash'), BufferLayout__namespace.blob(encodedInstructionsLength.length, 'instructionsLength'), BufferLayout__namespace.blob(serializedInstructions.length, 'serializedInstructions'), BufferLayout__namespace.blob(encodedAddressTableLookupsLength.length, 'addressTableLookupsLength'), BufferLayout__namespace.blob(serializedAddressTableLookups.length, 'serializedAddressTableLookups')]);
768
+ const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
769
+ const MESSAGE_VERSION_0_PREFIX = 1 << 7;
770
+ const serializedMessageLength = messageLayout.encode({
771
+ prefix: MESSAGE_VERSION_0_PREFIX,
772
+ header: this.header,
773
+ staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
774
+ staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
775
+ recentBlockhash: bs58__default["default"].decode(this.recentBlockhash),
776
+ instructionsLength: new Uint8Array(encodedInstructionsLength),
777
+ serializedInstructions,
778
+ addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
779
+ serializedAddressTableLookups
780
+ }, serializedMessage);
781
+ return serializedMessage.slice(0, serializedMessageLength);
782
+ }
783
+
784
+ serializeInstructions() {
785
+ let serializedLength = 0;
786
+ const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
787
+
788
+ for (const instruction of this.compiledInstructions) {
789
+ const encodedAccountKeyIndexesLength = Array();
790
+ encodeLength(encodedAccountKeyIndexesLength, instruction.accountKeyIndexes.length);
791
+ const encodedDataLength = Array();
792
+ encodeLength(encodedDataLength, instruction.data.length);
793
+ const instructionLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u8('programIdIndex'), BufferLayout__namespace.blob(encodedAccountKeyIndexesLength.length, 'encodedAccountKeyIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), instruction.accountKeyIndexes.length, 'accountKeyIndexes'), BufferLayout__namespace.blob(encodedDataLength.length, 'encodedDataLength'), BufferLayout__namespace.blob(instruction.data.length, 'data')]);
794
+ serializedLength += instructionLayout.encode({
795
+ programIdIndex: instruction.programIdIndex,
796
+ encodedAccountKeyIndexesLength: new Uint8Array(encodedAccountKeyIndexesLength),
797
+ accountKeyIndexes: instruction.accountKeyIndexes,
798
+ encodedDataLength: new Uint8Array(encodedDataLength),
799
+ data: instruction.data
800
+ }, serializedInstructions, serializedLength);
801
+ }
802
+
803
+ return serializedInstructions.slice(0, serializedLength);
804
+ }
805
+
806
+ serializeAddressTableLookups() {
807
+ let serializedLength = 0;
808
+ const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
809
+
810
+ for (const lookup of this.addressTableLookups) {
811
+ const encodedWritableIndexesLength = Array();
812
+ encodeLength(encodedWritableIndexesLength, lookup.writableIndexes.length);
813
+ const encodedReadonlyIndexesLength = Array();
814
+ encodeLength(encodedReadonlyIndexesLength, lookup.readonlyIndexes.length);
815
+ const addressTableLookupLayout = BufferLayout__namespace.struct([publicKey('accountKey'), BufferLayout__namespace.blob(encodedWritableIndexesLength.length, 'encodedWritableIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), lookup.writableIndexes.length, 'writableIndexes'), BufferLayout__namespace.blob(encodedReadonlyIndexesLength.length, 'encodedReadonlyIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), lookup.readonlyIndexes.length, 'readonlyIndexes')]);
816
+ serializedLength += addressTableLookupLayout.encode({
817
+ accountKey: lookup.accountKey.toBytes(),
818
+ encodedWritableIndexesLength: new Uint8Array(encodedWritableIndexesLength),
819
+ writableIndexes: lookup.writableIndexes,
820
+ encodedReadonlyIndexesLength: new Uint8Array(encodedReadonlyIndexesLength),
821
+ readonlyIndexes: lookup.readonlyIndexes
822
+ }, serializedAddressTableLookups, serializedLength);
823
+ }
824
+
825
+ return serializedAddressTableLookups.slice(0, serializedLength);
826
+ }
827
+
828
+ static deserialize(serializedMessage) {
829
+ let byteArray = [...serializedMessage];
830
+ const prefix = byteArray.shift();
831
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK;
832
+ assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
833
+ const version = maskedPrefix;
834
+ assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
835
+ const header = {
836
+ numRequiredSignatures: byteArray.shift(),
837
+ numReadonlySignedAccounts: byteArray.shift(),
838
+ numReadonlyUnsignedAccounts: byteArray.shift()
839
+ };
840
+ const staticAccountKeys = [];
841
+ const staticAccountKeysLength = decodeLength(byteArray);
842
+
843
+ for (let i = 0; i < staticAccountKeysLength; i++) {
844
+ staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
845
+ }
846
+
847
+ const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
848
+ const instructionCount = decodeLength(byteArray);
849
+ const compiledInstructions = [];
850
+
851
+ for (let i = 0; i < instructionCount; i++) {
852
+ const programIdIndex = byteArray.shift();
853
+ const accountKeyIndexesLength = decodeLength(byteArray);
854
+ const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
855
+ const dataLength = decodeLength(byteArray);
856
+ const data = new Uint8Array(byteArray.splice(0, dataLength));
857
+ compiledInstructions.push({
858
+ programIdIndex,
859
+ accountKeyIndexes,
860
+ data
861
+ });
862
+ }
863
+
864
+ const addressTableLookupsCount = decodeLength(byteArray);
865
+ const addressTableLookups = [];
866
+
867
+ for (let i = 0; i < addressTableLookupsCount; i++) {
868
+ const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
869
+ const writableIndexesLength = decodeLength(byteArray);
870
+ const writableIndexes = byteArray.splice(0, writableIndexesLength);
871
+ const readonlyIndexesLength = decodeLength(byteArray);
872
+ const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
873
+ addressTableLookups.push({
874
+ accountKey,
875
+ writableIndexes,
876
+ readonlyIndexes
877
+ });
878
+ }
879
+
880
+ return new MessageV0({
881
+ header,
882
+ staticAccountKeys,
883
+ recentBlockhash,
884
+ compiledInstructions,
885
+ addressTableLookups
886
+ });
887
+ }
888
+
889
+ }
890
+
891
+ // eslint-disable-next-line no-redeclare
892
+ const VersionedMessage = {
893
+ deserializeMessageVersion(serializedMessage) {
894
+ const prefix = serializedMessage[0];
895
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
896
+
897
+ if (maskedPrefix === prefix) {
898
+ return 'legacy';
899
+ } // the lower 7 bits of the prefix indicate the message version
900
+
901
+
902
+ return maskedPrefix;
903
+ },
904
+
905
+ deserialize: serializedMessage => {
906
+ const version = VersionedMessage.deserializeMessageVersion(serializedMessage);
907
+
908
+ if (version === 'legacy') {
909
+ return Message.from(serializedMessage);
910
+ }
911
+
912
+ if (version === 0) {
913
+ return MessageV0.deserialize(serializedMessage);
914
+ } else {
915
+ throw new Error(`Transaction message version ${version} deserialization is not supported`);
916
+ }
917
+ }
918
+ };
919
+
920
+ /**
921
+ * Transaction signature as base-58 encoded string
922
+ */
923
+
2406
924
  exports.TransactionStatus = void 0;
2407
925
  /**
2408
926
  * Default (empty) signature
@@ -2928,7 +1446,7 @@ class Transaction {
2928
1446
  _partialSign(message, ...signers) {
2929
1447
  const signData = message.serialize();
2930
1448
  signers.forEach(signer => {
2931
- const signature = nacl__default["default"].sign.detached(signData, signer.secretKey);
1449
+ const signature = sign(signData, signer.secretKey);
2932
1450
 
2933
1451
  this._addSignature(signer.publicKey, toBuffer(signature));
2934
1452
  });
@@ -2984,7 +1502,7 @@ class Transaction {
2984
1502
  return false;
2985
1503
  }
2986
1504
  } else {
2987
- if (!nacl__default["default"].sign.detached.verify(signData, signature, publicKey.toBuffer())) {
1505
+ if (!verify(signature, signData, publicKey.toBuffer())) {
2988
1506
  return false;
2989
1507
  }
2990
1508
  }
@@ -3131,6 +1649,70 @@ class Transaction {
3131
1649
 
3132
1650
  }
3133
1651
 
1652
+ /**
1653
+ * Versioned transaction class
1654
+ */
1655
+ class VersionedTransaction {
1656
+ constructor(message, signatures) {
1657
+ this.signatures = void 0;
1658
+ this.message = void 0;
1659
+
1660
+ if (signatures !== undefined) {
1661
+ assert(signatures.length === message.header.numRequiredSignatures, 'Expected signatures length to be equal to the number of required signatures');
1662
+ this.signatures = signatures;
1663
+ } else {
1664
+ const defaultSignatures = [];
1665
+
1666
+ for (let i = 0; i < message.header.numRequiredSignatures; i++) {
1667
+ defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
1668
+ }
1669
+
1670
+ this.signatures = defaultSignatures;
1671
+ }
1672
+
1673
+ this.message = message;
1674
+ }
1675
+
1676
+ serialize() {
1677
+ const serializedMessage = this.message.serialize();
1678
+ const encodedSignaturesLength = Array();
1679
+ encodeLength(encodedSignaturesLength, this.signatures.length);
1680
+ const transactionLayout = BufferLayout__namespace.struct([BufferLayout__namespace.blob(encodedSignaturesLength.length, 'encodedSignaturesLength'), BufferLayout__namespace.seq(signature(), this.signatures.length, 'signatures'), BufferLayout__namespace.blob(serializedMessage.length, 'serializedMessage')]);
1681
+ const serializedTransaction = new Uint8Array(2048);
1682
+ const serializedTransactionLength = transactionLayout.encode({
1683
+ encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
1684
+ signatures: this.signatures,
1685
+ serializedMessage
1686
+ }, serializedTransaction);
1687
+ return serializedTransaction.slice(0, serializedTransactionLength);
1688
+ }
1689
+
1690
+ static deserialize(serializedTransaction) {
1691
+ let byteArray = [...serializedTransaction];
1692
+ const signatures = [];
1693
+ const signaturesLength = decodeLength(byteArray);
1694
+
1695
+ for (let i = 0; i < signaturesLength; i++) {
1696
+ signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1697
+ }
1698
+
1699
+ const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
1700
+ return new VersionedTransaction(message, signatures);
1701
+ }
1702
+
1703
+ sign(signers) {
1704
+ const messageData = this.message.serialize();
1705
+ const signerPubkeys = this.message.staticAccountKeys.slice(0, this.message.header.numRequiredSignatures);
1706
+
1707
+ for (const signer of signers) {
1708
+ const signerIndex = signerPubkeys.findIndex(pubkey => pubkey.equals(signer.publicKey));
1709
+ assert(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
1710
+ this.signatures[signerIndex] = sign(messageData, signer.secretKey);
1711
+ }
1712
+ }
1713
+
1714
+ }
1715
+
3134
1716
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3135
1717
  const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3136
1718
  const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
@@ -4524,22 +3106,26 @@ const LookupTableMetaLayout = {
4524
3106
  BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u8(), -1), 'authority')])
4525
3107
  };
4526
3108
 
3109
+ const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
4527
3110
  function makeWebsocketUrl(endpoint) {
4528
- let url = new reactNativeUrlPolyfill.URL(endpoint);
4529
- const useHttps = url.protocol === 'https:';
4530
- url.protocol = useHttps ? 'wss:' : 'ws:';
4531
- url.host = ''; // Only shift the port by +1 as a convention for ws(s) only if given endpoint
3111
+ const matches = endpoint.match(URL_RE);
3112
+
3113
+ if (matches == null) {
3114
+ throw TypeError(`Failed to validate endpoint URL \`${endpoint}\``);
3115
+ }
3116
+
3117
+ const [_, // eslint-disable-line @typescript-eslint/no-unused-vars
3118
+ hostish, portWithColon, rest] = matches;
3119
+ const protocol = endpoint.startsWith('https:') ? 'wss:' : 'ws:';
3120
+ const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
3121
+ const websocketPort = // Only shift the port by +1 as a convention for ws(s) only if given endpoint
4532
3122
  // is explictly specifying the endpoint port (HTTP-based RPC), assuming
4533
3123
  // we're directly trying to connect to solana-validator's ws listening port.
4534
3124
  // When the endpoint omits the port, we're connecting to the protocol
4535
3125
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
4536
3126
  // proxy which manages WebSocket upgrade and backend port redirection.
4537
-
4538
- if (url.port !== '') {
4539
- url.port = String(Number(url.port) + 1);
4540
- }
4541
-
4542
- return url.toString();
3127
+ startPort == null ? '' : `:${startPort + 1}`;
3128
+ return `${protocol}//${hostish}${websocketPort}${rest}`;
4543
3129
  }
4544
3130
 
4545
3131
  var _process$env$npm_pack;
@@ -4559,7 +3145,17 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4559
3145
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4560
3146
  */
4561
3147
 
3148
+ /* @internal */
3149
+ function assertEndpointUrl(putativeUrl) {
3150
+ if (/^https?:/.test(putativeUrl) === false) {
3151
+ throw new TypeError('Endpoint URL must start with `http:` or `https:`.');
3152
+ }
3153
+
3154
+ return putativeUrl;
3155
+ }
4562
3156
  /** @internal */
3157
+
3158
+
4563
3159
  function extractCommitmentFromConfig(commitmentOrConfig) {
4564
3160
  let commitment;
4565
3161
  let config;
@@ -4754,7 +3350,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4754
3350
  * A performance sample
4755
3351
  */
4756
3352
 
4757
- function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
3353
+ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4758
3354
  const fetch = customFetch ? customFetch : fetchImpl;
4759
3355
 
4760
3356
  let fetchWithMiddleware;
@@ -5560,8 +4156,6 @@ class Connection {
5560
4156
  this._subscriptionCallbacksByServerSubscriptionId = {};
5561
4157
  this._subscriptionsByHash = {};
5562
4158
  this._subscriptionsAutoDisposedByRpc = new Set();
5563
- let url = new reactNativeUrlPolyfill.URL(endpoint);
5564
- const useHttps = url.protocol === 'https:';
5565
4159
  let wsEndpoint;
5566
4160
  let httpHeaders;
5567
4161
  let fetch;
@@ -5580,9 +4174,9 @@ class Connection {
5580
4174
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
5581
4175
  }
5582
4176
 
5583
- this._rpcEndpoint = endpoint;
4177
+ this._rpcEndpoint = assertEndpointUrl(endpoint);
5584
4178
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
5585
- this._rpcClient = createRpcClient(url.toString(), useHttps, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
4179
+ this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5586
4180
  this._rpcRequest = createRpcRequest(this._rpcClient);
5587
4181
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
5588
4182
  this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
@@ -8259,12 +6853,7 @@ class Keypair {
8259
6853
  */
8260
6854
  constructor(keypair) {
8261
6855
  this._keypair = void 0;
8262
-
8263
- if (keypair) {
8264
- this._keypair = keypair;
8265
- } else {
8266
- this._keypair = nacl__default["default"].sign.keyPair();
8267
- }
6856
+ this._keypair = keypair !== null && keypair !== void 0 ? keypair : generateKeypair();
8268
6857
  }
8269
6858
  /**
8270
6859
  * Generate a new random keypair
@@ -8272,7 +6861,7 @@ class Keypair {
8272
6861
 
8273
6862
 
8274
6863
  static generate() {
8275
- return new Keypair(nacl__default["default"].sign.keyPair());
6864
+ return new Keypair(generateKeypair());
8276
6865
  }
8277
6866
  /**
8278
6867
  * Create a keypair from a raw secret key byte array.
@@ -8289,19 +6878,27 @@ class Keypair {
8289
6878
 
8290
6879
 
8291
6880
  static fromSecretKey(secretKey, options) {
8292
- const keypair = nacl__default["default"].sign.keyPair.fromSecretKey(secretKey);
6881
+ if (secretKey.byteLength !== 64) {
6882
+ throw new Error('bad secret key size');
6883
+ }
6884
+
6885
+ const publicKey = secretKey.slice(32, 64);
8293
6886
 
8294
6887
  if (!options || !options.skipValidation) {
8295
- const encoder = new TextEncoder();
8296
- const signData = encoder.encode('@solana/web3.js-validation-v1');
8297
- const signature = nacl__default["default"].sign.detached(signData, keypair.secretKey);
6888
+ const privateScalar = secretKey.slice(0, 32);
6889
+ const computedPublicKey = getPublicKey(privateScalar);
8298
6890
 
8299
- if (!nacl__default["default"].sign.detached.verify(signData, signature, keypair.publicKey)) {
8300
- throw new Error('provided secretKey is invalid');
6891
+ for (let ii = 0; ii < 32; ii++) {
6892
+ if (publicKey[ii] !== computedPublicKey[ii]) {
6893
+ throw new Error('provided secretKey is invalid');
6894
+ }
8301
6895
  }
8302
6896
  }
8303
6897
 
8304
- return new Keypair(keypair);
6898
+ return new Keypair({
6899
+ publicKey,
6900
+ secretKey
6901
+ });
8305
6902
  }
8306
6903
  /**
8307
6904
  * Generate a keypair from a 32 byte seed.
@@ -8311,7 +6908,14 @@ class Keypair {
8311
6908
 
8312
6909
 
8313
6910
  static fromSeed(seed) {
8314
- return new Keypair(nacl__default["default"].sign.keyPair.fromSeed(seed));
6911
+ const publicKey = getPublicKey(seed);
6912
+ const secretKey = new Uint8Array(64);
6913
+ secretKey.set(seed);
6914
+ secretKey.set(publicKey, 32);
6915
+ return new Keypair({
6916
+ publicKey,
6917
+ secretKey
6918
+ });
8315
6919
  }
8316
6920
  /**
8317
6921
  * The public key for this keypair
@@ -8863,7 +7467,7 @@ class Ed25519Program {
8863
7467
  try {
8864
7468
  const keypair = Keypair.fromSecretKey(privateKey);
8865
7469
  const publicKey = keypair.publicKey.toBytes();
8866
- const signature = nacl__default["default"].sign.detached(message, keypair.secretKey);
7470
+ const signature = sign(message, keypair.secretKey);
8867
7471
  return this.createInstructionWithPublicKey({
8868
7472
  publicKey,
8869
7473
  message,
@@ -8878,10 +7482,21 @@ class Ed25519Program {
8878
7482
  }
8879
7483
  Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
8880
7484
 
8881
- const {
8882
- publicKeyCreate,
8883
- ecdsaSign
8884
- } = secp256k1__default["default"];
7485
+ // library interoperable with the synchronous APIs in web3.js.
7486
+
7487
+ secp256k1__namespace.utils.hmacSha256Sync = (key, ...msgs) => {
7488
+ const h = hmac.hmac.create(sha256.sha256, key);
7489
+ msgs.forEach(msg => h.update(msg));
7490
+ return h.digest();
7491
+ };
7492
+
7493
+ const ecdsaSign = (msgHash, privKey) => secp256k1__namespace.signSync(msgHash, privKey, {
7494
+ der: false,
7495
+ recovered: true
7496
+ });
7497
+ secp256k1__namespace.utils.isValidPrivateKey;
7498
+ const publicKeyCreate = secp256k1__namespace.getPublicKey;
7499
+
8885
7500
  const PRIVATE_KEY_BYTES = 32;
8886
7501
  const ETHEREUM_ADDRESS_BYTES = 20;
8887
7502
  const PUBLIC_KEY_BYTES = 64;
@@ -9005,13 +7620,12 @@ class Secp256k1Program {
9005
7620
 
9006
7621
  try {
9007
7622
  const privateKey = toBuffer(pkey);
9008
- const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
7623
+ const publicKey = publicKeyCreate(privateKey, false
7624
+ /* isCompressed */
7625
+ ).slice(1); // throw away leading byte
9009
7626
 
9010
7627
  const messageHash = buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(message)).digest());
9011
- const {
9012
- signature,
9013
- recid: recoveryId
9014
- } = ecdsaSign(messageHash, privateKey);
7628
+ const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
9015
7629
  return this.createInstructionWithPublicKey({
9016
7630
  publicKey,
9017
7631
  message,
@@ -10123,6 +8737,23 @@ class VoteProgram {
10123
8737
  data
10124
8738
  });
10125
8739
  }
8740
+ /**
8741
+ * Generate a transaction to withdraw safely from a Vote account.
8742
+ *
8743
+ * This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
8744
+ * checks that the withdraw amount will not exceed the specified balance while leaving enough left
8745
+ * to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
8746
+ * `withdraw` method directly.
8747
+ */
8748
+
8749
+
8750
+ static safeWithdraw(params, currentVoteAccountBalance, rentExemptMinimum) {
8751
+ if (params.lamports > currentVoteAccountBalance - rentExemptMinimum) {
8752
+ throw new Error('Withdraw will leave vote account with insuffcient funds.');
8753
+ }
8754
+
8755
+ return VoteProgram.withdraw(params);
8756
+ }
10126
8757
 
10127
8758
  }
10128
8759
  VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
@@ -10174,15 +8805,14 @@ class ValidatorInfo {
10174
8805
 
10175
8806
 
10176
8807
  static fromConfigData(buffer$1) {
10177
- const PUBKEY_LENGTH = 32;
10178
8808
  let byteArray = [...buffer$1];
10179
8809
  const configKeyCount = decodeLength(byteArray);
10180
8810
  if (configKeyCount !== 2) return null;
10181
8811
  const configKeys = [];
10182
8812
 
10183
8813
  for (let i = 0; i < 2; i++) {
10184
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
10185
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8814
+ const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
8815
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10186
8816
  const isSigner = byteArray.slice(0, 1)[0] === 1;
10187
8817
  byteArray = byteArray.slice(1);
10188
8818
  configKeys.push({
@@ -10418,9 +9048,11 @@ exports.Loader = Loader;
10418
9048
  exports.Lockup = Lockup;
10419
9049
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
10420
9050
  exports.Message = Message;
9051
+ exports.MessageV0 = MessageV0;
10421
9052
  exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
10422
9053
  exports.NonceAccount = NonceAccount;
10423
9054
  exports.PACKET_DATA_SIZE = PACKET_DATA_SIZE;
9055
+ exports.PUBLIC_KEY_LENGTH = PUBLIC_KEY_LENGTH;
10424
9056
  exports.PublicKey = PublicKey;
10425
9057
  exports.SIGNATURE_LENGTH_IN_BYTES = SIGNATURE_LENGTH_IN_BYTES;
10426
9058
  exports.SOLANA_SCHEMA = SOLANA_SCHEMA;
@@ -10451,8 +9083,11 @@ exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheig
10451
9083
  exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
10452
9084
  exports.TransactionInstruction = TransactionInstruction;
10453
9085
  exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
9086
+ exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
10454
9087
  exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
10455
9088
  exports.ValidatorInfo = ValidatorInfo;
9089
+ exports.VersionedMessage = VersionedMessage;
9090
+ exports.VersionedTransaction = VersionedTransaction;
10456
9091
  exports.VoteAccount = VoteAccount;
10457
9092
  exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
10458
9093
  exports.VoteInit = VoteInit;