@solana/web3.js 1.56.3 → 1.57.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 +225 -3
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +225 -4
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +225 -3
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2977 -2950
- package/lib/index.esm.js +225 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +225 -3
- 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 +225 -3
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- 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.esm.js
CHANGED
|
@@ -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,6 +421,71 @@ 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
|
*/
|
|
@@ -739,6 +816,115 @@ function assert (condition, message) {
|
|
|
739
816
|
}
|
|
740
817
|
}
|
|
741
818
|
|
|
819
|
+
class CompiledKeys {
|
|
820
|
+
constructor(payer, keyMetaMap) {
|
|
821
|
+
this.payer = void 0;
|
|
822
|
+
this.keyMetaMap = void 0;
|
|
823
|
+
this.payer = payer;
|
|
824
|
+
this.keyMetaMap = keyMetaMap;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
static compile(instructions, payer) {
|
|
828
|
+
const keyMetaMap = new Map();
|
|
829
|
+
|
|
830
|
+
const getOrInsertDefault = pubkey => {
|
|
831
|
+
const address = pubkey.toBase58();
|
|
832
|
+
let keyMeta = keyMetaMap.get(address);
|
|
833
|
+
|
|
834
|
+
if (keyMeta === undefined) {
|
|
835
|
+
keyMeta = {
|
|
836
|
+
isSigner: false,
|
|
837
|
+
isWritable: false,
|
|
838
|
+
isInvoked: false
|
|
839
|
+
};
|
|
840
|
+
keyMetaMap.set(address, keyMeta);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
return keyMeta;
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
const payerKeyMeta = getOrInsertDefault(payer);
|
|
847
|
+
payerKeyMeta.isSigner = true;
|
|
848
|
+
payerKeyMeta.isWritable = true;
|
|
849
|
+
|
|
850
|
+
for (const ix of instructions) {
|
|
851
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
852
|
+
|
|
853
|
+
for (const accountMeta of ix.keys) {
|
|
854
|
+
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
855
|
+
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
856
|
+
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
getMessageComponents() {
|
|
864
|
+
const mapEntries = [...this.keyMetaMap.entries()];
|
|
865
|
+
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
866
|
+
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
867
|
+
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
868
|
+
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
869
|
+
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
870
|
+
const header = {
|
|
871
|
+
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
872
|
+
numReadonlySignedAccounts: readonlySigners.length,
|
|
873
|
+
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
874
|
+
}; // sanity checks
|
|
875
|
+
|
|
876
|
+
{
|
|
877
|
+
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
878
|
+
const [payerAddress] = writableSigners[0];
|
|
879
|
+
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
880
|
+
}
|
|
881
|
+
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))];
|
|
882
|
+
return [header, staticAccountKeys];
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
extractTableLookup(lookupTable) {
|
|
886
|
+
const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
|
|
887
|
+
const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
|
|
888
|
+
|
|
889
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
return [{
|
|
894
|
+
accountKey: lookupTable.key,
|
|
895
|
+
writableIndexes,
|
|
896
|
+
readonlyIndexes
|
|
897
|
+
}, {
|
|
898
|
+
writable: drainedWritableKeys,
|
|
899
|
+
readonly: drainedReadonlyKeys
|
|
900
|
+
}];
|
|
901
|
+
}
|
|
902
|
+
/** @internal */
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
906
|
+
const lookupTableIndexes = new Array();
|
|
907
|
+
const drainedKeys = new Array();
|
|
908
|
+
|
|
909
|
+
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
910
|
+
if (keyMetaFilter(keyMeta)) {
|
|
911
|
+
const key = new PublicKey(address);
|
|
912
|
+
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
913
|
+
|
|
914
|
+
if (lookupTableIndex >= 0) {
|
|
915
|
+
assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
916
|
+
lookupTableIndexes.push(lookupTableIndex);
|
|
917
|
+
drainedKeys.push(key);
|
|
918
|
+
this.keyMetaMap.delete(address);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
return [lookupTableIndexes, drainedKeys];
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
}
|
|
927
|
+
|
|
742
928
|
/**
|
|
743
929
|
* Message constructor arguments
|
|
744
930
|
*/
|
|
@@ -761,6 +947,41 @@ class MessageV0 {
|
|
|
761
947
|
return 0;
|
|
762
948
|
}
|
|
763
949
|
|
|
950
|
+
static compile(args) {
|
|
951
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
952
|
+
const addressTableLookups = new Array();
|
|
953
|
+
const accountKeysFromLookups = {
|
|
954
|
+
writable: new Array(),
|
|
955
|
+
readonly: new Array()
|
|
956
|
+
};
|
|
957
|
+
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
|
958
|
+
|
|
959
|
+
for (const lookupTable of lookupTableAccounts) {
|
|
960
|
+
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
|
961
|
+
|
|
962
|
+
if (extractResult !== undefined) {
|
|
963
|
+
const [addressTableLookup, {
|
|
964
|
+
writable,
|
|
965
|
+
readonly
|
|
966
|
+
}] = extractResult;
|
|
967
|
+
addressTableLookups.push(addressTableLookup);
|
|
968
|
+
accountKeysFromLookups.writable.push(...writable);
|
|
969
|
+
accountKeysFromLookups.readonly.push(...readonly);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
974
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
|
|
975
|
+
const compiledInstructions = accountKeys.compileInstructions(args.instructions);
|
|
976
|
+
return new MessageV0({
|
|
977
|
+
header,
|
|
978
|
+
staticAccountKeys,
|
|
979
|
+
recentBlockhash: args.recentBlockhash,
|
|
980
|
+
compiledInstructions,
|
|
981
|
+
addressTableLookups
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
|
|
764
985
|
serialize() {
|
|
765
986
|
const encodedStaticAccountKeysLength = Array();
|
|
766
987
|
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
@@ -4157,7 +4378,7 @@ const LogsNotificationResult = type({
|
|
|
4157
4378
|
|
|
4158
4379
|
/** @internal */
|
|
4159
4380
|
const COMMON_HTTP_HEADERS = {
|
|
4160
|
-
'solana-client': `js/${(_process$env$npm_pack = "1.
|
|
4381
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.57.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4161
4382
|
};
|
|
4162
4383
|
/**
|
|
4163
4384
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9146,5 +9367,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9146
9367
|
|
|
9147
9368
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9148
9369
|
|
|
9149
|
-
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 };
|
|
9370
|
+
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 };
|
|
9150
9371
|
//# sourceMappingURL=index.esm.js.map
|