@solana/web3.js 1.56.2 → 1.59.0

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
@@ -14,7 +14,7 @@ import RpcClient from 'jayson/lib/client/browser';
14
14
  import http from 'http';
15
15
  import https from 'https';
16
16
  import * as nodeFetch from 'node-fetch';
17
- import sha3 from 'js-sha3';
17
+ import { keccak_256 } from '@noble/hashes/sha3';
18
18
  import { hmac } from '@noble/hashes/hmac';
19
19
  import * as secp256k1 from '@noble/secp256k1';
20
20
 
@@ -115,12 +115,14 @@ const PUBLIC_KEY_LENGTH = 32;
115
115
 
116
116
  function isPublicKeyData(value) {
117
117
  return value._bn !== undefined;
118
- }
118
+ } // local counter used by PublicKey.unique()
119
+
120
+
121
+ let uniquePublicKeyCounter = 1;
119
122
  /**
120
123
  * A public key
121
124
  */
122
125
 
123
-
124
126
  class PublicKey extends Struct {
125
127
  /** @internal */
126
128
 
@@ -153,6 +155,16 @@ class PublicKey extends Struct {
153
155
  }
154
156
  }
155
157
  }
158
+ /**
159
+ * Returns a unique PublicKey for tests and benchmarks using acounter
160
+ */
161
+
162
+
163
+ static unique() {
164
+ const key = new PublicKey(uniquePublicKeyCounter);
165
+ uniquePublicKeyCounter += 1;
166
+ return new PublicKey(key.toBuffer());
167
+ }
156
168
  /**
157
169
  * Default public key value. (All zeros)
158
170
  */
@@ -409,10 +421,74 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
409
421
  value: 'TransactionExpiredTimeoutError'
410
422
  });
411
423
 
424
+ class MessageAccountKeys {
425
+ constructor(staticAccountKeys, accountKeysFromLookups) {
426
+ this.staticAccountKeys = void 0;
427
+ this.accountKeysFromLookups = void 0;
428
+ this.staticAccountKeys = staticAccountKeys;
429
+ this.accountKeysFromLookups = accountKeysFromLookups;
430
+ }
431
+
432
+ keySegments() {
433
+ const keySegments = [this.staticAccountKeys];
434
+
435
+ if (this.accountKeysFromLookups) {
436
+ keySegments.push(this.accountKeysFromLookups.writable);
437
+ keySegments.push(this.accountKeysFromLookups.readonly);
438
+ }
439
+
440
+ return keySegments;
441
+ }
442
+
443
+ get(index) {
444
+ for (const keySegment of this.keySegments()) {
445
+ if (index < keySegment.length) {
446
+ return keySegment[index];
447
+ } else {
448
+ index -= keySegment.length;
449
+ }
450
+ }
451
+
452
+ return;
453
+ }
454
+
455
+ get length() {
456
+ return this.keySegments().flat().length;
457
+ }
458
+
459
+ compileInstructions(instructions) {
460
+ // Bail early if any account indexes would overflow a u8
461
+ const U8_MAX = 255;
462
+
463
+ if (this.length > U8_MAX + 1) {
464
+ throw new Error('Account index overflow encountered during compilation');
465
+ }
466
+
467
+ const keyIndexMap = new Map();
468
+ this.keySegments().flat().forEach((key, index) => {
469
+ keyIndexMap.set(key.toBase58(), index);
470
+ });
471
+
472
+ const findKeyIndex = key => {
473
+ const keyIndex = keyIndexMap.get(key.toBase58());
474
+ if (keyIndex === undefined) throw new Error('Encountered an unknown instruction account key during compilation');
475
+ return keyIndex;
476
+ };
477
+
478
+ return instructions.map(instruction => {
479
+ return {
480
+ programIdIndex: findKeyIndex(instruction.programId),
481
+ accountKeyIndexes: instruction.keys.map(meta => findKeyIndex(meta.pubkey)),
482
+ data: instruction.data
483
+ };
484
+ });
485
+ }
486
+
487
+ }
488
+
412
489
  /**
413
490
  * Layout for a public key
414
491
  */
415
-
416
492
  const publicKey = (property = 'publicKey') => {
417
493
  return BufferLayout.blob(32, property);
418
494
  };
@@ -476,6 +552,13 @@ const lockup = (property = 'lockup') => {
476
552
  const voteInit = (property = 'voteInit') => {
477
553
  return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
478
554
  };
555
+ /**
556
+ * Layout for a VoteAuthorizeWithSeedArgs object
557
+ */
558
+
559
+ const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
560
+ return BufferLayout.struct([BufferLayout.u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
561
+ };
479
562
  function getAlloc(type, fields) {
480
563
  const getItemAlloc = item => {
481
564
  if (item.span >= 0) {
@@ -488,6 +571,11 @@ function getAlloc(type, fields) {
488
571
  if (Array.isArray(field)) {
489
572
  return field.length * getItemAlloc(item.elementLayout);
490
573
  }
574
+ } else if ('fields' in item) {
575
+ // This is a `Structure` whose size needs to be recursively measured.
576
+ return getAlloc({
577
+ layout: item
578
+ }, fields[item.property]);
491
579
  } // Couldn't determine allocated size of layout
492
580
 
493
581
 
@@ -534,6 +622,129 @@ function encodeLength(bytes, len) {
534
622
  }
535
623
  }
536
624
 
625
+ function assert (condition, message) {
626
+ if (!condition) {
627
+ throw new Error(message || 'Assertion failed');
628
+ }
629
+ }
630
+
631
+ class CompiledKeys {
632
+ constructor(payer, keyMetaMap) {
633
+ this.payer = void 0;
634
+ this.keyMetaMap = void 0;
635
+ this.payer = payer;
636
+ this.keyMetaMap = keyMetaMap;
637
+ }
638
+
639
+ static compile(instructions, payer) {
640
+ const keyMetaMap = new Map();
641
+
642
+ const getOrInsertDefault = pubkey => {
643
+ const address = pubkey.toBase58();
644
+ let keyMeta = keyMetaMap.get(address);
645
+
646
+ if (keyMeta === undefined) {
647
+ keyMeta = {
648
+ isSigner: false,
649
+ isWritable: false,
650
+ isInvoked: false
651
+ };
652
+ keyMetaMap.set(address, keyMeta);
653
+ }
654
+
655
+ return keyMeta;
656
+ };
657
+
658
+ const payerKeyMeta = getOrInsertDefault(payer);
659
+ payerKeyMeta.isSigner = true;
660
+ payerKeyMeta.isWritable = true;
661
+
662
+ for (const ix of instructions) {
663
+ getOrInsertDefault(ix.programId).isInvoked = true;
664
+
665
+ for (const accountMeta of ix.keys) {
666
+ const keyMeta = getOrInsertDefault(accountMeta.pubkey);
667
+ keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
668
+ keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
669
+ }
670
+ }
671
+
672
+ return new CompiledKeys(payer, keyMetaMap);
673
+ }
674
+
675
+ getMessageComponents() {
676
+ const mapEntries = [...this.keyMetaMap.entries()];
677
+ assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
678
+ const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
679
+ const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
680
+ const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
681
+ const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
682
+ const header = {
683
+ numRequiredSignatures: writableSigners.length + readonlySigners.length,
684
+ numReadonlySignedAccounts: readonlySigners.length,
685
+ numReadonlyUnsignedAccounts: readonlyNonSigners.length
686
+ }; // sanity checks
687
+
688
+ {
689
+ assert(writableSigners.length > 0, 'Expected at least one writable signer key');
690
+ const [payerAddress] = writableSigners[0];
691
+ assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
692
+ }
693
+ 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))];
694
+ return [header, staticAccountKeys];
695
+ }
696
+
697
+ extractTableLookup(lookupTable) {
698
+ const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
699
+ const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
700
+
701
+ if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
702
+ return;
703
+ }
704
+
705
+ return [{
706
+ accountKey: lookupTable.key,
707
+ writableIndexes,
708
+ readonlyIndexes
709
+ }, {
710
+ writable: drainedWritableKeys,
711
+ readonly: drainedReadonlyKeys
712
+ }];
713
+ }
714
+ /** @internal */
715
+
716
+
717
+ drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
718
+ const lookupTableIndexes = new Array();
719
+ const drainedKeys = new Array();
720
+
721
+ for (const [address, keyMeta] of this.keyMetaMap.entries()) {
722
+ if (keyMetaFilter(keyMeta)) {
723
+ const key = new PublicKey(address);
724
+ const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
725
+
726
+ if (lookupTableIndex >= 0) {
727
+ assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
728
+ lookupTableIndexes.push(lookupTableIndex);
729
+ drainedKeys.push(key);
730
+ this.keyMetaMap.delete(address);
731
+ }
732
+ }
733
+ }
734
+
735
+ return [lookupTableIndexes, drainedKeys];
736
+ }
737
+
738
+ }
739
+
740
+ /**
741
+ * An instruction to execute by a program
742
+ *
743
+ * @property {number} programIdIndex
744
+ * @property {number[]} accounts
745
+ * @property {string} data
746
+ */
747
+
537
748
  /**
538
749
  * List of instructions to be processed atomically
539
750
  */
@@ -571,6 +782,27 @@ class Message {
571
782
  return [];
572
783
  }
573
784
 
785
+ getAccountKeys() {
786
+ return new MessageAccountKeys(this.staticAccountKeys);
787
+ }
788
+
789
+ static compile(args) {
790
+ const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
791
+ const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
792
+ const accountKeys = new MessageAccountKeys(staticAccountKeys);
793
+ const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
794
+ programIdIndex: ix.programIdIndex,
795
+ accounts: ix.accountKeyIndexes,
796
+ data: bs58.encode(ix.data)
797
+ }));
798
+ return new Message({
799
+ header,
800
+ accountKeys: staticAccountKeys,
801
+ recentBlockhash: args.recentBlockhash,
802
+ instructions
803
+ });
804
+ }
805
+
574
806
  isAccountSigner(index) {
575
807
  return index < this.header.numRequiredSignatures;
576
808
  }
@@ -660,7 +892,7 @@ class Message {
660
892
  for (let i = 0; i < accountCount; i++) {
661
893
  const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
662
894
  byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
663
- accountKeys.push(bs58.encode(Buffer.from(account)));
895
+ accountKeys.push(new PublicKey(Buffer.from(account)));
664
896
  }
665
897
 
666
898
  const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
@@ -699,12 +931,6 @@ class Message {
699
931
 
700
932
  }
701
933
 
702
- function assert (condition, message) {
703
- if (!condition) {
704
- throw new Error(message || 'Assertion failed');
705
- }
706
- }
707
-
708
934
  /**
709
935
  * Message constructor arguments
710
936
  */
@@ -727,6 +953,102 @@ class MessageV0 {
727
953
  return 0;
728
954
  }
729
955
 
956
+ get numAccountKeysFromLookups() {
957
+ let count = 0;
958
+
959
+ for (const lookup of this.addressTableLookups) {
960
+ count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
961
+ }
962
+
963
+ return count;
964
+ }
965
+
966
+ getAccountKeys(args) {
967
+ let accountKeysFromLookups;
968
+
969
+ if (args && 'accountKeysFromLookups' in args) {
970
+ if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
971
+ throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
972
+ }
973
+
974
+ accountKeysFromLookups = args.accountKeysFromLookups;
975
+ } else if (args && 'addressLookupTableAccounts' in args) {
976
+ accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
977
+ } else if (this.addressTableLookups.length > 0) {
978
+ throw new Error('Failed to get account keys because address table lookups were not resolved');
979
+ }
980
+
981
+ return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
982
+ }
983
+
984
+ resolveAddressTableLookups(addressLookupTableAccounts) {
985
+ const accountKeysFromLookups = {
986
+ writable: [],
987
+ readonly: []
988
+ };
989
+
990
+ for (const tableLookup of this.addressTableLookups) {
991
+ const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
992
+
993
+ if (!tableAccount) {
994
+ throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
995
+ }
996
+
997
+ for (const index of tableLookup.writableIndexes) {
998
+ if (index < tableAccount.state.addresses.length) {
999
+ accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
1000
+ } else {
1001
+ throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
1002
+ }
1003
+ }
1004
+
1005
+ for (const index of tableLookup.readonlyIndexes) {
1006
+ if (index < tableAccount.state.addresses.length) {
1007
+ accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
1008
+ } else {
1009
+ throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
1010
+ }
1011
+ }
1012
+ }
1013
+
1014
+ return accountKeysFromLookups;
1015
+ }
1016
+
1017
+ static compile(args) {
1018
+ const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
1019
+ const addressTableLookups = new Array();
1020
+ const accountKeysFromLookups = {
1021
+ writable: new Array(),
1022
+ readonly: new Array()
1023
+ };
1024
+ const lookupTableAccounts = args.addressLookupTableAccounts || [];
1025
+
1026
+ for (const lookupTable of lookupTableAccounts) {
1027
+ const extractResult = compiledKeys.extractTableLookup(lookupTable);
1028
+
1029
+ if (extractResult !== undefined) {
1030
+ const [addressTableLookup, {
1031
+ writable,
1032
+ readonly
1033
+ }] = extractResult;
1034
+ addressTableLookups.push(addressTableLookup);
1035
+ accountKeysFromLookups.writable.push(...writable);
1036
+ accountKeysFromLookups.readonly.push(...readonly);
1037
+ }
1038
+ }
1039
+
1040
+ const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
1041
+ const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
1042
+ const compiledInstructions = accountKeys.compileInstructions(args.instructions);
1043
+ return new MessageV0({
1044
+ header,
1045
+ staticAccountKeys,
1046
+ recentBlockhash: args.recentBlockhash,
1047
+ compiledInstructions,
1048
+ addressTableLookups
1049
+ });
1050
+ }
1051
+
730
1052
  serialize() {
731
1053
  const encodedStaticAccountKeysLength = Array();
732
1054
  encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
@@ -1621,6 +1943,114 @@ class Transaction {
1621
1943
 
1622
1944
  }
1623
1945
 
1946
+ class TransactionMessage {
1947
+ constructor(args) {
1948
+ this.accountKeys = void 0;
1949
+ this.instructions = void 0;
1950
+ this.recentBlockhash = void 0;
1951
+ this.accountKeys = args.accountKeys;
1952
+ this.instructions = args.instructions;
1953
+ this.recentBlockhash = args.recentBlockhash;
1954
+ }
1955
+
1956
+ static decompile(message, args) {
1957
+ const {
1958
+ header,
1959
+ compiledInstructions,
1960
+ recentBlockhash
1961
+ } = message;
1962
+ const {
1963
+ numRequiredSignatures,
1964
+ numReadonlySignedAccounts,
1965
+ numReadonlyUnsignedAccounts
1966
+ } = header;
1967
+ const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
1968
+ assert(numWritableSignedAccounts > 0, 'Message header is invalid');
1969
+ const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
1970
+ assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
1971
+ const accountKeys = message.getAccountKeys(args);
1972
+ const instructions = [];
1973
+
1974
+ for (const compiledIx of compiledInstructions) {
1975
+ const keys = [];
1976
+
1977
+ for (const keyIndex of compiledIx.accountKeyIndexes) {
1978
+ const pubkey = accountKeys.get(keyIndex);
1979
+
1980
+ if (pubkey === undefined) {
1981
+ throw new Error(`Failed to find key for account key index ${keyIndex}`);
1982
+ }
1983
+
1984
+ const isSigner = keyIndex < numRequiredSignatures;
1985
+ let isWritable;
1986
+
1987
+ if (isSigner) {
1988
+ isWritable = keyIndex < numWritableSignedAccounts;
1989
+ } else if (keyIndex < accountKeys.staticAccountKeys.length) {
1990
+ isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
1991
+ } else {
1992
+ isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
1993
+ accountKeys.accountKeysFromLookups.writable.length;
1994
+ }
1995
+
1996
+ keys.push({
1997
+ pubkey,
1998
+ isSigner: keyIndex < header.numRequiredSignatures,
1999
+ isWritable
2000
+ });
2001
+ }
2002
+
2003
+ const programId = accountKeys.get(compiledIx.programIdIndex);
2004
+
2005
+ if (programId === undefined) {
2006
+ throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
2007
+ }
2008
+
2009
+ instructions.push(new TransactionInstruction({
2010
+ programId,
2011
+ data: toBuffer(compiledIx.data),
2012
+ keys
2013
+ }));
2014
+ }
2015
+
2016
+ return new TransactionMessage({
2017
+ accountKeys,
2018
+ instructions,
2019
+ recentBlockhash
2020
+ });
2021
+ }
2022
+
2023
+ compileToLegacyMessage() {
2024
+ const payerKey = this.accountKeys.get(0);
2025
+
2026
+ if (payerKey === undefined) {
2027
+ throw new Error('Failed to compile message because no account keys were found');
2028
+ }
2029
+
2030
+ return Message.compile({
2031
+ payerKey,
2032
+ recentBlockhash: this.recentBlockhash,
2033
+ instructions: this.instructions
2034
+ });
2035
+ }
2036
+
2037
+ compileToV0Message(addressLookupTableAccounts) {
2038
+ const payerKey = this.accountKeys.get(0);
2039
+
2040
+ if (payerKey === undefined) {
2041
+ throw new Error('Failed to compile message because no account keys were found');
2042
+ }
2043
+
2044
+ return MessageV0.compile({
2045
+ payerKey,
2046
+ recentBlockhash: this.recentBlockhash,
2047
+ instructions: this.instructions,
2048
+ addressLookupTableAccounts
2049
+ });
2050
+ }
2051
+
2052
+ }
2053
+
1624
2054
  /**
1625
2055
  * Versioned transaction class
1626
2056
  */
@@ -5984,10 +6414,44 @@ class Connection {
5984
6414
  }
5985
6415
  /**
5986
6416
  * Simulate a transaction
6417
+ *
6418
+ * @deprecated Instead, call {@link simulateTransaction} with {@link
6419
+ * VersionedTransaction} and {@link SimulateTransactionConfig} parameters
5987
6420
  */
5988
6421
 
5989
6422
 
5990
- async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
6423
+ /**
6424
+ * Simulate a transaction
6425
+ */
6426
+ // eslint-disable-next-line no-dupe-class-members
6427
+ async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
6428
+ if ('message' in transactionOrMessage) {
6429
+ const versionedTx = transactionOrMessage;
6430
+ const wireTransaction = versionedTx.serialize();
6431
+ const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
6432
+
6433
+ if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
6434
+ throw new Error('Invalid arguments');
6435
+ }
6436
+
6437
+ const config = configOrSigners || {};
6438
+ config.encoding = 'base64';
6439
+
6440
+ if (!('commitment' in config)) {
6441
+ config.commitment = this.commitment;
6442
+ }
6443
+
6444
+ const args = [encodedTransaction, config];
6445
+ const unsafeRes = await this._rpcRequest('simulateTransaction', args);
6446
+ const res = create(unsafeRes, SimulatedTransactionResponseStruct);
6447
+
6448
+ if ('error' in res) {
6449
+ throw new Error('failed to simulate transaction: ' + res.error.message);
6450
+ }
6451
+
6452
+ return res.result;
6453
+ }
6454
+
5991
6455
  let transaction;
5992
6456
 
5993
6457
  if (transactionOrMessage instanceof Transaction) {
@@ -6003,6 +6467,12 @@ class Connection {
6003
6467
  transaction._message = transaction._json = undefined;
6004
6468
  }
6005
6469
 
6470
+ if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
6471
+ throw new Error('Invalid arguments');
6472
+ }
6473
+
6474
+ const signers = configOrSigners;
6475
+
6006
6476
  if (transaction.nonceInfo && signers) {
6007
6477
  transaction.sign(...signers);
6008
6478
  } else {
@@ -6085,10 +6555,32 @@ class Connection {
6085
6555
  }
6086
6556
  /**
6087
6557
  * Sign and send a transaction
6558
+ *
6559
+ * @deprecated Instead, call {@link sendTransaction} with a {@link
6560
+ * VersionedTransaction}
6088
6561
  */
6089
6562
 
6090
6563
 
6091
- async sendTransaction(transaction, signers, options) {
6564
+ /**
6565
+ * Sign and send a transaction
6566
+ */
6567
+ // eslint-disable-next-line no-dupe-class-members
6568
+ async sendTransaction(transaction, signersOrOptions, options) {
6569
+ if ('message' in transaction) {
6570
+ if (signersOrOptions && Array.isArray(signersOrOptions)) {
6571
+ throw new Error('Invalid arguments');
6572
+ }
6573
+
6574
+ const wireTransaction = transaction.serialize();
6575
+ return await this.sendRawTransaction(wireTransaction, options);
6576
+ }
6577
+
6578
+ if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
6579
+ throw new Error('Invalid arguments');
6580
+ }
6581
+
6582
+ const signers = signersOrOptions;
6583
+
6092
6584
  if (transaction.nonceInfo) {
6093
6585
  transaction.sign(...signers);
6094
6586
  } else {
@@ -7615,7 +8107,7 @@ class Secp256k1Program {
7615
8107
  assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
7616
8108
 
7617
8109
  try {
7618
- return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8110
+ return Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
7619
8111
  } catch (error) {
7620
8112
  throw new Error(`Error constructing Ethereum address: ${error}`);
7621
8113
  }
@@ -7715,7 +8207,7 @@ class Secp256k1Program {
7715
8207
  /* isCompressed */
7716
8208
  ).slice(1); // throw away leading byte
7717
8209
 
7718
- const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
8210
+ const messageHash = Buffer.from(keccak_256(toBuffer(message)));
7719
8211
  const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
7720
8212
  return this.createInstructionWithPublicKey({
7721
8213
  publicKey,
@@ -8609,6 +9101,33 @@ class VoteInstruction {
8609
9101
  }
8610
9102
  };
8611
9103
  }
9104
+ /**
9105
+ * Decode an authorize instruction and retrieve the instruction params.
9106
+ */
9107
+
9108
+
9109
+ static decodeAuthorizeWithSeed(instruction) {
9110
+ this.checkProgramId(instruction.programId);
9111
+ this.checkKeyLength(instruction.keys, 3);
9112
+ const {
9113
+ voteAuthorizeWithSeedArgs: {
9114
+ currentAuthorityDerivedKeyOwnerPubkey,
9115
+ currentAuthorityDerivedKeySeed,
9116
+ newAuthorized,
9117
+ voteAuthorizationType
9118
+ }
9119
+ } = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
9120
+ return {
9121
+ currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
9122
+ currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
9123
+ currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
9124
+ newAuthorizedPubkey: new PublicKey(newAuthorized),
9125
+ voteAuthorizationType: {
9126
+ index: voteAuthorizationType
9127
+ },
9128
+ votePubkey: instruction.keys[0].pubkey
9129
+ };
9130
+ }
8612
9131
  /**
8613
9132
  * Decode a withdraw instruction and retrieve the instruction params.
8614
9133
  */
@@ -8665,6 +9184,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
8665
9184
  Withdraw: {
8666
9185
  index: 3,
8667
9186
  layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
9187
+ },
9188
+ AuthorizeWithSeed: {
9189
+ index: 10,
9190
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteAuthorizeWithSeedArgs()])
8668
9191
  }
8669
9192
  });
8670
9193
  /**
@@ -8793,6 +9316,49 @@ class VoteProgram {
8793
9316
  data
8794
9317
  });
8795
9318
  }
9319
+ /**
9320
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
9321
+ * where the current Voter or Withdrawer authority is a derived key.
9322
+ */
9323
+
9324
+
9325
+ static authorizeWithSeed(params) {
9326
+ const {
9327
+ currentAuthorityDerivedKeyBasePubkey,
9328
+ currentAuthorityDerivedKeyOwnerPubkey,
9329
+ currentAuthorityDerivedKeySeed,
9330
+ newAuthorizedPubkey,
9331
+ voteAuthorizationType,
9332
+ votePubkey
9333
+ } = params;
9334
+ const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
9335
+ const data = encodeData(type, {
9336
+ voteAuthorizeWithSeedArgs: {
9337
+ currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
9338
+ currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
9339
+ newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
9340
+ voteAuthorizationType: voteAuthorizationType.index
9341
+ }
9342
+ });
9343
+ const keys = [{
9344
+ pubkey: votePubkey,
9345
+ isSigner: false,
9346
+ isWritable: true
9347
+ }, {
9348
+ pubkey: SYSVAR_CLOCK_PUBKEY,
9349
+ isSigner: false,
9350
+ isWritable: false
9351
+ }, {
9352
+ pubkey: currentAuthorityDerivedKeyBasePubkey,
9353
+ isSigner: true,
9354
+ isWritable: false
9355
+ }];
9356
+ return new Transaction().add({
9357
+ keys,
9358
+ programId: this.programId,
9359
+ data
9360
+ });
9361
+ }
8796
9362
  /**
8797
9363
  * Generate a transaction to withdraw from a Vote account.
8798
9364
  */
@@ -9115,5 +9681,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
9115
9681
 
9116
9682
  const LAMPORTS_PER_SOL = 1000000000;
9117
9683
 
9118
- 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, 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 };
9684
+ 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 };
9119
9685
  //# sourceMappingURL=index.esm.js.map