@solana/web3.js 1.67.1 → 1.67.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.
@@ -750,6 +750,36 @@ class CompiledKeys {
750
750
 
751
751
  }
752
752
 
753
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
754
+ /**
755
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
756
+ */
757
+
758
+ function guardedShift(byteArray) {
759
+ if (byteArray.length === 0) {
760
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
761
+ }
762
+
763
+ return byteArray.shift();
764
+ }
765
+ /**
766
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
767
+ * the array.
768
+ */
769
+
770
+ function guardedSplice(byteArray, ...args) {
771
+ var _args$;
772
+
773
+ const [start] = args;
774
+
775
+ if (args.length === 2 // Implies that `deleteCount` was supplied
776
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
777
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
778
+ }
779
+
780
+ return byteArray.splice(...args);
781
+ }
782
+
753
783
  /**
754
784
  * An instruction to execute by a program
755
785
  *
@@ -901,37 +931,33 @@ class Message {
901
931
  static from(buffer) {
902
932
  // Slice up wire data
903
933
  let byteArray = [...buffer];
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.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.encode(Buffer.from(dataSlice));
934
- byteArray = byteArray.slice(dataLength);
935
961
  instructions.push({
936
962
  programIdIndex,
937
963
  accounts,
@@ -1167,33 +1193,33 @@ class MessageV0 {
1167
1193
 
1168
1194
  static deserialize(serializedMessage) {
1169
1195
  let byteArray = [...serializedMessage];
1170
- const prefix = byteArray.shift();
1196
+ const prefix = guardedShift(byteArray);
1171
1197
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1172
1198
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1173
1199
  const version = maskedPrefix;
1174
1200
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1175
1201
  const header = {
1176
- numRequiredSignatures: byteArray.shift(),
1177
- numReadonlySignedAccounts: byteArray.shift(),
1178
- numReadonlyUnsignedAccounts: byteArray.shift()
1202
+ numRequiredSignatures: guardedShift(byteArray),
1203
+ numReadonlySignedAccounts: guardedShift(byteArray),
1204
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1179
1205
  };
1180
1206
  const staticAccountKeys = [];
1181
1207
  const staticAccountKeysLength = decodeLength(byteArray);
1182
1208
 
1183
1209
  for (let i = 0; i < staticAccountKeysLength; i++) {
1184
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1210
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1185
1211
  }
1186
1212
 
1187
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1213
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1188
1214
  const instructionCount = decodeLength(byteArray);
1189
1215
  const compiledInstructions = [];
1190
1216
 
1191
1217
  for (let i = 0; i < instructionCount; i++) {
1192
- const programIdIndex = byteArray.shift();
1218
+ const programIdIndex = guardedShift(byteArray);
1193
1219
  const accountKeyIndexesLength = decodeLength(byteArray);
1194
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1220
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1195
1221
  const dataLength = decodeLength(byteArray);
1196
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1222
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1197
1223
  compiledInstructions.push({
1198
1224
  programIdIndex,
1199
1225
  accountKeyIndexes,
@@ -1205,11 +1231,11 @@ class MessageV0 {
1205
1231
  const addressTableLookups = [];
1206
1232
 
1207
1233
  for (let i = 0; i < addressTableLookupsCount; i++) {
1208
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1234
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1209
1235
  const writableIndexesLength = decodeLength(byteArray);
1210
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1236
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1211
1237
  const readonlyIndexesLength = decodeLength(byteArray);
1212
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1238
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1213
1239
  addressTableLookups.push({
1214
1240
  accountKey,
1215
1241
  writableIndexes,
@@ -1949,8 +1975,7 @@ class Transaction {
1949
1975
  let signatures = [];
1950
1976
 
1951
1977
  for (let i = 0; i < signatureCount; i++) {
1952
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1953
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1978
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1954
1979
  signatures.push(bs58.encode(Buffer.from(signature)));
1955
1980
  }
1956
1981
 
@@ -2148,7 +2173,7 @@ class VersionedTransaction {
2148
2173
  const signaturesLength = decodeLength(byteArray);
2149
2174
 
2150
2175
  for (let i = 0; i < signaturesLength; i++) {
2151
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2176
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2152
2177
  }
2153
2178
 
2154
2179
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4601,7 +4626,7 @@ const LogsNotificationResult = type({
4601
4626
 
4602
4627
  /** @internal */
4603
4628
  const COMMON_HTTP_HEADERS = {
4604
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4629
+ 'solana-client': `js/${(_process$env$npm_pack = "1.67.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4605
4630
  };
4606
4631
  /**
4607
4632
  * A connection to a fullnode JSON RPC endpoint
@@ -5983,7 +6008,7 @@ class Connection {
5983
6008
 
5984
6009
 
5985
6010
  async getFeeForMessage(message, commitment) {
5986
- const wireMessage = message.serialize().toString('base64');
6011
+ const wireMessage = toBuffer(message.serialize()).toString('base64');
5987
6012
 
5988
6013
  const args = this._buildArgs([wireMessage], commitment);
5989
6014
 
@@ -9924,10 +9949,8 @@ class ValidatorInfo {
9924
9949
  const configKeys = [];
9925
9950
 
9926
9951
  for (let i = 0; i < 2; i++) {
9927
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9928
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9929
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9930
- byteArray = byteArray.slice(1);
9952
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9953
+ const isSigner = guardedShift(byteArray) === 1;
9931
9954
  configKeys.push({
9932
9955
  publicKey,
9933
9956
  isSigner