@solana/transactions 2.0.0-experimental.0de6c3e → 2.0.0-experimental.10bfcd8
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 +314 -5
- package/dist/index.browser.cjs +686 -287
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +675 -289
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +1260 -661
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +675 -289
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +688 -287
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +675 -291
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +20 -7
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/blockhash.d.ts +9 -1
- package/dist/types/compile-address-table-lookups.d.ts +1 -1
- package/dist/types/compile-instructions.d.ts +1 -1
- package/dist/types/compile-static-accounts.d.ts +1 -1
- package/dist/types/decompile-transaction.d.ts +7 -0
- package/dist/types/durable-nonce.d.ts +23 -10
- package/dist/types/fee-payer.d.ts +3 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts +5 -3
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/instruction.d.ts +4 -2
- package/dist/types/serializers/message.d.ts +4 -4
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/serializers/transaction.d.ts +7 -4
- package/dist/types/signatures.d.ts +14 -6
- package/dist/types/types.d.ts +7 -0
- package/dist/types/unsigned-transaction.d.ts +4 -0
- package/dist/types/wire-transaction.d.ts +2 -2
- package/package.json +26 -23
- 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/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/wire-transaction.d.ts.map +0 -1
package/dist/index.browser.cjs
CHANGED
|
@@ -1,79 +1,72 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var keys = require('@solana/keys');
|
|
4
3
|
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
|
+
var codecsCore = require('@solana/codecs-core');
|
|
5
|
+
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
6
|
+
var codecsNumbers = require('@solana/codecs-numbers');
|
|
7
|
+
var addresses = require('@solana/addresses');
|
|
8
|
+
var functional = require('@solana/functional');
|
|
9
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
10
|
+
var keys = require('@solana/keys');
|
|
5
11
|
|
|
6
12
|
// ../build-scripts/env-shim.ts
|
|
7
13
|
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
8
14
|
|
|
9
|
-
// src/
|
|
10
|
-
function
|
|
11
|
-
version
|
|
12
|
-
}) {
|
|
13
|
-
const out = {
|
|
14
|
-
instructions: [],
|
|
15
|
-
version
|
|
16
|
-
};
|
|
17
|
-
Object.freeze(out);
|
|
18
|
-
return out;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/fee-payer.ts
|
|
22
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
23
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
24
|
-
return transaction;
|
|
25
|
-
}
|
|
26
|
-
let out;
|
|
15
|
+
// src/unsigned-transaction.ts
|
|
16
|
+
function getUnsignedTransaction(transaction) {
|
|
27
17
|
if ("signatures" in transaction) {
|
|
28
18
|
const {
|
|
29
19
|
signatures: _,
|
|
30
20
|
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
31
21
|
...unsignedTransaction
|
|
32
22
|
} = transaction;
|
|
33
|
-
|
|
34
|
-
...unsignedTransaction,
|
|
35
|
-
feePayer
|
|
36
|
-
};
|
|
23
|
+
return unsignedTransaction;
|
|
37
24
|
} else {
|
|
38
|
-
|
|
39
|
-
...transaction,
|
|
40
|
-
feePayer
|
|
41
|
-
};
|
|
25
|
+
return transaction;
|
|
42
26
|
}
|
|
43
|
-
Object.freeze(out);
|
|
44
|
-
return out;
|
|
45
27
|
}
|
|
46
28
|
|
|
47
|
-
// src/
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
29
|
+
// src/blockhash.ts
|
|
30
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
31
|
+
try {
|
|
32
|
+
if (
|
|
33
|
+
// Lowest value (32 bytes of zeroes)
|
|
34
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
35
|
+
putativeBlockhash.length > 44
|
|
36
|
+
) {
|
|
37
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
38
|
+
}
|
|
39
|
+
const bytes = umiSerializers.base58.serialize(putativeBlockhash);
|
|
40
|
+
const numBytes = bytes.byteLength;
|
|
41
|
+
if (numBytes !== 32) {
|
|
42
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
43
|
+
}
|
|
44
|
+
} catch (e) {
|
|
45
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
46
|
+
cause: e
|
|
47
|
+
});
|
|
65
48
|
}
|
|
66
|
-
return out;
|
|
67
49
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
51
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
52
|
+
return transaction;
|
|
53
|
+
}
|
|
54
|
+
const out = {
|
|
55
|
+
...getUnsignedTransaction(transaction),
|
|
56
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
57
|
+
};
|
|
71
58
|
Object.freeze(out);
|
|
72
59
|
return out;
|
|
73
60
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
|
|
62
|
+
// src/create-transaction.ts
|
|
63
|
+
function createTransaction({
|
|
64
|
+
version
|
|
65
|
+
}) {
|
|
66
|
+
const out = {
|
|
67
|
+
instructions: [],
|
|
68
|
+
version
|
|
69
|
+
};
|
|
77
70
|
Object.freeze(out);
|
|
78
71
|
return out;
|
|
79
72
|
}
|
|
@@ -100,6 +93,113 @@ function isWritableRole(role) {
|
|
|
100
93
|
function mergeRoles(roleA, roleB) {
|
|
101
94
|
return roleA | roleB;
|
|
102
95
|
}
|
|
96
|
+
|
|
97
|
+
// src/durable-nonce.ts
|
|
98
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
99
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
100
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
101
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
102
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
106
|
+
return {
|
|
107
|
+
accounts: [
|
|
108
|
+
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
109
|
+
{
|
|
110
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
111
|
+
role: AccountRole.READONLY
|
|
112
|
+
},
|
|
113
|
+
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
114
|
+
],
|
|
115
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
116
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
120
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
121
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
122
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
123
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
124
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
125
|
+
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
126
|
+
}
|
|
127
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
128
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
129
|
+
}
|
|
130
|
+
function isDurableNonceTransaction(transaction) {
|
|
131
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
132
|
+
}
|
|
133
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
134
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
135
|
+
}
|
|
136
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
137
|
+
nonce,
|
|
138
|
+
nonceAccountAddress,
|
|
139
|
+
nonceAuthorityAddress
|
|
140
|
+
}, transaction) {
|
|
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
|
+
];
|
|
161
|
+
}
|
|
162
|
+
const out = {
|
|
163
|
+
...getUnsignedTransaction(transaction),
|
|
164
|
+
instructions: newInstructions,
|
|
165
|
+
lifetimeConstraint: {
|
|
166
|
+
nonce
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
Object.freeze(out);
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/fee-payer.ts
|
|
174
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
175
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
176
|
+
return transaction;
|
|
177
|
+
}
|
|
178
|
+
const out = {
|
|
179
|
+
...getUnsignedTransaction(transaction),
|
|
180
|
+
feePayer
|
|
181
|
+
};
|
|
182
|
+
Object.freeze(out);
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/instructions.ts
|
|
187
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
188
|
+
const out = {
|
|
189
|
+
...getUnsignedTransaction(transaction),
|
|
190
|
+
instructions: [...transaction.instructions, instruction]
|
|
191
|
+
};
|
|
192
|
+
Object.freeze(out);
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
196
|
+
const out = {
|
|
197
|
+
...getUnsignedTransaction(transaction),
|
|
198
|
+
instructions: [instruction, ...transaction.instructions]
|
|
199
|
+
};
|
|
200
|
+
Object.freeze(out);
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
103
203
|
function upsert(addressMap, address, update) {
|
|
104
204
|
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
|
|
105
205
|
}
|
|
@@ -152,7 +252,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
152
252
|
const shouldReplaceEntry = (
|
|
153
253
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
154
254
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
155
|
-
(addressComparator || (addressComparator =
|
|
255
|
+
(addressComparator || (addressComparator = addresses.getAddressComparator()))(
|
|
156
256
|
accountMeta.lookupTableAddress,
|
|
157
257
|
entry.lookupTableAddress
|
|
158
258
|
) < 0
|
|
@@ -258,7 +358,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
258
358
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
259
359
|
return leftIsWritable ? -1 : 1;
|
|
260
360
|
}
|
|
261
|
-
addressComparator || (addressComparator =
|
|
361
|
+
addressComparator || (addressComparator = addresses.getAddressComparator());
|
|
262
362
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
263
363
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
264
364
|
} else {
|
|
@@ -287,7 +387,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
287
387
|
entry.readableIndices.push(account.addressIndex);
|
|
288
388
|
}
|
|
289
389
|
}
|
|
290
|
-
return Object.keys(index).sort(
|
|
390
|
+
return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
|
|
291
391
|
lookupTableAddress,
|
|
292
392
|
...index[lookupTableAddress]
|
|
293
393
|
}));
|
|
@@ -366,151 +466,317 @@ function compileMessage(transaction) {
|
|
|
366
466
|
version: transaction.version
|
|
367
467
|
};
|
|
368
468
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
469
|
+
|
|
470
|
+
// src/compile-transaction.ts
|
|
471
|
+
function getCompiledTransaction(transaction) {
|
|
472
|
+
const compiledMessage = compileMessage(transaction);
|
|
473
|
+
let signatures;
|
|
474
|
+
if ("signatures" in transaction) {
|
|
475
|
+
signatures = [];
|
|
476
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
477
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
compiledMessage,
|
|
484
|
+
signatures
|
|
485
|
+
};
|
|
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
|
+
addresses.assertIsAddress(nonceAccountAddress);
|
|
546
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
547
|
+
addresses.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 functional.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
|
|
402
595
|
);
|
|
403
596
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
597
|
+
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
598
|
+
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
599
|
+
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
600
|
+
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";
|
|
601
|
+
var memoizedAddressTableLookupEncoder;
|
|
602
|
+
function getAddressTableLookupEncoder() {
|
|
603
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
604
|
+
memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder(
|
|
407
605
|
[
|
|
408
|
-
"
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
606
|
+
["lookupTableAddress", addresses.getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
607
|
+
[
|
|
608
|
+
"writableIndices",
|
|
609
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
610
|
+
description: writableIndicesDescription,
|
|
611
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
612
|
+
})
|
|
613
|
+
],
|
|
614
|
+
[
|
|
615
|
+
"readableIndices",
|
|
616
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
617
|
+
description: readableIndicesDescription,
|
|
618
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
619
|
+
})
|
|
620
|
+
]
|
|
414
621
|
],
|
|
622
|
+
{ description: addressTableLookupDescription }
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
return memoizedAddressTableLookupEncoder;
|
|
626
|
+
}
|
|
627
|
+
var memoizedAddressTableLookupDecoder;
|
|
628
|
+
function getAddressTableLookupDecoder() {
|
|
629
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
630
|
+
memoizedAddressTableLookupDecoder = codecsDataStructures.getStructDecoder(
|
|
415
631
|
[
|
|
416
|
-
"
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
632
|
+
["lookupTableAddress", addresses.getAddressDecoder({ description: lookupTableAddressDescription })],
|
|
633
|
+
[
|
|
634
|
+
"writableIndices",
|
|
635
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
|
|
636
|
+
description: writableIndicesDescription,
|
|
637
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
638
|
+
})
|
|
639
|
+
],
|
|
640
|
+
[
|
|
641
|
+
"readableIndices",
|
|
642
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
|
|
643
|
+
description: readableIndicesDescription,
|
|
644
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
645
|
+
})
|
|
646
|
+
]
|
|
422
647
|
],
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
648
|
+
{ description: addressTableLookupDescription }
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
return memoizedAddressTableLookupDecoder;
|
|
652
|
+
}
|
|
653
|
+
var memoizedU8Encoder;
|
|
654
|
+
function getMemoizedU8Encoder() {
|
|
655
|
+
if (!memoizedU8Encoder)
|
|
656
|
+
memoizedU8Encoder = codecsNumbers.getU8Encoder();
|
|
657
|
+
return memoizedU8Encoder;
|
|
658
|
+
}
|
|
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 = codecsNumbers.getU8Decoder();
|
|
670
|
+
return memoizedU8Decoder;
|
|
671
|
+
}
|
|
672
|
+
function getMemoizedU8DecoderDescription(description) {
|
|
673
|
+
const decoder = getMemoizedU8Decoder();
|
|
674
|
+
return {
|
|
675
|
+
...decoder,
|
|
676
|
+
description: description ?? decoder.description
|
|
677
|
+
};
|
|
678
|
+
}
|
|
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;
|
|
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;
|
|
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;
|
|
682
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
683
|
+
function getMessageHeaderEncoder() {
|
|
684
|
+
return codecsDataStructures.getStructEncoder(
|
|
685
|
+
[
|
|
686
|
+
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
687
|
+
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
688
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
431
689
|
],
|
|
432
|
-
|
|
433
|
-
description:
|
|
434
|
-
}
|
|
690
|
+
{
|
|
691
|
+
description: messageHeaderDescription
|
|
692
|
+
}
|
|
435
693
|
);
|
|
436
694
|
}
|
|
437
|
-
function
|
|
438
|
-
return
|
|
439
|
-
|
|
440
|
-
[
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
)
|
|
447
|
-
],
|
|
448
|
-
[
|
|
449
|
-
"addressIndices",
|
|
450
|
-
umiSerializers.array(
|
|
451
|
-
umiSerializers.u8({
|
|
452
|
-
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
453
|
-
}),
|
|
454
|
-
{
|
|
455
|
-
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" : "",
|
|
456
|
-
size: umiSerializers.shortU16()
|
|
457
|
-
}
|
|
458
|
-
)
|
|
459
|
-
],
|
|
460
|
-
[
|
|
461
|
-
"data",
|
|
462
|
-
umiSerializers.bytes({
|
|
463
|
-
description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
|
|
464
|
-
size: umiSerializers.shortU16()
|
|
465
|
-
})
|
|
466
|
-
]
|
|
467
|
-
]),
|
|
468
|
-
(value) => {
|
|
469
|
-
if (value.addressIndices !== void 0 && value.data !== void 0) {
|
|
470
|
-
return value;
|
|
471
|
-
}
|
|
472
|
-
return {
|
|
473
|
-
...value,
|
|
474
|
-
addressIndices: value.addressIndices ?? [],
|
|
475
|
-
data: value.data ?? new Uint8Array(0)
|
|
476
|
-
};
|
|
477
|
-
},
|
|
478
|
-
(value) => {
|
|
479
|
-
if (value.addressIndices.length && value.data.byteLength) {
|
|
480
|
-
return value;
|
|
481
|
-
}
|
|
482
|
-
const { addressIndices, data, ...rest } = value;
|
|
483
|
-
return {
|
|
484
|
-
...rest,
|
|
485
|
-
...addressIndices.length ? { addressIndices } : null,
|
|
486
|
-
...data.byteLength ? { data } : null
|
|
487
|
-
};
|
|
695
|
+
function getMessageHeaderDecoder() {
|
|
696
|
+
return codecsDataStructures.getStructDecoder(
|
|
697
|
+
[
|
|
698
|
+
["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
|
|
699
|
+
["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
|
|
700
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
701
|
+
],
|
|
702
|
+
{
|
|
703
|
+
description: messageHeaderDescription
|
|
488
704
|
}
|
|
489
705
|
);
|
|
490
706
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
)
|
|
707
|
+
var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
|
|
708
|
+
var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
|
|
709
|
+
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";
|
|
710
|
+
var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
|
|
711
|
+
var memoizedGetInstructionEncoder;
|
|
712
|
+
function getInstructionEncoder() {
|
|
713
|
+
if (!memoizedGetInstructionEncoder) {
|
|
714
|
+
memoizedGetInstructionEncoder = codecsCore.mapEncoder(
|
|
715
|
+
codecsDataStructures.getStructEncoder([
|
|
716
|
+
["programAddressIndex", codecsNumbers.getU8Encoder({ description: programAddressIndexDescription })],
|
|
717
|
+
[
|
|
718
|
+
"accountIndices",
|
|
719
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder({ description: accountIndexDescription }), {
|
|
720
|
+
description: accountIndicesDescription,
|
|
721
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
722
|
+
})
|
|
723
|
+
],
|
|
724
|
+
["data", codecsDataStructures.getBytesEncoder({ description: dataDescription, size: codecsNumbers.getShortU16Encoder() })]
|
|
725
|
+
]),
|
|
726
|
+
// Convert an instruction to have all fields defined
|
|
727
|
+
(instruction) => {
|
|
728
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
729
|
+
return instruction;
|
|
730
|
+
}
|
|
731
|
+
return {
|
|
732
|
+
...instruction,
|
|
733
|
+
accountIndices: instruction.accountIndices ?? [],
|
|
734
|
+
data: instruction.data ?? new Uint8Array(0)
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
return memoizedGetInstructionEncoder;
|
|
498
740
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
741
|
+
var memoizedGetInstructionDecoder;
|
|
742
|
+
function getInstructionDecoder() {
|
|
743
|
+
if (!memoizedGetInstructionDecoder) {
|
|
744
|
+
memoizedGetInstructionDecoder = codecsCore.mapDecoder(
|
|
745
|
+
codecsDataStructures.getStructDecoder([
|
|
746
|
+
["programAddressIndex", codecsNumbers.getU8Decoder({ description: programAddressIndexDescription })],
|
|
747
|
+
[
|
|
748
|
+
"accountIndices",
|
|
749
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder({ description: accountIndexDescription }), {
|
|
750
|
+
description: accountIndicesDescription,
|
|
751
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
752
|
+
})
|
|
753
|
+
],
|
|
754
|
+
["data", codecsDataStructures.getBytesDecoder({ description: dataDescription, size: codecsNumbers.getShortU16Decoder() })]
|
|
755
|
+
]),
|
|
756
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
757
|
+
(instruction) => {
|
|
758
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
759
|
+
return instruction;
|
|
760
|
+
}
|
|
761
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
762
|
+
return {
|
|
763
|
+
...rest,
|
|
764
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
765
|
+
...data.byteLength ? { data } : null
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
return memoizedGetInstructionDecoder;
|
|
503
771
|
}
|
|
504
|
-
|
|
505
|
-
// src/serializers/transaction-version.ts
|
|
506
772
|
var VERSION_FLAG_MASK = 128;
|
|
507
773
|
var BASE_CONFIG = {
|
|
508
774
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
509
775
|
fixedSize: null,
|
|
510
776
|
maxSize: 1
|
|
511
777
|
};
|
|
512
|
-
function
|
|
513
|
-
const firstByte =
|
|
778
|
+
function decode(bytes, offset = 0) {
|
|
779
|
+
const firstByte = bytes[offset];
|
|
514
780
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
515
781
|
return ["legacy", offset];
|
|
516
782
|
} else {
|
|
@@ -518,7 +784,7 @@ function deserialize(bytes3, offset = 0) {
|
|
|
518
784
|
return [version, offset + 1];
|
|
519
785
|
}
|
|
520
786
|
}
|
|
521
|
-
function
|
|
787
|
+
function encode(value) {
|
|
522
788
|
if (value === "legacy") {
|
|
523
789
|
return new Uint8Array();
|
|
524
790
|
}
|
|
@@ -527,99 +793,251 @@ function serialize(value) {
|
|
|
527
793
|
}
|
|
528
794
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
529
795
|
}
|
|
530
|
-
function
|
|
796
|
+
function getTransactionVersionDecoder() {
|
|
797
|
+
return {
|
|
798
|
+
...BASE_CONFIG,
|
|
799
|
+
decode
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
function getTransactionVersionEncoder() {
|
|
531
803
|
return {
|
|
532
804
|
...BASE_CONFIG,
|
|
533
|
-
|
|
534
|
-
serialize
|
|
805
|
+
encode
|
|
535
806
|
};
|
|
536
807
|
}
|
|
537
808
|
|
|
538
809
|
// src/serializers/message.ts
|
|
539
|
-
var
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
(value)
|
|
554
|
-
|
|
555
|
-
return value;
|
|
556
|
-
}
|
|
557
|
-
return {
|
|
558
|
-
...value,
|
|
559
|
-
addressTableLookups: value.addressTableLookups ?? []
|
|
560
|
-
};
|
|
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 codecsDataStructures.getStructEncoder(getPreludeStructEncoderTuple());
|
|
816
|
+
}
|
|
817
|
+
function getCompiledMessageVersionedEncoder() {
|
|
818
|
+
return codecsCore.mapEncoder(
|
|
819
|
+
codecsDataStructures.getStructEncoder([
|
|
820
|
+
...getPreludeStructEncoderTuple(),
|
|
821
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
822
|
+
]),
|
|
823
|
+
(value) => {
|
|
824
|
+
if (value.version === "legacy") {
|
|
825
|
+
return value;
|
|
561
826
|
}
|
|
562
|
-
|
|
563
|
-
|
|
827
|
+
return {
|
|
828
|
+
...value,
|
|
829
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
);
|
|
564
833
|
}
|
|
565
|
-
function
|
|
834
|
+
function getPreludeStructEncoderTuple() {
|
|
566
835
|
return [
|
|
567
|
-
["version",
|
|
568
|
-
["header",
|
|
836
|
+
["version", getTransactionVersionEncoder()],
|
|
837
|
+
["header", getMessageHeaderEncoder()],
|
|
569
838
|
[
|
|
570
839
|
"staticAccounts",
|
|
571
|
-
|
|
572
|
-
description:
|
|
573
|
-
size:
|
|
840
|
+
codecsDataStructures.getArrayEncoder(addresses.getAddressEncoder(), {
|
|
841
|
+
description: staticAccountsDescription,
|
|
842
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
574
843
|
})
|
|
575
844
|
],
|
|
576
845
|
[
|
|
577
846
|
"lifetimeToken",
|
|
578
|
-
|
|
579
|
-
description:
|
|
580
|
-
encoding:
|
|
847
|
+
codecsStrings.getStringEncoder({
|
|
848
|
+
description: lifetimeTokenDescription,
|
|
849
|
+
encoding: codecsStrings.getBase58Encoder(),
|
|
581
850
|
size: 32
|
|
582
851
|
})
|
|
583
852
|
],
|
|
584
853
|
[
|
|
585
854
|
"instructions",
|
|
586
|
-
|
|
587
|
-
description:
|
|
588
|
-
size:
|
|
855
|
+
codecsDataStructures.getArrayEncoder(getInstructionEncoder(), {
|
|
856
|
+
description: instructionsDescription,
|
|
857
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
589
858
|
})
|
|
590
859
|
]
|
|
591
860
|
];
|
|
592
861
|
}
|
|
593
|
-
function
|
|
594
|
-
return
|
|
595
|
-
|
|
596
|
-
|
|
862
|
+
function getPreludeStructDecoderTuple() {
|
|
863
|
+
return [
|
|
864
|
+
["version", getTransactionVersionDecoder()],
|
|
865
|
+
["header", getMessageHeaderDecoder()],
|
|
866
|
+
[
|
|
867
|
+
"staticAccounts",
|
|
868
|
+
codecsDataStructures.getArrayDecoder(addresses.getAddressDecoder(), {
|
|
869
|
+
description: staticAccountsDescription,
|
|
870
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
871
|
+
})
|
|
872
|
+
],
|
|
873
|
+
[
|
|
874
|
+
"lifetimeToken",
|
|
875
|
+
codecsStrings.getStringDecoder({
|
|
876
|
+
description: lifetimeTokenDescription,
|
|
877
|
+
encoding: codecsStrings.getBase58Decoder(),
|
|
878
|
+
size: 32
|
|
879
|
+
})
|
|
880
|
+
],
|
|
881
|
+
[
|
|
882
|
+
"instructions",
|
|
883
|
+
codecsDataStructures.getArrayDecoder(getInstructionDecoder(), {
|
|
884
|
+
description: instructionsDescription,
|
|
885
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
886
|
+
})
|
|
887
|
+
],
|
|
888
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
889
|
+
];
|
|
890
|
+
}
|
|
891
|
+
function getAddressTableLookupArrayEncoder() {
|
|
892
|
+
return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
893
|
+
description: addressTableLookupsDescription,
|
|
894
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
function getAddressTableLookupArrayDecoder() {
|
|
898
|
+
return codecsDataStructures.getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
899
|
+
description: addressTableLookupsDescription,
|
|
900
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
597
901
|
});
|
|
598
902
|
}
|
|
903
|
+
var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
|
|
599
904
|
function getCompiledMessageEncoder() {
|
|
600
905
|
return {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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
|
|
604
916
|
};
|
|
605
917
|
}
|
|
918
|
+
function getCompiledMessageDecoder() {
|
|
919
|
+
return codecsCore.mapDecoder(
|
|
920
|
+
codecsDataStructures.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
|
+
}
|
|
606
931
|
|
|
607
|
-
// src/
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
return
|
|
932
|
+
// src/serializers/transaction.ts
|
|
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 codecsDataStructures.getStructEncoder(
|
|
937
|
+
[
|
|
938
|
+
[
|
|
939
|
+
"signatures",
|
|
940
|
+
codecsDataStructures.getArrayEncoder(codecsDataStructures.getBytesEncoder({ size: 64 }), {
|
|
941
|
+
description: signaturesDescription,
|
|
942
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
943
|
+
})
|
|
944
|
+
],
|
|
945
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
946
|
+
],
|
|
947
|
+
{
|
|
948
|
+
description: transactionDescription
|
|
949
|
+
}
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
function getSignatureDecoder() {
|
|
953
|
+
return codecsCore.mapDecoder(codecsDataStructures.getBytesDecoder({ size: 64 }), (bytes) => bytes);
|
|
954
|
+
}
|
|
955
|
+
function getCompiledTransactionDecoder() {
|
|
956
|
+
return codecsDataStructures.getStructDecoder(
|
|
957
|
+
[
|
|
958
|
+
[
|
|
959
|
+
"signatures",
|
|
960
|
+
codecsDataStructures.getArrayDecoder(getSignatureDecoder(), {
|
|
961
|
+
description: signaturesDescription,
|
|
962
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
963
|
+
})
|
|
964
|
+
],
|
|
965
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
966
|
+
],
|
|
967
|
+
{
|
|
968
|
+
description: transactionDescription
|
|
969
|
+
}
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
function getTransactionEncoder() {
|
|
973
|
+
return codecsCore.mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
974
|
+
}
|
|
975
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
976
|
+
return codecsCore.mapDecoder(
|
|
977
|
+
getCompiledTransactionDecoder(),
|
|
978
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
979
|
+
);
|
|
612
980
|
}
|
|
613
|
-
|
|
981
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
982
|
+
return codecsCore.combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
983
|
+
}
|
|
984
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
985
|
+
try {
|
|
986
|
+
if (
|
|
987
|
+
// Lowest value (64 bytes of zeroes)
|
|
988
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
989
|
+
putativeTransactionSignature.length > 88
|
|
990
|
+
) {
|
|
991
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
992
|
+
}
|
|
993
|
+
const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
994
|
+
const numBytes = bytes.byteLength;
|
|
995
|
+
if (numBytes !== 64) {
|
|
996
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
997
|
+
}
|
|
998
|
+
} catch (e) {
|
|
999
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1000
|
+
cause: e
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
1005
|
+
if (
|
|
1006
|
+
// Lowest value (64 bytes of zeroes)
|
|
1007
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1008
|
+
putativeTransactionSignature.length > 88
|
|
1009
|
+
) {
|
|
1010
|
+
return false;
|
|
1011
|
+
}
|
|
1012
|
+
const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
1013
|
+
const numBytes = bytes.byteLength;
|
|
1014
|
+
if (numBytes !== 64) {
|
|
1015
|
+
return false;
|
|
1016
|
+
}
|
|
1017
|
+
return true;
|
|
1018
|
+
}
|
|
1019
|
+
function getSignatureFromTransaction(transaction) {
|
|
1020
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1021
|
+
if (!signatureBytes) {
|
|
1022
|
+
throw new Error(
|
|
1023
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
const transactionSignature2 = umiSerializers.base58.deserialize(signatureBytes)[0];
|
|
1027
|
+
return transactionSignature2;
|
|
1028
|
+
}
|
|
1029
|
+
async function signTransaction(keyPairs, transaction) {
|
|
614
1030
|
const compiledMessage = compileMessage(transaction);
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
1031
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1032
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
1033
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
1034
|
+
keyPairs.map(
|
|
1035
|
+
(keyPair) => Promise.all([addresses.getAddressFromPublicKey(keyPair.publicKey), keys.signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
1036
|
+
)
|
|
1037
|
+
);
|
|
1038
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
1039
|
+
nextSignatures[signerPublicKey] = signature;
|
|
1040
|
+
}
|
|
623
1041
|
const out = {
|
|
624
1042
|
...transaction,
|
|
625
1043
|
signatures: nextSignatures
|
|
@@ -627,65 +1045,46 @@ async function signTransaction(keyPair, transaction) {
|
|
|
627
1045
|
Object.freeze(out);
|
|
628
1046
|
return out;
|
|
629
1047
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const compiledMessage = compileMessage(transaction);
|
|
634
|
-
let signatures;
|
|
635
|
-
if ("signatures" in transaction) {
|
|
636
|
-
signatures = [];
|
|
637
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
638
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
639
|
-
}
|
|
640
|
-
} else {
|
|
641
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
642
|
-
}
|
|
643
|
-
return {
|
|
644
|
-
compiledMessage,
|
|
645
|
-
signatures
|
|
646
|
-
};
|
|
1048
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
1049
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
1050
|
+
return putativeTransactionSignature;
|
|
647
1051
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
const compiledTransaction = getCompiledTransaction(transaction);
|
|
657
|
-
return umiSerializers.struct([
|
|
658
|
-
[
|
|
659
|
-
"signatures",
|
|
660
|
-
umiSerializers.array(umiSerializers.bytes({ size: 64 }), {
|
|
661
|
-
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
|
|
662
|
-
size: umiSerializers.shortU16()
|
|
663
|
-
})
|
|
664
|
-
],
|
|
665
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
666
|
-
]).serialize(compiledTransaction);
|
|
667
|
-
}
|
|
668
|
-
function getTransactionEncoder() {
|
|
669
|
-
return {
|
|
670
|
-
...BASE_CONFIG3,
|
|
671
|
-
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
672
|
-
serialize: serialize3
|
|
673
|
-
};
|
|
1052
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
1053
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
1054
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1055
|
+
requiredSigners.forEach((address) => {
|
|
1056
|
+
if (!transaction.signatures[address]) {
|
|
1057
|
+
throw new Error(`Transaction is missing signature for address \`${address}\``);
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
674
1060
|
}
|
|
675
1061
|
|
|
676
1062
|
// src/wire-transaction.ts
|
|
677
1063
|
function getBase64EncodedWireTransaction(transaction) {
|
|
678
|
-
const wireTransactionBytes = getTransactionEncoder().
|
|
1064
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
679
1065
|
{
|
|
680
1066
|
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
681
1067
|
}
|
|
682
1068
|
}
|
|
683
1069
|
|
|
684
1070
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1071
|
+
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1072
|
+
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1073
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
1074
|
+
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
685
1075
|
exports.createTransaction = createTransaction;
|
|
686
1076
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1077
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1078
|
+
exports.getTransactionCodec = getTransactionCodec;
|
|
1079
|
+
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1080
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1081
|
+
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1082
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
687
1083
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
688
1084
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1085
|
+
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1086
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
689
1087
|
exports.signTransaction = signTransaction;
|
|
1088
|
+
exports.transactionSignature = transactionSignature;
|
|
690
1089
|
//# sourceMappingURL=out.js.map
|
|
691
1090
|
//# sourceMappingURL=index.browser.cjs.map
|