@solana/transactions 2.0.0-experimental.98b85fd → 2.0.0-experimental.99a64e9

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.
@@ -1,8 +1,28 @@
1
1
  import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers';
2
- import { getBase58EncodedAddressFromPublicKey, signBytes, getBase58EncodedAddressComparator, getBase58EncodedAddressCodec } from '@solana/keys';
2
+ import { getAddressFromPublicKey, getAddressComparator, getAddressCodec } from '@solana/addresses';
3
+ import { getStructCodec } from '@solana/codecs-data-structures';
4
+ import { getU8Codec } from '@solana/codecs-numbers';
5
+ import { combineCodec } from '@solana/codecs-core';
6
+ import { signBytes } from '@solana/keys';
3
7
 
4
8
  // ../build-scripts/env-shim.ts
5
9
  var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
10
+
11
+ // src/unsigned-transaction.ts
12
+ function getUnsignedTransaction(transaction) {
13
+ if ("signatures" in transaction) {
14
+ const {
15
+ signatures: _,
16
+ // eslint-disable-line @typescript-eslint/no-unused-vars
17
+ ...unsignedTransaction
18
+ } = transaction;
19
+ return unsignedTransaction;
20
+ } else {
21
+ return transaction;
22
+ }
23
+ }
24
+
25
+ // src/blockhash.ts
6
26
  function assertIsBlockhash(putativeBlockhash) {
7
27
  try {
8
28
  if (
@@ -23,6 +43,17 @@ function assertIsBlockhash(putativeBlockhash) {
23
43
  });
24
44
  }
25
45
  }
46
+ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
47
+ if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
48
+ return transaction;
49
+ }
50
+ const out = {
51
+ ...getUnsignedTransaction(transaction),
52
+ lifetimeConstraint: blockhashLifetimeConstraint
53
+ };
54
+ Object.freeze(out);
55
+ return out;
56
+ }
26
57
 
27
58
  // src/create-transaction.ts
28
59
  function createTransaction({
@@ -36,66 +67,6 @@ function createTransaction({
36
67
  return out;
37
68
  }
38
69
 
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
70
  // ../instructions/dist/index.browser.js
100
71
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
101
72
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
@@ -118,6 +89,96 @@ function isWritableRole(role) {
118
89
  function mergeRoles(roleA, roleB) {
119
90
  return roleA | roleB;
120
91
  }
92
+
93
+ // src/durable-nonce.ts
94
+ var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
95
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
96
+ function assertIsDurableNonceTransaction(transaction) {
97
+ if (!isDurableNonceTransaction(transaction)) {
98
+ throw new Error("Transaction is not a durable nonce transaction");
99
+ }
100
+ }
101
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
102
+ return {
103
+ accounts: [
104
+ { address: nonceAccountAddress, role: AccountRole.WRITABLE },
105
+ {
106
+ address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
107
+ role: AccountRole.READONLY
108
+ },
109
+ { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
110
+ ],
111
+ data: new Uint8Array([4, 0, 0, 0]),
112
+ programAddress: SYSTEM_PROGRAM_ADDRESS
113
+ };
114
+ }
115
+ function isAdvanceNonceAccountInstruction(instruction) {
116
+ return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
117
+ instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
118
+ instruction.accounts?.length === 3 && // First account is nonce account address
119
+ instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
120
+ instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
121
+ instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
122
+ }
123
+ function isAdvanceNonceAccountInstructionData(data) {
124
+ return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
125
+ }
126
+ function isDurableNonceTransaction(transaction) {
127
+ return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
128
+ }
129
+ function setTransactionLifetimeUsingDurableNonce({
130
+ nonce,
131
+ nonceAccountAddress,
132
+ nonceAuthorityAddress
133
+ }, transaction) {
134
+ const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
135
+ if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
136
+ return transaction;
137
+ }
138
+ const out = {
139
+ ...getUnsignedTransaction(transaction),
140
+ instructions: [
141
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
142
+ ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
143
+ ],
144
+ lifetimeConstraint: {
145
+ nonce
146
+ }
147
+ };
148
+ Object.freeze(out);
149
+ return out;
150
+ }
151
+
152
+ // src/fee-payer.ts
153
+ function setTransactionFeePayer(feePayer, transaction) {
154
+ if ("feePayer" in transaction && feePayer === transaction.feePayer) {
155
+ return transaction;
156
+ }
157
+ const out = {
158
+ ...getUnsignedTransaction(transaction),
159
+ feePayer
160
+ };
161
+ Object.freeze(out);
162
+ return out;
163
+ }
164
+
165
+ // src/instructions.ts
166
+ function appendTransactionInstruction(instruction, transaction) {
167
+ const out = {
168
+ ...getUnsignedTransaction(transaction),
169
+ instructions: [...transaction.instructions, instruction]
170
+ };
171
+ Object.freeze(out);
172
+ return out;
173
+ }
174
+ function prependTransactionInstruction(instruction, transaction) {
175
+ const out = {
176
+ ...getUnsignedTransaction(transaction),
177
+ instructions: [instruction, ...transaction.instructions]
178
+ };
179
+ Object.freeze(out);
180
+ return out;
181
+ }
121
182
  function upsert(addressMap, address, update) {
122
183
  addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
123
184
  }
@@ -170,7 +231,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
170
231
  const shouldReplaceEntry = (
171
232
  // Consider using the new LOOKUP_TABLE if its address is different...
172
233
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
173
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
234
+ (addressComparator || (addressComparator = getAddressComparator()))(
174
235
  accountMeta.lookupTableAddress,
175
236
  entry.lookupTableAddress
176
237
  ) < 0
@@ -276,7 +337,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
276
337
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
277
338
  return leftIsWritable ? -1 : 1;
278
339
  }
279
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
340
+ addressComparator || (addressComparator = getAddressComparator());
280
341
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
281
342
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
282
343
  } else {
@@ -305,7 +366,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
305
366
  entry.readableIndices.push(account.addressIndex);
306
367
  }
307
368
  }
308
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
369
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
309
370
  lookupTableAddress,
310
371
  ...index[lookupTableAddress]
311
372
  }));
@@ -384,12 +445,40 @@ function compileMessage(transaction) {
384
445
  version: transaction.version
385
446
  };
386
447
  }
448
+
449
+ // src/compile-transaction.ts
450
+ function getCompiledTransaction(transaction) {
451
+ const compiledMessage = compileMessage(transaction);
452
+ let signatures;
453
+ if ("signatures" in transaction) {
454
+ signatures = [];
455
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
456
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
457
+ }
458
+ } else {
459
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
460
+ }
461
+ return {
462
+ compiledMessage,
463
+ signatures
464
+ };
465
+ }
466
+ function addressSerializerCompat(compat) {
467
+ const codec = getAddressCodec();
468
+ return {
469
+ description: compat?.description ?? codec.description,
470
+ deserialize: codec.decode,
471
+ fixedSize: codec.fixedSize,
472
+ maxSize: codec.maxSize,
473
+ serialize: codec.encode
474
+ };
475
+ }
387
476
  function getAddressTableLookupCodec() {
388
477
  return struct(
389
478
  [
390
479
  [
391
480
  "lookupTableAddress",
392
- getBase58EncodedAddressCodec(
481
+ addressSerializerCompat(
393
482
  __DEV__ ? {
394
483
  description: "The address of the address lookup table account from which instruction addresses should be looked up"
395
484
  } : void 0
@@ -419,37 +508,33 @@ function getAddressTableLookupCodec() {
419
508
  } : void 0
420
509
  );
421
510
  }
511
+ var memoizedU8Codec;
512
+ function getMemoizedU8Codec() {
513
+ if (!memoizedU8Codec)
514
+ memoizedU8Codec = getU8Codec();
515
+ return memoizedU8Codec;
516
+ }
517
+ function getMemoizedU8CodecDescription(description) {
518
+ const codec = getMemoizedU8Codec();
519
+ return {
520
+ ...codec,
521
+ description: description ?? codec.description
522
+ };
523
+ }
524
+ 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;
525
+ 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;
526
+ var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
527
+ var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
422
528
  function getMessageHeaderCodec() {
423
- return struct(
529
+ return getStructCodec(
424
530
  [
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
- ]
531
+ ["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
532
+ ["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
533
+ ["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
449
534
  ],
450
- __DEV__ ? {
451
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
452
- } : void 0
535
+ {
536
+ description: messageHeaderDescription
537
+ }
453
538
  );
454
539
  }
455
540
  function getInstructionCodec() {
@@ -464,7 +549,7 @@ function getInstructionCodec() {
464
549
  )
465
550
  ],
466
551
  [
467
- "addressIndices",
552
+ "accountIndices",
468
553
  array(
469
554
  u8({
470
555
  description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
@@ -484,50 +569,35 @@ function getInstructionCodec() {
484
569
  ]
485
570
  ]),
486
571
  (value) => {
487
- if (value.addressIndices !== void 0 && value.data !== void 0) {
572
+ if (value.accountIndices !== void 0 && value.data !== void 0) {
488
573
  return value;
489
574
  }
490
575
  return {
491
576
  ...value,
492
- addressIndices: value.addressIndices ?? [],
577
+ accountIndices: value.accountIndices ?? [],
493
578
  data: value.data ?? new Uint8Array(0)
494
579
  };
495
580
  },
496
581
  (value) => {
497
- if (value.addressIndices.length && value.data.byteLength) {
582
+ if (value.accountIndices.length && value.data.byteLength) {
498
583
  return value;
499
584
  }
500
- const { addressIndices, data, ...rest } = value;
585
+ const { accountIndices, data, ...rest } = value;
501
586
  return {
502
587
  ...rest,
503
- ...addressIndices.length ? { addressIndices } : null,
588
+ ...accountIndices.length ? { accountIndices } : null,
504
589
  ...data.byteLength ? { data } : null
505
590
  };
506
591
  }
507
592
  );
508
593
  }
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
- );
516
- }
517
- function getUnimplementedDecoder(name) {
518
- return () => {
519
- throw getError("decoder", name);
520
- };
521
- }
522
-
523
- // src/serializers/transaction-version.ts
524
594
  var VERSION_FLAG_MASK = 128;
525
595
  var BASE_CONFIG = {
526
596
  description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
527
597
  fixedSize: null,
528
598
  maxSize: 1
529
599
  };
530
- function deserialize(bytes3, offset = 0) {
600
+ function decode(bytes3, offset = 0) {
531
601
  const firstByte = bytes3[offset];
532
602
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
533
603
  return ["legacy", offset];
@@ -536,7 +606,7 @@ function deserialize(bytes3, offset = 0) {
536
606
  return [version, offset + 1];
537
607
  }
538
608
  }
539
- function serialize(value) {
609
+ function encode(value) {
540
610
  if (value === "legacy") {
541
611
  return new Uint8Array();
542
612
  }
@@ -545,11 +615,32 @@ function serialize(value) {
545
615
  }
546
616
  return new Uint8Array([value | VERSION_FLAG_MASK]);
547
617
  }
548
- function getTransactionVersionCodec() {
618
+ function getTransactionVersionDecoder() {
549
619
  return {
550
620
  ...BASE_CONFIG,
551
- deserialize,
552
- serialize
621
+ decode
622
+ };
623
+ }
624
+ function getTransactionVersionEncoder() {
625
+ return {
626
+ ...BASE_CONFIG,
627
+ encode
628
+ };
629
+ }
630
+ function getTransactionVersionCodec() {
631
+ return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
632
+ }
633
+
634
+ // src/serializers/unimplemented.ts
635
+ function getError(type, name) {
636
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
637
+ return new Error(
638
+ `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}`
639
+ );
640
+ }
641
+ function getUnimplementedDecoder(name) {
642
+ return () => {
643
+ throw getError("decoder", name);
553
644
  };
554
645
  }
555
646
 
@@ -559,7 +650,7 @@ var BASE_CONFIG2 = {
559
650
  fixedSize: null,
560
651
  maxSize: null
561
652
  };
562
- function serialize2(compiledMessage) {
653
+ function serialize(compiledMessage) {
563
654
  if (compiledMessage.version === "legacy") {
564
655
  return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
565
656
  } else {
@@ -580,13 +671,22 @@ function serialize2(compiledMessage) {
580
671
  ).serialize(compiledMessage);
581
672
  }
582
673
  }
674
+ function toSerializer(codec) {
675
+ return {
676
+ description: codec.description,
677
+ deserialize: codec.decode,
678
+ fixedSize: codec.fixedSize,
679
+ maxSize: codec.maxSize,
680
+ serialize: codec.encode
681
+ };
682
+ }
583
683
  function getPreludeStructSerializerTuple() {
584
684
  return [
585
- ["version", getTransactionVersionCodec()],
586
- ["header", getMessageHeaderCodec()],
685
+ ["version", toSerializer(getTransactionVersionCodec())],
686
+ ["header", toSerializer(getMessageHeaderCodec())],
587
687
  [
588
688
  "staticAccounts",
589
- array(getBase58EncodedAddressCodec(), {
689
+ array(toSerializer(getAddressCodec()), {
590
690
  description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
591
691
  size: shortU16()
592
692
  })
@@ -618,49 +718,7 @@ function getCompiledMessageEncoder() {
618
718
  return {
619
719
  ...BASE_CONFIG2,
620
720
  deserialize: getUnimplementedDecoder("CompiledMessage"),
621
- serialize: serialize2
622
- };
623
- }
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;
630
- }
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;
647
- }
648
-
649
- // src/compile-transaction.ts
650
- function getCompiledTransaction(transaction) {
651
- const compiledMessage = compileMessage(transaction);
652
- let signatures;
653
- if ("signatures" in transaction) {
654
- signatures = [];
655
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
656
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
657
- }
658
- } else {
659
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
660
- }
661
- return {
662
- compiledMessage,
663
- signatures
721
+ serialize
664
722
  };
665
723
  }
666
724
 
@@ -670,7 +728,7 @@ var BASE_CONFIG3 = {
670
728
  fixedSize: null,
671
729
  maxSize: null
672
730
  };
673
- function serialize3(transaction) {
731
+ function serialize2(transaction) {
674
732
  const compiledTransaction = getCompiledTransaction(transaction);
675
733
  return struct([
676
734
  [
@@ -687,9 +745,84 @@ function getTransactionEncoder() {
687
745
  return {
688
746
  ...BASE_CONFIG3,
689
747
  deserialize: getUnimplementedDecoder("CompiledMessage"),
690
- serialize: serialize3
748
+ serialize: serialize2
691
749
  };
692
750
  }
751
+ function assertIsTransactionSignature(putativeTransactionSignature) {
752
+ try {
753
+ if (
754
+ // Lowest value (64 bytes of zeroes)
755
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
756
+ putativeTransactionSignature.length > 88
757
+ ) {
758
+ throw new Error("Expected input string to decode to a byte array of length 64.");
759
+ }
760
+ const bytes3 = base58.serialize(putativeTransactionSignature);
761
+ const numBytes = bytes3.byteLength;
762
+ if (numBytes !== 64) {
763
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
764
+ }
765
+ } catch (e) {
766
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
767
+ cause: e
768
+ });
769
+ }
770
+ }
771
+ function isTransactionSignature(putativeTransactionSignature) {
772
+ if (
773
+ // Lowest value (64 bytes of zeroes)
774
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
775
+ putativeTransactionSignature.length > 88
776
+ ) {
777
+ return false;
778
+ }
779
+ const bytes3 = base58.serialize(putativeTransactionSignature);
780
+ const numBytes = bytes3.byteLength;
781
+ if (numBytes !== 64) {
782
+ return false;
783
+ }
784
+ return true;
785
+ }
786
+ async function getCompiledMessageSignature(message, secretKey) {
787
+ const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
788
+ const signature = await signBytes(secretKey, wireMessageBytes);
789
+ return signature;
790
+ }
791
+ function getSignatureFromTransaction(transaction) {
792
+ const signatureBytes = transaction.signatures[transaction.feePayer];
793
+ if (!signatureBytes) {
794
+ throw new Error(
795
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
796
+ );
797
+ }
798
+ const transactionSignature2 = base58.deserialize(signatureBytes)[0];
799
+ return transactionSignature2;
800
+ }
801
+ async function signTransaction(keyPairs, transaction) {
802
+ const compiledMessage = compileMessage(transaction);
803
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
804
+ const publicKeySignaturePairs = await Promise.all(
805
+ keyPairs.map(
806
+ (keyPair) => Promise.all([
807
+ getAddressFromPublicKey(keyPair.publicKey),
808
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
809
+ ])
810
+ )
811
+ );
812
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
813
+ nextSignatures[signerPublicKey] = signature;
814
+ }
815
+ const out = {
816
+ ...transaction,
817
+ signatures: nextSignatures
818
+ };
819
+ Object.freeze(out);
820
+ return out;
821
+ }
822
+ function transactionSignature(putativeTransactionSignature) {
823
+ assertIsTransactionSignature(putativeTransactionSignature);
824
+ return putativeTransactionSignature;
825
+ }
693
826
 
694
827
  // src/wire-transaction.ts
695
828
  function getBase64EncodedWireTransaction(transaction) {
@@ -699,6 +832,4 @@ function getBase64EncodedWireTransaction(transaction) {
699
832
  }
700
833
  }
701
834
 
702
- export { appendTransactionInstruction, assertIsBlockhash, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, signTransaction };
703
- //# sourceMappingURL=out.js.map
704
- //# sourceMappingURL=index.browser.js.map
835
+ export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };