@solana/web3.js 1.41.3 → 1.41.6

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,7 +8,7 @@ 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 crossFetch = require('cross-fetch');
11
+ var fetch = require('cross-fetch');
12
12
  var superstruct = require('superstruct');
13
13
  var rpcWebsockets = require('rpc-websockets');
14
14
  var RpcClient = require('jayson/lib/client/browser');
@@ -41,7 +41,7 @@ var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
41
41
  var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
42
42
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
43
43
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
44
- var crossFetch__default = /*#__PURE__*/_interopDefaultLegacy(crossFetch);
44
+ var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
45
45
  var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
46
46
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
47
47
  var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
@@ -2533,11 +2533,7 @@ class Transaction {
2533
2533
 
2534
2534
 
2535
2535
  compileMessage() {
2536
- if (this._message) {
2537
- if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
2538
- throw new Error('Transaction message mutated after being populated from Message');
2539
- }
2540
-
2536
+ if (this._message && JSON.stringify(this.toJSON()) === JSON.stringify(this._json)) {
2541
2537
  return this._message;
2542
2538
  }
2543
2539
 
@@ -3111,6 +3107,106 @@ function sleep(ms) {
3111
3107
  return new Promise(resolve => setTimeout(resolve, ms));
3112
3108
  }
3113
3109
 
3110
+ const encodeDecode = (layout) => {
3111
+ const decode = layout.decode.bind(layout);
3112
+ const encode = layout.encode.bind(layout);
3113
+ return { decode, encode };
3114
+ };
3115
+
3116
+ var node = {};
3117
+
3118
+ Object.defineProperty(node, "__esModule", { value: true });
3119
+ let converter;
3120
+ {
3121
+ try {
3122
+ converter = require('bindings')('bigint_buffer');
3123
+ }
3124
+ catch (e) {
3125
+ console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
3126
+ }
3127
+ }
3128
+ /**
3129
+ * Convert a little-endian buffer into a BigInt.
3130
+ * @param buf The little-endian buffer to convert
3131
+ * @returns A BigInt with the little-endian representation of buf.
3132
+ */
3133
+ function toBigIntLE(buf) {
3134
+ if (converter === undefined) {
3135
+ const reversed = Buffer.from(buf);
3136
+ reversed.reverse();
3137
+ const hex = reversed.toString('hex');
3138
+ if (hex.length === 0) {
3139
+ return BigInt(0);
3140
+ }
3141
+ return BigInt(`0x${hex}`);
3142
+ }
3143
+ return converter.toBigInt(buf, false);
3144
+ }
3145
+ var toBigIntLE_1 = node.toBigIntLE = toBigIntLE;
3146
+ /**
3147
+ * Convert a big-endian buffer into a BigInt
3148
+ * @param buf The big-endian buffer to convert.
3149
+ * @returns A BigInt with the big-endian representation of buf.
3150
+ */
3151
+ function toBigIntBE(buf) {
3152
+ if (converter === undefined) {
3153
+ const hex = buf.toString('hex');
3154
+ if (hex.length === 0) {
3155
+ return BigInt(0);
3156
+ }
3157
+ return BigInt(`0x${hex}`);
3158
+ }
3159
+ return converter.toBigInt(buf, true);
3160
+ }
3161
+ node.toBigIntBE = toBigIntBE;
3162
+ /**
3163
+ * Convert a BigInt to a little-endian buffer.
3164
+ * @param num The BigInt to convert.
3165
+ * @param width The number of bytes that the resulting buffer should be.
3166
+ * @returns A little-endian buffer representation of num.
3167
+ */
3168
+ function toBufferLE(num, width) {
3169
+ if (converter === undefined) {
3170
+ const hex = num.toString(16);
3171
+ const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
3172
+ buffer.reverse();
3173
+ return buffer;
3174
+ }
3175
+ // Allocation is done here, since it is slower using napi in C
3176
+ return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
3177
+ }
3178
+ var toBufferLE_1 = node.toBufferLE = toBufferLE;
3179
+ /**
3180
+ * Convert a BigInt to a big-endian buffer.
3181
+ * @param num The BigInt to convert.
3182
+ * @param width The number of bytes that the resulting buffer should be.
3183
+ * @returns A big-endian buffer representation of num.
3184
+ */
3185
+ function toBufferBE(num, width) {
3186
+ if (converter === undefined) {
3187
+ const hex = num.toString(16);
3188
+ return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
3189
+ }
3190
+ return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
3191
+ }
3192
+ node.toBufferBE = toBufferBE;
3193
+
3194
+ const bigInt = (length) => (property) => {
3195
+ const layout = BufferLayout.blob(length, property);
3196
+ const { encode, decode } = encodeDecode(layout);
3197
+ const bigIntLayout = layout;
3198
+ bigIntLayout.decode = (buffer, offset) => {
3199
+ const src = decode(buffer, offset);
3200
+ return toBigIntLE_1(Buffer.from(src));
3201
+ };
3202
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
3203
+ const src = toBufferLE_1(bigInt, length);
3204
+ return encode(src, buffer, offset);
3205
+ };
3206
+ return bigIntLayout;
3207
+ };
3208
+ const u64 = bigInt(8);
3209
+
3114
3210
  /**
3115
3211
  * Populate a buffer of instruction data using an InstructionType
3116
3212
  * @internal
@@ -3500,7 +3596,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3500
3596
  },
3501
3597
  Transfer: {
3502
3598
  index: 2,
3503
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
3599
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports')])
3504
3600
  },
3505
3601
  CreateWithSeed: {
3506
3602
  index: 3,
@@ -3536,7 +3632,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3536
3632
  },
3537
3633
  TransferWithSeed: {
3538
3634
  index: 11,
3539
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports'), rustString('seed'), publicKey('programId')])
3635
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports'), rustString('seed'), publicKey('programId')])
3540
3636
  }
3541
3637
  });
3542
3638
  /**
@@ -3589,7 +3685,7 @@ class SystemProgram {
3589
3685
  if ('basePubkey' in params) {
3590
3686
  const type = SYSTEM_INSTRUCTION_LAYOUTS.TransferWithSeed;
3591
3687
  data = encodeData(type, {
3592
- lamports: params.lamports,
3688
+ lamports: BigInt(params.lamports),
3593
3689
  seed: params.seed,
3594
3690
  programId: toBuffer(params.programId.toBuffer())
3595
3691
  });
@@ -3609,7 +3705,7 @@ class SystemProgram {
3609
3705
  } else {
3610
3706
  const type = SYSTEM_INSTRUCTION_LAYOUTS.Transfer;
3611
3707
  data = encodeData(type, {
3612
- lamports: params.lamports
3708
+ lamports: BigInt(params.lamports)
3613
3709
  });
3614
3710
  keys = [{
3615
3711
  pubkey: params.fromPubkey,
@@ -4711,7 +4807,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4711
4807
  */
4712
4808
 
4713
4809
  function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4714
- const fetch = customFetch ? customFetch : crossFetch__default["default"];
4810
+ const fetch = customFetch ? customFetch : fetch__default["default"];
4715
4811
  let agentManager;
4716
4812
 
4717
4813
  {
@@ -7886,7 +7982,7 @@ class Connection {
7886
7982
 
7887
7983
  try {
7888
7984
  this.removeSignatureListener(clientSubscriptionId); // eslint-disable-next-line no-empty
7889
- } catch {// Already removed.
7985
+ } catch (_err) {// Already removed.
7890
7986
  }
7891
7987
  }
7892
7988
  },
@@ -7928,7 +8024,7 @@ class Connection {
7928
8024
 
7929
8025
  try {
7930
8026
  this.removeSignatureListener(clientSubscriptionId); // eslint-disable-next-line no-empty
7931
- } catch {// Already removed.
8027
+ } catch (_err) {// Already removed.
7932
8028
  }
7933
8029
  },
7934
8030
  method: 'signatureSubscribe',