@solana/web3.js 1.77.3 → 2.0.0-development

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 (99) hide show
  1. package/README.md +56 -112
  2. package/dist/index.browser.cjs +158 -0
  3. package/dist/index.browser.cjs.map +1 -0
  4. package/dist/index.browser.js +137 -0
  5. package/dist/index.browser.js.map +1 -0
  6. package/dist/index.development.js +1044 -0
  7. package/dist/index.development.js.map +1 -0
  8. package/dist/index.native.js +139 -0
  9. package/dist/index.native.js.map +1 -0
  10. package/dist/index.node.cjs +158 -0
  11. package/dist/index.node.cjs.map +1 -0
  12. package/dist/index.node.js +139 -0
  13. package/dist/index.node.js.map +1 -0
  14. package/dist/index.production.min.js +25 -0
  15. package/dist/types/index.d.ts +5 -0
  16. package/dist/types/rpc-default-config.d.ts +3 -0
  17. package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
  18. package/dist/types/rpc-request-coalescer.d.ts +5 -0
  19. package/dist/types/rpc-request-deduplication.d.ts +2 -0
  20. package/dist/types/rpc-transport.d.ts +4 -0
  21. package/dist/types/rpc.d.ts +5 -0
  22. package/package.json +86 -110
  23. package/lib/index.browser.cjs.js +0 -9534
  24. package/lib/index.browser.cjs.js.map +0 -1
  25. package/lib/index.browser.esm.js +0 -9432
  26. package/lib/index.browser.esm.js.map +0 -1
  27. package/lib/index.cjs.js +0 -12058
  28. package/lib/index.cjs.js.map +0 -1
  29. package/lib/index.d.ts +0 -3891
  30. package/lib/index.esm.js +0 -11949
  31. package/lib/index.esm.js.map +0 -1
  32. package/lib/index.iife.js +0 -25985
  33. package/lib/index.iife.js.map +0 -1
  34. package/lib/index.iife.min.js +0 -20
  35. package/lib/index.iife.min.js.map +0 -1
  36. package/lib/index.native.js +0 -9534
  37. package/lib/index.native.js.map +0 -1
  38. package/src/__forks__/browser/fetch-impl.ts +0 -4
  39. package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
  40. package/src/__forks__/react-native/fetch-impl.ts +0 -4
  41. package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
  42. package/src/account-data.ts +0 -39
  43. package/src/account.ts +0 -55
  44. package/src/blockhash.ts +0 -4
  45. package/src/bpf-loader-deprecated.ts +0 -5
  46. package/src/bpf-loader.ts +0 -45
  47. package/src/connection.ts +0 -6756
  48. package/src/epoch-schedule.ts +0 -102
  49. package/src/errors.ts +0 -50
  50. package/src/fee-calculator.ts +0 -18
  51. package/src/fetch-impl.ts +0 -13
  52. package/src/index.ts +0 -24
  53. package/src/instruction.ts +0 -58
  54. package/src/keypair.ts +0 -93
  55. package/src/layout.ts +0 -188
  56. package/src/loader.ts +0 -267
  57. package/src/message/account-keys.ts +0 -79
  58. package/src/message/compiled-keys.ts +0 -165
  59. package/src/message/index.ts +0 -47
  60. package/src/message/legacy.ts +0 -326
  61. package/src/message/v0.ts +0 -496
  62. package/src/message/versioned.ts +0 -36
  63. package/src/nonce-account.ts +0 -82
  64. package/src/programs/address-lookup-table/index.ts +0 -435
  65. package/src/programs/address-lookup-table/state.ts +0 -84
  66. package/src/programs/compute-budget.ts +0 -281
  67. package/src/programs/ed25519.ts +0 -157
  68. package/src/programs/index.ts +0 -7
  69. package/src/programs/secp256k1.ts +0 -228
  70. package/src/programs/stake.ts +0 -935
  71. package/src/programs/system.ts +0 -1048
  72. package/src/programs/vote.ts +0 -543
  73. package/src/publickey.ts +0 -259
  74. package/src/rpc-websocket-factory.ts +0 -4
  75. package/src/rpc-websocket.ts +0 -79
  76. package/src/sysvar.ts +0 -37
  77. package/src/timing.ts +0 -23
  78. package/src/transaction/constants.ts +0 -12
  79. package/src/transaction/expiry-custom-errors.ts +0 -48
  80. package/src/transaction/index.ts +0 -5
  81. package/src/transaction/legacy.ts +0 -918
  82. package/src/transaction/message.ts +0 -140
  83. package/src/transaction/versioned.ts +0 -126
  84. package/src/utils/assert.ts +0 -8
  85. package/src/utils/bigint.ts +0 -43
  86. package/src/utils/borsh-schema.ts +0 -38
  87. package/src/utils/cluster.ts +0 -31
  88. package/src/utils/ed25519.ts +0 -43
  89. package/src/utils/index.ts +0 -5
  90. package/src/utils/makeWebsocketUrl.ts +0 -26
  91. package/src/utils/promise-timeout.ts +0 -14
  92. package/src/utils/secp256k1.ts +0 -11
  93. package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
  94. package/src/utils/send-and-confirm-transaction.ts +0 -98
  95. package/src/utils/shortvec-encoding.ts +0 -28
  96. package/src/utils/sleep.ts +0 -4
  97. package/src/utils/to-buffer.ts +0 -11
  98. package/src/validator-info.ts +0 -104
  99. package/src/vote-account.ts +0 -236
@@ -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
- }