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