@solana/transactions 2.0.0-experimental.d554dd4 → 2.0.0-experimental.d93c93b

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 (67) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +272 -5
  3. package/dist/index.browser.cjs +638 -288
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +626 -292
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.development.js +1291 -773
  8. package/dist/index.development.js.map +1 -1
  9. package/dist/index.native.js +626 -290
  10. package/dist/index.native.js.map +1 -1
  11. package/dist/index.node.cjs +638 -290
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.js +626 -292
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.production.min.js +22 -8
  16. package/dist/types/accounts.d.ts +3 -3
  17. package/dist/types/accounts.d.ts.map +1 -0
  18. package/dist/types/blockhash.d.ts +6 -1
  19. package/dist/types/blockhash.d.ts.map +1 -0
  20. package/dist/types/compilable-transaction.d.ts +7 -0
  21. package/dist/types/compilable-transaction.d.ts.map +1 -0
  22. package/dist/types/compile-address-table-lookups.d.ts +2 -2
  23. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  24. package/dist/types/compile-header.d.ts.map +1 -0
  25. package/dist/types/compile-instructions.d.ts +1 -1
  26. package/dist/types/compile-instructions.d.ts.map +1 -0
  27. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  28. package/dist/types/compile-static-accounts.d.ts +2 -2
  29. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  30. package/dist/types/compile-transaction.d.ts +5 -6
  31. package/dist/types/compile-transaction.d.ts.map +1 -0
  32. package/dist/types/create-transaction.d.ts.map +1 -0
  33. package/dist/types/decompile-transaction.d.ts +5 -0
  34. package/dist/types/decompile-transaction.d.ts.map +1 -0
  35. package/dist/types/durable-nonce.d.ts +23 -10
  36. package/dist/types/durable-nonce.d.ts.map +1 -0
  37. package/dist/types/fee-payer.d.ts +4 -3
  38. package/dist/types/fee-payer.d.ts.map +1 -0
  39. package/dist/types/index.d.ts +3 -0
  40. package/dist/types/index.d.ts.map +1 -0
  41. package/dist/types/instructions.d.ts.map +1 -0
  42. package/dist/types/message.d.ts +1 -5
  43. package/dist/types/message.d.ts.map +1 -0
  44. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  45. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  46. package/dist/types/serializers/header.d.ts +4 -2
  47. package/dist/types/serializers/header.d.ts.map +1 -0
  48. package/dist/types/serializers/index.d.ts +3 -0
  49. package/dist/types/serializers/index.d.ts.map +1 -0
  50. package/dist/types/serializers/instruction.d.ts +4 -2
  51. package/dist/types/serializers/instruction.d.ts.map +1 -0
  52. package/dist/types/serializers/message.d.ts +4 -4
  53. package/dist/types/serializers/message.d.ts.map +1 -0
  54. package/dist/types/serializers/transaction-version.d.ts +4 -4
  55. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  56. package/dist/types/serializers/transaction.d.ts +6 -5
  57. package/dist/types/serializers/transaction.d.ts.map +1 -0
  58. package/dist/types/signatures.d.ts +10 -7
  59. package/dist/types/signatures.d.ts.map +1 -0
  60. package/dist/types/types.d.ts +13 -13
  61. package/dist/types/types.d.ts.map +1 -0
  62. package/dist/types/unsigned-transaction.d.ts +4 -0
  63. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  64. package/dist/types/wire-transaction.d.ts +2 -2
  65. package/dist/types/wire-transaction.d.ts.map +1 -0
  66. package/package.json +22 -18
  67. package/dist/types/serializers/unimplemented.d.ts +0 -3
@@ -1,9 +1,33 @@
1
- import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers';
2
- import { getBase58EncodedAddressFromPublicKey, signBytes, getBase58EncodedAddressComparator, getBase58EncodedAddressCodec } from '@solana/keys';
1
+ import { getBase58Encoder, getBase58Decoder, getBase64Decoder, getStringEncoder, getStringDecoder } from '@solana/codecs-strings';
2
+ import { getAddressFromPublicKey, getAddressComparator, getAddressEncoder, getAddressDecoder, assertIsAddress } from '@solana/addresses';
3
+ import { mapDecoder, combineCodec, mapEncoder } from '@solana/codecs-core';
4
+ import { getStructDecoder, getStructEncoder, getArrayEncoder, getArrayDecoder, getBytesEncoder, getBytesDecoder } from '@solana/codecs-data-structures';
5
+ import { getShortU16Encoder, getShortU16Decoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';
6
+ import { pipe } from '@solana/functional';
7
+ import { signBytes } from '@solana/keys';
3
8
 
4
9
  // ../build-scripts/env-shim.ts
5
10
  var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
11
+
12
+ // src/unsigned-transaction.ts
13
+ function getUnsignedTransaction(transaction) {
14
+ if ("signatures" in transaction) {
15
+ const {
16
+ signatures: _,
17
+ // eslint-disable-line @typescript-eslint/no-unused-vars
18
+ ...unsignedTransaction
19
+ } = transaction;
20
+ return unsignedTransaction;
21
+ } else {
22
+ return transaction;
23
+ }
24
+ }
25
+
26
+ // src/blockhash.ts
27
+ var base58Encoder;
6
28
  function assertIsBlockhash(putativeBlockhash) {
29
+ if (!base58Encoder)
30
+ base58Encoder = getBase58Encoder();
7
31
  try {
8
32
  if (
9
33
  // Lowest value (32 bytes of zeroes)
@@ -12,8 +36,8 @@ function assertIsBlockhash(putativeBlockhash) {
12
36
  ) {
13
37
  throw new Error("Expected input string to decode to a byte array of length 32.");
14
38
  }
15
- const bytes3 = base58.serialize(putativeBlockhash);
16
- const numBytes = bytes3.byteLength;
39
+ const bytes = base58Encoder.encode(putativeBlockhash);
40
+ const numBytes = bytes.byteLength;
17
41
  if (numBytes !== 32) {
18
42
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
19
43
  }
@@ -23,6 +47,17 @@ function assertIsBlockhash(putativeBlockhash) {
23
47
  });
24
48
  }
25
49
  }
50
+ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
51
+ if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
52
+ return transaction;
53
+ }
54
+ const out = {
55
+ ...getUnsignedTransaction(transaction),
56
+ lifetimeConstraint: blockhashLifetimeConstraint
57
+ };
58
+ Object.freeze(out);
59
+ return out;
60
+ }
26
61
 
27
62
  // src/create-transaction.ts
28
63
  function createTransaction({
@@ -36,66 +71,6 @@ function createTransaction({
36
71
  return out;
37
72
  }
38
73
 
39
- // src/fee-payer.ts
40
- function setTransactionFeePayer(feePayer, transaction) {
41
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
42
- return transaction;
43
- }
44
- let out;
45
- if ("signatures" in transaction) {
46
- const {
47
- signatures: _,
48
- // eslint-disable-line @typescript-eslint/no-unused-vars
49
- ...unsignedTransaction
50
- } = transaction;
51
- out = {
52
- ...unsignedTransaction,
53
- feePayer
54
- };
55
- } else {
56
- out = {
57
- ...transaction,
58
- feePayer
59
- };
60
- }
61
- Object.freeze(out);
62
- return out;
63
- }
64
-
65
- // src/instructions.ts
66
- function replaceInstructions(transaction, nextInstructions) {
67
- let out;
68
- if ("signatures" in transaction) {
69
- const {
70
- signatures: _,
71
- // eslint-disable-line @typescript-eslint/no-unused-vars
72
- ...unsignedTransaction
73
- } = transaction;
74
- out = {
75
- ...unsignedTransaction,
76
- instructions: nextInstructions
77
- };
78
- } else {
79
- out = {
80
- ...transaction,
81
- instructions: nextInstructions
82
- };
83
- }
84
- return out;
85
- }
86
- function appendTransactionInstruction(instruction, transaction) {
87
- const nextInstructions = [...transaction.instructions, instruction];
88
- const out = replaceInstructions(transaction, nextInstructions);
89
- Object.freeze(out);
90
- return out;
91
- }
92
- function prependTransactionInstruction(instruction, transaction) {
93
- const nextInstructions = [instruction, ...transaction.instructions];
94
- const out = replaceInstructions(transaction, nextInstructions);
95
- Object.freeze(out);
96
- return out;
97
- }
98
-
99
74
  // ../instructions/dist/index.browser.js
100
75
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
101
76
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
@@ -118,6 +93,113 @@ function isWritableRole(role) {
118
93
  function mergeRoles(roleA, roleB) {
119
94
  return roleA | roleB;
120
95
  }
96
+
97
+ // src/durable-nonce.ts
98
+ var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
99
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
100
+ function assertIsDurableNonceTransaction(transaction) {
101
+ if (!isDurableNonceTransaction(transaction)) {
102
+ throw new Error("Transaction is not a durable nonce transaction");
103
+ }
104
+ }
105
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
106
+ return {
107
+ accounts: [
108
+ { address: nonceAccountAddress, role: AccountRole.WRITABLE },
109
+ {
110
+ address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
111
+ role: AccountRole.READONLY
112
+ },
113
+ { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
114
+ ],
115
+ data: new Uint8Array([4, 0, 0, 0]),
116
+ programAddress: SYSTEM_PROGRAM_ADDRESS
117
+ };
118
+ }
119
+ function isAdvanceNonceAccountInstruction(instruction) {
120
+ return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
121
+ instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
122
+ instruction.accounts?.length === 3 && // First account is nonce account address
123
+ instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
124
+ instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
125
+ instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
126
+ }
127
+ function isAdvanceNonceAccountInstructionData(data) {
128
+ return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
129
+ }
130
+ function isDurableNonceTransaction(transaction) {
131
+ return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
132
+ }
133
+ function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
134
+ return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
135
+ }
136
+ function setTransactionLifetimeUsingDurableNonce({
137
+ nonce,
138
+ nonceAccountAddress,
139
+ nonceAuthorityAddress
140
+ }, transaction) {
141
+ let newInstructions;
142
+ const firstInstruction = transaction.instructions[0];
143
+ if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
144
+ if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
145
+ if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
146
+ return transaction;
147
+ } else {
148
+ newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
149
+ }
150
+ } else {
151
+ newInstructions = [
152
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
153
+ ...transaction.instructions.slice(1)
154
+ ];
155
+ }
156
+ } else {
157
+ newInstructions = [
158
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
159
+ ...transaction.instructions
160
+ ];
161
+ }
162
+ const out = {
163
+ ...getUnsignedTransaction(transaction),
164
+ instructions: newInstructions,
165
+ lifetimeConstraint: {
166
+ nonce
167
+ }
168
+ };
169
+ Object.freeze(out);
170
+ return out;
171
+ }
172
+
173
+ // src/fee-payer.ts
174
+ function setTransactionFeePayer(feePayer, transaction) {
175
+ if ("feePayer" in transaction && feePayer === transaction.feePayer) {
176
+ return transaction;
177
+ }
178
+ const out = {
179
+ ...getUnsignedTransaction(transaction),
180
+ feePayer
181
+ };
182
+ Object.freeze(out);
183
+ return out;
184
+ }
185
+
186
+ // src/instructions.ts
187
+ function appendTransactionInstruction(instruction, transaction) {
188
+ const out = {
189
+ ...getUnsignedTransaction(transaction),
190
+ instructions: [...transaction.instructions, instruction]
191
+ };
192
+ Object.freeze(out);
193
+ return out;
194
+ }
195
+ function prependTransactionInstruction(instruction, transaction) {
196
+ const out = {
197
+ ...getUnsignedTransaction(transaction),
198
+ instructions: [instruction, ...transaction.instructions]
199
+ };
200
+ Object.freeze(out);
201
+ return out;
202
+ }
121
203
  function upsert(addressMap, address, update) {
122
204
  addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
123
205
  }
@@ -170,7 +252,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
170
252
  const shouldReplaceEntry = (
171
253
  // Consider using the new LOOKUP_TABLE if its address is different...
172
254
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
173
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
255
+ (addressComparator ||= getAddressComparator())(
174
256
  accountMeta.lookupTableAddress,
175
257
  entry.lookupTableAddress
176
258
  ) < 0
@@ -276,7 +358,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
276
358
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
277
359
  return leftIsWritable ? -1 : 1;
278
360
  }
279
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
361
+ addressComparator ||= getAddressComparator();
280
362
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
281
363
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
282
364
  } else {
@@ -289,23 +371,22 @@ function getOrderedAccountsFromAddressMap(addressMap) {
289
371
  return orderedAccounts;
290
372
  }
291
373
  function getCompiledAddressTableLookups(orderedAccounts) {
292
- var _a;
293
374
  const index = {};
294
375
  for (const account of orderedAccounts) {
295
376
  if (!("lookupTableAddress" in account)) {
296
377
  continue;
297
378
  }
298
- const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
379
+ const entry = index[account.lookupTableAddress] ||= {
299
380
  readableIndices: [],
300
381
  writableIndices: []
301
- });
382
+ };
302
383
  if (account.role === AccountRole.WRITABLE) {
303
384
  entry.writableIndices.push(account.addressIndex);
304
385
  } else {
305
386
  entry.readableIndices.push(account.addressIndex);
306
387
  }
307
388
  }
308
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
389
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
309
390
  lookupTableAddress,
310
391
  ...index[lookupTableAddress]
311
392
  }));
@@ -384,151 +465,189 @@ function compileMessage(transaction) {
384
465
  version: transaction.version
385
466
  };
386
467
  }
387
- function getAddressTableLookupCodec() {
388
- return struct(
389
- [
468
+ var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
469
+ var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
470
+ var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
471
+ var addressTableLookupDescription = __DEV__ ? "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" : "addressTableLookup";
472
+ var memoizedAddressTableLookupEncoder;
473
+ function getAddressTableLookupEncoder() {
474
+ if (!memoizedAddressTableLookupEncoder) {
475
+ memoizedAddressTableLookupEncoder = getStructEncoder(
390
476
  [
391
- "lookupTableAddress",
392
- getBase58EncodedAddressCodec(
393
- __DEV__ ? {
394
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
395
- } : void 0
396
- )
477
+ ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
478
+ [
479
+ "writableIndices",
480
+ getArrayEncoder(getU8Encoder(), {
481
+ description: writableIndicesDescription,
482
+ size: getShortU16Encoder()
483
+ })
484
+ ],
485
+ [
486
+ "readableIndices",
487
+ getArrayEncoder(getU8Encoder(), {
488
+ description: readableIndicesDescription,
489
+ size: getShortU16Encoder()
490
+ })
491
+ ]
397
492
  ],
493
+ { description: addressTableLookupDescription }
494
+ );
495
+ }
496
+ return memoizedAddressTableLookupEncoder;
497
+ }
498
+ var memoizedAddressTableLookupDecoder;
499
+ function getAddressTableLookupDecoder() {
500
+ if (!memoizedAddressTableLookupDecoder) {
501
+ memoizedAddressTableLookupDecoder = getStructDecoder(
398
502
  [
399
- "writableIndices",
400
- array(u8(), {
401
- ...__DEV__ ? {
402
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
403
- } : null,
404
- size: shortU16()
405
- })
503
+ ["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
504
+ [
505
+ "writableIndices",
506
+ getArrayDecoder(getU8Decoder(), {
507
+ description: writableIndicesDescription,
508
+ size: getShortU16Decoder()
509
+ })
510
+ ],
511
+ [
512
+ "readableIndices",
513
+ getArrayDecoder(getU8Decoder(), {
514
+ description: readableIndicesDescription,
515
+ size: getShortU16Decoder()
516
+ })
517
+ ]
406
518
  ],
407
- [
408
- "readableIndices",
409
- array(u8(), {
410
- ...__DEV__ ? {
411
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
412
- } : void 0,
413
- size: shortU16()
414
- })
415
- ]
416
- ],
417
- __DEV__ ? {
418
- 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"
419
- } : void 0
420
- );
519
+ { description: addressTableLookupDescription }
520
+ );
521
+ }
522
+ return memoizedAddressTableLookupDecoder;
421
523
  }
422
- function getMessageHeaderCodec() {
423
- return struct(
524
+ var memoizedU8Encoder;
525
+ function getMemoizedU8Encoder() {
526
+ if (!memoizedU8Encoder)
527
+ memoizedU8Encoder = getU8Encoder();
528
+ return memoizedU8Encoder;
529
+ }
530
+ function getMemoizedU8EncoderDescription(description) {
531
+ const encoder = getMemoizedU8Encoder();
532
+ return {
533
+ ...encoder,
534
+ description: description ?? encoder.description
535
+ };
536
+ }
537
+ var memoizedU8Decoder;
538
+ function getMemoizedU8Decoder() {
539
+ if (!memoizedU8Decoder)
540
+ memoizedU8Decoder = getU8Decoder();
541
+ return memoizedU8Decoder;
542
+ }
543
+ function getMemoizedU8DecoderDescription(description) {
544
+ const decoder = getMemoizedU8Decoder();
545
+ return {
546
+ ...decoder,
547
+ description: description ?? decoder.description
548
+ };
549
+ }
550
+ 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;
551
+ 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;
552
+ var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
553
+ var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
554
+ function getMessageHeaderEncoder() {
555
+ return getStructEncoder(
424
556
  [
425
- [
426
- "numSignerAccounts",
427
- u8(
428
- __DEV__ ? {
429
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
430
- } : void 0
431
- )
432
- ],
433
- [
434
- "numReadonlySignerAccounts",
435
- u8(
436
- __DEV__ ? {
437
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable"
438
- } : void 0
439
- )
440
- ],
441
- [
442
- "numReadonlyNonSignerAccounts",
443
- u8(
444
- __DEV__ ? {
445
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
446
- } : void 0
447
- )
448
- ]
557
+ ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
558
+ ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
559
+ ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
449
560
  ],
450
- __DEV__ ? {
451
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
452
- } : void 0
561
+ {
562
+ description: messageHeaderDescription
563
+ }
453
564
  );
454
565
  }
455
- function getInstructionCodec() {
456
- return mapSerializer(
457
- struct([
458
- [
459
- "programAddressIndex",
460
- u8(
461
- __DEV__ ? {
462
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
463
- } : void 0
464
- )
465
- ],
466
- [
467
- "addressIndices",
468
- array(
469
- u8({
470
- description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
471
- }),
472
- {
473
- 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" : "",
474
- size: shortU16()
475
- }
476
- )
477
- ],
478
- [
479
- "data",
480
- bytes({
481
- description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
482
- size: shortU16()
483
- })
484
- ]
485
- ]),
486
- (value) => {
487
- if (value.addressIndices !== void 0 && value.data !== void 0) {
488
- return value;
489
- }
490
- return {
491
- ...value,
492
- addressIndices: value.addressIndices ?? [],
493
- data: value.data ?? new Uint8Array(0)
494
- };
495
- },
496
- (value) => {
497
- if (value.addressIndices.length && value.data.byteLength) {
498
- return value;
499
- }
500
- const { addressIndices, data, ...rest } = value;
501
- return {
502
- ...rest,
503
- ...addressIndices.length ? { addressIndices } : null,
504
- ...data.byteLength ? { data } : null
505
- };
566
+ function getMessageHeaderDecoder() {
567
+ return getStructDecoder(
568
+ [
569
+ ["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
570
+ ["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
571
+ ["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
572
+ ],
573
+ {
574
+ description: messageHeaderDescription
506
575
  }
507
576
  );
508
577
  }
509
-
510
- // src/serializers/unimplemented.ts
511
- function getError(type, name) {
512
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
513
- return new Error(
514
- `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}`
515
- );
578
+ var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
579
+ var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
580
+ var accountIndicesDescription = __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "accountIndices";
581
+ var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
582
+ var memoizedGetInstructionEncoder;
583
+ function getInstructionEncoder() {
584
+ if (!memoizedGetInstructionEncoder) {
585
+ memoizedGetInstructionEncoder = mapEncoder(
586
+ getStructEncoder([
587
+ ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
588
+ [
589
+ "accountIndices",
590
+ getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
591
+ description: accountIndicesDescription,
592
+ size: getShortU16Encoder()
593
+ })
594
+ ],
595
+ ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
596
+ ]),
597
+ // Convert an instruction to have all fields defined
598
+ (instruction) => {
599
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
600
+ return instruction;
601
+ }
602
+ return {
603
+ ...instruction,
604
+ accountIndices: instruction.accountIndices ?? [],
605
+ data: instruction.data ?? new Uint8Array(0)
606
+ };
607
+ }
608
+ );
609
+ }
610
+ return memoizedGetInstructionEncoder;
516
611
  }
517
- function getUnimplementedDecoder(name) {
518
- return () => {
519
- throw getError("decoder", name);
520
- };
612
+ var memoizedGetInstructionDecoder;
613
+ function getInstructionDecoder() {
614
+ if (!memoizedGetInstructionDecoder) {
615
+ memoizedGetInstructionDecoder = mapDecoder(
616
+ getStructDecoder([
617
+ ["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
618
+ [
619
+ "accountIndices",
620
+ getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
621
+ description: accountIndicesDescription,
622
+ size: getShortU16Decoder()
623
+ })
624
+ ],
625
+ ["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
626
+ ]),
627
+ // Convert an instruction to exclude optional fields if they are empty
628
+ (instruction) => {
629
+ if (instruction.accountIndices.length && instruction.data.byteLength) {
630
+ return instruction;
631
+ }
632
+ const { accountIndices, data, ...rest } = instruction;
633
+ return {
634
+ ...rest,
635
+ ...accountIndices.length ? { accountIndices } : null,
636
+ ...data.byteLength ? { data } : null
637
+ };
638
+ }
639
+ );
640
+ }
641
+ return memoizedGetInstructionDecoder;
521
642
  }
522
-
523
- // src/serializers/transaction-version.ts
524
643
  var VERSION_FLAG_MASK = 128;
525
644
  var BASE_CONFIG = {
526
645
  description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
527
646
  fixedSize: null,
528
647
  maxSize: 1
529
648
  };
530
- function deserialize(bytes3, offset = 0) {
531
- const firstByte = bytes3[offset];
649
+ function decode(bytes, offset = 0) {
650
+ const firstByte = bytes[offset];
532
651
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
533
652
  return ["legacy", offset];
534
653
  } else {
@@ -536,7 +655,7 @@ function deserialize(bytes3, offset = 0) {
536
655
  return [version, offset + 1];
537
656
  }
538
657
  }
539
- function serialize(value) {
658
+ function encode(value) {
540
659
  if (value === "legacy") {
541
660
  return new Uint8Array();
542
661
  }
@@ -545,105 +664,143 @@ function serialize(value) {
545
664
  }
546
665
  return new Uint8Array([value | VERSION_FLAG_MASK]);
547
666
  }
548
- function getTransactionVersionCodec() {
667
+ function getTransactionVersionDecoder() {
668
+ return {
669
+ ...BASE_CONFIG,
670
+ decode
671
+ };
672
+ }
673
+ function getTransactionVersionEncoder() {
549
674
  return {
550
675
  ...BASE_CONFIG,
551
- deserialize,
552
- serialize
676
+ encode
553
677
  };
554
678
  }
555
679
 
556
680
  // src/serializers/message.ts
557
- var BASE_CONFIG2 = {
558
- description: __DEV__ ? "The wire format of a Solana transaction message" : "",
559
- fixedSize: null,
560
- maxSize: null
561
- };
562
- function serialize2(compiledMessage) {
563
- if (compiledMessage.version === "legacy") {
564
- return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
565
- } else {
566
- return mapSerializer(
567
- struct([
568
- ...getPreludeStructSerializerTuple(),
569
- ["addressTableLookups", getAddressTableLookupsSerializer()]
570
- ]),
571
- (value) => {
572
- if (value.version === "legacy") {
573
- return value;
574
- }
575
- return {
576
- ...value,
577
- addressTableLookups: value.addressTableLookups ?? []
578
- };
681
+ var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
682
+ var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
683
+ var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
684
+ var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
685
+ function getCompiledMessageLegacyEncoder() {
686
+ return getStructEncoder(getPreludeStructEncoderTuple());
687
+ }
688
+ function getCompiledMessageVersionedEncoder() {
689
+ return mapEncoder(
690
+ getStructEncoder([
691
+ ...getPreludeStructEncoderTuple(),
692
+ ["addressTableLookups", getAddressTableLookupArrayEncoder()]
693
+ ]),
694
+ (value) => {
695
+ if (value.version === "legacy") {
696
+ return value;
579
697
  }
580
- ).serialize(compiledMessage);
581
- }
698
+ return {
699
+ ...value,
700
+ addressTableLookups: value.addressTableLookups ?? []
701
+ };
702
+ }
703
+ );
582
704
  }
583
- function getPreludeStructSerializerTuple() {
705
+ function getPreludeStructEncoderTuple() {
584
706
  return [
585
- ["version", getTransactionVersionCodec()],
586
- ["header", getMessageHeaderCodec()],
707
+ ["version", getTransactionVersionEncoder()],
708
+ ["header", getMessageHeaderEncoder()],
587
709
  [
588
710
  "staticAccounts",
589
- array(getBase58EncodedAddressCodec(), {
590
- description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
591
- size: shortU16()
711
+ getArrayEncoder(getAddressEncoder(), {
712
+ description: staticAccountsDescription,
713
+ size: getShortU16Encoder()
592
714
  })
593
715
  ],
594
716
  [
595
717
  "lifetimeToken",
596
- string({
597
- description: __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "",
598
- encoding: base58,
718
+ getStringEncoder({
719
+ description: lifetimeTokenDescription,
720
+ encoding: getBase58Encoder(),
599
721
  size: 32
600
722
  })
601
723
  ],
602
724
  [
603
725
  "instructions",
604
- array(getInstructionCodec(), {
605
- description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "",
606
- size: shortU16()
726
+ getArrayEncoder(getInstructionEncoder(), {
727
+ description: instructionsDescription,
728
+ size: getShortU16Encoder()
607
729
  })
608
730
  ]
609
731
  ];
610
732
  }
611
- function getAddressTableLookupsSerializer() {
612
- return array(getAddressTableLookupCodec(), {
613
- ...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null,
614
- size: shortU16()
733
+ function getPreludeStructDecoderTuple() {
734
+ return [
735
+ ["version", getTransactionVersionDecoder()],
736
+ ["header", getMessageHeaderDecoder()],
737
+ [
738
+ "staticAccounts",
739
+ getArrayDecoder(getAddressDecoder(), {
740
+ description: staticAccountsDescription,
741
+ size: getShortU16Decoder()
742
+ })
743
+ ],
744
+ [
745
+ "lifetimeToken",
746
+ getStringDecoder({
747
+ description: lifetimeTokenDescription,
748
+ encoding: getBase58Decoder(),
749
+ size: 32
750
+ })
751
+ ],
752
+ [
753
+ "instructions",
754
+ getArrayDecoder(getInstructionDecoder(), {
755
+ description: instructionsDescription,
756
+ size: getShortU16Decoder()
757
+ })
758
+ ],
759
+ ["addressTableLookups", getAddressTableLookupArrayDecoder()]
760
+ ];
761
+ }
762
+ function getAddressTableLookupArrayEncoder() {
763
+ return getArrayEncoder(getAddressTableLookupEncoder(), {
764
+ description: addressTableLookupsDescription,
765
+ size: getShortU16Encoder()
766
+ });
767
+ }
768
+ function getAddressTableLookupArrayDecoder() {
769
+ return getArrayDecoder(getAddressTableLookupDecoder(), {
770
+ description: addressTableLookupsDescription,
771
+ size: getShortU16Decoder()
615
772
  });
616
773
  }
774
+ var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
617
775
  function getCompiledMessageEncoder() {
618
776
  return {
619
- ...BASE_CONFIG2,
620
- deserialize: getUnimplementedDecoder("CompiledMessage"),
621
- serialize: serialize2
777
+ description: messageDescription,
778
+ encode: (compiledMessage) => {
779
+ if (compiledMessage.version === "legacy") {
780
+ return getCompiledMessageLegacyEncoder().encode(compiledMessage);
781
+ } else {
782
+ return getCompiledMessageVersionedEncoder().encode(compiledMessage);
783
+ }
784
+ },
785
+ fixedSize: null,
786
+ maxSize: null
622
787
  };
623
788
  }
624
-
625
- // src/signatures.ts
626
- async function getCompiledMessageSignature(message, secretKey) {
627
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
628
- const signature = await signBytes(secretKey, wireMessageBytes);
629
- return signature;
789
+ function getCompiledMessageDecoder() {
790
+ return mapDecoder(
791
+ getStructDecoder(getPreludeStructDecoderTuple(), {
792
+ description: messageDescription
793
+ }),
794
+ ({ addressTableLookups, ...restOfMessage }) => {
795
+ if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
796
+ return restOfMessage;
797
+ }
798
+ return { ...restOfMessage, addressTableLookups };
799
+ }
800
+ );
630
801
  }
631
- async function signTransaction(keyPair, transaction) {
632
- const compiledMessage = compileMessage(transaction);
633
- const [signerPublicKey, signature] = await Promise.all([
634
- getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
635
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
636
- ]);
637
- const nextSignatures = {
638
- ..."signatures" in transaction ? transaction.signatures : null,
639
- ...{ [signerPublicKey]: signature }
640
- };
641
- const out = {
642
- ...transaction,
643
- signatures: nextSignatures
644
- };
645
- Object.freeze(out);
646
- return out;
802
+ function getCompiledMessageCodec() {
803
+ return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
647
804
  }
648
805
 
649
806
  // src/compile-transaction.ts
@@ -663,42 +820,219 @@ function getCompiledTransaction(transaction) {
663
820
  signatures
664
821
  };
665
822
  }
823
+ function getAccountMetas(message) {
824
+ const { header } = message;
825
+ const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
826
+ const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
827
+ const accountMetas = [];
828
+ let accountIndex = 0;
829
+ for (let i = 0; i < numWritableSignerAccounts; i++) {
830
+ accountMetas.push({
831
+ address: message.staticAccounts[accountIndex],
832
+ role: AccountRole.WRITABLE_SIGNER
833
+ });
834
+ accountIndex++;
835
+ }
836
+ for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
837
+ accountMetas.push({
838
+ address: message.staticAccounts[accountIndex],
839
+ role: AccountRole.READONLY_SIGNER
840
+ });
841
+ accountIndex++;
842
+ }
843
+ for (let i = 0; i < numWritableNonSignerAccounts; i++) {
844
+ accountMetas.push({
845
+ address: message.staticAccounts[accountIndex],
846
+ role: AccountRole.WRITABLE
847
+ });
848
+ accountIndex++;
849
+ }
850
+ for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
851
+ accountMetas.push({
852
+ address: message.staticAccounts[accountIndex],
853
+ role: AccountRole.READONLY
854
+ });
855
+ accountIndex++;
856
+ }
857
+ return accountMetas;
858
+ }
859
+ function convertInstruction(instruction, accountMetas) {
860
+ const programAddress = accountMetas[instruction.programAddressIndex]?.address;
861
+ if (!programAddress) {
862
+ throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
863
+ }
864
+ const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
865
+ const { data } = instruction;
866
+ return {
867
+ programAddress,
868
+ ...accounts && accounts.length ? { accounts } : {},
869
+ ...data && data.length ? { data } : {}
870
+ };
871
+ }
872
+ function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
873
+ if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
874
+ return {
875
+ blockhash: messageLifetimeToken,
876
+ lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
877
+ // U64 MAX
878
+ };
879
+ } else {
880
+ const nonceAccountAddress = firstInstruction.accounts[0].address;
881
+ assertIsAddress(nonceAccountAddress);
882
+ const nonceAuthorityAddress = firstInstruction.accounts[2].address;
883
+ assertIsAddress(nonceAuthorityAddress);
884
+ return {
885
+ nonce: messageLifetimeToken,
886
+ nonceAccountAddress,
887
+ nonceAuthorityAddress
888
+ };
889
+ }
890
+ }
891
+ function convertSignatures(compiledTransaction) {
892
+ const {
893
+ compiledMessage: { staticAccounts },
894
+ signatures
895
+ } = compiledTransaction;
896
+ return signatures.reduce((acc, sig, index) => {
897
+ const allZeros = sig.every((byte) => byte === 0);
898
+ if (allZeros)
899
+ return acc;
900
+ const address = staticAccounts[index];
901
+ return { ...acc, [address]: sig };
902
+ }, {});
903
+ }
904
+ function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
905
+ const { compiledMessage } = compiledTransaction;
906
+ if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
907
+ throw new Error("Cannot convert transaction with addressTableLookups");
908
+ }
909
+ const feePayer = compiledMessage.staticAccounts[0];
910
+ if (!feePayer)
911
+ throw new Error("No fee payer set in CompiledTransaction");
912
+ const accountMetas = getAccountMetas(compiledMessage);
913
+ const instructions = compiledMessage.instructions.map(
914
+ (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
915
+ );
916
+ const firstInstruction = instructions[0];
917
+ const lifetimeConstraint = getLifetimeConstraint(
918
+ compiledMessage.lifetimeToken,
919
+ firstInstruction,
920
+ lastValidBlockHeight
921
+ );
922
+ const signatures = convertSignatures(compiledTransaction);
923
+ return pipe(
924
+ createTransaction({ version: compiledMessage.version }),
925
+ (tx) => setTransactionFeePayer(feePayer, tx),
926
+ (tx) => instructions.reduce((acc, instruction) => {
927
+ return appendTransactionInstruction(instruction, acc);
928
+ }, tx),
929
+ (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
930
+ (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
931
+ );
932
+ }
666
933
 
667
934
  // src/serializers/transaction.ts
668
- var BASE_CONFIG3 = {
669
- description: __DEV__ ? "The wire format of a Solana transaction" : "",
670
- fixedSize: null,
671
- maxSize: null
672
- };
673
- function serialize3(transaction) {
674
- const compiledTransaction = getCompiledTransaction(transaction);
675
- return struct([
935
+ var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
936
+ var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
937
+ function getCompiledTransactionEncoder() {
938
+ return getStructEncoder(
676
939
  [
677
- "signatures",
678
- array(bytes({ size: 64 }), {
679
- ...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
680
- size: shortU16()
681
- })
940
+ [
941
+ "signatures",
942
+ getArrayEncoder(getBytesEncoder({ size: 64 }), {
943
+ description: signaturesDescription,
944
+ size: getShortU16Encoder()
945
+ })
946
+ ],
947
+ ["compiledMessage", getCompiledMessageEncoder()]
948
+ ],
949
+ {
950
+ description: transactionDescription
951
+ }
952
+ );
953
+ }
954
+ function getSignatureDecoder() {
955
+ return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
956
+ }
957
+ function getCompiledTransactionDecoder() {
958
+ return getStructDecoder(
959
+ [
960
+ [
961
+ "signatures",
962
+ getArrayDecoder(getSignatureDecoder(), {
963
+ description: signaturesDescription,
964
+ size: getShortU16Decoder()
965
+ })
966
+ ],
967
+ ["compiledMessage", getCompiledMessageDecoder()]
682
968
  ],
683
- ["compiledMessage", getCompiledMessageEncoder()]
684
- ]).serialize(compiledTransaction);
969
+ {
970
+ description: transactionDescription
971
+ }
972
+ );
685
973
  }
686
974
  function getTransactionEncoder() {
687
- return {
688
- ...BASE_CONFIG3,
689
- deserialize: getUnimplementedDecoder("CompiledMessage"),
690
- serialize: serialize3
975
+ return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
976
+ }
977
+ function getTransactionDecoder(lastValidBlockHeight) {
978
+ return mapDecoder(
979
+ getCompiledTransactionDecoder(),
980
+ (compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
981
+ );
982
+ }
983
+ function getTransactionCodec(lastValidBlockHeight) {
984
+ return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
985
+ }
986
+ var base58Decoder;
987
+ function getSignatureFromTransaction(transaction) {
988
+ if (!base58Decoder)
989
+ base58Decoder = getBase58Decoder();
990
+ const signatureBytes = transaction.signatures[transaction.feePayer];
991
+ if (!signatureBytes) {
992
+ throw new Error(
993
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
994
+ );
995
+ }
996
+ const transactionSignature = base58Decoder.decode(signatureBytes)[0];
997
+ return transactionSignature;
998
+ }
999
+ async function partiallySignTransaction(keyPairs, transaction) {
1000
+ const compiledMessage = compileMessage(transaction);
1001
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1002
+ const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
1003
+ const publicKeySignaturePairs = await Promise.all(
1004
+ keyPairs.map(
1005
+ (keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
1006
+ )
1007
+ );
1008
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
1009
+ nextSignatures[signerPublicKey] = signature;
1010
+ }
1011
+ const out = {
1012
+ ...transaction,
1013
+ signatures: nextSignatures
691
1014
  };
1015
+ Object.freeze(out);
1016
+ return out;
1017
+ }
1018
+ async function signTransaction(keyPairs, transaction) {
1019
+ const out = await partiallySignTransaction(keyPairs, transaction);
1020
+ assertTransactionIsFullySigned(out);
1021
+ Object.freeze(out);
1022
+ return out;
1023
+ }
1024
+ function assertTransactionIsFullySigned(transaction) {
1025
+ const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
1026
+ const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
1027
+ requiredSigners.forEach((address) => {
1028
+ if (!transaction.signatures[address]) {
1029
+ throw new Error(`Transaction is missing signature for address \`${address}\``);
1030
+ }
1031
+ });
692
1032
  }
693
-
694
- // src/wire-transaction.ts
695
1033
  function getBase64EncodedWireTransaction(transaction) {
696
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
697
- {
698
- return btoa(String.fromCharCode(...wireTransactionBytes));
699
- }
1034
+ const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1035
+ return getBase64Decoder().decode(wireTransactionBytes)[0];
700
1036
  }
701
1037
 
702
- export { appendTransactionInstruction, assertIsBlockhash, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, signTransaction };
703
- //# sourceMappingURL=out.js.map
704
- //# sourceMappingURL=index.browser.js.map
1038
+ export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertTransactionIsFullySigned, compileMessage, createTransaction, getBase64EncodedWireTransaction, getCompiledMessageCodec, getCompiledMessageDecoder, getCompiledMessageEncoder, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, partiallySignTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };