@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/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 {
|
|
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() {
|
|
@@ -522,7 +549,7 @@ function getInstructionCodec() {
|
|
|
522
549
|
)
|
|
523
550
|
],
|
|
524
551
|
[
|
|
525
|
-
"
|
|
552
|
+
"accountIndices",
|
|
526
553
|
array(
|
|
527
554
|
u8({
|
|
528
555
|
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
@@ -542,50 +569,35 @@ function getInstructionCodec() {
|
|
|
542
569
|
]
|
|
543
570
|
]),
|
|
544
571
|
(value) => {
|
|
545
|
-
if (value.
|
|
572
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
546
573
|
return value;
|
|
547
574
|
}
|
|
548
575
|
return {
|
|
549
576
|
...value,
|
|
550
|
-
|
|
577
|
+
accountIndices: value.accountIndices ?? [],
|
|
551
578
|
data: value.data ?? new Uint8Array(0)
|
|
552
579
|
};
|
|
553
580
|
},
|
|
554
581
|
(value) => {
|
|
555
|
-
if (value.
|
|
582
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
556
583
|
return value;
|
|
557
584
|
}
|
|
558
|
-
const {
|
|
585
|
+
const { accountIndices, data, ...rest } = value;
|
|
559
586
|
return {
|
|
560
587
|
...rest,
|
|
561
|
-
...
|
|
588
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
562
589
|
...data.byteLength ? { data } : null
|
|
563
590
|
};
|
|
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,49 +718,7 @@ function getCompiledMessageEncoder() {
|
|
|
676
718
|
return {
|
|
677
719
|
...BASE_CONFIG2,
|
|
678
720
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
679
|
-
serialize
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
// src/signatures.ts
|
|
684
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
685
|
-
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
686
|
-
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
687
|
-
return signature;
|
|
688
|
-
}
|
|
689
|
-
async function signTransaction(keyPair, transaction) {
|
|
690
|
-
const compiledMessage = compileMessage(transaction);
|
|
691
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
692
|
-
getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
|
|
693
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
694
|
-
]);
|
|
695
|
-
const nextSignatures = {
|
|
696
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
697
|
-
...{ [signerPublicKey]: signature }
|
|
698
|
-
};
|
|
699
|
-
const out = {
|
|
700
|
-
...transaction,
|
|
701
|
-
signatures: nextSignatures
|
|
702
|
-
};
|
|
703
|
-
Object.freeze(out);
|
|
704
|
-
return out;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
// src/compile-transaction.ts
|
|
708
|
-
function getCompiledTransaction(transaction) {
|
|
709
|
-
const compiledMessage = compileMessage(transaction);
|
|
710
|
-
let signatures;
|
|
711
|
-
if ("signatures" in transaction) {
|
|
712
|
-
signatures = [];
|
|
713
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
714
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
715
|
-
}
|
|
716
|
-
} else {
|
|
717
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
718
|
-
}
|
|
719
|
-
return {
|
|
720
|
-
compiledMessage,
|
|
721
|
-
signatures
|
|
721
|
+
serialize
|
|
722
722
|
};
|
|
723
723
|
}
|
|
724
724
|
|
|
@@ -728,7 +728,7 @@ var BASE_CONFIG3 = {
|
|
|
728
728
|
fixedSize: null,
|
|
729
729
|
maxSize: null
|
|
730
730
|
};
|
|
731
|
-
function
|
|
731
|
+
function serialize2(transaction) {
|
|
732
732
|
const compiledTransaction = getCompiledTransaction(transaction);
|
|
733
733
|
return struct([
|
|
734
734
|
[
|
|
@@ -745,8 +745,82 @@ function getTransactionEncoder() {
|
|
|
745
745
|
return {
|
|
746
746
|
...BASE_CONFIG3,
|
|
747
747
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
748
|
-
serialize:
|
|
748
|
+
serialize: serialize2
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
752
|
+
try {
|
|
753
|
+
if (
|
|
754
|
+
// Lowest value (64 bytes of zeroes)
|
|
755
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
756
|
+
putativeTransactionSignature.length > 88
|
|
757
|
+
) {
|
|
758
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
759
|
+
}
|
|
760
|
+
const bytes3 = base58.serialize(putativeTransactionSignature);
|
|
761
|
+
const numBytes = bytes3.byteLength;
|
|
762
|
+
if (numBytes !== 64) {
|
|
763
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
764
|
+
}
|
|
765
|
+
} catch (e) {
|
|
766
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
767
|
+
cause: e
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
772
|
+
if (
|
|
773
|
+
// Lowest value (64 bytes of zeroes)
|
|
774
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
775
|
+
putativeTransactionSignature.length > 88
|
|
776
|
+
) {
|
|
777
|
+
return false;
|
|
778
|
+
}
|
|
779
|
+
const bytes3 = base58.serialize(putativeTransactionSignature);
|
|
780
|
+
const numBytes = bytes3.byteLength;
|
|
781
|
+
if (numBytes !== 64) {
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
787
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
788
|
+
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
789
|
+
return signature;
|
|
790
|
+
}
|
|
791
|
+
function getSignatureFromTransaction(transaction) {
|
|
792
|
+
const signature = transaction.signatures[transaction.feePayer];
|
|
793
|
+
if (!signature) {
|
|
794
|
+
throw new Error(
|
|
795
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
return signature;
|
|
799
|
+
}
|
|
800
|
+
async function signTransaction(keyPairs, transaction) {
|
|
801
|
+
const compiledMessage = compileMessage(transaction);
|
|
802
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
803
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
804
|
+
keyPairs.map(
|
|
805
|
+
(keyPair) => Promise.all([
|
|
806
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
807
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
808
|
+
])
|
|
809
|
+
)
|
|
810
|
+
);
|
|
811
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
812
|
+
nextSignatures[signerPublicKey] = signature;
|
|
813
|
+
}
|
|
814
|
+
const out = {
|
|
815
|
+
...transaction,
|
|
816
|
+
signatures: nextSignatures
|
|
749
817
|
};
|
|
818
|
+
Object.freeze(out);
|
|
819
|
+
return out;
|
|
820
|
+
}
|
|
821
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
822
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
823
|
+
return putativeTransactionSignature;
|
|
750
824
|
}
|
|
751
825
|
|
|
752
826
|
// src/wire-transaction.ts
|
|
@@ -757,6 +831,6 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
757
831
|
}
|
|
758
832
|
}
|
|
759
833
|
|
|
760
|
-
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
|
|
834
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|
|
761
835
|
//# sourceMappingURL=out.js.map
|
|
762
836
|
//# sourceMappingURL=index.browser.js.map
|