@solana/transactions 2.0.0-experimental.63423f2 → 2.0.0-experimental.6556a8b

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 (50) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.browser.cjs +130 -53
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +125 -55
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +543 -97
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +127 -55
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +130 -53
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +125 -57
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +16 -11
  15. package/dist/types/accounts.d.ts +1 -1
  16. package/dist/types/blockhash.d.ts +1 -1
  17. package/dist/types/compile-instructions.d.ts +1 -1
  18. package/dist/types/durable-nonce.d.ts +4 -3
  19. package/dist/types/fee-payer.d.ts +2 -1
  20. package/dist/types/index.d.ts +1 -0
  21. package/dist/types/serializers/index.d.ts +2 -0
  22. package/dist/types/signatures.d.ts +10 -2
  23. package/dist/types/types.d.ts +7 -0
  24. package/dist/types/wire-transaction.d.ts +1 -1
  25. package/package.json +17 -15
  26. package/dist/types/accounts.d.ts.map +0 -1
  27. package/dist/types/blockhash.d.ts.map +0 -1
  28. package/dist/types/compile-address-table-lookups.d.ts.map +0 -1
  29. package/dist/types/compile-header.d.ts.map +0 -1
  30. package/dist/types/compile-instructions.d.ts.map +0 -1
  31. package/dist/types/compile-lifetime-token.d.ts.map +0 -1
  32. package/dist/types/compile-static-accounts.d.ts.map +0 -1
  33. package/dist/types/compile-transaction.d.ts.map +0 -1
  34. package/dist/types/create-transaction.d.ts.map +0 -1
  35. package/dist/types/durable-nonce.d.ts.map +0 -1
  36. package/dist/types/fee-payer.d.ts.map +0 -1
  37. package/dist/types/index.d.ts.map +0 -1
  38. package/dist/types/instructions.d.ts.map +0 -1
  39. package/dist/types/message.d.ts.map +0 -1
  40. package/dist/types/serializers/address-table-lookup.d.ts.map +0 -1
  41. package/dist/types/serializers/header.d.ts.map +0 -1
  42. package/dist/types/serializers/instruction.d.ts.map +0 -1
  43. package/dist/types/serializers/message.d.ts.map +0 -1
  44. package/dist/types/serializers/transaction-version.d.ts.map +0 -1
  45. package/dist/types/serializers/transaction.d.ts.map +0 -1
  46. package/dist/types/serializers/unimplemented.d.ts.map +0 -1
  47. package/dist/types/signatures.d.ts.map +0 -1
  48. package/dist/types/types.d.ts.map +0 -1
  49. package/dist/types/unsigned-transaction.d.ts.map +0 -1
  50. package/dist/types/wire-transaction.d.ts.map +0 -1
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
@@ -230,7 +230,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
230
230
  const shouldReplaceEntry = (
231
231
  // Consider using the new LOOKUP_TABLE if its address is different...
232
232
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
233
- (addressComparator || (addressComparator = addresses.getBase58EncodedAddressComparator()))(
233
+ (addressComparator || (addressComparator = addresses.getAddressComparator()))(
234
234
  accountMeta.lookupTableAddress,
235
235
  entry.lookupTableAddress
236
236
  ) < 0
@@ -336,7 +336,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
336
336
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
337
337
  return leftIsWritable ? -1 : 1;
338
338
  }
339
- addressComparator || (addressComparator = addresses.getBase58EncodedAddressComparator());
339
+ addressComparator || (addressComparator = addresses.getAddressComparator());
340
340
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
341
341
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
342
342
  } else {
@@ -365,7 +365,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
365
365
  entry.readableIndices.push(account.addressIndex);
366
366
  }
367
367
  }
368
- return Object.keys(index).sort(addresses.getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
368
+ return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
369
369
  lookupTableAddress,
370
370
  ...index[lookupTableAddress]
371
371
  }));
@@ -444,12 +444,40 @@ function compileMessage(transaction) {
444
444
  version: transaction.version
445
445
  };
446
446
  }
447
+
448
+ // src/compile-transaction.ts
449
+ function getCompiledTransaction(transaction) {
450
+ const compiledMessage = compileMessage(transaction);
451
+ let signatures;
452
+ if ("signatures" in transaction) {
453
+ signatures = [];
454
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
455
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
456
+ }
457
+ } else {
458
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
459
+ }
460
+ return {
461
+ compiledMessage,
462
+ signatures
463
+ };
464
+ }
465
+ function addressSerializerCompat(compat) {
466
+ const codec = addresses.getAddressCodec();
467
+ return {
468
+ description: compat?.description ?? codec.description,
469
+ deserialize: codec.decode,
470
+ fixedSize: codec.fixedSize,
471
+ maxSize: codec.maxSize,
472
+ serialize: codec.encode
473
+ };
474
+ }
447
475
  function getAddressTableLookupCodec() {
448
476
  return umiSerializers.struct(
449
477
  [
450
478
  [
451
479
  "lookupTableAddress",
452
- addresses.getBase58EncodedAddressCodec(
480
+ addressSerializerCompat(
453
481
  __DEV__ ? {
454
482
  description: "The address of the address lookup table account from which instruction addresses should be looked up"
455
483
  } : void 0
@@ -524,7 +552,7 @@ function getInstructionCodec() {
524
552
  )
525
553
  ],
526
554
  [
527
- "addressIndices",
555
+ "accountIndices",
528
556
  umiSerializers.array(
529
557
  umiSerializers.u8({
530
558
  description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
@@ -544,23 +572,23 @@ function getInstructionCodec() {
544
572
  ]
545
573
  ]),
546
574
  (value) => {
547
- if (value.addressIndices !== void 0 && value.data !== void 0) {
575
+ if (value.accountIndices !== void 0 && value.data !== void 0) {
548
576
  return value;
549
577
  }
550
578
  return {
551
579
  ...value,
552
- addressIndices: value.addressIndices ?? [],
580
+ accountIndices: value.accountIndices ?? [],
553
581
  data: value.data ?? new Uint8Array(0)
554
582
  };
555
583
  },
556
584
  (value) => {
557
- if (value.addressIndices.length && value.data.byteLength) {
585
+ if (value.accountIndices.length && value.data.byteLength) {
558
586
  return value;
559
587
  }
560
- const { addressIndices, data, ...rest } = value;
588
+ const { accountIndices, data, ...rest } = value;
561
589
  return {
562
590
  ...rest,
563
- ...addressIndices.length ? { addressIndices } : null,
591
+ ...accountIndices.length ? { accountIndices } : null,
564
592
  ...data.byteLength ? { data } : null
565
593
  };
566
594
  }
@@ -640,13 +668,23 @@ function serialize2(compiledMessage) {
640
668
  ).serialize(compiledMessage);
641
669
  }
642
670
  }
671
+ function addressSerializerCompat2() {
672
+ const codec = addresses.getAddressCodec();
673
+ return {
674
+ description: codec.description,
675
+ deserialize: codec.decode,
676
+ fixedSize: codec.fixedSize,
677
+ maxSize: codec.maxSize,
678
+ serialize: codec.encode
679
+ };
680
+ }
643
681
  function getPreludeStructSerializerTuple() {
644
682
  return [
645
683
  ["version", getTransactionVersionCodec()],
646
684
  ["header", getMessageHeaderCodec()],
647
685
  [
648
686
  "staticAccounts",
649
- umiSerializers.array(addresses.getBase58EncodedAddressCodec(), {
687
+ umiSerializers.array(addressSerializerCompat2(), {
650
688
  description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
651
689
  size: umiSerializers.shortU16()
652
690
  })
@@ -682,48 +720,6 @@ function getCompiledMessageEncoder() {
682
720
  };
683
721
  }
684
722
 
685
- // src/signatures.ts
686
- async function getCompiledMessageSignature(message, secretKey) {
687
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
688
- const signature = await keys.signBytes(secretKey, wireMessageBytes);
689
- return signature;
690
- }
691
- async function signTransaction(keyPair, transaction) {
692
- const compiledMessage = compileMessage(transaction);
693
- const [signerPublicKey, signature] = await Promise.all([
694
- addresses.getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
695
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
696
- ]);
697
- const nextSignatures = {
698
- ..."signatures" in transaction ? transaction.signatures : null,
699
- ...{ [signerPublicKey]: signature }
700
- };
701
- const out = {
702
- ...transaction,
703
- signatures: nextSignatures
704
- };
705
- Object.freeze(out);
706
- return out;
707
- }
708
-
709
- // src/compile-transaction.ts
710
- function getCompiledTransaction(transaction) {
711
- const compiledMessage = compileMessage(transaction);
712
- let signatures;
713
- if ("signatures" in transaction) {
714
- signatures = [];
715
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
716
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
717
- }
718
- } else {
719
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
720
- }
721
- return {
722
- compiledMessage,
723
- signatures
724
- };
725
- }
726
-
727
723
  // src/serializers/transaction.ts
728
724
  var BASE_CONFIG3 = {
729
725
  description: __DEV__ ? "The wire format of a Solana transaction" : "",
@@ -750,6 +746,80 @@ function getTransactionEncoder() {
750
746
  serialize: serialize3
751
747
  };
752
748
  }
749
+ function assertIsTransactionSignature(putativeTransactionSignature) {
750
+ try {
751
+ if (
752
+ // Lowest value (64 bytes of zeroes)
753
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
754
+ putativeTransactionSignature.length > 88
755
+ ) {
756
+ throw new Error("Expected input string to decode to a byte array of length 64.");
757
+ }
758
+ const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
759
+ const numBytes = bytes3.byteLength;
760
+ if (numBytes !== 64) {
761
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
762
+ }
763
+ } catch (e) {
764
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
765
+ cause: e
766
+ });
767
+ }
768
+ }
769
+ function isTransactionSignature(putativeTransactionSignature) {
770
+ if (
771
+ // Lowest value (64 bytes of zeroes)
772
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
773
+ putativeTransactionSignature.length > 88
774
+ ) {
775
+ return false;
776
+ }
777
+ const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
778
+ const numBytes = bytes3.byteLength;
779
+ if (numBytes !== 64) {
780
+ return false;
781
+ }
782
+ return true;
783
+ }
784
+ async function getCompiledMessageSignature(message, secretKey) {
785
+ const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
786
+ const signature = await keys.signBytes(secretKey, wireMessageBytes);
787
+ return signature;
788
+ }
789
+ function getSignatureFromTransaction(transaction) {
790
+ const signature = transaction.signatures[transaction.feePayer];
791
+ if (!signature) {
792
+ throw new Error(
793
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
794
+ );
795
+ }
796
+ return signature;
797
+ }
798
+ async function signTransaction(keyPairs, transaction) {
799
+ const compiledMessage = compileMessage(transaction);
800
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
801
+ const publicKeySignaturePairs = await Promise.all(
802
+ keyPairs.map(
803
+ (keyPair) => Promise.all([
804
+ addresses.getAddressFromPublicKey(keyPair.publicKey),
805
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
806
+ ])
807
+ )
808
+ );
809
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
810
+ nextSignatures[signerPublicKey] = signature;
811
+ }
812
+ const out = {
813
+ ...transaction,
814
+ signatures: nextSignatures
815
+ };
816
+ Object.freeze(out);
817
+ return out;
818
+ }
819
+ function transactionSignature(putativeTransactionSignature) {
820
+ assertIsTransactionSignature(putativeTransactionSignature);
821
+ return putativeTransactionSignature;
822
+ }
753
823
 
754
824
  // src/wire-transaction.ts
755
825
  function getBase64EncodedWireTransaction(transaction) {
@@ -762,10 +832,17 @@ function getBase64EncodedWireTransaction(transaction) {
762
832
  exports.appendTransactionInstruction = appendTransactionInstruction;
763
833
  exports.assertIsBlockhash = assertIsBlockhash;
764
834
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
835
+ exports.assertIsTransactionSignature = assertIsTransactionSignature;
765
836
  exports.createTransaction = createTransaction;
766
837
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
838
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
839
+ exports.getTransactionEncoder = getTransactionEncoder;
840
+ exports.isTransactionSignature = isTransactionSignature;
767
841
  exports.prependTransactionInstruction = prependTransactionInstruction;
768
842
  exports.setTransactionFeePayer = setTransactionFeePayer;
769
843
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
770
844
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
771
845
  exports.signTransaction = signTransaction;
846
+ exports.transactionSignature = transactionSignature;
847
+ //# sourceMappingURL=out.js.map
848
+ //# sourceMappingURL=index.browser.cjs.map