@solana/transactions 2.0.0-experimental.ba21818 → 2.0.0-experimental.ba9b4c7

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 (44) hide show
  1. package/dist/index.browser.cjs +164 -149
  2. package/dist/index.browser.cjs.map +1 -1
  3. package/dist/index.browser.js +167 -153
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.development.js +397 -146
  6. package/dist/index.development.js.map +1 -1
  7. package/dist/index.native.js +167 -153
  8. package/dist/index.native.js.map +1 -1
  9. package/dist/index.node.cjs +164 -147
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.js +167 -153
  12. package/dist/index.node.js.map +1 -1
  13. package/dist/index.production.min.js +17 -16
  14. package/dist/types/durable-nonce.d.ts +1 -0
  15. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  16. package/dist/types/serializers/header.d.ts +4 -2
  17. package/dist/types/serializers/instruction.d.ts +4 -2
  18. package/package.json +10 -8
  19. package/dist/types/accounts.d.ts.map +0 -1
  20. package/dist/types/blockhash.d.ts.map +0 -1
  21. package/dist/types/compile-address-table-lookups.d.ts.map +0 -1
  22. package/dist/types/compile-header.d.ts.map +0 -1
  23. package/dist/types/compile-instructions.d.ts.map +0 -1
  24. package/dist/types/compile-lifetime-token.d.ts.map +0 -1
  25. package/dist/types/compile-static-accounts.d.ts.map +0 -1
  26. package/dist/types/compile-transaction.d.ts.map +0 -1
  27. package/dist/types/create-transaction.d.ts.map +0 -1
  28. package/dist/types/durable-nonce.d.ts.map +0 -1
  29. package/dist/types/fee-payer.d.ts.map +0 -1
  30. package/dist/types/index.d.ts.map +0 -1
  31. package/dist/types/instructions.d.ts.map +0 -1
  32. package/dist/types/message.d.ts.map +0 -1
  33. package/dist/types/serializers/address-table-lookup.d.ts.map +0 -1
  34. package/dist/types/serializers/header.d.ts.map +0 -1
  35. package/dist/types/serializers/index.d.ts.map +0 -1
  36. package/dist/types/serializers/instruction.d.ts.map +0 -1
  37. package/dist/types/serializers/message.d.ts.map +0 -1
  38. package/dist/types/serializers/transaction-version.d.ts.map +0 -1
  39. package/dist/types/serializers/transaction.d.ts.map +0 -1
  40. package/dist/types/serializers/unimplemented.d.ts.map +0 -1
  41. package/dist/types/signatures.d.ts.map +0 -1
  42. package/dist/types/types.d.ts.map +0 -1
  43. package/dist/types/unsigned-transaction.d.ts.map +0 -1
  44. package/dist/types/wire-transaction.d.ts.map +0 -1
@@ -3,6 +3,8 @@
3
3
  var umiSerializers = require('@metaplex-foundation/umi-serializers');
4
4
  var addresses = require('@solana/addresses');
5
5
  var codecsCore = require('@solana/codecs-core');
6
+ var codecsDataStructures = require('@solana/codecs-data-structures');
7
+ var codecsNumbers = require('@solana/codecs-numbers');
6
8
  var keys = require('@solana/keys');
7
9
 
8
10
  // ../build-scripts/env-shim.ts
@@ -32,8 +34,8 @@ function assertIsBlockhash(putativeBlockhash) {
32
34
  ) {
33
35
  throw new Error("Expected input string to decode to a byte array of length 32.");
34
36
  }
35
- const bytes3 = umiSerializers.base58.serialize(putativeBlockhash);
36
- const numBytes = bytes3.byteLength;
37
+ const bytes2 = umiSerializers.base58.serialize(putativeBlockhash);
38
+ const numBytes = bytes2.byteLength;
37
39
  if (numBytes !== 32) {
38
40
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
39
41
  }
@@ -463,137 +465,161 @@ function getCompiledTransaction(transaction) {
463
465
  signatures
464
466
  };
465
467
  }
466
- function addressSerializerCompat(compat) {
467
- const codec = addresses.getAddressCodec();
468
- return {
469
- description: compat?.description ?? codec.description,
470
- deserialize: codec.decode,
471
- fixedSize: codec.fixedSize,
472
- maxSize: codec.maxSize,
473
- serialize: codec.encode
474
- };
475
- }
476
- function getAddressTableLookupCodec() {
477
- return umiSerializers.struct(
478
- [
468
+ var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
469
+ var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
470
+ var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
471
+ 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";
472
+ var memoizedAddressTableLookupEncoder;
473
+ function getAddressTableLookupEncoder() {
474
+ if (!memoizedAddressTableLookupEncoder) {
475
+ memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder(
479
476
  [
480
- "lookupTableAddress",
481
- addressSerializerCompat(
482
- __DEV__ ? {
483
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
484
- } : void 0
485
- )
477
+ ["lookupTableAddress", addresses.getAddressEncoder({ description: lookupTableAddressDescription })],
478
+ [
479
+ "writableIndices",
480
+ codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
481
+ description: writableIndicesDescription,
482
+ size: codecsNumbers.getShortU16Encoder()
483
+ })
484
+ ],
485
+ [
486
+ "readableIndices",
487
+ codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
488
+ description: readableIndicesDescription,
489
+ size: codecsNumbers.getShortU16Encoder()
490
+ })
491
+ ]
486
492
  ],
493
+ { description: addressTableLookupDescription }
494
+ );
495
+ }
496
+ return memoizedAddressTableLookupEncoder;
497
+ }
498
+ var memoizedAddressTableLookupDecoder;
499
+ function getAddressTableLookupDecoder() {
500
+ if (!memoizedAddressTableLookupDecoder) {
501
+ memoizedAddressTableLookupDecoder = codecsDataStructures.getStructDecoder(
487
502
  [
488
- "writableIndices",
489
- umiSerializers.array(umiSerializers.u8(), {
490
- ...__DEV__ ? {
491
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
492
- } : null,
493
- size: umiSerializers.shortU16()
494
- })
503
+ ["lookupTableAddress", addresses.getAddressDecoder({ description: lookupTableAddressDescription })],
504
+ [
505
+ "writableIndices",
506
+ codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
507
+ description: writableIndicesDescription,
508
+ size: codecsNumbers.getShortU16Decoder()
509
+ })
510
+ ],
511
+ [
512
+ "readableIndices",
513
+ codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
514
+ description: readableIndicesDescription,
515
+ size: codecsNumbers.getShortU16Decoder()
516
+ })
517
+ ]
495
518
  ],
496
- [
497
- "readableIndices",
498
- umiSerializers.array(umiSerializers.u8(), {
499
- ...__DEV__ ? {
500
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
501
- } : void 0,
502
- size: umiSerializers.shortU16()
503
- })
504
- ]
505
- ],
506
- __DEV__ ? {
507
- description: "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"
508
- } : void 0
509
- );
519
+ { description: addressTableLookupDescription }
520
+ );
521
+ }
522
+ return memoizedAddressTableLookupDecoder;
523
+ }
524
+ function getAddressTableLookupCodec() {
525
+ return codecsCore.combineCodec(getAddressTableLookupEncoder(), getAddressTableLookupDecoder());
526
+ }
527
+ var memoizedU8Codec;
528
+ function getMemoizedU8Codec() {
529
+ if (!memoizedU8Codec)
530
+ memoizedU8Codec = codecsNumbers.getU8Codec();
531
+ return memoizedU8Codec;
510
532
  }
533
+ function getMemoizedU8CodecDescription(description) {
534
+ const codec = getMemoizedU8Codec();
535
+ return {
536
+ ...codec,
537
+ description: description ?? codec.description
538
+ };
539
+ }
540
+ 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;
541
+ 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;
542
+ var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
543
+ var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
511
544
  function getMessageHeaderCodec() {
512
- return umiSerializers.struct(
545
+ return codecsDataStructures.getStructCodec(
513
546
  [
514
- [
515
- "numSignerAccounts",
516
- umiSerializers.u8(
517
- __DEV__ ? {
518
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
519
- } : void 0
520
- )
521
- ],
522
- [
523
- "numReadonlySignerAccounts",
524
- umiSerializers.u8(
525
- __DEV__ ? {
526
- description: "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"
527
- } : void 0
528
- )
529
- ],
530
- [
531
- "numReadonlyNonSignerAccounts",
532
- umiSerializers.u8(
533
- __DEV__ ? {
534
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
535
- } : void 0
536
- )
537
- ]
547
+ ["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
548
+ ["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
549
+ ["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
538
550
  ],
539
- __DEV__ ? {
540
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
541
- } : void 0
551
+ {
552
+ description: messageHeaderDescription
553
+ }
542
554
  );
543
555
  }
544
- function getInstructionCodec() {
545
- return umiSerializers.mapSerializer(
546
- umiSerializers.struct([
547
- [
548
- "programAddressIndex",
549
- umiSerializers.u8(
550
- __DEV__ ? {
551
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
552
- } : void 0
553
- )
554
- ],
555
- [
556
- "accountIndices",
557
- umiSerializers.array(
558
- umiSerializers.u8({
559
- description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
560
- }),
561
- {
562
- description: __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" : "",
563
- size: umiSerializers.shortU16()
564
- }
565
- )
566
- ],
567
- [
568
- "data",
569
- umiSerializers.bytes({
570
- description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
571
- size: umiSerializers.shortU16()
572
- })
573
- ]
574
- ]),
575
- (value) => {
576
- if (value.accountIndices !== void 0 && value.data !== void 0) {
577
- return value;
556
+ var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
557
+ var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
558
+ 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";
559
+ var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
560
+ var memoizedGetInstructionEncoder;
561
+ function getInstructionEncoder() {
562
+ if (!memoizedGetInstructionEncoder) {
563
+ memoizedGetInstructionEncoder = codecsCore.mapEncoder(
564
+ codecsDataStructures.getStructEncoder([
565
+ ["programAddressIndex", codecsNumbers.getU8Encoder({ description: programAddressIndexDescription })],
566
+ [
567
+ "accountIndices",
568
+ codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder({ description: accountIndexDescription }), {
569
+ description: accountIndicesDescription,
570
+ size: codecsNumbers.getShortU16Encoder()
571
+ })
572
+ ],
573
+ ["data", codecsDataStructures.getBytesEncoder({ description: dataDescription, size: codecsNumbers.getShortU16Encoder() })]
574
+ ]),
575
+ // Convert an instruction to have all fields defined
576
+ (instruction) => {
577
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
578
+ return instruction;
579
+ }
580
+ return {
581
+ ...instruction,
582
+ accountIndices: instruction.accountIndices ?? [],
583
+ data: instruction.data ?? new Uint8Array(0)
584
+ };
578
585
  }
579
- return {
580
- ...value,
581
- accountIndices: value.accountIndices ?? [],
582
- data: value.data ?? new Uint8Array(0)
583
- };
584
- },
585
- (value) => {
586
- if (value.accountIndices.length && value.data.byteLength) {
587
- return value;
586
+ );
587
+ }
588
+ return memoizedGetInstructionEncoder;
589
+ }
590
+ var memoizedGetInstructionDecoder;
591
+ function getInstructionDecoder() {
592
+ if (!memoizedGetInstructionDecoder) {
593
+ memoizedGetInstructionDecoder = codecsCore.mapDecoder(
594
+ codecsDataStructures.getStructDecoder([
595
+ ["programAddressIndex", codecsNumbers.getU8Decoder({ description: programAddressIndexDescription })],
596
+ [
597
+ "accountIndices",
598
+ codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder({ description: accountIndexDescription }), {
599
+ description: accountIndicesDescription,
600
+ size: codecsNumbers.getShortU16Decoder()
601
+ })
602
+ ],
603
+ ["data", codecsDataStructures.getBytesDecoder({ description: dataDescription, size: codecsNumbers.getShortU16Decoder() })]
604
+ ]),
605
+ // Convert an instruction to exclude optional fields if they are empty
606
+ (instruction) => {
607
+ if (instruction.accountIndices.length && instruction.data.byteLength) {
608
+ return instruction;
609
+ }
610
+ const { accountIndices, data, ...rest } = instruction;
611
+ return {
612
+ ...rest,
613
+ ...accountIndices.length ? { accountIndices } : null,
614
+ ...data.byteLength ? { data } : null
615
+ };
588
616
  }
589
- const { accountIndices, data, ...rest } = value;
590
- return {
591
- ...rest,
592
- ...accountIndices.length ? { accountIndices } : null,
593
- ...data.byteLength ? { data } : null
594
- };
595
- }
596
- );
617
+ );
618
+ }
619
+ return memoizedGetInstructionDecoder;
620
+ }
621
+ function getInstructionCodec() {
622
+ return codecsCore.combineCodec(getInstructionEncoder(), getInstructionDecoder());
597
623
  }
598
624
  var VERSION_FLAG_MASK = 128;
599
625
  var BASE_CONFIG = {
@@ -601,8 +627,8 @@ var BASE_CONFIG = {
601
627
  fixedSize: null,
602
628
  maxSize: 1
603
629
  };
604
- function decode(bytes3, offset = 0) {
605
- const firstByte = bytes3[offset];
630
+ function decode(bytes2, offset = 0) {
631
+ const firstByte = bytes2[offset];
606
632
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
607
633
  return ["legacy", offset];
608
634
  } else {
@@ -675,18 +701,7 @@ function serialize(compiledMessage) {
675
701
  ).serialize(compiledMessage);
676
702
  }
677
703
  }
678
- function addressSerializerCompat2() {
679
- const codec = addresses.getAddressCodec();
680
- return {
681
- description: codec.description,
682
- deserialize: codec.decode,
683
- fixedSize: codec.fixedSize,
684
- maxSize: codec.maxSize,
685
- serialize: codec.encode
686
- };
687
- }
688
- function transactionVersionSerializerCompat() {
689
- const codec = getTransactionVersionCodec();
704
+ function toSerializer(codec) {
690
705
  return {
691
706
  description: codec.description,
692
707
  deserialize: codec.decode,
@@ -697,11 +712,11 @@ function transactionVersionSerializerCompat() {
697
712
  }
698
713
  function getPreludeStructSerializerTuple() {
699
714
  return [
700
- ["version", transactionVersionSerializerCompat()],
701
- ["header", getMessageHeaderCodec()],
715
+ ["version", toSerializer(getTransactionVersionCodec())],
716
+ ["header", toSerializer(getMessageHeaderCodec())],
702
717
  [
703
718
  "staticAccounts",
704
- umiSerializers.array(addressSerializerCompat2(), {
719
+ umiSerializers.array(toSerializer(addresses.getAddressCodec()), {
705
720
  description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
706
721
  size: umiSerializers.shortU16()
707
722
  })
@@ -716,7 +731,7 @@ function getPreludeStructSerializerTuple() {
716
731
  ],
717
732
  [
718
733
  "instructions",
719
- umiSerializers.array(getInstructionCodec(), {
734
+ umiSerializers.array(toSerializer(getInstructionCodec()), {
720
735
  description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "",
721
736
  size: umiSerializers.shortU16()
722
737
  })
@@ -724,7 +739,7 @@ function getPreludeStructSerializerTuple() {
724
739
  ];
725
740
  }
726
741
  function getAddressTableLookupsSerializer() {
727
- return umiSerializers.array(getAddressTableLookupCodec(), {
742
+ return umiSerializers.array(toSerializer(getAddressTableLookupCodec()), {
728
743
  ...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null,
729
744
  size: umiSerializers.shortU16()
730
745
  });
@@ -772,8 +787,8 @@ function assertIsTransactionSignature(putativeTransactionSignature) {
772
787
  ) {
773
788
  throw new Error("Expected input string to decode to a byte array of length 64.");
774
789
  }
775
- const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
776
- const numBytes = bytes3.byteLength;
790
+ const bytes2 = umiSerializers.base58.serialize(putativeTransactionSignature);
791
+ const numBytes = bytes2.byteLength;
777
792
  if (numBytes !== 64) {
778
793
  throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
779
794
  }
@@ -791,8 +806,8 @@ function isTransactionSignature(putativeTransactionSignature) {
791
806
  ) {
792
807
  return false;
793
808
  }
794
- const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
795
- const numBytes = bytes3.byteLength;
809
+ const bytes2 = umiSerializers.base58.serialize(putativeTransactionSignature);
810
+ const numBytes = bytes2.byteLength;
796
811
  if (numBytes !== 64) {
797
812
  return false;
798
813
  }
@@ -804,13 +819,14 @@ async function getCompiledMessageSignature(message, secretKey) {
804
819
  return signature;
805
820
  }
806
821
  function getSignatureFromTransaction(transaction) {
807
- const signature = transaction.signatures[transaction.feePayer];
808
- if (!signature) {
822
+ const signatureBytes = transaction.signatures[transaction.feePayer];
823
+ if (!signatureBytes) {
809
824
  throw new Error(
810
825
  "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
811
826
  );
812
827
  }
813
- return signature;
828
+ const transactionSignature2 = umiSerializers.base58.deserialize(signatureBytes)[0];
829
+ return transactionSignature2;
814
830
  }
815
831
  async function signTransaction(keyPairs, transaction) {
816
832
  const compiledMessage = compileMessage(transaction);
@@ -854,6 +870,7 @@ exports.createTransaction = createTransaction;
854
870
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
855
871
  exports.getSignatureFromTransaction = getSignatureFromTransaction;
856
872
  exports.getTransactionEncoder = getTransactionEncoder;
873
+ exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
857
874
  exports.isTransactionSignature = isTransactionSignature;
858
875
  exports.prependTransactionInstruction = prependTransactionInstruction;
859
876
  exports.setTransactionFeePayer = setTransactionFeePayer;
@@ -861,5 +878,3 @@ exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockh
861
878
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
862
879
  exports.signTransaction = signTransaction;
863
880
  exports.transactionSignature = transactionSignature;
864
- //# sourceMappingURL=out.js.map
865
- //# sourceMappingURL=index.browser.cjs.map