@solana/web3.js 1.60.0 → 1.60.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
@@ -770,6 +770,36 @@ class CompiledKeys {
770
770
 
771
771
  }
772
772
 
773
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
774
+ /**
775
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
776
+ */
777
+
778
+ function guardedShift(byteArray) {
779
+ if (byteArray.length === 0) {
780
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
781
+ }
782
+
783
+ return byteArray.shift();
784
+ }
785
+ /**
786
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
787
+ * the array.
788
+ */
789
+
790
+ function guardedSplice(byteArray, ...args) {
791
+ var _args$;
792
+
793
+ const [start] = args;
794
+
795
+ if (args.length === 2 // Implies that `deleteCount` was supplied
796
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
797
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
798
+ }
799
+
800
+ return byteArray.splice(...args);
801
+ }
802
+
773
803
  /**
774
804
  * An instruction to execute by a program
775
805
  *
@@ -911,37 +941,33 @@ class Message {
911
941
  static from(buffer$1) {
912
942
  // Slice up wire data
913
943
  let byteArray = [...buffer$1];
914
- const numRequiredSignatures = byteArray.shift();
944
+ const numRequiredSignatures = guardedShift(byteArray);
915
945
 
916
946
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
917
947
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
918
948
  }
919
949
 
920
- const numReadonlySignedAccounts = byteArray.shift();
921
- const numReadonlyUnsignedAccounts = byteArray.shift();
950
+ const numReadonlySignedAccounts = guardedShift(byteArray);
951
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
922
952
  const accountCount = decodeLength(byteArray);
923
953
  let accountKeys = [];
924
954
 
925
955
  for (let i = 0; i < accountCount; i++) {
926
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
927
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
956
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
928
957
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
929
958
  }
930
959
 
931
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
932
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
960
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
933
961
  const instructionCount = decodeLength(byteArray);
934
962
  let instructions = [];
935
963
 
936
964
  for (let i = 0; i < instructionCount; i++) {
937
- const programIdIndex = byteArray.shift();
965
+ const programIdIndex = guardedShift(byteArray);
938
966
  const accountCount = decodeLength(byteArray);
939
- const accounts = byteArray.slice(0, accountCount);
940
- byteArray = byteArray.slice(accountCount);
967
+ const accounts = guardedSplice(byteArray, 0, accountCount);
941
968
  const dataLength = decodeLength(byteArray);
942
- const dataSlice = byteArray.slice(0, dataLength);
969
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
943
970
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
944
- byteArray = byteArray.slice(dataLength);
945
971
  instructions.push({
946
972
  programIdIndex,
947
973
  accounts,
@@ -1154,33 +1180,33 @@ class MessageV0 {
1154
1180
 
1155
1181
  static deserialize(serializedMessage) {
1156
1182
  let byteArray = [...serializedMessage];
1157
- const prefix = byteArray.shift();
1183
+ const prefix = guardedShift(byteArray);
1158
1184
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1159
1185
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1160
1186
  const version = maskedPrefix;
1161
1187
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1162
1188
  const header = {
1163
- numRequiredSignatures: byteArray.shift(),
1164
- numReadonlySignedAccounts: byteArray.shift(),
1165
- numReadonlyUnsignedAccounts: byteArray.shift()
1189
+ numRequiredSignatures: guardedShift(byteArray),
1190
+ numReadonlySignedAccounts: guardedShift(byteArray),
1191
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1166
1192
  };
1167
1193
  const staticAccountKeys = [];
1168
1194
  const staticAccountKeysLength = decodeLength(byteArray);
1169
1195
 
1170
1196
  for (let i = 0; i < staticAccountKeysLength; i++) {
1171
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1197
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1172
1198
  }
1173
1199
 
1174
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1200
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1175
1201
  const instructionCount = decodeLength(byteArray);
1176
1202
  const compiledInstructions = [];
1177
1203
 
1178
1204
  for (let i = 0; i < instructionCount; i++) {
1179
- const programIdIndex = byteArray.shift();
1205
+ const programIdIndex = guardedShift(byteArray);
1180
1206
  const accountKeyIndexesLength = decodeLength(byteArray);
1181
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1207
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1182
1208
  const dataLength = decodeLength(byteArray);
1183
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1209
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1184
1210
  compiledInstructions.push({
1185
1211
  programIdIndex,
1186
1212
  accountKeyIndexes,
@@ -1192,11 +1218,11 @@ class MessageV0 {
1192
1218
  const addressTableLookups = [];
1193
1219
 
1194
1220
  for (let i = 0; i < addressTableLookupsCount; i++) {
1195
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1221
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1196
1222
  const writableIndexesLength = decodeLength(byteArray);
1197
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1223
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1198
1224
  const readonlyIndexesLength = decodeLength(byteArray);
1199
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1225
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1200
1226
  addressTableLookups.push({
1201
1227
  accountKey,
1202
1228
  writableIndexes,
@@ -1927,8 +1953,7 @@ class Transaction {
1927
1953
  let signatures = [];
1928
1954
 
1929
1955
  for (let i = 0; i < signatureCount; i++) {
1930
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1931
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1956
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1932
1957
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1933
1958
  }
1934
1959
 
@@ -2122,7 +2147,7 @@ class VersionedTransaction {
2122
2147
  const signaturesLength = decodeLength(byteArray);
2123
2148
 
2124
2149
  for (let i = 0; i < signaturesLength; i++) {
2125
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2150
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2126
2151
  }
2127
2152
 
2128
2153
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4582,7 +4607,7 @@ const LogsNotificationResult = superstruct.type({
4582
4607
 
4583
4608
  /** @internal */
4584
4609
  const COMMON_HTTP_HEADERS = {
4585
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4610
+ 'solana-client': `js/${(_process$env$npm_pack = "1.60.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4586
4611
  };
4587
4612
  /**
4588
4613
  * A connection to a fullnode JSON RPC endpoint
@@ -9496,10 +9521,8 @@ class ValidatorInfo {
9496
9521
  const configKeys = [];
9497
9522
 
9498
9523
  for (let i = 0; i < 2; i++) {
9499
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9500
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9501
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9502
- byteArray = byteArray.slice(1);
9524
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9525
+ const isSigner = guardedShift(byteArray) === 1;
9503
9526
  configKeys.push({
9504
9527
  publicKey,
9505
9528
  isSigner