@solana/transactions 2.0.0-experimental.1584fe6 → 2.0.0-experimental.19791fe
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/dist/index.browser.cjs +368 -324
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +363 -327
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +842 -754
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +363 -327
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +368 -324
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +363 -325
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +17 -9
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +1 -1
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts +1 -1
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
- package/dist/types/compile-header.d.ts.map +1 -0
- package/dist/types/compile-instructions.d.ts +1 -1
- package/dist/types/compile-instructions.d.ts.map +1 -0
- package/dist/types/compile-lifetime-token.d.ts.map +1 -0
- package/dist/types/compile-static-accounts.d.ts +1 -1
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +15 -4
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +3 -2
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instructions.d.ts.map +1 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts +5 -3
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts +4 -2
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts +4 -4
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts +5 -4
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +13 -6
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts +4 -0
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts +2 -2
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +22 -18
- package/dist/types/serializers/unimplemented.d.ts +0 -3
package/dist/index.browser.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
import { base58
|
|
2
|
-
import {
|
|
1
|
+
import { base58 } from '@metaplex-foundation/umi-serializers';
|
|
2
|
+
import { mapEncoder } from '@solana/codecs-core';
|
|
3
|
+
import { getStructEncoder, getArrayEncoder, getBytesEncoder } from '@solana/codecs-data-structures';
|
|
4
|
+
import { getShortU16Encoder, getU8Encoder } from '@solana/codecs-numbers';
|
|
5
|
+
import { getAddressFromPublicKey, getAddressComparator, getAddressEncoder } from '@solana/addresses';
|
|
6
|
+
import { getStringEncoder, getBase58Encoder } from '@solana/codecs-strings';
|
|
7
|
+
import { signBytes } from '@solana/keys';
|
|
3
8
|
|
|
4
9
|
// ../build-scripts/env-shim.ts
|
|
5
10
|
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
11
|
+
|
|
12
|
+
// src/unsigned-transaction.ts
|
|
13
|
+
function getUnsignedTransaction(transaction) {
|
|
14
|
+
if ("signatures" in transaction) {
|
|
15
|
+
const {
|
|
16
|
+
signatures: _,
|
|
17
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
18
|
+
...unsignedTransaction
|
|
19
|
+
} = transaction;
|
|
20
|
+
return unsignedTransaction;
|
|
21
|
+
} else {
|
|
22
|
+
return transaction;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/blockhash.ts
|
|
6
27
|
function assertIsBlockhash(putativeBlockhash) {
|
|
7
28
|
try {
|
|
8
29
|
if (
|
|
@@ -12,8 +33,8 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
12
33
|
) {
|
|
13
34
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
14
35
|
}
|
|
15
|
-
const
|
|
16
|
-
const numBytes =
|
|
36
|
+
const bytes = base58.serialize(putativeBlockhash);
|
|
37
|
+
const numBytes = bytes.byteLength;
|
|
17
38
|
if (numBytes !== 32) {
|
|
18
39
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
19
40
|
}
|
|
@@ -27,23 +48,10 @@ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, trans
|
|
|
27
48
|
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
28
49
|
return transaction;
|
|
29
50
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
35
|
-
...unsignedTransaction
|
|
36
|
-
} = transaction;
|
|
37
|
-
out = {
|
|
38
|
-
...unsignedTransaction,
|
|
39
|
-
lifetimeConstraint: blockhashLifetimeConstraint
|
|
40
|
-
};
|
|
41
|
-
} else {
|
|
42
|
-
out = {
|
|
43
|
-
...transaction,
|
|
44
|
-
lifetimeConstraint: blockhashLifetimeConstraint
|
|
45
|
-
};
|
|
46
|
-
}
|
|
51
|
+
const out = {
|
|
52
|
+
...getUnsignedTransaction(transaction),
|
|
53
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
54
|
+
};
|
|
47
55
|
Object.freeze(out);
|
|
48
56
|
return out;
|
|
49
57
|
}
|
|
@@ -60,66 +68,6 @@ function createTransaction({
|
|
|
60
68
|
return out;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
|
-
// src/fee-payer.ts
|
|
64
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
65
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
66
|
-
return transaction;
|
|
67
|
-
}
|
|
68
|
-
let out;
|
|
69
|
-
if ("signatures" in transaction) {
|
|
70
|
-
const {
|
|
71
|
-
signatures: _,
|
|
72
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
73
|
-
...unsignedTransaction
|
|
74
|
-
} = transaction;
|
|
75
|
-
out = {
|
|
76
|
-
...unsignedTransaction,
|
|
77
|
-
feePayer
|
|
78
|
-
};
|
|
79
|
-
} else {
|
|
80
|
-
out = {
|
|
81
|
-
...transaction,
|
|
82
|
-
feePayer
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
Object.freeze(out);
|
|
86
|
-
return out;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// src/instructions.ts
|
|
90
|
-
function replaceInstructions(transaction, nextInstructions) {
|
|
91
|
-
let out;
|
|
92
|
-
if ("signatures" in transaction) {
|
|
93
|
-
const {
|
|
94
|
-
signatures: _,
|
|
95
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
96
|
-
...unsignedTransaction
|
|
97
|
-
} = transaction;
|
|
98
|
-
out = {
|
|
99
|
-
...unsignedTransaction,
|
|
100
|
-
instructions: nextInstructions
|
|
101
|
-
};
|
|
102
|
-
} else {
|
|
103
|
-
out = {
|
|
104
|
-
...transaction,
|
|
105
|
-
instructions: nextInstructions
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return out;
|
|
109
|
-
}
|
|
110
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
111
|
-
const nextInstructions = [...transaction.instructions, instruction];
|
|
112
|
-
const out = replaceInstructions(transaction, nextInstructions);
|
|
113
|
-
Object.freeze(out);
|
|
114
|
-
return out;
|
|
115
|
-
}
|
|
116
|
-
function prependTransactionInstruction(instruction, transaction) {
|
|
117
|
-
const nextInstructions = [instruction, ...transaction.instructions];
|
|
118
|
-
const out = replaceInstructions(transaction, nextInstructions);
|
|
119
|
-
Object.freeze(out);
|
|
120
|
-
return out;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
71
|
// ../instructions/dist/index.browser.js
|
|
124
72
|
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
125
73
|
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
@@ -142,6 +90,96 @@ function isWritableRole(role) {
|
|
|
142
90
|
function mergeRoles(roleA, roleB) {
|
|
143
91
|
return roleA | roleB;
|
|
144
92
|
}
|
|
93
|
+
|
|
94
|
+
// src/durable-nonce.ts
|
|
95
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
96
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
97
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
98
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
99
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
103
|
+
return {
|
|
104
|
+
accounts: [
|
|
105
|
+
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
106
|
+
{
|
|
107
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
108
|
+
role: AccountRole.READONLY
|
|
109
|
+
},
|
|
110
|
+
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
111
|
+
],
|
|
112
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
113
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
117
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
118
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
119
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
120
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
121
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
122
|
+
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
|
|
123
|
+
}
|
|
124
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
125
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
126
|
+
}
|
|
127
|
+
function isDurableNonceTransaction(transaction) {
|
|
128
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
129
|
+
}
|
|
130
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
131
|
+
nonce,
|
|
132
|
+
nonceAccountAddress,
|
|
133
|
+
nonceAuthorityAddress
|
|
134
|
+
}, transaction) {
|
|
135
|
+
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
136
|
+
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
137
|
+
return transaction;
|
|
138
|
+
}
|
|
139
|
+
const out = {
|
|
140
|
+
...getUnsignedTransaction(transaction),
|
|
141
|
+
instructions: [
|
|
142
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
143
|
+
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
144
|
+
],
|
|
145
|
+
lifetimeConstraint: {
|
|
146
|
+
nonce
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
Object.freeze(out);
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/fee-payer.ts
|
|
154
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
155
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
156
|
+
return transaction;
|
|
157
|
+
}
|
|
158
|
+
const out = {
|
|
159
|
+
...getUnsignedTransaction(transaction),
|
|
160
|
+
feePayer
|
|
161
|
+
};
|
|
162
|
+
Object.freeze(out);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/instructions.ts
|
|
167
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
168
|
+
const out = {
|
|
169
|
+
...getUnsignedTransaction(transaction),
|
|
170
|
+
instructions: [...transaction.instructions, instruction]
|
|
171
|
+
};
|
|
172
|
+
Object.freeze(out);
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
176
|
+
const out = {
|
|
177
|
+
...getUnsignedTransaction(transaction),
|
|
178
|
+
instructions: [instruction, ...transaction.instructions]
|
|
179
|
+
};
|
|
180
|
+
Object.freeze(out);
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
145
183
|
function upsert(addressMap, address, update) {
|
|
146
184
|
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
|
|
147
185
|
}
|
|
@@ -194,7 +232,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
194
232
|
const shouldReplaceEntry = (
|
|
195
233
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
196
234
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
197
|
-
(addressComparator || (addressComparator =
|
|
235
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
198
236
|
accountMeta.lookupTableAddress,
|
|
199
237
|
entry.lookupTableAddress
|
|
200
238
|
) < 0
|
|
@@ -300,7 +338,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
300
338
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
301
339
|
return leftIsWritable ? -1 : 1;
|
|
302
340
|
}
|
|
303
|
-
addressComparator || (addressComparator =
|
|
341
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
304
342
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
305
343
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
306
344
|
} else {
|
|
@@ -329,7 +367,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
329
367
|
entry.readableIndices.push(account.addressIndex);
|
|
330
368
|
}
|
|
331
369
|
}
|
|
332
|
-
return Object.keys(index).sort(
|
|
370
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
333
371
|
lookupTableAddress,
|
|
334
372
|
...index[lookupTableAddress]
|
|
335
373
|
}));
|
|
@@ -408,159 +446,124 @@ function compileMessage(transaction) {
|
|
|
408
446
|
version: transaction.version
|
|
409
447
|
};
|
|
410
448
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
449
|
+
|
|
450
|
+
// src/compile-transaction.ts
|
|
451
|
+
function getCompiledTransaction(transaction) {
|
|
452
|
+
const compiledMessage = compileMessage(transaction);
|
|
453
|
+
let signatures;
|
|
454
|
+
if ("signatures" in transaction) {
|
|
455
|
+
signatures = [];
|
|
456
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
457
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
compiledMessage,
|
|
464
|
+
signatures
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
468
|
+
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
469
|
+
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
470
|
+
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";
|
|
471
|
+
var memoizedAddressTableLookupEncoder;
|
|
472
|
+
function getAddressTableLookupEncoder() {
|
|
473
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
474
|
+
memoizedAddressTableLookupEncoder = getStructEncoder(
|
|
422
475
|
[
|
|
423
|
-
"
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
476
|
+
["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
477
|
+
[
|
|
478
|
+
"writableIndices",
|
|
479
|
+
getArrayEncoder(getU8Encoder(), {
|
|
480
|
+
description: writableIndicesDescription,
|
|
481
|
+
size: getShortU16Encoder()
|
|
482
|
+
})
|
|
483
|
+
],
|
|
484
|
+
[
|
|
485
|
+
"readableIndices",
|
|
486
|
+
getArrayEncoder(getU8Encoder(), {
|
|
487
|
+
description: readableIndicesDescription,
|
|
488
|
+
size: getShortU16Encoder()
|
|
489
|
+
})
|
|
490
|
+
]
|
|
430
491
|
],
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
492
|
+
{ description: addressTableLookupDescription }
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
return memoizedAddressTableLookupEncoder;
|
|
496
|
+
}
|
|
497
|
+
var memoizedU8Encoder;
|
|
498
|
+
function getMemoizedU8Encoder() {
|
|
499
|
+
if (!memoizedU8Encoder)
|
|
500
|
+
memoizedU8Encoder = getU8Encoder();
|
|
501
|
+
return memoizedU8Encoder;
|
|
502
|
+
}
|
|
503
|
+
function getMemoizedU8EncoderDescription(description) {
|
|
504
|
+
const encoder = getMemoizedU8Encoder();
|
|
505
|
+
return {
|
|
506
|
+
...encoder,
|
|
507
|
+
description: description ?? encoder.description
|
|
508
|
+
};
|
|
445
509
|
}
|
|
446
|
-
|
|
447
|
-
|
|
510
|
+
var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0;
|
|
511
|
+
var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0;
|
|
512
|
+
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
513
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
514
|
+
function getMessageHeaderEncoder() {
|
|
515
|
+
return getStructEncoder(
|
|
448
516
|
[
|
|
449
|
-
[
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
__DEV__ ? {
|
|
453
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
454
|
-
} : void 0
|
|
455
|
-
)
|
|
456
|
-
],
|
|
457
|
-
[
|
|
458
|
-
"numReadonlySignerAccounts",
|
|
459
|
-
u8(
|
|
460
|
-
__DEV__ ? {
|
|
461
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable"
|
|
462
|
-
} : void 0
|
|
463
|
-
)
|
|
464
|
-
],
|
|
465
|
-
[
|
|
466
|
-
"numReadonlyNonSignerAccounts",
|
|
467
|
-
u8(
|
|
468
|
-
__DEV__ ? {
|
|
469
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
470
|
-
} : void 0
|
|
471
|
-
)
|
|
472
|
-
]
|
|
517
|
+
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
518
|
+
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
519
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
473
520
|
],
|
|
474
|
-
|
|
475
|
-
description:
|
|
476
|
-
} : void 0
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
function getInstructionCodec() {
|
|
480
|
-
return mapSerializer(
|
|
481
|
-
struct([
|
|
482
|
-
[
|
|
483
|
-
"programAddressIndex",
|
|
484
|
-
u8(
|
|
485
|
-
__DEV__ ? {
|
|
486
|
-
description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
|
|
487
|
-
} : void 0
|
|
488
|
-
)
|
|
489
|
-
],
|
|
490
|
-
[
|
|
491
|
-
"addressIndices",
|
|
492
|
-
array(
|
|
493
|
-
u8({
|
|
494
|
-
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
495
|
-
}),
|
|
496
|
-
{
|
|
497
|
-
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" : "",
|
|
498
|
-
size: shortU16()
|
|
499
|
-
}
|
|
500
|
-
)
|
|
501
|
-
],
|
|
502
|
-
[
|
|
503
|
-
"data",
|
|
504
|
-
bytes({
|
|
505
|
-
description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
|
|
506
|
-
size: shortU16()
|
|
507
|
-
})
|
|
508
|
-
]
|
|
509
|
-
]),
|
|
510
|
-
(value) => {
|
|
511
|
-
if (value.addressIndices !== void 0 && value.data !== void 0) {
|
|
512
|
-
return value;
|
|
513
|
-
}
|
|
514
|
-
return {
|
|
515
|
-
...value,
|
|
516
|
-
addressIndices: value.addressIndices ?? [],
|
|
517
|
-
data: value.data ?? new Uint8Array(0)
|
|
518
|
-
};
|
|
519
|
-
},
|
|
520
|
-
(value) => {
|
|
521
|
-
if (value.addressIndices.length && value.data.byteLength) {
|
|
522
|
-
return value;
|
|
523
|
-
}
|
|
524
|
-
const { addressIndices, data, ...rest } = value;
|
|
525
|
-
return {
|
|
526
|
-
...rest,
|
|
527
|
-
...addressIndices.length ? { addressIndices } : null,
|
|
528
|
-
...data.byteLength ? { data } : null
|
|
529
|
-
};
|
|
521
|
+
{
|
|
522
|
+
description: messageHeaderDescription
|
|
530
523
|
}
|
|
531
524
|
);
|
|
532
525
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
)
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
526
|
+
var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
|
|
527
|
+
var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
|
|
528
|
+
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";
|
|
529
|
+
var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
|
|
530
|
+
var memoizedGetInstructionEncoder;
|
|
531
|
+
function getInstructionEncoder() {
|
|
532
|
+
if (!memoizedGetInstructionEncoder) {
|
|
533
|
+
memoizedGetInstructionEncoder = mapEncoder(
|
|
534
|
+
getStructEncoder([
|
|
535
|
+
["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
|
|
536
|
+
[
|
|
537
|
+
"accountIndices",
|
|
538
|
+
getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
|
|
539
|
+
description: accountIndicesDescription,
|
|
540
|
+
size: getShortU16Encoder()
|
|
541
|
+
})
|
|
542
|
+
],
|
|
543
|
+
["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
|
|
544
|
+
]),
|
|
545
|
+
// Convert an instruction to have all fields defined
|
|
546
|
+
(instruction) => {
|
|
547
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
548
|
+
return instruction;
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
...instruction,
|
|
552
|
+
accountIndices: instruction.accountIndices ?? [],
|
|
553
|
+
data: instruction.data ?? new Uint8Array(0)
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
return memoizedGetInstructionEncoder;
|
|
545
559
|
}
|
|
546
|
-
|
|
547
|
-
// src/serializers/transaction-version.ts
|
|
548
560
|
var VERSION_FLAG_MASK = 128;
|
|
549
561
|
var BASE_CONFIG = {
|
|
550
562
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
551
563
|
fixedSize: null,
|
|
552
564
|
maxSize: 1
|
|
553
565
|
};
|
|
554
|
-
function
|
|
555
|
-
const firstByte = bytes3[offset];
|
|
556
|
-
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
557
|
-
return ["legacy", offset];
|
|
558
|
-
} else {
|
|
559
|
-
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
560
|
-
return [version, offset + 1];
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
function serialize(value) {
|
|
566
|
+
function encode(value) {
|
|
564
567
|
if (value === "legacy") {
|
|
565
568
|
return new Uint8Array();
|
|
566
569
|
}
|
|
@@ -569,99 +572,175 @@ function serialize(value) {
|
|
|
569
572
|
}
|
|
570
573
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
571
574
|
}
|
|
572
|
-
function
|
|
575
|
+
function getTransactionVersionEncoder() {
|
|
573
576
|
return {
|
|
574
577
|
...BASE_CONFIG,
|
|
575
|
-
|
|
576
|
-
serialize
|
|
578
|
+
encode
|
|
577
579
|
};
|
|
578
580
|
}
|
|
579
581
|
|
|
580
582
|
// src/serializers/message.ts
|
|
581
|
-
var
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
(value)
|
|
596
|
-
|
|
597
|
-
return value;
|
|
598
|
-
}
|
|
599
|
-
return {
|
|
600
|
-
...value,
|
|
601
|
-
addressTableLookups: value.addressTableLookups ?? []
|
|
602
|
-
};
|
|
583
|
+
var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
|
|
584
|
+
var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
|
|
585
|
+
var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
|
|
586
|
+
var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
|
|
587
|
+
function getCompiledMessageLegacyEncoder() {
|
|
588
|
+
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
589
|
+
}
|
|
590
|
+
function getCompiledMessageVersionedEncoder() {
|
|
591
|
+
return mapEncoder(
|
|
592
|
+
getStructEncoder([
|
|
593
|
+
...getPreludeStructEncoderTuple(),
|
|
594
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
595
|
+
]),
|
|
596
|
+
(value) => {
|
|
597
|
+
if (value.version === "legacy") {
|
|
598
|
+
return value;
|
|
603
599
|
}
|
|
604
|
-
|
|
605
|
-
|
|
600
|
+
return {
|
|
601
|
+
...value,
|
|
602
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
);
|
|
606
606
|
}
|
|
607
|
-
function
|
|
607
|
+
function getPreludeStructEncoderTuple() {
|
|
608
608
|
return [
|
|
609
|
-
["version",
|
|
610
|
-
["header",
|
|
609
|
+
["version", getTransactionVersionEncoder()],
|
|
610
|
+
["header", getMessageHeaderEncoder()],
|
|
611
611
|
[
|
|
612
612
|
"staticAccounts",
|
|
613
|
-
|
|
614
|
-
description:
|
|
615
|
-
size:
|
|
613
|
+
getArrayEncoder(getAddressEncoder(), {
|
|
614
|
+
description: staticAccountsDescription,
|
|
615
|
+
size: getShortU16Encoder()
|
|
616
616
|
})
|
|
617
617
|
],
|
|
618
618
|
[
|
|
619
619
|
"lifetimeToken",
|
|
620
|
-
|
|
621
|
-
description:
|
|
622
|
-
encoding:
|
|
620
|
+
getStringEncoder({
|
|
621
|
+
description: lifetimeTokenDescription,
|
|
622
|
+
encoding: getBase58Encoder(),
|
|
623
623
|
size: 32
|
|
624
624
|
})
|
|
625
625
|
],
|
|
626
626
|
[
|
|
627
627
|
"instructions",
|
|
628
|
-
|
|
629
|
-
description:
|
|
630
|
-
size:
|
|
628
|
+
getArrayEncoder(getInstructionEncoder(), {
|
|
629
|
+
description: instructionsDescription,
|
|
630
|
+
size: getShortU16Encoder()
|
|
631
631
|
})
|
|
632
632
|
]
|
|
633
633
|
];
|
|
634
634
|
}
|
|
635
|
-
function
|
|
636
|
-
return
|
|
637
|
-
|
|
638
|
-
size:
|
|
635
|
+
function getAddressTableLookupArrayEncoder() {
|
|
636
|
+
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
637
|
+
description: addressTableLookupsDescription,
|
|
638
|
+
size: getShortU16Encoder()
|
|
639
639
|
});
|
|
640
640
|
}
|
|
641
|
+
var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
|
|
641
642
|
function getCompiledMessageEncoder() {
|
|
642
643
|
return {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
644
|
+
description: messageDescription,
|
|
645
|
+
encode: (compiledMessage) => {
|
|
646
|
+
if (compiledMessage.version === "legacy") {
|
|
647
|
+
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
|
|
648
|
+
} else {
|
|
649
|
+
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
fixedSize: null,
|
|
653
|
+
maxSize: null
|
|
646
654
|
};
|
|
647
655
|
}
|
|
648
656
|
|
|
649
|
-
// src/
|
|
657
|
+
// src/serializers/transaction.ts
|
|
658
|
+
var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
|
|
659
|
+
var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
|
|
660
|
+
function getCompiledTransactionEncoder() {
|
|
661
|
+
return getStructEncoder(
|
|
662
|
+
[
|
|
663
|
+
[
|
|
664
|
+
"signatures",
|
|
665
|
+
getArrayEncoder(getBytesEncoder({ size: 64 }), {
|
|
666
|
+
description: signaturesDescription,
|
|
667
|
+
size: getShortU16Encoder()
|
|
668
|
+
})
|
|
669
|
+
],
|
|
670
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
671
|
+
],
|
|
672
|
+
{
|
|
673
|
+
description: transactionDescription
|
|
674
|
+
}
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
function getTransactionEncoder() {
|
|
678
|
+
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
679
|
+
}
|
|
680
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
681
|
+
try {
|
|
682
|
+
if (
|
|
683
|
+
// Lowest value (64 bytes of zeroes)
|
|
684
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
685
|
+
putativeTransactionSignature.length > 88
|
|
686
|
+
) {
|
|
687
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
688
|
+
}
|
|
689
|
+
const bytes = base58.serialize(putativeTransactionSignature);
|
|
690
|
+
const numBytes = bytes.byteLength;
|
|
691
|
+
if (numBytes !== 64) {
|
|
692
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
693
|
+
}
|
|
694
|
+
} catch (e) {
|
|
695
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
696
|
+
cause: e
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
701
|
+
if (
|
|
702
|
+
// Lowest value (64 bytes of zeroes)
|
|
703
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
704
|
+
putativeTransactionSignature.length > 88
|
|
705
|
+
) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
const bytes = base58.serialize(putativeTransactionSignature);
|
|
709
|
+
const numBytes = bytes.byteLength;
|
|
710
|
+
if (numBytes !== 64) {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
return true;
|
|
714
|
+
}
|
|
650
715
|
async function getCompiledMessageSignature(message, secretKey) {
|
|
651
|
-
const wireMessageBytes = getCompiledMessageEncoder().
|
|
716
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(message);
|
|
652
717
|
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
653
718
|
return signature;
|
|
654
719
|
}
|
|
655
|
-
|
|
720
|
+
function getSignatureFromTransaction(transaction) {
|
|
721
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
722
|
+
if (!signatureBytes) {
|
|
723
|
+
throw new Error(
|
|
724
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
const transactionSignature2 = base58.deserialize(signatureBytes)[0];
|
|
728
|
+
return transactionSignature2;
|
|
729
|
+
}
|
|
730
|
+
async function signTransaction(keyPairs, transaction) {
|
|
656
731
|
const compiledMessage = compileMessage(transaction);
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
732
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
733
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
734
|
+
keyPairs.map(
|
|
735
|
+
(keyPair) => Promise.all([
|
|
736
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
737
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
738
|
+
])
|
|
739
|
+
)
|
|
740
|
+
);
|
|
741
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
742
|
+
nextSignatures[signerPublicKey] = signature;
|
|
743
|
+
}
|
|
665
744
|
const out = {
|
|
666
745
|
...transaction,
|
|
667
746
|
signatures: nextSignatures
|
|
@@ -669,60 +748,17 @@ async function signTransaction(keyPair, transaction) {
|
|
|
669
748
|
Object.freeze(out);
|
|
670
749
|
return out;
|
|
671
750
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const compiledMessage = compileMessage(transaction);
|
|
676
|
-
let signatures;
|
|
677
|
-
if ("signatures" in transaction) {
|
|
678
|
-
signatures = [];
|
|
679
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
680
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
681
|
-
}
|
|
682
|
-
} else {
|
|
683
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
684
|
-
}
|
|
685
|
-
return {
|
|
686
|
-
compiledMessage,
|
|
687
|
-
signatures
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
// src/serializers/transaction.ts
|
|
692
|
-
var BASE_CONFIG3 = {
|
|
693
|
-
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
694
|
-
fixedSize: null,
|
|
695
|
-
maxSize: null
|
|
696
|
-
};
|
|
697
|
-
function serialize3(transaction) {
|
|
698
|
-
const compiledTransaction = getCompiledTransaction(transaction);
|
|
699
|
-
return struct([
|
|
700
|
-
[
|
|
701
|
-
"signatures",
|
|
702
|
-
array(bytes({ size: 64 }), {
|
|
703
|
-
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
|
|
704
|
-
size: shortU16()
|
|
705
|
-
})
|
|
706
|
-
],
|
|
707
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
708
|
-
]).serialize(compiledTransaction);
|
|
709
|
-
}
|
|
710
|
-
function getTransactionEncoder() {
|
|
711
|
-
return {
|
|
712
|
-
...BASE_CONFIG3,
|
|
713
|
-
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
714
|
-
serialize: serialize3
|
|
715
|
-
};
|
|
751
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
752
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
753
|
+
return putativeTransactionSignature;
|
|
716
754
|
}
|
|
717
755
|
|
|
718
756
|
// src/wire-transaction.ts
|
|
719
757
|
function getBase64EncodedWireTransaction(transaction) {
|
|
720
|
-
const wireTransactionBytes = getTransactionEncoder().
|
|
758
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
721
759
|
{
|
|
722
760
|
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
723
761
|
}
|
|
724
762
|
}
|
|
725
763
|
|
|
726
|
-
export { appendTransactionInstruction, assertIsBlockhash, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, signTransaction };
|
|
727
|
-
//# sourceMappingURL=out.js.map
|
|
728
|
-
//# sourceMappingURL=index.browser.js.map
|
|
764
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isAdvanceNonceAccountInstruction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|