@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.esm.js CHANGED
@@ -534,6 +534,44 @@ function encodeLength(bytes, len) {
534
534
  }
535
535
  }
536
536
 
537
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
538
+ /**
539
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
540
+ */
541
+
542
+ function guardedShift(byteArray) {
543
+ if (byteArray.length === 0) {
544
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
545
+ }
546
+
547
+ return byteArray.shift();
548
+ }
549
+ /**
550
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
551
+ * the array.
552
+ */
553
+
554
+ function guardedSplice(byteArray, ...args) {
555
+ var _args$;
556
+
557
+ const [start] = args;
558
+
559
+ if (args.length === 2 // Implies that `deleteCount` was supplied
560
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
561
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
562
+ }
563
+
564
+ return byteArray.splice(...args);
565
+ }
566
+
567
+ /**
568
+ * An instruction to execute by a program
569
+ *
570
+ * @property {number} programIdIndex
571
+ * @property {number[]} accounts
572
+ * @property {string} data
573
+ */
574
+
537
575
  /**
538
576
  * List of instructions to be processed atomically
539
577
  */
@@ -646,37 +684,33 @@ class Message {
646
684
  static from(buffer) {
647
685
  // Slice up wire data
648
686
  let byteArray = [...buffer];
649
- const numRequiredSignatures = byteArray.shift();
687
+ const numRequiredSignatures = guardedShift(byteArray);
650
688
 
651
689
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
652
690
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
653
691
  }
654
692
 
655
- const numReadonlySignedAccounts = byteArray.shift();
656
- const numReadonlyUnsignedAccounts = byteArray.shift();
693
+ const numReadonlySignedAccounts = guardedShift(byteArray);
694
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
657
695
  const accountCount = decodeLength(byteArray);
658
696
  let accountKeys = [];
659
697
 
660
698
  for (let i = 0; i < accountCount; i++) {
661
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
662
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
699
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
663
700
  accountKeys.push(bs58.encode(Buffer.from(account)));
664
701
  }
665
702
 
666
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
667
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
703
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
668
704
  const instructionCount = decodeLength(byteArray);
669
705
  let instructions = [];
670
706
 
671
707
  for (let i = 0; i < instructionCount; i++) {
672
- const programIdIndex = byteArray.shift();
708
+ const programIdIndex = guardedShift(byteArray);
673
709
  const accountCount = decodeLength(byteArray);
674
- const accounts = byteArray.slice(0, accountCount);
675
- byteArray = byteArray.slice(accountCount);
710
+ const accounts = guardedSplice(byteArray, 0, accountCount);
676
711
  const dataLength = decodeLength(byteArray);
677
- const dataSlice = byteArray.slice(0, dataLength);
712
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
678
713
  const data = bs58.encode(Buffer.from(dataSlice));
679
- byteArray = byteArray.slice(dataLength);
680
714
  instructions.push({
681
715
  programIdIndex,
682
716
  accounts,
@@ -799,33 +833,33 @@ class MessageV0 {
799
833
 
800
834
  static deserialize(serializedMessage) {
801
835
  let byteArray = [...serializedMessage];
802
- const prefix = byteArray.shift();
836
+ const prefix = guardedShift(byteArray);
803
837
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
804
838
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
805
839
  const version = maskedPrefix;
806
840
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
807
841
  const header = {
808
- numRequiredSignatures: byteArray.shift(),
809
- numReadonlySignedAccounts: byteArray.shift(),
810
- numReadonlyUnsignedAccounts: byteArray.shift()
842
+ numRequiredSignatures: guardedShift(byteArray),
843
+ numReadonlySignedAccounts: guardedShift(byteArray),
844
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
811
845
  };
812
846
  const staticAccountKeys = [];
813
847
  const staticAccountKeysLength = decodeLength(byteArray);
814
848
 
815
849
  for (let i = 0; i < staticAccountKeysLength; i++) {
816
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
850
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
817
851
  }
818
852
 
819
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
853
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
820
854
  const instructionCount = decodeLength(byteArray);
821
855
  const compiledInstructions = [];
822
856
 
823
857
  for (let i = 0; i < instructionCount; i++) {
824
- const programIdIndex = byteArray.shift();
858
+ const programIdIndex = guardedShift(byteArray);
825
859
  const accountKeyIndexesLength = decodeLength(byteArray);
826
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
860
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
827
861
  const dataLength = decodeLength(byteArray);
828
- const data = new Uint8Array(byteArray.splice(0, dataLength));
862
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
829
863
  compiledInstructions.push({
830
864
  programIdIndex,
831
865
  accountKeyIndexes,
@@ -837,11 +871,11 @@ class MessageV0 {
837
871
  const addressTableLookups = [];
838
872
 
839
873
  for (let i = 0; i < addressTableLookupsCount; i++) {
840
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
874
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
841
875
  const writableIndexesLength = decodeLength(byteArray);
842
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
876
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
843
877
  const readonlyIndexesLength = decodeLength(byteArray);
844
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
878
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
845
879
  addressTableLookups.push({
846
880
  accountKey,
847
881
  writableIndexes,
@@ -1572,8 +1606,7 @@ class Transaction {
1572
1606
  let signatures = [];
1573
1607
 
1574
1608
  for (let i = 0; i < signatureCount; i++) {
1575
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1576
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1609
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1577
1610
  signatures.push(bs58.encode(Buffer.from(signature)));
1578
1611
  }
1579
1612
 
@@ -1665,7 +1698,7 @@ class VersionedTransaction {
1665
1698
  const signaturesLength = decodeLength(byteArray);
1666
1699
 
1667
1700
  for (let i = 0; i < signaturesLength; i++) {
1668
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1701
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1669
1702
  }
1670
1703
 
1671
1704
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4124,7 +4157,7 @@ const LogsNotificationResult = type({
4124
4157
 
4125
4158
  /** @internal */
4126
4159
  const COMMON_HTTP_HEADERS = {
4127
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4160
+ 'solana-client': `js/${(_process$env$npm_pack = "1.56.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4128
4161
  };
4129
4162
  /**
4130
4163
  * A connection to a fullnode JSON RPC endpoint
@@ -8902,10 +8935,8 @@ class ValidatorInfo {
8902
8935
  const configKeys = [];
8903
8936
 
8904
8937
  for (let i = 0; i < 2; i++) {
8905
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
8906
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
8907
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8908
- byteArray = byteArray.slice(1);
8938
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
8939
+ const isSigner = guardedShift(byteArray) === 1;
8909
8940
  configKeys.push({
8910
8941
  publicKey,
8911
8942
  isSigner