@solana/transactions 2.0.0-experimental.e8095b1 → 2.0.0-experimental.e9e224b
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 +314 -5
- package/dist/index.browser.cjs +354 -138
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +357 -140
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +767 -1031
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +355 -140
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +354 -136
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +357 -140
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +20 -17
- package/dist/types/decompile-transaction.d.ts +7 -0
- package/dist/types/durable-nonce.d.ts +2 -3
- package/dist/types/serializers/message.d.ts +4 -4
- package/dist/types/serializers/transaction.d.ts +7 -4
- package/dist/types/signatures.d.ts +1 -0
- package/dist/types/wire-transaction.d.ts +1 -1
- package/package.json +12 -11
- package/dist/types/accounts.d.ts.map +0 -1
- package/dist/types/blockhash.d.ts.map +0 -1
- package/dist/types/compile-address-table-lookups.d.ts.map +0 -1
- package/dist/types/compile-header.d.ts.map +0 -1
- package/dist/types/compile-instructions.d.ts.map +0 -1
- package/dist/types/compile-lifetime-token.d.ts.map +0 -1
- package/dist/types/compile-static-accounts.d.ts.map +0 -1
- package/dist/types/compile-transaction.d.ts.map +0 -1
- package/dist/types/create-transaction.d.ts.map +0 -1
- package/dist/types/durable-nonce.d.ts.map +0 -1
- package/dist/types/fee-payer.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/instructions.d.ts.map +0 -1
- package/dist/types/message.d.ts.map +0 -1
- package/dist/types/serializers/address-table-lookup.d.ts.map +0 -1
- package/dist/types/serializers/header.d.ts.map +0 -1
- package/dist/types/serializers/index.d.ts.map +0 -1
- package/dist/types/serializers/instruction.d.ts.map +0 -1
- package/dist/types/serializers/message.d.ts.map +0 -1
- package/dist/types/serializers/transaction-version.d.ts.map +0 -1
- package/dist/types/serializers/transaction.d.ts.map +0 -1
- package/dist/types/serializers/unimplemented.d.ts +0 -3
- package/dist/types/serializers/unimplemented.d.ts.map +0 -1
- package/dist/types/signatures.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/unsigned-transaction.d.ts.map +0 -1
- package/dist/types/wire-transaction.d.ts.map +0 -1
package/dist/index.native.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { getBase58Encoder, getBase58Decoder, getStringEncoder, getStringDecoder } from '@solana/codecs-strings';
|
|
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';
|
|
6
7
|
import { signBytes } from '@solana/keys';
|
|
7
8
|
|
|
8
9
|
// ../build-scripts/env-shim.ts
|
|
@@ -23,7 +24,10 @@ function getUnsignedTransaction(transaction) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// src/blockhash.ts
|
|
27
|
+
var base58Encoder;
|
|
26
28
|
function assertIsBlockhash(putativeBlockhash) {
|
|
29
|
+
if (!base58Encoder)
|
|
30
|
+
base58Encoder = getBase58Encoder();
|
|
27
31
|
try {
|
|
28
32
|
if (
|
|
29
33
|
// Lowest value (32 bytes of zeroes)
|
|
@@ -32,8 +36,8 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
32
36
|
) {
|
|
33
37
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
34
38
|
}
|
|
35
|
-
const
|
|
36
|
-
const numBytes =
|
|
39
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
40
|
+
const numBytes = bytes.byteLength;
|
|
37
41
|
if (numBytes !== 32) {
|
|
38
42
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
39
43
|
}
|
|
@@ -118,7 +122,7 @@ function isAdvanceNonceAccountInstruction(instruction) {
|
|
|
118
122
|
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
119
123
|
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
120
124
|
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
121
|
-
instruction.accounts[2].address != null && instruction.accounts[2].role
|
|
125
|
+
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
122
126
|
}
|
|
123
127
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
124
128
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
@@ -126,21 +130,38 @@ function isAdvanceNonceAccountInstructionData(data) {
|
|
|
126
130
|
function isDurableNonceTransaction(transaction) {
|
|
127
131
|
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
128
132
|
}
|
|
133
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
134
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
135
|
+
}
|
|
129
136
|
function setTransactionLifetimeUsingDurableNonce({
|
|
130
137
|
nonce,
|
|
131
138
|
nonceAccountAddress,
|
|
132
139
|
nonceAuthorityAddress
|
|
133
140
|
}, transaction) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
let newInstructions;
|
|
142
|
+
const firstInstruction = transaction.instructions[0];
|
|
143
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
144
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
145
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
146
|
+
return transaction;
|
|
147
|
+
} else {
|
|
148
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
newInstructions = [
|
|
152
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
153
|
+
...transaction.instructions.slice(1)
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
newInstructions = [
|
|
158
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
159
|
+
...transaction.instructions
|
|
160
|
+
];
|
|
137
161
|
}
|
|
138
162
|
const out = {
|
|
139
163
|
...getUnsignedTransaction(transaction),
|
|
140
|
-
instructions:
|
|
141
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
142
|
-
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
143
|
-
],
|
|
164
|
+
instructions: newInstructions,
|
|
144
165
|
lifetimeConstraint: {
|
|
145
166
|
nonce
|
|
146
167
|
}
|
|
@@ -463,6 +484,116 @@ function getCompiledTransaction(transaction) {
|
|
|
463
484
|
signatures
|
|
464
485
|
};
|
|
465
486
|
}
|
|
487
|
+
function getAccountMetas(message) {
|
|
488
|
+
const { header } = message;
|
|
489
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
490
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
491
|
+
const accountMetas = [];
|
|
492
|
+
let accountIndex = 0;
|
|
493
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
494
|
+
accountMetas.push({
|
|
495
|
+
address: message.staticAccounts[accountIndex],
|
|
496
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
497
|
+
});
|
|
498
|
+
accountIndex++;
|
|
499
|
+
}
|
|
500
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
501
|
+
accountMetas.push({
|
|
502
|
+
address: message.staticAccounts[accountIndex],
|
|
503
|
+
role: AccountRole.READONLY_SIGNER
|
|
504
|
+
});
|
|
505
|
+
accountIndex++;
|
|
506
|
+
}
|
|
507
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
508
|
+
accountMetas.push({
|
|
509
|
+
address: message.staticAccounts[accountIndex],
|
|
510
|
+
role: AccountRole.WRITABLE
|
|
511
|
+
});
|
|
512
|
+
accountIndex++;
|
|
513
|
+
}
|
|
514
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
515
|
+
accountMetas.push({
|
|
516
|
+
address: message.staticAccounts[accountIndex],
|
|
517
|
+
role: AccountRole.READONLY
|
|
518
|
+
});
|
|
519
|
+
accountIndex++;
|
|
520
|
+
}
|
|
521
|
+
return accountMetas;
|
|
522
|
+
}
|
|
523
|
+
function convertInstruction(instruction, accountMetas) {
|
|
524
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
525
|
+
if (!programAddress) {
|
|
526
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
527
|
+
}
|
|
528
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
529
|
+
const { data } = instruction;
|
|
530
|
+
return {
|
|
531
|
+
programAddress,
|
|
532
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
533
|
+
...data && data.length ? { data } : {}
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
537
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
538
|
+
return {
|
|
539
|
+
blockhash: messageLifetimeToken,
|
|
540
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
541
|
+
// U64 MAX
|
|
542
|
+
};
|
|
543
|
+
} else {
|
|
544
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
545
|
+
assertIsAddress(nonceAccountAddress);
|
|
546
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
547
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
548
|
+
return {
|
|
549
|
+
nonce: messageLifetimeToken,
|
|
550
|
+
nonceAccountAddress,
|
|
551
|
+
nonceAuthorityAddress
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function convertSignatures(compiledTransaction) {
|
|
556
|
+
const {
|
|
557
|
+
compiledMessage: { staticAccounts },
|
|
558
|
+
signatures
|
|
559
|
+
} = compiledTransaction;
|
|
560
|
+
return signatures.reduce((acc, sig, index) => {
|
|
561
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
562
|
+
if (allZeros)
|
|
563
|
+
return acc;
|
|
564
|
+
const address = staticAccounts[index];
|
|
565
|
+
return { ...acc, [address]: sig };
|
|
566
|
+
}, {});
|
|
567
|
+
}
|
|
568
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
569
|
+
const { compiledMessage } = compiledTransaction;
|
|
570
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
571
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
572
|
+
}
|
|
573
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
574
|
+
if (!feePayer)
|
|
575
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
576
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
577
|
+
const instructions = compiledMessage.instructions.map(
|
|
578
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
579
|
+
);
|
|
580
|
+
const firstInstruction = instructions[0];
|
|
581
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
582
|
+
compiledMessage.lifetimeToken,
|
|
583
|
+
firstInstruction,
|
|
584
|
+
lastValidBlockHeight
|
|
585
|
+
);
|
|
586
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
587
|
+
return pipe(
|
|
588
|
+
createTransaction({ version: compiledMessage.version }),
|
|
589
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
590
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
591
|
+
return appendTransactionInstruction(instruction, acc);
|
|
592
|
+
}, tx),
|
|
593
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
594
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
595
|
+
);
|
|
596
|
+
}
|
|
466
597
|
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
467
598
|
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
468
599
|
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
@@ -519,32 +650,54 @@ function getAddressTableLookupDecoder() {
|
|
|
519
650
|
}
|
|
520
651
|
return memoizedAddressTableLookupDecoder;
|
|
521
652
|
}
|
|
522
|
-
|
|
523
|
-
|
|
653
|
+
var memoizedU8Encoder;
|
|
654
|
+
function getMemoizedU8Encoder() {
|
|
655
|
+
if (!memoizedU8Encoder)
|
|
656
|
+
memoizedU8Encoder = getU8Encoder();
|
|
657
|
+
return memoizedU8Encoder;
|
|
524
658
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
659
|
+
function getMemoizedU8EncoderDescription(description) {
|
|
660
|
+
const encoder = getMemoizedU8Encoder();
|
|
661
|
+
return {
|
|
662
|
+
...encoder,
|
|
663
|
+
description: description ?? encoder.description
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
var memoizedU8Decoder;
|
|
667
|
+
function getMemoizedU8Decoder() {
|
|
668
|
+
if (!memoizedU8Decoder)
|
|
669
|
+
memoizedU8Decoder = getU8Decoder();
|
|
670
|
+
return memoizedU8Decoder;
|
|
530
671
|
}
|
|
531
|
-
function
|
|
532
|
-
const
|
|
672
|
+
function getMemoizedU8DecoderDescription(description) {
|
|
673
|
+
const decoder = getMemoizedU8Decoder();
|
|
533
674
|
return {
|
|
534
|
-
...
|
|
535
|
-
description: description ??
|
|
675
|
+
...decoder,
|
|
676
|
+
description: description ?? decoder.description
|
|
536
677
|
};
|
|
537
678
|
}
|
|
538
679
|
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;
|
|
539
680
|
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;
|
|
540
681
|
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
541
682
|
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
542
|
-
function
|
|
543
|
-
return
|
|
683
|
+
function getMessageHeaderEncoder() {
|
|
684
|
+
return getStructEncoder(
|
|
544
685
|
[
|
|
545
|
-
["numSignerAccounts",
|
|
546
|
-
["numReadonlySignerAccounts",
|
|
547
|
-
["numReadonlyNonSignerAccounts",
|
|
686
|
+
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
687
|
+
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
688
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
689
|
+
],
|
|
690
|
+
{
|
|
691
|
+
description: messageHeaderDescription
|
|
692
|
+
}
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
function getMessageHeaderDecoder() {
|
|
696
|
+
return getStructDecoder(
|
|
697
|
+
[
|
|
698
|
+
["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
|
|
699
|
+
["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
|
|
700
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
548
701
|
],
|
|
549
702
|
{
|
|
550
703
|
description: messageHeaderDescription
|
|
@@ -616,17 +769,14 @@ function getInstructionDecoder() {
|
|
|
616
769
|
}
|
|
617
770
|
return memoizedGetInstructionDecoder;
|
|
618
771
|
}
|
|
619
|
-
function getInstructionCodec() {
|
|
620
|
-
return combineCodec(getInstructionEncoder(), getInstructionDecoder());
|
|
621
|
-
}
|
|
622
772
|
var VERSION_FLAG_MASK = 128;
|
|
623
773
|
var BASE_CONFIG = {
|
|
624
774
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
625
775
|
fixedSize: null,
|
|
626
776
|
maxSize: 1
|
|
627
777
|
};
|
|
628
|
-
function decode(
|
|
629
|
-
const firstByte =
|
|
778
|
+
function decode(bytes, offset = 0) {
|
|
779
|
+
const firstByte = bytes[offset];
|
|
630
780
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
631
781
|
return ["legacy", offset];
|
|
632
782
|
} else {
|
|
@@ -655,128 +805,187 @@ function getTransactionVersionEncoder() {
|
|
|
655
805
|
encode
|
|
656
806
|
};
|
|
657
807
|
}
|
|
658
|
-
function getTransactionVersionCodec() {
|
|
659
|
-
return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// src/serializers/unimplemented.ts
|
|
663
|
-
function getError(type, name) {
|
|
664
|
-
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
665
|
-
return new Error(
|
|
666
|
-
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
667
|
-
);
|
|
668
|
-
}
|
|
669
|
-
function getUnimplementedDecoder(name) {
|
|
670
|
-
return () => {
|
|
671
|
-
throw getError("decoder", name);
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
808
|
|
|
675
809
|
// src/serializers/message.ts
|
|
676
|
-
var
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
if (compiledMessage.version === "legacy") {
|
|
683
|
-
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
684
|
-
} else {
|
|
685
|
-
return mapSerializer(
|
|
686
|
-
struct([
|
|
687
|
-
...getPreludeStructSerializerTuple(),
|
|
688
|
-
["addressTableLookups", getAddressTableLookupsSerializer()]
|
|
689
|
-
]),
|
|
690
|
-
(value) => {
|
|
691
|
-
if (value.version === "legacy") {
|
|
692
|
-
return value;
|
|
693
|
-
}
|
|
694
|
-
return {
|
|
695
|
-
...value,
|
|
696
|
-
addressTableLookups: value.addressTableLookups ?? []
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
).serialize(compiledMessage);
|
|
700
|
-
}
|
|
810
|
+
var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
|
|
811
|
+
var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
|
|
812
|
+
var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
|
|
813
|
+
var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
|
|
814
|
+
function getCompiledMessageLegacyEncoder() {
|
|
815
|
+
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
701
816
|
}
|
|
702
|
-
function
|
|
703
|
-
return
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
817
|
+
function getCompiledMessageVersionedEncoder() {
|
|
818
|
+
return mapEncoder(
|
|
819
|
+
getStructEncoder([
|
|
820
|
+
...getPreludeStructEncoderTuple(),
|
|
821
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
822
|
+
]),
|
|
823
|
+
(value) => {
|
|
824
|
+
if (value.version === "legacy") {
|
|
825
|
+
return value;
|
|
826
|
+
}
|
|
827
|
+
return {
|
|
828
|
+
...value,
|
|
829
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
);
|
|
710
833
|
}
|
|
711
|
-
function
|
|
834
|
+
function getPreludeStructEncoderTuple() {
|
|
712
835
|
return [
|
|
713
|
-
["version",
|
|
714
|
-
["header",
|
|
836
|
+
["version", getTransactionVersionEncoder()],
|
|
837
|
+
["header", getMessageHeaderEncoder()],
|
|
715
838
|
[
|
|
716
839
|
"staticAccounts",
|
|
717
|
-
|
|
718
|
-
description:
|
|
719
|
-
size:
|
|
840
|
+
getArrayEncoder(getAddressEncoder(), {
|
|
841
|
+
description: staticAccountsDescription,
|
|
842
|
+
size: getShortU16Encoder()
|
|
720
843
|
})
|
|
721
844
|
],
|
|
722
845
|
[
|
|
723
846
|
"lifetimeToken",
|
|
724
|
-
|
|
725
|
-
description:
|
|
726
|
-
encoding:
|
|
847
|
+
getStringEncoder({
|
|
848
|
+
description: lifetimeTokenDescription,
|
|
849
|
+
encoding: getBase58Encoder(),
|
|
727
850
|
size: 32
|
|
728
851
|
})
|
|
729
852
|
],
|
|
730
853
|
[
|
|
731
854
|
"instructions",
|
|
732
|
-
|
|
733
|
-
description:
|
|
734
|
-
size:
|
|
855
|
+
getArrayEncoder(getInstructionEncoder(), {
|
|
856
|
+
description: instructionsDescription,
|
|
857
|
+
size: getShortU16Encoder()
|
|
735
858
|
})
|
|
736
859
|
]
|
|
737
860
|
];
|
|
738
861
|
}
|
|
739
|
-
function
|
|
740
|
-
return
|
|
741
|
-
|
|
742
|
-
|
|
862
|
+
function getPreludeStructDecoderTuple() {
|
|
863
|
+
return [
|
|
864
|
+
["version", getTransactionVersionDecoder()],
|
|
865
|
+
["header", getMessageHeaderDecoder()],
|
|
866
|
+
[
|
|
867
|
+
"staticAccounts",
|
|
868
|
+
getArrayDecoder(getAddressDecoder(), {
|
|
869
|
+
description: staticAccountsDescription,
|
|
870
|
+
size: getShortU16Decoder()
|
|
871
|
+
})
|
|
872
|
+
],
|
|
873
|
+
[
|
|
874
|
+
"lifetimeToken",
|
|
875
|
+
getStringDecoder({
|
|
876
|
+
description: lifetimeTokenDescription,
|
|
877
|
+
encoding: getBase58Decoder(),
|
|
878
|
+
size: 32
|
|
879
|
+
})
|
|
880
|
+
],
|
|
881
|
+
[
|
|
882
|
+
"instructions",
|
|
883
|
+
getArrayDecoder(getInstructionDecoder(), {
|
|
884
|
+
description: instructionsDescription,
|
|
885
|
+
size: getShortU16Decoder()
|
|
886
|
+
})
|
|
887
|
+
],
|
|
888
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
889
|
+
];
|
|
890
|
+
}
|
|
891
|
+
function getAddressTableLookupArrayEncoder() {
|
|
892
|
+
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
893
|
+
description: addressTableLookupsDescription,
|
|
894
|
+
size: getShortU16Encoder()
|
|
743
895
|
});
|
|
744
896
|
}
|
|
897
|
+
function getAddressTableLookupArrayDecoder() {
|
|
898
|
+
return getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
899
|
+
description: addressTableLookupsDescription,
|
|
900
|
+
size: getShortU16Decoder()
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
|
|
745
904
|
function getCompiledMessageEncoder() {
|
|
746
905
|
return {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
906
|
+
description: messageDescription,
|
|
907
|
+
encode: (compiledMessage) => {
|
|
908
|
+
if (compiledMessage.version === "legacy") {
|
|
909
|
+
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
|
|
910
|
+
} else {
|
|
911
|
+
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
fixedSize: null,
|
|
915
|
+
maxSize: null
|
|
750
916
|
};
|
|
751
917
|
}
|
|
918
|
+
function getCompiledMessageDecoder() {
|
|
919
|
+
return mapDecoder(
|
|
920
|
+
getStructDecoder(getPreludeStructDecoderTuple(), {
|
|
921
|
+
description: messageDescription
|
|
922
|
+
}),
|
|
923
|
+
({ addressTableLookups, ...restOfMessage }) => {
|
|
924
|
+
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
|
|
925
|
+
return restOfMessage;
|
|
926
|
+
}
|
|
927
|
+
return { ...restOfMessage, addressTableLookups };
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
}
|
|
752
931
|
|
|
753
932
|
// src/serializers/transaction.ts
|
|
754
|
-
var
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
};
|
|
759
|
-
function serialize2(transaction) {
|
|
760
|
-
const compiledTransaction = getCompiledTransaction(transaction);
|
|
761
|
-
return struct([
|
|
933
|
+
var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
|
|
934
|
+
var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
|
|
935
|
+
function getCompiledTransactionEncoder() {
|
|
936
|
+
return getStructEncoder(
|
|
762
937
|
[
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
938
|
+
[
|
|
939
|
+
"signatures",
|
|
940
|
+
getArrayEncoder(getBytesEncoder({ size: 64 }), {
|
|
941
|
+
description: signaturesDescription,
|
|
942
|
+
size: getShortU16Encoder()
|
|
943
|
+
})
|
|
944
|
+
],
|
|
945
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
768
946
|
],
|
|
769
|
-
|
|
770
|
-
|
|
947
|
+
{
|
|
948
|
+
description: transactionDescription
|
|
949
|
+
}
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
function getSignatureDecoder() {
|
|
953
|
+
return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
|
|
954
|
+
}
|
|
955
|
+
function getCompiledTransactionDecoder() {
|
|
956
|
+
return getStructDecoder(
|
|
957
|
+
[
|
|
958
|
+
[
|
|
959
|
+
"signatures",
|
|
960
|
+
getArrayDecoder(getSignatureDecoder(), {
|
|
961
|
+
description: signaturesDescription,
|
|
962
|
+
size: getShortU16Decoder()
|
|
963
|
+
})
|
|
964
|
+
],
|
|
965
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
966
|
+
],
|
|
967
|
+
{
|
|
968
|
+
description: transactionDescription
|
|
969
|
+
}
|
|
970
|
+
);
|
|
771
971
|
}
|
|
772
972
|
function getTransactionEncoder() {
|
|
773
|
-
return
|
|
774
|
-
...BASE_CONFIG3,
|
|
775
|
-
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
776
|
-
serialize: serialize2
|
|
777
|
-
};
|
|
973
|
+
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
778
974
|
}
|
|
975
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
976
|
+
return mapDecoder(
|
|
977
|
+
getCompiledTransactionDecoder(),
|
|
978
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
982
|
+
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
983
|
+
}
|
|
984
|
+
var base58Encoder2;
|
|
985
|
+
var base58Decoder;
|
|
779
986
|
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
987
|
+
if (!base58Encoder2)
|
|
988
|
+
base58Encoder2 = getBase58Encoder();
|
|
780
989
|
try {
|
|
781
990
|
if (
|
|
782
991
|
// Lowest value (64 bytes of zeroes)
|
|
@@ -785,8 +994,8 @@ function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
|
785
994
|
) {
|
|
786
995
|
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
787
996
|
}
|
|
788
|
-
const
|
|
789
|
-
const numBytes =
|
|
997
|
+
const bytes = base58Encoder2.encode(putativeTransactionSignature);
|
|
998
|
+
const numBytes = bytes.byteLength;
|
|
790
999
|
if (numBytes !== 64) {
|
|
791
1000
|
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
792
1001
|
}
|
|
@@ -797,6 +1006,8 @@ function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
|
797
1006
|
}
|
|
798
1007
|
}
|
|
799
1008
|
function isTransactionSignature(putativeTransactionSignature) {
|
|
1009
|
+
if (!base58Encoder2)
|
|
1010
|
+
base58Encoder2 = getBase58Encoder();
|
|
800
1011
|
if (
|
|
801
1012
|
// Lowest value (64 bytes of zeroes)
|
|
802
1013
|
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
@@ -804,37 +1015,32 @@ function isTransactionSignature(putativeTransactionSignature) {
|
|
|
804
1015
|
) {
|
|
805
1016
|
return false;
|
|
806
1017
|
}
|
|
807
|
-
const
|
|
808
|
-
const numBytes =
|
|
1018
|
+
const bytes = base58Encoder2.encode(putativeTransactionSignature);
|
|
1019
|
+
const numBytes = bytes.byteLength;
|
|
809
1020
|
if (numBytes !== 64) {
|
|
810
1021
|
return false;
|
|
811
1022
|
}
|
|
812
1023
|
return true;
|
|
813
1024
|
}
|
|
814
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
815
|
-
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
816
|
-
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
817
|
-
return signature;
|
|
818
|
-
}
|
|
819
1025
|
function getSignatureFromTransaction(transaction) {
|
|
1026
|
+
if (!base58Decoder)
|
|
1027
|
+
base58Decoder = getBase58Decoder();
|
|
820
1028
|
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
821
1029
|
if (!signatureBytes) {
|
|
822
1030
|
throw new Error(
|
|
823
1031
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
824
1032
|
);
|
|
825
1033
|
}
|
|
826
|
-
const transactionSignature2 =
|
|
1034
|
+
const transactionSignature2 = base58Decoder.decode(signatureBytes)[0];
|
|
827
1035
|
return transactionSignature2;
|
|
828
1036
|
}
|
|
829
1037
|
async function signTransaction(keyPairs, transaction) {
|
|
830
1038
|
const compiledMessage = compileMessage(transaction);
|
|
831
1039
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1040
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
832
1041
|
const publicKeySignaturePairs = await Promise.all(
|
|
833
1042
|
keyPairs.map(
|
|
834
|
-
(keyPair) => Promise.all([
|
|
835
|
-
getAddressFromPublicKey(keyPair.publicKey),
|
|
836
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
837
|
-
])
|
|
1043
|
+
(keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
838
1044
|
)
|
|
839
1045
|
);
|
|
840
1046
|
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
@@ -851,15 +1057,24 @@ function transactionSignature(putativeTransactionSignature) {
|
|
|
851
1057
|
assertIsTransactionSignature(putativeTransactionSignature);
|
|
852
1058
|
return putativeTransactionSignature;
|
|
853
1059
|
}
|
|
1060
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
1061
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
1062
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1063
|
+
requiredSigners.forEach((address) => {
|
|
1064
|
+
if (!transaction.signatures[address]) {
|
|
1065
|
+
throw new Error(`Transaction is missing signature for address \`${address}\``);
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
854
1069
|
|
|
855
1070
|
// src/wire-transaction.ts
|
|
856
1071
|
function getBase64EncodedWireTransaction(transaction) {
|
|
857
|
-
const wireTransactionBytes = getTransactionEncoder().
|
|
1072
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
858
1073
|
{
|
|
859
1074
|
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
860
1075
|
}
|
|
861
1076
|
}
|
|
862
1077
|
|
|
863
|
-
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isAdvanceNonceAccountInstruction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|
|
1078
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, assertTransactionIsFullySigned, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|
|
864
1079
|
//# sourceMappingURL=out.js.map
|
|
865
1080
|
//# sourceMappingURL=index.native.js.map
|