@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.
- package/lib/index.browser.cjs.js +460 -121
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +460 -121
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +460 -121
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +105 -1
- package/lib/index.esm.js +460 -121
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +726 -831
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +5 -13
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +460 -121
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -2
- package/src/connection.ts +106 -2
- package/src/layout.ts +22 -0
- package/src/message/legacy.ts +34 -2
- package/src/message/v0.ts +90 -0
- package/src/programs/secp256k1.ts +5 -7
- package/src/programs/vote.ts +109 -2
- package/src/transaction/index.ts +1 -0
- package/src/transaction/message.ts +138 -0
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
|
|
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
|
|
|
@@ -489,7 +489,6 @@ class MessageAccountKeys {
|
|
|
489
489
|
/**
|
|
490
490
|
* Layout for a public key
|
|
491
491
|
*/
|
|
492
|
-
|
|
493
492
|
const publicKey = (property = 'publicKey') => {
|
|
494
493
|
return BufferLayout.blob(32, property);
|
|
495
494
|
};
|
|
@@ -553,6 +552,13 @@ const lockup = (property = 'lockup') => {
|
|
|
553
552
|
const voteInit = (property = 'voteInit') => {
|
|
554
553
|
return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
|
|
555
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
|
+
};
|
|
556
562
|
function getAlloc(type, fields) {
|
|
557
563
|
const getItemAlloc = item => {
|
|
558
564
|
if (item.span >= 0) {
|
|
@@ -565,6 +571,11 @@ function getAlloc(type, fields) {
|
|
|
565
571
|
if (Array.isArray(field)) {
|
|
566
572
|
return field.length * getItemAlloc(item.elementLayout);
|
|
567
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]);
|
|
568
579
|
} // Couldn't determine allocated size of layout
|
|
569
580
|
|
|
570
581
|
|
|
@@ -611,6 +622,129 @@ function encodeLength(bytes, len) {
|
|
|
611
622
|
}
|
|
612
623
|
}
|
|
613
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
|
+
|
|
614
748
|
/**
|
|
615
749
|
* List of instructions to be processed atomically
|
|
616
750
|
*/
|
|
@@ -648,6 +782,27 @@ class Message {
|
|
|
648
782
|
return [];
|
|
649
783
|
}
|
|
650
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
|
+
|
|
651
806
|
isAccountSigner(index) {
|
|
652
807
|
return index < this.header.numRequiredSignatures;
|
|
653
808
|
}
|
|
@@ -737,7 +892,7 @@ class Message {
|
|
|
737
892
|
for (let i = 0; i < accountCount; i++) {
|
|
738
893
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
739
894
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
740
|
-
accountKeys.push(
|
|
895
|
+
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
741
896
|
}
|
|
742
897
|
|
|
743
898
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -776,141 +931,87 @@ class Message {
|
|
|
776
931
|
|
|
777
932
|
}
|
|
778
933
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
}
|
|
783
|
-
}
|
|
934
|
+
/**
|
|
935
|
+
* Message constructor arguments
|
|
936
|
+
*/
|
|
784
937
|
|
|
785
|
-
class
|
|
786
|
-
constructor(
|
|
787
|
-
this.
|
|
788
|
-
this.
|
|
789
|
-
this.
|
|
790
|
-
this.
|
|
938
|
+
class MessageV0 {
|
|
939
|
+
constructor(args) {
|
|
940
|
+
this.header = void 0;
|
|
941
|
+
this.staticAccountKeys = void 0;
|
|
942
|
+
this.recentBlockhash = void 0;
|
|
943
|
+
this.compiledInstructions = void 0;
|
|
944
|
+
this.addressTableLookups = void 0;
|
|
945
|
+
this.header = args.header;
|
|
946
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
947
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
948
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
949
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
791
950
|
}
|
|
792
951
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
const getOrInsertDefault = pubkey => {
|
|
797
|
-
const address = pubkey.toBase58();
|
|
798
|
-
let keyMeta = keyMetaMap.get(address);
|
|
799
|
-
|
|
800
|
-
if (keyMeta === undefined) {
|
|
801
|
-
keyMeta = {
|
|
802
|
-
isSigner: false,
|
|
803
|
-
isWritable: false,
|
|
804
|
-
isInvoked: false
|
|
805
|
-
};
|
|
806
|
-
keyMetaMap.set(address, keyMeta);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
return keyMeta;
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
813
|
-
payerKeyMeta.isSigner = true;
|
|
814
|
-
payerKeyMeta.isWritable = true;
|
|
952
|
+
get version() {
|
|
953
|
+
return 0;
|
|
954
|
+
}
|
|
815
955
|
|
|
816
|
-
|
|
817
|
-
|
|
956
|
+
get numAccountKeysFromLookups() {
|
|
957
|
+
let count = 0;
|
|
818
958
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
822
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
823
|
-
}
|
|
959
|
+
for (const lookup of this.addressTableLookups) {
|
|
960
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
824
961
|
}
|
|
825
962
|
|
|
826
|
-
return
|
|
963
|
+
return count;
|
|
827
964
|
}
|
|
828
965
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
832
|
-
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
833
|
-
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
834
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
835
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
836
|
-
const header = {
|
|
837
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
838
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
839
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
840
|
-
}; // sanity checks
|
|
841
|
-
|
|
842
|
-
{
|
|
843
|
-
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
844
|
-
const [payerAddress] = writableSigners[0];
|
|
845
|
-
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
846
|
-
}
|
|
847
|
-
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))];
|
|
848
|
-
return [header, staticAccountKeys];
|
|
849
|
-
}
|
|
966
|
+
getAccountKeys(args) {
|
|
967
|
+
let accountKeysFromLookups;
|
|
850
968
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
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
|
+
}
|
|
854
973
|
|
|
855
|
-
|
|
856
|
-
|
|
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');
|
|
857
979
|
}
|
|
858
980
|
|
|
859
|
-
return
|
|
860
|
-
accountKey: lookupTable.key,
|
|
861
|
-
writableIndexes,
|
|
862
|
-
readonlyIndexes
|
|
863
|
-
}, {
|
|
864
|
-
writable: drainedWritableKeys,
|
|
865
|
-
readonly: drainedReadonlyKeys
|
|
866
|
-
}];
|
|
981
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
867
982
|
}
|
|
868
|
-
/** @internal */
|
|
869
983
|
|
|
984
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
985
|
+
const accountKeysFromLookups = {
|
|
986
|
+
writable: [],
|
|
987
|
+
readonly: []
|
|
988
|
+
};
|
|
870
989
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
const drainedKeys = new Array();
|
|
990
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
991
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
874
992
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
993
|
+
if (!tableAccount) {
|
|
994
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
995
|
+
}
|
|
879
996
|
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
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()}`);
|
|
885
1002
|
}
|
|
886
1003
|
}
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
return [lookupTableIndexes, drainedKeys];
|
|
890
|
-
}
|
|
891
1004
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
this.header = void 0;
|
|
901
|
-
this.staticAccountKeys = void 0;
|
|
902
|
-
this.recentBlockhash = void 0;
|
|
903
|
-
this.compiledInstructions = void 0;
|
|
904
|
-
this.addressTableLookups = void 0;
|
|
905
|
-
this.header = args.header;
|
|
906
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
907
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
908
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
909
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
910
|
-
}
|
|
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
|
+
}
|
|
911
1013
|
|
|
912
|
-
|
|
913
|
-
return 0;
|
|
1014
|
+
return accountKeysFromLookups;
|
|
914
1015
|
}
|
|
915
1016
|
|
|
916
1017
|
static compile(args) {
|
|
@@ -1842,6 +1943,108 @@ class Transaction {
|
|
|
1842
1943
|
|
|
1843
1944
|
}
|
|
1844
1945
|
|
|
1946
|
+
class TransactionMessage {
|
|
1947
|
+
constructor(args) {
|
|
1948
|
+
this.payerKey = void 0;
|
|
1949
|
+
this.instructions = void 0;
|
|
1950
|
+
this.recentBlockhash = void 0;
|
|
1951
|
+
this.payerKey = args.payerKey;
|
|
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 payerKey = accountKeys.get(0);
|
|
1973
|
+
|
|
1974
|
+
if (payerKey === undefined) {
|
|
1975
|
+
throw new Error('Failed to decompile message because no account keys were found');
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
const instructions = [];
|
|
1979
|
+
|
|
1980
|
+
for (const compiledIx of compiledInstructions) {
|
|
1981
|
+
const keys = [];
|
|
1982
|
+
|
|
1983
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
1984
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
1985
|
+
|
|
1986
|
+
if (pubkey === undefined) {
|
|
1987
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
1991
|
+
let isWritable;
|
|
1992
|
+
|
|
1993
|
+
if (isSigner) {
|
|
1994
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
1995
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
1996
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
1997
|
+
} else {
|
|
1998
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
1999
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
keys.push({
|
|
2003
|
+
pubkey,
|
|
2004
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
2005
|
+
isWritable
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
2010
|
+
|
|
2011
|
+
if (programId === undefined) {
|
|
2012
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
instructions.push(new TransactionInstruction({
|
|
2016
|
+
programId,
|
|
2017
|
+
data: toBuffer(compiledIx.data),
|
|
2018
|
+
keys
|
|
2019
|
+
}));
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
return new TransactionMessage({
|
|
2023
|
+
payerKey,
|
|
2024
|
+
instructions,
|
|
2025
|
+
recentBlockhash
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
compileToLegacyMessage() {
|
|
2030
|
+
return Message.compile({
|
|
2031
|
+
payerKey: this.payerKey,
|
|
2032
|
+
recentBlockhash: this.recentBlockhash,
|
|
2033
|
+
instructions: this.instructions
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2038
|
+
return MessageV0.compile({
|
|
2039
|
+
payerKey: this.payerKey,
|
|
2040
|
+
recentBlockhash: this.recentBlockhash,
|
|
2041
|
+
instructions: this.instructions,
|
|
2042
|
+
addressLookupTableAccounts
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
}
|
|
2047
|
+
|
|
1845
2048
|
/**
|
|
1846
2049
|
* Versioned transaction class
|
|
1847
2050
|
*/
|
|
@@ -6205,10 +6408,44 @@ class Connection {
|
|
|
6205
6408
|
}
|
|
6206
6409
|
/**
|
|
6207
6410
|
* Simulate a transaction
|
|
6411
|
+
*
|
|
6412
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6413
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
6208
6414
|
*/
|
|
6209
6415
|
|
|
6210
6416
|
|
|
6211
|
-
|
|
6417
|
+
/**
|
|
6418
|
+
* Simulate a transaction
|
|
6419
|
+
*/
|
|
6420
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6421
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6422
|
+
if ('message' in transactionOrMessage) {
|
|
6423
|
+
const versionedTx = transactionOrMessage;
|
|
6424
|
+
const wireTransaction = versionedTx.serialize();
|
|
6425
|
+
const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
|
|
6426
|
+
|
|
6427
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6428
|
+
throw new Error('Invalid arguments');
|
|
6429
|
+
}
|
|
6430
|
+
|
|
6431
|
+
const config = configOrSigners || {};
|
|
6432
|
+
config.encoding = 'base64';
|
|
6433
|
+
|
|
6434
|
+
if (!('commitment' in config)) {
|
|
6435
|
+
config.commitment = this.commitment;
|
|
6436
|
+
}
|
|
6437
|
+
|
|
6438
|
+
const args = [encodedTransaction, config];
|
|
6439
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6440
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6441
|
+
|
|
6442
|
+
if ('error' in res) {
|
|
6443
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6444
|
+
}
|
|
6445
|
+
|
|
6446
|
+
return res.result;
|
|
6447
|
+
}
|
|
6448
|
+
|
|
6212
6449
|
let transaction;
|
|
6213
6450
|
|
|
6214
6451
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -6224,6 +6461,12 @@ class Connection {
|
|
|
6224
6461
|
transaction._message = transaction._json = undefined;
|
|
6225
6462
|
}
|
|
6226
6463
|
|
|
6464
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6465
|
+
throw new Error('Invalid arguments');
|
|
6466
|
+
}
|
|
6467
|
+
|
|
6468
|
+
const signers = configOrSigners;
|
|
6469
|
+
|
|
6227
6470
|
if (transaction.nonceInfo && signers) {
|
|
6228
6471
|
transaction.sign(...signers);
|
|
6229
6472
|
} else {
|
|
@@ -6304,12 +6547,34 @@ class Connection {
|
|
|
6304
6547
|
|
|
6305
6548
|
return res.result;
|
|
6306
6549
|
}
|
|
6550
|
+
/**
|
|
6551
|
+
* Sign and send a transaction
|
|
6552
|
+
*
|
|
6553
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6554
|
+
* VersionedTransaction}
|
|
6555
|
+
*/
|
|
6556
|
+
|
|
6557
|
+
|
|
6307
6558
|
/**
|
|
6308
6559
|
* Sign and send a transaction
|
|
6309
6560
|
*/
|
|
6561
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6562
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6563
|
+
if ('message' in transaction) {
|
|
6564
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6565
|
+
throw new Error('Invalid arguments');
|
|
6566
|
+
}
|
|
6567
|
+
|
|
6568
|
+
const wireTransaction = transaction.serialize();
|
|
6569
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6570
|
+
}
|
|
6571
|
+
|
|
6572
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6573
|
+
throw new Error('Invalid arguments');
|
|
6574
|
+
}
|
|
6310
6575
|
|
|
6576
|
+
const signers = signersOrOptions;
|
|
6311
6577
|
|
|
6312
|
-
async sendTransaction(transaction, signers, options) {
|
|
6313
6578
|
if (transaction.nonceInfo) {
|
|
6314
6579
|
transaction.sign(...signers);
|
|
6315
6580
|
} else {
|
|
@@ -7836,7 +8101,7 @@ class Secp256k1Program {
|
|
|
7836
8101
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
7837
8102
|
|
|
7838
8103
|
try {
|
|
7839
|
-
return Buffer.from(
|
|
8104
|
+
return Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
7840
8105
|
} catch (error) {
|
|
7841
8106
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
7842
8107
|
}
|
|
@@ -7936,7 +8201,7 @@ class Secp256k1Program {
|
|
|
7936
8201
|
/* isCompressed */
|
|
7937
8202
|
).slice(1); // throw away leading byte
|
|
7938
8203
|
|
|
7939
|
-
const messageHash = Buffer.from(
|
|
8204
|
+
const messageHash = Buffer.from(keccak_256(toBuffer(message)));
|
|
7940
8205
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
7941
8206
|
return this.createInstructionWithPublicKey({
|
|
7942
8207
|
publicKey,
|
|
@@ -8830,6 +9095,33 @@ class VoteInstruction {
|
|
|
8830
9095
|
}
|
|
8831
9096
|
};
|
|
8832
9097
|
}
|
|
9098
|
+
/**
|
|
9099
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
9100
|
+
*/
|
|
9101
|
+
|
|
9102
|
+
|
|
9103
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
9104
|
+
this.checkProgramId(instruction.programId);
|
|
9105
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
9106
|
+
const {
|
|
9107
|
+
voteAuthorizeWithSeedArgs: {
|
|
9108
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9109
|
+
currentAuthorityDerivedKeySeed,
|
|
9110
|
+
newAuthorized,
|
|
9111
|
+
voteAuthorizationType
|
|
9112
|
+
}
|
|
9113
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
9114
|
+
return {
|
|
9115
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
9116
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
9117
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9118
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
9119
|
+
voteAuthorizationType: {
|
|
9120
|
+
index: voteAuthorizationType
|
|
9121
|
+
},
|
|
9122
|
+
votePubkey: instruction.keys[0].pubkey
|
|
9123
|
+
};
|
|
9124
|
+
}
|
|
8833
9125
|
/**
|
|
8834
9126
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
8835
9127
|
*/
|
|
@@ -8886,6 +9178,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
8886
9178
|
Withdraw: {
|
|
8887
9179
|
index: 3,
|
|
8888
9180
|
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
9181
|
+
},
|
|
9182
|
+
AuthorizeWithSeed: {
|
|
9183
|
+
index: 10,
|
|
9184
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
8889
9185
|
}
|
|
8890
9186
|
});
|
|
8891
9187
|
/**
|
|
@@ -9014,6 +9310,49 @@ class VoteProgram {
|
|
|
9014
9310
|
data
|
|
9015
9311
|
});
|
|
9016
9312
|
}
|
|
9313
|
+
/**
|
|
9314
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
9315
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
9316
|
+
*/
|
|
9317
|
+
|
|
9318
|
+
|
|
9319
|
+
static authorizeWithSeed(params) {
|
|
9320
|
+
const {
|
|
9321
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
9322
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9323
|
+
currentAuthorityDerivedKeySeed,
|
|
9324
|
+
newAuthorizedPubkey,
|
|
9325
|
+
voteAuthorizationType,
|
|
9326
|
+
votePubkey
|
|
9327
|
+
} = params;
|
|
9328
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
9329
|
+
const data = encodeData(type, {
|
|
9330
|
+
voteAuthorizeWithSeedArgs: {
|
|
9331
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
9332
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9333
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9334
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9335
|
+
}
|
|
9336
|
+
});
|
|
9337
|
+
const keys = [{
|
|
9338
|
+
pubkey: votePubkey,
|
|
9339
|
+
isSigner: false,
|
|
9340
|
+
isWritable: true
|
|
9341
|
+
}, {
|
|
9342
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9343
|
+
isSigner: false,
|
|
9344
|
+
isWritable: false
|
|
9345
|
+
}, {
|
|
9346
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
9347
|
+
isSigner: true,
|
|
9348
|
+
isWritable: false
|
|
9349
|
+
}];
|
|
9350
|
+
return new Transaction().add({
|
|
9351
|
+
keys,
|
|
9352
|
+
programId: this.programId,
|
|
9353
|
+
data
|
|
9354
|
+
});
|
|
9355
|
+
}
|
|
9017
9356
|
/**
|
|
9018
9357
|
* Generate a transaction to withdraw from a Vote account.
|
|
9019
9358
|
*/
|
|
@@ -9336,5 +9675,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9336
9675
|
|
|
9337
9676
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9338
9677
|
|
|
9339
|
-
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 };
|
|
9678
|
+
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 };
|
|
9340
9679
|
//# sourceMappingURL=index.esm.js.map
|