@solana/transaction-messages 2.1.1-canary-20250425205850 → 2.1.1-canary-20250425210025
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.
- package/README.md +7 -7
- package/dist/index.browser.cjs +44 -41
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +44 -41
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +44 -41
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +44 -41
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +44 -41
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/blockhash.d.ts +4 -4
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/compile/message.d.ts +2 -2
- package/dist/types/compile/message.d.ts.map +1 -1
- package/dist/types/durable-nonce.d.ts +3 -3
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/instructions.d.ts +4 -4
- package/dist/types/instructions.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/index.browser.mjs
CHANGED
|
@@ -8,27 +8,27 @@ import { isSignerRole, AccountRole, isWritableRole, mergeRoles } from '@solana/i
|
|
|
8
8
|
import { pipe } from '@solana/functional';
|
|
9
9
|
|
|
10
10
|
// src/blockhash.ts
|
|
11
|
-
function isTransactionMessageWithBlockhashLifetime(
|
|
12
|
-
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in
|
|
11
|
+
function isTransactionMessageWithBlockhashLifetime(transactionMessage) {
|
|
12
|
+
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.blockhash === "string" && typeof transactionMessage.lifetimeConstraint.lastValidBlockHeight === "bigint";
|
|
13
13
|
if (!lifetimeConstraintShapeMatches) return false;
|
|
14
14
|
try {
|
|
15
|
-
assertIsBlockhash(
|
|
15
|
+
assertIsBlockhash(transactionMessage.lifetimeConstraint.blockhash);
|
|
16
16
|
return true;
|
|
17
17
|
} catch {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
function assertIsTransactionMessageWithBlockhashLifetime(
|
|
22
|
-
if (!isTransactionMessageWithBlockhashLifetime(
|
|
21
|
+
function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
|
|
22
|
+
if (!isTransactionMessageWithBlockhashLifetime(transactionMessage)) {
|
|
23
23
|
throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint,
|
|
27
|
-
if ("lifetimeConstraint" in
|
|
28
|
-
return
|
|
26
|
+
function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint, transactionMessage) {
|
|
27
|
+
if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transactionMessage.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
28
|
+
return transactionMessage;
|
|
29
29
|
}
|
|
30
30
|
const out = {
|
|
31
|
-
...
|
|
31
|
+
...transactionMessage,
|
|
32
32
|
lifetimeConstraint: Object.freeze(blockhashLifetimeConstraint)
|
|
33
33
|
};
|
|
34
34
|
Object.freeze(out);
|
|
@@ -584,16 +584,19 @@ function getCompiledStaticAccounts(orderedAccounts) {
|
|
|
584
584
|
}
|
|
585
585
|
|
|
586
586
|
// src/compile/message.ts
|
|
587
|
-
function compileTransactionMessage(
|
|
588
|
-
const addressMap = getAddressMapFromInstructions(
|
|
587
|
+
function compileTransactionMessage(transactionMessage) {
|
|
588
|
+
const addressMap = getAddressMapFromInstructions(
|
|
589
|
+
transactionMessage.feePayer.address,
|
|
590
|
+
transactionMessage.instructions
|
|
591
|
+
);
|
|
589
592
|
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
|
|
590
593
|
return {
|
|
591
|
-
...
|
|
594
|
+
...transactionMessage.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
|
|
592
595
|
header: getCompiledMessageHeader(orderedAccounts),
|
|
593
|
-
instructions: getCompiledInstructions(
|
|
594
|
-
lifetimeToken: getCompiledLifetimeToken(
|
|
596
|
+
instructions: getCompiledInstructions(transactionMessage.instructions, orderedAccounts),
|
|
597
|
+
lifetimeToken: getCompiledLifetimeToken(transactionMessage.lifetimeConstraint),
|
|
595
598
|
staticAccounts: getCompiledStaticAccounts(orderedAccounts),
|
|
596
|
-
version:
|
|
599
|
+
version: transactionMessage.version
|
|
597
600
|
};
|
|
598
601
|
}
|
|
599
602
|
function findAddressInLookupTables(address, role, addressesByLookupTableAddress) {
|
|
@@ -655,8 +658,8 @@ function createTransactionMessage({
|
|
|
655
658
|
}
|
|
656
659
|
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
657
660
|
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
658
|
-
function assertIsDurableNonceTransactionMessage(
|
|
659
|
-
if (!isDurableNonceTransaction(
|
|
661
|
+
function assertIsDurableNonceTransactionMessage(transactionMessage) {
|
|
662
|
+
if (!isDurableNonceTransaction(transactionMessage)) {
|
|
660
663
|
throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);
|
|
661
664
|
}
|
|
662
665
|
}
|
|
@@ -685,8 +688,8 @@ function isAdvanceNonceAccountInstruction(instruction) {
|
|
|
685
688
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
686
689
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
687
690
|
}
|
|
688
|
-
function isDurableNonceTransaction(
|
|
689
|
-
return "lifetimeConstraint" in
|
|
691
|
+
function isDurableNonceTransaction(transactionMessage) {
|
|
692
|
+
return "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.nonce === "string" && transactionMessage.instructions[0] != null && isAdvanceNonceAccountInstruction(transactionMessage.instructions[0]);
|
|
690
693
|
}
|
|
691
694
|
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
692
695
|
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
@@ -695,30 +698,30 @@ function setTransactionMessageLifetimeUsingDurableNonce({
|
|
|
695
698
|
nonce,
|
|
696
699
|
nonceAccountAddress,
|
|
697
700
|
nonceAuthorityAddress
|
|
698
|
-
},
|
|
701
|
+
}, transactionMessage) {
|
|
699
702
|
let newInstructions;
|
|
700
|
-
const firstInstruction =
|
|
703
|
+
const firstInstruction = transactionMessage.instructions[0];
|
|
701
704
|
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
702
705
|
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
703
|
-
if (isDurableNonceTransaction(
|
|
704
|
-
return
|
|
706
|
+
if (isDurableNonceTransaction(transactionMessage) && transactionMessage.lifetimeConstraint.nonce === nonce) {
|
|
707
|
+
return transactionMessage;
|
|
705
708
|
} else {
|
|
706
|
-
newInstructions = [firstInstruction, ...
|
|
709
|
+
newInstructions = [firstInstruction, ...transactionMessage.instructions.slice(1)];
|
|
707
710
|
}
|
|
708
711
|
} else {
|
|
709
712
|
newInstructions = [
|
|
710
713
|
Object.freeze(createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress)),
|
|
711
|
-
...
|
|
714
|
+
...transactionMessage.instructions.slice(1)
|
|
712
715
|
];
|
|
713
716
|
}
|
|
714
717
|
} else {
|
|
715
718
|
newInstructions = [
|
|
716
719
|
Object.freeze(createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress)),
|
|
717
|
-
...
|
|
720
|
+
...transactionMessage.instructions
|
|
718
721
|
];
|
|
719
722
|
}
|
|
720
723
|
return Object.freeze({
|
|
721
|
-
...
|
|
724
|
+
...transactionMessage,
|
|
722
725
|
instructions: Object.freeze(newInstructions),
|
|
723
726
|
lifetimeConstraint: Object.freeze({
|
|
724
727
|
nonce
|
|
@@ -743,22 +746,22 @@ function isAddressOnlyFeePayer(feePayer) {
|
|
|
743
746
|
}
|
|
744
747
|
|
|
745
748
|
// src/instructions.ts
|
|
746
|
-
function appendTransactionMessageInstruction(instruction,
|
|
747
|
-
return appendTransactionMessageInstructions([instruction],
|
|
749
|
+
function appendTransactionMessageInstruction(instruction, transactionMessage) {
|
|
750
|
+
return appendTransactionMessageInstructions([instruction], transactionMessage);
|
|
748
751
|
}
|
|
749
|
-
function appendTransactionMessageInstructions(instructions,
|
|
752
|
+
function appendTransactionMessageInstructions(instructions, transactionMessage) {
|
|
750
753
|
return Object.freeze({
|
|
751
|
-
...
|
|
752
|
-
instructions: Object.freeze([...
|
|
754
|
+
...transactionMessage,
|
|
755
|
+
instructions: Object.freeze([...transactionMessage.instructions, ...instructions])
|
|
753
756
|
});
|
|
754
757
|
}
|
|
755
|
-
function prependTransactionMessageInstruction(instruction,
|
|
756
|
-
return prependTransactionMessageInstructions([instruction],
|
|
758
|
+
function prependTransactionMessageInstruction(instruction, transactionMessage) {
|
|
759
|
+
return prependTransactionMessageInstructions([instruction], transactionMessage);
|
|
757
760
|
}
|
|
758
|
-
function prependTransactionMessageInstructions(instructions,
|
|
761
|
+
function prependTransactionMessageInstructions(instructions, transactionMessage) {
|
|
759
762
|
return Object.freeze({
|
|
760
|
-
...
|
|
761
|
-
instructions: Object.freeze([...instructions, ...
|
|
763
|
+
...transactionMessage,
|
|
764
|
+
instructions: Object.freeze([...instructions, ...transactionMessage.instructions])
|
|
762
765
|
});
|
|
763
766
|
}
|
|
764
767
|
|
|
@@ -895,11 +898,11 @@ function decompileTransactionMessage(compiledTransactionMessage, config) {
|
|
|
895
898
|
);
|
|
896
899
|
return pipe(
|
|
897
900
|
createTransactionMessage({ version: compiledTransactionMessage.version }),
|
|
898
|
-
(
|
|
899
|
-
(
|
|
901
|
+
(m) => setTransactionMessageFeePayer(feePayer, m),
|
|
902
|
+
(m) => instructions.reduce((acc, instruction) => {
|
|
900
903
|
return appendTransactionMessageInstruction(instruction, acc);
|
|
901
|
-
},
|
|
902
|
-
(
|
|
904
|
+
}, m),
|
|
905
|
+
(m) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, m) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, m)
|
|
903
906
|
);
|
|
904
907
|
}
|
|
905
908
|
|