@solana/transaction-messages 2.2.0-canary-20250708184753 → 2.2.0

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