@solana/transactions 2.0.0-experimental.68e85dc → 2.0.0-experimental.6910664
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/dist/index.browser.cjs +323 -11
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +326 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +479 -9
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +326 -17
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +323 -9
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +328 -15
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +20 -17
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
- package/dist/types/compile-header.d.ts.map +1 -0
- package/dist/types/compile-instructions.d.ts.map +1 -0
- package/dist/types/compile-lifetime-token.d.ts.map +1 -0
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/decompile-transaction.d.ts +7 -0
- package/dist/types/decompile-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +2 -3
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instructions.d.ts.map +1 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts +4 -2
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +1 -0
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +9 -9
package/dist/index.native.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { base58 } from '@metaplex-foundation/umi-serializers';
|
|
2
|
-
import { mapEncoder } from '@solana/codecs-core';
|
|
3
|
-
import { getStructEncoder, getArrayEncoder, getBytesEncoder } from '@solana/codecs-data-structures';
|
|
4
|
-
import { getShortU16Encoder, getU8Encoder } from '@solana/codecs-numbers';
|
|
5
|
-
import { getAddressFromPublicKey, getAddressComparator, getAddressEncoder } from '@solana/addresses';
|
|
6
|
-
import {
|
|
2
|
+
import { mapEncoder, mapDecoder, combineCodec } from '@solana/codecs-core';
|
|
3
|
+
import { getStructEncoder, getArrayEncoder, getBytesEncoder, getStructDecoder, getArrayDecoder, getBytesDecoder } from '@solana/codecs-data-structures';
|
|
4
|
+
import { getShortU16Encoder, getShortU16Decoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';
|
|
5
|
+
import { getAddressFromPublicKey, getAddressComparator, assertIsAddress, getAddressEncoder, getAddressDecoder } from '@solana/addresses';
|
|
6
|
+
import { pipe } from '@solana/functional';
|
|
7
|
+
import { getStringEncoder, getBase58Encoder, getStringDecoder, getBase58Decoder } from '@solana/codecs-strings';
|
|
7
8
|
import { signBytes } from '@solana/keys';
|
|
8
9
|
|
|
9
10
|
// ../build-scripts/env-shim.ts
|
|
@@ -119,7 +120,7 @@ function isAdvanceNonceAccountInstruction(instruction) {
|
|
|
119
120
|
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
120
121
|
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
121
122
|
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
122
|
-
instruction.accounts[2].address != null && instruction.accounts[2].role
|
|
123
|
+
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
123
124
|
}
|
|
124
125
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
125
126
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
@@ -127,21 +128,38 @@ function isAdvanceNonceAccountInstructionData(data) {
|
|
|
127
128
|
function isDurableNonceTransaction(transaction) {
|
|
128
129
|
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
129
130
|
}
|
|
131
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
132
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
133
|
+
}
|
|
130
134
|
function setTransactionLifetimeUsingDurableNonce({
|
|
131
135
|
nonce,
|
|
132
136
|
nonceAccountAddress,
|
|
133
137
|
nonceAuthorityAddress
|
|
134
138
|
}, transaction) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
let newInstructions;
|
|
140
|
+
const firstInstruction = transaction.instructions[0];
|
|
141
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
142
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
143
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
144
|
+
return transaction;
|
|
145
|
+
} else {
|
|
146
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
newInstructions = [
|
|
150
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
151
|
+
...transaction.instructions.slice(1)
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
newInstructions = [
|
|
156
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
157
|
+
...transaction.instructions
|
|
158
|
+
];
|
|
138
159
|
}
|
|
139
160
|
const out = {
|
|
140
161
|
...getUnsignedTransaction(transaction),
|
|
141
|
-
instructions:
|
|
142
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
143
|
-
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
144
|
-
],
|
|
162
|
+
instructions: newInstructions,
|
|
145
163
|
lifetimeConstraint: {
|
|
146
164
|
nonce
|
|
147
165
|
}
|
|
@@ -464,6 +482,116 @@ function getCompiledTransaction(transaction) {
|
|
|
464
482
|
signatures
|
|
465
483
|
};
|
|
466
484
|
}
|
|
485
|
+
function getAccountMetas(message) {
|
|
486
|
+
const { header } = message;
|
|
487
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
488
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
489
|
+
const accountMetas = [];
|
|
490
|
+
let accountIndex = 0;
|
|
491
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
492
|
+
accountMetas.push({
|
|
493
|
+
address: message.staticAccounts[accountIndex],
|
|
494
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
495
|
+
});
|
|
496
|
+
accountIndex++;
|
|
497
|
+
}
|
|
498
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
499
|
+
accountMetas.push({
|
|
500
|
+
address: message.staticAccounts[accountIndex],
|
|
501
|
+
role: AccountRole.READONLY_SIGNER
|
|
502
|
+
});
|
|
503
|
+
accountIndex++;
|
|
504
|
+
}
|
|
505
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
506
|
+
accountMetas.push({
|
|
507
|
+
address: message.staticAccounts[accountIndex],
|
|
508
|
+
role: AccountRole.WRITABLE
|
|
509
|
+
});
|
|
510
|
+
accountIndex++;
|
|
511
|
+
}
|
|
512
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
513
|
+
accountMetas.push({
|
|
514
|
+
address: message.staticAccounts[accountIndex],
|
|
515
|
+
role: AccountRole.READONLY
|
|
516
|
+
});
|
|
517
|
+
accountIndex++;
|
|
518
|
+
}
|
|
519
|
+
return accountMetas;
|
|
520
|
+
}
|
|
521
|
+
function convertInstruction(instruction, accountMetas) {
|
|
522
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
523
|
+
if (!programAddress) {
|
|
524
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
525
|
+
}
|
|
526
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
527
|
+
const { data } = instruction;
|
|
528
|
+
return {
|
|
529
|
+
programAddress,
|
|
530
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
531
|
+
...data && data.length ? { data } : {}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
535
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
536
|
+
return {
|
|
537
|
+
blockhash: messageLifetimeToken,
|
|
538
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
539
|
+
// U64 MAX
|
|
540
|
+
};
|
|
541
|
+
} else {
|
|
542
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
543
|
+
assertIsAddress(nonceAccountAddress);
|
|
544
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
545
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
546
|
+
return {
|
|
547
|
+
nonce: messageLifetimeToken,
|
|
548
|
+
nonceAccountAddress,
|
|
549
|
+
nonceAuthorityAddress
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function convertSignatures(compiledTransaction) {
|
|
554
|
+
const {
|
|
555
|
+
compiledMessage: { staticAccounts },
|
|
556
|
+
signatures
|
|
557
|
+
} = compiledTransaction;
|
|
558
|
+
return signatures.reduce((acc, sig, index) => {
|
|
559
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
560
|
+
if (allZeros)
|
|
561
|
+
return acc;
|
|
562
|
+
const address = staticAccounts[index];
|
|
563
|
+
return { ...acc, [address]: sig };
|
|
564
|
+
}, {});
|
|
565
|
+
}
|
|
566
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
567
|
+
const { compiledMessage } = compiledTransaction;
|
|
568
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
569
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
570
|
+
}
|
|
571
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
572
|
+
if (!feePayer)
|
|
573
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
574
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
575
|
+
const instructions = compiledMessage.instructions.map(
|
|
576
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
577
|
+
);
|
|
578
|
+
const firstInstruction = instructions[0];
|
|
579
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
580
|
+
compiledMessage.lifetimeToken,
|
|
581
|
+
firstInstruction,
|
|
582
|
+
lastValidBlockHeight
|
|
583
|
+
);
|
|
584
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
585
|
+
return pipe(
|
|
586
|
+
createTransaction({ version: compiledMessage.version }),
|
|
587
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
588
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
589
|
+
return appendTransactionInstruction(instruction, acc);
|
|
590
|
+
}, tx),
|
|
591
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
592
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
593
|
+
);
|
|
594
|
+
}
|
|
467
595
|
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
468
596
|
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
469
597
|
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
@@ -494,6 +622,32 @@ function getAddressTableLookupEncoder() {
|
|
|
494
622
|
}
|
|
495
623
|
return memoizedAddressTableLookupEncoder;
|
|
496
624
|
}
|
|
625
|
+
var memoizedAddressTableLookupDecoder;
|
|
626
|
+
function getAddressTableLookupDecoder() {
|
|
627
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
628
|
+
memoizedAddressTableLookupDecoder = getStructDecoder(
|
|
629
|
+
[
|
|
630
|
+
["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
|
|
631
|
+
[
|
|
632
|
+
"writableIndices",
|
|
633
|
+
getArrayDecoder(getU8Decoder(), {
|
|
634
|
+
description: writableIndicesDescription,
|
|
635
|
+
size: getShortU16Decoder()
|
|
636
|
+
})
|
|
637
|
+
],
|
|
638
|
+
[
|
|
639
|
+
"readableIndices",
|
|
640
|
+
getArrayDecoder(getU8Decoder(), {
|
|
641
|
+
description: readableIndicesDescription,
|
|
642
|
+
size: getShortU16Decoder()
|
|
643
|
+
})
|
|
644
|
+
]
|
|
645
|
+
],
|
|
646
|
+
{ description: addressTableLookupDescription }
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
return memoizedAddressTableLookupDecoder;
|
|
650
|
+
}
|
|
497
651
|
var memoizedU8Encoder;
|
|
498
652
|
function getMemoizedU8Encoder() {
|
|
499
653
|
if (!memoizedU8Encoder)
|
|
@@ -507,6 +661,19 @@ function getMemoizedU8EncoderDescription(description) {
|
|
|
507
661
|
description: description ?? encoder.description
|
|
508
662
|
};
|
|
509
663
|
}
|
|
664
|
+
var memoizedU8Decoder;
|
|
665
|
+
function getMemoizedU8Decoder() {
|
|
666
|
+
if (!memoizedU8Decoder)
|
|
667
|
+
memoizedU8Decoder = getU8Decoder();
|
|
668
|
+
return memoizedU8Decoder;
|
|
669
|
+
}
|
|
670
|
+
function getMemoizedU8DecoderDescription(description) {
|
|
671
|
+
const decoder = getMemoizedU8Decoder();
|
|
672
|
+
return {
|
|
673
|
+
...decoder,
|
|
674
|
+
description: description ?? decoder.description
|
|
675
|
+
};
|
|
676
|
+
}
|
|
510
677
|
var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0;
|
|
511
678
|
var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0;
|
|
512
679
|
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
@@ -523,6 +690,18 @@ function getMessageHeaderEncoder() {
|
|
|
523
690
|
}
|
|
524
691
|
);
|
|
525
692
|
}
|
|
693
|
+
function getMessageHeaderDecoder() {
|
|
694
|
+
return getStructDecoder(
|
|
695
|
+
[
|
|
696
|
+
["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
|
|
697
|
+
["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
|
|
698
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
699
|
+
],
|
|
700
|
+
{
|
|
701
|
+
description: messageHeaderDescription
|
|
702
|
+
}
|
|
703
|
+
);
|
|
704
|
+
}
|
|
526
705
|
var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
|
|
527
706
|
var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
|
|
528
707
|
var accountIndicesDescription = __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "accountIndices";
|
|
@@ -557,12 +736,52 @@ function getInstructionEncoder() {
|
|
|
557
736
|
}
|
|
558
737
|
return memoizedGetInstructionEncoder;
|
|
559
738
|
}
|
|
739
|
+
var memoizedGetInstructionDecoder;
|
|
740
|
+
function getInstructionDecoder() {
|
|
741
|
+
if (!memoizedGetInstructionDecoder) {
|
|
742
|
+
memoizedGetInstructionDecoder = mapDecoder(
|
|
743
|
+
getStructDecoder([
|
|
744
|
+
["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
|
|
745
|
+
[
|
|
746
|
+
"accountIndices",
|
|
747
|
+
getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
|
|
748
|
+
description: accountIndicesDescription,
|
|
749
|
+
size: getShortU16Decoder()
|
|
750
|
+
})
|
|
751
|
+
],
|
|
752
|
+
["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
|
|
753
|
+
]),
|
|
754
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
755
|
+
(instruction) => {
|
|
756
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
757
|
+
return instruction;
|
|
758
|
+
}
|
|
759
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
760
|
+
return {
|
|
761
|
+
...rest,
|
|
762
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
763
|
+
...data.byteLength ? { data } : null
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
return memoizedGetInstructionDecoder;
|
|
769
|
+
}
|
|
560
770
|
var VERSION_FLAG_MASK = 128;
|
|
561
771
|
var BASE_CONFIG = {
|
|
562
772
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
563
773
|
fixedSize: null,
|
|
564
774
|
maxSize: 1
|
|
565
775
|
};
|
|
776
|
+
function decode(bytes, offset = 0) {
|
|
777
|
+
const firstByte = bytes[offset];
|
|
778
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
779
|
+
return ["legacy", offset];
|
|
780
|
+
} else {
|
|
781
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
782
|
+
return [version, offset + 1];
|
|
783
|
+
}
|
|
784
|
+
}
|
|
566
785
|
function encode(value) {
|
|
567
786
|
if (value === "legacy") {
|
|
568
787
|
return new Uint8Array();
|
|
@@ -572,6 +791,12 @@ function encode(value) {
|
|
|
572
791
|
}
|
|
573
792
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
574
793
|
}
|
|
794
|
+
function getTransactionVersionDecoder() {
|
|
795
|
+
return {
|
|
796
|
+
...BASE_CONFIG,
|
|
797
|
+
decode
|
|
798
|
+
};
|
|
799
|
+
}
|
|
575
800
|
function getTransactionVersionEncoder() {
|
|
576
801
|
return {
|
|
577
802
|
...BASE_CONFIG,
|
|
@@ -632,12 +857,47 @@ function getPreludeStructEncoderTuple() {
|
|
|
632
857
|
]
|
|
633
858
|
];
|
|
634
859
|
}
|
|
860
|
+
function getPreludeStructDecoderTuple() {
|
|
861
|
+
return [
|
|
862
|
+
["version", getTransactionVersionDecoder()],
|
|
863
|
+
["header", getMessageHeaderDecoder()],
|
|
864
|
+
[
|
|
865
|
+
"staticAccounts",
|
|
866
|
+
getArrayDecoder(getAddressDecoder(), {
|
|
867
|
+
description: staticAccountsDescription,
|
|
868
|
+
size: getShortU16Decoder()
|
|
869
|
+
})
|
|
870
|
+
],
|
|
871
|
+
[
|
|
872
|
+
"lifetimeToken",
|
|
873
|
+
getStringDecoder({
|
|
874
|
+
description: lifetimeTokenDescription,
|
|
875
|
+
encoding: getBase58Decoder(),
|
|
876
|
+
size: 32
|
|
877
|
+
})
|
|
878
|
+
],
|
|
879
|
+
[
|
|
880
|
+
"instructions",
|
|
881
|
+
getArrayDecoder(getInstructionDecoder(), {
|
|
882
|
+
description: instructionsDescription,
|
|
883
|
+
size: getShortU16Decoder()
|
|
884
|
+
})
|
|
885
|
+
],
|
|
886
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
887
|
+
];
|
|
888
|
+
}
|
|
635
889
|
function getAddressTableLookupArrayEncoder() {
|
|
636
890
|
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
637
891
|
description: addressTableLookupsDescription,
|
|
638
892
|
size: getShortU16Encoder()
|
|
639
893
|
});
|
|
640
894
|
}
|
|
895
|
+
function getAddressTableLookupArrayDecoder() {
|
|
896
|
+
return getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
897
|
+
description: addressTableLookupsDescription,
|
|
898
|
+
size: getShortU16Decoder()
|
|
899
|
+
});
|
|
900
|
+
}
|
|
641
901
|
var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
|
|
642
902
|
function getCompiledMessageEncoder() {
|
|
643
903
|
return {
|
|
@@ -653,10 +913,23 @@ function getCompiledMessageEncoder() {
|
|
|
653
913
|
maxSize: null
|
|
654
914
|
};
|
|
655
915
|
}
|
|
916
|
+
function getCompiledMessageDecoder() {
|
|
917
|
+
return mapDecoder(
|
|
918
|
+
getStructDecoder(getPreludeStructDecoderTuple(), {
|
|
919
|
+
description: messageDescription
|
|
920
|
+
}),
|
|
921
|
+
({ addressTableLookups, ...restOfMessage }) => {
|
|
922
|
+
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
|
|
923
|
+
return restOfMessage;
|
|
924
|
+
}
|
|
925
|
+
return { ...restOfMessage, addressTableLookups };
|
|
926
|
+
}
|
|
927
|
+
);
|
|
928
|
+
}
|
|
656
929
|
|
|
657
930
|
// src/serializers/transaction.ts
|
|
658
|
-
var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
|
|
659
931
|
var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
|
|
932
|
+
var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
|
|
660
933
|
function getCompiledTransactionEncoder() {
|
|
661
934
|
return getStructEncoder(
|
|
662
935
|
[
|
|
@@ -674,9 +947,38 @@ function getCompiledTransactionEncoder() {
|
|
|
674
947
|
}
|
|
675
948
|
);
|
|
676
949
|
}
|
|
950
|
+
function getSignatureDecoder() {
|
|
951
|
+
return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
|
|
952
|
+
}
|
|
953
|
+
function getCompiledTransactionDecoder() {
|
|
954
|
+
return getStructDecoder(
|
|
955
|
+
[
|
|
956
|
+
[
|
|
957
|
+
"signatures",
|
|
958
|
+
getArrayDecoder(getSignatureDecoder(), {
|
|
959
|
+
description: signaturesDescription,
|
|
960
|
+
size: getShortU16Decoder()
|
|
961
|
+
})
|
|
962
|
+
],
|
|
963
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
964
|
+
],
|
|
965
|
+
{
|
|
966
|
+
description: transactionDescription
|
|
967
|
+
}
|
|
968
|
+
);
|
|
969
|
+
}
|
|
677
970
|
function getTransactionEncoder() {
|
|
678
971
|
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
679
972
|
}
|
|
973
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
974
|
+
return mapDecoder(
|
|
975
|
+
getCompiledTransactionDecoder(),
|
|
976
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
977
|
+
);
|
|
978
|
+
}
|
|
979
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
980
|
+
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
981
|
+
}
|
|
680
982
|
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
681
983
|
try {
|
|
682
984
|
if (
|
|
@@ -752,6 +1054,15 @@ function transactionSignature(putativeTransactionSignature) {
|
|
|
752
1054
|
assertIsTransactionSignature(putativeTransactionSignature);
|
|
753
1055
|
return putativeTransactionSignature;
|
|
754
1056
|
}
|
|
1057
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
1058
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
1059
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1060
|
+
requiredSigners.forEach((address) => {
|
|
1061
|
+
if (!transaction.signatures[address]) {
|
|
1062
|
+
throw new Error(`Transaction is missing signature for address \`${address}\``);
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
755
1066
|
|
|
756
1067
|
// src/wire-transaction.ts
|
|
757
1068
|
function getBase64EncodedWireTransaction(transaction) {
|
|
@@ -761,6 +1072,4 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
761
1072
|
}
|
|
762
1073
|
}
|
|
763
1074
|
|
|
764
|
-
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isAdvanceNonceAccountInstruction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|
|
765
|
-
//# sourceMappingURL=out.js.map
|
|
766
|
-
//# sourceMappingURL=index.native.js.map
|
|
1075
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, assertTransactionIsFullySigned, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|