@talismn/solana 0.0.0-pr2295-20260109145032 → 0.0.0-pr2296-20260110010758
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/declarations/src/index.d.ts +4 -0
- package/dist/declarations/src/utils/chains.d.ts +3 -0
- package/dist/declarations/src/utils/serialization.d.ts +52 -0
- package/dist/declarations/src/utils/signing.d.ts +2 -0
- package/dist/declarations/src/utils/transaction.d.ts +7 -0
- package/dist/talismn-solana.cjs.d.ts +1 -0
- package/dist/talismn-solana.cjs.dev.js +162 -0
- package/dist/talismn-solana.cjs.js +7 -0
- package/dist/talismn-solana.cjs.prod.js +162 -0
- package/dist/{index.mjs → talismn-solana.esm.js} +54 -70
- package/package.json +7 -21
- package/dist/index.d.mts +0 -68
- package/dist/index.d.ts +0 -68
- package/dist/index.js +0 -199
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const SOLANA_CHAINS: readonly ["solana:mainnet", "solana:devnet", "solana:testnet", "solana:localnet"];
|
|
2
|
+
export type SolanaChainId = (typeof SOLANA_CHAINS)[number];
|
|
3
|
+
export declare const getSolNetworkId: (chain: SolanaChainId) => "solana-mainnet" | "solana-devnet" | "solana-testnet" | "solana-localnet";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Transaction, TransactionInstruction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
export declare const solInstructionToJson: (instruction: TransactionInstruction) => {
|
|
3
|
+
type: "solana-instruction";
|
|
4
|
+
value: {
|
|
5
|
+
programId: string;
|
|
6
|
+
keys: {
|
|
7
|
+
pubkey: string;
|
|
8
|
+
isSigner: boolean;
|
|
9
|
+
isWritable: boolean;
|
|
10
|
+
}[];
|
|
11
|
+
data: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type SolInstructionJson = ReturnType<typeof solInstructionToJson>;
|
|
15
|
+
export declare const solInstructionFromJson: (serialized: SolInstructionJson) => TransactionInstruction;
|
|
16
|
+
export declare const serializeTransaction: (transaction: Transaction | VersionedTransaction) => string;
|
|
17
|
+
export declare const deserializeTransaction: (transaction: string) => Transaction | VersionedTransaction;
|
|
18
|
+
export declare const txToHumanJSON: (tx: string | Transaction | VersionedTransaction) => {
|
|
19
|
+
type: string;
|
|
20
|
+
version: 0 | "legacy";
|
|
21
|
+
signatures: string[];
|
|
22
|
+
recentBlockhash: string;
|
|
23
|
+
staticAccountKeys: string[];
|
|
24
|
+
addressTableLookups: {
|
|
25
|
+
accountKey: string;
|
|
26
|
+
writableIndexes: number[];
|
|
27
|
+
readonlyIndexes: number[];
|
|
28
|
+
}[];
|
|
29
|
+
instructions: {
|
|
30
|
+
programIdIndex: number;
|
|
31
|
+
programId: string;
|
|
32
|
+
accounts: {
|
|
33
|
+
index: number;
|
|
34
|
+
pubkey: string;
|
|
35
|
+
}[];
|
|
36
|
+
data: string;
|
|
37
|
+
}[];
|
|
38
|
+
} | {
|
|
39
|
+
type: string;
|
|
40
|
+
signatures: (string | null)[];
|
|
41
|
+
feePayer: string | null;
|
|
42
|
+
recentBlockhash: string | null;
|
|
43
|
+
instructions: {
|
|
44
|
+
programId: string;
|
|
45
|
+
accounts: {
|
|
46
|
+
pubkey: string;
|
|
47
|
+
isSigner: boolean;
|
|
48
|
+
isWritable: boolean;
|
|
49
|
+
}[];
|
|
50
|
+
data: string;
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
export declare const isVersionedTransaction: (transaction: Transaction | VersionedTransaction) => transaction is VersionedTransaction;
|
|
3
|
+
export declare const parseTransactionInfo: (tx: Transaction | VersionedTransaction) => {
|
|
4
|
+
recentBlockhash: string | undefined;
|
|
5
|
+
address: string | undefined;
|
|
6
|
+
signature: string | null;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./declarations/src/index";
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var web3_js = require('@solana/web3.js');
|
|
4
|
+
var crypto = require('@talismn/crypto');
|
|
5
|
+
|
|
6
|
+
const isVersionedTransaction = transaction => {
|
|
7
|
+
return "version" in transaction;
|
|
8
|
+
};
|
|
9
|
+
const parseTransactionInfo = tx => {
|
|
10
|
+
if (isVersionedTransaction(tx)) {
|
|
11
|
+
const recentBlockhash = tx.message.recentBlockhash;
|
|
12
|
+
const requiredSigners = tx.message.staticAccountKeys.filter((_, index) => tx.message.isAccountSigner(index));
|
|
13
|
+
const address = requiredSigners.length === 1 ? requiredSigners[0].toBase58() : undefined;
|
|
14
|
+
const sigBytes = tx.signatures.length ? tx.signatures[0] : null;
|
|
15
|
+
|
|
16
|
+
// signature might be an array of zeros, signature needs to be verified manually
|
|
17
|
+
const signature = sigBytes && address && crypto.ed25519.verify(sigBytes, tx.message.serialize(), crypto.base58.decode(address)) ? crypto.base58.encode(sigBytes) : null;
|
|
18
|
+
return {
|
|
19
|
+
recentBlockhash,
|
|
20
|
+
address,
|
|
21
|
+
signature
|
|
22
|
+
};
|
|
23
|
+
} else {
|
|
24
|
+
const recentBlockhash = tx.recentBlockhash;
|
|
25
|
+
const address = tx.feePayer ? tx.feePayer.toBase58() : undefined;
|
|
26
|
+
const signature = tx.verifySignatures() ? crypto.base58.encode(tx.signature) : null;
|
|
27
|
+
return {
|
|
28
|
+
recentBlockhash,
|
|
29
|
+
address,
|
|
30
|
+
signature
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Serialize TransactionInstruction to JSON
|
|
36
|
+
const solInstructionToJson = instruction => {
|
|
37
|
+
return {
|
|
38
|
+
type: "solana-instruction",
|
|
39
|
+
value: {
|
|
40
|
+
programId: instruction.programId.toString(),
|
|
41
|
+
keys: instruction.keys.map(key => ({
|
|
42
|
+
pubkey: key.pubkey.toString(),
|
|
43
|
+
isSigner: key.isSigner,
|
|
44
|
+
isWritable: key.isWritable
|
|
45
|
+
})),
|
|
46
|
+
data: instruction.data.toString("base64")
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
// Deserialize JSON back to TransactionInstruction
|
|
51
|
+
const solInstructionFromJson = serialized => {
|
|
52
|
+
if (serialized.type !== "solana-instruction") throw new Error("Invalid serialized instruction type");
|
|
53
|
+
return {
|
|
54
|
+
programId: new web3_js.PublicKey(serialized.value.programId),
|
|
55
|
+
keys: serialized.value.keys.map(key => ({
|
|
56
|
+
pubkey: new web3_js.PublicKey(key.pubkey),
|
|
57
|
+
isSigner: key.isSigner,
|
|
58
|
+
isWritable: key.isWritable
|
|
59
|
+
})),
|
|
60
|
+
data: Buffer.from(serialized.value.data, "base64")
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const serializeTransaction = transaction => {
|
|
64
|
+
if (isVersionedTransaction(transaction)) {
|
|
65
|
+
return crypto.base58.encode(transaction.serialize());
|
|
66
|
+
} else {
|
|
67
|
+
return crypto.base58.encode(transaction.serialize({
|
|
68
|
+
requireAllSignatures: false,
|
|
69
|
+
verifySignatures: false
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const deserializeTransaction = transaction => {
|
|
74
|
+
const bytes = crypto.base58.decode(transaction);
|
|
75
|
+
try {
|
|
76
|
+
return web3_js.VersionedTransaction.deserialize(bytes);
|
|
77
|
+
} catch {
|
|
78
|
+
return web3_js.Transaction.from(bytes);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const txToHumanJSON = tx => {
|
|
82
|
+
if (typeof tx === "string") tx = deserializeTransaction(tx);
|
|
83
|
+
return isVersionedTransaction(tx) ? versionedTxToJSON(tx) : legacyTxToJSON(tx);
|
|
84
|
+
};
|
|
85
|
+
const legacyTxToJSON = tx => {
|
|
86
|
+
return {
|
|
87
|
+
type: "legacy",
|
|
88
|
+
signatures: tx.signatures.map(s => s.signature ? crypto.base58.encode(s.signature) : null),
|
|
89
|
+
feePayer: tx.feePayer?.toBase58() ?? null,
|
|
90
|
+
recentBlockhash: tx.recentBlockhash ?? null,
|
|
91
|
+
instructions: tx.instructions.map(ix => ({
|
|
92
|
+
programId: ix.programId.toBase58(),
|
|
93
|
+
accounts: ix.keys.map(k => ({
|
|
94
|
+
pubkey: k.pubkey.toBase58(),
|
|
95
|
+
isSigner: k.isSigner,
|
|
96
|
+
isWritable: k.isWritable
|
|
97
|
+
})),
|
|
98
|
+
data: crypto.base58.encode(ix.data)
|
|
99
|
+
}))
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const versionedTxToJSON = tx => {
|
|
103
|
+
const msg = tx.message;
|
|
104
|
+
|
|
105
|
+
// ⚠️ NOTE: without address lookup table accounts we only have static keys.
|
|
106
|
+
const staticKeys = msg.staticAccountKeys;
|
|
107
|
+
return {
|
|
108
|
+
type: "versioned",
|
|
109
|
+
version: msg.version,
|
|
110
|
+
// usually 0
|
|
111
|
+
signatures: tx.signatures.map(sig => crypto.base58.encode(sig)),
|
|
112
|
+
recentBlockhash: msg.recentBlockhash,
|
|
113
|
+
staticAccountKeys: staticKeys.map(k => k.toBase58()),
|
|
114
|
+
addressTableLookups: msg.addressTableLookups?.map(l => ({
|
|
115
|
+
accountKey: l.accountKey.toBase58(),
|
|
116
|
+
writableIndexes: Array.from(l.writableIndexes),
|
|
117
|
+
readonlyIndexes: Array.from(l.readonlyIndexes)
|
|
118
|
+
})) ?? [],
|
|
119
|
+
instructions: msg.compiledInstructions.map(ix => ({
|
|
120
|
+
programIdIndex: ix.programIdIndex,
|
|
121
|
+
programId: staticKeys[ix.programIdIndex]?.toBase58() ?? null,
|
|
122
|
+
accounts: ix.accountKeyIndexes.map(i => ({
|
|
123
|
+
index: i,
|
|
124
|
+
pubkey: staticKeys[i]?.toBase58() ?? null
|
|
125
|
+
})),
|
|
126
|
+
data: crypto.base58.encode(ix.data)
|
|
127
|
+
}))
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const getKeypair = secretKey => {
|
|
132
|
+
const publicKey = crypto.getPublicKeyFromSecret(secretKey, "solana");
|
|
133
|
+
const fullScretKey = new Uint8Array([...secretKey, ...publicKey]);
|
|
134
|
+
return web3_js.Keypair.fromSecretKey(fullScretKey);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const SOLANA_CHAINS = ["solana:mainnet", "solana:devnet", "solana:testnet", "solana:localnet"];
|
|
138
|
+
const getSolNetworkId = chain => {
|
|
139
|
+
switch (chain) {
|
|
140
|
+
case "solana:mainnet":
|
|
141
|
+
return "solana-mainnet";
|
|
142
|
+
case "solana:devnet":
|
|
143
|
+
return "solana-devnet";
|
|
144
|
+
case "solana:testnet":
|
|
145
|
+
return "solana-testnet";
|
|
146
|
+
case "solana:localnet":
|
|
147
|
+
return "solana-localnet";
|
|
148
|
+
default:
|
|
149
|
+
throw new Error(`Unknown Solana chain: ${chain}`);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
exports.SOLANA_CHAINS = SOLANA_CHAINS;
|
|
154
|
+
exports.deserializeTransaction = deserializeTransaction;
|
|
155
|
+
exports.getKeypair = getKeypair;
|
|
156
|
+
exports.getSolNetworkId = getSolNetworkId;
|
|
157
|
+
exports.isVersionedTransaction = isVersionedTransaction;
|
|
158
|
+
exports.parseTransactionInfo = parseTransactionInfo;
|
|
159
|
+
exports.serializeTransaction = serializeTransaction;
|
|
160
|
+
exports.solInstructionFromJson = solInstructionFromJson;
|
|
161
|
+
exports.solInstructionToJson = solInstructionToJson;
|
|
162
|
+
exports.txToHumanJSON = txToHumanJSON;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var web3_js = require('@solana/web3.js');
|
|
4
|
+
var crypto = require('@talismn/crypto');
|
|
5
|
+
|
|
6
|
+
const isVersionedTransaction = transaction => {
|
|
7
|
+
return "version" in transaction;
|
|
8
|
+
};
|
|
9
|
+
const parseTransactionInfo = tx => {
|
|
10
|
+
if (isVersionedTransaction(tx)) {
|
|
11
|
+
const recentBlockhash = tx.message.recentBlockhash;
|
|
12
|
+
const requiredSigners = tx.message.staticAccountKeys.filter((_, index) => tx.message.isAccountSigner(index));
|
|
13
|
+
const address = requiredSigners.length === 1 ? requiredSigners[0].toBase58() : undefined;
|
|
14
|
+
const sigBytes = tx.signatures.length ? tx.signatures[0] : null;
|
|
15
|
+
|
|
16
|
+
// signature might be an array of zeros, signature needs to be verified manually
|
|
17
|
+
const signature = sigBytes && address && crypto.ed25519.verify(sigBytes, tx.message.serialize(), crypto.base58.decode(address)) ? crypto.base58.encode(sigBytes) : null;
|
|
18
|
+
return {
|
|
19
|
+
recentBlockhash,
|
|
20
|
+
address,
|
|
21
|
+
signature
|
|
22
|
+
};
|
|
23
|
+
} else {
|
|
24
|
+
const recentBlockhash = tx.recentBlockhash;
|
|
25
|
+
const address = tx.feePayer ? tx.feePayer.toBase58() : undefined;
|
|
26
|
+
const signature = tx.verifySignatures() ? crypto.base58.encode(tx.signature) : null;
|
|
27
|
+
return {
|
|
28
|
+
recentBlockhash,
|
|
29
|
+
address,
|
|
30
|
+
signature
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Serialize TransactionInstruction to JSON
|
|
36
|
+
const solInstructionToJson = instruction => {
|
|
37
|
+
return {
|
|
38
|
+
type: "solana-instruction",
|
|
39
|
+
value: {
|
|
40
|
+
programId: instruction.programId.toString(),
|
|
41
|
+
keys: instruction.keys.map(key => ({
|
|
42
|
+
pubkey: key.pubkey.toString(),
|
|
43
|
+
isSigner: key.isSigner,
|
|
44
|
+
isWritable: key.isWritable
|
|
45
|
+
})),
|
|
46
|
+
data: instruction.data.toString("base64")
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
// Deserialize JSON back to TransactionInstruction
|
|
51
|
+
const solInstructionFromJson = serialized => {
|
|
52
|
+
if (serialized.type !== "solana-instruction") throw new Error("Invalid serialized instruction type");
|
|
53
|
+
return {
|
|
54
|
+
programId: new web3_js.PublicKey(serialized.value.programId),
|
|
55
|
+
keys: serialized.value.keys.map(key => ({
|
|
56
|
+
pubkey: new web3_js.PublicKey(key.pubkey),
|
|
57
|
+
isSigner: key.isSigner,
|
|
58
|
+
isWritable: key.isWritable
|
|
59
|
+
})),
|
|
60
|
+
data: Buffer.from(serialized.value.data, "base64")
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const serializeTransaction = transaction => {
|
|
64
|
+
if (isVersionedTransaction(transaction)) {
|
|
65
|
+
return crypto.base58.encode(transaction.serialize());
|
|
66
|
+
} else {
|
|
67
|
+
return crypto.base58.encode(transaction.serialize({
|
|
68
|
+
requireAllSignatures: false,
|
|
69
|
+
verifySignatures: false
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const deserializeTransaction = transaction => {
|
|
74
|
+
const bytes = crypto.base58.decode(transaction);
|
|
75
|
+
try {
|
|
76
|
+
return web3_js.VersionedTransaction.deserialize(bytes);
|
|
77
|
+
} catch {
|
|
78
|
+
return web3_js.Transaction.from(bytes);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const txToHumanJSON = tx => {
|
|
82
|
+
if (typeof tx === "string") tx = deserializeTransaction(tx);
|
|
83
|
+
return isVersionedTransaction(tx) ? versionedTxToJSON(tx) : legacyTxToJSON(tx);
|
|
84
|
+
};
|
|
85
|
+
const legacyTxToJSON = tx => {
|
|
86
|
+
return {
|
|
87
|
+
type: "legacy",
|
|
88
|
+
signatures: tx.signatures.map(s => s.signature ? crypto.base58.encode(s.signature) : null),
|
|
89
|
+
feePayer: tx.feePayer?.toBase58() ?? null,
|
|
90
|
+
recentBlockhash: tx.recentBlockhash ?? null,
|
|
91
|
+
instructions: tx.instructions.map(ix => ({
|
|
92
|
+
programId: ix.programId.toBase58(),
|
|
93
|
+
accounts: ix.keys.map(k => ({
|
|
94
|
+
pubkey: k.pubkey.toBase58(),
|
|
95
|
+
isSigner: k.isSigner,
|
|
96
|
+
isWritable: k.isWritable
|
|
97
|
+
})),
|
|
98
|
+
data: crypto.base58.encode(ix.data)
|
|
99
|
+
}))
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const versionedTxToJSON = tx => {
|
|
103
|
+
const msg = tx.message;
|
|
104
|
+
|
|
105
|
+
// ⚠️ NOTE: without address lookup table accounts we only have static keys.
|
|
106
|
+
const staticKeys = msg.staticAccountKeys;
|
|
107
|
+
return {
|
|
108
|
+
type: "versioned",
|
|
109
|
+
version: msg.version,
|
|
110
|
+
// usually 0
|
|
111
|
+
signatures: tx.signatures.map(sig => crypto.base58.encode(sig)),
|
|
112
|
+
recentBlockhash: msg.recentBlockhash,
|
|
113
|
+
staticAccountKeys: staticKeys.map(k => k.toBase58()),
|
|
114
|
+
addressTableLookups: msg.addressTableLookups?.map(l => ({
|
|
115
|
+
accountKey: l.accountKey.toBase58(),
|
|
116
|
+
writableIndexes: Array.from(l.writableIndexes),
|
|
117
|
+
readonlyIndexes: Array.from(l.readonlyIndexes)
|
|
118
|
+
})) ?? [],
|
|
119
|
+
instructions: msg.compiledInstructions.map(ix => ({
|
|
120
|
+
programIdIndex: ix.programIdIndex,
|
|
121
|
+
programId: staticKeys[ix.programIdIndex]?.toBase58() ?? null,
|
|
122
|
+
accounts: ix.accountKeyIndexes.map(i => ({
|
|
123
|
+
index: i,
|
|
124
|
+
pubkey: staticKeys[i]?.toBase58() ?? null
|
|
125
|
+
})),
|
|
126
|
+
data: crypto.base58.encode(ix.data)
|
|
127
|
+
}))
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const getKeypair = secretKey => {
|
|
132
|
+
const publicKey = crypto.getPublicKeyFromSecret(secretKey, "solana");
|
|
133
|
+
const fullScretKey = new Uint8Array([...secretKey, ...publicKey]);
|
|
134
|
+
return web3_js.Keypair.fromSecretKey(fullScretKey);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const SOLANA_CHAINS = ["solana:mainnet", "solana:devnet", "solana:testnet", "solana:localnet"];
|
|
138
|
+
const getSolNetworkId = chain => {
|
|
139
|
+
switch (chain) {
|
|
140
|
+
case "solana:mainnet":
|
|
141
|
+
return "solana-mainnet";
|
|
142
|
+
case "solana:devnet":
|
|
143
|
+
return "solana-devnet";
|
|
144
|
+
case "solana:testnet":
|
|
145
|
+
return "solana-testnet";
|
|
146
|
+
case "solana:localnet":
|
|
147
|
+
return "solana-localnet";
|
|
148
|
+
default:
|
|
149
|
+
throw new Error(`Unknown Solana chain: ${chain}`);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
exports.SOLANA_CHAINS = SOLANA_CHAINS;
|
|
154
|
+
exports.deserializeTransaction = deserializeTransaction;
|
|
155
|
+
exports.getKeypair = getKeypair;
|
|
156
|
+
exports.getSolNetworkId = getSolNetworkId;
|
|
157
|
+
exports.isVersionedTransaction = isVersionedTransaction;
|
|
158
|
+
exports.parseTransactionInfo = parseTransactionInfo;
|
|
159
|
+
exports.serializeTransaction = serializeTransaction;
|
|
160
|
+
exports.solInstructionFromJson = solInstructionFromJson;
|
|
161
|
+
exports.solInstructionToJson = solInstructionToJson;
|
|
162
|
+
exports.txToHumanJSON = txToHumanJSON;
|
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
PublicKey,
|
|
4
|
-
Transaction,
|
|
5
|
-
VersionedTransaction
|
|
6
|
-
} from "@solana/web3.js";
|
|
7
|
-
import { base58 as base582 } from "@talismn/crypto";
|
|
1
|
+
import { PublicKey, VersionedTransaction, Transaction, Keypair } from '@solana/web3.js';
|
|
2
|
+
import { ed25519, base58, getPublicKeyFromSecret } from '@talismn/crypto';
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
import { base58, ed25519 } from "@talismn/crypto";
|
|
11
|
-
var isVersionedTransaction = (transaction) => {
|
|
4
|
+
const isVersionedTransaction = transaction => {
|
|
12
5
|
return "version" in transaction;
|
|
13
6
|
};
|
|
14
|
-
|
|
7
|
+
const parseTransactionInfo = tx => {
|
|
15
8
|
if (isVersionedTransaction(tx)) {
|
|
16
9
|
const recentBlockhash = tx.message.recentBlockhash;
|
|
17
|
-
const requiredSigners = tx.message.staticAccountKeys.filter(
|
|
18
|
-
|
|
19
|
-
);
|
|
20
|
-
const address = requiredSigners.length === 1 ? requiredSigners[0].toBase58() : void 0;
|
|
10
|
+
const requiredSigners = tx.message.staticAccountKeys.filter((_, index) => tx.message.isAccountSigner(index));
|
|
11
|
+
const address = requiredSigners.length === 1 ? requiredSigners[0].toBase58() : undefined;
|
|
21
12
|
const sigBytes = tx.signatures.length ? tx.signatures[0] : null;
|
|
13
|
+
|
|
14
|
+
// signature might be an array of zeros, signature needs to be verified manually
|
|
22
15
|
const signature = sigBytes && address && ed25519.verify(sigBytes, tx.message.serialize(), base58.decode(address)) ? base58.encode(sigBytes) : null;
|
|
23
|
-
return {
|
|
16
|
+
return {
|
|
17
|
+
recentBlockhash,
|
|
18
|
+
address,
|
|
19
|
+
signature
|
|
20
|
+
};
|
|
24
21
|
} else {
|
|
25
22
|
const recentBlockhash = tx.recentBlockhash;
|
|
26
|
-
const address = tx.feePayer ? tx.feePayer.toBase58() :
|
|
23
|
+
const address = tx.feePayer ? tx.feePayer.toBase58() : undefined;
|
|
27
24
|
const signature = tx.verifySignatures() ? base58.encode(tx.signature) : null;
|
|
28
|
-
return {
|
|
25
|
+
return {
|
|
26
|
+
recentBlockhash,
|
|
27
|
+
address,
|
|
28
|
+
signature
|
|
29
|
+
};
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
//
|
|
33
|
-
|
|
33
|
+
// Serialize TransactionInstruction to JSON
|
|
34
|
+
const solInstructionToJson = instruction => {
|
|
34
35
|
return {
|
|
35
36
|
type: "solana-instruction",
|
|
36
37
|
value: {
|
|
37
38
|
programId: instruction.programId.toString(),
|
|
38
|
-
keys: instruction.keys.map(
|
|
39
|
+
keys: instruction.keys.map(key => ({
|
|
39
40
|
pubkey: key.pubkey.toString(),
|
|
40
41
|
isSigner: key.isSigner,
|
|
41
42
|
isWritable: key.isWritable
|
|
@@ -44,12 +45,12 @@ var solInstructionToJson = (instruction) => {
|
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
47
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// Deserialize JSON back to TransactionInstruction
|
|
49
|
+
const solInstructionFromJson = serialized => {
|
|
50
|
+
if (serialized.type !== "solana-instruction") throw new Error("Invalid serialized instruction type");
|
|
50
51
|
return {
|
|
51
52
|
programId: new PublicKey(serialized.value.programId),
|
|
52
|
-
keys: serialized.value.keys.map(
|
|
53
|
+
keys: serialized.value.keys.map(key => ({
|
|
53
54
|
pubkey: new PublicKey(key.pubkey),
|
|
54
55
|
isSigner: key.isSigner,
|
|
55
56
|
isWritable: key.isWritable
|
|
@@ -57,88 +58,82 @@ var solInstructionFromJson = (serialized) => {
|
|
|
57
58
|
data: Buffer.from(serialized.value.data, "base64")
|
|
58
59
|
};
|
|
59
60
|
};
|
|
60
|
-
|
|
61
|
+
const serializeTransaction = transaction => {
|
|
61
62
|
if (isVersionedTransaction(transaction)) {
|
|
62
|
-
return
|
|
63
|
+
return base58.encode(transaction.serialize());
|
|
63
64
|
} else {
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
return base58.encode(transaction.serialize({
|
|
66
|
+
requireAllSignatures: false,
|
|
67
|
+
verifySignatures: false
|
|
68
|
+
}));
|
|
67
69
|
}
|
|
68
70
|
};
|
|
69
|
-
|
|
70
|
-
const bytes =
|
|
71
|
+
const deserializeTransaction = transaction => {
|
|
72
|
+
const bytes = base58.decode(transaction);
|
|
71
73
|
try {
|
|
72
74
|
return VersionedTransaction.deserialize(bytes);
|
|
73
75
|
} catch {
|
|
74
76
|
return Transaction.from(bytes);
|
|
75
77
|
}
|
|
76
78
|
};
|
|
77
|
-
|
|
79
|
+
const txToHumanJSON = tx => {
|
|
78
80
|
if (typeof tx === "string") tx = deserializeTransaction(tx);
|
|
79
81
|
return isVersionedTransaction(tx) ? versionedTxToJSON(tx) : legacyTxToJSON(tx);
|
|
80
82
|
};
|
|
81
|
-
|
|
83
|
+
const legacyTxToJSON = tx => {
|
|
82
84
|
return {
|
|
83
85
|
type: "legacy",
|
|
84
|
-
signatures: tx.signatures.map(
|
|
86
|
+
signatures: tx.signatures.map(s => s.signature ? base58.encode(s.signature) : null),
|
|
85
87
|
feePayer: tx.feePayer?.toBase58() ?? null,
|
|
86
88
|
recentBlockhash: tx.recentBlockhash ?? null,
|
|
87
|
-
instructions: tx.instructions.map(
|
|
89
|
+
instructions: tx.instructions.map(ix => ({
|
|
88
90
|
programId: ix.programId.toBase58(),
|
|
89
|
-
accounts: ix.keys.map(
|
|
91
|
+
accounts: ix.keys.map(k => ({
|
|
90
92
|
pubkey: k.pubkey.toBase58(),
|
|
91
93
|
isSigner: k.isSigner,
|
|
92
94
|
isWritable: k.isWritable
|
|
93
95
|
})),
|
|
94
|
-
data:
|
|
96
|
+
data: base58.encode(ix.data)
|
|
95
97
|
}))
|
|
96
98
|
};
|
|
97
99
|
};
|
|
98
|
-
|
|
100
|
+
const versionedTxToJSON = tx => {
|
|
99
101
|
const msg = tx.message;
|
|
102
|
+
|
|
103
|
+
// ⚠️ NOTE: without address lookup table accounts we only have static keys.
|
|
100
104
|
const staticKeys = msg.staticAccountKeys;
|
|
101
105
|
return {
|
|
102
106
|
type: "versioned",
|
|
103
107
|
version: msg.version,
|
|
104
108
|
// usually 0
|
|
105
|
-
signatures: tx.signatures.map(
|
|
109
|
+
signatures: tx.signatures.map(sig => base58.encode(sig)),
|
|
106
110
|
recentBlockhash: msg.recentBlockhash,
|
|
107
|
-
staticAccountKeys: staticKeys.map(
|
|
108
|
-
addressTableLookups: msg.addressTableLookups?.map(
|
|
111
|
+
staticAccountKeys: staticKeys.map(k => k.toBase58()),
|
|
112
|
+
addressTableLookups: msg.addressTableLookups?.map(l => ({
|
|
109
113
|
accountKey: l.accountKey.toBase58(),
|
|
110
114
|
writableIndexes: Array.from(l.writableIndexes),
|
|
111
115
|
readonlyIndexes: Array.from(l.readonlyIndexes)
|
|
112
116
|
})) ?? [],
|
|
113
|
-
instructions: msg.compiledInstructions.map(
|
|
117
|
+
instructions: msg.compiledInstructions.map(ix => ({
|
|
114
118
|
programIdIndex: ix.programIdIndex,
|
|
115
119
|
programId: staticKeys[ix.programIdIndex]?.toBase58() ?? null,
|
|
116
|
-
accounts: ix.accountKeyIndexes.map(
|
|
120
|
+
accounts: ix.accountKeyIndexes.map(i => ({
|
|
117
121
|
index: i,
|
|
118
122
|
pubkey: staticKeys[i]?.toBase58() ?? null
|
|
119
123
|
})),
|
|
120
|
-
data:
|
|
124
|
+
data: base58.encode(ix.data)
|
|
121
125
|
}))
|
|
122
126
|
};
|
|
123
127
|
};
|
|
124
128
|
|
|
125
|
-
|
|
126
|
-
import { Keypair } from "@solana/web3.js";
|
|
127
|
-
import { getPublicKeyFromSecret } from "@talismn/crypto";
|
|
128
|
-
var getKeypair = (secretKey) => {
|
|
129
|
+
const getKeypair = secretKey => {
|
|
129
130
|
const publicKey = getPublicKeyFromSecret(secretKey, "solana");
|
|
130
131
|
const fullScretKey = new Uint8Array([...secretKey, ...publicKey]);
|
|
131
132
|
return Keypair.fromSecretKey(fullScretKey);
|
|
132
133
|
};
|
|
133
134
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
"solana:mainnet",
|
|
137
|
-
"solana:devnet",
|
|
138
|
-
"solana:testnet",
|
|
139
|
-
"solana:localnet"
|
|
140
|
-
];
|
|
141
|
-
var getSolNetworkId = (chain) => {
|
|
135
|
+
const SOLANA_CHAINS = ["solana:mainnet", "solana:devnet", "solana:testnet", "solana:localnet"];
|
|
136
|
+
const getSolNetworkId = chain => {
|
|
142
137
|
switch (chain) {
|
|
143
138
|
case "solana:mainnet":
|
|
144
139
|
return "solana-mainnet";
|
|
@@ -152,16 +147,5 @@ var getSolNetworkId = (chain) => {
|
|
|
152
147
|
throw new Error(`Unknown Solana chain: ${chain}`);
|
|
153
148
|
}
|
|
154
149
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
deserializeTransaction,
|
|
158
|
-
getKeypair,
|
|
159
|
-
getSolNetworkId,
|
|
160
|
-
isVersionedTransaction,
|
|
161
|
-
parseTransactionInfo,
|
|
162
|
-
serializeTransaction,
|
|
163
|
-
solInstructionFromJson,
|
|
164
|
-
solInstructionToJson,
|
|
165
|
-
txToHumanJSON
|
|
166
|
-
};
|
|
167
|
-
//# sourceMappingURL=index.mjs.map
|
|
150
|
+
|
|
151
|
+
export { SOLANA_CHAINS, deserializeTransaction, getKeypair, getSolNetworkId, isVersionedTransaction, parseTransactionInfo, serializeTransaction, solInstructionFromJson, solInstructionToJson, txToHumanJSON };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talismn/solana",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-pr2296-20260110010758",
|
|
4
4
|
"author": "Talisman",
|
|
5
5
|
"homepage": "https://talisman.xyz",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "https://github.com/talismansociety/talisman.git"
|
|
14
14
|
},
|
|
15
|
-
"main": "
|
|
16
|
-
"module": "
|
|
15
|
+
"main": "dist/talismn-solana.cjs.js",
|
|
16
|
+
"module": "dist/talismn-solana.esm.js",
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"/dist"
|
|
19
19
|
],
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"jest": "^29.7",
|
|
32
32
|
"ts-jest": "^29.2.5",
|
|
33
33
|
"typescript": "^5.6.3",
|
|
34
|
-
"@talismn/
|
|
35
|
-
"@talismn/
|
|
34
|
+
"@talismn/tsconfig": "0.0.3",
|
|
35
|
+
"@talismn/eslint-config": "0.0.3"
|
|
36
36
|
},
|
|
37
37
|
"eslintConfig": {
|
|
38
38
|
"root": true,
|
|
@@ -40,23 +40,9 @@
|
|
|
40
40
|
"@talismn/eslint-config/base"
|
|
41
41
|
]
|
|
42
42
|
},
|
|
43
|
-
"types": "./dist/index.d.ts",
|
|
44
|
-
"exports": {
|
|
45
|
-
".": {
|
|
46
|
-
"import": {
|
|
47
|
-
"types": "./dist/index.d.mts",
|
|
48
|
-
"default": "./dist/index.mjs"
|
|
49
|
-
},
|
|
50
|
-
"require": {
|
|
51
|
-
"types": "./dist/index.d.ts",
|
|
52
|
-
"default": "./dist/index.js"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
43
|
"scripts": {
|
|
57
44
|
"test": "jest",
|
|
58
45
|
"lint": "eslint src --max-warnings 0",
|
|
59
|
-
"clean": "rm -rf dist .turbo node_modules"
|
|
60
|
-
"build": "tsup"
|
|
46
|
+
"clean": "rm -rf dist .turbo node_modules"
|
|
61
47
|
}
|
|
62
48
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { TransactionInstruction, Transaction, VersionedTransaction, Keypair } from '@solana/web3.js';
|
|
2
|
-
|
|
3
|
-
declare const solInstructionToJson: (instruction: TransactionInstruction) => {
|
|
4
|
-
type: "solana-instruction";
|
|
5
|
-
value: {
|
|
6
|
-
programId: string;
|
|
7
|
-
keys: {
|
|
8
|
-
pubkey: string;
|
|
9
|
-
isSigner: boolean;
|
|
10
|
-
isWritable: boolean;
|
|
11
|
-
}[];
|
|
12
|
-
data: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
type SolInstructionJson = ReturnType<typeof solInstructionToJson>;
|
|
16
|
-
declare const solInstructionFromJson: (serialized: SolInstructionJson) => TransactionInstruction;
|
|
17
|
-
declare const serializeTransaction: (transaction: Transaction | VersionedTransaction) => string;
|
|
18
|
-
declare const deserializeTransaction: (transaction: string) => Transaction | VersionedTransaction;
|
|
19
|
-
declare const txToHumanJSON: (tx: string | Transaction | VersionedTransaction) => {
|
|
20
|
-
type: string;
|
|
21
|
-
version: 0 | "legacy";
|
|
22
|
-
signatures: string[];
|
|
23
|
-
recentBlockhash: string;
|
|
24
|
-
staticAccountKeys: string[];
|
|
25
|
-
addressTableLookups: {
|
|
26
|
-
accountKey: string;
|
|
27
|
-
writableIndexes: number[];
|
|
28
|
-
readonlyIndexes: number[];
|
|
29
|
-
}[];
|
|
30
|
-
instructions: {
|
|
31
|
-
programIdIndex: number;
|
|
32
|
-
programId: string;
|
|
33
|
-
accounts: {
|
|
34
|
-
index: number;
|
|
35
|
-
pubkey: string;
|
|
36
|
-
}[];
|
|
37
|
-
data: string;
|
|
38
|
-
}[];
|
|
39
|
-
} | {
|
|
40
|
-
type: string;
|
|
41
|
-
signatures: (string | null)[];
|
|
42
|
-
feePayer: string | null;
|
|
43
|
-
recentBlockhash: string | null;
|
|
44
|
-
instructions: {
|
|
45
|
-
programId: string;
|
|
46
|
-
accounts: {
|
|
47
|
-
pubkey: string;
|
|
48
|
-
isSigner: boolean;
|
|
49
|
-
isWritable: boolean;
|
|
50
|
-
}[];
|
|
51
|
-
data: string;
|
|
52
|
-
}[];
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
declare const getKeypair: (secretKey: Uint8Array) => Keypair;
|
|
56
|
-
|
|
57
|
-
declare const SOLANA_CHAINS: readonly ["solana:mainnet", "solana:devnet", "solana:testnet", "solana:localnet"];
|
|
58
|
-
type SolanaChainId = (typeof SOLANA_CHAINS)[number];
|
|
59
|
-
declare const getSolNetworkId: (chain: SolanaChainId) => "solana-mainnet" | "solana-devnet" | "solana-testnet" | "solana-localnet";
|
|
60
|
-
|
|
61
|
-
declare const isVersionedTransaction: (transaction: Transaction | VersionedTransaction) => transaction is VersionedTransaction;
|
|
62
|
-
declare const parseTransactionInfo: (tx: Transaction | VersionedTransaction) => {
|
|
63
|
-
recentBlockhash: string | undefined;
|
|
64
|
-
address: string | undefined;
|
|
65
|
-
signature: string | null;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export { SOLANA_CHAINS, type SolInstructionJson, type SolanaChainId, deserializeTransaction, getKeypair, getSolNetworkId, isVersionedTransaction, parseTransactionInfo, serializeTransaction, solInstructionFromJson, solInstructionToJson, txToHumanJSON };
|
package/dist/index.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { TransactionInstruction, Transaction, VersionedTransaction, Keypair } from '@solana/web3.js';
|
|
2
|
-
|
|
3
|
-
declare const solInstructionToJson: (instruction: TransactionInstruction) => {
|
|
4
|
-
type: "solana-instruction";
|
|
5
|
-
value: {
|
|
6
|
-
programId: string;
|
|
7
|
-
keys: {
|
|
8
|
-
pubkey: string;
|
|
9
|
-
isSigner: boolean;
|
|
10
|
-
isWritable: boolean;
|
|
11
|
-
}[];
|
|
12
|
-
data: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
type SolInstructionJson = ReturnType<typeof solInstructionToJson>;
|
|
16
|
-
declare const solInstructionFromJson: (serialized: SolInstructionJson) => TransactionInstruction;
|
|
17
|
-
declare const serializeTransaction: (transaction: Transaction | VersionedTransaction) => string;
|
|
18
|
-
declare const deserializeTransaction: (transaction: string) => Transaction | VersionedTransaction;
|
|
19
|
-
declare const txToHumanJSON: (tx: string | Transaction | VersionedTransaction) => {
|
|
20
|
-
type: string;
|
|
21
|
-
version: 0 | "legacy";
|
|
22
|
-
signatures: string[];
|
|
23
|
-
recentBlockhash: string;
|
|
24
|
-
staticAccountKeys: string[];
|
|
25
|
-
addressTableLookups: {
|
|
26
|
-
accountKey: string;
|
|
27
|
-
writableIndexes: number[];
|
|
28
|
-
readonlyIndexes: number[];
|
|
29
|
-
}[];
|
|
30
|
-
instructions: {
|
|
31
|
-
programIdIndex: number;
|
|
32
|
-
programId: string;
|
|
33
|
-
accounts: {
|
|
34
|
-
index: number;
|
|
35
|
-
pubkey: string;
|
|
36
|
-
}[];
|
|
37
|
-
data: string;
|
|
38
|
-
}[];
|
|
39
|
-
} | {
|
|
40
|
-
type: string;
|
|
41
|
-
signatures: (string | null)[];
|
|
42
|
-
feePayer: string | null;
|
|
43
|
-
recentBlockhash: string | null;
|
|
44
|
-
instructions: {
|
|
45
|
-
programId: string;
|
|
46
|
-
accounts: {
|
|
47
|
-
pubkey: string;
|
|
48
|
-
isSigner: boolean;
|
|
49
|
-
isWritable: boolean;
|
|
50
|
-
}[];
|
|
51
|
-
data: string;
|
|
52
|
-
}[];
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
declare const getKeypair: (secretKey: Uint8Array) => Keypair;
|
|
56
|
-
|
|
57
|
-
declare const SOLANA_CHAINS: readonly ["solana:mainnet", "solana:devnet", "solana:testnet", "solana:localnet"];
|
|
58
|
-
type SolanaChainId = (typeof SOLANA_CHAINS)[number];
|
|
59
|
-
declare const getSolNetworkId: (chain: SolanaChainId) => "solana-mainnet" | "solana-devnet" | "solana-testnet" | "solana-localnet";
|
|
60
|
-
|
|
61
|
-
declare const isVersionedTransaction: (transaction: Transaction | VersionedTransaction) => transaction is VersionedTransaction;
|
|
62
|
-
declare const parseTransactionInfo: (tx: Transaction | VersionedTransaction) => {
|
|
63
|
-
recentBlockhash: string | undefined;
|
|
64
|
-
address: string | undefined;
|
|
65
|
-
signature: string | null;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export { SOLANA_CHAINS, type SolInstructionJson, type SolanaChainId, deserializeTransaction, getKeypair, getSolNetworkId, isVersionedTransaction, parseTransactionInfo, serializeTransaction, solInstructionFromJson, solInstructionToJson, txToHumanJSON };
|
package/dist/index.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
SOLANA_CHAINS: () => SOLANA_CHAINS,
|
|
24
|
-
deserializeTransaction: () => deserializeTransaction,
|
|
25
|
-
getKeypair: () => getKeypair,
|
|
26
|
-
getSolNetworkId: () => getSolNetworkId,
|
|
27
|
-
isVersionedTransaction: () => isVersionedTransaction,
|
|
28
|
-
parseTransactionInfo: () => parseTransactionInfo,
|
|
29
|
-
serializeTransaction: () => serializeTransaction,
|
|
30
|
-
solInstructionFromJson: () => solInstructionFromJson,
|
|
31
|
-
solInstructionToJson: () => solInstructionToJson,
|
|
32
|
-
txToHumanJSON: () => txToHumanJSON
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(index_exports);
|
|
35
|
-
|
|
36
|
-
// src/utils/serialization.ts
|
|
37
|
-
var import_web3 = require("@solana/web3.js");
|
|
38
|
-
var import_crypto2 = require("@talismn/crypto");
|
|
39
|
-
|
|
40
|
-
// src/utils/transaction.ts
|
|
41
|
-
var import_crypto = require("@talismn/crypto");
|
|
42
|
-
var isVersionedTransaction = (transaction) => {
|
|
43
|
-
return "version" in transaction;
|
|
44
|
-
};
|
|
45
|
-
var parseTransactionInfo = (tx) => {
|
|
46
|
-
if (isVersionedTransaction(tx)) {
|
|
47
|
-
const recentBlockhash = tx.message.recentBlockhash;
|
|
48
|
-
const requiredSigners = tx.message.staticAccountKeys.filter(
|
|
49
|
-
(_, index) => tx.message.isAccountSigner(index)
|
|
50
|
-
);
|
|
51
|
-
const address = requiredSigners.length === 1 ? requiredSigners[0].toBase58() : void 0;
|
|
52
|
-
const sigBytes = tx.signatures.length ? tx.signatures[0] : null;
|
|
53
|
-
const signature = sigBytes && address && import_crypto.ed25519.verify(sigBytes, tx.message.serialize(), import_crypto.base58.decode(address)) ? import_crypto.base58.encode(sigBytes) : null;
|
|
54
|
-
return { recentBlockhash, address, signature };
|
|
55
|
-
} else {
|
|
56
|
-
const recentBlockhash = tx.recentBlockhash;
|
|
57
|
-
const address = tx.feePayer ? tx.feePayer.toBase58() : void 0;
|
|
58
|
-
const signature = tx.verifySignatures() ? import_crypto.base58.encode(tx.signature) : null;
|
|
59
|
-
return { recentBlockhash, address, signature };
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// src/utils/serialization.ts
|
|
64
|
-
var solInstructionToJson = (instruction) => {
|
|
65
|
-
return {
|
|
66
|
-
type: "solana-instruction",
|
|
67
|
-
value: {
|
|
68
|
-
programId: instruction.programId.toString(),
|
|
69
|
-
keys: instruction.keys.map((key) => ({
|
|
70
|
-
pubkey: key.pubkey.toString(),
|
|
71
|
-
isSigner: key.isSigner,
|
|
72
|
-
isWritable: key.isWritable
|
|
73
|
-
})),
|
|
74
|
-
data: instruction.data.toString("base64")
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
var solInstructionFromJson = (serialized) => {
|
|
79
|
-
if (serialized.type !== "solana-instruction")
|
|
80
|
-
throw new Error("Invalid serialized instruction type");
|
|
81
|
-
return {
|
|
82
|
-
programId: new import_web3.PublicKey(serialized.value.programId),
|
|
83
|
-
keys: serialized.value.keys.map((key) => ({
|
|
84
|
-
pubkey: new import_web3.PublicKey(key.pubkey),
|
|
85
|
-
isSigner: key.isSigner,
|
|
86
|
-
isWritable: key.isWritable
|
|
87
|
-
})),
|
|
88
|
-
data: Buffer.from(serialized.value.data, "base64")
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
var serializeTransaction = (transaction) => {
|
|
92
|
-
if (isVersionedTransaction(transaction)) {
|
|
93
|
-
return import_crypto2.base58.encode(transaction.serialize());
|
|
94
|
-
} else {
|
|
95
|
-
return import_crypto2.base58.encode(
|
|
96
|
-
transaction.serialize({ requireAllSignatures: false, verifySignatures: false })
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
var deserializeTransaction = (transaction) => {
|
|
101
|
-
const bytes = import_crypto2.base58.decode(transaction);
|
|
102
|
-
try {
|
|
103
|
-
return import_web3.VersionedTransaction.deserialize(bytes);
|
|
104
|
-
} catch {
|
|
105
|
-
return import_web3.Transaction.from(bytes);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var txToHumanJSON = (tx) => {
|
|
109
|
-
if (typeof tx === "string") tx = deserializeTransaction(tx);
|
|
110
|
-
return isVersionedTransaction(tx) ? versionedTxToJSON(tx) : legacyTxToJSON(tx);
|
|
111
|
-
};
|
|
112
|
-
var legacyTxToJSON = (tx) => {
|
|
113
|
-
return {
|
|
114
|
-
type: "legacy",
|
|
115
|
-
signatures: tx.signatures.map((s) => s.signature ? import_crypto2.base58.encode(s.signature) : null),
|
|
116
|
-
feePayer: tx.feePayer?.toBase58() ?? null,
|
|
117
|
-
recentBlockhash: tx.recentBlockhash ?? null,
|
|
118
|
-
instructions: tx.instructions.map((ix) => ({
|
|
119
|
-
programId: ix.programId.toBase58(),
|
|
120
|
-
accounts: ix.keys.map((k) => ({
|
|
121
|
-
pubkey: k.pubkey.toBase58(),
|
|
122
|
-
isSigner: k.isSigner,
|
|
123
|
-
isWritable: k.isWritable
|
|
124
|
-
})),
|
|
125
|
-
data: import_crypto2.base58.encode(ix.data)
|
|
126
|
-
}))
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
var versionedTxToJSON = (tx) => {
|
|
130
|
-
const msg = tx.message;
|
|
131
|
-
const staticKeys = msg.staticAccountKeys;
|
|
132
|
-
return {
|
|
133
|
-
type: "versioned",
|
|
134
|
-
version: msg.version,
|
|
135
|
-
// usually 0
|
|
136
|
-
signatures: tx.signatures.map((sig) => import_crypto2.base58.encode(sig)),
|
|
137
|
-
recentBlockhash: msg.recentBlockhash,
|
|
138
|
-
staticAccountKeys: staticKeys.map((k) => k.toBase58()),
|
|
139
|
-
addressTableLookups: msg.addressTableLookups?.map((l) => ({
|
|
140
|
-
accountKey: l.accountKey.toBase58(),
|
|
141
|
-
writableIndexes: Array.from(l.writableIndexes),
|
|
142
|
-
readonlyIndexes: Array.from(l.readonlyIndexes)
|
|
143
|
-
})) ?? [],
|
|
144
|
-
instructions: msg.compiledInstructions.map((ix) => ({
|
|
145
|
-
programIdIndex: ix.programIdIndex,
|
|
146
|
-
programId: staticKeys[ix.programIdIndex]?.toBase58() ?? null,
|
|
147
|
-
accounts: ix.accountKeyIndexes.map((i) => ({
|
|
148
|
-
index: i,
|
|
149
|
-
pubkey: staticKeys[i]?.toBase58() ?? null
|
|
150
|
-
})),
|
|
151
|
-
data: import_crypto2.base58.encode(ix.data)
|
|
152
|
-
}))
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// src/utils/signing.ts
|
|
157
|
-
var import_web32 = require("@solana/web3.js");
|
|
158
|
-
var import_crypto3 = require("@talismn/crypto");
|
|
159
|
-
var getKeypair = (secretKey) => {
|
|
160
|
-
const publicKey = (0, import_crypto3.getPublicKeyFromSecret)(secretKey, "solana");
|
|
161
|
-
const fullScretKey = new Uint8Array([...secretKey, ...publicKey]);
|
|
162
|
-
return import_web32.Keypair.fromSecretKey(fullScretKey);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// src/utils/chains.ts
|
|
166
|
-
var SOLANA_CHAINS = [
|
|
167
|
-
"solana:mainnet",
|
|
168
|
-
"solana:devnet",
|
|
169
|
-
"solana:testnet",
|
|
170
|
-
"solana:localnet"
|
|
171
|
-
];
|
|
172
|
-
var getSolNetworkId = (chain) => {
|
|
173
|
-
switch (chain) {
|
|
174
|
-
case "solana:mainnet":
|
|
175
|
-
return "solana-mainnet";
|
|
176
|
-
case "solana:devnet":
|
|
177
|
-
return "solana-devnet";
|
|
178
|
-
case "solana:testnet":
|
|
179
|
-
return "solana-testnet";
|
|
180
|
-
case "solana:localnet":
|
|
181
|
-
return "solana-localnet";
|
|
182
|
-
default:
|
|
183
|
-
throw new Error(`Unknown Solana chain: ${chain}`);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
187
|
-
0 && (module.exports = {
|
|
188
|
-
SOLANA_CHAINS,
|
|
189
|
-
deserializeTransaction,
|
|
190
|
-
getKeypair,
|
|
191
|
-
getSolNetworkId,
|
|
192
|
-
isVersionedTransaction,
|
|
193
|
-
parseTransactionInfo,
|
|
194
|
-
serializeTransaction,
|
|
195
|
-
solInstructionFromJson,
|
|
196
|
-
solInstructionToJson,
|
|
197
|
-
txToHumanJSON
|
|
198
|
-
});
|
|
199
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils/serialization.ts","../src/utils/transaction.ts","../src/utils/signing.ts","../src/utils/chains.ts"],"sourcesContent":["export * from \"./utils/serialization\"\nexport * from \"./utils/signing\"\nexport * from \"./utils/chains\"\nexport * from \"./utils/transaction\"\n","import {\n PublicKey,\n Transaction,\n TransactionInstruction,\n VersionedTransaction,\n} from \"@solana/web3.js\"\nimport { base58 } from \"@talismn/crypto\"\n\nimport { isVersionedTransaction } from \"./transaction\"\n\n// Serialize TransactionInstruction to JSON\nexport const solInstructionToJson = (instruction: TransactionInstruction) => {\n return {\n type: \"solana-instruction\" as const,\n value: {\n programId: instruction.programId.toString(),\n keys: instruction.keys.map((key) => ({\n pubkey: key.pubkey.toString(),\n isSigner: key.isSigner,\n isWritable: key.isWritable,\n })),\n data: instruction.data.toString(\"base64\"),\n },\n }\n}\n\nexport type SolInstructionJson = ReturnType<typeof solInstructionToJson>\n\n// Deserialize JSON back to TransactionInstruction\nexport const solInstructionFromJson = (serialized: SolInstructionJson): TransactionInstruction => {\n if (serialized.type !== \"solana-instruction\")\n throw new Error(\"Invalid serialized instruction type\")\n\n return {\n programId: new PublicKey(serialized.value.programId),\n keys: serialized.value.keys.map((key) => ({\n pubkey: new PublicKey(key.pubkey),\n isSigner: key.isSigner,\n isWritable: key.isWritable,\n })),\n data: Buffer.from(serialized.value.data, \"base64\"),\n }\n}\n\nexport const serializeTransaction = (transaction: Transaction | VersionedTransaction): string => {\n if (isVersionedTransaction(transaction)) {\n return base58.encode(transaction.serialize())\n } else {\n return base58.encode(\n transaction.serialize({ requireAllSignatures: false, verifySignatures: false }),\n )\n }\n}\n\nexport const deserializeTransaction = (transaction: string): Transaction | VersionedTransaction => {\n const bytes = base58.decode(transaction)\n\n try {\n return VersionedTransaction.deserialize(bytes)\n } catch {\n return Transaction.from(bytes)\n }\n}\n\nexport const txToHumanJSON = (tx: string | Transaction | VersionedTransaction) => {\n if (typeof tx === \"string\") tx = deserializeTransaction(tx)\n return isVersionedTransaction(tx) ? versionedTxToJSON(tx) : legacyTxToJSON(tx)\n}\n\nconst legacyTxToJSON = (tx: Transaction) => {\n return {\n type: \"legacy\",\n signatures: tx.signatures.map((s) => (s.signature ? base58.encode(s.signature) : null)),\n feePayer: tx.feePayer?.toBase58() ?? null,\n recentBlockhash: tx.recentBlockhash ?? null,\n instructions: tx.instructions.map((ix) => ({\n programId: ix.programId.toBase58(),\n accounts: ix.keys.map((k) => ({\n pubkey: k.pubkey.toBase58(),\n isSigner: k.isSigner,\n isWritable: k.isWritable,\n })),\n data: base58.encode(ix.data),\n })),\n }\n}\n\nconst versionedTxToJSON = (tx: VersionedTransaction) => {\n const msg = tx.message\n\n // ⚠️ NOTE: without address lookup table accounts we only have static keys.\n const staticKeys = msg.staticAccountKeys\n\n return {\n type: \"versioned\",\n version: msg.version, // usually 0\n signatures: tx.signatures.map((sig) => base58.encode(sig)),\n recentBlockhash: msg.recentBlockhash,\n staticAccountKeys: staticKeys.map((k) => k.toBase58()),\n addressTableLookups:\n msg.addressTableLookups?.map((l) => ({\n accountKey: l.accountKey.toBase58(),\n writableIndexes: Array.from(l.writableIndexes),\n readonlyIndexes: Array.from(l.readonlyIndexes),\n })) ?? [],\n instructions: msg.compiledInstructions.map((ix) => ({\n programIdIndex: ix.programIdIndex,\n programId: staticKeys[ix.programIdIndex]?.toBase58() ?? null,\n accounts: ix.accountKeyIndexes.map((i) => ({\n index: i,\n pubkey: staticKeys[i]?.toBase58() ?? null,\n })),\n data: base58.encode(ix.data),\n })),\n }\n}\n","import { Transaction, VersionedTransaction } from \"@solana/web3.js\"\nimport { base58, ed25519 } from \"@talismn/crypto\"\n\nexport const isVersionedTransaction = (\n transaction: Transaction | VersionedTransaction,\n): transaction is VersionedTransaction => {\n return \"version\" in transaction\n}\n\nexport const parseTransactionInfo = (tx: Transaction | VersionedTransaction) => {\n if (isVersionedTransaction(tx)) {\n const recentBlockhash = tx.message.recentBlockhash\n const requiredSigners = tx.message.staticAccountKeys.filter((_, index) =>\n tx.message.isAccountSigner(index),\n )\n const address = requiredSigners.length === 1 ? requiredSigners[0].toBase58() : undefined\n const sigBytes = tx.signatures.length ? tx.signatures[0] : null\n\n // signature might be an array of zeros, signature needs to be verified manually\n const signature =\n sigBytes &&\n address &&\n ed25519.verify(sigBytes, tx.message.serialize(), base58.decode(address))\n ? base58.encode(sigBytes)\n : null\n\n return { recentBlockhash, address, signature }\n } else {\n const recentBlockhash = tx.recentBlockhash\n const address = tx.feePayer ? tx.feePayer.toBase58() : undefined\n const signature = tx.verifySignatures() ? base58.encode(tx.signature!) : null\n\n return { recentBlockhash, address, signature }\n }\n}\n","import { Keypair } from \"@solana/web3.js\"\nimport { getPublicKeyFromSecret } from \"@talismn/crypto\"\n\nexport const getKeypair = (secretKey: Uint8Array): Keypair => {\n const publicKey = getPublicKeyFromSecret(secretKey, \"solana\")\n const fullScretKey = new Uint8Array([...secretKey, ...publicKey])\n return Keypair.fromSecretKey(fullScretKey)\n}\n","export const SOLANA_CHAINS = [\n \"solana:mainnet\",\n \"solana:devnet\",\n \"solana:testnet\",\n \"solana:localnet\",\n] as const\n\nexport type SolanaChainId = (typeof SOLANA_CHAINS)[number]\n\nexport const getSolNetworkId = (chain: SolanaChainId) => {\n switch (chain) {\n case \"solana:mainnet\":\n return \"solana-mainnet\"\n case \"solana:devnet\":\n return \"solana-devnet\"\n case \"solana:testnet\":\n return \"solana-testnet\"\n case \"solana:localnet\":\n return \"solana-localnet\"\n default:\n throw new Error(`Unknown Solana chain: ${chain}`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAKO;AACP,IAAAA,iBAAuB;;;ACLvB,oBAAgC;AAEzB,IAAM,yBAAyB,CACpC,gBACwC;AACxC,SAAO,aAAa;AACtB;AAEO,IAAM,uBAAuB,CAAC,OAA2C;AAC9E,MAAI,uBAAuB,EAAE,GAAG;AAC9B,UAAM,kBAAkB,GAAG,QAAQ;AACnC,UAAM,kBAAkB,GAAG,QAAQ,kBAAkB;AAAA,MAAO,CAAC,GAAG,UAC9D,GAAG,QAAQ,gBAAgB,KAAK;AAAA,IAClC;AACA,UAAM,UAAU,gBAAgB,WA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A,IACT;AACE,YAAM,IAAI,MAAM,yBAAyB,KAAK,EAAE;AAAA,EACpD;AACF;","names":["import_crypto","import_web3","import_crypto"]}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/serialization.ts","../src/utils/transaction.ts","../src/utils/signing.ts","../src/utils/chains.ts"],"sourcesContent":["import {\n PublicKey,\n Transaction,\n TransactionInstruction,\n VersionedTransaction,\n} from \"@solana/web3.js\"\nimport { base58 } from \"@talismn/crypto\"\n\nimport { isVersionedTransaction } from \"./transaction\"\n\n// Serialize TransactionInstruction to JSON\nexport const solInstructionToJson = (instruction: TransactionInstruction) => {\n return {\n type: \"solana-instruction\" as const,\n value: {\n programId: instruction.programId.toString(),\n keys: instruction.keys.map((key) => ({\n pubkey: key.pubkey.toString(),\n isSigner: key.isSigner,\n isWritable: key.isWritable,\n })),\n data: instruction.data.toString(\"base64\"),\n },\n }\n}\n\nexport type SolInstructionJson = ReturnType<typeof solInstructionToJson>\n\n// Deserialize JSON back to TransactionInstruction\nexport const solInstructionFromJson = (serialized: SolInstructionJson): TransactionInstruction => {\n if (serialized.type !== \"solana-instruction\")\n throw new Error(\"Invalid serialized instruction type\")\n\n return {\n programId: new PublicKey(serialized.value.programId),\n keys: serialized.value.keys.map((key) => ({\n pubkey: new PublicKey(key.pubkey),\n isSigner: key.isSigner,\n isWritable: key.isWritable,\n })),\n data: Buffer.from(serialized.value.data, \"base64\"),\n }\n}\n\nexport const serializeTransaction = (transaction: Transaction | VersionedTransaction): string => {\n if (isVersionedTransaction(transaction)) {\n return base58.encode(transaction.serialize())\n } else {\n return base58.encode(\n transaction.serialize({ requireAllSignatures: false, verifySignatures: false }),\n )\n }\n}\n\nexport const deserializeTransaction = (transaction: string): Transaction | VersionedTransaction => {\n const bytes = base58.decode(transaction)\n\n try {\n return VersionedTransaction.deserialize(bytes)\n } catch {\n return Transaction.from(bytes)\n }\n}\n\nexport const txToHumanJSON = (tx: string | Transaction | VersionedTransaction) => {\n if (typeof tx === \"string\") tx = deserializeTransaction(tx)\n return isVersionedTransaction(tx) ? versionedTxToJSON(tx) : legacyTxToJSON(tx)\n}\n\nconst legacyTxToJSON = (tx: Transaction) => {\n return {\n type: \"legacy\",\n signatures: tx.signatures.map((s) => (s.signature ? base58.encode(s.signature) : null)),\n feePayer: tx.feePayer?.toBase58() ?? null,\n recentBlockhash: tx.recentBlockhash ?? null,\n instructions: tx.instructions.map((ix) => ({\n programId: ix.programId.toBase58(),\n accounts: ix.keys.map((k) => ({\n pubkey: k.pubkey.toBase58(),\n isSigner: k.isSigner,\n isWritable: k.isWritable,\n })),\n data: base58.encode(ix.data),\n })),\n }\n}\n\nconst versionedTxToJSON = (tx: VersionedTransaction) => {\n const msg = tx.message\n\n // ⚠️ NOTE: without address lookup table accounts we only have static keys.\n const staticKeys = msg.staticAccountKeys\n\n return {\n type: \"versioned\",\n version: msg.version, // usually 0\n signatures: tx.signatures.map((sig) => base58.encode(sig)),\n recentBlockhash: msg.recentBlockhash,\n staticAccountKeys: staticKeys.map((k) => k.toBase58()),\n addressTableLookups:\n msg.addressTableLookups?.map((l) => ({\n accountKey: l.accountKey.toBase58(),\n writableIndexes: Array.from(l.writableIndexes),\n readonlyIndexes: Array.from(l.readonlyIndexes),\n })) ?? [],\n instructions: msg.compiledInstructions.map((ix) => ({\n programIdIndex: ix.programIdIndex,\n programId: staticKeys[ix.programIdIndex]?.toBase58() ?? null,\n accounts: ix.accountKeyIndexes.map((i) => ({\n index: i,\n pubkey: staticKeys[i]?.toBase58() ?? null,\n })),\n data: base58.encode(ix.data),\n })),\n }\n}\n","import { Transaction, VersionedTransaction } from \"@solana/web3.js\"\nimport { base58, ed25519 } from \"@talismn/crypto\"\n\nexport const isVersionedTransaction = (\n transaction: Transaction | VersionedTransaction,\n): transaction is VersionedTransaction => {\n return \"version\" in transaction\n}\n\nexport const parseTransactionInfo = (tx: Transaction | VersionedTransaction) => {\n if (isVersionedTransaction(tx)) {\n const recentBlockhash = tx.message.recentBlockhash\n const requiredSigners = tx.message.staticAccountKeys.filter((_, index) =>\n tx.message.isAccountSigner(index),\n )\n const address = requiredSigners.length === 1 ? requiredSigners[0].toBase58() : undefined\n const sigBytes = tx.signatures.length ? tx.signatures[0] : null\n\n // signature might be an array of zeros, signature needs to be verified manually\n const signature =\n sigBytes &&\n address &&\n ed25519.verify(sigBytes, tx.message.serialize(), base58.decode(address))\n ? base58.encode(sigBytes)\n : null\n\n return { recentBlockhash, address, signature }\n } else {\n const recentBlockhash = tx.recentBlockhash\n const address = tx.feePayer ? tx.feePayer.toBase58() : undefined\n const signature = tx.verifySignatures() ? base58.encode(tx.signature!) : null\n\n return { recentBlockhash, address, signature }\n }\n}\n","import { Keypair } from \"@solana/web3.js\"\nimport { getPublicKeyFromSecret } from \"@talismn/crypto\"\n\nexport const getKeypair = (secretKey: Uint8Array): Keypair => {\n const publicKey = getPublicKeyFromSecret(secretKey, \"solana\")\n const fullScretKey = new Uint8Array([...secretKey, ...publicKey])\n return Keypair.fromSecretKey(fullScretKey)\n}\n","export const SOLANA_CHAINS = [\n \"solana:mainnet\",\n \"solana:devnet\",\n \"solana:testnet\",\n \"solana:localnet\",\n] as const\n\nexport type SolanaChainId = (typeof SOLANA_CHAINS)[number]\n\nexport const getSolNetworkId = (chain: SolanaChainId) => {\n switch (chain) {\n case \"solana:mainnet\":\n return \"solana-mainnet\"\n case \"solana:devnet\":\n return \"solana-devnet\"\n case \"solana:testnet\":\n return \"solana-testnet\"\n case \"solana:localnet\":\n return \"solana-localnet\"\n default:\n throw new Error(`Unknown Solana chain: ${chain}`)\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,UAAAA,eAAc;;;ACLvB,SAAS,QAAQ,eAAe;AAEzB,IAAM,yBAAyB,CACpC,gBACwC;AACxC,SAAO,aAAa;AACtB;AAEO,IAAM,uBAAuB,CAAC,OAA2C;AAC9E,MAAI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