@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.
- package/README.md +9 -9
- package/dist/index.browser.cjs +32 -34
- 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 +32 -34
- 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 +3 -2
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/compilable-transaction-message.d.ts +5 -4
- 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 +3 -7
- package/dist/types/create-transaction-message.d.ts.map +1 -1
- package/dist/types/decompile-message.d.ts.map +1 -1
- package/dist/types/durable-nonce.d.ts +49 -47
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/fee-payer.d.ts +3 -8
- package/dist/types/fee-payer.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/instructions.d.ts +6 -21
- package/dist/types/instructions.d.ts.map +1 -1
- 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/dist/types/deprecated.d.ts +0 -65
- package/dist/types/deprecated.d.ts.map +0 -1
- package/dist/types/durable-nonce-instruction.d.ts +0 -43
- package/dist/types/durable-nonce-instruction.d.ts.map +0 -1
- package/dist/types/lifetime.d.ts +0 -12
- package/dist/types/lifetime.d.ts.map +0 -1
- package/dist/types/transaction-message-size.d.ts +0 -13
- package/dist/types/transaction-message-size.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ const message = createTransactionMessage({ version: 0 });
|
|
|
56
56
|
|
|
57
57
|
### Types
|
|
58
58
|
|
|
59
|
-
#### `
|
|
59
|
+
#### `ITransactionMessageWithFeePayer`
|
|
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 `ITransactionMessageWithFeePayer` 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
|
+
#### `assertIsDurableNonceTransactionMessage()`
|
|
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 `assertIsDurableNonceTransactionMessage` 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
|
+
#### `IInstruction`
|
|
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
|
+
#### `IInstructionWithAccounts`
|
|
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 `IAccountMeta | IAccountLookupMeta` in the order the instruction requires.
|
|
191
191
|
|
|
192
|
-
#### `
|
|
192
|
+
#### `IInstructionWithData`
|
|
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 `IAccountLookupMeta` instead of an `IAccountMeta`.
|
|
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,7 +11,14 @@ var functional = require('@solana/functional');
|
|
|
11
11
|
|
|
12
12
|
// src/blockhash.ts
|
|
13
13
|
function isTransactionMessageWithBlockhashLifetime(transactionMessage) {
|
|
14
|
-
|
|
14
|
+
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.blockhash === "string" && typeof transactionMessage.lifetimeConstraint.lastValidBlockHeight === "bigint";
|
|
15
|
+
if (!lifetimeConstraintShapeMatches) return false;
|
|
16
|
+
try {
|
|
17
|
+
rpcTypes.assertIsBlockhash(transactionMessage.lifetimeConstraint.blockhash);
|
|
18
|
+
return true;
|
|
19
|
+
} catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
15
22
|
}
|
|
16
23
|
function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
|
|
17
24
|
if (!isTransactionMessageWithBlockhashLifetime(transactionMessage)) {
|
|
@@ -19,13 +26,15 @@ function assertIsTransactionMessageWithBlockhashLifetime(transactionMessage) {
|
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
function setTransactionMessageLifetimeUsingBlockhash(blockhashLifetimeConstraint, transactionMessage) {
|
|
22
|
-
if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint
|
|
29
|
+
if ("lifetimeConstraint" in transactionMessage && transactionMessage.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transactionMessage.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
23
30
|
return transactionMessage;
|
|
24
31
|
}
|
|
25
|
-
|
|
32
|
+
const out = {
|
|
26
33
|
...transactionMessage,
|
|
27
34
|
lifetimeConstraint: Object.freeze(blockhashLifetimeConstraint)
|
|
28
|
-
}
|
|
35
|
+
};
|
|
36
|
+
Object.freeze(out);
|
|
37
|
+
return out;
|
|
29
38
|
}
|
|
30
39
|
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
31
40
|
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
@@ -651,14 +660,21 @@ function compressTransactionMessageUsingAddressLookupTables(transactionMessage,
|
|
|
651
660
|
}
|
|
652
661
|
|
|
653
662
|
// src/create-transaction-message.ts
|
|
654
|
-
function createTransactionMessage(
|
|
663
|
+
function createTransactionMessage({
|
|
664
|
+
version
|
|
665
|
+
}) {
|
|
655
666
|
return Object.freeze({
|
|
656
667
|
instructions: Object.freeze([]),
|
|
657
|
-
version
|
|
668
|
+
version
|
|
658
669
|
});
|
|
659
670
|
}
|
|
660
671
|
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
661
672
|
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
|
+
}
|
|
662
678
|
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
663
679
|
return {
|
|
664
680
|
accounts: [
|
|
@@ -684,16 +700,9 @@ function isAdvanceNonceAccountInstruction(instruction) {
|
|
|
684
700
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
685
701
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
686
702
|
}
|
|
687
|
-
|
|
688
|
-
// src/durable-nonce.ts
|
|
689
|
-
function isTransactionMessageWithDurableNonceLifetime(transactionMessage) {
|
|
703
|
+
function isDurableNonceTransaction(transactionMessage) {
|
|
690
704
|
return "lifetimeConstraint" in transactionMessage && typeof transactionMessage.lifetimeConstraint.nonce === "string" && transactionMessage.instructions[0] != null && isAdvanceNonceAccountInstruction(transactionMessage.instructions[0]);
|
|
691
705
|
}
|
|
692
|
-
function assertIsTransactionMessageWithDurableNonceLifetime(transactionMessage) {
|
|
693
|
-
if (!isTransactionMessageWithDurableNonceLifetime(transactionMessage)) {
|
|
694
|
-
throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
706
|
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
698
707
|
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
699
708
|
}
|
|
@@ -706,7 +715,7 @@ function setTransactionMessageLifetimeUsingDurableNonce({
|
|
|
706
715
|
const firstInstruction = transactionMessage.instructions[0];
|
|
707
716
|
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
708
717
|
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
709
|
-
if (
|
|
718
|
+
if (isDurableNonceTransaction(transactionMessage) && transactionMessage.lifetimeConstraint.nonce === nonce) {
|
|
710
719
|
return transactionMessage;
|
|
711
720
|
} else {
|
|
712
721
|
newInstructions = [firstInstruction, ...transactionMessage.instructions.slice(1)];
|
|
@@ -726,7 +735,9 @@ function setTransactionMessageLifetimeUsingDurableNonce({
|
|
|
726
735
|
return Object.freeze({
|
|
727
736
|
...transactionMessage,
|
|
728
737
|
instructions: Object.freeze(newInstructions),
|
|
729
|
-
lifetimeConstraint: Object.freeze({
|
|
738
|
+
lifetimeConstraint: Object.freeze({
|
|
739
|
+
nonce
|
|
740
|
+
})
|
|
730
741
|
});
|
|
731
742
|
}
|
|
732
743
|
|
|
@@ -753,10 +764,7 @@ function appendTransactionMessageInstruction(instruction, transactionMessage) {
|
|
|
753
764
|
function appendTransactionMessageInstructions(instructions, transactionMessage) {
|
|
754
765
|
return Object.freeze({
|
|
755
766
|
...transactionMessage,
|
|
756
|
-
instructions: Object.freeze([
|
|
757
|
-
...transactionMessage.instructions,
|
|
758
|
-
...instructions
|
|
759
|
-
])
|
|
767
|
+
instructions: Object.freeze([...transactionMessage.instructions, ...instructions])
|
|
760
768
|
});
|
|
761
769
|
}
|
|
762
770
|
function prependTransactionMessageInstruction(instruction, transactionMessage) {
|
|
@@ -765,10 +773,7 @@ function prependTransactionMessageInstruction(instruction, transactionMessage) {
|
|
|
765
773
|
function prependTransactionMessageInstructions(instructions, transactionMessage) {
|
|
766
774
|
return Object.freeze({
|
|
767
775
|
...transactionMessage,
|
|
768
|
-
instructions: Object.freeze([
|
|
769
|
-
...instructions,
|
|
770
|
-
...transactionMessage.instructions
|
|
771
|
-
])
|
|
776
|
+
instructions: Object.freeze([...instructions, ...transactionMessage.instructions])
|
|
772
777
|
});
|
|
773
778
|
}
|
|
774
779
|
|
|
@@ -910,23 +915,17 @@ function decompileTransactionMessage(compiledTransactionMessage, config) {
|
|
|
910
915
|
return functional.pipe(
|
|
911
916
|
createTransactionMessage({ version: compiledTransactionMessage.version }),
|
|
912
917
|
(m) => setTransactionMessageFeePayer(feePayer, m),
|
|
913
|
-
(m) => instructions.reduce(
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
),
|
|
918
|
+
(m) => instructions.reduce((acc, instruction) => {
|
|
919
|
+
return appendTransactionMessageInstruction(instruction, acc);
|
|
920
|
+
}, m),
|
|
917
921
|
(m) => "blockhash" in lifetimeConstraint ? setTransactionMessageLifetimeUsingBlockhash(lifetimeConstraint, m) : setTransactionMessageLifetimeUsingDurableNonce(lifetimeConstraint, m)
|
|
918
922
|
);
|
|
919
923
|
}
|
|
920
924
|
|
|
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;
|
|
930
929
|
exports.compileTransactionMessage = compileTransactionMessage;
|
|
931
930
|
exports.compressTransactionMessageUsingAddressLookupTables = compressTransactionMessageUsingAddressLookupTables;
|
|
932
931
|
exports.createTransactionMessage = createTransactionMessage;
|
|
@@ -940,7 +939,6 @@ exports.getTransactionVersionEncoder = getTransactionVersionEncoder;
|
|
|
940
939
|
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
941
940
|
exports.isDurableNonceTransaction = isDurableNonceTransaction;
|
|
942
941
|
exports.isTransactionMessageWithBlockhashLifetime = isTransactionMessageWithBlockhashLifetime;
|
|
943
|
-
exports.isTransactionMessageWithDurableNonceLifetime = isTransactionMessageWithDurableNonceLifetime;
|
|
944
942
|
exports.prependTransactionMessageInstruction = prependTransactionMessageInstruction;
|
|
945
943
|
exports.prependTransactionMessageInstructions = prependTransactionMessageInstructions;
|
|
946
944
|
exports.setTransactionMessageFeePayer = setTransactionMessageFeePayer;
|