@solana/transactions 2.0.0-experimental.8245fa6 → 2.0.0-experimental.85b7dfe
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 +167 -190
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +165 -189
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +445 -423
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +165 -189
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +167 -188
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +165 -189
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +23 -20
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +1 -0
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compilable-transaction.d.ts +3 -2
- package/dist/types/compilable-transaction.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
- package/dist/types/compile-header.d.ts.map +1 -0
- package/dist/types/compile-instructions.d.ts.map +1 -0
- package/dist/types/compile-lifetime-token.d.ts.map +1 -0
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts +2 -2
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/decompile-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instructions.d.ts.map +1 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts +1 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +5 -10
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts +6 -13
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +13 -13
package/dist/index.browser.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getBase58Encoder, getBase58Decoder, getStringEncoder, getStringDecoder } from '@solana/codecs-strings';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { getBase58Encoder, getBase58Decoder, getBase64Decoder, getStringEncoder, getStringDecoder } from '@solana/codecs-strings';
|
|
2
|
+
import { getAddressFromPublicKey, getAddressComparator, getAddressEncoder, getAddressDecoder, assertIsAddress } from '@solana/addresses';
|
|
3
|
+
import { mapDecoder, combineCodec, mapEncoder } from '@solana/codecs-core';
|
|
4
|
+
import { getStructDecoder, getStructEncoder, getArrayEncoder, getArrayDecoder, getBytesEncoder, getBytesDecoder } from '@solana/codecs-data-structures';
|
|
4
5
|
import { getShortU16Encoder, getShortU16Decoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';
|
|
5
|
-
import { getAddressFromPublicKey, getAddressComparator, assertIsAddress, getAddressEncoder, getAddressDecoder } from '@solana/addresses';
|
|
6
6
|
import { pipe } from '@solana/functional';
|
|
7
7
|
import { signBytes } from '@solana/keys';
|
|
8
8
|
|
|
@@ -47,6 +47,22 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
function isTransactionWithBlockhashLifetime(transaction) {
|
|
51
|
+
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
|
|
52
|
+
if (!lifetimeConstraintShapeMatches)
|
|
53
|
+
return false;
|
|
54
|
+
try {
|
|
55
|
+
assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
|
|
56
|
+
return true;
|
|
57
|
+
} catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function assertIsTransactionWithBlockhashLifetime(transaction) {
|
|
62
|
+
if (!isTransactionWithBlockhashLifetime(transaction)) {
|
|
63
|
+
throw new Error("Transaction does not have a blockhash lifetime");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
50
66
|
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
51
67
|
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
52
68
|
return transaction;
|
|
@@ -252,7 +268,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
252
268
|
const shouldReplaceEntry = (
|
|
253
269
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
254
270
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
255
|
-
(addressComparator
|
|
271
|
+
(addressComparator ||= getAddressComparator())(
|
|
256
272
|
accountMeta.lookupTableAddress,
|
|
257
273
|
entry.lookupTableAddress
|
|
258
274
|
) < 0
|
|
@@ -358,7 +374,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
358
374
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
359
375
|
return leftIsWritable ? -1 : 1;
|
|
360
376
|
}
|
|
361
|
-
addressComparator
|
|
377
|
+
addressComparator ||= getAddressComparator();
|
|
362
378
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
363
379
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
364
380
|
} else {
|
|
@@ -371,16 +387,15 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
371
387
|
return orderedAccounts;
|
|
372
388
|
}
|
|
373
389
|
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
374
|
-
var _a;
|
|
375
390
|
const index = {};
|
|
376
391
|
for (const account of orderedAccounts) {
|
|
377
392
|
if (!("lookupTableAddress" in account)) {
|
|
378
393
|
continue;
|
|
379
394
|
}
|
|
380
|
-
const entry = index[
|
|
395
|
+
const entry = index[account.lookupTableAddress] ||= {
|
|
381
396
|
readableIndices: [],
|
|
382
397
|
writableIndices: []
|
|
383
|
-
}
|
|
398
|
+
};
|
|
384
399
|
if (account.role === AccountRole.WRITABLE) {
|
|
385
400
|
entry.writableIndices.push(account.addressIndex);
|
|
386
401
|
} else {
|
|
@@ -466,134 +481,6 @@ function compileMessage(transaction) {
|
|
|
466
481
|
version: transaction.version
|
|
467
482
|
};
|
|
468
483
|
}
|
|
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
|
-
assertIsAddress(nonceAccountAddress);
|
|
546
|
-
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
547
|
-
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 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
484
|
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
598
485
|
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
599
486
|
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
@@ -928,6 +815,137 @@ function getCompiledMessageDecoder() {
|
|
|
928
815
|
}
|
|
929
816
|
);
|
|
930
817
|
}
|
|
818
|
+
function getCompiledMessageCodec() {
|
|
819
|
+
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// src/compile-transaction.ts
|
|
823
|
+
function getCompiledTransaction(transaction) {
|
|
824
|
+
const compiledMessage = compileMessage(transaction);
|
|
825
|
+
let signatures;
|
|
826
|
+
if ("signatures" in transaction) {
|
|
827
|
+
signatures = [];
|
|
828
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
829
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
830
|
+
}
|
|
831
|
+
} else {
|
|
832
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
833
|
+
}
|
|
834
|
+
return {
|
|
835
|
+
compiledMessage,
|
|
836
|
+
signatures
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
function getAccountMetas(message) {
|
|
840
|
+
const { header } = message;
|
|
841
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
842
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
843
|
+
const accountMetas = [];
|
|
844
|
+
let accountIndex = 0;
|
|
845
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
846
|
+
accountMetas.push({
|
|
847
|
+
address: message.staticAccounts[accountIndex],
|
|
848
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
849
|
+
});
|
|
850
|
+
accountIndex++;
|
|
851
|
+
}
|
|
852
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
853
|
+
accountMetas.push({
|
|
854
|
+
address: message.staticAccounts[accountIndex],
|
|
855
|
+
role: AccountRole.READONLY_SIGNER
|
|
856
|
+
});
|
|
857
|
+
accountIndex++;
|
|
858
|
+
}
|
|
859
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
860
|
+
accountMetas.push({
|
|
861
|
+
address: message.staticAccounts[accountIndex],
|
|
862
|
+
role: AccountRole.WRITABLE
|
|
863
|
+
});
|
|
864
|
+
accountIndex++;
|
|
865
|
+
}
|
|
866
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
867
|
+
accountMetas.push({
|
|
868
|
+
address: message.staticAccounts[accountIndex],
|
|
869
|
+
role: AccountRole.READONLY
|
|
870
|
+
});
|
|
871
|
+
accountIndex++;
|
|
872
|
+
}
|
|
873
|
+
return accountMetas;
|
|
874
|
+
}
|
|
875
|
+
function convertInstruction(instruction, accountMetas) {
|
|
876
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
877
|
+
if (!programAddress) {
|
|
878
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
879
|
+
}
|
|
880
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
881
|
+
const { data } = instruction;
|
|
882
|
+
return {
|
|
883
|
+
programAddress,
|
|
884
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
885
|
+
...data && data.length ? { data } : {}
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
889
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
890
|
+
return {
|
|
891
|
+
blockhash: messageLifetimeToken,
|
|
892
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
893
|
+
// U64 MAX
|
|
894
|
+
};
|
|
895
|
+
} else {
|
|
896
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
897
|
+
assertIsAddress(nonceAccountAddress);
|
|
898
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
899
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
900
|
+
return {
|
|
901
|
+
nonce: messageLifetimeToken,
|
|
902
|
+
nonceAccountAddress,
|
|
903
|
+
nonceAuthorityAddress
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
function convertSignatures(compiledTransaction) {
|
|
908
|
+
const {
|
|
909
|
+
compiledMessage: { staticAccounts },
|
|
910
|
+
signatures
|
|
911
|
+
} = compiledTransaction;
|
|
912
|
+
return signatures.reduce((acc, sig, index) => {
|
|
913
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
914
|
+
if (allZeros)
|
|
915
|
+
return acc;
|
|
916
|
+
const address = staticAccounts[index];
|
|
917
|
+
return { ...acc, [address]: sig };
|
|
918
|
+
}, {});
|
|
919
|
+
}
|
|
920
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
921
|
+
const { compiledMessage } = compiledTransaction;
|
|
922
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
923
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
924
|
+
}
|
|
925
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
926
|
+
if (!feePayer)
|
|
927
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
928
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
929
|
+
const instructions = compiledMessage.instructions.map(
|
|
930
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
931
|
+
);
|
|
932
|
+
const firstInstruction = instructions[0];
|
|
933
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
934
|
+
compiledMessage.lifetimeToken,
|
|
935
|
+
firstInstruction,
|
|
936
|
+
lastValidBlockHeight
|
|
937
|
+
);
|
|
938
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
939
|
+
return pipe(
|
|
940
|
+
createTransaction({ version: compiledMessage.version }),
|
|
941
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
942
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
943
|
+
return appendTransactionInstruction(instruction, acc);
|
|
944
|
+
}, tx),
|
|
945
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
946
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
947
|
+
);
|
|
948
|
+
}
|
|
931
949
|
|
|
932
950
|
// src/serializers/transaction.ts
|
|
933
951
|
var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
|
|
@@ -981,47 +999,7 @@ function getTransactionDecoder(lastValidBlockHeight) {
|
|
|
981
999
|
function getTransactionCodec(lastValidBlockHeight) {
|
|
982
1000
|
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
983
1001
|
}
|
|
984
|
-
var base58Encoder2;
|
|
985
1002
|
var base58Decoder;
|
|
986
|
-
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
987
|
-
if (!base58Encoder2)
|
|
988
|
-
base58Encoder2 = getBase58Encoder();
|
|
989
|
-
try {
|
|
990
|
-
if (
|
|
991
|
-
// Lowest value (64 bytes of zeroes)
|
|
992
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
993
|
-
putativeTransactionSignature.length > 88
|
|
994
|
-
) {
|
|
995
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
996
|
-
}
|
|
997
|
-
const bytes = base58Encoder2.encode(putativeTransactionSignature);
|
|
998
|
-
const numBytes = bytes.byteLength;
|
|
999
|
-
if (numBytes !== 64) {
|
|
1000
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1001
|
-
}
|
|
1002
|
-
} catch (e) {
|
|
1003
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1004
|
-
cause: e
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1009
|
-
if (!base58Encoder2)
|
|
1010
|
-
base58Encoder2 = getBase58Encoder();
|
|
1011
|
-
if (
|
|
1012
|
-
// Lowest value (64 bytes of zeroes)
|
|
1013
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1014
|
-
putativeTransactionSignature.length > 88
|
|
1015
|
-
) {
|
|
1016
|
-
return false;
|
|
1017
|
-
}
|
|
1018
|
-
const bytes = base58Encoder2.encode(putativeTransactionSignature);
|
|
1019
|
-
const numBytes = bytes.byteLength;
|
|
1020
|
-
if (numBytes !== 64) {
|
|
1021
|
-
return false;
|
|
1022
|
-
}
|
|
1023
|
-
return true;
|
|
1024
|
-
}
|
|
1025
1003
|
function getSignatureFromTransaction(transaction) {
|
|
1026
1004
|
if (!base58Decoder)
|
|
1027
1005
|
base58Decoder = getBase58Decoder();
|
|
@@ -1031,10 +1009,10 @@ function getSignatureFromTransaction(transaction) {
|
|
|
1031
1009
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1032
1010
|
);
|
|
1033
1011
|
}
|
|
1034
|
-
const
|
|
1035
|
-
return
|
|
1012
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
1013
|
+
return transactionSignature;
|
|
1036
1014
|
}
|
|
1037
|
-
async function
|
|
1015
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1038
1016
|
const compiledMessage = compileMessage(transaction);
|
|
1039
1017
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1040
1018
|
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
@@ -1053,9 +1031,11 @@ async function signTransaction(keyPairs, transaction) {
|
|
|
1053
1031
|
Object.freeze(out);
|
|
1054
1032
|
return out;
|
|
1055
1033
|
}
|
|
1056
|
-
function
|
|
1057
|
-
|
|
1058
|
-
|
|
1034
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1035
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1036
|
+
assertTransactionIsFullySigned(out);
|
|
1037
|
+
Object.freeze(out);
|
|
1038
|
+
return out;
|
|
1059
1039
|
}
|
|
1060
1040
|
function assertTransactionIsFullySigned(transaction) {
|
|
1061
1041
|
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
@@ -1066,15 +1046,11 @@ function assertTransactionIsFullySigned(transaction) {
|
|
|
1066
1046
|
}
|
|
1067
1047
|
});
|
|
1068
1048
|
}
|
|
1069
|
-
|
|
1070
|
-
// src/wire-transaction.ts
|
|
1071
1049
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1072
1050
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1073
|
-
|
|
1074
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1075
|
-
}
|
|
1051
|
+
return getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
1076
1052
|
}
|
|
1077
1053
|
|
|
1078
|
-
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction,
|
|
1054
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionWithBlockhashLifetime, assertTransactionIsFullySigned, compileMessage, createTransaction, getBase64EncodedWireTransaction, getCompiledMessageCodec, getCompiledMessageDecoder, getCompiledMessageEncoder, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, partiallySignTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
|
|
1079
1055
|
//# sourceMappingURL=out.js.map
|
|
1080
1056
|
//# sourceMappingURL=index.browser.js.map
|