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