@solana/web3.js 1.58.0 → 1.58.1

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
@@ -760,6 +760,36 @@ class CompiledKeys {
760
760
 
761
761
  }
762
762
 
763
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
764
+ /**
765
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
766
+ */
767
+
768
+ function guardedShift(byteArray) {
769
+ if (byteArray.length === 0) {
770
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
771
+ }
772
+
773
+ return byteArray.shift();
774
+ }
775
+ /**
776
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
777
+ * the array.
778
+ */
779
+
780
+ function guardedSplice(byteArray, ...args) {
781
+ var _args$;
782
+
783
+ const [start] = args;
784
+
785
+ if (args.length === 2 // Implies that `deleteCount` was supplied
786
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
787
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
788
+ }
789
+
790
+ return byteArray.splice(...args);
791
+ }
792
+
763
793
  /**
764
794
  * An instruction to execute by a program
765
795
  *
@@ -901,37 +931,33 @@ class Message {
901
931
  static from(buffer$1) {
902
932
  // Slice up wire data
903
933
  let byteArray = [...buffer$1];
904
- const numRequiredSignatures = byteArray.shift();
934
+ const numRequiredSignatures = guardedShift(byteArray);
905
935
 
906
936
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
907
937
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
908
938
  }
909
939
 
910
- const numReadonlySignedAccounts = byteArray.shift();
911
- const numReadonlyUnsignedAccounts = byteArray.shift();
940
+ const numReadonlySignedAccounts = guardedShift(byteArray);
941
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
912
942
  const accountCount = decodeLength(byteArray);
913
943
  let accountKeys = [];
914
944
 
915
945
  for (let i = 0; i < accountCount; i++) {
916
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
917
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
946
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
918
947
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
919
948
  }
920
949
 
921
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
922
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
950
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
923
951
  const instructionCount = decodeLength(byteArray);
924
952
  let instructions = [];
925
953
 
926
954
  for (let i = 0; i < instructionCount; i++) {
927
- const programIdIndex = byteArray.shift();
955
+ const programIdIndex = guardedShift(byteArray);
928
956
  const accountCount = decodeLength(byteArray);
929
- const accounts = byteArray.slice(0, accountCount);
930
- byteArray = byteArray.slice(accountCount);
957
+ const accounts = guardedSplice(byteArray, 0, accountCount);
931
958
  const dataLength = decodeLength(byteArray);
932
- const dataSlice = byteArray.slice(0, dataLength);
959
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
933
960
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
934
- byteArray = byteArray.slice(dataLength);
935
961
  instructions.push({
936
962
  programIdIndex,
937
963
  accounts,
@@ -1144,33 +1170,33 @@ class MessageV0 {
1144
1170
 
1145
1171
  static deserialize(serializedMessage) {
1146
1172
  let byteArray = [...serializedMessage];
1147
- const prefix = byteArray.shift();
1173
+ const prefix = guardedShift(byteArray);
1148
1174
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1149
1175
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1150
1176
  const version = maskedPrefix;
1151
1177
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1152
1178
  const header = {
1153
- numRequiredSignatures: byteArray.shift(),
1154
- numReadonlySignedAccounts: byteArray.shift(),
1155
- numReadonlyUnsignedAccounts: byteArray.shift()
1179
+ numRequiredSignatures: guardedShift(byteArray),
1180
+ numReadonlySignedAccounts: guardedShift(byteArray),
1181
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1156
1182
  };
1157
1183
  const staticAccountKeys = [];
1158
1184
  const staticAccountKeysLength = decodeLength(byteArray);
1159
1185
 
1160
1186
  for (let i = 0; i < staticAccountKeysLength; i++) {
1161
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1187
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1162
1188
  }
1163
1189
 
1164
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1190
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1165
1191
  const instructionCount = decodeLength(byteArray);
1166
1192
  const compiledInstructions = [];
1167
1193
 
1168
1194
  for (let i = 0; i < instructionCount; i++) {
1169
- const programIdIndex = byteArray.shift();
1195
+ const programIdIndex = guardedShift(byteArray);
1170
1196
  const accountKeyIndexesLength = decodeLength(byteArray);
1171
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1197
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1172
1198
  const dataLength = decodeLength(byteArray);
1173
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1199
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1174
1200
  compiledInstructions.push({
1175
1201
  programIdIndex,
1176
1202
  accountKeyIndexes,
@@ -1182,11 +1208,11 @@ class MessageV0 {
1182
1208
  const addressTableLookups = [];
1183
1209
 
1184
1210
  for (let i = 0; i < addressTableLookupsCount; i++) {
1185
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1211
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1186
1212
  const writableIndexesLength = decodeLength(byteArray);
1187
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1213
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1188
1214
  const readonlyIndexesLength = decodeLength(byteArray);
1189
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1215
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1190
1216
  addressTableLookups.push({
1191
1217
  accountKey,
1192
1218
  writableIndexes,
@@ -1917,8 +1943,7 @@ class Transaction {
1917
1943
  let signatures = [];
1918
1944
 
1919
1945
  for (let i = 0; i < signatureCount; i++) {
1920
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1921
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1946
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1922
1947
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1923
1948
  }
1924
1949
 
@@ -2118,7 +2143,7 @@ class VersionedTransaction {
2118
2143
  const signaturesLength = decodeLength(byteArray);
2119
2144
 
2120
2145
  for (let i = 0; i < signaturesLength; i++) {
2121
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2146
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2122
2147
  }
2123
2148
 
2124
2149
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4577,7 +4602,7 @@ const LogsNotificationResult = superstruct.type({
4577
4602
 
4578
4603
  /** @internal */
4579
4604
  const COMMON_HTTP_HEADERS = {
4580
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4605
+ 'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4581
4606
  };
4582
4607
  /**
4583
4608
  * A connection to a fullnode JSON RPC endpoint
@@ -9417,10 +9442,8 @@ class ValidatorInfo {
9417
9442
  const configKeys = [];
9418
9443
 
9419
9444
  for (let i = 0; i < 2; i++) {
9420
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9421
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9422
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9423
- byteArray = byteArray.slice(1);
9445
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9446
+ const isSigner = guardedShift(byteArray) === 1;
9424
9447
  configKeys.push({
9425
9448
  publicKey,
9426
9449
  isSigner