@solana/web3.js 1.43.0 → 1.43.3

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.
package/lib/index.cjs.js CHANGED
@@ -8,13 +8,13 @@ var BN = require('bn.js');
8
8
  var bs58 = require('bs58');
9
9
  var borsh = require('borsh');
10
10
  var BufferLayout = require('@solana/buffer-layout');
11
- var bufferLayoutUtils = require('@solana/buffer-layout-utils');
12
- var crossFetch = require('cross-fetch');
11
+ var bigintBuffer = require('bigint-buffer');
13
12
  var superstruct = require('superstruct');
14
13
  var rpcWebsockets = require('rpc-websockets');
15
14
  var RpcClient = require('jayson/lib/client/browser');
16
15
  var http = require('http');
17
16
  var https = require('https');
17
+ var nodeFetch = require('node-fetch');
18
18
  var secp256k1 = require('secp256k1');
19
19
  var sha3 = require('js-sha3');
20
20
 
@@ -42,10 +42,10 @@ var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
42
42
  var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
43
43
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
44
44
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
45
- var crossFetch__default = /*#__PURE__*/_interopDefaultLegacy(crossFetch);
46
45
  var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
47
46
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
48
47
  var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
48
+ var nodeFetch__namespace = /*#__PURE__*/_interopNamespace(nodeFetch);
49
49
  var secp256k1__default = /*#__PURE__*/_interopDefaultLegacy(secp256k1);
50
50
  var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
51
51
 
@@ -79,43 +79,52 @@ var inherits$1 = {exports: {}};
79
79
 
80
80
  var inherits_browser = {exports: {}};
81
81
 
82
- if (typeof Object.create === 'function') {
83
- // implementation from standard node.js 'util' module
84
- inherits_browser.exports = function inherits(ctor, superCtor) {
85
- if (superCtor) {
86
- ctor.super_ = superCtor;
87
- ctor.prototype = Object.create(superCtor.prototype, {
88
- constructor: {
89
- value: ctor,
90
- enumerable: false,
91
- writable: true,
92
- configurable: true
93
- }
94
- });
95
- }
96
- };
97
- } else {
98
- // old school shim for old browsers
99
- inherits_browser.exports = function inherits(ctor, superCtor) {
100
- if (superCtor) {
101
- ctor.super_ = superCtor;
102
- var TempCtor = function () {};
103
- TempCtor.prototype = superCtor.prototype;
104
- ctor.prototype = new TempCtor();
105
- ctor.prototype.constructor = ctor;
106
- }
107
- };
82
+ var hasRequiredInherits_browser;
83
+
84
+ function requireInherits_browser () {
85
+ if (hasRequiredInherits_browser) return inherits_browser.exports;
86
+ hasRequiredInherits_browser = 1;
87
+ if (typeof Object.create === 'function') {
88
+ // implementation from standard node.js 'util' module
89
+ inherits_browser.exports = function inherits(ctor, superCtor) {
90
+ if (superCtor) {
91
+ ctor.super_ = superCtor;
92
+ ctor.prototype = Object.create(superCtor.prototype, {
93
+ constructor: {
94
+ value: ctor,
95
+ enumerable: false,
96
+ writable: true,
97
+ configurable: true
98
+ }
99
+ });
100
+ }
101
+ };
102
+ } else {
103
+ // old school shim for old browsers
104
+ inherits_browser.exports = function inherits(ctor, superCtor) {
105
+ if (superCtor) {
106
+ ctor.super_ = superCtor;
107
+ var TempCtor = function () {};
108
+ TempCtor.prototype = superCtor.prototype;
109
+ ctor.prototype = new TempCtor();
110
+ ctor.prototype.constructor = ctor;
111
+ }
112
+ };
113
+ }
114
+ return inherits_browser.exports;
108
115
  }
109
116
 
110
- try {
111
- var util = require('util');
112
- /* istanbul ignore next */
113
- if (typeof util.inherits !== 'function') throw '';
114
- inherits$1.exports = util.inherits;
115
- } catch (e) {
116
- /* istanbul ignore next */
117
- inherits$1.exports = inherits_browser.exports;
118
- }
117
+ (function (module) {
118
+ try {
119
+ var util = require('util');
120
+ /* istanbul ignore next */
121
+ if (typeof util.inherits !== 'function') throw '';
122
+ module.exports = util.inherits;
123
+ } catch (e) {
124
+ /* istanbul ignore next */
125
+ module.exports = requireInherits_browser();
126
+ }
127
+ } (inherits$1));
119
128
 
120
129
  var assert$5 = minimalisticAssert;
121
130
  var inherits = inherits$1.exports;
@@ -1307,22 +1316,22 @@ Hmac.prototype.digest = function digest(enc) {
1307
1316
  };
1308
1317
 
1309
1318
  (function (exports) {
1310
- var hash = exports;
1311
-
1312
- hash.utils = utils$9;
1313
- hash.common = common$5;
1314
- hash.sha = sha;
1315
- hash.ripemd = ripemd;
1316
- hash.hmac = hmac;
1317
-
1318
- // Proxy hash functions to the main object
1319
- hash.sha1 = hash.sha.sha1;
1320
- hash.sha256 = hash.sha.sha256;
1321
- hash.sha224 = hash.sha.sha224;
1322
- hash.sha384 = hash.sha.sha384;
1323
- hash.sha512 = hash.sha.sha512;
1324
- hash.ripemd160 = hash.ripemd.ripemd160;
1325
- }(hash$1));
1319
+ var hash = exports;
1320
+
1321
+ hash.utils = utils$9;
1322
+ hash.common = common$5;
1323
+ hash.sha = sha;
1324
+ hash.ripemd = ripemd;
1325
+ hash.hmac = hmac;
1326
+
1327
+ // Proxy hash functions to the main object
1328
+ hash.sha1 = hash.sha.sha1;
1329
+ hash.sha256 = hash.sha.sha256;
1330
+ hash.sha224 = hash.sha.sha224;
1331
+ hash.sha384 = hash.sha.sha384;
1332
+ hash.sha512 = hash.sha.sha512;
1333
+ hash.ripemd160 = hash.ripemd.ripemd160;
1334
+ } (hash$1));
1326
1335
 
1327
1336
  var hash = hash$1;
1328
1337
 
@@ -2617,13 +2626,6 @@ class Transaction {
2617
2626
  isSigner: false,
2618
2627
  isWritable: false
2619
2628
  });
2620
- }); // Sort. Prioritizing first by signer, then by writable
2621
-
2622
- accountMetas.sort(function (x, y) {
2623
- const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2624
- const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2625
- const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2626
- return checkSigner || checkWritable;
2627
2629
  }); // Cull duplicate account metas
2628
2630
 
2629
2631
  const uniqueMetas = [];
@@ -2635,9 +2637,17 @@ class Transaction {
2635
2637
 
2636
2638
  if (uniqueIndex > -1) {
2637
2639
  uniqueMetas[uniqueIndex].isWritable = uniqueMetas[uniqueIndex].isWritable || accountMeta.isWritable;
2640
+ uniqueMetas[uniqueIndex].isSigner = uniqueMetas[uniqueIndex].isSigner || accountMeta.isSigner;
2638
2641
  } else {
2639
2642
  uniqueMetas.push(accountMeta);
2640
2643
  }
2644
+ }); // Sort. Prioritizing first by signer, then by writable
2645
+
2646
+ uniqueMetas.sort(function (x, y) {
2647
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2648
+ const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2649
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2650
+ return checkSigner || checkWritable;
2641
2651
  }); // Move fee payer to the front
2642
2652
 
2643
2653
  const feePayerIndex = uniqueMetas.findIndex(x => {
@@ -3219,6 +3229,38 @@ class NonceAccount {
3219
3229
 
3220
3230
  }
3221
3231
 
3232
+ const encodeDecode = layout => {
3233
+ const decode = layout.decode.bind(layout);
3234
+ const encode = layout.encode.bind(layout);
3235
+ return {
3236
+ decode,
3237
+ encode
3238
+ };
3239
+ };
3240
+
3241
+ const bigInt = length => property => {
3242
+ const layout = BufferLayout.blob(length, property);
3243
+ const {
3244
+ encode,
3245
+ decode
3246
+ } = encodeDecode(layout);
3247
+ const bigIntLayout = layout;
3248
+
3249
+ bigIntLayout.decode = (buffer$1, offset) => {
3250
+ const src = decode(buffer$1, offset);
3251
+ return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
3252
+ };
3253
+
3254
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
3255
+ const src = bigintBuffer.toBufferLE(bigInt, length);
3256
+ return encode(src, buffer, offset);
3257
+ };
3258
+
3259
+ return bigIntLayout;
3260
+ };
3261
+
3262
+ const u64 = bigInt(8);
3263
+
3222
3264
  /**
3223
3265
  * Create account system transaction params
3224
3266
  */
@@ -3520,7 +3562,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3520
3562
  },
3521
3563
  Transfer: {
3522
3564
  index: 2,
3523
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), bufferLayoutUtils.u64('lamports')])
3565
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports')])
3524
3566
  },
3525
3567
  CreateWithSeed: {
3526
3568
  index: 3,
@@ -3556,7 +3598,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3556
3598
  },
3557
3599
  TransferWithSeed: {
3558
3600
  index: 11,
3559
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), bufferLayoutUtils.u64('lamports'), rustString('seed'), publicKey('programId')])
3601
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports'), rustString('seed'), publicKey('programId')])
3560
3602
  }
3561
3603
  });
3562
3604
  /**
@@ -4260,7 +4302,7 @@ const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
4260
4302
  },
4261
4303
  SetComputeUnitPrice: {
4262
4304
  index: 3,
4263
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), bufferLayoutUtils.u64('microLamports')])
4305
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), u64('microLamports')])
4264
4306
  }
4265
4307
  });
4266
4308
  /**
@@ -4552,6 +4594,11 @@ class SendTransactionError extends Error {
4552
4594
 
4553
4595
  }
4554
4596
 
4597
+ async function fetchImpl (input, init) {
4598
+ const processedInput = typeof input === 'string' && input.slice(0, 2) === '//' ? 'https:' + input : input;
4599
+ return await nodeFetch__namespace.default(processedInput, init);
4600
+ }
4601
+
4555
4602
  // TODO: These constants should be removed in favor of reading them out of a
4556
4603
  // Syscall account
4557
4604
 
@@ -4801,7 +4848,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4801
4848
  */
4802
4849
 
4803
4850
  function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4804
- const fetch = customFetch ? customFetch : crossFetch__default["default"];
4851
+ const fetch = customFetch ? customFetch : fetchImpl;
4805
4852
  let agentManager;
4806
4853
 
4807
4854
  {
@@ -4811,10 +4858,10 @@ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddlewar
4811
4858
  let fetchWithMiddleware;
4812
4859
 
4813
4860
  if (fetchMiddleware) {
4814
- fetchWithMiddleware = async (url, options) => {
4861
+ fetchWithMiddleware = async (info, init) => {
4815
4862
  const modifiedFetchArgs = await new Promise((resolve, reject) => {
4816
4863
  try {
4817
- fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4864
+ fetchMiddleware(info, init, (modifiedInfo, modifiedInit) => resolve([modifiedInfo, modifiedInit]));
4818
4865
  } catch (error) {
4819
4866
  reject(error);
4820
4867
  }