@solana/transactions 2.0.0-experimental.cf6ca9d → 2.0.0-experimental.d06660c

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 (69) hide show
  1. package/README.md +8 -46
  2. package/dist/index.browser.cjs +343 -451
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +335 -450
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.native.js +335 -450
  7. package/dist/index.native.js.map +1 -1
  8. package/dist/index.node.cjs +343 -451
  9. package/dist/index.node.cjs.map +1 -1
  10. package/dist/index.node.js +337 -450
  11. package/dist/index.node.js.map +1 -1
  12. package/dist/types/accounts.d.ts +2 -2
  13. package/dist/types/accounts.d.ts.map +1 -0
  14. package/dist/types/blockhash.d.ts +5 -7
  15. package/dist/types/blockhash.d.ts.map +1 -0
  16. package/dist/types/compilable-transaction.d.ts +7 -0
  17. package/dist/types/compilable-transaction.d.ts.map +1 -0
  18. package/dist/types/compile-address-table-lookups.d.ts +3 -3
  19. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  20. package/dist/types/compile-header.d.ts +1 -1
  21. package/dist/types/compile-header.d.ts.map +1 -0
  22. package/dist/types/compile-instructions.d.ts +1 -1
  23. package/dist/types/compile-instructions.d.ts.map +1 -0
  24. package/dist/types/compile-lifetime-token.d.ts +1 -1
  25. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  26. package/dist/types/compile-static-accounts.d.ts +3 -3
  27. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  28. package/dist/types/compile-transaction.d.ts +6 -7
  29. package/dist/types/compile-transaction.d.ts.map +1 -0
  30. package/dist/types/create-transaction.d.ts +1 -1
  31. package/dist/types/create-transaction.d.ts.map +1 -0
  32. package/dist/types/decompile-transaction.d.ts +12 -6
  33. package/dist/types/decompile-transaction.d.ts.map +1 -0
  34. package/dist/types/durable-nonce.d.ts +5 -5
  35. package/dist/types/durable-nonce.d.ts.map +1 -0
  36. package/dist/types/fee-payer.d.ts +6 -6
  37. package/dist/types/fee-payer.d.ts.map +1 -0
  38. package/dist/types/index.d.ts +13 -9
  39. package/dist/types/index.d.ts.map +1 -0
  40. package/dist/types/instructions.d.ts +4 -2
  41. package/dist/types/instructions.d.ts.map +1 -0
  42. package/dist/types/message.d.ts +6 -10
  43. package/dist/types/message.d.ts.map +1 -0
  44. package/dist/types/serializers/address-table-lookup.d.ts +5 -5
  45. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  46. package/dist/types/serializers/header.d.ts +5 -5
  47. package/dist/types/serializers/header.d.ts.map +1 -0
  48. package/dist/types/serializers/index.d.ts +2 -1
  49. package/dist/types/serializers/index.d.ts.map +1 -0
  50. package/dist/types/serializers/instruction.d.ts +5 -5
  51. package/dist/types/serializers/instruction.d.ts.map +1 -0
  52. package/dist/types/serializers/message.d.ts +5 -5
  53. package/dist/types/serializers/message.d.ts.map +1 -0
  54. package/dist/types/serializers/transaction-version.d.ts +5 -5
  55. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  56. package/dist/types/serializers/transaction.d.ts +9 -8
  57. package/dist/types/serializers/transaction.d.ts.map +1 -0
  58. package/dist/types/signatures.d.ts +9 -14
  59. package/dist/types/signatures.d.ts.map +1 -0
  60. package/dist/types/types.d.ts +6 -13
  61. package/dist/types/types.d.ts.map +1 -0
  62. package/dist/types/unsigned-transaction.d.ts +1 -1
  63. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  64. package/dist/types/wire-transaction.d.ts +1 -1
  65. package/dist/types/wire-transaction.d.ts.map +1 -0
  66. package/package.json +18 -40
  67. package/dist/index.development.js +0 -1841
  68. package/dist/index.development.js.map +0 -1
  69. package/dist/index.production.min.js +0 -29
@@ -1,33 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var umiSerializers = require('@metaplex-foundation/umi-serializers');
3
+ var codecsStrings = require('@solana/codecs-strings');
4
+ var addresses = require('@solana/addresses');
5
+ var functional = require('@solana/functional');
4
6
  var codecsCore = require('@solana/codecs-core');
5
7
  var codecsDataStructures = require('@solana/codecs-data-structures');
6
8
  var codecsNumbers = require('@solana/codecs-numbers');
7
- var addresses = require('@solana/addresses');
8
- var functional = require('@solana/functional');
9
- var codecsStrings = require('@solana/codecs-strings');
9
+ var errors = require('@solana/errors');
10
10
  var keys = require('@solana/keys');
11
11
 
12
- // ../build-scripts/env-shim.ts
13
- var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
14
-
15
- // src/unsigned-transaction.ts
16
- function getUnsignedTransaction(transaction) {
17
- if ("signatures" in transaction) {
18
- const {
19
- signatures: _,
20
- // eslint-disable-line @typescript-eslint/no-unused-vars
21
- ...unsignedTransaction
22
- } = transaction;
23
- return unsignedTransaction;
24
- } else {
25
- return transaction;
26
- }
27
- }
28
-
29
- // src/blockhash.ts
12
+ // ../rpc-types/dist/index.browser.js
13
+ var base58Encoder;
30
14
  function assertIsBlockhash(putativeBlockhash) {
15
+ if (!base58Encoder)
16
+ base58Encoder = codecsStrings.getBase58Encoder();
31
17
  try {
32
18
  if (
33
19
  // Lowest value (32 bytes of zeroes)
@@ -36,7 +22,7 @@ function assertIsBlockhash(putativeBlockhash) {
36
22
  ) {
37
23
  throw new Error("Expected input string to decode to a byte array of length 32.");
38
24
  }
39
- const bytes = umiSerializers.base58.serialize(putativeBlockhash);
25
+ const bytes = base58Encoder.encode(putativeBlockhash);
40
26
  const numBytes = bytes.byteLength;
41
27
  if (numBytes !== 32) {
42
28
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
@@ -47,6 +33,38 @@ function assertIsBlockhash(putativeBlockhash) {
47
33
  });
48
34
  }
49
35
  }
36
+
37
+ // src/unsigned-transaction.ts
38
+ function getUnsignedTransaction(transaction) {
39
+ if ("signatures" in transaction) {
40
+ const {
41
+ signatures: _,
42
+ // eslint-disable-line @typescript-eslint/no-unused-vars
43
+ ...unsignedTransaction
44
+ } = transaction;
45
+ return unsignedTransaction;
46
+ } else {
47
+ return transaction;
48
+ }
49
+ }
50
+
51
+ // src/blockhash.ts
52
+ function isTransactionWithBlockhashLifetime(transaction) {
53
+ const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
54
+ if (!lifetimeConstraintShapeMatches)
55
+ return false;
56
+ try {
57
+ assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
58
+ return true;
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+ function assertIsTransactionWithBlockhashLifetime(transaction) {
64
+ if (!isTransactionWithBlockhashLifetime(transaction)) {
65
+ throw new Error("Transaction does not have a blockhash lifetime");
66
+ }
67
+ }
50
68
  function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
51
69
  if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
52
70
  return transaction;
@@ -185,21 +203,172 @@ function setTransactionFeePayer(feePayer, transaction) {
185
203
 
186
204
  // src/instructions.ts
187
205
  function appendTransactionInstruction(instruction, transaction) {
206
+ return appendTransactionInstructions([instruction], transaction);
207
+ }
208
+ function appendTransactionInstructions(instructions, transaction) {
188
209
  const out = {
189
210
  ...getUnsignedTransaction(transaction),
190
- instructions: [...transaction.instructions, instruction]
211
+ instructions: [...transaction.instructions, ...instructions]
191
212
  };
192
213
  Object.freeze(out);
193
214
  return out;
194
215
  }
195
216
  function prependTransactionInstruction(instruction, transaction) {
217
+ return prependTransactionInstructions([instruction], transaction);
218
+ }
219
+ function prependTransactionInstructions(instructions, transaction) {
196
220
  const out = {
197
221
  ...getUnsignedTransaction(transaction),
198
- instructions: [instruction, ...transaction.instructions]
222
+ instructions: [...instructions, ...transaction.instructions]
199
223
  };
200
224
  Object.freeze(out);
201
225
  return out;
202
226
  }
227
+
228
+ // src/decompile-transaction.ts
229
+ function getAccountMetas(message) {
230
+ const { header } = message;
231
+ const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
232
+ const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
233
+ const accountMetas = [];
234
+ let accountIndex = 0;
235
+ for (let i = 0; i < numWritableSignerAccounts; i++) {
236
+ accountMetas.push({
237
+ address: message.staticAccounts[accountIndex],
238
+ role: AccountRole.WRITABLE_SIGNER
239
+ });
240
+ accountIndex++;
241
+ }
242
+ for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
243
+ accountMetas.push({
244
+ address: message.staticAccounts[accountIndex],
245
+ role: AccountRole.READONLY_SIGNER
246
+ });
247
+ accountIndex++;
248
+ }
249
+ for (let i = 0; i < numWritableNonSignerAccounts; i++) {
250
+ accountMetas.push({
251
+ address: message.staticAccounts[accountIndex],
252
+ role: AccountRole.WRITABLE
253
+ });
254
+ accountIndex++;
255
+ }
256
+ for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
257
+ accountMetas.push({
258
+ address: message.staticAccounts[accountIndex],
259
+ role: AccountRole.READONLY
260
+ });
261
+ accountIndex++;
262
+ }
263
+ return accountMetas;
264
+ }
265
+ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTableAddress) {
266
+ const compiledAddressTableLookupAddresses = compiledAddressTableLookups.map((l) => l.lookupTableAddress);
267
+ const missing = compiledAddressTableLookupAddresses.filter((a) => addressesByLookupTableAddress[a] === void 0);
268
+ if (missing.length > 0) {
269
+ const missingAddresses = missing.join(", ");
270
+ throw new Error(`Addresses not provided for lookup tables: [${missingAddresses}]`);
271
+ }
272
+ const readOnlyMetas = [];
273
+ const writableMetas = [];
274
+ for (const lookup of compiledAddressTableLookups) {
275
+ const addresses = addressesByLookupTableAddress[lookup.lookupTableAddress];
276
+ const highestIndex = Math.max(...lookup.readableIndices, ...lookup.writableIndices);
277
+ if (highestIndex >= addresses.length) {
278
+ throw new Error(
279
+ `Cannot look up index ${highestIndex} in lookup table [${lookup.lookupTableAddress}]. The lookup table may have been extended since the addresses provided were retrieved.`
280
+ );
281
+ }
282
+ const readOnlyForLookup = lookup.readableIndices.map((r) => ({
283
+ address: addresses[r],
284
+ addressIndex: r,
285
+ lookupTableAddress: lookup.lookupTableAddress,
286
+ role: AccountRole.READONLY
287
+ }));
288
+ readOnlyMetas.push(...readOnlyForLookup);
289
+ const writableForLookup = lookup.writableIndices.map((w) => ({
290
+ address: addresses[w],
291
+ addressIndex: w,
292
+ lookupTableAddress: lookup.lookupTableAddress,
293
+ role: AccountRole.WRITABLE
294
+ }));
295
+ writableMetas.push(...writableForLookup);
296
+ }
297
+ return [...writableMetas, ...readOnlyMetas];
298
+ }
299
+ function convertInstruction(instruction, accountMetas) {
300
+ const programAddress = accountMetas[instruction.programAddressIndex]?.address;
301
+ if (!programAddress) {
302
+ throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
303
+ }
304
+ const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
305
+ const { data } = instruction;
306
+ return {
307
+ programAddress,
308
+ ...accounts && accounts.length ? { accounts } : {},
309
+ ...data && data.length ? { data } : {}
310
+ };
311
+ }
312
+ function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
313
+ if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
314
+ return {
315
+ blockhash: messageLifetimeToken,
316
+ lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
317
+ // U64 MAX
318
+ };
319
+ } else {
320
+ const nonceAccountAddress = firstInstruction.accounts[0].address;
321
+ addresses.assertIsAddress(nonceAccountAddress);
322
+ const nonceAuthorityAddress = firstInstruction.accounts[2].address;
323
+ addresses.assertIsAddress(nonceAuthorityAddress);
324
+ return {
325
+ nonce: messageLifetimeToken,
326
+ nonceAccountAddress,
327
+ nonceAuthorityAddress
328
+ };
329
+ }
330
+ }
331
+ function convertSignatures(compiledTransaction) {
332
+ const {
333
+ compiledMessage: { staticAccounts },
334
+ signatures
335
+ } = compiledTransaction;
336
+ return signatures.reduce((acc, sig, index) => {
337
+ const allZeros = sig.every((byte) => byte === 0);
338
+ if (allZeros)
339
+ return acc;
340
+ const address = staticAccounts[index];
341
+ return { ...acc, [address]: sig };
342
+ }, {});
343
+ }
344
+ function decompileTransaction(compiledTransaction, config) {
345
+ const { compiledMessage } = compiledTransaction;
346
+ const feePayer = compiledMessage.staticAccounts[0];
347
+ if (!feePayer)
348
+ throw new Error("No fee payer set in CompiledTransaction");
349
+ const accountMetas = getAccountMetas(compiledMessage);
350
+ const accountLookupMetas = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? getAddressLookupMetas(compiledMessage.addressTableLookups, config?.addressesByLookupTableAddress ?? {}) : [];
351
+ const transactionMetas = [...accountMetas, ...accountLookupMetas];
352
+ const instructions = compiledMessage.instructions.map(
353
+ (compiledInstruction) => convertInstruction(compiledInstruction, transactionMetas)
354
+ );
355
+ const firstInstruction = instructions[0];
356
+ const lifetimeConstraint = getLifetimeConstraint(
357
+ compiledMessage.lifetimeToken,
358
+ firstInstruction,
359
+ config?.lastValidBlockHeight
360
+ );
361
+ const signatures = convertSignatures(compiledTransaction);
362
+ return functional.pipe(
363
+ createTransaction({ version: compiledMessage.version }),
364
+ (tx) => setTransactionFeePayer(feePayer, tx),
365
+ (tx) => instructions.reduce((acc, instruction) => {
366
+ return appendTransactionInstruction(instruction, acc);
367
+ }, tx),
368
+ (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
369
+ (tx) => Object.keys(signatures).length > 0 ? { ...tx, signatures } : tx
370
+ );
371
+ }
203
372
  function upsert(addressMap, address, update) {
204
373
  addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
205
374
  }
@@ -252,7 +421,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
252
421
  const shouldReplaceEntry = (
253
422
  // Consider using the new LOOKUP_TABLE if its address is different...
254
423
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
255
- (addressComparator || (addressComparator = addresses.getAddressComparator()))(
424
+ (addressComparator ||= addresses.getAddressComparator())(
256
425
  accountMeta.lookupTableAddress,
257
426
  entry.lookupTableAddress
258
427
  ) < 0
@@ -358,7 +527,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
358
527
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
359
528
  return leftIsWritable ? -1 : 1;
360
529
  }
361
- addressComparator || (addressComparator = addresses.getAddressComparator());
530
+ addressComparator ||= addresses.getAddressComparator();
362
531
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
363
532
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
364
533
  } else {
@@ -371,16 +540,15 @@ function getOrderedAccountsFromAddressMap(addressMap) {
371
540
  return orderedAccounts;
372
541
  }
373
542
  function getCompiledAddressTableLookups(orderedAccounts) {
374
- var _a;
375
543
  const index = {};
376
544
  for (const account of orderedAccounts) {
377
545
  if (!("lookupTableAddress" in account)) {
378
546
  continue;
379
547
  }
380
- const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
548
+ const entry = index[account.lookupTableAddress] ||= {
381
549
  readableIndices: [],
382
550
  writableIndices: []
383
- });
551
+ };
384
552
  if (account.role === AccountRole.WRITABLE) {
385
553
  entry.writableIndices.push(account.addressIndex);
386
554
  } else {
@@ -466,187 +634,31 @@ function compileMessage(transaction) {
466
634
  version: transaction.version
467
635
  };
468
636
  }
469
-
470
- // src/compile-transaction.ts
471
- function getCompiledTransaction(transaction) {
472
- const compiledMessage = compileMessage(transaction);
473
- let signatures;
474
- if ("signatures" in transaction) {
475
- signatures = [];
476
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
477
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
478
- }
479
- } else {
480
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
481
- }
482
- return {
483
- compiledMessage,
484
- signatures
485
- };
486
- }
487
- function getAccountMetas(message) {
488
- const { header } = message;
489
- const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
490
- const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
491
- const accountMetas = [];
492
- let accountIndex = 0;
493
- for (let i = 0; i < numWritableSignerAccounts; i++) {
494
- accountMetas.push({
495
- address: message.staticAccounts[accountIndex],
496
- role: AccountRole.WRITABLE_SIGNER
497
- });
498
- accountIndex++;
499
- }
500
- for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
501
- accountMetas.push({
502
- address: message.staticAccounts[accountIndex],
503
- role: AccountRole.READONLY_SIGNER
504
- });
505
- accountIndex++;
506
- }
507
- for (let i = 0; i < numWritableNonSignerAccounts; i++) {
508
- accountMetas.push({
509
- address: message.staticAccounts[accountIndex],
510
- role: AccountRole.WRITABLE
511
- });
512
- accountIndex++;
513
- }
514
- for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
515
- accountMetas.push({
516
- address: message.staticAccounts[accountIndex],
517
- role: AccountRole.READONLY
518
- });
519
- accountIndex++;
520
- }
521
- return accountMetas;
522
- }
523
- function convertInstruction(instruction, accountMetas) {
524
- const programAddress = accountMetas[instruction.programAddressIndex]?.address;
525
- if (!programAddress) {
526
- throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
527
- }
528
- const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
529
- const { data } = instruction;
530
- return {
531
- programAddress,
532
- ...accounts && accounts.length ? { accounts } : {},
533
- ...data && data.length ? { data } : {}
534
- };
535
- }
536
- function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
537
- if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
538
- return {
539
- blockhash: messageLifetimeToken,
540
- lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
541
- // U64 MAX
542
- };
543
- } else {
544
- const nonceAccountAddress = firstInstruction.accounts[0].address;
545
- addresses.assertIsAddress(nonceAccountAddress);
546
- const nonceAuthorityAddress = firstInstruction.accounts[2].address;
547
- addresses.assertIsAddress(nonceAuthorityAddress);
548
- return {
549
- nonce: messageLifetimeToken,
550
- nonceAccountAddress,
551
- nonceAuthorityAddress
552
- };
553
- }
554
- }
555
- function convertSignatures(compiledTransaction) {
556
- const {
557
- compiledMessage: { staticAccounts },
558
- signatures
559
- } = compiledTransaction;
560
- return signatures.reduce((acc, sig, index) => {
561
- const allZeros = sig.every((byte) => byte === 0);
562
- if (allZeros)
563
- return acc;
564
- const address = staticAccounts[index];
565
- return { ...acc, [address]: sig };
566
- }, {});
567
- }
568
- function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
569
- const { compiledMessage } = compiledTransaction;
570
- if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
571
- throw new Error("Cannot convert transaction with addressTableLookups");
572
- }
573
- const feePayer = compiledMessage.staticAccounts[0];
574
- if (!feePayer)
575
- throw new Error("No fee payer set in CompiledTransaction");
576
- const accountMetas = getAccountMetas(compiledMessage);
577
- const instructions = compiledMessage.instructions.map(
578
- (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
579
- );
580
- const firstInstruction = instructions[0];
581
- const lifetimeConstraint = getLifetimeConstraint(
582
- compiledMessage.lifetimeToken,
583
- firstInstruction,
584
- lastValidBlockHeight
585
- );
586
- const signatures = convertSignatures(compiledTransaction);
587
- return functional.pipe(
588
- createTransaction({ version: compiledMessage.version }),
589
- (tx) => setTransactionFeePayer(feePayer, tx),
590
- (tx) => instructions.reduce((acc, instruction) => {
591
- return appendTransactionInstruction(instruction, acc);
592
- }, tx),
593
- (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
594
- (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
595
- );
596
- }
597
- var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
598
- var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
599
- var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
600
- var addressTableLookupDescription = __DEV__ ? "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" : "addressTableLookup";
601
637
  var memoizedAddressTableLookupEncoder;
602
638
  function getAddressTableLookupEncoder() {
603
639
  if (!memoizedAddressTableLookupEncoder) {
604
- memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder(
640
+ memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder([
641
+ ["lookupTableAddress", addresses.getAddressEncoder()],
605
642
  [
606
- ["lookupTableAddress", addresses.getAddressEncoder({ description: lookupTableAddressDescription })],
607
- [
608
- "writableIndices",
609
- codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
610
- description: writableIndicesDescription,
611
- size: codecsNumbers.getShortU16Encoder()
612
- })
613
- ],
614
- [
615
- "readableIndices",
616
- codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
617
- description: readableIndicesDescription,
618
- size: codecsNumbers.getShortU16Encoder()
619
- })
620
- ]
643
+ "writableIndices",
644
+ codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), { size: codecsNumbers.getShortU16Encoder() })
621
645
  ],
622
- { description: addressTableLookupDescription }
623
- );
646
+ [
647
+ "readableIndices",
648
+ codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), { size: codecsNumbers.getShortU16Encoder() })
649
+ ]
650
+ ]);
624
651
  }
625
652
  return memoizedAddressTableLookupEncoder;
626
653
  }
627
654
  var memoizedAddressTableLookupDecoder;
628
655
  function getAddressTableLookupDecoder() {
629
656
  if (!memoizedAddressTableLookupDecoder) {
630
- memoizedAddressTableLookupDecoder = codecsDataStructures.getStructDecoder(
631
- [
632
- ["lookupTableAddress", addresses.getAddressDecoder({ description: lookupTableAddressDescription })],
633
- [
634
- "writableIndices",
635
- codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
636
- description: writableIndicesDescription,
637
- size: codecsNumbers.getShortU16Decoder()
638
- })
639
- ],
640
- [
641
- "readableIndices",
642
- codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
643
- description: readableIndicesDescription,
644
- size: codecsNumbers.getShortU16Decoder()
645
- })
646
- ]
647
- ],
648
- { description: addressTableLookupDescription }
649
- );
657
+ memoizedAddressTableLookupDecoder = codecsDataStructures.getStructDecoder([
658
+ ["lookupTableAddress", addresses.getAddressDecoder()],
659
+ ["writableIndices", codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), { size: codecsNumbers.getShortU16Decoder() })],
660
+ ["readableIndices", codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), { size: codecsNumbers.getShortU16Decoder() })]
661
+ ]);
650
662
  }
651
663
  return memoizedAddressTableLookupDecoder;
652
664
  }
@@ -656,72 +668,34 @@ function getMemoizedU8Encoder() {
656
668
  memoizedU8Encoder = codecsNumbers.getU8Encoder();
657
669
  return memoizedU8Encoder;
658
670
  }
659
- function getMemoizedU8EncoderDescription(description) {
660
- const encoder = getMemoizedU8Encoder();
661
- return {
662
- ...encoder,
663
- description: description ?? encoder.description
664
- };
665
- }
666
671
  var memoizedU8Decoder;
667
672
  function getMemoizedU8Decoder() {
668
673
  if (!memoizedU8Decoder)
669
674
  memoizedU8Decoder = codecsNumbers.getU8Decoder();
670
675
  return memoizedU8Decoder;
671
676
  }
672
- function getMemoizedU8DecoderDescription(description) {
673
- const decoder = getMemoizedU8Decoder();
674
- return {
675
- ...decoder,
676
- description: description ?? decoder.description
677
- };
678
- }
679
- var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0;
680
- var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0;
681
- var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
682
- var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
683
677
  function getMessageHeaderEncoder() {
684
- return codecsDataStructures.getStructEncoder(
685
- [
686
- ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
687
- ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
688
- ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
689
- ],
690
- {
691
- description: messageHeaderDescription
692
- }
693
- );
678
+ return codecsDataStructures.getStructEncoder([
679
+ ["numSignerAccounts", getMemoizedU8Encoder()],
680
+ ["numReadonlySignerAccounts", getMemoizedU8Encoder()],
681
+ ["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
682
+ ]);
694
683
  }
695
684
  function getMessageHeaderDecoder() {
696
- return codecsDataStructures.getStructDecoder(
697
- [
698
- ["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
699
- ["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
700
- ["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
701
- ],
702
- {
703
- description: messageHeaderDescription
704
- }
705
- );
685
+ return codecsDataStructures.getStructDecoder([
686
+ ["numSignerAccounts", getMemoizedU8Decoder()],
687
+ ["numReadonlySignerAccounts", getMemoizedU8Decoder()],
688
+ ["numReadonlyNonSignerAccounts", getMemoizedU8Decoder()]
689
+ ]);
706
690
  }
707
- var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
708
- var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
709
- var accountIndicesDescription = __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "accountIndices";
710
- var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
711
691
  var memoizedGetInstructionEncoder;
712
692
  function getInstructionEncoder() {
713
693
  if (!memoizedGetInstructionEncoder) {
714
694
  memoizedGetInstructionEncoder = codecsCore.mapEncoder(
715
695
  codecsDataStructures.getStructEncoder([
716
- ["programAddressIndex", codecsNumbers.getU8Encoder({ description: programAddressIndexDescription })],
717
- [
718
- "accountIndices",
719
- codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder({ description: accountIndexDescription }), {
720
- description: accountIndicesDescription,
721
- size: codecsNumbers.getShortU16Encoder()
722
- })
723
- ],
724
- ["data", codecsDataStructures.getBytesEncoder({ description: dataDescription, size: codecsNumbers.getShortU16Encoder() })]
696
+ ["programAddressIndex", codecsNumbers.getU8Encoder()],
697
+ ["accountIndices", codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), { size: codecsNumbers.getShortU16Encoder() })],
698
+ ["data", codecsDataStructures.getBytesEncoder({ size: codecsNumbers.getShortU16Encoder() })]
725
699
  ]),
726
700
  // Convert an instruction to have all fields defined
727
701
  (instruction) => {
@@ -743,15 +717,9 @@ function getInstructionDecoder() {
743
717
  if (!memoizedGetInstructionDecoder) {
744
718
  memoizedGetInstructionDecoder = codecsCore.mapDecoder(
745
719
  codecsDataStructures.getStructDecoder([
746
- ["programAddressIndex", codecsNumbers.getU8Decoder({ description: programAddressIndexDescription })],
747
- [
748
- "accountIndices",
749
- codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder({ description: accountIndexDescription }), {
750
- description: accountIndicesDescription,
751
- size: codecsNumbers.getShortU16Decoder()
752
- })
753
- ],
754
- ["data", codecsDataStructures.getBytesDecoder({ description: dataDescription, size: codecsNumbers.getShortU16Decoder() })]
720
+ ["programAddressIndex", codecsNumbers.getU8Decoder()],
721
+ ["accountIndices", codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), { size: codecsNumbers.getShortU16Decoder() })],
722
+ ["data", codecsDataStructures.getBytesDecoder({ size: codecsNumbers.getShortU16Decoder() })]
755
723
  ]),
756
724
  // Convert an instruction to exclude optional fields if they are empty
757
725
  (instruction) => {
@@ -770,47 +738,38 @@ function getInstructionDecoder() {
770
738
  return memoizedGetInstructionDecoder;
771
739
  }
772
740
  var VERSION_FLAG_MASK = 128;
773
- var BASE_CONFIG = {
774
- description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
775
- fixedSize: null,
776
- maxSize: 1
777
- };
778
- function decode(bytes, offset = 0) {
779
- const firstByte = bytes[offset];
780
- if ((firstByte & VERSION_FLAG_MASK) === 0) {
781
- return ["legacy", offset];
782
- } else {
783
- const version = firstByte ^ VERSION_FLAG_MASK;
784
- return [version, offset + 1];
785
- }
786
- }
787
- function encode(value) {
788
- if (value === "legacy") {
789
- return new Uint8Array();
790
- }
791
- if (value < 0 || value > 127) {
792
- throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
793
- }
794
- return new Uint8Array([value | VERSION_FLAG_MASK]);
741
+ function getTransactionVersionEncoder() {
742
+ return codecsCore.createEncoder({
743
+ getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
744
+ maxSize: 1,
745
+ write: (value, bytes, offset) => {
746
+ if (value === "legacy") {
747
+ return offset;
748
+ }
749
+ if (value < 0 || value > 127) {
750
+ throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
751
+ }
752
+ bytes.set([value | VERSION_FLAG_MASK], offset);
753
+ return offset + 1;
754
+ }
755
+ });
795
756
  }
796
757
  function getTransactionVersionDecoder() {
797
- return {
798
- ...BASE_CONFIG,
799
- decode
800
- };
801
- }
802
- function getTransactionVersionEncoder() {
803
- return {
804
- ...BASE_CONFIG,
805
- encode
806
- };
758
+ return codecsCore.createDecoder({
759
+ maxSize: 1,
760
+ read: (bytes, offset) => {
761
+ const firstByte = bytes[offset];
762
+ if ((firstByte & VERSION_FLAG_MASK) === 0) {
763
+ return ["legacy", offset];
764
+ } else {
765
+ const version = firstByte ^ VERSION_FLAG_MASK;
766
+ return [version, offset + 1];
767
+ }
768
+ }
769
+ });
807
770
  }
808
771
 
809
772
  // src/serializers/message.ts
810
- var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
811
- var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
812
- var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
813
- var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
814
773
  function getCompiledMessageLegacyEncoder() {
815
774
  return codecsDataStructures.getStructEncoder(getPreludeStructEncoderTuple());
816
775
  }
@@ -835,91 +794,48 @@ function getPreludeStructEncoderTuple() {
835
794
  return [
836
795
  ["version", getTransactionVersionEncoder()],
837
796
  ["header", getMessageHeaderEncoder()],
838
- [
839
- "staticAccounts",
840
- codecsDataStructures.getArrayEncoder(addresses.getAddressEncoder(), {
841
- description: staticAccountsDescription,
842
- size: codecsNumbers.getShortU16Encoder()
843
- })
844
- ],
845
- [
846
- "lifetimeToken",
847
- codecsStrings.getStringEncoder({
848
- description: lifetimeTokenDescription,
849
- encoding: codecsStrings.getBase58Encoder(),
850
- size: 32
851
- })
852
- ],
853
- [
854
- "instructions",
855
- codecsDataStructures.getArrayEncoder(getInstructionEncoder(), {
856
- description: instructionsDescription,
857
- size: codecsNumbers.getShortU16Encoder()
858
- })
859
- ]
797
+ ["staticAccounts", codecsDataStructures.getArrayEncoder(addresses.getAddressEncoder(), { size: codecsNumbers.getShortU16Encoder() })],
798
+ ["lifetimeToken", codecsStrings.getStringEncoder({ encoding: codecsStrings.getBase58Encoder(), size: 32 })],
799
+ ["instructions", codecsDataStructures.getArrayEncoder(getInstructionEncoder(), { size: codecsNumbers.getShortU16Encoder() })]
860
800
  ];
861
801
  }
862
802
  function getPreludeStructDecoderTuple() {
863
803
  return [
864
804
  ["version", getTransactionVersionDecoder()],
865
805
  ["header", getMessageHeaderDecoder()],
866
- [
867
- "staticAccounts",
868
- codecsDataStructures.getArrayDecoder(addresses.getAddressDecoder(), {
869
- description: staticAccountsDescription,
870
- size: codecsNumbers.getShortU16Decoder()
871
- })
872
- ],
873
- [
874
- "lifetimeToken",
875
- codecsStrings.getStringDecoder({
876
- description: lifetimeTokenDescription,
877
- encoding: codecsStrings.getBase58Decoder(),
878
- size: 32
879
- })
880
- ],
881
- [
882
- "instructions",
883
- codecsDataStructures.getArrayDecoder(getInstructionDecoder(), {
884
- description: instructionsDescription,
885
- size: codecsNumbers.getShortU16Decoder()
886
- })
887
- ],
806
+ ["staticAccounts", codecsDataStructures.getArrayDecoder(addresses.getAddressDecoder(), { size: codecsNumbers.getShortU16Decoder() })],
807
+ ["lifetimeToken", codecsStrings.getStringDecoder({ encoding: codecsStrings.getBase58Decoder(), size: 32 })],
808
+ ["instructions", codecsDataStructures.getArrayDecoder(getInstructionDecoder(), { size: codecsNumbers.getShortU16Decoder() })],
888
809
  ["addressTableLookups", getAddressTableLookupArrayDecoder()]
889
810
  ];
890
811
  }
891
812
  function getAddressTableLookupArrayEncoder() {
892
- return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), {
893
- description: addressTableLookupsDescription,
894
- size: codecsNumbers.getShortU16Encoder()
895
- });
813
+ return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), { size: codecsNumbers.getShortU16Encoder() });
896
814
  }
897
815
  function getAddressTableLookupArrayDecoder() {
898
- return codecsDataStructures.getArrayDecoder(getAddressTableLookupDecoder(), {
899
- description: addressTableLookupsDescription,
900
- size: codecsNumbers.getShortU16Decoder()
901
- });
816
+ return codecsDataStructures.getArrayDecoder(getAddressTableLookupDecoder(), { size: codecsNumbers.getShortU16Decoder() });
902
817
  }
903
- var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
904
818
  function getCompiledMessageEncoder() {
905
- return {
906
- description: messageDescription,
907
- encode: (compiledMessage) => {
819
+ return codecsCore.createEncoder({
820
+ getSizeFromValue: (compiledMessage) => {
908
821
  if (compiledMessage.version === "legacy") {
909
- return getCompiledMessageLegacyEncoder().encode(compiledMessage);
822
+ return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
910
823
  } else {
911
- return getCompiledMessageVersionedEncoder().encode(compiledMessage);
824
+ return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
912
825
  }
913
826
  },
914
- fixedSize: null,
915
- maxSize: null
916
- };
827
+ write: (compiledMessage, bytes, offset) => {
828
+ if (compiledMessage.version === "legacy") {
829
+ return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
830
+ } else {
831
+ return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
832
+ }
833
+ }
834
+ });
917
835
  }
918
836
  function getCompiledMessageDecoder() {
919
837
  return codecsCore.mapDecoder(
920
- codecsDataStructures.getStructDecoder(getPreludeStructDecoderTuple(), {
921
- description: messageDescription
922
- }),
838
+ codecsDataStructures.getStructDecoder(getPreludeStructDecoderTuple()),
923
839
  ({ addressTableLookups, ...restOfMessage }) => {
924
840
  if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
925
841
  return restOfMessage;
@@ -928,105 +844,70 @@ function getCompiledMessageDecoder() {
928
844
  }
929
845
  );
930
846
  }
847
+ function getCompiledMessageCodec() {
848
+ return codecsCore.combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
849
+ }
931
850
 
932
- // src/serializers/transaction.ts
933
- var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
934
- var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
935
- function getCompiledTransactionEncoder() {
936
- return codecsDataStructures.getStructEncoder(
937
- [
938
- [
939
- "signatures",
940
- codecsDataStructures.getArrayEncoder(codecsDataStructures.getBytesEncoder({ size: 64 }), {
941
- description: signaturesDescription,
942
- size: codecsNumbers.getShortU16Encoder()
943
- })
944
- ],
945
- ["compiledMessage", getCompiledMessageEncoder()]
946
- ],
947
- {
948
- description: transactionDescription
851
+ // src/compile-transaction.ts
852
+ function getCompiledTransaction(transaction) {
853
+ const compiledMessage = compileMessage(transaction);
854
+ let signatures;
855
+ if ("signatures" in transaction) {
856
+ signatures = [];
857
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
858
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
949
859
  }
950
- );
860
+ } else {
861
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
862
+ }
863
+ return {
864
+ compiledMessage,
865
+ signatures
866
+ };
951
867
  }
952
- function getSignatureDecoder() {
953
- return codecsCore.mapDecoder(codecsDataStructures.getBytesDecoder({ size: 64 }), (bytes) => bytes);
868
+
869
+ // src/serializers/transaction.ts
870
+ function getCompiledTransactionEncoder() {
871
+ return codecsDataStructures.getStructEncoder([
872
+ ["signatures", codecsDataStructures.getArrayEncoder(codecsDataStructures.getBytesEncoder({ size: 64 }), { size: codecsNumbers.getShortU16Encoder() })],
873
+ ["compiledMessage", getCompiledMessageEncoder()]
874
+ ]);
954
875
  }
955
876
  function getCompiledTransactionDecoder() {
956
- return codecsDataStructures.getStructDecoder(
877
+ return codecsDataStructures.getStructDecoder([
957
878
  [
958
- [
959
- "signatures",
960
- codecsDataStructures.getArrayDecoder(getSignatureDecoder(), {
961
- description: signaturesDescription,
962
- size: codecsNumbers.getShortU16Decoder()
963
- })
964
- ],
965
- ["compiledMessage", getCompiledMessageDecoder()]
879
+ "signatures",
880
+ codecsDataStructures.getArrayDecoder(codecsDataStructures.getBytesDecoder({ size: 64 }), {
881
+ size: codecsNumbers.getShortU16Decoder()
882
+ })
966
883
  ],
967
- {
968
- description: transactionDescription
969
- }
970
- );
884
+ ["compiledMessage", getCompiledMessageDecoder()]
885
+ ]);
971
886
  }
972
887
  function getTransactionEncoder() {
973
888
  return codecsCore.mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
974
889
  }
975
- function getTransactionDecoder(lastValidBlockHeight) {
890
+ function getTransactionDecoder(config) {
976
891
  return codecsCore.mapDecoder(
977
892
  getCompiledTransactionDecoder(),
978
- (compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
893
+ (compiledTransaction) => decompileTransaction(compiledTransaction, config)
979
894
  );
980
895
  }
981
- function getTransactionCodec(lastValidBlockHeight) {
982
- return codecsCore.combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
983
- }
984
- function assertIsTransactionSignature(putativeTransactionSignature) {
985
- try {
986
- if (
987
- // Lowest value (64 bytes of zeroes)
988
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
989
- putativeTransactionSignature.length > 88
990
- ) {
991
- throw new Error("Expected input string to decode to a byte array of length 64.");
992
- }
993
- const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
994
- const numBytes = bytes.byteLength;
995
- if (numBytes !== 64) {
996
- throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
997
- }
998
- } catch (e) {
999
- throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1000
- cause: e
1001
- });
1002
- }
1003
- }
1004
- function isTransactionSignature(putativeTransactionSignature) {
1005
- if (
1006
- // Lowest value (64 bytes of zeroes)
1007
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1008
- putativeTransactionSignature.length > 88
1009
- ) {
1010
- return false;
1011
- }
1012
- const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
1013
- const numBytes = bytes.byteLength;
1014
- if (numBytes !== 64) {
1015
- return false;
1016
- }
1017
- return true;
896
+ function getTransactionCodec(config) {
897
+ return codecsCore.combineCodec(getTransactionEncoder(), getTransactionDecoder(config));
1018
898
  }
899
+ var base58Decoder;
1019
900
  function getSignatureFromTransaction(transaction) {
901
+ if (!base58Decoder)
902
+ base58Decoder = codecsStrings.getBase58Decoder();
1020
903
  const signatureBytes = transaction.signatures[transaction.feePayer];
1021
904
  if (!signatureBytes) {
1022
- throw new Error(
1023
- "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1024
- );
905
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE);
1025
906
  }
1026
- const transactionSignature2 = umiSerializers.base58.deserialize(signatureBytes)[0];
1027
- return transactionSignature2;
907
+ const transactionSignature = base58Decoder.decode(signatureBytes);
908
+ return transactionSignature;
1028
909
  }
1029
- async function signTransaction(keyPairs, transaction) {
910
+ async function partiallySignTransaction(keyPairs, transaction) {
1030
911
  const compiledMessage = compileMessage(transaction);
1031
912
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1032
913
  const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
@@ -1045,46 +926,57 @@ async function signTransaction(keyPairs, transaction) {
1045
926
  Object.freeze(out);
1046
927
  return out;
1047
928
  }
1048
- function transactionSignature(putativeTransactionSignature) {
1049
- assertIsTransactionSignature(putativeTransactionSignature);
1050
- return putativeTransactionSignature;
929
+ async function signTransaction(keyPairs, transaction) {
930
+ const out = await partiallySignTransaction(keyPairs, transaction);
931
+ assertTransactionIsFullySigned(out);
932
+ Object.freeze(out);
933
+ return out;
1051
934
  }
1052
935
  function assertTransactionIsFullySigned(transaction) {
1053
936
  const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
1054
937
  const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
938
+ const missingSigs = [];
1055
939
  requiredSigners.forEach((address) => {
1056
940
  if (!transaction.signatures[address]) {
1057
- throw new Error(`Transaction is missing signature for address \`${address}\``);
941
+ missingSigs.push(address);
1058
942
  }
1059
943
  });
944
+ if (missingSigs.length > 0) {
945
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, {
946
+ addresses: missingSigs
947
+ });
948
+ }
1060
949
  }
1061
-
1062
- // src/wire-transaction.ts
1063
950
  function getBase64EncodedWireTransaction(transaction) {
1064
951
  const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1065
- {
1066
- return btoa(String.fromCharCode(...wireTransactionBytes));
1067
- }
952
+ return codecsStrings.getBase64Decoder().decode(wireTransactionBytes);
1068
953
  }
1069
954
 
1070
955
  exports.appendTransactionInstruction = appendTransactionInstruction;
1071
- exports.assertIsBlockhash = assertIsBlockhash;
956
+ exports.appendTransactionInstructions = appendTransactionInstructions;
1072
957
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1073
- exports.assertIsTransactionSignature = assertIsTransactionSignature;
958
+ exports.assertIsTransactionWithBlockhashLifetime = assertIsTransactionWithBlockhashLifetime;
1074
959
  exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
960
+ exports.compileMessage = compileMessage;
1075
961
  exports.createTransaction = createTransaction;
962
+ exports.decompileTransaction = decompileTransaction;
1076
963
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
964
+ exports.getCompiledMessageCodec = getCompiledMessageCodec;
965
+ exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
966
+ exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
967
+ exports.getCompiledTransactionDecoder = getCompiledTransactionDecoder;
1077
968
  exports.getSignatureFromTransaction = getSignatureFromTransaction;
1078
969
  exports.getTransactionCodec = getTransactionCodec;
1079
970
  exports.getTransactionDecoder = getTransactionDecoder;
1080
971
  exports.getTransactionEncoder = getTransactionEncoder;
972
+ exports.getUnsignedTransaction = getUnsignedTransaction;
1081
973
  exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
1082
- exports.isTransactionSignature = isTransactionSignature;
974
+ exports.partiallySignTransaction = partiallySignTransaction;
1083
975
  exports.prependTransactionInstruction = prependTransactionInstruction;
976
+ exports.prependTransactionInstructions = prependTransactionInstructions;
1084
977
  exports.setTransactionFeePayer = setTransactionFeePayer;
1085
978
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1086
979
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1087
980
  exports.signTransaction = signTransaction;
1088
- exports.transactionSignature = transactionSignature;
1089
981
  //# sourceMappingURL=out.js.map
1090
982
  //# sourceMappingURL=index.browser.cjs.map