@solana/web3.js 1.87.3 → 2.0.0-experimental.0099b2a

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 (113) hide show
  1. package/README.md +56 -112
  2. package/dist/index.browser.cjs +927 -0
  3. package/dist/index.browser.cjs.map +1 -0
  4. package/dist/index.browser.js +876 -0
  5. package/dist/index.browser.js.map +1 -0
  6. package/dist/index.development.js +4180 -0
  7. package/dist/index.development.js.map +1 -0
  8. package/dist/index.native.js +865 -0
  9. package/dist/index.native.js.map +1 -0
  10. package/dist/index.node.cjs +916 -0
  11. package/dist/index.node.cjs.map +1 -0
  12. package/dist/index.node.js +865 -0
  13. package/dist/index.node.js.map +1 -0
  14. package/dist/index.production.min.js +87 -0
  15. package/dist/types/airdrop-confirmer.d.ts +20 -0
  16. package/dist/types/airdrop.d.ts +23 -0
  17. package/dist/types/cached-abortable-iterable.d.ts +11 -0
  18. package/dist/types/index.d.ts +15 -0
  19. package/dist/types/rpc-default-config.d.ts +3 -0
  20. package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
  21. package/dist/types/rpc-request-coalescer.d.ts +5 -0
  22. package/dist/types/rpc-request-deduplication.d.ts +2 -0
  23. package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
  24. package/dist/types/rpc-transport.d.ts +4 -0
  25. package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
  26. package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
  27. package/dist/types/rpc-websocket-transport.d.ts +13 -0
  28. package/dist/types/rpc.d.ts +7 -0
  29. package/dist/types/send-transaction.d.ts +37 -0
  30. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +10 -0
  31. package/dist/types/transaction-confirmation-strategy-nonce.d.ts +15 -0
  32. package/dist/types/transaction-confirmation-strategy-racer.d.ts +14 -0
  33. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +13 -0
  34. package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
  35. package/dist/types/transaction-confirmation.d.ts +37 -0
  36. package/package.json +85 -109
  37. package/lib/index.browser.cjs.js +0 -10296
  38. package/lib/index.browser.cjs.js.map +0 -1
  39. package/lib/index.browser.esm.js +0 -10193
  40. package/lib/index.browser.esm.js.map +0 -1
  41. package/lib/index.cjs.js +0 -12589
  42. package/lib/index.cjs.js.map +0 -1
  43. package/lib/index.d.ts +0 -3947
  44. package/lib/index.esm.js +0 -12480
  45. package/lib/index.esm.js.map +0 -1
  46. package/lib/index.iife.js +0 -26233
  47. package/lib/index.iife.js.map +0 -1
  48. package/lib/index.iife.min.js +0 -20
  49. package/lib/index.iife.min.js.map +0 -1
  50. package/lib/index.native.js +0 -10296
  51. package/lib/index.native.js.map +0 -1
  52. package/src/__forks__/browser/fetch-impl.ts +0 -4
  53. package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
  54. package/src/__forks__/react-native/fetch-impl.ts +0 -4
  55. package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
  56. package/src/account-data.ts +0 -39
  57. package/src/account.ts +0 -55
  58. package/src/blockhash.ts +0 -4
  59. package/src/bpf-loader-deprecated.ts +0 -5
  60. package/src/bpf-loader.ts +0 -45
  61. package/src/connection.ts +0 -6796
  62. package/src/epoch-schedule.ts +0 -102
  63. package/src/errors.ts +0 -50
  64. package/src/fee-calculator.ts +0 -18
  65. package/src/fetch-impl.ts +0 -16
  66. package/src/index.ts +0 -24
  67. package/src/instruction.ts +0 -58
  68. package/src/keypair.ts +0 -102
  69. package/src/layout.ts +0 -188
  70. package/src/loader.ts +0 -267
  71. package/src/message/account-keys.ts +0 -79
  72. package/src/message/compiled-keys.ts +0 -165
  73. package/src/message/index.ts +0 -47
  74. package/src/message/legacy.ts +0 -326
  75. package/src/message/v0.ts +0 -496
  76. package/src/message/versioned.ts +0 -36
  77. package/src/nonce-account.ts +0 -82
  78. package/src/programs/address-lookup-table/index.ts +0 -435
  79. package/src/programs/address-lookup-table/state.ts +0 -84
  80. package/src/programs/compute-budget.ts +0 -281
  81. package/src/programs/ed25519.ts +0 -157
  82. package/src/programs/index.ts +0 -7
  83. package/src/programs/secp256k1.ts +0 -228
  84. package/src/programs/stake.ts +0 -935
  85. package/src/programs/system.ts +0 -1048
  86. package/src/programs/vote.ts +0 -543
  87. package/src/publickey.ts +0 -259
  88. package/src/rpc-websocket-factory.ts +0 -4
  89. package/src/rpc-websocket.ts +0 -79
  90. package/src/sysvar.ts +0 -37
  91. package/src/timing.ts +0 -23
  92. package/src/transaction/constants.ts +0 -12
  93. package/src/transaction/expiry-custom-errors.ts +0 -48
  94. package/src/transaction/index.ts +0 -5
  95. package/src/transaction/legacy.ts +0 -948
  96. package/src/transaction/message.ts +0 -140
  97. package/src/transaction/versioned.ts +0 -126
  98. package/src/utils/assert.ts +0 -8
  99. package/src/utils/bigint.ts +0 -43
  100. package/src/utils/borsh-schema.ts +0 -38
  101. package/src/utils/cluster.ts +0 -35
  102. package/src/utils/ed25519.ts +0 -43
  103. package/src/utils/index.ts +0 -5
  104. package/src/utils/makeWebsocketUrl.ts +0 -26
  105. package/src/utils/promise-timeout.ts +0 -14
  106. package/src/utils/secp256k1.ts +0 -11
  107. package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
  108. package/src/utils/send-and-confirm-transaction.ts +0 -98
  109. package/src/utils/shortvec-encoding.ts +0 -28
  110. package/src/utils/sleep.ts +0 -4
  111. package/src/utils/to-buffer.ts +0 -11
  112. package/src/validator-info.ts +0 -104
  113. package/src/vote-account.ts +0 -236
@@ -1,326 +0,0 @@
1
- import bs58 from 'bs58';
2
- import {Buffer} from 'buffer';
3
- import * as BufferLayout from '@solana/buffer-layout';
4
-
5
- import {PublicKey, PUBLIC_KEY_LENGTH} from '../publickey';
6
- import type {Blockhash} from '../blockhash';
7
- import * as Layout from '../layout';
8
- import {PACKET_DATA_SIZE, VERSION_PREFIX_MASK} from '../transaction/constants';
9
- import * as shortvec from '../utils/shortvec-encoding';
10
- import {toBuffer} from '../utils/to-buffer';
11
- import {
12
- MessageHeader,
13
- MessageAddressTableLookup,
14
- MessageCompiledInstruction,
15
- } from './index';
16
- import {TransactionInstruction} from '../transaction';
17
- import {CompiledKeys} from './compiled-keys';
18
- import {MessageAccountKeys} from './account-keys';
19
-
20
- /**
21
- * An instruction to execute by a program
22
- *
23
- * @property {number} programIdIndex
24
- * @property {number[]} accounts
25
- * @property {string} data
26
- */
27
- export type CompiledInstruction = {
28
- /** Index into the transaction keys array indicating the program account that executes this instruction */
29
- programIdIndex: number;
30
- /** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
31
- accounts: number[];
32
- /** The program input data encoded as base 58 */
33
- data: string;
34
- };
35
-
36
- /**
37
- * Message constructor arguments
38
- */
39
- export type MessageArgs = {
40
- /** The message header, identifying signed and read-only `accountKeys` */
41
- header: MessageHeader;
42
- /** All the account keys used by this transaction */
43
- accountKeys: string[] | PublicKey[];
44
- /** The hash of a recent ledger block */
45
- recentBlockhash: Blockhash;
46
- /** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
47
- instructions: CompiledInstruction[];
48
- };
49
-
50
- export type CompileLegacyArgs = {
51
- payerKey: PublicKey;
52
- instructions: Array<TransactionInstruction>;
53
- recentBlockhash: Blockhash;
54
- };
55
-
56
- /**
57
- * List of instructions to be processed atomically
58
- */
59
- export class Message {
60
- header: MessageHeader;
61
- accountKeys: PublicKey[];
62
- recentBlockhash: Blockhash;
63
- instructions: CompiledInstruction[];
64
-
65
- private indexToProgramIds: Map<number, PublicKey> = new Map<
66
- number,
67
- PublicKey
68
- >();
69
-
70
- constructor(args: MessageArgs) {
71
- this.header = args.header;
72
- this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
73
- this.recentBlockhash = args.recentBlockhash;
74
- this.instructions = args.instructions;
75
- this.instructions.forEach(ix =>
76
- this.indexToProgramIds.set(
77
- ix.programIdIndex,
78
- this.accountKeys[ix.programIdIndex],
79
- ),
80
- );
81
- }
82
-
83
- get version(): 'legacy' {
84
- return 'legacy';
85
- }
86
-
87
- get staticAccountKeys(): Array<PublicKey> {
88
- return this.accountKeys;
89
- }
90
-
91
- get compiledInstructions(): Array<MessageCompiledInstruction> {
92
- return this.instructions.map(
93
- (ix): MessageCompiledInstruction => ({
94
- programIdIndex: ix.programIdIndex,
95
- accountKeyIndexes: ix.accounts,
96
- data: bs58.decode(ix.data),
97
- }),
98
- );
99
- }
100
-
101
- get addressTableLookups(): Array<MessageAddressTableLookup> {
102
- return [];
103
- }
104
-
105
- getAccountKeys(): MessageAccountKeys {
106
- return new MessageAccountKeys(this.staticAccountKeys);
107
- }
108
-
109
- static compile(args: CompileLegacyArgs): Message {
110
- const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
111
- const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
112
- const accountKeys = new MessageAccountKeys(staticAccountKeys);
113
- const instructions = accountKeys.compileInstructions(args.instructions).map(
114
- (ix: MessageCompiledInstruction): CompiledInstruction => ({
115
- programIdIndex: ix.programIdIndex,
116
- accounts: ix.accountKeyIndexes,
117
- data: bs58.encode(ix.data),
118
- }),
119
- );
120
- return new Message({
121
- header,
122
- accountKeys: staticAccountKeys,
123
- recentBlockhash: args.recentBlockhash,
124
- instructions,
125
- });
126
- }
127
-
128
- isAccountSigner(index: number): boolean {
129
- return index < this.header.numRequiredSignatures;
130
- }
131
-
132
- isAccountWritable(index: number): boolean {
133
- const numSignedAccounts = this.header.numRequiredSignatures;
134
- if (index >= this.header.numRequiredSignatures) {
135
- const unsignedAccountIndex = index - numSignedAccounts;
136
- const numUnsignedAccounts = this.accountKeys.length - numSignedAccounts;
137
- const numWritableUnsignedAccounts =
138
- numUnsignedAccounts - this.header.numReadonlyUnsignedAccounts;
139
- return unsignedAccountIndex < numWritableUnsignedAccounts;
140
- } else {
141
- const numWritableSignedAccounts =
142
- numSignedAccounts - this.header.numReadonlySignedAccounts;
143
- return index < numWritableSignedAccounts;
144
- }
145
- }
146
-
147
- isProgramId(index: number): boolean {
148
- return this.indexToProgramIds.has(index);
149
- }
150
-
151
- programIds(): PublicKey[] {
152
- return [...this.indexToProgramIds.values()];
153
- }
154
-
155
- nonProgramIds(): PublicKey[] {
156
- return this.accountKeys.filter((_, index) => !this.isProgramId(index));
157
- }
158
-
159
- serialize(): Buffer {
160
- const numKeys = this.accountKeys.length;
161
-
162
- let keyCount: number[] = [];
163
- shortvec.encodeLength(keyCount, numKeys);
164
-
165
- const instructions = this.instructions.map(instruction => {
166
- const {accounts, programIdIndex} = instruction;
167
- const data = Array.from(bs58.decode(instruction.data));
168
-
169
- let keyIndicesCount: number[] = [];
170
- shortvec.encodeLength(keyIndicesCount, accounts.length);
171
-
172
- let dataCount: number[] = [];
173
- shortvec.encodeLength(dataCount, data.length);
174
-
175
- return {
176
- programIdIndex,
177
- keyIndicesCount: Buffer.from(keyIndicesCount),
178
- keyIndices: accounts,
179
- dataLength: Buffer.from(dataCount),
180
- data,
181
- };
182
- });
183
-
184
- let instructionCount: number[] = [];
185
- shortvec.encodeLength(instructionCount, instructions.length);
186
- let instructionBuffer = Buffer.alloc(PACKET_DATA_SIZE);
187
- Buffer.from(instructionCount).copy(instructionBuffer);
188
- let instructionBufferLength = instructionCount.length;
189
-
190
- instructions.forEach(instruction => {
191
- const instructionLayout = BufferLayout.struct<
192
- Readonly<{
193
- data: number[];
194
- dataLength: Uint8Array;
195
- keyIndices: number[];
196
- keyIndicesCount: Uint8Array;
197
- programIdIndex: number;
198
- }>
199
- >([
200
- BufferLayout.u8('programIdIndex'),
201
-
202
- BufferLayout.blob(
203
- instruction.keyIndicesCount.length,
204
- 'keyIndicesCount',
205
- ),
206
- BufferLayout.seq(
207
- BufferLayout.u8('keyIndex'),
208
- instruction.keyIndices.length,
209
- 'keyIndices',
210
- ),
211
- BufferLayout.blob(instruction.dataLength.length, 'dataLength'),
212
- BufferLayout.seq(
213
- BufferLayout.u8('userdatum'),
214
- instruction.data.length,
215
- 'data',
216
- ),
217
- ]);
218
- const length = instructionLayout.encode(
219
- instruction,
220
- instructionBuffer,
221
- instructionBufferLength,
222
- );
223
- instructionBufferLength += length;
224
- });
225
- instructionBuffer = instructionBuffer.slice(0, instructionBufferLength);
226
-
227
- const signDataLayout = BufferLayout.struct<
228
- Readonly<{
229
- keyCount: Uint8Array;
230
- keys: Uint8Array[];
231
- numReadonlySignedAccounts: Uint8Array;
232
- numReadonlyUnsignedAccounts: Uint8Array;
233
- numRequiredSignatures: Uint8Array;
234
- recentBlockhash: Uint8Array;
235
- }>
236
- >([
237
- BufferLayout.blob(1, 'numRequiredSignatures'),
238
- BufferLayout.blob(1, 'numReadonlySignedAccounts'),
239
- BufferLayout.blob(1, 'numReadonlyUnsignedAccounts'),
240
- BufferLayout.blob(keyCount.length, 'keyCount'),
241
- BufferLayout.seq(Layout.publicKey('key'), numKeys, 'keys'),
242
- Layout.publicKey('recentBlockhash'),
243
- ]);
244
-
245
- const transaction = {
246
- numRequiredSignatures: Buffer.from([this.header.numRequiredSignatures]),
247
- numReadonlySignedAccounts: Buffer.from([
248
- this.header.numReadonlySignedAccounts,
249
- ]),
250
- numReadonlyUnsignedAccounts: Buffer.from([
251
- this.header.numReadonlyUnsignedAccounts,
252
- ]),
253
- keyCount: Buffer.from(keyCount),
254
- keys: this.accountKeys.map(key => toBuffer(key.toBytes())),
255
- recentBlockhash: bs58.decode(this.recentBlockhash),
256
- };
257
-
258
- let signData = Buffer.alloc(2048);
259
- const length = signDataLayout.encode(transaction, signData);
260
- instructionBuffer.copy(signData, length);
261
- return signData.slice(0, length + instructionBuffer.length);
262
- }
263
-
264
- /**
265
- * Decode a compiled message into a Message object.
266
- */
267
- static from(buffer: Buffer | Uint8Array | Array<number>): Message {
268
- // Slice up wire data
269
- let byteArray = [...buffer];
270
-
271
- const numRequiredSignatures = byteArray.shift()!;
272
- if (
273
- numRequiredSignatures !==
274
- (numRequiredSignatures & VERSION_PREFIX_MASK)
275
- ) {
276
- throw new Error(
277
- 'Versioned messages must be deserialized with VersionedMessage.deserialize()',
278
- );
279
- }
280
-
281
- const numReadonlySignedAccounts = byteArray.shift()!;
282
- const numReadonlyUnsignedAccounts = byteArray.shift()!;
283
-
284
- const accountCount = shortvec.decodeLength(byteArray);
285
- let accountKeys = [];
286
- for (let i = 0; i < accountCount; i++) {
287
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
288
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
289
- accountKeys.push(new PublicKey(Buffer.from(account)));
290
- }
291
-
292
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
293
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
294
-
295
- const instructionCount = shortvec.decodeLength(byteArray);
296
- let instructions: CompiledInstruction[] = [];
297
- for (let i = 0; i < instructionCount; i++) {
298
- const programIdIndex = byteArray.shift()!;
299
- const accountCount = shortvec.decodeLength(byteArray);
300
- const accounts = byteArray.slice(0, accountCount);
301
- byteArray = byteArray.slice(accountCount);
302
- const dataLength = shortvec.decodeLength(byteArray);
303
- const dataSlice = byteArray.slice(0, dataLength);
304
- const data = bs58.encode(Buffer.from(dataSlice));
305
- byteArray = byteArray.slice(dataLength);
306
- instructions.push({
307
- programIdIndex,
308
- accounts,
309
- data,
310
- });
311
- }
312
-
313
- const messageArgs = {
314
- header: {
315
- numRequiredSignatures,
316
- numReadonlySignedAccounts,
317
- numReadonlyUnsignedAccounts,
318
- },
319
- recentBlockhash: bs58.encode(Buffer.from(recentBlockhash)),
320
- accountKeys,
321
- instructions,
322
- };
323
-
324
- return new Message(messageArgs);
325
- }
326
- }