@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evm-sign.mjs","names":[],"sources":["../src/evm/sign.ts"],"sourcesContent":["/**\n * /evm/sign — deterministic (RFC 6979) ECDSA signing over the chain's canonical payloads. Inputs\n * must already be normalized: the kernel calls `normalizeEvm` first and rejects on a ChainError. No\n * key caching; the caller wipes key bytes.\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 { EvmAccessListEntry, EvmTransaction } from \"../index.ts\";\nimport { parseTypedData } from \"./typed-data.ts\";\n\n/** Validates a string is `0x`-hex and narrows it for ox's branded type. */\nfunction assertHex(value: string, field: string): asserts value is `0x${string}` {\n if (!/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) {\n throw new ChainError(\"invalid-quantity\", `${field} must be 0x-prefixed bytes`);\n }\n}\n\nconst hex = (value: string, field: string): `0x${string}` => {\n assertHex(value, field);\n return value;\n};\n\nconst key = (privateKey: Uint8Array): `0x${string}` => {\n if (privateKey.length !== 32) {\n throw new ChainError(\"invalid-request\", \"private key must be 32 bytes\");\n }\n return Hex.fromBytes(privateKey);\n};\n\nconst accessEntry = (entry: EvmAccessListEntry) => ({\n address: hex(entry.address, \"accessList.address\"),\n storageKeys: entry.storageKeys.map((k) => hex(k, \"accessList.storageKeys\")),\n});\n\nconst sign = (payload: `0x${string}`, privateKey: `0x${string}`) =>\n Secp256k1.sign({ payload, privateKey, as: \"Object\" as const });\n\n/** Signs a normalized transaction; returns the serialized signed envelope. */\nexport const signEvmTransaction = (tx: EvmTransaction, privateKey: Uint8Array): Uint8Array => {\n const privateKeyHex = key(privateKey);\n const base = {\n chainId: tx.chainId,\n to: tx.to === undefined ? undefined : hex(tx.to, \"to\"),\n data: hex(tx.data, \"data\"),\n value: BigInt(tx.value),\n nonce: BigInt(tx.nonce),\n gas: BigInt(tx.gas),\n };\n if (tx.type === \"legacy\") {\n const envelope = { ...base, type: \"legacy\" as const, gasPrice: BigInt(tx.gasPrice) };\n const signature = sign(TxEnvelopeLegacy.getSignPayload(envelope), privateKeyHex);\n return Hex.toBytes(TxEnvelopeLegacy.serialize(envelope, { signature }));\n }\n if (tx.type === \"eip2930\") {\n const envelope = {\n ...base,\n type: \"eip2930\" as const,\n gasPrice: BigInt(tx.gasPrice),\n accessList: tx.accessList.map(accessEntry),\n };\n const signature = sign(TxEnvelopeEip2930.getSignPayload(envelope), privateKeyHex);\n return Hex.toBytes(TxEnvelopeEip2930.serialize(envelope, { signature }));\n }\n const envelope = {\n ...base,\n type: \"eip1559\" as const,\n accessList: tx.accessList.map(accessEntry),\n maxFeePerGas: BigInt(tx.maxFeePerGas),\n maxPriorityFeePerGas: BigInt(tx.maxPriorityFeePerGas),\n };\n const signature = sign(TxEnvelopeEip1559.getSignPayload(envelope), privateKeyHex);\n return Hex.toBytes(TxEnvelopeEip1559.serialize(envelope, { signature }));\n};\n\n/** 65-byte r‖s‖v; `Signature.toBytes` emits v = 27 + yParity already. */\nconst rs_v = (signature: Signature.Signature): Uint8Array => Signature.toBytes(signature);\n\n/** EIP-191 personal_sign; returns the 65-byte signature r‖s‖v with v∈{27,28}. */\nexport const signEvmPersonalMessage = (message: Uint8Array, privateKey: Uint8Array): Uint8Array => {\n const payload = PersonalMessage.getSignPayload(Hex.fromBytes(message));\n return rs_v(Signature.from(sign(payload, key(privateKey))));\n};\n\n/** EIP-712 typed data; returns the 65-byte signature r‖s‖v with v∈{27,28}. */\nexport const signEvmTypedData = (typedData: string, privateKey: Uint8Array): Uint8Array => {\n const { json } = parseTypedData(typedData, \"eip155:1\");\n const payload = TypedData.getSignPayload(json);\n return rs_v(Signature.from(sign(payload, key(privateKey))));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAS,UAAU,OAAe,OAA+C;CAC/E,IAAI,CAAC,0BAA0B,KAAK,KAAK,GACvC,MAAM,IAAI,WAAW,oBAAoB,GAAG,MAAM,2BAA2B;AAEjF;AAEA,MAAM,OAAO,OAAe,UAAiC;CAC3D,UAAU,OAAO,KAAK;CACtB,OAAO;AACT;AAEA,MAAM,OAAO,eAA0C;CACrD,IAAI,WAAW,WAAW,IACxB,MAAM,IAAI,WAAW,mBAAmB,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D;CACA,MAAM,YAAY,KAAK,kBAAkB,eAAe,QAAQ,GAAG,aAAa;CAChF,OAAO,IAAI,QAAQ,kBAAkB,UAAU,UAAU,EAAE,UAAU,CAAC,CAAC;AACzE;;AAGA,MAAM,QAAQ,cAA+C,UAAU,QAAQ,SAAS;;AAGxF,MAAa,0BAA0B,SAAqB,eAAuC;CACjG,MAAM,UAAU,gBAAgB,eAAe,IAAI,UAAU,OAAO,CAAC;CACrE,OAAO,KAAK,UAAU,KAAK,KAAK,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC;AAC5D;;AAGA,MAAa,oBAAoB,WAAmB,eAAuC;CACzF,MAAM,EAAE,SAAS,eAAe,WAAW,UAAU;CACrD,MAAM,UAAU,UAAU,eAAe,IAAI;CAC7C,OAAO,KAAK,UAAU,KAAK,KAAK,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC;AAC5D"}
|
package/dist/evm.d.mts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { DisplayIntent, EvmTransaction, SignRequest, Verifiability } from "./index.mjs";
|
|
2
|
+
//#region src/evm/address.d.ts
|
|
3
|
+
/** EIP-55 checksummed address, e.g. `0x52908400098527886E0F7030069857D2E4169EE7`. */
|
|
4
|
+
export declare const isEvmAddress: (value: string) => boolean;
|
|
5
|
+
export declare function checksumEvmAddress(address: string): string;
|
|
6
|
+
/** `keccak256(pubkey)[12:]` — accepts a 33-byte compressed or 65-byte uncompressed secp256k1 key. */
|
|
7
|
+
export declare function evmAddressFromPublicKey(pubkey: Uint8Array): string;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/evm/transaction.d.ts
|
|
10
|
+
export declare const isCanonicalHex: (value: string) => boolean;
|
|
11
|
+
export declare const canonicalHex: (value: bigint) => string;
|
|
12
|
+
/** The EIP-155 part of a CAIP-2 `network` string, e.g. `eip155:1` → 1. */
|
|
13
|
+
export declare const networkChainId: (network: string) => number;
|
|
14
|
+
/**
|
|
15
|
+
* Canonicalizes an EVM transaction: exact key sets per type, all required fields present, `0x`
|
|
16
|
+
* canonical quantities, EIP-55 addresses. Idempotent.
|
|
17
|
+
*/
|
|
18
|
+
export declare const normalizeEvmTransaction: (tx: unknown) => EvmTransaction;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/evm/tokens.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* Built-in ERC-20 token table, keyed by `chainId` then checksummed address. An entry here makes an
|
|
23
|
+
* ERC-20 `transfer` `full`-verifiable (WD-065), so every entry must come from the issuer's own
|
|
24
|
+
* published list and be reviewed against it; the source is recorded per issuer below.
|
|
25
|
+
*/
|
|
26
|
+
type EvmToken = {
|
|
27
|
+
readonly symbol: string;
|
|
28
|
+
readonly decimals: number;
|
|
29
|
+
readonly name?: string;
|
|
30
|
+
};
|
|
31
|
+
type EvmTokenTable = Readonly<Record<string, Readonly<Record<string, EvmToken>>>>;
|
|
32
|
+
/** The built-in table. */
|
|
33
|
+
export declare const evmTokenTable: EvmTokenTable;
|
|
34
|
+
export declare const lookupEvmToken: (table: EvmTokenTable, chainId: number, address: string) => EvmToken | undefined;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/evm/decode.d.ts
|
|
37
|
+
/** What the signer can guarantee about this request (WD-065). */
|
|
38
|
+
export declare const verifiabilityEvm: (request: SignRequest) => Verifiability;
|
|
39
|
+
/**
|
|
40
|
+
* Decodes a normalized request into a DisplayIntent. The token table parameter is for tests;
|
|
41
|
+
* production callers use the built-in table.
|
|
42
|
+
*/
|
|
43
|
+
export declare const decodeEvm: (request: SignRequest, table?: EvmTokenTable) => DisplayIntent;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/evm/recover.d.ts
|
|
46
|
+
/**
|
|
47
|
+
* The EIP-55 address that produced `result` for `request` — a `chain.sign` round-trip check
|
|
48
|
+
* (`{kind:"evm.transaction",signedTransaction}` | `{kind,signature}`).
|
|
49
|
+
*/
|
|
50
|
+
export declare const recoverEvmSigner: (request: Extract<SignRequest, {
|
|
51
|
+
network: string;
|
|
52
|
+
}>, result: {
|
|
53
|
+
readonly signedTransaction?: Uint8Array;
|
|
54
|
+
readonly signature?: Uint8Array;
|
|
55
|
+
}) => string;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/evm/typed-data.d.ts
|
|
58
|
+
type TypedDataField = {
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly type: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The subset of the EIP-712 document the wallet needs to see before handing it to ox's validator —
|
|
64
|
+
* object with `types`, `primaryType`, `domain` and `message` of the right shapes.
|
|
65
|
+
*/
|
|
66
|
+
type TypedDataInput = {
|
|
67
|
+
readonly types: Record<string, ReadonlyArray<TypedDataField>>;
|
|
68
|
+
readonly primaryType: string;
|
|
69
|
+
readonly domain: Record<string, unknown>;
|
|
70
|
+
readonly message: Record<string, unknown>;
|
|
71
|
+
};
|
|
72
|
+
type ParsedTypedData = {
|
|
73
|
+
readonly json: TypedDataInput;
|
|
74
|
+
/**
|
|
75
|
+
* True when `domain.chainId` disagrees with the request's network — the intent is still signable
|
|
76
|
+
* but renders `opaque` with a warning.
|
|
77
|
+
*/
|
|
78
|
+
readonly chainIdMismatch: boolean;
|
|
79
|
+
};
|
|
80
|
+
/** Parses the EIP-712 JSON source and validates its shape with ox. */
|
|
81
|
+
export declare const parseTypedData: (typedData: string, network: string) => ParsedTypedData;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/evm/index.d.ts
|
|
84
|
+
export declare const normalizeEvm: (request: unknown) => SignRequest;
|
|
85
|
+
//#endregion
|
|
86
|
+
export type { EvmToken, EvmTokenTable };
|
|
87
|
+
//# sourceMappingURL=evm.d.mts.map
|
package/dist/evm.mjs
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
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-C6XANSQF.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
|
+
//#region src/evm/tokens.ts
|
|
13
|
+
const USDC = Object.freeze({
|
|
14
|
+
symbol: "USDC",
|
|
15
|
+
decimals: 6,
|
|
16
|
+
name: "USD Coin"
|
|
17
|
+
});
|
|
18
|
+
const USDT = Object.freeze({
|
|
19
|
+
symbol: "USDT",
|
|
20
|
+
decimals: 6,
|
|
21
|
+
name: "Tether USD"
|
|
22
|
+
});
|
|
23
|
+
/** The built-in table. */
|
|
24
|
+
const evmTokenTable = Object.freeze({
|
|
25
|
+
"1": Object.freeze({
|
|
26
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48": USDC,
|
|
27
|
+
"0xdAC17F958D2ee523a2206206994597C13D831ec7": USDT
|
|
28
|
+
}),
|
|
29
|
+
"10": Object.freeze({ "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85": USDC }),
|
|
30
|
+
"137": Object.freeze({ "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359": USDC }),
|
|
31
|
+
"999": Object.freeze({ "0xb88339CB7199b77E23DB6E890353E22632Ba630f": USDC }),
|
|
32
|
+
"8453": Object.freeze({ "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913": USDC }),
|
|
33
|
+
"42161": Object.freeze({ "0xaf88d065e77c8cC2239327C5EDb3A432268e5831": USDC }),
|
|
34
|
+
"43114": Object.freeze({
|
|
35
|
+
"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E": USDC,
|
|
36
|
+
"0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7": USDT
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
const lookupEvmToken = (table, chainId, address) => table[String(chainId)]?.[address];
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/evm/decode.ts
|
|
42
|
+
const ERC20_TRANSFER = AbiFunction.from("function transfer(address to, uint256 amount)");
|
|
43
|
+
const ERC20_APPROVE = AbiFunction.from("function approve(address spender, uint256 amount)");
|
|
44
|
+
const ERC20_INCREASE = AbiFunction.from("function increaseAllowance(address spender, uint256 amount)");
|
|
45
|
+
const ERC721_TRANSFER_FROM = AbiFunction.from("function transferFrom(address from, address to, uint256 tokenId)");
|
|
46
|
+
const ERC721_SAFE_FROM = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 tokenId)");
|
|
47
|
+
const ERC1155_SAFE_FROM = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data)");
|
|
48
|
+
const NATIVE_ASSET = "native";
|
|
49
|
+
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
50
|
+
const argAddress = (args, index) => {
|
|
51
|
+
const value = args[index];
|
|
52
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) throw new ChainError("invalid-request", "decoded argument is not an address");
|
|
53
|
+
return checksumEvmAddress(value);
|
|
54
|
+
};
|
|
55
|
+
const argUint = (args, index) => {
|
|
56
|
+
const value = args[index];
|
|
57
|
+
if (typeof value !== "bigint") throw new ChainError("invalid-request", "decoded argument is not a uint256");
|
|
58
|
+
return value;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Decodes `data` as `fn` and verifies the encoding is canonical (re-encoding the decoded args
|
|
62
|
+
* reproduces the input byte-for-byte). Returns undefined on selector mismatch, decode failure or a
|
|
63
|
+
* non-canonical encoding — the caller falls through to the next candidate or the opaque class.
|
|
64
|
+
*/
|
|
65
|
+
const tryCall = (fn, data) => {
|
|
66
|
+
const selector = AbiFunction.getSelector(fn);
|
|
67
|
+
if (!data.toLowerCase().startsWith(selector)) return;
|
|
68
|
+
try {
|
|
69
|
+
assertHex(data, "data");
|
|
70
|
+
const args = AbiFunction.decodeData(fn, data);
|
|
71
|
+
if (!Array.isArray(args)) return;
|
|
72
|
+
return AbiFunction.encodeData(fn, args).toLowerCase() === data.toLowerCase() ? args : void 0;
|
|
73
|
+
} catch {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const weiAmount = (wei, symbol, decimals) => ({
|
|
78
|
+
asset: NATIVE_ASSET,
|
|
79
|
+
amount: wei.toString(10),
|
|
80
|
+
...symbol === void 0 ? {} : { symbol },
|
|
81
|
+
...decimals === void 0 ? {} : { decimals }
|
|
82
|
+
});
|
|
83
|
+
const feeWei = (tx) => BigInt(tx.gas) * (tx.type === "eip1559" ? BigInt(tx.maxFeePerGas) : BigInt(tx.gasPrice));
|
|
84
|
+
const nativeOutflow = (tx, to) => [{
|
|
85
|
+
to,
|
|
86
|
+
amount: weiAmount(BigInt(tx.value)),
|
|
87
|
+
verified: true
|
|
88
|
+
}];
|
|
89
|
+
const tokenFlow = (tx, to, amount, chainId, table) => {
|
|
90
|
+
const token = lookupEvmToken(table, chainId, tx.to ?? "");
|
|
91
|
+
return {
|
|
92
|
+
flows: [{
|
|
93
|
+
to,
|
|
94
|
+
amount: {
|
|
95
|
+
asset: tx.to ?? "",
|
|
96
|
+
amount: amount.toString(10),
|
|
97
|
+
...token === void 0 ? {} : {
|
|
98
|
+
symbol: token.symbol,
|
|
99
|
+
decimals: token.decimals
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
verified: token !== void 0
|
|
103
|
+
}],
|
|
104
|
+
verified: token !== void 0
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const approvalChange = (tx, spender, amount) => ({
|
|
108
|
+
asset: tx.to ?? "",
|
|
109
|
+
spender,
|
|
110
|
+
amount: amount.toString(10),
|
|
111
|
+
unlimited: amount === MAX_UINT256,
|
|
112
|
+
verified: false
|
|
113
|
+
});
|
|
114
|
+
const nftFlow = (asset, to, id) => [{
|
|
115
|
+
to,
|
|
116
|
+
amount: {
|
|
117
|
+
asset,
|
|
118
|
+
amount: id.toString(10)
|
|
119
|
+
},
|
|
120
|
+
verified: false
|
|
121
|
+
}];
|
|
122
|
+
const decodeTransaction = (request, table) => {
|
|
123
|
+
const { tx } = request;
|
|
124
|
+
const chainId = networkChainId(request.network);
|
|
125
|
+
const data = tx.data.toLowerCase();
|
|
126
|
+
const fee = { max: weiAmount(feeWei(tx)) };
|
|
127
|
+
const base = {
|
|
128
|
+
family: "evm",
|
|
129
|
+
network: request.network,
|
|
130
|
+
approvals: [],
|
|
131
|
+
warnings: []
|
|
132
|
+
};
|
|
133
|
+
if (data === "0x") {
|
|
134
|
+
if (tx.to === void 0) return {
|
|
135
|
+
...base,
|
|
136
|
+
summary: "contract-call",
|
|
137
|
+
outflows: [],
|
|
138
|
+
fee,
|
|
139
|
+
verifiability: "opaque"
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
...base,
|
|
143
|
+
summary: "transfer",
|
|
144
|
+
outflows: nativeOutflow(tx, tx.to),
|
|
145
|
+
fee,
|
|
146
|
+
verifiability: "full"
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const transferArgs = tryCall(ERC20_TRANSFER, data);
|
|
150
|
+
if (transferArgs !== void 0) {
|
|
151
|
+
const { flows, verified } = tokenFlow(tx, argAddress(transferArgs, 0), argUint(transferArgs, 1), chainId, table);
|
|
152
|
+
return {
|
|
153
|
+
...base,
|
|
154
|
+
summary: "transfer",
|
|
155
|
+
outflows: flows,
|
|
156
|
+
fee,
|
|
157
|
+
verifiability: verified ? "full" : "partial"
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const approveArgs = tryCall(ERC20_APPROVE, data);
|
|
161
|
+
if (approveArgs !== void 0) return {
|
|
162
|
+
...base,
|
|
163
|
+
summary: "approve",
|
|
164
|
+
outflows: [],
|
|
165
|
+
approvals: [approvalChange(tx, argAddress(approveArgs, 0), argUint(approveArgs, 1))],
|
|
166
|
+
fee,
|
|
167
|
+
verifiability: "partial"
|
|
168
|
+
};
|
|
169
|
+
const increaseArgs = tryCall(ERC20_INCREASE, data);
|
|
170
|
+
if (increaseArgs !== void 0) return {
|
|
171
|
+
...base,
|
|
172
|
+
summary: "approve",
|
|
173
|
+
outflows: [],
|
|
174
|
+
approvals: [approvalChange(tx, argAddress(increaseArgs, 0), argUint(increaseArgs, 1))],
|
|
175
|
+
fee,
|
|
176
|
+
verifiability: "partial"
|
|
177
|
+
};
|
|
178
|
+
for (const fn of [ERC721_TRANSFER_FROM, ERC721_SAFE_FROM]) {
|
|
179
|
+
const args = tryCall(fn, data);
|
|
180
|
+
if (args !== void 0) return {
|
|
181
|
+
...base,
|
|
182
|
+
summary: "transfer",
|
|
183
|
+
outflows: nftFlow(tx.to ?? "", argAddress(args, 1), argUint(args, 2)),
|
|
184
|
+
fee,
|
|
185
|
+
verifiability: "partial"
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const erc1155Args = tryCall(ERC1155_SAFE_FROM, data);
|
|
189
|
+
if (erc1155Args !== void 0) return {
|
|
190
|
+
...base,
|
|
191
|
+
summary: "transfer",
|
|
192
|
+
outflows: nftFlow(tx.to ?? "", argAddress(erc1155Args, 1), argUint(erc1155Args, 2)),
|
|
193
|
+
fee,
|
|
194
|
+
verifiability: "partial"
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
...base,
|
|
198
|
+
summary: "contract-call",
|
|
199
|
+
outflows: [],
|
|
200
|
+
fee,
|
|
201
|
+
verifiability: "opaque"
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
/** What the signer can guarantee about this request (WD-065). */
|
|
205
|
+
const verifiabilityEvm = (request) => decodeEvm(request).verifiability;
|
|
206
|
+
/**
|
|
207
|
+
* Decodes a normalized request into a DisplayIntent. The token table parameter is for tests;
|
|
208
|
+
* production callers use the built-in table.
|
|
209
|
+
*/
|
|
210
|
+
const decodeEvm = (request, table = evmTokenTable) => {
|
|
211
|
+
if (request.kind === "evm.transaction") return decodeTransaction(request, table);
|
|
212
|
+
if (request.kind === "evm.personal-message") return {
|
|
213
|
+
family: "evm",
|
|
214
|
+
network: request.network,
|
|
215
|
+
summary: "message",
|
|
216
|
+
outflows: [],
|
|
217
|
+
approvals: [],
|
|
218
|
+
fee: void 0,
|
|
219
|
+
warnings: [],
|
|
220
|
+
verifiability: "opaque"
|
|
221
|
+
};
|
|
222
|
+
if (request.kind !== "evm.typed-data") throw new ChainError("unsupported", `unsupported sign request kind: ${request.kind}`);
|
|
223
|
+
const parsed = parseTypedData(request.typedData, request.network);
|
|
224
|
+
return {
|
|
225
|
+
family: "evm",
|
|
226
|
+
network: request.network,
|
|
227
|
+
summary: "message",
|
|
228
|
+
outflows: [],
|
|
229
|
+
approvals: [],
|
|
230
|
+
fee: void 0,
|
|
231
|
+
warnings: typedDataWarnings(parsed),
|
|
232
|
+
verifiability: "opaque"
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/evm/recover.ts
|
|
237
|
+
/**
|
|
238
|
+
* Signer recovery for `chain.sign` results: the host re-derives the signer address from a signed
|
|
239
|
+
* envelope or a 65-byte signature and compares it with the account's `wallet.accounts` address — a
|
|
240
|
+
* kernel returning someone else's signature fails closed.
|
|
241
|
+
*/
|
|
242
|
+
function assertEip1559Hex(hex) {
|
|
243
|
+
if (!hex.startsWith("0x02")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
244
|
+
}
|
|
245
|
+
function assertEip2930Hex(hex) {
|
|
246
|
+
if (!hex.startsWith("0x01")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
247
|
+
}
|
|
248
|
+
const signatureOf = (env) => {
|
|
249
|
+
const { r, s, yParity } = env;
|
|
250
|
+
if (r === void 0 || s === void 0 || yParity === void 0) throw new ChainError("invalid-request", "envelope carries no signature");
|
|
251
|
+
return Signature.from({
|
|
252
|
+
r,
|
|
253
|
+
s,
|
|
254
|
+
yParity
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
/** Recover the signer's EIP-55 address from a serialized signed transaction envelope. */
|
|
258
|
+
const signerFromEnvelope = (signedTransaction) => {
|
|
259
|
+
const hex = Hex.fromBytes(signedTransaction);
|
|
260
|
+
const [tag] = signedTransaction;
|
|
261
|
+
if (tag === 2) {
|
|
262
|
+
assertEip1559Hex(hex);
|
|
263
|
+
const env = TxEnvelopeEip1559.deserialize(hex);
|
|
264
|
+
const payload = TxEnvelopeEip1559.getSignPayload(env);
|
|
265
|
+
return Secp256k1.recoverAddress({
|
|
266
|
+
payload,
|
|
267
|
+
signature: signatureOf(env)
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (tag === 1) {
|
|
271
|
+
assertEip2930Hex(hex);
|
|
272
|
+
const env = TxEnvelopeEip2930.deserialize(hex);
|
|
273
|
+
const payload = TxEnvelopeEip2930.getSignPayload(env);
|
|
274
|
+
return Secp256k1.recoverAddress({
|
|
275
|
+
payload,
|
|
276
|
+
signature: signatureOf(env)
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
const env = TxEnvelopeLegacy.deserialize(hex);
|
|
281
|
+
const payload = TxEnvelopeLegacy.getSignPayload(env);
|
|
282
|
+
return Secp256k1.recoverAddress({
|
|
283
|
+
payload,
|
|
284
|
+
signature: signatureOf(env)
|
|
285
|
+
});
|
|
286
|
+
} catch {
|
|
287
|
+
throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* The EIP-55 address that produced `result` for `request` — a `chain.sign` round-trip check
|
|
292
|
+
* (`{kind:"evm.transaction",signedTransaction}` | `{kind,signature}`).
|
|
293
|
+
*/
|
|
294
|
+
const recoverEvmSigner = (request, result) => {
|
|
295
|
+
if (request.kind === "evm.transaction") {
|
|
296
|
+
if (result.signedTransaction === void 0) throw new ChainError("invalid-request", "expected a signed transaction");
|
|
297
|
+
return signerFromEnvelope(result.signedTransaction);
|
|
298
|
+
}
|
|
299
|
+
if (result.signature === void 0 || result.signature.length !== 65) throw new ChainError("invalid-request", "expected a 65-byte signature");
|
|
300
|
+
const signature = Signature.from(result.signature);
|
|
301
|
+
if (request.kind === "evm.personal-message") {
|
|
302
|
+
const payload = PersonalMessage.getSignPayload(Hex.fromBytes(request.message));
|
|
303
|
+
return Secp256k1.recoverAddress({
|
|
304
|
+
payload,
|
|
305
|
+
signature
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
if (request.kind === "evm.typed-data") {
|
|
309
|
+
const { json } = parseTypedData(request.typedData, request.network);
|
|
310
|
+
const payload = TypedData.getSignPayload(json);
|
|
311
|
+
return Secp256k1.recoverAddress({
|
|
312
|
+
payload,
|
|
313
|
+
signature
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
throw new ChainError("unsupported", `cannot recover a signer for ${request.kind}`);
|
|
317
|
+
};
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/evm/index.ts
|
|
320
|
+
/**
|
|
321
|
+
* Normalizes a SignRequest for the EVM family: exact key sets, chainId vs the CAIP-2 `network`,
|
|
322
|
+
* canonical quantities and EIP-55 addresses. Idempotent.
|
|
323
|
+
*/
|
|
324
|
+
const isAccountRef = (value) => {
|
|
325
|
+
if (!isRecord(value) || typeof value["kind"] !== "string") return false;
|
|
326
|
+
if (value["kind"] === "hd") return typeof value["walletId"] === "string" && typeof value["groupIndex"] === "number" && typeof value["template"] === "string";
|
|
327
|
+
if (value["kind"] === "imported") return typeof value["keyId"] === "string" && typeof value["family"] === "string";
|
|
328
|
+
return false;
|
|
329
|
+
};
|
|
330
|
+
const normalizeEvm = (request) => {
|
|
331
|
+
if (!isRecord(request) || typeof request["kind"] !== "string") throw new ChainError("invalid-request", "request must be an object with a kind");
|
|
332
|
+
const { network } = request;
|
|
333
|
+
const { account } = request;
|
|
334
|
+
if (typeof network !== "string") throw new ChainError("invalid-request", "request.network must be a string");
|
|
335
|
+
if (!isAccountRef(account)) throw new ChainError("invalid-request", "request.account must be an AccountRef");
|
|
336
|
+
const chainId = networkChainId(network);
|
|
337
|
+
if (request["kind"] === "evm.transaction") {
|
|
338
|
+
const tx = normalizeEvmTransaction(request["tx"]);
|
|
339
|
+
if (tx.chainId !== chainId) throw new ChainError("chain-id-mismatch", `tx.chainId ${tx.chainId} does not match network ${network}`);
|
|
340
|
+
return {
|
|
341
|
+
kind: "evm.transaction",
|
|
342
|
+
network,
|
|
343
|
+
account,
|
|
344
|
+
tx
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if (request["kind"] === "evm.personal-message") {
|
|
348
|
+
const { message } = request;
|
|
349
|
+
if (!(message instanceof Uint8Array)) throw new ChainError("invalid-request", "personal-message payload must be bytes");
|
|
350
|
+
return {
|
|
351
|
+
kind: "evm.personal-message",
|
|
352
|
+
network,
|
|
353
|
+
account,
|
|
354
|
+
message
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
if (request["kind"] === "evm.typed-data") {
|
|
358
|
+
const { typedData } = request;
|
|
359
|
+
if (typeof typedData !== "string") throw new ChainError("invalid-request", "typed-data payload must be the JSON source string");
|
|
360
|
+
parseTypedData(typedData, network);
|
|
361
|
+
return {
|
|
362
|
+
kind: "evm.typed-data",
|
|
363
|
+
network,
|
|
364
|
+
account,
|
|
365
|
+
typedData
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
throw new ChainError("unsupported", `unsupported sign request kind: ${request["kind"]}`);
|
|
369
|
+
};
|
|
370
|
+
//#endregion
|
|
371
|
+
export { canonicalHex, checksumEvmAddress, decodeEvm, evmAddressFromPublicKey, evmTokenTable, isCanonicalHex, isEvmAddress, lookupEvmToken, networkChainId, normalizeEvm, normalizeEvmTransaction, parseTypedData, recoverEvmSigner, verifiabilityEvm };
|
|
372
|
+
|
|
373
|
+
//# 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. An entry here makes an\n * ERC-20 `transfer` `full`-verifiable (WD-065), so every entry must come from the issuer's own\n * published list and be reviewed against it; the source is recorded per issuer below.\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\n// Circle USDC (native issuance, 6 decimals), from\n// https://developers.circle.com/stablecoins/usdc-contract-addresses (reviewed 2026-10-30). BNB\n// Chain has no Circle-issued USDC (the Binance-pegged token is a different issuer), so it is absent.\nconst USDC: EvmToken = Object.freeze({ symbol: \"USDC\", decimals: 6, name: \"USD Coin\" });\n\n// Tether USDT (6 decimals), from https://tether.to/en/supported-protocols/ (reviewed 2026-10-31):\n// Tether lists USD₮ on Ethereum and Avalanche among our networks; bridged or third-party USDT on\n// other chains is a different issuer and is absent.\nconst USDT: EvmToken = Object.freeze({ symbol: \"USDT\", decimals: 6, name: \"Tether USD\" });\n\n/** The built-in table. */\nexport const evmTokenTable: EvmTokenTable = Object.freeze({\n \"1\": Object.freeze({\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\": USDC,\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\": USDT,\n }),\n \"10\": Object.freeze({ \"0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85\": USDC }),\n \"137\": Object.freeze({ \"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359\": USDC }),\n \"999\": Object.freeze({ \"0xb88339CB7199b77E23DB6E890353E22632Ba630f\": USDC }),\n \"8453\": Object.freeze({ \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\": USDC }),\n \"42161\": Object.freeze({ \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\": USDC }),\n \"43114\": Object.freeze({\n \"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E\": USDC,\n \"0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7\": USDT,\n }),\n});\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":";;;;;;;;;;;;AAiBA,MAAM,OAAiB,OAAO,OAAO;CAAE,QAAQ;CAAQ,UAAU;CAAG,MAAM;AAAW,CAAC;AAKtF,MAAM,OAAiB,OAAO,OAAO;CAAE,QAAQ;CAAQ,UAAU;CAAG,MAAM;AAAa,CAAC;;AAGxF,MAAa,gBAA+B,OAAO,OAAO;CACxD,KAAK,OAAO,OAAO;EACjB,8CAA8C;EAC9C,8CAA8C;CAChD,CAAC;CACD,MAAM,OAAO,OAAO,EAAE,8CAA8C,KAAK,CAAC;CAC1E,OAAO,OAAO,OAAO,EAAE,8CAA8C,KAAK,CAAC;CAC3E,OAAO,OAAO,OAAO,EAAE,8CAA8C,KAAK,CAAC;CAC3E,QAAQ,OAAO,OAAO,EAAE,8CAA8C,KAAK,CAAC;CAC5E,SAAS,OAAO,OAAO,EAAE,8CAA8C,KAAK,CAAC;CAC7E,SAAS,OAAO,OAAO;EACrB,8CAA8C;EAC9C,8CAA8C;CAChD,CAAC;AACH,CAAC;AAED,MAAa,kBACX,OACA,SACA,YACyB,MAAM,OAAO,OAAO,EAAE,GAAG;;;AC5BpD,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,QAAQ,KAAK;CACnB,IAAI,OAAO,UAAU,YAAY,CAAC,sBAAsB,KAAK,KAAK,GAChE,MAAM,IAAI,WAAW,mBAAmB,oCAAoC;CAE9E,OAAO,mBAA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,gBAAgB,YAAkC;CAC7D,IAAI,CAAC,SAAS,OAAO,KAAK,OAAO,QAAQ,YAAY,UACnD,MAAM,IAAI,WAAW,mBAAmB,uCAAuC;CAEjF,MAAM,EAAE,YAAY;CACpB,MAAM,EAAE,YAAY;CACpB,IAAI,OAAO,YAAY,UACrB,MAAM,IAAI,WAAW,mBAAmB,kCAAkC;CAE5E,IAAI,CAAC,aAAa,OAAO,GACvB,MAAM,IAAI,WAAW,mBAAmB,uCAAuC;CAEjF,MAAM,UAAU,eAAe,OAAO;CACtC,IAAI,QAAQ,YAAY,mBAAmB;EACzC,MAAM,KAAK,wBAAwB,QAAQ,KAAK;EAChD,IAAI,GAAG,YAAY,SACjB,MAAM,IAAI,WACR,qBACA,cAAc,GAAG,QAAQ,0BAA0B,SACrD;EAEF,OAAO;GAAE,MAAM;GAAmB;GAAS;GAAS;EAAG;CACzD;CACA,IAAI,QAAQ,YAAY,wBAAwB;EAC9C,MAAM,EAAE,YAAY;EACpB,IAAI,EAAE,mBAAmB,aACvB,MAAM,IAAI,WAAW,mBAAmB,wCAAwC;EAElF,OAAO;GAAE,MAAM;GAAwB;GAAS;GAAS;EAAQ;CACnE;CACA,IAAI,QAAQ,YAAY,kBAAkB;EACxC,MAAM,EAAE,cAAc;EACtB,IAAI,OAAO,cAAc,UACvB,MAAM,IAAI,WAAW,mBAAmB,mDAAmD;EAE7F,eAAe,WAAW,OAAO;EACjC,OAAO;GAAE,MAAM;GAAkB;GAAS;GAAS;EAAU;CAC/D;CACA,MAAM,IAAI,WAAW,eAAe,kCAAkC,QAAQ,SAAS;AACzF"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @qntx/wallet-chains — 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
|