@solana/web3.js 1.57.0 → 1.59.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.
@@ -11,7 +11,7 @@ import { toBigIntLE, toBufferLE } from 'bigint-buffer';
11
11
  import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$1 } from 'superstruct';
12
12
  import { Client } from 'rpc-websockets';
13
13
  import RpcClient from 'jayson/lib/client/browser';
14
- import sha3 from 'js-sha3';
14
+ import { keccak_256 } from '@noble/hashes/sha3';
15
15
  import { hmac } from '@noble/hashes/hmac';
16
16
  import * as secp256k1 from '@noble/secp256k1';
17
17
 
@@ -486,7 +486,6 @@ class MessageAccountKeys {
486
486
  /**
487
487
  * Layout for a public key
488
488
  */
489
-
490
489
  const publicKey = (property = 'publicKey') => {
491
490
  return BufferLayout.blob(32, property);
492
491
  };
@@ -550,6 +549,13 @@ const lockup = (property = 'lockup') => {
550
549
  const voteInit = (property = 'voteInit') => {
551
550
  return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
552
551
  };
552
+ /**
553
+ * Layout for a VoteAuthorizeWithSeedArgs object
554
+ */
555
+
556
+ const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
557
+ return BufferLayout.struct([BufferLayout.u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
558
+ };
553
559
  function getAlloc(type, fields) {
554
560
  const getItemAlloc = item => {
555
561
  if (item.span >= 0) {
@@ -562,6 +568,11 @@ function getAlloc(type, fields) {
562
568
  if (Array.isArray(field)) {
563
569
  return field.length * getItemAlloc(item.elementLayout);
564
570
  }
571
+ } else if ('fields' in item) {
572
+ // This is a `Structure` whose size needs to be recursively measured.
573
+ return getAlloc({
574
+ layout: item
575
+ }, fields[item.property]);
565
576
  } // Couldn't determine allocated size of layout
566
577
 
567
578
 
@@ -608,6 +619,129 @@ function encodeLength(bytes, len) {
608
619
  }
609
620
  }
610
621
 
622
+ function assert (condition, message) {
623
+ if (!condition) {
624
+ throw new Error(message || 'Assertion failed');
625
+ }
626
+ }
627
+
628
+ class CompiledKeys {
629
+ constructor(payer, keyMetaMap) {
630
+ this.payer = void 0;
631
+ this.keyMetaMap = void 0;
632
+ this.payer = payer;
633
+ this.keyMetaMap = keyMetaMap;
634
+ }
635
+
636
+ static compile(instructions, payer) {
637
+ const keyMetaMap = new Map();
638
+
639
+ const getOrInsertDefault = pubkey => {
640
+ const address = pubkey.toBase58();
641
+ let keyMeta = keyMetaMap.get(address);
642
+
643
+ if (keyMeta === undefined) {
644
+ keyMeta = {
645
+ isSigner: false,
646
+ isWritable: false,
647
+ isInvoked: false
648
+ };
649
+ keyMetaMap.set(address, keyMeta);
650
+ }
651
+
652
+ return keyMeta;
653
+ };
654
+
655
+ const payerKeyMeta = getOrInsertDefault(payer);
656
+ payerKeyMeta.isSigner = true;
657
+ payerKeyMeta.isWritable = true;
658
+
659
+ for (const ix of instructions) {
660
+ getOrInsertDefault(ix.programId).isInvoked = true;
661
+
662
+ for (const accountMeta of ix.keys) {
663
+ const keyMeta = getOrInsertDefault(accountMeta.pubkey);
664
+ keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
665
+ keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
666
+ }
667
+ }
668
+
669
+ return new CompiledKeys(payer, keyMetaMap);
670
+ }
671
+
672
+ getMessageComponents() {
673
+ const mapEntries = [...this.keyMetaMap.entries()];
674
+ assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
675
+ const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
676
+ const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
677
+ const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
678
+ const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
679
+ const header = {
680
+ numRequiredSignatures: writableSigners.length + readonlySigners.length,
681
+ numReadonlySignedAccounts: readonlySigners.length,
682
+ numReadonlyUnsignedAccounts: readonlyNonSigners.length
683
+ }; // sanity checks
684
+
685
+ {
686
+ assert(writableSigners.length > 0, 'Expected at least one writable signer key');
687
+ const [payerAddress] = writableSigners[0];
688
+ assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
689
+ }
690
+ const staticAccountKeys = [...writableSigners.map(([address]) => new PublicKey(address)), ...readonlySigners.map(([address]) => new PublicKey(address)), ...writableNonSigners.map(([address]) => new PublicKey(address)), ...readonlyNonSigners.map(([address]) => new PublicKey(address))];
691
+ return [header, staticAccountKeys];
692
+ }
693
+
694
+ extractTableLookup(lookupTable) {
695
+ const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
696
+ const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
697
+
698
+ if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
699
+ return;
700
+ }
701
+
702
+ return [{
703
+ accountKey: lookupTable.key,
704
+ writableIndexes,
705
+ readonlyIndexes
706
+ }, {
707
+ writable: drainedWritableKeys,
708
+ readonly: drainedReadonlyKeys
709
+ }];
710
+ }
711
+ /** @internal */
712
+
713
+
714
+ drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
715
+ const lookupTableIndexes = new Array();
716
+ const drainedKeys = new Array();
717
+
718
+ for (const [address, keyMeta] of this.keyMetaMap.entries()) {
719
+ if (keyMetaFilter(keyMeta)) {
720
+ const key = new PublicKey(address);
721
+ const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
722
+
723
+ if (lookupTableIndex >= 0) {
724
+ assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
725
+ lookupTableIndexes.push(lookupTableIndex);
726
+ drainedKeys.push(key);
727
+ this.keyMetaMap.delete(address);
728
+ }
729
+ }
730
+ }
731
+
732
+ return [lookupTableIndexes, drainedKeys];
733
+ }
734
+
735
+ }
736
+
737
+ /**
738
+ * An instruction to execute by a program
739
+ *
740
+ * @property {number} programIdIndex
741
+ * @property {number[]} accounts
742
+ * @property {string} data
743
+ */
744
+
611
745
  /**
612
746
  * List of instructions to be processed atomically
613
747
  */
@@ -645,6 +779,27 @@ class Message {
645
779
  return [];
646
780
  }
647
781
 
782
+ getAccountKeys() {
783
+ return new MessageAccountKeys(this.staticAccountKeys);
784
+ }
785
+
786
+ static compile(args) {
787
+ const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
788
+ const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
789
+ const accountKeys = new MessageAccountKeys(staticAccountKeys);
790
+ const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
791
+ programIdIndex: ix.programIdIndex,
792
+ accounts: ix.accountKeyIndexes,
793
+ data: bs58.encode(ix.data)
794
+ }));
795
+ return new Message({
796
+ header,
797
+ accountKeys: staticAccountKeys,
798
+ recentBlockhash: args.recentBlockhash,
799
+ instructions
800
+ });
801
+ }
802
+
648
803
  isAccountSigner(index) {
649
804
  return index < this.header.numRequiredSignatures;
650
805
  }
@@ -734,7 +889,7 @@ class Message {
734
889
  for (let i = 0; i < accountCount; i++) {
735
890
  const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
736
891
  byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
737
- accountKeys.push(bs58.encode(Buffer.from(account)));
892
+ accountKeys.push(new PublicKey(Buffer.from(account)));
738
893
  }
739
894
 
740
895
  const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
@@ -773,141 +928,87 @@ class Message {
773
928
 
774
929
  }
775
930
 
776
- function assert (condition, message) {
777
- if (!condition) {
778
- throw new Error(message || 'Assertion failed');
779
- }
780
- }
931
+ /**
932
+ * Message constructor arguments
933
+ */
781
934
 
782
- class CompiledKeys {
783
- constructor(payer, keyMetaMap) {
784
- this.payer = void 0;
785
- this.keyMetaMap = void 0;
786
- this.payer = payer;
787
- this.keyMetaMap = keyMetaMap;
935
+ class MessageV0 {
936
+ constructor(args) {
937
+ this.header = void 0;
938
+ this.staticAccountKeys = void 0;
939
+ this.recentBlockhash = void 0;
940
+ this.compiledInstructions = void 0;
941
+ this.addressTableLookups = void 0;
942
+ this.header = args.header;
943
+ this.staticAccountKeys = args.staticAccountKeys;
944
+ this.recentBlockhash = args.recentBlockhash;
945
+ this.compiledInstructions = args.compiledInstructions;
946
+ this.addressTableLookups = args.addressTableLookups;
788
947
  }
789
948
 
790
- static compile(instructions, payer) {
791
- const keyMetaMap = new Map();
792
-
793
- const getOrInsertDefault = pubkey => {
794
- const address = pubkey.toBase58();
795
- let keyMeta = keyMetaMap.get(address);
796
-
797
- if (keyMeta === undefined) {
798
- keyMeta = {
799
- isSigner: false,
800
- isWritable: false,
801
- isInvoked: false
802
- };
803
- keyMetaMap.set(address, keyMeta);
804
- }
805
-
806
- return keyMeta;
807
- };
808
-
809
- const payerKeyMeta = getOrInsertDefault(payer);
810
- payerKeyMeta.isSigner = true;
811
- payerKeyMeta.isWritable = true;
949
+ get version() {
950
+ return 0;
951
+ }
812
952
 
813
- for (const ix of instructions) {
814
- getOrInsertDefault(ix.programId).isInvoked = true;
953
+ get numAccountKeysFromLookups() {
954
+ let count = 0;
815
955
 
816
- for (const accountMeta of ix.keys) {
817
- const keyMeta = getOrInsertDefault(accountMeta.pubkey);
818
- keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
819
- keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
820
- }
956
+ for (const lookup of this.addressTableLookups) {
957
+ count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
821
958
  }
822
959
 
823
- return new CompiledKeys(payer, keyMetaMap);
960
+ return count;
824
961
  }
825
962
 
826
- getMessageComponents() {
827
- const mapEntries = [...this.keyMetaMap.entries()];
828
- assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
829
- const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
830
- const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
831
- const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
832
- const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
833
- const header = {
834
- numRequiredSignatures: writableSigners.length + readonlySigners.length,
835
- numReadonlySignedAccounts: readonlySigners.length,
836
- numReadonlyUnsignedAccounts: readonlyNonSigners.length
837
- }; // sanity checks
838
-
839
- {
840
- assert(writableSigners.length > 0, 'Expected at least one writable signer key');
841
- const [payerAddress] = writableSigners[0];
842
- assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
843
- }
844
- const staticAccountKeys = [...writableSigners.map(([address]) => new PublicKey(address)), ...readonlySigners.map(([address]) => new PublicKey(address)), ...writableNonSigners.map(([address]) => new PublicKey(address)), ...readonlyNonSigners.map(([address]) => new PublicKey(address))];
845
- return [header, staticAccountKeys];
846
- }
963
+ getAccountKeys(args) {
964
+ let accountKeysFromLookups;
847
965
 
848
- extractTableLookup(lookupTable) {
849
- const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
850
- const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
966
+ if (args && 'accountKeysFromLookups' in args) {
967
+ if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
968
+ throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
969
+ }
851
970
 
852
- if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
853
- return;
971
+ accountKeysFromLookups = args.accountKeysFromLookups;
972
+ } else if (args && 'addressLookupTableAccounts' in args) {
973
+ accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
974
+ } else if (this.addressTableLookups.length > 0) {
975
+ throw new Error('Failed to get account keys because address table lookups were not resolved');
854
976
  }
855
977
 
856
- return [{
857
- accountKey: lookupTable.key,
858
- writableIndexes,
859
- readonlyIndexes
860
- }, {
861
- writable: drainedWritableKeys,
862
- readonly: drainedReadonlyKeys
863
- }];
978
+ return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
864
979
  }
865
- /** @internal */
866
980
 
981
+ resolveAddressTableLookups(addressLookupTableAccounts) {
982
+ const accountKeysFromLookups = {
983
+ writable: [],
984
+ readonly: []
985
+ };
867
986
 
868
- drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
869
- const lookupTableIndexes = new Array();
870
- const drainedKeys = new Array();
987
+ for (const tableLookup of this.addressTableLookups) {
988
+ const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
871
989
 
872
- for (const [address, keyMeta] of this.keyMetaMap.entries()) {
873
- if (keyMetaFilter(keyMeta)) {
874
- const key = new PublicKey(address);
875
- const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
990
+ if (!tableAccount) {
991
+ throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
992
+ }
876
993
 
877
- if (lookupTableIndex >= 0) {
878
- assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
879
- lookupTableIndexes.push(lookupTableIndex);
880
- drainedKeys.push(key);
881
- this.keyMetaMap.delete(address);
994
+ for (const index of tableLookup.writableIndexes) {
995
+ if (index < tableAccount.state.addresses.length) {
996
+ accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
997
+ } else {
998
+ throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
882
999
  }
883
1000
  }
884
- }
885
-
886
- return [lookupTableIndexes, drainedKeys];
887
- }
888
1001
 
889
- }
890
-
891
- /**
892
- * Message constructor arguments
893
- */
894
-
895
- class MessageV0 {
896
- constructor(args) {
897
- this.header = void 0;
898
- this.staticAccountKeys = void 0;
899
- this.recentBlockhash = void 0;
900
- this.compiledInstructions = void 0;
901
- this.addressTableLookups = void 0;
902
- this.header = args.header;
903
- this.staticAccountKeys = args.staticAccountKeys;
904
- this.recentBlockhash = args.recentBlockhash;
905
- this.compiledInstructions = args.compiledInstructions;
906
- this.addressTableLookups = args.addressTableLookups;
907
- }
1002
+ for (const index of tableLookup.readonlyIndexes) {
1003
+ if (index < tableAccount.state.addresses.length) {
1004
+ accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
1005
+ } else {
1006
+ throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
1007
+ }
1008
+ }
1009
+ }
908
1010
 
909
- get version() {
910
- return 0;
1011
+ return accountKeysFromLookups;
911
1012
  }
912
1013
 
913
1014
  static compile(args) {
@@ -1839,6 +1940,108 @@ class Transaction {
1839
1940
 
1840
1941
  }
1841
1942
 
1943
+ class TransactionMessage {
1944
+ constructor(args) {
1945
+ this.payerKey = void 0;
1946
+ this.instructions = void 0;
1947
+ this.recentBlockhash = void 0;
1948
+ this.payerKey = args.payerKey;
1949
+ this.instructions = args.instructions;
1950
+ this.recentBlockhash = args.recentBlockhash;
1951
+ }
1952
+
1953
+ static decompile(message, args) {
1954
+ const {
1955
+ header,
1956
+ compiledInstructions,
1957
+ recentBlockhash
1958
+ } = message;
1959
+ const {
1960
+ numRequiredSignatures,
1961
+ numReadonlySignedAccounts,
1962
+ numReadonlyUnsignedAccounts
1963
+ } = header;
1964
+ const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
1965
+ assert(numWritableSignedAccounts > 0, 'Message header is invalid');
1966
+ const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
1967
+ assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
1968
+ const accountKeys = message.getAccountKeys(args);
1969
+ const payerKey = accountKeys.get(0);
1970
+
1971
+ if (payerKey === undefined) {
1972
+ throw new Error('Failed to decompile message because no account keys were found');
1973
+ }
1974
+
1975
+ const instructions = [];
1976
+
1977
+ for (const compiledIx of compiledInstructions) {
1978
+ const keys = [];
1979
+
1980
+ for (const keyIndex of compiledIx.accountKeyIndexes) {
1981
+ const pubkey = accountKeys.get(keyIndex);
1982
+
1983
+ if (pubkey === undefined) {
1984
+ throw new Error(`Failed to find key for account key index ${keyIndex}`);
1985
+ }
1986
+
1987
+ const isSigner = keyIndex < numRequiredSignatures;
1988
+ let isWritable;
1989
+
1990
+ if (isSigner) {
1991
+ isWritable = keyIndex < numWritableSignedAccounts;
1992
+ } else if (keyIndex < accountKeys.staticAccountKeys.length) {
1993
+ isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
1994
+ } else {
1995
+ isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
1996
+ accountKeys.accountKeysFromLookups.writable.length;
1997
+ }
1998
+
1999
+ keys.push({
2000
+ pubkey,
2001
+ isSigner: keyIndex < header.numRequiredSignatures,
2002
+ isWritable
2003
+ });
2004
+ }
2005
+
2006
+ const programId = accountKeys.get(compiledIx.programIdIndex);
2007
+
2008
+ if (programId === undefined) {
2009
+ throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
2010
+ }
2011
+
2012
+ instructions.push(new TransactionInstruction({
2013
+ programId,
2014
+ data: toBuffer(compiledIx.data),
2015
+ keys
2016
+ }));
2017
+ }
2018
+
2019
+ return new TransactionMessage({
2020
+ payerKey,
2021
+ instructions,
2022
+ recentBlockhash
2023
+ });
2024
+ }
2025
+
2026
+ compileToLegacyMessage() {
2027
+ return Message.compile({
2028
+ payerKey: this.payerKey,
2029
+ recentBlockhash: this.recentBlockhash,
2030
+ instructions: this.instructions
2031
+ });
2032
+ }
2033
+
2034
+ compileToV0Message(addressLookupTableAccounts) {
2035
+ return MessageV0.compile({
2036
+ payerKey: this.payerKey,
2037
+ recentBlockhash: this.recentBlockhash,
2038
+ instructions: this.instructions,
2039
+ addressLookupTableAccounts
2040
+ });
2041
+ }
2042
+
2043
+ }
2044
+
1842
2045
  /**
1843
2046
  * Versioned transaction class
1844
2047
  */
@@ -6142,10 +6345,44 @@ class Connection {
6142
6345
  }
6143
6346
  /**
6144
6347
  * Simulate a transaction
6348
+ *
6349
+ * @deprecated Instead, call {@link simulateTransaction} with {@link
6350
+ * VersionedTransaction} and {@link SimulateTransactionConfig} parameters
6145
6351
  */
6146
6352
 
6147
6353
 
6148
- async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
6354
+ /**
6355
+ * Simulate a transaction
6356
+ */
6357
+ // eslint-disable-next-line no-dupe-class-members
6358
+ async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
6359
+ if ('message' in transactionOrMessage) {
6360
+ const versionedTx = transactionOrMessage;
6361
+ const wireTransaction = versionedTx.serialize();
6362
+ const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
6363
+
6364
+ if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
6365
+ throw new Error('Invalid arguments');
6366
+ }
6367
+
6368
+ const config = configOrSigners || {};
6369
+ config.encoding = 'base64';
6370
+
6371
+ if (!('commitment' in config)) {
6372
+ config.commitment = this.commitment;
6373
+ }
6374
+
6375
+ const args = [encodedTransaction, config];
6376
+ const unsafeRes = await this._rpcRequest('simulateTransaction', args);
6377
+ const res = create(unsafeRes, SimulatedTransactionResponseStruct);
6378
+
6379
+ if ('error' in res) {
6380
+ throw new Error('failed to simulate transaction: ' + res.error.message);
6381
+ }
6382
+
6383
+ return res.result;
6384
+ }
6385
+
6149
6386
  let transaction;
6150
6387
 
6151
6388
  if (transactionOrMessage instanceof Transaction) {
@@ -6161,6 +6398,12 @@ class Connection {
6161
6398
  transaction._message = transaction._json = undefined;
6162
6399
  }
6163
6400
 
6401
+ if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
6402
+ throw new Error('Invalid arguments');
6403
+ }
6404
+
6405
+ const signers = configOrSigners;
6406
+
6164
6407
  if (transaction.nonceInfo && signers) {
6165
6408
  transaction.sign(...signers);
6166
6409
  } else {
@@ -6241,12 +6484,34 @@ class Connection {
6241
6484
 
6242
6485
  return res.result;
6243
6486
  }
6487
+ /**
6488
+ * Sign and send a transaction
6489
+ *
6490
+ * @deprecated Instead, call {@link sendTransaction} with a {@link
6491
+ * VersionedTransaction}
6492
+ */
6493
+
6494
+
6244
6495
  /**
6245
6496
  * Sign and send a transaction
6246
6497
  */
6498
+ // eslint-disable-next-line no-dupe-class-members
6499
+ async sendTransaction(transaction, signersOrOptions, options) {
6500
+ if ('message' in transaction) {
6501
+ if (signersOrOptions && Array.isArray(signersOrOptions)) {
6502
+ throw new Error('Invalid arguments');
6503
+ }
6504
+
6505
+ const wireTransaction = transaction.serialize();
6506
+ return await this.sendRawTransaction(wireTransaction, options);
6507
+ }
6508
+
6509
+ if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
6510
+ throw new Error('Invalid arguments');
6511
+ }
6247
6512
 
6513
+ const signers = signersOrOptions;
6248
6514
 
6249
- async sendTransaction(transaction, signers, options) {
6250
6515
  if (transaction.nonceInfo) {
6251
6516
  transaction.sign(...signers);
6252
6517
  } else {
@@ -7773,7 +8038,7 @@ class Secp256k1Program {
7773
8038
  assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
7774
8039
 
7775
8040
  try {
7776
- return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8041
+ return Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
7777
8042
  } catch (error) {
7778
8043
  throw new Error(`Error constructing Ethereum address: ${error}`);
7779
8044
  }
@@ -7873,7 +8138,7 @@ class Secp256k1Program {
7873
8138
  /* isCompressed */
7874
8139
  ).slice(1); // throw away leading byte
7875
8140
 
7876
- const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
8141
+ const messageHash = Buffer.from(keccak_256(toBuffer(message)));
7877
8142
  const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
7878
8143
  return this.createInstructionWithPublicKey({
7879
8144
  publicKey,
@@ -8767,6 +9032,33 @@ class VoteInstruction {
8767
9032
  }
8768
9033
  };
8769
9034
  }
9035
+ /**
9036
+ * Decode an authorize instruction and retrieve the instruction params.
9037
+ */
9038
+
9039
+
9040
+ static decodeAuthorizeWithSeed(instruction) {
9041
+ this.checkProgramId(instruction.programId);
9042
+ this.checkKeyLength(instruction.keys, 3);
9043
+ const {
9044
+ voteAuthorizeWithSeedArgs: {
9045
+ currentAuthorityDerivedKeyOwnerPubkey,
9046
+ currentAuthorityDerivedKeySeed,
9047
+ newAuthorized,
9048
+ voteAuthorizationType
9049
+ }
9050
+ } = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
9051
+ return {
9052
+ currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
9053
+ currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
9054
+ currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
9055
+ newAuthorizedPubkey: new PublicKey(newAuthorized),
9056
+ voteAuthorizationType: {
9057
+ index: voteAuthorizationType
9058
+ },
9059
+ votePubkey: instruction.keys[0].pubkey
9060
+ };
9061
+ }
8770
9062
  /**
8771
9063
  * Decode a withdraw instruction and retrieve the instruction params.
8772
9064
  */
@@ -8823,6 +9115,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
8823
9115
  Withdraw: {
8824
9116
  index: 3,
8825
9117
  layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
9118
+ },
9119
+ AuthorizeWithSeed: {
9120
+ index: 10,
9121
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteAuthorizeWithSeedArgs()])
8826
9122
  }
8827
9123
  });
8828
9124
  /**
@@ -8951,6 +9247,49 @@ class VoteProgram {
8951
9247
  data
8952
9248
  });
8953
9249
  }
9250
+ /**
9251
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
9252
+ * where the current Voter or Withdrawer authority is a derived key.
9253
+ */
9254
+
9255
+
9256
+ static authorizeWithSeed(params) {
9257
+ const {
9258
+ currentAuthorityDerivedKeyBasePubkey,
9259
+ currentAuthorityDerivedKeyOwnerPubkey,
9260
+ currentAuthorityDerivedKeySeed,
9261
+ newAuthorizedPubkey,
9262
+ voteAuthorizationType,
9263
+ votePubkey
9264
+ } = params;
9265
+ const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
9266
+ const data = encodeData(type, {
9267
+ voteAuthorizeWithSeedArgs: {
9268
+ currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
9269
+ currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
9270
+ newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
9271
+ voteAuthorizationType: voteAuthorizationType.index
9272
+ }
9273
+ });
9274
+ const keys = [{
9275
+ pubkey: votePubkey,
9276
+ isSigner: false,
9277
+ isWritable: true
9278
+ }, {
9279
+ pubkey: SYSVAR_CLOCK_PUBKEY,
9280
+ isSigner: false,
9281
+ isWritable: false
9282
+ }, {
9283
+ pubkey: currentAuthorityDerivedKeyBasePubkey,
9284
+ isSigner: true,
9285
+ isWritable: false
9286
+ }];
9287
+ return new Transaction().add({
9288
+ keys,
9289
+ programId: this.programId,
9290
+ data
9291
+ });
9292
+ }
8954
9293
  /**
8955
9294
  * Generate a transaction to withdraw from a Vote account.
8956
9295
  */
@@ -9273,5 +9612,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
9273
9612
 
9274
9613
  const LAMPORTS_PER_SOL = 1000000000;
9275
9614
 
9276
- export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, MessageAccountKeys, MessageV0, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PUBLIC_KEY_LENGTH, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9615
+ export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, MessageAccountKeys, MessageV0, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PUBLIC_KEY_LENGTH, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionMessage, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9277
9616
  //# sourceMappingURL=index.browser.esm.js.map