@solana/web3.js 0.0.0-development → 0.0.0-pr-29130

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 (47) hide show
  1. package/README.md +18 -16
  2. package/lib/index.browser.cjs.js +1955 -1660
  3. package/lib/index.browser.cjs.js.map +1 -1
  4. package/lib/index.browser.esm.js +2058 -1770
  5. package/lib/index.browser.esm.js.map +1 -1
  6. package/lib/index.cjs.js +4733 -1870
  7. package/lib/index.cjs.js.map +1 -1
  8. package/lib/index.d.ts +3451 -2821
  9. package/lib/index.esm.js +4761 -1909
  10. package/lib/index.esm.js.map +1 -1
  11. package/lib/index.iife.js +5212 -5553
  12. package/lib/index.iife.js.map +1 -1
  13. package/lib/index.iife.min.js +7 -14
  14. package/lib/index.iife.min.js.map +1 -1
  15. package/lib/index.native.js +1955 -1660
  16. package/lib/index.native.js.map +1 -1
  17. package/package.json +18 -21
  18. package/src/account.ts +19 -10
  19. package/src/bpf-loader.ts +2 -2
  20. package/src/connection.ts +1377 -185
  21. package/src/epoch-schedule.ts +1 -1
  22. package/src/keypair.ts +20 -25
  23. package/src/layout.ts +29 -0
  24. package/src/message/account-keys.ts +79 -0
  25. package/src/message/compiled-keys.ts +165 -0
  26. package/src/message/index.ts +21 -6
  27. package/src/message/legacy.ts +103 -16
  28. package/src/message/v0.ts +496 -0
  29. package/src/message/versioned.ts +36 -0
  30. package/src/nonce-account.ts +7 -3
  31. package/src/programs/address-lookup-table/state.ts +1 -1
  32. package/src/programs/compute-budget.ts +3 -0
  33. package/src/programs/ed25519.ts +2 -2
  34. package/src/programs/secp256k1.ts +5 -7
  35. package/src/programs/vote.ts +109 -2
  36. package/src/publickey.ts +25 -73
  37. package/src/transaction/constants.ts +2 -0
  38. package/src/transaction/expiry-custom-errors.ts +13 -0
  39. package/src/transaction/index.ts +2 -0
  40. package/src/transaction/legacy.ts +46 -9
  41. package/src/transaction/message.ts +140 -0
  42. package/src/transaction/versioned.ts +126 -0
  43. package/src/utils/ed25519.ts +46 -0
  44. package/src/utils/index.ts +1 -0
  45. package/src/utils/send-and-confirm-raw-transaction.ts +13 -0
  46. package/src/utils/send-and-confirm-transaction.ts +53 -19
  47. package/src/agent-manager.ts +0 -44
@@ -0,0 +1,496 @@
1
+ import bs58 from 'bs58';
2
+ import * as BufferLayout from '@solana/buffer-layout';
3
+
4
+ import * as Layout from '../layout';
5
+ import {Blockhash} from '../blockhash';
6
+ import {
7
+ MessageHeader,
8
+ MessageAddressTableLookup,
9
+ MessageCompiledInstruction,
10
+ } from './index';
11
+ import {PublicKey, PUBLIC_KEY_LENGTH} from '../publickey';
12
+ import * as shortvec from '../utils/shortvec-encoding';
13
+ import assert from '../utils/assert';
14
+ import {PACKET_DATA_SIZE, VERSION_PREFIX_MASK} from '../transaction/constants';
15
+ import {TransactionInstruction} from '../transaction';
16
+ import {AddressLookupTableAccount} from '../programs';
17
+ import {CompiledKeys} from './compiled-keys';
18
+ import {AccountKeysFromLookups, MessageAccountKeys} from './account-keys';
19
+
20
+ /**
21
+ * Message constructor arguments
22
+ */
23
+ export type MessageV0Args = {
24
+ /** The message header, identifying signed and read-only `accountKeys` */
25
+ header: MessageHeader;
26
+ /** The static account keys used by this transaction */
27
+ staticAccountKeys: PublicKey[];
28
+ /** The hash of a recent ledger block */
29
+ recentBlockhash: Blockhash;
30
+ /** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
31
+ compiledInstructions: MessageCompiledInstruction[];
32
+ /** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
33
+ addressTableLookups: MessageAddressTableLookup[];
34
+ };
35
+
36
+ export type CompileV0Args = {
37
+ payerKey: PublicKey;
38
+ instructions: Array<TransactionInstruction>;
39
+ recentBlockhash: Blockhash;
40
+ addressLookupTableAccounts?: Array<AddressLookupTableAccount>;
41
+ };
42
+
43
+ export type GetAccountKeysArgs =
44
+ | {
45
+ accountKeysFromLookups?: AccountKeysFromLookups | null;
46
+ }
47
+ | {
48
+ addressLookupTableAccounts?: AddressLookupTableAccount[] | null;
49
+ };
50
+
51
+ export class MessageV0 {
52
+ header: MessageHeader;
53
+ staticAccountKeys: Array<PublicKey>;
54
+ recentBlockhash: Blockhash;
55
+ compiledInstructions: Array<MessageCompiledInstruction>;
56
+ addressTableLookups: Array<MessageAddressTableLookup>;
57
+
58
+ constructor(args: MessageV0Args) {
59
+ this.header = args.header;
60
+ this.staticAccountKeys = args.staticAccountKeys;
61
+ this.recentBlockhash = args.recentBlockhash;
62
+ this.compiledInstructions = args.compiledInstructions;
63
+ this.addressTableLookups = args.addressTableLookups;
64
+ }
65
+
66
+ get version(): 0 {
67
+ return 0;
68
+ }
69
+
70
+ get numAccountKeysFromLookups(): number {
71
+ let count = 0;
72
+ for (const lookup of this.addressTableLookups) {
73
+ count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
74
+ }
75
+ return count;
76
+ }
77
+
78
+ getAccountKeys(args?: GetAccountKeysArgs): MessageAccountKeys {
79
+ let accountKeysFromLookups: AccountKeysFromLookups | undefined;
80
+ if (
81
+ args &&
82
+ 'accountKeysFromLookups' in args &&
83
+ args.accountKeysFromLookups
84
+ ) {
85
+ if (
86
+ this.numAccountKeysFromLookups !=
87
+ args.accountKeysFromLookups.writable.length +
88
+ args.accountKeysFromLookups.readonly.length
89
+ ) {
90
+ throw new Error(
91
+ 'Failed to get account keys because of a mismatch in the number of account keys from lookups',
92
+ );
93
+ }
94
+ accountKeysFromLookups = args.accountKeysFromLookups;
95
+ } else if (
96
+ args &&
97
+ 'addressLookupTableAccounts' in args &&
98
+ args.addressLookupTableAccounts
99
+ ) {
100
+ accountKeysFromLookups = this.resolveAddressTableLookups(
101
+ args.addressLookupTableAccounts,
102
+ );
103
+ } else if (this.addressTableLookups.length > 0) {
104
+ throw new Error(
105
+ 'Failed to get account keys because address table lookups were not resolved',
106
+ );
107
+ }
108
+ return new MessageAccountKeys(
109
+ this.staticAccountKeys,
110
+ accountKeysFromLookups,
111
+ );
112
+ }
113
+
114
+ isAccountSigner(index: number): boolean {
115
+ return index < this.header.numRequiredSignatures;
116
+ }
117
+
118
+ isAccountWritable(index: number): boolean {
119
+ const numSignedAccounts = this.header.numRequiredSignatures;
120
+ const numStaticAccountKeys = this.staticAccountKeys.length;
121
+ if (index >= numStaticAccountKeys) {
122
+ const lookupAccountKeysIndex = index - numStaticAccountKeys;
123
+ const numWritableLookupAccountKeys = this.addressTableLookups.reduce(
124
+ (count, lookup) => count + lookup.writableIndexes.length,
125
+ 0,
126
+ );
127
+ return lookupAccountKeysIndex < numWritableLookupAccountKeys;
128
+ } else if (index >= this.header.numRequiredSignatures) {
129
+ const unsignedAccountIndex = index - numSignedAccounts;
130
+ const numUnsignedAccounts = numStaticAccountKeys - numSignedAccounts;
131
+ const numWritableUnsignedAccounts =
132
+ numUnsignedAccounts - this.header.numReadonlyUnsignedAccounts;
133
+ return unsignedAccountIndex < numWritableUnsignedAccounts;
134
+ } else {
135
+ const numWritableSignedAccounts =
136
+ numSignedAccounts - this.header.numReadonlySignedAccounts;
137
+ return index < numWritableSignedAccounts;
138
+ }
139
+ }
140
+
141
+ resolveAddressTableLookups(
142
+ addressLookupTableAccounts: AddressLookupTableAccount[],
143
+ ): AccountKeysFromLookups {
144
+ const accountKeysFromLookups: AccountKeysFromLookups = {
145
+ writable: [],
146
+ readonly: [],
147
+ };
148
+
149
+ for (const tableLookup of this.addressTableLookups) {
150
+ const tableAccount = addressLookupTableAccounts.find(account =>
151
+ account.key.equals(tableLookup.accountKey),
152
+ );
153
+ if (!tableAccount) {
154
+ throw new Error(
155
+ `Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`,
156
+ );
157
+ }
158
+
159
+ for (const index of tableLookup.writableIndexes) {
160
+ if (index < tableAccount.state.addresses.length) {
161
+ accountKeysFromLookups.writable.push(
162
+ tableAccount.state.addresses[index],
163
+ );
164
+ } else {
165
+ throw new Error(
166
+ `Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`,
167
+ );
168
+ }
169
+ }
170
+
171
+ for (const index of tableLookup.readonlyIndexes) {
172
+ if (index < tableAccount.state.addresses.length) {
173
+ accountKeysFromLookups.readonly.push(
174
+ tableAccount.state.addresses[index],
175
+ );
176
+ } else {
177
+ throw new Error(
178
+ `Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`,
179
+ );
180
+ }
181
+ }
182
+ }
183
+
184
+ return accountKeysFromLookups;
185
+ }
186
+
187
+ static compile(args: CompileV0Args): MessageV0 {
188
+ const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
189
+
190
+ const addressTableLookups = new Array<MessageAddressTableLookup>();
191
+ const accountKeysFromLookups: AccountKeysFromLookups = {
192
+ writable: new Array(),
193
+ readonly: new Array(),
194
+ };
195
+ const lookupTableAccounts = args.addressLookupTableAccounts || [];
196
+ for (const lookupTable of lookupTableAccounts) {
197
+ const extractResult = compiledKeys.extractTableLookup(lookupTable);
198
+ if (extractResult !== undefined) {
199
+ const [addressTableLookup, {writable, readonly}] = extractResult;
200
+ addressTableLookups.push(addressTableLookup);
201
+ accountKeysFromLookups.writable.push(...writable);
202
+ accountKeysFromLookups.readonly.push(...readonly);
203
+ }
204
+ }
205
+
206
+ const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
207
+ const accountKeys = new MessageAccountKeys(
208
+ staticAccountKeys,
209
+ accountKeysFromLookups,
210
+ );
211
+ const compiledInstructions = accountKeys.compileInstructions(
212
+ args.instructions,
213
+ );
214
+ return new MessageV0({
215
+ header,
216
+ staticAccountKeys,
217
+ recentBlockhash: args.recentBlockhash,
218
+ compiledInstructions,
219
+ addressTableLookups,
220
+ });
221
+ }
222
+
223
+ serialize(): Uint8Array {
224
+ const encodedStaticAccountKeysLength = Array<number>();
225
+ shortvec.encodeLength(
226
+ encodedStaticAccountKeysLength,
227
+ this.staticAccountKeys.length,
228
+ );
229
+
230
+ const serializedInstructions = this.serializeInstructions();
231
+ const encodedInstructionsLength = Array<number>();
232
+ shortvec.encodeLength(
233
+ encodedInstructionsLength,
234
+ this.compiledInstructions.length,
235
+ );
236
+
237
+ const serializedAddressTableLookups = this.serializeAddressTableLookups();
238
+ const encodedAddressTableLookupsLength = Array<number>();
239
+ shortvec.encodeLength(
240
+ encodedAddressTableLookupsLength,
241
+ this.addressTableLookups.length,
242
+ );
243
+
244
+ const messageLayout = BufferLayout.struct<{
245
+ prefix: number;
246
+ header: MessageHeader;
247
+ staticAccountKeysLength: Uint8Array;
248
+ staticAccountKeys: Array<Uint8Array>;
249
+ recentBlockhash: Uint8Array;
250
+ instructionsLength: Uint8Array;
251
+ serializedInstructions: Uint8Array;
252
+ addressTableLookupsLength: Uint8Array;
253
+ serializedAddressTableLookups: Uint8Array;
254
+ }>([
255
+ BufferLayout.u8('prefix'),
256
+ BufferLayout.struct<MessageHeader>(
257
+ [
258
+ BufferLayout.u8('numRequiredSignatures'),
259
+ BufferLayout.u8('numReadonlySignedAccounts'),
260
+ BufferLayout.u8('numReadonlyUnsignedAccounts'),
261
+ ],
262
+ 'header',
263
+ ),
264
+ BufferLayout.blob(
265
+ encodedStaticAccountKeysLength.length,
266
+ 'staticAccountKeysLength',
267
+ ),
268
+ BufferLayout.seq(
269
+ Layout.publicKey(),
270
+ this.staticAccountKeys.length,
271
+ 'staticAccountKeys',
272
+ ),
273
+ Layout.publicKey('recentBlockhash'),
274
+ BufferLayout.blob(encodedInstructionsLength.length, 'instructionsLength'),
275
+ BufferLayout.blob(
276
+ serializedInstructions.length,
277
+ 'serializedInstructions',
278
+ ),
279
+ BufferLayout.blob(
280
+ encodedAddressTableLookupsLength.length,
281
+ 'addressTableLookupsLength',
282
+ ),
283
+ BufferLayout.blob(
284
+ serializedAddressTableLookups.length,
285
+ 'serializedAddressTableLookups',
286
+ ),
287
+ ]);
288
+
289
+ const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
290
+ const MESSAGE_VERSION_0_PREFIX = 1 << 7;
291
+ const serializedMessageLength = messageLayout.encode(
292
+ {
293
+ prefix: MESSAGE_VERSION_0_PREFIX,
294
+ header: this.header,
295
+ staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
296
+ staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
297
+ recentBlockhash: bs58.decode(this.recentBlockhash),
298
+ instructionsLength: new Uint8Array(encodedInstructionsLength),
299
+ serializedInstructions,
300
+ addressTableLookupsLength: new Uint8Array(
301
+ encodedAddressTableLookupsLength,
302
+ ),
303
+ serializedAddressTableLookups,
304
+ },
305
+ serializedMessage,
306
+ );
307
+ return serializedMessage.slice(0, serializedMessageLength);
308
+ }
309
+
310
+ private serializeInstructions(): Uint8Array {
311
+ let serializedLength = 0;
312
+ const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
313
+ for (const instruction of this.compiledInstructions) {
314
+ const encodedAccountKeyIndexesLength = Array<number>();
315
+ shortvec.encodeLength(
316
+ encodedAccountKeyIndexesLength,
317
+ instruction.accountKeyIndexes.length,
318
+ );
319
+
320
+ const encodedDataLength = Array<number>();
321
+ shortvec.encodeLength(encodedDataLength, instruction.data.length);
322
+
323
+ const instructionLayout = BufferLayout.struct<{
324
+ programIdIndex: number;
325
+ encodedAccountKeyIndexesLength: Uint8Array;
326
+ accountKeyIndexes: number[];
327
+ encodedDataLength: Uint8Array;
328
+ data: Uint8Array;
329
+ }>([
330
+ BufferLayout.u8('programIdIndex'),
331
+ BufferLayout.blob(
332
+ encodedAccountKeyIndexesLength.length,
333
+ 'encodedAccountKeyIndexesLength',
334
+ ),
335
+ BufferLayout.seq(
336
+ BufferLayout.u8(),
337
+ instruction.accountKeyIndexes.length,
338
+ 'accountKeyIndexes',
339
+ ),
340
+ BufferLayout.blob(encodedDataLength.length, 'encodedDataLength'),
341
+ BufferLayout.blob(instruction.data.length, 'data'),
342
+ ]);
343
+
344
+ serializedLength += instructionLayout.encode(
345
+ {
346
+ programIdIndex: instruction.programIdIndex,
347
+ encodedAccountKeyIndexesLength: new Uint8Array(
348
+ encodedAccountKeyIndexesLength,
349
+ ),
350
+ accountKeyIndexes: instruction.accountKeyIndexes,
351
+ encodedDataLength: new Uint8Array(encodedDataLength),
352
+ data: instruction.data,
353
+ },
354
+ serializedInstructions,
355
+ serializedLength,
356
+ );
357
+ }
358
+
359
+ return serializedInstructions.slice(0, serializedLength);
360
+ }
361
+
362
+ private serializeAddressTableLookups(): Uint8Array {
363
+ let serializedLength = 0;
364
+ const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
365
+ for (const lookup of this.addressTableLookups) {
366
+ const encodedWritableIndexesLength = Array<number>();
367
+ shortvec.encodeLength(
368
+ encodedWritableIndexesLength,
369
+ lookup.writableIndexes.length,
370
+ );
371
+
372
+ const encodedReadonlyIndexesLength = Array<number>();
373
+ shortvec.encodeLength(
374
+ encodedReadonlyIndexesLength,
375
+ lookup.readonlyIndexes.length,
376
+ );
377
+
378
+ const addressTableLookupLayout = BufferLayout.struct<{
379
+ accountKey: Uint8Array;
380
+ encodedWritableIndexesLength: Uint8Array;
381
+ writableIndexes: number[];
382
+ encodedReadonlyIndexesLength: Uint8Array;
383
+ readonlyIndexes: number[];
384
+ }>([
385
+ Layout.publicKey('accountKey'),
386
+ BufferLayout.blob(
387
+ encodedWritableIndexesLength.length,
388
+ 'encodedWritableIndexesLength',
389
+ ),
390
+ BufferLayout.seq(
391
+ BufferLayout.u8(),
392
+ lookup.writableIndexes.length,
393
+ 'writableIndexes',
394
+ ),
395
+ BufferLayout.blob(
396
+ encodedReadonlyIndexesLength.length,
397
+ 'encodedReadonlyIndexesLength',
398
+ ),
399
+ BufferLayout.seq(
400
+ BufferLayout.u8(),
401
+ lookup.readonlyIndexes.length,
402
+ 'readonlyIndexes',
403
+ ),
404
+ ]);
405
+
406
+ serializedLength += addressTableLookupLayout.encode(
407
+ {
408
+ accountKey: lookup.accountKey.toBytes(),
409
+ encodedWritableIndexesLength: new Uint8Array(
410
+ encodedWritableIndexesLength,
411
+ ),
412
+ writableIndexes: lookup.writableIndexes,
413
+ encodedReadonlyIndexesLength: new Uint8Array(
414
+ encodedReadonlyIndexesLength,
415
+ ),
416
+ readonlyIndexes: lookup.readonlyIndexes,
417
+ },
418
+ serializedAddressTableLookups,
419
+ serializedLength,
420
+ );
421
+ }
422
+
423
+ return serializedAddressTableLookups.slice(0, serializedLength);
424
+ }
425
+
426
+ static deserialize(serializedMessage: Uint8Array): MessageV0 {
427
+ let byteArray = [...serializedMessage];
428
+
429
+ const prefix = byteArray.shift() as number;
430
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK;
431
+ assert(
432
+ prefix !== maskedPrefix,
433
+ `Expected versioned message but received legacy message`,
434
+ );
435
+
436
+ const version = maskedPrefix;
437
+ assert(
438
+ version === 0,
439
+ `Expected versioned message with version 0 but found version ${version}`,
440
+ );
441
+
442
+ const header: MessageHeader = {
443
+ numRequiredSignatures: byteArray.shift() as number,
444
+ numReadonlySignedAccounts: byteArray.shift() as number,
445
+ numReadonlyUnsignedAccounts: byteArray.shift() as number,
446
+ };
447
+
448
+ const staticAccountKeys = [];
449
+ const staticAccountKeysLength = shortvec.decodeLength(byteArray);
450
+ for (let i = 0; i < staticAccountKeysLength; i++) {
451
+ staticAccountKeys.push(
452
+ new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)),
453
+ );
454
+ }
455
+
456
+ const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
457
+
458
+ const instructionCount = shortvec.decodeLength(byteArray);
459
+ const compiledInstructions: MessageCompiledInstruction[] = [];
460
+ for (let i = 0; i < instructionCount; i++) {
461
+ const programIdIndex = byteArray.shift() as number;
462
+ const accountKeyIndexesLength = shortvec.decodeLength(byteArray);
463
+ const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
464
+ const dataLength = shortvec.decodeLength(byteArray);
465
+ const data = new Uint8Array(byteArray.splice(0, dataLength));
466
+ compiledInstructions.push({
467
+ programIdIndex,
468
+ accountKeyIndexes,
469
+ data,
470
+ });
471
+ }
472
+
473
+ const addressTableLookupsCount = shortvec.decodeLength(byteArray);
474
+ const addressTableLookups: MessageAddressTableLookup[] = [];
475
+ for (let i = 0; i < addressTableLookupsCount; i++) {
476
+ const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
477
+ const writableIndexesLength = shortvec.decodeLength(byteArray);
478
+ const writableIndexes = byteArray.splice(0, writableIndexesLength);
479
+ const readonlyIndexesLength = shortvec.decodeLength(byteArray);
480
+ const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
481
+ addressTableLookups.push({
482
+ accountKey,
483
+ writableIndexes,
484
+ readonlyIndexes,
485
+ });
486
+ }
487
+
488
+ return new MessageV0({
489
+ header,
490
+ staticAccountKeys,
491
+ recentBlockhash,
492
+ compiledInstructions,
493
+ addressTableLookups,
494
+ });
495
+ }
496
+ }
@@ -0,0 +1,36 @@
1
+ import {VERSION_PREFIX_MASK} from '../transaction/constants';
2
+ import {Message} from './legacy';
3
+ import {MessageV0} from './v0';
4
+
5
+ export type VersionedMessage = Message | MessageV0;
6
+ // eslint-disable-next-line no-redeclare
7
+ export const VersionedMessage = {
8
+ deserializeMessageVersion(serializedMessage: Uint8Array): 'legacy' | number {
9
+ const prefix = serializedMessage[0];
10
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK;
11
+
12
+ // if the highest bit of the prefix is not set, the message is not versioned
13
+ if (maskedPrefix === prefix) {
14
+ return 'legacy';
15
+ }
16
+
17
+ // the lower 7 bits of the prefix indicate the message version
18
+ return maskedPrefix;
19
+ },
20
+
21
+ deserialize: (serializedMessage: Uint8Array): VersionedMessage => {
22
+ const version =
23
+ VersionedMessage.deserializeMessageVersion(serializedMessage);
24
+ if (version === 'legacy') {
25
+ return Message.from(serializedMessage);
26
+ }
27
+
28
+ if (version === 0) {
29
+ return MessageV0.deserialize(serializedMessage);
30
+ } else {
31
+ throw new Error(
32
+ `Transaction message version ${version} deserialization is not supported`,
33
+ );
34
+ }
35
+ },
36
+ };
@@ -1,7 +1,6 @@
1
1
  import * as BufferLayout from '@solana/buffer-layout';
2
2
  import {Buffer} from 'buffer';
3
3
 
4
- import type {Blockhash} from './blockhash';
5
4
  import * as Layout from './layout';
6
5
  import {PublicKey} from './publickey';
7
6
  import type {FeeCalculator} from './fee-calculator';
@@ -36,9 +35,14 @@ const NonceAccountLayout = BufferLayout.struct<
36
35
 
37
36
  export const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
38
37
 
38
+ /**
39
+ * A durable nonce is a 32 byte value encoded as a base58 string.
40
+ */
41
+ export type DurableNonce = string;
42
+
39
43
  type NonceAccountArgs = {
40
44
  authorizedPubkey: PublicKey;
41
- nonce: Blockhash;
45
+ nonce: DurableNonce;
42
46
  feeCalculator: FeeCalculator;
43
47
  };
44
48
 
@@ -47,7 +51,7 @@ type NonceAccountArgs = {
47
51
  */
48
52
  export class NonceAccount {
49
53
  authorizedPubkey: PublicKey;
50
- nonce: Blockhash;
54
+ nonce: DurableNonce;
51
55
  feeCalculator: FeeCalculator;
52
56
 
53
57
  /**
@@ -32,7 +32,7 @@ export class AddressLookupTableAccount {
32
32
  }
33
33
 
34
34
  isActive(): boolean {
35
- const U64_MAX = 2n ** 64n - 1n;
35
+ const U64_MAX = BigInt('0xffffffffffffffff');
36
36
  return this.state.deactivationSlot === U64_MAX;
37
37
  }
38
38
 
@@ -228,6 +228,9 @@ export class ComputeBudgetProgram {
228
228
  'ComputeBudget111111111111111111111111111111',
229
229
  );
230
230
 
231
+ /**
232
+ * @deprecated Instead, call {@link setComputeUnitLimit} and/or {@link setComputeUnitPrice}
233
+ */
231
234
  static requestUnits(params: RequestUnitsParams): TransactionInstruction {
232
235
  const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits;
233
236
  const data = encodeData(type, params);
@@ -1,11 +1,11 @@
1
1
  import {Buffer} from 'buffer';
2
2
  import * as BufferLayout from '@solana/buffer-layout';
3
- import nacl from 'tweetnacl';
4
3
 
5
4
  import {Keypair} from '../keypair';
6
5
  import {PublicKey} from '../publickey';
7
6
  import {TransactionInstruction} from '../transaction';
8
7
  import assert from '../utils/assert';
8
+ import {sign} from '../utils/ed25519';
9
9
 
10
10
  const PRIVATE_KEY_BYTES = 64;
11
11
  const PUBLIC_KEY_BYTES = 32;
@@ -142,7 +142,7 @@ export class Ed25519Program {
142
142
  try {
143
143
  const keypair = Keypair.fromSecretKey(privateKey);
144
144
  const publicKey = keypair.publicKey.toBytes();
145
- const signature = nacl.sign.detached(message, keypair.secretKey);
145
+ const signature = sign(message, keypair.secretKey);
146
146
 
147
147
  return this.createInstructionWithPublicKey({
148
148
  publicKey,
@@ -1,6 +1,6 @@
1
1
  import {Buffer} from 'buffer';
2
2
  import * as BufferLayout from '@solana/buffer-layout';
3
- import sha3 from 'js-sha3';
3
+ import {keccak_256} from '@noble/hashes/sha3';
4
4
 
5
5
  import {PublicKey} from '../publickey';
6
6
  import {TransactionInstruction} from '../transaction';
@@ -98,9 +98,9 @@ export class Secp256k1Program {
98
98
  );
99
99
 
100
100
  try {
101
- return Buffer.from(
102
- sha3.keccak_256.update(toBuffer(publicKey)).digest(),
103
- ).slice(-ETHEREUM_ADDRESS_BYTES);
101
+ return Buffer.from(keccak_256(toBuffer(publicKey))).slice(
102
+ -ETHEREUM_ADDRESS_BYTES,
103
+ );
104
104
  } catch (error) {
105
105
  throw new Error(`Error constructing Ethereum address: ${error}`);
106
106
  }
@@ -211,9 +211,7 @@ export class Secp256k1Program {
211
211
  privateKey,
212
212
  false /* isCompressed */,
213
213
  ).slice(1); // throw away leading byte
214
- const messageHash = Buffer.from(
215
- sha3.keccak_256.update(toBuffer(message)).digest(),
216
- );
214
+ const messageHash = Buffer.from(keccak_256(toBuffer(message)));
217
215
  const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
218
216
 
219
217
  return this.createInstructionWithPublicKey({