@solana/transactions 2.0.0-experimental.71b920d → 2.0.0-experimental.72efece

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018 Solana Labs, Inc
1
+ Copyright (c) 2023 Solana Labs, Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,79 +1,70 @@
1
1
  'use strict';
2
2
 
3
- var keys = require('@solana/keys');
4
3
  var umiSerializers = require('@metaplex-foundation/umi-serializers');
4
+ var addresses = require('@solana/addresses');
5
+ var codecsDataStructures = require('@solana/codecs-data-structures');
6
+ var codecsNumbers = require('@solana/codecs-numbers');
7
+ var codecsCore = require('@solana/codecs-core');
8
+ var keys = require('@solana/keys');
5
9
 
6
10
  // ../build-scripts/env-shim.ts
7
11
  var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
8
12
 
9
- // src/create-transaction.ts
10
- function createTransaction({
11
- version
12
- }) {
13
- const out = {
14
- instructions: [],
15
- version
16
- };
17
- Object.freeze(out);
18
- return out;
19
- }
20
-
21
- // src/fee-payer.ts
22
- function setTransactionFeePayer(feePayer, transaction) {
23
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
24
- return transaction;
25
- }
26
- let out;
13
+ // src/unsigned-transaction.ts
14
+ function getUnsignedTransaction(transaction) {
27
15
  if ("signatures" in transaction) {
28
16
  const {
29
17
  signatures: _,
30
18
  // eslint-disable-line @typescript-eslint/no-unused-vars
31
19
  ...unsignedTransaction
32
20
  } = transaction;
33
- out = {
34
- ...unsignedTransaction,
35
- feePayer
36
- };
21
+ return unsignedTransaction;
37
22
  } else {
38
- out = {
39
- ...transaction,
40
- feePayer
41
- };
23
+ return transaction;
42
24
  }
43
- Object.freeze(out);
44
- return out;
45
25
  }
46
26
 
47
- // src/instructions.ts
48
- function replaceInstructions(transaction, nextInstructions) {
49
- let out;
50
- if ("signatures" in transaction) {
51
- const {
52
- signatures: _,
53
- // eslint-disable-line @typescript-eslint/no-unused-vars
54
- ...unsignedTransaction
55
- } = transaction;
56
- out = {
57
- ...unsignedTransaction,
58
- instructions: nextInstructions
59
- };
60
- } else {
61
- out = {
62
- ...transaction,
63
- instructions: nextInstructions
64
- };
27
+ // src/blockhash.ts
28
+ function assertIsBlockhash(putativeBlockhash) {
29
+ try {
30
+ if (
31
+ // Lowest value (32 bytes of zeroes)
32
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
33
+ putativeBlockhash.length > 44
34
+ ) {
35
+ throw new Error("Expected input string to decode to a byte array of length 32.");
36
+ }
37
+ const bytes3 = umiSerializers.base58.serialize(putativeBlockhash);
38
+ const numBytes = bytes3.byteLength;
39
+ if (numBytes !== 32) {
40
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
41
+ }
42
+ } catch (e) {
43
+ throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
44
+ cause: e
45
+ });
65
46
  }
66
- return out;
67
47
  }
68
- function appendTransactionInstruction(instruction, transaction) {
69
- const nextInstructions = [...transaction.instructions, instruction];
70
- const out = replaceInstructions(transaction, nextInstructions);
48
+ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
49
+ if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
50
+ return transaction;
51
+ }
52
+ const out = {
53
+ ...getUnsignedTransaction(transaction),
54
+ lifetimeConstraint: blockhashLifetimeConstraint
55
+ };
71
56
  Object.freeze(out);
72
57
  return out;
73
58
  }
74
- function prependTransactionInstruction(instruction, transaction) {
75
- const nextInstructions = [instruction, ...transaction.instructions];
76
- const out = replaceInstructions(transaction, nextInstructions);
59
+
60
+ // src/create-transaction.ts
61
+ function createTransaction({
62
+ version
63
+ }) {
64
+ const out = {
65
+ instructions: [],
66
+ version
67
+ };
77
68
  Object.freeze(out);
78
69
  return out;
79
70
  }
@@ -100,6 +91,96 @@ function isWritableRole(role) {
100
91
  function mergeRoles(roleA, roleB) {
101
92
  return roleA | roleB;
102
93
  }
94
+
95
+ // src/durable-nonce.ts
96
+ var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
97
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
98
+ function assertIsDurableNonceTransaction(transaction) {
99
+ if (!isDurableNonceTransaction(transaction)) {
100
+ throw new Error("Transaction is not a durable nonce transaction");
101
+ }
102
+ }
103
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
104
+ return {
105
+ accounts: [
106
+ { address: nonceAccountAddress, role: AccountRole.WRITABLE },
107
+ {
108
+ address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
109
+ role: AccountRole.READONLY
110
+ },
111
+ { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
112
+ ],
113
+ data: new Uint8Array([4, 0, 0, 0]),
114
+ programAddress: SYSTEM_PROGRAM_ADDRESS
115
+ };
116
+ }
117
+ function isAdvanceNonceAccountInstruction(instruction) {
118
+ return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
119
+ instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
120
+ instruction.accounts?.length === 3 && // First account is nonce account address
121
+ instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
122
+ instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
123
+ instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
124
+ }
125
+ function isAdvanceNonceAccountInstructionData(data) {
126
+ return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
127
+ }
128
+ function isDurableNonceTransaction(transaction) {
129
+ return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
130
+ }
131
+ function setTransactionLifetimeUsingDurableNonce({
132
+ nonce,
133
+ nonceAccountAddress,
134
+ nonceAuthorityAddress
135
+ }, transaction) {
136
+ const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
137
+ if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
138
+ return transaction;
139
+ }
140
+ const out = {
141
+ ...getUnsignedTransaction(transaction),
142
+ instructions: [
143
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
144
+ ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
145
+ ],
146
+ lifetimeConstraint: {
147
+ nonce
148
+ }
149
+ };
150
+ Object.freeze(out);
151
+ return out;
152
+ }
153
+
154
+ // src/fee-payer.ts
155
+ function setTransactionFeePayer(feePayer, transaction) {
156
+ if ("feePayer" in transaction && feePayer === transaction.feePayer) {
157
+ return transaction;
158
+ }
159
+ const out = {
160
+ ...getUnsignedTransaction(transaction),
161
+ feePayer
162
+ };
163
+ Object.freeze(out);
164
+ return out;
165
+ }
166
+
167
+ // src/instructions.ts
168
+ function appendTransactionInstruction(instruction, transaction) {
169
+ const out = {
170
+ ...getUnsignedTransaction(transaction),
171
+ instructions: [...transaction.instructions, instruction]
172
+ };
173
+ Object.freeze(out);
174
+ return out;
175
+ }
176
+ function prependTransactionInstruction(instruction, transaction) {
177
+ const out = {
178
+ ...getUnsignedTransaction(transaction),
179
+ instructions: [instruction, ...transaction.instructions]
180
+ };
181
+ Object.freeze(out);
182
+ return out;
183
+ }
103
184
  function upsert(addressMap, address, update) {
104
185
  addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
105
186
  }
@@ -152,7 +233,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
152
233
  const shouldReplaceEntry = (
153
234
  // Consider using the new LOOKUP_TABLE if its address is different...
154
235
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
155
- (addressComparator || (addressComparator = keys.getBase58EncodedAddressComparator()))(
236
+ (addressComparator || (addressComparator = addresses.getAddressComparator()))(
156
237
  accountMeta.lookupTableAddress,
157
238
  entry.lookupTableAddress
158
239
  ) < 0
@@ -258,7 +339,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
258
339
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
259
340
  return leftIsWritable ? -1 : 1;
260
341
  }
261
- addressComparator || (addressComparator = keys.getBase58EncodedAddressComparator());
342
+ addressComparator || (addressComparator = addresses.getAddressComparator());
262
343
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
263
344
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
264
345
  } else {
@@ -287,7 +368,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
287
368
  entry.readableIndices.push(account.addressIndex);
288
369
  }
289
370
  }
290
- return Object.keys(index).sort(keys.getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
371
+ return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
291
372
  lookupTableAddress,
292
373
  ...index[lookupTableAddress]
293
374
  }));
@@ -366,12 +447,40 @@ function compileMessage(transaction) {
366
447
  version: transaction.version
367
448
  };
368
449
  }
450
+
451
+ // src/compile-transaction.ts
452
+ function getCompiledTransaction(transaction) {
453
+ const compiledMessage = compileMessage(transaction);
454
+ let signatures;
455
+ if ("signatures" in transaction) {
456
+ signatures = [];
457
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
458
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
459
+ }
460
+ } else {
461
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
462
+ }
463
+ return {
464
+ compiledMessage,
465
+ signatures
466
+ };
467
+ }
468
+ function addressSerializerCompat(compat) {
469
+ const codec = addresses.getAddressCodec();
470
+ return {
471
+ description: compat?.description ?? codec.description,
472
+ deserialize: codec.decode,
473
+ fixedSize: codec.fixedSize,
474
+ maxSize: codec.maxSize,
475
+ serialize: codec.encode
476
+ };
477
+ }
369
478
  function getAddressTableLookupCodec() {
370
479
  return umiSerializers.struct(
371
480
  [
372
481
  [
373
482
  "lookupTableAddress",
374
- keys.getBase58EncodedAddressCodec(
483
+ addressSerializerCompat(
375
484
  __DEV__ ? {
376
485
  description: "The address of the address lookup table account from which instruction addresses should be looked up"
377
486
  } : void 0
@@ -401,37 +510,33 @@ function getAddressTableLookupCodec() {
401
510
  } : void 0
402
511
  );
403
512
  }
513
+ var memoizedU8Codec;
514
+ function getMemoizedU8Codec() {
515
+ if (!memoizedU8Codec)
516
+ memoizedU8Codec = codecsNumbers.getU8Codec();
517
+ return memoizedU8Codec;
518
+ }
519
+ function getMemoizedU8CodecDescription(description) {
520
+ const codec = getMemoizedU8Codec();
521
+ return {
522
+ ...codec,
523
+ description: description ?? codec.description
524
+ };
525
+ }
526
+ var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0;
527
+ var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0;
528
+ var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
529
+ var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
404
530
  function getMessageHeaderCodec() {
405
- return umiSerializers.struct(
531
+ return codecsDataStructures.getStructCodec(
406
532
  [
407
- [
408
- "numSignerAccounts",
409
- umiSerializers.u8(
410
- __DEV__ ? {
411
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
412
- } : void 0
413
- )
414
- ],
415
- [
416
- "numReadonlySignerAccounts",
417
- umiSerializers.u8(
418
- __DEV__ ? {
419
- 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"
420
- } : void 0
421
- )
422
- ],
423
- [
424
- "numReadonlyNonSignerAccounts",
425
- umiSerializers.u8(
426
- __DEV__ ? {
427
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
428
- } : void 0
429
- )
430
- ]
533
+ ["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
534
+ ["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
535
+ ["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
431
536
  ],
432
- __DEV__ ? {
433
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
434
- } : void 0
537
+ {
538
+ description: messageHeaderDescription
539
+ }
435
540
  );
436
541
  }
437
542
  function getInstructionCodec() {
@@ -446,7 +551,7 @@ function getInstructionCodec() {
446
551
  )
447
552
  ],
448
553
  [
449
- "addressIndices",
554
+ "accountIndices",
450
555
  umiSerializers.array(
451
556
  umiSerializers.u8({
452
557
  description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
@@ -466,51 +571,36 @@ function getInstructionCodec() {
466
571
  ]
467
572
  ]),
468
573
  (value) => {
469
- if (value.addressIndices !== void 0 && value.data !== void 0) {
574
+ if (value.accountIndices !== void 0 && value.data !== void 0) {
470
575
  return value;
471
576
  }
472
577
  return {
473
578
  ...value,
474
- addressIndices: value.addressIndices ?? [],
579
+ accountIndices: value.accountIndices ?? [],
475
580
  data: value.data ?? new Uint8Array(0)
476
581
  };
477
582
  },
478
583
  (value) => {
479
- if (value.addressIndices.length && value.data.byteLength) {
584
+ if (value.accountIndices.length && value.data.byteLength) {
480
585
  return value;
481
586
  }
482
- const { addressIndices, data, ...rest } = value;
587
+ const { accountIndices, data, ...rest } = value;
483
588
  return {
484
589
  ...rest,
485
- ...addressIndices.length ? { addressIndices } : null,
590
+ ...accountIndices.length ? { accountIndices } : null,
486
591
  ...data.byteLength ? { data } : null
487
592
  };
488
593
  }
489
594
  );
490
595
  }
491
-
492
- // src/serializers/unimplemented.ts
493
- function getError(type, name) {
494
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
495
- return new Error(
496
- `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}`
497
- );
498
- }
499
- function getUnimplementedDecoder(name) {
500
- return () => {
501
- throw getError("decoder", name);
502
- };
503
- }
504
-
505
- // src/serializers/transaction-version.ts
506
596
  var VERSION_FLAG_MASK = 128;
507
597
  var BASE_CONFIG = {
508
598
  description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
509
599
  fixedSize: null,
510
600
  maxSize: 1
511
601
  };
512
- function deserialize(bytes2, offset = 0) {
513
- const firstByte = bytes2[offset];
602
+ function decode(bytes3, offset = 0) {
603
+ const firstByte = bytes3[offset];
514
604
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
515
605
  return ["legacy", offset];
516
606
  } else {
@@ -518,7 +608,7 @@ function deserialize(bytes2, offset = 0) {
518
608
  return [version, offset + 1];
519
609
  }
520
610
  }
521
- function serialize(value) {
611
+ function encode(value) {
522
612
  if (value === "legacy") {
523
613
  return new Uint8Array();
524
614
  }
@@ -527,11 +617,32 @@ function serialize(value) {
527
617
  }
528
618
  return new Uint8Array([value | VERSION_FLAG_MASK]);
529
619
  }
530
- function getTransactionVersionCodec() {
620
+ function getTransactionVersionDecoder() {
531
621
  return {
532
622
  ...BASE_CONFIG,
533
- deserialize,
534
- serialize
623
+ decode
624
+ };
625
+ }
626
+ function getTransactionVersionEncoder() {
627
+ return {
628
+ ...BASE_CONFIG,
629
+ encode
630
+ };
631
+ }
632
+ function getTransactionVersionCodec() {
633
+ return codecsCore.combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
634
+ }
635
+
636
+ // src/serializers/unimplemented.ts
637
+ function getError(type, name) {
638
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
639
+ return new Error(
640
+ `No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
641
+ );
642
+ }
643
+ function getUnimplementedDecoder(name) {
644
+ return () => {
645
+ throw getError("decoder", name);
535
646
  };
536
647
  }
537
648
 
@@ -541,7 +652,7 @@ var BASE_CONFIG2 = {
541
652
  fixedSize: null,
542
653
  maxSize: null
543
654
  };
544
- function serialize2(compiledMessage) {
655
+ function serialize(compiledMessage) {
545
656
  if (compiledMessage.version === "legacy") {
546
657
  return umiSerializers.struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
547
658
  } else {
@@ -562,13 +673,22 @@ function serialize2(compiledMessage) {
562
673
  ).serialize(compiledMessage);
563
674
  }
564
675
  }
676
+ function toSerializer(codec) {
677
+ return {
678
+ description: codec.description,
679
+ deserialize: codec.decode,
680
+ fixedSize: codec.fixedSize,
681
+ maxSize: codec.maxSize,
682
+ serialize: codec.encode
683
+ };
684
+ }
565
685
  function getPreludeStructSerializerTuple() {
566
686
  return [
567
- ["version", getTransactionVersionCodec()],
568
- ["header", getMessageHeaderCodec()],
687
+ ["version", toSerializer(getTransactionVersionCodec())],
688
+ ["header", toSerializer(getMessageHeaderCodec())],
569
689
  [
570
690
  "staticAccounts",
571
- umiSerializers.array(keys.getBase58EncodedAddressCodec(), {
691
+ umiSerializers.array(toSerializer(addresses.getAddressCodec()), {
572
692
  description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
573
693
  size: umiSerializers.shortU16()
574
694
  })
@@ -600,26 +720,99 @@ function getCompiledMessageEncoder() {
600
720
  return {
601
721
  ...BASE_CONFIG2,
602
722
  deserialize: getUnimplementedDecoder("CompiledMessage"),
603
- serialize: serialize2
723
+ serialize
604
724
  };
605
725
  }
606
726
 
607
- // src/signatures.ts
727
+ // src/serializers/transaction.ts
728
+ var BASE_CONFIG3 = {
729
+ description: __DEV__ ? "The wire format of a Solana transaction" : "",
730
+ fixedSize: null,
731
+ maxSize: null
732
+ };
733
+ function serialize2(transaction) {
734
+ const compiledTransaction = getCompiledTransaction(transaction);
735
+ return umiSerializers.struct([
736
+ [
737
+ "signatures",
738
+ umiSerializers.array(umiSerializers.bytes({ size: 64 }), {
739
+ ...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
740
+ size: umiSerializers.shortU16()
741
+ })
742
+ ],
743
+ ["compiledMessage", getCompiledMessageEncoder()]
744
+ ]).serialize(compiledTransaction);
745
+ }
746
+ function getTransactionEncoder() {
747
+ return {
748
+ ...BASE_CONFIG3,
749
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
750
+ serialize: serialize2
751
+ };
752
+ }
753
+ function assertIsTransactionSignature(putativeTransactionSignature) {
754
+ try {
755
+ if (
756
+ // Lowest value (64 bytes of zeroes)
757
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
758
+ putativeTransactionSignature.length > 88
759
+ ) {
760
+ throw new Error("Expected input string to decode to a byte array of length 64.");
761
+ }
762
+ const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
763
+ const numBytes = bytes3.byteLength;
764
+ if (numBytes !== 64) {
765
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
766
+ }
767
+ } catch (e) {
768
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
769
+ cause: e
770
+ });
771
+ }
772
+ }
773
+ function isTransactionSignature(putativeTransactionSignature) {
774
+ if (
775
+ // Lowest value (64 bytes of zeroes)
776
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
777
+ putativeTransactionSignature.length > 88
778
+ ) {
779
+ return false;
780
+ }
781
+ const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
782
+ const numBytes = bytes3.byteLength;
783
+ if (numBytes !== 64) {
784
+ return false;
785
+ }
786
+ return true;
787
+ }
608
788
  async function getCompiledMessageSignature(message, secretKey) {
609
789
  const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
610
790
  const signature = await keys.signBytes(secretKey, wireMessageBytes);
611
791
  return signature;
612
792
  }
613
- async function signTransaction(keyPair, transaction) {
793
+ function getSignatureFromTransaction(transaction) {
794
+ const signature = transaction.signatures[transaction.feePayer];
795
+ if (!signature) {
796
+ throw new Error(
797
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
798
+ );
799
+ }
800
+ return signature;
801
+ }
802
+ async function signTransaction(keyPairs, transaction) {
614
803
  const compiledMessage = compileMessage(transaction);
615
- const [signerPublicKey, signature] = await Promise.all([
616
- keys.getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
617
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
618
- ]);
619
- const nextSignatures = {
620
- ..."signatures" in transaction ? transaction.signatures : null,
621
- ...{ [signerPublicKey]: signature }
622
- };
804
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
805
+ const publicKeySignaturePairs = await Promise.all(
806
+ keyPairs.map(
807
+ (keyPair) => Promise.all([
808
+ addresses.getAddressFromPublicKey(keyPair.publicKey),
809
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
810
+ ])
811
+ )
812
+ );
813
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
814
+ nextSignatures[signerPublicKey] = signature;
815
+ }
623
816
  const out = {
624
817
  ...transaction,
625
818
  signatures: nextSignatures
@@ -627,11 +820,33 @@ async function signTransaction(keyPair, transaction) {
627
820
  Object.freeze(out);
628
821
  return out;
629
822
  }
823
+ function transactionSignature(putativeTransactionSignature) {
824
+ assertIsTransactionSignature(putativeTransactionSignature);
825
+ return putativeTransactionSignature;
826
+ }
827
+
828
+ // src/wire-transaction.ts
829
+ function getBase64EncodedWireTransaction(transaction) {
830
+ const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
831
+ {
832
+ return btoa(String.fromCharCode(...wireTransactionBytes));
833
+ }
834
+ }
630
835
 
631
836
  exports.appendTransactionInstruction = appendTransactionInstruction;
837
+ exports.assertIsBlockhash = assertIsBlockhash;
838
+ exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
839
+ exports.assertIsTransactionSignature = assertIsTransactionSignature;
632
840
  exports.createTransaction = createTransaction;
841
+ exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
842
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
843
+ exports.getTransactionEncoder = getTransactionEncoder;
844
+ exports.isTransactionSignature = isTransactionSignature;
633
845
  exports.prependTransactionInstruction = prependTransactionInstruction;
634
846
  exports.setTransactionFeePayer = setTransactionFeePayer;
847
+ exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
848
+ exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
635
849
  exports.signTransaction = signTransaction;
850
+ exports.transactionSignature = transactionSignature;
636
851
  //# sourceMappingURL=out.js.map
637
852
  //# sourceMappingURL=index.browser.cjs.map