@qntx/wallet 0.13.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.
Files changed (56) hide show
  1. package/README.md +145 -22
  2. package/dist/backup-CLzMs8DP.mjs +51 -0
  3. package/dist/backup-CLzMs8DP.mjs.map +1 -0
  4. package/dist/card.d.mts +12 -0
  5. package/dist/card.mjs +119 -0
  6. package/dist/card.mjs.map +1 -0
  7. package/dist/{chains-B-FmFmuV.d.mts → chains-u1M0CWkT.d.mts} +148 -31
  8. package/dist/chains.d.mts +11 -4
  9. package/dist/chains.mjs +19 -67
  10. package/dist/chains.mjs.map +1 -1
  11. package/dist/{channel-BLwce5hh.mjs → channel-BCZXU3pt.mjs} +105 -44
  12. package/dist/channel-BCZXU3pt.mjs.map +1 -0
  13. package/dist/check-C1fUpgva.mjs +193 -0
  14. package/dist/check-C1fUpgva.mjs.map +1 -0
  15. package/dist/{core-DaRwkTaV.mjs → core-Cx7p-0nG.mjs} +99 -19
  16. package/dist/core-Cx7p-0nG.mjs.map +1 -0
  17. package/dist/hardware-BL6zvhQh.d.mts +107 -0
  18. package/dist/hardware.d.mts +81 -0
  19. package/dist/hardware.mjs +446 -0
  20. package/dist/hardware.mjs.map +1 -0
  21. package/dist/host.d.mts +27 -19
  22. package/dist/host.mjs +440 -164
  23. package/dist/host.mjs.map +1 -1
  24. package/dist/{index-CEhrd0Pl.d.mts → index-UclKfprm.d.mts} +269 -19
  25. package/dist/index.d.mts +5 -3
  26. package/dist/index.mjs +3 -33
  27. package/dist/{internal-CAKfHjIg.mjs → internal-DwCus_Ws.mjs} +1 -6
  28. package/dist/internal-DwCus_Ws.mjs.map +1 -0
  29. package/dist/nostr.d.mts +2 -2
  30. package/dist/nostr.mjs +14 -14
  31. package/dist/nostr.mjs.map +1 -1
  32. package/dist/{protocol-fXHXJguP.mjs → protocol-DLE6lHmP.mjs} +475 -49
  33. package/dist/protocol-DLE6lHmP.mjs.map +1 -0
  34. package/dist/protocol.d.mts +5 -4
  35. package/dist/protocol.mjs +3 -3
  36. package/dist/secret-CbjbY5-f.mjs +25 -0
  37. package/dist/secret-CbjbY5-f.mjs.map +1 -0
  38. package/dist/sessions.d.mts +52 -0
  39. package/dist/sessions.mjs +71 -0
  40. package/dist/sessions.mjs.map +1 -0
  41. package/dist/spark.d.mts +3 -3
  42. package/dist/spark.mjs +5 -8
  43. package/dist/spark.mjs.map +1 -1
  44. package/dist/types-CRnacSqJ.d.mts +390 -0
  45. package/dist/types.d.mts +2 -2
  46. package/dist/types.mjs +7 -1
  47. package/dist/types.mjs.map +1 -1
  48. package/package.json +27 -13
  49. package/dist/channel-BLwce5hh.mjs.map +0 -1
  50. package/dist/core-DaRwkTaV.mjs.map +0 -1
  51. package/dist/index.mjs.map +0 -1
  52. package/dist/internal-CAKfHjIg.mjs.map +0 -1
  53. package/dist/protocol-fXHXJguP.mjs.map +0 -1
  54. package/dist/secret-CcjyF8D3.mjs +0 -205
  55. package/dist/secret-CcjyF8D3.mjs.map +0 -1
  56. package/dist/types-cAQAJBLi.d.mts +0 -260
@@ -1,4 +1,4 @@
1
- import { C as WalletErrorCode, c as FactorInfo, w as WalletInfo } from "./types-cAQAJBLi.mjs";
1
+ import { N as WalletErrorCode, d as FactorInfo, k as VaultWalletInfo } from "./types-CRnacSqJ.mjs";
2
2
  /**
3
3
  * Strict validator combinators for the secret-area protocol. Both sides share them: the kernel
4
4
  * validates every request, the host validates every response. Anything that does not match is a
@@ -9,6 +9,9 @@ declare class ValidationError extends Error {
9
9
  }
10
10
  type Validator<T> = (value: unknown) => T;
11
11
  type NullValue = null;
12
+ type ProtocolValue = NullValue | boolean | number | string | Uint8Array | ReadonlyArray<ProtocolValue> | {
13
+ readonly [key: string]: ProtocolValue;
14
+ };
12
15
  declare function literal<T extends NullValue | boolean | number | string>(expected: T): Validator<T>;
13
16
  declare const nullValue: Validator<NullValue>;
14
17
  declare const bool: Validator<boolean>;
@@ -40,16 +43,23 @@ declare function union<Vs extends ReadonlyArray<Validator<unknown>>>(...branches
40
43
  declare function validate<T>(validator: Validator<T>, value: unknown): T | undefined;
41
44
  type MethodSpec<P, R> = {
42
45
  readonly session: boolean;
43
- /** Whether a successful call refreshes the idle timer — presence-bearing methods only. */
46
+ /**
47
+ * Whether a successful call counts as user presence for the idle timer. It refreshes the deadline
48
+ * only on a host without a platform keystore (Web, Node); on a keystore host only a successful
49
+ * factor verification does.
50
+ */
44
51
  readonly presence: boolean;
45
52
  readonly params: Validator<P>;
46
53
  readonly result: Validator<R>;
47
54
  };
48
55
  /**
49
- * Vault factor material on the wire. `hardware` carries nothing: the kernel runs the platform
50
- * keystore ceremony itself, so the main runtime never touches the KEK.
56
+ * Vault factor material on the wire. `device` and `hardware` carry nothing: the kernel runs the
57
+ * platform keystore operations itself, so the main runtime never touches the KEK. `device` opens a
58
+ * session without user presence — it can never appear in a `verify` field.
51
59
  */
52
60
  type Factor = {
61
+ readonly kind: "device";
62
+ } | {
53
63
  readonly kind: "hardware";
54
64
  } | {
55
65
  readonly kind: "password";
@@ -59,6 +69,14 @@ type Factor = {
59
69
  readonly credentialId: Uint8Array;
60
70
  readonly prf: Uint8Array;
61
71
  };
72
+ /**
73
+ * A factor that may prove user presence — every `verify` field uses this validator, so a device
74
+ * factor never reaches `verifyFactor` through the protocol (the kernel rejects it again anyway).
75
+ */
76
+ type VerifyFactor = Exclude<Factor, {
77
+ readonly kind: "device";
78
+ }>;
79
+ declare const verifier: Validator<VerifyFactor>;
62
80
  /** A host-run backup passkey ceremony's evidence: the PRF over `backupSalt` (web). */
63
81
  type HostBackupPasskey = {
64
82
  readonly kind: "passkey";
@@ -66,15 +84,24 @@ type HostBackupPasskey = {
66
84
  readonly credentialId: Uint8Array;
67
85
  readonly prfBackup: Uint8Array;
68
86
  };
87
+ /**
88
+ * The backup password arm: the wire carries the bytes only on hosts without a keystore — on React
89
+ * Native the kernel collects the password through its secure input (`kernel`), so the main runtime
90
+ * never holds it.
91
+ */
92
+ type BackupPasswordFactor = {
93
+ readonly kind: "password";
94
+ readonly password: Uint8Array;
95
+ } | {
96
+ readonly kind: "password";
97
+ readonly ceremony: "kernel";
98
+ };
69
99
  /**
70
100
  * A factor that seals a new backup key. On React Native the kernel registers a protection
71
101
  * credential (`kernel`) itself and names it; on the web the host hands over its ceremony's
72
102
  * evidence.
73
103
  */
74
- type BackupFactor = {
75
- readonly kind: "password";
76
- readonly password: Uint8Array;
77
- } | HostBackupPasskey | {
104
+ type BackupFactor = BackupPasswordFactor | HostBackupPasskey | {
78
105
  readonly kind: "passkey";
79
106
  readonly ceremony: "kernel";
80
107
  readonly rpId: string;
@@ -85,10 +112,7 @@ type BackupFactor = {
85
112
  * A factor that opens a backup envelope. The `kernel` passkey arm asserts one of the envelope's own
86
113
  * credentials.
87
114
  */
88
- type BackupUnlockFactor = {
89
- readonly kind: "password";
90
- readonly password: Uint8Array;
91
- } | HostBackupPasskey | {
115
+ type BackupUnlockFactor = BackupPasswordFactor | HostBackupPasskey | {
92
116
  readonly kind: "passkey";
93
117
  readonly ceremony: "kernel";
94
118
  readonly rpId: string;
@@ -131,7 +155,7 @@ declare const walletErrorCode: Validator<WalletErrorCode>;
131
155
  * session it opened. Creating a wallet derives no protocol keys — modules add keys separately.
132
156
  */
133
157
  type CreatedResult = {
134
- readonly wallet: WalletInfo;
158
+ readonly wallet: VaultWalletInfo;
135
159
  readonly session: string;
136
160
  };
137
161
  declare const CORE_METHODS: {
@@ -142,13 +166,22 @@ declare const CORE_METHODS: {
142
166
  }>;
143
167
  readonly "vault.reset": MethodSpec<NullValue, NullValue>;
144
168
  readonly "vault.addFactor": MethodSpec<{
145
- readonly verify: Factor;
169
+ readonly verify: VerifyFactor;
146
170
  readonly factor: Factor;
147
171
  }, FactorInfo>;
148
172
  readonly "vault.removeFactor": MethodSpec<{
149
- readonly verify: Factor;
173
+ readonly verify: VerifyFactor;
150
174
  readonly id: string;
151
175
  }, NullValue>;
176
+ readonly "vault.enrolVerification": MethodSpec<NullValue, NullValue>;
177
+ readonly "vault.setAppLock": MethodSpec<{
178
+ readonly enabled: boolean;
179
+ readonly verify: VerifyFactor;
180
+ }, NullValue>;
181
+ readonly "vault.setBlindSigning": MethodSpec<{
182
+ readonly enabled: boolean;
183
+ readonly verify: VerifyFactor;
184
+ }, NullValue>;
152
185
  readonly "session.touch": MethodSpec<NullValue, NullValue>;
153
186
  readonly "wallet.createWithPasskey": MethodSpec<CreateWithPasskeyParams, CreatedResult>;
154
187
  readonly "wallet.restoreWithPasskey": MethodSpec<RestoreWithPasskeyParams, CreatedResult>;
@@ -169,13 +202,15 @@ declare const CORE_METHODS: {
169
202
  readonly draft: string;
170
203
  }, NullValue>;
171
204
  readonly "backup.enable": MethodSpec<{
172
- readonly verify: Factor;
205
+ readonly verify: VerifyFactor;
173
206
  readonly factors: ReadonlyArray<BackupFactor>;
174
207
  }, NullValue>;
175
208
  readonly "backup.update": MethodSpec<NullValue, {
176
209
  readonly envelope: string;
177
210
  }>;
178
- readonly "backup.disable": MethodSpec<NullValue, NullValue>;
211
+ readonly "backup.disable": MethodSpec<{
212
+ readonly verify: VerifyFactor;
213
+ }, NullValue>;
179
214
  readonly "backup.restore": MethodSpec<{
180
215
  readonly envelope: string;
181
216
  readonly backupFactor: BackupUnlockFactor;
@@ -185,7 +220,7 @@ declare const CORE_METHODS: {
185
220
  }>;
186
221
  readonly factor?: Factor;
187
222
  }, {
188
- readonly wallets: ReadonlyArray<WalletInfo>;
223
+ readonly wallets: ReadonlyArray<VaultWalletInfo>;
189
224
  readonly passphraseRequired: ReadonlyArray<string>;
190
225
  readonly session: string;
191
226
  }>;
@@ -195,44 +230,44 @@ declare const CORE_METHODS: {
195
230
  readonly factor?: Factor;
196
231
  }, CreatedResult>;
197
232
  readonly "wallet.exportMnemonic": MethodSpec<{
198
- readonly verify: Factor;
233
+ readonly verify: VerifyFactor;
199
234
  readonly walletId: string;
200
235
  }, {
201
236
  readonly mnemonic: Uint8Array;
202
237
  readonly passphrase?: Uint8Array;
203
238
  }>;
204
239
  readonly "wallet.delete": MethodSpec<{
205
- readonly verify: Factor;
240
+ readonly verify: VerifyFactor;
206
241
  readonly walletId: string;
207
242
  }, NullValue>;
208
243
  readonly "dataKeys.get": MethodSpec<{
209
244
  readonly purpose: string;
210
245
  }, Uint8Array>;
211
246
  readonly "keys.import": MethodSpec<{
212
- readonly family: "evm" | "solana" | "bitcoin";
247
+ readonly family: "evm" | "solana" | "bitcoin" | "tron";
213
248
  readonly secret: Uint8Array;
214
249
  }, {
215
250
  readonly keyId: string;
216
- readonly family: "evm" | "solana" | "bitcoin";
251
+ readonly family: "evm" | "solana" | "bitcoin" | "tron";
217
252
  readonly address: string;
218
253
  readonly createdAt: number;
219
254
  }>;
220
255
  readonly "keys.list": MethodSpec<NullValue, ReadonlyArray<{
221
256
  readonly keyId: string;
222
- readonly family: "evm" | "solana" | "bitcoin";
257
+ readonly family: "evm" | "solana" | "bitcoin" | "tron";
223
258
  readonly address: string;
224
259
  readonly createdAt: number;
225
260
  }>>;
226
261
  readonly "keys.remove": MethodSpec<{
227
- readonly verify: Factor;
262
+ readonly verify: VerifyFactor;
228
263
  readonly keyId: string;
229
264
  }, NullValue>;
230
265
  readonly "keys.export": MethodSpec<{
231
- readonly verify: Factor;
266
+ readonly verify: VerifyFactor;
232
267
  readonly keyId: string;
233
268
  }, Uint8Array>;
234
269
  };
235
- type ChainTemplate = "evm.bip44" | "solana.bip44-change" | "btc.bip44" | "btc.bip49" | "btc.bip84" | "btc.bip86";
270
+ type ChainTemplate = "evm.bip44" | "solana.bip44-change" | "tron.bip44" | "btc.bip44" | "btc.bip49" | "btc.bip84" | "btc.bip86";
236
271
  type ChainAccountsParams = {
237
272
  readonly walletId: string;
238
273
  readonly groupIndex: number;
@@ -243,10 +278,18 @@ type ChainAccount = {
243
278
  readonly template: "evm.bip44";
244
279
  readonly network: string;
245
280
  readonly address: string;
281
+ /** The serving entry passed an on-device check — always true for seed-custody wallets. */
282
+ readonly confirmed: boolean;
246
283
  } | {
247
284
  readonly template: "solana.bip44-change";
248
285
  readonly network: string;
249
286
  readonly address: string;
287
+ readonly confirmed: boolean;
288
+ } | {
289
+ readonly template: "tron.bip44";
290
+ readonly network: string;
291
+ readonly address: string;
292
+ readonly confirmed: boolean;
250
293
  } | {
251
294
  readonly template: "btc.bip44" | "btc.bip49" | "btc.bip84" | "btc.bip86";
252
295
  readonly network: string;
@@ -255,6 +298,9 @@ type ChainAccount = {
255
298
  readonly fingerprint: string;
256
299
  /** Account derivation path, e.g. "m/84'/0'/0'". */
257
300
  readonly path: string;
301
+ /** Highest proven change-chain index — the sealed mark the change scan reaches beyond. */
302
+ readonly changeMark: number;
303
+ readonly confirmed: boolean;
258
304
  };
259
305
  type AccountRef = {
260
306
  readonly kind: "hd";
@@ -264,7 +310,7 @@ type AccountRef = {
264
310
  } | {
265
311
  readonly kind: "imported";
266
312
  readonly keyId: string;
267
- readonly family: "evm" | "solana" | "bitcoin";
313
+ readonly family: "evm" | "solana" | "bitcoin" | "tron";
268
314
  };
269
315
  type EvmAccessListEntryWire = {
270
316
  readonly address: string;
@@ -311,6 +357,14 @@ type ChainSignRequest = {
311
357
  readonly network: string;
312
358
  readonly account: AccountRef;
313
359
  readonly message: Uint8Array;
360
+ } | {
361
+ readonly kind: "evm.fiat24-session";
362
+ readonly network: string;
363
+ readonly account: AccountRef;
364
+ /** The Fiat24 account token's decimal id. */
365
+ readonly tokenId: string;
366
+ /** Session expiry, Unix seconds. */
367
+ readonly deadline: number;
314
368
  } | {
315
369
  readonly kind: "evm.typed-data";
316
370
  readonly network: string;
@@ -340,6 +394,8 @@ type ChainSignRequest = {
340
394
  readonly walletId: string;
341
395
  readonly groupIndex: number;
342
396
  };
397
+ /** Who built this request — only "internal" requests may raise the change mark. */
398
+ readonly origin: "internal" | "external";
343
399
  readonly psbt: Uint8Array;
344
400
  readonly sign: ReadonlyArray<{
345
401
  readonly index: number;
@@ -354,12 +410,28 @@ type ChainSignRequest = {
354
410
  readonly format: "bip322-simple" | "legacy";
355
411
  readonly change: 0 | 1;
356
412
  readonly index: number;
413
+ } | {
414
+ readonly kind: "tron.transaction";
415
+ readonly network: string;
416
+ readonly account: AccountRef;
417
+ readonly rawData: Uint8Array;
418
+ } | {
419
+ readonly kind: "tron.message";
420
+ readonly network: string;
421
+ readonly account: AccountRef;
422
+ readonly message: Uint8Array;
423
+ } | {
424
+ readonly kind: "tron.typed-data";
425
+ readonly network: string;
426
+ readonly account: AccountRef;
427
+ /** The canonical TIP-712 document, as JSON text. */
428
+ readonly typedData: string;
357
429
  };
358
430
  type ChainSignResult = {
359
431
  readonly kind: "evm.transaction";
360
432
  readonly signedTransaction: Uint8Array;
361
433
  } | {
362
- readonly kind: "evm.personal-message" | "evm.typed-data";
434
+ readonly kind: "evm.personal-message" | "evm.fiat24-session" | "evm.typed-data";
363
435
  readonly signature: Uint8Array;
364
436
  } | {
365
437
  readonly kind: "solana.transaction" | "solana.message";
@@ -370,14 +442,59 @@ type ChainSignResult = {
370
442
  } | {
371
443
  readonly kind: "bitcoin.message";
372
444
  readonly signature: string;
445
+ } | {
446
+ readonly kind: "tron.transaction" | "tron.message" | "tron.typed-data";
447
+ readonly signature: Uint8Array;
373
448
  };
374
449
  type ChainSignParams = {
375
450
  readonly request: ChainSignRequest;
376
- readonly verify: Factor;
451
+ readonly verify: VerifyFactor;
452
+ };
453
+ /**
454
+ * A node `chain.exportAccount` can serve: the EVM account xpub (`m/44'/60'/0'`, MetaMask's
455
+ * crypto-hdkey), a group's signing leaf, or a Bitcoin account xpub (`m/p'/coin'/group'`).
456
+ */
457
+ type ChainExportNode = {
458
+ readonly kind: "evm.account";
459
+ } | {
460
+ readonly kind: "leaf";
461
+ readonly template: "evm.bip44" | "tron.bip44" | "solana.bip44-change";
462
+ } | {
463
+ readonly kind: "btc.account";
464
+ readonly template: "btc.bip44" | "btc.bip49" | "btc.bip84" | "btc.bip86";
465
+ readonly network: string;
466
+ };
467
+ type ChainExportParams = {
468
+ readonly walletId: string;
469
+ readonly groupIndex: number;
470
+ readonly nodes: ReadonlyArray<ChainExportNode>;
471
+ readonly verify: VerifyFactor;
472
+ /**
473
+ * Acknowledge exporting nodes a device never confirmed on-screen — the prompt shows one danger
474
+ * row per unconfirmed node. Absent, an unconfirmed node refuses with `approval-required`.
475
+ */
476
+ readonly acknowledgeUnconfirmed?: true;
477
+ };
478
+ type ChainExportedKey = {
479
+ readonly node: ChainExportNode;
480
+ readonly path: string;
481
+ readonly curve: "secp256k1" | "ed25519";
482
+ readonly publicKey: Uint8Array;
483
+ /** 32 bytes — present iff the node is an account (evm.account / btc.account). */
484
+ readonly chainCode?: Uint8Array;
485
+ /** 8 lowercase hex chars — present iff `chainCode` is. */
486
+ readonly parentFingerprint?: string;
487
+ };
488
+ type ChainExportResult = {
489
+ /** Master-key fingerprint as 8 lowercase hex chars. */
490
+ readonly fingerprint: string;
491
+ /** One key per requested node, in the same order. */
492
+ readonly keys: ReadonlyArray<ChainExportedKey>;
377
493
  };
378
494
  declare const CHAINS_METHODS: {
379
495
  readonly "wallet.accounts": MethodSpec<ChainAccountsParams, ChainAccount>;
380
496
  readonly "chain.sign": MethodSpec<ChainSignParams, ChainSignResult>;
497
+ readonly "chain.exportAccount": MethodSpec<ChainExportParams, ChainExportResult>;
381
498
  };
382
- export { validate as A, literal as C, record as D, opt as E, str as O, int as S, obj as T, ValidationError as _, ChainSignResult as a, bool as b, BackupUnlockFactor as c, CreatedResult as d, Factor as f, NullValue as g, walletErrorCode as h, ChainSignRequest as i, union as k, CORE_METHODS as l, RestoreWithPasskeyParams as m, ChainAccount as n, ChainTemplate as o, MethodSpec as p, ChainAccountsParams as r, BackupFactor as s, CHAINS_METHODS as t, CreateWithPasskeyParams as u, Validator as v, nullValue as w, bytes as x, arr as y };
383
- //# sourceMappingURL=chains-B-FmFmuV.d.mts.map
499
+ export { literal as A, ProtocolValue as C, bool as D, arr as E, str as F, union as I, validate as L, obj as M, opt as N, bytes as O, record as P, NullValue as S, Validator as T, MethodSpec as _, ChainExportParams as a, verifier as b, ChainSignRequest as c, BackupFactor as d, BackupUnlockFactor as f, Factor as g, CreatedResult as h, ChainExportNode as i, nullValue as j, int as k, ChainSignResult as l, CreateWithPasskeyParams as m, ChainAccount as n, ChainExportResult as o, CORE_METHODS as p, ChainAccountsParams as r, ChainExportedKey as s, CHAINS_METHODS as t, ChainTemplate as u, RestoreWithPasskeyParams as v, ValidationError as w, walletErrorCode as x, VerifyFactor as y };
500
+ //# sourceMappingURL=chains-u1M0CWkT.d.mts.map
package/dist/chains.d.mts CHANGED
@@ -1,12 +1,19 @@
1
- import { v as UnlockFactor, x as Wallet } from "./types-cAQAJBLi.mjs";
2
- import { a as ChainSignResult, i as ChainSignRequest, n as ChainAccount, o as ChainTemplate, r as ChainAccountsParams } from "./chains-B-FmFmuV.mjs";
1
+ import { A as VerifyFactor, j as Wallet } from "./types-CRnacSqJ.mjs";
2
+ import { a as ChainExportParams, c as ChainSignRequest, i as ChainExportNode, l as ChainSignResult, n as ChainAccount, o as ChainExportResult, r as ChainAccountsParams, s as ChainExportedKey, u as ChainTemplate } from "./chains-u1M0CWkT.mjs";
3
3
  export type ChainsApi = {
4
4
  readonly account: (params: ChainAccountsParams) => Promise<ChainAccount>;
5
5
  readonly sign: (params: {
6
6
  readonly request: ChainSignRequest;
7
- readonly verify: UnlockFactor;
7
+ readonly verify: VerifyFactor;
8
8
  }) => Promise<ChainSignResult>;
9
+ readonly exportAccount: (params: {
10
+ readonly walletId: string;
11
+ readonly groupIndex: number;
12
+ readonly nodes: ReadonlyArray<ChainExportNode>;
13
+ readonly verify: VerifyFactor;
14
+ readonly acknowledgeUnconfirmed?: true;
15
+ }) => Promise<ChainExportResult>;
9
16
  };
10
17
  export declare function chains(wallet: Wallet): ChainsApi;
11
- export type { ChainAccount, ChainAccountsParams, ChainSignRequest, ChainSignResult, ChainTemplate };
18
+ export type { ChainAccount, ChainAccountsParams, ChainExportNode, ChainExportParams, ChainExportResult, ChainExportedKey, ChainSignRequest, ChainSignResult, ChainTemplate };
12
19
  //# sourceMappingURL=chains.d.mts.map
package/dist/chains.mjs CHANGED
@@ -1,80 +1,32 @@
1
- import { n as integrity } from "./channel-BLwce5hh.mjs";
2
- import { t as internalsOf } from "./internal-CAKfHjIg.mjs";
3
- import { bitcoinAddressFromXpub, verifyBitcoinMessage, verifyBitcoinPsbtSignatures } from "@qntx/wallet-chains/bitcoin";
4
- import { recoverEvmSigner } from "@qntx/wallet-chains/evm";
5
- import { verifySolanaSignature } from "@qntx/wallet-chains/solana";
1
+ import { t as internalsOf } from "./internal-DwCus_Ws.mjs";
2
+ import { n as checkSignResult, t as checkExportResult } from "./check-C1fUpgva.mjs";
6
3
  // src/chains/index.ts
7
4
  /**
8
5
  * The chains module of @qntx/wallet: `chains(wallet)` returns the wallet's chain API. `account`
9
6
  * calls the kernel's `wallet.accounts`; `sign` calls `chain.sign` and then verifies the returned
10
- * signature against the account address — a kernel that answers with someone else's signature fails
11
- * closed with `integrity`.
7
+ * signature against the request and the account address — a kernel that answers with someone else's
8
+ * signature, or a signature over other content, fails closed with `integrity`.
12
9
  */
13
- /**
14
- * The PSBT check: each sign entry names its template, so the account is fetched once per distinct
15
- * template and each group's signatures verify against that template's xpub.
16
- */
17
- const checkPsbt = async (internals, request, result) => {
18
- if (result.kind !== "bitcoin.psbt") throw integrity("result kind does not match the request");
19
- const byTemplate = /* @__PURE__ */ new Map();
20
- for (const { index, template } of request.sign) {
21
- const group = byTemplate.get(template) ?? [];
22
- group.push(index);
23
- byTemplate.set(template, group);
24
- }
25
- for (const [template, indices] of byTemplate) {
26
- const account = await internals.call("wallet.accounts", {
27
- walletId: request.account.walletId,
28
- groupIndex: request.account.groupIndex,
29
- template,
30
- network: request.network
31
- });
32
- if (!("xpub" in account)) throw integrity("chain account has no xpub");
33
- if (!verifyBitcoinPsbtSignatures(result.signedPsbt, indices, account.xpub, template, request.network)) throw integrity("psbt signatures do not verify for the account");
34
- }
35
- };
36
- /** Whether the kernel's signature belongs to the account it was asked to sign for. */
37
- const checkSigner = (request, result, account) => {
38
- if (request.kind === "bitcoin.message") {
39
- if (!("xpub" in account)) throw integrity("chain account has no xpub");
40
- if (request.kind === "bitcoin.message" && result.kind === "bitcoin.message") {
41
- if (bitcoinAddressFromXpub(account.xpub, account.template, request.network, request.change, request.index) !== request.address || !verifyBitcoinMessage(request.address, request.message, result.signature, request.network)) throw integrity("message signature does not verify for the account");
42
- return;
43
- }
44
- throw integrity("result kind does not match the request");
45
- }
46
- if (!("address" in account)) throw integrity("chain account has no address");
47
- if (request.kind.startsWith("evm.")) {
48
- if (result.kind !== "evm.transaction" && result.kind !== "evm.personal-message" && result.kind !== "evm.typed-data") throw integrity("result kind does not match the request");
49
- if (recoverEvmSigner(request, result).toLowerCase() !== account.address.toLowerCase()) throw integrity("signer does not match the account");
50
- return;
51
- }
52
- if ((request.kind === "solana.transaction" || request.kind === "solana.message") && (result.kind === "solana.transaction" || result.kind === "solana.message") && !verifySolanaSignature(request.message, result.signature, account.address)) throw integrity("signature does not verify for the account");
53
- };
54
10
  function createChainsApi(internals) {
55
11
  return {
56
12
  account: async (params) => internals.call("wallet.accounts", params),
57
13
  sign: async (params) => internals.withVerifying(async () => {
58
- const verify = await internals.resolveFactor(params.verify, []);
59
- const result = await internals.call("chain.sign", {
14
+ const result = await internals.secretCall("chain.sign", async (wire) => ({
60
15
  request: params.request,
61
- verify
62
- });
63
- if (params.request.kind === "bitcoin.psbt") await checkPsbt(internals, params.request, result);
64
- else if (params.request.account.kind === "hd") {
65
- const account = await internals.call("wallet.accounts", {
66
- walletId: params.request.account.walletId,
67
- groupIndex: params.request.account.groupIndex,
68
- template: params.request.account.template,
69
- network: params.request.network
70
- });
71
- checkSigner(params.request, result, account);
72
- } else {
73
- const { keyId } = params.request.account;
74
- const key = (await internals.call("keys.list", null)).find((k) => k.keyId === keyId);
75
- if (key === void 0) throw integrity("chain.sign answered for a key not in the vault");
76
- checkSigner(params.request, result, { address: key.address });
77
- }
16
+ verify: await internals.resolveVerifyFactor(params.verify, wire)
17
+ }));
18
+ await checkSignResult(internals, params.request, result);
19
+ return result;
20
+ }),
21
+ exportAccount: async (params) => internals.withVerifying(async () => {
22
+ const result = await internals.secretCall("chain.exportAccount", async (wire) => ({
23
+ walletId: params.walletId,
24
+ groupIndex: params.groupIndex,
25
+ nodes: params.nodes,
26
+ verify: await internals.resolveVerifyFactor(params.verify, wire),
27
+ ...params.acknowledgeUnconfirmed === void 0 ? {} : { acknowledgeUnconfirmed: params.acknowledgeUnconfirmed }
28
+ }));
29
+ await checkExportResult(internals, params, result);
78
30
  return result;
79
31
  })
80
32
  };
@@ -1 +1 @@
1
- {"version":3,"file":"chains.mjs","names":[],"sources":["../src/chains/index.ts"],"sourcesContent":["/**\n * The chains module of @qntx/wallet: `chains(wallet)` returns the wallet's chain API. `account`\n * calls the kernel's `wallet.accounts`; `sign` calls `chain.sign` and then verifies the returned\n * signature against the account address — a kernel that answers with someone else's signature fails\n * closed with `integrity`.\n */\nimport {\n bitcoinAddressFromXpub,\n verifyBitcoinMessage,\n verifyBitcoinPsbtSignatures,\n} from \"@qntx/wallet-chains/bitcoin\";\nimport { recoverEvmSigner } from \"@qntx/wallet-chains/evm\";\nimport { verifySolanaSignature } from \"@qntx/wallet-chains/solana\";\n\nimport { integrity } from \"../channel.ts\";\nimport { internalsOf } from \"../internal.ts\";\nimport type { WalletInternals } from \"../internal.ts\";\nimport type {\n ChainAccount,\n ChainAccountsParams,\n ChainSignRequest,\n ChainSignResult,\n} from \"../protocol/chains.ts\";\nimport type { UnlockFactor, Wallet } from \"../types.ts\";\n\nexport type {\n ChainAccount,\n ChainAccountsParams,\n ChainSignRequest,\n ChainSignResult,\n ChainTemplate,\n} from \"../protocol/chains.ts\";\n\nexport type ChainsApi = {\n readonly account: (params: ChainAccountsParams) => Promise<ChainAccount>;\n readonly sign: (params: {\n readonly request: ChainSignRequest;\n readonly verify: UnlockFactor;\n }) => Promise<ChainSignResult>;\n};\n\n/**\n * The PSBT check: each sign entry names its template, so the account is fetched once per distinct\n * template and each group's signatures verify against that template's xpub.\n */\nconst checkPsbt = async (\n internals: WalletInternals,\n request: Extract<ChainSignRequest, { kind: \"bitcoin.psbt\" }>,\n result: ChainSignResult,\n): Promise<void> => {\n if (result.kind !== \"bitcoin.psbt\") {\n throw integrity(\"result kind does not match the request\");\n }\n const byTemplate = new Map<\"btc.bip44\" | \"btc.bip49\" | \"btc.bip84\" | \"btc.bip86\", number[]>();\n for (const { index, template } of request.sign) {\n const group = byTemplate.get(template) ?? [];\n group.push(index);\n byTemplate.set(template, group);\n }\n for (const [template, indices] of byTemplate) {\n // oxlint-disable-next-line eslint/no-await-in-loop -- one wallet.accounts call per template.\n const account = await internals.call(\"wallet.accounts\", {\n walletId: request.account.walletId,\n groupIndex: request.account.groupIndex,\n template,\n network: request.network,\n });\n if (!(\"xpub\" in account)) {\n throw integrity(\"chain account has no xpub\");\n }\n if (\n !verifyBitcoinPsbtSignatures(\n result.signedPsbt,\n indices,\n account.xpub,\n template,\n request.network,\n )\n ) {\n throw integrity(\"psbt signatures do not verify for the account\");\n }\n }\n};\n\n/** Whether the kernel's signature belongs to the account it was asked to sign for. */\nconst checkSigner = (\n request: ChainSignRequest,\n result: ChainSignResult,\n account: ChainAccount | { readonly address: string },\n) => {\n if (request.kind === \"bitcoin.message\") {\n if (!(\"xpub\" in account)) {\n throw integrity(\"chain account has no xpub\");\n }\n if (request.kind === \"bitcoin.message\" && result.kind === \"bitcoin.message\") {\n const derived = bitcoinAddressFromXpub(\n account.xpub,\n account.template,\n request.network,\n request.change,\n request.index,\n );\n if (\n derived !== request.address ||\n !verifyBitcoinMessage(request.address, request.message, result.signature, request.network)\n ) {\n throw integrity(\"message signature does not verify for the account\");\n }\n return;\n }\n throw integrity(\"result kind does not match the request\");\n }\n if (!(\"address\" in account)) {\n throw integrity(\"chain account has no address\");\n }\n if (request.kind.startsWith(\"evm.\")) {\n if (\n result.kind !== \"evm.transaction\" &&\n result.kind !== \"evm.personal-message\" &&\n result.kind !== \"evm.typed-data\"\n ) {\n throw integrity(\"result kind does not match the request\");\n }\n const signer = recoverEvmSigner(request, result);\n if (signer.toLowerCase() !== account.address.toLowerCase()) {\n throw integrity(\"signer does not match the account\");\n }\n return;\n }\n if (\n (request.kind === \"solana.transaction\" || request.kind === \"solana.message\") &&\n (result.kind === \"solana.transaction\" || result.kind === \"solana.message\") &&\n !verifySolanaSignature(request.message, result.signature, account.address)\n ) {\n throw integrity(\"signature does not verify for the account\");\n }\n};\n\nfunction createChainsApi(internals: WalletInternals): ChainsApi {\n return {\n account: async (params) => internals.call(\"wallet.accounts\", params),\n sign: async (params) =>\n internals.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const verify = await internals.resolveFactor(params.verify, transfer);\n const result = await internals.call(\"chain.sign\", { request: params.request, verify });\n if (params.request.kind === \"bitcoin.psbt\") {\n await checkPsbt(internals, params.request, result);\n } else if (params.request.account.kind === \"hd\") {\n const account = await internals.call(\"wallet.accounts\", {\n walletId: params.request.account.walletId,\n groupIndex: params.request.account.groupIndex,\n template: params.request.account.template,\n network: params.request.network,\n });\n checkSigner(params.request, result, account);\n } else {\n const { keyId } = params.request.account;\n const keys = await internals.call(\"keys.list\", null);\n const key = keys.find((k) => k.keyId === keyId);\n if (key === undefined) {\n throw integrity(\"chain.sign answered for a key not in the vault\");\n }\n checkSigner(params.request, result, { address: key.address });\n }\n return result;\n }),\n };\n}\n\nconst apis = new WeakMap<Wallet, ChainsApi>();\n\nexport function chains(wallet: Wallet): ChainsApi {\n const internals = internalsOf(wallet);\n let api = apis.get(wallet);\n if (api === undefined) {\n api = createChainsApi(internals);\n apis.set(wallet, api);\n }\n return api;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6CA,MAAM,YAAY,OAChB,WACA,SACA,WACkB;CAClB,IAAI,OAAO,SAAS,gBAClB,MAAM,UAAU,wCAAwC;CAE1D,MAAM,6BAAa,IAAI,IAAqE;CAC5F,KAAK,MAAM,EAAE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AI,QAAQ,GAAG;CACtB;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"chains.mjs","names":[],"sources":["../src/chains/index.ts"],"sourcesContent":["/**\n * The chains module of @qntx/wallet: `chains(wallet)` returns the wallet's chain API. `account`\n * calls the kernel's `wallet.accounts`; `sign` calls `chain.sign` and then verifies the returned\n * signature against the request and the account address — a kernel that answers with someone else's\n * signature, or a signature over other content, fails closed with `integrity`.\n */\nimport { internalsOf } from \"../internal.ts\";\nimport type { WalletInternals } from \"../internal.ts\";\nimport type {\n ChainAccount,\n ChainAccountsParams,\n ChainExportNode,\n ChainExportResult,\n ChainSignRequest,\n ChainSignResult,\n} from \"../protocol/chains.ts\";\nimport type { VerifyFactor, Wallet } from \"../types.ts\";\nimport { checkExportResult, checkSignResult } from \"./check.ts\";\n\nexport type {\n ChainAccount,\n ChainAccountsParams,\n ChainExportedKey,\n ChainExportNode,\n ChainExportParams,\n ChainExportResult,\n ChainSignRequest,\n ChainSignResult,\n ChainTemplate,\n} from \"../protocol/chains.ts\";\n\nexport type ChainsApi = {\n readonly account: (params: ChainAccountsParams) => Promise<ChainAccount>;\n readonly sign: (params: {\n readonly request: ChainSignRequest;\n readonly verify: VerifyFactor;\n }) => Promise<ChainSignResult>;\n readonly exportAccount: (params: {\n readonly walletId: string;\n readonly groupIndex: number;\n readonly nodes: ReadonlyArray<ChainExportNode>;\n readonly verify: VerifyFactor;\n /* A node served by device material never confirmed on the device refuses with\n `approval-required` unless the host acknowledged the danger-row warning. */\n readonly acknowledgeUnconfirmed?: true;\n }) => Promise<ChainExportResult>;\n};\n\nfunction createChainsApi(internals: WalletInternals): ChainsApi {\n return {\n account: async (params) => internals.call(\"wallet.accounts\", params),\n sign: async (params) =>\n internals.withVerifying(async () => {\n const result = await internals.secretCall(\"chain.sign\", async (wire) => ({\n request: params.request,\n verify: await internals.resolveVerifyFactor(params.verify, wire),\n }));\n await checkSignResult(internals, params.request, result);\n return result;\n }),\n exportAccount: async (params) =>\n internals.withVerifying(async () => {\n const result = await internals.secretCall(\"chain.exportAccount\", async (wire) => ({\n walletId: params.walletId,\n groupIndex: params.groupIndex,\n nodes: params.nodes,\n verify: await internals.resolveVerifyFactor(params.verify, wire),\n ...(params.acknowledgeUnconfirmed === undefined\n ? {}\n : { acknowledgeUnconfirmed: params.acknowledgeUnconfirmed }),\n }));\n await checkExportResult(internals, params, result);\n return result;\n }),\n };\n}\n\nconst apis = new WeakMap<Wallet, ChainsApi>();\n\nexport function chains(wallet: Wallet): ChainsApi {\n const internals = internalsOf(wallet);\n let api = apis.get(wallet);\n if (api === undefined) {\n api = createChainsApi(internals);\n apis.set(wallet, api);\n }\n return api;\n}\n"],"mappings":";;;;;;;;;AAgDA,SAAS,gBAAgB,WAAuC;CAC9D,OAAO;EACL,SAAS,OAAO,WAAW,UAAU,KAAK,mBAAmB,MAAM;EACnE,MAAM,OAAO,WACX,UAAU,cAAc,YAAY;GAClC,MAAM,SAAS,MAAM,UAAU,WAAW,cAAc,OAAO,UAAU;IACvE,SAAS,OAAO;IAChB,QAAQ,MAAM,UAAU,oBAAoB,OAAO,QAAQ,IAAI;GACjE,EAAE;GACF,MAAM,gBAAgB,WAAW,OAAO,SAAS,MAAM;GACvD,OAAO;EACT,CAAC;EACH,eAAe,OAAO,WACpB,UAAU,cAAc,YAAY;GAClC,MAAM,SAAS,MAAM,UAAU,WAAW,uBAAuB,OAAO,UAAU;IAChF,UAAU,OAAO;IACjB,YAAY,OAAO;IACnB,OAAO,OAAO;IACd,QAAQ,MAAM,UAAU,oBAAoB,OAAO,QAAQ,IAAI;IAC/D,GAAI,OAAO,2BAA2B,KAAA,IAClC,CAAC,IACD,EAAE,wBAAwB,OAAO,uBAAuB;GAC9D,EAAE;GACF,MAAM,kBAAkB,WAAW,QAAQ,MAAM;GACjD,OAAO;EACT,CAAC;CACL;AACF;AAEA,MAAM,uBAAO,IAAI,QAA2B;AAE5C,SAAgB,OAAO,QAA2B;CAChD,MAAM,YAAY,YAAY,MAAM;CACpC,IAAI,MAAM,KAAK,IAAI,MAAM;CACzB,IAAI,QAAQ,KAAA,GAAW;EACrB,MAAM,gBAAgB,SAAS;EAC/B,KAAK,IAAI,QAAQ,GAAG;CACtB;CACA,OAAO;AACT"}