@solana/transactions 2.0.0-experimental.c5061ae → 2.0.0-experimental.c8d8b83
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/dist/index.browser.cjs +148 -53
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +142 -55
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +197 -99
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +142 -55
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +146 -53
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +144 -55
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +16 -10
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +1 -1
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +10 -2
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +3 -2
- 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 +2 -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/serializers/unimplemented.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +12 -3
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts +7 -0
- 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 +1 -1
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +18 -18
package/dist/index.browser.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
|
+
var addresses = require('@solana/addresses');
|
|
4
5
|
var keys = require('@solana/keys');
|
|
5
6
|
|
|
6
7
|
// ../build-scripts/env-shim.ts
|
|
@@ -96,6 +97,20 @@ function assertIsDurableNonceTransaction(transaction) {
|
|
|
96
97
|
throw new Error("Transaction is not a durable nonce transaction");
|
|
97
98
|
}
|
|
98
99
|
}
|
|
100
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
101
|
+
return {
|
|
102
|
+
accounts: [
|
|
103
|
+
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
104
|
+
{
|
|
105
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
106
|
+
role: AccountRole.READONLY
|
|
107
|
+
},
|
|
108
|
+
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
109
|
+
],
|
|
110
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
111
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
112
|
+
};
|
|
113
|
+
}
|
|
99
114
|
function isAdvanceNonceAccountInstruction(instruction) {
|
|
100
115
|
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
101
116
|
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
@@ -110,6 +125,28 @@ function isAdvanceNonceAccountInstructionData(data) {
|
|
|
110
125
|
function isDurableNonceTransaction(transaction) {
|
|
111
126
|
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
112
127
|
}
|
|
128
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
129
|
+
nonce,
|
|
130
|
+
nonceAccountAddress,
|
|
131
|
+
nonceAuthorityAddress
|
|
132
|
+
}, transaction) {
|
|
133
|
+
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
134
|
+
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
135
|
+
return transaction;
|
|
136
|
+
}
|
|
137
|
+
const out = {
|
|
138
|
+
...getUnsignedTransaction(transaction),
|
|
139
|
+
instructions: [
|
|
140
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
141
|
+
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
142
|
+
],
|
|
143
|
+
lifetimeConstraint: {
|
|
144
|
+
nonce
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
Object.freeze(out);
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
113
150
|
|
|
114
151
|
// src/fee-payer.ts
|
|
115
152
|
function setTransactionFeePayer(feePayer, transaction) {
|
|
@@ -193,7 +230,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
193
230
|
const shouldReplaceEntry = (
|
|
194
231
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
195
232
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
196
|
-
(addressComparator || (addressComparator =
|
|
233
|
+
(addressComparator || (addressComparator = addresses.getAddressComparator()))(
|
|
197
234
|
accountMeta.lookupTableAddress,
|
|
198
235
|
entry.lookupTableAddress
|
|
199
236
|
) < 0
|
|
@@ -299,7 +336,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
299
336
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
300
337
|
return leftIsWritable ? -1 : 1;
|
|
301
338
|
}
|
|
302
|
-
addressComparator || (addressComparator =
|
|
339
|
+
addressComparator || (addressComparator = addresses.getAddressComparator());
|
|
303
340
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
304
341
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
305
342
|
} else {
|
|
@@ -328,7 +365,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
328
365
|
entry.readableIndices.push(account.addressIndex);
|
|
329
366
|
}
|
|
330
367
|
}
|
|
331
|
-
return Object.keys(index).sort(
|
|
368
|
+
return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
|
|
332
369
|
lookupTableAddress,
|
|
333
370
|
...index[lookupTableAddress]
|
|
334
371
|
}));
|
|
@@ -407,12 +444,30 @@ function compileMessage(transaction) {
|
|
|
407
444
|
version: transaction.version
|
|
408
445
|
};
|
|
409
446
|
}
|
|
447
|
+
|
|
448
|
+
// src/compile-transaction.ts
|
|
449
|
+
function getCompiledTransaction(transaction) {
|
|
450
|
+
const compiledMessage = compileMessage(transaction);
|
|
451
|
+
let signatures;
|
|
452
|
+
if ("signatures" in transaction) {
|
|
453
|
+
signatures = [];
|
|
454
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
455
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
456
|
+
}
|
|
457
|
+
} else {
|
|
458
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
compiledMessage,
|
|
462
|
+
signatures
|
|
463
|
+
};
|
|
464
|
+
}
|
|
410
465
|
function getAddressTableLookupCodec() {
|
|
411
466
|
return umiSerializers.struct(
|
|
412
467
|
[
|
|
413
468
|
[
|
|
414
469
|
"lookupTableAddress",
|
|
415
|
-
|
|
470
|
+
addresses.getAddressCodec(
|
|
416
471
|
__DEV__ ? {
|
|
417
472
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
418
473
|
} : void 0
|
|
@@ -487,7 +542,7 @@ function getInstructionCodec() {
|
|
|
487
542
|
)
|
|
488
543
|
],
|
|
489
544
|
[
|
|
490
|
-
"
|
|
545
|
+
"accountIndices",
|
|
491
546
|
umiSerializers.array(
|
|
492
547
|
umiSerializers.u8({
|
|
493
548
|
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
@@ -507,23 +562,23 @@ function getInstructionCodec() {
|
|
|
507
562
|
]
|
|
508
563
|
]),
|
|
509
564
|
(value) => {
|
|
510
|
-
if (value.
|
|
565
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
511
566
|
return value;
|
|
512
567
|
}
|
|
513
568
|
return {
|
|
514
569
|
...value,
|
|
515
|
-
|
|
570
|
+
accountIndices: value.accountIndices ?? [],
|
|
516
571
|
data: value.data ?? new Uint8Array(0)
|
|
517
572
|
};
|
|
518
573
|
},
|
|
519
574
|
(value) => {
|
|
520
|
-
if (value.
|
|
575
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
521
576
|
return value;
|
|
522
577
|
}
|
|
523
|
-
const {
|
|
578
|
+
const { accountIndices, data, ...rest } = value;
|
|
524
579
|
return {
|
|
525
580
|
...rest,
|
|
526
|
-
...
|
|
581
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
527
582
|
...data.byteLength ? { data } : null
|
|
528
583
|
};
|
|
529
584
|
}
|
|
@@ -609,7 +664,7 @@ function getPreludeStructSerializerTuple() {
|
|
|
609
664
|
["header", getMessageHeaderCodec()],
|
|
610
665
|
[
|
|
611
666
|
"staticAccounts",
|
|
612
|
-
umiSerializers.array(
|
|
667
|
+
umiSerializers.array(addresses.getAddressCodec(), {
|
|
613
668
|
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
|
|
614
669
|
size: umiSerializers.shortU16()
|
|
615
670
|
})
|
|
@@ -645,48 +700,6 @@ function getCompiledMessageEncoder() {
|
|
|
645
700
|
};
|
|
646
701
|
}
|
|
647
702
|
|
|
648
|
-
// src/signatures.ts
|
|
649
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
650
|
-
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
651
|
-
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
652
|
-
return signature;
|
|
653
|
-
}
|
|
654
|
-
async function signTransaction(keyPair, transaction) {
|
|
655
|
-
const compiledMessage = compileMessage(transaction);
|
|
656
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
657
|
-
keys.getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
|
|
658
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
659
|
-
]);
|
|
660
|
-
const nextSignatures = {
|
|
661
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
662
|
-
...{ [signerPublicKey]: signature }
|
|
663
|
-
};
|
|
664
|
-
const out = {
|
|
665
|
-
...transaction,
|
|
666
|
-
signatures: nextSignatures
|
|
667
|
-
};
|
|
668
|
-
Object.freeze(out);
|
|
669
|
-
return out;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
// src/compile-transaction.ts
|
|
673
|
-
function getCompiledTransaction(transaction) {
|
|
674
|
-
const compiledMessage = compileMessage(transaction);
|
|
675
|
-
let signatures;
|
|
676
|
-
if ("signatures" in transaction) {
|
|
677
|
-
signatures = [];
|
|
678
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
679
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
680
|
-
}
|
|
681
|
-
} else {
|
|
682
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
683
|
-
}
|
|
684
|
-
return {
|
|
685
|
-
compiledMessage,
|
|
686
|
-
signatures
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
|
|
690
703
|
// src/serializers/transaction.ts
|
|
691
704
|
var BASE_CONFIG3 = {
|
|
692
705
|
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
@@ -713,6 +726,80 @@ function getTransactionEncoder() {
|
|
|
713
726
|
serialize: serialize3
|
|
714
727
|
};
|
|
715
728
|
}
|
|
729
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
730
|
+
try {
|
|
731
|
+
if (
|
|
732
|
+
// Lowest value (64 bytes of zeroes)
|
|
733
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
734
|
+
putativeTransactionSignature.length > 88
|
|
735
|
+
) {
|
|
736
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
737
|
+
}
|
|
738
|
+
const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
739
|
+
const numBytes = bytes3.byteLength;
|
|
740
|
+
if (numBytes !== 64) {
|
|
741
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
742
|
+
}
|
|
743
|
+
} catch (e) {
|
|
744
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
745
|
+
cause: e
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
750
|
+
if (
|
|
751
|
+
// Lowest value (64 bytes of zeroes)
|
|
752
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
753
|
+
putativeTransactionSignature.length > 88
|
|
754
|
+
) {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
const bytes3 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
758
|
+
const numBytes = bytes3.byteLength;
|
|
759
|
+
if (numBytes !== 64) {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
return true;
|
|
763
|
+
}
|
|
764
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
765
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
766
|
+
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
767
|
+
return signature;
|
|
768
|
+
}
|
|
769
|
+
function getSignatureFromTransaction(transaction) {
|
|
770
|
+
const signature = transaction.signatures[transaction.feePayer];
|
|
771
|
+
if (!signature) {
|
|
772
|
+
throw new Error(
|
|
773
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
return signature;
|
|
777
|
+
}
|
|
778
|
+
async function signTransaction(keyPairs, transaction) {
|
|
779
|
+
const compiledMessage = compileMessage(transaction);
|
|
780
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
781
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
782
|
+
keyPairs.map(
|
|
783
|
+
(keyPair) => Promise.all([
|
|
784
|
+
addresses.getAddressFromPublicKey(keyPair.publicKey),
|
|
785
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
786
|
+
])
|
|
787
|
+
)
|
|
788
|
+
);
|
|
789
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
790
|
+
nextSignatures[signerPublicKey] = signature;
|
|
791
|
+
}
|
|
792
|
+
const out = {
|
|
793
|
+
...transaction,
|
|
794
|
+
signatures: nextSignatures
|
|
795
|
+
};
|
|
796
|
+
Object.freeze(out);
|
|
797
|
+
return out;
|
|
798
|
+
}
|
|
799
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
800
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
801
|
+
return putativeTransactionSignature;
|
|
802
|
+
}
|
|
716
803
|
|
|
717
804
|
// src/wire-transaction.ts
|
|
718
805
|
function getBase64EncodedWireTransaction(transaction) {
|
|
@@ -725,9 +812,17 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
725
812
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
726
813
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
727
814
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
815
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
728
816
|
exports.createTransaction = createTransaction;
|
|
729
817
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
818
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
819
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
820
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
730
821
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
731
822
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
732
823
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
824
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
733
825
|
exports.signTransaction = signTransaction;
|
|
826
|
+
exports.transactionSignature = transactionSignature;
|
|
827
|
+
//# sourceMappingURL=out.js.map
|
|
828
|
+
//# sourceMappingURL=index.browser.cjs.map
|