@qntx/wallet-chains 0.0.0-stage → 0.4.0
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 +71 -0
- package/dist/bitcoin.mjs +632 -0
- package/dist/bitcoin.mjs.map +1 -0
- package/dist/curve-BeDNVVGm.mjs +2865 -0
- package/dist/curve-BeDNVVGm.mjs.map +1 -0
- package/dist/ed25519-DUtI5nWr.mjs +586 -0
- package/dist/ed25519-DUtI5nWr.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 +88 -0
- package/dist/evm.mjs +348 -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-AfNel4WZ.mjs +185 -0
- package/dist/message-AfNel4WZ.mjs.map +1 -0
- package/dist/secp256k1-D0CRzacO.mjs +1384 -0
- package/dist/secp256k1-D0CRzacO.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 +78 -0
- package/dist/solana.mjs +355 -0
- package/dist/solana.mjs.map +1 -0
- package/dist/typed-data-D28VBOIm.mjs +464 -0
- package/dist/typed-data-D28VBOIm.mjs.map +1 -0
- package/package.json +98 -4
package/dist/evm.mjs
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { ChainError } from "./index.mjs";
|
|
2
|
+
import { a as isCanonicalHex, c as normalizeEvmTransaction, d as isEvmAddress, i as canonicalHex, l as checksumEvmAddress, n as typedDataWarnings, o as isRecord, r as assertHex, s as networkChainId, t as parseTypedData, u as evmAddressFromPublicKey } from "./typed-data-D28VBOIm.mjs";
|
|
3
|
+
import * as TypedData from "ox/TypedData";
|
|
4
|
+
import * as AbiFunction from "ox/AbiFunction";
|
|
5
|
+
import * as Hex from "ox/Hex";
|
|
6
|
+
import * as PersonalMessage from "ox/PersonalMessage";
|
|
7
|
+
import * as Secp256k1 from "ox/Secp256k1";
|
|
8
|
+
import * as Signature from "ox/Signature";
|
|
9
|
+
import * as TxEnvelopeEip1559 from "ox/TxEnvelopeEip1559";
|
|
10
|
+
import * as TxEnvelopeEip2930 from "ox/TxEnvelopeEip2930";
|
|
11
|
+
import * as TxEnvelopeLegacy from "ox/TxEnvelopeLegacy";
|
|
12
|
+
/** The built-in table — empty until official-source review lands the entries. */
|
|
13
|
+
const evmTokenTable = Object.freeze({});
|
|
14
|
+
const lookupEvmToken = (table, chainId, address) => table[String(chainId)]?.[address];
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/evm/decode.ts
|
|
17
|
+
const ERC20_TRANSFER = AbiFunction.from("function transfer(address to, uint256 amount)");
|
|
18
|
+
const ERC20_APPROVE = AbiFunction.from("function approve(address spender, uint256 amount)");
|
|
19
|
+
const ERC20_INCREASE = AbiFunction.from("function increaseAllowance(address spender, uint256 amount)");
|
|
20
|
+
const ERC721_TRANSFER_FROM = AbiFunction.from("function transferFrom(address from, address to, uint256 tokenId)");
|
|
21
|
+
const ERC721_SAFE_FROM = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 tokenId)");
|
|
22
|
+
const ERC1155_SAFE_FROM = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data)");
|
|
23
|
+
const NATIVE_ASSET = "native";
|
|
24
|
+
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
25
|
+
const argAddress = (args, index) => {
|
|
26
|
+
const value = args[index];
|
|
27
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) throw new ChainError("invalid-request", "decoded argument is not an address");
|
|
28
|
+
return checksumEvmAddress(value);
|
|
29
|
+
};
|
|
30
|
+
const argUint = (args, index) => {
|
|
31
|
+
const value = args[index];
|
|
32
|
+
if (typeof value !== "bigint") throw new ChainError("invalid-request", "decoded argument is not a uint256");
|
|
33
|
+
return value;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Decodes `data` as `fn` and verifies the encoding is canonical (re-encoding the decoded args
|
|
37
|
+
* reproduces the input byte-for-byte). Returns undefined on selector mismatch, decode failure or a
|
|
38
|
+
* non-canonical encoding — the caller falls through to the next candidate or the opaque class.
|
|
39
|
+
*/
|
|
40
|
+
const tryCall = (fn, data) => {
|
|
41
|
+
const selector = AbiFunction.getSelector(fn);
|
|
42
|
+
if (!data.toLowerCase().startsWith(selector)) return;
|
|
43
|
+
try {
|
|
44
|
+
assertHex(data, "data");
|
|
45
|
+
const args = AbiFunction.decodeData(fn, data);
|
|
46
|
+
if (!Array.isArray(args)) return;
|
|
47
|
+
return AbiFunction.encodeData(fn, args).toLowerCase() === data.toLowerCase() ? args : void 0;
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const weiAmount = (wei, symbol, decimals) => ({
|
|
53
|
+
asset: NATIVE_ASSET,
|
|
54
|
+
amount: wei.toString(10),
|
|
55
|
+
...symbol === void 0 ? {} : { symbol },
|
|
56
|
+
...decimals === void 0 ? {} : { decimals }
|
|
57
|
+
});
|
|
58
|
+
const feeWei = (tx) => BigInt(tx.gas) * (tx.type === "eip1559" ? BigInt(tx.maxFeePerGas) : BigInt(tx.gasPrice));
|
|
59
|
+
const nativeOutflow = (tx, to) => [{
|
|
60
|
+
to,
|
|
61
|
+
amount: weiAmount(BigInt(tx.value)),
|
|
62
|
+
verified: true
|
|
63
|
+
}];
|
|
64
|
+
const tokenFlow = (tx, to, amount, chainId, table) => {
|
|
65
|
+
const token = lookupEvmToken(table, chainId, tx.to ?? "");
|
|
66
|
+
return {
|
|
67
|
+
flows: [{
|
|
68
|
+
to,
|
|
69
|
+
amount: {
|
|
70
|
+
asset: tx.to ?? "",
|
|
71
|
+
amount: amount.toString(10),
|
|
72
|
+
...token === void 0 ? {} : {
|
|
73
|
+
symbol: token.symbol,
|
|
74
|
+
decimals: token.decimals
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
verified: token !== void 0
|
|
78
|
+
}],
|
|
79
|
+
verified: token !== void 0
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const approvalChange = (tx, spender, amount) => ({
|
|
83
|
+
asset: tx.to ?? "",
|
|
84
|
+
spender,
|
|
85
|
+
amount: amount.toString(10),
|
|
86
|
+
unlimited: amount === MAX_UINT256,
|
|
87
|
+
verified: false
|
|
88
|
+
});
|
|
89
|
+
const nftFlow = (asset, to, id) => [{
|
|
90
|
+
to,
|
|
91
|
+
amount: {
|
|
92
|
+
asset,
|
|
93
|
+
amount: id.toString(10)
|
|
94
|
+
},
|
|
95
|
+
verified: false
|
|
96
|
+
}];
|
|
97
|
+
const decodeTransaction = (request, table) => {
|
|
98
|
+
const { tx } = request;
|
|
99
|
+
const chainId = networkChainId(request.network);
|
|
100
|
+
const data = tx.data.toLowerCase();
|
|
101
|
+
const fee = { max: weiAmount(feeWei(tx)) };
|
|
102
|
+
const base = {
|
|
103
|
+
family: "evm",
|
|
104
|
+
network: request.network,
|
|
105
|
+
approvals: [],
|
|
106
|
+
warnings: []
|
|
107
|
+
};
|
|
108
|
+
if (data === "0x") {
|
|
109
|
+
if (tx.to === void 0) return {
|
|
110
|
+
...base,
|
|
111
|
+
summary: "contract-call",
|
|
112
|
+
outflows: [],
|
|
113
|
+
fee,
|
|
114
|
+
verifiability: "opaque"
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
...base,
|
|
118
|
+
summary: "transfer",
|
|
119
|
+
outflows: nativeOutflow(tx, tx.to),
|
|
120
|
+
fee,
|
|
121
|
+
verifiability: "full"
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const transferArgs = tryCall(ERC20_TRANSFER, data);
|
|
125
|
+
if (transferArgs !== void 0) {
|
|
126
|
+
const { flows, verified } = tokenFlow(tx, argAddress(transferArgs, 0), argUint(transferArgs, 1), chainId, table);
|
|
127
|
+
return {
|
|
128
|
+
...base,
|
|
129
|
+
summary: "transfer",
|
|
130
|
+
outflows: flows,
|
|
131
|
+
fee,
|
|
132
|
+
verifiability: verified ? "full" : "partial"
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const approveArgs = tryCall(ERC20_APPROVE, data);
|
|
136
|
+
if (approveArgs !== void 0) return {
|
|
137
|
+
...base,
|
|
138
|
+
summary: "approve",
|
|
139
|
+
outflows: [],
|
|
140
|
+
approvals: [approvalChange(tx, argAddress(approveArgs, 0), argUint(approveArgs, 1))],
|
|
141
|
+
fee,
|
|
142
|
+
verifiability: "partial"
|
|
143
|
+
};
|
|
144
|
+
const increaseArgs = tryCall(ERC20_INCREASE, data);
|
|
145
|
+
if (increaseArgs !== void 0) return {
|
|
146
|
+
...base,
|
|
147
|
+
summary: "approve",
|
|
148
|
+
outflows: [],
|
|
149
|
+
approvals: [approvalChange(tx, argAddress(increaseArgs, 0), argUint(increaseArgs, 1))],
|
|
150
|
+
fee,
|
|
151
|
+
verifiability: "partial"
|
|
152
|
+
};
|
|
153
|
+
for (const fn of [ERC721_TRANSFER_FROM, ERC721_SAFE_FROM]) {
|
|
154
|
+
const args = tryCall(fn, data);
|
|
155
|
+
if (args !== void 0) return {
|
|
156
|
+
...base,
|
|
157
|
+
summary: "transfer",
|
|
158
|
+
outflows: nftFlow(tx.to ?? "", argAddress(args, 1), argUint(args, 2)),
|
|
159
|
+
fee,
|
|
160
|
+
verifiability: "partial"
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const erc1155Args = tryCall(ERC1155_SAFE_FROM, data);
|
|
164
|
+
if (erc1155Args !== void 0) return {
|
|
165
|
+
...base,
|
|
166
|
+
summary: "transfer",
|
|
167
|
+
outflows: nftFlow(tx.to ?? "", argAddress(erc1155Args, 1), argUint(erc1155Args, 2)),
|
|
168
|
+
fee,
|
|
169
|
+
verifiability: "partial"
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
...base,
|
|
173
|
+
summary: "contract-call",
|
|
174
|
+
outflows: [],
|
|
175
|
+
fee,
|
|
176
|
+
verifiability: "opaque"
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
/** What the signer can guarantee about this request (WD-065). */
|
|
180
|
+
const verifiabilityEvm = (request) => decodeEvm(request).verifiability;
|
|
181
|
+
/**
|
|
182
|
+
* Decodes a normalized request into a DisplayIntent. The token table parameter is for tests;
|
|
183
|
+
* production callers use the built-in table.
|
|
184
|
+
*/
|
|
185
|
+
const decodeEvm = (request, table = evmTokenTable) => {
|
|
186
|
+
if (request.kind === "evm.transaction") return decodeTransaction(request, table);
|
|
187
|
+
if (request.kind === "evm.personal-message") return {
|
|
188
|
+
family: "evm",
|
|
189
|
+
network: request.network,
|
|
190
|
+
summary: "message",
|
|
191
|
+
outflows: [],
|
|
192
|
+
approvals: [],
|
|
193
|
+
fee: void 0,
|
|
194
|
+
warnings: [],
|
|
195
|
+
verifiability: "opaque"
|
|
196
|
+
};
|
|
197
|
+
if (request.kind !== "evm.typed-data") throw new ChainError("unsupported", `unsupported sign request kind: ${request.kind}`);
|
|
198
|
+
const parsed = parseTypedData(request.typedData, request.network);
|
|
199
|
+
return {
|
|
200
|
+
family: "evm",
|
|
201
|
+
network: request.network,
|
|
202
|
+
summary: "message",
|
|
203
|
+
outflows: [],
|
|
204
|
+
approvals: [],
|
|
205
|
+
fee: void 0,
|
|
206
|
+
warnings: typedDataWarnings(parsed),
|
|
207
|
+
verifiability: "opaque"
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/evm/recover.ts
|
|
212
|
+
/**
|
|
213
|
+
* Signer recovery for `chain.sign` results: the host re-derives the signer address from a signed
|
|
214
|
+
* envelope or a 65-byte signature and compares it with the account's `wallet.accounts` address — a
|
|
215
|
+
* kernel returning someone else's signature fails closed.
|
|
216
|
+
*/
|
|
217
|
+
function assertEip1559Hex(hex) {
|
|
218
|
+
if (!hex.startsWith("0x02")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
219
|
+
}
|
|
220
|
+
function assertEip2930Hex(hex) {
|
|
221
|
+
if (!hex.startsWith("0x01")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
222
|
+
}
|
|
223
|
+
const signatureOf = (env) => {
|
|
224
|
+
const { r, s, yParity } = env;
|
|
225
|
+
if (r === void 0 || s === void 0 || yParity === void 0) throw new ChainError("invalid-request", "envelope carries no signature");
|
|
226
|
+
return Signature.from({
|
|
227
|
+
r,
|
|
228
|
+
s,
|
|
229
|
+
yParity
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
/** Recover the signer's EIP-55 address from a serialized signed transaction envelope. */
|
|
233
|
+
const signerFromEnvelope = (signedTransaction) => {
|
|
234
|
+
const hex = Hex.fromBytes(signedTransaction);
|
|
235
|
+
const [tag] = signedTransaction;
|
|
236
|
+
if (tag === 2) {
|
|
237
|
+
assertEip1559Hex(hex);
|
|
238
|
+
const env = TxEnvelopeEip1559.deserialize(hex);
|
|
239
|
+
const payload = TxEnvelopeEip1559.getSignPayload(env);
|
|
240
|
+
return Secp256k1.recoverAddress({
|
|
241
|
+
payload,
|
|
242
|
+
signature: signatureOf(env)
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (tag === 1) {
|
|
246
|
+
assertEip2930Hex(hex);
|
|
247
|
+
const env = TxEnvelopeEip2930.deserialize(hex);
|
|
248
|
+
const payload = TxEnvelopeEip2930.getSignPayload(env);
|
|
249
|
+
return Secp256k1.recoverAddress({
|
|
250
|
+
payload,
|
|
251
|
+
signature: signatureOf(env)
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const env = TxEnvelopeLegacy.deserialize(hex);
|
|
256
|
+
const payload = TxEnvelopeLegacy.getSignPayload(env);
|
|
257
|
+
return Secp256k1.recoverAddress({
|
|
258
|
+
payload,
|
|
259
|
+
signature: signatureOf(env)
|
|
260
|
+
});
|
|
261
|
+
} catch {
|
|
262
|
+
throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* The EIP-55 address that produced `result` for `request` — a `chain.sign` round-trip check
|
|
267
|
+
* (`{kind:"evm.transaction",signedTransaction}` | `{kind,signature}`).
|
|
268
|
+
*/
|
|
269
|
+
const recoverEvmSigner = (request, result) => {
|
|
270
|
+
if (request.kind === "evm.transaction") {
|
|
271
|
+
if (result.signedTransaction === void 0) throw new ChainError("invalid-request", "expected a signed transaction");
|
|
272
|
+
return signerFromEnvelope(result.signedTransaction);
|
|
273
|
+
}
|
|
274
|
+
if (result.signature === void 0 || result.signature.length !== 65) throw new ChainError("invalid-request", "expected a 65-byte signature");
|
|
275
|
+
const signature = Signature.from(result.signature);
|
|
276
|
+
if (request.kind === "evm.personal-message") {
|
|
277
|
+
const payload = PersonalMessage.getSignPayload(Hex.fromBytes(request.message));
|
|
278
|
+
return Secp256k1.recoverAddress({
|
|
279
|
+
payload,
|
|
280
|
+
signature
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
if (request.kind === "evm.typed-data") {
|
|
284
|
+
const { json } = parseTypedData(request.typedData, request.network);
|
|
285
|
+
const payload = TypedData.getSignPayload(json);
|
|
286
|
+
return Secp256k1.recoverAddress({
|
|
287
|
+
payload,
|
|
288
|
+
signature
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
throw new ChainError("unsupported", `cannot recover a signer for ${request.kind}`);
|
|
292
|
+
};
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/evm/index.ts
|
|
295
|
+
/**
|
|
296
|
+
* Normalizes a SignRequest for the EVM family: exact key sets, chainId vs the CAIP-2 `network`,
|
|
297
|
+
* canonical quantities and EIP-55 addresses. Idempotent.
|
|
298
|
+
*/
|
|
299
|
+
const isAccountRef = (value) => {
|
|
300
|
+
if (!isRecord(value) || typeof value["kind"] !== "string") return false;
|
|
301
|
+
if (value["kind"] === "hd") return typeof value["walletId"] === "string" && typeof value["groupIndex"] === "number" && typeof value["template"] === "string";
|
|
302
|
+
if (value["kind"] === "imported") return typeof value["keyId"] === "string" && typeof value["family"] === "string";
|
|
303
|
+
return false;
|
|
304
|
+
};
|
|
305
|
+
const normalizeEvm = (request) => {
|
|
306
|
+
if (!isRecord(request) || typeof request["kind"] !== "string") throw new ChainError("invalid-request", "request must be an object with a kind");
|
|
307
|
+
const { network } = request;
|
|
308
|
+
const { account } = request;
|
|
309
|
+
if (typeof network !== "string") throw new ChainError("invalid-request", "request.network must be a string");
|
|
310
|
+
if (!isAccountRef(account)) throw new ChainError("invalid-request", "request.account must be an AccountRef");
|
|
311
|
+
const chainId = networkChainId(network);
|
|
312
|
+
if (request["kind"] === "evm.transaction") {
|
|
313
|
+
const tx = normalizeEvmTransaction(request["tx"]);
|
|
314
|
+
if (tx.chainId !== chainId) throw new ChainError("chain-id-mismatch", `tx.chainId ${tx.chainId} does not match network ${network}`);
|
|
315
|
+
return {
|
|
316
|
+
kind: "evm.transaction",
|
|
317
|
+
network,
|
|
318
|
+
account,
|
|
319
|
+
tx
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
if (request["kind"] === "evm.personal-message") {
|
|
323
|
+
const { message } = request;
|
|
324
|
+
if (!(message instanceof Uint8Array)) throw new ChainError("invalid-request", "personal-message payload must be bytes");
|
|
325
|
+
return {
|
|
326
|
+
kind: "evm.personal-message",
|
|
327
|
+
network,
|
|
328
|
+
account,
|
|
329
|
+
message
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
if (request["kind"] === "evm.typed-data") {
|
|
333
|
+
const { typedData } = request;
|
|
334
|
+
if (typeof typedData !== "string") throw new ChainError("invalid-request", "typed-data payload must be the JSON source string");
|
|
335
|
+
parseTypedData(typedData, network);
|
|
336
|
+
return {
|
|
337
|
+
kind: "evm.typed-data",
|
|
338
|
+
network,
|
|
339
|
+
account,
|
|
340
|
+
typedData
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
throw new ChainError("unsupported", `unsupported sign request kind: ${request["kind"]}`);
|
|
344
|
+
};
|
|
345
|
+
//#endregion
|
|
346
|
+
export { canonicalHex, checksumEvmAddress, decodeEvm, evmAddressFromPublicKey, evmTokenTable, isCanonicalHex, isEvmAddress, lookupEvmToken, networkChainId, normalizeEvm, normalizeEvmTransaction, parseTypedData, recoverEvmSigner, verifiabilityEvm };
|
|
347
|
+
|
|
348
|
+
//# sourceMappingURL=evm.mjs.map
|
package/dist/evm.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evm.mjs","names":[],"sources":["../src/evm/tokens.ts","../src/evm/decode.ts","../src/evm/recover.ts","../src/evm/index.ts"],"sourcesContent":["/**\n * Built-in ERC-20 token table, keyed by `chainId` then checksummed address. Intentionally EMPTY in\n * this layer — real entries need official-source review (C6). Tests exercise the `full` ERC-20 path\n * through `evmTokenTable`, which is exported for the kernel/test callers only via the `/evm` entry\n * point.\n */\n\nexport type EvmToken = {\n readonly symbol: string;\n readonly decimals: number;\n readonly name?: string;\n};\n\nexport type EvmTokenTable = Readonly<Record<string, Readonly<Record<string, EvmToken>>>>;\n\nconst EMPTY_TABLE: EvmTokenTable = Object.freeze({});\n\n/** The built-in table — empty until official-source review lands the entries. */\nexport const evmTokenTable: EvmTokenTable = EMPTY_TABLE;\n\nexport const lookupEvmToken = (\n table: EvmTokenTable,\n chainId: number,\n address: string,\n): EvmToken | undefined => table[String(chainId)]?.[address];\n","import * as AbiFunction from \"ox/AbiFunction\";\n\nimport { ChainError } from \"../index.ts\";\nimport type {\n ApprovalChange,\n AssetFlow,\n DisplayIntent,\n EvmTransaction,\n SignRequest,\n Verifiability,\n} from \"../index.ts\";\nimport { checksumEvmAddress } from \"./address.ts\";\nimport { lookupEvmToken, evmTokenTable } from \"./tokens.ts\";\nimport type { EvmTokenTable } from \"./tokens.ts\";\nimport { assertHex, networkChainId } from \"./transaction.ts\";\nimport { parseTypedData, typedDataWarnings } from \"./typed-data.ts\";\n\nconst ERC20_TRANSFER = AbiFunction.from(\"function transfer(address to, uint256 amount)\");\nconst ERC20_APPROVE = AbiFunction.from(\"function approve(address spender, uint256 amount)\");\nconst ERC20_INCREASE = AbiFunction.from(\n \"function increaseAllowance(address spender, uint256 amount)\",\n);\nconst ERC721_TRANSFER_FROM = AbiFunction.from(\n \"function transferFrom(address from, address to, uint256 tokenId)\",\n);\nconst ERC721_SAFE_FROM = AbiFunction.from(\n \"function safeTransferFrom(address from, address to, uint256 tokenId)\",\n);\nconst ERC1155_SAFE_FROM = AbiFunction.from(\n \"function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data)\",\n);\n\nconst NATIVE_ASSET = \"native\";\nconst MAX_UINT256 = 2n ** 256n - 1n;\n\nconst argAddress = (args: ReadonlyArray<unknown>, index: number): string => {\n const value = args[index];\n if (typeof value !== \"string\" || !/^0x[0-9a-fA-F]{40}$/.test(value)) {\n throw new ChainError(\"invalid-request\", \"decoded argument is not an address\");\n }\n return checksumEvmAddress(value);\n};\n\nconst argUint = (args: ReadonlyArray<unknown>, index: number): bigint => {\n const value = args[index];\n if (typeof value !== \"bigint\") {\n throw new ChainError(\"invalid-request\", \"decoded argument is not a uint256\");\n }\n return value;\n};\n\n/**\n * Decodes `data` as `fn` and verifies the encoding is canonical (re-encoding the decoded args\n * reproduces the input byte-for-byte). Returns undefined on selector mismatch, decode failure or a\n * non-canonical encoding — the caller falls through to the next candidate or the opaque class.\n */\nconst tryCall = (fn: AbiFunction.AbiFunction, data: string): ReadonlyArray<unknown> | undefined => {\n const selector = AbiFunction.getSelector(fn);\n if (!data.toLowerCase().startsWith(selector)) {\n return undefined;\n }\n try {\n assertHex(data, \"data\");\n const args: unknown = AbiFunction.decodeData(fn, data);\n if (!Array.isArray(args)) {\n return undefined;\n }\n const reencoded = AbiFunction.encodeData(fn, args);\n return reencoded.toLowerCase() === data.toLowerCase() ? args : undefined;\n } catch {\n return undefined;\n }\n};\n\nconst weiAmount = (wei: bigint, symbol?: string, decimals?: number) => ({\n asset: NATIVE_ASSET,\n amount: wei.toString(10),\n ...(symbol === undefined ? {} : { symbol }),\n ...(decimals === undefined ? {} : { decimals }),\n});\n\nconst feeWei = (tx: EvmTransaction): bigint =>\n BigInt(tx.gas) * (tx.type === \"eip1559\" ? BigInt(tx.maxFeePerGas) : BigInt(tx.gasPrice));\n\nconst nativeOutflow = (tx: EvmTransaction, to: string): ReadonlyArray<AssetFlow> => [\n { to, amount: weiAmount(BigInt(tx.value)), verified: true },\n];\n\nconst tokenFlow = (\n tx: EvmTransaction,\n to: string,\n amount: bigint,\n chainId: number,\n table: EvmTokenTable,\n): { flows: ReadonlyArray<AssetFlow>; verified: boolean } => {\n const token = lookupEvmToken(table, chainId, tx.to ?? \"\");\n return {\n flows: [\n {\n to,\n amount: {\n asset: tx.to ?? \"\",\n amount: amount.toString(10),\n ...(token === undefined ? {} : { symbol: token.symbol, decimals: token.decimals }),\n },\n verified: token !== undefined,\n },\n ],\n verified: token !== undefined,\n };\n};\n\nconst approvalChange = (tx: EvmTransaction, spender: string, amount: bigint): ApprovalChange => ({\n asset: tx.to ?? \"\",\n spender,\n amount: amount.toString(10),\n unlimited: amount === MAX_UINT256,\n verified: false,\n});\n\nconst nftFlow = (asset: string, to: string, id: bigint): ReadonlyArray<AssetFlow> => [\n { to, amount: { asset, amount: id.toString(10) }, verified: false },\n];\n\nconst decodeTransaction = (\n request: Extract<SignRequest, { kind: \"evm.transaction\" }>,\n table: EvmTokenTable,\n): DisplayIntent => {\n const { tx } = request;\n const chainId = networkChainId(request.network);\n const data = tx.data.toLowerCase();\n const fee = { max: weiAmount(feeWei(tx)) };\n const base = { family: \"evm\" as const, network: request.network, approvals: [], warnings: [] };\n\n if (data === \"0x\") {\n if (tx.to === undefined) {\n return { ...base, summary: \"contract-call\", outflows: [], fee, verifiability: \"opaque\" };\n }\n return {\n ...base,\n summary: \"transfer\",\n outflows: nativeOutflow(tx, tx.to),\n fee,\n verifiability: \"full\",\n };\n }\n\n const transferArgs = tryCall(ERC20_TRANSFER, data);\n if (transferArgs !== undefined) {\n const { flows, verified } = tokenFlow(\n tx,\n argAddress(transferArgs, 0),\n argUint(transferArgs, 1),\n chainId,\n table,\n );\n return {\n ...base,\n summary: \"transfer\",\n outflows: flows,\n fee,\n verifiability: verified ? \"full\" : \"partial\",\n };\n }\n const approveArgs = tryCall(ERC20_APPROVE, data);\n if (approveArgs !== undefined) {\n return {\n ...base,\n summary: \"approve\",\n outflows: [],\n approvals: [approvalChange(tx, argAddress(approveArgs, 0), argUint(approveArgs, 1))],\n fee,\n verifiability: \"partial\",\n };\n }\n const increaseArgs = tryCall(ERC20_INCREASE, data);\n if (increaseArgs !== undefined) {\n return {\n ...base,\n summary: \"approve\",\n outflows: [],\n approvals: [approvalChange(tx, argAddress(increaseArgs, 0), argUint(increaseArgs, 1))],\n fee,\n verifiability: \"partial\",\n };\n }\n for (const fn of [ERC721_TRANSFER_FROM, ERC721_SAFE_FROM]) {\n const args = tryCall(fn, data);\n if (args !== undefined) {\n return {\n ...base,\n summary: \"transfer\",\n outflows: nftFlow(tx.to ?? \"\", argAddress(args, 1), argUint(args, 2)),\n fee,\n verifiability: \"partial\",\n };\n }\n }\n const erc1155Args = tryCall(ERC1155_SAFE_FROM, data);\n if (erc1155Args !== undefined) {\n return {\n ...base,\n summary: \"transfer\",\n outflows: nftFlow(tx.to ?? \"\", argAddress(erc1155Args, 1), argUint(erc1155Args, 2)),\n fee,\n verifiability: \"partial\",\n };\n }\n return { ...base, summary: \"contract-call\", outflows: [], fee, verifiability: \"opaque\" };\n};\n\n/** What the signer can guarantee about this request (WD-065). */\nexport const verifiabilityEvm = (request: SignRequest): Verifiability =>\n decodeEvm(request).verifiability;\n\n/**\n * Decodes a normalized request into a DisplayIntent. The token table parameter is for tests;\n * production callers use the built-in table.\n */\nexport const decodeEvm = (\n request: SignRequest,\n table: EvmTokenTable = evmTokenTable,\n): DisplayIntent => {\n if (request.kind === \"evm.transaction\") {\n return decodeTransaction(request, table);\n }\n if (request.kind === \"evm.personal-message\") {\n return {\n family: \"evm\",\n network: request.network,\n summary: \"message\",\n outflows: [],\n approvals: [],\n fee: undefined,\n warnings: [],\n verifiability: \"opaque\",\n };\n }\n if (request.kind !== \"evm.typed-data\") {\n throw new ChainError(\"unsupported\", `unsupported sign request kind: ${request.kind}`);\n }\n const parsed = parseTypedData(request.typedData, request.network);\n return {\n family: \"evm\",\n network: request.network,\n summary: \"message\",\n outflows: [],\n approvals: [],\n fee: undefined,\n warnings: typedDataWarnings(parsed),\n verifiability: \"opaque\",\n };\n};\n","/**\n * Signer recovery for `chain.sign` results: the host re-derives the signer address from a signed\n * envelope or a 65-byte signature and compares it with the account's `wallet.accounts` address — a\n * kernel returning someone else's signature fails closed.\n */\nimport * as Hex from \"ox/Hex\";\nimport * as PersonalMessage from \"ox/PersonalMessage\";\nimport * as Secp256k1 from \"ox/Secp256k1\";\nimport * as Signature from \"ox/Signature\";\nimport * as TxEnvelopeEip1559 from \"ox/TxEnvelopeEip1559\";\nimport * as TxEnvelopeEip2930 from \"ox/TxEnvelopeEip2930\";\nimport * as TxEnvelopeLegacy from \"ox/TxEnvelopeLegacy\";\nimport * as TypedData from \"ox/TypedData\";\n\nimport { ChainError } from \"../index.ts\";\nimport type { SignRequest } from \"../index.ts\";\nimport { parseTypedData } from \"./typed-data.ts\";\n\nfunction assertEip1559Hex(hex: `0x${string}`): asserts hex is `0x02${string}` {\n if (!hex.startsWith(\"0x02\")) {\n throw new ChainError(\"invalid-request\", \"unrecognized signed transaction envelope\");\n }\n}\nfunction assertEip2930Hex(hex: `0x${string}`): asserts hex is `0x01${string}` {\n if (!hex.startsWith(\"0x01\")) {\n throw new ChainError(\"invalid-request\", \"unrecognized signed transaction envelope\");\n }\n}\n\ntype EnvelopeFields = {\n readonly r?: `0x${string}` | undefined;\n readonly s?: `0x${string}` | undefined;\n readonly yParity?: number | undefined;\n};\n\nconst signatureOf = (env: EnvelopeFields) => {\n const { r, s, yParity } = env;\n if (r === undefined || s === undefined || yParity === undefined) {\n throw new ChainError(\"invalid-request\", \"envelope carries no signature\");\n }\n return Signature.from({ r, s, yParity });\n};\n\n/** Recover the signer's EIP-55 address from a serialized signed transaction envelope. */\nconst signerFromEnvelope = (signedTransaction: Uint8Array): string => {\n const hex = Hex.fromBytes(signedTransaction);\n const [tag] = signedTransaction;\n if (tag === 0x02) {\n assertEip1559Hex(hex);\n const env = TxEnvelopeEip1559.deserialize(hex);\n const payload = TxEnvelopeEip1559.getSignPayload(env);\n return Secp256k1.recoverAddress({ payload, signature: signatureOf(env) });\n }\n if (tag === 0x01) {\n assertEip2930Hex(hex);\n const env = TxEnvelopeEip2930.deserialize(hex);\n const payload = TxEnvelopeEip2930.getSignPayload(env);\n return Secp256k1.recoverAddress({ payload, signature: signatureOf(env) });\n }\n try {\n const env = TxEnvelopeLegacy.deserialize(hex);\n const payload = TxEnvelopeLegacy.getSignPayload(env);\n return Secp256k1.recoverAddress({ payload, signature: signatureOf(env) });\n } catch {\n throw new ChainError(\"invalid-request\", \"unrecognized signed transaction envelope\");\n }\n};\n\n/**\n * The EIP-55 address that produced `result` for `request` — a `chain.sign` round-trip check\n * (`{kind:\"evm.transaction\",signedTransaction}` | `{kind,signature}`).\n */\nexport const recoverEvmSigner = (\n request: Extract<SignRequest, { network: string }>,\n result: { readonly signedTransaction?: Uint8Array; readonly signature?: Uint8Array },\n): string => {\n if (request.kind === \"evm.transaction\") {\n if (result.signedTransaction === undefined) {\n throw new ChainError(\"invalid-request\", \"expected a signed transaction\");\n }\n return signerFromEnvelope(result.signedTransaction);\n }\n if (result.signature === undefined || result.signature.length !== 65) {\n throw new ChainError(\"invalid-request\", \"expected a 65-byte signature\");\n }\n const signature = Signature.from(result.signature);\n if (request.kind === \"evm.personal-message\") {\n const payload = PersonalMessage.getSignPayload(Hex.fromBytes(request.message));\n return Secp256k1.recoverAddress({ payload, signature });\n }\n if (request.kind === \"evm.typed-data\") {\n const { json } = parseTypedData(request.typedData, request.network);\n const payload = TypedData.getSignPayload(json);\n return Secp256k1.recoverAddress({ payload, signature });\n }\n throw new ChainError(\"unsupported\", `cannot recover a signer for ${request.kind}`);\n};\n","import { ChainError } from \"../index.ts\";\nimport type { AccountRef, SignRequest } from \"../index.ts\";\nimport { isRecord, networkChainId, normalizeEvmTransaction } from \"./transaction.ts\";\nimport { parseTypedData } from \"./typed-data.ts\";\n\nexport { isEvmAddress, checksumEvmAddress, evmAddressFromPublicKey } from \"./address.ts\";\nexport {\n networkChainId,\n normalizeEvmTransaction,\n canonicalHex,\n isCanonicalHex,\n} from \"./transaction.ts\";\nexport { decodeEvm, verifiabilityEvm } from \"./decode.ts\";\nexport { recoverEvmSigner } from \"./recover.ts\";\nexport { parseTypedData } from \"./typed-data.ts\";\nexport { evmTokenTable, lookupEvmToken } from \"./tokens.ts\";\nexport type { EvmToken, EvmTokenTable } from \"./tokens.ts\";\n\n/**\n * Normalizes a SignRequest for the EVM family: exact key sets, chainId vs the CAIP-2 `network`,\n * canonical quantities and EIP-55 addresses. Idempotent.\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 if (value[\"kind\"] === \"imported\") {\n return typeof value[\"keyId\"] === \"string\" && typeof value[\"family\"] === \"string\";\n }\n return false;\n};\n\nexport const normalizeEvm = (request: unknown): 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 const chainId = networkChainId(network);\n if (request[\"kind\"] === \"evm.transaction\") {\n const tx = normalizeEvmTransaction(request[\"tx\"]);\n if (tx.chainId !== chainId) {\n throw new ChainError(\n \"chain-id-mismatch\",\n `tx.chainId ${tx.chainId} does not match network ${network}`,\n );\n }\n return { kind: \"evm.transaction\", network, account, tx };\n }\n if (request[\"kind\"] === \"evm.personal-message\") {\n const { message } = request;\n if (!(message instanceof Uint8Array)) {\n throw new ChainError(\"invalid-request\", \"personal-message payload must be bytes\");\n }\n return { kind: \"evm.personal-message\", network, account, message };\n }\n if (request[\"kind\"] === \"evm.typed-data\") {\n const { typedData } = request;\n if (typeof typedData !== \"string\") {\n throw new ChainError(\"invalid-request\", \"typed-data payload must be the JSON source string\");\n }\n parseTypedData(typedData, network);\n return { kind: \"evm.typed-data\", network, account, typedData };\n }\n throw new ChainError(\"unsupported\", `unsupported sign request kind: ${request[\"kind\"]}`);\n};\n"],"mappings":";;;;;;;;;;;;AAkBA,MAAa,gBAHsB,OAAO,OAAO,CAAC,CAGN;AAE5C,MAAa,kBACX,OACA,SACA,YACyB,MAAM,OAAO,OAAO,EAAE,GAAG;;;ACPpD,MAAM,iBAAiB,YAAY,KAAK,+CAA+C;AACvF,MAAM,gBAAgB,YAAY,KAAK,mDAAmD;AAC1F,MAAM,iBAAiB,YAAY,KACjC,6DACF;AACA,MAAM,uBAAuB,YAAY,KACvC,kEACF;AACA,MAAM,mBAAmB,YAAY,KACnC,sEACF;AACA,MAAM,oBAAoB,YAAY,KACpC,6FACF;AAEA,MAAM,eAAe;AACrB,MAAM,cAAc,MAAM,OAAO;AAEjC,MAAM,cAAc,MAA8B,UAA0B;CAC1E,MAAM,QA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ains — shared chain semantics for the wallet.
|
|
4
|
+
* Types here are wire-safe: values crossing the main↔kernel protocol are
|
|
5
|
+
* Uint8Array, safe integers, strings, booleans, arrays and plain objects.
|
|
6
|
+
* Quantities are canonical `0x` hex (lowercase, no leading zeros, `0x0` for
|
|
7
|
+
* zero), token amounts are decimal strings of the smallest unit.
|
|
8
|
+
*/
|
|
9
|
+
export type ChainFamily = "evm" | "solana" | "bitcoin";
|
|
10
|
+
export type AccountRef = {
|
|
11
|
+
readonly kind: "hd";
|
|
12
|
+
readonly walletId: string;
|
|
13
|
+
readonly groupIndex: number;
|
|
14
|
+
readonly template: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "imported";
|
|
17
|
+
readonly keyId: string;
|
|
18
|
+
readonly family: ChainFamily;
|
|
19
|
+
};
|
|
20
|
+
export type SignRequest = {
|
|
21
|
+
readonly kind: "bitcoin.psbt";
|
|
22
|
+
readonly network: string;
|
|
23
|
+
readonly account: AccountRef;
|
|
24
|
+
readonly psbt: Uint8Array;
|
|
25
|
+
/** Input indices to sign — non-empty, unique, ascending, in range. */
|
|
26
|
+
readonly sign: ReadonlyArray<number>;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: "bitcoin.message";
|
|
29
|
+
readonly network: string;
|
|
30
|
+
readonly account: AccountRef;
|
|
31
|
+
readonly address: string;
|
|
32
|
+
readonly message: string;
|
|
33
|
+
readonly format: "bip322-simple" | "legacy";
|
|
34
|
+
/** Account change chain and index the address is derived at (0 = receive, 1 = change). */
|
|
35
|
+
readonly change: 0 | 1;
|
|
36
|
+
readonly index: number;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: "solana.transaction";
|
|
39
|
+
readonly network: string;
|
|
40
|
+
readonly account: AccountRef;
|
|
41
|
+
/** Compiled wire message (legacy or v0). */
|
|
42
|
+
readonly message: Uint8Array;
|
|
43
|
+
readonly lookupTables?: ReadonlyArray<{
|
|
44
|
+
readonly address: string;
|
|
45
|
+
readonly addresses: ReadonlyArray<string>;
|
|
46
|
+
}>;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: "solana.message";
|
|
49
|
+
readonly network: string;
|
|
50
|
+
readonly account: AccountRef;
|
|
51
|
+
readonly message: Uint8Array;
|
|
52
|
+
/** Only "raw" exists in this layer; offchain formats land with C7. */
|
|
53
|
+
readonly format: "raw";
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: "evm.transaction";
|
|
56
|
+
readonly network: string;
|
|
57
|
+
readonly account: AccountRef;
|
|
58
|
+
readonly tx: EvmTransaction;
|
|
59
|
+
} | {
|
|
60
|
+
readonly kind: "evm.personal-message";
|
|
61
|
+
readonly network: string;
|
|
62
|
+
readonly account: AccountRef;
|
|
63
|
+
readonly message: Uint8Array;
|
|
64
|
+
} | {
|
|
65
|
+
readonly kind: "evm.typed-data";
|
|
66
|
+
readonly network: string;
|
|
67
|
+
readonly account: AccountRef;
|
|
68
|
+
readonly typedData: string;
|
|
69
|
+
};
|
|
70
|
+
export type EvmAccessListEntry = {
|
|
71
|
+
readonly address: string;
|
|
72
|
+
readonly storageKeys: ReadonlyArray<string>;
|
|
73
|
+
};
|
|
74
|
+
type EvmTransactionBase = {
|
|
75
|
+
readonly chainId: number;
|
|
76
|
+
readonly nonce: number;
|
|
77
|
+
readonly gas: string;
|
|
78
|
+
readonly value: string;
|
|
79
|
+
readonly data: string;
|
|
80
|
+
readonly to?: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* A complete transaction — every field the signer needs is present; `to` absent means contract
|
|
84
|
+
* creation.
|
|
85
|
+
*/
|
|
86
|
+
export type EvmTransaction = (EvmTransactionBase & {
|
|
87
|
+
readonly type: "legacy";
|
|
88
|
+
readonly gasPrice: string;
|
|
89
|
+
}) | (EvmTransactionBase & {
|
|
90
|
+
readonly type: "eip2930";
|
|
91
|
+
readonly gasPrice: string;
|
|
92
|
+
readonly accessList: ReadonlyArray<EvmAccessListEntry>;
|
|
93
|
+
}) | (EvmTransactionBase & {
|
|
94
|
+
readonly type: "eip1559";
|
|
95
|
+
readonly accessList: ReadonlyArray<EvmAccessListEntry>;
|
|
96
|
+
readonly maxFeePerGas: string;
|
|
97
|
+
readonly maxPriorityFeePerGas: string;
|
|
98
|
+
});
|
|
99
|
+
export type Verifiability = "full" | "partial" | "opaque";
|
|
100
|
+
export type IntentSummary = "transfer" | "approve" | "contract-call" | "swap" | "message" | "authorization" | "batch";
|
|
101
|
+
export type AssetAmount = {
|
|
102
|
+
readonly asset: string;
|
|
103
|
+
readonly amount: string;
|
|
104
|
+
readonly decimals?: number;
|
|
105
|
+
readonly symbol?: string;
|
|
106
|
+
};
|
|
107
|
+
export type AssetFlow = {
|
|
108
|
+
readonly to: string;
|
|
109
|
+
readonly amount: AssetAmount;
|
|
110
|
+
readonly verified: boolean;
|
|
111
|
+
};
|
|
112
|
+
export type ApprovalChange = {
|
|
113
|
+
readonly asset: string;
|
|
114
|
+
readonly spender: string;
|
|
115
|
+
readonly amount: string;
|
|
116
|
+
readonly unlimited: boolean;
|
|
117
|
+
readonly verified: boolean;
|
|
118
|
+
};
|
|
119
|
+
export type IntentWarning = {
|
|
120
|
+
readonly kind: string;
|
|
121
|
+
readonly message: string;
|
|
122
|
+
};
|
|
123
|
+
export type DisplayIntent = {
|
|
124
|
+
readonly family: ChainFamily;
|
|
125
|
+
readonly network: string;
|
|
126
|
+
readonly summary: IntentSummary;
|
|
127
|
+
readonly outflows: ReadonlyArray<AssetFlow>;
|
|
128
|
+
readonly approvals: ReadonlyArray<ApprovalChange>;
|
|
129
|
+
readonly fee: {
|
|
130
|
+
readonly max: AssetAmount;
|
|
131
|
+
} | undefined;
|
|
132
|
+
readonly warnings: ReadonlyArray<IntentWarning>;
|
|
133
|
+
readonly verifiability: Verifiability;
|
|
134
|
+
};
|
|
135
|
+
export type ChainErrorCode = "unknown-field" | "chain-id-mismatch" | "fee-payer-mismatch" | "invalid-quantity" | "invalid-address" | "invalid-typed-data" | "invalid-request" | "unsupported";
|
|
136
|
+
export declare class ChainError extends Error {
|
|
137
|
+
readonly code: ChainErrorCode;
|
|
138
|
+
constructor(code: ChainErrorCode, message: string);
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
export {};
|
|
142
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
var ChainError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "ChainError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { ChainError };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @qntx/wallet-chains — shared chain semantics for the wallet.\n * Types here are wire-safe: values crossing the main↔kernel protocol are\n * Uint8Array, safe integers, strings, booleans, arrays and plain objects.\n * Quantities are canonical `0x` hex (lowercase, no leading zeros, `0x0` for\n * zero), token amounts are decimal strings of the smallest unit.\n */\n\nexport type ChainFamily = \"evm\" | \"solana\" | \"bitcoin\";\n\nexport type AccountRef =\n | {\n readonly kind: \"hd\";\n readonly walletId: string;\n readonly groupIndex: number;\n readonly template: string;\n }\n | { readonly kind: \"imported\"; readonly keyId: string; readonly family: ChainFamily };\n\nexport type SignRequest =\n | {\n readonly kind: \"bitcoin.psbt\";\n readonly network: string;\n readonly account: AccountRef;\n readonly psbt: Uint8Array;\n /** Input indices to sign — non-empty, unique, ascending, in range. */\n readonly sign: ReadonlyArray<number>;\n }\n | {\n readonly kind: \"bitcoin.message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly address: string;\n readonly message: string;\n readonly format: \"bip322-simple\" | \"legacy\";\n /** Account change chain and index the address is derived at (0 = receive, 1 = change). */\n readonly change: 0 | 1;\n readonly index: number;\n }\n | {\n readonly kind: \"solana.transaction\";\n readonly network: string;\n readonly account: AccountRef;\n /** Compiled wire message (legacy or v0). */\n readonly message: Uint8Array;\n readonly lookupTables?: ReadonlyArray<{\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n }>;\n }\n | {\n readonly kind: \"solana.message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly message: Uint8Array;\n /** Only \"raw\" exists in this layer; offchain formats land with C7. */\n readonly format: \"raw\";\n }\n | {\n readonly kind: \"evm.transaction\";\n readonly network: string;\n readonly account: AccountRef;\n readonly tx: EvmTransaction;\n }\n | {\n readonly kind: \"evm.personal-message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly message: Uint8Array;\n }\n | {\n readonly kind: \"evm.typed-data\";\n readonly network: string;\n readonly account: AccountRef;\n readonly typedData: string;\n };\n\nexport type EvmAccessListEntry = {\n readonly address: string;\n readonly storageKeys: ReadonlyArray<string>;\n};\n\ntype EvmTransactionBase = {\n readonly chainId: number;\n readonly nonce: number;\n readonly gas: string;\n readonly value: string;\n readonly data: string;\n readonly to?: string;\n};\n\n/**\n * A complete transaction — every field the signer needs is present; `to` absent means contract\n * creation.\n */\nexport type EvmTransaction =\n | (EvmTransactionBase & { readonly type: \"legacy\"; readonly gasPrice: string })\n | (EvmTransactionBase & {\n readonly type: \"eip2930\";\n readonly gasPrice: string;\n readonly accessList: ReadonlyArray<EvmAccessListEntry>;\n })\n | (EvmTransactionBase & {\n readonly type: \"eip1559\";\n readonly accessList: ReadonlyArray<EvmAccessListEntry>;\n readonly maxFeePerGas: string;\n readonly maxPriorityFeePerGas: string;\n });\n\nexport type Verifiability = \"full\" | \"partial\" | \"opaque\";\n\nexport type IntentSummary =\n | \"transfer\"\n | \"approve\"\n | \"contract-call\"\n | \"swap\"\n | \"message\"\n | \"authorization\"\n | \"batch\";\n\nexport type AssetAmount = {\n readonly asset: string;\n readonly amount: string;\n readonly decimals?: number;\n readonly symbol?: string;\n};\n\nexport type AssetFlow = {\n readonly to: string;\n readonly amount: AssetAmount;\n readonly verified: boolean;\n};\n\nexport type ApprovalChange = {\n readonly asset: string;\n readonly spender: string;\n readonly amount: string;\n readonly unlimited: boolean;\n readonly verified: boolean;\n};\n\nexport type IntentWarning = {\n readonly kind: string;\n readonly message: string;\n};\n\nexport type DisplayIntent = {\n readonly family: ChainFamily;\n readonly network: string;\n readonly summary: IntentSummary;\n readonly outflows: ReadonlyArray<AssetFlow>;\n readonly approvals: ReadonlyArray<ApprovalChange>;\n readonly fee: { readonly max: AssetAmount } | undefined;\n readonly warnings: ReadonlyArray<IntentWarning>;\n readonly verifiability: Verifiability;\n};\n\nexport type ChainErrorCode =\n | \"unknown-field\"\n | \"chain-id-mismatch\"\n | \"fee-payer-mismatch\"\n | \"invalid-quantity\"\n | \"invalid-address\"\n | \"invalid-typed-data\"\n | \"invalid-request\"\n | \"unsupported\";\n\nexport class ChainError extends Error {\n readonly code: ChainErrorCode;\n constructor(code: ChainErrorCode, message: string) {\n super(message);\n this.name = \"ChainError\";\n this.code = code;\n }\n}\n"],"mappings":";AAuKA,IAAa,aAAb,cAAgC,MAAM;CACpC;CACA,YAAY,MAAsB,SAAiB;EACjD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF"}
|