@solana/transactions 2.0.0-experimental.1584fe6 → 2.0.0-experimental.19791fe

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 (60) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.browser.cjs +368 -324
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +363 -327
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +842 -754
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +363 -327
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +368 -324
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +363 -325
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +17 -9
  15. package/dist/types/accounts.d.ts +2 -2
  16. package/dist/types/accounts.d.ts.map +1 -0
  17. package/dist/types/blockhash.d.ts +1 -1
  18. package/dist/types/blockhash.d.ts.map +1 -0
  19. package/dist/types/compile-address-table-lookups.d.ts +1 -1
  20. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  21. package/dist/types/compile-header.d.ts.map +1 -0
  22. package/dist/types/compile-instructions.d.ts +1 -1
  23. package/dist/types/compile-instructions.d.ts.map +1 -0
  24. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  25. package/dist/types/compile-static-accounts.d.ts +1 -1
  26. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  27. package/dist/types/compile-transaction.d.ts.map +1 -0
  28. package/dist/types/create-transaction.d.ts.map +1 -0
  29. package/dist/types/durable-nonce.d.ts +15 -4
  30. package/dist/types/durable-nonce.d.ts.map +1 -0
  31. package/dist/types/fee-payer.d.ts +3 -2
  32. package/dist/types/fee-payer.d.ts.map +1 -0
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/index.d.ts.map +1 -0
  35. package/dist/types/instructions.d.ts.map +1 -0
  36. package/dist/types/message.d.ts.map +1 -0
  37. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  38. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  39. package/dist/types/serializers/header.d.ts +4 -2
  40. package/dist/types/serializers/header.d.ts.map +1 -0
  41. package/dist/types/serializers/index.d.ts +2 -0
  42. package/dist/types/serializers/index.d.ts.map +1 -0
  43. package/dist/types/serializers/instruction.d.ts +4 -2
  44. package/dist/types/serializers/instruction.d.ts.map +1 -0
  45. package/dist/types/serializers/message.d.ts +4 -4
  46. package/dist/types/serializers/message.d.ts.map +1 -0
  47. package/dist/types/serializers/transaction-version.d.ts +4 -4
  48. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  49. package/dist/types/serializers/transaction.d.ts +5 -4
  50. package/dist/types/serializers/transaction.d.ts.map +1 -0
  51. package/dist/types/signatures.d.ts +13 -6
  52. package/dist/types/signatures.d.ts.map +1 -0
  53. package/dist/types/types.d.ts +7 -0
  54. package/dist/types/types.d.ts.map +1 -0
  55. package/dist/types/unsigned-transaction.d.ts +4 -0
  56. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  57. package/dist/types/wire-transaction.d.ts +2 -2
  58. package/dist/types/wire-transaction.d.ts.map +1 -0
  59. package/package.json +22 -18
  60. package/dist/types/serializers/unimplemented.d.ts +0 -3
@@ -1,10 +1,31 @@
1
1
  'use strict';
2
2
 
3
3
  var umiSerializers = require('@metaplex-foundation/umi-serializers');
4
+ var codecsCore = require('@solana/codecs-core');
5
+ var codecsDataStructures = require('@solana/codecs-data-structures');
6
+ var codecsNumbers = require('@solana/codecs-numbers');
7
+ var addresses = require('@solana/addresses');
8
+ var codecsStrings = require('@solana/codecs-strings');
4
9
  var keys = require('@solana/keys');
5
10
 
6
11
  // ../build-scripts/env-shim.ts
7
12
  var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
13
+
14
+ // src/unsigned-transaction.ts
15
+ function getUnsignedTransaction(transaction) {
16
+ if ("signatures" in transaction) {
17
+ const {
18
+ signatures: _,
19
+ // eslint-disable-line @typescript-eslint/no-unused-vars
20
+ ...unsignedTransaction
21
+ } = transaction;
22
+ return unsignedTransaction;
23
+ } else {
24
+ return transaction;
25
+ }
26
+ }
27
+
28
+ // src/blockhash.ts
8
29
  function assertIsBlockhash(putativeBlockhash) {
9
30
  try {
10
31
  if (
@@ -14,8 +35,8 @@ function assertIsBlockhash(putativeBlockhash) {
14
35
  ) {
15
36
  throw new Error("Expected input string to decode to a byte array of length 32.");
16
37
  }
17
- const bytes3 = umiSerializers.base58.serialize(putativeBlockhash);
18
- const numBytes = bytes3.byteLength;
38
+ const bytes = umiSerializers.base58.serialize(putativeBlockhash);
39
+ const numBytes = bytes.byteLength;
19
40
  if (numBytes !== 32) {
20
41
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
21
42
  }
@@ -29,23 +50,10 @@ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, trans
29
50
  if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
30
51
  return transaction;
31
52
  }
32
- let out;
33
- if ("signatures" in transaction) {
34
- const {
35
- signatures: _,
36
- // eslint-disable-line @typescript-eslint/no-unused-vars
37
- ...unsignedTransaction
38
- } = transaction;
39
- out = {
40
- ...unsignedTransaction,
41
- lifetimeConstraint: blockhashLifetimeConstraint
42
- };
43
- } else {
44
- out = {
45
- ...transaction,
46
- lifetimeConstraint: blockhashLifetimeConstraint
47
- };
48
- }
53
+ const out = {
54
+ ...getUnsignedTransaction(transaction),
55
+ lifetimeConstraint: blockhashLifetimeConstraint
56
+ };
49
57
  Object.freeze(out);
50
58
  return out;
51
59
  }
@@ -62,66 +70,6 @@ function createTransaction({
62
70
  return out;
63
71
  }
64
72
 
65
- // src/fee-payer.ts
66
- function setTransactionFeePayer(feePayer, transaction) {
67
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
68
- return transaction;
69
- }
70
- let out;
71
- if ("signatures" in transaction) {
72
- const {
73
- signatures: _,
74
- // eslint-disable-line @typescript-eslint/no-unused-vars
75
- ...unsignedTransaction
76
- } = transaction;
77
- out = {
78
- ...unsignedTransaction,
79
- feePayer
80
- };
81
- } else {
82
- out = {
83
- ...transaction,
84
- feePayer
85
- };
86
- }
87
- Object.freeze(out);
88
- return out;
89
- }
90
-
91
- // src/instructions.ts
92
- function replaceInstructions(transaction, nextInstructions) {
93
- let out;
94
- if ("signatures" in transaction) {
95
- const {
96
- signatures: _,
97
- // eslint-disable-line @typescript-eslint/no-unused-vars
98
- ...unsignedTransaction
99
- } = transaction;
100
- out = {
101
- ...unsignedTransaction,
102
- instructions: nextInstructions
103
- };
104
- } else {
105
- out = {
106
- ...transaction,
107
- instructions: nextInstructions
108
- };
109
- }
110
- return out;
111
- }
112
- function appendTransactionInstruction(instruction, transaction) {
113
- const nextInstructions = [...transaction.instructions, instruction];
114
- const out = replaceInstructions(transaction, nextInstructions);
115
- Object.freeze(out);
116
- return out;
117
- }
118
- function prependTransactionInstruction(instruction, transaction) {
119
- const nextInstructions = [instruction, ...transaction.instructions];
120
- const out = replaceInstructions(transaction, nextInstructions);
121
- Object.freeze(out);
122
- return out;
123
- }
124
-
125
73
  // ../instructions/dist/index.browser.js
126
74
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
127
75
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
@@ -144,6 +92,96 @@ function isWritableRole(role) {
144
92
  function mergeRoles(roleA, roleB) {
145
93
  return roleA | roleB;
146
94
  }
95
+
96
+ // src/durable-nonce.ts
97
+ var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
98
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
99
+ function assertIsDurableNonceTransaction(transaction) {
100
+ if (!isDurableNonceTransaction(transaction)) {
101
+ throw new Error("Transaction is not a durable nonce transaction");
102
+ }
103
+ }
104
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
105
+ return {
106
+ accounts: [
107
+ { address: nonceAccountAddress, role: AccountRole.WRITABLE },
108
+ {
109
+ address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
110
+ role: AccountRole.READONLY
111
+ },
112
+ { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
113
+ ],
114
+ data: new Uint8Array([4, 0, 0, 0]),
115
+ programAddress: SYSTEM_PROGRAM_ADDRESS
116
+ };
117
+ }
118
+ function isAdvanceNonceAccountInstruction(instruction) {
119
+ return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
120
+ instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
121
+ instruction.accounts?.length === 3 && // First account is nonce account address
122
+ instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
123
+ instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
124
+ instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
125
+ }
126
+ function isAdvanceNonceAccountInstructionData(data) {
127
+ return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
128
+ }
129
+ function isDurableNonceTransaction(transaction) {
130
+ return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
131
+ }
132
+ function setTransactionLifetimeUsingDurableNonce({
133
+ nonce,
134
+ nonceAccountAddress,
135
+ nonceAuthorityAddress
136
+ }, transaction) {
137
+ const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
138
+ if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
139
+ return transaction;
140
+ }
141
+ const out = {
142
+ ...getUnsignedTransaction(transaction),
143
+ instructions: [
144
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
145
+ ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
146
+ ],
147
+ lifetimeConstraint: {
148
+ nonce
149
+ }
150
+ };
151
+ Object.freeze(out);
152
+ return out;
153
+ }
154
+
155
+ // src/fee-payer.ts
156
+ function setTransactionFeePayer(feePayer, transaction) {
157
+ if ("feePayer" in transaction && feePayer === transaction.feePayer) {
158
+ return transaction;
159
+ }
160
+ const out = {
161
+ ...getUnsignedTransaction(transaction),
162
+ feePayer
163
+ };
164
+ Object.freeze(out);
165
+ return out;
166
+ }
167
+
168
+ // src/instructions.ts
169
+ function appendTransactionInstruction(instruction, transaction) {
170
+ const out = {
171
+ ...getUnsignedTransaction(transaction),
172
+ instructions: [...transaction.instructions, instruction]
173
+ };
174
+ Object.freeze(out);
175
+ return out;
176
+ }
177
+ function prependTransactionInstruction(instruction, transaction) {
178
+ const out = {
179
+ ...getUnsignedTransaction(transaction),
180
+ instructions: [instruction, ...transaction.instructions]
181
+ };
182
+ Object.freeze(out);
183
+ return out;
184
+ }
147
185
  function upsert(addressMap, address, update) {
148
186
  addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
149
187
  }
@@ -196,7 +234,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
196
234
  const shouldReplaceEntry = (
197
235
  // Consider using the new LOOKUP_TABLE if its address is different...
198
236
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
199
- (addressComparator || (addressComparator = keys.getBase58EncodedAddressComparator()))(
237
+ (addressComparator || (addressComparator = addresses.getAddressComparator()))(
200
238
  accountMeta.lookupTableAddress,
201
239
  entry.lookupTableAddress
202
240
  ) < 0
@@ -302,7 +340,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
302
340
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
303
341
  return leftIsWritable ? -1 : 1;
304
342
  }
305
- addressComparator || (addressComparator = keys.getBase58EncodedAddressComparator());
343
+ addressComparator || (addressComparator = addresses.getAddressComparator());
306
344
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
307
345
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
308
346
  } else {
@@ -331,7 +369,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
331
369
  entry.readableIndices.push(account.addressIndex);
332
370
  }
333
371
  }
334
- return Object.keys(index).sort(keys.getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
372
+ return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
335
373
  lookupTableAddress,
336
374
  ...index[lookupTableAddress]
337
375
  }));
@@ -410,159 +448,124 @@ function compileMessage(transaction) {
410
448
  version: transaction.version
411
449
  };
412
450
  }
413
- function getAddressTableLookupCodec() {
414
- return umiSerializers.struct(
415
- [
416
- [
417
- "lookupTableAddress",
418
- keys.getBase58EncodedAddressCodec(
419
- __DEV__ ? {
420
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
421
- } : void 0
422
- )
423
- ],
451
+
452
+ // src/compile-transaction.ts
453
+ function getCompiledTransaction(transaction) {
454
+ const compiledMessage = compileMessage(transaction);
455
+ let signatures;
456
+ if ("signatures" in transaction) {
457
+ signatures = [];
458
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
459
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
460
+ }
461
+ } else {
462
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
463
+ }
464
+ return {
465
+ compiledMessage,
466
+ signatures
467
+ };
468
+ }
469
+ var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
470
+ var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
471
+ var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
472
+ 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";
473
+ var memoizedAddressTableLookupEncoder;
474
+ function getAddressTableLookupEncoder() {
475
+ if (!memoizedAddressTableLookupEncoder) {
476
+ memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder(
424
477
  [
425
- "writableIndices",
426
- umiSerializers.array(umiSerializers.u8(), {
427
- ...__DEV__ ? {
428
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
429
- } : null,
430
- size: umiSerializers.shortU16()
431
- })
478
+ ["lookupTableAddress", addresses.getAddressEncoder({ description: lookupTableAddressDescription })],
479
+ [
480
+ "writableIndices",
481
+ codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
482
+ description: writableIndicesDescription,
483
+ size: codecsNumbers.getShortU16Encoder()
484
+ })
485
+ ],
486
+ [
487
+ "readableIndices",
488
+ codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
489
+ description: readableIndicesDescription,
490
+ size: codecsNumbers.getShortU16Encoder()
491
+ })
492
+ ]
432
493
  ],
433
- [
434
- "readableIndices",
435
- umiSerializers.array(umiSerializers.u8(), {
436
- ...__DEV__ ? {
437
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
438
- } : void 0,
439
- size: umiSerializers.shortU16()
440
- })
441
- ]
442
- ],
443
- __DEV__ ? {
444
- 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"
445
- } : void 0
446
- );
494
+ { description: addressTableLookupDescription }
495
+ );
496
+ }
497
+ return memoizedAddressTableLookupEncoder;
498
+ }
499
+ var memoizedU8Encoder;
500
+ function getMemoizedU8Encoder() {
501
+ if (!memoizedU8Encoder)
502
+ memoizedU8Encoder = codecsNumbers.getU8Encoder();
503
+ return memoizedU8Encoder;
504
+ }
505
+ function getMemoizedU8EncoderDescription(description) {
506
+ const encoder = getMemoizedU8Encoder();
507
+ return {
508
+ ...encoder,
509
+ description: description ?? encoder.description
510
+ };
447
511
  }
448
- function getMessageHeaderCodec() {
449
- return umiSerializers.struct(
512
+ 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;
513
+ 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;
514
+ var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
515
+ var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
516
+ function getMessageHeaderEncoder() {
517
+ return codecsDataStructures.getStructEncoder(
450
518
  [
451
- [
452
- "numSignerAccounts",
453
- umiSerializers.u8(
454
- __DEV__ ? {
455
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
456
- } : void 0
457
- )
458
- ],
459
- [
460
- "numReadonlySignerAccounts",
461
- umiSerializers.u8(
462
- __DEV__ ? {
463
- 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"
464
- } : void 0
465
- )
466
- ],
467
- [
468
- "numReadonlyNonSignerAccounts",
469
- umiSerializers.u8(
470
- __DEV__ ? {
471
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
472
- } : void 0
473
- )
474
- ]
519
+ ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
520
+ ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
521
+ ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
475
522
  ],
476
- __DEV__ ? {
477
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
478
- } : void 0
479
- );
480
- }
481
- function getInstructionCodec() {
482
- return umiSerializers.mapSerializer(
483
- umiSerializers.struct([
484
- [
485
- "programAddressIndex",
486
- umiSerializers.u8(
487
- __DEV__ ? {
488
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
489
- } : void 0
490
- )
491
- ],
492
- [
493
- "addressIndices",
494
- umiSerializers.array(
495
- umiSerializers.u8({
496
- description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
497
- }),
498
- {
499
- 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" : "",
500
- size: umiSerializers.shortU16()
501
- }
502
- )
503
- ],
504
- [
505
- "data",
506
- umiSerializers.bytes({
507
- description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
508
- size: umiSerializers.shortU16()
509
- })
510
- ]
511
- ]),
512
- (value) => {
513
- if (value.addressIndices !== void 0 && value.data !== void 0) {
514
- return value;
515
- }
516
- return {
517
- ...value,
518
- addressIndices: value.addressIndices ?? [],
519
- data: value.data ?? new Uint8Array(0)
520
- };
521
- },
522
- (value) => {
523
- if (value.addressIndices.length && value.data.byteLength) {
524
- return value;
525
- }
526
- const { addressIndices, data, ...rest } = value;
527
- return {
528
- ...rest,
529
- ...addressIndices.length ? { addressIndices } : null,
530
- ...data.byteLength ? { data } : null
531
- };
523
+ {
524
+ description: messageHeaderDescription
532
525
  }
533
526
  );
534
527
  }
535
-
536
- // src/serializers/unimplemented.ts
537
- function getError(type, name) {
538
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
539
- return new Error(
540
- `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}`
541
- );
542
- }
543
- function getUnimplementedDecoder(name) {
544
- return () => {
545
- throw getError("decoder", name);
546
- };
528
+ var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
529
+ var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
530
+ 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";
531
+ var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
532
+ var memoizedGetInstructionEncoder;
533
+ function getInstructionEncoder() {
534
+ if (!memoizedGetInstructionEncoder) {
535
+ memoizedGetInstructionEncoder = codecsCore.mapEncoder(
536
+ codecsDataStructures.getStructEncoder([
537
+ ["programAddressIndex", codecsNumbers.getU8Encoder({ description: programAddressIndexDescription })],
538
+ [
539
+ "accountIndices",
540
+ codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder({ description: accountIndexDescription }), {
541
+ description: accountIndicesDescription,
542
+ size: codecsNumbers.getShortU16Encoder()
543
+ })
544
+ ],
545
+ ["data", codecsDataStructures.getBytesEncoder({ description: dataDescription, size: codecsNumbers.getShortU16Encoder() })]
546
+ ]),
547
+ // Convert an instruction to have all fields defined
548
+ (instruction) => {
549
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
550
+ return instruction;
551
+ }
552
+ return {
553
+ ...instruction,
554
+ accountIndices: instruction.accountIndices ?? [],
555
+ data: instruction.data ?? new Uint8Array(0)
556
+ };
557
+ }
558
+ );
559
+ }
560
+ return memoizedGetInstructionEncoder;
547
561
  }
548
-
549
- // src/serializers/transaction-version.ts
550
562
  var VERSION_FLAG_MASK = 128;
551
563
  var BASE_CONFIG = {
552
564
  description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
553
565
  fixedSize: null,
554
566
  maxSize: 1
555
567
  };
556
- function deserialize(bytes3, offset = 0) {
557
- const firstByte = bytes3[offset];
558
- if ((firstByte & VERSION_FLAG_MASK) === 0) {
559
- return ["legacy", offset];
560
- } else {
561
- const version = firstByte ^ VERSION_FLAG_MASK;
562
- return [version, offset + 1];
563
- }
564
- }
565
- function serialize(value) {
568
+ function encode(value) {
566
569
  if (value === "legacy") {
567
570
  return new Uint8Array();
568
571
  }
@@ -571,99 +574,175 @@ function serialize(value) {
571
574
  }
572
575
  return new Uint8Array([value | VERSION_FLAG_MASK]);
573
576
  }
574
- function getTransactionVersionCodec() {
577
+ function getTransactionVersionEncoder() {
575
578
  return {
576
579
  ...BASE_CONFIG,
577
- deserialize,
578
- serialize
580
+ encode
579
581
  };
580
582
  }
581
583
 
582
584
  // src/serializers/message.ts
583
- var BASE_CONFIG2 = {
584
- description: __DEV__ ? "The wire format of a Solana transaction message" : "",
585
- fixedSize: null,
586
- maxSize: null
587
- };
588
- function serialize2(compiledMessage) {
589
- if (compiledMessage.version === "legacy") {
590
- return umiSerializers.struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
591
- } else {
592
- return umiSerializers.mapSerializer(
593
- umiSerializers.struct([
594
- ...getPreludeStructSerializerTuple(),
595
- ["addressTableLookups", getAddressTableLookupsSerializer()]
596
- ]),
597
- (value) => {
598
- if (value.version === "legacy") {
599
- return value;
600
- }
601
- return {
602
- ...value,
603
- addressTableLookups: value.addressTableLookups ?? []
604
- };
585
+ var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
586
+ var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
587
+ var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
588
+ var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
589
+ function getCompiledMessageLegacyEncoder() {
590
+ return codecsDataStructures.getStructEncoder(getPreludeStructEncoderTuple());
591
+ }
592
+ function getCompiledMessageVersionedEncoder() {
593
+ return codecsCore.mapEncoder(
594
+ codecsDataStructures.getStructEncoder([
595
+ ...getPreludeStructEncoderTuple(),
596
+ ["addressTableLookups", getAddressTableLookupArrayEncoder()]
597
+ ]),
598
+ (value) => {
599
+ if (value.version === "legacy") {
600
+ return value;
605
601
  }
606
- ).serialize(compiledMessage);
607
- }
602
+ return {
603
+ ...value,
604
+ addressTableLookups: value.addressTableLookups ?? []
605
+ };
606
+ }
607
+ );
608
608
  }
609
- function getPreludeStructSerializerTuple() {
609
+ function getPreludeStructEncoderTuple() {
610
610
  return [
611
- ["version", getTransactionVersionCodec()],
612
- ["header", getMessageHeaderCodec()],
611
+ ["version", getTransactionVersionEncoder()],
612
+ ["header", getMessageHeaderEncoder()],
613
613
  [
614
614
  "staticAccounts",
615
- umiSerializers.array(keys.getBase58EncodedAddressCodec(), {
616
- description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
617
- size: umiSerializers.shortU16()
615
+ codecsDataStructures.getArrayEncoder(addresses.getAddressEncoder(), {
616
+ description: staticAccountsDescription,
617
+ size: codecsNumbers.getShortU16Encoder()
618
618
  })
619
619
  ],
620
620
  [
621
621
  "lifetimeToken",
622
- umiSerializers.string({
623
- description: __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "",
624
- encoding: umiSerializers.base58,
622
+ codecsStrings.getStringEncoder({
623
+ description: lifetimeTokenDescription,
624
+ encoding: codecsStrings.getBase58Encoder(),
625
625
  size: 32
626
626
  })
627
627
  ],
628
628
  [
629
629
  "instructions",
630
- umiSerializers.array(getInstructionCodec(), {
631
- description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "",
632
- size: umiSerializers.shortU16()
630
+ codecsDataStructures.getArrayEncoder(getInstructionEncoder(), {
631
+ description: instructionsDescription,
632
+ size: codecsNumbers.getShortU16Encoder()
633
633
  })
634
634
  ]
635
635
  ];
636
636
  }
637
- function getAddressTableLookupsSerializer() {
638
- return umiSerializers.array(getAddressTableLookupCodec(), {
639
- ...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null,
640
- size: umiSerializers.shortU16()
637
+ function getAddressTableLookupArrayEncoder() {
638
+ return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), {
639
+ description: addressTableLookupsDescription,
640
+ size: codecsNumbers.getShortU16Encoder()
641
641
  });
642
642
  }
643
+ var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
643
644
  function getCompiledMessageEncoder() {
644
645
  return {
645
- ...BASE_CONFIG2,
646
- deserialize: getUnimplementedDecoder("CompiledMessage"),
647
- serialize: serialize2
646
+ description: messageDescription,
647
+ encode: (compiledMessage) => {
648
+ if (compiledMessage.version === "legacy") {
649
+ return getCompiledMessageLegacyEncoder().encode(compiledMessage);
650
+ } else {
651
+ return getCompiledMessageVersionedEncoder().encode(compiledMessage);
652
+ }
653
+ },
654
+ fixedSize: null,
655
+ maxSize: null
648
656
  };
649
657
  }
650
658
 
651
- // src/signatures.ts
659
+ // src/serializers/transaction.ts
660
+ var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
661
+ var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
662
+ function getCompiledTransactionEncoder() {
663
+ return codecsDataStructures.getStructEncoder(
664
+ [
665
+ [
666
+ "signatures",
667
+ codecsDataStructures.getArrayEncoder(codecsDataStructures.getBytesEncoder({ size: 64 }), {
668
+ description: signaturesDescription,
669
+ size: codecsNumbers.getShortU16Encoder()
670
+ })
671
+ ],
672
+ ["compiledMessage", getCompiledMessageEncoder()]
673
+ ],
674
+ {
675
+ description: transactionDescription
676
+ }
677
+ );
678
+ }
679
+ function getTransactionEncoder() {
680
+ return codecsCore.mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
681
+ }
682
+ function assertIsTransactionSignature(putativeTransactionSignature) {
683
+ try {
684
+ if (
685
+ // Lowest value (64 bytes of zeroes)
686
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
687
+ putativeTransactionSignature.length > 88
688
+ ) {
689
+ throw new Error("Expected input string to decode to a byte array of length 64.");
690
+ }
691
+ const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
692
+ const numBytes = bytes.byteLength;
693
+ if (numBytes !== 64) {
694
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
695
+ }
696
+ } catch (e) {
697
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
698
+ cause: e
699
+ });
700
+ }
701
+ }
702
+ function isTransactionSignature(putativeTransactionSignature) {
703
+ if (
704
+ // Lowest value (64 bytes of zeroes)
705
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
706
+ putativeTransactionSignature.length > 88
707
+ ) {
708
+ return false;
709
+ }
710
+ const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
711
+ const numBytes = bytes.byteLength;
712
+ if (numBytes !== 64) {
713
+ return false;
714
+ }
715
+ return true;
716
+ }
652
717
  async function getCompiledMessageSignature(message, secretKey) {
653
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
718
+ const wireMessageBytes = getCompiledMessageEncoder().encode(message);
654
719
  const signature = await keys.signBytes(secretKey, wireMessageBytes);
655
720
  return signature;
656
721
  }
657
- async function signTransaction(keyPair, transaction) {
722
+ function getSignatureFromTransaction(transaction) {
723
+ const signatureBytes = transaction.signatures[transaction.feePayer];
724
+ if (!signatureBytes) {
725
+ throw new Error(
726
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
727
+ );
728
+ }
729
+ const transactionSignature2 = umiSerializers.base58.deserialize(signatureBytes)[0];
730
+ return transactionSignature2;
731
+ }
732
+ async function signTransaction(keyPairs, transaction) {
658
733
  const compiledMessage = compileMessage(transaction);
659
- const [signerPublicKey, signature] = await Promise.all([
660
- keys.getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
661
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
662
- ]);
663
- const nextSignatures = {
664
- ..."signatures" in transaction ? transaction.signatures : null,
665
- ...{ [signerPublicKey]: signature }
666
- };
734
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
735
+ const publicKeySignaturePairs = await Promise.all(
736
+ keyPairs.map(
737
+ (keyPair) => Promise.all([
738
+ addresses.getAddressFromPublicKey(keyPair.publicKey),
739
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
740
+ ])
741
+ )
742
+ );
743
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
744
+ nextSignatures[signerPublicKey] = signature;
745
+ }
667
746
  const out = {
668
747
  ...transaction,
669
748
  signatures: nextSignatures
@@ -671,55 +750,14 @@ async function signTransaction(keyPair, transaction) {
671
750
  Object.freeze(out);
672
751
  return out;
673
752
  }
674
-
675
- // src/compile-transaction.ts
676
- function getCompiledTransaction(transaction) {
677
- const compiledMessage = compileMessage(transaction);
678
- let signatures;
679
- if ("signatures" in transaction) {
680
- signatures = [];
681
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
682
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
683
- }
684
- } else {
685
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
686
- }
687
- return {
688
- compiledMessage,
689
- signatures
690
- };
691
- }
692
-
693
- // src/serializers/transaction.ts
694
- var BASE_CONFIG3 = {
695
- description: __DEV__ ? "The wire format of a Solana transaction" : "",
696
- fixedSize: null,
697
- maxSize: null
698
- };
699
- function serialize3(transaction) {
700
- const compiledTransaction = getCompiledTransaction(transaction);
701
- return umiSerializers.struct([
702
- [
703
- "signatures",
704
- umiSerializers.array(umiSerializers.bytes({ size: 64 }), {
705
- ...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
706
- size: umiSerializers.shortU16()
707
- })
708
- ],
709
- ["compiledMessage", getCompiledMessageEncoder()]
710
- ]).serialize(compiledTransaction);
711
- }
712
- function getTransactionEncoder() {
713
- return {
714
- ...BASE_CONFIG3,
715
- deserialize: getUnimplementedDecoder("CompiledMessage"),
716
- serialize: serialize3
717
- };
753
+ function transactionSignature(putativeTransactionSignature) {
754
+ assertIsTransactionSignature(putativeTransactionSignature);
755
+ return putativeTransactionSignature;
718
756
  }
719
757
 
720
758
  // src/wire-transaction.ts
721
759
  function getBase64EncodedWireTransaction(transaction) {
722
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
760
+ const wireTransactionBytes = getTransactionEncoder().encode(transaction);
723
761
  {
724
762
  return btoa(String.fromCharCode(...wireTransactionBytes));
725
763
  }
@@ -727,11 +765,17 @@ function getBase64EncodedWireTransaction(transaction) {
727
765
 
728
766
  exports.appendTransactionInstruction = appendTransactionInstruction;
729
767
  exports.assertIsBlockhash = assertIsBlockhash;
768
+ exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
769
+ exports.assertIsTransactionSignature = assertIsTransactionSignature;
730
770
  exports.createTransaction = createTransaction;
731
771
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
772
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
773
+ exports.getTransactionEncoder = getTransactionEncoder;
774
+ exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
775
+ exports.isTransactionSignature = isTransactionSignature;
732
776
  exports.prependTransactionInstruction = prependTransactionInstruction;
733
777
  exports.setTransactionFeePayer = setTransactionFeePayer;
734
778
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
779
+ exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
735
780
  exports.signTransaction = signTransaction;
736
- //# sourceMappingURL=out.js.map
737
- //# sourceMappingURL=index.browser.cjs.map
781
+ exports.transactionSignature = transactionSignature;