@qntx/wallet 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.
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-BSP0x9RI.d.mts → chains-u1M0CWkT.d.mts} +175 -26
  8. package/dist/chains.d.mts +11 -4
  9. package/dist/chains.mjs +19 -62
  10. package/dist/chains.mjs.map +1 -1
  11. package/dist/{channel-BQg--l_3.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-DDfzuSIa.mjs → core-Cx7p-0nG.mjs} +136 -15
  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 +471 -144
  23. package/dist/host.mjs.map +1 -1
  24. package/dist/{index-DDyJ9KqA.d.mts → index-UclKfprm.d.mts} +274 -18
  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-C8x0H3Rr.mjs → protocol-DLE6lHmP.mjs} +493 -52
  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-BQg--l_3.mjs.map +0 -1
  50. package/dist/core-DDfzuSIa.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-C8x0H3Rr.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-Dub5eUl3.d.mts +0 -239
@@ -1,8 +1,8 @@
1
- import { C as opt, E as union, S as obj, T as str, a as MAX_TEXT, b as literal, c as groupIndex, d as safeTime, f as walletErrorCode, g as arr, h as ValidationError, i as MAX_TAG_ITEM, l as identityIndex, m as walletInfo, n as MAX_SNAPSHOT_ITEMS, o as factor, p as walletId, r as MAX_TAGS, s as factorInfo, t as CORE_METHODS, u as publicKey, v as bytes, w as record, x as nullValue, y as int } from "./core-DDfzuSIa.mjs";
1
+ import { C as literal, D as record, E as opt, O as str, S as int, T as obj, _ as walletInfo, a as MAX_TEXT, b as bool, c as groupIndex, d as keyInfo, f as publicKey, g as walletId, h as walletErrorCode, i as MAX_TAG_ITEM, k as union, l as hardwareDevice, m as verifier, n as MAX_SNAPSHOT_ITEMS, o as cardId, p as safeTime, r as MAX_TAGS, s as factorInfo, t as CORE_METHODS, u as identityIndex, v as ValidationError, w as nullValue, x as bytes, y as arr } from "./core-Cx7p-0nG.mjs";
2
2
  // src/protocol/backup.ts
3
3
  /**
4
4
  * Backup-envelope wire validators (design/backup.mdx): the strict structural shape the kernel and
5
- * the host-side `parseBackupHeader` share — version 1, bounded fields, `obj` rejects unknown keys.
5
+ * the host-side `parseBackupHeader` share — version 3, bounded fields, `obj` rejects unknown keys.
6
6
  * Cryptographic checks (the payload tag, factor unwrap) stay in the kernel; these rules only shape
7
7
  * the JSON.
8
8
  */
@@ -17,23 +17,32 @@ const backupEnvelopeFactor = union(obj({
17
17
  sealedBek: str(MAX_FACTOR_CHARS)
18
18
  }), obj({
19
19
  kind: literal("password"),
20
- iterations: literal(6e5),
20
+ kdf: literal("argon2id"),
21
+ memoryKiB: literal(65536),
22
+ passes: literal(3),
23
+ lanes: literal(4),
21
24
  salt: str(128),
22
25
  sealedBek: str(MAX_FACTOR_CHARS)
23
26
  }));
24
27
  const backupEnvelope = obj({
25
- version: literal(1),
28
+ version: literal(3),
26
29
  createdAt: int(0, Number.MAX_SAFE_INTEGER),
27
30
  header: str(MAX_STRING_BYTES),
28
31
  factors: arr(backupEnvelopeFactor, 5, 1),
29
32
  payload: str(MAX_PAYLOAD_CHARS)
30
33
  });
31
- const backupHeader = obj({ wallets: arr(obj({
32
- walletId: str(128),
33
- origin: union(literal("mnemonic"), literal("passkey")),
34
- words: union(literal(12), literal(15), literal(18), literal(21), literal(24)),
35
- passphrase: opt(literal(true))
36
- }), 1e3) });
34
+ const backupHeader = obj({
35
+ wallets: arr(obj({
36
+ walletId: str(128),
37
+ origin: union(literal("mnemonic"), literal("passkey")),
38
+ words: union(literal(12), literal(15), literal(18), literal(21), literal(24)),
39
+ passphrase: opt(literal(true))
40
+ }), 1e3),
41
+ keys: opt(arr(obj({
42
+ keyId: str(16, /^[0-9a-f]{16}$/),
43
+ family: union(literal("evm"), literal("solana"), literal("bitcoin"), literal("tron"))
44
+ }), 256))
45
+ });
37
46
  /** The whole-envelope text bound — `backup.update` results and `backup.restore` params use it. */
38
47
  const backupEnvelopeText = str(MAX_ENVELOPE_CHARS);
39
48
  const backupInfo = obj({
@@ -42,13 +51,14 @@ const backupInfo = obj({
42
51
  createdAt: safeTime
43
52
  });
44
53
  // src/protocol/chains.ts
45
- const template = union(literal("evm.bip44"), literal("solana.bip44-change"), union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84")), literal("btc.bip86"));
54
+ const template = union(literal("evm.bip44"), literal("solana.bip44-change"), literal("tron.bip44"), union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84")), literal("btc.bip86"));
46
55
  const btcTemplate = union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84"), literal("btc.bip86"));
47
56
  const caip2 = str(200, /^[a-z0-9-]{3,64}:[0-9a-zA-Z-]{1,128}$/);
48
- const addressResult = (t) => obj({
57
+ const addressResult = (t, address = str(128, /^[0-9a-zA-Z-]{20,128}$/)) => obj({
49
58
  template: literal(t),
50
59
  network: caip2,
51
- address: str(128, /^[0-9a-zA-Z-]{20,128}$/)
60
+ address,
61
+ confirmed: bool
52
62
  });
53
63
  const accountRef = union(obj({
54
64
  kind: literal("hd"),
@@ -58,16 +68,16 @@ const accountRef = union(obj({
58
68
  }), obj({
59
69
  kind: literal("imported"),
60
70
  keyId: str(64, /^[0-9a-f]{8,64}$/),
61
- family: union(literal("evm"), literal("solana"), literal("bitcoin"))
71
+ family: union(literal("evm"), literal("solana"), literal("bitcoin"), literal("tron"))
62
72
  }));
63
73
  const hexQuantity = str(66, /^0x[0-9a-fA-F]+$/);
64
74
  const hexData = str(4e4, /^0x[0-9a-fA-F]*$/);
65
- const evmAddress = str(42, /^0x[0-9a-fA-F]{40}$/);
75
+ const evmAddress$1 = str(42, /^0x[0-9a-fA-F]{40}$/);
66
76
  const solanaAddress = str(44, /^[1-9A-HJ-NP-Za-km-z]{32,44}$/);
67
77
  const bitcoinAddress = str(90, /^(bc1|tb1|bcrt1|[13mn2])[a-zA-Z0-9]{4,87}$/);
68
78
  const safeInt = int(0, 9007199254740991);
69
79
  const accessList = arr(obj({
70
- address: evmAddress,
80
+ address: evmAddress$1,
71
81
  storageKeys: arr(str(66, /^0x[0-9a-fA-F]{64}$/), 256)
72
82
  }), 256);
73
83
  const txBase = {
@@ -76,7 +86,7 @@ const txBase = {
76
86
  gas: hexQuantity,
77
87
  value: hexQuantity,
78
88
  data: hexData,
79
- to: opt(evmAddress)
89
+ to: opt(evmAddress$1)
80
90
  };
81
91
  const evmTx = union(obj({
82
92
  ...txBase,
@@ -93,6 +103,14 @@ const evmTx = union(obj({
93
103
  maxFeePerGas: hexQuantity,
94
104
  maxPriorityFeePerGas: hexQuantity,
95
105
  accessList
106
+ }), obj({
107
+ ...txBase,
108
+ type: literal("eip7702"),
109
+ to: evmAddress$1,
110
+ maxFeePerGas: hexQuantity,
111
+ maxPriorityFeePerGas: hexQuantity,
112
+ accessList,
113
+ authorization: obj({ address: evmAddress$1 })
96
114
  }));
97
115
  const signRequest = union(obj({
98
116
  kind: literal("evm.transaction"),
@@ -104,6 +122,12 @@ const signRequest = union(obj({
104
122
  network: caip2,
105
123
  account: accountRef,
106
124
  message: bytes(0, 65536)
125
+ }), obj({
126
+ kind: literal("evm.fiat24-session"),
127
+ network: caip2,
128
+ account: accountRef,
129
+ tokenId: str(78, /^[1-9][0-9]{0,77}$/),
130
+ deadline: int(1, 9007199254740991)
107
131
  }), obj({
108
132
  kind: literal("evm.typed-data"),
109
133
  network: caip2,
@@ -113,7 +137,7 @@ const signRequest = union(obj({
113
137
  kind: literal("solana.transaction"),
114
138
  network: caip2,
115
139
  account: accountRef,
116
- message: bytes(1, 1232),
140
+ message: bytes(1, 4096),
117
141
  lookupTables: opt(arr(obj({
118
142
  address: solanaAddress,
119
143
  addresses: arr(solanaAddress, 256)
@@ -132,6 +156,7 @@ const signRequest = union(obj({
132
156
  walletId,
133
157
  groupIndex
134
158
  }),
159
+ origin: union(literal("internal"), literal("external")),
135
160
  psbt: bytes(1, 131072),
136
161
  sign: arr(obj({
137
162
  index: int(0, 1024),
@@ -146,12 +171,27 @@ const signRequest = union(obj({
146
171
  format: union(literal("bip322-simple"), literal("legacy")),
147
172
  change: union(literal(0), literal(1)),
148
173
  index: int(0, 2147483647)
174
+ }), obj({
175
+ kind: literal("tron.transaction"),
176
+ network: caip2,
177
+ account: accountRef,
178
+ rawData: bytes(1, 512e3)
179
+ }), obj({
180
+ kind: literal("tron.message"),
181
+ network: caip2,
182
+ account: accountRef,
183
+ message: bytes(1, 65536)
184
+ }), obj({
185
+ kind: literal("tron.typed-data"),
186
+ network: caip2,
187
+ account: accountRef,
188
+ typedData: str(1048576)
149
189
  }));
150
190
  const signResult = union(obj({
151
191
  kind: literal("evm.transaction"),
152
192
  signedTransaction: bytes(1, 65536)
153
193
  }), obj({
154
- kind: union(literal("evm.personal-message"), literal("evm.typed-data")),
194
+ kind: union(literal("evm.personal-message"), literal("evm.fiat24-session"), literal("evm.typed-data")),
155
195
  signature: bytes(65, 65)
156
196
  }), obj({
157
197
  kind: union(literal("solana.transaction"), literal("solana.message")),
@@ -162,7 +202,36 @@ const signResult = union(obj({
162
202
  }), obj({
163
203
  kind: literal("bitcoin.message"),
164
204
  signature: str(512)
205
+ }), obj({
206
+ kind: union(literal("tron.transaction"), literal("tron.message"), literal("tron.typed-data")),
207
+ signature: bytes(65, 65)
208
+ }));
209
+ const chainAccount = union(addressResult("evm.bip44"), addressResult("solana.bip44-change"), addressResult("tron.bip44", str(34, /^T[1-9A-HJ-NP-Za-km-z]{33}$/)), obj({
210
+ template: union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84"), literal("btc.bip86")),
211
+ network: caip2,
212
+ xpub: str(111, /^[a-zA-Z0-9]{111}$/),
213
+ fingerprint: str(8, /^[0-9a-f]{8}$/),
214
+ path: str(11, /^m\/[0-9'/]+$/),
215
+ confirmed: bool,
216
+ changeMark: int(0, 2147483647)
217
+ }));
218
+ const exportNode = union(obj({ kind: literal("evm.account") }), obj({
219
+ kind: literal("leaf"),
220
+ template: union(literal("evm.bip44"), literal("tron.bip44"), literal("solana.bip44-change"))
221
+ }), obj({
222
+ kind: literal("btc.account"),
223
+ template: btcTemplate,
224
+ network: caip2
165
225
  }));
226
+ const fingerprint = str(8, /^[0-9a-f]{8}$/);
227
+ const exportedKey = obj({
228
+ node: exportNode,
229
+ path: str(32, /^m\/[0-9'/]+$/),
230
+ curve: union(literal("secp256k1"), literal("ed25519")),
231
+ publicKey: union(bytes(33), bytes(32)),
232
+ chainCode: opt(bytes(32)),
233
+ parentFingerprint: opt(fingerprint)
234
+ });
166
235
  const CHAINS_METHODS = {
167
236
  "wallet.accounts": {
168
237
  session: true,
@@ -173,22 +242,269 @@ const CHAINS_METHODS = {
173
242
  template,
174
243
  network: caip2
175
244
  }),
176
- result: union(addressResult("evm.bip44"), addressResult("solana.bip44-change"), obj({
177
- template: union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84"), literal("btc.bip86")),
178
- network: caip2,
179
- xpub: str(111, /^[a-zA-Z0-9]{111}$/),
180
- fingerprint: str(8, /^[0-9a-f]{8}$/),
181
- path: str(11, /^m\/[0-9'/]+$/)
182
- }))
245
+ result: chainAccount
183
246
  },
184
247
  "chain.sign": {
185
248
  session: true,
186
249
  presence: true,
187
250
  params: obj({
188
251
  request: signRequest,
189
- verify: factor
252
+ verify: verifier
190
253
  }),
191
254
  result: signResult
255
+ },
256
+ "chain.exportAccount": {
257
+ session: true,
258
+ presence: true,
259
+ params: obj({
260
+ walletId,
261
+ groupIndex,
262
+ nodes: arr(exportNode, 4, 1),
263
+ verify: verifier,
264
+ acknowledgeUnconfirmed: opt(literal(true))
265
+ }),
266
+ result: obj({
267
+ fingerprint,
268
+ keys: arr(exportedKey, 4, 1)
269
+ })
270
+ }
271
+ };
272
+ // src/protocol/card.ts
273
+ /** `XXXX-XXXX` — the short id printed on a card and shown in prompts. */
274
+ const shortId = str(9, /^[0-9A-F]{4}-[0-9A-F]{4}$/);
275
+ const opId$1 = str(32, /^[0-9a-f]{32}$/);
276
+ /** Rejects a list whose entries repeat — the protocol requires distinct templates. */
277
+ const distinct = (validator) => {
278
+ return (value) => {
279
+ const list = validator(value);
280
+ if (new Set(list).size !== list.length) throw new ValidationError();
281
+ return list;
282
+ };
283
+ };
284
+ const cardOperation = union(obj({ kind: literal("status") }), obj({
285
+ kind: literal("add"),
286
+ groups: opt(int(1, 20))
287
+ }), obj({
288
+ kind: literal("accounts"),
289
+ walletId,
290
+ groupIndex,
291
+ templates: distinct(arr(template, 7, 1)),
292
+ network: caip2
293
+ }), obj({
294
+ kind: literal("health"),
295
+ walletId
296
+ }), obj({
297
+ kind: literal("change-access"),
298
+ walletId,
299
+ remember: opt(literal(true))
300
+ }), obj({
301
+ kind: literal("erase"),
302
+ walletId,
303
+ card: cardId,
304
+ last: opt(literal(true))
305
+ }), obj({
306
+ kind: literal("create"),
307
+ cards: int(1, 3),
308
+ source: union(obj({ kind: literal("generate") }), obj({
309
+ kind: literal("wallet"),
310
+ walletId
311
+ })),
312
+ groups: opt(int(1, 20)),
313
+ remember: opt(literal(true))
314
+ }), obj({
315
+ kind: literal("transfer"),
316
+ walletId
317
+ }), obj({
318
+ kind: literal("reseal"),
319
+ walletId,
320
+ card: cardId,
321
+ member: opt(cardId)
322
+ }), obj({
323
+ kind: literal("sign"),
324
+ request: signRequest,
325
+ remember: opt(literal(true))
326
+ }), obj({
327
+ kind: literal("forget-access"),
328
+ walletId
329
+ }));
330
+ const cardOpResult = union(obj({
331
+ kind: literal("status"),
332
+ life: union(literal("blank"), literal("loaded")),
333
+ tries: int(0, 10),
334
+ walletId: opt(walletId)
335
+ }), obj({
336
+ kind: literal("sign"),
337
+ result: signResult
338
+ }), obj({
339
+ kind: literal("accounts"),
340
+ accounts: arr(chainAccount, 64)
341
+ }), obj({
342
+ kind: literal("add"),
343
+ walletId
344
+ }), obj({
345
+ kind: literal("health"),
346
+ walletId
347
+ }), obj({
348
+ kind: literal("change-access"),
349
+ walletId
350
+ }), obj({
351
+ kind: literal("erase"),
352
+ walletId
353
+ }), obj({
354
+ kind: literal("create"),
355
+ walletId
356
+ }), obj({
357
+ kind: literal("transfer"),
358
+ walletId
359
+ }), obj({
360
+ kind: literal("reseal"),
361
+ walletId
362
+ }), obj({
363
+ kind: literal("forget-access"),
364
+ walletId
365
+ }));
366
+ const cardStep = union(obj({
367
+ kind: literal("input"),
368
+ purpose: union(literal("access-code"), literal("new-access-code"), literal("confirm-access-code"), literal("short-id")),
369
+ card: opt(shortId),
370
+ remaining: opt(int(0, 10))
371
+ }), obj({
372
+ kind: literal("tap"),
373
+ reason: union(literal("any"), literal("source"), literal("target"), literal("member"), literal("retry")),
374
+ card: opt(shortId),
375
+ hold: opt(literal(true))
376
+ }), obj({
377
+ kind: literal("done"),
378
+ result: cardOpResult
379
+ }));
380
+ const CARD_METHODS = {
381
+ "card.begin": {
382
+ session: true,
383
+ presence: true,
384
+ params: obj({
385
+ op: cardOperation,
386
+ verify: opt(verifier)
387
+ }),
388
+ result: obj({
389
+ opId: opId$1,
390
+ step: cardStep
391
+ })
392
+ },
393
+ "card.step": {
394
+ session: true,
395
+ presence: true,
396
+ params: obj({ opId: opId$1 }),
397
+ result: cardStep
398
+ },
399
+ "card.cancel": {
400
+ session: true,
401
+ presence: false,
402
+ params: obj({ opId: opId$1 }),
403
+ result: literal(null)
404
+ }
405
+ };
406
+ // src/protocol/hardware.ts
407
+ const UR_TYPE = /^[a-z0-9-]{1,64}$/;
408
+ const DERIVATION_PATH = /^m(\/[0-9]+'?){1,10}$/;
409
+ const qrPayload = obj({
410
+ type: str(64, UR_TYPE),
411
+ cbor: bytes(1, 262144)
412
+ });
413
+ const deviceRequest = union(obj({
414
+ kind: literal("qr"),
415
+ show: opt(qrPayload),
416
+ scan: arr(str(64, UR_TYPE), 4, 1)
417
+ }), obj({
418
+ kind: literal("message"),
419
+ data: bytes(1, 65536)
420
+ }), obj({
421
+ kind: literal("compare"),
422
+ address: str(128, /^.+$/),
423
+ path: str(128, DERIVATION_PATH)
424
+ }));
425
+ const deviceResponse = union(obj({
426
+ kind: literal("qr"),
427
+ ur: qrPayload
428
+ }), obj({
429
+ kind: literal("message"),
430
+ data: bytes(1, 65536)
431
+ }), obj({
432
+ kind: literal("compare"),
433
+ matched: bool
434
+ }));
435
+ const deviceDisplay = union(literal("clear"), literal("blind"));
436
+ const hardwareOperation = union(obj({
437
+ kind: literal("pair"),
438
+ device: hardwareDevice
439
+ }), obj({
440
+ kind: literal("accounts"),
441
+ walletId,
442
+ groupIndex,
443
+ templates: arr(template, 7, 1),
444
+ network: caip2
445
+ }), obj({
446
+ kind: literal("sign"),
447
+ request: signRequest,
448
+ acknowledgeUnconfirmed: opt(literal(true))
449
+ }), obj({
450
+ kind: literal("verify-address"),
451
+ walletId,
452
+ groupIndex,
453
+ template,
454
+ network: caip2,
455
+ index: opt(int(0, 2147483647))
456
+ }));
457
+ const hardwareResult = union(obj({
458
+ kind: literal("pair"),
459
+ wallet: walletInfo
460
+ }), obj({
461
+ kind: literal("accounts"),
462
+ accounts: arr(chainAccount, 64)
463
+ }), obj({
464
+ kind: literal("sign"),
465
+ result: signResult
466
+ }), obj({
467
+ kind: literal("verify-address"),
468
+ address: str(128, /^.+$/),
469
+ method: union(literal("device"), literal("compare"))
470
+ }));
471
+ const hardwareStep = union(obj({
472
+ kind: literal("exchange"),
473
+ device: hardwareDevice,
474
+ request: deviceRequest,
475
+ display: opt(deviceDisplay)
476
+ }), obj({
477
+ kind: literal("done"),
478
+ result: hardwareResult
479
+ }));
480
+ const opId = str(32, /^[0-9a-f]{32}$/);
481
+ const HARDWARE_METHODS = {
482
+ "hardware.begin": {
483
+ session: true,
484
+ presence: true,
485
+ params: obj({
486
+ op: hardwareOperation,
487
+ verify: opt(verifier)
488
+ }),
489
+ result: obj({
490
+ opId,
491
+ step: hardwareStep
492
+ })
493
+ },
494
+ "hardware.step": {
495
+ session: true,
496
+ presence: true,
497
+ params: obj({
498
+ opId,
499
+ response: deviceResponse
500
+ }),
501
+ result: hardwareStep
502
+ },
503
+ "hardware.cancel": {
504
+ session: true,
505
+ presence: false,
506
+ params: obj({ opId }),
507
+ result: nullValue
192
508
  }
193
509
  };
194
510
  // src/protocol/nostr.ts
@@ -274,7 +590,7 @@ const NOSTR_METHODS = {
274
590
  session: true,
275
591
  presence: true,
276
592
  params: obj({
277
- verify: factor,
593
+ verify: verifier,
278
594
  publicKey,
279
595
  format: nostrExportFormat
280
596
  }),
@@ -356,6 +672,75 @@ const NOSTR_METHODS = {
356
672
  result: textResult
357
673
  }
358
674
  };
675
+ // src/protocol/sessions.ts
676
+ const schemeId = str(32, /^[a-z][a-z0-9-]{1,31}$/);
677
+ const scope = str(64, /^[A-Za-z0-9._:-]{1,64}$/);
678
+ const evmAddress = str(42, /^0x[0-9a-fA-F]{40}$/);
679
+ const paramsValue = (value) => value;
680
+ const sessionInfo = obj({
681
+ address: evmAddress,
682
+ scheme: schemeId,
683
+ supported: bool,
684
+ walletId,
685
+ groupIndex,
686
+ owner: evmAddress,
687
+ scope,
688
+ name: str(16, /^[A-Za-z0-9._-]{1,16}$/),
689
+ validUntil: safeTime,
690
+ createdAt: safeTime,
691
+ limits: paramsValue,
692
+ spent: paramsValue
693
+ });
694
+ const SESSIONS_METHODS = {
695
+ "sessions.create": {
696
+ session: true,
697
+ presence: true,
698
+ params: obj({
699
+ scheme: schemeId,
700
+ owner: obj({
701
+ walletId,
702
+ groupIndex
703
+ }),
704
+ scope,
705
+ name: str(16, /^[A-Za-z0-9._-]{1,16}$/),
706
+ validUntil: safeTime,
707
+ limits: paramsValue,
708
+ verify: verifier
709
+ }),
710
+ result: obj({ address: evmAddress })
711
+ },
712
+ "sessions.list": {
713
+ session: true,
714
+ presence: false,
715
+ params: nullValue,
716
+ result: arr(sessionInfo, 64)
717
+ },
718
+ "sessions.delete": {
719
+ session: true,
720
+ presence: true,
721
+ params: obj({ address: evmAddress }),
722
+ result: nullValue
723
+ },
724
+ "sessions.open": {
725
+ session: true,
726
+ presence: true,
727
+ params: obj({
728
+ address: evmAddress,
729
+ verify: verifier
730
+ }),
731
+ result: nullValue
732
+ },
733
+ "sessions.sign": {
734
+ session: true,
735
+ presence: false,
736
+ params: obj({
737
+ scheme: schemeId,
738
+ address: evmAddress,
739
+ params: paramsValue
740
+ }),
741
+ result: obj({ signature: bytes(65, 65) })
742
+ }
743
+ };
359
744
  // src/protocol/spark.ts
360
745
  /**
361
746
  * The spark module's method table and wire validators. The protocol stays free of @qntx/spark
@@ -429,7 +814,11 @@ const frostSignJob = obj({
429
814
  verifyingKey: bytes33,
430
815
  commitment: signingCommitment,
431
816
  operatorCommitments: arr(operatorCommitment, MAX_OPERATORS),
432
- adaptorPublicKey
817
+ adaptorPublicKey,
818
+ exit: opt(obj({
819
+ connectorTx: bytes(1, MAX_TX_BYTES),
820
+ exitTx: bytes(1, MAX_TX_BYTES)
821
+ }))
433
822
  });
434
823
  const frostAggregateJob = obj({
435
824
  key: sparkKey,
@@ -713,19 +1102,33 @@ const SPARK_METHODS = {
713
1102
  params: obj({
714
1103
  account,
715
1104
  intent: approveIntent,
716
- verify: factor
1105
+ verify: verifier
717
1106
  }),
718
1107
  result: approvalSummary
719
1108
  }
720
1109
  };
721
1110
  // src/protocol/index.ts
722
- const PROTOCOL_VERSION = 2;
1111
+ const PROTOCOL_VERSION = 3;
723
1112
  /**
724
1113
  * Responses to requests whose `id` cannot be parsed (malformed envelope) carry id 0. Main-side
725
1114
  * request ids start at 1, so a `0` is never a real pending request.
726
1115
  */
727
1116
  const UNATTRIBUTED_ID = 0;
728
1117
  /**
1118
+ * Param field names whose bytes are secrets: the kernel consumes and wipes them, so each must own
1119
+ * its memory.
1120
+ */
1121
+ const SECRET_FIELDS = [
1122
+ "password",
1123
+ "prf",
1124
+ "prfWallet",
1125
+ "prfBackup",
1126
+ "mnemonic",
1127
+ "passphrase",
1128
+ "secret",
1129
+ "answers"
1130
+ ];
1131
+ /**
729
1132
  * The worst-case encoded size of one request, enforced by both sides: the host refuses to post a
730
1133
  * request over the cap and the kernel answers an oversized raw request with `invalid-input`.
731
1134
  * Responses are not capped.
@@ -734,13 +1137,15 @@ const MAX_REQUEST_BYTES = 1048576;
734
1137
  /**
735
1138
  * Upper-bound byte weight of a protocol value: a string costs `length * 3` (worst-case UTF-8), a
736
1139
  * Uint8Array its `byteLength`, every scalar and every array element 8, and every object key
737
- * `key.length * 3 + 8` plus its value. Iterative — a deeply nested value cannot overflow the
738
- * stack.
1140
+ * `key.length * 3 + 8` plus its value. Iterative — a deeply nested value cannot overflow the stack
1141
+ * — and stops once the running total passes MAX_REQUEST_BYTES, the only comparison callers make, so
1142
+ * oversized values are rejected without walking the whole value.
739
1143
  */
740
1144
  function requestBytes(value) {
741
1145
  let total = 0;
742
1146
  const stack = [value];
743
1147
  while (stack.length > 0) {
1148
+ if (total > 1048576) return total;
744
1149
  const item = stack.pop();
745
1150
  if (item === void 0) continue;
746
1151
  if (typeof item === "string") total += item.length * 3;
@@ -757,28 +1162,57 @@ function requestBytes(value) {
757
1162
  }
758
1163
  return total;
759
1164
  }
760
- /** Deep check that a structured-cloned value is a strict ProtocolValue (no cycles detected). */
1165
+ /**
1166
+ * Deep check that a structured-cloned value is a strict ProtocolValue. Structured clone keeps
1167
+ * shared references, so the value may be a graph: every object and array is checked once however
1168
+ * often it is referenced — a shared reference serializes once and must not expand on every walk —
1169
+ * and one that contains itself (a cycle, which can never be a protocol value) is rejected.
1170
+ * Iterative — a deeply nested value cannot overflow the stack.
1171
+ */
761
1172
  function isProtocolValue(value) {
762
- switch (typeof value) {
763
- case "boolean":
764
- case "string": return true;
765
- case "number": return Number.isSafeInteger(value);
766
- case "object": break;
767
- default: return false;
1173
+ const checked = /* @__PURE__ */ new Set();
1174
+ const open = /* @__PURE__ */ new Set();
1175
+ const stack = [{ value }];
1176
+ while (stack.length > 0) {
1177
+ const frame = stack.pop();
1178
+ if (frame === void 0) break;
1179
+ if ("close" in frame) {
1180
+ open.delete(frame.close);
1181
+ continue;
1182
+ }
1183
+ const item = frame.value;
1184
+ switch (typeof item) {
1185
+ case "boolean":
1186
+ case "string": continue;
1187
+ case "number":
1188
+ if (!Number.isSafeInteger(item)) return false;
1189
+ continue;
1190
+ case "object": break;
1191
+ default: return false;
1192
+ }
1193
+ if (item === null || item instanceof Uint8Array) continue;
1194
+ if (open.has(item)) return false;
1195
+ if (checked.has(item)) continue;
1196
+ if (!Array.isArray(item) && Object.getPrototypeOf(item) !== Object.prototype) return false;
1197
+ checked.add(item);
1198
+ open.add(item);
1199
+ stack.push({ close: item });
1200
+ for (const child of Array.isArray(item) ? item : Object.values(item)) stack.push({ value: child });
768
1201
  }
769
- if (value === null || value instanceof Uint8Array) return true;
770
- if (Array.isArray(value)) return value.every(isProtocolValue);
771
- if (Object.getPrototypeOf(value) !== Object.prototype) return false;
772
- return Object.values(value).every(isProtocolValue);
1202
+ return true;
773
1203
  }
774
1204
  /** The status payload: core sections plus one object section per protocol module. */
775
1205
  const statusPayload = obj({
776
- protocol: literal(2),
1206
+ protocol: literal(3),
777
1207
  vault: union(literal("uninitialized"), literal("locked"), literal("unlocked"), literal("corrupted"), literal("unsupported"), literal("unavailable")),
778
1208
  factors: arr(factorInfo, MAX_SNAPSHOT_ITEMS),
1209
+ appLock: bool,
1210
+ verification: union(literal("available"), literal("unavailable")),
779
1211
  wallets: arr(walletInfo, MAX_SNAPSHOT_ITEMS),
780
1212
  nostr: nostrStatus,
781
- backup: union(backupInfo, nullValue)
1213
+ importedKeys: arr(keyInfo, MAX_SNAPSHOT_ITEMS),
1214
+ backup: union(backupInfo, nullValue),
1215
+ blindSigning: bool
782
1216
  });
783
1217
  const METHODS = {
784
1218
  status: {
@@ -788,9 +1222,12 @@ const METHODS = {
788
1222
  result: statusPayload
789
1223
  },
790
1224
  ...CORE_METHODS,
1225
+ ...CARD_METHODS,
791
1226
  ...CHAINS_METHODS,
792
1227
  ...NOSTR_METHODS,
793
- ...SPARK_METHODS
1228
+ ...SPARK_METHODS,
1229
+ ...SESSIONS_METHODS,
1230
+ ...HARDWARE_METHODS
794
1231
  };
795
1232
  const lockReason = union(literal("cold-start"), literal("user"), literal("idle"), literal("background"), literal("expired"), literal("crashed"), literal("invalidated"));
796
1233
  const errorPayload = obj({
@@ -798,18 +1235,22 @@ const errorPayload = obj({
798
1235
  retryAt: opt(safeTime),
799
1236
  detail: opt(str(80, /^[A-Za-z0-9_.:-]+$/))
800
1237
  });
801
- /** Host-side validators: `kernelEvent` covers the two push messages. */
1238
+ /** Host-side validators: `kernelEvent` covers the push messages. */
802
1239
  const kernelEvent = union(obj({
803
- v: literal(2),
1240
+ v: literal(3),
804
1241
  event: literal("status"),
805
1242
  status: statusPayload
806
1243
  }), obj({
807
- v: literal(2),
1244
+ v: literal(3),
808
1245
  event: literal("locked"),
809
1246
  reason: lockReason
1247
+ }), obj({
1248
+ v: literal(3),
1249
+ event: literal("ceremony"),
1250
+ active: bool
810
1251
  }));
811
1252
  /** Validates the `err` payload of a response; `ok` is checked against `METHODS[m].result`. */
812
1253
  const responseError = errorPayload;
813
- export { isProtocolValue as a, responseError as c, CHAINS_METHODS as d, backupEnvelope as f, backupInfo as g, backupHeader as h, UNATTRIBUTED_ID as i, SPARK_METHODS as l, backupEnvelopeText as m, METHODS as n, kernelEvent as o, backupEnvelopeFactor as p, PROTOCOL_VERSION as r, requestBytes as s, MAX_REQUEST_BYTES as t, NOSTR_METHODS as u };
1254
+ export { backupEnvelopeFactor as _, UNATTRIBUTED_ID as a, backupInfo as b, requestBytes as c, SESSIONS_METHODS as d, NOSTR_METHODS as f, backupEnvelope as g, CHAINS_METHODS as h, SECRET_FIELDS as i, responseError as l, CARD_METHODS as m, METHODS as n, isProtocolValue as o, HARDWARE_METHODS as p, PROTOCOL_VERSION as r, kernelEvent as s, MAX_REQUEST_BYTES as t, SPARK_METHODS as u, backupEnvelopeText as v, backupHeader as y };
814
1255
 
815
- //# sourceMappingURL=protocol-C8x0H3Rr.mjs.map
1256
+ //# sourceMappingURL=protocol-DLE6lHmP.mjs.map