@solana/web3.js 1.41.3 → 1.41.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.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);
@@ -3111,6 +3111,106 @@ function sleep(ms) {
3111
3111
  return new Promise(resolve => setTimeout(resolve, ms));
3112
3112
  }
3113
3113
 
3114
+ const encodeDecode = (layout) => {
3115
+ const decode = layout.decode.bind(layout);
3116
+ const encode = layout.encode.bind(layout);
3117
+ return { decode, encode };
3118
+ };
3119
+
3120
+ var node = {};
3121
+
3122
+ Object.defineProperty(node, "__esModule", { value: true });
3123
+ let converter;
3124
+ {
3125
+ try {
3126
+ converter = require('bindings')('bigint_buffer');
3127
+ }
3128
+ catch (e) {
3129
+ console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
3130
+ }
3131
+ }
3132
+ /**
3133
+ * Convert a little-endian buffer into a BigInt.
3134
+ * @param buf The little-endian buffer to convert
3135
+ * @returns A BigInt with the little-endian representation of buf.
3136
+ */
3137
+ function toBigIntLE(buf) {
3138
+ if (converter === undefined) {
3139
+ const reversed = Buffer.from(buf);
3140
+ reversed.reverse();
3141
+ const hex = reversed.toString('hex');
3142
+ if (hex.length === 0) {
3143
+ return BigInt(0);
3144
+ }
3145
+ return BigInt(`0x${hex}`);
3146
+ }
3147
+ return converter.toBigInt(buf, false);
3148
+ }
3149
+ var toBigIntLE_1 = node.toBigIntLE = toBigIntLE;
3150
+ /**
3151
+ * Convert a big-endian buffer into a BigInt
3152
+ * @param buf The big-endian buffer to convert.
3153
+ * @returns A BigInt with the big-endian representation of buf.
3154
+ */
3155
+ function toBigIntBE(buf) {
3156
+ if (converter === undefined) {
3157
+ const hex = buf.toString('hex');
3158
+ if (hex.length === 0) {
3159
+ return BigInt(0);
3160
+ }
3161
+ return BigInt(`0x${hex}`);
3162
+ }
3163
+ return converter.toBigInt(buf, true);
3164
+ }
3165
+ node.toBigIntBE = toBigIntBE;
3166
+ /**
3167
+ * Convert a BigInt to a little-endian buffer.
3168
+ * @param num The BigInt to convert.
3169
+ * @param width The number of bytes that the resulting buffer should be.
3170
+ * @returns A little-endian buffer representation of num.
3171
+ */
3172
+ function toBufferLE(num, width) {
3173
+ if (converter === undefined) {
3174
+ const hex = num.toString(16);
3175
+ const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
3176
+ buffer.reverse();
3177
+ return buffer;
3178
+ }
3179
+ // Allocation is done here, since it is slower using napi in C
3180
+ return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
3181
+ }
3182
+ var toBufferLE_1 = node.toBufferLE = toBufferLE;
3183
+ /**
3184
+ * Convert a BigInt to a big-endian buffer.
3185
+ * @param num The BigInt to convert.
3186
+ * @param width The number of bytes that the resulting buffer should be.
3187
+ * @returns A big-endian buffer representation of num.
3188
+ */
3189
+ function toBufferBE(num, width) {
3190
+ if (converter === undefined) {
3191
+ const hex = num.toString(16);
3192
+ return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
3193
+ }
3194
+ return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
3195
+ }
3196
+ node.toBufferBE = toBufferBE;
3197
+
3198
+ const bigInt = (length) => (property) => {
3199
+ const layout = BufferLayout.blob(length, property);
3200
+ const { encode, decode } = encodeDecode(layout);
3201
+ const bigIntLayout = layout;
3202
+ bigIntLayout.decode = (buffer, offset) => {
3203
+ const src = decode(buffer, offset);
3204
+ return toBigIntLE_1(Buffer.from(src));
3205
+ };
3206
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
3207
+ const src = toBufferLE_1(bigInt, length);
3208
+ return encode(src, buffer, offset);
3209
+ };
3210
+ return bigIntLayout;
3211
+ };
3212
+ const u64 = bigInt(8);
3213
+
3114
3214
  /**
3115
3215
  * Populate a buffer of instruction data using an InstructionType
3116
3216
  * @internal
@@ -3500,7 +3600,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3500
3600
  },
3501
3601
  Transfer: {
3502
3602
  index: 2,
3503
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
3603
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports')])
3504
3604
  },
3505
3605
  CreateWithSeed: {
3506
3606
  index: 3,
@@ -3536,7 +3636,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3536
3636
  },
3537
3637
  TransferWithSeed: {
3538
3638
  index: 11,
3539
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports'), rustString('seed'), publicKey('programId')])
3639
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports'), rustString('seed'), publicKey('programId')])
3540
3640
  }
3541
3641
  });
3542
3642
  /**
@@ -3589,7 +3689,7 @@ class SystemProgram {
3589
3689
  if ('basePubkey' in params) {
3590
3690
  const type = SYSTEM_INSTRUCTION_LAYOUTS.TransferWithSeed;
3591
3691
  data = encodeData(type, {
3592
- lamports: params.lamports,
3692
+ lamports: BigInt(params.lamports),
3593
3693
  seed: params.seed,
3594
3694
  programId: toBuffer(params.programId.toBuffer())
3595
3695
  });
@@ -3609,7 +3709,7 @@ class SystemProgram {
3609
3709
  } else {
3610
3710
  const type = SYSTEM_INSTRUCTION_LAYOUTS.Transfer;
3611
3711
  data = encodeData(type, {
3612
- lamports: params.lamports
3712
+ lamports: BigInt(params.lamports)
3613
3713
  });
3614
3714
  keys = [{
3615
3715
  pubkey: params.fromPubkey,
@@ -4711,7 +4811,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4711
4811
  */
4712
4812
 
4713
4813
  function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4714
- const fetch = customFetch ? customFetch : crossFetch__default["default"];
4814
+ const fetch = customFetch ? customFetch : fetch__default["default"];
4715
4815
  let agentManager;
4716
4816
 
4717
4817
  {