@solana/transactions 2.0.0-experimental.95bfd9f → 2.0.0-experimental.99a64e9
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 +308 -167
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +302 -169
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +784 -219
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +304 -169
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +308 -167
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +302 -169
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +16 -8
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/blockhash.d.ts +6 -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/durable-nonce.d.ts +20 -7
- package/dist/types/fee-payer.d.ts +3 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/signatures.d.ts +13 -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 +1 -1
- package/package.json +21 -18
- 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.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/LICENSE
CHANGED
package/dist/index.browser.cjs
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
|
+
var addresses = require('@solana/addresses');
|
|
5
|
+
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
6
|
+
var codecsNumbers = require('@solana/codecs-numbers');
|
|
7
|
+
var codecsCore = require('@solana/codecs-core');
|
|
4
8
|
var keys = require('@solana/keys');
|
|
5
9
|
|
|
6
10
|
// ../build-scripts/env-shim.ts
|
|
7
11
|
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
12
|
+
|
|
13
|
+
// src/unsigned-transaction.ts
|
|
14
|
+
function getUnsignedTransaction(transaction) {
|
|
15
|
+
if ("signatures" in transaction) {
|
|
16
|
+
const {
|
|
17
|
+
signatures: _,
|
|
18
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
19
|
+
...unsignedTransaction
|
|
20
|
+
} = transaction;
|
|
21
|
+
return unsignedTransaction;
|
|
22
|
+
} else {
|
|
23
|
+
return transaction;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/blockhash.ts
|
|
8
28
|
function assertIsBlockhash(putativeBlockhash) {
|
|
9
29
|
try {
|
|
10
30
|
if (
|
|
@@ -25,6 +45,17 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
25
45
|
});
|
|
26
46
|
}
|
|
27
47
|
}
|
|
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
|
+
};
|
|
56
|
+
Object.freeze(out);
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
28
59
|
|
|
29
60
|
// src/create-transaction.ts
|
|
30
61
|
function createTransaction({
|
|
@@ -38,66 +69,6 @@ function createTransaction({
|
|
|
38
69
|
return out;
|
|
39
70
|
}
|
|
40
71
|
|
|
41
|
-
// src/fee-payer.ts
|
|
42
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
43
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
44
|
-
return transaction;
|
|
45
|
-
}
|
|
46
|
-
let out;
|
|
47
|
-
if ("signatures" in transaction) {
|
|
48
|
-
const {
|
|
49
|
-
signatures: _,
|
|
50
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
51
|
-
...unsignedTransaction
|
|
52
|
-
} = transaction;
|
|
53
|
-
out = {
|
|
54
|
-
...unsignedTransaction,
|
|
55
|
-
feePayer
|
|
56
|
-
};
|
|
57
|
-
} else {
|
|
58
|
-
out = {
|
|
59
|
-
...transaction,
|
|
60
|
-
feePayer
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
Object.freeze(out);
|
|
64
|
-
return out;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/instructions.ts
|
|
68
|
-
function replaceInstructions(transaction, nextInstructions) {
|
|
69
|
-
let out;
|
|
70
|
-
if ("signatures" in transaction) {
|
|
71
|
-
const {
|
|
72
|
-
signatures: _,
|
|
73
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
74
|
-
...unsignedTransaction
|
|
75
|
-
} = transaction;
|
|
76
|
-
out = {
|
|
77
|
-
...unsignedTransaction,
|
|
78
|
-
instructions: nextInstructions
|
|
79
|
-
};
|
|
80
|
-
} else {
|
|
81
|
-
out = {
|
|
82
|
-
...transaction,
|
|
83
|
-
instructions: nextInstructions
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
return out;
|
|
87
|
-
}
|
|
88
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
89
|
-
const nextInstructions = [...transaction.instructions, instruction];
|
|
90
|
-
const out = replaceInstructions(transaction, nextInstructions);
|
|
91
|
-
Object.freeze(out);
|
|
92
|
-
return out;
|
|
93
|
-
}
|
|
94
|
-
function prependTransactionInstruction(instruction, transaction) {
|
|
95
|
-
const nextInstructions = [instruction, ...transaction.instructions];
|
|
96
|
-
const out = replaceInstructions(transaction, nextInstructions);
|
|
97
|
-
Object.freeze(out);
|
|
98
|
-
return out;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
72
|
// ../instructions/dist/index.browser.js
|
|
102
73
|
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
103
74
|
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
@@ -120,6 +91,96 @@ function isWritableRole(role) {
|
|
|
120
91
|
function mergeRoles(roleA, roleB) {
|
|
121
92
|
return roleA | roleB;
|
|
122
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 && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
|
|
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 setTransactionLifetimeUsingDurableNonce({
|
|
132
|
+
nonce,
|
|
133
|
+
nonceAccountAddress,
|
|
134
|
+
nonceAuthorityAddress
|
|
135
|
+
}, transaction) {
|
|
136
|
+
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
137
|
+
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
138
|
+
return transaction;
|
|
139
|
+
}
|
|
140
|
+
const out = {
|
|
141
|
+
...getUnsignedTransaction(transaction),
|
|
142
|
+
instructions: [
|
|
143
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
144
|
+
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
145
|
+
],
|
|
146
|
+
lifetimeConstraint: {
|
|
147
|
+
nonce
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
Object.freeze(out);
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/fee-payer.ts
|
|
155
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
156
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
157
|
+
return transaction;
|
|
158
|
+
}
|
|
159
|
+
const out = {
|
|
160
|
+
...getUnsignedTransaction(transaction),
|
|
161
|
+
feePayer
|
|
162
|
+
};
|
|
163
|
+
Object.freeze(out);
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/instructions.ts
|
|
168
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
169
|
+
const out = {
|
|
170
|
+
...getUnsignedTransaction(transaction),
|
|
171
|
+
instructions: [...transaction.instructions, instruction]
|
|
172
|
+
};
|
|
173
|
+
Object.freeze(out);
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
177
|
+
const out = {
|
|
178
|
+
...getUnsignedTransaction(transaction),
|
|
179
|
+
instructions: [instruction, ...transaction.instructions]
|
|
180
|
+
};
|
|
181
|
+
Object.freeze(out);
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
123
184
|
function upsert(addressMap, address, update) {
|
|
124
185
|
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
|
|
125
186
|
}
|
|
@@ -172,7 +233,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
172
233
|
const shouldReplaceEntry = (
|
|
173
234
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
174
235
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
175
|
-
(addressComparator || (addressComparator =
|
|
236
|
+
(addressComparator || (addressComparator = addresses.getAddressComparator()))(
|
|
176
237
|
accountMeta.lookupTableAddress,
|
|
177
238
|
entry.lookupTableAddress
|
|
178
239
|
) < 0
|
|
@@ -278,7 +339,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
278
339
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
279
340
|
return leftIsWritable ? -1 : 1;
|
|
280
341
|
}
|
|
281
|
-
addressComparator || (addressComparator =
|
|
342
|
+
addressComparator || (addressComparator = addresses.getAddressComparator());
|
|
282
343
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
283
344
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
284
345
|
} else {
|
|
@@ -307,7 +368,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
307
368
|
entry.readableIndices.push(account.addressIndex);
|
|
308
369
|
}
|
|
309
370
|
}
|
|
310
|
-
return Object.keys(index).sort(
|
|
371
|
+
return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
|
|
311
372
|
lookupTableAddress,
|
|
312
373
|
...index[lookupTableAddress]
|
|
313
374
|
}));
|
|
@@ -386,12 +447,40 @@ function compileMessage(transaction) {
|
|
|
386
447
|
version: transaction.version
|
|
387
448
|
};
|
|
388
449
|
}
|
|
450
|
+
|
|
451
|
+
// src/compile-transaction.ts
|
|
452
|
+
function getCompiledTransaction(transaction) {
|
|
453
|
+
const compiledMessage = compileMessage(transaction);
|
|
454
|
+
let signatures;
|
|
455
|
+
if ("signatures" in transaction) {
|
|
456
|
+
signatures = [];
|
|
457
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
458
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
compiledMessage,
|
|
465
|
+
signatures
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function addressSerializerCompat(compat) {
|
|
469
|
+
const codec = addresses.getAddressCodec();
|
|
470
|
+
return {
|
|
471
|
+
description: compat?.description ?? codec.description,
|
|
472
|
+
deserialize: codec.decode,
|
|
473
|
+
fixedSize: codec.fixedSize,
|
|
474
|
+
maxSize: codec.maxSize,
|
|
475
|
+
serialize: codec.encode
|
|
476
|
+
};
|
|
477
|
+
}
|
|
389
478
|
function getAddressTableLookupCodec() {
|
|
390
479
|
return umiSerializers.struct(
|
|
391
480
|
[
|
|
392
481
|
[
|
|
393
482
|
"lookupTableAddress",
|
|
394
|
-
|
|
483
|
+
addressSerializerCompat(
|
|
395
484
|
__DEV__ ? {
|
|
396
485
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
397
486
|
} : void 0
|
|
@@ -421,37 +510,33 @@ function getAddressTableLookupCodec() {
|
|
|
421
510
|
} : void 0
|
|
422
511
|
);
|
|
423
512
|
}
|
|
513
|
+
var memoizedU8Codec;
|
|
514
|
+
function getMemoizedU8Codec() {
|
|
515
|
+
if (!memoizedU8Codec)
|
|
516
|
+
memoizedU8Codec = codecsNumbers.getU8Codec();
|
|
517
|
+
return memoizedU8Codec;
|
|
518
|
+
}
|
|
519
|
+
function getMemoizedU8CodecDescription(description) {
|
|
520
|
+
const codec = getMemoizedU8Codec();
|
|
521
|
+
return {
|
|
522
|
+
...codec,
|
|
523
|
+
description: description ?? codec.description
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
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;
|
|
527
|
+
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;
|
|
528
|
+
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
529
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
424
530
|
function getMessageHeaderCodec() {
|
|
425
|
-
return
|
|
531
|
+
return codecsDataStructures.getStructCodec(
|
|
426
532
|
[
|
|
427
|
-
[
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
__DEV__ ? {
|
|
431
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
432
|
-
} : void 0
|
|
433
|
-
)
|
|
434
|
-
],
|
|
435
|
-
[
|
|
436
|
-
"numReadonlySignerAccounts",
|
|
437
|
-
umiSerializers.u8(
|
|
438
|
-
__DEV__ ? {
|
|
439
|
-
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"
|
|
440
|
-
} : void 0
|
|
441
|
-
)
|
|
442
|
-
],
|
|
443
|
-
[
|
|
444
|
-
"numReadonlyNonSignerAccounts",
|
|
445
|
-
umiSerializers.u8(
|
|
446
|
-
__DEV__ ? {
|
|
447
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
448
|
-
} : void 0
|
|
449
|
-
)
|
|
450
|
-
]
|
|
533
|
+
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
|
|
534
|
+
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
|
|
535
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
|
|
451
536
|
],
|
|
452
|
-
|
|
453
|
-
description:
|
|
454
|
-
}
|
|
537
|
+
{
|
|
538
|
+
description: messageHeaderDescription
|
|
539
|
+
}
|
|
455
540
|
);
|
|
456
541
|
}
|
|
457
542
|
function getInstructionCodec() {
|
|
@@ -466,7 +551,7 @@ function getInstructionCodec() {
|
|
|
466
551
|
)
|
|
467
552
|
],
|
|
468
553
|
[
|
|
469
|
-
"
|
|
554
|
+
"accountIndices",
|
|
470
555
|
umiSerializers.array(
|
|
471
556
|
umiSerializers.u8({
|
|
472
557
|
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
@@ -486,50 +571,35 @@ function getInstructionCodec() {
|
|
|
486
571
|
]
|
|
487
572
|
]),
|
|
488
573
|
(value) => {
|
|
489
|
-
if (value.
|
|
574
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
490
575
|
return value;
|
|
491
576
|
}
|
|
492
577
|
return {
|
|
493
578
|
...value,
|
|
494
|
-
|
|
579
|
+
accountIndices: value.accountIndices ?? [],
|
|
495
580
|
data: value.data ?? new Uint8Array(0)
|
|
496
581
|
};
|
|
497
582
|
},
|
|
498
583
|
(value) => {
|
|
499
|
-
if (value.
|
|
584
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
500
585
|
return value;
|
|
501
586
|
}
|
|
502
|
-
const {
|
|
587
|
+
const { accountIndices, data, ...rest } = value;
|
|
503
588
|
return {
|
|
504
589
|
...rest,
|
|
505
|
-
...
|
|
590
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
506
591
|
...data.byteLength ? { data } : null
|
|
507
592
|
};
|
|
508
593
|
}
|
|
509
594
|
);
|
|
510
595
|
}
|
|
511
|
-
|
|
512
|
-
// src/serializers/unimplemented.ts
|
|
513
|
-
function getError(type, name) {
|
|
514
|
-
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
515
|
-
return new Error(
|
|
516
|
-
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
function getUnimplementedDecoder(name) {
|
|
520
|
-
return () => {
|
|
521
|
-
throw getError("decoder", name);
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// src/serializers/transaction-version.ts
|
|
526
596
|
var VERSION_FLAG_MASK = 128;
|
|
527
597
|
var BASE_CONFIG = {
|
|
528
598
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
529
599
|
fixedSize: null,
|
|
530
600
|
maxSize: 1
|
|
531
601
|
};
|
|
532
|
-
function
|
|
602
|
+
function decode(bytes3, offset = 0) {
|
|
533
603
|
const firstByte = bytes3[offset];
|
|
534
604
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
535
605
|
return ["legacy", offset];
|
|
@@ -538,7 +608,7 @@ function deserialize(bytes3, offset = 0) {
|
|
|
538
608
|
return [version, offset + 1];
|
|
539
609
|
}
|
|
540
610
|
}
|
|
541
|
-
function
|
|
611
|
+
function encode(value) {
|
|
542
612
|
if (value === "legacy") {
|
|
543
613
|
return new Uint8Array();
|
|
544
614
|
}
|
|
@@ -547,11 +617,32 @@ function serialize(value) {
|
|
|
547
617
|
}
|
|
548
618
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
549
619
|
}
|
|
550
|
-
function
|
|
620
|
+
function getTransactionVersionDecoder() {
|
|
551
621
|
return {
|
|
552
622
|
...BASE_CONFIG,
|
|
553
|
-
|
|
554
|
-
|
|
623
|
+
decode
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function getTransactionVersionEncoder() {
|
|
627
|
+
return {
|
|
628
|
+
...BASE_CONFIG,
|
|
629
|
+
encode
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function getTransactionVersionCodec() {
|
|
633
|
+
return codecsCore.combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// src/serializers/unimplemented.ts
|
|
637
|
+
function getError(type, name) {
|
|
638
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
639
|
+
return new Error(
|
|
640
|
+
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
function getUnimplementedDecoder(name) {
|
|
644
|
+
return () => {
|
|
645
|
+
throw getError("decoder", name);
|
|
555
646
|
};
|
|
556
647
|
}
|
|
557
648
|
|
|
@@ -561,7 +652,7 @@ var BASE_CONFIG2 = {
|
|
|
561
652
|
fixedSize: null,
|
|
562
653
|
maxSize: null
|
|
563
654
|
};
|
|
564
|
-
function
|
|
655
|
+
function serialize(compiledMessage) {
|
|
565
656
|
if (compiledMessage.version === "legacy") {
|
|
566
657
|
return umiSerializers.struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
567
658
|
} else {
|
|
@@ -582,13 +673,22 @@ function serialize2(compiledMessage) {
|
|
|
582
673
|
).serialize(compiledMessage);
|
|
583
674
|
}
|
|
584
675
|
}
|
|
676
|
+
function toSerializer(codec) {
|
|
677
|
+
return {
|
|
678
|
+
description: codec.description,
|
|
679
|
+
deserialize: codec.decode,
|
|
680
|
+
fixedSize: codec.fixedSize,
|
|
681
|
+
maxSize: codec.maxSize,
|
|
682
|
+
serialize: codec.encode
|
|
683
|
+
};
|
|
684
|
+
}
|
|
585
685
|
function getPreludeStructSerializerTuple() {
|
|
586
686
|
return [
|
|
587
|
-
["version", getTransactionVersionCodec()],
|
|
588
|
-
["header", getMessageHeaderCodec()],
|
|
687
|
+
["version", toSerializer(getTransactionVersionCodec())],
|
|
688
|
+
["header", toSerializer(getMessageHeaderCodec())],
|
|
589
689
|
[
|
|
590
690
|
"staticAccounts",
|
|
591
|
-
umiSerializers.array(
|
|
691
|
+
umiSerializers.array(toSerializer(addresses.getAddressCodec()), {
|
|
592
692
|
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
|
|
593
693
|
size: umiSerializers.shortU16()
|
|
594
694
|
})
|
|
@@ -620,49 +720,7 @@ function getCompiledMessageEncoder() {
|
|
|
620
720
|
return {
|
|
621
721
|
...BASE_CONFIG2,
|
|
622
722
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
623
|
-
serialize
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// src/signatures.ts
|
|
628
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
629
|
-
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
630
|
-
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
631
|
-
return signature;
|
|
632
|
-
}
|
|
633
|
-
async function signTransaction(keyPair, transaction) {
|
|
634
|
-
const compiledMessage = compileMessage(transaction);
|
|
635
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
636
|
-
keys.getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
|
|
637
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
638
|
-
]);
|
|
639
|
-
const nextSignatures = {
|
|
640
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
641
|
-
...{ [signerPublicKey]: signature }
|
|
642
|
-
};
|
|
643
|
-
const out = {
|
|
644
|
-
...transaction,
|
|
645
|
-
signatures: nextSignatures
|
|
646
|
-
};
|
|
647
|
-
Object.freeze(out);
|
|
648
|
-
return out;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
// src/compile-transaction.ts
|
|
652
|
-
function getCompiledTransaction(transaction) {
|
|
653
|
-
const compiledMessage = compileMessage(transaction);
|
|
654
|
-
let signatures;
|
|
655
|
-
if ("signatures" in transaction) {
|
|
656
|
-
signatures = [];
|
|
657
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
658
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
659
|
-
}
|
|
660
|
-
} else {
|
|
661
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
662
|
-
}
|
|
663
|
-
return {
|
|
664
|
-
compiledMessage,
|
|
665
|
-
signatures
|
|
723
|
+
serialize
|
|
666
724
|
};
|
|
667
725
|
}
|
|
668
726
|
|
|
@@ -672,7 +730,7 @@ var BASE_CONFIG3 = {
|
|
|
672
730
|
fixedSize: null,
|
|
673
731
|
maxSize: null
|
|
674
732
|
};
|
|
675
|
-
function
|
|
733
|
+
function serialize2(transaction) {
|
|
676
734
|
const compiledTransaction = getCompiledTransaction(transaction);
|
|
677
735
|
return umiSerializers.struct([
|
|
678
736
|
[
|
|
@@ -689,9 +747,84 @@ function getTransactionEncoder() {
|
|
|
689
747
|
return {
|
|
690
748
|
...BASE_CONFIG3,
|
|
691
749
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
692
|
-
serialize:
|
|
750
|
+
serialize: serialize2
|
|
693
751
|
};
|
|
694
752
|
}
|
|
753
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
754
|
+
try {
|
|
755
|
+
if (
|
|
756
|
+
// Lowest value (64 bytes of zeroes)
|
|
757
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
758
|
+
putativeTransactionSignature.length > 88
|
|
759
|
+
) {
|
|
760
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
761
|
+
}
|
|
762
|
+
const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
763
|
+
const numBytes = bytes3.byteLength;
|
|
764
|
+
if (numBytes !== 64) {
|
|
765
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
766
|
+
}
|
|
767
|
+
} catch (e) {
|
|
768
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
769
|
+
cause: e
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
774
|
+
if (
|
|
775
|
+
// Lowest value (64 bytes of zeroes)
|
|
776
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
777
|
+
putativeTransactionSignature.length > 88
|
|
778
|
+
) {
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
782
|
+
const numBytes = bytes3.byteLength;
|
|
783
|
+
if (numBytes !== 64) {
|
|
784
|
+
return false;
|
|
785
|
+
}
|
|
786
|
+
return true;
|
|
787
|
+
}
|
|
788
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
789
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
790
|
+
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
791
|
+
return signature;
|
|
792
|
+
}
|
|
793
|
+
function getSignatureFromTransaction(transaction) {
|
|
794
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
795
|
+
if (!signatureBytes) {
|
|
796
|
+
throw new Error(
|
|
797
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
const transactionSignature2 = umiSerializers.base58.deserialize(signatureBytes)[0];
|
|
801
|
+
return transactionSignature2;
|
|
802
|
+
}
|
|
803
|
+
async function signTransaction(keyPairs, transaction) {
|
|
804
|
+
const compiledMessage = compileMessage(transaction);
|
|
805
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
806
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
807
|
+
keyPairs.map(
|
|
808
|
+
(keyPair) => Promise.all([
|
|
809
|
+
addresses.getAddressFromPublicKey(keyPair.publicKey),
|
|
810
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
811
|
+
])
|
|
812
|
+
)
|
|
813
|
+
);
|
|
814
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
815
|
+
nextSignatures[signerPublicKey] = signature;
|
|
816
|
+
}
|
|
817
|
+
const out = {
|
|
818
|
+
...transaction,
|
|
819
|
+
signatures: nextSignatures
|
|
820
|
+
};
|
|
821
|
+
Object.freeze(out);
|
|
822
|
+
return out;
|
|
823
|
+
}
|
|
824
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
825
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
826
|
+
return putativeTransactionSignature;
|
|
827
|
+
}
|
|
695
828
|
|
|
696
829
|
// src/wire-transaction.ts
|
|
697
830
|
function getBase64EncodedWireTransaction(transaction) {
|
|
@@ -703,10 +836,18 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
703
836
|
|
|
704
837
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
705
838
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
839
|
+
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
840
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
706
841
|
exports.createTransaction = createTransaction;
|
|
707
842
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
843
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
844
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
845
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
708
846
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
709
847
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
848
|
+
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
849
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
710
850
|
exports.signTransaction = signTransaction;
|
|
851
|
+
exports.transactionSignature = transactionSignature;
|
|
711
852
|
//# sourceMappingURL=out.js.map
|
|
712
853
|
//# sourceMappingURL=index.browser.cjs.map
|