@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.esm.js CHANGED
@@ -737,6 +737,36 @@ class CompiledKeys {
737
737
 
738
738
  }
739
739
 
740
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
741
+ /**
742
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
743
+ */
744
+
745
+ function guardedShift(byteArray) {
746
+ if (byteArray.length === 0) {
747
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
748
+ }
749
+
750
+ return byteArray.shift();
751
+ }
752
+ /**
753
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
754
+ * the array.
755
+ */
756
+
757
+ function guardedSplice(byteArray, ...args) {
758
+ var _args$;
759
+
760
+ const [start] = args;
761
+
762
+ if (args.length === 2 // Implies that `deleteCount` was supplied
763
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
764
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
765
+ }
766
+
767
+ return byteArray.splice(...args);
768
+ }
769
+
740
770
  /**
741
771
  * An instruction to execute by a program
742
772
  *
@@ -878,37 +908,33 @@ class Message {
878
908
  static from(buffer) {
879
909
  // Slice up wire data
880
910
  let byteArray = [...buffer];
881
- const numRequiredSignatures = byteArray.shift();
911
+ const numRequiredSignatures = guardedShift(byteArray);
882
912
 
883
913
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
884
914
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
885
915
  }
886
916
 
887
- const numReadonlySignedAccounts = byteArray.shift();
888
- const numReadonlyUnsignedAccounts = byteArray.shift();
917
+ const numReadonlySignedAccounts = guardedShift(byteArray);
918
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
889
919
  const accountCount = decodeLength(byteArray);
890
920
  let accountKeys = [];
891
921
 
892
922
  for (let i = 0; i < accountCount; i++) {
893
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
894
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
923
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
895
924
  accountKeys.push(new PublicKey(Buffer.from(account)));
896
925
  }
897
926
 
898
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
899
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
927
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
900
928
  const instructionCount = decodeLength(byteArray);
901
929
  let instructions = [];
902
930
 
903
931
  for (let i = 0; i < instructionCount; i++) {
904
- const programIdIndex = byteArray.shift();
932
+ const programIdIndex = guardedShift(byteArray);
905
933
  const accountCount = decodeLength(byteArray);
906
- const accounts = byteArray.slice(0, accountCount);
907
- byteArray = byteArray.slice(accountCount);
934
+ const accounts = guardedSplice(byteArray, 0, accountCount);
908
935
  const dataLength = decodeLength(byteArray);
909
- const dataSlice = byteArray.slice(0, dataLength);
936
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
910
937
  const data = bs58.encode(Buffer.from(dataSlice));
911
- byteArray = byteArray.slice(dataLength);
912
938
  instructions.push({
913
939
  programIdIndex,
914
940
  accounts,
@@ -1121,33 +1147,33 @@ class MessageV0 {
1121
1147
 
1122
1148
  static deserialize(serializedMessage) {
1123
1149
  let byteArray = [...serializedMessage];
1124
- const prefix = byteArray.shift();
1150
+ const prefix = guardedShift(byteArray);
1125
1151
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1126
1152
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1127
1153
  const version = maskedPrefix;
1128
1154
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1129
1155
  const header = {
1130
- numRequiredSignatures: byteArray.shift(),
1131
- numReadonlySignedAccounts: byteArray.shift(),
1132
- numReadonlyUnsignedAccounts: byteArray.shift()
1156
+ numRequiredSignatures: guardedShift(byteArray),
1157
+ numReadonlySignedAccounts: guardedShift(byteArray),
1158
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1133
1159
  };
1134
1160
  const staticAccountKeys = [];
1135
1161
  const staticAccountKeysLength = decodeLength(byteArray);
1136
1162
 
1137
1163
  for (let i = 0; i < staticAccountKeysLength; i++) {
1138
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1164
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1139
1165
  }
1140
1166
 
1141
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1167
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1142
1168
  const instructionCount = decodeLength(byteArray);
1143
1169
  const compiledInstructions = [];
1144
1170
 
1145
1171
  for (let i = 0; i < instructionCount; i++) {
1146
- const programIdIndex = byteArray.shift();
1172
+ const programIdIndex = guardedShift(byteArray);
1147
1173
  const accountKeyIndexesLength = decodeLength(byteArray);
1148
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1174
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1149
1175
  const dataLength = decodeLength(byteArray);
1150
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1176
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1151
1177
  compiledInstructions.push({
1152
1178
  programIdIndex,
1153
1179
  accountKeyIndexes,
@@ -1159,11 +1185,11 @@ class MessageV0 {
1159
1185
  const addressTableLookups = [];
1160
1186
 
1161
1187
  for (let i = 0; i < addressTableLookupsCount; i++) {
1162
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1188
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1163
1189
  const writableIndexesLength = decodeLength(byteArray);
1164
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1190
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1165
1191
  const readonlyIndexesLength = decodeLength(byteArray);
1166
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1192
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1167
1193
  addressTableLookups.push({
1168
1194
  accountKey,
1169
1195
  writableIndexes,
@@ -1894,8 +1920,7 @@ class Transaction {
1894
1920
  let signatures = [];
1895
1921
 
1896
1922
  for (let i = 0; i < signatureCount; i++) {
1897
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1898
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1923
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1899
1924
  signatures.push(bs58.encode(Buffer.from(signature)));
1900
1925
  }
1901
1926
 
@@ -2089,7 +2114,7 @@ class VersionedTransaction {
2089
2114
  const signaturesLength = decodeLength(byteArray);
2090
2115
 
2091
2116
  for (let i = 0; i < signaturesLength; i++) {
2092
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2117
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2093
2118
  }
2094
2119
 
2095
2120
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4549,7 +4574,7 @@ const LogsNotificationResult = type({
4549
4574
 
4550
4575
  /** @internal */
4551
4576
  const COMMON_HTTP_HEADERS = {
4552
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4577
+ 'solana-client': `js/${(_process$env$npm_pack = "1.60.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4553
4578
  };
4554
4579
  /**
4555
4580
  * A connection to a fullnode JSON RPC endpoint
@@ -9463,10 +9488,8 @@ class ValidatorInfo {
9463
9488
  const configKeys = [];
9464
9489
 
9465
9490
  for (let i = 0; i < 2; i++) {
9466
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9467
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9468
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9469
- byteArray = byteArray.slice(1);
9491
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9492
+ const isSigner = guardedShift(byteArray) === 1;
9470
9493
  configKeys.push({
9471
9494
  publicKey,
9472
9495
  isSigner