@solana/transactions 2.0.0-experimental.835e62f → 2.0.0-experimental.85b7dfe
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/LICENSE +1 -1
- package/README.md +272 -5
- package/dist/index.browser.cjs +543 -236
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +533 -238
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +1141 -664
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +533 -238
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +543 -236
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +535 -238
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +23 -11
- package/dist/types/accounts.d.ts +3 -3
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +2 -1
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compilable-transaction.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts +2 -2
- 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 +1 -1
- 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 +2 -2
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts +5 -6
- 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 +5 -0
- package/dist/types/decompile-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +10 -9
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +4 -3
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -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 +1 -5
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts +5 -3
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts +3 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts +4 -2
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts +4 -4
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts +6 -5
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +10 -5
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts +13 -13
- 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 +2 -2
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +22 -18
- package/dist/types/serializers/unimplemented.d.ts +0 -3
package/dist/index.browser.cjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
4
|
+
var addresses = require('@solana/addresses');
|
|
5
|
+
var codecsCore = require('@solana/codecs-core');
|
|
6
|
+
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
7
|
+
var codecsNumbers = require('@solana/codecs-numbers');
|
|
8
|
+
var functional = require('@solana/functional');
|
|
4
9
|
var keys = require('@solana/keys');
|
|
5
10
|
|
|
6
11
|
// ../build-scripts/env-shim.ts
|
|
@@ -21,7 +26,10 @@ function getUnsignedTransaction(transaction) {
|
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
// src/blockhash.ts
|
|
29
|
+
var base58Encoder;
|
|
24
30
|
function assertIsBlockhash(putativeBlockhash) {
|
|
31
|
+
if (!base58Encoder)
|
|
32
|
+
base58Encoder = codecsStrings.getBase58Encoder();
|
|
25
33
|
try {
|
|
26
34
|
if (
|
|
27
35
|
// Lowest value (32 bytes of zeroes)
|
|
@@ -30,8 +38,8 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
30
38
|
) {
|
|
31
39
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
32
40
|
}
|
|
33
|
-
const
|
|
34
|
-
const numBytes =
|
|
41
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
42
|
+
const numBytes = bytes.byteLength;
|
|
35
43
|
if (numBytes !== 32) {
|
|
36
44
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
37
45
|
}
|
|
@@ -41,6 +49,22 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
41
49
|
});
|
|
42
50
|
}
|
|
43
51
|
}
|
|
52
|
+
function isTransactionWithBlockhashLifetime(transaction) {
|
|
53
|
+
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
|
|
54
|
+
if (!lifetimeConstraintShapeMatches)
|
|
55
|
+
return false;
|
|
56
|
+
try {
|
|
57
|
+
assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
|
|
58
|
+
return true;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function assertIsTransactionWithBlockhashLifetime(transaction) {
|
|
64
|
+
if (!isTransactionWithBlockhashLifetime(transaction)) {
|
|
65
|
+
throw new Error("Transaction does not have a blockhash lifetime");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
44
68
|
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
45
69
|
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
46
70
|
return transaction;
|
|
@@ -116,7 +140,7 @@ function isAdvanceNonceAccountInstruction(instruction) {
|
|
|
116
140
|
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
117
141
|
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
118
142
|
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
119
|
-
instruction.accounts[2].address != null && instruction.accounts[2].role
|
|
143
|
+
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
120
144
|
}
|
|
121
145
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
122
146
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
@@ -124,21 +148,38 @@ function isAdvanceNonceAccountInstructionData(data) {
|
|
|
124
148
|
function isDurableNonceTransaction(transaction) {
|
|
125
149
|
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
126
150
|
}
|
|
151
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
152
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
153
|
+
}
|
|
127
154
|
function setTransactionLifetimeUsingDurableNonce({
|
|
128
155
|
nonce,
|
|
129
156
|
nonceAccountAddress,
|
|
130
157
|
nonceAuthorityAddress
|
|
131
158
|
}, transaction) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
159
|
+
let newInstructions;
|
|
160
|
+
const firstInstruction = transaction.instructions[0];
|
|
161
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
162
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
163
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
164
|
+
return transaction;
|
|
165
|
+
} else {
|
|
166
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
newInstructions = [
|
|
170
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
171
|
+
...transaction.instructions.slice(1)
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
newInstructions = [
|
|
176
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
177
|
+
...transaction.instructions
|
|
178
|
+
];
|
|
135
179
|
}
|
|
136
180
|
const out = {
|
|
137
181
|
...getUnsignedTransaction(transaction),
|
|
138
|
-
instructions:
|
|
139
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
140
|
-
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
141
|
-
],
|
|
182
|
+
instructions: newInstructions,
|
|
142
183
|
lifetimeConstraint: {
|
|
143
184
|
nonce
|
|
144
185
|
}
|
|
@@ -229,7 +270,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
229
270
|
const shouldReplaceEntry = (
|
|
230
271
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
231
272
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
232
|
-
(addressComparator
|
|
273
|
+
(addressComparator ||= addresses.getAddressComparator())(
|
|
233
274
|
accountMeta.lookupTableAddress,
|
|
234
275
|
entry.lookupTableAddress
|
|
235
276
|
) < 0
|
|
@@ -335,7 +376,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
335
376
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
336
377
|
return leftIsWritable ? -1 : 1;
|
|
337
378
|
}
|
|
338
|
-
addressComparator
|
|
379
|
+
addressComparator ||= addresses.getAddressComparator();
|
|
339
380
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
340
381
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
341
382
|
} else {
|
|
@@ -348,23 +389,22 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
348
389
|
return orderedAccounts;
|
|
349
390
|
}
|
|
350
391
|
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
351
|
-
var _a;
|
|
352
392
|
const index = {};
|
|
353
393
|
for (const account of orderedAccounts) {
|
|
354
394
|
if (!("lookupTableAddress" in account)) {
|
|
355
395
|
continue;
|
|
356
396
|
}
|
|
357
|
-
const entry = index[
|
|
397
|
+
const entry = index[account.lookupTableAddress] ||= {
|
|
358
398
|
readableIndices: [],
|
|
359
399
|
writableIndices: []
|
|
360
|
-
}
|
|
400
|
+
};
|
|
361
401
|
if (account.role === AccountRole.WRITABLE) {
|
|
362
402
|
entry.writableIndices.push(account.addressIndex);
|
|
363
403
|
} else {
|
|
364
404
|
entry.readableIndices.push(account.addressIndex);
|
|
365
405
|
}
|
|
366
406
|
}
|
|
367
|
-
return Object.keys(index).sort(
|
|
407
|
+
return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
|
|
368
408
|
lookupTableAddress,
|
|
369
409
|
...index[lookupTableAddress]
|
|
370
410
|
}));
|
|
@@ -443,151 +483,189 @@ function compileMessage(transaction) {
|
|
|
443
483
|
version: transaction.version
|
|
444
484
|
};
|
|
445
485
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
486
|
+
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
487
|
+
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
488
|
+
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
489
|
+
var addressTableLookupDescription = __DEV__ ? "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" : "addressTableLookup";
|
|
490
|
+
var memoizedAddressTableLookupEncoder;
|
|
491
|
+
function getAddressTableLookupEncoder() {
|
|
492
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
493
|
+
memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder(
|
|
449
494
|
[
|
|
450
|
-
"lookupTableAddress",
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
495
|
+
["lookupTableAddress", addresses.getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
496
|
+
[
|
|
497
|
+
"writableIndices",
|
|
498
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
499
|
+
description: writableIndicesDescription,
|
|
500
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
501
|
+
})
|
|
502
|
+
],
|
|
503
|
+
[
|
|
504
|
+
"readableIndices",
|
|
505
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
506
|
+
description: readableIndicesDescription,
|
|
507
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
508
|
+
})
|
|
509
|
+
]
|
|
456
510
|
],
|
|
511
|
+
{ description: addressTableLookupDescription }
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
return memoizedAddressTableLookupEncoder;
|
|
515
|
+
}
|
|
516
|
+
var memoizedAddressTableLookupDecoder;
|
|
517
|
+
function getAddressTableLookupDecoder() {
|
|
518
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
519
|
+
memoizedAddressTableLookupDecoder = codecsDataStructures.getStructDecoder(
|
|
457
520
|
[
|
|
458
|
-
"
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
521
|
+
["lookupTableAddress", addresses.getAddressDecoder({ description: lookupTableAddressDescription })],
|
|
522
|
+
[
|
|
523
|
+
"writableIndices",
|
|
524
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
|
|
525
|
+
description: writableIndicesDescription,
|
|
526
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
527
|
+
})
|
|
528
|
+
],
|
|
529
|
+
[
|
|
530
|
+
"readableIndices",
|
|
531
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
|
|
532
|
+
description: readableIndicesDescription,
|
|
533
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
534
|
+
})
|
|
535
|
+
]
|
|
465
536
|
],
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
description: "The indices of the accounts in the lookup table that should be loaded as read-only"
|
|
471
|
-
} : void 0,
|
|
472
|
-
size: umiSerializers.shortU16()
|
|
473
|
-
})
|
|
474
|
-
]
|
|
475
|
-
],
|
|
476
|
-
__DEV__ ? {
|
|
477
|
-
description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it"
|
|
478
|
-
} : void 0
|
|
479
|
-
);
|
|
537
|
+
{ description: addressTableLookupDescription }
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
return memoizedAddressTableLookupDecoder;
|
|
480
541
|
}
|
|
481
|
-
|
|
482
|
-
|
|
542
|
+
var memoizedU8Encoder;
|
|
543
|
+
function getMemoizedU8Encoder() {
|
|
544
|
+
if (!memoizedU8Encoder)
|
|
545
|
+
memoizedU8Encoder = codecsNumbers.getU8Encoder();
|
|
546
|
+
return memoizedU8Encoder;
|
|
547
|
+
}
|
|
548
|
+
function getMemoizedU8EncoderDescription(description) {
|
|
549
|
+
const encoder = getMemoizedU8Encoder();
|
|
550
|
+
return {
|
|
551
|
+
...encoder,
|
|
552
|
+
description: description ?? encoder.description
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
var memoizedU8Decoder;
|
|
556
|
+
function getMemoizedU8Decoder() {
|
|
557
|
+
if (!memoizedU8Decoder)
|
|
558
|
+
memoizedU8Decoder = codecsNumbers.getU8Decoder();
|
|
559
|
+
return memoizedU8Decoder;
|
|
560
|
+
}
|
|
561
|
+
function getMemoizedU8DecoderDescription(description) {
|
|
562
|
+
const decoder = getMemoizedU8Decoder();
|
|
563
|
+
return {
|
|
564
|
+
...decoder,
|
|
565
|
+
description: description ?? decoder.description
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
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;
|
|
569
|
+
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;
|
|
570
|
+
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
571
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
572
|
+
function getMessageHeaderEncoder() {
|
|
573
|
+
return codecsDataStructures.getStructEncoder(
|
|
483
574
|
[
|
|
484
|
-
[
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
__DEV__ ? {
|
|
488
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
489
|
-
} : void 0
|
|
490
|
-
)
|
|
491
|
-
],
|
|
492
|
-
[
|
|
493
|
-
"numReadonlySignerAccounts",
|
|
494
|
-
umiSerializers.u8(
|
|
495
|
-
__DEV__ ? {
|
|
496
|
-
description: "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"
|
|
497
|
-
} : void 0
|
|
498
|
-
)
|
|
499
|
-
],
|
|
500
|
-
[
|
|
501
|
-
"numReadonlyNonSignerAccounts",
|
|
502
|
-
umiSerializers.u8(
|
|
503
|
-
__DEV__ ? {
|
|
504
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
505
|
-
} : void 0
|
|
506
|
-
)
|
|
507
|
-
]
|
|
575
|
+
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
576
|
+
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
577
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
508
578
|
],
|
|
509
|
-
|
|
510
|
-
description:
|
|
511
|
-
}
|
|
579
|
+
{
|
|
580
|
+
description: messageHeaderDescription
|
|
581
|
+
}
|
|
512
582
|
);
|
|
513
583
|
}
|
|
514
|
-
function
|
|
515
|
-
return
|
|
516
|
-
|
|
517
|
-
[
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
)
|
|
524
|
-
],
|
|
525
|
-
[
|
|
526
|
-
"addressIndices",
|
|
527
|
-
umiSerializers.array(
|
|
528
|
-
umiSerializers.u8({
|
|
529
|
-
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
530
|
-
}),
|
|
531
|
-
{
|
|
532
|
-
description: __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" : "",
|
|
533
|
-
size: umiSerializers.shortU16()
|
|
534
|
-
}
|
|
535
|
-
)
|
|
536
|
-
],
|
|
537
|
-
[
|
|
538
|
-
"data",
|
|
539
|
-
umiSerializers.bytes({
|
|
540
|
-
description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
|
|
541
|
-
size: umiSerializers.shortU16()
|
|
542
|
-
})
|
|
543
|
-
]
|
|
544
|
-
]),
|
|
545
|
-
(value) => {
|
|
546
|
-
if (value.addressIndices !== void 0 && value.data !== void 0) {
|
|
547
|
-
return value;
|
|
548
|
-
}
|
|
549
|
-
return {
|
|
550
|
-
...value,
|
|
551
|
-
addressIndices: value.addressIndices ?? [],
|
|
552
|
-
data: value.data ?? new Uint8Array(0)
|
|
553
|
-
};
|
|
554
|
-
},
|
|
555
|
-
(value) => {
|
|
556
|
-
if (value.addressIndices.length && value.data.byteLength) {
|
|
557
|
-
return value;
|
|
558
|
-
}
|
|
559
|
-
const { addressIndices, data, ...rest } = value;
|
|
560
|
-
return {
|
|
561
|
-
...rest,
|
|
562
|
-
...addressIndices.length ? { addressIndices } : null,
|
|
563
|
-
...data.byteLength ? { data } : null
|
|
564
|
-
};
|
|
584
|
+
function getMessageHeaderDecoder() {
|
|
585
|
+
return codecsDataStructures.getStructDecoder(
|
|
586
|
+
[
|
|
587
|
+
["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
|
|
588
|
+
["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
|
|
589
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
590
|
+
],
|
|
591
|
+
{
|
|
592
|
+
description: messageHeaderDescription
|
|
565
593
|
}
|
|
566
594
|
);
|
|
567
595
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
)
|
|
596
|
+
var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
|
|
597
|
+
var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
|
|
598
|
+
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";
|
|
599
|
+
var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
|
|
600
|
+
var memoizedGetInstructionEncoder;
|
|
601
|
+
function getInstructionEncoder() {
|
|
602
|
+
if (!memoizedGetInstructionEncoder) {
|
|
603
|
+
memoizedGetInstructionEncoder = codecsCore.mapEncoder(
|
|
604
|
+
codecsDataStructures.getStructEncoder([
|
|
605
|
+
["programAddressIndex", codecsNumbers.getU8Encoder({ description: programAddressIndexDescription })],
|
|
606
|
+
[
|
|
607
|
+
"accountIndices",
|
|
608
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder({ description: accountIndexDescription }), {
|
|
609
|
+
description: accountIndicesDescription,
|
|
610
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
611
|
+
})
|
|
612
|
+
],
|
|
613
|
+
["data", codecsDataStructures.getBytesEncoder({ description: dataDescription, size: codecsNumbers.getShortU16Encoder() })]
|
|
614
|
+
]),
|
|
615
|
+
// Convert an instruction to have all fields defined
|
|
616
|
+
(instruction) => {
|
|
617
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
618
|
+
return instruction;
|
|
619
|
+
}
|
|
620
|
+
return {
|
|
621
|
+
...instruction,
|
|
622
|
+
accountIndices: instruction.accountIndices ?? [],
|
|
623
|
+
data: instruction.data ?? new Uint8Array(0)
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
return memoizedGetInstructionEncoder;
|
|
575
629
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
630
|
+
var memoizedGetInstructionDecoder;
|
|
631
|
+
function getInstructionDecoder() {
|
|
632
|
+
if (!memoizedGetInstructionDecoder) {
|
|
633
|
+
memoizedGetInstructionDecoder = codecsCore.mapDecoder(
|
|
634
|
+
codecsDataStructures.getStructDecoder([
|
|
635
|
+
["programAddressIndex", codecsNumbers.getU8Decoder({ description: programAddressIndexDescription })],
|
|
636
|
+
[
|
|
637
|
+
"accountIndices",
|
|
638
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder({ description: accountIndexDescription }), {
|
|
639
|
+
description: accountIndicesDescription,
|
|
640
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
641
|
+
})
|
|
642
|
+
],
|
|
643
|
+
["data", codecsDataStructures.getBytesDecoder({ description: dataDescription, size: codecsNumbers.getShortU16Decoder() })]
|
|
644
|
+
]),
|
|
645
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
646
|
+
(instruction) => {
|
|
647
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
648
|
+
return instruction;
|
|
649
|
+
}
|
|
650
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
651
|
+
return {
|
|
652
|
+
...rest,
|
|
653
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
654
|
+
...data.byteLength ? { data } : null
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
return memoizedGetInstructionDecoder;
|
|
580
660
|
}
|
|
581
|
-
|
|
582
|
-
// src/serializers/transaction-version.ts
|
|
583
661
|
var VERSION_FLAG_MASK = 128;
|
|
584
662
|
var BASE_CONFIG = {
|
|
585
663
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
586
664
|
fixedSize: null,
|
|
587
665
|
maxSize: 1
|
|
588
666
|
};
|
|
589
|
-
function
|
|
590
|
-
const firstByte =
|
|
667
|
+
function decode(bytes, offset = 0) {
|
|
668
|
+
const firstByte = bytes[offset];
|
|
591
669
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
592
670
|
return ["legacy", offset];
|
|
593
671
|
} else {
|
|
@@ -595,7 +673,7 @@ function deserialize(bytes3, offset = 0) {
|
|
|
595
673
|
return [version, offset + 1];
|
|
596
674
|
}
|
|
597
675
|
}
|
|
598
|
-
function
|
|
676
|
+
function encode(value) {
|
|
599
677
|
if (value === "legacy") {
|
|
600
678
|
return new Uint8Array();
|
|
601
679
|
}
|
|
@@ -604,105 +682,143 @@ function serialize(value) {
|
|
|
604
682
|
}
|
|
605
683
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
606
684
|
}
|
|
607
|
-
function
|
|
685
|
+
function getTransactionVersionDecoder() {
|
|
686
|
+
return {
|
|
687
|
+
...BASE_CONFIG,
|
|
688
|
+
decode
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
function getTransactionVersionEncoder() {
|
|
608
692
|
return {
|
|
609
693
|
...BASE_CONFIG,
|
|
610
|
-
|
|
611
|
-
serialize
|
|
694
|
+
encode
|
|
612
695
|
};
|
|
613
696
|
}
|
|
614
697
|
|
|
615
698
|
// src/serializers/message.ts
|
|
616
|
-
var
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
(value)
|
|
631
|
-
|
|
632
|
-
return value;
|
|
633
|
-
}
|
|
634
|
-
return {
|
|
635
|
-
...value,
|
|
636
|
-
addressTableLookups: value.addressTableLookups ?? []
|
|
637
|
-
};
|
|
699
|
+
var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
|
|
700
|
+
var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
|
|
701
|
+
var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
|
|
702
|
+
var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
|
|
703
|
+
function getCompiledMessageLegacyEncoder() {
|
|
704
|
+
return codecsDataStructures.getStructEncoder(getPreludeStructEncoderTuple());
|
|
705
|
+
}
|
|
706
|
+
function getCompiledMessageVersionedEncoder() {
|
|
707
|
+
return codecsCore.mapEncoder(
|
|
708
|
+
codecsDataStructures.getStructEncoder([
|
|
709
|
+
...getPreludeStructEncoderTuple(),
|
|
710
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
711
|
+
]),
|
|
712
|
+
(value) => {
|
|
713
|
+
if (value.version === "legacy") {
|
|
714
|
+
return value;
|
|
638
715
|
}
|
|
639
|
-
|
|
640
|
-
|
|
716
|
+
return {
|
|
717
|
+
...value,
|
|
718
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
);
|
|
641
722
|
}
|
|
642
|
-
function
|
|
723
|
+
function getPreludeStructEncoderTuple() {
|
|
643
724
|
return [
|
|
644
|
-
["version",
|
|
645
|
-
["header",
|
|
725
|
+
["version", getTransactionVersionEncoder()],
|
|
726
|
+
["header", getMessageHeaderEncoder()],
|
|
646
727
|
[
|
|
647
728
|
"staticAccounts",
|
|
648
|
-
|
|
649
|
-
description:
|
|
650
|
-
size:
|
|
729
|
+
codecsDataStructures.getArrayEncoder(addresses.getAddressEncoder(), {
|
|
730
|
+
description: staticAccountsDescription,
|
|
731
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
651
732
|
})
|
|
652
733
|
],
|
|
653
734
|
[
|
|
654
735
|
"lifetimeToken",
|
|
655
|
-
|
|
656
|
-
description:
|
|
657
|
-
encoding:
|
|
736
|
+
codecsStrings.getStringEncoder({
|
|
737
|
+
description: lifetimeTokenDescription,
|
|
738
|
+
encoding: codecsStrings.getBase58Encoder(),
|
|
658
739
|
size: 32
|
|
659
740
|
})
|
|
660
741
|
],
|
|
661
742
|
[
|
|
662
743
|
"instructions",
|
|
663
|
-
|
|
664
|
-
description:
|
|
665
|
-
size:
|
|
744
|
+
codecsDataStructures.getArrayEncoder(getInstructionEncoder(), {
|
|
745
|
+
description: instructionsDescription,
|
|
746
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
666
747
|
})
|
|
667
748
|
]
|
|
668
749
|
];
|
|
669
750
|
}
|
|
670
|
-
function
|
|
671
|
-
return
|
|
672
|
-
|
|
673
|
-
|
|
751
|
+
function getPreludeStructDecoderTuple() {
|
|
752
|
+
return [
|
|
753
|
+
["version", getTransactionVersionDecoder()],
|
|
754
|
+
["header", getMessageHeaderDecoder()],
|
|
755
|
+
[
|
|
756
|
+
"staticAccounts",
|
|
757
|
+
codecsDataStructures.getArrayDecoder(addresses.getAddressDecoder(), {
|
|
758
|
+
description: staticAccountsDescription,
|
|
759
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
760
|
+
})
|
|
761
|
+
],
|
|
762
|
+
[
|
|
763
|
+
"lifetimeToken",
|
|
764
|
+
codecsStrings.getStringDecoder({
|
|
765
|
+
description: lifetimeTokenDescription,
|
|
766
|
+
encoding: codecsStrings.getBase58Decoder(),
|
|
767
|
+
size: 32
|
|
768
|
+
})
|
|
769
|
+
],
|
|
770
|
+
[
|
|
771
|
+
"instructions",
|
|
772
|
+
codecsDataStructures.getArrayDecoder(getInstructionDecoder(), {
|
|
773
|
+
description: instructionsDescription,
|
|
774
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
775
|
+
})
|
|
776
|
+
],
|
|
777
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
778
|
+
];
|
|
779
|
+
}
|
|
780
|
+
function getAddressTableLookupArrayEncoder() {
|
|
781
|
+
return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
782
|
+
description: addressTableLookupsDescription,
|
|
783
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
function getAddressTableLookupArrayDecoder() {
|
|
787
|
+
return codecsDataStructures.getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
788
|
+
description: addressTableLookupsDescription,
|
|
789
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
674
790
|
});
|
|
675
791
|
}
|
|
792
|
+
var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
|
|
676
793
|
function getCompiledMessageEncoder() {
|
|
677
794
|
return {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
795
|
+
description: messageDescription,
|
|
796
|
+
encode: (compiledMessage) => {
|
|
797
|
+
if (compiledMessage.version === "legacy") {
|
|
798
|
+
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
|
|
799
|
+
} else {
|
|
800
|
+
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
|
|
801
|
+
}
|
|
802
|
+
},
|
|
803
|
+
fixedSize: null,
|
|
804
|
+
maxSize: null
|
|
681
805
|
};
|
|
682
806
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
807
|
+
function getCompiledMessageDecoder() {
|
|
808
|
+
return codecsCore.mapDecoder(
|
|
809
|
+
codecsDataStructures.getStructDecoder(getPreludeStructDecoderTuple(), {
|
|
810
|
+
description: messageDescription
|
|
811
|
+
}),
|
|
812
|
+
({ addressTableLookups, ...restOfMessage }) => {
|
|
813
|
+
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
|
|
814
|
+
return restOfMessage;
|
|
815
|
+
}
|
|
816
|
+
return { ...restOfMessage, addressTableLookups };
|
|
817
|
+
}
|
|
818
|
+
);
|
|
689
819
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
693
|
-
keys.getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
|
|
694
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
695
|
-
]);
|
|
696
|
-
const nextSignatures = {
|
|
697
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
698
|
-
...{ [signerPublicKey]: signature }
|
|
699
|
-
};
|
|
700
|
-
const out = {
|
|
701
|
-
...transaction,
|
|
702
|
-
signatures: nextSignatures
|
|
703
|
-
};
|
|
704
|
-
Object.freeze(out);
|
|
705
|
-
return out;
|
|
820
|
+
function getCompiledMessageCodec() {
|
|
821
|
+
return codecsCore.combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
706
822
|
}
|
|
707
823
|
|
|
708
824
|
// src/compile-transaction.ts
|
|
@@ -722,47 +838,238 @@ function getCompiledTransaction(transaction) {
|
|
|
722
838
|
signatures
|
|
723
839
|
};
|
|
724
840
|
}
|
|
841
|
+
function getAccountMetas(message) {
|
|
842
|
+
const { header } = message;
|
|
843
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
844
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
845
|
+
const accountMetas = [];
|
|
846
|
+
let accountIndex = 0;
|
|
847
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
848
|
+
accountMetas.push({
|
|
849
|
+
address: message.staticAccounts[accountIndex],
|
|
850
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
851
|
+
});
|
|
852
|
+
accountIndex++;
|
|
853
|
+
}
|
|
854
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
855
|
+
accountMetas.push({
|
|
856
|
+
address: message.staticAccounts[accountIndex],
|
|
857
|
+
role: AccountRole.READONLY_SIGNER
|
|
858
|
+
});
|
|
859
|
+
accountIndex++;
|
|
860
|
+
}
|
|
861
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
862
|
+
accountMetas.push({
|
|
863
|
+
address: message.staticAccounts[accountIndex],
|
|
864
|
+
role: AccountRole.WRITABLE
|
|
865
|
+
});
|
|
866
|
+
accountIndex++;
|
|
867
|
+
}
|
|
868
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
869
|
+
accountMetas.push({
|
|
870
|
+
address: message.staticAccounts[accountIndex],
|
|
871
|
+
role: AccountRole.READONLY
|
|
872
|
+
});
|
|
873
|
+
accountIndex++;
|
|
874
|
+
}
|
|
875
|
+
return accountMetas;
|
|
876
|
+
}
|
|
877
|
+
function convertInstruction(instruction, accountMetas) {
|
|
878
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
879
|
+
if (!programAddress) {
|
|
880
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
881
|
+
}
|
|
882
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
883
|
+
const { data } = instruction;
|
|
884
|
+
return {
|
|
885
|
+
programAddress,
|
|
886
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
887
|
+
...data && data.length ? { data } : {}
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
891
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
892
|
+
return {
|
|
893
|
+
blockhash: messageLifetimeToken,
|
|
894
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
895
|
+
// U64 MAX
|
|
896
|
+
};
|
|
897
|
+
} else {
|
|
898
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
899
|
+
addresses.assertIsAddress(nonceAccountAddress);
|
|
900
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
901
|
+
addresses.assertIsAddress(nonceAuthorityAddress);
|
|
902
|
+
return {
|
|
903
|
+
nonce: messageLifetimeToken,
|
|
904
|
+
nonceAccountAddress,
|
|
905
|
+
nonceAuthorityAddress
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
function convertSignatures(compiledTransaction) {
|
|
910
|
+
const {
|
|
911
|
+
compiledMessage: { staticAccounts },
|
|
912
|
+
signatures
|
|
913
|
+
} = compiledTransaction;
|
|
914
|
+
return signatures.reduce((acc, sig, index) => {
|
|
915
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
916
|
+
if (allZeros)
|
|
917
|
+
return acc;
|
|
918
|
+
const address = staticAccounts[index];
|
|
919
|
+
return { ...acc, [address]: sig };
|
|
920
|
+
}, {});
|
|
921
|
+
}
|
|
922
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
923
|
+
const { compiledMessage } = compiledTransaction;
|
|
924
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
925
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
926
|
+
}
|
|
927
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
928
|
+
if (!feePayer)
|
|
929
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
930
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
931
|
+
const instructions = compiledMessage.instructions.map(
|
|
932
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
933
|
+
);
|
|
934
|
+
const firstInstruction = instructions[0];
|
|
935
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
936
|
+
compiledMessage.lifetimeToken,
|
|
937
|
+
firstInstruction,
|
|
938
|
+
lastValidBlockHeight
|
|
939
|
+
);
|
|
940
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
941
|
+
return functional.pipe(
|
|
942
|
+
createTransaction({ version: compiledMessage.version }),
|
|
943
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
944
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
945
|
+
return appendTransactionInstruction(instruction, acc);
|
|
946
|
+
}, tx),
|
|
947
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
948
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
949
|
+
);
|
|
950
|
+
}
|
|
725
951
|
|
|
726
952
|
// src/serializers/transaction.ts
|
|
727
|
-
var
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
};
|
|
732
|
-
function serialize3(transaction) {
|
|
733
|
-
const compiledTransaction = getCompiledTransaction(transaction);
|
|
734
|
-
return umiSerializers.struct([
|
|
953
|
+
var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
|
|
954
|
+
var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
|
|
955
|
+
function getCompiledTransactionEncoder() {
|
|
956
|
+
return codecsDataStructures.getStructEncoder(
|
|
735
957
|
[
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
958
|
+
[
|
|
959
|
+
"signatures",
|
|
960
|
+
codecsDataStructures.getArrayEncoder(codecsDataStructures.getBytesEncoder({ size: 64 }), {
|
|
961
|
+
description: signaturesDescription,
|
|
962
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
963
|
+
})
|
|
964
|
+
],
|
|
965
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
741
966
|
],
|
|
742
|
-
|
|
743
|
-
|
|
967
|
+
{
|
|
968
|
+
description: transactionDescription
|
|
969
|
+
}
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
function getSignatureDecoder() {
|
|
973
|
+
return codecsCore.mapDecoder(codecsDataStructures.getBytesDecoder({ size: 64 }), (bytes) => bytes);
|
|
974
|
+
}
|
|
975
|
+
function getCompiledTransactionDecoder() {
|
|
976
|
+
return codecsDataStructures.getStructDecoder(
|
|
977
|
+
[
|
|
978
|
+
[
|
|
979
|
+
"signatures",
|
|
980
|
+
codecsDataStructures.getArrayDecoder(getSignatureDecoder(), {
|
|
981
|
+
description: signaturesDescription,
|
|
982
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
983
|
+
})
|
|
984
|
+
],
|
|
985
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
986
|
+
],
|
|
987
|
+
{
|
|
988
|
+
description: transactionDescription
|
|
989
|
+
}
|
|
990
|
+
);
|
|
744
991
|
}
|
|
745
992
|
function getTransactionEncoder() {
|
|
746
|
-
return
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
993
|
+
return codecsCore.mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
994
|
+
}
|
|
995
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
996
|
+
return codecsCore.mapDecoder(
|
|
997
|
+
getCompiledTransactionDecoder(),
|
|
998
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
1002
|
+
return codecsCore.combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
1003
|
+
}
|
|
1004
|
+
var base58Decoder;
|
|
1005
|
+
function getSignatureFromTransaction(transaction) {
|
|
1006
|
+
if (!base58Decoder)
|
|
1007
|
+
base58Decoder = codecsStrings.getBase58Decoder();
|
|
1008
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1009
|
+
if (!signatureBytes) {
|
|
1010
|
+
throw new Error(
|
|
1011
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
1014
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
1015
|
+
return transactionSignature;
|
|
1016
|
+
}
|
|
1017
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1018
|
+
const compiledMessage = compileMessage(transaction);
|
|
1019
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1020
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
1021
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
1022
|
+
keyPairs.map(
|
|
1023
|
+
(keyPair) => Promise.all([addresses.getAddressFromPublicKey(keyPair.publicKey), keys.signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
1024
|
+
)
|
|
1025
|
+
);
|
|
1026
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
1027
|
+
nextSignatures[signerPublicKey] = signature;
|
|
1028
|
+
}
|
|
1029
|
+
const out = {
|
|
1030
|
+
...transaction,
|
|
1031
|
+
signatures: nextSignatures
|
|
750
1032
|
};
|
|
1033
|
+
Object.freeze(out);
|
|
1034
|
+
return out;
|
|
1035
|
+
}
|
|
1036
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1037
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1038
|
+
assertTransactionIsFullySigned(out);
|
|
1039
|
+
Object.freeze(out);
|
|
1040
|
+
return out;
|
|
1041
|
+
}
|
|
1042
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
1043
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
1044
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1045
|
+
requiredSigners.forEach((address) => {
|
|
1046
|
+
if (!transaction.signatures[address]) {
|
|
1047
|
+
throw new Error(`Transaction is missing signature for address \`${address}\``);
|
|
1048
|
+
}
|
|
1049
|
+
});
|
|
751
1050
|
}
|
|
752
|
-
|
|
753
|
-
// src/wire-transaction.ts
|
|
754
1051
|
function getBase64EncodedWireTransaction(transaction) {
|
|
755
|
-
const wireTransactionBytes = getTransactionEncoder().
|
|
756
|
-
|
|
757
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
758
|
-
}
|
|
1052
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1053
|
+
return codecsStrings.getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
759
1054
|
}
|
|
760
1055
|
|
|
761
1056
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
762
1057
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
763
1058
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1059
|
+
exports.assertIsTransactionWithBlockhashLifetime = assertIsTransactionWithBlockhashLifetime;
|
|
1060
|
+
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
1061
|
+
exports.compileMessage = compileMessage;
|
|
764
1062
|
exports.createTransaction = createTransaction;
|
|
765
1063
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1064
|
+
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
1065
|
+
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
1066
|
+
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
1067
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1068
|
+
exports.getTransactionCodec = getTransactionCodec;
|
|
1069
|
+
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1070
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1071
|
+
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1072
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
766
1073
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
767
1074
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
768
1075
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|