@solana/transactions 2.0.0-experimental.2491912 → 2.0.0-experimental.25278c4

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 (34) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.browser.cjs +256 -245
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +253 -248
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +783 -728
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +253 -248
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +256 -247
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +255 -248
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +17 -11
  15. package/dist/types/accounts.d.ts +2 -2
  16. package/dist/types/blockhash.d.ts +1 -1
  17. package/dist/types/compile-address-table-lookups.d.ts +1 -1
  18. package/dist/types/compile-instructions.d.ts +1 -1
  19. package/dist/types/compile-static-accounts.d.ts +1 -1
  20. package/dist/types/durable-nonce.d.ts +6 -4
  21. package/dist/types/fee-payer.d.ts +3 -2
  22. package/dist/types/index.d.ts +1 -0
  23. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  24. package/dist/types/serializers/header.d.ts +4 -2
  25. package/dist/types/serializers/index.d.ts +2 -0
  26. package/dist/types/serializers/instruction.d.ts +4 -2
  27. package/dist/types/serializers/message.d.ts +4 -4
  28. package/dist/types/serializers/transaction-version.d.ts +4 -4
  29. package/dist/types/serializers/transaction.d.ts +5 -4
  30. package/dist/types/signatures.d.ts +12 -3
  31. package/dist/types/types.d.ts +7 -0
  32. package/dist/types/wire-transaction.d.ts +2 -2
  33. package/package.json +22 -18
  34. package/dist/types/serializers/unimplemented.d.ts +0 -3
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,6 +1,11 @@
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
@@ -30,8 +35,8 @@ function assertIsBlockhash(putativeBlockhash) {
30
35
  ) {
31
36
  throw new Error("Expected input string to decode to a byte array of length 32.");
32
37
  }
33
- const bytes3 = umiSerializers.base58.serialize(putativeBlockhash);
34
- const numBytes = bytes3.byteLength;
38
+ const bytes = umiSerializers.base58.serialize(putativeBlockhash);
39
+ const numBytes = bytes.byteLength;
35
40
  if (numBytes !== 32) {
36
41
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
37
42
  }
@@ -229,7 +234,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
229
234
  const shouldReplaceEntry = (
230
235
  // Consider using the new LOOKUP_TABLE if its address is different...
231
236
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
232
- (addressComparator || (addressComparator = keys.getBase58EncodedAddressComparator()))(
237
+ (addressComparator || (addressComparator = addresses.getAddressComparator()))(
233
238
  accountMeta.lookupTableAddress,
234
239
  entry.lookupTableAddress
235
240
  ) < 0
@@ -335,7 +340,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
335
340
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
336
341
  return leftIsWritable ? -1 : 1;
337
342
  }
338
- addressComparator || (addressComparator = keys.getBase58EncodedAddressComparator());
343
+ addressComparator || (addressComparator = addresses.getAddressComparator());
339
344
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
340
345
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
341
346
  } else {
@@ -364,7 +369,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
364
369
  entry.readableIndices.push(account.addressIndex);
365
370
  }
366
371
  }
367
- return Object.keys(index).sort(keys.getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
372
+ return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
368
373
  lookupTableAddress,
369
374
  ...index[lookupTableAddress]
370
375
  }));
@@ -443,159 +448,124 @@ function compileMessage(transaction) {
443
448
  version: transaction.version
444
449
  };
445
450
  }
446
- function getAddressTableLookupCodec() {
447
- return umiSerializers.struct(
448
- [
449
- [
450
- "lookupTableAddress",
451
- keys.getBase58EncodedAddressCodec(
452
- __DEV__ ? {
453
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
454
- } : void 0
455
- )
456
- ],
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(
457
477
  [
458
- "writableIndices",
459
- umiSerializers.array(umiSerializers.u8(), {
460
- ...__DEV__ ? {
461
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
462
- } : null,
463
- size: umiSerializers.shortU16()
464
- })
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
+ ]
465
493
  ],
466
- [
467
- "readableIndices",
468
- umiSerializers.array(umiSerializers.u8(), {
469
- ...__DEV__ ? {
470
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
471
- } : void 0,
472
- size: umiSerializers.shortU16()
473
- })
474
- ]
475
- ],
476
- __DEV__ ? {
477
- 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"
478
- } : void 0
479
- );
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;
480
504
  }
481
- function getMessageHeaderCodec() {
482
- return umiSerializers.struct(
505
+ function getMemoizedU8EncoderDescription(description) {
506
+ const encoder = getMemoizedU8Encoder();
507
+ return {
508
+ ...encoder,
509
+ description: description ?? encoder.description
510
+ };
511
+ }
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(
483
518
  [
484
- [
485
- "numSignerAccounts",
486
- umiSerializers.u8(
487
- __DEV__ ? {
488
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
489
- } : void 0
490
- )
491
- ],
492
- [
493
- "numReadonlySignerAccounts",
494
- umiSerializers.u8(
495
- __DEV__ ? {
496
- 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"
497
- } : void 0
498
- )
499
- ],
500
- [
501
- "numReadonlyNonSignerAccounts",
502
- umiSerializers.u8(
503
- __DEV__ ? {
504
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
505
- } : void 0
506
- )
507
- ]
519
+ ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
520
+ ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
521
+ ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
508
522
  ],
509
- __DEV__ ? {
510
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
511
- } : void 0
512
- );
513
- }
514
- function getInstructionCodec() {
515
- return umiSerializers.mapSerializer(
516
- umiSerializers.struct([
517
- [
518
- "programAddressIndex",
519
- umiSerializers.u8(
520
- __DEV__ ? {
521
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
522
- } : void 0
523
- )
524
- ],
525
- [
526
- "addressIndices",
527
- umiSerializers.array(
528
- umiSerializers.u8({
529
- description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
530
- }),
531
- {
532
- 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" : "",
533
- size: umiSerializers.shortU16()
534
- }
535
- )
536
- ],
537
- [
538
- "data",
539
- umiSerializers.bytes({
540
- description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
541
- size: umiSerializers.shortU16()
542
- })
543
- ]
544
- ]),
545
- (value) => {
546
- if (value.addressIndices !== void 0 && value.data !== void 0) {
547
- return value;
548
- }
549
- return {
550
- ...value,
551
- addressIndices: value.addressIndices ?? [],
552
- data: value.data ?? new Uint8Array(0)
553
- };
554
- },
555
- (value) => {
556
- if (value.addressIndices.length && value.data.byteLength) {
557
- return value;
558
- }
559
- const { addressIndices, data, ...rest } = value;
560
- return {
561
- ...rest,
562
- ...addressIndices.length ? { addressIndices } : null,
563
- ...data.byteLength ? { data } : null
564
- };
523
+ {
524
+ description: messageHeaderDescription
565
525
  }
566
526
  );
567
527
  }
568
-
569
- // src/serializers/unimplemented.ts
570
- function getError(type, name) {
571
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
572
- return new Error(
573
- `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}`
574
- );
575
- }
576
- function getUnimplementedDecoder(name) {
577
- return () => {
578
- throw getError("decoder", name);
579
- };
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;
580
561
  }
581
-
582
- // src/serializers/transaction-version.ts
583
562
  var VERSION_FLAG_MASK = 128;
584
563
  var BASE_CONFIG = {
585
564
  description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
586
565
  fixedSize: null,
587
566
  maxSize: 1
588
567
  };
589
- function deserialize(bytes3, offset = 0) {
590
- const firstByte = bytes3[offset];
591
- if ((firstByte & VERSION_FLAG_MASK) === 0) {
592
- return ["legacy", offset];
593
- } else {
594
- const version = firstByte ^ VERSION_FLAG_MASK;
595
- return [version, offset + 1];
596
- }
597
- }
598
- function serialize(value) {
568
+ function encode(value) {
599
569
  if (value === "legacy") {
600
570
  return new Uint8Array();
601
571
  }
@@ -604,99 +574,175 @@ function serialize(value) {
604
574
  }
605
575
  return new Uint8Array([value | VERSION_FLAG_MASK]);
606
576
  }
607
- function getTransactionVersionCodec() {
577
+ function getTransactionVersionEncoder() {
608
578
  return {
609
579
  ...BASE_CONFIG,
610
- deserialize,
611
- serialize
580
+ encode
612
581
  };
613
582
  }
614
583
 
615
584
  // src/serializers/message.ts
616
- var BASE_CONFIG2 = {
617
- description: __DEV__ ? "The wire format of a Solana transaction message" : "",
618
- fixedSize: null,
619
- maxSize: null
620
- };
621
- function serialize2(compiledMessage) {
622
- if (compiledMessage.version === "legacy") {
623
- return umiSerializers.struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
624
- } else {
625
- return umiSerializers.mapSerializer(
626
- umiSerializers.struct([
627
- ...getPreludeStructSerializerTuple(),
628
- ["addressTableLookups", getAddressTableLookupsSerializer()]
629
- ]),
630
- (value) => {
631
- if (value.version === "legacy") {
632
- return value;
633
- }
634
- return {
635
- ...value,
636
- addressTableLookups: value.addressTableLookups ?? []
637
- };
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;
638
601
  }
639
- ).serialize(compiledMessage);
640
- }
602
+ return {
603
+ ...value,
604
+ addressTableLookups: value.addressTableLookups ?? []
605
+ };
606
+ }
607
+ );
641
608
  }
642
- function getPreludeStructSerializerTuple() {
609
+ function getPreludeStructEncoderTuple() {
643
610
  return [
644
- ["version", getTransactionVersionCodec()],
645
- ["header", getMessageHeaderCodec()],
611
+ ["version", getTransactionVersionEncoder()],
612
+ ["header", getMessageHeaderEncoder()],
646
613
  [
647
614
  "staticAccounts",
648
- umiSerializers.array(keys.getBase58EncodedAddressCodec(), {
649
- description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
650
- size: umiSerializers.shortU16()
615
+ codecsDataStructures.getArrayEncoder(addresses.getAddressEncoder(), {
616
+ description: staticAccountsDescription,
617
+ size: codecsNumbers.getShortU16Encoder()
651
618
  })
652
619
  ],
653
620
  [
654
621
  "lifetimeToken",
655
- umiSerializers.string({
656
- description: __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "",
657
- encoding: umiSerializers.base58,
622
+ codecsStrings.getStringEncoder({
623
+ description: lifetimeTokenDescription,
624
+ encoding: codecsStrings.getBase58Encoder(),
658
625
  size: 32
659
626
  })
660
627
  ],
661
628
  [
662
629
  "instructions",
663
- umiSerializers.array(getInstructionCodec(), {
664
- description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "",
665
- size: umiSerializers.shortU16()
630
+ codecsDataStructures.getArrayEncoder(getInstructionEncoder(), {
631
+ description: instructionsDescription,
632
+ size: codecsNumbers.getShortU16Encoder()
666
633
  })
667
634
  ]
668
635
  ];
669
636
  }
670
- function getAddressTableLookupsSerializer() {
671
- return umiSerializers.array(getAddressTableLookupCodec(), {
672
- ...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null,
673
- size: umiSerializers.shortU16()
637
+ function getAddressTableLookupArrayEncoder() {
638
+ return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), {
639
+ description: addressTableLookupsDescription,
640
+ size: codecsNumbers.getShortU16Encoder()
674
641
  });
675
642
  }
643
+ var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
676
644
  function getCompiledMessageEncoder() {
677
645
  return {
678
- ...BASE_CONFIG2,
679
- deserialize: getUnimplementedDecoder("CompiledMessage"),
680
- 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
681
656
  };
682
657
  }
683
658
 
684
- // 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
+ }
685
717
  async function getCompiledMessageSignature(message, secretKey) {
686
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
718
+ const wireMessageBytes = getCompiledMessageEncoder().encode(message);
687
719
  const signature = await keys.signBytes(secretKey, wireMessageBytes);
688
720
  return signature;
689
721
  }
690
- 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) {
691
733
  const compiledMessage = compileMessage(transaction);
692
- const [signerPublicKey, signature] = await Promise.all([
693
- keys.getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
694
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
695
- ]);
696
- const nextSignatures = {
697
- ..."signatures" in transaction ? transaction.signatures : null,
698
- ...{ [signerPublicKey]: signature }
699
- };
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
+ }
700
746
  const out = {
701
747
  ...transaction,
702
748
  signatures: nextSignatures
@@ -704,55 +750,14 @@ async function signTransaction(keyPair, transaction) {
704
750
  Object.freeze(out);
705
751
  return out;
706
752
  }
707
-
708
- // src/compile-transaction.ts
709
- function getCompiledTransaction(transaction) {
710
- const compiledMessage = compileMessage(transaction);
711
- let signatures;
712
- if ("signatures" in transaction) {
713
- signatures = [];
714
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
715
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
716
- }
717
- } else {
718
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
719
- }
720
- return {
721
- compiledMessage,
722
- signatures
723
- };
724
- }
725
-
726
- // src/serializers/transaction.ts
727
- var BASE_CONFIG3 = {
728
- description: __DEV__ ? "The wire format of a Solana transaction" : "",
729
- fixedSize: null,
730
- maxSize: null
731
- };
732
- function serialize3(transaction) {
733
- const compiledTransaction = getCompiledTransaction(transaction);
734
- return umiSerializers.struct([
735
- [
736
- "signatures",
737
- umiSerializers.array(umiSerializers.bytes({ size: 64 }), {
738
- ...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
739
- size: umiSerializers.shortU16()
740
- })
741
- ],
742
- ["compiledMessage", getCompiledMessageEncoder()]
743
- ]).serialize(compiledTransaction);
744
- }
745
- function getTransactionEncoder() {
746
- return {
747
- ...BASE_CONFIG3,
748
- deserialize: getUnimplementedDecoder("CompiledMessage"),
749
- serialize: serialize3
750
- };
753
+ function transactionSignature(putativeTransactionSignature) {
754
+ assertIsTransactionSignature(putativeTransactionSignature);
755
+ return putativeTransactionSignature;
751
756
  }
752
757
 
753
758
  // src/wire-transaction.ts
754
759
  function getBase64EncodedWireTransaction(transaction) {
755
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
760
+ const wireTransactionBytes = getTransactionEncoder().encode(transaction);
756
761
  {
757
762
  return btoa(String.fromCharCode(...wireTransactionBytes));
758
763
  }
@@ -761,10 +766,16 @@ function getBase64EncodedWireTransaction(transaction) {
761
766
  exports.appendTransactionInstruction = appendTransactionInstruction;
762
767
  exports.assertIsBlockhash = assertIsBlockhash;
763
768
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
769
+ exports.assertIsTransactionSignature = assertIsTransactionSignature;
764
770
  exports.createTransaction = createTransaction;
765
771
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
772
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
773
+ exports.getTransactionEncoder = getTransactionEncoder;
774
+ exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
775
+ exports.isTransactionSignature = isTransactionSignature;
766
776
  exports.prependTransactionInstruction = prependTransactionInstruction;
767
777
  exports.setTransactionFeePayer = setTransactionFeePayer;
768
778
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
769
779
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
770
780
  exports.signTransaction = signTransaction;
781
+ exports.transactionSignature = transactionSignature;