@solana/web3.js 1.75.0 → 2.0.0-experimental.20762e0

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 (97) hide show
  1. package/dist/index.browser.cjs +79 -0
  2. package/dist/index.browser.cjs.map +1 -0
  3. package/dist/index.browser.js +70 -0
  4. package/dist/index.browser.js.map +1 -0
  5. package/dist/index.development.js +539 -0
  6. package/dist/index.development.js.map +1 -0
  7. package/dist/index.native.js +68 -0
  8. package/dist/index.native.js.map +1 -0
  9. package/dist/index.node.cjs +79 -0
  10. package/dist/index.node.cjs.map +1 -0
  11. package/dist/index.node.js +70 -0
  12. package/dist/index.node.js.map +1 -0
  13. package/dist/index.production.min.js +13 -0
  14. package/dist/types/index.d.ts +4 -0
  15. package/dist/types/rpc-default-config.d.ts +3 -0
  16. package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
  17. package/dist/types/rpc-transport.d.ts +4 -0
  18. package/dist/types/rpc.d.ts +5 -0
  19. package/package.json +86 -113
  20. package/README.md +0 -155
  21. package/lib/index.browser.cjs.js +0 -9510
  22. package/lib/index.browser.cjs.js.map +0 -1
  23. package/lib/index.browser.esm.js +0 -9404
  24. package/lib/index.browser.esm.js.map +0 -1
  25. package/lib/index.cjs.js +0 -12034
  26. package/lib/index.cjs.js.map +0 -1
  27. package/lib/index.d.ts +0 -3885
  28. package/lib/index.esm.js +0 -11921
  29. package/lib/index.esm.js.map +0 -1
  30. package/lib/index.iife.js +0 -24593
  31. package/lib/index.iife.js.map +0 -1
  32. package/lib/index.iife.min.js +0 -13
  33. package/lib/index.iife.min.js.map +0 -1
  34. package/lib/index.native.js +0 -9510
  35. package/lib/index.native.js.map +0 -1
  36. package/src/__forks__/browser/fetch-impl.ts +0 -4
  37. package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
  38. package/src/__forks__/react-native/fetch-impl.ts +0 -4
  39. package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
  40. package/src/account-data.ts +0 -39
  41. package/src/account.ts +0 -55
  42. package/src/blockhash.ts +0 -4
  43. package/src/bpf-loader-deprecated.ts +0 -5
  44. package/src/bpf-loader.ts +0 -45
  45. package/src/connection.ts +0 -6734
  46. package/src/epoch-schedule.ts +0 -102
  47. package/src/errors.ts +0 -50
  48. package/src/fee-calculator.ts +0 -18
  49. package/src/fetch-impl.ts +0 -13
  50. package/src/index.ts +0 -24
  51. package/src/instruction.ts +0 -58
  52. package/src/keypair.ts +0 -93
  53. package/src/layout.ts +0 -188
  54. package/src/loader.ts +0 -236
  55. package/src/message/account-keys.ts +0 -79
  56. package/src/message/compiled-keys.ts +0 -165
  57. package/src/message/index.ts +0 -47
  58. package/src/message/legacy.ts +0 -326
  59. package/src/message/v0.ts +0 -496
  60. package/src/message/versioned.ts +0 -36
  61. package/src/nonce-account.ts +0 -82
  62. package/src/programs/address-lookup-table/index.ts +0 -435
  63. package/src/programs/address-lookup-table/state.ts +0 -84
  64. package/src/programs/compute-budget.ts +0 -281
  65. package/src/programs/ed25519.ts +0 -157
  66. package/src/programs/index.ts +0 -7
  67. package/src/programs/secp256k1.ts +0 -228
  68. package/src/programs/stake.ts +0 -935
  69. package/src/programs/system.ts +0 -1048
  70. package/src/programs/vote.ts +0 -541
  71. package/src/publickey.ts +0 -259
  72. package/src/rpc-websocket-factory.ts +0 -4
  73. package/src/rpc-websocket.ts +0 -79
  74. package/src/sysvar.ts +0 -37
  75. package/src/timing.ts +0 -23
  76. package/src/transaction/constants.ts +0 -12
  77. package/src/transaction/expiry-custom-errors.ts +0 -48
  78. package/src/transaction/index.ts +0 -5
  79. package/src/transaction/legacy.ts +0 -908
  80. package/src/transaction/message.ts +0 -140
  81. package/src/transaction/versioned.ts +0 -126
  82. package/src/utils/assert.ts +0 -8
  83. package/src/utils/bigint.ts +0 -43
  84. package/src/utils/borsh-schema.ts +0 -38
  85. package/src/utils/cluster.ts +0 -31
  86. package/src/utils/ed25519.ts +0 -46
  87. package/src/utils/index.ts +0 -5
  88. package/src/utils/makeWebsocketUrl.ts +0 -26
  89. package/src/utils/promise-timeout.ts +0 -14
  90. package/src/utils/secp256k1.ts +0 -18
  91. package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
  92. package/src/utils/send-and-confirm-transaction.ts +0 -98
  93. package/src/utils/shortvec-encoding.ts +0 -28
  94. package/src/utils/sleep.ts +0 -4
  95. package/src/utils/to-buffer.ts +0 -11
  96. package/src/validator-info.ts +0 -104
  97. package/src/vote-account.ts +0 -236
@@ -1,98 +0,0 @@
1
- import {Connection, SignatureResult} from '../connection';
2
- import {Transaction} from '../transaction';
3
- import type {ConfirmOptions} from '../connection';
4
- import type {Signer} from '../keypair';
5
- import type {TransactionSignature} from '../transaction';
6
-
7
- /**
8
- * Sign, send and confirm a transaction.
9
- *
10
- * If `commitment` option is not specified, defaults to 'max' commitment.
11
- *
12
- * @param {Connection} connection
13
- * @param {Transaction} transaction
14
- * @param {Array<Signer>} signers
15
- * @param {ConfirmOptions} [options]
16
- * @returns {Promise<TransactionSignature>}
17
- */
18
- export async function sendAndConfirmTransaction(
19
- connection: Connection,
20
- transaction: Transaction,
21
- signers: Array<Signer>,
22
- options?: ConfirmOptions &
23
- Readonly<{
24
- // A signal that, when aborted, cancels any outstanding transaction confirmation operations
25
- abortSignal?: AbortSignal;
26
- }>,
27
- ): Promise<TransactionSignature> {
28
- const sendOptions = options && {
29
- skipPreflight: options.skipPreflight,
30
- preflightCommitment: options.preflightCommitment || options.commitment,
31
- maxRetries: options.maxRetries,
32
- minContextSlot: options.minContextSlot,
33
- };
34
-
35
- const signature = await connection.sendTransaction(
36
- transaction,
37
- signers,
38
- sendOptions,
39
- );
40
-
41
- let status: SignatureResult;
42
- if (
43
- transaction.recentBlockhash != null &&
44
- transaction.lastValidBlockHeight != null
45
- ) {
46
- status = (
47
- await connection.confirmTransaction(
48
- {
49
- abortSignal: options?.abortSignal,
50
- signature: signature,
51
- blockhash: transaction.recentBlockhash,
52
- lastValidBlockHeight: transaction.lastValidBlockHeight,
53
- },
54
- options && options.commitment,
55
- )
56
- ).value;
57
- } else if (
58
- transaction.minNonceContextSlot != null &&
59
- transaction.nonceInfo != null
60
- ) {
61
- const {nonceInstruction} = transaction.nonceInfo;
62
- const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
63
- status = (
64
- await connection.confirmTransaction(
65
- {
66
- abortSignal: options?.abortSignal,
67
- minContextSlot: transaction.minNonceContextSlot,
68
- nonceAccountPubkey,
69
- nonceValue: transaction.nonceInfo.nonce,
70
- signature,
71
- },
72
- options && options.commitment,
73
- )
74
- ).value;
75
- } else {
76
- if (options?.abortSignal != null) {
77
- console.warn(
78
- 'sendAndConfirmTransaction(): A transaction with a deprecated confirmation strategy was ' +
79
- 'supplied along with an `abortSignal`. Only transactions having `lastValidBlockHeight` ' +
80
- 'or a combination of `nonceInfo` and `minNonceContextSlot` are abortable.',
81
- );
82
- }
83
- status = (
84
- await connection.confirmTransaction(
85
- signature,
86
- options && options.commitment,
87
- )
88
- ).value;
89
- }
90
-
91
- if (status.err) {
92
- throw new Error(
93
- `Transaction ${signature} failed (${JSON.stringify(status)})`,
94
- );
95
- }
96
-
97
- return signature;
98
- }
@@ -1,28 +0,0 @@
1
- export function decodeLength(bytes: Array<number>): number {
2
- let len = 0;
3
- let size = 0;
4
- for (;;) {
5
- let elem = bytes.shift() as number;
6
- len |= (elem & 0x7f) << (size * 7);
7
- size += 1;
8
- if ((elem & 0x80) === 0) {
9
- break;
10
- }
11
- }
12
- return len;
13
- }
14
-
15
- export function encodeLength(bytes: Array<number>, len: number) {
16
- let rem_len = len;
17
- for (;;) {
18
- let elem = rem_len & 0x7f;
19
- rem_len >>= 7;
20
- if (rem_len == 0) {
21
- bytes.push(elem);
22
- break;
23
- } else {
24
- elem |= 0x80;
25
- bytes.push(elem);
26
- }
27
- }
28
- }
@@ -1,4 +0,0 @@
1
- // zzz
2
- export function sleep(ms: number): Promise<void> {
3
- return new Promise(resolve => setTimeout(resolve, ms));
4
- }
@@ -1,11 +0,0 @@
1
- import {Buffer} from 'buffer';
2
-
3
- export const toBuffer = (arr: Buffer | Uint8Array | Array<number>): Buffer => {
4
- if (Buffer.isBuffer(arr)) {
5
- return arr;
6
- } else if (arr instanceof Uint8Array) {
7
- return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
8
- } else {
9
- return Buffer.from(arr);
10
- }
11
- };
@@ -1,104 +0,0 @@
1
- import {Buffer} from 'buffer';
2
- import {
3
- assert as assertType,
4
- optional,
5
- string,
6
- type as pick,
7
- } from 'superstruct';
8
-
9
- import * as Layout from './layout';
10
- import * as shortvec from './utils/shortvec-encoding';
11
- import {PublicKey, PUBLIC_KEY_LENGTH} from './publickey';
12
-
13
- export const VALIDATOR_INFO_KEY = new PublicKey(
14
- 'Va1idator1nfo111111111111111111111111111111',
15
- );
16
-
17
- /**
18
- * @internal
19
- */
20
- type ConfigKey = {
21
- publicKey: PublicKey;
22
- isSigner: boolean;
23
- };
24
-
25
- /**
26
- * Info used to identity validators.
27
- */
28
- export type Info = {
29
- /** validator name */
30
- name: string;
31
- /** optional, validator website */
32
- website?: string;
33
- /** optional, extra information the validator chose to share */
34
- details?: string;
35
- /** optional, used to identify validators on keybase.io */
36
- keybaseUsername?: string;
37
- };
38
-
39
- const InfoString = pick({
40
- name: string(),
41
- website: optional(string()),
42
- details: optional(string()),
43
- keybaseUsername: optional(string()),
44
- });
45
-
46
- /**
47
- * ValidatorInfo class
48
- */
49
- export class ValidatorInfo {
50
- /**
51
- * validator public key
52
- */
53
- key: PublicKey;
54
- /**
55
- * validator information
56
- */
57
- info: Info;
58
-
59
- /**
60
- * Construct a valid ValidatorInfo
61
- *
62
- * @param key validator public key
63
- * @param info validator information
64
- */
65
- constructor(key: PublicKey, info: Info) {
66
- this.key = key;
67
- this.info = info;
68
- }
69
-
70
- /**
71
- * Deserialize ValidatorInfo from the config account data. Exactly two config
72
- * keys are required in the data.
73
- *
74
- * @param buffer config account data
75
- * @return null if info was not found
76
- */
77
- static fromConfigData(
78
- buffer: Buffer | Uint8Array | Array<number>,
79
- ): ValidatorInfo | null {
80
- let byteArray = [...buffer];
81
- const configKeyCount = shortvec.decodeLength(byteArray);
82
- if (configKeyCount !== 2) return null;
83
-
84
- const configKeys: Array<ConfigKey> = [];
85
- for (let i = 0; i < 2; i++) {
86
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
87
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
88
- const isSigner = byteArray.slice(0, 1)[0] === 1;
89
- byteArray = byteArray.slice(1);
90
- configKeys.push({publicKey, isSigner});
91
- }
92
-
93
- if (configKeys[0].publicKey.equals(VALIDATOR_INFO_KEY)) {
94
- if (configKeys[1].isSigner) {
95
- const rawInfo: any = Layout.rustString().decode(Buffer.from(byteArray));
96
- const info = JSON.parse(rawInfo as string);
97
- assertType(info, InfoString);
98
- return new ValidatorInfo(configKeys[1].publicKey, info);
99
- }
100
- }
101
-
102
- return null;
103
- }
104
- }
@@ -1,236 +0,0 @@
1
- import * as BufferLayout from '@solana/buffer-layout';
2
- import type {Buffer} from 'buffer';
3
-
4
- import * as Layout from './layout';
5
- import {PublicKey} from './publickey';
6
- import {toBuffer} from './utils/to-buffer';
7
-
8
- export const VOTE_PROGRAM_ID = new PublicKey(
9
- 'Vote111111111111111111111111111111111111111',
10
- );
11
-
12
- export type Lockout = {
13
- slot: number;
14
- confirmationCount: number;
15
- };
16
-
17
- /**
18
- * History of how many credits earned by the end of each epoch
19
- */
20
- export type EpochCredits = Readonly<{
21
- epoch: number;
22
- credits: number;
23
- prevCredits: number;
24
- }>;
25
-
26
- export type AuthorizedVoter = Readonly<{
27
- epoch: number;
28
- authorizedVoter: PublicKey;
29
- }>;
30
-
31
- type AuthorizedVoterRaw = Readonly<{
32
- authorizedVoter: Uint8Array;
33
- epoch: number;
34
- }>;
35
-
36
- type PriorVoters = Readonly<{
37
- buf: PriorVoterRaw[];
38
- idx: number;
39
- isEmpty: number;
40
- }>;
41
-
42
- export type PriorVoter = Readonly<{
43
- authorizedPubkey: PublicKey;
44
- epochOfLastAuthorizedSwitch: number;
45
- targetEpoch: number;
46
- }>;
47
-
48
- type PriorVoterRaw = Readonly<{
49
- authorizedPubkey: Uint8Array;
50
- epochOfLastAuthorizedSwitch: number;
51
- targetEpoch: number;
52
- }>;
53
-
54
- export type BlockTimestamp = Readonly<{
55
- slot: number;
56
- timestamp: number;
57
- }>;
58
-
59
- type VoteAccountData = Readonly<{
60
- authorizedVoters: AuthorizedVoterRaw[];
61
- authorizedWithdrawer: Uint8Array;
62
- commission: number;
63
- epochCredits: EpochCredits[];
64
- lastTimestamp: BlockTimestamp;
65
- nodePubkey: Uint8Array;
66
- priorVoters: PriorVoters;
67
- rootSlot: number;
68
- rootSlotValid: number;
69
- votes: Lockout[];
70
- }>;
71
-
72
- /**
73
- * See https://github.com/solana-labs/solana/blob/8a12ed029cfa38d4a45400916c2463fb82bbec8c/programs/vote_api/src/vote_state.rs#L68-L88
74
- *
75
- * @internal
76
- */
77
- const VoteAccountLayout = BufferLayout.struct<VoteAccountData>([
78
- Layout.publicKey('nodePubkey'),
79
- Layout.publicKey('authorizedWithdrawer'),
80
- BufferLayout.u8('commission'),
81
- BufferLayout.nu64(), // votes.length
82
- BufferLayout.seq<Lockout>(
83
- BufferLayout.struct([
84
- BufferLayout.nu64('slot'),
85
- BufferLayout.u32('confirmationCount'),
86
- ]),
87
- BufferLayout.offset(BufferLayout.u32(), -8),
88
- 'votes',
89
- ),
90
- BufferLayout.u8('rootSlotValid'),
91
- BufferLayout.nu64('rootSlot'),
92
- BufferLayout.nu64(), // authorizedVoters.length
93
- BufferLayout.seq<AuthorizedVoterRaw>(
94
- BufferLayout.struct([
95
- BufferLayout.nu64('epoch'),
96
- Layout.publicKey('authorizedVoter'),
97
- ]),
98
- BufferLayout.offset(BufferLayout.u32(), -8),
99
- 'authorizedVoters',
100
- ),
101
- BufferLayout.struct<PriorVoters>(
102
- [
103
- BufferLayout.seq(
104
- BufferLayout.struct([
105
- Layout.publicKey('authorizedPubkey'),
106
- BufferLayout.nu64('epochOfLastAuthorizedSwitch'),
107
- BufferLayout.nu64('targetEpoch'),
108
- ]),
109
- 32,
110
- 'buf',
111
- ),
112
- BufferLayout.nu64('idx'),
113
- BufferLayout.u8('isEmpty'),
114
- ],
115
- 'priorVoters',
116
- ),
117
- BufferLayout.nu64(), // epochCredits.length
118
- BufferLayout.seq<EpochCredits>(
119
- BufferLayout.struct([
120
- BufferLayout.nu64('epoch'),
121
- BufferLayout.nu64('credits'),
122
- BufferLayout.nu64('prevCredits'),
123
- ]),
124
- BufferLayout.offset(BufferLayout.u32(), -8),
125
- 'epochCredits',
126
- ),
127
- BufferLayout.struct<BlockTimestamp>(
128
- [BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')],
129
- 'lastTimestamp',
130
- ),
131
- ]);
132
-
133
- type VoteAccountArgs = {
134
- nodePubkey: PublicKey;
135
- authorizedWithdrawer: PublicKey;
136
- commission: number;
137
- rootSlot: number | null;
138
- votes: Lockout[];
139
- authorizedVoters: AuthorizedVoter[];
140
- priorVoters: PriorVoter[];
141
- epochCredits: EpochCredits[];
142
- lastTimestamp: BlockTimestamp;
143
- };
144
-
145
- /**
146
- * VoteAccount class
147
- */
148
- export class VoteAccount {
149
- nodePubkey: PublicKey;
150
- authorizedWithdrawer: PublicKey;
151
- commission: number;
152
- rootSlot: number | null;
153
- votes: Lockout[];
154
- authorizedVoters: AuthorizedVoter[];
155
- priorVoters: PriorVoter[];
156
- epochCredits: EpochCredits[];
157
- lastTimestamp: BlockTimestamp;
158
-
159
- /**
160
- * @internal
161
- */
162
- constructor(args: VoteAccountArgs) {
163
- this.nodePubkey = args.nodePubkey;
164
- this.authorizedWithdrawer = args.authorizedWithdrawer;
165
- this.commission = args.commission;
166
- this.rootSlot = args.rootSlot;
167
- this.votes = args.votes;
168
- this.authorizedVoters = args.authorizedVoters;
169
- this.priorVoters = args.priorVoters;
170
- this.epochCredits = args.epochCredits;
171
- this.lastTimestamp = args.lastTimestamp;
172
- }
173
-
174
- /**
175
- * Deserialize VoteAccount from the account data.
176
- *
177
- * @param buffer account data
178
- * @return VoteAccount
179
- */
180
- static fromAccountData(
181
- buffer: Buffer | Uint8Array | Array<number>,
182
- ): VoteAccount {
183
- const versionOffset = 4;
184
- const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
185
-
186
- let rootSlot: number | null = va.rootSlot;
187
- if (!va.rootSlotValid) {
188
- rootSlot = null;
189
- }
190
-
191
- return new VoteAccount({
192
- nodePubkey: new PublicKey(va.nodePubkey),
193
- authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
194
- commission: va.commission,
195
- votes: va.votes,
196
- rootSlot,
197
- authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
198
- priorVoters: getPriorVoters(va.priorVoters),
199
- epochCredits: va.epochCredits,
200
- lastTimestamp: va.lastTimestamp,
201
- });
202
- }
203
- }
204
-
205
- function parseAuthorizedVoter({
206
- authorizedVoter,
207
- epoch,
208
- }: AuthorizedVoterRaw): AuthorizedVoter {
209
- return {
210
- epoch,
211
- authorizedVoter: new PublicKey(authorizedVoter),
212
- };
213
- }
214
-
215
- function parsePriorVoters({
216
- authorizedPubkey,
217
- epochOfLastAuthorizedSwitch,
218
- targetEpoch,
219
- }: PriorVoterRaw): PriorVoter {
220
- return {
221
- authorizedPubkey: new PublicKey(authorizedPubkey),
222
- epochOfLastAuthorizedSwitch,
223
- targetEpoch,
224
- };
225
- }
226
-
227
- function getPriorVoters({buf, idx, isEmpty}: PriorVoters): PriorVoter[] {
228
- if (isEmpty) {
229
- return [];
230
- }
231
-
232
- return [
233
- ...buf.slice(idx + 1).map(parsePriorVoters),
234
- ...buf.slice(0, idx).map(parsePriorVoters),
235
- ];
236
- }