@solana/transactions 2.0.0-experimental.d32897d → 2.0.0-experimental.d3af599
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 +152 -188
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +149 -189
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +436 -431
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +149 -189
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +152 -188
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +149 -189
- 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/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compilable-transaction.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts +2 -2
- 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 +2 -2
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts +5 -6
- 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 +2 -4
- package/dist/types/decompile-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +3 -3
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +4 -4
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -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 +1 -5
- 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 +1 -3
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +8 -13
- 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 +11 -11
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
|
|
|
@@ -252,7 +252,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
252
252
|
const shouldReplaceEntry = (
|
|
253
253
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
254
254
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
255
|
-
(addressComparator
|
|
255
|
+
(addressComparator ||= getAddressComparator())(
|
|
256
256
|
accountMeta.lookupTableAddress,
|
|
257
257
|
entry.lookupTableAddress
|
|
258
258
|
) < 0
|
|
@@ -358,7 +358,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
358
358
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
359
359
|
return leftIsWritable ? -1 : 1;
|
|
360
360
|
}
|
|
361
|
-
addressComparator
|
|
361
|
+
addressComparator ||= getAddressComparator();
|
|
362
362
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
363
363
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
364
364
|
} else {
|
|
@@ -371,16 +371,15 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
371
371
|
return orderedAccounts;
|
|
372
372
|
}
|
|
373
373
|
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
374
|
-
var _a;
|
|
375
374
|
const index = {};
|
|
376
375
|
for (const account of orderedAccounts) {
|
|
377
376
|
if (!("lookupTableAddress" in account)) {
|
|
378
377
|
continue;
|
|
379
378
|
}
|
|
380
|
-
const entry = index[
|
|
379
|
+
const entry = index[account.lookupTableAddress] ||= {
|
|
381
380
|
readableIndices: [],
|
|
382
381
|
writableIndices: []
|
|
383
|
-
}
|
|
382
|
+
};
|
|
384
383
|
if (account.role === AccountRole.WRITABLE) {
|
|
385
384
|
entry.writableIndices.push(account.addressIndex);
|
|
386
385
|
} else {
|
|
@@ -466,134 +465,6 @@ function compileMessage(transaction) {
|
|
|
466
465
|
version: transaction.version
|
|
467
466
|
};
|
|
468
467
|
}
|
|
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
468
|
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
598
469
|
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
599
470
|
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
@@ -928,6 +799,137 @@ function getCompiledMessageDecoder() {
|
|
|
928
799
|
}
|
|
929
800
|
);
|
|
930
801
|
}
|
|
802
|
+
function getCompiledMessageCodec() {
|
|
803
|
+
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// src/compile-transaction.ts
|
|
807
|
+
function getCompiledTransaction(transaction) {
|
|
808
|
+
const compiledMessage = compileMessage(transaction);
|
|
809
|
+
let signatures;
|
|
810
|
+
if ("signatures" in transaction) {
|
|
811
|
+
signatures = [];
|
|
812
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
813
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
814
|
+
}
|
|
815
|
+
} else {
|
|
816
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
817
|
+
}
|
|
818
|
+
return {
|
|
819
|
+
compiledMessage,
|
|
820
|
+
signatures
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
function getAccountMetas(message) {
|
|
824
|
+
const { header } = message;
|
|
825
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
826
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
827
|
+
const accountMetas = [];
|
|
828
|
+
let accountIndex = 0;
|
|
829
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
830
|
+
accountMetas.push({
|
|
831
|
+
address: message.staticAccounts[accountIndex],
|
|
832
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
833
|
+
});
|
|
834
|
+
accountIndex++;
|
|
835
|
+
}
|
|
836
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
837
|
+
accountMetas.push({
|
|
838
|
+
address: message.staticAccounts[accountIndex],
|
|
839
|
+
role: AccountRole.READONLY_SIGNER
|
|
840
|
+
});
|
|
841
|
+
accountIndex++;
|
|
842
|
+
}
|
|
843
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
844
|
+
accountMetas.push({
|
|
845
|
+
address: message.staticAccounts[accountIndex],
|
|
846
|
+
role: AccountRole.WRITABLE
|
|
847
|
+
});
|
|
848
|
+
accountIndex++;
|
|
849
|
+
}
|
|
850
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
851
|
+
accountMetas.push({
|
|
852
|
+
address: message.staticAccounts[accountIndex],
|
|
853
|
+
role: AccountRole.READONLY
|
|
854
|
+
});
|
|
855
|
+
accountIndex++;
|
|
856
|
+
}
|
|
857
|
+
return accountMetas;
|
|
858
|
+
}
|
|
859
|
+
function convertInstruction(instruction, accountMetas) {
|
|
860
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
861
|
+
if (!programAddress) {
|
|
862
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
863
|
+
}
|
|
864
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
865
|
+
const { data } = instruction;
|
|
866
|
+
return {
|
|
867
|
+
programAddress,
|
|
868
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
869
|
+
...data && data.length ? { data } : {}
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
873
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
874
|
+
return {
|
|
875
|
+
blockhash: messageLifetimeToken,
|
|
876
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
877
|
+
// U64 MAX
|
|
878
|
+
};
|
|
879
|
+
} else {
|
|
880
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
881
|
+
assertIsAddress(nonceAccountAddress);
|
|
882
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
883
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
884
|
+
return {
|
|
885
|
+
nonce: messageLifetimeToken,
|
|
886
|
+
nonceAccountAddress,
|
|
887
|
+
nonceAuthorityAddress
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
function convertSignatures(compiledTransaction) {
|
|
892
|
+
const {
|
|
893
|
+
compiledMessage: { staticAccounts },
|
|
894
|
+
signatures
|
|
895
|
+
} = compiledTransaction;
|
|
896
|
+
return signatures.reduce((acc, sig, index) => {
|
|
897
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
898
|
+
if (allZeros)
|
|
899
|
+
return acc;
|
|
900
|
+
const address = staticAccounts[index];
|
|
901
|
+
return { ...acc, [address]: sig };
|
|
902
|
+
}, {});
|
|
903
|
+
}
|
|
904
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
905
|
+
const { compiledMessage } = compiledTransaction;
|
|
906
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
907
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
908
|
+
}
|
|
909
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
910
|
+
if (!feePayer)
|
|
911
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
912
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
913
|
+
const instructions = compiledMessage.instructions.map(
|
|
914
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
915
|
+
);
|
|
916
|
+
const firstInstruction = instructions[0];
|
|
917
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
918
|
+
compiledMessage.lifetimeToken,
|
|
919
|
+
firstInstruction,
|
|
920
|
+
lastValidBlockHeight
|
|
921
|
+
);
|
|
922
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
923
|
+
return pipe(
|
|
924
|
+
createTransaction({ version: compiledMessage.version }),
|
|
925
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
926
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
927
|
+
return appendTransactionInstruction(instruction, acc);
|
|
928
|
+
}, tx),
|
|
929
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
930
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
931
|
+
);
|
|
932
|
+
}
|
|
931
933
|
|
|
932
934
|
// src/serializers/transaction.ts
|
|
933
935
|
var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
|
|
@@ -981,47 +983,7 @@ function getTransactionDecoder(lastValidBlockHeight) {
|
|
|
981
983
|
function getTransactionCodec(lastValidBlockHeight) {
|
|
982
984
|
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
983
985
|
}
|
|
984
|
-
var base58Encoder2;
|
|
985
986
|
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
987
|
function getSignatureFromTransaction(transaction) {
|
|
1026
988
|
if (!base58Decoder)
|
|
1027
989
|
base58Decoder = getBase58Decoder();
|
|
@@ -1031,10 +993,10 @@ function getSignatureFromTransaction(transaction) {
|
|
|
1031
993
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1032
994
|
);
|
|
1033
995
|
}
|
|
1034
|
-
const
|
|
1035
|
-
return
|
|
996
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
997
|
+
return transactionSignature;
|
|
1036
998
|
}
|
|
1037
|
-
async function
|
|
999
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1038
1000
|
const compiledMessage = compileMessage(transaction);
|
|
1039
1001
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1040
1002
|
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
@@ -1053,9 +1015,11 @@ async function signTransaction(keyPairs, transaction) {
|
|
|
1053
1015
|
Object.freeze(out);
|
|
1054
1016
|
return out;
|
|
1055
1017
|
}
|
|
1056
|
-
function
|
|
1057
|
-
|
|
1058
|
-
|
|
1018
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1019
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1020
|
+
assertTransactionIsFullySigned(out);
|
|
1021
|
+
Object.freeze(out);
|
|
1022
|
+
return out;
|
|
1059
1023
|
}
|
|
1060
1024
|
function assertTransactionIsFullySigned(transaction) {
|
|
1061
1025
|
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
@@ -1066,15 +1030,11 @@ function assertTransactionIsFullySigned(transaction) {
|
|
|
1066
1030
|
}
|
|
1067
1031
|
});
|
|
1068
1032
|
}
|
|
1069
|
-
|
|
1070
|
-
// src/wire-transaction.ts
|
|
1071
1033
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1072
1034
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1073
|
-
|
|
1074
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1075
|
-
}
|
|
1035
|
+
return getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
1076
1036
|
}
|
|
1077
1037
|
|
|
1078
|
-
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction,
|
|
1038
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertTransactionIsFullySigned, compileMessage, createTransaction, getBase64EncodedWireTransaction, getCompiledMessageCodec, getCompiledMessageDecoder, getCompiledMessageEncoder, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, partiallySignTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
|
|
1079
1039
|
//# sourceMappingURL=out.js.map
|
|
1080
1040
|
//# sourceMappingURL=index.browser.js.map
|