@solana/web3.js 1.56.2 → 1.56.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.cjs.js CHANGED
@@ -568,6 +568,44 @@ function encodeLength(bytes, len) {
568
568
  }
569
569
  }
570
570
 
571
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
572
+ /**
573
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
574
+ */
575
+
576
+ function guardedShift(byteArray) {
577
+ if (byteArray.length === 0) {
578
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
579
+ }
580
+
581
+ return byteArray.shift();
582
+ }
583
+ /**
584
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
585
+ * the array.
586
+ */
587
+
588
+ function guardedSplice(byteArray, ...args) {
589
+ var _args$;
590
+
591
+ const [start] = args;
592
+
593
+ if (args.length === 2 // Implies that `deleteCount` was supplied
594
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
595
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
596
+ }
597
+
598
+ return byteArray.splice(...args);
599
+ }
600
+
601
+ /**
602
+ * An instruction to execute by a program
603
+ *
604
+ * @property {number} programIdIndex
605
+ * @property {number[]} accounts
606
+ * @property {string} data
607
+ */
608
+
571
609
  /**
572
610
  * List of instructions to be processed atomically
573
611
  */
@@ -680,37 +718,33 @@ class Message {
680
718
  static from(buffer$1) {
681
719
  // Slice up wire data
682
720
  let byteArray = [...buffer$1];
683
- const numRequiredSignatures = byteArray.shift();
721
+ const numRequiredSignatures = guardedShift(byteArray);
684
722
 
685
723
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
686
724
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
687
725
  }
688
726
 
689
- const numReadonlySignedAccounts = byteArray.shift();
690
- const numReadonlyUnsignedAccounts = byteArray.shift();
727
+ const numReadonlySignedAccounts = guardedShift(byteArray);
728
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
691
729
  const accountCount = decodeLength(byteArray);
692
730
  let accountKeys = [];
693
731
 
694
732
  for (let i = 0; i < accountCount; i++) {
695
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
696
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
733
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
697
734
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
698
735
  }
699
736
 
700
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
701
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
737
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
702
738
  const instructionCount = decodeLength(byteArray);
703
739
  let instructions = [];
704
740
 
705
741
  for (let i = 0; i < instructionCount; i++) {
706
- const programIdIndex = byteArray.shift();
742
+ const programIdIndex = guardedShift(byteArray);
707
743
  const accountCount = decodeLength(byteArray);
708
- const accounts = byteArray.slice(0, accountCount);
709
- byteArray = byteArray.slice(accountCount);
744
+ const accounts = guardedSplice(byteArray, 0, accountCount);
710
745
  const dataLength = decodeLength(byteArray);
711
- const dataSlice = byteArray.slice(0, dataLength);
746
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
712
747
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
713
- byteArray = byteArray.slice(dataLength);
714
748
  instructions.push({
715
749
  programIdIndex,
716
750
  accounts,
@@ -833,33 +867,33 @@ class MessageV0 {
833
867
 
834
868
  static deserialize(serializedMessage) {
835
869
  let byteArray = [...serializedMessage];
836
- const prefix = byteArray.shift();
870
+ const prefix = guardedShift(byteArray);
837
871
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
838
872
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
839
873
  const version = maskedPrefix;
840
874
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
841
875
  const header = {
842
- numRequiredSignatures: byteArray.shift(),
843
- numReadonlySignedAccounts: byteArray.shift(),
844
- numReadonlyUnsignedAccounts: byteArray.shift()
876
+ numRequiredSignatures: guardedShift(byteArray),
877
+ numReadonlySignedAccounts: guardedShift(byteArray),
878
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
845
879
  };
846
880
  const staticAccountKeys = [];
847
881
  const staticAccountKeysLength = decodeLength(byteArray);
848
882
 
849
883
  for (let i = 0; i < staticAccountKeysLength; i++) {
850
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
884
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
851
885
  }
852
886
 
853
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
887
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
854
888
  const instructionCount = decodeLength(byteArray);
855
889
  const compiledInstructions = [];
856
890
 
857
891
  for (let i = 0; i < instructionCount; i++) {
858
- const programIdIndex = byteArray.shift();
892
+ const programIdIndex = guardedShift(byteArray);
859
893
  const accountKeyIndexesLength = decodeLength(byteArray);
860
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
894
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
861
895
  const dataLength = decodeLength(byteArray);
862
- const data = new Uint8Array(byteArray.splice(0, dataLength));
896
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
863
897
  compiledInstructions.push({
864
898
  programIdIndex,
865
899
  accountKeyIndexes,
@@ -871,11 +905,11 @@ class MessageV0 {
871
905
  const addressTableLookups = [];
872
906
 
873
907
  for (let i = 0; i < addressTableLookupsCount; i++) {
874
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
908
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
875
909
  const writableIndexesLength = decodeLength(byteArray);
876
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
910
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
877
911
  const readonlyIndexesLength = decodeLength(byteArray);
878
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
912
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
879
913
  addressTableLookups.push({
880
914
  accountKey,
881
915
  writableIndexes,
@@ -1606,8 +1640,7 @@ class Transaction {
1606
1640
  let signatures = [];
1607
1641
 
1608
1642
  for (let i = 0; i < signatureCount; i++) {
1609
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1610
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1643
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1611
1644
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1612
1645
  }
1613
1646
 
@@ -1699,7 +1732,7 @@ class VersionedTransaction {
1699
1732
  const signaturesLength = decodeLength(byteArray);
1700
1733
 
1701
1734
  for (let i = 0; i < signaturesLength; i++) {
1702
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1735
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1703
1736
  }
1704
1737
 
1705
1738
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4158,7 +4191,7 @@ const LogsNotificationResult = superstruct.type({
4158
4191
 
4159
4192
  /** @internal */
4160
4193
  const COMMON_HTTP_HEADERS = {
4161
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4194
+ 'solana-client': `js/${(_process$env$npm_pack = "1.56.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4162
4195
  };
4163
4196
  /**
4164
4197
  * A connection to a fullnode JSON RPC endpoint
@@ -8936,10 +8969,8 @@ class ValidatorInfo {
8936
8969
  const configKeys = [];
8937
8970
 
8938
8971
  for (let i = 0; i < 2; i++) {
8939
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
8940
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
8941
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8942
- byteArray = byteArray.slice(1);
8972
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
8973
+ const isSigner = guardedShift(byteArray) === 1;
8943
8974
  configKeys.push({
8944
8975
  publicKey,
8945
8976
  isSigner