@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.
package/lib/index.d.ts CHANGED
@@ -1111,6 +1111,8 @@ declare module '@solana/web3.js' {
1111
1111
  err: TransactionError | null;
1112
1112
  /** The collection of addresses loaded using address lookup tables */
1113
1113
  loadedAddresses?: LoadedAddresses;
1114
+ /** The compute units consumed after processing the transaction */
1115
+ computeUnitsConsumed?: number;
1114
1116
  };
1115
1117
  export type CompiledInnerInstruction = {
1116
1118
  index: number;
@@ -1138,6 +1140,8 @@ declare module '@solana/web3.js' {
1138
1140
  err: TransactionError | null;
1139
1141
  /** The collection of addresses loaded using address lookup tables */
1140
1142
  loadedAddresses?: LoadedAddresses;
1143
+ /** The compute units consumed after processing the transaction */
1144
+ computeUnitsConsumed?: number;
1141
1145
  };
1142
1146
  /**
1143
1147
  * A processed transaction from the RPC API
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));
@@ -3945,7 +3978,8 @@ const ConfirmedTransactionMetaResult = type({
3945
3978
  logMessages: optional(nullable(array(string()))),
3946
3979
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
3947
3980
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
3948
- loadedAddresses: optional(LoadedAddressesResult)
3981
+ loadedAddresses: optional(LoadedAddressesResult),
3982
+ computeUnitsConsumed: optional(number())
3949
3983
  });
3950
3984
  /**
3951
3985
  * @internal
@@ -3963,7 +3997,8 @@ const ParsedConfirmedTransactionMetaResult = type({
3963
3997
  logMessages: optional(nullable(array(string()))),
3964
3998
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
3965
3999
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
3966
- loadedAddresses: optional(LoadedAddressesResult)
4000
+ loadedAddresses: optional(LoadedAddressesResult),
4001
+ computeUnitsConsumed: optional(number())
3967
4002
  });
3968
4003
  const TransactionVersionStruct = union([literal(0), literal('legacy')]);
3969
4004
  /**
@@ -4122,7 +4157,7 @@ const LogsNotificationResult = type({
4122
4157
 
4123
4158
  /** @internal */
4124
4159
  const COMMON_HTTP_HEADERS = {
4125
- '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'}`
4126
4161
  };
4127
4162
  /**
4128
4163
  * A connection to a fullnode JSON RPC endpoint
@@ -8900,10 +8935,8 @@ class ValidatorInfo {
8900
8935
  const configKeys = [];
8901
8936
 
8902
8937
  for (let i = 0; i < 2; i++) {
8903
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
8904
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
8905
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8906
- byteArray = byteArray.slice(1);
8938
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
8939
+ const isSigner = guardedShift(byteArray) === 1;
8907
8940
  configKeys.push({
8908
8941
  publicKey,
8909
8942
  isSigner