@solana/transactions 2.0.0-experimental.2bae733 → 2.0.0-experimental.2f6fdd4
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 +204 -68
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +196 -67
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +264 -125
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +196 -65
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +206 -68
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +196 -65
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +11 -6
- package/dist/types/accounts.d.ts +1 -1
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +9 -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 +11 -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 +18 -6
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +1 -1
- 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/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 +6 -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 +3 -4
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts +4 -0
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts +6 -0
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +12 -16
package/dist/index.node.js
CHANGED
|
@@ -1,77 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers';
|
|
2
|
+
import { getAddressFromPublicKey, getBase58EncodedAddressComparator, getBase58EncodedAddressCodec } 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")();
|
|
6
7
|
|
|
7
|
-
// src/
|
|
8
|
-
function
|
|
9
|
-
version
|
|
10
|
-
}) {
|
|
11
|
-
const out = {
|
|
12
|
-
instructions: [],
|
|
13
|
-
version
|
|
14
|
-
};
|
|
15
|
-
Object.freeze(out);
|
|
16
|
-
return out;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/fee-payer.ts
|
|
20
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
21
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
22
|
-
return transaction;
|
|
23
|
-
}
|
|
24
|
-
let out;
|
|
8
|
+
// src/unsigned-transaction.ts
|
|
9
|
+
function getUnsignedTransaction(transaction) {
|
|
25
10
|
if ("signatures" in transaction) {
|
|
26
11
|
const {
|
|
27
12
|
signatures: _,
|
|
28
13
|
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
29
14
|
...unsignedTransaction
|
|
30
15
|
} = transaction;
|
|
31
|
-
|
|
32
|
-
...unsignedTransaction,
|
|
33
|
-
feePayer
|
|
34
|
-
};
|
|
16
|
+
return unsignedTransaction;
|
|
35
17
|
} else {
|
|
36
|
-
|
|
37
|
-
...transaction,
|
|
38
|
-
feePayer
|
|
39
|
-
};
|
|
18
|
+
return transaction;
|
|
40
19
|
}
|
|
41
|
-
Object.freeze(out);
|
|
42
|
-
return out;
|
|
43
20
|
}
|
|
44
21
|
|
|
45
|
-
// src/
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
22
|
+
// src/blockhash.ts
|
|
23
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
24
|
+
try {
|
|
25
|
+
if (
|
|
26
|
+
// Lowest value (32 bytes of zeroes)
|
|
27
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
28
|
+
putativeBlockhash.length > 44
|
|
29
|
+
) {
|
|
30
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
31
|
+
}
|
|
32
|
+
const bytes3 = base58.serialize(putativeBlockhash);
|
|
33
|
+
const numBytes = bytes3.byteLength;
|
|
34
|
+
if (numBytes !== 32) {
|
|
35
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
36
|
+
}
|
|
37
|
+
} catch (e) {
|
|
38
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
39
|
+
cause: e
|
|
40
|
+
});
|
|
63
41
|
}
|
|
64
|
-
return out;
|
|
65
42
|
}
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
43
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
44
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
45
|
+
return transaction;
|
|
46
|
+
}
|
|
47
|
+
const out = {
|
|
48
|
+
...getUnsignedTransaction(transaction),
|
|
49
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
50
|
+
};
|
|
69
51
|
Object.freeze(out);
|
|
70
52
|
return out;
|
|
71
53
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
54
|
+
|
|
55
|
+
// src/create-transaction.ts
|
|
56
|
+
function createTransaction({
|
|
57
|
+
version
|
|
58
|
+
}) {
|
|
59
|
+
const out = {
|
|
60
|
+
instructions: [],
|
|
61
|
+
version
|
|
62
|
+
};
|
|
75
63
|
Object.freeze(out);
|
|
76
64
|
return out;
|
|
77
65
|
}
|
|
@@ -98,6 +86,96 @@ function isWritableRole(role) {
|
|
|
98
86
|
function mergeRoles(roleA, roleB) {
|
|
99
87
|
return roleA | roleB;
|
|
100
88
|
}
|
|
89
|
+
|
|
90
|
+
// src/durable-nonce.ts
|
|
91
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
92
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
93
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
94
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
95
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
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
|
+
}
|
|
112
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
113
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
114
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
115
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
116
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
117
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
118
|
+
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
|
|
119
|
+
}
|
|
120
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
121
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
122
|
+
}
|
|
123
|
+
function isDurableNonceTransaction(transaction) {
|
|
124
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
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
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/fee-payer.ts
|
|
150
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
151
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
152
|
+
return transaction;
|
|
153
|
+
}
|
|
154
|
+
const out = {
|
|
155
|
+
...getUnsignedTransaction(transaction),
|
|
156
|
+
feePayer
|
|
157
|
+
};
|
|
158
|
+
Object.freeze(out);
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/instructions.ts
|
|
163
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
164
|
+
const out = {
|
|
165
|
+
...getUnsignedTransaction(transaction),
|
|
166
|
+
instructions: [...transaction.instructions, instruction]
|
|
167
|
+
};
|
|
168
|
+
Object.freeze(out);
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
172
|
+
const out = {
|
|
173
|
+
...getUnsignedTransaction(transaction),
|
|
174
|
+
instructions: [instruction, ...transaction.instructions]
|
|
175
|
+
};
|
|
176
|
+
Object.freeze(out);
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
101
179
|
function upsert(addressMap, address, update) {
|
|
102
180
|
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
|
|
103
181
|
}
|
|
@@ -444,7 +522,7 @@ function getInstructionCodec() {
|
|
|
444
522
|
)
|
|
445
523
|
],
|
|
446
524
|
[
|
|
447
|
-
"
|
|
525
|
+
"accountIndices",
|
|
448
526
|
array(
|
|
449
527
|
u8({
|
|
450
528
|
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
@@ -464,23 +542,23 @@ function getInstructionCodec() {
|
|
|
464
542
|
]
|
|
465
543
|
]),
|
|
466
544
|
(value) => {
|
|
467
|
-
if (value.
|
|
545
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
468
546
|
return value;
|
|
469
547
|
}
|
|
470
548
|
return {
|
|
471
549
|
...value,
|
|
472
|
-
|
|
550
|
+
accountIndices: value.accountIndices ?? [],
|
|
473
551
|
data: value.data ?? new Uint8Array(0)
|
|
474
552
|
};
|
|
475
553
|
},
|
|
476
554
|
(value) => {
|
|
477
|
-
if (value.
|
|
555
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
478
556
|
return value;
|
|
479
557
|
}
|
|
480
|
-
const {
|
|
558
|
+
const { accountIndices, data, ...rest } = value;
|
|
481
559
|
return {
|
|
482
560
|
...rest,
|
|
483
|
-
...
|
|
561
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
484
562
|
...data.byteLength ? { data } : null
|
|
485
563
|
};
|
|
486
564
|
}
|
|
@@ -507,8 +585,8 @@ var BASE_CONFIG = {
|
|
|
507
585
|
fixedSize: null,
|
|
508
586
|
maxSize: 1
|
|
509
587
|
};
|
|
510
|
-
function deserialize(
|
|
511
|
-
const firstByte =
|
|
588
|
+
function deserialize(bytes3, offset = 0) {
|
|
589
|
+
const firstByte = bytes3[offset];
|
|
512
590
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
513
591
|
return ["legacy", offset];
|
|
514
592
|
} else {
|
|
@@ -611,7 +689,7 @@ async function getCompiledMessageSignature(message, secretKey) {
|
|
|
611
689
|
async function signTransaction(keyPair, transaction) {
|
|
612
690
|
const compiledMessage = compileMessage(transaction);
|
|
613
691
|
const [signerPublicKey, signature] = await Promise.all([
|
|
614
|
-
|
|
692
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
615
693
|
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
616
694
|
]);
|
|
617
695
|
const nextSignatures = {
|
|
@@ -626,6 +704,59 @@ async function signTransaction(keyPair, transaction) {
|
|
|
626
704
|
return out;
|
|
627
705
|
}
|
|
628
706
|
|
|
629
|
-
|
|
707
|
+
// src/compile-transaction.ts
|
|
708
|
+
function getCompiledTransaction(transaction) {
|
|
709
|
+
const compiledMessage = compileMessage(transaction);
|
|
710
|
+
let signatures;
|
|
711
|
+
if ("signatures" in transaction) {
|
|
712
|
+
signatures = [];
|
|
713
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
714
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
715
|
+
}
|
|
716
|
+
} else {
|
|
717
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
compiledMessage,
|
|
721
|
+
signatures
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// src/serializers/transaction.ts
|
|
726
|
+
var BASE_CONFIG3 = {
|
|
727
|
+
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
728
|
+
fixedSize: null,
|
|
729
|
+
maxSize: null
|
|
730
|
+
};
|
|
731
|
+
function serialize3(transaction) {
|
|
732
|
+
const compiledTransaction = getCompiledTransaction(transaction);
|
|
733
|
+
return struct([
|
|
734
|
+
[
|
|
735
|
+
"signatures",
|
|
736
|
+
array(bytes({ size: 64 }), {
|
|
737
|
+
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
|
|
738
|
+
size: shortU16()
|
|
739
|
+
})
|
|
740
|
+
],
|
|
741
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
742
|
+
]).serialize(compiledTransaction);
|
|
743
|
+
}
|
|
744
|
+
function getTransactionEncoder() {
|
|
745
|
+
return {
|
|
746
|
+
...BASE_CONFIG3,
|
|
747
|
+
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
748
|
+
serialize: serialize3
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// src/wire-transaction.ts
|
|
753
|
+
function getBase64EncodedWireTransaction(transaction) {
|
|
754
|
+
const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
|
|
755
|
+
{
|
|
756
|
+
return Buffer.from(wireTransactionBytes).toString("base64");
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
|
|
630
761
|
//# sourceMappingURL=out.js.map
|
|
631
762
|
//# sourceMappingURL=index.node.js.map
|