@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.
- package/README.md +56 -112
- package/dist/index.browser.cjs +158 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +137 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.development.js +1044 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.js +139 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +158 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +139 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.production.min.js +25 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/rpc-default-config.d.ts +3 -0
- package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
- package/dist/types/rpc-request-coalescer.d.ts +5 -0
- package/dist/types/rpc-request-deduplication.d.ts +2 -0
- package/dist/types/rpc-transport.d.ts +4 -0
- package/dist/types/rpc.d.ts +5 -0
- package/package.json +86 -110
- package/lib/index.browser.cjs.js +0 -9534
- package/lib/index.browser.cjs.js.map +0 -1
- package/lib/index.browser.esm.js +0 -9432
- package/lib/index.browser.esm.js.map +0 -1
- package/lib/index.cjs.js +0 -12058
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.d.ts +0 -3891
- package/lib/index.esm.js +0 -11949
- package/lib/index.esm.js.map +0 -1
- package/lib/index.iife.js +0 -25985
- package/lib/index.iife.js.map +0 -1
- package/lib/index.iife.min.js +0 -20
- package/lib/index.iife.min.js.map +0 -1
- package/lib/index.native.js +0 -9534
- package/lib/index.native.js.map +0 -1
- package/src/__forks__/browser/fetch-impl.ts +0 -4
- package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
- package/src/__forks__/react-native/fetch-impl.ts +0 -4
- package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
- package/src/account-data.ts +0 -39
- package/src/account.ts +0 -55
- package/src/blockhash.ts +0 -4
- package/src/bpf-loader-deprecated.ts +0 -5
- package/src/bpf-loader.ts +0 -45
- package/src/connection.ts +0 -6756
- package/src/epoch-schedule.ts +0 -102
- package/src/errors.ts +0 -50
- package/src/fee-calculator.ts +0 -18
- package/src/fetch-impl.ts +0 -13
- package/src/index.ts +0 -24
- package/src/instruction.ts +0 -58
- package/src/keypair.ts +0 -93
- package/src/layout.ts +0 -188
- package/src/loader.ts +0 -267
- package/src/message/account-keys.ts +0 -79
- package/src/message/compiled-keys.ts +0 -165
- package/src/message/index.ts +0 -47
- package/src/message/legacy.ts +0 -326
- package/src/message/v0.ts +0 -496
- package/src/message/versioned.ts +0 -36
- package/src/nonce-account.ts +0 -82
- package/src/programs/address-lookup-table/index.ts +0 -435
- package/src/programs/address-lookup-table/state.ts +0 -84
- package/src/programs/compute-budget.ts +0 -281
- package/src/programs/ed25519.ts +0 -157
- package/src/programs/index.ts +0 -7
- package/src/programs/secp256k1.ts +0 -228
- package/src/programs/stake.ts +0 -935
- package/src/programs/system.ts +0 -1048
- package/src/programs/vote.ts +0 -543
- package/src/publickey.ts +0 -259
- package/src/rpc-websocket-factory.ts +0 -4
- package/src/rpc-websocket.ts +0 -79
- package/src/sysvar.ts +0 -37
- package/src/timing.ts +0 -23
- package/src/transaction/constants.ts +0 -12
- package/src/transaction/expiry-custom-errors.ts +0 -48
- package/src/transaction/index.ts +0 -5
- package/src/transaction/legacy.ts +0 -918
- package/src/transaction/message.ts +0 -140
- package/src/transaction/versioned.ts +0 -126
- package/src/utils/assert.ts +0 -8
- package/src/utils/bigint.ts +0 -43
- package/src/utils/borsh-schema.ts +0 -38
- package/src/utils/cluster.ts +0 -31
- package/src/utils/ed25519.ts +0 -43
- package/src/utils/index.ts +0 -5
- package/src/utils/makeWebsocketUrl.ts +0 -26
- package/src/utils/promise-timeout.ts +0 -14
- package/src/utils/secp256k1.ts +0 -11
- package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
- package/src/utils/send-and-confirm-transaction.ts +0 -98
- package/src/utils/shortvec-encoding.ts +0 -28
- package/src/utils/sleep.ts +0 -4
- package/src/utils/to-buffer.ts +0 -11
- package/src/validator-info.ts +0 -104
- package/src/vote-account.ts +0 -236
package/src/message/legacy.ts
DELETED
|
@@ -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
|
-
}
|