@solana/compat 2.0.0-experimental.8de8e11 → 2.0.0-experimental.96442d1
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.node.js
CHANGED
|
@@ -210,3 +210,5 @@ function fromVersionedTransactionWithDurableNonce(transaction) {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
export { fromLegacyKeypair, fromLegacyPublicKey, fromVersionedTransactionWithBlockhash, fromVersionedTransactionWithDurableNonce };
|
|
213
|
+
//# sourceMappingURL=out.js.map
|
|
214
|
+
//# sourceMappingURL=index.node.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/compat",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.96442d1",
|
|
4
4
|
"description": "Helpers for converting from legacy web3js classes",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -49,16 +49,16 @@
|
|
|
49
49
|
"node": ">=17.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@solana/functional": "2.0.0-experimental.
|
|
53
|
-
"@solana/keys": "2.0.0-experimental.
|
|
54
|
-
"@solana/instructions": "2.0.0-experimental.
|
|
55
|
-
"@solana/transactions": "2.0.0-experimental.
|
|
52
|
+
"@solana/functional": "2.0.0-experimental.96442d1",
|
|
53
|
+
"@solana/keys": "2.0.0-experimental.96442d1",
|
|
54
|
+
"@solana/instructions": "2.0.0-experimental.96442d1",
|
|
55
|
+
"@solana/transactions": "2.0.0-experimental.96442d1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@solana/eslint-config-solana": "^1.0.2",
|
|
59
59
|
"@swc/jest": "^0.2.29",
|
|
60
60
|
"@types/jest": "^29.5.11",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
62
62
|
"@typescript-eslint/parser": "^6.3.0",
|
|
63
63
|
"agadoo": "^3.0.0",
|
|
64
64
|
"eslint": "^8.45.0",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"tsup": "^8.0.1",
|
|
73
73
|
"typescript": "^5.2.2",
|
|
74
74
|
"version-from-git": "^1.1.1",
|
|
75
|
-
"@solana/addresses": "2.0.0-experimental.
|
|
76
|
-
"@solana/keys": "2.0.0-experimental.
|
|
75
|
+
"@solana/addresses": "2.0.0-experimental.96442d1",
|
|
76
|
+
"@solana/keys": "2.0.0-experimental.96442d1",
|
|
77
77
|
"@solana/web3.js": "0.0.0-development",
|
|
78
78
|
"build-scripts": "0.0.0",
|
|
79
79
|
"test-config": "0.0.0",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
]
|
|
89
89
|
},
|
|
90
90
|
"scripts": {
|
|
91
|
-
"compile:js": "tsup --config build-scripts/tsup.config.
|
|
91
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
92
92
|
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
|
|
93
93
|
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
94
94
|
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
|
@@ -1,435 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
// src/address.ts
|
|
6
|
-
function fromLegacyPublicKey(publicKey) {
|
|
7
|
-
return publicKey.toBase58();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// ../codecs-core/dist/index.browser.js
|
|
11
|
-
function getEncodedSize(value, encoder) {
|
|
12
|
-
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
|
|
13
|
-
}
|
|
14
|
-
function createEncoder(encoder) {
|
|
15
|
-
return Object.freeze({
|
|
16
|
-
...encoder,
|
|
17
|
-
encode: (value) => {
|
|
18
|
-
const bytes = new Uint8Array(getEncodedSize(value, encoder));
|
|
19
|
-
encoder.write(value, bytes, 0);
|
|
20
|
-
return bytes;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// ../codecs-strings/dist/index.browser.js
|
|
26
|
-
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
27
|
-
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
28
|
-
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
var getBaseXEncoder = (alphabet4) => {
|
|
32
|
-
return createEncoder({
|
|
33
|
-
getSizeFromValue: (value) => {
|
|
34
|
-
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
35
|
-
if (tailChars === "")
|
|
36
|
-
return value.length;
|
|
37
|
-
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
38
|
-
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
|
|
39
|
-
},
|
|
40
|
-
write(value, bytes, offset) {
|
|
41
|
-
assertValidBaseString(alphabet4, value);
|
|
42
|
-
if (value === "")
|
|
43
|
-
return offset;
|
|
44
|
-
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
45
|
-
if (tailChars === "") {
|
|
46
|
-
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
|
|
47
|
-
return offset + leadingZeroes.length;
|
|
48
|
-
}
|
|
49
|
-
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
50
|
-
const tailBytes = [];
|
|
51
|
-
while (base10Number > 0n) {
|
|
52
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
53
|
-
base10Number /= 256n;
|
|
54
|
-
}
|
|
55
|
-
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
|
|
56
|
-
bytes.set(bytesToAdd, offset);
|
|
57
|
-
return offset + bytesToAdd.length;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
function partitionLeadingZeroes(value, zeroCharacter) {
|
|
62
|
-
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
|
|
63
|
-
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
|
|
64
|
-
}
|
|
65
|
-
function getBigIntFromBaseX(value, alphabet4) {
|
|
66
|
-
const base = BigInt(alphabet4.length);
|
|
67
|
-
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
|
|
68
|
-
}
|
|
69
|
-
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
70
|
-
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
71
|
-
|
|
72
|
-
// ../keys/dist/index.browser.js
|
|
73
|
-
function addPkcs8Header(bytes) {
|
|
74
|
-
return new Uint8Array([
|
|
75
|
-
/**
|
|
76
|
-
* PKCS#8 header
|
|
77
|
-
*/
|
|
78
|
-
48,
|
|
79
|
-
// ASN.1 sequence tag
|
|
80
|
-
46,
|
|
81
|
-
// Length of sequence (46 more bytes)
|
|
82
|
-
2,
|
|
83
|
-
// ASN.1 integer tag
|
|
84
|
-
1,
|
|
85
|
-
// Length of integer
|
|
86
|
-
0,
|
|
87
|
-
// Version number
|
|
88
|
-
48,
|
|
89
|
-
// ASN.1 sequence tag
|
|
90
|
-
5,
|
|
91
|
-
// Length of sequence
|
|
92
|
-
6,
|
|
93
|
-
// ASN.1 object identifier tag
|
|
94
|
-
3,
|
|
95
|
-
// Length of object identifier
|
|
96
|
-
// Edwards curve algorithms identifier https://oid-rep.orange-labs.fr/get/1.3.101.112
|
|
97
|
-
43,
|
|
98
|
-
// iso(1) / identified-organization(3) (The first node is multiplied by the decimal 40 and the result is added to the value of the second node)
|
|
99
|
-
101,
|
|
100
|
-
// thawte(101)
|
|
101
|
-
// Ed25519 identifier
|
|
102
|
-
112,
|
|
103
|
-
// id-Ed25519(112)
|
|
104
|
-
/**
|
|
105
|
-
* Private key payload
|
|
106
|
-
*/
|
|
107
|
-
4,
|
|
108
|
-
// ASN.1 octet string tag
|
|
109
|
-
34,
|
|
110
|
-
// String length (34 more bytes)
|
|
111
|
-
// Private key bytes as octet string
|
|
112
|
-
4,
|
|
113
|
-
// ASN.1 octet string tag
|
|
114
|
-
32,
|
|
115
|
-
// String length (32 bytes)
|
|
116
|
-
...bytes
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
async function createPrivateKeyFromBytes(bytes, extractable) {
|
|
120
|
-
if (bytes.byteLength !== 32) {
|
|
121
|
-
throw new Error("Private key bytes must be of length 32");
|
|
122
|
-
}
|
|
123
|
-
const privateKeyBytesPkcs8 = addPkcs8Header(bytes);
|
|
124
|
-
return await crypto.subtle.importKey("pkcs8", privateKeyBytesPkcs8, "Ed25519", extractable != null ? extractable : false, ["sign"]);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/keypair.ts
|
|
128
|
-
async function fromLegacyKeypair(keypair, extractable) {
|
|
129
|
-
const [publicKey, privateKey] = await Promise.all([
|
|
130
|
-
crypto.subtle.importKey("raw", keypair.publicKey.toBytes(), "Ed25519", true, ["verify"]),
|
|
131
|
-
createPrivateKeyFromBytes(keypair.secretKey.slice(0, 32), extractable)
|
|
132
|
-
]);
|
|
133
|
-
return {
|
|
134
|
-
privateKey,
|
|
135
|
-
publicKey
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// ../addresses/dist/index.browser.js
|
|
140
|
-
var memoizedBase58Encoder;
|
|
141
|
-
function getMemoizedBase58Encoder() {
|
|
142
|
-
if (!memoizedBase58Encoder)
|
|
143
|
-
memoizedBase58Encoder = getBase58Encoder();
|
|
144
|
-
return memoizedBase58Encoder;
|
|
145
|
-
}
|
|
146
|
-
function assertIsAddress(putativeAddress) {
|
|
147
|
-
try {
|
|
148
|
-
if (
|
|
149
|
-
// Lowest address (32 bytes of zeroes)
|
|
150
|
-
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
151
|
-
putativeAddress.length > 44
|
|
152
|
-
) {
|
|
153
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
154
|
-
}
|
|
155
|
-
const base58Encoder = getMemoizedBase58Encoder();
|
|
156
|
-
const bytes = base58Encoder.encode(putativeAddress);
|
|
157
|
-
const numBytes = bytes.byteLength;
|
|
158
|
-
if (numBytes !== 32) {
|
|
159
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
160
|
-
}
|
|
161
|
-
} catch (e2) {
|
|
162
|
-
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
163
|
-
cause: e2
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// ../functional/dist/index.browser.js
|
|
169
|
-
function pipe(init, ...fns) {
|
|
170
|
-
return fns.reduce((acc, fn) => fn(acc), init);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// ../instructions/dist/index.browser.js
|
|
174
|
-
var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
|
|
175
|
-
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
176
|
-
3] = "WRITABLE_SIGNER";
|
|
177
|
-
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
178
|
-
2] = "READONLY_SIGNER";
|
|
179
|
-
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
180
|
-
1] = "WRITABLE";
|
|
181
|
-
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
182
|
-
0] = "READONLY";
|
|
183
|
-
return AccountRole22;
|
|
184
|
-
})(AccountRole || {});
|
|
185
|
-
|
|
186
|
-
// ../transactions/dist/index.browser.js
|
|
187
|
-
function getUnsignedTransaction(transaction) {
|
|
188
|
-
if ("signatures" in transaction) {
|
|
189
|
-
const {
|
|
190
|
-
signatures: _,
|
|
191
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
192
|
-
...unsignedTransaction
|
|
193
|
-
} = transaction;
|
|
194
|
-
return unsignedTransaction;
|
|
195
|
-
} else {
|
|
196
|
-
return transaction;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
200
|
-
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
201
|
-
return transaction;
|
|
202
|
-
}
|
|
203
|
-
const out = {
|
|
204
|
-
...getUnsignedTransaction(transaction),
|
|
205
|
-
lifetimeConstraint: blockhashLifetimeConstraint
|
|
206
|
-
};
|
|
207
|
-
Object.freeze(out);
|
|
208
|
-
return out;
|
|
209
|
-
}
|
|
210
|
-
function createTransaction({
|
|
211
|
-
version
|
|
212
|
-
}) {
|
|
213
|
-
const out = {
|
|
214
|
-
instructions: [],
|
|
215
|
-
version
|
|
216
|
-
};
|
|
217
|
-
Object.freeze(out);
|
|
218
|
-
return out;
|
|
219
|
-
}
|
|
220
|
-
var AccountRole2 = /* @__PURE__ */ ((AccountRole22) => {
|
|
221
|
-
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
222
|
-
3] = "WRITABLE_SIGNER";
|
|
223
|
-
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
224
|
-
2] = "READONLY_SIGNER";
|
|
225
|
-
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
226
|
-
1] = "WRITABLE";
|
|
227
|
-
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
228
|
-
0] = "READONLY";
|
|
229
|
-
return AccountRole22;
|
|
230
|
-
})(AccountRole2 || {});
|
|
231
|
-
function isSignerRole(role) {
|
|
232
|
-
return role >= 2;
|
|
233
|
-
}
|
|
234
|
-
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
235
|
-
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
236
|
-
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
237
|
-
return {
|
|
238
|
-
accounts: [
|
|
239
|
-
{ address: nonceAccountAddress, role: AccountRole2.WRITABLE },
|
|
240
|
-
{
|
|
241
|
-
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
242
|
-
role: AccountRole2.READONLY
|
|
243
|
-
},
|
|
244
|
-
{ address: nonceAuthorityAddress, role: AccountRole2.READONLY_SIGNER }
|
|
245
|
-
],
|
|
246
|
-
data: new Uint8Array([4, 0, 0, 0]),
|
|
247
|
-
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function isAdvanceNonceAccountInstruction(instruction) {
|
|
251
|
-
var _a;
|
|
252
|
-
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
253
|
-
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
254
|
-
((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
|
|
255
|
-
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
|
|
256
|
-
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
|
|
257
|
-
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
258
|
-
}
|
|
259
|
-
function isAdvanceNonceAccountInstructionData(data) {
|
|
260
|
-
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
261
|
-
}
|
|
262
|
-
function isDurableNonceTransaction(transaction) {
|
|
263
|
-
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
264
|
-
}
|
|
265
|
-
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
266
|
-
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
267
|
-
}
|
|
268
|
-
function setTransactionLifetimeUsingDurableNonce({
|
|
269
|
-
nonce,
|
|
270
|
-
nonceAccountAddress,
|
|
271
|
-
nonceAuthorityAddress
|
|
272
|
-
}, transaction) {
|
|
273
|
-
let newInstructions;
|
|
274
|
-
const firstInstruction = transaction.instructions[0];
|
|
275
|
-
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
276
|
-
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
277
|
-
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
278
|
-
return transaction;
|
|
279
|
-
} else {
|
|
280
|
-
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
281
|
-
}
|
|
282
|
-
} else {
|
|
283
|
-
newInstructions = [
|
|
284
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
285
|
-
...transaction.instructions.slice(1)
|
|
286
|
-
];
|
|
287
|
-
}
|
|
288
|
-
} else {
|
|
289
|
-
newInstructions = [
|
|
290
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
291
|
-
...transaction.instructions
|
|
292
|
-
];
|
|
293
|
-
}
|
|
294
|
-
const out = {
|
|
295
|
-
...getUnsignedTransaction(transaction),
|
|
296
|
-
instructions: newInstructions,
|
|
297
|
-
lifetimeConstraint: {
|
|
298
|
-
nonce
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
Object.freeze(out);
|
|
302
|
-
return out;
|
|
303
|
-
}
|
|
304
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
305
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
306
|
-
return transaction;
|
|
307
|
-
}
|
|
308
|
-
const out = {
|
|
309
|
-
...getUnsignedTransaction(transaction),
|
|
310
|
-
feePayer
|
|
311
|
-
};
|
|
312
|
-
Object.freeze(out);
|
|
313
|
-
return out;
|
|
314
|
-
}
|
|
315
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
316
|
-
const out = {
|
|
317
|
-
...getUnsignedTransaction(transaction),
|
|
318
|
-
instructions: [...transaction.instructions, instruction]
|
|
319
|
-
};
|
|
320
|
-
Object.freeze(out);
|
|
321
|
-
return out;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// src/transaction.ts
|
|
325
|
-
function convertAccount(message, accountKeys, accountIndex) {
|
|
326
|
-
const accountPublicKey = accountKeys.get(accountIndex);
|
|
327
|
-
if (!accountPublicKey) {
|
|
328
|
-
throw new Error(`Could not find account address at index ${accountIndex}`);
|
|
329
|
-
}
|
|
330
|
-
const isSigner = message.isAccountSigner(accountIndex);
|
|
331
|
-
const isWritable = message.isAccountWritable(accountIndex);
|
|
332
|
-
const role = isSigner ? isWritable ? AccountRole.WRITABLE_SIGNER : AccountRole.READONLY_SIGNER : isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
|
|
333
|
-
return {
|
|
334
|
-
address: accountPublicKey.toBase58(),
|
|
335
|
-
role
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
function convertInstruction(message, accountKeys, instruction) {
|
|
339
|
-
const programAddressPublicKey = accountKeys.get(instruction.programIdIndex);
|
|
340
|
-
if (!programAddressPublicKey) {
|
|
341
|
-
throw new Error(`Could not find program address at index ${instruction.programIdIndex}`);
|
|
342
|
-
}
|
|
343
|
-
const accounts = instruction.accountKeyIndexes.map(
|
|
344
|
-
(accountIndex) => convertAccount(message, accountKeys, accountIndex)
|
|
345
|
-
);
|
|
346
|
-
return {
|
|
347
|
-
programAddress: programAddressPublicKey.toBase58(),
|
|
348
|
-
...accounts.length ? { accounts } : {},
|
|
349
|
-
...instruction.data.length ? { data: instruction.data } : {}
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
function convertSignatures(transaction, staticAccountKeys) {
|
|
353
|
-
return transaction.signatures.reduce((acc, sig, index) => {
|
|
354
|
-
const allZeros = sig.every((byte) => byte === 0);
|
|
355
|
-
if (allZeros)
|
|
356
|
-
return acc;
|
|
357
|
-
const address = staticAccountKeys[index].toBase58();
|
|
358
|
-
return { ...acc, [address]: sig };
|
|
359
|
-
}, {});
|
|
360
|
-
}
|
|
361
|
-
function fromVersionedTransactionWithBlockhash(transaction, lastValidBlockHeight) {
|
|
362
|
-
if (transaction.message.addressTableLookups.length > 0) {
|
|
363
|
-
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
364
|
-
}
|
|
365
|
-
const accountKeys = transaction.message.getAccountKeys();
|
|
366
|
-
const feePayer = accountKeys.staticAccountKeys[0];
|
|
367
|
-
if (!feePayer)
|
|
368
|
-
throw new Error("No fee payer set in VersionedTransaction");
|
|
369
|
-
const blockhashLifetime = {
|
|
370
|
-
blockhash: transaction.message.recentBlockhash,
|
|
371
|
-
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
372
|
-
// U64 MAX
|
|
373
|
-
};
|
|
374
|
-
const instructions = transaction.message.compiledInstructions.map(
|
|
375
|
-
(instruction) => convertInstruction(transaction.message, accountKeys, instruction)
|
|
376
|
-
);
|
|
377
|
-
const signatures = convertSignatures(transaction, accountKeys.staticAccountKeys);
|
|
378
|
-
return pipe(
|
|
379
|
-
createTransaction({ version: transaction.version }),
|
|
380
|
-
(tx) => setTransactionFeePayer(feePayer.toBase58(), tx),
|
|
381
|
-
(tx) => setTransactionLifetimeUsingBlockhash(blockhashLifetime, tx),
|
|
382
|
-
(tx) => instructions.reduce((acc, instruction) => {
|
|
383
|
-
return appendTransactionInstruction(instruction, acc);
|
|
384
|
-
}, tx),
|
|
385
|
-
(tx) => transaction.signatures.length ? { ...tx, signatures } : tx
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
function fromVersionedTransactionWithDurableNonce(transaction) {
|
|
389
|
-
if (transaction.message.addressTableLookups.length > 0) {
|
|
390
|
-
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
391
|
-
}
|
|
392
|
-
const accountKeys = transaction.message.getAccountKeys();
|
|
393
|
-
const feePayer = accountKeys.staticAccountKeys[0];
|
|
394
|
-
if (!feePayer)
|
|
395
|
-
throw new Error("No fee payer set in VersionedTransaction");
|
|
396
|
-
const instructions = transaction.message.compiledInstructions.map(
|
|
397
|
-
(instruction) => convertInstruction(transaction.message, accountKeys, instruction)
|
|
398
|
-
);
|
|
399
|
-
if (instructions.length === 0) {
|
|
400
|
-
throw new Error("transaction with no instructions cannot be durable nonce transaction");
|
|
401
|
-
}
|
|
402
|
-
if (!isAdvanceNonceAccountInstruction(instructions[0])) {
|
|
403
|
-
throw new Error("transaction first instruction is not advance nonce account instruction");
|
|
404
|
-
}
|
|
405
|
-
const nonceAccountAddress = instructions[0].accounts[0].address;
|
|
406
|
-
assertIsAddress(nonceAccountAddress);
|
|
407
|
-
const nonceAuthorityAddress = instructions[0].accounts[2].address;
|
|
408
|
-
assertIsAddress(nonceAuthorityAddress);
|
|
409
|
-
const durableNonceLifetime = {
|
|
410
|
-
nonce: transaction.message.recentBlockhash,
|
|
411
|
-
nonceAccountAddress,
|
|
412
|
-
nonceAuthorityAddress
|
|
413
|
-
};
|
|
414
|
-
const signatures = convertSignatures(transaction, accountKeys.staticAccountKeys);
|
|
415
|
-
return pipe(
|
|
416
|
-
createTransaction({ version: transaction.version }),
|
|
417
|
-
(tx) => setTransactionFeePayer(feePayer.toBase58(), tx),
|
|
418
|
-
(tx) => setTransactionLifetimeUsingDurableNonce(durableNonceLifetime, tx),
|
|
419
|
-
(tx) => instructions.slice(1).reduce((acc, instruction) => {
|
|
420
|
-
return appendTransactionInstruction(instruction, acc);
|
|
421
|
-
}, tx),
|
|
422
|
-
(tx) => transaction.signatures.length ? { ...tx, signatures } : tx
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
exports.fromLegacyKeypair = fromLegacyKeypair;
|
|
427
|
-
exports.fromLegacyPublicKey = fromLegacyPublicKey;
|
|
428
|
-
exports.fromVersionedTransactionWithBlockhash = fromVersionedTransactionWithBlockhash;
|
|
429
|
-
exports.fromVersionedTransactionWithDurableNonce = fromVersionedTransactionWithDurableNonce;
|
|
430
|
-
|
|
431
|
-
return exports;
|
|
432
|
-
|
|
433
|
-
})({});
|
|
434
|
-
//# sourceMappingURL=out.js.map
|
|
435
|
-
//# sourceMappingURL=index.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/address.ts","../../codecs-core/src/codec.ts","../../codecs-strings/src/assertions.ts","../../codecs-strings/src/baseX.ts","../../codecs-strings/src/base16.ts","../../codecs-strings/src/base64.ts","../../keys/dist/index.browser.js","../src/keypair.ts","../../addresses/src/address.ts","../../functional/src/pipe.ts","../../instructions/src/roles.ts","../../transactions/dist/index.browser.js","../src/transaction.ts"],"names":["alphabet","e","AccountRole","AccountRole2"],"mappings":";AAQO,SAAS,oBAA6C,WAAyC;AAClG,SAAO,UAAU,SAAS;AAC9B;;;ACqEO,SAAS,eACZ,OACA,SACM;AACN,SAAO,eAAe,UAAU,QAAQ,YAAY,QAAQ,iBAAiB,KAAK;AACtF;AAUO,SAAS,cACZ,SACc;AACd,SAAO,OAAO,OAAO;IACjB,GAAG;IACH,QAAQ,CA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kB,EAAE,SAAS,YAAY,QAAQ,CAAC;AAAA,IAClD,QAAM,uBAAuB,SAAS,SAAS,GAAc,EAAE;AAAA,IAC/D,QAAM,wCAAwC,sBAAsB,EAAE;AAAA,IACtE,QACI,aAAa,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,gBAAgB;AAC/C,aAAO,6BAA6B,aAAa,GAAG;AAAA,IACxD,GAAG,EAAE;AAAA,IACT,QAAO,YAAY,WAAW,SAAS,EAAE,GAAG,IAAI,WAAW,IAAI;AAAA,EACnE;AACJ","sourcesContent":["import { Address } from '@solana/addresses';\nimport { PublicKey } from '@solana/web3.js';\n\n/**\n * Convert from a Legacy Web3 JS PublicKey to a base58 encoded address\n * @param publicKey The PublicKey to convert\n * @returns An Address\n */\nexport function fromLegacyPublicKey<TAddress extends string>(publicKey: PublicKey): Address<TAddress> {\n return publicKey.toBase58() as Address<TAddress>;\n}\n","/**\n * Defines an offset in bytes.\n */\nexport type Offset = number;\n\ntype BaseEncoder<TFrom> = {\n /** Encode the provided value and return the encoded bytes directly. */\n readonly encode: (value: TFrom) => Uint8Array;\n /**\n * Writes the encoded value into the provided byte array at the given offset.\n * Returns the offset of the next byte after the encoded value.\n */\n readonly write: (value: TFrom, bytes: Uint8Array, offset: Offset) => Offset;\n};\n\nexport type FixedSizeEncoder<TFrom, TSize extends number = number> = BaseEncoder<TFrom> & {\n /** The fixed size of the encoded value in bytes. */\n readonly fixedSize: TSize;\n};\n\nexport type VariableSizeEncoder<TFrom> = BaseEncoder<TFrom> & {\n /** The total size of the encoded value in bytes. */\n readonly getSizeFromValue: (value: TFrom) => number;\n /** The maximum size an encoded value can be in bytes, if applicable. */\n readonly maxSize?: number;\n};\n\n/**\n * An object that can encode a value to a `Uint8Array`.\n */\nexport type Encoder<TFrom> = FixedSizeEncoder<TFrom> | VariableSizeEncoder<TFrom>;\n\ntype BaseDecoder<TTo> = {\n /** Decodes the provided byte array at the given offset (or zero) and returns the value directly. */\n readonly decode: (bytes: Uint8Array, offset?: Offset) => TTo;\n /**\n * Reads the encoded value from the provided byte array at the given offset.\n * Returns the decoded value and the offset of the next byte after the encoded value.\n */\n readonly read: (bytes: Uint8Array, offset: Offset) => [TTo, Offset];\n};\n\nexport type FixedSizeDecoder<TTo, TSize extends number = number> = BaseDecoder<TTo> & {\n /** The fixed size of the encoded value in bytes. */\n readonly fixedSize: TSize;\n};\n\nexport type VariableSizeDecoder<TTo> = BaseDecoder<TTo> & {\n /** The maximum size an encoded value can be in bytes, if applicable. */\n readonly maxSize?: number;\n};\n\n/**\n * An object that can decode a value from a `Uint8Array`.\n */\nexport type Decoder<TTo> = FixedSizeDecoder<TTo> | VariableSizeDecoder<TTo>;\n\nexport type FixedSizeCodec<TFrom, TTo extends TFrom = TFrom, TSize extends number = number> = FixedSizeEncoder<\n TFrom,\n TSize\n> &\n FixedSizeDecoder<TTo, TSize>;\n\nexport type VariableSizeCodec<TFrom, TTo extends TFrom = TFrom> = VariableSizeEncoder<TFrom> & VariableSizeDecoder<TTo>;\n\n/**\n * An object that can encode and decode a value to and from a `Uint8Array`.\n * It supports encoding looser types than it decodes for convenience.\n * For example, a `bigint` encoder will always decode to a `bigint`\n * but can be used to encode a `number`.\n *\n * @typeParam TFrom - The type of the value to encode.\n * @typeParam TTo - The type of the decoded value. Defaults to `TFrom`.\n */\nexport type Codec<TFrom, TTo extends TFrom = TFrom> = FixedSizeCodec<TFrom, TTo> | VariableSizeCodec<TFrom, TTo>;\n\n/**\n * Get the encoded size of a given value in bytes.\n */\nexport function getEncodedSize<TFrom>(\n value: TFrom,\n encoder: { fixedSize: number } | { getSizeFromValue: (value: TFrom) => number },\n): number {\n return 'fixedSize' in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);\n}\n\n/** Fills the missing `encode` function using the existing `write` function. */\nexport function createEncoder<TFrom, TSize extends number>(\n encoder: Omit<FixedSizeEncoder<TFrom, TSize>, 'encode'>,\n): FixedSizeEncoder<TFrom, TSize>;\nexport function createEncoder<TFrom>(encoder: Omit<VariableSizeEncoder<TFrom>, 'encode'>): VariableSizeEncoder<TFrom>;\nexport function createEncoder<TFrom>(\n encoder: Omit<FixedSizeEncoder<TFrom>, 'encode'> | Omit<VariableSizeEncoder<TFrom>, 'encode'>,\n): Encoder<TFrom>;\nexport function createEncoder<TFrom>(\n encoder: Omit<FixedSizeEncoder<TFrom>, 'encode'> | Omit<VariableSizeEncoder<TFrom>, 'encode'>,\n): Encoder<TFrom> {\n return Object.freeze({\n ...encoder,\n encode: value => {\n const bytes = new Uint8Array(getEncodedSize(value, encoder));\n encoder.write(value, bytes, 0);\n return bytes;\n },\n });\n}\n\n/** Fills the missing `decode` function using the existing `read` function. */\nexport function createDecoder<TTo, TSize extends number>(\n decoder: Omit<FixedSizeDecoder<TTo, TSize>, 'decode'>,\n): FixedSizeDecoder<TTo, TSize>;\nexport function createDecoder<TTo>(decoder: Omit<VariableSizeDecoder<TTo>, 'decode'>): VariableSizeDecoder<TTo>;\nexport function createDecoder<TTo>(\n decoder: Omit<FixedSizeDecoder<TTo>, 'decode'> | Omit<VariableSizeDecoder<TTo>, 'decode'>,\n): Decoder<TTo>;\nexport function createDecoder<TTo>(\n decoder: Omit<FixedSizeDecoder<TTo>, 'decode'> | Omit<VariableSizeDecoder<TTo>, 'decode'>,\n): Decoder<TTo> {\n return Object.freeze({\n ...decoder,\n decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0],\n });\n}\n\n/** Fills the missing `encode` and `decode` function using the existing `write` and `read` functions. */\nexport function createCodec<TFrom, TTo extends TFrom = TFrom, TSize extends number = number>(\n codec: Omit<FixedSizeCodec<TFrom, TTo, TSize>, 'encode' | 'decode'>,\n): FixedSizeCodec<TFrom, TTo, TSize>;\nexport function createCodec<TFrom, TTo extends TFrom = TFrom>(\n codec: Omit<VariableSizeCodec<TFrom, TTo>, 'encode' | 'decode'>,\n): VariableSizeCodec<TFrom, TTo>;\nexport function createCodec<TFrom, TTo extends TFrom = TFrom>(\n codec:\n | Omit<FixedSizeCodec<TFrom, TTo>, 'encode' | 'decode'>\n | Omit<VariableSizeCodec<TFrom, TTo>, 'encode' | 'decode'>,\n): Codec<TFrom, TTo>;\nexport function createCodec<TFrom, TTo extends TFrom = TFrom>(\n codec:\n | Omit<FixedSizeCodec<TFrom, TTo>, 'encode' | 'decode'>\n | Omit<VariableSizeCodec<TFrom, TTo>, 'encode' | 'decode'>,\n): Codec<TFrom, TTo> {\n return Object.freeze({\n ...codec,\n decode: (bytes, offset = 0) => codec.read(bytes, offset)[0],\n encode: value => {\n const bytes = new Uint8Array(getEncodedSize(value, codec));\n codec.write(value, bytes, 0);\n return bytes;\n },\n });\n}\n\nexport function isFixedSize<TFrom, TSize extends number>(\n encoder: FixedSizeEncoder<TFrom, TSize> | VariableSizeEncoder<TFrom>,\n): encoder is FixedSizeEncoder<TFrom, TSize>;\nexport function isFixedSize<TTo, TSize extends number>(\n decoder: FixedSizeDecoder<TTo, TSize> | VariableSizeDecoder<TTo>,\n): decoder is FixedSizeDecoder<TTo, TSize>;\nexport function isFixedSize<TFrom, TTo extends TFrom, TSize extends number>(\n codec: FixedSizeCodec<TFrom, TTo, TSize> | VariableSizeCodec<TFrom, TTo>,\n): codec is FixedSizeCodec<TFrom, TTo, TSize>;\nexport function isFixedSize<TSize extends number>(\n codec: { fixedSize: TSize } | { maxSize?: number },\n): codec is { fixedSize: TSize };\nexport function isFixedSize(codec: { fixedSize: number } | { maxSize?: number }): codec is { fixedSize: number } {\n return 'fixedSize' in codec && typeof codec.fixedSize === 'number';\n}\n\nexport function assertIsFixedSize<TFrom, TSize extends number>(\n encoder: FixedSizeEncoder<TFrom, TSize> | VariableSizeEncoder<TFrom>,\n message?: string,\n): asserts encoder is FixedSizeEncoder<TFrom, TSize>;\nexport function assertIsFixedSize<TTo, TSize extends number>(\n decoder: FixedSizeDecoder<TTo, TSize> | VariableSizeDecoder<TTo>,\n message?: string,\n): asserts decoder is FixedSizeDecoder<TTo, TSize>;\nexport function assertIsFixedSize<TFrom, TTo extends TFrom, TSize extends number>(\n codec: FixedSizeCodec<TFrom, TTo, TSize> | VariableSizeCodec<TFrom, TTo>,\n message?: string,\n): asserts codec is FixedSizeCodec<TFrom, TTo, TSize>;\nexport function assertIsFixedSize<TSize extends number>(\n codec: { fixedSize: TSize } | { maxSize?: number },\n message?: string,\n): asserts codec is { fixedSize: TSize };\nexport function assertIsFixedSize(\n codec: { fixedSize: number } | { maxSize?: number },\n message?: string,\n): asserts codec is { fixedSize: number } {\n if (!isFixedSize(codec)) {\n // TODO: Coded error.\n throw new Error(message ?? 'Expected a fixed-size codec, got a variable-size one.');\n }\n}\n\nexport function isVariableSize<TFrom>(encoder: Encoder<TFrom>): encoder is VariableSizeEncoder<TFrom>;\nexport function isVariableSize<TTo>(decoder: Decoder<TTo>): decoder is VariableSizeDecoder<TTo>;\nexport function isVariableSize<TFrom, TTo extends TFrom>(\n codec: Codec<TFrom, TTo>,\n): codec is VariableSizeCodec<TFrom, TTo>;\nexport function isVariableSize(codec: { fixedSize: number } | { maxSize?: number }): codec is { maxSize?: number };\nexport function isVariableSize(codec: { fixedSize: number } | { maxSize?: number }): codec is { maxSize?: number } {\n return !isFixedSize(codec);\n}\n\nexport function assertIsVariableSize<T>(\n encoder: Encoder<T>,\n message?: string,\n): asserts encoder is VariableSizeEncoder<T>;\nexport function assertIsVariableSize<T>(\n decoder: Decoder<T>,\n message?: string,\n): asserts decoder is VariableSizeDecoder<T>;\nexport function assertIsVariableSize<TFrom, TTo extends TFrom>(\n codec: Codec<TFrom, TTo>,\n message?: string,\n): asserts codec is VariableSizeCodec<TFrom, TTo>;\nexport function assertIsVariableSize(\n codec: { fixedSize: number } | { maxSize?: number },\n message?: string,\n): asserts codec is { maxSize?: number };\nexport function assertIsVariableSize(\n codec: { fixedSize: number } | { maxSize?: number },\n message?: string,\n): asserts codec is { maxSize?: number } {\n if (!isVariableSize(codec)) {\n // TODO: Coded error.\n throw new Error(message ?? 'Expected a variable-size codec, got a fixed-size one.');\n }\n}\n","/**\n * Asserts that a given string matches a given alphabet.\n */\nexport function assertValidBaseString(alphabet: string, testValue: string, givenValue = testValue) {\n if (!testValue.match(new RegExp(`^[${alphabet}]*$`))) {\n // TODO: Coded error.\n throw new Error(`Expected a string of base ${alphabet.length}, got [${givenValue}].`);\n }\n}\n","import {\n combineCodec,\n createDecoder,\n createEncoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\n\n/**\n * Encodes a string using a custom alphabet by dividing\n * by the base and handling leading zeroes.\n * @see {@link getBaseXCodec} for a more detailed description.\n */\nexport const getBaseXEncoder = (alphabet: string): VariableSizeEncoder<string> => {\n return createEncoder({\n getSizeFromValue: (value: string): number => {\n const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet[0]);\n if (tailChars === '') return value.length;\n\n const base10Number = getBigIntFromBaseX(tailChars, alphabet);\n return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);\n },\n write(value: string, bytes, offset) {\n // Check if the value is valid.\n assertValidBaseString(alphabet, value);\n if (value === '') return offset;\n\n // Handle leading zeroes.\n const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet[0]);\n if (tailChars === '') {\n bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);\n return offset + leadingZeroes.length;\n }\n\n // From baseX to base10.\n let base10Number = getBigIntFromBaseX(tailChars, alphabet);\n\n // From base10 to bytes.\n const tailBytes: number[] = [];\n while (base10Number > 0n) {\n tailBytes.unshift(Number(base10Number % 256n));\n base10Number /= 256n;\n }\n\n const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];\n bytes.set(bytesToAdd, offset);\n return offset + bytesToAdd.length;\n },\n });\n};\n\n/**\n * Decodes a string using a custom alphabet by dividing\n * by the base and handling leading zeroes.\n * @see {@link getBaseXCodec} for a more detailed description.\n */\nexport const getBaseXDecoder = (alphabet: string): VariableSizeDecoder<string> => {\n return createDecoder({\n read(rawBytes, offset): [string, number] {\n const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);\n if (bytes.length === 0) return ['', 0];\n\n // Handle leading zeroes.\n let trailIndex = bytes.findIndex(n => n !== 0);\n trailIndex = trailIndex === -1 ? bytes.length : trailIndex;\n const leadingZeroes = alphabet[0].repeat(trailIndex);\n if (trailIndex === bytes.length) return [leadingZeroes, rawBytes.length];\n\n // From bytes to base10.\n const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);\n\n // From base10 to baseX.\n const tailChars = getBaseXFromBigInt(base10Number, alphabet);\n\n return [leadingZeroes + tailChars, rawBytes.length];\n },\n });\n};\n\n/**\n * A string codec that requires a custom alphabet and uses\n * the length of that alphabet as the base. It then divides\n * the input by the base as many times as necessary to get\n * the output. It also supports leading zeroes by using the\n * first character of the alphabet as the zero character.\n *\n * This can be used to create codecs such as base10 or base58.\n */\nexport const getBaseXCodec = (alphabet: string): VariableSizeCodec<string> =>\n combineCodec(getBaseXEncoder(alphabet), getBaseXDecoder(alphabet));\n\nfunction partitionLeadingZeroes(value: string, zeroCharacter: string): [string, string] {\n const leadingZeroIndex = [...value].findIndex(c => c !== zeroCharacter);\n return leadingZeroIndex === -1 ? [value, ''] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];\n}\n\nfunction getBigIntFromBaseX(value: string, alphabet: string): bigint {\n const base = BigInt(alphabet.length);\n return [...value].reduce((sum, char) => sum * base + BigInt(alphabet.indexOf(char)), 0n);\n}\n\nfunction getBaseXFromBigInt(value: bigint, alphabet: string): string {\n const base = BigInt(alphabet.length);\n const tailChars = [];\n while (value > 0n) {\n tailChars.unshift(alphabet[Number(value % base)]);\n value /= base;\n }\n return tailChars.join('');\n}\n","import {\n combineCodec,\n createDecoder,\n createEncoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\n\n/** Encodes strings in base16. */\nexport const getBase16Encoder = (): VariableSizeEncoder<string> =>\n createEncoder({\n getSizeFromValue: (value: string) => Math.ceil(value.length / 2),\n write(value: string, bytes, offset) {\n const lowercaseValue = value.toLowerCase();\n assertValidBaseString('0123456789abcdef', lowercaseValue, value);\n const matches = lowercaseValue.match(/.{1,2}/g);\n const hexBytes = matches ? matches.map((byte: string) => parseInt(byte, 16)) : [];\n bytes.set(hexBytes, offset);\n return hexBytes.length + offset;\n },\n });\n\n/** Decodes strings in base16. */\nexport const getBase16Decoder = (): VariableSizeDecoder<string> =>\n createDecoder({\n read(bytes, offset) {\n const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n return [value, bytes.length];\n },\n });\n\n/** Encodes and decodes strings in base16. */\nexport const getBase16Codec = (): VariableSizeCodec<string> => combineCodec(getBase16Encoder(), getBase16Decoder());\n","import {\n combineCodec,\n createDecoder,\n createEncoder,\n mapDecoder,\n mapEncoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\nimport { getBaseXResliceDecoder, getBaseXResliceEncoder } from './baseX-reslice';\n\nconst alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n/** Encodes strings in base64. */\nexport const getBase64Encoder = (): VariableSizeEncoder<string> => {\n if (__BROWSER__) {\n return createEncoder({\n getSizeFromValue: (value: string) => {\n try {\n return (atob as Window['atob'])(value).length;\n } catch (e) {\n // TODO: Coded error.\n throw new Error(`Expected a string of base 64, got [${value}].`);\n }\n },\n write(value: string, bytes, offset) {\n try {\n const bytesToAdd = (atob as Window['atob'])(value)\n .split('')\n .map(c => c.charCodeAt(0));\n bytes.set(bytesToAdd, offset);\n return bytesToAdd.length + offset;\n } catch (e) {\n // TODO: Coded error.\n throw new Error(`Expected a string of base 64, got [${value}].`);\n }\n },\n });\n }\n\n if (__NODEJS__) {\n return createEncoder({\n getSizeFromValue: (value: string) => Buffer.from(value, 'base64').length,\n write(value: string, bytes, offset) {\n assertValidBaseString(alphabet, value.replace(/=/g, ''));\n const buffer = Buffer.from(value, 'base64');\n bytes.set(buffer, offset);\n return buffer.length + offset;\n },\n });\n }\n\n return mapEncoder(getBaseXResliceEncoder(alphabet, 6), (value: string): string => value.replace(/=/g, ''));\n};\n\n/** Decodes strings in base64. */\nexport const getBase64Decoder = (): VariableSizeDecoder<string> => {\n if (__BROWSER__) {\n return createDecoder({\n read(bytes, offset = 0) {\n const slice = bytes.slice(offset);\n const value = (btoa as Window['btoa'])(String.fromCharCode(...slice));\n return [value, bytes.length];\n },\n });\n }\n\n if (__NODEJS__) {\n return createDecoder({\n read: (bytes, offset = 0) => [Buffer.from(bytes, offset).toString('base64'), bytes.length],\n });\n }\n\n return mapDecoder(getBaseXResliceDecoder(alphabet, 6), (value: string): string =>\n value.padEnd(Math.ceil(value.length / 4) * 4, '='),\n );\n};\n\n/** Encodes and decodes strings in base64. */\nexport const getBase64Codec = (): VariableSizeCodec<string> => combineCodec(getBase64Encoder(), getBase64Decoder());\n","import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions';\nimport { getBase58Encoder } from '@solana/codecs-strings';\n\n// src/key-pair.ts\nasync function generateKeyPair() {\n await assertKeyGenerationIsAvailable();\n const keyPair = await crypto.subtle.generateKey(\n /* algorithm */\n \"Ed25519\",\n // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20\n /* extractable */\n false,\n // Prevents the bytes of the private key from being visible to JS.\n /* allowed uses */\n [\"sign\", \"verify\"]\n );\n return keyPair;\n}\n\n// src/private-key.ts\nfunction addPkcs8Header(bytes) {\n return new Uint8Array([\n /**\n * PKCS#8 header\n */\n 48,\n // ASN.1 sequence tag\n 46,\n // Length of sequence (46 more bytes)\n 2,\n // ASN.1 integer tag\n 1,\n // Length of integer\n 0,\n // Version number\n 48,\n // ASN.1 sequence tag\n 5,\n // Length of sequence\n 6,\n // ASN.1 object identifier tag\n 3,\n // Length of object identifier\n // Edwards curve algorithms identifier https://oid-rep.orange-labs.fr/get/1.3.101.112\n 43,\n // iso(1) / identified-organization(3) (The first node is multiplied by the decimal 40 and the result is added to the value of the second node)\n 101,\n // thawte(101)\n // Ed25519 identifier\n 112,\n // id-Ed25519(112)\n /**\n * Private key payload\n */\n 4,\n // ASN.1 octet string tag\n 34,\n // String length (34 more bytes)\n // Private key bytes as octet string\n 4,\n // ASN.1 octet string tag\n 32,\n // String length (32 bytes)\n ...bytes\n ]);\n}\nasync function createPrivateKeyFromBytes(bytes, extractable) {\n if (bytes.byteLength !== 32) {\n throw new Error(\"Private key bytes must be of length 32\");\n }\n const privateKeyBytesPkcs8 = addPkcs8Header(bytes);\n return await crypto.subtle.importKey(\"pkcs8\", privateKeyBytesPkcs8, \"Ed25519\", extractable ?? false, [\"sign\"]);\n}\nvar base58Encoder;\nfunction assertIsSignature(putativeSignature) {\n if (!base58Encoder)\n base58Encoder = getBase58Encoder();\n try {\n if (\n // Lowest value (64 bytes of zeroes)\n putativeSignature.length < 64 || // Highest value (64 bytes of 255)\n putativeSignature.length > 88\n ) {\n throw new Error(\"Expected input string to decode to a byte array of length 64.\");\n }\n const bytes = base58Encoder.encode(putativeSignature);\n const numBytes = bytes.byteLength;\n if (numBytes !== 64) {\n throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeSignature}\\` is not a signature`, {\n cause: e\n });\n }\n}\nfunction isSignature(putativeSignature) {\n if (!base58Encoder)\n base58Encoder = getBase58Encoder();\n if (\n // Lowest value (64 bytes of zeroes)\n putativeSignature.length < 64 || // Highest value (64 bytes of 255)\n putativeSignature.length > 88\n ) {\n return false;\n }\n const bytes = base58Encoder.encode(putativeSignature);\n const numBytes = bytes.byteLength;\n if (numBytes !== 64) {\n return false;\n }\n return true;\n}\nasync function signBytes(key, data) {\n await assertSigningCapabilityIsAvailable();\n const signedData = await crypto.subtle.sign(\"Ed25519\", key, data);\n return new Uint8Array(signedData);\n}\nfunction signature(putativeSignature) {\n assertIsSignature(putativeSignature);\n return putativeSignature;\n}\nasync function verifySignature(key, signature2, data) {\n await assertVerificationCapabilityIsAvailable();\n return await crypto.subtle.verify(\"Ed25519\", key, signature2, data);\n}\n\nexport { assertIsSignature, createPrivateKeyFromBytes, generateKeyPair, isSignature, signBytes, signature, verifySignature };\n","import { createPrivateKeyFromBytes } from '@solana/keys';\nimport { Keypair } from '@solana/web3.js';\n\n/**\n * Convert from a Legacy Web3 JS Keypair to a CryptoKeyPair\n * @param keypair The Keypair to convert\n * @returns A CryptoKeyPair\n */\nexport async function fromLegacyKeypair(keypair: Keypair, extractable?: boolean): Promise<CryptoKeyPair> {\n const [publicKey, privateKey] = await Promise.all([\n crypto.subtle.importKey('raw', keypair.publicKey.toBytes(), 'Ed25519', true, ['verify']),\n createPrivateKeyFromBytes(keypair.secretKey.slice(0, 32), extractable),\n ]);\n return {\n privateKey,\n publicKey,\n } as CryptoKeyPair;\n}\n","import {\n combineCodec,\n Decoder,\n Encoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n mapEncoder,\n} from '@solana/codecs-core';\nimport { getBase58Decoder, getBase58Encoder, getStringDecoder, getStringEncoder } from '@solana/codecs-strings';\n\nexport type Address<TAddress extends string = string> = TAddress & {\n readonly __brand: unique symbol;\n};\n\nlet memoizedBase58Encoder: Encoder<string> | undefined;\nlet memoizedBase58Decoder: Decoder<string> | undefined;\n\nfunction getMemoizedBase58Encoder(): Encoder<string> {\n if (!memoizedBase58Encoder) memoizedBase58Encoder = getBase58Encoder();\n return memoizedBase58Encoder;\n}\n\nfunction getMemoizedBase58Decoder(): Decoder<string> {\n if (!memoizedBase58Decoder) memoizedBase58Decoder = getBase58Decoder();\n return memoizedBase58Decoder;\n}\n\nexport function isAddress(putativeAddress: string): putativeAddress is Address<typeof putativeAddress> {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeAddress.length > 44\n ) {\n return false;\n }\n // Slow-path; actually attempt to decode the input string.\n const base58Encoder = getMemoizedBase58Encoder();\n const bytes = base58Encoder.encode(putativeAddress);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n return false;\n }\n return true;\n}\n\nexport function assertIsAddress(putativeAddress: string): asserts putativeAddress is Address<typeof putativeAddress> {\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeAddress.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const base58Encoder = getMemoizedBase58Encoder();\n const bytes = base58Encoder.encode(putativeAddress);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeAddress}\\` is not a base-58 encoded address`, {\n cause: e,\n });\n }\n}\n\nexport function address<TAddress extends string = string>(putativeAddress: TAddress): Address<TAddress> {\n assertIsAddress(putativeAddress);\n return putativeAddress as Address<TAddress>;\n}\n\nexport function getAddressEncoder(): FixedSizeEncoder<Address, 32> {\n return mapEncoder(getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }), putativeAddress =>\n address(putativeAddress),\n );\n}\n\nexport function getAddressDecoder(): FixedSizeDecoder<Address, 32> {\n return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 }) as FixedSizeDecoder<Address, 32>;\n}\n\nexport function getAddressCodec(): FixedSizeCodec<Address, Address, 32> {\n return combineCodec(getAddressEncoder(), getAddressDecoder());\n}\n\nexport function getAddressComparator(): (x: string, y: string) => number {\n return new Intl.Collator('en', {\n caseFirst: 'lower',\n ignorePunctuation: false,\n localeMatcher: 'best fit',\n numeric: false,\n sensitivity: 'variant',\n usage: 'sort',\n }).compare;\n}\n","/**\n * General pipe function.\n * Provide an initial value and a list of functions to pipe it through.\n *\n * Following common implementations of pipe functions that use TypeScript,\n * this function supports a maximum arity of 10 for type safety.\n * @see https://github.com/ramda/ramda/blob/master/source/pipe.js\n * @see https://github.com/darky/rocket-pipes/blob/master/index.ts\n *\n * Note you can use nested pipes to extend this limitation, like so:\n * ```typescript\n * const myValue = pipe(\n * pipe(\n * 1,\n * (x) => x + 1,\n * (x) => x * 2,\n * (x) => x - 1,\n * ),\n * (y) => y / 3,\n * (y) => y + 1,\n * );\n * ```\n * @param init The initial value\n * @param fns Any number of functions to pipe the value through\n * @returns The final value with all functions applied\n */\nexport function pipe<TInitial>(init: TInitial): TInitial;\nexport function pipe<TInitial, R1>(init: TInitial, init_r1: (init: TInitial) => R1): R1;\nexport function pipe<TInitial, R1, R2>(init: TInitial, init_r1: (init: TInitial) => R1, r1_r2: (r1: R1) => R2): R2;\nexport function pipe<TInitial, R1, R2, R3>(\n init: TInitial,\n init_r1: (init: TInitial) => R1,\n r1_r2: (r1: R1) => R2,\n r2_r3: (r2: R2) => R3,\n): R3;\nexport function pipe<TInitial, R1, R2, R3, R4>(\n init: TInitial,\n init_r1: (init: TInitial) => R1,\n r1_r2: (r1: R1) => R2,\n r2_r3: (r2: R2) => R3,\n r3_r4: (r3: R3) => R4,\n): R4;\nexport function pipe<TInitial, R1, R2, R3, R4, R5>(\n init: TInitial,\n init_r1: (init: TInitial) => R1,\n r1_r2: (r1: R1) => R2,\n r2_r3: (r2: R2) => R3,\n r3_r4: (r3: R3) => R4,\n r4_r5: (r4: R4) => R5,\n): R5;\nexport function pipe<TInitial, R1, R2, R3, R4, R5, R6>(\n init: TInitial,\n init_r1: (init: TInitial) => R1,\n r1_r2: (r1: R1) => R2,\n r2_r3: (r2: R2) => R3,\n r3_r4: (r3: R3) => R4,\n r4_r5: (r4: R4) => R5,\n r5_r6: (r5: R5) => R6,\n): R6;\nexport function pipe<TInitial, R1, R2, R3, R4, R5, R6, R7>(\n init: TInitial,\n init_r1: (init: TInitial) => R1,\n r1_r2: (r1: R1) => R2,\n r2_r3: (r2: R2) => R3,\n r3_r4: (r3: R3) => R4,\n r4_r5: (r4: R4) => R5,\n r5_r6: (r5: R5) => R6,\n r6_r7: (r6: R6) => R7,\n): R7;\nexport function pipe<TInitial, R1, R2, R3, R4, R5, R6, R7, R8>(\n init: TInitial,\n init_r1: (init: TInitial) => R1,\n r1_r2: (r1: R1) => R2,\n r2_r3: (r2: R2) => R3,\n r3_r4: (r3: R3) => R4,\n r4_r5: (r4: R4) => R5,\n r5_r6: (r5: R5) => R6,\n r6_r7: (r6: R6) => R7,\n r7_r8: (r7: R7) => R8,\n): R8;\nexport function pipe<TInitial, R1, R2, R3, R4, R5, R6, R7, R8, R9>(\n init: TInitial,\n init_r1: (init: TInitial) => R1,\n r1_r2: (r1: R1) => R2,\n r2_r3: (r2: R2) => R3,\n r3_r4: (r3: R3) => R4,\n r4_r5: (r4: R4) => R5,\n r5_r6: (r5: R5) => R6,\n r6_r7: (r6: R6) => R7,\n r7_r8: (r7: R7) => R8,\n r8_r9: (r8: R8) => R9,\n): R9;\nexport function pipe<TInitial, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10>(\n init: TInitial,\n init_r1: (init: TInitial) => R1,\n r1_r2: (r1: R1) => R2,\n r2_r3: (r2: R2) => R3,\n r3_r4: (r3: R3) => R4,\n r4_r5: (r4: R4) => R5,\n r5_r6: (r5: R5) => R6,\n r6_r7: (r6: R6) => R7,\n r7_r8: (r7: R7) => R8,\n r8_r9: (r8: R8) => R9,\n r9_r10: (r9: R9) => R10,\n): R10;\nexport function pipe<TInitial>(init: TInitial, ...fns: CallableFunction[]) {\n return fns.reduce((acc, fn) => fn(acc), init);\n}\n","/**\n * Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\n */\n\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n","import { getBase58Encoder, getBase58Decoder, getBase64Decoder, getStringEncoder, getStringDecoder } from '@solana/codecs-strings';\nimport { getAddressFromPublicKey, getAddressComparator, getAddressEncoder, getAddressDecoder, assertIsAddress } from '@solana/addresses';\nimport { createEncoder, mapDecoder, combineCodec, mapEncoder, createDecoder } from '@solana/codecs-core';\nimport { getStructDecoder, getStructEncoder, getArrayEncoder, getArrayDecoder, getBytesEncoder, getBytesDecoder } from '@solana/codecs-data-structures';\nimport { getShortU16Encoder, getShortU16Decoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';\nimport { pipe } from '@solana/functional';\nimport { signBytes } from '@solana/keys';\n\n// src/blockhash.ts\n\n// src/unsigned-transaction.ts\nfunction getUnsignedTransaction(transaction) {\n if (\"signatures\" in transaction) {\n const {\n signatures: _,\n // eslint-disable-line @typescript-eslint/no-unused-vars\n ...unsignedTransaction\n } = transaction;\n return unsignedTransaction;\n } else {\n return transaction;\n }\n}\n\n// src/blockhash.ts\nvar base58Encoder;\nfunction assertIsBlockhash(putativeBlockhash) {\n if (!base58Encoder)\n base58Encoder = getBase58Encoder();\n try {\n if (\n // Lowest value (32 bytes of zeroes)\n putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)\n putativeBlockhash.length > 44\n ) {\n throw new Error(\"Expected input string to decode to a byte array of length 32.\");\n }\n const bytes = base58Encoder.encode(putativeBlockhash);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBlockhash}\\` is not a blockhash`, {\n cause: e\n });\n }\n}\nfunction isTransactionWithBlockhashLifetime(transaction) {\n const lifetimeConstraintShapeMatches = \"lifetimeConstraint\" in transaction && typeof transaction.lifetimeConstraint.blockhash === \"string\" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === \"bigint\";\n if (!lifetimeConstraintShapeMatches)\n return false;\n try {\n assertIsBlockhash(transaction.lifetimeConstraint.blockhash);\n return true;\n } catch {\n return false;\n }\n}\nfunction assertIsTransactionWithBlockhashLifetime(transaction) {\n if (!isTransactionWithBlockhashLifetime(transaction)) {\n throw new Error(\"Transaction does not have a blockhash lifetime\");\n }\n}\nfunction setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {\n if (\"lifetimeConstraint\" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {\n return transaction;\n }\n const out = {\n ...getUnsignedTransaction(transaction),\n lifetimeConstraint: blockhashLifetimeConstraint\n };\n Object.freeze(out);\n return out;\n}\n\n// src/create-transaction.ts\nfunction createTransaction({\n version\n}) {\n const out = {\n instructions: [],\n version\n };\n Object.freeze(out);\n return out;\n}\n\n// ../instructions/dist/index.browser.js\nvar AccountRole = /* @__PURE__ */ ((AccountRole2) => {\n AccountRole2[AccountRole2[\"WRITABLE_SIGNER\"] = /* 3 */\n 3] = \"WRITABLE_SIGNER\";\n AccountRole2[AccountRole2[\"READONLY_SIGNER\"] = /* 2 */\n 2] = \"READONLY_SIGNER\";\n AccountRole2[AccountRole2[\"WRITABLE\"] = /* 1 */\n 1] = \"WRITABLE\";\n AccountRole2[AccountRole2[\"READONLY\"] = /* 0 */\n 0] = \"READONLY\";\n return AccountRole2;\n})(AccountRole || {});\nvar IS_WRITABLE_BITMASK = 1;\nfunction isSignerRole(role) {\n return role >= 2;\n}\nfunction isWritableRole(role) {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\nfunction mergeRoles(roleA, roleB) {\n return roleA | roleB;\n}\n\n// src/durable-nonce.ts\nvar RECENT_BLOCKHASHES_SYSVAR_ADDRESS = \"SysvarRecentB1ockHashes11111111111111111111\";\nvar SYSTEM_PROGRAM_ADDRESS = \"11111111111111111111111111111111\";\nfunction assertIsDurableNonceTransaction(transaction) {\n if (!isDurableNonceTransaction(transaction)) {\n throw new Error(\"Transaction is not a durable nonce transaction\");\n }\n}\nfunction createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {\n return {\n accounts: [\n { address: nonceAccountAddress, role: AccountRole.WRITABLE },\n {\n address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,\n role: AccountRole.READONLY\n },\n { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }\n ],\n data: new Uint8Array([4, 0, 0, 0]),\n programAddress: SYSTEM_PROGRAM_ADDRESS\n };\n}\nfunction isAdvanceNonceAccountInstruction(instruction) {\n return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data\n instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts\n instruction.accounts?.length === 3 && // First account is nonce account address\n instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar\n instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account\n instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);\n}\nfunction isAdvanceNonceAccountInstructionData(data) {\n return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;\n}\nfunction isDurableNonceTransaction(transaction) {\n return \"lifetimeConstraint\" in transaction && typeof transaction.lifetimeConstraint.nonce === \"string\" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);\n}\nfunction isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {\n return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;\n}\nfunction setTransactionLifetimeUsingDurableNonce({\n nonce,\n nonceAccountAddress,\n nonceAuthorityAddress\n}, transaction) {\n let newInstructions;\n const firstInstruction = transaction.instructions[0];\n if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {\n if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {\n if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {\n return transaction;\n } else {\n newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];\n }\n } else {\n newInstructions = [\n createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),\n ...transaction.instructions.slice(1)\n ];\n }\n } else {\n newInstructions = [\n createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),\n ...transaction.instructions\n ];\n }\n const out = {\n ...getUnsignedTransaction(transaction),\n instructions: newInstructions,\n lifetimeConstraint: {\n nonce\n }\n };\n Object.freeze(out);\n return out;\n}\n\n// src/fee-payer.ts\nfunction setTransactionFeePayer(feePayer, transaction) {\n if (\"feePayer\" in transaction && feePayer === transaction.feePayer) {\n return transaction;\n }\n const out = {\n ...getUnsignedTransaction(transaction),\n feePayer\n };\n Object.freeze(out);\n return out;\n}\n\n// src/instructions.ts\nfunction appendTransactionInstruction(instruction, transaction) {\n const out = {\n ...getUnsignedTransaction(transaction),\n instructions: [...transaction.instructions, instruction]\n };\n Object.freeze(out);\n return out;\n}\nfunction prependTransactionInstruction(instruction, transaction) {\n const out = {\n ...getUnsignedTransaction(transaction),\n instructions: [instruction, ...transaction.instructions]\n };\n Object.freeze(out);\n return out;\n}\nfunction upsert(addressMap, address, update) {\n addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });\n}\nvar TYPE = Symbol(\"AddressMapTypeProperty\");\nfunction getAddressMapFromInstructions(feePayer, instructions) {\n const addressMap = {\n [feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER }\n };\n const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();\n for (const instruction of instructions) {\n upsert(addressMap, instruction.programAddress, (entry) => {\n addressesOfInvokedPrograms.add(instruction.programAddress);\n if (TYPE in entry) {\n if (isWritableRole(entry.role)) {\n switch (entry[TYPE]) {\n case 0 /* FEE_PAYER */:\n throw new Error(\n `This transaction includes an address (\\`${instruction.programAddress}\\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`\n );\n default:\n throw new Error(\n `This transaction includes an address (\\`${instruction.programAddress}\\`) which is both invoked and marked writable. Program addresses may not be writable.`\n );\n }\n }\n if (entry[TYPE] === 2 /* STATIC */) {\n return entry;\n }\n }\n return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY };\n });\n let addressComparator;\n if (!instruction.accounts) {\n continue;\n }\n for (const account of instruction.accounts) {\n upsert(addressMap, account.address, (entry) => {\n const {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n address: _,\n ...accountMeta\n } = account;\n if (TYPE in entry) {\n switch (entry[TYPE]) {\n case 0 /* FEE_PAYER */:\n return entry;\n case 1 /* LOOKUP_TABLE */: {\n const nextRole = mergeRoles(entry.role, accountMeta.role);\n if (\"lookupTableAddress\" in accountMeta) {\n const shouldReplaceEntry = (\n // Consider using the new LOOKUP_TABLE if its address is different...\n entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.\n (addressComparator ||= getAddressComparator())(\n accountMeta.lookupTableAddress,\n entry.lookupTableAddress\n ) < 0\n );\n if (shouldReplaceEntry) {\n return {\n [TYPE]: 1 /* LOOKUP_TABLE */,\n ...accountMeta,\n role: nextRole\n };\n }\n } else if (isSignerRole(accountMeta.role)) {\n return {\n [TYPE]: 2 /* STATIC */,\n role: nextRole\n };\n }\n if (entry.role !== nextRole) {\n return {\n ...entry,\n role: nextRole\n };\n } else {\n return entry;\n }\n }\n case 2 /* STATIC */: {\n const nextRole = mergeRoles(entry.role, accountMeta.role);\n if (\n // Check to see if this address represents a program that is invoked\n // in this transaction.\n addressesOfInvokedPrograms.has(account.address)\n ) {\n if (isWritableRole(accountMeta.role)) {\n throw new Error(\n `This transaction includes an address (\\`${account.address}\\`) which is both invoked and marked writable. Program addresses may not be writable.`\n );\n }\n if (entry.role !== nextRole) {\n return {\n ...entry,\n role: nextRole\n };\n } else {\n return entry;\n }\n } else if (\"lookupTableAddress\" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as\n // long as they are not require to sign the transaction.\n !isSignerRole(entry.role)) {\n return {\n ...accountMeta,\n [TYPE]: 1 /* LOOKUP_TABLE */,\n role: nextRole\n };\n } else {\n if (entry.role !== nextRole) {\n return {\n ...entry,\n role: nextRole\n };\n } else {\n return entry;\n }\n }\n }\n }\n }\n if (\"lookupTableAddress\" in accountMeta) {\n return {\n ...accountMeta,\n [TYPE]: 1 /* LOOKUP_TABLE */\n };\n } else {\n return {\n ...accountMeta,\n [TYPE]: 2 /* STATIC */\n };\n }\n });\n }\n }\n return addressMap;\n}\nfunction getOrderedAccountsFromAddressMap(addressMap) {\n let addressComparator;\n const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {\n if (leftEntry[TYPE] !== rightEntry[TYPE]) {\n if (leftEntry[TYPE] === 0 /* FEE_PAYER */) {\n return -1;\n } else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) {\n return 1;\n } else if (leftEntry[TYPE] === 2 /* STATIC */) {\n return -1;\n } else if (rightEntry[TYPE] === 2 /* STATIC */) {\n return 1;\n }\n }\n const leftIsSigner = isSignerRole(leftEntry.role);\n if (leftIsSigner !== isSignerRole(rightEntry.role)) {\n return leftIsSigner ? -1 : 1;\n }\n const leftIsWritable = isWritableRole(leftEntry.role);\n if (leftIsWritable !== isWritableRole(rightEntry.role)) {\n return leftIsWritable ? -1 : 1;\n }\n addressComparator ||= getAddressComparator();\n if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {\n return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);\n } else {\n return addressComparator(leftAddress, rightAddress);\n }\n }).map(([address, addressMeta]) => ({\n address,\n ...addressMeta\n }));\n return orderedAccounts;\n}\nfunction getCompiledAddressTableLookups(orderedAccounts) {\n const index = {};\n for (const account of orderedAccounts) {\n if (!(\"lookupTableAddress\" in account)) {\n continue;\n }\n const entry = index[account.lookupTableAddress] ||= {\n readableIndices: [],\n writableIndices: []\n };\n if (account.role === AccountRole.WRITABLE) {\n entry.writableIndices.push(account.addressIndex);\n } else {\n entry.readableIndices.push(account.addressIndex);\n }\n }\n return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({\n lookupTableAddress,\n ...index[lookupTableAddress]\n }));\n}\n\n// src/compile-header.ts\nfunction getCompiledMessageHeader(orderedAccounts) {\n let numReadonlyNonSignerAccounts = 0;\n let numReadonlySignerAccounts = 0;\n let numSignerAccounts = 0;\n for (const account of orderedAccounts) {\n if (\"lookupTableAddress\" in account) {\n break;\n }\n const accountIsWritable = isWritableRole(account.role);\n if (isSignerRole(account.role)) {\n numSignerAccounts++;\n if (!accountIsWritable) {\n numReadonlySignerAccounts++;\n }\n } else if (!accountIsWritable) {\n numReadonlyNonSignerAccounts++;\n }\n }\n return {\n numReadonlyNonSignerAccounts,\n numReadonlySignerAccounts,\n numSignerAccounts\n };\n}\n\n// src/compile-instructions.ts\nfunction getAccountIndex(orderedAccounts) {\n const out = {};\n for (const [index, account] of orderedAccounts.entries()) {\n out[account.address] = index;\n }\n return out;\n}\nfunction getCompiledInstructions(instructions, orderedAccounts) {\n const accountIndex = getAccountIndex(orderedAccounts);\n return instructions.map(({ accounts, data, programAddress }) => {\n return {\n programAddressIndex: accountIndex[programAddress],\n ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,\n ...data ? { data } : null\n };\n });\n}\n\n// src/compile-lifetime-token.ts\nfunction getCompiledLifetimeToken(lifetimeConstraint) {\n if (\"nonce\" in lifetimeConstraint) {\n return lifetimeConstraint.nonce;\n }\n return lifetimeConstraint.blockhash;\n}\n\n// src/compile-static-accounts.ts\nfunction getCompiledStaticAccounts(orderedAccounts) {\n const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => \"lookupTableAddress\" in account);\n const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);\n return orderedStaticAccounts.map(({ address }) => address);\n}\n\n// src/message.ts\nfunction compileMessage(transaction) {\n const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);\n const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);\n return {\n ...transaction.version !== \"legacy\" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,\n header: getCompiledMessageHeader(orderedAccounts),\n instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),\n lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),\n staticAccounts: getCompiledStaticAccounts(orderedAccounts),\n version: transaction.version\n };\n}\nvar memoizedAddressTableLookupEncoder;\nfunction getAddressTableLookupEncoder() {\n if (!memoizedAddressTableLookupEncoder) {\n memoizedAddressTableLookupEncoder = getStructEncoder([\n [\"lookupTableAddress\", getAddressEncoder()],\n [\n \"writableIndices\",\n getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })\n ],\n [\n \"readableIndices\",\n getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })\n ]\n ]);\n }\n return memoizedAddressTableLookupEncoder;\n}\nvar memoizedAddressTableLookupDecoder;\nfunction getAddressTableLookupDecoder() {\n if (!memoizedAddressTableLookupDecoder) {\n memoizedAddressTableLookupDecoder = getStructDecoder([\n [\"lookupTableAddress\", getAddressDecoder()],\n [\"writableIndices\", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],\n [\"readableIndices\", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })]\n ]);\n }\n return memoizedAddressTableLookupDecoder;\n}\nvar memoizedU8Encoder;\nfunction getMemoizedU8Encoder() {\n if (!memoizedU8Encoder)\n memoizedU8Encoder = getU8Encoder();\n return memoizedU8Encoder;\n}\nvar memoizedU8Decoder;\nfunction getMemoizedU8Decoder() {\n if (!memoizedU8Decoder)\n memoizedU8Decoder = getU8Decoder();\n return memoizedU8Decoder;\n}\nfunction getMessageHeaderEncoder() {\n return getStructEncoder([\n [\"numSignerAccounts\", getMemoizedU8Encoder()],\n [\"numReadonlySignerAccounts\", getMemoizedU8Encoder()],\n [\"numReadonlyNonSignerAccounts\", getMemoizedU8Encoder()]\n ]);\n}\nfunction getMessageHeaderDecoder() {\n return getStructDecoder([\n [\"numSignerAccounts\", getMemoizedU8Decoder()],\n [\"numReadonlySignerAccounts\", getMemoizedU8Decoder()],\n [\"numReadonlyNonSignerAccounts\", getMemoizedU8Decoder()]\n ]);\n}\nvar memoizedGetInstructionEncoder;\nfunction getInstructionEncoder() {\n if (!memoizedGetInstructionEncoder) {\n memoizedGetInstructionEncoder = mapEncoder(\n getStructEncoder([\n [\"programAddressIndex\", getU8Encoder()],\n [\"accountIndices\", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],\n [\"data\", getBytesEncoder({ size: getShortU16Encoder() })]\n ]),\n // Convert an instruction to have all fields defined\n (instruction) => {\n if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {\n return instruction;\n }\n return {\n ...instruction,\n accountIndices: instruction.accountIndices ?? [],\n data: instruction.data ?? new Uint8Array(0)\n };\n }\n );\n }\n return memoizedGetInstructionEncoder;\n}\nvar memoizedGetInstructionDecoder;\nfunction getInstructionDecoder() {\n if (!memoizedGetInstructionDecoder) {\n memoizedGetInstructionDecoder = mapDecoder(\n getStructDecoder([\n [\"programAddressIndex\", getU8Decoder()],\n [\"accountIndices\", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],\n [\"data\", getBytesDecoder({ size: getShortU16Decoder() })]\n ]),\n // Convert an instruction to exclude optional fields if they are empty\n (instruction) => {\n if (instruction.accountIndices.length && instruction.data.byteLength) {\n return instruction;\n }\n const { accountIndices, data, ...rest } = instruction;\n return {\n ...rest,\n ...accountIndices.length ? { accountIndices } : null,\n ...data.byteLength ? { data } : null\n };\n }\n );\n }\n return memoizedGetInstructionDecoder;\n}\nvar VERSION_FLAG_MASK = 128;\nfunction getTransactionVersionEncoder() {\n return createEncoder({\n getSizeFromValue: (value) => value === \"legacy\" ? 0 : 1,\n maxSize: 1,\n write: (value, bytes, offset) => {\n if (value === \"legacy\") {\n return offset;\n }\n if (value < 0 || value > 127) {\n throw new Error(`Transaction version must be in the range [0, 127]. \\`${value}\\` given.`);\n }\n bytes.set([value | VERSION_FLAG_MASK], offset);\n return offset + 1;\n }\n });\n}\nfunction getTransactionVersionDecoder() {\n return createDecoder({\n maxSize: 1,\n read: (bytes, offset) => {\n const firstByte = bytes[offset];\n if ((firstByte & VERSION_FLAG_MASK) === 0) {\n return [\"legacy\", offset];\n } else {\n const version = firstByte ^ VERSION_FLAG_MASK;\n return [version, offset + 1];\n }\n }\n });\n}\n\n// src/serializers/message.ts\nfunction getCompiledMessageLegacyEncoder() {\n return getStructEncoder(getPreludeStructEncoderTuple());\n}\nfunction getCompiledMessageVersionedEncoder() {\n return mapEncoder(\n getStructEncoder([\n ...getPreludeStructEncoderTuple(),\n [\"addressTableLookups\", getAddressTableLookupArrayEncoder()]\n ]),\n (value) => {\n if (value.version === \"legacy\") {\n return value;\n }\n return {\n ...value,\n addressTableLookups: value.addressTableLookups ?? []\n };\n }\n );\n}\nfunction getPreludeStructEncoderTuple() {\n return [\n [\"version\", getTransactionVersionEncoder()],\n [\"header\", getMessageHeaderEncoder()],\n [\"staticAccounts\", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],\n [\"lifetimeToken\", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],\n [\"instructions\", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]\n ];\n}\nfunction getPreludeStructDecoderTuple() {\n return [\n [\"version\", getTransactionVersionDecoder()],\n [\"header\", getMessageHeaderDecoder()],\n [\"staticAccounts\", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],\n [\"lifetimeToken\", getStringDecoder({ encoding: getBase58Decoder(), size: 32 })],\n [\"instructions\", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],\n [\"addressTableLookups\", getAddressTableLookupArrayDecoder()]\n ];\n}\nfunction getAddressTableLookupArrayEncoder() {\n return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });\n}\nfunction getAddressTableLookupArrayDecoder() {\n return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });\n}\nfunction getCompiledMessageEncoder() {\n return createEncoder({\n getSizeFromValue: (compiledMessage) => {\n if (compiledMessage.version === \"legacy\") {\n return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);\n } else {\n return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);\n }\n },\n write: (compiledMessage, bytes, offset) => {\n if (compiledMessage.version === \"legacy\") {\n return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);\n } else {\n return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);\n }\n }\n });\n}\nfunction getCompiledMessageDecoder() {\n return mapDecoder(getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {\n if (restOfMessage.version === \"legacy\" || !addressTableLookups?.length) {\n return restOfMessage;\n }\n return { ...restOfMessage, addressTableLookups };\n });\n}\nfunction getCompiledMessageCodec() {\n return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());\n}\n\n// src/compile-transaction.ts\nfunction getCompiledTransaction(transaction) {\n const compiledMessage = compileMessage(transaction);\n let signatures;\n if (\"signatures\" in transaction) {\n signatures = [];\n for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {\n signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));\n }\n } else {\n signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));\n }\n return {\n compiledMessage,\n signatures\n };\n}\nfunction getAccountMetas(message) {\n const { header } = message;\n const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;\n const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;\n const accountMetas = [];\n let accountIndex = 0;\n for (let i = 0; i < numWritableSignerAccounts; i++) {\n accountMetas.push({\n address: message.staticAccounts[accountIndex],\n role: AccountRole.WRITABLE_SIGNER\n });\n accountIndex++;\n }\n for (let i = 0; i < header.numReadonlySignerAccounts; i++) {\n accountMetas.push({\n address: message.staticAccounts[accountIndex],\n role: AccountRole.READONLY_SIGNER\n });\n accountIndex++;\n }\n for (let i = 0; i < numWritableNonSignerAccounts; i++) {\n accountMetas.push({\n address: message.staticAccounts[accountIndex],\n role: AccountRole.WRITABLE\n });\n accountIndex++;\n }\n for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {\n accountMetas.push({\n address: message.staticAccounts[accountIndex],\n role: AccountRole.READONLY\n });\n accountIndex++;\n }\n return accountMetas;\n}\nfunction convertInstruction(instruction, accountMetas) {\n const programAddress = accountMetas[instruction.programAddressIndex]?.address;\n if (!programAddress) {\n throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);\n }\n const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);\n const { data } = instruction;\n return {\n programAddress,\n ...accounts && accounts.length ? { accounts } : {},\n ...data && data.length ? { data } : {}\n };\n}\nfunction getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {\n if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {\n return {\n blockhash: messageLifetimeToken,\n lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n\n // U64 MAX\n };\n } else {\n const nonceAccountAddress = firstInstruction.accounts[0].address;\n assertIsAddress(nonceAccountAddress);\n const nonceAuthorityAddress = firstInstruction.accounts[2].address;\n assertIsAddress(nonceAuthorityAddress);\n return {\n nonce: messageLifetimeToken,\n nonceAccountAddress,\n nonceAuthorityAddress\n };\n }\n}\nfunction convertSignatures(compiledTransaction) {\n const {\n compiledMessage: { staticAccounts },\n signatures\n } = compiledTransaction;\n return signatures.reduce((acc, sig, index) => {\n const allZeros = sig.every((byte) => byte === 0);\n if (allZeros)\n return acc;\n const address = staticAccounts[index];\n return { ...acc, [address]: sig };\n }, {});\n}\nfunction decompileTransaction(compiledTransaction, lastValidBlockHeight) {\n const { compiledMessage } = compiledTransaction;\n if (\"addressTableLookups\" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {\n throw new Error(\"Cannot convert transaction with addressTableLookups\");\n }\n const feePayer = compiledMessage.staticAccounts[0];\n if (!feePayer)\n throw new Error(\"No fee payer set in CompiledTransaction\");\n const accountMetas = getAccountMetas(compiledMessage);\n const instructions = compiledMessage.instructions.map(\n (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)\n );\n const firstInstruction = instructions[0];\n const lifetimeConstraint = getLifetimeConstraint(\n compiledMessage.lifetimeToken,\n firstInstruction,\n lastValidBlockHeight\n );\n const signatures = convertSignatures(compiledTransaction);\n return pipe(\n createTransaction({ version: compiledMessage.version }),\n (tx) => setTransactionFeePayer(feePayer, tx),\n (tx) => instructions.reduce((acc, instruction) => {\n return appendTransactionInstruction(instruction, acc);\n }, tx),\n (tx) => \"blockhash\" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),\n (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx\n );\n}\n\n// src/serializers/transaction.ts\nfunction getCompiledTransactionEncoder() {\n return getStructEncoder([\n [\"signatures\", getArrayEncoder(getBytesEncoder({ size: 64 }), { size: getShortU16Encoder() })],\n [\"compiledMessage\", getCompiledMessageEncoder()]\n ]);\n}\nfunction getCompiledTransactionDecoder() {\n return getStructDecoder([\n [\n \"signatures\",\n getArrayDecoder(getBytesDecoder({ size: 64 }), {\n size: getShortU16Decoder()\n })\n ],\n [\"compiledMessage\", getCompiledMessageDecoder()]\n ]);\n}\nfunction getTransactionEncoder() {\n return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);\n}\nfunction getTransactionDecoder(lastValidBlockHeight) {\n return mapDecoder(\n getCompiledTransactionDecoder(),\n (compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)\n );\n}\nfunction getTransactionCodec(lastValidBlockHeight) {\n return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));\n}\nvar base58Decoder;\nfunction getSignatureFromTransaction(transaction) {\n if (!base58Decoder)\n base58Decoder = getBase58Decoder();\n const signatureBytes = transaction.signatures[transaction.feePayer];\n if (!signatureBytes) {\n throw new Error(\n \"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer.\"\n );\n }\n const transactionSignature = base58Decoder.decode(signatureBytes);\n return transactionSignature;\n}\nasync function partiallySignTransaction(keyPairs, transaction) {\n const compiledMessage = compileMessage(transaction);\n const nextSignatures = \"signatures\" in transaction ? { ...transaction.signatures } : {};\n const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);\n const publicKeySignaturePairs = await Promise.all(\n keyPairs.map(\n (keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])\n )\n );\n for (const [signerPublicKey, signature] of publicKeySignaturePairs) {\n nextSignatures[signerPublicKey] = signature;\n }\n const out = {\n ...transaction,\n signatures: nextSignatures\n };\n Object.freeze(out);\n return out;\n}\nasync function signTransaction(keyPairs, transaction) {\n const out = await partiallySignTransaction(keyPairs, transaction);\n assertTransactionIsFullySigned(out);\n Object.freeze(out);\n return out;\n}\nfunction assertTransactionIsFullySigned(transaction) {\n const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);\n const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);\n requiredSigners.forEach((address) => {\n if (!transaction.signatures[address]) {\n throw new Error(`Transaction is missing signature for address \\`${address}\\``);\n }\n });\n}\nfunction getBase64EncodedWireTransaction(transaction) {\n const wireTransactionBytes = getTransactionEncoder().encode(transaction);\n return getBase64Decoder().decode(wireTransactionBytes);\n}\n\nexport { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionWithBlockhashLifetime, assertTransactionIsFullySigned, compileMessage, createTransaction, getBase64EncodedWireTransaction, getCompiledMessageCodec, getCompiledMessageDecoder, getCompiledMessageEncoder, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, partiallySignTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };\n","import { type Address, assertIsAddress } from '@solana/addresses';\nimport { pipe } from '@solana/functional';\nimport type { IAccountMeta, IInstruction } from '@solana/instructions';\nimport { AccountRole } from '@solana/instructions';\nimport type { SignatureBytes } from '@solana/keys';\nimport {\n appendTransactionInstruction,\n type Blockhash,\n createTransaction,\n type IDurableNonceTransaction,\n isAdvanceNonceAccountInstruction,\n type ITransactionWithBlockhashLifetime,\n type ITransactionWithFeePayer,\n type ITransactionWithSignatures,\n type Nonce,\n setTransactionFeePayer,\n setTransactionLifetimeUsingBlockhash,\n setTransactionLifetimeUsingDurableNonce,\n type Transaction,\n} from '@solana/transactions';\nimport type {\n MessageAccountKeys,\n MessageCompiledInstruction,\n PublicKey,\n VersionedMessage,\n VersionedTransaction,\n} from '@solana/web3.js';\n\nfunction convertAccount(\n message: VersionedMessage,\n accountKeys: MessageAccountKeys,\n accountIndex: number,\n): IAccountMeta {\n const accountPublicKey = accountKeys.get(accountIndex);\n if (!accountPublicKey) {\n // TODO coded error\n throw new Error(`Could not find account address at index ${accountIndex}`);\n }\n const isSigner = message.isAccountSigner(accountIndex);\n const isWritable = message.isAccountWritable(accountIndex);\n\n const role = isSigner\n ? isWritable\n ? AccountRole.WRITABLE_SIGNER\n : AccountRole.READONLY_SIGNER\n : isWritable\n ? AccountRole.WRITABLE\n : AccountRole.READONLY;\n\n return {\n address: accountPublicKey.toBase58() as Address,\n role,\n };\n}\n\nfunction convertInstruction(\n message: VersionedMessage,\n accountKeys: MessageAccountKeys,\n instruction: MessageCompiledInstruction,\n): IInstruction {\n const programAddressPublicKey = accountKeys.get(instruction.programIdIndex);\n if (!programAddressPublicKey) {\n // TODO coded error\n throw new Error(`Could not find program address at index ${instruction.programIdIndex}`);\n }\n\n const accounts = instruction.accountKeyIndexes.map(accountIndex =>\n convertAccount(message, accountKeys, accountIndex),\n );\n\n return {\n programAddress: programAddressPublicKey.toBase58() as Address,\n ...(accounts.length ? { accounts } : {}),\n ...(instruction.data.length ? { data: instruction.data } : {}),\n };\n}\n\nfunction convertSignatures(\n transaction: VersionedTransaction,\n staticAccountKeys: PublicKey[],\n): ITransactionWithSignatures['signatures'] {\n return transaction.signatures.reduce((acc, sig, index) => {\n // legacy web3js includes a fake all 0 signature if it hasn't been signed\n // we don't do that for the new tx model. So just skip if it's all 0s\n const allZeros = sig.every(byte => byte === 0);\n if (allZeros) return acc;\n\n const address = staticAccountKeys[index].toBase58() as Address;\n return { ...acc, [address]: sig as SignatureBytes };\n }, {});\n}\n\nexport function fromVersionedTransactionWithBlockhash(\n transaction: VersionedTransaction,\n lastValidBlockHeight?: bigint,\n): Transaction & ITransactionWithFeePayer & ITransactionWithBlockhashLifetime {\n // TODO: add support for address table lookups\n // - will need to take `AddressLookupTableAccounts[]` as input\n // - will need to convert account instructions to `IAccountLookupMeta` when appropriate\n if (transaction.message.addressTableLookups.length > 0) {\n // TODO coded error\n throw new Error('Cannot convert transaction with addressTableLookups');\n }\n\n const accountKeys = transaction.message.getAccountKeys();\n\n // Fee payer is first account\n const feePayer = accountKeys.staticAccountKeys[0];\n // TODO: coded error\n if (!feePayer) throw new Error('No fee payer set in VersionedTransaction');\n\n const blockhashLifetime = {\n blockhash: transaction.message.recentBlockhash as Blockhash,\n lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n, // U64 MAX\n };\n\n const instructions = transaction.message.compiledInstructions.map(instruction =>\n convertInstruction(transaction.message, accountKeys, instruction),\n );\n\n const signatures = convertSignatures(transaction, accountKeys.staticAccountKeys);\n\n return pipe(\n createTransaction({ version: transaction.version }),\n tx => setTransactionFeePayer(feePayer.toBase58() as Address, tx),\n tx => setTransactionLifetimeUsingBlockhash(blockhashLifetime, tx),\n tx =>\n instructions.reduce((acc, instruction) => {\n return appendTransactionInstruction(instruction, acc);\n }, tx),\n tx => (transaction.signatures.length ? { ...tx, signatures } : tx),\n );\n}\n\nexport function fromVersionedTransactionWithDurableNonce(\n transaction: VersionedTransaction,\n): Transaction & ITransactionWithFeePayer & IDurableNonceTransaction {\n // TODO: add support for address table lookups\n // - will need to take `AddressLookupTableAccounts[]` as input\n // - will need to convert account instructions to `IAccountLookupMeta` when appropriate\n if (transaction.message.addressTableLookups.length > 0) {\n // TODO coded error\n throw new Error('Cannot convert transaction with addressTableLookups');\n }\n\n const accountKeys = transaction.message.getAccountKeys();\n\n // Fee payer is first account\n const feePayer = accountKeys.staticAccountKeys[0];\n // TODO: coded error\n if (!feePayer) throw new Error('No fee payer set in VersionedTransaction');\n\n const instructions = transaction.message.compiledInstructions.map(instruction =>\n convertInstruction(transaction.message, accountKeys, instruction),\n );\n\n // Check first instruction is durable nonce + extract params\n if (instructions.length === 0) {\n // TODO: coded error\n throw new Error('transaction with no instructions cannot be durable nonce transaction');\n }\n\n if (!isAdvanceNonceAccountInstruction(instructions[0])) {\n // TODO: coded error\n throw new Error('transaction first instruction is not advance nonce account instruction');\n }\n\n // We know these accounts are defined because we checked `isAdvanceNonceAccountInstruction`\n const nonceAccountAddress = instructions[0].accounts![0].address;\n assertIsAddress(nonceAccountAddress);\n\n const nonceAuthorityAddress = instructions[0].accounts![2].address;\n assertIsAddress(nonceAuthorityAddress);\n\n const durableNonceLifetime = {\n nonce: transaction.message.recentBlockhash as Nonce,\n nonceAccountAddress,\n nonceAuthorityAddress,\n };\n\n const signatures = convertSignatures(transaction, accountKeys.staticAccountKeys);\n\n return pipe(\n createTransaction({ version: transaction.version }),\n tx => setTransactionFeePayer(feePayer.toBase58() as Address, tx),\n tx => setTransactionLifetimeUsingDurableNonce(durableNonceLifetime, tx),\n tx =>\n instructions.slice(1).reduce((acc, instruction) => {\n return appendTransactionInstruction(instruction, acc);\n }, tx),\n tx => (transaction.signatures.length ? { ...tx, signatures } : tx),\n );\n}\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
function Y(e){return e.toBase58()}function w(e,r){return "fixedSize"in r?r.fixedSize:r.getSizeFromValue(e)}function S(e){return Object.freeze({...e,encode:r=>{let n=new Uint8Array(w(r,e));return e.write(r,n,0),n}})}function P(e,r,n=r){if(!r.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${n}].`)}var K=e=>S({getSizeFromValue:r=>{let[n,t]=I(r,e[0]);if(t==="")return r.length;let o=T(t,e);return n.length+Math.ceil(o.toString(16).length/2)},write(r,n,t){if(P(e,r),r==="")return t;let[o,s]=I(r,e[0]);if(s==="")return n.set(new Uint8Array(o.length).fill(0),t),t+o.length;let a=T(s,e),i=[];for(;a>0n;)i.unshift(Number(a%256n)),a/=256n;let c=[...Array(o.length).fill(0),...i];return n.set(c,t),t+c.length}});function I(e,r){let n=[...e].findIndex(t=>t!==r);return n===-1?[e,""]:[e.slice(0,n),e.slice(n)]}function T(e,r){let n=BigInt(r.length);return [...e].reduce((t,o)=>t*n+BigInt(r.indexOf(o)),0n)}var M="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",v=()=>K(M);function _(e){return new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32,...e])}async function B(e,r){if(e.byteLength!==32)throw new Error("Private key bytes must be of length 32");let n=_(e);return await crypto.subtle.importKey("pkcs8",n,"Ed25519",r!=null?r:!1,["sign"])}async function le(e,r){let[n,t]=await Promise.all([crypto.subtle.importKey("raw",e.publicKey.toBytes(),"Ed25519",!0,["verify"]),B(e.secretKey.slice(0,32),r)]);return {privateKey:t,publicKey:n}}var h;function O(){return h||(h=v()),h}function p(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let t=O().encode(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(r){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:r})}}function y(e,...r){return r.reduce((n,t)=>t(n),e)}var u=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(u||{});function g(e){if("signatures"in e){let{signatures:r,...n}=e;return n}else return e}function x(e,r){if("lifetimeConstraint"in r&&r.lifetimeConstraint.blockhash===e.blockhash&&r.lifetimeConstraint.lastValidBlockHeight===e.lastValidBlockHeight)return r;let n={...g(r),lifetimeConstraint:e};return Object.freeze(n),n}function A({version:e}){let r={instructions:[],version:e};return Object.freeze(r),r}var l=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(l||{});function F(e){return e>=2}var C="SysvarRecentB1ockHashes11111111111111111111",D="11111111111111111111111111111111";function z(e,r){return {accounts:[{address:e,role:l.WRITABLE},{address:C,role:l.READONLY},{address:r,role:l.READONLY_SIGNER}],data:new Uint8Array([4,0,0,0]),programAddress:D}}function f(e){var r;return e.programAddress===D&&e.data!=null&&W(e.data)&&((r=e.accounts)==null?void 0:r.length)===3&&e.accounts[0].address!=null&&e.accounts[0].role===l.WRITABLE&&e.accounts[1].address===C&&e.accounts[1].role===l.READONLY&&e.accounts[2].address!=null&&F(e.accounts[2].role)}function W(e){return e.byteLength===4&&e[0]===4&&e[1]===0&&e[2]===0&&e[3]===0}function U(e){return "lifetimeConstraint"in e&&typeof e.lifetimeConstraint.nonce=="string"&&e.instructions[0]!=null&&f(e.instructions[0])}function $(e,r,n){return e.accounts[0].address===r&&e.accounts[2].address===n}function L({nonce:e,nonceAccountAddress:r,nonceAuthorityAddress:n},t){let o,s=t.instructions[0];if(s&&f(s))if($(s,r,n)){if(U(t)&&t.lifetimeConstraint.nonce===e)return t;o=[s,...t.instructions.slice(1)];}else o=[z(r,n),...t.instructions.slice(1)];else o=[z(r,n),...t.instructions];let a={...g(t),instructions:o,lifetimeConstraint:{nonce:e}};return Object.freeze(a),a}function E(e,r){if("feePayer"in r&&e===r.feePayer)return r;let n={...g(r),feePayer:e};return Object.freeze(n),n}function b(e,r){let n={...g(r),instructions:[...r.instructions,e]};return Object.freeze(n),n}function V(e,r,n){let t=r.get(n);if(!t)throw new Error(`Could not find account address at index ${n}`);let o=e.isAccountSigner(n),s=e.isAccountWritable(n),a=o?s?u.WRITABLE_SIGNER:u.READONLY_SIGNER:s?u.WRITABLE:u.READONLY;return {address:t.toBase58(),role:a}}function R(e,r,n){let t=r.get(n.programIdIndex);if(!t)throw new Error(`Could not find program address at index ${n.programIdIndex}`);let o=n.accountKeyIndexes.map(s=>V(e,r,s));return {programAddress:t.toBase58(),...o.length?{accounts:o}:{},...n.data.length?{data:n.data}:{}}}function N(e,r){return e.signatures.reduce((n,t,o)=>{if(t.every(i=>i===0))return n;let a=r[o].toBase58();return {...n,[a]:t}},{})}function Le(e,r){if(e.message.addressTableLookups.length>0)throw new Error("Cannot convert transaction with addressTableLookups");let n=e.message.getAccountKeys(),t=n.staticAccountKeys[0];if(!t)throw new Error("No fee payer set in VersionedTransaction");let o={blockhash:e.message.recentBlockhash,lastValidBlockHeight:r!=null?r:2n**64n-1n},s=e.message.compiledInstructions.map(i=>R(e.message,n,i)),a=N(e,n.staticAccountKeys);return y(A({version:e.version}),i=>E(t.toBase58(),i),i=>x(o,i),i=>s.reduce((c,m)=>b(m,c),i),i=>e.signatures.length?{...i,signatures:a}:i)}function Re(e){if(e.message.addressTableLookups.length>0)throw new Error("Cannot convert transaction with addressTableLookups");let r=e.message.getAccountKeys(),n=r.staticAccountKeys[0];if(!n)throw new Error("No fee payer set in VersionedTransaction");let t=e.message.compiledInstructions.map(c=>R(e.message,r,c));if(t.length===0)throw new Error("transaction with no instructions cannot be durable nonce transaction");if(!f(t[0]))throw new Error("transaction first instruction is not advance nonce account instruction");let o=t[0].accounts[0].address;p(o);let s=t[0].accounts[2].address;p(s);let a={nonce:e.message.recentBlockhash,nonceAccountAddress:o,nonceAuthorityAddress:s},i=N(e,r.staticAccountKeys);return y(A({version:e.version}),c=>E(n.toBase58(),c),c=>L(a,c),c=>t.slice(1).reduce((m,k)=>b(k,m),c),c=>e.signatures.length?{...c,signatures:i}:c)}
|
|
6
|
-
|
|
7
|
-
exports.fromLegacyKeypair = le;
|
|
8
|
-
exports.fromLegacyPublicKey = Y;
|
|
9
|
-
exports.fromVersionedTransactionWithBlockhash = Le;
|
|
10
|
-
exports.fromVersionedTransactionWithDurableNonce = Re;
|
|
11
|
-
|
|
12
|
-
return exports;
|
|
13
|
-
|
|
14
|
-
})({});
|