@solana/transactions 2.0.0-experimental.b9c1a94 → 2.0.0-experimental.ba21818
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/index.browser.cjs +166 -72
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +163 -74
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +555 -91
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +161 -74
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +164 -72
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +161 -74
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +16 -11
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
- package/dist/types/compile-header.d.ts.map +1 -0
- package/dist/types/compile-instructions.d.ts.map +1 -0
- package/dist/types/compile-lifetime-token.d.ts.map +1 -0
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +2 -1
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +2 -1
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instructions.d.ts.map +1 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/serializers/unimplemented.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +9 -1
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +13 -11
package/LICENSE
CHANGED
package/dist/index.browser.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
4
|
var addresses = require('@solana/addresses');
|
|
5
|
+
var codecsCore = require('@solana/codecs-core');
|
|
5
6
|
var keys = require('@solana/keys');
|
|
6
7
|
|
|
7
8
|
// ../build-scripts/env-shim.ts
|
|
@@ -230,7 +231,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
230
231
|
const shouldReplaceEntry = (
|
|
231
232
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
232
233
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
233
|
-
(addressComparator || (addressComparator = addresses.
|
|
234
|
+
(addressComparator || (addressComparator = addresses.getAddressComparator()))(
|
|
234
235
|
accountMeta.lookupTableAddress,
|
|
235
236
|
entry.lookupTableAddress
|
|
236
237
|
) < 0
|
|
@@ -336,7 +337,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
336
337
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
337
338
|
return leftIsWritable ? -1 : 1;
|
|
338
339
|
}
|
|
339
|
-
addressComparator || (addressComparator = addresses.
|
|
340
|
+
addressComparator || (addressComparator = addresses.getAddressComparator());
|
|
340
341
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
341
342
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
342
343
|
} else {
|
|
@@ -365,7 +366,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
365
366
|
entry.readableIndices.push(account.addressIndex);
|
|
366
367
|
}
|
|
367
368
|
}
|
|
368
|
-
return Object.keys(index).sort(addresses.
|
|
369
|
+
return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
|
|
369
370
|
lookupTableAddress,
|
|
370
371
|
...index[lookupTableAddress]
|
|
371
372
|
}));
|
|
@@ -444,12 +445,40 @@ function compileMessage(transaction) {
|
|
|
444
445
|
version: transaction.version
|
|
445
446
|
};
|
|
446
447
|
}
|
|
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
|
+
function addressSerializerCompat(compat) {
|
|
467
|
+
const codec = addresses.getAddressCodec();
|
|
468
|
+
return {
|
|
469
|
+
description: compat?.description ?? codec.description,
|
|
470
|
+
deserialize: codec.decode,
|
|
471
|
+
fixedSize: codec.fixedSize,
|
|
472
|
+
maxSize: codec.maxSize,
|
|
473
|
+
serialize: codec.encode
|
|
474
|
+
};
|
|
475
|
+
}
|
|
447
476
|
function getAddressTableLookupCodec() {
|
|
448
477
|
return umiSerializers.struct(
|
|
449
478
|
[
|
|
450
479
|
[
|
|
451
480
|
"lookupTableAddress",
|
|
452
|
-
|
|
481
|
+
addressSerializerCompat(
|
|
453
482
|
__DEV__ ? {
|
|
454
483
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
455
484
|
} : void 0
|
|
@@ -566,28 +595,13 @@ function getInstructionCodec() {
|
|
|
566
595
|
}
|
|
567
596
|
);
|
|
568
597
|
}
|
|
569
|
-
|
|
570
|
-
// src/serializers/unimplemented.ts
|
|
571
|
-
function getError(type, name) {
|
|
572
|
-
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
573
|
-
return new Error(
|
|
574
|
-
`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}`
|
|
575
|
-
);
|
|
576
|
-
}
|
|
577
|
-
function getUnimplementedDecoder(name) {
|
|
578
|
-
return () => {
|
|
579
|
-
throw getError("decoder", name);
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// src/serializers/transaction-version.ts
|
|
584
598
|
var VERSION_FLAG_MASK = 128;
|
|
585
599
|
var BASE_CONFIG = {
|
|
586
600
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
587
601
|
fixedSize: null,
|
|
588
602
|
maxSize: 1
|
|
589
603
|
};
|
|
590
|
-
function
|
|
604
|
+
function decode(bytes3, offset = 0) {
|
|
591
605
|
const firstByte = bytes3[offset];
|
|
592
606
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
593
607
|
return ["legacy", offset];
|
|
@@ -596,7 +610,7 @@ function deserialize(bytes3, offset = 0) {
|
|
|
596
610
|
return [version, offset + 1];
|
|
597
611
|
}
|
|
598
612
|
}
|
|
599
|
-
function
|
|
613
|
+
function encode(value) {
|
|
600
614
|
if (value === "legacy") {
|
|
601
615
|
return new Uint8Array();
|
|
602
616
|
}
|
|
@@ -605,11 +619,32 @@ function serialize(value) {
|
|
|
605
619
|
}
|
|
606
620
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
607
621
|
}
|
|
608
|
-
function
|
|
622
|
+
function getTransactionVersionDecoder() {
|
|
609
623
|
return {
|
|
610
624
|
...BASE_CONFIG,
|
|
611
|
-
|
|
612
|
-
|
|
625
|
+
decode
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function getTransactionVersionEncoder() {
|
|
629
|
+
return {
|
|
630
|
+
...BASE_CONFIG,
|
|
631
|
+
encode
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
function getTransactionVersionCodec() {
|
|
635
|
+
return codecsCore.combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// src/serializers/unimplemented.ts
|
|
639
|
+
function getError(type, name) {
|
|
640
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
641
|
+
return new Error(
|
|
642
|
+
`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}`
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
function getUnimplementedDecoder(name) {
|
|
646
|
+
return () => {
|
|
647
|
+
throw getError("decoder", name);
|
|
613
648
|
};
|
|
614
649
|
}
|
|
615
650
|
|
|
@@ -619,7 +654,7 @@ var BASE_CONFIG2 = {
|
|
|
619
654
|
fixedSize: null,
|
|
620
655
|
maxSize: null
|
|
621
656
|
};
|
|
622
|
-
function
|
|
657
|
+
function serialize(compiledMessage) {
|
|
623
658
|
if (compiledMessage.version === "legacy") {
|
|
624
659
|
return umiSerializers.struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
625
660
|
} else {
|
|
@@ -640,13 +675,33 @@ function serialize2(compiledMessage) {
|
|
|
640
675
|
).serialize(compiledMessage);
|
|
641
676
|
}
|
|
642
677
|
}
|
|
678
|
+
function addressSerializerCompat2() {
|
|
679
|
+
const codec = addresses.getAddressCodec();
|
|
680
|
+
return {
|
|
681
|
+
description: codec.description,
|
|
682
|
+
deserialize: codec.decode,
|
|
683
|
+
fixedSize: codec.fixedSize,
|
|
684
|
+
maxSize: codec.maxSize,
|
|
685
|
+
serialize: codec.encode
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
function transactionVersionSerializerCompat() {
|
|
689
|
+
const codec = getTransactionVersionCodec();
|
|
690
|
+
return {
|
|
691
|
+
description: codec.description,
|
|
692
|
+
deserialize: codec.decode,
|
|
693
|
+
fixedSize: codec.fixedSize,
|
|
694
|
+
maxSize: codec.maxSize,
|
|
695
|
+
serialize: codec.encode
|
|
696
|
+
};
|
|
697
|
+
}
|
|
643
698
|
function getPreludeStructSerializerTuple() {
|
|
644
699
|
return [
|
|
645
|
-
["version",
|
|
700
|
+
["version", transactionVersionSerializerCompat()],
|
|
646
701
|
["header", getMessageHeaderCodec()],
|
|
647
702
|
[
|
|
648
703
|
"staticAccounts",
|
|
649
|
-
umiSerializers.array(
|
|
704
|
+
umiSerializers.array(addressSerializerCompat2(), {
|
|
650
705
|
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
|
|
651
706
|
size: umiSerializers.shortU16()
|
|
652
707
|
})
|
|
@@ -678,49 +733,7 @@ function getCompiledMessageEncoder() {
|
|
|
678
733
|
return {
|
|
679
734
|
...BASE_CONFIG2,
|
|
680
735
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
681
|
-
serialize
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
|
|
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.getAddressFromPublicKey(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
|
|
736
|
+
serialize
|
|
724
737
|
};
|
|
725
738
|
}
|
|
726
739
|
|
|
@@ -730,7 +743,7 @@ var BASE_CONFIG3 = {
|
|
|
730
743
|
fixedSize: null,
|
|
731
744
|
maxSize: null
|
|
732
745
|
};
|
|
733
|
-
function
|
|
746
|
+
function serialize2(transaction) {
|
|
734
747
|
const compiledTransaction = getCompiledTransaction(transaction);
|
|
735
748
|
return umiSerializers.struct([
|
|
736
749
|
[
|
|
@@ -747,9 +760,83 @@ function getTransactionEncoder() {
|
|
|
747
760
|
return {
|
|
748
761
|
...BASE_CONFIG3,
|
|
749
762
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
750
|
-
serialize:
|
|
763
|
+
serialize: serialize2
|
|
751
764
|
};
|
|
752
765
|
}
|
|
766
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
767
|
+
try {
|
|
768
|
+
if (
|
|
769
|
+
// Lowest value (64 bytes of zeroes)
|
|
770
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
771
|
+
putativeTransactionSignature.length > 88
|
|
772
|
+
) {
|
|
773
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
774
|
+
}
|
|
775
|
+
const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
776
|
+
const numBytes = bytes3.byteLength;
|
|
777
|
+
if (numBytes !== 64) {
|
|
778
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
779
|
+
}
|
|
780
|
+
} catch (e) {
|
|
781
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
782
|
+
cause: e
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
787
|
+
if (
|
|
788
|
+
// Lowest value (64 bytes of zeroes)
|
|
789
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
790
|
+
putativeTransactionSignature.length > 88
|
|
791
|
+
) {
|
|
792
|
+
return false;
|
|
793
|
+
}
|
|
794
|
+
const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
795
|
+
const numBytes = bytes3.byteLength;
|
|
796
|
+
if (numBytes !== 64) {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
802
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
803
|
+
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
804
|
+
return signature;
|
|
805
|
+
}
|
|
806
|
+
function getSignatureFromTransaction(transaction) {
|
|
807
|
+
const signature = transaction.signatures[transaction.feePayer];
|
|
808
|
+
if (!signature) {
|
|
809
|
+
throw new Error(
|
|
810
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
return signature;
|
|
814
|
+
}
|
|
815
|
+
async function signTransaction(keyPairs, transaction) {
|
|
816
|
+
const compiledMessage = compileMessage(transaction);
|
|
817
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
818
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
819
|
+
keyPairs.map(
|
|
820
|
+
(keyPair) => Promise.all([
|
|
821
|
+
addresses.getAddressFromPublicKey(keyPair.publicKey),
|
|
822
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
823
|
+
])
|
|
824
|
+
)
|
|
825
|
+
);
|
|
826
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
827
|
+
nextSignatures[signerPublicKey] = signature;
|
|
828
|
+
}
|
|
829
|
+
const out = {
|
|
830
|
+
...transaction,
|
|
831
|
+
signatures: nextSignatures
|
|
832
|
+
};
|
|
833
|
+
Object.freeze(out);
|
|
834
|
+
return out;
|
|
835
|
+
}
|
|
836
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
837
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
838
|
+
return putativeTransactionSignature;
|
|
839
|
+
}
|
|
753
840
|
|
|
754
841
|
// src/wire-transaction.ts
|
|
755
842
|
function getBase64EncodedWireTransaction(transaction) {
|
|
@@ -762,10 +849,17 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
762
849
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
763
850
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
764
851
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
852
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
765
853
|
exports.createTransaction = createTransaction;
|
|
766
854
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
855
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
856
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
857
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
767
858
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
768
859
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
769
860
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
770
861
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
771
862
|
exports.signTransaction = signTransaction;
|
|
863
|
+
exports.transactionSignature = transactionSignature;
|
|
864
|
+
//# sourceMappingURL=out.js.map
|
|
865
|
+
//# sourceMappingURL=index.browser.cjs.map
|