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