@solana/web3.js 1.32.1 → 1.32.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.iife.js CHANGED
@@ -14023,6 +14023,36 @@ var solanaWeb3 = (function (exports) {
14023
14023
  }
14024
14024
  }
14025
14025
 
14026
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
14027
+ /**
14028
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
14029
+ */
14030
+
14031
+ function guardedShift(byteArray) {
14032
+ if (byteArray.length === 0) {
14033
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
14034
+ }
14035
+
14036
+ return byteArray.shift();
14037
+ }
14038
+ /**
14039
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
14040
+ * the array.
14041
+ */
14042
+
14043
+ function guardedSplice(byteArray, ...args) {
14044
+ var _args$;
14045
+
14046
+ const [start] = args;
14047
+
14048
+ if (args.length === 2 // Implies that `deleteCount` was supplied
14049
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
14050
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
14051
+ }
14052
+
14053
+ return byteArray.splice(...args);
14054
+ }
14055
+
14026
14056
  /**
14027
14057
  * The message header, identifying signed and read-only account
14028
14058
  */
@@ -14121,32 +14151,28 @@ var solanaWeb3 = (function (exports) {
14121
14151
  static from(buffer$1) {
14122
14152
  // Slice up wire data
14123
14153
  let byteArray = [...buffer$1];
14124
- const numRequiredSignatures = byteArray.shift();
14125
- const numReadonlySignedAccounts = byteArray.shift();
14126
- const numReadonlyUnsignedAccounts = byteArray.shift();
14154
+ const numRequiredSignatures = guardedShift(byteArray);
14155
+ const numReadonlySignedAccounts = guardedShift(byteArray);
14156
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
14127
14157
  const accountCount = decodeLength(byteArray);
14128
14158
  let accountKeys = [];
14129
14159
 
14130
14160
  for (let i = 0; i < accountCount; i++) {
14131
- const account = byteArray.slice(0, PUBKEY_LENGTH);
14132
- byteArray = byteArray.slice(PUBKEY_LENGTH);
14161
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
14133
14162
  accountKeys.push(bs58$1.encode(buffer.Buffer.from(account)));
14134
14163
  }
14135
14164
 
14136
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
14137
- byteArray = byteArray.slice(PUBKEY_LENGTH);
14165
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
14138
14166
  const instructionCount = decodeLength(byteArray);
14139
14167
  let instructions = [];
14140
14168
 
14141
14169
  for (let i = 0; i < instructionCount; i++) {
14142
- const programIdIndex = byteArray.shift();
14170
+ const programIdIndex = guardedShift(byteArray);
14143
14171
  const accountCount = decodeLength(byteArray);
14144
- const accounts = byteArray.slice(0, accountCount);
14145
- byteArray = byteArray.slice(accountCount);
14172
+ const accounts = guardedSplice(byteArray, 0, accountCount);
14146
14173
  const dataLength = decodeLength(byteArray);
14147
- const dataSlice = byteArray.slice(0, dataLength);
14174
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
14148
14175
  const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
14149
- byteArray = byteArray.slice(dataLength);
14150
14176
  instructions.push({
14151
14177
  programIdIndex,
14152
14178
  accounts,
@@ -14175,6 +14201,10 @@ var solanaWeb3 = (function (exports) {
14175
14201
  }
14176
14202
  }
14177
14203
 
14204
+ /**
14205
+ * Transaction signature as base-58 encoded string
14206
+ */
14207
+
14178
14208
  /**
14179
14209
  * Default (empty) signature
14180
14210
  *
@@ -14761,8 +14791,7 @@ var solanaWeb3 = (function (exports) {
14761
14791
  let signatures = [];
14762
14792
 
14763
14793
  for (let i = 0; i < signatureCount; i++) {
14764
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
14765
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
14794
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
14766
14795
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
14767
14796
  }
14768
14797
 
@@ -22430,7 +22459,14 @@ var solanaWeb3 = (function (exports) {
22430
22459
  this._rpcWebSocketIdleTimeout = setTimeout(() => {
22431
22460
  this._rpcWebSocketIdleTimeout = null;
22432
22461
 
22433
- this._rpcWebSocket.close();
22462
+ try {
22463
+ this._rpcWebSocket.close();
22464
+ } catch (err) {
22465
+ // swallow error if socket has already been closed.
22466
+ if (err instanceof Error) {
22467
+ console.log(`Error when closing socket connection: ${err.message}`);
22468
+ }
22469
+ }
22434
22470
  }, 500);
22435
22471
  }
22436
22472
 
@@ -28946,10 +28982,8 @@ var solanaWeb3 = (function (exports) {
28946
28982
  const configKeys = [];
28947
28983
 
28948
28984
  for (let i = 0; i < 2; i++) {
28949
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
28950
- byteArray = byteArray.slice(PUBKEY_LENGTH);
28951
- const isSigner = byteArray.slice(0, 1)[0] === 1;
28952
- byteArray = byteArray.slice(1);
28985
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
28986
+ const isSigner = guardedShift(byteArray) === 1;
28953
28987
  configKeys.push({
28954
28988
  publicKey,
28955
28989
  isSigner