@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.native.js
CHANGED
|
@@ -143,12 +143,14 @@ const PUBLIC_KEY_LENGTH = 32;
|
|
|
143
143
|
|
|
144
144
|
function isPublicKeyData(value) {
|
|
145
145
|
return value._bn !== undefined;
|
|
146
|
-
}
|
|
146
|
+
} // local counter used by PublicKey.unique()
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
let uniquePublicKeyCounter = 1;
|
|
147
150
|
/**
|
|
148
151
|
* A public key
|
|
149
152
|
*/
|
|
150
153
|
|
|
151
|
-
|
|
152
154
|
class PublicKey extends Struct {
|
|
153
155
|
/** @internal */
|
|
154
156
|
|
|
@@ -181,6 +183,16 @@ class PublicKey extends Struct {
|
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Returns a unique PublicKey for tests and benchmarks using acounter
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
static unique() {
|
|
192
|
+
const key = new PublicKey(uniquePublicKeyCounter);
|
|
193
|
+
uniquePublicKeyCounter += 1;
|
|
194
|
+
return new PublicKey(key.toBuffer());
|
|
195
|
+
}
|
|
184
196
|
/**
|
|
185
197
|
* Default public key value. (All zeros)
|
|
186
198
|
*/
|
|
@@ -437,6 +449,71 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
|
437
449
|
value: 'TransactionExpiredTimeoutError'
|
|
438
450
|
});
|
|
439
451
|
|
|
452
|
+
class MessageAccountKeys {
|
|
453
|
+
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
454
|
+
this.staticAccountKeys = void 0;
|
|
455
|
+
this.accountKeysFromLookups = void 0;
|
|
456
|
+
this.staticAccountKeys = staticAccountKeys;
|
|
457
|
+
this.accountKeysFromLookups = accountKeysFromLookups;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
keySegments() {
|
|
461
|
+
const keySegments = [this.staticAccountKeys];
|
|
462
|
+
|
|
463
|
+
if (this.accountKeysFromLookups) {
|
|
464
|
+
keySegments.push(this.accountKeysFromLookups.writable);
|
|
465
|
+
keySegments.push(this.accountKeysFromLookups.readonly);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return keySegments;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
get(index) {
|
|
472
|
+
for (const keySegment of this.keySegments()) {
|
|
473
|
+
if (index < keySegment.length) {
|
|
474
|
+
return keySegment[index];
|
|
475
|
+
} else {
|
|
476
|
+
index -= keySegment.length;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
get length() {
|
|
484
|
+
return this.keySegments().flat().length;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
compileInstructions(instructions) {
|
|
488
|
+
// Bail early if any account indexes would overflow a u8
|
|
489
|
+
const U8_MAX = 255;
|
|
490
|
+
|
|
491
|
+
if (this.length > U8_MAX + 1) {
|
|
492
|
+
throw new Error('Account index overflow encountered during compilation');
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const keyIndexMap = new Map();
|
|
496
|
+
this.keySegments().flat().forEach((key, index) => {
|
|
497
|
+
keyIndexMap.set(key.toBase58(), index);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
const findKeyIndex = key => {
|
|
501
|
+
const keyIndex = keyIndexMap.get(key.toBase58());
|
|
502
|
+
if (keyIndex === undefined) throw new Error('Encountered an unknown instruction account key during compilation');
|
|
503
|
+
return keyIndex;
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
return instructions.map(instruction => {
|
|
507
|
+
return {
|
|
508
|
+
programIdIndex: findKeyIndex(instruction.programId),
|
|
509
|
+
accountKeyIndexes: instruction.keys.map(meta => findKeyIndex(meta.pubkey)),
|
|
510
|
+
data: instruction.data
|
|
511
|
+
};
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
}
|
|
516
|
+
|
|
440
517
|
/**
|
|
441
518
|
* Layout for a public key
|
|
442
519
|
*/
|
|
@@ -767,6 +844,115 @@ function assert (condition, message) {
|
|
|
767
844
|
}
|
|
768
845
|
}
|
|
769
846
|
|
|
847
|
+
class CompiledKeys {
|
|
848
|
+
constructor(payer, keyMetaMap) {
|
|
849
|
+
this.payer = void 0;
|
|
850
|
+
this.keyMetaMap = void 0;
|
|
851
|
+
this.payer = payer;
|
|
852
|
+
this.keyMetaMap = keyMetaMap;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
static compile(instructions, payer) {
|
|
856
|
+
const keyMetaMap = new Map();
|
|
857
|
+
|
|
858
|
+
const getOrInsertDefault = pubkey => {
|
|
859
|
+
const address = pubkey.toBase58();
|
|
860
|
+
let keyMeta = keyMetaMap.get(address);
|
|
861
|
+
|
|
862
|
+
if (keyMeta === undefined) {
|
|
863
|
+
keyMeta = {
|
|
864
|
+
isSigner: false,
|
|
865
|
+
isWritable: false,
|
|
866
|
+
isInvoked: false
|
|
867
|
+
};
|
|
868
|
+
keyMetaMap.set(address, keyMeta);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
return keyMeta;
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
const payerKeyMeta = getOrInsertDefault(payer);
|
|
875
|
+
payerKeyMeta.isSigner = true;
|
|
876
|
+
payerKeyMeta.isWritable = true;
|
|
877
|
+
|
|
878
|
+
for (const ix of instructions) {
|
|
879
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
880
|
+
|
|
881
|
+
for (const accountMeta of ix.keys) {
|
|
882
|
+
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
883
|
+
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
884
|
+
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
getMessageComponents() {
|
|
892
|
+
const mapEntries = [...this.keyMetaMap.entries()];
|
|
893
|
+
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
894
|
+
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
895
|
+
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
896
|
+
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
897
|
+
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
898
|
+
const header = {
|
|
899
|
+
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
900
|
+
numReadonlySignedAccounts: readonlySigners.length,
|
|
901
|
+
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
902
|
+
}; // sanity checks
|
|
903
|
+
|
|
904
|
+
{
|
|
905
|
+
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
906
|
+
const [payerAddress] = writableSigners[0];
|
|
907
|
+
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
908
|
+
}
|
|
909
|
+
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))];
|
|
910
|
+
return [header, staticAccountKeys];
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
extractTableLookup(lookupTable) {
|
|
914
|
+
const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
|
|
915
|
+
const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
|
|
916
|
+
|
|
917
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
return [{
|
|
922
|
+
accountKey: lookupTable.key,
|
|
923
|
+
writableIndexes,
|
|
924
|
+
readonlyIndexes
|
|
925
|
+
}, {
|
|
926
|
+
writable: drainedWritableKeys,
|
|
927
|
+
readonly: drainedReadonlyKeys
|
|
928
|
+
}];
|
|
929
|
+
}
|
|
930
|
+
/** @internal */
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
934
|
+
const lookupTableIndexes = new Array();
|
|
935
|
+
const drainedKeys = new Array();
|
|
936
|
+
|
|
937
|
+
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
938
|
+
if (keyMetaFilter(keyMeta)) {
|
|
939
|
+
const key = new PublicKey(address);
|
|
940
|
+
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
941
|
+
|
|
942
|
+
if (lookupTableIndex >= 0) {
|
|
943
|
+
assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
944
|
+
lookupTableIndexes.push(lookupTableIndex);
|
|
945
|
+
drainedKeys.push(key);
|
|
946
|
+
this.keyMetaMap.delete(address);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
return [lookupTableIndexes, drainedKeys];
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
}
|
|
955
|
+
|
|
770
956
|
/**
|
|
771
957
|
* Message constructor arguments
|
|
772
958
|
*/
|
|
@@ -789,6 +975,41 @@ class MessageV0 {
|
|
|
789
975
|
return 0;
|
|
790
976
|
}
|
|
791
977
|
|
|
978
|
+
static compile(args) {
|
|
979
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
980
|
+
const addressTableLookups = new Array();
|
|
981
|
+
const accountKeysFromLookups = {
|
|
982
|
+
writable: new Array(),
|
|
983
|
+
readonly: new Array()
|
|
984
|
+
};
|
|
985
|
+
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
|
986
|
+
|
|
987
|
+
for (const lookupTable of lookupTableAccounts) {
|
|
988
|
+
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
|
989
|
+
|
|
990
|
+
if (extractResult !== undefined) {
|
|
991
|
+
const [addressTableLookup, {
|
|
992
|
+
writable,
|
|
993
|
+
readonly
|
|
994
|
+
}] = extractResult;
|
|
995
|
+
addressTableLookups.push(addressTableLookup);
|
|
996
|
+
accountKeysFromLookups.writable.push(...writable);
|
|
997
|
+
accountKeysFromLookups.readonly.push(...readonly);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
1002
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
|
|
1003
|
+
const compiledInstructions = accountKeys.compileInstructions(args.instructions);
|
|
1004
|
+
return new MessageV0({
|
|
1005
|
+
header,
|
|
1006
|
+
staticAccountKeys,
|
|
1007
|
+
recentBlockhash: args.recentBlockhash,
|
|
1008
|
+
compiledInstructions,
|
|
1009
|
+
addressTableLookups
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
|
|
792
1013
|
serialize() {
|
|
793
1014
|
const encodedStaticAccountKeysLength = Array();
|
|
794
1015
|
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
@@ -4125,7 +4346,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4125
4346
|
|
|
4126
4347
|
/** @internal */
|
|
4127
4348
|
const COMMON_HTTP_HEADERS = {
|
|
4128
|
-
'solana-client': `js/${(_process$env$npm_pack = "1.
|
|
4349
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.57.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4129
4350
|
};
|
|
4130
4351
|
/**
|
|
4131
4352
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9138,6 +9359,7 @@ exports.Loader = Loader;
|
|
|
9138
9359
|
exports.Lockup = Lockup;
|
|
9139
9360
|
exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
|
|
9140
9361
|
exports.Message = Message;
|
|
9362
|
+
exports.MessageAccountKeys = MessageAccountKeys;
|
|
9141
9363
|
exports.MessageV0 = MessageV0;
|
|
9142
9364
|
exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
|
|
9143
9365
|
exports.NonceAccount = NonceAccount;
|