@solana/web3.js 1.51.0 → 1.54.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 (60) hide show
  1. package/lib/index.browser.cjs.js +3600 -3205
  2. package/lib/index.browser.cjs.js.map +1 -1
  3. package/lib/index.browser.esm.js +3595 -3206
  4. package/lib/index.browser.esm.js.map +1 -1
  5. package/lib/index.cjs.js +3602 -3205
  6. package/lib/index.cjs.js.map +1 -1
  7. package/lib/index.d.ts +953 -831
  8. package/lib/index.esm.js +3597 -3206
  9. package/lib/index.esm.js.map +1 -1
  10. package/lib/index.iife.js +2630 -2235
  11. package/lib/index.iife.js.map +1 -1
  12. package/lib/index.iife.min.js +3 -3
  13. package/lib/index.iife.min.js.map +1 -1
  14. package/lib/index.native.js +3600 -3204
  15. package/lib/index.native.js.map +1 -1
  16. package/package.json +1 -2
  17. package/src/account-data.ts +39 -0
  18. package/src/account.ts +1 -1
  19. package/src/connection.ts +49 -16
  20. package/src/fee-calculator.ts +2 -0
  21. package/src/index.ts +3 -14
  22. package/src/layout.ts +7 -0
  23. package/src/loader.ts +4 -5
  24. package/src/message/index.ts +45 -0
  25. package/src/{message.ts → message/legacy.ts} +46 -27
  26. package/src/message/v0.ts +324 -0
  27. package/src/message/versioned.ts +27 -0
  28. package/src/nonce-account.ts +1 -1
  29. package/src/{address-lookup-table-program.ts → programs/address-lookup-table/index.ts} +8 -6
  30. package/src/programs/address-lookup-table/state.ts +84 -0
  31. package/src/{compute-budget.ts → programs/compute-budget.ts} +4 -4
  32. package/src/{ed25519-program.ts → programs/ed25519.ts} +4 -4
  33. package/src/programs/index.ts +7 -0
  34. package/src/{secp256k1-program.ts → programs/secp256k1.ts} +4 -4
  35. package/src/{stake-program.ts → programs/stake.ts} +7 -7
  36. package/src/{system-program.ts → programs/system.ts} +8 -8
  37. package/src/{vote-program.ts → programs/vote.ts} +28 -7
  38. package/src/publickey.ts +9 -4
  39. package/src/{transaction-constants.ts → transaction/constants.ts} +2 -0
  40. package/src/{util/tx-expiry-custom-errors.ts → transaction/expiry-custom-errors.ts} +0 -0
  41. package/src/transaction/index.ts +4 -0
  42. package/src/{transaction.ts → transaction/legacy.ts} +10 -13
  43. package/src/transaction/versioned.ts +108 -0
  44. package/src/{util → utils}/assert.ts +0 -0
  45. package/src/{util → utils}/bigint.ts +0 -0
  46. package/src/{util → utils}/borsh-schema.ts +0 -0
  47. package/src/{util → utils}/cluster.ts +0 -0
  48. package/src/utils/index.ts +4 -0
  49. package/src/utils/makeWebsocketUrl.ts +26 -0
  50. package/src/{util → utils}/promise-timeout.ts +0 -0
  51. package/src/{util → utils}/send-and-confirm-raw-transaction.ts +0 -0
  52. package/src/{util → utils}/send-and-confirm-transaction.ts +0 -0
  53. package/src/{util → utils}/shortvec-encoding.ts +0 -0
  54. package/src/{util → utils}/sleep.ts +0 -0
  55. package/src/{util → utils}/to-buffer.ts +0 -0
  56. package/src/validator-info.ts +4 -6
  57. package/src/vote-account.ts +1 -1
  58. package/src/util/__forks__/react-native/url-impl.ts +0 -2
  59. package/src/util/makeWebsocketUrl.ts +0 -20
  60. package/src/util/url-impl.ts +0 -2
@@ -2,19 +2,16 @@ import nacl from 'tweetnacl';
2
2
  import bs58 from 'bs58';
3
3
  import {Buffer} from 'buffer';
4
4
 
5
- import {
6
- PACKET_DATA_SIZE,
7
- SIGNATURE_LENGTH_IN_BYTES,
8
- } from './transaction-constants';
9
- import {Connection} from './connection';
10
- import {Message} from './message';
11
- import {PublicKey} from './publickey';
12
- import * as shortvec from './util/shortvec-encoding';
13
- import {toBuffer} from './util/to-buffer';
14
- import invariant from './util/assert';
15
- import type {Signer} from './keypair';
16
- import type {Blockhash} from './blockhash';
17
- import type {CompiledInstruction} from './message';
5
+ import {PACKET_DATA_SIZE, SIGNATURE_LENGTH_IN_BYTES} from './constants';
6
+ import {Connection} from '../connection';
7
+ import {Message} from '../message';
8
+ import {PublicKey} from '../publickey';
9
+ import * as shortvec from '../utils/shortvec-encoding';
10
+ import {toBuffer} from '../utils/to-buffer';
11
+ import invariant from '../utils/assert';
12
+ import type {Signer} from '../keypair';
13
+ import type {Blockhash} from '../blockhash';
14
+ import type {CompiledInstruction} from '../message';
18
15
 
19
16
  /**
20
17
  * Transaction signature as base-58 encoded string
@@ -0,0 +1,108 @@
1
+ import nacl from 'tweetnacl';
2
+ import * as BufferLayout from '@solana/buffer-layout';
3
+
4
+ import {Signer} from '../keypair';
5
+ import assert from '../utils/assert';
6
+ import {VersionedMessage} from '../message/versioned';
7
+ import {SIGNATURE_LENGTH_IN_BYTES} from './constants';
8
+ import * as shortvec from '../utils/shortvec-encoding';
9
+ import * as Layout from '../layout';
10
+
11
+ export type TransactionVersion = 'legacy' | 0;
12
+
13
+ /**
14
+ * Versioned transaction class
15
+ */
16
+ export class VersionedTransaction {
17
+ signatures: Array<Uint8Array>;
18
+ message: VersionedMessage;
19
+
20
+ constructor(message: VersionedMessage, signatures?: Array<Uint8Array>) {
21
+ if (signatures !== undefined) {
22
+ assert(
23
+ signatures.length === message.header.numRequiredSignatures,
24
+ 'Expected signatures length to be equal to the number of required signatures',
25
+ );
26
+ this.signatures = signatures;
27
+ } else {
28
+ const defaultSignatures = [];
29
+ for (let i = 0; i < message.header.numRequiredSignatures; i++) {
30
+ defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
31
+ }
32
+ this.signatures = defaultSignatures;
33
+ }
34
+ this.message = message;
35
+ }
36
+
37
+ serialize(): Uint8Array {
38
+ const serializedMessage = this.message.serialize();
39
+
40
+ const encodedSignaturesLength = Array<number>();
41
+ shortvec.encodeLength(encodedSignaturesLength, this.signatures.length);
42
+
43
+ const transactionLayout = BufferLayout.struct<{
44
+ encodedSignaturesLength: Uint8Array;
45
+ signatures: Array<Uint8Array>;
46
+ serializedMessage: Uint8Array;
47
+ }>([
48
+ BufferLayout.blob(
49
+ encodedSignaturesLength.length,
50
+ 'encodedSignaturesLength',
51
+ ),
52
+ BufferLayout.seq(
53
+ Layout.signature(),
54
+ this.signatures.length,
55
+ 'signatures',
56
+ ),
57
+ BufferLayout.blob(serializedMessage.length, 'serializedMessage'),
58
+ ]);
59
+
60
+ const serializedTransaction = new Uint8Array(2048);
61
+ const serializedTransactionLength = transactionLayout.encode(
62
+ {
63
+ encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
64
+ signatures: this.signatures,
65
+ serializedMessage,
66
+ },
67
+ serializedTransaction,
68
+ );
69
+
70
+ return serializedTransaction.slice(0, serializedTransactionLength);
71
+ }
72
+
73
+ static deserialize(serializedTransaction: Uint8Array): VersionedTransaction {
74
+ let byteArray = [...serializedTransaction];
75
+
76
+ const signatures = [];
77
+ const signaturesLength = shortvec.decodeLength(byteArray);
78
+ for (let i = 0; i < signaturesLength; i++) {
79
+ signatures.push(
80
+ new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)),
81
+ );
82
+ }
83
+
84
+ const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
85
+ return new VersionedTransaction(message, signatures);
86
+ }
87
+
88
+ sign(signers: Array<Signer>) {
89
+ const messageData = this.message.serialize();
90
+ const signerPubkeys = this.message.staticAccountKeys.slice(
91
+ 0,
92
+ this.message.header.numRequiredSignatures,
93
+ );
94
+ for (const signer of signers) {
95
+ const signerIndex = signerPubkeys.findIndex(pubkey =>
96
+ pubkey.equals(signer.publicKey),
97
+ );
98
+ assert(
99
+ signerIndex >= 0,
100
+ `Cannot sign with non signer key ${signer.publicKey.toBase58()}`,
101
+ );
102
+ this.signatures[signerIndex] = nacl.sign.detached(
103
+ messageData,
104
+ signer.secretKey,
105
+ );
106
+ }
107
+ }
108
+ }
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ export * from './borsh-schema';
2
+ export * from './cluster';
3
+ export * from './send-and-confirm-raw-transaction';
4
+ export * from './send-and-confirm-transaction';
@@ -0,0 +1,26 @@
1
+ const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
2
+
3
+ export function makeWebsocketUrl(endpoint: string) {
4
+ const matches = endpoint.match(URL_RE);
5
+ if (matches == null) {
6
+ throw TypeError(`Failed to validate endpoint URL \`${endpoint}\``);
7
+ }
8
+ const [
9
+ _, // eslint-disable-line @typescript-eslint/no-unused-vars
10
+ hostish,
11
+ portWithColon,
12
+ rest,
13
+ ] = matches;
14
+ const protocol = endpoint.startsWith('https:') ? 'wss:' : 'ws:';
15
+ const startPort =
16
+ portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
17
+ const websocketPort =
18
+ // Only shift the port by +1 as a convention for ws(s) only if given endpoint
19
+ // is explictly specifying the endpoint port (HTTP-based RPC), assuming
20
+ // we're directly trying to connect to solana-validator's ws listening port.
21
+ // When the endpoint omits the port, we're connecting to the protocol
22
+ // default ports: http(80) or https(443) and it's assumed we're behind a reverse
23
+ // proxy which manages WebSocket upgrade and backend port redirection.
24
+ startPort == null ? '' : `:${startPort + 1}`;
25
+ return `${protocol}//${hostish}${websocketPort}${rest}`;
26
+ }
File without changes
File without changes
File without changes
File without changes
@@ -7,8 +7,8 @@ import {
7
7
  } from 'superstruct';
8
8
 
9
9
  import * as Layout from './layout';
10
- import * as shortvec from './util/shortvec-encoding';
11
- import {PublicKey} from './publickey';
10
+ import * as shortvec from './utils/shortvec-encoding';
11
+ import {PublicKey, PUBLIC_KEY_LENGTH} from './publickey';
12
12
 
13
13
  export const VALIDATOR_INFO_KEY = new PublicKey(
14
14
  'Va1idator1nfo111111111111111111111111111111',
@@ -77,16 +77,14 @@ export class ValidatorInfo {
77
77
  static fromConfigData(
78
78
  buffer: Buffer | Uint8Array | Array<number>,
79
79
  ): ValidatorInfo | null {
80
- const PUBKEY_LENGTH = 32;
81
-
82
80
  let byteArray = [...buffer];
83
81
  const configKeyCount = shortvec.decodeLength(byteArray);
84
82
  if (configKeyCount !== 2) return null;
85
83
 
86
84
  const configKeys: Array<ConfigKey> = [];
87
85
  for (let i = 0; i < 2; i++) {
88
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
89
- byteArray = byteArray.slice(PUBKEY_LENGTH);
86
+ const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
87
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
90
88
  const isSigner = byteArray.slice(0, 1)[0] === 1;
91
89
  byteArray = byteArray.slice(1);
92
90
  configKeys.push({publicKey, isSigner});
@@ -3,7 +3,7 @@ import type {Buffer} from 'buffer';
3
3
 
4
4
  import * as Layout from './layout';
5
5
  import {PublicKey} from './publickey';
6
- import {toBuffer} from './util/to-buffer';
6
+ import {toBuffer} from './utils/to-buffer';
7
7
 
8
8
  export const VOTE_PROGRAM_ID = new PublicKey(
9
9
  'Vote111111111111111111111111111111111111111',
@@ -1,2 +0,0 @@
1
- export {default} from 'react-native-url-polyfill';
2
- export * from 'react-native-url-polyfill';
@@ -1,20 +0,0 @@
1
- import {URL} from './url-impl';
2
-
3
- export function makeWebsocketUrl(endpoint: string) {
4
- let url = new URL(endpoint);
5
- const useHttps = url.protocol === 'https:';
6
-
7
- url.protocol = useHttps ? 'wss:' : 'ws:';
8
- url.host = '';
9
-
10
- // Only shift the port by +1 as a convention for ws(s) only if given endpoint
11
- // is explictly specifying the endpoint port (HTTP-based RPC), assuming
12
- // we're directly trying to connect to solana-validator's ws listening port.
13
- // When the endpoint omits the port, we're connecting to the protocol
14
- // default ports: http(80) or https(443) and it's assumed we're behind a reverse
15
- // proxy which manages WebSocket upgrade and backend port redirection.
16
- if (url.port !== '') {
17
- url.port = String(Number(url.port) + 1);
18
- }
19
- return url.toString();
20
- }
@@ -1,2 +0,0 @@
1
- export const URL = globalThis.URL;
2
- export const URLSearchParams = globalThis.URLSearchParams;