@solana/transaction-messages 2.2.1 → 2.3.0-canary-20250708185953

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 (43) hide show
  1. package/README.md +9 -9
  2. package/dist/index.browser.cjs +34 -32
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.mjs +34 -34
  5. package/dist/index.browser.mjs.map +1 -1
  6. package/dist/index.native.mjs +34 -34
  7. package/dist/index.native.mjs.map +1 -1
  8. package/dist/index.node.cjs +34 -32
  9. package/dist/index.node.cjs.map +1 -1
  10. package/dist/index.node.mjs +34 -34
  11. package/dist/index.node.mjs.map +1 -1
  12. package/dist/types/blockhash.d.ts +2 -3
  13. package/dist/types/blockhash.d.ts.map +1 -1
  14. package/dist/types/compilable-transaction-message.d.ts +4 -5
  15. package/dist/types/compilable-transaction-message.d.ts.map +1 -1
  16. package/dist/types/compile/accounts.d.ts +3 -3
  17. package/dist/types/compile/accounts.d.ts.map +1 -1
  18. package/dist/types/compile/instructions.d.ts +2 -2
  19. package/dist/types/compile/instructions.d.ts.map +1 -1
  20. package/dist/types/compress-transaction-message.d.ts +5 -5
  21. package/dist/types/compress-transaction-message.d.ts.map +1 -1
  22. package/dist/types/create-transaction-message.d.ts +7 -3
  23. package/dist/types/create-transaction-message.d.ts.map +1 -1
  24. package/dist/types/decompile-message.d.ts.map +1 -1
  25. package/dist/types/deprecated.d.ts +65 -0
  26. package/dist/types/deprecated.d.ts.map +1 -0
  27. package/dist/types/durable-nonce-instruction.d.ts +43 -0
  28. package/dist/types/durable-nonce-instruction.d.ts.map +1 -0
  29. package/dist/types/durable-nonce.d.ts +47 -49
  30. package/dist/types/durable-nonce.d.ts.map +1 -1
  31. package/dist/types/fee-payer.d.ts +8 -3
  32. package/dist/types/fee-payer.d.ts.map +1 -1
  33. package/dist/types/index.d.ts +3 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/instructions.d.ts +21 -6
  36. package/dist/types/instructions.d.ts.map +1 -1
  37. package/dist/types/lifetime.d.ts +12 -0
  38. package/dist/types/lifetime.d.ts.map +1 -0
  39. package/dist/types/transaction-message-size.d.ts +13 -0
  40. package/dist/types/transaction-message-size.d.ts.map +1 -0
  41. package/dist/types/transaction-message.d.ts +5 -5
  42. package/dist/types/transaction-message.d.ts.map +1 -1
  43. package/package.json +10 -10
@@ -1,5 +1,5 @@
1
1
  import { SolanaError, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_CANNOT_PAY_FEES } from '@solana/errors';
2
- import { assertIsBlockhash } from '@solana/rpc-types';
2
+ import { isBlockhash } from '@solana/rpc-types';
3
3
  import { getAddressDecoder, getAddressComparator, assertIsAddress, getAddressEncoder } from '@solana/addresses';
4
4
  import { createEncoder, createDecoder, combineCodec, transformDecoder, transformEncoder, fixDecoderSize, fixEncoderSize, addDecoderSizePrefix, addEncoderSizePrefix } from '@solana/codecs-core';
5
5
  import { getStructDecoder, getStructEncoder, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder } from '@solana/codecs-data-structures';
@@ -9,14 +9,7 @@ import { pipe } from '@solana/functional';
9
9
 
10
10
  // src/blockhash.ts
11
11
  function isTransactionMessageWithBlockhashLifetime(transactionMessage) {
12
- const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.blockhash === "string" && typeof transactionMessage.lifetimeConstraint.lastValidBlockHeight === "bigint";
13
- if (!lifetimeConstraintShapeMatches) return false;
14
- try {
15
- assertIsBlockhash(transactionMessage.lifetimeConstraint.blockhash);
16
- return true;
17
- } catch {
18
- return false;
19
- }
12
+ return "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.blockhash === "string" && typeof transactionMessage.lifetimeConstraint.lastValidBlockHeight === "bigint" && isBlockhash(transactionMessage.lifetimeConstraint.blockhash);
20
13
  }
21
14
  function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
22
15
  if (!isTransactionMessageWithBlockhashLifetime(transactionMessage)) {
@@ -24,15 +17,13 @@ function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
24
17
  }
25
18
  }
26
19
  function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint, transactionMessage) {
27
- if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transactionMessage.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
20
+ if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint && "blockhash" in transactionMessage.lifetimeConstraint && transactionMessage.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transactionMessage.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
28
21
  return transactionMessage;
29
22
  }
30
- const out = {
23
+ return Object.freeze({
31
24
  ...transactionMessage,
32
25
  lifetimeConstraint: Object.freeze(blockhashLifetimeConstraint)
33
- };
34
- Object.freeze(out);
35
- return out;
26
+ });
36
27
  }
37
28
  function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
38
29
  if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
@@ -658,21 +649,14 @@ function compressTransactionMessageUsingAddressLookupTables(transactionMessage,
658
649
  }
659
650
 
660
651
  // src/create-transaction-message.ts
661
- function createTransactionMessage({
662
- version
663
- }) {
652
+ function createTransactionMessage(config) {
664
653
  return Object.freeze({
665
654
  instructions: Object.freeze([]),
666
- version
655
+ version: config.version
667
656
  });
668
657
  }
669
658
  var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
670
659
  var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
671
- function assertIsDurableNonceTransactionMessage(transactionMessage) {
672
- if (!isDurableNonceTransaction(transactionMessage)) {
673
- throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);
674
- }
675
- }
676
660
  function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
677
661
  return {
678
662
  accounts: [
@@ -698,9 +682,16 @@ function isAdvanceNonceAccountInstruction(instruction) {
698
682
  function isAdvanceNonceAccountInstructionData(data) {
699
683
  return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
700
684
  }
701
- function isDurableNonceTransaction(transactionMessage) {
685
+
686
+ // src/durable-nonce.ts
687
+ function isTransactionMessageWithDurableNonceLifetime(transactionMessage) {
702
688
  return "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.nonce === "string" && transactionMessage.instructions[0] != null && isAdvanceNonceAccountInstruction(transactionMessage.instructions[0]);
703
689
  }
690
+ function assertIsTransactionMessageWithDurableNonceLifetime(transactionMessage) {
691
+ if (!isTransactionMessageWithDurableNonceLifetime(transactionMessage)) {
692
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);
693
+ }
694
+ }
704
695
  function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
705
696
  return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
706
697
  }
@@ -713,7 +704,7 @@ function setTransactionMessageLifetimeUsingDurableNonce({
713
704
  const firstInstruction = transactionMessage.instructions[0];
714
705
  if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
715
706
  if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
716
- if (isDurableNonceTransaction(transactionMessage) && transactionMessage.lifetimeConstraint.nonce === nonce) {
707
+ if (isTransactionMessageWithDurableNonceLifetime(transactionMessage) && transactionMessage.lifetimeConstraint.nonce === nonce) {
717
708
  return transactionMessage;
718
709
  } else {
719
710
  newInstructions = [firstInstruction, ...transactionMessage.instructions.slice(1)];
@@ -733,9 +724,7 @@ function setTransactionMessageLifetimeUsingDurableNonce({
733
724
  return Object.freeze({
734
725
  ...transactionMessage,
735
726
  instructions: Object.freeze(newInstructions),
736
- lifetimeConstraint: Object.freeze({
737
- nonce
738
- })
727
+ lifetimeConstraint: Object.freeze({ nonce })
739
728
  });
740
729
  }
741
730
 
@@ -762,7 +751,10 @@ function appendTransactionMessageInstruction(instruction, transactionMessage) {
762
751
  function appendTransactionMessageInstructions(instructions, transactionMessage) {
763
752
  return Object.freeze({
764
753
  ...transactionMessage,
765
- instructions: Object.freeze([...transactionMessage.instructions, ...instructions])
754
+ instructions: Object.freeze([
755
+ ...transactionMessage.instructions,
756
+ ...instructions
757
+ ])
766
758
  });
767
759
  }
768
760
  function prependTransactionMessageInstruction(instruction, transactionMessage) {
@@ -771,7 +763,10 @@ function prependTransactionMessageInstruction(instruction, transactionMessage) {
771
763
  function prependTransactionMessageInstructions(instructions, transactionMessage) {
772
764
  return Object.freeze({
773
765
  ...transactionMessage,
774
- instructions: Object.freeze([...instructions, ...transactionMessage.instructions])
766
+ instructions: Object.freeze([
767
+ ...instructions,
768
+ ...transactionMessage.instructions
769
+ ])
775
770
  });
776
771
  }
777
772
 
@@ -913,13 +908,18 @@ function decompileTransactionMessage(compiledTransactionMessage, config) {
913
908
  return pipe(
914
909
  createTransactionMessage({ version: compiledTransactionMessage.version }),
915
910
  (m) => setTransactionMessageFeePayer(feePayer, m),
916
- (m) => instructions.reduce((acc, instruction) => {
917
- return appendTransactionMessageInstruction(instruction, acc);
918
- }, m),
911
+ (m) => instructions.reduce(
912
+ (acc, instruction) => appendTransactionMessageInstruction(instruction, acc),
913
+ m
914
+ ),
919
915
  (m) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, m) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, m)
920
916
  );
921
917
  }
922
918
 
923
- export { appendTransactionMessageInstruction, appendTransactionMessageInstructions, assertIsDurableNonceTransactionMessage, assertIsTransactionMessageWithBlockhashLifetime, compileTransactionMessage, compressTransactionMessageUsingAddressLookupTables, createTransactionMessage, decompileTransactionMessage, getCompiledTransactionMessageCodec, getCompiledTransactionMessageDecoder, getCompiledTransactionMessageEncoder, getTransactionVersionCodec, getTransactionVersionDecoder, getTransactionVersionEncoder, isAdvanceNonceAccountInstruction, isDurableNonceTransaction, isTransactionMessageWithBlockhashLifetime, prependTransactionMessageInstruction, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageLifetimeUsingDurableNonce };
919
+ // src/deprecated.ts
920
+ var assertIsDurableNonceTransactionMessage = assertIsTransactionMessageWithDurableNonceLifetime;
921
+ var isDurableNonceTransaction = isTransactionMessageWithDurableNonceLifetime;
922
+
923
+ export { appendTransactionMessageInstruction, appendTransactionMessageInstructions, assertIsDurableNonceTransactionMessage, assertIsTransactionMessageWithBlockhashLifetime, assertIsTransactionMessageWithDurableNonceLifetime, compileTransactionMessage, compressTransactionMessageUsingAddressLookupTables, createTransactionMessage, decompileTransactionMessage, getCompiledTransactionMessageCodec, getCompiledTransactionMessageDecoder, getCompiledTransactionMessageEncoder, getTransactionVersionCodec, getTransactionVersionDecoder, getTransactionVersionEncoder, isAdvanceNonceAccountInstruction, isDurableNonceTransaction, isTransactionMessageWithBlockhashLifetime, isTransactionMessageWithDurableNonceLifetime, prependTransactionMessageInstruction, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageLifetimeUsingDurableNonce };
924
924
  //# sourceMappingURL=index.browser.mjs.map
925
925
  //# sourceMappingURL=index.browser.mjs.map