@qntx/wallet-chains 0.0.0-stage → 0.5.2
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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +22 -2
- package/dist/bitcoin-sign.d.mts +14 -0
- package/dist/bitcoin-sign.mjs +29 -0
- package/dist/bitcoin-sign.mjs.map +1 -0
- package/dist/bitcoin.d.mts +72 -0
- package/dist/bitcoin.mjs +465 -0
- package/dist/bitcoin.mjs.map +1 -0
- package/dist/evm-sign.d.mts +10 -0
- package/dist/evm-sign.mjs +94 -0
- package/dist/evm-sign.mjs.map +1 -0
- package/dist/evm.d.mts +87 -0
- package/dist/evm.mjs +373 -0
- package/dist/evm.mjs.map +1 -0
- package/dist/index.d.mts +142 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/dist/message-DtIS0ZWB.mjs +185 -0
- package/dist/message-DtIS0ZWB.mjs.map +1 -0
- package/dist/solana-sign.d.mts +5 -0
- package/dist/solana-sign.mjs +20 -0
- package/dist/solana-sign.mjs.map +1 -0
- package/dist/solana.d.mts +122 -0
- package/dist/solana.mjs +446 -0
- package/dist/solana.mjs.map +1 -0
- package/dist/typed-data-C6XANSQF.mjs +202 -0
- package/dist/typed-data-C6XANSQF.mjs.map +1 -0
- package/package.json +101 -4
package/dist/solana.mjs
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { ChainError } from "./index.mjs";
|
|
2
|
+
import { address, getAddressDecoder, getAddressEncoder } from "@solana/addresses";
|
|
3
|
+
import { getCompiledTransactionMessageDecoder } from "@solana/transaction-messages";
|
|
4
|
+
import { getU32Decoder, getU64Decoder } from "@solana/codecs";
|
|
5
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
6
|
+
//#region src/solana/ids.ts
|
|
7
|
+
/** Well-known Solana program ids (base58, 32 bytes) — frozen constants. */
|
|
8
|
+
const PROGRAM_IDS = Object.freeze({
|
|
9
|
+
system: "11111111111111111111111111111111",
|
|
10
|
+
computeBudget: "ComputeBudget111111111111111111111111111111",
|
|
11
|
+
associatedToken: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
12
|
+
token: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
13
|
+
token2022: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
|
|
14
|
+
stake: "Stake11111111111111111111111111111111111111"
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* CAIP-2 ids the wallet knows. The wire message itself carries no network marker — `network` is the
|
|
18
|
+
* only declaration and cannot be proven from the bytes.
|
|
19
|
+
*/
|
|
20
|
+
const SOLANA_NETWORKS = Object.freeze(["solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"]);
|
|
21
|
+
const BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
22
|
+
const isSolanaAddress = (value) => BASE58.test(value);
|
|
23
|
+
const decoder$1 = getAddressDecoder();
|
|
24
|
+
/** Base58-encoded address for a 32-byte ed25519 public key. */
|
|
25
|
+
function solanaAddressFromPublicKey(pubkey) {
|
|
26
|
+
if (pubkey.length !== 32) throw new ChainError("invalid-address", "expected a 32-byte ed25519 public key");
|
|
27
|
+
return decoder$1.decode(pubkey);
|
|
28
|
+
}
|
|
29
|
+
const decoder = getCompiledTransactionMessageDecoder();
|
|
30
|
+
/**
|
|
31
|
+
* Decodes a compiled wire message; rejects trailing bytes and the 1232-byte transaction limit. The
|
|
32
|
+
* fee payer is `staticAccounts[0]` — every valid transaction signs it.
|
|
33
|
+
*/
|
|
34
|
+
const parseCompiledMessage = (bytes) => {
|
|
35
|
+
if (bytes.length > 1232) throw new ChainError("invalid-request", "compiled message exceeds the 1232-byte limit");
|
|
36
|
+
if (bytes.length === 0) throw new ChainError("invalid-request", "compiled message is empty");
|
|
37
|
+
let decoded;
|
|
38
|
+
try {
|
|
39
|
+
decoded = decoder.decode(bytes);
|
|
40
|
+
} catch {
|
|
41
|
+
throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
42
|
+
}
|
|
43
|
+
const message = asCompiledMessage(decoded);
|
|
44
|
+
const staticAccounts = [...message.staticAccounts];
|
|
45
|
+
const lookups = message.addressTableLookups;
|
|
46
|
+
return {
|
|
47
|
+
version: message.version,
|
|
48
|
+
numRequiredSignatures: message.numSignerAccounts,
|
|
49
|
+
staticAccounts,
|
|
50
|
+
instructions: message.instructions,
|
|
51
|
+
lookupCount: lookups.length,
|
|
52
|
+
lookupAddresses: lookups.map((l) => l.lookupTableAddress)
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56
|
+
const isStringArray = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
57
|
+
const isNumberArray = (value) => Array.isArray(value) && value.every((v) => typeof v === "number");
|
|
58
|
+
const isArrayLike = (value) => isRecord$1(value) && typeof value["length"] === "number";
|
|
59
|
+
const isIx = (value) => isRecord$1(value) && typeof value["programAddressIndex"] === "number" && (value["accountIndices"] === void 0 || isNumberArray(value["accountIndices"]) || isArrayLike(value["accountIndices"])) && value["data"] instanceof Uint8Array;
|
|
60
|
+
const isLookup = (value) => isRecord$1(value) && typeof value["lookupTableAddress"] === "string" && (isNumberArray(value["readonlyIndexes"]) || value["readonlyIndexes"] instanceof Uint8Array) && (isNumberArray(value["writableIndexes"]) || value["writableIndexes"] instanceof Uint8Array);
|
|
61
|
+
const asCompiledMessage = (value) => {
|
|
62
|
+
if (!isRecord$1(value) || !isRecord$1(value["header"])) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
63
|
+
const { header } = value;
|
|
64
|
+
const { staticAccounts } = value;
|
|
65
|
+
const { instructions } = value;
|
|
66
|
+
const lookups = value["addressTableLookups"];
|
|
67
|
+
if (typeof header["numSignerAccounts"] !== "number" || !isStringArray(staticAccounts) || !Array.isArray(instructions) || !instructions.every(isIx) || lookups !== void 0 && (!Array.isArray(lookups) || !lookups.every(isLookup))) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
68
|
+
const version = value["version"] === 0 ? 0 : "legacy";
|
|
69
|
+
const ixs = instructions.map((ix) => {
|
|
70
|
+
if (!isIx(ix)) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
71
|
+
const indices = ix.accountIndices;
|
|
72
|
+
return {
|
|
73
|
+
programAddressIndex: ix.programAddressIndex,
|
|
74
|
+
accountIndices: indices === void 0 ? [] : [...indices],
|
|
75
|
+
data: ix.data
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
const tables = (lookups ?? []).map((t) => {
|
|
79
|
+
if (!isLookup(t)) throw new ChainError("invalid-request", "compiled message failed to decode");
|
|
80
|
+
return {
|
|
81
|
+
lookupTableAddress: t.lookupTableAddress,
|
|
82
|
+
readonlyIndexes: [...t.readonlyIndexes],
|
|
83
|
+
writableIndexes: [...t.writableIndexes]
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
version,
|
|
88
|
+
numSignerAccounts: header["numSignerAccounts"],
|
|
89
|
+
staticAccounts,
|
|
90
|
+
instructions: ixs,
|
|
91
|
+
addressTableLookups: tables
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Resolves an account index across static accounts and (request-declared) lookup tables in the
|
|
96
|
+
* compiled lookup order: writable entries then readable.
|
|
97
|
+
*/
|
|
98
|
+
const resolveAccountIndex = (parsed, index, lookups) => {
|
|
99
|
+
if (index < parsed.staticAccounts.length) return parsed.staticAccounts[index];
|
|
100
|
+
if (lookups === void 0) return;
|
|
101
|
+
let offset = index - parsed.staticAccounts.length;
|
|
102
|
+
for (const table of lookups) {
|
|
103
|
+
if (offset < table.addresses.length) return table.addresses[offset];
|
|
104
|
+
offset -= table.addresses.length;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/** All declared lookup-table entries must be valid base58 32-byte addresses. */
|
|
108
|
+
const validateLookupTables = (tables) => {
|
|
109
|
+
if (tables === void 0) return;
|
|
110
|
+
for (const table of tables) if (!isSolanaAddress(table.address) || !table.addresses.every(isSolanaAddress)) throw new ChainError("invalid-address", "lookup table entries must be base58 32-byte addresses");
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/solana/tokens.ts
|
|
114
|
+
const USDC = Object.freeze({
|
|
115
|
+
symbol: "USDC",
|
|
116
|
+
decimals: 6,
|
|
117
|
+
name: "USD Coin"
|
|
118
|
+
});
|
|
119
|
+
const USDT = Object.freeze({
|
|
120
|
+
symbol: "USDT",
|
|
121
|
+
decimals: 6,
|
|
122
|
+
name: "Tether USD"
|
|
123
|
+
});
|
|
124
|
+
const solanaTokenTable = Object.freeze({ "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": Object.freeze({
|
|
125
|
+
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: USDC,
|
|
126
|
+
Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB: USDT
|
|
127
|
+
}) });
|
|
128
|
+
const lookupSolanaToken = (table, network, mint) => table[network]?.[mint];
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/solana/decode.ts
|
|
131
|
+
const LAMPORTS_ASSET = "lamports";
|
|
132
|
+
const u32 = getU32Decoder();
|
|
133
|
+
const u64$1 = getU64Decoder();
|
|
134
|
+
const u32le = (data, offset) => u32.decode(data, offset);
|
|
135
|
+
const u64le = (data, offset) => u64$1.decode(data, offset);
|
|
136
|
+
/**
|
|
137
|
+
* Classifies one instruction by program + discriminator/layout. Exact-length checks keep
|
|
138
|
+
* non-canonical encodings out of the `full` class.
|
|
139
|
+
*/
|
|
140
|
+
const classifyIx = (parsed, ix, lookups) => {
|
|
141
|
+
const program = resolveAccountIndex(parsed, ix.programAddressIndex, lookups);
|
|
142
|
+
const { data } = ix;
|
|
143
|
+
if (program === PROGRAM_IDS.system) {
|
|
144
|
+
if (data.length === 12 && u32le(data, 0) === 2) return {
|
|
145
|
+
kind: "system-transfer",
|
|
146
|
+
to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),
|
|
147
|
+
amount: u64le(data, 4)
|
|
148
|
+
};
|
|
149
|
+
return { kind: "other" };
|
|
150
|
+
}
|
|
151
|
+
if (program === PROGRAM_IDS.computeBudget) {
|
|
152
|
+
if (data.length === 5 && data[0] === 2) return {
|
|
153
|
+
kind: "cu-limit",
|
|
154
|
+
units: u32le(data, 1)
|
|
155
|
+
};
|
|
156
|
+
if (data.length === 9 && data[0] === 3) return {
|
|
157
|
+
kind: "cu-price",
|
|
158
|
+
microLamports: u64le(data, 1)
|
|
159
|
+
};
|
|
160
|
+
return { kind: "other" };
|
|
161
|
+
}
|
|
162
|
+
if (program === PROGRAM_IDS.associatedToken) {
|
|
163
|
+
if (data.length === 1 && data[0] === 0) return { kind: "ata-create" };
|
|
164
|
+
if (data.length === 1 && data[0] === 1) return { kind: "ata-create-idempotent" };
|
|
165
|
+
return { kind: "other" };
|
|
166
|
+
}
|
|
167
|
+
if (program === PROGRAM_IDS.token || program === PROGRAM_IDS.token2022) {
|
|
168
|
+
if (data.length === 10 && data[0] === 12) return {
|
|
169
|
+
kind: "token-transfer-checked",
|
|
170
|
+
amount: u64le(data, 1),
|
|
171
|
+
decimals: data[9],
|
|
172
|
+
to: resolveAccountIndex(parsed, ix.accountIndices[2] ?? 0, lookups),
|
|
173
|
+
mint: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups)
|
|
174
|
+
};
|
|
175
|
+
if (data.length === 9 && data[0] === 4) return {
|
|
176
|
+
kind: "token-approve",
|
|
177
|
+
amount: u64le(data, 1),
|
|
178
|
+
to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups)
|
|
179
|
+
};
|
|
180
|
+
return { kind: "other" };
|
|
181
|
+
}
|
|
182
|
+
if (program === PROGRAM_IDS.stake) return { kind: "stake" };
|
|
183
|
+
return { kind: "other" };
|
|
184
|
+
};
|
|
185
|
+
const FULL_KINDS = /* @__PURE__ */ new Set([
|
|
186
|
+
"system-transfer",
|
|
187
|
+
"cu-limit",
|
|
188
|
+
"cu-price",
|
|
189
|
+
"ata-create",
|
|
190
|
+
"ata-create-idempotent"
|
|
191
|
+
]);
|
|
192
|
+
const classify = (parsed, calls, network, table) => {
|
|
193
|
+
if (parsed.lookupCount > 0) return "partial";
|
|
194
|
+
let allFull = true;
|
|
195
|
+
for (const call of calls) {
|
|
196
|
+
if (call.kind === "other") return "opaque";
|
|
197
|
+
if (call.kind === "token-approve" || call.kind === "stake") allFull = false;
|
|
198
|
+
if (call.kind === "token-transfer-checked" && lookupSolanaToken(table, network, call.mint ?? "") === void 0) allFull = false;
|
|
199
|
+
if (!FULL_KINDS.has(call.kind) && call.kind !== "token-transfer-checked" && call.kind !== "token-approve" && call.kind !== "stake") return "opaque";
|
|
200
|
+
}
|
|
201
|
+
return allFull ? "full" : "partial";
|
|
202
|
+
};
|
|
203
|
+
const feeLamports = (parsed, calls) => {
|
|
204
|
+
const limit = calls.find((c) => c.kind === "cu-limit")?.units;
|
|
205
|
+
const price = calls.find((c) => c.kind === "cu-price")?.microLamports;
|
|
206
|
+
if (limit === void 0 || price === void 0) return;
|
|
207
|
+
return 5000n * BigInt(parsed.numRequiredSignatures) + (price * BigInt(limit) + 999999n) / 1000000n;
|
|
208
|
+
};
|
|
209
|
+
const decodeTransaction = (request, signer, table) => {
|
|
210
|
+
const parsed = parseCompiledMessage(request.message);
|
|
211
|
+
const lookups = request.lookupTables?.map((t) => ({
|
|
212
|
+
address: t.address,
|
|
213
|
+
addresses: t.addresses
|
|
214
|
+
}));
|
|
215
|
+
const calls = parsed.instructions.map((ix) => classifyIx(parsed, ix, lookups));
|
|
216
|
+
const verifiability = classify(parsed, calls, request.network, table);
|
|
217
|
+
const outflows = [];
|
|
218
|
+
const approvals = [];
|
|
219
|
+
for (const call of calls) {
|
|
220
|
+
if (call.kind === "system-transfer" && call.to !== void 0) {
|
|
221
|
+
const [source] = parsed.staticAccounts;
|
|
222
|
+
if (source === signer) outflows.push({
|
|
223
|
+
to: call.to,
|
|
224
|
+
amount: {
|
|
225
|
+
asset: LAMPORTS_ASSET,
|
|
226
|
+
amount: (call.amount ?? 0n).toString(10)
|
|
227
|
+
},
|
|
228
|
+
verified: true
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if (call.kind === "token-transfer-checked") {
|
|
232
|
+
const token = lookupSolanaToken(table, request.network, call.mint ?? "");
|
|
233
|
+
outflows.push({
|
|
234
|
+
to: call.to ?? "",
|
|
235
|
+
amount: {
|
|
236
|
+
asset: call.mint ?? "",
|
|
237
|
+
amount: (call.amount ?? 0n).toString(10),
|
|
238
|
+
...token === void 0 ? {} : {
|
|
239
|
+
symbol: token.symbol,
|
|
240
|
+
decimals: token.decimals
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
verified: token !== void 0
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
if (call.kind === "token-approve") approvals.push({
|
|
247
|
+
asset: call.mint ?? "",
|
|
248
|
+
spender: call.to ?? "",
|
|
249
|
+
amount: (call.amount ?? 0n).toString(10),
|
|
250
|
+
unlimited: false,
|
|
251
|
+
verified: false
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const fee = feeLamports(parsed, calls);
|
|
255
|
+
return {
|
|
256
|
+
family: "solana",
|
|
257
|
+
network: request.network,
|
|
258
|
+
summary: outflows.length > 0 ? "transfer" : "contract-call",
|
|
259
|
+
outflows,
|
|
260
|
+
approvals,
|
|
261
|
+
fee: fee === void 0 ? void 0 : { max: {
|
|
262
|
+
asset: LAMPORTS_ASSET,
|
|
263
|
+
amount: fee.toString(10)
|
|
264
|
+
} },
|
|
265
|
+
warnings: [],
|
|
266
|
+
verifiability
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
/** What the signer can guarantee about this request (WD-065). */
|
|
270
|
+
const verifiabilitySolana = (request, signer, table = solanaTokenTable) => decodeSolana(request, signer, table).verifiability;
|
|
271
|
+
const decodeSolana = (request, signer, table = solanaTokenTable) => decodeTransaction(request, signer, table);
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/solana/token2022.ts
|
|
274
|
+
/** SPL Token-2022 mint-account TLV extension type numbers (spl-token-2022 `ExtensionType`). */
|
|
275
|
+
const EXT = {
|
|
276
|
+
transferFeeConfig: 1,
|
|
277
|
+
confidentialTransferMint: 4,
|
|
278
|
+
defaultAccountState: 6,
|
|
279
|
+
nonTransferable: 9,
|
|
280
|
+
cpiGuard: 11,
|
|
281
|
+
permanentDelegate: 12,
|
|
282
|
+
transferHook: 14,
|
|
283
|
+
confidentialTransferFee: 16,
|
|
284
|
+
confidentialTransferFeeAmount: 17
|
|
285
|
+
};
|
|
286
|
+
const u64 = (v) => new DataView(v.buffer, v.byteOffset, 8).getBigUint64(0, true);
|
|
287
|
+
const u16 = (v) => new DataView(v.buffer, v.byteOffset, 2).getUint16(0, true);
|
|
288
|
+
const ACCOUNT_TYPE_MINT = 1;
|
|
289
|
+
const TYPE_OFFSET = 165;
|
|
290
|
+
/**
|
|
291
|
+
* Parse the extension region of a full Token-2022 mint account. The account is the 82-byte mint
|
|
292
|
+
* base, zero padding up to byte 165, the account-type byte (`1` = Mint) at 165, then the TLV region
|
|
293
|
+
* at 166 — each entry `u16 type, u16 len, len bytes`. Returns a typed summary; extensions this
|
|
294
|
+
* layer does not read are reported by type number in `unknown` rather than parsed.
|
|
295
|
+
*/
|
|
296
|
+
const parseMintExtensions = (data, epoch) => {
|
|
297
|
+
if (data.length <= 166 || data[TYPE_OFFSET] !== ACCOUNT_TYPE_MINT) return {};
|
|
298
|
+
const tlv = data.subarray(166);
|
|
299
|
+
const out = { unknown: [] };
|
|
300
|
+
let offset = 0;
|
|
301
|
+
while (offset + 2 <= tlv.length) {
|
|
302
|
+
const type = u16(tlv.subarray(offset, offset + 2));
|
|
303
|
+
if (type === 0) break;
|
|
304
|
+
if (offset + 4 > tlv.length) throw new ChainError("invalid-request", `mint extension ${type} truncated`);
|
|
305
|
+
const len = u16(tlv.subarray(offset + 2, offset + 4));
|
|
306
|
+
offset += 4;
|
|
307
|
+
if (offset + len > tlv.length) throw new ChainError("invalid-request", `mint extension ${type} truncated`);
|
|
308
|
+
const body = tlv.subarray(offset, offset + len);
|
|
309
|
+
offset += len;
|
|
310
|
+
if (type === EXT.transferFeeConfig && len >= 108) {
|
|
311
|
+
const olderMax = u64(body.subarray(80));
|
|
312
|
+
const olderBps = u16(body.subarray(88));
|
|
313
|
+
const newerEpoch = u64(body.subarray(90));
|
|
314
|
+
const newerMax = u64(body.subarray(98));
|
|
315
|
+
const newerBps = u16(body.subarray(106));
|
|
316
|
+
const active = newerEpoch <= epoch ? {
|
|
317
|
+
bps: newerBps,
|
|
318
|
+
max: newerMax
|
|
319
|
+
} : {
|
|
320
|
+
bps: olderBps,
|
|
321
|
+
max: olderMax
|
|
322
|
+
};
|
|
323
|
+
if (active.bps !== 0 || active.max !== 0n) out.transferFee = {
|
|
324
|
+
basisPoints: active.bps,
|
|
325
|
+
maximumFee: active.max
|
|
326
|
+
};
|
|
327
|
+
} else if (type === EXT.transferHook && len >= 64) out.transferHook = { programId: body.subarray(32, 64) };
|
|
328
|
+
else if (type === EXT.permanentDelegate && len >= 32) {
|
|
329
|
+
const delegate = body.subarray(0, 32);
|
|
330
|
+
if (delegate.some((b) => b !== 0)) out.permanentDelegate = { delegate };
|
|
331
|
+
} else if (type === EXT.nonTransferable) out.nonTransferable = true;
|
|
332
|
+
else if (type === EXT.confidentialTransferMint || type === EXT.confidentialTransferFee || type === EXT.confidentialTransferFeeAmount) out.confidential = true;
|
|
333
|
+
else out.unknown.push(type);
|
|
334
|
+
}
|
|
335
|
+
return out.unknown.length === 0 ? out : {
|
|
336
|
+
...out,
|
|
337
|
+
unknown: out.unknown
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Net amount a recipient gets after the current-epoch transfer fee, `amt − min(amt*bps/10000,
|
|
342
|
+
* max)`.
|
|
343
|
+
*/
|
|
344
|
+
const netAfterTransferFee = (amount, bps, max) => {
|
|
345
|
+
const fee = amount * BigInt(bps) / 10000n;
|
|
346
|
+
return amount - (fee > max ? max : fee);
|
|
347
|
+
};
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/solana/verify.ts
|
|
350
|
+
/**
|
|
351
|
+
* Ed25519 signature verification for `chain.sign` results: the host checks the kernel's 64-byte
|
|
352
|
+
* signature against the message and the account address returned by `wallet.accounts` — a wrong
|
|
353
|
+
* signer fails closed.
|
|
354
|
+
*/
|
|
355
|
+
/** Whether `signature` is a valid ed25519 signature of `message` by the key behind `address`. */
|
|
356
|
+
const verifySolanaSignature = (message, signature, accountAddress) => {
|
|
357
|
+
if (signature.length !== 64) return false;
|
|
358
|
+
try {
|
|
359
|
+
return ed25519.verify(signature, message, new Uint8Array(getAddressEncoder().encode(address(accountAddress))));
|
|
360
|
+
} catch {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/solana/index.ts
|
|
366
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
367
|
+
const isAccountRef = (value) => {
|
|
368
|
+
if (!isRecord(value) || typeof value["kind"] !== "string") return false;
|
|
369
|
+
if (value["kind"] === "hd") return typeof value["walletId"] === "string" && typeof value["groupIndex"] === "number" && typeof value["template"] === "string";
|
|
370
|
+
return value["kind"] === "imported" && typeof value["keyId"] === "string" && typeof value["family"] === "string";
|
|
371
|
+
};
|
|
372
|
+
const solanaNetwork = (network) => {
|
|
373
|
+
if (!SOLANA_NETWORKS.includes(network)) throw new ChainError("unsupported", `unknown Solana network: ${network}`);
|
|
374
|
+
};
|
|
375
|
+
const validateLookupTablesRaw = (tables) => {
|
|
376
|
+
if (tables === void 0) return;
|
|
377
|
+
if (!Array.isArray(tables)) throw new ChainError("unknown-field", "lookupTables must be an array");
|
|
378
|
+
const parsed = tables.map((t) => {
|
|
379
|
+
if (!isRecord(t) || typeof t["address"] !== "string" || !Array.isArray(t["addresses"])) throw new ChainError("unknown-field", "lookupTables entries must be { address, addresses }");
|
|
380
|
+
const addresses = t["addresses"].map((a) => {
|
|
381
|
+
if (typeof a !== "string") throw new ChainError("invalid-address", "lookup table addresses must be strings");
|
|
382
|
+
return a;
|
|
383
|
+
});
|
|
384
|
+
return {
|
|
385
|
+
address: t["address"],
|
|
386
|
+
addresses
|
|
387
|
+
};
|
|
388
|
+
});
|
|
389
|
+
validateLookupTables(parsed);
|
|
390
|
+
return parsed;
|
|
391
|
+
};
|
|
392
|
+
/**
|
|
393
|
+
* Normalizes a Solana sign request. `signer` is the fee payer the wallet is about to sign for — the
|
|
394
|
+
* message must declare it as the first static account. A raw `solana.message` must not decode as a
|
|
395
|
+
* transaction message (chains.mdx rule — a bytes-to-sign path that produces a transaction signature
|
|
396
|
+
* is a wallet-drainer). Idempotent.
|
|
397
|
+
*/
|
|
398
|
+
const normalizeSolana = (request, signer) => {
|
|
399
|
+
if (!isRecord(request) || typeof request["kind"] !== "string") throw new ChainError("invalid-request", "request must be an object with a kind");
|
|
400
|
+
const { network } = request;
|
|
401
|
+
const { account } = request;
|
|
402
|
+
if (typeof network !== "string") throw new ChainError("invalid-request", "request.network must be a string");
|
|
403
|
+
if (!isAccountRef(account)) throw new ChainError("invalid-request", "request.account must be an AccountRef");
|
|
404
|
+
solanaNetwork(network);
|
|
405
|
+
if (!isSolanaAddress(signer)) throw new ChainError("invalid-address", "signer is not a base58 address");
|
|
406
|
+
const { message } = request;
|
|
407
|
+
if (!(message instanceof Uint8Array)) throw new ChainError("invalid-request", "message must be bytes");
|
|
408
|
+
if (request["kind"] === "solana.transaction") {
|
|
409
|
+
const lookupTables = validateLookupTablesRaw(request["lookupTables"]);
|
|
410
|
+
const [feePayer] = parseCompiledMessage(message).staticAccounts;
|
|
411
|
+
if (feePayer === void 0 || feePayer !== signer) throw new ChainError("fee-payer-mismatch", "signer is not the transaction fee payer");
|
|
412
|
+
return {
|
|
413
|
+
kind: "solana.transaction",
|
|
414
|
+
network,
|
|
415
|
+
account,
|
|
416
|
+
message,
|
|
417
|
+
...lookupTables === void 0 ? {} : { lookupTables: lookupTables.map((t) => ({
|
|
418
|
+
address: t.address,
|
|
419
|
+
addresses: [...t.addresses]
|
|
420
|
+
})) }
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
if (request["kind"] === "solana.message") {
|
|
424
|
+
const { format } = request;
|
|
425
|
+
if (format !== "raw") throw new ChainError("unsupported", `solana.message format ${String(format)} is not supported`);
|
|
426
|
+
let decodesAsTransaction = true;
|
|
427
|
+
try {
|
|
428
|
+
parseCompiledMessage(message);
|
|
429
|
+
} catch {
|
|
430
|
+
decodesAsTransaction = false;
|
|
431
|
+
}
|
|
432
|
+
if (decodesAsTransaction) throw new ChainError("invalid-request", "solana.message payload decodes as a transaction message — use solana.transaction");
|
|
433
|
+
return {
|
|
434
|
+
kind: "solana.message",
|
|
435
|
+
network,
|
|
436
|
+
account,
|
|
437
|
+
message,
|
|
438
|
+
format
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
throw new ChainError("unsupported", `unsupported sign request kind: ${request["kind"]}`);
|
|
442
|
+
};
|
|
443
|
+
//#endregion
|
|
444
|
+
export { EXT, PROGRAM_IDS, SOLANA_NETWORKS, decodeSolana, isSolanaAddress, netAfterTransferFee, normalizeSolana, parseCompiledMessage, parseMintExtensions, solanaAddressFromPublicKey, solanaTokenTable, verifiabilitySolana, verifySolanaSignature };
|
|
445
|
+
|
|
446
|
+
//# sourceMappingURL=solana.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana.mjs","names":["decoder","isRecord","u64"],"sources":["../src/solana/ids.ts","../src/solana/message.ts","../src/solana/tokens.ts","../src/solana/decode.ts","../src/solana/token2022.ts","../src/solana/verify.ts","../src/solana/index.ts"],"sourcesContent":["import { getAddressDecoder } from \"@solana/addresses\";\n\nimport { ChainError } from \"../index.ts\";\n\n/** Well-known Solana program ids (base58, 32 bytes) — frozen constants. */\nexport const PROGRAM_IDS: Readonly<{\n system: string;\n computeBudget: string;\n associatedToken: string;\n token: string;\n token2022: string;\n stake: string;\n}> = Object.freeze({\n system: \"11111111111111111111111111111111\",\n computeBudget: \"ComputeBudget111111111111111111111111111111\",\n associatedToken: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n token: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n token2022: \"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb\",\n stake: \"Stake11111111111111111111111111111111111111\",\n});\n\n/**\n * CAIP-2 ids the wallet knows. The wire message itself carries no network marker — `network` is the\n * only declaration and cannot be proven from the bytes.\n */\nexport const SOLANA_NETWORKS: ReadonlyArray<string> = Object.freeze([\n \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\",\n \"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1\",\n] as const);\n\nconst BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\n\nexport const isSolanaAddress = (value: string): boolean => BASE58.test(value);\n\nconst decoder = getAddressDecoder();\n\n/** Base58-encoded address for a 32-byte ed25519 public key. */\nexport function solanaAddressFromPublicKey(pubkey: Uint8Array): string {\n if (pubkey.length !== 32) {\n throw new ChainError(\"invalid-address\", \"expected a 32-byte ed25519 public key\");\n }\n return decoder.decode(pubkey);\n}\n","import { getCompiledTransactionMessageDecoder } from \"@solana/transaction-messages\";\n\nimport { ChainError } from \"../index.ts\";\nimport { isSolanaAddress } from \"./ids.ts\";\n\nexport const SOLANA_TRANSACTION_MAX_BYTES = 1232;\n\nexport type CompiledIx = {\n readonly programAddressIndex: number;\n readonly accountIndices: ReadonlyArray<number>;\n readonly data: Uint8Array;\n};\n\nexport type ParsedSolanaMessage = {\n readonly version: \"legacy\" | 0;\n readonly numRequiredSignatures: number;\n readonly staticAccounts: ReadonlyArray<string>;\n readonly instructions: ReadonlyArray<CompiledIx>;\n readonly lookupCount: number;\n readonly lookupAddresses: ReadonlyArray<string>;\n};\n\nconst decoder = getCompiledTransactionMessageDecoder();\n\n/**\n * Decodes a compiled wire message; rejects trailing bytes and the 1232-byte transaction limit. The\n * fee payer is `staticAccounts[0]` — every valid transaction signs it.\n */\nexport const parseCompiledMessage = (bytes: Uint8Array): ParsedSolanaMessage => {\n if (bytes.length > SOLANA_TRANSACTION_MAX_BYTES) {\n throw new ChainError(\"invalid-request\", \"compiled message exceeds the 1232-byte limit\");\n }\n if (bytes.length === 0) {\n throw new ChainError(\"invalid-request\", \"compiled message is empty\");\n }\n let decoded: unknown;\n try {\n decoded = decoder.decode(bytes);\n } catch {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const message = asCompiledMessage(decoded);\n const staticAccounts = [...message.staticAccounts];\n const lookups = message.addressTableLookups;\n return {\n version: message.version,\n numRequiredSignatures: message.numSignerAccounts,\n staticAccounts,\n instructions: message.instructions,\n lookupCount: lookups.length,\n lookupAddresses: lookups.map((l) => l.lookupTableAddress),\n };\n};\n\ntype CompiledMessage = {\n readonly version: \"legacy\" | 0;\n readonly numSignerAccounts: number;\n readonly staticAccounts: ReadonlyArray<string>;\n readonly instructions: ReadonlyArray<CompiledIx>;\n readonly addressTableLookups: ReadonlyArray<{\n readonly lookupTableAddress: string;\n readonly readonlyIndexes: ReadonlyArray<number>;\n readonly writableIndexes: ReadonlyArray<number>;\n }>;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isStringArray = (value: unknown): value is ReadonlyArray<string> =>\n Array.isArray(value) && value.every((v) => typeof v === \"string\");\n\nconst isNumberArray = (value: unknown): value is ReadonlyArray<number> =>\n Array.isArray(value) && value.every((v) => typeof v === \"number\");\n\nconst isArrayLike = (value: unknown): value is { readonly length: number } =>\n isRecord(value) && typeof value[\"length\"] === \"number\";\n\nconst isIx = (value: unknown): value is CompiledIx =>\n isRecord(value) &&\n typeof value[\"programAddressIndex\"] === \"number\" &&\n (value[\"accountIndices\"] === undefined ||\n isNumberArray(value[\"accountIndices\"]) ||\n isArrayLike(value[\"accountIndices\"])) &&\n value[\"data\"] instanceof Uint8Array;\n\nconst isLookup = (\n value: unknown,\n): value is {\n lookupTableAddress: string;\n readonlyIndexes: ReadonlyArray<number> | Uint8Array;\n writableIndexes: ReadonlyArray<number> | Uint8Array;\n} =>\n isRecord(value) &&\n typeof value[\"lookupTableAddress\"] === \"string\" &&\n (isNumberArray(value[\"readonlyIndexes\"]) || value[\"readonlyIndexes\"] instanceof Uint8Array) &&\n (isNumberArray(value[\"writableIndexes\"]) || value[\"writableIndexes\"] instanceof Uint8Array);\n\nconst asCompiledMessage = (value: unknown): CompiledMessage => {\n if (!isRecord(value) || !isRecord(value[\"header\"])) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const { header } = value;\n const { staticAccounts } = value;\n const { instructions } = value;\n const lookups = value[\"addressTableLookups\"];\n if (\n typeof header[\"numSignerAccounts\"] !== \"number\" ||\n !isStringArray(staticAccounts) ||\n !Array.isArray(instructions) ||\n !instructions.every(isIx) ||\n (lookups !== undefined && (!Array.isArray(lookups) || !lookups.every(isLookup)))\n ) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const version = value[\"version\"] === 0 ? 0 : \"legacy\";\n const ixs = instructions.map((ix) => {\n if (!isIx(ix)) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const indices = ix.accountIndices;\n return {\n programAddressIndex: ix.programAddressIndex,\n accountIndices: indices === undefined ? [] : [...indices],\n data: ix.data,\n };\n });\n const tables = (lookups ?? []).map((t) => {\n if (!isLookup(t)) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n return {\n lookupTableAddress: t.lookupTableAddress,\n readonlyIndexes: [...t.readonlyIndexes],\n writableIndexes: [...t.writableIndexes],\n };\n });\n return {\n version,\n numSignerAccounts: header[\"numSignerAccounts\"],\n staticAccounts,\n instructions: ixs,\n addressTableLookups: tables,\n };\n};\n\n/**\n * Resolves an account index across static accounts and (request-declared) lookup tables in the\n * compiled lookup order: writable entries then readable.\n */\nexport const resolveAccountIndex = (\n parsed: ParsedSolanaMessage,\n index: number,\n lookups: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): string | undefined => {\n if (index < parsed.staticAccounts.length) {\n return parsed.staticAccounts[index];\n }\n if (lookups === undefined) {\n return undefined;\n }\n let offset = index - parsed.staticAccounts.length;\n for (const table of lookups) {\n if (offset < table.addresses.length) {\n return table.addresses[offset];\n }\n offset -= table.addresses.length;\n }\n return undefined;\n};\n\n/** All declared lookup-table entries must be valid base58 32-byte addresses. */\nexport const validateLookupTables = (\n tables: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): void => {\n if (tables === undefined) {\n return;\n }\n for (const table of tables) {\n if (!isSolanaAddress(table.address) || !table.addresses.every(isSolanaAddress)) {\n throw new ChainError(\n \"invalid-address\",\n \"lookup table entries must be base58 32-byte addresses\",\n );\n }\n }\n};\n","/**\n * Built-in SPL token table, keyed by `network` then mint address. An entry makes a\n * `transferChecked` `full`-verifiable (WD-065), so every entry must come from the issuer's own\n * published list; the source is recorded per issuer below.\n */\n\nexport type SolanaToken = {\n readonly symbol: string;\n readonly decimals: number;\n readonly name?: string;\n};\n\nexport type SolanaTokenTable = Readonly<Record<string, Readonly<Record<string, SolanaToken>>>>;\n\n// Circle USDC on Solana mainnet (SPL Token program mint, 6 decimals), from\n// https://developers.circle.com/stablecoins/usdc-contract-addresses (reviewed 2026-10-30).\nconst USDC: SolanaToken = Object.freeze({ symbol: \"USDC\", decimals: 6, name: \"USD Coin\" });\n\n// Tether USDT on Solana mainnet (SPL Token program mint, 6 decimals), from\n// https://tether.to/en/supported-protocols/ (reviewed 2026-10-31).\nconst USDT: SolanaToken = Object.freeze({ symbol: \"USDT\", decimals: 6, name: \"Tether USD\" });\n\nexport const solanaTokenTable: SolanaTokenTable = Object.freeze({\n \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\": Object.freeze({\n EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: USDC,\n Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB: USDT,\n }),\n});\n\nexport const lookupSolanaToken = (\n table: SolanaTokenTable,\n network: string,\n mint: string,\n): SolanaToken | undefined => table[network]?.[mint];\n","import { getU32Decoder, getU64Decoder } from \"@solana/codecs\";\n\nimport type {\n ApprovalChange,\n AssetFlow,\n DisplayIntent,\n SignRequest,\n Verifiability,\n} from \"../index.ts\";\nimport { PROGRAM_IDS } from \"./ids.ts\";\nimport { parseCompiledMessage, resolveAccountIndex } from \"./message.ts\";\nimport type { ParsedSolanaMessage } from \"./message.ts\";\nimport { lookupSolanaToken, solanaTokenTable } from \"./tokens.ts\";\nimport type { SolanaTokenTable } from \"./tokens.ts\";\n\nconst LAMPORTS_ASSET = \"lamports\";\n\nconst u32 = getU32Decoder();\nconst u64 = getU64Decoder();\nconst u32le = (data: Uint8Array, offset: number): number => u32.decode(data, offset);\nconst u64le = (data: Uint8Array, offset: number): bigint => u64.decode(data, offset);\n\ntype IxCall = {\n readonly kind:\n | \"system-transfer\"\n | \"cu-limit\"\n | \"cu-price\"\n | \"ata-create\"\n | \"ata-create-idempotent\"\n | \"token-transfer-checked\"\n | \"token-approve\"\n | \"stake\"\n | \"other\";\n readonly to?: string | undefined;\n readonly amount?: bigint | undefined;\n readonly decimals?: number | undefined;\n readonly mint?: string | undefined;\n readonly units?: number | undefined;\n readonly microLamports?: bigint | undefined;\n};\n\n/**\n * Classifies one instruction by program + discriminator/layout. Exact-length checks keep\n * non-canonical encodings out of the `full` class.\n */\nconst classifyIx = (\n parsed: ParsedSolanaMessage,\n ix: { programAddressIndex: number; accountIndices: ReadonlyArray<number>; data: Uint8Array },\n lookups: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): IxCall => {\n const program = resolveAccountIndex(parsed, ix.programAddressIndex, lookups);\n const { data } = ix;\n if (program === PROGRAM_IDS.system) {\n if (data.length === 12 && u32le(data, 0) === 2) {\n return {\n kind: \"system-transfer\",\n to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n amount: u64le(data, 4),\n };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.computeBudget) {\n if (data.length === 5 && data[0] === 2) {\n return { kind: \"cu-limit\", units: u32le(data, 1) };\n }\n if (data.length === 9 && data[0] === 3) {\n return { kind: \"cu-price\", microLamports: u64le(data, 1) };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.associatedToken) {\n if (data.length === 1 && data[0] === 0) {\n return { kind: \"ata-create\" };\n }\n if (data.length === 1 && data[0] === 1) {\n return { kind: \"ata-create-idempotent\" };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.token || program === PROGRAM_IDS.token2022) {\n if (data.length === 10 && data[0] === 12) {\n return {\n kind: \"token-transfer-checked\",\n amount: u64le(data, 1),\n decimals: data[9],\n to: resolveAccountIndex(parsed, ix.accountIndices[2] ?? 0, lookups),\n mint: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n };\n }\n if (data.length === 9 && data[0] === 4) {\n return {\n kind: \"token-approve\",\n amount: u64le(data, 1),\n to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.stake) {\n return { kind: \"stake\" };\n }\n return { kind: \"other\" };\n};\n\nconst FULL_KINDS = new Set([\n \"system-transfer\",\n \"cu-limit\",\n \"cu-price\",\n \"ata-create\",\n \"ata-create-idempotent\",\n]);\n\nconst classify = (\n parsed: ParsedSolanaMessage,\n calls: ReadonlyArray<IxCall>,\n network: string,\n table: SolanaTokenTable,\n): Verifiability => {\n if (parsed.lookupCount > 0) {\n return \"partial\";\n }\n let allFull = true;\n for (const call of calls) {\n if (call.kind === \"other\") {\n return \"opaque\";\n }\n if (call.kind === \"token-approve\" || call.kind === \"stake\") {\n allFull = false;\n }\n if (\n call.kind === \"token-transfer-checked\" &&\n lookupSolanaToken(table, network, call.mint ?? \"\") === undefined\n ) {\n allFull = false;\n }\n if (\n !FULL_KINDS.has(call.kind) &&\n call.kind !== \"token-transfer-checked\" &&\n call.kind !== \"token-approve\" &&\n call.kind !== \"stake\"\n ) {\n return \"opaque\";\n }\n }\n return allFull ? \"full\" : \"partial\";\n};\n\nconst feeLamports = (\n parsed: ParsedSolanaMessage,\n calls: ReadonlyArray<IxCall>,\n): bigint | undefined => {\n const limit = calls.find((c) => c.kind === \"cu-limit\")?.units;\n const price = calls.find((c) => c.kind === \"cu-price\")?.microLamports;\n if (limit === undefined || price === undefined) {\n return undefined;\n }\n const signatures = BigInt(parsed.numRequiredSignatures);\n return 5000n * signatures + (price * BigInt(limit) + 999_999n) / 1_000_000n;\n};\n\nconst decodeTransaction = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable,\n): DisplayIntent => {\n const parsed = parseCompiledMessage(request.message);\n const lookups = request.lookupTables?.map((t) => ({\n address: t.address,\n addresses: t.addresses,\n }));\n const calls = parsed.instructions.map((ix) => classifyIx(parsed, ix, lookups));\n const verifiability = classify(parsed, calls, request.network, table);\n const outflows: AssetFlow[] = [];\n const approvals: ApprovalChange[] = [];\n for (const call of calls) {\n if (call.kind === \"system-transfer\" && call.to !== undefined) {\n const [source] = parsed.staticAccounts;\n if (source === signer) {\n outflows.push({\n to: call.to,\n amount: { asset: LAMPORTS_ASSET, amount: (call.amount ?? 0n).toString(10) },\n verified: true,\n });\n }\n }\n if (call.kind === \"token-transfer-checked\") {\n const token = lookupSolanaToken(table, request.network, call.mint ?? \"\");\n outflows.push({\n to: call.to ?? \"\",\n amount: {\n asset: call.mint ?? \"\",\n amount: (call.amount ?? 0n).toString(10),\n ...(token === undefined ? {} : { symbol: token.symbol, decimals: token.decimals }),\n },\n verified: token !== undefined,\n });\n }\n if (call.kind === \"token-approve\") {\n approvals.push({\n asset: call.mint ?? \"\",\n spender: call.to ?? \"\",\n amount: (call.amount ?? 0n).toString(10),\n unlimited: false,\n verified: false,\n });\n }\n }\n const fee = feeLamports(parsed, calls);\n return {\n family: \"solana\",\n network: request.network,\n summary: outflows.length > 0 ? \"transfer\" : \"contract-call\",\n outflows,\n approvals,\n fee:\n fee === undefined ? undefined : { max: { asset: LAMPORTS_ASSET, amount: fee.toString(10) } },\n warnings: [],\n verifiability,\n };\n};\n\n/** What the signer can guarantee about this request (WD-065). */\nexport const verifiabilitySolana = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable = solanaTokenTable,\n): Verifiability => decodeSolana(request, signer, table).verifiability;\n\nexport const decodeSolana = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable = solanaTokenTable,\n): DisplayIntent => decodeTransaction(request, signer, table);\n","import { ChainError } from \"../index.ts\";\n\n/** SPL Token-2022 mint-account TLV extension type numbers (spl-token-2022 `ExtensionType`). */\nexport const EXT = {\n transferFeeConfig: 1,\n confidentialTransferMint: 4,\n defaultAccountState: 6,\n nonTransferable: 9,\n cpiGuard: 11,\n permanentDelegate: 12,\n transferHook: 14,\n confidentialTransferFee: 16,\n confidentialTransferFeeAmount: 17,\n} as const;\n\nexport type MintExtensionSummary = {\n /** The current-epoch fee from TransferFeeConfig (basis points and the maximum fee), if set. */\n readonly transferFee?: { readonly basisPoints: number; readonly maximumFee: bigint };\n readonly transferHook?: { readonly programId: Uint8Array };\n readonly permanentDelegate?: { readonly delegate: Uint8Array };\n readonly nonTransferable?: boolean;\n /** True when a ConfidentialTransfer extension is present — confidential amounts are not supported. */\n readonly confidential?: boolean;\n /** Extension type numbers we do not parse (informational). */\n readonly unknown?: ReadonlyArray<number>;\n};\n\nconst u64 = (v: Uint8Array): bigint =>\n new DataView(v.buffer, v.byteOffset, 8).getBigUint64(0, true);\nconst u16 = (v: Uint8Array): number => new DataView(v.buffer, v.byteOffset, 2).getUint16(0, true);\n\nconst ACCOUNT_TYPE_MINT = 1;\nconst TYPE_OFFSET = 165;\n\n/**\n * Parse the extension region of a full Token-2022 mint account. The account is the 82-byte mint\n * base, zero padding up to byte 165, the account-type byte (`1` = Mint) at 165, then the TLV region\n * at 166 — each entry `u16 type, u16 len, len bytes`. Returns a typed summary; extensions this\n * layer does not read are reported by type number in `unknown` rather than parsed.\n */\nexport const parseMintExtensions = (data: Uint8Array, epoch: bigint): MintExtensionSummary => {\n if (data.length <= TYPE_OFFSET + 1 || data[TYPE_OFFSET] !== ACCOUNT_TYPE_MINT) {\n return {};\n }\n const tlv = data.subarray(TYPE_OFFSET + 1);\n const out: {\n transferFee?: { basisPoints: number; maximumFee: bigint };\n transferHook?: { programId: Uint8Array };\n permanentDelegate?: { delegate: Uint8Array };\n nonTransferable?: boolean;\n confidential?: boolean;\n unknown: number[];\n } = { unknown: [] };\n let offset = 0;\n while (offset + 2 <= tlv.length) {\n const type = u16(tlv.subarray(offset, offset + 2));\n // Uninitialized entries are a u16 marker only — the program stops scanning there and\n // treats the rest as unused space.\n if (type === 0) {\n break;\n }\n if (offset + 4 > tlv.length) {\n throw new ChainError(\"invalid-request\", `mint extension ${type} truncated`);\n }\n const len = u16(tlv.subarray(offset + 2, offset + 4));\n offset += 4;\n if (offset + len > tlv.length) {\n throw new ChainError(\"invalid-request\", `mint extension ${type} truncated`);\n }\n const body = tlv.subarray(offset, offset + len);\n offset += len;\n if (type === EXT.transferFeeConfig && len >= 108) {\n // OptionalNonZeroPubkey×2 (32 B each, zero = none) + u64 withheld + TransferFee×2\n // (18 B each: u64 epoch + u64 maximumFee + u16 basisPoints). The current-epoch fee is\n // the \"newer\" record once its activation epoch is reached, else the \"older\" one.\n const olderMax = u64(body.subarray(80));\n const olderBps = u16(body.subarray(88));\n const newerEpoch = u64(body.subarray(90));\n const newerMax = u64(body.subarray(98));\n const newerBps = u16(body.subarray(106));\n const active =\n newerEpoch <= epoch ? { bps: newerBps, max: newerMax } : { bps: olderBps, max: olderMax };\n if (active.bps !== 0 || active.max !== 0n) {\n out.transferFee = { basisPoints: active.bps, maximumFee: active.max };\n }\n } else if (type === EXT.transferHook && len >= 64) {\n // OptionalNonZeroPubkey authority (32) + program id (32).\n const programId = body.subarray(32, 64);\n out.transferHook = { programId };\n } else if (type === EXT.permanentDelegate && len >= 32) {\n // OptionalNonZeroPubkey delegate (32) — all-zero means none.\n const delegate = body.subarray(0, 32);\n if (delegate.some((b) => b !== 0)) {\n out.permanentDelegate = { delegate };\n }\n } else if (type === EXT.nonTransferable) {\n out.nonTransferable = true;\n } else if (\n type === EXT.confidentialTransferMint ||\n type === EXT.confidentialTransferFee ||\n type === EXT.confidentialTransferFeeAmount\n ) {\n out.confidential = true;\n } else {\n out.unknown.push(type);\n }\n }\n return out.unknown.length === 0 ? out : { ...out, unknown: out.unknown };\n};\n\n/**\n * Net amount a recipient gets after the current-epoch transfer fee, `amt − min(amt*bps/10000,\n * max)`.\n */\nexport const netAfterTransferFee = (amount: bigint, bps: number, max: bigint): bigint => {\n const fee = (amount * BigInt(bps)) / 10_000n;\n return amount - (fee > max ? max : fee);\n};\n","/**\n * Ed25519 signature verification for `chain.sign` results: the host checks the kernel's 64-byte\n * signature against the message and the account address returned by `wallet.accounts` — a wrong\n * signer fails closed.\n */\nimport { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { address, getAddressEncoder } from \"@solana/addresses\";\n\n/** Whether `signature` is a valid ed25519 signature of `message` by the key behind `address`. */\nexport const verifySolanaSignature = (\n message: Uint8Array,\n signature: Uint8Array,\n accountAddress: string,\n): boolean => {\n if (signature.length !== 64) {\n return false;\n }\n try {\n return ed25519.verify(\n signature,\n message,\n new Uint8Array(getAddressEncoder().encode(address(accountAddress))),\n );\n } catch {\n return false;\n }\n};\n","import { ChainError } from \"../index.ts\";\nimport type { AccountRef, SignRequest } from \"../index.ts\";\nimport { SOLANA_NETWORKS, isSolanaAddress } from \"./ids.ts\";\nimport { parseCompiledMessage, validateLookupTables } from \"./message.ts\";\n\nexport {\n PROGRAM_IDS,\n SOLANA_NETWORKS,\n isSolanaAddress,\n solanaAddressFromPublicKey,\n} from \"./ids.ts\";\nexport { decodeSolana, verifiabilitySolana } from \"./decode.ts\";\nexport { EXT, parseMintExtensions, netAfterTransferFee } from \"./token2022.ts\";\nexport type { MintExtensionSummary } from \"./token2022.ts\";\nexport { parseCompiledMessage } from \"./message.ts\";\nexport { verifySolanaSignature } from \"./verify.ts\";\nexport type { SolanaTokenTable } from \"./tokens.ts\";\nexport { solanaTokenTable } from \"./tokens.ts\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isAccountRef = (value: unknown): value is AccountRef => {\n if (!isRecord(value) || typeof value[\"kind\"] !== \"string\") {\n return false;\n }\n if (value[\"kind\"] === \"hd\") {\n return (\n typeof value[\"walletId\"] === \"string\" &&\n typeof value[\"groupIndex\"] === \"number\" &&\n typeof value[\"template\"] === \"string\"\n );\n }\n return (\n value[\"kind\"] === \"imported\" &&\n typeof value[\"keyId\"] === \"string\" &&\n typeof value[\"family\"] === \"string\"\n );\n};\n\nconst solanaNetwork = (network: string): void => {\n if (!SOLANA_NETWORKS.includes(network)) {\n throw new ChainError(\"unsupported\", `unknown Solana network: ${network}`);\n }\n};\n\ntype LookupTable = {\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n};\n\nconst validateLookupTablesRaw = (tables: unknown): ReadonlyArray<LookupTable> | undefined => {\n if (tables === undefined) {\n return undefined;\n }\n if (!Array.isArray(tables)) {\n throw new ChainError(\"unknown-field\", \"lookupTables must be an array\");\n }\n const parsed = tables.map((t): LookupTable => {\n if (!isRecord(t) || typeof t[\"address\"] !== \"string\" || !Array.isArray(t[\"addresses\"])) {\n throw new ChainError(\"unknown-field\", \"lookupTables entries must be { address, addresses }\");\n }\n const addresses = t[\"addresses\"].map((a): string => {\n if (typeof a !== \"string\") {\n throw new ChainError(\"invalid-address\", \"lookup table addresses must be strings\");\n }\n return a;\n });\n return { address: t[\"address\"], addresses };\n });\n validateLookupTables(parsed);\n return parsed;\n};\n\n/**\n * Normalizes a Solana sign request. `signer` is the fee payer the wallet is about to sign for — the\n * message must declare it as the first static account. A raw `solana.message` must not decode as a\n * transaction message (chains.mdx rule — a bytes-to-sign path that produces a transaction signature\n * is a wallet-drainer). Idempotent.\n */\nexport const normalizeSolana = (request: unknown, signer: string): SignRequest => {\n if (!isRecord(request) || typeof request[\"kind\"] !== \"string\") {\n throw new ChainError(\"invalid-request\", \"request must be an object with a kind\");\n }\n const { network } = request;\n const { account } = request;\n if (typeof network !== \"string\") {\n throw new ChainError(\"invalid-request\", \"request.network must be a string\");\n }\n if (!isAccountRef(account)) {\n throw new ChainError(\"invalid-request\", \"request.account must be an AccountRef\");\n }\n solanaNetwork(network);\n if (!isSolanaAddress(signer)) {\n throw new ChainError(\"invalid-address\", \"signer is not a base58 address\");\n }\n const { message } = request;\n if (!(message instanceof Uint8Array)) {\n throw new ChainError(\"invalid-request\", \"message must be bytes\");\n }\n if (request[\"kind\"] === \"solana.transaction\") {\n const lookupTables = validateLookupTablesRaw(request[\"lookupTables\"]);\n const parsed = parseCompiledMessage(message);\n const [feePayer] = parsed.staticAccounts;\n if (feePayer === undefined || feePayer !== signer) {\n throw new ChainError(\"fee-payer-mismatch\", \"signer is not the transaction fee payer\");\n }\n return {\n kind: \"solana.transaction\",\n network,\n account,\n message,\n ...(lookupTables === undefined\n ? {}\n : {\n lookupTables: (\n lookupTables as ReadonlyArray<{\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n }>\n ).map((t) => ({ address: t.address, addresses: [...t.addresses] })),\n }),\n };\n }\n if (request[\"kind\"] === \"solana.message\") {\n const { format } = request;\n if (format !== \"raw\") {\n throw new ChainError(\n \"unsupported\",\n `solana.message format ${String(format)} is not supported`,\n );\n }\n let decodesAsTransaction = true;\n try {\n parseCompiledMessage(message);\n } catch {\n decodesAsTransaction = false;\n }\n if (decodesAsTransaction) {\n throw new ChainError(\n \"invalid-request\",\n \"solana.message payload decodes as a transaction message — use solana.transaction\",\n );\n }\n return { kind: \"solana.message\", network, account, message, format };\n }\n throw new ChainError(\"unsupported\", `unsupported sign request kind: ${request[\"kind\"]}`);\n};\n"],"mappings":";;;;;;;AAKA,MAAa,cAOR,OAAO,OAAO;CACjB,QAAQ;CACR,eAAe;CACf,iBAAiB;CACjB,OAAO;CACP,WAAW;CACX,OAAO;AACT,CAAC;;;;;AAMD,MAAa,kBAAyC,OAAO,OAAO,CAClE,2CACA,yCACF,CAAU;AAEV,MAAM,SAAS;AAEf,MAAa,mBAAmB,UAA2B,OAAO,KAAK,KAAK;AAE5E,MAAMA,YAAU,kBAAkB;;AAGlC,SAAgB,2BAA2B,QAA4B;CACrE,IAAI,OAAO,WAAW,IACpB,MAAM,IAAI,WAAW,mBAAmB,uCAAuC;CAEjF,OAAOA,UAAQ,OAAO,MAAM;AAC9B;ACpBA,MAAM,UAAU,qCAAqC;;;;;AAMrD,MAAa,wBAAwB,UAA2C;CAC9E,IAAI,MAAM,SAAA,MACR,MAAM,IAAI,WAAW,mBAAmB,8CAA8C;CAExF,IAAI,MAAM,WAAW,GACnB,MAAM,IAAI,WAAW,mBAAmB,2BAA2B;CAErE,IAAI;CACJ,IAAI;EACF,UAAU,QAAQ,OAAO,KAAK;CAChC,QAAQ;EACN,MAAM,IAAI,WAAW,mBAAmB,mCAAmC;CAC7E;CACA,MAAM,UAAU,kBAAkB,OAAO;CACzC,MAAM,iBAAiB,CAAC,GAAG,QAAQ,cAAc;CACjD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