@solana/transactions 2.0.0-experimental.f8b14a7 → 2.0.0-experimental.fc4e943
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 +186 -107
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +183 -109
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +650 -148
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +183 -109
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +188 -107
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +183 -109
- 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/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/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 +19 -14
- 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() {
|
|
@@ -524,7 +551,7 @@ function getInstructionCodec() {
|
|
|
524
551
|
)
|
|
525
552
|
],
|
|
526
553
|
[
|
|
527
|
-
"
|
|
554
|
+
"accountIndices",
|
|
528
555
|
umiSerializers.array(
|
|
529
556
|
umiSerializers.u8({
|
|
530
557
|
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
@@ -544,50 +571,35 @@ function getInstructionCodec() {
|
|
|
544
571
|
]
|
|
545
572
|
]),
|
|
546
573
|
(value) => {
|
|
547
|
-
if (value.
|
|
574
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
548
575
|
return value;
|
|
549
576
|
}
|
|
550
577
|
return {
|
|
551
578
|
...value,
|
|
552
|
-
|
|
579
|
+
accountIndices: value.accountIndices ?? [],
|
|
553
580
|
data: value.data ?? new Uint8Array(0)
|
|
554
581
|
};
|
|
555
582
|
},
|
|
556
583
|
(value) => {
|
|
557
|
-
if (value.
|
|
584
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
558
585
|
return value;
|
|
559
586
|
}
|
|
560
|
-
const {
|
|
587
|
+
const { accountIndices, data, ...rest } = value;
|
|
561
588
|
return {
|
|
562
589
|
...rest,
|
|
563
|
-
...
|
|
590
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
564
591
|
...data.byteLength ? { data } : null
|
|
565
592
|
};
|
|
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,49 +720,7 @@ function getCompiledMessageEncoder() {
|
|
|
678
720
|
return {
|
|
679
721
|
...BASE_CONFIG2,
|
|
680
722
|
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.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
|
|
723
|
+
serialize
|
|
724
724
|
};
|
|
725
725
|
}
|
|
726
726
|
|
|
@@ -730,7 +730,7 @@ var BASE_CONFIG3 = {
|
|
|
730
730
|
fixedSize: null,
|
|
731
731
|
maxSize: null
|
|
732
732
|
};
|
|
733
|
-
function
|
|
733
|
+
function serialize2(transaction) {
|
|
734
734
|
const compiledTransaction = getCompiledTransaction(transaction);
|
|
735
735
|
return umiSerializers.struct([
|
|
736
736
|
[
|
|
@@ -747,8 +747,82 @@ function getTransactionEncoder() {
|
|
|
747
747
|
return {
|
|
748
748
|
...BASE_CONFIG3,
|
|
749
749
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
750
|
-
serialize:
|
|
750
|
+
serialize: serialize2
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
754
|
+
try {
|
|
755
|
+
if (
|
|
756
|
+
// Lowest value (64 bytes of zeroes)
|
|
757
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
758
|
+
putativeTransactionSignature.length > 88
|
|
759
|
+
) {
|
|
760
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
761
|
+
}
|
|
762
|
+
const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
763
|
+
const numBytes = bytes3.byteLength;
|
|
764
|
+
if (numBytes !== 64) {
|
|
765
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
766
|
+
}
|
|
767
|
+
} catch (e) {
|
|
768
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
769
|
+
cause: e
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
774
|
+
if (
|
|
775
|
+
// Lowest value (64 bytes of zeroes)
|
|
776
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
777
|
+
putativeTransactionSignature.length > 88
|
|
778
|
+
) {
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
782
|
+
const numBytes = bytes3.byteLength;
|
|
783
|
+
if (numBytes !== 64) {
|
|
784
|
+
return false;
|
|
785
|
+
}
|
|
786
|
+
return true;
|
|
787
|
+
}
|
|
788
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
789
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
790
|
+
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
791
|
+
return signature;
|
|
792
|
+
}
|
|
793
|
+
function getSignatureFromTransaction(transaction) {
|
|
794
|
+
const signature = transaction.signatures[transaction.feePayer];
|
|
795
|
+
if (!signature) {
|
|
796
|
+
throw new Error(
|
|
797
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
return signature;
|
|
801
|
+
}
|
|
802
|
+
async function signTransaction(keyPairs, transaction) {
|
|
803
|
+
const compiledMessage = compileMessage(transaction);
|
|
804
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
805
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
806
|
+
keyPairs.map(
|
|
807
|
+
(keyPair) => Promise.all([
|
|
808
|
+
addresses.getAddressFromPublicKey(keyPair.publicKey),
|
|
809
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
810
|
+
])
|
|
811
|
+
)
|
|
812
|
+
);
|
|
813
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
814
|
+
nextSignatures[signerPublicKey] = signature;
|
|
815
|
+
}
|
|
816
|
+
const out = {
|
|
817
|
+
...transaction,
|
|
818
|
+
signatures: nextSignatures
|
|
751
819
|
};
|
|
820
|
+
Object.freeze(out);
|
|
821
|
+
return out;
|
|
822
|
+
}
|
|
823
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
824
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
825
|
+
return putativeTransactionSignature;
|
|
752
826
|
}
|
|
753
827
|
|
|
754
828
|
// src/wire-transaction.ts
|
|
@@ -762,12 +836,17 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
762
836
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
763
837
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
764
838
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
839
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
765
840
|
exports.createTransaction = createTransaction;
|
|
766
841
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
842
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
843
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
844
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
767
845
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
768
846
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
769
847
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
770
848
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
771
849
|
exports.signTransaction = signTransaction;
|
|
850
|
+
exports.transactionSignature = transactionSignature;
|
|
772
851
|
//# sourceMappingURL=out.js.map
|
|
773
852
|
//# sourceMappingURL=index.browser.cjs.map
|