@solana/web3.js 1.56.1 → 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.
@@ -562,6 +562,44 @@ function encodeLength(bytes, len) {
562
562
  }
563
563
  }
564
564
 
565
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
566
+ /**
567
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
568
+ */
569
+
570
+ function guardedShift(byteArray) {
571
+ if (byteArray.length === 0) {
572
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
573
+ }
574
+
575
+ return byteArray.shift();
576
+ }
577
+ /**
578
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
579
+ * the array.
580
+ */
581
+
582
+ function guardedSplice(byteArray, ...args) {
583
+ var _args$;
584
+
585
+ const [start] = args;
586
+
587
+ if (args.length === 2 // Implies that `deleteCount` was supplied
588
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
589
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
590
+ }
591
+
592
+ return byteArray.splice(...args);
593
+ }
594
+
595
+ /**
596
+ * An instruction to execute by a program
597
+ *
598
+ * @property {number} programIdIndex
599
+ * @property {number[]} accounts
600
+ * @property {string} data
601
+ */
602
+
565
603
  /**
566
604
  * List of instructions to be processed atomically
567
605
  */
@@ -674,37 +712,33 @@ class Message {
674
712
  static from(buffer$1) {
675
713
  // Slice up wire data
676
714
  let byteArray = [...buffer$1];
677
- const numRequiredSignatures = byteArray.shift();
715
+ const numRequiredSignatures = guardedShift(byteArray);
678
716
 
679
717
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
680
718
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
681
719
  }
682
720
 
683
- const numReadonlySignedAccounts = byteArray.shift();
684
- const numReadonlyUnsignedAccounts = byteArray.shift();
721
+ const numReadonlySignedAccounts = guardedShift(byteArray);
722
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
685
723
  const accountCount = decodeLength(byteArray);
686
724
  let accountKeys = [];
687
725
 
688
726
  for (let i = 0; i < accountCount; i++) {
689
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
690
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
727
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
691
728
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
692
729
  }
693
730
 
694
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
695
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
731
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
696
732
  const instructionCount = decodeLength(byteArray);
697
733
  let instructions = [];
698
734
 
699
735
  for (let i = 0; i < instructionCount; i++) {
700
- const programIdIndex = byteArray.shift();
736
+ const programIdIndex = guardedShift(byteArray);
701
737
  const accountCount = decodeLength(byteArray);
702
- const accounts = byteArray.slice(0, accountCount);
703
- byteArray = byteArray.slice(accountCount);
738
+ const accounts = guardedSplice(byteArray, 0, accountCount);
704
739
  const dataLength = decodeLength(byteArray);
705
- const dataSlice = byteArray.slice(0, dataLength);
740
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
706
741
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
707
- byteArray = byteArray.slice(dataLength);
708
742
  instructions.push({
709
743
  programIdIndex,
710
744
  accounts,
@@ -827,33 +861,33 @@ class MessageV0 {
827
861
 
828
862
  static deserialize(serializedMessage) {
829
863
  let byteArray = [...serializedMessage];
830
- const prefix = byteArray.shift();
864
+ const prefix = guardedShift(byteArray);
831
865
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
832
866
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
833
867
  const version = maskedPrefix;
834
868
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
835
869
  const header = {
836
- numRequiredSignatures: byteArray.shift(),
837
- numReadonlySignedAccounts: byteArray.shift(),
838
- numReadonlyUnsignedAccounts: byteArray.shift()
870
+ numRequiredSignatures: guardedShift(byteArray),
871
+ numReadonlySignedAccounts: guardedShift(byteArray),
872
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
839
873
  };
840
874
  const staticAccountKeys = [];
841
875
  const staticAccountKeysLength = decodeLength(byteArray);
842
876
 
843
877
  for (let i = 0; i < staticAccountKeysLength; i++) {
844
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
878
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
845
879
  }
846
880
 
847
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
881
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
848
882
  const instructionCount = decodeLength(byteArray);
849
883
  const compiledInstructions = [];
850
884
 
851
885
  for (let i = 0; i < instructionCount; i++) {
852
- const programIdIndex = byteArray.shift();
886
+ const programIdIndex = guardedShift(byteArray);
853
887
  const accountKeyIndexesLength = decodeLength(byteArray);
854
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
888
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
855
889
  const dataLength = decodeLength(byteArray);
856
- const data = new Uint8Array(byteArray.splice(0, dataLength));
890
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
857
891
  compiledInstructions.push({
858
892
  programIdIndex,
859
893
  accountKeyIndexes,
@@ -865,11 +899,11 @@ class MessageV0 {
865
899
  const addressTableLookups = [];
866
900
 
867
901
  for (let i = 0; i < addressTableLookupsCount; i++) {
868
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
902
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
869
903
  const writableIndexesLength = decodeLength(byteArray);
870
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
904
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
871
905
  const readonlyIndexesLength = decodeLength(byteArray);
872
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
906
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
873
907
  addressTableLookups.push({
874
908
  accountKey,
875
909
  writableIndexes,
@@ -1600,8 +1634,7 @@ class Transaction {
1600
1634
  let signatures = [];
1601
1635
 
1602
1636
  for (let i = 0; i < signatureCount; i++) {
1603
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1604
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1637
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1605
1638
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1606
1639
  }
1607
1640
 
@@ -1693,7 +1726,7 @@ class VersionedTransaction {
1693
1726
  const signaturesLength = decodeLength(byteArray);
1694
1727
 
1695
1728
  for (let i = 0; i < signaturesLength; i++) {
1696
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1729
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1697
1730
  }
1698
1731
 
1699
1732
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -3913,7 +3946,8 @@ const ConfirmedTransactionMetaResult = superstruct.type({
3913
3946
  logMessages: superstruct.optional(superstruct.nullable(superstruct.array(superstruct.string()))),
3914
3947
  preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
3915
3948
  postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
3916
- loadedAddresses: superstruct.optional(LoadedAddressesResult)
3949
+ loadedAddresses: superstruct.optional(LoadedAddressesResult),
3950
+ computeUnitsConsumed: superstruct.optional(superstruct.number())
3917
3951
  });
3918
3952
  /**
3919
3953
  * @internal
@@ -3931,7 +3965,8 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
3931
3965
  logMessages: superstruct.optional(superstruct.nullable(superstruct.array(superstruct.string()))),
3932
3966
  preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
3933
3967
  postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
3934
- loadedAddresses: superstruct.optional(LoadedAddressesResult)
3968
+ loadedAddresses: superstruct.optional(LoadedAddressesResult),
3969
+ computeUnitsConsumed: superstruct.optional(superstruct.number())
3935
3970
  });
3936
3971
  const TransactionVersionStruct = superstruct.union([superstruct.literal(0), superstruct.literal('legacy')]);
3937
3972
  /**
@@ -4090,7 +4125,7 @@ const LogsNotificationResult = superstruct.type({
4090
4125
 
4091
4126
  /** @internal */
4092
4127
  const COMMON_HTTP_HEADERS = {
4093
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4128
+ 'solana-client': `js/${(_process$env$npm_pack = "1.56.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4094
4129
  };
4095
4130
  /**
4096
4131
  * A connection to a fullnode JSON RPC endpoint
@@ -8868,10 +8903,8 @@ class ValidatorInfo {
8868
8903
  const configKeys = [];
8869
8904
 
8870
8905
  for (let i = 0; i < 2; i++) {
8871
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
8872
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
8873
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8874
- byteArray = byteArray.slice(1);
8906
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
8907
+ const isSigner = guardedShift(byteArray) === 1;
8875
8908
  configKeys.push({
8876
8909
  publicKey,
8877
8910
  isSigner