@solana/web3.js 1.43.1 → 1.43.4

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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  declare module '@solana/web3.js' {
3
3
  import {Buffer} from 'buffer';
4
- import crossFetch from 'cross-fetch';
4
+ import * as nodeFetch from 'node-fetch';
5
5
 
6
6
  export class Struct {
7
7
  constructor(properties: any);
@@ -179,6 +179,11 @@ declare module '@solana/web3.js' {
179
179
  getSlotsInEpoch(epoch: number): number;
180
180
  }
181
181
 
182
+ export function export_default(
183
+ input: nodeFetch.RequestInfo,
184
+ init?: nodeFetch.RequestInit,
185
+ ): Promise<nodeFetch.Response>;
186
+
182
187
  /**
183
188
  * Calculator for transaction fees.
184
189
  */
@@ -1444,13 +1449,17 @@ declare module '@solana/web3.js' {
1444
1449
  export type HttpHeaders = {
1445
1450
  [header: string]: string;
1446
1451
  };
1452
+ /**
1453
+ * The type of the JavaScript `fetch()` API
1454
+ */
1455
+ export type FetchFn = typeof export_default;
1447
1456
  /**
1448
1457
  * A callback used to augment the outgoing HTTP request
1449
1458
  */
1450
1459
  export type FetchMiddleware = (
1451
- url: string,
1452
- options: any,
1453
- fetch: (modifiedUrl: string, modifiedOptions: any) => void,
1460
+ info: Parameters<FetchFn>[0],
1461
+ init: Parameters<FetchFn>[1],
1462
+ fetch: (...a: Parameters<FetchFn>) => void,
1454
1463
  ) => void;
1455
1464
  /**
1456
1465
  * Configuration for instantiating a Connection
@@ -1463,7 +1472,7 @@ declare module '@solana/web3.js' {
1463
1472
  /** Optional HTTP headers object */
1464
1473
  httpHeaders?: HttpHeaders;
1465
1474
  /** Optional custom fetch function */
1466
- fetch?: typeof crossFetch;
1475
+ fetch?: FetchFn;
1467
1476
  /** Optional fetch middleware callback */
1468
1477
  fetchMiddleware?: FetchMiddleware;
1469
1478
  /** Optional Disable retrying calls when server responds with HTTP 429 (Too Many Requests) */
package/lib/index.esm.js CHANGED
@@ -6,12 +6,12 @@ import { serialize, deserialize, deserializeUnchecked } from 'borsh';
6
6
  import * as BufferLayout from '@solana/buffer-layout';
7
7
  import { blob } from '@solana/buffer-layout';
8
8
  import { toBigIntLE, toBufferLE } from 'bigint-buffer';
9
- import crossFetch from 'cross-fetch';
10
9
  import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
11
10
  import { Client } from 'rpc-websockets';
12
11
  import RpcClient from 'jayson/lib/client/browser';
13
12
  import http from 'http';
14
13
  import https from 'https';
14
+ import * as nodeFetch from 'node-fetch';
15
15
  import secp256k1 from 'secp256k1';
16
16
  import sha3 from 'js-sha3';
17
17
 
@@ -45,43 +45,52 @@ var inherits$1 = {exports: {}};
45
45
 
46
46
  var inherits_browser = {exports: {}};
47
47
 
48
- if (typeof Object.create === 'function') {
49
- // implementation from standard node.js 'util' module
50
- inherits_browser.exports = function inherits(ctor, superCtor) {
51
- if (superCtor) {
52
- ctor.super_ = superCtor;
53
- ctor.prototype = Object.create(superCtor.prototype, {
54
- constructor: {
55
- value: ctor,
56
- enumerable: false,
57
- writable: true,
58
- configurable: true
59
- }
60
- });
61
- }
62
- };
63
- } else {
64
- // old school shim for old browsers
65
- inherits_browser.exports = function inherits(ctor, superCtor) {
66
- if (superCtor) {
67
- ctor.super_ = superCtor;
68
- var TempCtor = function () {};
69
- TempCtor.prototype = superCtor.prototype;
70
- ctor.prototype = new TempCtor();
71
- ctor.prototype.constructor = ctor;
72
- }
73
- };
48
+ var hasRequiredInherits_browser;
49
+
50
+ function requireInherits_browser () {
51
+ if (hasRequiredInherits_browser) return inherits_browser.exports;
52
+ hasRequiredInherits_browser = 1;
53
+ if (typeof Object.create === 'function') {
54
+ // implementation from standard node.js 'util' module
55
+ inherits_browser.exports = function inherits(ctor, superCtor) {
56
+ if (superCtor) {
57
+ ctor.super_ = superCtor;
58
+ ctor.prototype = Object.create(superCtor.prototype, {
59
+ constructor: {
60
+ value: ctor,
61
+ enumerable: false,
62
+ writable: true,
63
+ configurable: true
64
+ }
65
+ });
66
+ }
67
+ };
68
+ } else {
69
+ // old school shim for old browsers
70
+ inherits_browser.exports = function inherits(ctor, superCtor) {
71
+ if (superCtor) {
72
+ ctor.super_ = superCtor;
73
+ var TempCtor = function () {};
74
+ TempCtor.prototype = superCtor.prototype;
75
+ ctor.prototype = new TempCtor();
76
+ ctor.prototype.constructor = ctor;
77
+ }
78
+ };
79
+ }
80
+ return inherits_browser.exports;
74
81
  }
75
82
 
76
- try {
77
- var util = require('util');
78
- /* istanbul ignore next */
79
- if (typeof util.inherits !== 'function') throw '';
80
- inherits$1.exports = util.inherits;
81
- } catch (e) {
82
- /* istanbul ignore next */
83
- inherits$1.exports = inherits_browser.exports;
84
- }
83
+ (function (module) {
84
+ try {
85
+ var util = require('util');
86
+ /* istanbul ignore next */
87
+ if (typeof util.inherits !== 'function') throw '';
88
+ module.exports = util.inherits;
89
+ } catch (e) {
90
+ /* istanbul ignore next */
91
+ module.exports = requireInherits_browser();
92
+ }
93
+ } (inherits$1));
85
94
 
86
95
  var assert$5 = minimalisticAssert;
87
96
  var inherits = inherits$1.exports;
@@ -1273,22 +1282,22 @@ Hmac.prototype.digest = function digest(enc) {
1273
1282
  };
1274
1283
 
1275
1284
  (function (exports) {
1276
- var hash = exports;
1277
-
1278
- hash.utils = utils$9;
1279
- hash.common = common$5;
1280
- hash.sha = sha;
1281
- hash.ripemd = ripemd;
1282
- hash.hmac = hmac;
1283
-
1284
- // Proxy hash functions to the main object
1285
- hash.sha1 = hash.sha.sha1;
1286
- hash.sha256 = hash.sha.sha256;
1287
- hash.sha224 = hash.sha.sha224;
1288
- hash.sha384 = hash.sha.sha384;
1289
- hash.sha512 = hash.sha.sha512;
1290
- hash.ripemd160 = hash.ripemd.ripemd160;
1291
- }(hash$1));
1285
+ var hash = exports;
1286
+
1287
+ hash.utils = utils$9;
1288
+ hash.common = common$5;
1289
+ hash.sha = sha;
1290
+ hash.ripemd = ripemd;
1291
+ hash.hmac = hmac;
1292
+
1293
+ // Proxy hash functions to the main object
1294
+ hash.sha1 = hash.sha.sha1;
1295
+ hash.sha256 = hash.sha.sha256;
1296
+ hash.sha224 = hash.sha.sha224;
1297
+ hash.sha384 = hash.sha.sha384;
1298
+ hash.sha512 = hash.sha.sha512;
1299
+ hash.ripemd160 = hash.ripemd.ripemd160;
1300
+ } (hash$1));
1292
1301
 
1293
1302
  var hash = hash$1;
1294
1303
 
@@ -2583,13 +2592,6 @@ class Transaction {
2583
2592
  isSigner: false,
2584
2593
  isWritable: false
2585
2594
  });
2586
- }); // Sort. Prioritizing first by signer, then by writable
2587
-
2588
- accountMetas.sort(function (x, y) {
2589
- const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2590
- const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2591
- const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2592
- return checkSigner || checkWritable;
2593
2595
  }); // Cull duplicate account metas
2594
2596
 
2595
2597
  const uniqueMetas = [];
@@ -2601,9 +2603,25 @@ class Transaction {
2601
2603
 
2602
2604
  if (uniqueIndex > -1) {
2603
2605
  uniqueMetas[uniqueIndex].isWritable = uniqueMetas[uniqueIndex].isWritable || accountMeta.isWritable;
2606
+ uniqueMetas[uniqueIndex].isSigner = uniqueMetas[uniqueIndex].isSigner || accountMeta.isSigner;
2604
2607
  } else {
2605
2608
  uniqueMetas.push(accountMeta);
2606
2609
  }
2610
+ }); // Sort. Prioritizing first by signer, then by writable
2611
+
2612
+ uniqueMetas.sort(function (x, y) {
2613
+ if (x.isSigner !== y.isSigner) {
2614
+ // Signers always come before non-signers
2615
+ return x.isSigner ? -1 : 1;
2616
+ }
2617
+
2618
+ if (x.isWritable !== y.isWritable) {
2619
+ // Writable accounts always come before read-only accounts
2620
+ return x.isWritable ? -1 : 1;
2621
+ } // Otherwise, sort by pubkey.
2622
+
2623
+
2624
+ return x.pubkey._bn.cmp(y.pubkey._bn);
2607
2625
  }); // Move fee payer to the front
2608
2626
 
2609
2627
  const feePayerIndex = uniqueMetas.findIndex(x => {
@@ -4550,6 +4568,11 @@ class SendTransactionError extends Error {
4550
4568
 
4551
4569
  }
4552
4570
 
4571
+ async function fetchImpl (input, init) {
4572
+ const processedInput = typeof input === 'string' && input.slice(0, 2) === '//' ? 'https:' + input : input;
4573
+ return await nodeFetch.default(processedInput, init);
4574
+ }
4575
+
4553
4576
  // TODO: These constants should be removed in favor of reading them out of a
4554
4577
  // Syscall account
4555
4578
 
@@ -4799,7 +4822,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
4799
4822
  */
4800
4823
 
4801
4824
  function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4802
- const fetch = customFetch ? customFetch : crossFetch;
4825
+ const fetch = customFetch ? customFetch : fetchImpl;
4803
4826
  let agentManager;
4804
4827
 
4805
4828
  {
@@ -4809,10 +4832,10 @@ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddlewar
4809
4832
  let fetchWithMiddleware;
4810
4833
 
4811
4834
  if (fetchMiddleware) {
4812
- fetchWithMiddleware = async (url, options) => {
4835
+ fetchWithMiddleware = async (info, init) => {
4813
4836
  const modifiedFetchArgs = await new Promise((resolve, reject) => {
4814
4837
  try {
4815
- fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4838
+ fetchMiddleware(info, init, (modifiedInfo, modifiedInit) => resolve([modifiedInfo, modifiedInit]));
4816
4839
  } catch (error) {
4817
4840
  reject(error);
4818
4841
  }