@talismn/solana 0.0.0-pr2294-20260109005735 → 0.0.0-pr2295-20260109145032
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.d.mts +68 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -0
- package/dist/{talismn-solana.esm.js → index.mjs} +70 -54
- package/dist/index.mjs.map +1 -0
- package/package.json +21 -7
- package/dist/declarations/src/index.d.ts +0 -4
- package/dist/declarations/src/utils/chains.d.ts +0 -3
- package/dist/declarations/src/utils/serialization.d.ts +0 -52
- package/dist/declarations/src/utils/signing.d.ts +0 -2
- package/dist/declarations/src/utils/transaction.d.ts +0 -7
- package/dist/talismn-solana.cjs.d.ts +0 -1
- package/dist/talismn-solana.cjs.dev.js +0 -162
- package/dist/talismn-solana.cjs.js +0 -7
- package/dist/talismn-solana.cjs.prod.js +0 -162
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,WAAW,IAAI,gBAAgB,CAAC,EAAE,SAAS,IAAI;AAC/E,UAAM,WAAW,GAAG,WAAW,SAAS,GAAG,WAAW,CAAC,IAAI;AAG3D,UAAM,YACJ,YACA,WACA,sBAAQ,OAAO,UAAU,GAAG,QAAQ,UAAU,GAAG,qBAAO,OAAO,OAAO,CAAC,IACnE,qBAAO,OAAO,QAAQ,IACtB;AAEN,WAAO,EAAE,i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,OAAO;AAAA,MACnC,YAAY,EAAE,WAAW,SAAS;AAAA,MAClC,iBAAiB,MAAM,KAAK,EAAE,eAAe;AAAA,MAC7C,iBAAiB,MAAM,KAAK,EAAE,eAAe;AAAA,IAC/C,EAAE,KAAK,CAAC;AAAA,IACV,cAAc,IAAI,qBAAqB,IAAI,CAAC,QAAQ;AAAA,MAClD,gBAAgB,GAAG;AAAA,MACnB,WAAW,WAAW,GAAG,cAAc,GAAG,SAAS,KAAK;AAAA,MACxD,UAAU,GAAG,kBAAkB,IAAI,CAAC,OAAO;AAAA,QACzC,OAAO;AAAA,QACP,QAAQ,WAAW,CAAC,GAAG,SAAS,KAAK;AAAA,MACvC,EAAE;AAAA,MACF,MAAM,sBAAO,OAAO,GAAG,IAAI;AAAA,IAC7B,EAAE;AAAA,EACJ;AACF;;;AEnHA,IAAAC,eAAwB;AACxB,IAAAC,iBAAuC;AAEhC,IAAM,aAAa,CAAC,cAAmC;AAC5D,QAAM,gBAAY,uCAAuB,WAAW,QAAQ;AAC5D,QAAM,eAAe,IAAI,WAAW,CAAC,GAAG,WAAW,GAAG,SAAS,CAAC;AAChE,SAAO,qBAAQ,cAAc,YAAY;AAC3C;;;ACPO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIO,IAAM,kBAAkB,CAAC,UAAyB;AACvD,UAAQ,OAAO;AAAA,IACb,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,yBAAyB,KAAK,EAAE;AAAA,EACpD;AACF;","names":["import_crypto","import_web3","import_crypto"]}
|
|
@@ -1,42 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
// src/utils/serialization.ts
|
|
2
|
+
import {
|
|
3
|
+
PublicKey,
|
|
4
|
+
Transaction,
|
|
5
|
+
VersionedTransaction
|
|
6
|
+
} from "@solana/web3.js";
|
|
7
|
+
import { base58 as base582 } from "@talismn/crypto";
|
|
3
8
|
|
|
4
|
-
|
|
9
|
+
// src/utils/transaction.ts
|
|
10
|
+
import { base58, ed25519 } from "@talismn/crypto";
|
|
11
|
+
var isVersionedTransaction = (transaction) => {
|
|
5
12
|
return "version" in transaction;
|
|
6
13
|
};
|
|
7
|
-
|
|
14
|
+
var parseTransactionInfo = (tx) => {
|
|
8
15
|
if (isVersionedTransaction(tx)) {
|
|
9
16
|
const recentBlockhash = tx.message.recentBlockhash;
|
|
10
|
-
const requiredSigners = tx.message.staticAccountKeys.filter(
|
|
11
|
-
|
|
17
|
+
const requiredSigners = tx.message.staticAccountKeys.filter(
|
|
18
|
+
(_, index) => tx.message.isAccountSigner(index)
|
|
19
|
+
);
|
|
20
|
+
const address = requiredSigners.length === 1 ? requiredSigners[0].toBase58() : void 0;
|
|
12
21
|
const sigBytes = tx.signatures.length ? tx.signatures[0] : null;
|
|
13
|
-
|
|
14
|
-
// signature might be an array of zeros, signature needs to be verified manually
|
|
15
22
|
const signature = sigBytes && address && ed25519.verify(sigBytes, tx.message.serialize(), base58.decode(address)) ? base58.encode(sigBytes) : null;
|
|
16
|
-
return {
|
|
17
|
-
recentBlockhash,
|
|
18
|
-
address,
|
|
19
|
-
signature
|
|
20
|
-
};
|
|
23
|
+
return { recentBlockhash, address, signature };
|
|
21
24
|
} else {
|
|
22
25
|
const recentBlockhash = tx.recentBlockhash;
|
|
23
|
-
const address = tx.feePayer ? tx.feePayer.toBase58() :
|
|
26
|
+
const address = tx.feePayer ? tx.feePayer.toBase58() : void 0;
|
|
24
27
|
const signature = tx.verifySignatures() ? base58.encode(tx.signature) : null;
|
|
25
|
-
return {
|
|
26
|
-
recentBlockhash,
|
|
27
|
-
address,
|
|
28
|
-
signature
|
|
29
|
-
};
|
|
28
|
+
return { recentBlockhash, address, signature };
|
|
30
29
|
}
|
|
31
30
|
};
|
|
32
31
|
|
|
33
|
-
//
|
|
34
|
-
|
|
32
|
+
// src/utils/serialization.ts
|
|
33
|
+
var solInstructionToJson = (instruction) => {
|
|
35
34
|
return {
|
|
36
35
|
type: "solana-instruction",
|
|
37
36
|
value: {
|
|
38
37
|
programId: instruction.programId.toString(),
|
|
39
|
-
keys: instruction.keys.map(key => ({
|
|
38
|
+
keys: instruction.keys.map((key) => ({
|
|
40
39
|
pubkey: key.pubkey.toString(),
|
|
41
40
|
isSigner: key.isSigner,
|
|
42
41
|
isWritable: key.isWritable
|
|
@@ -45,12 +44,12 @@ const solInstructionToJson = instruction => {
|
|
|
45
44
|
}
|
|
46
45
|
};
|
|
47
46
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
var solInstructionFromJson = (serialized) => {
|
|
48
|
+
if (serialized.type !== "solana-instruction")
|
|
49
|
+
throw new Error("Invalid serialized instruction type");
|
|
51
50
|
return {
|
|
52
51
|
programId: new PublicKey(serialized.value.programId),
|
|
53
|
-
keys: serialized.value.keys.map(key => ({
|
|
52
|
+
keys: serialized.value.keys.map((key) => ({
|
|
54
53
|
pubkey: new PublicKey(key.pubkey),
|
|
55
54
|
isSigner: key.isSigner,
|
|
56
55
|
isWritable: key.isWritable
|
|
@@ -58,82 +57,88 @@ const solInstructionFromJson = serialized => {
|
|
|
58
57
|
data: Buffer.from(serialized.value.data, "base64")
|
|
59
58
|
};
|
|
60
59
|
};
|
|
61
|
-
|
|
60
|
+
var serializeTransaction = (transaction) => {
|
|
62
61
|
if (isVersionedTransaction(transaction)) {
|
|
63
|
-
return
|
|
62
|
+
return base582.encode(transaction.serialize());
|
|
64
63
|
} else {
|
|
65
|
-
return
|
|
66
|
-
requireAllSignatures: false,
|
|
67
|
-
|
|
68
|
-
}));
|
|
64
|
+
return base582.encode(
|
|
65
|
+
transaction.serialize({ requireAllSignatures: false, verifySignatures: false })
|
|
66
|
+
);
|
|
69
67
|
}
|
|
70
68
|
};
|
|
71
|
-
|
|
72
|
-
const bytes =
|
|
69
|
+
var deserializeTransaction = (transaction) => {
|
|
70
|
+
const bytes = base582.decode(transaction);
|
|
73
71
|
try {
|
|
74
72
|
return VersionedTransaction.deserialize(bytes);
|
|
75
73
|
} catch {
|
|
76
74
|
return Transaction.from(bytes);
|
|
77
75
|
}
|
|
78
76
|
};
|
|
79
|
-
|
|
77
|
+
var txToHumanJSON = (tx) => {
|
|
80
78
|
if (typeof tx === "string") tx = deserializeTransaction(tx);
|
|
81
79
|
return isVersionedTransaction(tx) ? versionedTxToJSON(tx) : legacyTxToJSON(tx);
|
|
82
80
|
};
|
|
83
|
-
|
|
81
|
+
var legacyTxToJSON = (tx) => {
|
|
84
82
|
return {
|
|
85
83
|
type: "legacy",
|
|
86
|
-
signatures: tx.signatures.map(s => s.signature ?
|
|
84
|
+
signatures: tx.signatures.map((s) => s.signature ? base582.encode(s.signature) : null),
|
|
87
85
|
feePayer: tx.feePayer?.toBase58() ?? null,
|
|
88
86
|
recentBlockhash: tx.recentBlockhash ?? null,
|
|
89
|
-
instructions: tx.instructions.map(ix => ({
|
|
87
|
+
instructions: tx.instructions.map((ix) => ({
|
|
90
88
|
programId: ix.programId.toBase58(),
|
|
91
|
-
accounts: ix.keys.map(k => ({
|
|
89
|
+
accounts: ix.keys.map((k) => ({
|
|
92
90
|
pubkey: k.pubkey.toBase58(),
|
|
93
91
|
isSigner: k.isSigner,
|
|
94
92
|
isWritable: k.isWritable
|
|
95
93
|
})),
|
|
96
|
-
data:
|
|
94
|
+
data: base582.encode(ix.data)
|
|
97
95
|
}))
|
|
98
96
|
};
|
|
99
97
|
};
|
|
100
|
-
|
|
98
|
+
var versionedTxToJSON = (tx) => {
|
|
101
99
|
const msg = tx.message;
|
|
102
|
-
|
|
103
|
-
// ⚠️ NOTE: without address lookup table accounts we only have static keys.
|
|
104
100
|
const staticKeys = msg.staticAccountKeys;
|
|
105
101
|
return {
|
|
106
102
|
type: "versioned",
|
|
107
103
|
version: msg.version,
|
|
108
104
|
// usually 0
|
|
109
|
-
signatures: tx.signatures.map(sig =>
|
|
105
|
+
signatures: tx.signatures.map((sig) => base582.encode(sig)),
|
|
110
106
|
recentBlockhash: msg.recentBlockhash,
|
|
111
|
-
staticAccountKeys: staticKeys.map(k => k.toBase58()),
|
|
112
|
-
addressTableLookups: msg.addressTableLookups?.map(l => ({
|
|
107
|
+
staticAccountKeys: staticKeys.map((k) => k.toBase58()),
|
|
108
|
+
addressTableLookups: msg.addressTableLookups?.map((l) => ({
|
|
113
109
|
accountKey: l.accountKey.toBase58(),
|
|
114
110
|
writableIndexes: Array.from(l.writableIndexes),
|
|
115
111
|
readonlyIndexes: Array.from(l.readonlyIndexes)
|
|
116
112
|
})) ?? [],
|
|
117
|
-
instructions: msg.compiledInstructions.map(ix => ({
|
|
113
|
+
instructions: msg.compiledInstructions.map((ix) => ({
|
|
118
114
|
programIdIndex: ix.programIdIndex,
|
|
119
115
|
programId: staticKeys[ix.programIdIndex]?.toBase58() ?? null,
|
|
120
|
-
accounts: ix.accountKeyIndexes.map(i => ({
|
|
116
|
+
accounts: ix.accountKeyIndexes.map((i) => ({
|
|
121
117
|
index: i,
|
|
122
118
|
pubkey: staticKeys[i]?.toBase58() ?? null
|
|
123
119
|
})),
|
|
124
|
-
data:
|
|
120
|
+
data: base582.encode(ix.data)
|
|
125
121
|
}))
|
|
126
122
|
};
|
|
127
123
|
};
|
|
128
124
|
|
|
129
|
-
|
|
125
|
+
// src/utils/signing.ts
|
|
126
|
+
import { Keypair } from "@solana/web3.js";
|
|
127
|
+
import { getPublicKeyFromSecret } from "@talismn/crypto";
|
|
128
|
+
var getKeypair = (secretKey) => {
|
|
130
129
|
const publicKey = getPublicKeyFromSecret(secretKey, "solana");
|
|
131
130
|
const fullScretKey = new Uint8Array([...secretKey, ...publicKey]);
|
|
132
131
|
return Keypair.fromSecretKey(fullScretKey);
|
|
133
132
|
};
|
|
134
133
|
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
// src/utils/chains.ts
|
|
135
|
+
var SOLANA_CHAINS = [
|
|
136
|
+
"solana:mainnet",
|
|
137
|
+
"solana:devnet",
|
|
138
|
+
"solana:testnet",
|
|
139
|
+
"solana:localnet"
|
|
140
|
+
];
|
|
141
|
+
var getSolNetworkId = (chain) => {
|
|
137
142
|
switch (chain) {
|
|
138
143
|
case "solana:mainnet":
|
|
139
144
|
return "solana-mainnet";
|
|
@@ -147,5 +152,16 @@ const getSolNetworkId = chain => {
|
|
|
147
152
|
throw new Error(`Unknown Solana chain: ${chain}`);
|
|
148
153
|
}
|
|
149
154
|
};
|
|
150
|
-
|
|
151
|
-
|
|
155
|
+
export {
|
|
156
|
+
SOLANA_CHAINS,
|
|
157
|
+
deserializeTransaction,
|
|
158
|
+
getKeypair,
|
|
159
|
+
getSolNetworkId,
|
|
160
|
+
isVersionedTransaction,
|
|
161
|
+
parseTransactionInfo,
|
|
162
|
+
serializeTransaction,
|
|
163
|
+
solInstructionFromJson,
|
|
164
|
+
solInstructionToJson,
|
|
165
|
+
txToHumanJSON
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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,WAAW,IAAI,gBAAgB,CAAC,EAAE,SAAS,IAAI;AAC/E,UAAM,WAAW,GAAG,WAAW,SAAS,GAAG,WAAW,CAAC,IAAI;AAG3D,UAAM,YACJ,YACA,WACA,QAAQ,OAAO,UAAU,GAAG,QAAQ,UAAU,GAAG,OAAO,OAAO,OAAO,CAAC,IACnE,OAAO,OAAO,QAAQ,IACtB;AAEN,WAAO,EAAE,iBAAiB,SAAS,UAAU;AAAA,EAC/C,OAAO;AACL,UAAM,kBAAkB,GAAG;AAC3B,UAAM,UAAU,GAAG,WAAW,GAAG,SAAS,SAAS,IAAI;AACvD,UAAM,YAAY,GAAG,iBAAiB,IAAI,OAAO,OAAO,GAAG,SAAU,IAAI;AAEzE,WAAO,EAAE,iBAAiB,SAAS,UAAU;AAAA,EA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AAA,MACnB,WAAW,WAAW,GAAG,cAAc,GAAG,SAAS,KAAK;AAAA,MACxD,UAAU,GAAG,kBAAkB,IAAI,CAAC,OAAO;AAAA,QACzC,OAAO;AAAA,QACP,QAAQ,WAAW,CAAC,GAAG,SAAS,KAAK;AAAA,MACvC,EAAE;AAAA,MACF,MAAMA,QAAO,OAAO,GAAG,IAAI;AAAA,IAC7B,EAAE;AAAA,EACJ;AACF;;;AEnHA,SAAS,eAAe;AACxB,SAAS,8BAA8B;AAEhC,IAAM,aAAa,CAAC,cAAmC;AAC5D,QAAM,YAAY,uBAAuB,WAAW,QAAQ;AAC5D,QAAM,eAAe,IAAI,WAAW,CAAC,GAAG,WAAW,GAAG,SAAS,CAAC;AAChE,SAAO,QAAQ,cAAc,YAAY;AAC3C;;;ACPO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIO,IAAM,kBAAkB,CAAC,UAAyB;AACvD,UAAQ,OAAO;AAAA,IACb,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,yBAAyB,KAAK,EAAE;AAAA,EACpD;AACF;","names":["base58","base58"]}
|
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-pr2295-20260109145032",
|
|
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": "dist/
|
|
16
|
-
"module": "dist/
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
17
|
"files": [
|
|
18
|
-
"
|
|
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/eslint-config": "0.0.3",
|
|
35
|
+
"@talismn/tsconfig": "0.0.3"
|
|
36
36
|
},
|
|
37
37
|
"eslintConfig": {
|
|
38
38
|
"root": true,
|
|
@@ -40,9 +40,23 @@
|
|
|
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
|
+
},
|
|
43
56
|
"scripts": {
|
|
44
57
|
"test": "jest",
|
|
45
58
|
"lint": "eslint src --max-warnings 0",
|
|
46
|
-
"clean": "rm -rf dist .turbo node_modules"
|
|
59
|
+
"clean": "rm -rf dist .turbo node_modules",
|
|
60
|
+
"build": "tsup"
|
|
47
61
|
}
|
|
48
62
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
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";
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./declarations/src/index";
|
|
@@ -1,162 +0,0 @@
|
|
|
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,162 +0,0 @@
|
|
|
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;
|