@solana/transactions 2.0.0-experimental.9bf9fdb → 2.0.0-experimental.9e133fd

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.
Files changed (39) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.browser.cjs +815 -41
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +803 -42
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +1784 -41
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +803 -42
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +813 -41
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +803 -42
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +16 -5
  15. package/dist/types/accounts.d.ts +28 -0
  16. package/dist/types/blockhash.d.ts +9 -1
  17. package/dist/types/compile-address-table-lookups.d.ts +10 -0
  18. package/dist/types/compile-header.d.ts +9 -0
  19. package/dist/types/compile-instructions.d.ts +10 -0
  20. package/dist/types/compile-lifetime-token.d.ts +3 -0
  21. package/dist/types/compile-static-accounts.d.ts +4 -0
  22. package/dist/types/compile-transaction.d.ts +11 -0
  23. package/dist/types/durable-nonce.d.ts +20 -7
  24. package/dist/types/fee-payer.d.ts +3 -2
  25. package/dist/types/index.d.ts +2 -0
  26. package/dist/types/message.d.ts +30 -0
  27. package/dist/types/serializers/address-table-lookup.d.ts +6 -0
  28. package/dist/types/serializers/header.d.ts +8 -0
  29. package/dist/types/serializers/index.d.ts +2 -0
  30. package/dist/types/serializers/instruction.d.ts +6 -0
  31. package/dist/types/serializers/message.d.ts +6 -0
  32. package/dist/types/serializers/transaction-version.d.ts +6 -0
  33. package/dist/types/serializers/transaction.d.ts +6 -0
  34. package/dist/types/serializers/unimplemented.d.ts +3 -0
  35. package/dist/types/signatures.d.ts +14 -7
  36. package/dist/types/types.d.ts +7 -0
  37. package/dist/types/unsigned-transaction.d.ts +4 -0
  38. package/dist/types/wire-transaction.d.ts +6 -0
  39. package/package.json +23 -22
@@ -1,5 +1,62 @@
1
1
  'use strict';
2
2
 
3
+ var umiSerializers = require('@metaplex-foundation/umi-serializers');
4
+ var addresses = require('@solana/addresses');
5
+ var codecsDataStructures = require('@solana/codecs-data-structures');
6
+ var codecsNumbers = require('@solana/codecs-numbers');
7
+ var codecsCore = require('@solana/codecs-core');
8
+ var keys = require('@solana/keys');
9
+
10
+ // ../build-scripts/env-shim.ts
11
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
12
+
13
+ // src/unsigned-transaction.ts
14
+ function getUnsignedTransaction(transaction) {
15
+ if ("signatures" in transaction) {
16
+ const {
17
+ signatures: _,
18
+ // eslint-disable-line @typescript-eslint/no-unused-vars
19
+ ...unsignedTransaction
20
+ } = transaction;
21
+ return unsignedTransaction;
22
+ } else {
23
+ return transaction;
24
+ }
25
+ }
26
+
27
+ // src/blockhash.ts
28
+ function assertIsBlockhash(putativeBlockhash) {
29
+ try {
30
+ if (
31
+ // Lowest value (32 bytes of zeroes)
32
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
33
+ putativeBlockhash.length > 44
34
+ ) {
35
+ throw new Error("Expected input string to decode to a byte array of length 32.");
36
+ }
37
+ const bytes3 = umiSerializers.base58.serialize(putativeBlockhash);
38
+ const numBytes = bytes3.byteLength;
39
+ if (numBytes !== 32) {
40
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
41
+ }
42
+ } catch (e) {
43
+ throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
44
+ cause: e
45
+ });
46
+ }
47
+ }
48
+ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
49
+ if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
50
+ return transaction;
51
+ }
52
+ const out = {
53
+ ...getUnsignedTransaction(transaction),
54
+ lifetimeConstraint: blockhashLifetimeConstraint
55
+ };
56
+ Object.freeze(out);
57
+ return out;
58
+ }
59
+
3
60
  // src/create-transaction.ts
4
61
  function createTransaction({
5
62
  version
@@ -12,67 +69,784 @@ function createTransaction({
12
69
  return out;
13
70
  }
14
71
 
72
+ // ../instructions/dist/index.browser.js
73
+ var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
74
+ AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
75
+ 3] = "WRITABLE_SIGNER";
76
+ AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
77
+ 2] = "READONLY_SIGNER";
78
+ AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
79
+ 1] = "WRITABLE";
80
+ AccountRole2[AccountRole2["READONLY"] = /* 0 */
81
+ 0] = "READONLY";
82
+ return AccountRole2;
83
+ })(AccountRole || {});
84
+ var IS_WRITABLE_BITMASK = 1;
85
+ function isSignerRole(role) {
86
+ return role >= 2;
87
+ }
88
+ function isWritableRole(role) {
89
+ return (role & IS_WRITABLE_BITMASK) !== 0;
90
+ }
91
+ function mergeRoles(roleA, roleB) {
92
+ return roleA | roleB;
93
+ }
94
+
95
+ // src/durable-nonce.ts
96
+ var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
97
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
98
+ function assertIsDurableNonceTransaction(transaction) {
99
+ if (!isDurableNonceTransaction(transaction)) {
100
+ throw new Error("Transaction is not a durable nonce transaction");
101
+ }
102
+ }
103
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
104
+ return {
105
+ accounts: [
106
+ { address: nonceAccountAddress, role: AccountRole.WRITABLE },
107
+ {
108
+ address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
109
+ role: AccountRole.READONLY
110
+ },
111
+ { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
112
+ ],
113
+ data: new Uint8Array([4, 0, 0, 0]),
114
+ programAddress: SYSTEM_PROGRAM_ADDRESS
115
+ };
116
+ }
117
+ function isAdvanceNonceAccountInstruction(instruction) {
118
+ return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
119
+ instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
120
+ instruction.accounts?.length === 3 && // First account is nonce account address
121
+ instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
122
+ instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
123
+ instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
124
+ }
125
+ function isAdvanceNonceAccountInstructionData(data) {
126
+ return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
127
+ }
128
+ function isDurableNonceTransaction(transaction) {
129
+ return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
130
+ }
131
+ function setTransactionLifetimeUsingDurableNonce({
132
+ nonce,
133
+ nonceAccountAddress,
134
+ nonceAuthorityAddress
135
+ }, transaction) {
136
+ const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
137
+ if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
138
+ return transaction;
139
+ }
140
+ const out = {
141
+ ...getUnsignedTransaction(transaction),
142
+ instructions: [
143
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
144
+ ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
145
+ ],
146
+ lifetimeConstraint: {
147
+ nonce
148
+ }
149
+ };
150
+ Object.freeze(out);
151
+ return out;
152
+ }
153
+
15
154
  // src/fee-payer.ts
16
155
  function setTransactionFeePayer(feePayer, transaction) {
17
156
  if ("feePayer" in transaction && feePayer === transaction.feePayer) {
18
157
  return transaction;
19
158
  }
20
- let out;
21
- if ("signatures" in transaction) {
22
- const {
23
- signatures: _,
24
- // eslint-disable-line @typescript-eslint/no-unused-vars
25
- ...unsignedTransaction
26
- } = transaction;
27
- out = {
28
- ...unsignedTransaction,
29
- feePayer
30
- };
31
- } else {
32
- out = {
33
- ...transaction,
34
- feePayer
35
- };
36
- }
159
+ const out = {
160
+ ...getUnsignedTransaction(transaction),
161
+ feePayer
162
+ };
37
163
  Object.freeze(out);
38
164
  return out;
39
165
  }
40
166
 
41
167
  // src/instructions.ts
42
- function replaceInstructions(transaction, nextInstructions) {
43
- let out;
44
- if ("signatures" in transaction) {
45
- const {
46
- signatures: _,
47
- // eslint-disable-line @typescript-eslint/no-unused-vars
48
- ...unsignedTransaction
49
- } = transaction;
50
- out = {
51
- ...unsignedTransaction,
52
- instructions: nextInstructions
53
- };
54
- } else {
55
- out = {
56
- ...transaction,
57
- instructions: nextInstructions
58
- };
59
- }
60
- return out;
61
- }
62
168
  function appendTransactionInstruction(instruction, transaction) {
63
- const nextInstructions = [...transaction.instructions, instruction];
64
- const out = replaceInstructions(transaction, nextInstructions);
169
+ const out = {
170
+ ...getUnsignedTransaction(transaction),
171
+ instructions: [...transaction.instructions, instruction]
172
+ };
65
173
  Object.freeze(out);
66
174
  return out;
67
175
  }
68
176
  function prependTransactionInstruction(instruction, transaction) {
69
- const nextInstructions = [instruction, ...transaction.instructions];
70
- const out = replaceInstructions(transaction, nextInstructions);
177
+ const out = {
178
+ ...getUnsignedTransaction(transaction),
179
+ instructions: [instruction, ...transaction.instructions]
180
+ };
181
+ Object.freeze(out);
182
+ return out;
183
+ }
184
+ function upsert(addressMap, address, update) {
185
+ addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
186
+ }
187
+ var TYPE = Symbol("AddressMapTypeProperty");
188
+ function getAddressMapFromInstructions(feePayer, instructions) {
189
+ const addressMap = {
190
+ [feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER }
191
+ };
192
+ const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
193
+ for (const instruction of instructions) {
194
+ upsert(addressMap, instruction.programAddress, (entry) => {
195
+ addressesOfInvokedPrograms.add(instruction.programAddress);
196
+ if (TYPE in entry) {
197
+ if (isWritableRole(entry.role)) {
198
+ switch (entry[TYPE]) {
199
+ case 0 /* FEE_PAYER */:
200
+ throw new Error(
201
+ `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
202
+ );
203
+ default:
204
+ throw new Error(
205
+ `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
206
+ );
207
+ }
208
+ }
209
+ if (entry[TYPE] === 2 /* STATIC */) {
210
+ return entry;
211
+ }
212
+ }
213
+ return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY };
214
+ });
215
+ let addressComparator;
216
+ if (!instruction.accounts) {
217
+ continue;
218
+ }
219
+ for (const account of instruction.accounts) {
220
+ upsert(addressMap, account.address, (entry) => {
221
+ const {
222
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
223
+ address: _,
224
+ ...accountMeta
225
+ } = account;
226
+ if (TYPE in entry) {
227
+ switch (entry[TYPE]) {
228
+ case 0 /* FEE_PAYER */:
229
+ return entry;
230
+ case 1 /* LOOKUP_TABLE */: {
231
+ const nextRole = mergeRoles(entry.role, accountMeta.role);
232
+ if ("lookupTableAddress" in accountMeta) {
233
+ const shouldReplaceEntry = (
234
+ // Consider using the new LOOKUP_TABLE if its address is different...
235
+ entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
236
+ (addressComparator || (addressComparator = addresses.getAddressComparator()))(
237
+ accountMeta.lookupTableAddress,
238
+ entry.lookupTableAddress
239
+ ) < 0
240
+ );
241
+ if (shouldReplaceEntry) {
242
+ return {
243
+ [TYPE]: 1 /* LOOKUP_TABLE */,
244
+ ...accountMeta,
245
+ role: nextRole
246
+ };
247
+ }
248
+ } else if (isSignerRole(accountMeta.role)) {
249
+ return {
250
+ [TYPE]: 2 /* STATIC */,
251
+ role: nextRole
252
+ };
253
+ }
254
+ if (entry.role !== nextRole) {
255
+ return {
256
+ ...entry,
257
+ role: nextRole
258
+ };
259
+ } else {
260
+ return entry;
261
+ }
262
+ }
263
+ case 2 /* STATIC */: {
264
+ const nextRole = mergeRoles(entry.role, accountMeta.role);
265
+ if (
266
+ // Check to see if this address represents a program that is invoked
267
+ // in this transaction.
268
+ addressesOfInvokedPrograms.has(account.address)
269
+ ) {
270
+ if (isWritableRole(accountMeta.role)) {
271
+ throw new Error(
272
+ `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
273
+ );
274
+ }
275
+ if (entry.role !== nextRole) {
276
+ return {
277
+ ...entry,
278
+ role: nextRole
279
+ };
280
+ } else {
281
+ return entry;
282
+ }
283
+ } else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
284
+ // long as they are not require to sign the transaction.
285
+ !isSignerRole(entry.role)) {
286
+ return {
287
+ ...accountMeta,
288
+ [TYPE]: 1 /* LOOKUP_TABLE */,
289
+ role: nextRole
290
+ };
291
+ } else {
292
+ if (entry.role !== nextRole) {
293
+ return {
294
+ ...entry,
295
+ role: nextRole
296
+ };
297
+ } else {
298
+ return entry;
299
+ }
300
+ }
301
+ }
302
+ }
303
+ }
304
+ if ("lookupTableAddress" in accountMeta) {
305
+ return {
306
+ ...accountMeta,
307
+ [TYPE]: 1 /* LOOKUP_TABLE */
308
+ };
309
+ } else {
310
+ return {
311
+ ...accountMeta,
312
+ [TYPE]: 2 /* STATIC */
313
+ };
314
+ }
315
+ });
316
+ }
317
+ }
318
+ return addressMap;
319
+ }
320
+ function getOrderedAccountsFromAddressMap(addressMap) {
321
+ let addressComparator;
322
+ const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
323
+ if (leftEntry[TYPE] !== rightEntry[TYPE]) {
324
+ if (leftEntry[TYPE] === 0 /* FEE_PAYER */) {
325
+ return -1;
326
+ } else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) {
327
+ return 1;
328
+ } else if (leftEntry[TYPE] === 2 /* STATIC */) {
329
+ return -1;
330
+ } else if (rightEntry[TYPE] === 2 /* STATIC */) {
331
+ return 1;
332
+ }
333
+ }
334
+ const leftIsSigner = isSignerRole(leftEntry.role);
335
+ if (leftIsSigner !== isSignerRole(rightEntry.role)) {
336
+ return leftIsSigner ? -1 : 1;
337
+ }
338
+ const leftIsWritable = isWritableRole(leftEntry.role);
339
+ if (leftIsWritable !== isWritableRole(rightEntry.role)) {
340
+ return leftIsWritable ? -1 : 1;
341
+ }
342
+ addressComparator || (addressComparator = addresses.getAddressComparator());
343
+ if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
344
+ return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
345
+ } else {
346
+ return addressComparator(leftAddress, rightAddress);
347
+ }
348
+ }).map(([address, addressMeta]) => ({
349
+ address,
350
+ ...addressMeta
351
+ }));
352
+ return orderedAccounts;
353
+ }
354
+ function getCompiledAddressTableLookups(orderedAccounts) {
355
+ var _a;
356
+ const index = {};
357
+ for (const account of orderedAccounts) {
358
+ if (!("lookupTableAddress" in account)) {
359
+ continue;
360
+ }
361
+ const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
362
+ readableIndices: [],
363
+ writableIndices: []
364
+ });
365
+ if (account.role === AccountRole.WRITABLE) {
366
+ entry.writableIndices.push(account.addressIndex);
367
+ } else {
368
+ entry.readableIndices.push(account.addressIndex);
369
+ }
370
+ }
371
+ return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
372
+ lookupTableAddress,
373
+ ...index[lookupTableAddress]
374
+ }));
375
+ }
376
+
377
+ // src/compile-header.ts
378
+ function getCompiledMessageHeader(orderedAccounts) {
379
+ let numReadonlyNonSignerAccounts = 0;
380
+ let numReadonlySignerAccounts = 0;
381
+ let numSignerAccounts = 0;
382
+ for (const account of orderedAccounts) {
383
+ if ("lookupTableAddress" in account) {
384
+ break;
385
+ }
386
+ const accountIsWritable = isWritableRole(account.role);
387
+ if (isSignerRole(account.role)) {
388
+ numSignerAccounts++;
389
+ if (!accountIsWritable) {
390
+ numReadonlySignerAccounts++;
391
+ }
392
+ } else if (!accountIsWritable) {
393
+ numReadonlyNonSignerAccounts++;
394
+ }
395
+ }
396
+ return {
397
+ numReadonlyNonSignerAccounts,
398
+ numReadonlySignerAccounts,
399
+ numSignerAccounts
400
+ };
401
+ }
402
+
403
+ // src/compile-instructions.ts
404
+ function getAccountIndex(orderedAccounts) {
405
+ const out = {};
406
+ for (const [index, account] of orderedAccounts.entries()) {
407
+ out[account.address] = index;
408
+ }
409
+ return out;
410
+ }
411
+ function getCompiledInstructions(instructions, orderedAccounts) {
412
+ const accountIndex = getAccountIndex(orderedAccounts);
413
+ return instructions.map(({ accounts, data, programAddress }) => {
414
+ return {
415
+ programAddressIndex: accountIndex[programAddress],
416
+ ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
417
+ ...data ? { data } : null
418
+ };
419
+ });
420
+ }
421
+
422
+ // src/compile-lifetime-token.ts
423
+ function getCompiledLifetimeToken(lifetimeConstraint) {
424
+ if ("nonce" in lifetimeConstraint) {
425
+ return lifetimeConstraint.nonce;
426
+ }
427
+ return lifetimeConstraint.blockhash;
428
+ }
429
+
430
+ // src/compile-static-accounts.ts
431
+ function getCompiledStaticAccounts(orderedAccounts) {
432
+ const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
433
+ const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
434
+ return orderedStaticAccounts.map(({ address }) => address);
435
+ }
436
+
437
+ // src/message.ts
438
+ function compileMessage(transaction) {
439
+ const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
440
+ const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
441
+ return {
442
+ ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
443
+ header: getCompiledMessageHeader(orderedAccounts),
444
+ instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
445
+ lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
446
+ staticAccounts: getCompiledStaticAccounts(orderedAccounts),
447
+ version: transaction.version
448
+ };
449
+ }
450
+
451
+ // src/compile-transaction.ts
452
+ function getCompiledTransaction(transaction) {
453
+ const compiledMessage = compileMessage(transaction);
454
+ let signatures;
455
+ if ("signatures" in transaction) {
456
+ signatures = [];
457
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
458
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
459
+ }
460
+ } else {
461
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
462
+ }
463
+ return {
464
+ compiledMessage,
465
+ signatures
466
+ };
467
+ }
468
+ function addressSerializerCompat(compat) {
469
+ const codec = addresses.getAddressCodec();
470
+ return {
471
+ description: compat?.description ?? codec.description,
472
+ deserialize: codec.decode,
473
+ fixedSize: codec.fixedSize,
474
+ maxSize: codec.maxSize,
475
+ serialize: codec.encode
476
+ };
477
+ }
478
+ function getAddressTableLookupCodec() {
479
+ return umiSerializers.struct(
480
+ [
481
+ [
482
+ "lookupTableAddress",
483
+ addressSerializerCompat(
484
+ __DEV__ ? {
485
+ description: "The address of the address lookup table account from which instruction addresses should be looked up"
486
+ } : void 0
487
+ )
488
+ ],
489
+ [
490
+ "writableIndices",
491
+ umiSerializers.array(umiSerializers.u8(), {
492
+ ...__DEV__ ? {
493
+ description: "The indices of the accounts in the lookup table that should be loaded as writeable"
494
+ } : null,
495
+ size: umiSerializers.shortU16()
496
+ })
497
+ ],
498
+ [
499
+ "readableIndices",
500
+ umiSerializers.array(umiSerializers.u8(), {
501
+ ...__DEV__ ? {
502
+ description: "The indices of the accounts in the lookup table that should be loaded as read-only"
503
+ } : void 0,
504
+ size: umiSerializers.shortU16()
505
+ })
506
+ ]
507
+ ],
508
+ __DEV__ ? {
509
+ description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it"
510
+ } : void 0
511
+ );
512
+ }
513
+ var memoizedU8Codec;
514
+ function getMemoizedU8Codec() {
515
+ if (!memoizedU8Codec)
516
+ memoizedU8Codec = codecsNumbers.getU8Codec();
517
+ return memoizedU8Codec;
518
+ }
519
+ function getMemoizedU8CodecDescription(description) {
520
+ const codec = getMemoizedU8Codec();
521
+ return {
522
+ ...codec,
523
+ description: description ?? codec.description
524
+ };
525
+ }
526
+ var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0;
527
+ var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0;
528
+ var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
529
+ var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
530
+ function getMessageHeaderCodec() {
531
+ return codecsDataStructures.getStructCodec(
532
+ [
533
+ ["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
534
+ ["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
535
+ ["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
536
+ ],
537
+ {
538
+ description: messageHeaderDescription
539
+ }
540
+ );
541
+ }
542
+ function getInstructionCodec() {
543
+ return umiSerializers.mapSerializer(
544
+ umiSerializers.struct([
545
+ [
546
+ "programAddressIndex",
547
+ umiSerializers.u8(
548
+ __DEV__ ? {
549
+ description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
550
+ } : void 0
551
+ )
552
+ ],
553
+ [
554
+ "accountIndices",
555
+ umiSerializers.array(
556
+ umiSerializers.u8({
557
+ description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
558
+ }),
559
+ {
560
+ description: __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "",
561
+ size: umiSerializers.shortU16()
562
+ }
563
+ )
564
+ ],
565
+ [
566
+ "data",
567
+ umiSerializers.bytes({
568
+ description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
569
+ size: umiSerializers.shortU16()
570
+ })
571
+ ]
572
+ ]),
573
+ (value) => {
574
+ if (value.accountIndices !== void 0 && value.data !== void 0) {
575
+ return value;
576
+ }
577
+ return {
578
+ ...value,
579
+ accountIndices: value.accountIndices ?? [],
580
+ data: value.data ?? new Uint8Array(0)
581
+ };
582
+ },
583
+ (value) => {
584
+ if (value.accountIndices.length && value.data.byteLength) {
585
+ return value;
586
+ }
587
+ const { accountIndices, data, ...rest } = value;
588
+ return {
589
+ ...rest,
590
+ ...accountIndices.length ? { accountIndices } : null,
591
+ ...data.byteLength ? { data } : null
592
+ };
593
+ }
594
+ );
595
+ }
596
+ var VERSION_FLAG_MASK = 128;
597
+ var BASE_CONFIG = {
598
+ description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
599
+ fixedSize: null,
600
+ maxSize: 1
601
+ };
602
+ function decode(bytes3, offset = 0) {
603
+ const firstByte = bytes3[offset];
604
+ if ((firstByte & VERSION_FLAG_MASK) === 0) {
605
+ return ["legacy", offset];
606
+ } else {
607
+ const version = firstByte ^ VERSION_FLAG_MASK;
608
+ return [version, offset + 1];
609
+ }
610
+ }
611
+ function encode(value) {
612
+ if (value === "legacy") {
613
+ return new Uint8Array();
614
+ }
615
+ if (value < 0 || value > 127) {
616
+ throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
617
+ }
618
+ return new Uint8Array([value | VERSION_FLAG_MASK]);
619
+ }
620
+ function getTransactionVersionDecoder() {
621
+ return {
622
+ ...BASE_CONFIG,
623
+ decode
624
+ };
625
+ }
626
+ function getTransactionVersionEncoder() {
627
+ return {
628
+ ...BASE_CONFIG,
629
+ encode
630
+ };
631
+ }
632
+ function getTransactionVersionCodec() {
633
+ return codecsCore.combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
634
+ }
635
+
636
+ // src/serializers/unimplemented.ts
637
+ function getError(type, name) {
638
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
639
+ return new Error(
640
+ `No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
641
+ );
642
+ }
643
+ function getUnimplementedDecoder(name) {
644
+ return () => {
645
+ throw getError("decoder", name);
646
+ };
647
+ }
648
+
649
+ // src/serializers/message.ts
650
+ var BASE_CONFIG2 = {
651
+ description: __DEV__ ? "The wire format of a Solana transaction message" : "",
652
+ fixedSize: null,
653
+ maxSize: null
654
+ };
655
+ function serialize(compiledMessage) {
656
+ if (compiledMessage.version === "legacy") {
657
+ return umiSerializers.struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
658
+ } else {
659
+ return umiSerializers.mapSerializer(
660
+ umiSerializers.struct([
661
+ ...getPreludeStructSerializerTuple(),
662
+ ["addressTableLookups", getAddressTableLookupsSerializer()]
663
+ ]),
664
+ (value) => {
665
+ if (value.version === "legacy") {
666
+ return value;
667
+ }
668
+ return {
669
+ ...value,
670
+ addressTableLookups: value.addressTableLookups ?? []
671
+ };
672
+ }
673
+ ).serialize(compiledMessage);
674
+ }
675
+ }
676
+ function toSerializer(codec) {
677
+ return {
678
+ description: codec.description,
679
+ deserialize: codec.decode,
680
+ fixedSize: codec.fixedSize,
681
+ maxSize: codec.maxSize,
682
+ serialize: codec.encode
683
+ };
684
+ }
685
+ function getPreludeStructSerializerTuple() {
686
+ return [
687
+ ["version", toSerializer(getTransactionVersionCodec())],
688
+ ["header", toSerializer(getMessageHeaderCodec())],
689
+ [
690
+ "staticAccounts",
691
+ umiSerializers.array(toSerializer(addresses.getAddressCodec()), {
692
+ description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
693
+ size: umiSerializers.shortU16()
694
+ })
695
+ ],
696
+ [
697
+ "lifetimeToken",
698
+ umiSerializers.string({
699
+ description: __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "",
700
+ encoding: umiSerializers.base58,
701
+ size: 32
702
+ })
703
+ ],
704
+ [
705
+ "instructions",
706
+ umiSerializers.array(getInstructionCodec(), {
707
+ description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "",
708
+ size: umiSerializers.shortU16()
709
+ })
710
+ ]
711
+ ];
712
+ }
713
+ function getAddressTableLookupsSerializer() {
714
+ return umiSerializers.array(getAddressTableLookupCodec(), {
715
+ ...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null,
716
+ size: umiSerializers.shortU16()
717
+ });
718
+ }
719
+ function getCompiledMessageEncoder() {
720
+ return {
721
+ ...BASE_CONFIG2,
722
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
723
+ serialize
724
+ };
725
+ }
726
+
727
+ // src/serializers/transaction.ts
728
+ var BASE_CONFIG3 = {
729
+ description: __DEV__ ? "The wire format of a Solana transaction" : "",
730
+ fixedSize: null,
731
+ maxSize: null
732
+ };
733
+ function serialize2(transaction) {
734
+ const compiledTransaction = getCompiledTransaction(transaction);
735
+ return umiSerializers.struct([
736
+ [
737
+ "signatures",
738
+ umiSerializers.array(umiSerializers.bytes({ size: 64 }), {
739
+ ...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
740
+ size: umiSerializers.shortU16()
741
+ })
742
+ ],
743
+ ["compiledMessage", getCompiledMessageEncoder()]
744
+ ]).serialize(compiledTransaction);
745
+ }
746
+ function getTransactionEncoder() {
747
+ return {
748
+ ...BASE_CONFIG3,
749
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
750
+ serialize: serialize2
751
+ };
752
+ }
753
+ function assertIsTransactionSignature(putativeTransactionSignature) {
754
+ try {
755
+ if (
756
+ // Lowest value (64 bytes of zeroes)
757
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
758
+ putativeTransactionSignature.length > 88
759
+ ) {
760
+ throw new Error("Expected input string to decode to a byte array of length 64.");
761
+ }
762
+ const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
763
+ const numBytes = bytes3.byteLength;
764
+ if (numBytes !== 64) {
765
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
766
+ }
767
+ } catch (e) {
768
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
769
+ cause: e
770
+ });
771
+ }
772
+ }
773
+ function isTransactionSignature(putativeTransactionSignature) {
774
+ if (
775
+ // Lowest value (64 bytes of zeroes)
776
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
777
+ putativeTransactionSignature.length > 88
778
+ ) {
779
+ return false;
780
+ }
781
+ const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
782
+ const numBytes = bytes3.byteLength;
783
+ if (numBytes !== 64) {
784
+ return false;
785
+ }
786
+ return true;
787
+ }
788
+ async function getCompiledMessageSignature(message, secretKey) {
789
+ const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
790
+ const signature = await keys.signBytes(secretKey, wireMessageBytes);
791
+ return signature;
792
+ }
793
+ function getSignatureFromTransaction(transaction) {
794
+ const signature = transaction.signatures[transaction.feePayer];
795
+ if (!signature) {
796
+ throw new Error(
797
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
798
+ );
799
+ }
800
+ return signature;
801
+ }
802
+ async function signTransaction(keyPairs, transaction) {
803
+ const compiledMessage = compileMessage(transaction);
804
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
805
+ const publicKeySignaturePairs = await Promise.all(
806
+ keyPairs.map(
807
+ (keyPair) => Promise.all([
808
+ addresses.getAddressFromPublicKey(keyPair.publicKey),
809
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
810
+ ])
811
+ )
812
+ );
813
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
814
+ nextSignatures[signerPublicKey] = signature;
815
+ }
816
+ const out = {
817
+ ...transaction,
818
+ signatures: nextSignatures
819
+ };
71
820
  Object.freeze(out);
72
821
  return out;
73
822
  }
823
+ function transactionSignature(putativeTransactionSignature) {
824
+ assertIsTransactionSignature(putativeTransactionSignature);
825
+ return putativeTransactionSignature;
826
+ }
827
+
828
+ // src/wire-transaction.ts
829
+ function getBase64EncodedWireTransaction(transaction) {
830
+ const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
831
+ {
832
+ return btoa(String.fromCharCode(...wireTransactionBytes));
833
+ }
834
+ }
74
835
 
75
836
  exports.appendTransactionInstruction = appendTransactionInstruction;
837
+ exports.assertIsBlockhash = assertIsBlockhash;
838
+ exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
839
+ exports.assertIsTransactionSignature = assertIsTransactionSignature;
76
840
  exports.createTransaction = createTransaction;
841
+ exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
842
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
843
+ exports.getTransactionEncoder = getTransactionEncoder;
844
+ exports.isTransactionSignature = isTransactionSignature;
77
845
  exports.prependTransactionInstruction = prependTransactionInstruction;
78
846
  exports.setTransactionFeePayer = setTransactionFeePayer;
847
+ exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
848
+ exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
849
+ exports.signTransaction = signTransaction;
850
+ exports.transactionSignature = transactionSignature;
851
+ //# sourceMappingURL=out.js.map
852
+ //# sourceMappingURL=index.browser.cjs.map