@solana/transactions 2.0.0-experimental.762ff13 → 2.0.0-experimental.76cf6b4

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 +1 -43
  2. package/dist/index.browser.cjs +260 -429
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +256 -430
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +679 -829
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +256 -432
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +260 -429
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +256 -432
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +23 -20
  15. package/dist/types/accounts.d.ts +2 -2
  16. package/dist/types/accounts.d.ts.map +1 -0
  17. package/dist/types/blockhash.d.ts +4 -3
  18. package/dist/types/blockhash.d.ts.map +1 -0
  19. package/dist/types/compilable-transaction.d.ts +7 -0
  20. package/dist/types/compilable-transaction.d.ts.map +1 -0
  21. package/dist/types/compile-address-table-lookups.d.ts +3 -3
  22. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  23. package/dist/types/compile-header.d.ts +1 -1
  24. package/dist/types/compile-header.d.ts.map +1 -0
  25. package/dist/types/compile-instructions.d.ts +1 -1
  26. package/dist/types/compile-instructions.d.ts.map +1 -0
  27. package/dist/types/compile-lifetime-token.d.ts +1 -1
  28. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  29. package/dist/types/compile-static-accounts.d.ts +3 -3
  30. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  31. package/dist/types/compile-transaction.d.ts +6 -7
  32. package/dist/types/compile-transaction.d.ts.map +1 -0
  33. package/dist/types/create-transaction.d.ts +1 -1
  34. package/dist/types/create-transaction.d.ts.map +1 -0
  35. package/dist/types/decompile-transaction.d.ts +3 -5
  36. package/dist/types/decompile-transaction.d.ts.map +1 -0
  37. package/dist/types/durable-nonce.d.ts +5 -5
  38. package/dist/types/durable-nonce.d.ts.map +1 -0
  39. package/dist/types/fee-payer.d.ts +6 -6
  40. package/dist/types/fee-payer.d.ts.map +1 -0
  41. package/dist/types/index.d.ts +11 -9
  42. package/dist/types/index.d.ts.map +1 -0
  43. package/dist/types/instructions.d.ts +2 -2
  44. package/dist/types/instructions.d.ts.map +1 -0
  45. package/dist/types/message.d.ts +6 -10
  46. package/dist/types/message.d.ts.map +1 -0
  47. package/dist/types/serializers/address-table-lookup.d.ts +5 -5
  48. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  49. package/dist/types/serializers/header.d.ts +5 -5
  50. package/dist/types/serializers/header.d.ts.map +1 -0
  51. package/dist/types/serializers/index.d.ts +2 -1
  52. package/dist/types/serializers/index.d.ts.map +1 -0
  53. package/dist/types/serializers/instruction.d.ts +5 -5
  54. package/dist/types/serializers/instruction.d.ts.map +1 -0
  55. package/dist/types/serializers/message.d.ts +5 -5
  56. package/dist/types/serializers/message.d.ts.map +1 -0
  57. package/dist/types/serializers/transaction-version.d.ts +5 -5
  58. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  59. package/dist/types/serializers/transaction.d.ts +6 -8
  60. package/dist/types/serializers/transaction.d.ts.map +1 -0
  61. package/dist/types/signatures.d.ts +9 -14
  62. package/dist/types/signatures.d.ts.map +1 -0
  63. package/dist/types/types.d.ts +6 -13
  64. package/dist/types/types.d.ts.map +1 -0
  65. package/dist/types/unsigned-transaction.d.ts +1 -1
  66. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  67. package/dist/types/wire-transaction.d.ts +1 -1
  68. package/dist/types/wire-transaction.d.ts.map +1 -0
  69. package/package.json +15 -15
@@ -1,13 +1,12 @@
1
- import { getBase58Encoder, getBase58Decoder, getStringEncoder, getStringDecoder } from '@solana/codecs-strings';
2
- import { mapEncoder, mapDecoder, combineCodec } from '@solana/codecs-core';
3
- import { getStructEncoder, getArrayEncoder, getBytesEncoder, getStructDecoder, getArrayDecoder, getBytesDecoder } from '@solana/codecs-data-structures';
1
+ import { getBase58Encoder, getBase58Decoder, getBase64Decoder, getStringEncoder, getStringDecoder } from '@solana/codecs-strings';
2
+ import { getAddressFromPublicKey, getAddressComparator, getAddressEncoder, getAddressDecoder, assertIsAddress } from '@solana/addresses';
3
+ import { createEncoder, mapDecoder, combineCodec, mapEncoder, createDecoder } from '@solana/codecs-core';
4
+ import { getStructDecoder, getStructEncoder, getArrayEncoder, getArrayDecoder, getBytesEncoder, getBytesDecoder } from '@solana/codecs-data-structures';
4
5
  import { getShortU16Encoder, getShortU16Decoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';
5
- import { getAddressFromPublicKey, getAddressComparator, assertIsAddress, getAddressEncoder, getAddressDecoder } from '@solana/addresses';
6
6
  import { pipe } from '@solana/functional';
7
7
  import { signBytes } from '@solana/keys';
8
8
 
9
- // ../build-scripts/env-shim.ts
10
- var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
9
+ // src/blockhash.ts
11
10
 
12
11
  // src/unsigned-transaction.ts
13
12
  function getUnsignedTransaction(transaction) {
@@ -47,6 +46,22 @@ function assertIsBlockhash(putativeBlockhash) {
47
46
  });
48
47
  }
49
48
  }
49
+ function isTransactionWithBlockhashLifetime(transaction) {
50
+ const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
51
+ if (!lifetimeConstraintShapeMatches)
52
+ return false;
53
+ try {
54
+ assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
55
+ return true;
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+ function assertIsTransactionWithBlockhashLifetime(transaction) {
61
+ if (!isTransactionWithBlockhashLifetime(transaction)) {
62
+ throw new Error("Transaction does not have a blockhash lifetime");
63
+ }
64
+ }
50
65
  function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
51
66
  if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
52
67
  return transaction;
@@ -252,7 +267,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
252
267
  const shouldReplaceEntry = (
253
268
  // Consider using the new LOOKUP_TABLE if its address is different...
254
269
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
255
- (addressComparator || (addressComparator = getAddressComparator()))(
270
+ (addressComparator ||= getAddressComparator())(
256
271
  accountMeta.lookupTableAddress,
257
272
  entry.lookupTableAddress
258
273
  ) < 0
@@ -358,7 +373,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
358
373
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
359
374
  return leftIsWritable ? -1 : 1;
360
375
  }
361
- addressComparator || (addressComparator = getAddressComparator());
376
+ addressComparator ||= getAddressComparator();
362
377
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
363
378
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
364
379
  } else {
@@ -371,16 +386,15 @@ function getOrderedAccountsFromAddressMap(addressMap) {
371
386
  return orderedAccounts;
372
387
  }
373
388
  function getCompiledAddressTableLookups(orderedAccounts) {
374
- var _a;
375
389
  const index = {};
376
390
  for (const account of orderedAccounts) {
377
391
  if (!("lookupTableAddress" in account)) {
378
392
  continue;
379
393
  }
380
- const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
394
+ const entry = index[account.lookupTableAddress] ||= {
381
395
  readableIndices: [],
382
396
  writableIndices: []
383
- });
397
+ };
384
398
  if (account.role === AccountRole.WRITABLE) {
385
399
  entry.writableIndices.push(account.addressIndex);
386
400
  } else {
@@ -466,6 +480,216 @@ function compileMessage(transaction) {
466
480
  version: transaction.version
467
481
  };
468
482
  }
483
+ var memoizedAddressTableLookupEncoder;
484
+ function getAddressTableLookupEncoder() {
485
+ if (!memoizedAddressTableLookupEncoder) {
486
+ memoizedAddressTableLookupEncoder = getStructEncoder([
487
+ ["lookupTableAddress", getAddressEncoder()],
488
+ [
489
+ "writableIndices",
490
+ getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
491
+ ],
492
+ [
493
+ "readableIndices",
494
+ getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
495
+ ]
496
+ ]);
497
+ }
498
+ return memoizedAddressTableLookupEncoder;
499
+ }
500
+ var memoizedAddressTableLookupDecoder;
501
+ function getAddressTableLookupDecoder() {
502
+ if (!memoizedAddressTableLookupDecoder) {
503
+ memoizedAddressTableLookupDecoder = getStructDecoder([
504
+ ["lookupTableAddress", getAddressDecoder()],
505
+ ["writableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
506
+ ["readableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })]
507
+ ]);
508
+ }
509
+ return memoizedAddressTableLookupDecoder;
510
+ }
511
+ var memoizedU8Encoder;
512
+ function getMemoizedU8Encoder() {
513
+ if (!memoizedU8Encoder)
514
+ memoizedU8Encoder = getU8Encoder();
515
+ return memoizedU8Encoder;
516
+ }
517
+ var memoizedU8Decoder;
518
+ function getMemoizedU8Decoder() {
519
+ if (!memoizedU8Decoder)
520
+ memoizedU8Decoder = getU8Decoder();
521
+ return memoizedU8Decoder;
522
+ }
523
+ function getMessageHeaderEncoder() {
524
+ return getStructEncoder([
525
+ ["numSignerAccounts", getMemoizedU8Encoder()],
526
+ ["numReadonlySignerAccounts", getMemoizedU8Encoder()],
527
+ ["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
528
+ ]);
529
+ }
530
+ function getMessageHeaderDecoder() {
531
+ return getStructDecoder([
532
+ ["numSignerAccounts", getMemoizedU8Decoder()],
533
+ ["numReadonlySignerAccounts", getMemoizedU8Decoder()],
534
+ ["numReadonlyNonSignerAccounts", getMemoizedU8Decoder()]
535
+ ]);
536
+ }
537
+ var memoizedGetInstructionEncoder;
538
+ function getInstructionEncoder() {
539
+ if (!memoizedGetInstructionEncoder) {
540
+ memoizedGetInstructionEncoder = mapEncoder(
541
+ getStructEncoder([
542
+ ["programAddressIndex", getU8Encoder()],
543
+ ["accountIndices", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],
544
+ ["data", getBytesEncoder({ size: getShortU16Encoder() })]
545
+ ]),
546
+ // Convert an instruction to have all fields defined
547
+ (instruction) => {
548
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
549
+ return instruction;
550
+ }
551
+ return {
552
+ ...instruction,
553
+ accountIndices: instruction.accountIndices ?? [],
554
+ data: instruction.data ?? new Uint8Array(0)
555
+ };
556
+ }
557
+ );
558
+ }
559
+ return memoizedGetInstructionEncoder;
560
+ }
561
+ var memoizedGetInstructionDecoder;
562
+ function getInstructionDecoder() {
563
+ if (!memoizedGetInstructionDecoder) {
564
+ memoizedGetInstructionDecoder = mapDecoder(
565
+ getStructDecoder([
566
+ ["programAddressIndex", getU8Decoder()],
567
+ ["accountIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
568
+ ["data", getBytesDecoder({ size: getShortU16Decoder() })]
569
+ ]),
570
+ // Convert an instruction to exclude optional fields if they are empty
571
+ (instruction) => {
572
+ if (instruction.accountIndices.length && instruction.data.byteLength) {
573
+ return instruction;
574
+ }
575
+ const { accountIndices, data, ...rest } = instruction;
576
+ return {
577
+ ...rest,
578
+ ...accountIndices.length ? { accountIndices } : null,
579
+ ...data.byteLength ? { data } : null
580
+ };
581
+ }
582
+ );
583
+ }
584
+ return memoizedGetInstructionDecoder;
585
+ }
586
+ var VERSION_FLAG_MASK = 128;
587
+ function getTransactionVersionEncoder() {
588
+ return createEncoder({
589
+ getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
590
+ maxSize: 1,
591
+ write: (value, bytes, offset) => {
592
+ if (value === "legacy") {
593
+ return offset;
594
+ }
595
+ if (value < 0 || value > 127) {
596
+ throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
597
+ }
598
+ bytes.set([value | VERSION_FLAG_MASK], offset);
599
+ return offset + 1;
600
+ }
601
+ });
602
+ }
603
+ function getTransactionVersionDecoder() {
604
+ return createDecoder({
605
+ maxSize: 1,
606
+ read: (bytes, offset) => {
607
+ const firstByte = bytes[offset];
608
+ if ((firstByte & VERSION_FLAG_MASK) === 0) {
609
+ return ["legacy", offset];
610
+ } else {
611
+ const version = firstByte ^ VERSION_FLAG_MASK;
612
+ return [version, offset + 1];
613
+ }
614
+ }
615
+ });
616
+ }
617
+
618
+ // src/serializers/message.ts
619
+ function getCompiledMessageLegacyEncoder() {
620
+ return getStructEncoder(getPreludeStructEncoderTuple());
621
+ }
622
+ function getCompiledMessageVersionedEncoder() {
623
+ return mapEncoder(
624
+ getStructEncoder([
625
+ ...getPreludeStructEncoderTuple(),
626
+ ["addressTableLookups", getAddressTableLookupArrayEncoder()]
627
+ ]),
628
+ (value) => {
629
+ if (value.version === "legacy") {
630
+ return value;
631
+ }
632
+ return {
633
+ ...value,
634
+ addressTableLookups: value.addressTableLookups ?? []
635
+ };
636
+ }
637
+ );
638
+ }
639
+ function getPreludeStructEncoderTuple() {
640
+ return [
641
+ ["version", getTransactionVersionEncoder()],
642
+ ["header", getMessageHeaderEncoder()],
643
+ ["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
644
+ ["lifetimeToken", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],
645
+ ["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
646
+ ];
647
+ }
648
+ function getPreludeStructDecoderTuple() {
649
+ return [
650
+ ["version", getTransactionVersionDecoder()],
651
+ ["header", getMessageHeaderDecoder()],
652
+ ["staticAccounts", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],
653
+ ["lifetimeToken", getStringDecoder({ encoding: getBase58Decoder(), size: 32 })],
654
+ ["instructions", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],
655
+ ["addressTableLookups", getAddressTableLookupArrayDecoder()]
656
+ ];
657
+ }
658
+ function getAddressTableLookupArrayEncoder() {
659
+ return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
660
+ }
661
+ function getAddressTableLookupArrayDecoder() {
662
+ return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });
663
+ }
664
+ function getCompiledMessageEncoder() {
665
+ return createEncoder({
666
+ getSizeFromValue: (compiledMessage) => {
667
+ if (compiledMessage.version === "legacy") {
668
+ return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
669
+ } else {
670
+ return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
671
+ }
672
+ },
673
+ write: (compiledMessage, bytes, offset) => {
674
+ if (compiledMessage.version === "legacy") {
675
+ return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
676
+ } else {
677
+ return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
678
+ }
679
+ }
680
+ });
681
+ }
682
+ function getCompiledMessageDecoder() {
683
+ return mapDecoder(getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
684
+ if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
685
+ return restOfMessage;
686
+ }
687
+ return { ...restOfMessage, addressTableLookups };
688
+ });
689
+ }
690
+ function getCompiledMessageCodec() {
691
+ return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
692
+ }
469
693
 
470
694
  // src/compile-transaction.ts
471
695
  function getCompiledTransaction(transaction) {
@@ -594,380 +818,24 @@ function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
594
818
  (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
595
819
  );
596
820
  }
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
- var memoizedAddressTableLookupEncoder;
602
- function getAddressTableLookupEncoder() {
603
- if (!memoizedAddressTableLookupEncoder) {
604
- memoizedAddressTableLookupEncoder = getStructEncoder(
605
- [
606
- ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
607
- [
608
- "writableIndices",
609
- getArrayEncoder(getU8Encoder(), {
610
- description: writableIndicesDescription,
611
- size: getShortU16Encoder()
612
- })
613
- ],
614
- [
615
- "readableIndices",
616
- getArrayEncoder(getU8Encoder(), {
617
- description: readableIndicesDescription,
618
- size: getShortU16Encoder()
619
- })
620
- ]
621
- ],
622
- { description: addressTableLookupDescription }
623
- );
624
- }
625
- return memoizedAddressTableLookupEncoder;
626
- }
627
- var memoizedAddressTableLookupDecoder;
628
- function getAddressTableLookupDecoder() {
629
- if (!memoizedAddressTableLookupDecoder) {
630
- memoizedAddressTableLookupDecoder = getStructDecoder(
631
- [
632
- ["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
633
- [
634
- "writableIndices",
635
- getArrayDecoder(getU8Decoder(), {
636
- description: writableIndicesDescription,
637
- size: getShortU16Decoder()
638
- })
639
- ],
640
- [
641
- "readableIndices",
642
- getArrayDecoder(getU8Decoder(), {
643
- description: readableIndicesDescription,
644
- size: getShortU16Decoder()
645
- })
646
- ]
647
- ],
648
- { description: addressTableLookupDescription }
649
- );
650
- }
651
- return memoizedAddressTableLookupDecoder;
652
- }
653
- var memoizedU8Encoder;
654
- function getMemoizedU8Encoder() {
655
- if (!memoizedU8Encoder)
656
- memoizedU8Encoder = getU8Encoder();
657
- return memoizedU8Encoder;
658
- }
659
- function getMemoizedU8EncoderDescription(description) {
660
- const encoder = getMemoizedU8Encoder();
661
- return {
662
- ...encoder,
663
- description: description ?? encoder.description
664
- };
665
- }
666
- var memoizedU8Decoder;
667
- function getMemoizedU8Decoder() {
668
- if (!memoizedU8Decoder)
669
- memoizedU8Decoder = getU8Decoder();
670
- return memoizedU8Decoder;
671
- }
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
- function getMessageHeaderEncoder() {
684
- return getStructEncoder(
685
- [
686
- ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
687
- ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
688
- ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
689
- ],
690
- {
691
- description: messageHeaderDescription
692
- }
693
- );
694
- }
695
- function getMessageHeaderDecoder() {
696
- return getStructDecoder(
697
- [
698
- ["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
699
- ["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
700
- ["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
701
- ],
702
- {
703
- description: messageHeaderDescription
704
- }
705
- );
706
- }
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
- var memoizedGetInstructionEncoder;
712
- function getInstructionEncoder() {
713
- if (!memoizedGetInstructionEncoder) {
714
- memoizedGetInstructionEncoder = mapEncoder(
715
- getStructEncoder([
716
- ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
717
- [
718
- "accountIndices",
719
- getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
720
- description: accountIndicesDescription,
721
- size: getShortU16Encoder()
722
- })
723
- ],
724
- ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
725
- ]),
726
- // Convert an instruction to have all fields defined
727
- (instruction) => {
728
- if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
729
- return instruction;
730
- }
731
- return {
732
- ...instruction,
733
- accountIndices: instruction.accountIndices ?? [],
734
- data: instruction.data ?? new Uint8Array(0)
735
- };
736
- }
737
- );
738
- }
739
- return memoizedGetInstructionEncoder;
740
- }
741
- var memoizedGetInstructionDecoder;
742
- function getInstructionDecoder() {
743
- if (!memoizedGetInstructionDecoder) {
744
- memoizedGetInstructionDecoder = mapDecoder(
745
- getStructDecoder([
746
- ["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
747
- [
748
- "accountIndices",
749
- getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
750
- description: accountIndicesDescription,
751
- size: getShortU16Decoder()
752
- })
753
- ],
754
- ["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
755
- ]),
756
- // Convert an instruction to exclude optional fields if they are empty
757
- (instruction) => {
758
- if (instruction.accountIndices.length && instruction.data.byteLength) {
759
- return instruction;
760
- }
761
- const { accountIndices, data, ...rest } = instruction;
762
- return {
763
- ...rest,
764
- ...accountIndices.length ? { accountIndices } : null,
765
- ...data.byteLength ? { data } : null
766
- };
767
- }
768
- );
769
- }
770
- return memoizedGetInstructionDecoder;
771
- }
772
- 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]);
795
- }
796
- function getTransactionVersionDecoder() {
797
- return {
798
- ...BASE_CONFIG,
799
- decode
800
- };
801
- }
802
- function getTransactionVersionEncoder() {
803
- return {
804
- ...BASE_CONFIG,
805
- encode
806
- };
807
- }
808
-
809
- // 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
- function getCompiledMessageLegacyEncoder() {
815
- return getStructEncoder(getPreludeStructEncoderTuple());
816
- }
817
- function getCompiledMessageVersionedEncoder() {
818
- return mapEncoder(
819
- getStructEncoder([
820
- ...getPreludeStructEncoderTuple(),
821
- ["addressTableLookups", getAddressTableLookupArrayEncoder()]
822
- ]),
823
- (value) => {
824
- if (value.version === "legacy") {
825
- return value;
826
- }
827
- return {
828
- ...value,
829
- addressTableLookups: value.addressTableLookups ?? []
830
- };
831
- }
832
- );
833
- }
834
- function getPreludeStructEncoderTuple() {
835
- return [
836
- ["version", getTransactionVersionEncoder()],
837
- ["header", getMessageHeaderEncoder()],
838
- [
839
- "staticAccounts",
840
- getArrayEncoder(getAddressEncoder(), {
841
- description: staticAccountsDescription,
842
- size: getShortU16Encoder()
843
- })
844
- ],
845
- [
846
- "lifetimeToken",
847
- getStringEncoder({
848
- description: lifetimeTokenDescription,
849
- encoding: getBase58Encoder(),
850
- size: 32
851
- })
852
- ],
853
- [
854
- "instructions",
855
- getArrayEncoder(getInstructionEncoder(), {
856
- description: instructionsDescription,
857
- size: getShortU16Encoder()
858
- })
859
- ]
860
- ];
861
- }
862
- function getPreludeStructDecoderTuple() {
863
- return [
864
- ["version", getTransactionVersionDecoder()],
865
- ["header", getMessageHeaderDecoder()],
866
- [
867
- "staticAccounts",
868
- getArrayDecoder(getAddressDecoder(), {
869
- description: staticAccountsDescription,
870
- size: getShortU16Decoder()
871
- })
872
- ],
873
- [
874
- "lifetimeToken",
875
- getStringDecoder({
876
- description: lifetimeTokenDescription,
877
- encoding: getBase58Decoder(),
878
- size: 32
879
- })
880
- ],
881
- [
882
- "instructions",
883
- getArrayDecoder(getInstructionDecoder(), {
884
- description: instructionsDescription,
885
- size: getShortU16Decoder()
886
- })
887
- ],
888
- ["addressTableLookups", getAddressTableLookupArrayDecoder()]
889
- ];
890
- }
891
- function getAddressTableLookupArrayEncoder() {
892
- return getArrayEncoder(getAddressTableLookupEncoder(), {
893
- description: addressTableLookupsDescription,
894
- size: getShortU16Encoder()
895
- });
896
- }
897
- function getAddressTableLookupArrayDecoder() {
898
- return getArrayDecoder(getAddressTableLookupDecoder(), {
899
- description: addressTableLookupsDescription,
900
- size: getShortU16Decoder()
901
- });
902
- }
903
- var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
904
- function getCompiledMessageEncoder() {
905
- return {
906
- description: messageDescription,
907
- encode: (compiledMessage) => {
908
- if (compiledMessage.version === "legacy") {
909
- return getCompiledMessageLegacyEncoder().encode(compiledMessage);
910
- } else {
911
- return getCompiledMessageVersionedEncoder().encode(compiledMessage);
912
- }
913
- },
914
- fixedSize: null,
915
- maxSize: null
916
- };
917
- }
918
- function getCompiledMessageDecoder() {
919
- return mapDecoder(
920
- getStructDecoder(getPreludeStructDecoderTuple(), {
921
- description: messageDescription
922
- }),
923
- ({ addressTableLookups, ...restOfMessage }) => {
924
- if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
925
- return restOfMessage;
926
- }
927
- return { ...restOfMessage, addressTableLookups };
928
- }
929
- );
930
- }
931
821
 
932
822
  // 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
823
  function getCompiledTransactionEncoder() {
936
- return getStructEncoder(
937
- [
938
- [
939
- "signatures",
940
- getArrayEncoder(getBytesEncoder({ size: 64 }), {
941
- description: signaturesDescription,
942
- size: getShortU16Encoder()
943
- })
944
- ],
945
- ["compiledMessage", getCompiledMessageEncoder()]
946
- ],
947
- {
948
- description: transactionDescription
949
- }
950
- );
951
- }
952
- function getSignatureDecoder() {
953
- return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
824
+ return getStructEncoder([
825
+ ["signatures", getArrayEncoder(getBytesEncoder({ size: 64 }), { size: getShortU16Encoder() })],
826
+ ["compiledMessage", getCompiledMessageEncoder()]
827
+ ]);
954
828
  }
955
829
  function getCompiledTransactionDecoder() {
956
- return getStructDecoder(
830
+ return getStructDecoder([
957
831
  [
958
- [
959
- "signatures",
960
- getArrayDecoder(getSignatureDecoder(), {
961
- description: signaturesDescription,
962
- size: getShortU16Decoder()
963
- })
964
- ],
965
- ["compiledMessage", getCompiledMessageDecoder()]
832
+ "signatures",
833
+ getArrayDecoder(getBytesDecoder({ size: 64 }), {
834
+ size: getShortU16Decoder()
835
+ })
966
836
  ],
967
- {
968
- description: transactionDescription
969
- }
970
- );
837
+ ["compiledMessage", getCompiledMessageDecoder()]
838
+ ]);
971
839
  }
972
840
  function getTransactionEncoder() {
973
841
  return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
@@ -981,47 +849,7 @@ function getTransactionDecoder(lastValidBlockHeight) {
981
849
  function getTransactionCodec(lastValidBlockHeight) {
982
850
  return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
983
851
  }
984
- var base58Encoder2;
985
852
  var base58Decoder;
986
- function assertIsTransactionSignature(putativeTransactionSignature) {
987
- if (!base58Encoder2)
988
- base58Encoder2 = getBase58Encoder();
989
- try {
990
- if (
991
- // Lowest value (64 bytes of zeroes)
992
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
993
- putativeTransactionSignature.length > 88
994
- ) {
995
- throw new Error("Expected input string to decode to a byte array of length 64.");
996
- }
997
- const bytes = base58Encoder2.encode(putativeTransactionSignature);
998
- const numBytes = bytes.byteLength;
999
- if (numBytes !== 64) {
1000
- throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1001
- }
1002
- } catch (e) {
1003
- throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1004
- cause: e
1005
- });
1006
- }
1007
- }
1008
- function isTransactionSignature(putativeTransactionSignature) {
1009
- if (!base58Encoder2)
1010
- base58Encoder2 = getBase58Encoder();
1011
- if (
1012
- // Lowest value (64 bytes of zeroes)
1013
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1014
- putativeTransactionSignature.length > 88
1015
- ) {
1016
- return false;
1017
- }
1018
- const bytes = base58Encoder2.encode(putativeTransactionSignature);
1019
- const numBytes = bytes.byteLength;
1020
- if (numBytes !== 64) {
1021
- return false;
1022
- }
1023
- return true;
1024
- }
1025
853
  function getSignatureFromTransaction(transaction) {
1026
854
  if (!base58Decoder)
1027
855
  base58Decoder = getBase58Decoder();
@@ -1031,10 +859,10 @@ function getSignatureFromTransaction(transaction) {
1031
859
  "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1032
860
  );
1033
861
  }
1034
- const transactionSignature2 = base58Decoder.decode(signatureBytes)[0];
1035
- return transactionSignature2;
862
+ const transactionSignature = base58Decoder.decode(signatureBytes);
863
+ return transactionSignature;
1036
864
  }
1037
- async function signTransaction(keyPairs, transaction) {
865
+ async function partiallySignTransaction(keyPairs, transaction) {
1038
866
  const compiledMessage = compileMessage(transaction);
1039
867
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1040
868
  const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
@@ -1053,9 +881,11 @@ async function signTransaction(keyPairs, transaction) {
1053
881
  Object.freeze(out);
1054
882
  return out;
1055
883
  }
1056
- function transactionSignature(putativeTransactionSignature) {
1057
- assertIsTransactionSignature(putativeTransactionSignature);
1058
- return putativeTransactionSignature;
884
+ async function signTransaction(keyPairs, transaction) {
885
+ const out = await partiallySignTransaction(keyPairs, transaction);
886
+ assertTransactionIsFullySigned(out);
887
+ Object.freeze(out);
888
+ return out;
1059
889
  }
1060
890
  function assertTransactionIsFullySigned(transaction) {
1061
891
  const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
@@ -1066,15 +896,11 @@ function assertTransactionIsFullySigned(transaction) {
1066
896
  }
1067
897
  });
1068
898
  }
1069
-
1070
- // src/wire-transaction.ts
1071
899
  function getBase64EncodedWireTransaction(transaction) {
1072
900
  const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1073
- {
1074
- return btoa(String.fromCharCode(...wireTransactionBytes));
1075
- }
901
+ return getBase64Decoder().decode(wireTransactionBytes);
1076
902
  }
1077
903
 
1078
- export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, assertTransactionIsFullySigned, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
904
+ export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionWithBlockhashLifetime, assertTransactionIsFullySigned, compileMessage, createTransaction, getBase64EncodedWireTransaction, getCompiledMessageCodec, getCompiledMessageDecoder, getCompiledMessageEncoder, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, partiallySignTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
1079
905
  //# sourceMappingURL=out.js.map
1080
906
  //# sourceMappingURL=index.browser.js.map