@solana/web3.js 1.43.1 → 1.43.2

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
 
@@ -4550,6 +4559,11 @@ class SendTransactionError extends Error {
4550
4559
 
4551
4560
  }
4552
4561
 
4562
+ async function fetchImpl (input, init) {
4563
+ const processedInput = typeof input === 'string' && input.slice(0, 2) === '//' ? 'https:' + input : input;
4564
+ return await nodeFetch.default(processedInput, init);
4565
+ }
4566
+
4553
4567
  // TODO: These constants should be removed in favor of reading them out of a
4554
4568
  // Syscall account
4555
4569
 
@@ -4799,7 +4813,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
4799
4813
  */
4800
4814
 
4801
4815
  function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4802
- const fetch = customFetch ? customFetch : crossFetch;
4816
+ const fetch = customFetch ? customFetch : fetchImpl;
4803
4817
  let agentManager;
4804
4818
 
4805
4819
  {
@@ -4809,10 +4823,10 @@ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddlewar
4809
4823
  let fetchWithMiddleware;
4810
4824
 
4811
4825
  if (fetchMiddleware) {
4812
- fetchWithMiddleware = async (url, options) => {
4826
+ fetchWithMiddleware = async (info, init) => {
4813
4827
  const modifiedFetchArgs = await new Promise((resolve, reject) => {
4814
4828
  try {
4815
- fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4829
+ fetchMiddleware(info, init, (modifiedInfo, modifiedInit) => resolve([modifiedInfo, modifiedInit]));
4816
4830
  } catch (error) {
4817
4831
  reject(error);
4818
4832
  }