@talismn/solana 0.0.3 → 0.0.5
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.
|
@@ -15,3 +15,38 @@ export type SolInstructionJson = ReturnType<typeof solInstructionToJson>;
|
|
|
15
15
|
export declare const solInstructionFromJson: (serialized: SolInstructionJson) => TransactionInstruction;
|
|
16
16
|
export declare const serializeTransaction: (transaction: Transaction | VersionedTransaction) => string;
|
|
17
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
|
+
};
|
|
@@ -78,6 +78,55 @@ const deserializeTransaction = transaction => {
|
|
|
78
78
|
return web3_js.Transaction.from(bytes);
|
|
79
79
|
}
|
|
80
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
|
+
};
|
|
81
130
|
|
|
82
131
|
const getKeypair = secretKey => {
|
|
83
132
|
const publicKey = crypto.getPublicKeyFromSecret(secretKey, "solana");
|
|
@@ -110,3 +159,4 @@ exports.parseTransactionInfo = parseTransactionInfo;
|
|
|
110
159
|
exports.serializeTransaction = serializeTransaction;
|
|
111
160
|
exports.solInstructionFromJson = solInstructionFromJson;
|
|
112
161
|
exports.solInstructionToJson = solInstructionToJson;
|
|
162
|
+
exports.txToHumanJSON = txToHumanJSON;
|
|
@@ -78,6 +78,55 @@ const deserializeTransaction = transaction => {
|
|
|
78
78
|
return web3_js.Transaction.from(bytes);
|
|
79
79
|
}
|
|
80
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
|
+
};
|
|
81
130
|
|
|
82
131
|
const getKeypair = secretKey => {
|
|
83
132
|
const publicKey = crypto.getPublicKeyFromSecret(secretKey, "solana");
|
|
@@ -110,3 +159,4 @@ exports.parseTransactionInfo = parseTransactionInfo;
|
|
|
110
159
|
exports.serializeTransaction = serializeTransaction;
|
|
111
160
|
exports.solInstructionFromJson = solInstructionFromJson;
|
|
112
161
|
exports.solInstructionToJson = solInstructionToJson;
|
|
162
|
+
exports.txToHumanJSON = txToHumanJSON;
|
|
@@ -76,6 +76,55 @@ const deserializeTransaction = transaction => {
|
|
|
76
76
|
return Transaction.from(bytes);
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
+
const txToHumanJSON = tx => {
|
|
80
|
+
if (typeof tx === "string") tx = deserializeTransaction(tx);
|
|
81
|
+
return isVersionedTransaction(tx) ? versionedTxToJSON(tx) : legacyTxToJSON(tx);
|
|
82
|
+
};
|
|
83
|
+
const legacyTxToJSON = tx => {
|
|
84
|
+
return {
|
|
85
|
+
type: "legacy",
|
|
86
|
+
signatures: tx.signatures.map(s => s.signature ? base58.encode(s.signature) : null),
|
|
87
|
+
feePayer: tx.feePayer?.toBase58() ?? null,
|
|
88
|
+
recentBlockhash: tx.recentBlockhash ?? null,
|
|
89
|
+
instructions: tx.instructions.map(ix => ({
|
|
90
|
+
programId: ix.programId.toBase58(),
|
|
91
|
+
accounts: ix.keys.map(k => ({
|
|
92
|
+
pubkey: k.pubkey.toBase58(),
|
|
93
|
+
isSigner: k.isSigner,
|
|
94
|
+
isWritable: k.isWritable
|
|
95
|
+
})),
|
|
96
|
+
data: base58.encode(ix.data)
|
|
97
|
+
}))
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const versionedTxToJSON = tx => {
|
|
101
|
+
const msg = tx.message;
|
|
102
|
+
|
|
103
|
+
// ⚠️ NOTE: without address lookup table accounts we only have static keys.
|
|
104
|
+
const staticKeys = msg.staticAccountKeys;
|
|
105
|
+
return {
|
|
106
|
+
type: "versioned",
|
|
107
|
+
version: msg.version,
|
|
108
|
+
// usually 0
|
|
109
|
+
signatures: tx.signatures.map(sig => base58.encode(sig)),
|
|
110
|
+
recentBlockhash: msg.recentBlockhash,
|
|
111
|
+
staticAccountKeys: staticKeys.map(k => k.toBase58()),
|
|
112
|
+
addressTableLookups: msg.addressTableLookups?.map(l => ({
|
|
113
|
+
accountKey: l.accountKey.toBase58(),
|
|
114
|
+
writableIndexes: Array.from(l.writableIndexes),
|
|
115
|
+
readonlyIndexes: Array.from(l.readonlyIndexes)
|
|
116
|
+
})) ?? [],
|
|
117
|
+
instructions: msg.compiledInstructions.map(ix => ({
|
|
118
|
+
programIdIndex: ix.programIdIndex,
|
|
119
|
+
programId: staticKeys[ix.programIdIndex]?.toBase58() ?? null,
|
|
120
|
+
accounts: ix.accountKeyIndexes.map(i => ({
|
|
121
|
+
index: i,
|
|
122
|
+
pubkey: staticKeys[i]?.toBase58() ?? null
|
|
123
|
+
})),
|
|
124
|
+
data: base58.encode(ix.data)
|
|
125
|
+
}))
|
|
126
|
+
};
|
|
127
|
+
};
|
|
79
128
|
|
|
80
129
|
const getKeypair = secretKey => {
|
|
81
130
|
const publicKey = getPublicKeyFromSecret(secretKey, "solana");
|
|
@@ -99,4 +148,4 @@ const getSolNetworkId = chain => {
|
|
|
99
148
|
}
|
|
100
149
|
};
|
|
101
150
|
|
|
102
|
-
export { SOLANA_CHAINS, deserializeTransaction, getKeypair, getSolNetworkId, isVersionedTransaction, parseTransactionInfo, serializeTransaction, solInstructionFromJson, solInstructionToJson };
|
|
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.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"author": "Talisman",
|
|
5
5
|
"homepage": "https://talisman.xyz",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@solana/web3.js": "^1.98.2",
|
|
25
25
|
"anylogger": "^1.0.11",
|
|
26
|
-
"@talismn/crypto": "0.
|
|
26
|
+
"@talismn/crypto": "0.3.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/jest": "^29.5.14",
|