@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/dist/index.browser.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers';
|
|
2
|
-
import { getAddressFromPublicKey,
|
|
2
|
+
import { getAddressFromPublicKey, getAddressComparator, getAddressCodec } from '@solana/addresses';
|
|
3
|
+
import { getStructCodec } from '@solana/codecs-data-structures';
|
|
4
|
+
import { getU8Codec } from '@solana/codecs-numbers';
|
|
5
|
+
import { combineCodec } from '@solana/codecs-core';
|
|
3
6
|
import { signBytes } from '@solana/keys';
|
|
4
7
|
|
|
5
8
|
// ../build-scripts/env-shim.ts
|
|
@@ -228,7 +231,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
228
231
|
const shouldReplaceEntry = (
|
|
229
232
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
230
233
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
231
|
-
(addressComparator || (addressComparator =
|
|
234
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
232
235
|
accountMeta.lookupTableAddress,
|
|
233
236
|
entry.lookupTableAddress
|
|
234
237
|
) < 0
|
|
@@ -334,7 +337,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
334
337
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
335
338
|
return leftIsWritable ? -1 : 1;
|
|
336
339
|
}
|
|
337
|
-
addressComparator || (addressComparator =
|
|
340
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
338
341
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
339
342
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
340
343
|
} else {
|
|
@@ -363,7 +366,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
363
366
|
entry.readableIndices.push(account.addressIndex);
|
|
364
367
|
}
|
|
365
368
|
}
|
|
366
|
-
return Object.keys(index).sort(
|
|
369
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
367
370
|
lookupTableAddress,
|
|
368
371
|
...index[lookupTableAddress]
|
|
369
372
|
}));
|
|
@@ -442,12 +445,40 @@ function compileMessage(transaction) {
|
|
|
442
445
|
version: transaction.version
|
|
443
446
|
};
|
|
444
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 = 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
|
+
}
|
|
445
476
|
function getAddressTableLookupCodec() {
|
|
446
477
|
return struct(
|
|
447
478
|
[
|
|
448
479
|
[
|
|
449
480
|
"lookupTableAddress",
|
|
450
|
-
|
|
481
|
+
addressSerializerCompat(
|
|
451
482
|
__DEV__ ? {
|
|
452
483
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
453
484
|
} : void 0
|
|
@@ -477,37 +508,33 @@ function getAddressTableLookupCodec() {
|
|
|
477
508
|
} : void 0
|
|
478
509
|
);
|
|
479
510
|
}
|
|
511
|
+
var memoizedU8Codec;
|
|
512
|
+
function getMemoizedU8Codec() {
|
|
513
|
+
if (!memoizedU8Codec)
|
|
514
|
+
memoizedU8Codec = getU8Codec();
|
|
515
|
+
return memoizedU8Codec;
|
|
516
|
+
}
|
|
517
|
+
function getMemoizedU8CodecDescription(description) {
|
|
518
|
+
const codec = getMemoizedU8Codec();
|
|
519
|
+
return {
|
|
520
|
+
...codec,
|
|
521
|
+
description: description ?? codec.description
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
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;
|
|
525
|
+
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;
|
|
526
|
+
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
527
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
480
528
|
function getMessageHeaderCodec() {
|
|
481
|
-
return
|
|
529
|
+
return getStructCodec(
|
|
482
530
|
[
|
|
483
|
-
[
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
__DEV__ ? {
|
|
487
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
488
|
-
} : void 0
|
|
489
|
-
)
|
|
490
|
-
],
|
|
491
|
-
[
|
|
492
|
-
"numReadonlySignerAccounts",
|
|
493
|
-
u8(
|
|
494
|
-
__DEV__ ? {
|
|
495
|
-
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"
|
|
496
|
-
} : void 0
|
|
497
|
-
)
|
|
498
|
-
],
|
|
499
|
-
[
|
|
500
|
-
"numReadonlyNonSignerAccounts",
|
|
501
|
-
u8(
|
|
502
|
-
__DEV__ ? {
|
|
503
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
504
|
-
} : void 0
|
|
505
|
-
)
|
|
506
|
-
]
|
|
531
|
+
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
|
|
532
|
+
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
|
|
533
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
|
|
507
534
|
],
|
|
508
|
-
|
|
509
|
-
description:
|
|
510
|
-
}
|
|
535
|
+
{
|
|
536
|
+
description: messageHeaderDescription
|
|
537
|
+
}
|
|
511
538
|
);
|
|
512
539
|
}
|
|
513
540
|
function getInstructionCodec() {
|
|
@@ -564,28 +591,13 @@ function getInstructionCodec() {
|
|
|
564
591
|
}
|
|
565
592
|
);
|
|
566
593
|
}
|
|
567
|
-
|
|
568
|
-
// src/serializers/unimplemented.ts
|
|
569
|
-
function getError(type, name) {
|
|
570
|
-
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
571
|
-
return new Error(
|
|
572
|
-
`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}`
|
|
573
|
-
);
|
|
574
|
-
}
|
|
575
|
-
function getUnimplementedDecoder(name) {
|
|
576
|
-
return () => {
|
|
577
|
-
throw getError("decoder", name);
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// src/serializers/transaction-version.ts
|
|
582
594
|
var VERSION_FLAG_MASK = 128;
|
|
583
595
|
var BASE_CONFIG = {
|
|
584
596
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
585
597
|
fixedSize: null,
|
|
586
598
|
maxSize: 1
|
|
587
599
|
};
|
|
588
|
-
function
|
|
600
|
+
function decode(bytes3, offset = 0) {
|
|
589
601
|
const firstByte = bytes3[offset];
|
|
590
602
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
591
603
|
return ["legacy", offset];
|
|
@@ -594,7 +606,7 @@ function deserialize(bytes3, offset = 0) {
|
|
|
594
606
|
return [version, offset + 1];
|
|
595
607
|
}
|
|
596
608
|
}
|
|
597
|
-
function
|
|
609
|
+
function encode(value) {
|
|
598
610
|
if (value === "legacy") {
|
|
599
611
|
return new Uint8Array();
|
|
600
612
|
}
|
|
@@ -603,11 +615,32 @@ function serialize(value) {
|
|
|
603
615
|
}
|
|
604
616
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
605
617
|
}
|
|
606
|
-
function
|
|
618
|
+
function getTransactionVersionDecoder() {
|
|
607
619
|
return {
|
|
608
620
|
...BASE_CONFIG,
|
|
609
|
-
|
|
610
|
-
|
|
621
|
+
decode
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function getTransactionVersionEncoder() {
|
|
625
|
+
return {
|
|
626
|
+
...BASE_CONFIG,
|
|
627
|
+
encode
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
function getTransactionVersionCodec() {
|
|
631
|
+
return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/serializers/unimplemented.ts
|
|
635
|
+
function getError(type, name) {
|
|
636
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
637
|
+
return new Error(
|
|
638
|
+
`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}`
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
function getUnimplementedDecoder(name) {
|
|
642
|
+
return () => {
|
|
643
|
+
throw getError("decoder", name);
|
|
611
644
|
};
|
|
612
645
|
}
|
|
613
646
|
|
|
@@ -617,7 +650,7 @@ var BASE_CONFIG2 = {
|
|
|
617
650
|
fixedSize: null,
|
|
618
651
|
maxSize: null
|
|
619
652
|
};
|
|
620
|
-
function
|
|
653
|
+
function serialize(compiledMessage) {
|
|
621
654
|
if (compiledMessage.version === "legacy") {
|
|
622
655
|
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
623
656
|
} else {
|
|
@@ -638,13 +671,22 @@ function serialize2(compiledMessage) {
|
|
|
638
671
|
).serialize(compiledMessage);
|
|
639
672
|
}
|
|
640
673
|
}
|
|
674
|
+
function toSerializer(codec) {
|
|
675
|
+
return {
|
|
676
|
+
description: codec.description,
|
|
677
|
+
deserialize: codec.decode,
|
|
678
|
+
fixedSize: codec.fixedSize,
|
|
679
|
+
maxSize: codec.maxSize,
|
|
680
|
+
serialize: codec.encode
|
|
681
|
+
};
|
|
682
|
+
}
|
|
641
683
|
function getPreludeStructSerializerTuple() {
|
|
642
684
|
return [
|
|
643
|
-
["version", getTransactionVersionCodec()],
|
|
644
|
-
["header", getMessageHeaderCodec()],
|
|
685
|
+
["version", toSerializer(getTransactionVersionCodec())],
|
|
686
|
+
["header", toSerializer(getMessageHeaderCodec())],
|
|
645
687
|
[
|
|
646
688
|
"staticAccounts",
|
|
647
|
-
array(
|
|
689
|
+
array(toSerializer(getAddressCodec()), {
|
|
648
690
|
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
|
|
649
691
|
size: shortU16()
|
|
650
692
|
})
|
|
@@ -676,11 +718,36 @@ function getCompiledMessageEncoder() {
|
|
|
676
718
|
return {
|
|
677
719
|
...BASE_CONFIG2,
|
|
678
720
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
679
|
-
serialize
|
|
721
|
+
serialize
|
|
680
722
|
};
|
|
681
723
|
}
|
|
682
724
|
|
|
683
|
-
// src/
|
|
725
|
+
// src/serializers/transaction.ts
|
|
726
|
+
var BASE_CONFIG3 = {
|
|
727
|
+
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
728
|
+
fixedSize: null,
|
|
729
|
+
maxSize: null
|
|
730
|
+
};
|
|
731
|
+
function serialize2(transaction) {
|
|
732
|
+
const compiledTransaction = getCompiledTransaction(transaction);
|
|
733
|
+
return struct([
|
|
734
|
+
[
|
|
735
|
+
"signatures",
|
|
736
|
+
array(bytes({ size: 64 }), {
|
|
737
|
+
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
|
|
738
|
+
size: shortU16()
|
|
739
|
+
})
|
|
740
|
+
],
|
|
741
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
742
|
+
]).serialize(compiledTransaction);
|
|
743
|
+
}
|
|
744
|
+
function getTransactionEncoder() {
|
|
745
|
+
return {
|
|
746
|
+
...BASE_CONFIG3,
|
|
747
|
+
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
748
|
+
serialize: serialize2
|
|
749
|
+
};
|
|
750
|
+
}
|
|
684
751
|
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
685
752
|
try {
|
|
686
753
|
if (
|
|
@@ -756,51 +823,6 @@ function transactionSignature(putativeTransactionSignature) {
|
|
|
756
823
|
return putativeTransactionSignature;
|
|
757
824
|
}
|
|
758
825
|
|
|
759
|
-
// src/compile-transaction.ts
|
|
760
|
-
function getCompiledTransaction(transaction) {
|
|
761
|
-
const compiledMessage = compileMessage(transaction);
|
|
762
|
-
let signatures;
|
|
763
|
-
if ("signatures" in transaction) {
|
|
764
|
-
signatures = [];
|
|
765
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
766
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
767
|
-
}
|
|
768
|
-
} else {
|
|
769
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
770
|
-
}
|
|
771
|
-
return {
|
|
772
|
-
compiledMessage,
|
|
773
|
-
signatures
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
// src/serializers/transaction.ts
|
|
778
|
-
var BASE_CONFIG3 = {
|
|
779
|
-
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
780
|
-
fixedSize: null,
|
|
781
|
-
maxSize: null
|
|
782
|
-
};
|
|
783
|
-
function serialize3(transaction) {
|
|
784
|
-
const compiledTransaction = getCompiledTransaction(transaction);
|
|
785
|
-
return struct([
|
|
786
|
-
[
|
|
787
|
-
"signatures",
|
|
788
|
-
array(bytes({ size: 64 }), {
|
|
789
|
-
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
|
|
790
|
-
size: shortU16()
|
|
791
|
-
})
|
|
792
|
-
],
|
|
793
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
794
|
-
]).serialize(compiledTransaction);
|
|
795
|
-
}
|
|
796
|
-
function getTransactionEncoder() {
|
|
797
|
-
return {
|
|
798
|
-
...BASE_CONFIG3,
|
|
799
|
-
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
800
|
-
serialize: serialize3
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
|
|
804
826
|
// src/wire-transaction.ts
|
|
805
827
|
function getBase64EncodedWireTransaction(transaction) {
|
|
806
828
|
const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
|
|
@@ -809,6 +831,6 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
809
831
|
}
|
|
810
832
|
}
|
|
811
833
|
|
|
812
|
-
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|
|
834
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|
|
813
835
|
//# sourceMappingURL=out.js.map
|
|
814
836
|
//# sourceMappingURL=index.browser.js.map
|