@qntx/wallet-chains 0.12.0 → 0.14.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/README.md +13 -10
- package/dist/{account-ref-D2rW_qlI.mjs → account-ref-BFTeEyHt.mjs} +2 -2
- package/dist/{account-ref-D2rW_qlI.mjs.map → account-ref-BFTeEyHt.mjs.map} +1 -1
- package/dist/assemble-8GvNDony.mjs +405 -0
- package/dist/assemble-8GvNDony.mjs.map +1 -0
- package/dist/assemble-B3sO9Fvc.mjs +629 -0
- package/dist/assemble-B3sO9Fvc.mjs.map +1 -0
- package/dist/assemble-BdiPo0ZX.mjs +32 -0
- package/dist/assemble-BdiPo0ZX.mjs.map +1 -0
- package/dist/assets-sg2_Z3nZ.mjs +200 -0
- package/dist/assets-sg2_Z3nZ.mjs.map +1 -0
- package/dist/bitcoin-sign.d.mts +3 -0
- package/dist/bitcoin-sign.mjs +52 -18
- package/dist/bitcoin-sign.mjs.map +1 -1
- package/dist/bitcoin.d.mts +123 -7
- package/dist/bitcoin.mjs +162 -69
- package/dist/bitcoin.mjs.map +1 -1
- package/dist/evm-sign.d.mts +3 -1
- package/dist/evm-sign.mjs +25 -82
- package/dist/evm-sign.mjs.map +1 -1
- package/dist/evm.d.mts +252 -22
- package/dist/evm.mjs +2460 -448
- package/dist/evm.mjs.map +1 -1
- package/dist/families-BlgplKAJ.mjs +412 -0
- package/dist/families-BlgplKAJ.mjs.map +1 -0
- package/dist/index-CIRaHKpx.d.mts +941 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/networks.d.mts +29 -0
- package/dist/networks.mjs +245 -0
- package/dist/networks.mjs.map +1 -0
- package/dist/plan-wCnxHqRu.mjs +1311 -0
- package/dist/plan-wCnxHqRu.mjs.map +1 -0
- package/dist/solana-sign.d.mts +3 -0
- package/dist/solana-sign.mjs +23 -10
- package/dist/solana-sign.mjs.map +1 -1
- package/dist/solana.d.mts +136 -24
- package/dist/solana.mjs +1244 -63
- package/dist/solana.mjs.map +1 -1
- package/dist/src-CHB_z45M.mjs +387 -0
- package/dist/src-CHB_z45M.mjs.map +1 -0
- package/dist/tasks-7AFv3PQn.mjs +86 -0
- package/dist/tasks-7AFv3PQn.mjs.map +1 -0
- package/dist/token-call-DH22g8BL.mjs +914 -0
- package/dist/token-call-DH22g8BL.mjs.map +1 -0
- package/dist/tron-sign.d.mts +10 -0
- package/dist/tron-sign.mjs +36 -0
- package/dist/tron-sign.mjs.map +1 -0
- package/dist/tron.d.mts +328 -0
- package/dist/tron.mjs +1484 -0
- package/dist/tron.mjs.map +1 -0
- package/dist/typed-data-CE9h4U0F.d.mts +51 -0
- package/dist/typed-data-DRtKULsH.mjs +466 -0
- package/dist/typed-data-DRtKULsH.mjs.map +1 -0
- package/package.json +17 -10
- package/dist/index-DYwm4-Ec.d.mts +0 -256
- package/dist/message-ChhEZ0lx.mjs +0 -188
- package/dist/message-ChhEZ0lx.mjs.map +0 -1
- package/dist/src-8NZeEnrW.mjs +0 -67
- package/dist/src-8NZeEnrW.mjs.map +0 -1
- package/dist/typed-data-J5g2WemC.mjs +0 -227
- package/dist/typed-data-J5g2WemC.mjs.map +0 -1
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { MessageFields } from "@qntx/siwx";
|
|
2
|
-
/** A Sign-In with X message found in signed text (ERC-4361 / SIWS). */
|
|
3
|
-
type SignInParse = {
|
|
4
|
-
readonly status: "valid";
|
|
5
|
-
readonly fields: MessageFields;
|
|
6
|
-
} |
|
|
7
|
-
/** The text contains the sign-in preamble but is not a conforming message for this chain family. */
|
|
8
|
-
{
|
|
9
|
-
readonly status: "malformed";
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Finds a Sign-In with X message in `text` for the chain `family`. `undefined` when the text has no
|
|
13
|
-
* sign-in preamble; `malformed` when it has one but is not a conforming message for the family
|
|
14
|
-
* (ERC-4361: wallets should warn about that shape).
|
|
15
|
-
*/
|
|
16
|
-
declare function parseSignIn(text: string, family: "evm" | "solana"): SignInParse | undefined;
|
|
17
|
-
type ChainFamily = "evm" | "solana" | "bitcoin";
|
|
18
|
-
type AccountRef = {
|
|
19
|
-
readonly kind: "hd";
|
|
20
|
-
readonly walletId: string;
|
|
21
|
-
readonly groupIndex: number;
|
|
22
|
-
readonly template: string;
|
|
23
|
-
} | {
|
|
24
|
-
readonly kind: "imported";
|
|
25
|
-
readonly keyId: string;
|
|
26
|
-
readonly family: ChainFamily;
|
|
27
|
-
};
|
|
28
|
-
/** The BIP-44/49/84/86 account-level templates a bitcoin.psbt input may sign under. */
|
|
29
|
-
type BitcoinTemplate = "btc.bip44" | "btc.bip49" | "btc.bip84" | "btc.bip86";
|
|
30
|
-
type SignRequest = {
|
|
31
|
-
readonly kind: "bitcoin.psbt";
|
|
32
|
-
readonly network: string;
|
|
33
|
-
/** The wallet group whose keys sign; each signed input names its template. */
|
|
34
|
-
readonly account: {
|
|
35
|
-
readonly kind: "hd";
|
|
36
|
-
readonly walletId: string;
|
|
37
|
-
readonly groupIndex: number;
|
|
38
|
-
};
|
|
39
|
-
readonly psbt: Uint8Array;
|
|
40
|
-
/** Inputs to sign — non-empty, unique, ascending by index, in range; each with its template. */
|
|
41
|
-
readonly sign: ReadonlyArray<{
|
|
42
|
-
readonly index: number;
|
|
43
|
-
readonly template: BitcoinTemplate;
|
|
44
|
-
}>;
|
|
45
|
-
} | {
|
|
46
|
-
readonly kind: "bitcoin.message";
|
|
47
|
-
readonly network: string;
|
|
48
|
-
readonly account: AccountRef;
|
|
49
|
-
readonly address: string;
|
|
50
|
-
readonly message: string;
|
|
51
|
-
readonly format: "bip322-simple" | "legacy";
|
|
52
|
-
/** Account change chain and index the address is derived at (0 = receive, 1 = change). */
|
|
53
|
-
readonly change: 0 | 1;
|
|
54
|
-
readonly index: number;
|
|
55
|
-
} | {
|
|
56
|
-
readonly kind: "solana.transaction";
|
|
57
|
-
readonly network: string;
|
|
58
|
-
readonly account: AccountRef;
|
|
59
|
-
/** Compiled wire message (legacy or v0). */
|
|
60
|
-
readonly message: Uint8Array;
|
|
61
|
-
readonly lookupTables?: ReadonlyArray<{
|
|
62
|
-
readonly address: string;
|
|
63
|
-
readonly addresses: ReadonlyArray<string>;
|
|
64
|
-
}>;
|
|
65
|
-
} | {
|
|
66
|
-
readonly kind: "solana.message";
|
|
67
|
-
readonly network: string;
|
|
68
|
-
readonly account: AccountRef;
|
|
69
|
-
readonly message: Uint8Array;
|
|
70
|
-
/** Only "raw" exists in this layer; offchain formats land with C7. */
|
|
71
|
-
readonly format: "raw";
|
|
72
|
-
} | {
|
|
73
|
-
readonly kind: "evm.transaction";
|
|
74
|
-
readonly network: string;
|
|
75
|
-
readonly account: AccountRef;
|
|
76
|
-
readonly tx: EvmTransaction;
|
|
77
|
-
} | {
|
|
78
|
-
readonly kind: "evm.personal-message";
|
|
79
|
-
readonly network: string;
|
|
80
|
-
readonly account: AccountRef;
|
|
81
|
-
readonly message: Uint8Array;
|
|
82
|
-
} | {
|
|
83
|
-
readonly kind: "evm.typed-data";
|
|
84
|
-
readonly network: string;
|
|
85
|
-
readonly account: AccountRef;
|
|
86
|
-
readonly typedData: string;
|
|
87
|
-
};
|
|
88
|
-
type EvmAccessListEntry = {
|
|
89
|
-
readonly address: string;
|
|
90
|
-
readonly storageKeys: ReadonlyArray<string>;
|
|
91
|
-
};
|
|
92
|
-
type EvmTransactionBase = {
|
|
93
|
-
readonly chainId: number;
|
|
94
|
-
readonly nonce: number;
|
|
95
|
-
readonly gas: string;
|
|
96
|
-
readonly value: string;
|
|
97
|
-
readonly data: string;
|
|
98
|
-
readonly to?: string;
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* A complete transaction — every field the signer needs is present; `to` absent means contract
|
|
102
|
-
* creation.
|
|
103
|
-
*/
|
|
104
|
-
type EvmTransaction = (EvmTransactionBase & {
|
|
105
|
-
readonly type: "legacy";
|
|
106
|
-
readonly gasPrice: string;
|
|
107
|
-
}) | (EvmTransactionBase & {
|
|
108
|
-
readonly type: "eip2930";
|
|
109
|
-
readonly gasPrice: string;
|
|
110
|
-
readonly accessList: ReadonlyArray<EvmAccessListEntry>;
|
|
111
|
-
}) | (EvmTransactionBase & {
|
|
112
|
-
readonly type: "eip1559";
|
|
113
|
-
readonly accessList: ReadonlyArray<EvmAccessListEntry>;
|
|
114
|
-
readonly maxFeePerGas: string;
|
|
115
|
-
readonly maxPriorityFeePerGas: string;
|
|
116
|
-
});
|
|
117
|
-
type Verifiability = "full" | "partial" | "opaque";
|
|
118
|
-
type IntentSummary = "transfer" | "approve" | "contract-call" | "swap" | "message" | "authorization" | "batch";
|
|
119
|
-
type AssetAmount = {
|
|
120
|
-
readonly asset: string;
|
|
121
|
-
readonly amount: string;
|
|
122
|
-
readonly decimals?: number;
|
|
123
|
-
readonly symbol?: string;
|
|
124
|
-
};
|
|
125
|
-
type AssetFlow = {
|
|
126
|
-
readonly to: string;
|
|
127
|
-
readonly amount: AssetAmount;
|
|
128
|
-
readonly verified: boolean;
|
|
129
|
-
/** The ENS name the recipient was resolved from; attached by the engine, never decoded. */
|
|
130
|
-
readonly name?: string;
|
|
131
|
-
};
|
|
132
|
-
type ApprovalChange = {
|
|
133
|
-
/** A fungible-token allowance: on the token itself, or on Permit2 when `via` is "permit2". */
|
|
134
|
-
readonly kind: "allowance";
|
|
135
|
-
readonly spender: string;
|
|
136
|
-
/** The token and amount (base units); symbol/decimals when the token is in the built-in table. */
|
|
137
|
-
readonly amount: AssetAmount;
|
|
138
|
-
/**
|
|
139
|
-
* `set`: the allowance becomes `amount`; `increase`/`decrease`: it changes by `amount`;
|
|
140
|
-
* `transfer`: a one-time right to take up to `amount` before `expiration` (Permit2
|
|
141
|
-
* SignatureTransfer).
|
|
142
|
-
*/
|
|
143
|
-
readonly change: "set" | "increase" | "decrease" | "transfer";
|
|
144
|
-
/** `amount` is the type's maximum (uint256; uint160 for Permit2). */
|
|
145
|
-
readonly unlimited: boolean;
|
|
146
|
-
/** Unix seconds after which the allowance lapses (Permit2), when it has one. */
|
|
147
|
-
readonly expiration?: number;
|
|
148
|
-
readonly via?: "permit2";
|
|
149
|
-
/** The token is in the built-in table. */
|
|
150
|
-
readonly verified: boolean;
|
|
151
|
-
} | {
|
|
152
|
-
/** ERC-721/1155 `setApprovalForAll`: `spender` may move every token of `asset`. */
|
|
153
|
-
readonly kind: "operator";
|
|
154
|
-
readonly asset: string;
|
|
155
|
-
readonly spender: string;
|
|
156
|
-
/** `false` revokes. */
|
|
157
|
-
readonly approved: boolean;
|
|
158
|
-
readonly verified: false;
|
|
159
|
-
};
|
|
160
|
-
type IntentWarning = {
|
|
161
|
-
readonly kind: string;
|
|
162
|
-
readonly message: string;
|
|
163
|
-
};
|
|
164
|
-
/** One item a Seaport order offers or requests; recognized from EIP-712 `itemType` 0–5. */
|
|
165
|
-
type SeaportItem = {
|
|
166
|
-
readonly kind: "native" | "erc20" | "erc721" | "erc1155" | "erc721-criteria" | "erc1155-criteria";
|
|
167
|
-
/** The item's contract (EIP-55 checksummed; the zero address for `native`). */
|
|
168
|
-
readonly token: string;
|
|
169
|
-
/** `identifierOrCriteria` as a decimal string; a criteria root for the criteria kinds. */
|
|
170
|
-
readonly identifier: string;
|
|
171
|
-
readonly startAmount: AssetAmount;
|
|
172
|
-
readonly endAmount: AssetAmount;
|
|
173
|
-
};
|
|
174
|
-
/** A recognized Seaport `OrderComponents` message. */
|
|
175
|
-
type SeaportOrder = {
|
|
176
|
-
readonly offerer: string;
|
|
177
|
-
readonly zone: string;
|
|
178
|
-
readonly startTime: number | undefined;
|
|
179
|
-
readonly endTime: number | undefined;
|
|
180
|
-
readonly offer: ReadonlyArray<SeaportItem>;
|
|
181
|
-
readonly consideration: ReadonlyArray<SeaportItem & {
|
|
182
|
-
readonly recipient: string;
|
|
183
|
-
}>;
|
|
184
|
-
};
|
|
185
|
-
/** A recognized Safe `SafeTx` message. */
|
|
186
|
-
type SafeTransaction = {
|
|
187
|
-
readonly safe: string;
|
|
188
|
-
/** The Safe nonce as a decimal string. */
|
|
189
|
-
readonly nonce: string;
|
|
190
|
-
readonly operation: "call" | "delegatecall";
|
|
191
|
-
readonly to: string;
|
|
192
|
-
/** Wei, decimal. */
|
|
193
|
-
readonly value: string;
|
|
194
|
-
readonly data: string;
|
|
195
|
-
/** The inner call(s) decoded with the transaction rules (no fee); one per MultiSend entry. */
|
|
196
|
-
readonly calls: ReadonlyArray<DisplayIntent>;
|
|
197
|
-
/** The gas-refund terms, present when `gasPrice` is not zero. */
|
|
198
|
-
readonly refund?: {
|
|
199
|
-
readonly gasPrice: string;
|
|
200
|
-
readonly gasToken: string;
|
|
201
|
-
readonly refundReceiver: string;
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
/** The EIP-712 domain fields a wallet shows. */
|
|
205
|
-
type TypedDataDomain = {
|
|
206
|
-
readonly name?: string;
|
|
207
|
-
readonly version?: string;
|
|
208
|
-
readonly chainId?: number;
|
|
209
|
-
/** EIP-55 checksummed. */
|
|
210
|
-
readonly verifyingContract?: string;
|
|
211
|
-
readonly salt?: string;
|
|
212
|
-
};
|
|
213
|
-
/** What a message request signs. */
|
|
214
|
-
type MessageContent = {
|
|
215
|
-
readonly kind: "text";
|
|
216
|
-
readonly text: string;
|
|
217
|
-
readonly signIn?: SignInParse;
|
|
218
|
-
} | {
|
|
219
|
-
readonly kind: "bytes";
|
|
220
|
-
readonly hex: string;
|
|
221
|
-
} | {
|
|
222
|
-
readonly kind: "typed-data";
|
|
223
|
-
readonly primaryType: string;
|
|
224
|
-
readonly domain: TypedDataDomain;
|
|
225
|
-
readonly data: Readonly<Record<string, unknown>>;
|
|
226
|
-
/** A recognized Seaport order; only the exact `OrderComponents` shape populates it. */
|
|
227
|
-
readonly seaport?: SeaportOrder;
|
|
228
|
-
/** A recognized Safe transaction; only the exact `SafeTx` shape populates it. */
|
|
229
|
-
readonly safe?: SafeTransaction;
|
|
230
|
-
};
|
|
231
|
-
type DisplayIntent = {
|
|
232
|
-
readonly family: ChainFamily;
|
|
233
|
-
readonly network: string;
|
|
234
|
-
readonly summary: IntentSummary;
|
|
235
|
-
readonly outflows: ReadonlyArray<AssetFlow>;
|
|
236
|
-
readonly approvals: ReadonlyArray<ApprovalChange>;
|
|
237
|
-
/**
|
|
238
|
-
* `l1Data`: OP Stack L1 data fee plus operator fee, estimated by the engine and charged on top of
|
|
239
|
-
* `max`; not decodable from the transaction, so the kernel's own decode never sets it.
|
|
240
|
-
*/
|
|
241
|
-
readonly fee: {
|
|
242
|
-
readonly max: AssetAmount;
|
|
243
|
-
readonly l1Data?: AssetAmount;
|
|
244
|
-
} | undefined;
|
|
245
|
-
readonly warnings: ReadonlyArray<IntentWarning>;
|
|
246
|
-
/** What a message request signs; absent for transactions. */
|
|
247
|
-
readonly message?: MessageContent;
|
|
248
|
-
readonly verifiability: Verifiability;
|
|
249
|
-
};
|
|
250
|
-
type ChainErrorCode = "unknown-field" | "chain-id-mismatch" | "fee-payer-mismatch" | "invalid-quantity" | "invalid-address" | "invalid-typed-data" | "invalid-request" | "unsupported";
|
|
251
|
-
declare class ChainError extends Error {
|
|
252
|
-
readonly code: ChainErrorCode;
|
|
253
|
-
constructor(code: ChainErrorCode, message: string);
|
|
254
|
-
}
|
|
255
|
-
export { parseSignIn as S, SeaportOrder as _, BitcoinTemplate as a, Verifiability as b, ChainFamily as c, EvmTransaction as d, IntentSummary as f, SeaportItem as g, SafeTransaction as h, AssetFlow as i, DisplayIntent as l, MessageContent as m, ApprovalChange as n, ChainError as o, IntentWarning as p, AssetAmount as r, ChainErrorCode as s, AccountRef as t, EvmAccessListEntry as u, SignRequest as v, SignInParse as x, TypedDataDomain as y };
|
|
256
|
-
//# sourceMappingURL=index-DYwm4-Ec.d.mts.map
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { t as ChainError } from "./src-8NZeEnrW.mjs";
|
|
2
|
-
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
3
|
-
import { NETWORK, TEST_NETWORK } from "@scure/btc-signer/utils.js";
|
|
4
|
-
import { SigHash, Transaction } from "@scure/btc-signer/transaction.js";
|
|
5
|
-
import { sha256 } from "@noble/hashes/sha2.js";
|
|
6
|
-
// src/bitcoin/networks.ts
|
|
7
|
-
/**
|
|
8
|
-
* Bip122 CAIP-2 networks = `bip122:` + the first 32 hex chars of the genesis hash, verified against
|
|
9
|
-
* Bitcoin Core `src/kernel/chainparams.cpp` (assert(consensus.hashGenesisBlock == ...) per network
|
|
10
|
-
* class).
|
|
11
|
-
*/
|
|
12
|
-
const MAINNET_BIP32 = {
|
|
13
|
-
public: 76067358,
|
|
14
|
-
private: 76066276
|
|
15
|
-
};
|
|
16
|
-
const TESTNET_BIP32 = {
|
|
17
|
-
public: 70617039,
|
|
18
|
-
private: 70615956
|
|
19
|
-
};
|
|
20
|
-
const REGTEST_NETWORK = {
|
|
21
|
-
...TEST_NETWORK,
|
|
22
|
-
bech32: "bcrt"
|
|
23
|
-
};
|
|
24
|
-
const NETWORKS = Object.freeze([
|
|
25
|
-
{
|
|
26
|
-
caip2: "bip122:000000000019d6689c085ae165831e93",
|
|
27
|
-
genesis: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
|
|
28
|
-
params: NETWORK,
|
|
29
|
-
coinType: 0,
|
|
30
|
-
bip32: MAINNET_BIP32
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
caip2: "bip122:00000000da84f2bafbbc53dee25a72ae",
|
|
34
|
-
genesis: "00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043",
|
|
35
|
-
params: TEST_NETWORK,
|
|
36
|
-
coinType: 1,
|
|
37
|
-
bip32: TESTNET_BIP32
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
caip2: "bip122:00000008819873e925422c1ff0f99f7c",
|
|
41
|
-
genesis: "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
|
|
42
|
-
params: TEST_NETWORK,
|
|
43
|
-
coinType: 1,
|
|
44
|
-
bip32: TESTNET_BIP32
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
caip2: "bip122:0f9188f13cb7b2c71f2a335e3a4fc328",
|
|
48
|
-
genesis: "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",
|
|
49
|
-
params: REGTEST_NETWORK,
|
|
50
|
-
coinType: 1,
|
|
51
|
-
bip32: TESTNET_BIP32
|
|
52
|
-
}
|
|
53
|
-
]);
|
|
54
|
-
const BITCOIN_NETWORKS = Object.freeze(Object.fromEntries(NETWORKS.map((n) => [n.caip2, n])));
|
|
55
|
-
const bitcoinNetwork = (caip2) => {
|
|
56
|
-
const net = BITCOIN_NETWORKS[caip2];
|
|
57
|
-
if (net === void 0) throw new ChainError("unsupported", `unknown bitcoin network: ${caip2}`);
|
|
58
|
-
return net;
|
|
59
|
-
};
|
|
60
|
-
// src/bitcoin/message.ts
|
|
61
|
-
/**
|
|
62
|
-
* BIP-322 message signing ("simple" + legacy) built on btc-signer primitives.
|
|
63
|
-
* https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
|
|
64
|
-
*/
|
|
65
|
-
const utf8 = (s) => new TextEncoder().encode(s);
|
|
66
|
-
const BIP322_TAG = "BIP0322-signed-message";
|
|
67
|
-
const LEGACY_MAGIC = utf8("Bitcoin Signed Message:\n");
|
|
68
|
-
const concat = (...parts) => {
|
|
69
|
-
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
70
|
-
let o = 0;
|
|
71
|
-
for (const p of parts) {
|
|
72
|
-
out.set(p, o);
|
|
73
|
-
o += p.length;
|
|
74
|
-
}
|
|
75
|
-
return out;
|
|
76
|
-
};
|
|
77
|
-
/** CompactSize length prefix for the one-byte form. */
|
|
78
|
-
const varint = (n) => Uint8Array.of(n);
|
|
79
|
-
const COMPACT_SIZE_ONE_BYTE_MAX = 252;
|
|
80
|
-
/** A length-prefixed push; longer data would need a multi-byte CompactSize this code never emits. */
|
|
81
|
-
const pushData = (data) => {
|
|
82
|
-
if (data.length > COMPACT_SIZE_ONE_BYTE_MAX) throw new ChainError("invalid-request", "BIP-322 script data exceeds 252 bytes");
|
|
83
|
-
return concat(varint(data.length), data);
|
|
84
|
-
};
|
|
85
|
-
const u32le = (n) => Uint8Array.of(n % 256, Math.floor(n / 256) % 256, Math.floor(n / 65536) % 256, Math.floor(n / 16777216) % 256);
|
|
86
|
-
const u64le = (n) => {
|
|
87
|
-
const out = /* @__PURE__ */ new Uint8Array(8);
|
|
88
|
-
let v = n;
|
|
89
|
-
for (let i = 0; i < 8; i++) {
|
|
90
|
-
out[i] = Number(v % 256n);
|
|
91
|
-
v /= 256n;
|
|
92
|
-
}
|
|
93
|
-
return out;
|
|
94
|
-
};
|
|
95
|
-
/** BIP340 tagged hash: sha256(sha256(tag) || sha256(tag) || m). */
|
|
96
|
-
const bip322MessageHash = (message) => {
|
|
97
|
-
const tag = sha256(utf8(BIP322_TAG));
|
|
98
|
-
return sha256(concat(tag, tag, utf8(message)));
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Serialized to_spend tx per BIP-322: version 0, one input spending the zero prevout with the
|
|
102
|
-
* message-hash scriptSig, one output paying the message's scriptPubKey. Returns txid (hash256d,
|
|
103
|
-
* big-endian display order).
|
|
104
|
-
*/
|
|
105
|
-
const toSpend = (scriptPubKey, messageHash) => {
|
|
106
|
-
const scriptSig = concat(Uint8Array.of(0), pushData(messageHash));
|
|
107
|
-
const raw = concat(u32le(0), varint(1), /* @__PURE__ */ new Uint8Array(32), u32le(4294967295), pushData(scriptSig), u32le(0), varint(1), u64le(0n), pushData(scriptPubKey), u32le(0));
|
|
108
|
-
return {
|
|
109
|
-
txid: sha256(sha256(raw)),
|
|
110
|
-
raw
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Display-order (big-endian) txid of the BIP-322 to_spend transaction — exported for vector
|
|
115
|
-
* verification.
|
|
116
|
-
*/
|
|
117
|
-
const bip322ToSpendTxid = (scriptPubKey, message) => Uint8Array.from([...toSpend(scriptPubKey, bip322MessageHash(message)).txid].reverse());
|
|
118
|
-
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
119
|
-
const b64 = (i) => BASE64[i] ?? "";
|
|
120
|
-
const base64 = (bytes) => {
|
|
121
|
-
const c = b64;
|
|
122
|
-
let out = "";
|
|
123
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
124
|
-
const b0 = bytes[i] ?? 0;
|
|
125
|
-
const b1 = bytes[i + 1] ?? 0;
|
|
126
|
-
const b2 = bytes[i + 2] ?? 0;
|
|
127
|
-
out += c(Math.floor(b0 / 4)) + c(b0 % 4 * 16 + Math.floor(b1 / 16));
|
|
128
|
-
out += i + 1 < bytes.length ? c(b1 % 16 * 4 + Math.floor(b2 / 64)) : "=";
|
|
129
|
-
out += i + 2 < bytes.length ? c(b2 % 64) : "=";
|
|
130
|
-
}
|
|
131
|
-
return out;
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Signs the BIP-322 to_sign input through a btc-signer Transaction and returns the `smp`-prefixed
|
|
135
|
-
* base64 witness encoding. `scriptPubKey` is the message address's output script (P2WPKH or P2TR).
|
|
136
|
-
*/
|
|
137
|
-
const signBip322Simple = (message, scriptPubKey, privateKey, auxRand) => {
|
|
138
|
-
const hash = bip322MessageHash(message);
|
|
139
|
-
const { txid } = toSpend(scriptPubKey, hash);
|
|
140
|
-
const tx = new Transaction({
|
|
141
|
-
version: 0,
|
|
142
|
-
lockTime: 0,
|
|
143
|
-
allowUnknownOutputs: true
|
|
144
|
-
});
|
|
145
|
-
const pub = secp256k1.getPublicKey(privateKey, true);
|
|
146
|
-
tx.addInput({
|
|
147
|
-
txid,
|
|
148
|
-
index: 0,
|
|
149
|
-
sequence: 0,
|
|
150
|
-
witnessUtxo: {
|
|
151
|
-
script: scriptPubKey,
|
|
152
|
-
amount: 0n
|
|
153
|
-
},
|
|
154
|
-
bip32Derivation: [[pub, {
|
|
155
|
-
fingerprint: 0,
|
|
156
|
-
path: []
|
|
157
|
-
}]],
|
|
158
|
-
...scriptPubKey[0] === 81 ? { tapInternalKey: pub.slice(1) } : {}
|
|
159
|
-
});
|
|
160
|
-
tx.addOutput({
|
|
161
|
-
script: Uint8Array.of(106),
|
|
162
|
-
amount: 0n
|
|
163
|
-
});
|
|
164
|
-
const isTaproot = scriptPubKey[0] === 81;
|
|
165
|
-
if (!tx.signIdx(privateKey, 0, isTaproot ? [SigHash.DEFAULT, SigHash.ALL] : [SigHash.ALL], auxRand(0))) throw new ChainError("invalid-request", "key cannot sign this BIP-322 input");
|
|
166
|
-
tx.finalizeIdx(0);
|
|
167
|
-
const witness = tx.getInput(0).finalScriptWitness;
|
|
168
|
-
if (witness === void 0) throw new ChainError("invalid-request", "BIP-322 input produced no witness");
|
|
169
|
-
const raw = concat(varint(witness.length), ...witness.map(pushData));
|
|
170
|
-
return `smp${base64(raw)}`;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Legacy "Bitcoin Signed Message" compact signature for P2PKH addresses: base64(1-byte header +
|
|
174
|
-
* 64-byte compact ECDSA sig), header = 27 + recovery + 4 (compressed pubkey).
|
|
175
|
-
*/
|
|
176
|
-
const signLegacyMessage = (message, privateKey) => {
|
|
177
|
-
const data = concat(pushData(LEGACY_MAGIC), pushData(utf8(message)));
|
|
178
|
-
const hash = sha256(sha256(data));
|
|
179
|
-
const recovered = secp256k1.sign(hash, privateKey, {
|
|
180
|
-
lowS: true,
|
|
181
|
-
format: "recovered"
|
|
182
|
-
});
|
|
183
|
-
const header = 27 + (recovered[0] ?? 0) + 4;
|
|
184
|
-
return base64(concat(Uint8Array.of(header), recovered.slice(1)));
|
|
185
|
-
};
|
|
186
|
-
export { bitcoinNetwork as a, BITCOIN_NETWORKS as i, signBip322Simple as n, signLegacyMessage as r, bip322ToSpendTxid as t };
|
|
187
|
-
|
|
188
|
-
//# sourceMappingURL=message-ChhEZ0lx.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message-ChhEZ0lx.mjs","names":[],"sources":["../src/bitcoin/networks.ts","../src/bitcoin/message.ts"],"sourcesContent":["import { NETWORK, TEST_NETWORK } from \"@scure/btc-signer/utils.js\";\n/**\n * Bip122 CAIP-2 networks = `bip122:` + the first 32 hex chars of the genesis hash, verified against\n * Bitcoin Core `src/kernel/chainparams.cpp` (assert(consensus.hashGenesisBlock == ...) per network\n * class).\n */\n\nimport { ChainError } from \"../index.ts\";\n\nexport type BitcoinNetwork = {\n readonly caip2: string;\n readonly genesis: string;\n readonly params: typeof NETWORK;\n readonly coinType: 0 | 1;\n /** BIP-32 extended-key version bytes: `xpub`/`xprv` on mainnet, `tpub`/`tprv` elsewhere. */\n readonly bip32: { readonly public: number; readonly private: number };\n};\n\nconst MAINNET_BIP32 = { public: 0x0488b21e, private: 0x0488ade4 } as const;\nconst TESTNET_BIP32 = { public: 0x043587cf, private: 0x04358394 } as const;\n\n// btc-signer ships mainnet and testnet parameters only; regtest shares testnet's version bytes but\n// uses the `bcrt` bech32 prefix.\nconst REGTEST_NETWORK: typeof NETWORK = { ...TEST_NETWORK, bech32: \"bcrt\" };\n\nconst NETWORKS: ReadonlyArray<BitcoinNetwork> = Object.freeze([\n {\n caip2: \"bip122:000000000019d6689c085ae165831e93\",\n genesis: \"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f\",\n params: NETWORK,\n coinType: 0,\n bip32: MAINNET_BIP32,\n },\n {\n caip2: \"bip122:00000000da84f2bafbbc53dee25a72ae\",\n genesis: \"00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043\",\n params: TEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n {\n caip2: \"bip122:00000008819873e925422c1ff0f99f7c\",\n genesis: \"00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6\",\n params: TEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n {\n caip2: \"bip122:0f9188f13cb7b2c71f2a335e3a4fc328\",\n genesis: \"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206\",\n params: REGTEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n] as const);\n\nexport const BITCOIN_NETWORKS: Readonly<Record<string, BitcoinNetwork>> = Object.freeze(\n Object.fromEntries(NETWORKS.map((n) => [n.caip2, n])),\n);\n\nexport const bitcoinNetwork = (caip2: string): BitcoinNetwork => {\n const net = BITCOIN_NETWORKS[caip2];\n if (net === undefined) {\n throw new ChainError(\"unsupported\", `unknown bitcoin network: ${caip2}`);\n }\n return net;\n};\n","import { secp256k1 } from \"@noble/curves/secp256k1.js\";\n/**\n * BIP-322 message signing (\"simple\" + legacy) built on btc-signer primitives.\n * https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki\n */\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { SigHash, Transaction } from \"@scure/btc-signer/transaction.js\";\n\nimport { ChainError } from \"../index.ts\";\n\nconst utf8 = (s: string): Uint8Array => new TextEncoder().encode(s);\n\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst LEGACY_MAGIC = utf8(\"Bitcoin Signed Message:\\n\");\n\nconst concat = (...parts: ReadonlyArray<Uint8Array>): Uint8Array => {\n const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));\n let o = 0;\n for (const p of parts) {\n out.set(p, o);\n o += p.length;\n }\n return out;\n};\n\n/** CompactSize length prefix for the one-byte form. */\nconst varint = (n: number): Uint8Array => Uint8Array.of(n);\n\nconst COMPACT_SIZE_ONE_BYTE_MAX = 252;\n\n/** A length-prefixed push; longer data would need a multi-byte CompactSize this code never emits. */\nexport const pushData = (data: Uint8Array): Uint8Array => {\n if (data.length > COMPACT_SIZE_ONE_BYTE_MAX) {\n throw new ChainError(\"invalid-request\", \"BIP-322 script data exceeds 252 bytes\");\n }\n return concat(varint(data.length), data);\n};\n\nconst u32le = (n: number): Uint8Array =>\n Uint8Array.of(\n n % 256,\n Math.floor(n / 256) % 256,\n Math.floor(n / 65536) % 256,\n Math.floor(n / 16777216) % 256,\n );\n\nconst u64le = (n: bigint): Uint8Array => {\n const out = new Uint8Array(8);\n let v = n;\n for (let i = 0; i < 8; i++) {\n out[i] = Number(v % 256n);\n v /= 256n;\n }\n return out;\n};\n\n/** BIP340 tagged hash: sha256(sha256(tag) || sha256(tag) || m). */\nconst bip322MessageHash = (message: string): Uint8Array => {\n const tag = sha256(utf8(BIP322_TAG));\n return sha256(concat(tag, tag, utf8(message)));\n};\n\n/**\n * Serialized to_spend tx per BIP-322: version 0, one input spending the zero prevout with the\n * message-hash scriptSig, one output paying the message's scriptPubKey. Returns txid (hash256d,\n * big-endian display order).\n */\nconst toSpend = (\n scriptPubKey: Uint8Array,\n messageHash: Uint8Array,\n): { txid: Uint8Array; raw: Uint8Array } => {\n const scriptSig = concat(Uint8Array.of(0x00), pushData(messageHash));\n const raw = concat(\n u32le(0),\n varint(1),\n new Uint8Array(32),\n u32le(0xffffffff),\n pushData(scriptSig),\n u32le(0),\n varint(1),\n u64le(0n),\n pushData(scriptPubKey),\n u32le(0),\n );\n const txid = sha256(sha256(raw));\n return { txid, raw };\n};\n\n/**\n * Display-order (big-endian) txid of the BIP-322 to_spend transaction — exported for vector\n * verification.\n */\nexport const bip322ToSpendTxid = (scriptPubKey: Uint8Array, message: string): Uint8Array =>\n Uint8Array.from([...toSpend(scriptPubKey, bip322MessageHash(message)).txid].reverse());\n\nconst BASE64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nconst b64 = (i: number): string => BASE64[i] ?? \"\";\nconst base64 = (bytes: Uint8Array): string => {\n const c = b64;\n let out = \"\";\n for (let i = 0; i < bytes.length; i += 3) {\n const b0 = bytes[i] ?? 0;\n const b1 = bytes[i + 1] ?? 0;\n const b2 = bytes[i + 2] ?? 0;\n out += c(Math.floor(b0 / 4)) + c((b0 % 4) * 16 + Math.floor(b1 / 16));\n out += i + 1 < bytes.length ? c((b1 % 16) * 4 + Math.floor(b2 / 64)) : \"=\";\n out += i + 2 < bytes.length ? c(b2 % 64) : \"=\";\n }\n return out;\n};\n\n/**\n * Signs the BIP-322 to_sign input through a btc-signer Transaction and returns the `smp`-prefixed\n * base64 witness encoding. `scriptPubKey` is the message address's output script (P2WPKH or P2TR).\n */\nexport const signBip322Simple = (\n message: string,\n scriptPubKey: Uint8Array,\n privateKey: Uint8Array,\n auxRand: (n: number) => Uint8Array,\n): string => {\n const hash = bip322MessageHash(message);\n const { txid } = toSpend(scriptPubKey, hash);\n const tx = new Transaction({ version: 0, lockTime: 0, allowUnknownOutputs: true });\n const pub = secp256k1.getPublicKey(privateKey, true);\n tx.addInput({\n txid,\n index: 0,\n sequence: 0,\n witnessUtxo: { script: scriptPubKey, amount: 0n },\n bip32Derivation: [[pub, { fingerprint: 0, path: [] }]],\n ...(scriptPubKey[0] === 0x51 ? { tapInternalKey: pub.slice(1) } : {}),\n });\n tx.addOutput({ script: Uint8Array.of(0x6a), amount: 0n });\n const isTaproot = scriptPubKey[0] === 0x51;\n const ok = tx.signIdx(\n privateKey,\n 0,\n isTaproot ? [SigHash.DEFAULT, SigHash.ALL] : [SigHash.ALL],\n auxRand(0),\n );\n if (!ok) {\n throw new ChainError(\"invalid-request\", \"key cannot sign this BIP-322 input\");\n }\n tx.finalizeIdx(0);\n const witness = tx.getInput(0).finalScriptWitness;\n if (witness === undefined) {\n throw new ChainError(\"invalid-request\", \"BIP-322 input produced no witness\");\n }\n const raw = concat(varint(witness.length), ...witness.map(pushData));\n return `smp${base64(raw)}`;\n};\n\n/**\n * Legacy \"Bitcoin Signed Message\" compact signature for P2PKH addresses: base64(1-byte header +\n * 64-byte compact ECDSA sig), header = 27 + recovery + 4 (compressed pubkey).\n */\nexport const signLegacyMessage = (message: string, privateKey: Uint8Array): string => {\n const data = concat(pushData(LEGACY_MAGIC), pushData(utf8(message)));\n const hash = sha256(sha256(data));\n const recovered = secp256k1.sign(hash, privateKey, { lowS: true, format: \"recovered\" });\n const header = 27 + (recovered[0] ?? 0) + 4;\n return base64(concat(Uint8Array.of(header), recovered.slice(1)));\n};\n"],"mappings":"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"}
|
package/dist/src-8NZeEnrW.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { evm } from "@qntx/siwx/evm";
|
|
2
|
-
import { siws, validateAddress } from "@qntx/siwx/svm";
|
|
3
|
-
// src/sign-in.ts
|
|
4
|
-
const PREAMBLE = " wants you to sign in with your ";
|
|
5
|
-
const OPTIONAL_KEYS = [
|
|
6
|
-
"scheme",
|
|
7
|
-
"statement",
|
|
8
|
-
"expirationTime",
|
|
9
|
-
"notBefore",
|
|
10
|
-
"requestId"
|
|
11
|
-
];
|
|
12
|
-
const plainFields = (message) => {
|
|
13
|
-
const { domain, address, uri, version, chainId, nonce, issuedAt, resources } = message;
|
|
14
|
-
const fields = {
|
|
15
|
-
domain,
|
|
16
|
-
address,
|
|
17
|
-
uri,
|
|
18
|
-
version,
|
|
19
|
-
chainId,
|
|
20
|
-
nonce,
|
|
21
|
-
issuedAt
|
|
22
|
-
};
|
|
23
|
-
for (const key of OPTIONAL_KEYS) {
|
|
24
|
-
const value = message[key];
|
|
25
|
-
if (value !== void 0) fields[key] = value;
|
|
26
|
-
}
|
|
27
|
-
if (resources !== void 0) fields.resources = [...resources];
|
|
28
|
-
return fields;
|
|
29
|
-
};
|
|
30
|
-
const parseValid = (text, family) => {
|
|
31
|
-
if (family === "evm") {
|
|
32
|
-
const ns = evm();
|
|
33
|
-
const message = ns.parse(new TextEncoder().encode(text));
|
|
34
|
-
ns.account(message);
|
|
35
|
-
return plainFields(message);
|
|
36
|
-
}
|
|
37
|
-
const message = siws.parse(text);
|
|
38
|
-
validateAddress(message.address);
|
|
39
|
-
return plainFields(message);
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Finds a Sign-In with X message in `text` for the chain `family`. `undefined` when the text has no
|
|
43
|
-
* sign-in preamble; `malformed` when it has one but is not a conforming message for the family
|
|
44
|
-
* (ERC-4361: wallets should warn about that shape).
|
|
45
|
-
*/
|
|
46
|
-
function parseSignIn(text, family) {
|
|
47
|
-
try {
|
|
48
|
-
return {
|
|
49
|
-
status: "valid",
|
|
50
|
-
fields: parseValid(text, family)
|
|
51
|
-
};
|
|
52
|
-
} catch {
|
|
53
|
-
return text.includes(PREAMBLE) ? { status: "malformed" } : void 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// src/index.ts
|
|
57
|
-
var ChainError = class extends Error {
|
|
58
|
-
code;
|
|
59
|
-
constructor(code, message) {
|
|
60
|
-
super(message);
|
|
61
|
-
this.name = "ChainError";
|
|
62
|
-
this.code = code;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
export { parseSignIn as n, ChainError as t };
|
|
66
|
-
|
|
67
|
-
//# sourceMappingURL=src-8NZeEnrW.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"src-8NZeEnrW.mjs","names":[],"sources":["../src/sign-in.ts","../src/index.ts"],"sourcesContent":["/** Recognition of Sign-In with Ethereum (ERC-4361) and Sign-In with Solana text in signed messages. */\nimport type { Message, MessageFields } from \"@qntx/siwx\";\nimport { evm } from \"@qntx/siwx/evm\";\nimport { siws, validateAddress as validateSolanaAddress } from \"@qntx/siwx/svm\";\n\n/** A Sign-In with X message found in signed text (ERC-4361 / SIWS). */\nexport type SignInParse =\n | { readonly status: \"valid\"; readonly fields: MessageFields }\n /** The text contains the sign-in preamble but is not a conforming message for this chain family. */\n | { readonly status: \"malformed\" };\n\nconst PREAMBLE = \" wants you to sign in with your \";\n\nconst OPTIONAL_KEYS = [\"scheme\", \"statement\", \"expirationTime\", \"notBefore\", \"requestId\"] as const;\n\nconst plainFields = (message: Message): MessageFields => {\n const { domain, address, uri, version, chainId, nonce, issuedAt, resources } = message;\n const fields: { -readonly [K in keyof MessageFields]: MessageFields[K] } = {\n domain,\n address,\n uri,\n version,\n chainId,\n nonce,\n issuedAt,\n };\n for (const key of OPTIONAL_KEYS) {\n const value = message[key];\n if (value !== undefined) {\n fields[key] = value;\n }\n }\n if (resources !== undefined) {\n fields.resources = [...resources];\n }\n return fields;\n};\n\nconst parseValid = (text: string, family: \"evm\" | \"solana\"): MessageFields => {\n if (family === \"evm\") {\n const ns = evm();\n const message = ns.parse(new TextEncoder().encode(text));\n ns.account(message);\n return plainFields(message);\n }\n const message = siws.parse(text);\n validateSolanaAddress(message.address);\n return plainFields(message);\n};\n\n/**\n * Finds a Sign-In with X message in `text` for the chain `family`. `undefined` when the text has no\n * sign-in preamble; `malformed` when it has one but is not a conforming message for the family\n * (ERC-4361: wallets should warn about that shape).\n */\nexport function parseSignIn(text: string, family: \"evm\" | \"solana\"): SignInParse | undefined {\n try {\n return { status: \"valid\", fields: parseValid(text, family) };\n } catch {\n return text.includes(PREAMBLE) ? { status: \"malformed\" } : undefined;\n }\n}\n","/**\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\nimport type { SignInParse } from \"./sign-in.ts\";\n\nexport { parseSignIn } from \"./sign-in.ts\";\nexport type { SignInParse } from \"./sign-in.ts\";\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\n/** The BIP-44/49/84/86 account-level templates a bitcoin.psbt input may sign under. */\nexport type BitcoinTemplate = \"btc.bip44\" | \"btc.bip49\" | \"btc.bip84\" | \"btc.bip86\";\n\nexport type SignRequest =\n | {\n readonly kind: \"bitcoin.psbt\";\n readonly network: string;\n /** The wallet group whose keys sign; each signed input names its template. */\n readonly account: {\n readonly kind: \"hd\";\n readonly walletId: string;\n readonly groupIndex: number;\n };\n readonly psbt: Uint8Array;\n /** Inputs to sign — non-empty, unique, ascending by index, in range; each with its template. */\n readonly sign: ReadonlyArray<{ readonly index: number; readonly template: BitcoinTemplate }>;\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 /** The ENS name the recipient was resolved from; attached by the engine, never decoded. */\n readonly name?: string;\n};\n\nexport type ApprovalChange =\n | {\n /** A fungible-token allowance: on the token itself, or on Permit2 when `via` is \"permit2\". */\n readonly kind: \"allowance\";\n readonly spender: string;\n /** The token and amount (base units); symbol/decimals when the token is in the built-in table. */\n readonly amount: AssetAmount;\n /**\n * `set`: the allowance becomes `amount`; `increase`/`decrease`: it changes by `amount`;\n * `transfer`: a one-time right to take up to `amount` before `expiration` (Permit2\n * SignatureTransfer).\n */\n readonly change: \"set\" | \"increase\" | \"decrease\" | \"transfer\";\n /** `amount` is the type's maximum (uint256; uint160 for Permit2). */\n readonly unlimited: boolean;\n /** Unix seconds after which the allowance lapses (Permit2), when it has one. */\n readonly expiration?: number;\n readonly via?: \"permit2\";\n /** The token is in the built-in table. */\n readonly verified: boolean;\n }\n | {\n /** ERC-721/1155 `setApprovalForAll`: `spender` may move every token of `asset`. */\n readonly kind: \"operator\";\n readonly asset: string;\n readonly spender: string;\n /** `false` revokes. */\n readonly approved: boolean;\n readonly verified: false;\n };\n\nexport type IntentWarning = {\n readonly kind: string;\n readonly message: string;\n};\n\n/** One item a Seaport order offers or requests; recognized from EIP-712 `itemType` 0–5. */\nexport type SeaportItem = {\n readonly kind: \"native\" | \"erc20\" | \"erc721\" | \"erc1155\" | \"erc721-criteria\" | \"erc1155-criteria\";\n /** The item's contract (EIP-55 checksummed; the zero address for `native`). */\n readonly token: string;\n /** `identifierOrCriteria` as a decimal string; a criteria root for the criteria kinds. */\n readonly identifier: string;\n readonly startAmount: AssetAmount;\n readonly endAmount: AssetAmount;\n};\n\n/** A recognized Seaport `OrderComponents` message. */\nexport type SeaportOrder = {\n readonly offerer: string;\n readonly zone: string;\n readonly startTime: number | undefined;\n readonly endTime: number | undefined;\n readonly offer: ReadonlyArray<SeaportItem>;\n readonly consideration: ReadonlyArray<SeaportItem & { readonly recipient: string }>;\n};\n\n/** A recognized Safe `SafeTx` message. */\nexport type SafeTransaction = {\n readonly safe: string;\n /** The Safe nonce as a decimal string. */\n readonly nonce: string;\n readonly operation: \"call\" | \"delegatecall\";\n readonly to: string;\n /** Wei, decimal. */\n readonly value: string;\n readonly data: string;\n /** The inner call(s) decoded with the transaction rules (no fee); one per MultiSend entry. */\n readonly calls: ReadonlyArray<DisplayIntent>;\n /** The gas-refund terms, present when `gasPrice` is not zero. */\n readonly refund?: {\n readonly gasPrice: string;\n readonly gasToken: string;\n readonly refundReceiver: string;\n };\n};\n\n/** The EIP-712 domain fields a wallet shows. */\nexport type TypedDataDomain = {\n readonly name?: string;\n readonly version?: string;\n readonly chainId?: number;\n /** EIP-55 checksummed. */\n readonly verifyingContract?: string;\n readonly salt?: string;\n};\n\n/** What a message request signs. */\nexport type MessageContent =\n | { readonly kind: \"text\"; readonly text: string; readonly signIn?: SignInParse }\n | { readonly kind: \"bytes\"; readonly hex: string }\n | {\n readonly kind: \"typed-data\";\n readonly primaryType: string;\n readonly domain: TypedDataDomain;\n readonly data: Readonly<Record<string, unknown>>;\n /** A recognized Seaport order; only the exact `OrderComponents` shape populates it. */\n readonly seaport?: SeaportOrder;\n /** A recognized Safe transaction; only the exact `SafeTx` shape populates it. */\n readonly safe?: SafeTransaction;\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 /**\n * `l1Data`: OP Stack L1 data fee plus operator fee, estimated by the engine and charged on top of\n * `max`; not decodable from the transaction, so the kernel's own decode never sets it.\n */\n readonly fee: { readonly max: AssetAmount; readonly l1Data?: AssetAmount } | undefined;\n readonly warnings: ReadonlyArray<IntentWarning>;\n /** What a message request signs; absent for transactions. */\n readonly message?: MessageContent;\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":";;;AAWA,MAAM,WAAW;AAEjB,MAAM,gBAAgB;CAAC;CAAU;CAAa;CAAkB;CAAa;AAAW;AAExF,MAAM,eAAe,YAAoC;CACvD,MAAM,EAAE,QAAQ,SAAS,KAAK,SAAS,SAAS,OAAO,UAAU,cAAc;CAC/E,MAAM,SAAqE;EACzE;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,KAAK,MAAM,OAAO,eAAe;EAC/B,MAAM,QAAQ,QAAQ;EACtB,IAAI,UAAU,KAAA,GACZ,OAAO,OAAO;CAElB;CACA,IAAI,cAAc,KAAA,GAChB,OAAO,YAAY,CAAC,GAAG,SAAS;CAElC,OAAO;AACT;AAEA,MAAM,cAAc,MAAc,WAA4C;CAC5E,IAAI,WAAW,OAAO;EACpB,MAAM,KAAK,IAAI;EACf,MAAM,UAAU,GAAG,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,IAAI,CAAC;EACvD,GAAG,QAAQ,OAAO;EAClB,OAAO,YAAY,OAAO;CAC5B;CACA,MAAM,UAAU,KAAK,MAAM,IAAI;CAC/B,gBAAsB,QAAQ,OAAO;CACrC,OAAO,YAAY,OAAO;AAC5B;;;;;;AAOA,SAAgB,YAAY,MAAc,QAAmD;CAC3F,IAAI;EACF,OAAO;GAAE,QAAQ;GAAS,QAAQ,WAAW,MAAM,MAAM;EAAE;CAC7D,QAAQ;EACN,OAAO,KAAK,SAAS,QAAQ,IAAI,EAAE,QAAQ,YAAY,IAAI,KAAA;CAC7D;AACF;;ACwNA,IAAa,aAAb,cAAgC,MAAM;CACpC;CACA,YAAY,MAAsB,SAAiB;EACjD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF"}
|