@solana/transaction-messages 2.2.1 → 2.3.0-canary-20250708190258
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 +9 -9
- package/dist/index.browser.cjs +34 -32
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +34 -34
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +34 -34
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +34 -32
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +34 -34
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/blockhash.d.ts +2 -3
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/compilable-transaction-message.d.ts +4 -5
- package/dist/types/compilable-transaction-message.d.ts.map +1 -1
- package/dist/types/compile/accounts.d.ts +3 -3
- package/dist/types/compile/accounts.d.ts.map +1 -1
- package/dist/types/compile/instructions.d.ts +2 -2
- package/dist/types/compile/instructions.d.ts.map +1 -1
- package/dist/types/compress-transaction-message.d.ts +5 -5
- package/dist/types/compress-transaction-message.d.ts.map +1 -1
- package/dist/types/create-transaction-message.d.ts +7 -3
- package/dist/types/create-transaction-message.d.ts.map +1 -1
- package/dist/types/decompile-message.d.ts.map +1 -1
- package/dist/types/deprecated.d.ts +65 -0
- package/dist/types/deprecated.d.ts.map +1 -0
- package/dist/types/durable-nonce-instruction.d.ts +43 -0
- package/dist/types/durable-nonce-instruction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +47 -49
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/fee-payer.d.ts +8 -3
- package/dist/types/fee-payer.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/instructions.d.ts +21 -6
- package/dist/types/instructions.d.ts.map +1 -1
- package/dist/types/lifetime.d.ts +12 -0
- package/dist/types/lifetime.d.ts.map +1 -0
- package/dist/types/transaction-message-size.d.ts +13 -0
- package/dist/types/transaction-message-size.d.ts.map +1 -0
- package/dist/types/transaction-message.d.ts +5 -5
- package/dist/types/transaction-message.d.ts.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ const message = createTransactionMessage({ version: 0 });
|
|
|
56
56
|
|
|
57
57
|
### Types
|
|
58
58
|
|
|
59
|
-
#### `
|
|
59
|
+
#### `TransactionMessageWithFeePayer`
|
|
60
60
|
|
|
61
61
|
This type represents a transaction message for which a fee payer has been declared. A transaction must conform to this type to be compiled and landed on the network.
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ This type represents a transaction message for which a fee payer has been declar
|
|
|
64
64
|
|
|
65
65
|
#### `setTransactionMessageFeePayer()`
|
|
66
66
|
|
|
67
|
-
Given a base58-encoded address of a system account, this method will return a new transaction message having the same type as the one supplied plus the `
|
|
67
|
+
Given a base58-encoded address of a system account, this method will return a new transaction message having the same type as the one supplied plus the `TransactionMessageWithFeePayer` type.
|
|
68
68
|
|
|
69
69
|
```ts
|
|
70
70
|
import { address } from '@solana/addresses';
|
|
@@ -171,9 +171,9 @@ function handleSubmit() {
|
|
|
171
171
|
}
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
#### `
|
|
174
|
+
#### `assertIsTransactionMessageWithDurableNonceLifetime()`
|
|
175
175
|
|
|
176
|
-
From time to time you might acquire a transaction message that you expect to be a durable nonce transaction, from an untrusted network API or user input. To assert that such an arbitrary transaction is in fact a durable nonce transaction, use the `
|
|
176
|
+
From time to time you might acquire a transaction message that you expect to be a durable nonce transaction, from an untrusted network API or user input. To assert that such an arbitrary transaction is in fact a durable nonce transaction, use the `assertIsTransactionMessageWithDurableNonceLifetime` function.
|
|
177
177
|
|
|
178
178
|
See [`assertIsBlockhash()`](#assertisblockhash) for an example of how to use an assertion function.
|
|
179
179
|
|
|
@@ -181,15 +181,15 @@ See [`assertIsBlockhash()`](#assertisblockhash) for an example of how to use an
|
|
|
181
181
|
|
|
182
182
|
### Types
|
|
183
183
|
|
|
184
|
-
#### `
|
|
184
|
+
#### `Instruction`
|
|
185
185
|
|
|
186
186
|
This type represents an instruction to be issued to a program. Objects that conform to this type have a `programAddress` property that is the base58-encoded address of the program in question.
|
|
187
187
|
|
|
188
|
-
#### `
|
|
188
|
+
#### `InstructionWithAccounts`
|
|
189
189
|
|
|
190
|
-
This type represents an instruction that specifies a list of accounts that a program may read from, write to, or require be signers of the transaction itself. Objects that conform to this type have an `accounts` property that is an array of `
|
|
190
|
+
This type represents an instruction that specifies a list of accounts that a program may read from, write to, or require be signers of the transaction itself. Objects that conform to this type have an `accounts` property that is an array of `AccountMeta | AccountLookupMeta` in the order the instruction requires.
|
|
191
191
|
|
|
192
|
-
#### `
|
|
192
|
+
#### `InstructionWithData`
|
|
193
193
|
|
|
194
194
|
This type represents an instruction that supplies some data as input to the program. Objects that conform to this type have a `data` property that can be any type of `Uint8Array`.
|
|
195
195
|
|
|
@@ -234,7 +234,7 @@ This type represents a mapping of lookup table addresses to the addresses of the
|
|
|
234
234
|
|
|
235
235
|
#### `compressTransactionMessageUsingAddressLookupTables`
|
|
236
236
|
|
|
237
|
-
Given a transaction message and a mapping of lookup tables to the addresses stored in them, this function will return a new transaction message with the same instructions but with all non-signer accounts that are found in the given lookup tables represented by an `
|
|
237
|
+
Given a transaction message and a mapping of lookup tables to the addresses stored in them, this function will return a new transaction message with the same instructions but with all non-signer accounts that are found in the given lookup tables represented by an `AccountLookupMeta` instead of an `AccountMeta`.
|
|
238
238
|
|
|
239
239
|
This means that these accounts will take up less space in the compiled transaction message. This size reduction is most significant when the transaction includes many accounts from the same lookup table.
|
|
240
240
|
|
package/dist/index.browser.cjs
CHANGED
|
@@ -11,14 +11,7 @@ var functional = require('@solana/functional');
|
|
|
11
11
|
|
|
12
12
|
// src/blockhash.ts
|
|
13
13
|
function isTransactionMessageWithBlockhashLifetime(transactionMessage) {
|
|
14
|
-
|
|
15
|
-
if (!lifetimeConstraintShapeMatches) return false;
|
|
16
|
-
try {
|
|
17
|
-
rpcTypes.assertIsBlockhash(transactionMessage.lifetimeConstraint.blockhash);
|
|
18
|
-
return true;
|
|
19
|
-
} catch {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
14
|
+
return "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.blockhash === "string" && typeof transactionMessage.lifetimeConstraint.lastValidBlockHeight === "bigint" && rpcTypes.isBlockhash(transactionMessage.lifetimeConstraint.blockhash);
|
|
22
15
|
}
|
|
23
16
|
function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
|
|
24
17
|
if (!isTransactionMessageWithBlockhashLifetime(transactionMessage)) {
|
|
@@ -26,15 +19,13 @@ function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
|
|
|
26
19
|
}
|
|
27
20
|
}
|
|
28
21
|
function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint, transactionMessage) {
|
|
29
|
-
if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transactionMessage.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
22
|
+
if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint && "blockhash" in transactionMessage.lifetimeConstraint && transactionMessage.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transactionMessage.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
30
23
|
return transactionMessage;
|
|
31
24
|
}
|
|
32
|
-
|
|
25
|
+
return Object.freeze({
|
|
33
26
|
...transactionMessage,
|
|
34
27
|
lifetimeConstraint: Object.freeze(blockhashLifetimeConstraint)
|
|
35
|
-
};
|
|
36
|
-
Object.freeze(out);
|
|
37
|
-
return out;
|
|
28
|
+
});
|
|
38
29
|
}
|
|
39
30
|
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
40
31
|
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
@@ -660,21 +651,14 @@ function compressTransactionMessageUsingAddressLookupTables(transactionMessage,
|
|
|
660
651
|
}
|
|
661
652
|
|
|
662
653
|
// src/create-transaction-message.ts
|
|
663
|
-
function createTransactionMessage({
|
|
664
|
-
version
|
|
665
|
-
}) {
|
|
654
|
+
function createTransactionMessage(config) {
|
|
666
655
|
return Object.freeze({
|
|
667
656
|
instructions: Object.freeze([]),
|
|
668
|
-
version
|
|
657
|
+
version: config.version
|
|
669
658
|
});
|
|
670
659
|
}
|
|
671
660
|
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
672
661
|
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
673
|
-
function assertIsDurableNonceTransactionMessage(transactionMessage) {
|
|
674
|
-
if (!isDurableNonceTransaction(transactionMessage)) {
|
|
675
|
-
throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
662
|
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
679
663
|
return {
|
|
680
664
|
accounts: [
|
|
@@ -700,9 +684,16 @@ function isAdvanceNonceAccountInstruction(instruction) {
|
|
|
700
684
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
701
685
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
702
686
|
}
|
|
703
|
-
|
|
687
|
+
|
|
688
|
+
// src/durable-nonce.ts
|
|
689
|
+
function isTransactionMessageWithDurableNonceLifetime(transactionMessage) {
|
|
704
690
|
return "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.nonce === "string" && transactionMessage.instructions[0] != null && isAdvanceNonceAccountInstruction(transactionMessage.instructions[0]);
|
|
705
691
|
}
|
|
692
|
+
function assertIsTransactionMessageWithDurableNonceLifetime(transactionMessage) {
|
|
693
|
+
if (!isTransactionMessageWithDurableNonceLifetime(transactionMessage)) {
|
|
694
|
+
throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
706
697
|
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
707
698
|
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
708
699
|
}
|
|
@@ -715,7 +706,7 @@ function setTransactionMessageLifetimeUsingDurableNonce({
|
|
|
715
706
|
const firstInstruction = transactionMessage.instructions[0];
|
|
716
707
|
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
717
708
|
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
718
|
-
if (
|
|
709
|
+
if (isTransactionMessageWithDurableNonceLifetime(transactionMessage) && transactionMessage.lifetimeConstraint.nonce === nonce) {
|
|
719
710
|
return transactionMessage;
|
|
720
711
|
} else {
|
|
721
712
|
newInstructions = [firstInstruction, ...transactionMessage.instructions.slice(1)];
|
|
@@ -735,9 +726,7 @@ function setTransactionMessageLifetimeUsingDurableNonce({
|
|
|
735
726
|
return Object.freeze({
|
|
736
727
|
...transactionMessage,
|
|
737
728
|
instructions: Object.freeze(newInstructions),
|
|
738
|
-
lifetimeConstraint: Object.freeze({
|
|
739
|
-
nonce
|
|
740
|
-
})
|
|
729
|
+
lifetimeConstraint: Object.freeze({ nonce })
|
|
741
730
|
});
|
|
742
731
|
}
|
|
743
732
|
|
|
@@ -764,7 +753,10 @@ function appendTransactionMessageInstruction(instruction, transactionMessage) {
|
|
|
764
753
|
function appendTransactionMessageInstructions(instructions, transactionMessage) {
|
|
765
754
|
return Object.freeze({
|
|
766
755
|
...transactionMessage,
|
|
767
|
-
instructions: Object.freeze([
|
|
756
|
+
instructions: Object.freeze([
|
|
757
|
+
...transactionMessage.instructions,
|
|
758
|
+
...instructions
|
|
759
|
+
])
|
|
768
760
|
});
|
|
769
761
|
}
|
|
770
762
|
function prependTransactionMessageInstruction(instruction, transactionMessage) {
|
|
@@ -773,7 +765,10 @@ function prependTransactionMessageInstruction(instruction, transactionMessage) {
|
|
|
773
765
|
function prependTransactionMessageInstructions(instructions, transactionMessage) {
|
|
774
766
|
return Object.freeze({
|
|
775
767
|
...transactionMessage,
|
|
776
|
-
instructions: Object.freeze([
|
|
768
|
+
instructions: Object.freeze([
|
|
769
|
+
...instructions,
|
|
770
|
+
...transactionMessage.instructions
|
|
771
|
+
])
|
|
777
772
|
});
|
|
778
773
|
}
|
|
779
774
|
|
|
@@ -915,17 +910,23 @@ function decompileTransactionMessage(compiledTransactionMessage, config) {
|
|
|
915
910
|
return functional.pipe(
|
|
916
911
|
createTransactionMessage({ version: compiledTransactionMessage.version }),
|
|
917
912
|
(m) => setTransactionMessageFeePayer(feePayer, m),
|
|
918
|
-
(m) => instructions.reduce(
|
|
919
|
-
|
|
920
|
-
|
|
913
|
+
(m) => instructions.reduce(
|
|
914
|
+
(acc, instruction) => appendTransactionMessageInstruction(instruction, acc),
|
|
915
|
+
m
|
|
916
|
+
),
|
|
921
917
|
(m) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, m) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, m)
|
|
922
918
|
);
|
|
923
919
|
}
|
|
924
920
|
|
|
921
|
+
// src/deprecated.ts
|
|
922
|
+
var assertIsDurableNonceTransactionMessage = assertIsTransactionMessageWithDurableNonceLifetime;
|
|
923
|
+
var isDurableNonceTransaction = isTransactionMessageWithDurableNonceLifetime;
|
|
924
|
+
|
|
925
925
|
exports.appendTransactionMessageInstruction = appendTransactionMessageInstruction;
|
|
926
926
|
exports.appendTransactionMessageInstructions = appendTransactionMessageInstructions;
|
|
927
927
|
exports.assertIsDurableNonceTransactionMessage = assertIsDurableNonceTransactionMessage;
|
|
928
928
|
exports.assertIsTransactionMessageWithBlockhashLifetime = assertIsTransactionMessageWithBlockhashLifetime;
|
|
929
|
+
exports.assertIsTransactionMessageWithDurableNonceLifetime = assertIsTransactionMessageWithDurableNonceLifetime;
|
|
929
930
|
exports.compileTransactionMessage = compileTransactionMessage;
|
|
930
931
|
exports.compressTransactionMessageUsingAddressLookupTables = compressTransactionMessageUsingAddressLookupTables;
|
|
931
932
|
exports.createTransactionMessage = createTransactionMessage;
|
|
@@ -939,6 +940,7 @@ exports.getTransactionVersionEncoder = getTransactionVersionEncoder;
|
|
|
939
940
|
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
940
941
|
exports.isDurableNonceTransaction = isDurableNonceTransaction;
|
|
941
942
|
exports.isTransactionMessageWithBlockhashLifetime = isTransactionMessageWithBlockhashLifetime;
|
|
943
|
+
exports.isTransactionMessageWithDurableNonceLifetime = isTransactionMessageWithDurableNonceLifetime;
|
|
942
944
|
exports.prependTransactionMessageInstruction = prependTransactionMessageInstruction;
|
|
943
945
|
exports.prependTransactionMessageInstructions = prependTransactionMessageInstructions;
|
|
944
946
|
exports.setTransactionMessageFeePayer = setTransactionMessageFeePayer;
|