@solana/web3.js 1.53.0 → 1.55.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.
Files changed (39) hide show
  1. package/lib/index.browser.cjs.js +459 -1825
  2. package/lib/index.browser.cjs.js.map +1 -1
  3. package/lib/index.browser.esm.js +455 -1826
  4. package/lib/index.browser.esm.js.map +1 -1
  5. package/lib/index.cjs.js +462 -1847
  6. package/lib/index.cjs.js.map +1 -1
  7. package/lib/index.d.ts +114 -12
  8. package/lib/index.esm.js +458 -1848
  9. package/lib/index.esm.js.map +1 -1
  10. package/lib/index.iife.js +19272 -25771
  11. package/lib/index.iife.js.map +1 -1
  12. package/lib/index.iife.min.js +8 -5
  13. package/lib/index.iife.min.js.map +1 -1
  14. package/lib/index.native.js +459 -1824
  15. package/lib/index.native.js.map +1 -1
  16. package/package.json +5 -7
  17. package/src/account.ts +18 -9
  18. package/src/connection.ts +11 -9
  19. package/src/keypair.ts +19 -24
  20. package/src/layout.ts +7 -0
  21. package/src/message/index.ts +19 -6
  22. package/src/message/legacy.ts +58 -9
  23. package/src/message/v0.ts +324 -0
  24. package/src/message/versioned.ts +36 -0
  25. package/src/programs/ed25519.ts +2 -2
  26. package/src/programs/secp256k1.ts +6 -5
  27. package/src/programs/vote.ts +21 -0
  28. package/src/publickey.ts +14 -73
  29. package/src/transaction/constants.ts +2 -0
  30. package/src/transaction/index.ts +1 -0
  31. package/src/transaction/legacy.ts +3 -5
  32. package/src/transaction/versioned.ts +105 -0
  33. package/src/utils/ed25519.ts +46 -0
  34. package/src/utils/index.ts +1 -0
  35. package/src/utils/makeWebsocketUrl.ts +22 -16
  36. package/src/utils/secp256k1.ts +18 -0
  37. package/src/validator-info.ts +3 -5
  38. package/src/utils/__forks__/react-native/url-impl.ts +0 -2
  39. package/src/utils/url-impl.ts +0 -2
package/lib/index.d.ts CHANGED
@@ -19,6 +19,10 @@ declare module '@solana/web3.js' {
19
19
  * Maximum length of derived pubkey seed
20
20
  */
21
21
  export const MAX_SEED_LENGTH = 32;
22
+ /**
23
+ * Size of public key in bytes
24
+ */
25
+ export const PUBLIC_KEY_LENGTH = 32;
22
26
  /**
23
27
  * Value to be converted into public key
24
28
  */
@@ -137,7 +141,9 @@ declare module '@solana/web3.js' {
137
141
  */
138
142
  get publicKey(): PublicKey;
139
143
  /**
140
- * The **unencrypted** secret key for this account
144
+ * The **unencrypted** secret key for this account. The first 32 bytes
145
+ * is the private scalar and the last 32 bytes is the public key.
146
+ * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
141
147
  */
142
148
  get secretKey(): Buffer;
143
149
  }
@@ -214,17 +220,24 @@ declare module '@solana/web3.js' {
214
220
  }
215
221
 
216
222
  /**
217
- * Keypair signer interface
223
+ * A 64 byte secret key, the first 32 bytes of which is the
224
+ * private scalar and the last 32 bytes is the public key.
225
+ * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
218
226
  */
219
- interface Signer {
220
- publicKey: PublicKey;
221
- secretKey: Uint8Array;
222
- }
227
+ export type Ed25519SecretKey = Uint8Array;
223
228
  /**
224
229
  * Ed25519 Keypair
225
230
  */
226
231
  interface Ed25519Keypair {
227
232
  publicKey: Uint8Array;
233
+ secretKey: Ed25519SecretKey;
234
+ }
235
+
236
+ /**
237
+ * Keypair signer interface
238
+ */
239
+ interface Signer {
240
+ publicKey: PublicKey;
228
241
  secretKey: Uint8Array;
229
242
  }
230
243
  /**
@@ -285,6 +298,7 @@ declare module '@solana/web3.js' {
285
298
  * 8 bytes is the size of the fragment header
286
299
  */
287
300
  export const PACKET_DATA_SIZE: number;
301
+ export const VERSION_PREFIX_MASK = 127;
288
302
  export const SIGNATURE_LENGTH_IN_BYTES = 64;
289
303
 
290
304
  export class TransactionExpiredBlockheightExceededError extends Error {
@@ -296,6 +310,21 @@ declare module '@solana/web3.js' {
296
310
  constructor(signature: string, timeoutSeconds: number);
297
311
  }
298
312
 
313
+ /**
314
+ * An instruction to execute by a program
315
+ *
316
+ * @property {number} programIdIndex
317
+ * @property {number[]} accounts
318
+ * @property {string} data
319
+ */
320
+ export type CompiledInstruction = {
321
+ /** Index into the transaction keys array indicating the program account that executes this instruction */
322
+ programIdIndex: number;
323
+ /** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
324
+ accounts: number[];
325
+ /** The program input data encoded as base 58 */
326
+ data: string;
327
+ };
299
328
  /**
300
329
  * Message constructor arguments
301
330
  */
@@ -319,6 +348,10 @@ declare module '@solana/web3.js' {
319
348
  instructions: CompiledInstruction[];
320
349
  private indexToProgramIds;
321
350
  constructor(args: MessageArgs);
351
+ get version(): 'legacy';
352
+ get staticAccountKeys(): Array<PublicKey>;
353
+ get compiledInstructions(): Array<MessageCompiledInstruction>;
354
+ get addressTableLookups(): Array<MessageAddressTableLookup>;
322
355
  isAccountSigner(index: number): boolean;
323
356
  isAccountWritable(index: number): boolean;
324
357
  isProgramId(index: number): boolean;
@@ -331,6 +364,41 @@ declare module '@solana/web3.js' {
331
364
  static from(buffer: Buffer | Uint8Array | Array<number>): Message;
332
365
  }
333
366
 
367
+ /**
368
+ * Message constructor arguments
369
+ */
370
+ export type MessageV0Args = {
371
+ /** The message header, identifying signed and read-only `accountKeys` */
372
+ header: MessageHeader;
373
+ /** The static account keys used by this transaction */
374
+ staticAccountKeys: PublicKey[];
375
+ /** The hash of a recent ledger block */
376
+ recentBlockhash: Blockhash;
377
+ /** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
378
+ compiledInstructions: MessageCompiledInstruction[];
379
+ /** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
380
+ addressTableLookups: MessageAddressTableLookup[];
381
+ };
382
+ export class MessageV0 {
383
+ header: MessageHeader;
384
+ staticAccountKeys: Array<PublicKey>;
385
+ recentBlockhash: Blockhash;
386
+ compiledInstructions: Array<MessageCompiledInstruction>;
387
+ addressTableLookups: Array<MessageAddressTableLookup>;
388
+ constructor(args: MessageV0Args);
389
+ get version(): 0;
390
+ serialize(): Uint8Array;
391
+ private serializeInstructions;
392
+ private serializeAddressTableLookups;
393
+ static deserialize(serializedMessage: Uint8Array): MessageV0;
394
+ }
395
+
396
+ export type VersionedMessage = Message | MessageV0;
397
+ export const VersionedMessage: {
398
+ deserializeMessageVersion(serializedMessage: Uint8Array): 'legacy' | number;
399
+ deserialize: (serializedMessage: Uint8Array) => VersionedMessage;
400
+ };
401
+
334
402
  /**
335
403
  * The message header, identifying signed and read-only account
336
404
  */
@@ -345,20 +413,28 @@ declare module '@solana/web3.js' {
345
413
  /** The last `numReadonlySignedAccounts` of the unsigned keys are read-only accounts */
346
414
  numReadonlyUnsignedAccounts: number;
347
415
  };
416
+ /**
417
+ * An address table lookup used to load additional accounts
418
+ */
419
+ export type MessageAddressTableLookup = {
420
+ accountKey: PublicKey;
421
+ writableIndexes: Array<number>;
422
+ readonlyIndexes: Array<number>;
423
+ };
348
424
  /**
349
425
  * An instruction to execute by a program
350
426
  *
351
427
  * @property {number} programIdIndex
352
- * @property {number[]} accounts
353
- * @property {string} data
428
+ * @property {number[]} accountKeyIndexes
429
+ * @property {Uint8Array} data
354
430
  */
355
- export type CompiledInstruction = {
431
+ export type MessageCompiledInstruction = {
356
432
  /** Index into the transaction keys array indicating the program account that executes this instruction */
357
433
  programIdIndex: number;
358
434
  /** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
359
- accounts: number[];
360
- /** The program input data encoded as base 58 */
361
- data: string;
435
+ accountKeyIndexes: number[];
436
+ /** The program input data */
437
+ data: Uint8Array;
362
438
  };
363
439
 
364
440
  /**
@@ -578,6 +654,19 @@ declare module '@solana/web3.js' {
578
654
  static populate(message: Message, signatures?: Array<string>): Transaction;
579
655
  }
580
656
 
657
+ export type TransactionVersion = 'legacy' | 0;
658
+ /**
659
+ * Versioned transaction class
660
+ */
661
+ export class VersionedTransaction {
662
+ signatures: Array<Uint8Array>;
663
+ message: VersionedMessage;
664
+ constructor(message: VersionedMessage, signatures?: Array<Uint8Array>);
665
+ serialize(): Uint8Array;
666
+ static deserialize(serializedTransaction: Uint8Array): VersionedTransaction;
667
+ sign(signers: Array<Signer>): void;
668
+ }
669
+
581
670
  export type AddressLookupTableState = {
582
671
  deactivationSlot: bigint;
583
672
  lastExtendedSlot: number;
@@ -3595,6 +3684,19 @@ declare module '@solana/web3.js' {
3595
3684
  * Generate a transaction to withdraw from a Vote account.
3596
3685
  */
3597
3686
  static withdraw(params: WithdrawFromVoteAccountParams): Transaction;
3687
+ /**
3688
+ * Generate a transaction to withdraw safely from a Vote account.
3689
+ *
3690
+ * This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
3691
+ * checks that the withdraw amount will not exceed the specified balance while leaving enough left
3692
+ * to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
3693
+ * `withdraw` method directly.
3694
+ */
3695
+ static safeWithdraw(
3696
+ params: WithdrawFromVoteAccountParams,
3697
+ currentVoteAccountBalance: number,
3698
+ rentExemptMinimum: number,
3699
+ ): Transaction;
3598
3700
  }
3599
3701
 
3600
3702
  export const VALIDATOR_INFO_KEY: PublicKey;