@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.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
@@ -4,13 +4,14 @@ import BN from 'bn.js';
4
4
  import bs58 from 'bs58';
5
5
  import { serialize, deserialize, deserializeUnchecked } from 'borsh';
6
6
  import * as BufferLayout from '@solana/buffer-layout';
7
- import { u64 } from '@solana/buffer-layout-utils';
8
- import crossFetch from 'cross-fetch';
7
+ import { blob } from '@solana/buffer-layout';
8
+ import { toBigIntLE, toBufferLE } from 'bigint-buffer';
9
9
  import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
10
10
  import { Client } from 'rpc-websockets';
11
11
  import RpcClient from 'jayson/lib/client/browser';
12
12
  import http from 'http';
13
13
  import https from 'https';
14
+ import * as nodeFetch from 'node-fetch';
14
15
  import secp256k1 from 'secp256k1';
15
16
  import sha3 from 'js-sha3';
16
17
 
@@ -44,43 +45,52 @@ var inherits$1 = {exports: {}};
44
45
 
45
46
  var inherits_browser = {exports: {}};
46
47
 
47
- if (typeof Object.create === 'function') {
48
- // implementation from standard node.js 'util' module
49
- inherits_browser.exports = function inherits(ctor, superCtor) {
50
- if (superCtor) {
51
- ctor.super_ = superCtor;
52
- ctor.prototype = Object.create(superCtor.prototype, {
53
- constructor: {
54
- value: ctor,
55
- enumerable: false,
56
- writable: true,
57
- configurable: true
58
- }
59
- });
60
- }
61
- };
62
- } else {
63
- // old school shim for old browsers
64
- inherits_browser.exports = function inherits(ctor, superCtor) {
65
- if (superCtor) {
66
- ctor.super_ = superCtor;
67
- var TempCtor = function () {};
68
- TempCtor.prototype = superCtor.prototype;
69
- ctor.prototype = new TempCtor();
70
- ctor.prototype.constructor = ctor;
71
- }
72
- };
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;
73
81
  }
74
82
 
75
- try {
76
- var util = require('util');
77
- /* istanbul ignore next */
78
- if (typeof util.inherits !== 'function') throw '';
79
- inherits$1.exports = util.inherits;
80
- } catch (e) {
81
- /* istanbul ignore next */
82
- inherits$1.exports = inherits_browser.exports;
83
- }
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));
84
94
 
85
95
  var assert$5 = minimalisticAssert;
86
96
  var inherits = inherits$1.exports;
@@ -1272,22 +1282,22 @@ Hmac.prototype.digest = function digest(enc) {
1272
1282
  };
1273
1283
 
1274
1284
  (function (exports) {
1275
- var hash = exports;
1276
-
1277
- hash.utils = utils$9;
1278
- hash.common = common$5;
1279
- hash.sha = sha;
1280
- hash.ripemd = ripemd;
1281
- hash.hmac = hmac;
1282
-
1283
- // Proxy hash functions to the main object
1284
- hash.sha1 = hash.sha.sha1;
1285
- hash.sha256 = hash.sha.sha256;
1286
- hash.sha224 = hash.sha.sha224;
1287
- hash.sha384 = hash.sha.sha384;
1288
- hash.sha512 = hash.sha.sha512;
1289
- hash.ripemd160 = hash.ripemd.ripemd160;
1290
- }(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));
1291
1301
 
1292
1302
  var hash = hash$1;
1293
1303
 
@@ -2582,13 +2592,6 @@ class Transaction {
2582
2592
  isSigner: false,
2583
2593
  isWritable: false
2584
2594
  });
2585
- }); // Sort. Prioritizing first by signer, then by writable
2586
-
2587
- accountMetas.sort(function (x, y) {
2588
- const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2589
- const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2590
- const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2591
- return checkSigner || checkWritable;
2592
2595
  }); // Cull duplicate account metas
2593
2596
 
2594
2597
  const uniqueMetas = [];
@@ -2600,9 +2603,17 @@ class Transaction {
2600
2603
 
2601
2604
  if (uniqueIndex > -1) {
2602
2605
  uniqueMetas[uniqueIndex].isWritable = uniqueMetas[uniqueIndex].isWritable || accountMeta.isWritable;
2606
+ uniqueMetas[uniqueIndex].isSigner = uniqueMetas[uniqueIndex].isSigner || accountMeta.isSigner;
2603
2607
  } else {
2604
2608
  uniqueMetas.push(accountMeta);
2605
2609
  }
2610
+ }); // Sort. Prioritizing first by signer, then by writable
2611
+
2612
+ uniqueMetas.sort(function (x, y) {
2613
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2614
+ const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2615
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2616
+ return checkSigner || checkWritable;
2606
2617
  }); // Move fee payer to the front
2607
2618
 
2608
2619
  const feePayerIndex = uniqueMetas.findIndex(x => {
@@ -3184,6 +3195,38 @@ class NonceAccount {
3184
3195
 
3185
3196
  }
3186
3197
 
3198
+ const encodeDecode = layout => {
3199
+ const decode = layout.decode.bind(layout);
3200
+ const encode = layout.encode.bind(layout);
3201
+ return {
3202
+ decode,
3203
+ encode
3204
+ };
3205
+ };
3206
+
3207
+ const bigInt = length => property => {
3208
+ const layout = blob(length, property);
3209
+ const {
3210
+ encode,
3211
+ decode
3212
+ } = encodeDecode(layout);
3213
+ const bigIntLayout = layout;
3214
+
3215
+ bigIntLayout.decode = (buffer, offset) => {
3216
+ const src = decode(buffer, offset);
3217
+ return toBigIntLE(Buffer.from(src));
3218
+ };
3219
+
3220
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
3221
+ const src = toBufferLE(bigInt, length);
3222
+ return encode(src, buffer, offset);
3223
+ };
3224
+
3225
+ return bigIntLayout;
3226
+ };
3227
+
3228
+ const u64 = bigInt(8);
3229
+
3187
3230
  /**
3188
3231
  * Create account system transaction params
3189
3232
  */
@@ -4517,6 +4560,11 @@ class SendTransactionError extends Error {
4517
4560
 
4518
4561
  }
4519
4562
 
4563
+ async function fetchImpl (input, init) {
4564
+ const processedInput = typeof input === 'string' && input.slice(0, 2) === '//' ? 'https:' + input : input;
4565
+ return await nodeFetch.default(processedInput, init);
4566
+ }
4567
+
4520
4568
  // TODO: These constants should be removed in favor of reading them out of a
4521
4569
  // Syscall account
4522
4570
 
@@ -4766,7 +4814,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
4766
4814
  */
4767
4815
 
4768
4816
  function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4769
- const fetch = customFetch ? customFetch : crossFetch;
4817
+ const fetch = customFetch ? customFetch : fetchImpl;
4770
4818
  let agentManager;
4771
4819
 
4772
4820
  {
@@ -4776,10 +4824,10 @@ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddlewar
4776
4824
  let fetchWithMiddleware;
4777
4825
 
4778
4826
  if (fetchMiddleware) {
4779
- fetchWithMiddleware = async (url, options) => {
4827
+ fetchWithMiddleware = async (info, init) => {
4780
4828
  const modifiedFetchArgs = await new Promise((resolve, reject) => {
4781
4829
  try {
4782
- fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4830
+ fetchMiddleware(info, init, (modifiedInfo, modifiedInit) => resolve([modifiedInfo, modifiedInit]));
4783
4831
  } catch (error) {
4784
4832
  reject(error);
4785
4833
  }