@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.
- package/LICENSE +1 -1
- package/dist/index.browser.cjs +130 -53
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +125 -55
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +543 -97
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +127 -55
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +130 -53
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +125 -57
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +16 -11
- package/dist/types/accounts.d.ts +1 -1
- package/dist/types/blockhash.d.ts +1 -1
- package/dist/types/compile-instructions.d.ts +1 -1
- package/dist/types/durable-nonce.d.ts +4 -3
- package/dist/types/fee-payer.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/signatures.d.ts +10 -2
- package/dist/types/types.d.ts +7 -0
- package/dist/types/wire-transaction.d.ts +1 -1
- package/package.json +17 -15
- package/dist/types/accounts.d.ts.map +0 -1
- package/dist/types/blockhash.d.ts.map +0 -1
- package/dist/types/compile-address-table-lookups.d.ts.map +0 -1
- package/dist/types/compile-header.d.ts.map +0 -1
- package/dist/types/compile-instructions.d.ts.map +0 -1
- package/dist/types/compile-lifetime-token.d.ts.map +0 -1
- package/dist/types/compile-static-accounts.d.ts.map +0 -1
- package/dist/types/compile-transaction.d.ts.map +0 -1
- package/dist/types/create-transaction.d.ts.map +0 -1
- package/dist/types/durable-nonce.d.ts.map +0 -1
- package/dist/types/fee-payer.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/instructions.d.ts.map +0 -1
- package/dist/types/message.d.ts.map +0 -1
- package/dist/types/serializers/address-table-lookup.d.ts.map +0 -1
- package/dist/types/serializers/header.d.ts.map +0 -1
- package/dist/types/serializers/instruction.d.ts.map +0 -1
- package/dist/types/serializers/message.d.ts.map +0 -1
- package/dist/types/serializers/transaction-version.d.ts.map +0 -1
- package/dist/types/serializers/transaction.d.ts.map +0 -1
- package/dist/types/serializers/unimplemented.d.ts.map +0 -1
- package/dist/types/signatures.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/unsigned-transaction.d.ts.map +0 -1
- package/dist/types/wire-transaction.d.ts.map +0 -1
package/LICENSE
CHANGED
package/dist/index.browser.cjs
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
"
|
|
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.
|
|
575
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
548
576
|
return value;
|
|
549
577
|
}
|
|
550
578
|
return {
|
|
551
579
|
...value,
|
|
552
|
-
|
|
580
|
+
accountIndices: value.accountIndices ?? [],
|
|
553
581
|
data: value.data ?? new Uint8Array(0)
|
|
554
582
|
};
|
|
555
583
|
},
|
|
556
584
|
(value) => {
|
|
557
|
-
if (value.
|
|
585
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
558
586
|
return value;
|
|
559
587
|
}
|
|
560
|
-
const {
|
|
588
|
+
const { accountIndices, data, ...rest } = value;
|
|
561
589
|
return {
|
|
562
590
|
...rest,
|
|
563
|
-
...
|
|
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(
|
|
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
|