@solana/transactions 2.0.0-experimental.7da1908 → 2.0.0-experimental.819a6f7
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 +126 -103
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +127 -105
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +567 -121
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +127 -105
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +128 -103
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +129 -105
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +16 -15
- package/dist/types/index.d.ts +1 -0
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/package.json +10 -7
- 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
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
4
|
var addresses = require('@solana/addresses');
|
|
5
|
+
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
6
|
+
var codecsNumbers = require('@solana/codecs-numbers');
|
|
7
|
+
var codecsCore = require('@solana/codecs-core');
|
|
5
8
|
var keys = require('@solana/keys');
|
|
6
9
|
|
|
7
10
|
// ../build-scripts/env-shim.ts
|
|
@@ -230,7 +233,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
230
233
|
const shouldReplaceEntry = (
|
|
231
234
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
232
235
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
233
|
-
(addressComparator || (addressComparator = addresses.
|
|
236
|
+
(addressComparator || (addressComparator = addresses.getAddressComparator()))(
|
|
234
237
|
accountMeta.lookupTableAddress,
|
|
235
238
|
entry.lookupTableAddress
|
|
236
239
|
) < 0
|
|
@@ -336,7 +339,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
336
339
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
337
340
|
return leftIsWritable ? -1 : 1;
|
|
338
341
|
}
|
|
339
|
-
addressComparator || (addressComparator = addresses.
|
|
342
|
+
addressComparator || (addressComparator = addresses.getAddressComparator());
|
|
340
343
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
341
344
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
342
345
|
} else {
|
|
@@ -365,7 +368,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
365
368
|
entry.readableIndices.push(account.addressIndex);
|
|
366
369
|
}
|
|
367
370
|
}
|
|
368
|
-
return Object.keys(index).sort(addresses.
|
|
371
|
+
return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
|
|
369
372
|
lookupTableAddress,
|
|
370
373
|
...index[lookupTableAddress]
|
|
371
374
|
}));
|
|
@@ -444,12 +447,40 @@ function compileMessage(transaction) {
|
|
|
444
447
|
version: transaction.version
|
|
445
448
|
};
|
|
446
449
|
}
|
|
450
|
+
|
|
451
|
+
// src/compile-transaction.ts
|
|
452
|
+
function getCompiledTransaction(transaction) {
|
|
453
|
+
const compiledMessage = compileMessage(transaction);
|
|
454
|
+
let signatures;
|
|
455
|
+
if ("signatures" in transaction) {
|
|
456
|
+
signatures = [];
|
|
457
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
458
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
compiledMessage,
|
|
465
|
+
signatures
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function addressSerializerCompat(compat) {
|
|
469
|
+
const codec = addresses.getAddressCodec();
|
|
470
|
+
return {
|
|
471
|
+
description: compat?.description ?? codec.description,
|
|
472
|
+
deserialize: codec.decode,
|
|
473
|
+
fixedSize: codec.fixedSize,
|
|
474
|
+
maxSize: codec.maxSize,
|
|
475
|
+
serialize: codec.encode
|
|
476
|
+
};
|
|
477
|
+
}
|
|
447
478
|
function getAddressTableLookupCodec() {
|
|
448
479
|
return umiSerializers.struct(
|
|
449
480
|
[
|
|
450
481
|
[
|
|
451
482
|
"lookupTableAddress",
|
|
452
|
-
|
|
483
|
+
addressSerializerCompat(
|
|
453
484
|
__DEV__ ? {
|
|
454
485
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
455
486
|
} : void 0
|
|
@@ -479,37 +510,33 @@ function getAddressTableLookupCodec() {
|
|
|
479
510
|
} : void 0
|
|
480
511
|
);
|
|
481
512
|
}
|
|
513
|
+
var memoizedU8Codec;
|
|
514
|
+
function getMemoizedU8Codec() {
|
|
515
|
+
if (!memoizedU8Codec)
|
|
516
|
+
memoizedU8Codec = codecsNumbers.getU8Codec();
|
|
517
|
+
return memoizedU8Codec;
|
|
518
|
+
}
|
|
519
|
+
function getMemoizedU8CodecDescription(description) {
|
|
520
|
+
const codec = getMemoizedU8Codec();
|
|
521
|
+
return {
|
|
522
|
+
...codec,
|
|
523
|
+
description: description ?? codec.description
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
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;
|
|
527
|
+
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;
|
|
528
|
+
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
529
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
482
530
|
function getMessageHeaderCodec() {
|
|
483
|
-
return
|
|
531
|
+
return codecsDataStructures.getStructCodec(
|
|
484
532
|
[
|
|
485
|
-
[
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
__DEV__ ? {
|
|
489
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
490
|
-
} : void 0
|
|
491
|
-
)
|
|
492
|
-
],
|
|
493
|
-
[
|
|
494
|
-
"numReadonlySignerAccounts",
|
|
495
|
-
umiSerializers.u8(
|
|
496
|
-
__DEV__ ? {
|
|
497
|
-
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"
|
|
498
|
-
} : void 0
|
|
499
|
-
)
|
|
500
|
-
],
|
|
501
|
-
[
|
|
502
|
-
"numReadonlyNonSignerAccounts",
|
|
503
|
-
umiSerializers.u8(
|
|
504
|
-
__DEV__ ? {
|
|
505
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
506
|
-
} : void 0
|
|
507
|
-
)
|
|
508
|
-
]
|
|
533
|
+
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
|
|
534
|
+
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
|
|
535
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
|
|
509
536
|
],
|
|
510
|
-
|
|
511
|
-
description:
|
|
512
|
-
}
|
|
537
|
+
{
|
|
538
|
+
description: messageHeaderDescription
|
|
539
|
+
}
|
|
513
540
|
);
|
|
514
541
|
}
|
|
515
542
|
function getInstructionCodec() {
|
|
@@ -566,28 +593,13 @@ function getInstructionCodec() {
|
|
|
566
593
|
}
|
|
567
594
|
);
|
|
568
595
|
}
|
|
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
596
|
var VERSION_FLAG_MASK = 128;
|
|
585
597
|
var BASE_CONFIG = {
|
|
586
598
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
587
599
|
fixedSize: null,
|
|
588
600
|
maxSize: 1
|
|
589
601
|
};
|
|
590
|
-
function
|
|
602
|
+
function decode(bytes3, offset = 0) {
|
|
591
603
|
const firstByte = bytes3[offset];
|
|
592
604
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
593
605
|
return ["legacy", offset];
|
|
@@ -596,7 +608,7 @@ function deserialize(bytes3, offset = 0) {
|
|
|
596
608
|
return [version, offset + 1];
|
|
597
609
|
}
|
|
598
610
|
}
|
|
599
|
-
function
|
|
611
|
+
function encode(value) {
|
|
600
612
|
if (value === "legacy") {
|
|
601
613
|
return new Uint8Array();
|
|
602
614
|
}
|
|
@@ -605,11 +617,32 @@ function serialize(value) {
|
|
|
605
617
|
}
|
|
606
618
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
607
619
|
}
|
|
608
|
-
function
|
|
620
|
+
function getTransactionVersionDecoder() {
|
|
609
621
|
return {
|
|
610
622
|
...BASE_CONFIG,
|
|
611
|
-
|
|
612
|
-
|
|
623
|
+
decode
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function getTransactionVersionEncoder() {
|
|
627
|
+
return {
|
|
628
|
+
...BASE_CONFIG,
|
|
629
|
+
encode
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function getTransactionVersionCodec() {
|
|
633
|
+
return codecsCore.combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// src/serializers/unimplemented.ts
|
|
637
|
+
function getError(type, name) {
|
|
638
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
639
|
+
return new Error(
|
|
640
|
+
`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}`
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
function getUnimplementedDecoder(name) {
|
|
644
|
+
return () => {
|
|
645
|
+
throw getError("decoder", name);
|
|
613
646
|
};
|
|
614
647
|
}
|
|
615
648
|
|
|
@@ -619,7 +652,7 @@ var BASE_CONFIG2 = {
|
|
|
619
652
|
fixedSize: null,
|
|
620
653
|
maxSize: null
|
|
621
654
|
};
|
|
622
|
-
function
|
|
655
|
+
function serialize(compiledMessage) {
|
|
623
656
|
if (compiledMessage.version === "legacy") {
|
|
624
657
|
return umiSerializers.struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
625
658
|
} else {
|
|
@@ -640,13 +673,22 @@ function serialize2(compiledMessage) {
|
|
|
640
673
|
).serialize(compiledMessage);
|
|
641
674
|
}
|
|
642
675
|
}
|
|
676
|
+
function toSerializer(codec) {
|
|
677
|
+
return {
|
|
678
|
+
description: codec.description,
|
|
679
|
+
deserialize: codec.decode,
|
|
680
|
+
fixedSize: codec.fixedSize,
|
|
681
|
+
maxSize: codec.maxSize,
|
|
682
|
+
serialize: codec.encode
|
|
683
|
+
};
|
|
684
|
+
}
|
|
643
685
|
function getPreludeStructSerializerTuple() {
|
|
644
686
|
return [
|
|
645
|
-
["version", getTransactionVersionCodec()],
|
|
646
|
-
["header", getMessageHeaderCodec()],
|
|
687
|
+
["version", toSerializer(getTransactionVersionCodec())],
|
|
688
|
+
["header", toSerializer(getMessageHeaderCodec())],
|
|
647
689
|
[
|
|
648
690
|
"staticAccounts",
|
|
649
|
-
umiSerializers.array(addresses.
|
|
691
|
+
umiSerializers.array(toSerializer(addresses.getAddressCodec()), {
|
|
650
692
|
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
|
|
651
693
|
size: umiSerializers.shortU16()
|
|
652
694
|
})
|
|
@@ -678,11 +720,36 @@ function getCompiledMessageEncoder() {
|
|
|
678
720
|
return {
|
|
679
721
|
...BASE_CONFIG2,
|
|
680
722
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
681
|
-
serialize
|
|
723
|
+
serialize
|
|
682
724
|
};
|
|
683
725
|
}
|
|
684
726
|
|
|
685
|
-
// src/
|
|
727
|
+
// src/serializers/transaction.ts
|
|
728
|
+
var BASE_CONFIG3 = {
|
|
729
|
+
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
730
|
+
fixedSize: null,
|
|
731
|
+
maxSize: null
|
|
732
|
+
};
|
|
733
|
+
function serialize2(transaction) {
|
|
734
|
+
const compiledTransaction = getCompiledTransaction(transaction);
|
|
735
|
+
return umiSerializers.struct([
|
|
736
|
+
[
|
|
737
|
+
"signatures",
|
|
738
|
+
umiSerializers.array(umiSerializers.bytes({ size: 64 }), {
|
|
739
|
+
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
|
|
740
|
+
size: umiSerializers.shortU16()
|
|
741
|
+
})
|
|
742
|
+
],
|
|
743
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
744
|
+
]).serialize(compiledTransaction);
|
|
745
|
+
}
|
|
746
|
+
function getTransactionEncoder() {
|
|
747
|
+
return {
|
|
748
|
+
...BASE_CONFIG3,
|
|
749
|
+
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
750
|
+
serialize: serialize2
|
|
751
|
+
};
|
|
752
|
+
}
|
|
686
753
|
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
687
754
|
try {
|
|
688
755
|
if (
|
|
@@ -758,51 +825,6 @@ function transactionSignature(putativeTransactionSignature) {
|
|
|
758
825
|
return putativeTransactionSignature;
|
|
759
826
|
}
|
|
760
827
|
|
|
761
|
-
// src/compile-transaction.ts
|
|
762
|
-
function getCompiledTransaction(transaction) {
|
|
763
|
-
const compiledMessage = compileMessage(transaction);
|
|
764
|
-
let signatures;
|
|
765
|
-
if ("signatures" in transaction) {
|
|
766
|
-
signatures = [];
|
|
767
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
768
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
769
|
-
}
|
|
770
|
-
} else {
|
|
771
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
772
|
-
}
|
|
773
|
-
return {
|
|
774
|
-
compiledMessage,
|
|
775
|
-
signatures
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
// src/serializers/transaction.ts
|
|
780
|
-
var BASE_CONFIG3 = {
|
|
781
|
-
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
782
|
-
fixedSize: null,
|
|
783
|
-
maxSize: null
|
|
784
|
-
};
|
|
785
|
-
function serialize3(transaction) {
|
|
786
|
-
const compiledTransaction = getCompiledTransaction(transaction);
|
|
787
|
-
return umiSerializers.struct([
|
|
788
|
-
[
|
|
789
|
-
"signatures",
|
|
790
|
-
umiSerializers.array(umiSerializers.bytes({ size: 64 }), {
|
|
791
|
-
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
|
|
792
|
-
size: umiSerializers.shortU16()
|
|
793
|
-
})
|
|
794
|
-
],
|
|
795
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
796
|
-
]).serialize(compiledTransaction);
|
|
797
|
-
}
|
|
798
|
-
function getTransactionEncoder() {
|
|
799
|
-
return {
|
|
800
|
-
...BASE_CONFIG3,
|
|
801
|
-
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
802
|
-
serialize: serialize3
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
|
|
806
828
|
// src/wire-transaction.ts
|
|
807
829
|
function getBase64EncodedWireTransaction(transaction) {
|
|
808
830
|
const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
|
|
@@ -818,6 +840,7 @@ exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
|
818
840
|
exports.createTransaction = createTransaction;
|
|
819
841
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
820
842
|
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
843
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
821
844
|
exports.isTransactionSignature = isTransactionSignature;
|
|
822
845
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
823
846
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|