@solana/web3.js 1.78.0 → 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 -111
  23. package/lib/index.browser.cjs.js +0 -10248
  24. package/lib/index.browser.cjs.js.map +0 -1
  25. package/lib/index.browser.esm.js +0 -10145
  26. package/lib/index.browser.esm.js.map +0 -1
  27. package/lib/index.cjs.js +0 -12748
  28. package/lib/index.cjs.js.map +0 -1
  29. package/lib/index.d.ts +0 -3904
  30. package/lib/index.esm.js +0 -12638
  31. package/lib/index.esm.js.map +0 -1
  32. package/lib/index.iife.js +0 -26757
  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 -10248
  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 -6796
  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
package/src/publickey.ts DELETED
@@ -1,259 +0,0 @@
1
- import BN from 'bn.js';
2
- import bs58 from 'bs58';
3
- import {Buffer} from 'buffer';
4
- import {sha256} from '@noble/hashes/sha256';
5
-
6
- import {isOnCurve} from './utils/ed25519';
7
- import {Struct, SOLANA_SCHEMA} from './utils/borsh-schema';
8
- import {toBuffer} from './utils/to-buffer';
9
-
10
- /**
11
- * Maximum length of derived pubkey seed
12
- */
13
- export const MAX_SEED_LENGTH = 32;
14
-
15
- /**
16
- * Size of public key in bytes
17
- */
18
- export const PUBLIC_KEY_LENGTH = 32;
19
-
20
- /**
21
- * Value to be converted into public key
22
- */
23
- export type PublicKeyInitData =
24
- | number
25
- | string
26
- | Uint8Array
27
- | Array<number>
28
- | PublicKeyData;
29
-
30
- /**
31
- * JSON object representation of PublicKey class
32
- */
33
- export type PublicKeyData = {
34
- /** @internal */
35
- _bn: BN;
36
- };
37
-
38
- function isPublicKeyData(value: PublicKeyInitData): value is PublicKeyData {
39
- return (value as PublicKeyData)._bn !== undefined;
40
- }
41
-
42
- // local counter used by PublicKey.unique()
43
- let uniquePublicKeyCounter = 1;
44
-
45
- /**
46
- * A public key
47
- */
48
- export class PublicKey extends Struct {
49
- /** @internal */
50
- _bn: BN;
51
-
52
- /**
53
- * Create a new PublicKey object
54
- * @param value ed25519 public key as buffer or base-58 encoded string
55
- */
56
- constructor(value: PublicKeyInitData) {
57
- super({});
58
- if (isPublicKeyData(value)) {
59
- this._bn = value._bn;
60
- } else {
61
- if (typeof value === 'string') {
62
- // assume base 58 encoding by default
63
- const decoded = bs58.decode(value);
64
- if (decoded.length != PUBLIC_KEY_LENGTH) {
65
- throw new Error(`Invalid public key input`);
66
- }
67
- this._bn = new BN(decoded);
68
- } else {
69
- this._bn = new BN(value);
70
- }
71
-
72
- if (this._bn.byteLength() > PUBLIC_KEY_LENGTH) {
73
- throw new Error(`Invalid public key input`);
74
- }
75
- }
76
- }
77
-
78
- /**
79
- * Returns a unique PublicKey for tests and benchmarks using a counter
80
- */
81
- static unique(): PublicKey {
82
- const key = new PublicKey(uniquePublicKeyCounter);
83
- uniquePublicKeyCounter += 1;
84
- return new PublicKey(key.toBuffer());
85
- }
86
-
87
- /**
88
- * Default public key value. The base58-encoded string representation is all ones (as seen below)
89
- * The underlying BN number is 32 bytes that are all zeros
90
- */
91
- static default: PublicKey = new PublicKey('11111111111111111111111111111111');
92
-
93
- /**
94
- * Checks if two publicKeys are equal
95
- */
96
- equals(publicKey: PublicKey): boolean {
97
- return this._bn.eq(publicKey._bn);
98
- }
99
-
100
- /**
101
- * Return the base-58 representation of the public key
102
- */
103
- toBase58(): string {
104
- return bs58.encode(this.toBytes());
105
- }
106
-
107
- toJSON(): string {
108
- return this.toBase58();
109
- }
110
-
111
- /**
112
- * Return the byte array representation of the public key in big endian
113
- */
114
- toBytes(): Uint8Array {
115
- const buf = this.toBuffer();
116
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
117
- }
118
-
119
- /**
120
- * Return the Buffer representation of the public key in big endian
121
- */
122
- toBuffer(): Buffer {
123
- const b = this._bn.toArrayLike(Buffer);
124
- if (b.length === PUBLIC_KEY_LENGTH) {
125
- return b;
126
- }
127
-
128
- const zeroPad = Buffer.alloc(32);
129
- b.copy(zeroPad, 32 - b.length);
130
- return zeroPad;
131
- }
132
-
133
- get [Symbol.toStringTag](): string {
134
- return `PublicKey(${this.toString()})`;
135
- }
136
-
137
- /**
138
- * Return the base-58 representation of the public key
139
- */
140
- toString(): string {
141
- return this.toBase58();
142
- }
143
-
144
- /**
145
- * Derive a public key from another key, a seed, and a program ID.
146
- * The program ID will also serve as the owner of the public key, giving
147
- * it permission to write data to the account.
148
- */
149
- /* eslint-disable require-await */
150
- static async createWithSeed(
151
- fromPublicKey: PublicKey,
152
- seed: string,
153
- programId: PublicKey,
154
- ): Promise<PublicKey> {
155
- const buffer = Buffer.concat([
156
- fromPublicKey.toBuffer(),
157
- Buffer.from(seed),
158
- programId.toBuffer(),
159
- ]);
160
- const publicKeyBytes = sha256(buffer);
161
- return new PublicKey(publicKeyBytes);
162
- }
163
-
164
- /**
165
- * Derive a program address from seeds and a program ID.
166
- */
167
- /* eslint-disable require-await */
168
- static createProgramAddressSync(
169
- seeds: Array<Buffer | Uint8Array>,
170
- programId: PublicKey,
171
- ): PublicKey {
172
- let buffer = Buffer.alloc(0);
173
- seeds.forEach(function (seed) {
174
- if (seed.length > MAX_SEED_LENGTH) {
175
- throw new TypeError(`Max seed length exceeded`);
176
- }
177
- buffer = Buffer.concat([buffer, toBuffer(seed)]);
178
- });
179
- buffer = Buffer.concat([
180
- buffer,
181
- programId.toBuffer(),
182
- Buffer.from('ProgramDerivedAddress'),
183
- ]);
184
- const publicKeyBytes = sha256(buffer);
185
- if (isOnCurve(publicKeyBytes)) {
186
- throw new Error(`Invalid seeds, address must fall off the curve`);
187
- }
188
- return new PublicKey(publicKeyBytes);
189
- }
190
-
191
- /**
192
- * Async version of createProgramAddressSync
193
- * For backwards compatibility
194
- *
195
- * @deprecated Use {@link createProgramAddressSync} instead
196
- */
197
- /* eslint-disable require-await */
198
- static async createProgramAddress(
199
- seeds: Array<Buffer | Uint8Array>,
200
- programId: PublicKey,
201
- ): Promise<PublicKey> {
202
- return this.createProgramAddressSync(seeds, programId);
203
- }
204
-
205
- /**
206
- * Find a valid program address
207
- *
208
- * Valid program addresses must fall off the ed25519 curve. This function
209
- * iterates a nonce until it finds one that when combined with the seeds
210
- * results in a valid program address.
211
- */
212
- static findProgramAddressSync(
213
- seeds: Array<Buffer | Uint8Array>,
214
- programId: PublicKey,
215
- ): [PublicKey, number] {
216
- let nonce = 255;
217
- let address;
218
- while (nonce != 0) {
219
- try {
220
- const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
221
- address = this.createProgramAddressSync(seedsWithNonce, programId);
222
- } catch (err) {
223
- if (err instanceof TypeError) {
224
- throw err;
225
- }
226
- nonce--;
227
- continue;
228
- }
229
- return [address, nonce];
230
- }
231
- throw new Error(`Unable to find a viable program address nonce`);
232
- }
233
-
234
- /**
235
- * Async version of findProgramAddressSync
236
- * For backwards compatibility
237
- *
238
- * @deprecated Use {@link findProgramAddressSync} instead
239
- */
240
- static async findProgramAddress(
241
- seeds: Array<Buffer | Uint8Array>,
242
- programId: PublicKey,
243
- ): Promise<[PublicKey, number]> {
244
- return this.findProgramAddressSync(seeds, programId);
245
- }
246
-
247
- /**
248
- * Check that a pubkey is on the ed25519 curve.
249
- */
250
- static isOnCurve(pubkeyData: PublicKeyInitData): boolean {
251
- const pubkey = new PublicKey(pubkeyData);
252
- return isOnCurve(pubkey.toBytes());
253
- }
254
- }
255
-
256
- SOLANA_SCHEMA.set(PublicKey, {
257
- kind: 'struct',
258
- fields: [['_bn', 'u256']],
259
- });
@@ -1,4 +0,0 @@
1
- import {ICommonWebSocketFactory} from 'rpc-websockets/dist/lib/client/client.types';
2
- import WebsocketFactory from 'rpc-websockets/dist/lib/client/websocket';
3
-
4
- export default WebsocketFactory as ICommonWebSocketFactory;
@@ -1,79 +0,0 @@
1
- import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client';
2
- import RpcWebSocketBrowserFactory from 'rpc-websockets/dist/lib/client/websocket.browser';
3
- import {
4
- ICommonWebSocket,
5
- IWSClientAdditionalOptions,
6
- NodeWebSocketType,
7
- NodeWebSocketTypeOptions,
8
- } from 'rpc-websockets/dist/lib/client/client.types';
9
-
10
- import createRpc from './rpc-websocket-factory';
11
-
12
- interface IHasReadyState {
13
- readyState: WebSocket['readyState'];
14
- }
15
-
16
- export default class RpcWebSocketClient extends RpcWebSocketCommonClient {
17
- private underlyingSocket: IHasReadyState | undefined;
18
- constructor(
19
- address?: string,
20
- options?: IWSClientAdditionalOptions & NodeWebSocketTypeOptions,
21
- generate_request_id?: (
22
- method: string,
23
- params: object | Array<any>,
24
- ) => number,
25
- ) {
26
- const webSocketFactory = (url: string) => {
27
- const rpc = createRpc(url, {
28
- autoconnect: true,
29
- max_reconnects: 5,
30
- reconnect: true,
31
- reconnect_interval: 1000,
32
- ...options,
33
- });
34
- if ('socket' in rpc) {
35
- this.underlyingSocket = (
36
- rpc as ReturnType<typeof RpcWebSocketBrowserFactory>
37
- ).socket;
38
- } else {
39
- this.underlyingSocket = rpc as NodeWebSocketType;
40
- }
41
- return rpc as ICommonWebSocket;
42
- };
43
- super(webSocketFactory, address, options, generate_request_id);
44
- }
45
- call(
46
- ...args: Parameters<RpcWebSocketCommonClient['call']>
47
- ): ReturnType<RpcWebSocketCommonClient['call']> {
48
- const readyState = this.underlyingSocket?.readyState;
49
- if (readyState === 1 /* WebSocket.OPEN */) {
50
- return super.call(...args);
51
- }
52
- return Promise.reject(
53
- new Error(
54
- 'Tried to call a JSON-RPC method `' +
55
- args[0] +
56
- '` but the socket was not `CONNECTING` or `OPEN` (`readyState` was ' +
57
- readyState +
58
- ')',
59
- ),
60
- );
61
- }
62
- notify(
63
- ...args: Parameters<RpcWebSocketCommonClient['notify']>
64
- ): ReturnType<RpcWebSocketCommonClient['notify']> {
65
- const readyState = this.underlyingSocket?.readyState;
66
- if (readyState === 1 /* WebSocket.OPEN */) {
67
- return super.notify(...args);
68
- }
69
- return Promise.reject(
70
- new Error(
71
- 'Tried to send a JSON-RPC notification `' +
72
- args[0] +
73
- '` but the socket was not `CONNECTING` or `OPEN` (`readyState` was ' +
74
- readyState +
75
- ')',
76
- ),
77
- );
78
- }
79
- }
package/src/sysvar.ts DELETED
@@ -1,37 +0,0 @@
1
- import {PublicKey} from './publickey';
2
-
3
- export const SYSVAR_CLOCK_PUBKEY = new PublicKey(
4
- 'SysvarC1ock11111111111111111111111111111111',
5
- );
6
-
7
- export const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey(
8
- 'SysvarEpochSchedu1e111111111111111111111111',
9
- );
10
-
11
- export const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey(
12
- 'Sysvar1nstructions1111111111111111111111111',
13
- );
14
-
15
- export const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey(
16
- 'SysvarRecentB1ockHashes11111111111111111111',
17
- );
18
-
19
- export const SYSVAR_RENT_PUBKEY = new PublicKey(
20
- 'SysvarRent111111111111111111111111111111111',
21
- );
22
-
23
- export const SYSVAR_REWARDS_PUBKEY = new PublicKey(
24
- 'SysvarRewards111111111111111111111111111111',
25
- );
26
-
27
- export const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey(
28
- 'SysvarS1otHashes111111111111111111111111111',
29
- );
30
-
31
- export const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey(
32
- 'SysvarS1otHistory11111111111111111111111111',
33
- );
34
-
35
- export const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey(
36
- 'SysvarStakeHistory1111111111111111111111111',
37
- );
package/src/timing.ts DELETED
@@ -1,23 +0,0 @@
1
- // TODO: These constants should be removed in favor of reading them out of a
2
- // Syscall account
3
-
4
- /**
5
- * @internal
6
- */
7
- export const NUM_TICKS_PER_SECOND = 160;
8
-
9
- /**
10
- * @internal
11
- */
12
- export const DEFAULT_TICKS_PER_SLOT = 64;
13
-
14
- /**
15
- * @internal
16
- */
17
- export const NUM_SLOTS_PER_SECOND =
18
- NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
19
-
20
- /**
21
- * @internal
22
- */
23
- export const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
@@ -1,12 +0,0 @@
1
- /**
2
- * Maximum over-the-wire size of a Transaction
3
- *
4
- * 1280 is IPv6 minimum MTU
5
- * 40 bytes is the size of the IPv6 header
6
- * 8 bytes is the size of the fragment header
7
- */
8
- export const PACKET_DATA_SIZE = 1280 - 40 - 8;
9
-
10
- export const VERSION_PREFIX_MASK = 0x7f;
11
-
12
- export const SIGNATURE_LENGTH_IN_BYTES = 64;
@@ -1,48 +0,0 @@
1
- export class TransactionExpiredBlockheightExceededError extends Error {
2
- signature: string;
3
-
4
- constructor(signature: string) {
5
- super(`Signature ${signature} has expired: block height exceeded.`);
6
- this.signature = signature;
7
- }
8
- }
9
-
10
- Object.defineProperty(
11
- TransactionExpiredBlockheightExceededError.prototype,
12
- 'name',
13
- {
14
- value: 'TransactionExpiredBlockheightExceededError',
15
- },
16
- );
17
-
18
- export class TransactionExpiredTimeoutError extends Error {
19
- signature: string;
20
-
21
- constructor(signature: string, timeoutSeconds: number) {
22
- super(
23
- `Transaction was not confirmed in ${timeoutSeconds.toFixed(
24
- 2,
25
- )} seconds. It is ` +
26
- 'unknown if it succeeded or failed. Check signature ' +
27
- `${signature} using the Solana Explorer or CLI tools.`,
28
- );
29
- this.signature = signature;
30
- }
31
- }
32
-
33
- Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
34
- value: 'TransactionExpiredTimeoutError',
35
- });
36
-
37
- export class TransactionExpiredNonceInvalidError extends Error {
38
- signature: string;
39
-
40
- constructor(signature: string) {
41
- super(`Signature ${signature} has expired: the nonce is no longer valid.`);
42
- this.signature = signature;
43
- }
44
- }
45
-
46
- Object.defineProperty(TransactionExpiredNonceInvalidError.prototype, 'name', {
47
- value: 'TransactionExpiredNonceInvalidError',
48
- });
@@ -1,5 +0,0 @@
1
- export * from './constants';
2
- export * from './expiry-custom-errors';
3
- export * from './legacy';
4
- export * from './message';
5
- export * from './versioned';