@solana/transactions 2.0.0-experimental.cf6ca9d → 2.0.0-experimental.d085c72
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/README.md +1 -43
- package/dist/index.browser.cjs +158 -188
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +156 -186
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +662 -720
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +156 -186
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +158 -186
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +158 -186
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +22 -20
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compile-address-table-lookups.d.ts +2 -2
- package/dist/types/compile-static-accounts.d.ts +2 -2
- package/dist/types/compile-transaction.d.ts +5 -6
- package/dist/types/decompile-transaction.d.ts +2 -4
- package/dist/types/durable-nonce.d.ts +3 -3
- package/dist/types/fee-payer.d.ts +4 -4
- package/dist/types/index.d.ts +2 -0
- package/dist/types/message.d.ts +1 -5
- package/dist/types/serializers/index.d.ts +1 -0
- package/dist/types/serializers/transaction.d.ts +1 -3
- package/dist/types/signatures.d.ts +8 -13
- package/dist/types/types.d.ts +6 -13
- package/package.json +12 -13
package/dist/index.node.cjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
4
|
+
var addresses = require('@solana/addresses');
|
|
4
5
|
var codecsCore = require('@solana/codecs-core');
|
|
5
6
|
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
6
7
|
var codecsNumbers = require('@solana/codecs-numbers');
|
|
7
|
-
var addresses = require('@solana/addresses');
|
|
8
8
|
var functional = require('@solana/functional');
|
|
9
|
-
var codecsStrings = require('@solana/codecs-strings');
|
|
10
9
|
var keys = require('@solana/keys');
|
|
11
10
|
|
|
12
11
|
// ../build-scripts/env-shim.ts
|
|
@@ -27,7 +26,10 @@ function getUnsignedTransaction(transaction) {
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
// src/blockhash.ts
|
|
29
|
+
var base58Encoder;
|
|
30
30
|
function assertIsBlockhash(putativeBlockhash) {
|
|
31
|
+
if (!base58Encoder)
|
|
32
|
+
base58Encoder = codecsStrings.getBase58Encoder();
|
|
31
33
|
try {
|
|
32
34
|
if (
|
|
33
35
|
// Lowest value (32 bytes of zeroes)
|
|
@@ -36,7 +38,7 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
36
38
|
) {
|
|
37
39
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
38
40
|
}
|
|
39
|
-
const bytes =
|
|
41
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
40
42
|
const numBytes = bytes.byteLength;
|
|
41
43
|
if (numBytes !== 32) {
|
|
42
44
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
@@ -252,7 +254,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
252
254
|
const shouldReplaceEntry = (
|
|
253
255
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
254
256
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
255
|
-
(addressComparator
|
|
257
|
+
(addressComparator ||= addresses.getAddressComparator())(
|
|
256
258
|
accountMeta.lookupTableAddress,
|
|
257
259
|
entry.lookupTableAddress
|
|
258
260
|
) < 0
|
|
@@ -358,7 +360,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
358
360
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
359
361
|
return leftIsWritable ? -1 : 1;
|
|
360
362
|
}
|
|
361
|
-
addressComparator
|
|
363
|
+
addressComparator ||= addresses.getAddressComparator();
|
|
362
364
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
363
365
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
364
366
|
} else {
|
|
@@ -371,16 +373,15 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
371
373
|
return orderedAccounts;
|
|
372
374
|
}
|
|
373
375
|
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
374
|
-
var _a;
|
|
375
376
|
const index = {};
|
|
376
377
|
for (const account of orderedAccounts) {
|
|
377
378
|
if (!("lookupTableAddress" in account)) {
|
|
378
379
|
continue;
|
|
379
380
|
}
|
|
380
|
-
const entry = index[
|
|
381
|
+
const entry = index[account.lookupTableAddress] ||= {
|
|
381
382
|
readableIndices: [],
|
|
382
383
|
writableIndices: []
|
|
383
|
-
}
|
|
384
|
+
};
|
|
384
385
|
if (account.role === AccountRole.WRITABLE) {
|
|
385
386
|
entry.writableIndices.push(account.addressIndex);
|
|
386
387
|
} else {
|
|
@@ -466,134 +467,6 @@ function compileMessage(transaction) {
|
|
|
466
467
|
version: transaction.version
|
|
467
468
|
};
|
|
468
469
|
}
|
|
469
|
-
|
|
470
|
-
// src/compile-transaction.ts
|
|
471
|
-
function getCompiledTransaction(transaction) {
|
|
472
|
-
const compiledMessage = compileMessage(transaction);
|
|
473
|
-
let signatures;
|
|
474
|
-
if ("signatures" in transaction) {
|
|
475
|
-
signatures = [];
|
|
476
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
477
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
478
|
-
}
|
|
479
|
-
} else {
|
|
480
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
481
|
-
}
|
|
482
|
-
return {
|
|
483
|
-
compiledMessage,
|
|
484
|
-
signatures
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
function getAccountMetas(message) {
|
|
488
|
-
const { header } = message;
|
|
489
|
-
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
490
|
-
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
491
|
-
const accountMetas = [];
|
|
492
|
-
let accountIndex = 0;
|
|
493
|
-
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
494
|
-
accountMetas.push({
|
|
495
|
-
address: message.staticAccounts[accountIndex],
|
|
496
|
-
role: AccountRole.WRITABLE_SIGNER
|
|
497
|
-
});
|
|
498
|
-
accountIndex++;
|
|
499
|
-
}
|
|
500
|
-
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
501
|
-
accountMetas.push({
|
|
502
|
-
address: message.staticAccounts[accountIndex],
|
|
503
|
-
role: AccountRole.READONLY_SIGNER
|
|
504
|
-
});
|
|
505
|
-
accountIndex++;
|
|
506
|
-
}
|
|
507
|
-
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
508
|
-
accountMetas.push({
|
|
509
|
-
address: message.staticAccounts[accountIndex],
|
|
510
|
-
role: AccountRole.WRITABLE
|
|
511
|
-
});
|
|
512
|
-
accountIndex++;
|
|
513
|
-
}
|
|
514
|
-
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
515
|
-
accountMetas.push({
|
|
516
|
-
address: message.staticAccounts[accountIndex],
|
|
517
|
-
role: AccountRole.READONLY
|
|
518
|
-
});
|
|
519
|
-
accountIndex++;
|
|
520
|
-
}
|
|
521
|
-
return accountMetas;
|
|
522
|
-
}
|
|
523
|
-
function convertInstruction(instruction, accountMetas) {
|
|
524
|
-
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
525
|
-
if (!programAddress) {
|
|
526
|
-
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
527
|
-
}
|
|
528
|
-
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
529
|
-
const { data } = instruction;
|
|
530
|
-
return {
|
|
531
|
-
programAddress,
|
|
532
|
-
...accounts && accounts.length ? { accounts } : {},
|
|
533
|
-
...data && data.length ? { data } : {}
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
537
|
-
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
538
|
-
return {
|
|
539
|
-
blockhash: messageLifetimeToken,
|
|
540
|
-
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
541
|
-
// U64 MAX
|
|
542
|
-
};
|
|
543
|
-
} else {
|
|
544
|
-
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
545
|
-
addresses.assertIsAddress(nonceAccountAddress);
|
|
546
|
-
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
547
|
-
addresses.assertIsAddress(nonceAuthorityAddress);
|
|
548
|
-
return {
|
|
549
|
-
nonce: messageLifetimeToken,
|
|
550
|
-
nonceAccountAddress,
|
|
551
|
-
nonceAuthorityAddress
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
function convertSignatures(compiledTransaction) {
|
|
556
|
-
const {
|
|
557
|
-
compiledMessage: { staticAccounts },
|
|
558
|
-
signatures
|
|
559
|
-
} = compiledTransaction;
|
|
560
|
-
return signatures.reduce((acc, sig, index) => {
|
|
561
|
-
const allZeros = sig.every((byte) => byte === 0);
|
|
562
|
-
if (allZeros)
|
|
563
|
-
return acc;
|
|
564
|
-
const address = staticAccounts[index];
|
|
565
|
-
return { ...acc, [address]: sig };
|
|
566
|
-
}, {});
|
|
567
|
-
}
|
|
568
|
-
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
569
|
-
const { compiledMessage } = compiledTransaction;
|
|
570
|
-
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
571
|
-
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
572
|
-
}
|
|
573
|
-
const feePayer = compiledMessage.staticAccounts[0];
|
|
574
|
-
if (!feePayer)
|
|
575
|
-
throw new Error("No fee payer set in CompiledTransaction");
|
|
576
|
-
const accountMetas = getAccountMetas(compiledMessage);
|
|
577
|
-
const instructions = compiledMessage.instructions.map(
|
|
578
|
-
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
579
|
-
);
|
|
580
|
-
const firstInstruction = instructions[0];
|
|
581
|
-
const lifetimeConstraint = getLifetimeConstraint(
|
|
582
|
-
compiledMessage.lifetimeToken,
|
|
583
|
-
firstInstruction,
|
|
584
|
-
lastValidBlockHeight
|
|
585
|
-
);
|
|
586
|
-
const signatures = convertSignatures(compiledTransaction);
|
|
587
|
-
return functional.pipe(
|
|
588
|
-
createTransaction({ version: compiledMessage.version }),
|
|
589
|
-
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
590
|
-
(tx) => instructions.reduce((acc, instruction) => {
|
|
591
|
-
return appendTransactionInstruction(instruction, acc);
|
|
592
|
-
}, tx),
|
|
593
|
-
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
594
|
-
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
595
|
-
);
|
|
596
|
-
}
|
|
597
470
|
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
598
471
|
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
599
472
|
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
@@ -928,6 +801,137 @@ function getCompiledMessageDecoder() {
|
|
|
928
801
|
}
|
|
929
802
|
);
|
|
930
803
|
}
|
|
804
|
+
function getCompiledMessageCodec() {
|
|
805
|
+
return codecsCore.combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// src/compile-transaction.ts
|
|
809
|
+
function getCompiledTransaction(transaction) {
|
|
810
|
+
const compiledMessage = compileMessage(transaction);
|
|
811
|
+
let signatures;
|
|
812
|
+
if ("signatures" in transaction) {
|
|
813
|
+
signatures = [];
|
|
814
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
815
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
816
|
+
}
|
|
817
|
+
} else {
|
|
818
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
819
|
+
}
|
|
820
|
+
return {
|
|
821
|
+
compiledMessage,
|
|
822
|
+
signatures
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
function getAccountMetas(message) {
|
|
826
|
+
const { header } = message;
|
|
827
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
828
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
829
|
+
const accountMetas = [];
|
|
830
|
+
let accountIndex = 0;
|
|
831
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
832
|
+
accountMetas.push({
|
|
833
|
+
address: message.staticAccounts[accountIndex],
|
|
834
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
835
|
+
});
|
|
836
|
+
accountIndex++;
|
|
837
|
+
}
|
|
838
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
839
|
+
accountMetas.push({
|
|
840
|
+
address: message.staticAccounts[accountIndex],
|
|
841
|
+
role: AccountRole.READONLY_SIGNER
|
|
842
|
+
});
|
|
843
|
+
accountIndex++;
|
|
844
|
+
}
|
|
845
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
846
|
+
accountMetas.push({
|
|
847
|
+
address: message.staticAccounts[accountIndex],
|
|
848
|
+
role: AccountRole.WRITABLE
|
|
849
|
+
});
|
|
850
|
+
accountIndex++;
|
|
851
|
+
}
|
|
852
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
853
|
+
accountMetas.push({
|
|
854
|
+
address: message.staticAccounts[accountIndex],
|
|
855
|
+
role: AccountRole.READONLY
|
|
856
|
+
});
|
|
857
|
+
accountIndex++;
|
|
858
|
+
}
|
|
859
|
+
return accountMetas;
|
|
860
|
+
}
|
|
861
|
+
function convertInstruction(instruction, accountMetas) {
|
|
862
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
863
|
+
if (!programAddress) {
|
|
864
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
865
|
+
}
|
|
866
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
867
|
+
const { data } = instruction;
|
|
868
|
+
return {
|
|
869
|
+
programAddress,
|
|
870
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
871
|
+
...data && data.length ? { data } : {}
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
875
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
876
|
+
return {
|
|
877
|
+
blockhash: messageLifetimeToken,
|
|
878
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
879
|
+
// U64 MAX
|
|
880
|
+
};
|
|
881
|
+
} else {
|
|
882
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
883
|
+
addresses.assertIsAddress(nonceAccountAddress);
|
|
884
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
885
|
+
addresses.assertIsAddress(nonceAuthorityAddress);
|
|
886
|
+
return {
|
|
887
|
+
nonce: messageLifetimeToken,
|
|
888
|
+
nonceAccountAddress,
|
|
889
|
+
nonceAuthorityAddress
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
function convertSignatures(compiledTransaction) {
|
|
894
|
+
const {
|
|
895
|
+
compiledMessage: { staticAccounts },
|
|
896
|
+
signatures
|
|
897
|
+
} = compiledTransaction;
|
|
898
|
+
return signatures.reduce((acc, sig, index) => {
|
|
899
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
900
|
+
if (allZeros)
|
|
901
|
+
return acc;
|
|
902
|
+
const address = staticAccounts[index];
|
|
903
|
+
return { ...acc, [address]: sig };
|
|
904
|
+
}, {});
|
|
905
|
+
}
|
|
906
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
907
|
+
const { compiledMessage } = compiledTransaction;
|
|
908
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
909
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
910
|
+
}
|
|
911
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
912
|
+
if (!feePayer)
|
|
913
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
914
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
915
|
+
const instructions = compiledMessage.instructions.map(
|
|
916
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
917
|
+
);
|
|
918
|
+
const firstInstruction = instructions[0];
|
|
919
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
920
|
+
compiledMessage.lifetimeToken,
|
|
921
|
+
firstInstruction,
|
|
922
|
+
lastValidBlockHeight
|
|
923
|
+
);
|
|
924
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
925
|
+
return functional.pipe(
|
|
926
|
+
createTransaction({ version: compiledMessage.version }),
|
|
927
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
928
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
929
|
+
return appendTransactionInstruction(instruction, acc);
|
|
930
|
+
}, tx),
|
|
931
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
932
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
933
|
+
);
|
|
934
|
+
}
|
|
931
935
|
|
|
932
936
|
// src/serializers/transaction.ts
|
|
933
937
|
var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
|
|
@@ -981,52 +985,20 @@ function getTransactionDecoder(lastValidBlockHeight) {
|
|
|
981
985
|
function getTransactionCodec(lastValidBlockHeight) {
|
|
982
986
|
return codecsCore.combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
983
987
|
}
|
|
984
|
-
|
|
985
|
-
try {
|
|
986
|
-
if (
|
|
987
|
-
// Lowest value (64 bytes of zeroes)
|
|
988
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
989
|
-
putativeTransactionSignature.length > 88
|
|
990
|
-
) {
|
|
991
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
992
|
-
}
|
|
993
|
-
const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
994
|
-
const numBytes = bytes.byteLength;
|
|
995
|
-
if (numBytes !== 64) {
|
|
996
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
997
|
-
}
|
|
998
|
-
} catch (e) {
|
|
999
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1000
|
-
cause: e
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1005
|
-
if (
|
|
1006
|
-
// Lowest value (64 bytes of zeroes)
|
|
1007
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1008
|
-
putativeTransactionSignature.length > 88
|
|
1009
|
-
) {
|
|
1010
|
-
return false;
|
|
1011
|
-
}
|
|
1012
|
-
const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
1013
|
-
const numBytes = bytes.byteLength;
|
|
1014
|
-
if (numBytes !== 64) {
|
|
1015
|
-
return false;
|
|
1016
|
-
}
|
|
1017
|
-
return true;
|
|
1018
|
-
}
|
|
988
|
+
var base58Decoder;
|
|
1019
989
|
function getSignatureFromTransaction(transaction) {
|
|
990
|
+
if (!base58Decoder)
|
|
991
|
+
base58Decoder = codecsStrings.getBase58Decoder();
|
|
1020
992
|
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1021
993
|
if (!signatureBytes) {
|
|
1022
994
|
throw new Error(
|
|
1023
995
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1024
996
|
);
|
|
1025
997
|
}
|
|
1026
|
-
const
|
|
1027
|
-
return
|
|
998
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
999
|
+
return transactionSignature;
|
|
1028
1000
|
}
|
|
1029
|
-
async function
|
|
1001
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1030
1002
|
const compiledMessage = compileMessage(transaction);
|
|
1031
1003
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1032
1004
|
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
@@ -1045,9 +1017,11 @@ async function signTransaction(keyPairs, transaction) {
|
|
|
1045
1017
|
Object.freeze(out);
|
|
1046
1018
|
return out;
|
|
1047
1019
|
}
|
|
1048
|
-
function
|
|
1049
|
-
|
|
1050
|
-
|
|
1020
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1021
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1022
|
+
assertTransactionIsFullySigned(out);
|
|
1023
|
+
Object.freeze(out);
|
|
1024
|
+
return out;
|
|
1051
1025
|
}
|
|
1052
1026
|
function assertTransactionIsFullySigned(transaction) {
|
|
1053
1027
|
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
@@ -1058,33 +1032,31 @@ function assertTransactionIsFullySigned(transaction) {
|
|
|
1058
1032
|
}
|
|
1059
1033
|
});
|
|
1060
1034
|
}
|
|
1061
|
-
|
|
1062
|
-
// src/wire-transaction.ts
|
|
1063
1035
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1064
1036
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1065
|
-
|
|
1066
|
-
return Buffer.from(wireTransactionBytes).toString("base64");
|
|
1067
|
-
}
|
|
1037
|
+
return codecsStrings.getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
1068
1038
|
}
|
|
1069
1039
|
|
|
1070
1040
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1071
1041
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1072
1042
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1073
|
-
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
1074
1043
|
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
1044
|
+
exports.compileMessage = compileMessage;
|
|
1075
1045
|
exports.createTransaction = createTransaction;
|
|
1076
1046
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1047
|
+
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
1048
|
+
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
1049
|
+
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
1077
1050
|
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1078
1051
|
exports.getTransactionCodec = getTransactionCodec;
|
|
1079
1052
|
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1080
1053
|
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1081
1054
|
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1082
|
-
exports.
|
|
1055
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
1083
1056
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
1084
1057
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1085
1058
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1086
1059
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1087
1060
|
exports.signTransaction = signTransaction;
|
|
1088
|
-
exports.transactionSignature = transactionSignature;
|
|
1089
1061
|
//# sourceMappingURL=out.js.map
|
|
1090
1062
|
//# sourceMappingURL=index.node.cjs.map
|