@solana/transactions 2.0.0-experimental.8245fa6 → 2.0.0-experimental.85b7dfe

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 (49) hide show
  1. package/README.md +1 -43
  2. package/dist/index.browser.cjs +167 -190
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +165 -189
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +445 -423
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +165 -189
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +167 -188
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +165 -189
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +23 -20
  15. package/dist/types/accounts.d.ts.map +1 -0
  16. package/dist/types/blockhash.d.ts +1 -0
  17. package/dist/types/blockhash.d.ts.map +1 -0
  18. package/dist/types/compilable-transaction.d.ts +3 -2
  19. package/dist/types/compilable-transaction.d.ts.map +1 -0
  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.map +1 -0
  23. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  24. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  25. package/dist/types/compile-transaction.d.ts +2 -2
  26. package/dist/types/compile-transaction.d.ts.map +1 -0
  27. package/dist/types/create-transaction.d.ts.map +1 -0
  28. package/dist/types/decompile-transaction.d.ts.map +1 -0
  29. package/dist/types/durable-nonce.d.ts.map +1 -0
  30. package/dist/types/fee-payer.d.ts.map +1 -0
  31. package/dist/types/index.d.ts +1 -0
  32. package/dist/types/index.d.ts.map +1 -0
  33. package/dist/types/instructions.d.ts.map +1 -0
  34. package/dist/types/message.d.ts.map +1 -0
  35. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  36. package/dist/types/serializers/header.d.ts.map +1 -0
  37. package/dist/types/serializers/index.d.ts +1 -0
  38. package/dist/types/serializers/index.d.ts.map +1 -0
  39. package/dist/types/serializers/instruction.d.ts.map +1 -0
  40. package/dist/types/serializers/message.d.ts.map +1 -0
  41. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  42. package/dist/types/serializers/transaction.d.ts.map +1 -0
  43. package/dist/types/signatures.d.ts +5 -10
  44. package/dist/types/signatures.d.ts.map +1 -0
  45. package/dist/types/types.d.ts +6 -13
  46. package/dist/types/types.d.ts.map +1 -0
  47. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  48. package/dist/types/wire-transaction.d.ts.map +1 -0
  49. package/package.json +13 -13
package/README.md CHANGED
@@ -244,21 +244,11 @@ This type represents a transaction that is signed by all of its required signers
244
244
 
245
245
  Expect any function that modifies a transaction (eg. `setTransactionFeePayer`, `appendTransactionInstruction`, et cetera) to delete a transaction's `signatures` property and unset this type.
246
246
 
247
- #### `TransactionSignature`
248
-
249
- This type represents the base58-encoded signature of a transactions fee payer. This value uniquely identifies the transaction on the network.
250
-
251
247
  ### Functions
252
248
 
253
- #### `assertIsTransactionSignature()`
254
-
255
- From time to time you might acquire a string that you expect to be the base58-encoded signature of a transaction, from an untrusted network API or user input. To assert that such an arbitrary string is in fact a transaction signature, use the `assertIsTransactionSignature` function.
256
-
257
- See [`assertIsBlockhash()`](#assertisblockhash) for an example of how to use an assertion function.
258
-
259
249
  #### `getSignatureFromTransaction()`
260
250
 
261
- Given a transaction signed by its fee payer, this method will return the `TransactionSignature` that uniquely identifies it. This string can be used to look up transactions at a later date, for example on a Solana block explorer.
251
+ Given a transaction signed by its fee payer, this method will return the `Signature` that uniquely identifies it. This string can be used to look up transactions at a later date, for example on a Solana block explorer.
262
252
 
263
253
  ```ts
264
254
  import { getSignatureFromTransaction } from '@solana/transactions';
@@ -267,25 +257,6 @@ const signature = getSignatureFromTransaction(tx);
267
257
  console.debug(`Inspect this transaction at https://explorer.solana.com/tx/${signature}`);
268
258
  ```
269
259
 
270
- #### `isTransactionSignature()`
271
-
272
- This is a type guard that accepts a string as input. It will both return `true` if the string conforms to the `TransactionSignature` type and will refine the type for use in your program.
273
-
274
- ```ts
275
- import { isTransactionSignature } from '@solana/transactions';
276
-
277
- if (isTransactionSignature(signature)) {
278
- // At this point, `signature` has been refined to a
279
- // `TransactionSignature` that can be used with the RPC.
280
- const {
281
- value: [status],
282
- } = await rpc.getSignatureStatuses([signature]).send();
283
- setSignatureStatus(status);
284
- } else {
285
- setError(`${signature} is not a transaction signature`);
286
- }
287
- ```
288
-
289
260
  #### `signTransaction()`
290
261
 
291
262
  Given an array of `CryptoKey` objects which are private keys pertaining to addresses that are required to sign a transaction, this method will return a new signed transaction having the same type as the one supplied plus the `ITransactionWithSignatures` type.
@@ -297,19 +268,6 @@ import { signTransaction } from '@solana/transactions';
297
268
  const signedTransaction = await signTransaction([myPrivateKey], tx);
298
269
  ```
299
270
 
300
- #### `transactionSignature()`
301
-
302
- This helper combines _asserting_ that a string is a transaction signature with _coercing_ it to the `TransactionSignature` type. It's best used with untrusted input.
303
-
304
- ```ts
305
- import { transactionSignature } from '@solana/transactions';
306
-
307
- const signature = transactionSignature(userSuppliedSignature);
308
- const {
309
- value: [status],
310
- } = await rpc.getSignatureStatuses([signature]).send();
311
- ```
312
-
313
271
  ## Serializing transactions
314
272
 
315
273
  Before sending a transaction to be landed on the network, you must serialize it in a particular way. You can use these types and functions to serialize a signed transaction into a binary format suitable for transit over the wire.
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var codecsStrings = require('@solana/codecs-strings');
4
+ var addresses = require('@solana/addresses');
4
5
  var codecsCore = require('@solana/codecs-core');
5
6
  var codecsDataStructures = require('@solana/codecs-data-structures');
6
7
  var codecsNumbers = require('@solana/codecs-numbers');
7
- var addresses = require('@solana/addresses');
8
8
  var functional = require('@solana/functional');
9
9
  var keys = require('@solana/keys');
10
10
 
@@ -49,6 +49,22 @@ function assertIsBlockhash(putativeBlockhash) {
49
49
  });
50
50
  }
51
51
  }
52
+ function isTransactionWithBlockhashLifetime(transaction) {
53
+ const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
54
+ if (!lifetimeConstraintShapeMatches)
55
+ return false;
56
+ try {
57
+ assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
58
+ return true;
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+ function assertIsTransactionWithBlockhashLifetime(transaction) {
64
+ if (!isTransactionWithBlockhashLifetime(transaction)) {
65
+ throw new Error("Transaction does not have a blockhash lifetime");
66
+ }
67
+ }
52
68
  function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
53
69
  if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
54
70
  return transaction;
@@ -254,7 +270,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
254
270
  const shouldReplaceEntry = (
255
271
  // Consider using the new LOOKUP_TABLE if its address is different...
256
272
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
257
- (addressComparator || (addressComparator = addresses.getAddressComparator()))(
273
+ (addressComparator ||= addresses.getAddressComparator())(
258
274
  accountMeta.lookupTableAddress,
259
275
  entry.lookupTableAddress
260
276
  ) < 0
@@ -360,7 +376,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
360
376
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
361
377
  return leftIsWritable ? -1 : 1;
362
378
  }
363
- addressComparator || (addressComparator = addresses.getAddressComparator());
379
+ addressComparator ||= addresses.getAddressComparator();
364
380
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
365
381
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
366
382
  } else {
@@ -373,16 +389,15 @@ function getOrderedAccountsFromAddressMap(addressMap) {
373
389
  return orderedAccounts;
374
390
  }
375
391
  function getCompiledAddressTableLookups(orderedAccounts) {
376
- var _a;
377
392
  const index = {};
378
393
  for (const account of orderedAccounts) {
379
394
  if (!("lookupTableAddress" in account)) {
380
395
  continue;
381
396
  }
382
- const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
397
+ const entry = index[account.lookupTableAddress] ||= {
383
398
  readableIndices: [],
384
399
  writableIndices: []
385
- });
400
+ };
386
401
  if (account.role === AccountRole.WRITABLE) {
387
402
  entry.writableIndices.push(account.addressIndex);
388
403
  } else {
@@ -468,134 +483,6 @@ function compileMessage(transaction) {
468
483
  version: transaction.version
469
484
  };
470
485
  }
471
-
472
- // src/compile-transaction.ts
473
- function getCompiledTransaction(transaction) {
474
- const compiledMessage = compileMessage(transaction);
475
- let signatures;
476
- if ("signatures" in transaction) {
477
- signatures = [];
478
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
479
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
480
- }
481
- } else {
482
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
483
- }
484
- return {
485
- compiledMessage,
486
- signatures
487
- };
488
- }
489
- function getAccountMetas(message) {
490
- const { header } = message;
491
- const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
492
- const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
493
- const accountMetas = [];
494
- let accountIndex = 0;
495
- for (let i = 0; i < numWritableSignerAccounts; i++) {
496
- accountMetas.push({
497
- address: message.staticAccounts[accountIndex],
498
- role: AccountRole.WRITABLE_SIGNER
499
- });
500
- accountIndex++;
501
- }
502
- for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
503
- accountMetas.push({
504
- address: message.staticAccounts[accountIndex],
505
- role: AccountRole.READONLY_SIGNER
506
- });
507
- accountIndex++;
508
- }
509
- for (let i = 0; i < numWritableNonSignerAccounts; i++) {
510
- accountMetas.push({
511
- address: message.staticAccounts[accountIndex],
512
- role: AccountRole.WRITABLE
513
- });
514
- accountIndex++;
515
- }
516
- for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
517
- accountMetas.push({
518
- address: message.staticAccounts[accountIndex],
519
- role: AccountRole.READONLY
520
- });
521
- accountIndex++;
522
- }
523
- return accountMetas;
524
- }
525
- function convertInstruction(instruction, accountMetas) {
526
- const programAddress = accountMetas[instruction.programAddressIndex]?.address;
527
- if (!programAddress) {
528
- throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
529
- }
530
- const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
531
- const { data } = instruction;
532
- return {
533
- programAddress,
534
- ...accounts && accounts.length ? { accounts } : {},
535
- ...data && data.length ? { data } : {}
536
- };
537
- }
538
- function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
539
- if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
540
- return {
541
- blockhash: messageLifetimeToken,
542
- lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
543
- // U64 MAX
544
- };
545
- } else {
546
- const nonceAccountAddress = firstInstruction.accounts[0].address;
547
- addresses.assertIsAddress(nonceAccountAddress);
548
- const nonceAuthorityAddress = firstInstruction.accounts[2].address;
549
- addresses.assertIsAddress(nonceAuthorityAddress);
550
- return {
551
- nonce: messageLifetimeToken,
552
- nonceAccountAddress,
553
- nonceAuthorityAddress
554
- };
555
- }
556
- }
557
- function convertSignatures(compiledTransaction) {
558
- const {
559
- compiledMessage: { staticAccounts },
560
- signatures
561
- } = compiledTransaction;
562
- return signatures.reduce((acc, sig, index) => {
563
- const allZeros = sig.every((byte) => byte === 0);
564
- if (allZeros)
565
- return acc;
566
- const address = staticAccounts[index];
567
- return { ...acc, [address]: sig };
568
- }, {});
569
- }
570
- function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
571
- const { compiledMessage } = compiledTransaction;
572
- if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
573
- throw new Error("Cannot convert transaction with addressTableLookups");
574
- }
575
- const feePayer = compiledMessage.staticAccounts[0];
576
- if (!feePayer)
577
- throw new Error("No fee payer set in CompiledTransaction");
578
- const accountMetas = getAccountMetas(compiledMessage);
579
- const instructions = compiledMessage.instructions.map(
580
- (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
581
- );
582
- const firstInstruction = instructions[0];
583
- const lifetimeConstraint = getLifetimeConstraint(
584
- compiledMessage.lifetimeToken,
585
- firstInstruction,
586
- lastValidBlockHeight
587
- );
588
- const signatures = convertSignatures(compiledTransaction);
589
- return functional.pipe(
590
- createTransaction({ version: compiledMessage.version }),
591
- (tx) => setTransactionFeePayer(feePayer, tx),
592
- (tx) => instructions.reduce((acc, instruction) => {
593
- return appendTransactionInstruction(instruction, acc);
594
- }, tx),
595
- (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
596
- (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
597
- );
598
- }
599
486
  var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
600
487
  var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
601
488
  var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
@@ -930,6 +817,137 @@ function getCompiledMessageDecoder() {
930
817
  }
931
818
  );
932
819
  }
820
+ function getCompiledMessageCodec() {
821
+ return codecsCore.combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
822
+ }
823
+
824
+ // src/compile-transaction.ts
825
+ function getCompiledTransaction(transaction) {
826
+ const compiledMessage = compileMessage(transaction);
827
+ let signatures;
828
+ if ("signatures" in transaction) {
829
+ signatures = [];
830
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
831
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
832
+ }
833
+ } else {
834
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
835
+ }
836
+ return {
837
+ compiledMessage,
838
+ signatures
839
+ };
840
+ }
841
+ function getAccountMetas(message) {
842
+ const { header } = message;
843
+ const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
844
+ const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
845
+ const accountMetas = [];
846
+ let accountIndex = 0;
847
+ for (let i = 0; i < numWritableSignerAccounts; i++) {
848
+ accountMetas.push({
849
+ address: message.staticAccounts[accountIndex],
850
+ role: AccountRole.WRITABLE_SIGNER
851
+ });
852
+ accountIndex++;
853
+ }
854
+ for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
855
+ accountMetas.push({
856
+ address: message.staticAccounts[accountIndex],
857
+ role: AccountRole.READONLY_SIGNER
858
+ });
859
+ accountIndex++;
860
+ }
861
+ for (let i = 0; i < numWritableNonSignerAccounts; i++) {
862
+ accountMetas.push({
863
+ address: message.staticAccounts[accountIndex],
864
+ role: AccountRole.WRITABLE
865
+ });
866
+ accountIndex++;
867
+ }
868
+ for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
869
+ accountMetas.push({
870
+ address: message.staticAccounts[accountIndex],
871
+ role: AccountRole.READONLY
872
+ });
873
+ accountIndex++;
874
+ }
875
+ return accountMetas;
876
+ }
877
+ function convertInstruction(instruction, accountMetas) {
878
+ const programAddress = accountMetas[instruction.programAddressIndex]?.address;
879
+ if (!programAddress) {
880
+ throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
881
+ }
882
+ const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
883
+ const { data } = instruction;
884
+ return {
885
+ programAddress,
886
+ ...accounts && accounts.length ? { accounts } : {},
887
+ ...data && data.length ? { data } : {}
888
+ };
889
+ }
890
+ function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
891
+ if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
892
+ return {
893
+ blockhash: messageLifetimeToken,
894
+ lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
895
+ // U64 MAX
896
+ };
897
+ } else {
898
+ const nonceAccountAddress = firstInstruction.accounts[0].address;
899
+ addresses.assertIsAddress(nonceAccountAddress);
900
+ const nonceAuthorityAddress = firstInstruction.accounts[2].address;
901
+ addresses.assertIsAddress(nonceAuthorityAddress);
902
+ return {
903
+ nonce: messageLifetimeToken,
904
+ nonceAccountAddress,
905
+ nonceAuthorityAddress
906
+ };
907
+ }
908
+ }
909
+ function convertSignatures(compiledTransaction) {
910
+ const {
911
+ compiledMessage: { staticAccounts },
912
+ signatures
913
+ } = compiledTransaction;
914
+ return signatures.reduce((acc, sig, index) => {
915
+ const allZeros = sig.every((byte) => byte === 0);
916
+ if (allZeros)
917
+ return acc;
918
+ const address = staticAccounts[index];
919
+ return { ...acc, [address]: sig };
920
+ }, {});
921
+ }
922
+ function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
923
+ const { compiledMessage } = compiledTransaction;
924
+ if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
925
+ throw new Error("Cannot convert transaction with addressTableLookups");
926
+ }
927
+ const feePayer = compiledMessage.staticAccounts[0];
928
+ if (!feePayer)
929
+ throw new Error("No fee payer set in CompiledTransaction");
930
+ const accountMetas = getAccountMetas(compiledMessage);
931
+ const instructions = compiledMessage.instructions.map(
932
+ (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
933
+ );
934
+ const firstInstruction = instructions[0];
935
+ const lifetimeConstraint = getLifetimeConstraint(
936
+ compiledMessage.lifetimeToken,
937
+ firstInstruction,
938
+ lastValidBlockHeight
939
+ );
940
+ const signatures = convertSignatures(compiledTransaction);
941
+ return functional.pipe(
942
+ createTransaction({ version: compiledMessage.version }),
943
+ (tx) => setTransactionFeePayer(feePayer, tx),
944
+ (tx) => instructions.reduce((acc, instruction) => {
945
+ return appendTransactionInstruction(instruction, acc);
946
+ }, tx),
947
+ (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
948
+ (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
949
+ );
950
+ }
933
951
 
934
952
  // src/serializers/transaction.ts
935
953
  var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
@@ -983,47 +1001,7 @@ function getTransactionDecoder(lastValidBlockHeight) {
983
1001
  function getTransactionCodec(lastValidBlockHeight) {
984
1002
  return codecsCore.combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
985
1003
  }
986
- var base58Encoder2;
987
1004
  var base58Decoder;
988
- function assertIsTransactionSignature(putativeTransactionSignature) {
989
- if (!base58Encoder2)
990
- base58Encoder2 = codecsStrings.getBase58Encoder();
991
- try {
992
- if (
993
- // Lowest value (64 bytes of zeroes)
994
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
995
- putativeTransactionSignature.length > 88
996
- ) {
997
- throw new Error("Expected input string to decode to a byte array of length 64.");
998
- }
999
- const bytes = base58Encoder2.encode(putativeTransactionSignature);
1000
- const numBytes = bytes.byteLength;
1001
- if (numBytes !== 64) {
1002
- throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1003
- }
1004
- } catch (e) {
1005
- throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1006
- cause: e
1007
- });
1008
- }
1009
- }
1010
- function isTransactionSignature(putativeTransactionSignature) {
1011
- if (!base58Encoder2)
1012
- base58Encoder2 = codecsStrings.getBase58Encoder();
1013
- if (
1014
- // Lowest value (64 bytes of zeroes)
1015
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1016
- putativeTransactionSignature.length > 88
1017
- ) {
1018
- return false;
1019
- }
1020
- const bytes = base58Encoder2.encode(putativeTransactionSignature);
1021
- const numBytes = bytes.byteLength;
1022
- if (numBytes !== 64) {
1023
- return false;
1024
- }
1025
- return true;
1026
- }
1027
1005
  function getSignatureFromTransaction(transaction) {
1028
1006
  if (!base58Decoder)
1029
1007
  base58Decoder = codecsStrings.getBase58Decoder();
@@ -1033,10 +1011,10 @@ function getSignatureFromTransaction(transaction) {
1033
1011
  "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1034
1012
  );
1035
1013
  }
1036
- const transactionSignature2 = base58Decoder.decode(signatureBytes)[0];
1037
- return transactionSignature2;
1014
+ const transactionSignature = base58Decoder.decode(signatureBytes)[0];
1015
+ return transactionSignature;
1038
1016
  }
1039
- async function signTransaction(keyPairs, transaction) {
1017
+ async function partiallySignTransaction(keyPairs, transaction) {
1040
1018
  const compiledMessage = compileMessage(transaction);
1041
1019
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1042
1020
  const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
@@ -1055,9 +1033,11 @@ async function signTransaction(keyPairs, transaction) {
1055
1033
  Object.freeze(out);
1056
1034
  return out;
1057
1035
  }
1058
- function transactionSignature(putativeTransactionSignature) {
1059
- assertIsTransactionSignature(putativeTransactionSignature);
1060
- return putativeTransactionSignature;
1036
+ async function signTransaction(keyPairs, transaction) {
1037
+ const out = await partiallySignTransaction(keyPairs, transaction);
1038
+ assertTransactionIsFullySigned(out);
1039
+ Object.freeze(out);
1040
+ return out;
1061
1041
  }
1062
1042
  function assertTransactionIsFullySigned(transaction) {
1063
1043
  const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
@@ -1068,33 +1048,30 @@ function assertTransactionIsFullySigned(transaction) {
1068
1048
  }
1069
1049
  });
1070
1050
  }
1071
-
1072
- // src/wire-transaction.ts
1073
1051
  function getBase64EncodedWireTransaction(transaction) {
1074
1052
  const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1075
- {
1076
- return btoa(String.fromCharCode(...wireTransactionBytes));
1077
- }
1053
+ return codecsStrings.getBase64Decoder().decode(wireTransactionBytes)[0];
1078
1054
  }
1079
1055
 
1080
1056
  exports.appendTransactionInstruction = appendTransactionInstruction;
1081
1057
  exports.assertIsBlockhash = assertIsBlockhash;
1082
1058
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1083
- exports.assertIsTransactionSignature = assertIsTransactionSignature;
1059
+ exports.assertIsTransactionWithBlockhashLifetime = assertIsTransactionWithBlockhashLifetime;
1084
1060
  exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
1061
+ exports.compileMessage = compileMessage;
1085
1062
  exports.createTransaction = createTransaction;
1086
1063
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1064
+ exports.getCompiledMessageCodec = getCompiledMessageCodec;
1065
+ exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
1066
+ exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
1087
1067
  exports.getSignatureFromTransaction = getSignatureFromTransaction;
1088
1068
  exports.getTransactionCodec = getTransactionCodec;
1089
1069
  exports.getTransactionDecoder = getTransactionDecoder;
1090
1070
  exports.getTransactionEncoder = getTransactionEncoder;
1091
1071
  exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
1092
- exports.isTransactionSignature = isTransactionSignature;
1072
+ exports.partiallySignTransaction = partiallySignTransaction;
1093
1073
  exports.prependTransactionInstruction = prependTransactionInstruction;
1094
1074
  exports.setTransactionFeePayer = setTransactionFeePayer;
1095
1075
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1096
1076
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1097
1077
  exports.signTransaction = signTransaction;
1098
- exports.transactionSignature = transactionSignature;
1099
- //# sourceMappingURL=out.js.map
1100
- //# sourceMappingURL=index.browser.cjs.map