@solana/web3.js 1.56.0 → 1.57.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.browser.cjs.js +228 -4
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +228 -5
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +228 -4
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2970 -2939
- package/lib/index.esm.js +228 -5
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +228 -4
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +228 -4
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/connection.ts +6 -0
- package/src/message/account-keys.ts +79 -0
- package/src/message/compiled-keys.ts +165 -0
- package/src/message/index.ts +2 -0
- package/src/message/v0.ts +47 -0
- package/src/publickey.ts +12 -0
package/lib/index.browser.esm.js
CHANGED
|
@@ -112,12 +112,14 @@ const PUBLIC_KEY_LENGTH = 32;
|
|
|
112
112
|
|
|
113
113
|
function isPublicKeyData(value) {
|
|
114
114
|
return value._bn !== undefined;
|
|
115
|
-
}
|
|
115
|
+
} // local counter used by PublicKey.unique()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
let uniquePublicKeyCounter = 1;
|
|
116
119
|
/**
|
|
117
120
|
* A public key
|
|
118
121
|
*/
|
|
119
122
|
|
|
120
|
-
|
|
121
123
|
class PublicKey extends Struct {
|
|
122
124
|
/** @internal */
|
|
123
125
|
|
|
@@ -150,6 +152,16 @@ class PublicKey extends Struct {
|
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Returns a unique PublicKey for tests and benchmarks using acounter
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
static unique() {
|
|
161
|
+
const key = new PublicKey(uniquePublicKeyCounter);
|
|
162
|
+
uniquePublicKeyCounter += 1;
|
|
163
|
+
return new PublicKey(key.toBuffer());
|
|
164
|
+
}
|
|
153
165
|
/**
|
|
154
166
|
* Default public key value. (All zeros)
|
|
155
167
|
*/
|
|
@@ -406,6 +418,71 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
|
406
418
|
value: 'TransactionExpiredTimeoutError'
|
|
407
419
|
});
|
|
408
420
|
|
|
421
|
+
class MessageAccountKeys {
|
|
422
|
+
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
423
|
+
this.staticAccountKeys = void 0;
|
|
424
|
+
this.accountKeysFromLookups = void 0;
|
|
425
|
+
this.staticAccountKeys = staticAccountKeys;
|
|
426
|
+
this.accountKeysFromLookups = accountKeysFromLookups;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
keySegments() {
|
|
430
|
+
const keySegments = [this.staticAccountKeys];
|
|
431
|
+
|
|
432
|
+
if (this.accountKeysFromLookups) {
|
|
433
|
+
keySegments.push(this.accountKeysFromLookups.writable);
|
|
434
|
+
keySegments.push(this.accountKeysFromLookups.readonly);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return keySegments;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
get(index) {
|
|
441
|
+
for (const keySegment of this.keySegments()) {
|
|
442
|
+
if (index < keySegment.length) {
|
|
443
|
+
return keySegment[index];
|
|
444
|
+
} else {
|
|
445
|
+
index -= keySegment.length;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
get length() {
|
|
453
|
+
return this.keySegments().flat().length;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
compileInstructions(instructions) {
|
|
457
|
+
// Bail early if any account indexes would overflow a u8
|
|
458
|
+
const U8_MAX = 255;
|
|
459
|
+
|
|
460
|
+
if (this.length > U8_MAX + 1) {
|
|
461
|
+
throw new Error('Account index overflow encountered during compilation');
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const keyIndexMap = new Map();
|
|
465
|
+
this.keySegments().flat().forEach((key, index) => {
|
|
466
|
+
keyIndexMap.set(key.toBase58(), index);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
const findKeyIndex = key => {
|
|
470
|
+
const keyIndex = keyIndexMap.get(key.toBase58());
|
|
471
|
+
if (keyIndex === undefined) throw new Error('Encountered an unknown instruction account key during compilation');
|
|
472
|
+
return keyIndex;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
return instructions.map(instruction => {
|
|
476
|
+
return {
|
|
477
|
+
programIdIndex: findKeyIndex(instruction.programId),
|
|
478
|
+
accountKeyIndexes: instruction.keys.map(meta => findKeyIndex(meta.pubkey)),
|
|
479
|
+
data: instruction.data
|
|
480
|
+
};
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
}
|
|
485
|
+
|
|
409
486
|
/**
|
|
410
487
|
* Layout for a public key
|
|
411
488
|
*/
|
|
@@ -702,6 +779,115 @@ function assert (condition, message) {
|
|
|
702
779
|
}
|
|
703
780
|
}
|
|
704
781
|
|
|
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;
|
|
788
|
+
}
|
|
789
|
+
|
|
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;
|
|
812
|
+
|
|
813
|
+
for (const ix of instructions) {
|
|
814
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
815
|
+
|
|
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
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
824
|
+
}
|
|
825
|
+
|
|
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
|
+
}
|
|
847
|
+
|
|
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
|
|
851
|
+
|
|
852
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
return [{
|
|
857
|
+
accountKey: lookupTable.key,
|
|
858
|
+
writableIndexes,
|
|
859
|
+
readonlyIndexes
|
|
860
|
+
}, {
|
|
861
|
+
writable: drainedWritableKeys,
|
|
862
|
+
readonly: drainedReadonlyKeys
|
|
863
|
+
}];
|
|
864
|
+
}
|
|
865
|
+
/** @internal */
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
869
|
+
const lookupTableIndexes = new Array();
|
|
870
|
+
const drainedKeys = new Array();
|
|
871
|
+
|
|
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));
|
|
876
|
+
|
|
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);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
return [lookupTableIndexes, drainedKeys];
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
}
|
|
890
|
+
|
|
705
891
|
/**
|
|
706
892
|
* Message constructor arguments
|
|
707
893
|
*/
|
|
@@ -724,6 +910,41 @@ class MessageV0 {
|
|
|
724
910
|
return 0;
|
|
725
911
|
}
|
|
726
912
|
|
|
913
|
+
static compile(args) {
|
|
914
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
915
|
+
const addressTableLookups = new Array();
|
|
916
|
+
const accountKeysFromLookups = {
|
|
917
|
+
writable: new Array(),
|
|
918
|
+
readonly: new Array()
|
|
919
|
+
};
|
|
920
|
+
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
|
921
|
+
|
|
922
|
+
for (const lookupTable of lookupTableAccounts) {
|
|
923
|
+
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
|
924
|
+
|
|
925
|
+
if (extractResult !== undefined) {
|
|
926
|
+
const [addressTableLookup, {
|
|
927
|
+
writable,
|
|
928
|
+
readonly
|
|
929
|
+
}] = extractResult;
|
|
930
|
+
addressTableLookups.push(addressTableLookup);
|
|
931
|
+
accountKeysFromLookups.writable.push(...writable);
|
|
932
|
+
accountKeysFromLookups.readonly.push(...readonly);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
937
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
|
|
938
|
+
const compiledInstructions = accountKeys.compileInstructions(args.instructions);
|
|
939
|
+
return new MessageV0({
|
|
940
|
+
header,
|
|
941
|
+
staticAccountKeys,
|
|
942
|
+
recentBlockhash: args.recentBlockhash,
|
|
943
|
+
compiledInstructions,
|
|
944
|
+
addressTableLookups
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
|
|
727
948
|
serialize() {
|
|
728
949
|
const encodedStaticAccountKeysLength = Array();
|
|
729
950
|
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
@@ -3882,7 +4103,8 @@ const ConfirmedTransactionMetaResult = type({
|
|
|
3882
4103
|
logMessages: optional(nullable(array(string()))),
|
|
3883
4104
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3884
4105
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3885
|
-
loadedAddresses: optional(LoadedAddressesResult)
|
|
4106
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
4107
|
+
computeUnitsConsumed: optional(number())
|
|
3886
4108
|
});
|
|
3887
4109
|
/**
|
|
3888
4110
|
* @internal
|
|
@@ -3900,7 +4122,8 @@ const ParsedConfirmedTransactionMetaResult = type({
|
|
|
3900
4122
|
logMessages: optional(nullable(array(string()))),
|
|
3901
4123
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3902
4124
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3903
|
-
loadedAddresses: optional(LoadedAddressesResult)
|
|
4125
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
4126
|
+
computeUnitsConsumed: optional(number())
|
|
3904
4127
|
});
|
|
3905
4128
|
const TransactionVersionStruct = union([literal(0), literal('legacy')]);
|
|
3906
4129
|
/**
|
|
@@ -9050,5 +9273,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9050
9273
|
|
|
9051
9274
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9052
9275
|
|
|
9053
|
-
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 };
|
|
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 };
|
|
9054
9277
|
//# sourceMappingURL=index.browser.esm.js.map
|