@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.iife.js CHANGED
@@ -8308,12 +8308,14 @@ var solanaWeb3 = (function (exports) {
8308
8308
 
8309
8309
  function isPublicKeyData(value) {
8310
8310
  return value._bn !== undefined;
8311
- }
8311
+ } // local counter used by PublicKey.unique()
8312
+
8313
+
8314
+ let uniquePublicKeyCounter = 1;
8312
8315
  /**
8313
8316
  * A public key
8314
8317
  */
8315
8318
 
8316
-
8317
8319
  class PublicKey extends Struct$1 {
8318
8320
  /** @internal */
8319
8321
 
@@ -8346,6 +8348,16 @@ var solanaWeb3 = (function (exports) {
8346
8348
  }
8347
8349
  }
8348
8350
  }
8351
+ /**
8352
+ * Returns a unique PublicKey for tests and benchmarks using acounter
8353
+ */
8354
+
8355
+
8356
+ static unique() {
8357
+ const key = new PublicKey(uniquePublicKeyCounter);
8358
+ uniquePublicKeyCounter += 1;
8359
+ return new PublicKey(key.toBuffer());
8360
+ }
8349
8361
  /**
8350
8362
  * Default public key value. (All zeros)
8351
8363
  */
@@ -10885,6 +10897,71 @@ var solanaWeb3 = (function (exports) {
10885
10897
  value: 'TransactionExpiredTimeoutError'
10886
10898
  });
10887
10899
 
10900
+ class MessageAccountKeys {
10901
+ constructor(staticAccountKeys, accountKeysFromLookups) {
10902
+ this.staticAccountKeys = void 0;
10903
+ this.accountKeysFromLookups = void 0;
10904
+ this.staticAccountKeys = staticAccountKeys;
10905
+ this.accountKeysFromLookups = accountKeysFromLookups;
10906
+ }
10907
+
10908
+ keySegments() {
10909
+ const keySegments = [this.staticAccountKeys];
10910
+
10911
+ if (this.accountKeysFromLookups) {
10912
+ keySegments.push(this.accountKeysFromLookups.writable);
10913
+ keySegments.push(this.accountKeysFromLookups.readonly);
10914
+ }
10915
+
10916
+ return keySegments;
10917
+ }
10918
+
10919
+ get(index) {
10920
+ for (const keySegment of this.keySegments()) {
10921
+ if (index < keySegment.length) {
10922
+ return keySegment[index];
10923
+ } else {
10924
+ index -= keySegment.length;
10925
+ }
10926
+ }
10927
+
10928
+ return;
10929
+ }
10930
+
10931
+ get length() {
10932
+ return this.keySegments().flat().length;
10933
+ }
10934
+
10935
+ compileInstructions(instructions) {
10936
+ // Bail early if any account indexes would overflow a u8
10937
+ const U8_MAX = 255;
10938
+
10939
+ if (this.length > U8_MAX + 1) {
10940
+ throw new Error('Account index overflow encountered during compilation');
10941
+ }
10942
+
10943
+ const keyIndexMap = new Map();
10944
+ this.keySegments().flat().forEach((key, index) => {
10945
+ keyIndexMap.set(key.toBase58(), index);
10946
+ });
10947
+
10948
+ const findKeyIndex = key => {
10949
+ const keyIndex = keyIndexMap.get(key.toBase58());
10950
+ if (keyIndex === undefined) throw new Error('Encountered an unknown instruction account key during compilation');
10951
+ return keyIndex;
10952
+ };
10953
+
10954
+ return instructions.map(instruction => {
10955
+ return {
10956
+ programIdIndex: findKeyIndex(instruction.programId),
10957
+ accountKeyIndexes: instruction.keys.map(meta => findKeyIndex(meta.pubkey)),
10958
+ data: instruction.data
10959
+ };
10960
+ });
10961
+ }
10962
+
10963
+ }
10964
+
10888
10965
  /**
10889
10966
  * Layout for a public key
10890
10967
  */
@@ -11215,6 +11292,115 @@ var solanaWeb3 = (function (exports) {
11215
11292
  }
11216
11293
  }
11217
11294
 
11295
+ class CompiledKeys {
11296
+ constructor(payer, keyMetaMap) {
11297
+ this.payer = void 0;
11298
+ this.keyMetaMap = void 0;
11299
+ this.payer = payer;
11300
+ this.keyMetaMap = keyMetaMap;
11301
+ }
11302
+
11303
+ static compile(instructions, payer) {
11304
+ const keyMetaMap = new Map();
11305
+
11306
+ const getOrInsertDefault = pubkey => {
11307
+ const address = pubkey.toBase58();
11308
+ let keyMeta = keyMetaMap.get(address);
11309
+
11310
+ if (keyMeta === undefined) {
11311
+ keyMeta = {
11312
+ isSigner: false,
11313
+ isWritable: false,
11314
+ isInvoked: false
11315
+ };
11316
+ keyMetaMap.set(address, keyMeta);
11317
+ }
11318
+
11319
+ return keyMeta;
11320
+ };
11321
+
11322
+ const payerKeyMeta = getOrInsertDefault(payer);
11323
+ payerKeyMeta.isSigner = true;
11324
+ payerKeyMeta.isWritable = true;
11325
+
11326
+ for (const ix of instructions) {
11327
+ getOrInsertDefault(ix.programId).isInvoked = true;
11328
+
11329
+ for (const accountMeta of ix.keys) {
11330
+ const keyMeta = getOrInsertDefault(accountMeta.pubkey);
11331
+ keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
11332
+ keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
11333
+ }
11334
+ }
11335
+
11336
+ return new CompiledKeys(payer, keyMetaMap);
11337
+ }
11338
+
11339
+ getMessageComponents() {
11340
+ const mapEntries = [...this.keyMetaMap.entries()];
11341
+ assert$1(mapEntries.length <= 256, 'Max static account keys length exceeded');
11342
+ const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
11343
+ const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
11344
+ const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
11345
+ const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
11346
+ const header = {
11347
+ numRequiredSignatures: writableSigners.length + readonlySigners.length,
11348
+ numReadonlySignedAccounts: readonlySigners.length,
11349
+ numReadonlyUnsignedAccounts: readonlyNonSigners.length
11350
+ }; // sanity checks
11351
+
11352
+ {
11353
+ assert$1(writableSigners.length > 0, 'Expected at least one writable signer key');
11354
+ const [payerAddress] = writableSigners[0];
11355
+ assert$1(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
11356
+ }
11357
+ 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))];
11358
+ return [header, staticAccountKeys];
11359
+ }
11360
+
11361
+ extractTableLookup(lookupTable) {
11362
+ const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
11363
+ const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
11364
+
11365
+ if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
11366
+ return;
11367
+ }
11368
+
11369
+ return [{
11370
+ accountKey: lookupTable.key,
11371
+ writableIndexes,
11372
+ readonlyIndexes
11373
+ }, {
11374
+ writable: drainedWritableKeys,
11375
+ readonly: drainedReadonlyKeys
11376
+ }];
11377
+ }
11378
+ /** @internal */
11379
+
11380
+
11381
+ drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
11382
+ const lookupTableIndexes = new Array();
11383
+ const drainedKeys = new Array();
11384
+
11385
+ for (const [address, keyMeta] of this.keyMetaMap.entries()) {
11386
+ if (keyMetaFilter(keyMeta)) {
11387
+ const key = new PublicKey(address);
11388
+ const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
11389
+
11390
+ if (lookupTableIndex >= 0) {
11391
+ assert$1(lookupTableIndex < 256, 'Max lookup table index exceeded');
11392
+ lookupTableIndexes.push(lookupTableIndex);
11393
+ drainedKeys.push(key);
11394
+ this.keyMetaMap.delete(address);
11395
+ }
11396
+ }
11397
+ }
11398
+
11399
+ return [lookupTableIndexes, drainedKeys];
11400
+ }
11401
+
11402
+ }
11403
+
11218
11404
  /**
11219
11405
  * Message constructor arguments
11220
11406
  */
@@ -11237,6 +11423,41 @@ var solanaWeb3 = (function (exports) {
11237
11423
  return 0;
11238
11424
  }
11239
11425
 
11426
+ static compile(args) {
11427
+ const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
11428
+ const addressTableLookups = new Array();
11429
+ const accountKeysFromLookups = {
11430
+ writable: new Array(),
11431
+ readonly: new Array()
11432
+ };
11433
+ const lookupTableAccounts = args.addressLookupTableAccounts || [];
11434
+
11435
+ for (const lookupTable of lookupTableAccounts) {
11436
+ const extractResult = compiledKeys.extractTableLookup(lookupTable);
11437
+
11438
+ if (extractResult !== undefined) {
11439
+ const [addressTableLookup, {
11440
+ writable,
11441
+ readonly
11442
+ }] = extractResult;
11443
+ addressTableLookups.push(addressTableLookup);
11444
+ accountKeysFromLookups.writable.push(...writable);
11445
+ accountKeysFromLookups.readonly.push(...readonly);
11446
+ }
11447
+ }
11448
+
11449
+ const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
11450
+ const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
11451
+ const compiledInstructions = accountKeys.compileInstructions(args.instructions);
11452
+ return new MessageV0({
11453
+ header,
11454
+ staticAccountKeys,
11455
+ recentBlockhash: args.recentBlockhash,
11456
+ compiledInstructions,
11457
+ addressTableLookups
11458
+ });
11459
+ }
11460
+
11240
11461
  serialize() {
11241
11462
  const encodedStaticAccountKeysLength = Array();
11242
11463
  encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
@@ -17738,7 +17959,7 @@ var solanaWeb3 = (function (exports) {
17738
17959
 
17739
17960
  /** @internal */
17740
17961
  const COMMON_HTTP_HEADERS = {
17741
- 'solana-client': `js/${(_process$env$npm_pack = "1.56.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
17962
+ 'solana-client': `js/${(_process$env$npm_pack = "1.57.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
17742
17963
  };
17743
17964
  /**
17744
17965
  * A connection to a fullnode JSON RPC endpoint
@@ -24423,6 +24644,7 @@ var solanaWeb3 = (function (exports) {
24423
24644
  exports.Lockup = Lockup;
24424
24645
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
24425
24646
  exports.Message = Message;
24647
+ exports.MessageAccountKeys = MessageAccountKeys;
24426
24648
  exports.MessageV0 = MessageV0;
24427
24649
  exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
24428
24650
  exports.NonceAccount = NonceAccount;