@solana/transactions 2.0.0-experimental.1584fe6 → 2.0.0-experimental.1ddb6b7
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/dist/index.browser.cjs +125 -89
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +120 -88
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +143 -106
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +120 -88
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +125 -89
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +120 -86
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +11 -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 +13 -4
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +1 -1
- package/dist/types/fee-payer.d.ts.map +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.map +1 -0
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/serializers/unimplemented.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +4 -5
- 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 +1 -1
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +10 -12
package/dist/index.browser.cjs
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
|
+
var addresses = require('@solana/addresses');
|
|
4
5
|
var keys = require('@solana/keys');
|
|
5
6
|
|
|
6
7
|
// ../build-scripts/env-shim.ts
|
|
7
8
|
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
9
|
+
|
|
10
|
+
// src/unsigned-transaction.ts
|
|
11
|
+
function getUnsignedTransaction(transaction) {
|
|
12
|
+
if ("signatures" in transaction) {
|
|
13
|
+
const {
|
|
14
|
+
signatures: _,
|
|
15
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
16
|
+
...unsignedTransaction
|
|
17
|
+
} = transaction;
|
|
18
|
+
return unsignedTransaction;
|
|
19
|
+
} else {
|
|
20
|
+
return transaction;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/blockhash.ts
|
|
8
25
|
function assertIsBlockhash(putativeBlockhash) {
|
|
9
26
|
try {
|
|
10
27
|
if (
|
|
@@ -29,23 +46,10 @@ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, trans
|
|
|
29
46
|
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
30
47
|
return transaction;
|
|
31
48
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
37
|
-
...unsignedTransaction
|
|
38
|
-
} = transaction;
|
|
39
|
-
out = {
|
|
40
|
-
...unsignedTransaction,
|
|
41
|
-
lifetimeConstraint: blockhashLifetimeConstraint
|
|
42
|
-
};
|
|
43
|
-
} else {
|
|
44
|
-
out = {
|
|
45
|
-
...transaction,
|
|
46
|
-
lifetimeConstraint: blockhashLifetimeConstraint
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
+
const out = {
|
|
50
|
+
...getUnsignedTransaction(transaction),
|
|
51
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
52
|
+
};
|
|
49
53
|
Object.freeze(out);
|
|
50
54
|
return out;
|
|
51
55
|
}
|
|
@@ -62,66 +66,6 @@ function createTransaction({
|
|
|
62
66
|
return out;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
// src/fee-payer.ts
|
|
66
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
67
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
68
|
-
return transaction;
|
|
69
|
-
}
|
|
70
|
-
let out;
|
|
71
|
-
if ("signatures" in transaction) {
|
|
72
|
-
const {
|
|
73
|
-
signatures: _,
|
|
74
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
75
|
-
...unsignedTransaction
|
|
76
|
-
} = transaction;
|
|
77
|
-
out = {
|
|
78
|
-
...unsignedTransaction,
|
|
79
|
-
feePayer
|
|
80
|
-
};
|
|
81
|
-
} else {
|
|
82
|
-
out = {
|
|
83
|
-
...transaction,
|
|
84
|
-
feePayer
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
Object.freeze(out);
|
|
88
|
-
return out;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/instructions.ts
|
|
92
|
-
function replaceInstructions(transaction, nextInstructions) {
|
|
93
|
-
let out;
|
|
94
|
-
if ("signatures" in transaction) {
|
|
95
|
-
const {
|
|
96
|
-
signatures: _,
|
|
97
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
98
|
-
...unsignedTransaction
|
|
99
|
-
} = transaction;
|
|
100
|
-
out = {
|
|
101
|
-
...unsignedTransaction,
|
|
102
|
-
instructions: nextInstructions
|
|
103
|
-
};
|
|
104
|
-
} else {
|
|
105
|
-
out = {
|
|
106
|
-
...transaction,
|
|
107
|
-
instructions: nextInstructions
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
return out;
|
|
111
|
-
}
|
|
112
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
113
|
-
const nextInstructions = [...transaction.instructions, instruction];
|
|
114
|
-
const out = replaceInstructions(transaction, nextInstructions);
|
|
115
|
-
Object.freeze(out);
|
|
116
|
-
return out;
|
|
117
|
-
}
|
|
118
|
-
function prependTransactionInstruction(instruction, transaction) {
|
|
119
|
-
const nextInstructions = [instruction, ...transaction.instructions];
|
|
120
|
-
const out = replaceInstructions(transaction, nextInstructions);
|
|
121
|
-
Object.freeze(out);
|
|
122
|
-
return out;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
69
|
// ../instructions/dist/index.browser.js
|
|
126
70
|
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
127
71
|
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
@@ -144,6 +88,96 @@ function isWritableRole(role) {
|
|
|
144
88
|
function mergeRoles(roleA, roleB) {
|
|
145
89
|
return roleA | roleB;
|
|
146
90
|
}
|
|
91
|
+
|
|
92
|
+
// src/durable-nonce.ts
|
|
93
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
94
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
95
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
96
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
97
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
101
|
+
return {
|
|
102
|
+
accounts: [
|
|
103
|
+
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
104
|
+
{
|
|
105
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
106
|
+
role: AccountRole.READONLY
|
|
107
|
+
},
|
|
108
|
+
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
109
|
+
],
|
|
110
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
111
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
115
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
116
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
117
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
118
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
119
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
120
|
+
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
|
|
121
|
+
}
|
|
122
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
123
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
124
|
+
}
|
|
125
|
+
function isDurableNonceTransaction(transaction) {
|
|
126
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
127
|
+
}
|
|
128
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
129
|
+
nonce,
|
|
130
|
+
nonceAccountAddress,
|
|
131
|
+
nonceAuthorityAddress
|
|
132
|
+
}, transaction) {
|
|
133
|
+
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
134
|
+
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
135
|
+
return transaction;
|
|
136
|
+
}
|
|
137
|
+
const out = {
|
|
138
|
+
...getUnsignedTransaction(transaction),
|
|
139
|
+
instructions: [
|
|
140
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
141
|
+
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
142
|
+
],
|
|
143
|
+
lifetimeConstraint: {
|
|
144
|
+
nonce
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
Object.freeze(out);
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/fee-payer.ts
|
|
152
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
153
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
154
|
+
return transaction;
|
|
155
|
+
}
|
|
156
|
+
const out = {
|
|
157
|
+
...getUnsignedTransaction(transaction),
|
|
158
|
+
feePayer
|
|
159
|
+
};
|
|
160
|
+
Object.freeze(out);
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/instructions.ts
|
|
165
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
166
|
+
const out = {
|
|
167
|
+
...getUnsignedTransaction(transaction),
|
|
168
|
+
instructions: [...transaction.instructions, instruction]
|
|
169
|
+
};
|
|
170
|
+
Object.freeze(out);
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
174
|
+
const out = {
|
|
175
|
+
...getUnsignedTransaction(transaction),
|
|
176
|
+
instructions: [instruction, ...transaction.instructions]
|
|
177
|
+
};
|
|
178
|
+
Object.freeze(out);
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
147
181
|
function upsert(addressMap, address, update) {
|
|
148
182
|
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
|
|
149
183
|
}
|
|
@@ -196,7 +230,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
196
230
|
const shouldReplaceEntry = (
|
|
197
231
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
198
232
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
199
|
-
(addressComparator || (addressComparator =
|
|
233
|
+
(addressComparator || (addressComparator = addresses.getBase58EncodedAddressComparator()))(
|
|
200
234
|
accountMeta.lookupTableAddress,
|
|
201
235
|
entry.lookupTableAddress
|
|
202
236
|
) < 0
|
|
@@ -302,7 +336,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
302
336
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
303
337
|
return leftIsWritable ? -1 : 1;
|
|
304
338
|
}
|
|
305
|
-
addressComparator || (addressComparator =
|
|
339
|
+
addressComparator || (addressComparator = addresses.getBase58EncodedAddressComparator());
|
|
306
340
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
307
341
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
308
342
|
} else {
|
|
@@ -331,7 +365,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
331
365
|
entry.readableIndices.push(account.addressIndex);
|
|
332
366
|
}
|
|
333
367
|
}
|
|
334
|
-
return Object.keys(index).sort(
|
|
368
|
+
return Object.keys(index).sort(addresses.getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
|
|
335
369
|
lookupTableAddress,
|
|
336
370
|
...index[lookupTableAddress]
|
|
337
371
|
}));
|
|
@@ -415,7 +449,7 @@ function getAddressTableLookupCodec() {
|
|
|
415
449
|
[
|
|
416
450
|
[
|
|
417
451
|
"lookupTableAddress",
|
|
418
|
-
|
|
452
|
+
addresses.getBase58EncodedAddressCodec(
|
|
419
453
|
__DEV__ ? {
|
|
420
454
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
421
455
|
} : void 0
|
|
@@ -490,7 +524,7 @@ function getInstructionCodec() {
|
|
|
490
524
|
)
|
|
491
525
|
],
|
|
492
526
|
[
|
|
493
|
-
"
|
|
527
|
+
"accountIndices",
|
|
494
528
|
umiSerializers.array(
|
|
495
529
|
umiSerializers.u8({
|
|
496
530
|
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
@@ -510,23 +544,23 @@ function getInstructionCodec() {
|
|
|
510
544
|
]
|
|
511
545
|
]),
|
|
512
546
|
(value) => {
|
|
513
|
-
if (value.
|
|
547
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
514
548
|
return value;
|
|
515
549
|
}
|
|
516
550
|
return {
|
|
517
551
|
...value,
|
|
518
|
-
|
|
552
|
+
accountIndices: value.accountIndices ?? [],
|
|
519
553
|
data: value.data ?? new Uint8Array(0)
|
|
520
554
|
};
|
|
521
555
|
},
|
|
522
556
|
(value) => {
|
|
523
|
-
if (value.
|
|
557
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
524
558
|
return value;
|
|
525
559
|
}
|
|
526
|
-
const {
|
|
560
|
+
const { accountIndices, data, ...rest } = value;
|
|
527
561
|
return {
|
|
528
562
|
...rest,
|
|
529
|
-
...
|
|
563
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
530
564
|
...data.byteLength ? { data } : null
|
|
531
565
|
};
|
|
532
566
|
}
|
|
@@ -612,7 +646,7 @@ function getPreludeStructSerializerTuple() {
|
|
|
612
646
|
["header", getMessageHeaderCodec()],
|
|
613
647
|
[
|
|
614
648
|
"staticAccounts",
|
|
615
|
-
umiSerializers.array(
|
|
649
|
+
umiSerializers.array(addresses.getBase58EncodedAddressCodec(), {
|
|
616
650
|
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
|
|
617
651
|
size: umiSerializers.shortU16()
|
|
618
652
|
})
|
|
@@ -657,7 +691,7 @@ async function getCompiledMessageSignature(message, secretKey) {
|
|
|
657
691
|
async function signTransaction(keyPair, transaction) {
|
|
658
692
|
const compiledMessage = compileMessage(transaction);
|
|
659
693
|
const [signerPublicKey, signature] = await Promise.all([
|
|
660
|
-
|
|
694
|
+
addresses.getAddressFromPublicKey(keyPair.publicKey),
|
|
661
695
|
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
662
696
|
]);
|
|
663
697
|
const nextSignatures = {
|
|
@@ -727,11 +761,13 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
727
761
|
|
|
728
762
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
729
763
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
764
|
+
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
730
765
|
exports.createTransaction = createTransaction;
|
|
731
766
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
732
767
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
733
768
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
734
769
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
770
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
735
771
|
exports.signTransaction = signTransaction;
|
|
736
772
|
//# sourceMappingURL=out.js.map
|
|
737
773
|
//# sourceMappingURL=index.browser.cjs.map
|