@solana/transactions 2.0.0-experimental.7000add → 2.0.0-experimental.70ec746

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 (56) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.browser.cjs +297 -185
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +292 -188
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +958 -239
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +292 -188
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +295 -187
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +292 -188
  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/transaction-version.d.ts +4 -4
  28. package/dist/types/signatures.d.ts +12 -3
  29. package/dist/types/types.d.ts +7 -0
  30. package/dist/types/wire-transaction.d.ts +1 -1
  31. package/package.json +21 -18
  32. package/dist/types/accounts.d.ts.map +0 -1
  33. package/dist/types/blockhash.d.ts.map +0 -1
  34. package/dist/types/compile-address-table-lookups.d.ts.map +0 -1
  35. package/dist/types/compile-header.d.ts.map +0 -1
  36. package/dist/types/compile-instructions.d.ts.map +0 -1
  37. package/dist/types/compile-lifetime-token.d.ts.map +0 -1
  38. package/dist/types/compile-static-accounts.d.ts.map +0 -1
  39. package/dist/types/compile-transaction.d.ts.map +0 -1
  40. package/dist/types/create-transaction.d.ts.map +0 -1
  41. package/dist/types/durable-nonce.d.ts.map +0 -1
  42. package/dist/types/fee-payer.d.ts.map +0 -1
  43. package/dist/types/index.d.ts.map +0 -1
  44. package/dist/types/instructions.d.ts.map +0 -1
  45. package/dist/types/message.d.ts.map +0 -1
  46. package/dist/types/serializers/address-table-lookup.d.ts.map +0 -1
  47. package/dist/types/serializers/header.d.ts.map +0 -1
  48. package/dist/types/serializers/instruction.d.ts.map +0 -1
  49. package/dist/types/serializers/message.d.ts.map +0 -1
  50. package/dist/types/serializers/transaction-version.d.ts.map +0 -1
  51. package/dist/types/serializers/transaction.d.ts.map +0 -1
  52. package/dist/types/serializers/unimplemented.d.ts.map +0 -1
  53. package/dist/types/signatures.d.ts.map +0 -1
  54. package/dist/types/types.d.ts.map +0 -1
  55. package/dist/types/unsigned-transaction.d.ts.map +0 -1
  56. package/dist/types/wire-transaction.d.ts.map +0 -1
@@ -1,5 +1,9 @@
1
- import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers';
2
- import { getBase58EncodedAddressFromPublicKey, signBytes, getBase58EncodedAddressComparator, getBase58EncodedAddressCodec } from '@solana/keys';
1
+ import { base58, struct, array, bytes, shortU16, mapSerializer, string } from '@metaplex-foundation/umi-serializers';
2
+ import { getAddressFromPublicKey, getAddressComparator, getAddressCodec, getAddressEncoder, getAddressDecoder } from '@solana/addresses';
3
+ import { combineCodec, mapEncoder, mapDecoder } from '@solana/codecs-core';
4
+ import { getStructCodec, getStructEncoder, getArrayEncoder, getStructDecoder, getArrayDecoder, getBytesEncoder, getBytesDecoder } from '@solana/codecs-data-structures';
5
+ import { getU8Encoder, getShortU16Encoder, getU8Decoder, getShortU16Decoder, getU8Codec } from '@solana/codecs-numbers';
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")();
@@ -28,8 +32,8 @@ function assertIsBlockhash(putativeBlockhash) {
28
32
  ) {
29
33
  throw new Error("Expected input string to decode to a byte array of length 32.");
30
34
  }
31
- const bytes3 = base58.serialize(putativeBlockhash);
32
- const numBytes = bytes3.byteLength;
35
+ const bytes2 = base58.serialize(putativeBlockhash);
36
+ const numBytes = bytes2.byteLength;
33
37
  if (numBytes !== 32) {
34
38
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
35
39
  }
@@ -227,7 +231,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
227
231
  const shouldReplaceEntry = (
228
232
  // Consider using the new LOOKUP_TABLE if its address is different...
229
233
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
230
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
234
+ (addressComparator || (addressComparator = getAddressComparator()))(
231
235
  accountMeta.lookupTableAddress,
232
236
  entry.lookupTableAddress
233
237
  ) < 0
@@ -333,7 +337,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
333
337
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
334
338
  return leftIsWritable ? -1 : 1;
335
339
  }
336
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
340
+ addressComparator || (addressComparator = getAddressComparator());
337
341
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
338
342
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
339
343
  } else {
@@ -362,7 +366,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
362
366
  entry.readableIndices.push(account.addressIndex);
363
367
  }
364
368
  }
365
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
369
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
366
370
  lookupTableAddress,
367
371
  ...index[lookupTableAddress]
368
372
  }));
@@ -441,151 +445,188 @@ function compileMessage(transaction) {
441
445
  version: transaction.version
442
446
  };
443
447
  }
444
- function getAddressTableLookupCodec() {
445
- return struct(
446
- [
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
+ var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
467
+ var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
468
+ var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
469
+ 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";
470
+ var memoizedAddressTableLookupEncoder;
471
+ function getAddressTableLookupEncoder() {
472
+ if (!memoizedAddressTableLookupEncoder) {
473
+ memoizedAddressTableLookupEncoder = getStructEncoder(
447
474
  [
448
- "lookupTableAddress",
449
- getBase58EncodedAddressCodec(
450
- __DEV__ ? {
451
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
452
- } : void 0
453
- )
475
+ ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
476
+ [
477
+ "writableIndices",
478
+ getArrayEncoder(getU8Encoder(), {
479
+ description: writableIndicesDescription,
480
+ size: getShortU16Encoder()
481
+ })
482
+ ],
483
+ [
484
+ "readableIndices",
485
+ getArrayEncoder(getU8Encoder(), {
486
+ description: readableIndicesDescription,
487
+ size: getShortU16Encoder()
488
+ })
489
+ ]
454
490
  ],
491
+ { description: addressTableLookupDescription }
492
+ );
493
+ }
494
+ return memoizedAddressTableLookupEncoder;
495
+ }
496
+ var memoizedAddressTableLookupDecoder;
497
+ function getAddressTableLookupDecoder() {
498
+ if (!memoizedAddressTableLookupDecoder) {
499
+ memoizedAddressTableLookupDecoder = getStructDecoder(
455
500
  [
456
- "writableIndices",
457
- array(u8(), {
458
- ...__DEV__ ? {
459
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
460
- } : null,
461
- size: shortU16()
462
- })
501
+ ["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
502
+ [
503
+ "writableIndices",
504
+ getArrayDecoder(getU8Decoder(), {
505
+ description: writableIndicesDescription,
506
+ size: getShortU16Decoder()
507
+ })
508
+ ],
509
+ [
510
+ "readableIndices",
511
+ getArrayDecoder(getU8Decoder(), {
512
+ description: readableIndicesDescription,
513
+ size: getShortU16Decoder()
514
+ })
515
+ ]
463
516
  ],
464
- [
465
- "readableIndices",
466
- array(u8(), {
467
- ...__DEV__ ? {
468
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
469
- } : void 0,
470
- size: shortU16()
471
- })
472
- ]
473
- ],
474
- __DEV__ ? {
475
- 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"
476
- } : void 0
477
- );
517
+ { description: addressTableLookupDescription }
518
+ );
519
+ }
520
+ return memoizedAddressTableLookupDecoder;
521
+ }
522
+ function getAddressTableLookupCodec() {
523
+ return combineCodec(getAddressTableLookupEncoder(), getAddressTableLookupDecoder());
524
+ }
525
+ var memoizedU8Codec;
526
+ function getMemoizedU8Codec() {
527
+ if (!memoizedU8Codec)
528
+ memoizedU8Codec = getU8Codec();
529
+ return memoizedU8Codec;
530
+ }
531
+ function getMemoizedU8CodecDescription(description) {
532
+ const codec = getMemoizedU8Codec();
533
+ return {
534
+ ...codec,
535
+ description: description ?? codec.description
536
+ };
478
537
  }
538
+ 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;
539
+ 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;
540
+ var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
541
+ var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
479
542
  function getMessageHeaderCodec() {
480
- return struct(
543
+ return getStructCodec(
481
544
  [
482
- [
483
- "numSignerAccounts",
484
- u8(
485
- __DEV__ ? {
486
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
487
- } : void 0
488
- )
489
- ],
490
- [
491
- "numReadonlySignerAccounts",
492
- u8(
493
- __DEV__ ? {
494
- 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"
495
- } : void 0
496
- )
497
- ],
498
- [
499
- "numReadonlyNonSignerAccounts",
500
- u8(
501
- __DEV__ ? {
502
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
503
- } : void 0
504
- )
505
- ]
545
+ ["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
546
+ ["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
547
+ ["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
506
548
  ],
507
- __DEV__ ? {
508
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
509
- } : void 0
549
+ {
550
+ description: messageHeaderDescription
551
+ }
510
552
  );
511
553
  }
512
- function getInstructionCodec() {
513
- return mapSerializer(
514
- struct([
515
- [
516
- "programAddressIndex",
517
- u8(
518
- __DEV__ ? {
519
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
520
- } : void 0
521
- )
522
- ],
523
- [
524
- "addressIndices",
525
- array(
526
- u8({
527
- description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
528
- }),
529
- {
530
- 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" : "",
531
- size: shortU16()
532
- }
533
- )
534
- ],
535
- [
536
- "data",
537
- bytes({
538
- description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
539
- size: shortU16()
540
- })
541
- ]
542
- ]),
543
- (value) => {
544
- if (value.addressIndices !== void 0 && value.data !== void 0) {
545
- return value;
554
+ var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
555
+ var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
556
+ 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";
557
+ var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
558
+ var memoizedGetInstructionEncoder;
559
+ function getInstructionEncoder() {
560
+ if (!memoizedGetInstructionEncoder) {
561
+ memoizedGetInstructionEncoder = mapEncoder(
562
+ getStructEncoder([
563
+ ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
564
+ [
565
+ "accountIndices",
566
+ getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
567
+ description: accountIndicesDescription,
568
+ size: getShortU16Encoder()
569
+ })
570
+ ],
571
+ ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
572
+ ]),
573
+ // Convert an instruction to have all fields defined
574
+ (instruction) => {
575
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
576
+ return instruction;
577
+ }
578
+ return {
579
+ ...instruction,
580
+ accountIndices: instruction.accountIndices ?? [],
581
+ data: instruction.data ?? new Uint8Array(0)
582
+ };
546
583
  }
547
- return {
548
- ...value,
549
- addressIndices: value.addressIndices ?? [],
550
- data: value.data ?? new Uint8Array(0)
551
- };
552
- },
553
- (value) => {
554
- if (value.addressIndices.length && value.data.byteLength) {
555
- return value;
584
+ );
585
+ }
586
+ return memoizedGetInstructionEncoder;
587
+ }
588
+ var memoizedGetInstructionDecoder;
589
+ function getInstructionDecoder() {
590
+ if (!memoizedGetInstructionDecoder) {
591
+ memoizedGetInstructionDecoder = mapDecoder(
592
+ getStructDecoder([
593
+ ["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
594
+ [
595
+ "accountIndices",
596
+ getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
597
+ description: accountIndicesDescription,
598
+ size: getShortU16Decoder()
599
+ })
600
+ ],
601
+ ["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
602
+ ]),
603
+ // Convert an instruction to exclude optional fields if they are empty
604
+ (instruction) => {
605
+ if (instruction.accountIndices.length && instruction.data.byteLength) {
606
+ return instruction;
607
+ }
608
+ const { accountIndices, data, ...rest } = instruction;
609
+ return {
610
+ ...rest,
611
+ ...accountIndices.length ? { accountIndices } : null,
612
+ ...data.byteLength ? { data } : null
613
+ };
556
614
  }
557
- const { addressIndices, data, ...rest } = value;
558
- return {
559
- ...rest,
560
- ...addressIndices.length ? { addressIndices } : null,
561
- ...data.byteLength ? { data } : null
562
- };
563
- }
564
- );
565
- }
566
-
567
- // src/serializers/unimplemented.ts
568
- function getError(type, name) {
569
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
570
- return new Error(
571
- `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}`
572
- );
615
+ );
616
+ }
617
+ return memoizedGetInstructionDecoder;
573
618
  }
574
- function getUnimplementedDecoder(name) {
575
- return () => {
576
- throw getError("decoder", name);
577
- };
619
+ function getInstructionCodec() {
620
+ return combineCodec(getInstructionEncoder(), getInstructionDecoder());
578
621
  }
579
-
580
- // src/serializers/transaction-version.ts
581
622
  var VERSION_FLAG_MASK = 128;
582
623
  var BASE_CONFIG = {
583
624
  description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
584
625
  fixedSize: null,
585
626
  maxSize: 1
586
627
  };
587
- function deserialize(bytes3, offset = 0) {
588
- const firstByte = bytes3[offset];
628
+ function decode(bytes2, offset = 0) {
629
+ const firstByte = bytes2[offset];
589
630
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
590
631
  return ["legacy", offset];
591
632
  } else {
@@ -593,7 +634,7 @@ function deserialize(bytes3, offset = 0) {
593
634
  return [version, offset + 1];
594
635
  }
595
636
  }
596
- function serialize(value) {
637
+ function encode(value) {
597
638
  if (value === "legacy") {
598
639
  return new Uint8Array();
599
640
  }
@@ -602,11 +643,32 @@ function serialize(value) {
602
643
  }
603
644
  return new Uint8Array([value | VERSION_FLAG_MASK]);
604
645
  }
605
- function getTransactionVersionCodec() {
646
+ function getTransactionVersionDecoder() {
606
647
  return {
607
648
  ...BASE_CONFIG,
608
- deserialize,
609
- serialize
649
+ decode
650
+ };
651
+ }
652
+ function getTransactionVersionEncoder() {
653
+ return {
654
+ ...BASE_CONFIG,
655
+ encode
656
+ };
657
+ }
658
+ function getTransactionVersionCodec() {
659
+ return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
660
+ }
661
+
662
+ // src/serializers/unimplemented.ts
663
+ function getError(type, name) {
664
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
665
+ return new Error(
666
+ `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}`
667
+ );
668
+ }
669
+ function getUnimplementedDecoder(name) {
670
+ return () => {
671
+ throw getError("decoder", name);
610
672
  };
611
673
  }
612
674
 
@@ -616,7 +678,7 @@ var BASE_CONFIG2 = {
616
678
  fixedSize: null,
617
679
  maxSize: null
618
680
  };
619
- function serialize2(compiledMessage) {
681
+ function serialize(compiledMessage) {
620
682
  if (compiledMessage.version === "legacy") {
621
683
  return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
622
684
  } else {
@@ -637,13 +699,22 @@ function serialize2(compiledMessage) {
637
699
  ).serialize(compiledMessage);
638
700
  }
639
701
  }
702
+ function toSerializer(codec) {
703
+ return {
704
+ description: codec.description,
705
+ deserialize: codec.decode,
706
+ fixedSize: codec.fixedSize,
707
+ maxSize: codec.maxSize,
708
+ serialize: codec.encode
709
+ };
710
+ }
640
711
  function getPreludeStructSerializerTuple() {
641
712
  return [
642
- ["version", getTransactionVersionCodec()],
643
- ["header", getMessageHeaderCodec()],
713
+ ["version", toSerializer(getTransactionVersionCodec())],
714
+ ["header", toSerializer(getMessageHeaderCodec())],
644
715
  [
645
716
  "staticAccounts",
646
- array(getBase58EncodedAddressCodec(), {
717
+ array(toSerializer(getAddressCodec()), {
647
718
  description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
648
719
  size: shortU16()
649
720
  })
@@ -658,7 +729,7 @@ function getPreludeStructSerializerTuple() {
658
729
  ],
659
730
  [
660
731
  "instructions",
661
- array(getInstructionCodec(), {
732
+ array(toSerializer(getInstructionCodec()), {
662
733
  description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "",
663
734
  size: shortU16()
664
735
  })
@@ -666,7 +737,7 @@ function getPreludeStructSerializerTuple() {
666
737
  ];
667
738
  }
668
739
  function getAddressTableLookupsSerializer() {
669
- return array(getAddressTableLookupCodec(), {
740
+ return array(toSerializer(getAddressTableLookupCodec()), {
670
741
  ...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null,
671
742
  size: shortU16()
672
743
  });
@@ -675,49 +746,7 @@ function getCompiledMessageEncoder() {
675
746
  return {
676
747
  ...BASE_CONFIG2,
677
748
  deserialize: getUnimplementedDecoder("CompiledMessage"),
678
- serialize: serialize2
679
- };
680
- }
681
-
682
- // src/signatures.ts
683
- async function getCompiledMessageSignature(message, secretKey) {
684
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
685
- const signature = await signBytes(secretKey, wireMessageBytes);
686
- return signature;
687
- }
688
- async function signTransaction(keyPair, transaction) {
689
- const compiledMessage = compileMessage(transaction);
690
- const [signerPublicKey, signature] = await Promise.all([
691
- getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
692
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
693
- ]);
694
- const nextSignatures = {
695
- ..."signatures" in transaction ? transaction.signatures : null,
696
- ...{ [signerPublicKey]: signature }
697
- };
698
- const out = {
699
- ...transaction,
700
- signatures: nextSignatures
701
- };
702
- Object.freeze(out);
703
- return out;
704
- }
705
-
706
- // src/compile-transaction.ts
707
- function getCompiledTransaction(transaction) {
708
- const compiledMessage = compileMessage(transaction);
709
- let signatures;
710
- if ("signatures" in transaction) {
711
- signatures = [];
712
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
713
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
714
- }
715
- } else {
716
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
717
- }
718
- return {
719
- compiledMessage,
720
- signatures
749
+ serialize
721
750
  };
722
751
  }
723
752
 
@@ -727,7 +756,7 @@ var BASE_CONFIG3 = {
727
756
  fixedSize: null,
728
757
  maxSize: null
729
758
  };
730
- function serialize3(transaction) {
759
+ function serialize2(transaction) {
731
760
  const compiledTransaction = getCompiledTransaction(transaction);
732
761
  return struct([
733
762
  [
@@ -744,8 +773,83 @@ function getTransactionEncoder() {
744
773
  return {
745
774
  ...BASE_CONFIG3,
746
775
  deserialize: getUnimplementedDecoder("CompiledMessage"),
747
- serialize: serialize3
776
+ serialize: serialize2
777
+ };
778
+ }
779
+ function assertIsTransactionSignature(putativeTransactionSignature) {
780
+ try {
781
+ if (
782
+ // Lowest value (64 bytes of zeroes)
783
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
784
+ putativeTransactionSignature.length > 88
785
+ ) {
786
+ throw new Error("Expected input string to decode to a byte array of length 64.");
787
+ }
788
+ const bytes2 = base58.serialize(putativeTransactionSignature);
789
+ const numBytes = bytes2.byteLength;
790
+ if (numBytes !== 64) {
791
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
792
+ }
793
+ } catch (e) {
794
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
795
+ cause: e
796
+ });
797
+ }
798
+ }
799
+ function isTransactionSignature(putativeTransactionSignature) {
800
+ if (
801
+ // Lowest value (64 bytes of zeroes)
802
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
803
+ putativeTransactionSignature.length > 88
804
+ ) {
805
+ return false;
806
+ }
807
+ const bytes2 = base58.serialize(putativeTransactionSignature);
808
+ const numBytes = bytes2.byteLength;
809
+ if (numBytes !== 64) {
810
+ return false;
811
+ }
812
+ return true;
813
+ }
814
+ async function getCompiledMessageSignature(message, secretKey) {
815
+ const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
816
+ const signature = await signBytes(secretKey, wireMessageBytes);
817
+ return signature;
818
+ }
819
+ function getSignatureFromTransaction(transaction) {
820
+ const signatureBytes = transaction.signatures[transaction.feePayer];
821
+ if (!signatureBytes) {
822
+ throw new Error(
823
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
824
+ );
825
+ }
826
+ const transactionSignature2 = base58.deserialize(signatureBytes)[0];
827
+ return transactionSignature2;
828
+ }
829
+ async function signTransaction(keyPairs, transaction) {
830
+ const compiledMessage = compileMessage(transaction);
831
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
832
+ const publicKeySignaturePairs = await Promise.all(
833
+ keyPairs.map(
834
+ (keyPair) => Promise.all([
835
+ getAddressFromPublicKey(keyPair.publicKey),
836
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
837
+ ])
838
+ )
839
+ );
840
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
841
+ nextSignatures[signerPublicKey] = signature;
842
+ }
843
+ const out = {
844
+ ...transaction,
845
+ signatures: nextSignatures
748
846
  };
847
+ Object.freeze(out);
848
+ return out;
849
+ }
850
+ function transactionSignature(putativeTransactionSignature) {
851
+ assertIsTransactionSignature(putativeTransactionSignature);
852
+ return putativeTransactionSignature;
749
853
  }
750
854
 
751
855
  // src/wire-transaction.ts
@@ -756,6 +860,6 @@ function getBase64EncodedWireTransaction(transaction) {
756
860
  }
757
861
  }
758
862
 
759
- export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
863
+ export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isAdvanceNonceAccountInstruction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
760
864
  //# sourceMappingURL=out.js.map
761
865
  //# sourceMappingURL=index.native.js.map