@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,8 +1,8 @@
1
- import { C as obj, D as union, E as str, S as nullValue, T as record, _ as arr, a as MAX_TEXT, b as int, c as groupIndex, d as publicKey, f as safeTime, g as ValidationError, h as walletInfo, i as MAX_TAG_ITEM, l as identityIndex, m as walletId, n as MAX_SNAPSHOT_ITEMS, o as factor, p as walletErrorCode, r as MAX_TAGS, s as factorInfo, t as CORE_METHODS, u as keyInfo, w as opt, x as literal, y as bytes } from "./core-DaRwkTaV.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,12 +17,15 @@ 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),
@@ -37,7 +40,7 @@ const backupHeader = obj({
37
40
  }), 1e3),
38
41
  keys: opt(arr(obj({
39
42
  keyId: str(16, /^[0-9a-f]{16}$/),
40
- family: union(literal("evm"), literal("solana"), literal("bitcoin"))
43
+ family: union(literal("evm"), literal("solana"), literal("bitcoin"), literal("tron"))
41
44
  }), 256))
42
45
  });
43
46
  /** The whole-envelope text bound — `backup.update` results and `backup.restore` params use it. */
@@ -48,13 +51,14 @@ const backupInfo = obj({
48
51
  createdAt: safeTime
49
52
  });
50
53
  // src/protocol/chains.ts
51
- 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"));
52
55
  const btcTemplate = union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84"), literal("btc.bip86"));
53
56
  const caip2 = str(200, /^[a-z0-9-]{3,64}:[0-9a-zA-Z-]{1,128}$/);
54
- const addressResult = (t) => obj({
57
+ const addressResult = (t, address = str(128, /^[0-9a-zA-Z-]{20,128}$/)) => obj({
55
58
  template: literal(t),
56
59
  network: caip2,
57
- address: str(128, /^[0-9a-zA-Z-]{20,128}$/)
60
+ address,
61
+ confirmed: bool
58
62
  });
59
63
  const accountRef = union(obj({
60
64
  kind: literal("hd"),
@@ -64,16 +68,16 @@ const accountRef = union(obj({
64
68
  }), obj({
65
69
  kind: literal("imported"),
66
70
  keyId: str(64, /^[0-9a-f]{8,64}$/),
67
- family: union(literal("evm"), literal("solana"), literal("bitcoin"))
71
+ family: union(literal("evm"), literal("solana"), literal("bitcoin"), literal("tron"))
68
72
  }));
69
73
  const hexQuantity = str(66, /^0x[0-9a-fA-F]+$/);
70
74
  const hexData = str(4e4, /^0x[0-9a-fA-F]*$/);
71
- const evmAddress = str(42, /^0x[0-9a-fA-F]{40}$/);
75
+ const evmAddress$1 = str(42, /^0x[0-9a-fA-F]{40}$/);
72
76
  const solanaAddress = str(44, /^[1-9A-HJ-NP-Za-km-z]{32,44}$/);
73
77
  const bitcoinAddress = str(90, /^(bc1|tb1|bcrt1|[13mn2])[a-zA-Z0-9]{4,87}$/);
74
78
  const safeInt = int(0, 9007199254740991);
75
79
  const accessList = arr(obj({
76
- address: evmAddress,
80
+ address: evmAddress$1,
77
81
  storageKeys: arr(str(66, /^0x[0-9a-fA-F]{64}$/), 256)
78
82
  }), 256);
79
83
  const txBase = {
@@ -82,7 +86,7 @@ const txBase = {
82
86
  gas: hexQuantity,
83
87
  value: hexQuantity,
84
88
  data: hexData,
85
- to: opt(evmAddress)
89
+ to: opt(evmAddress$1)
86
90
  };
87
91
  const evmTx = union(obj({
88
92
  ...txBase,
@@ -102,11 +106,11 @@ const evmTx = union(obj({
102
106
  }), obj({
103
107
  ...txBase,
104
108
  type: literal("eip7702"),
105
- to: evmAddress,
109
+ to: evmAddress$1,
106
110
  maxFeePerGas: hexQuantity,
107
111
  maxPriorityFeePerGas: hexQuantity,
108
112
  accessList,
109
- authorization: obj({ address: evmAddress })
113
+ authorization: obj({ address: evmAddress$1 })
110
114
  }));
111
115
  const signRequest = union(obj({
112
116
  kind: literal("evm.transaction"),
@@ -118,6 +122,12 @@ const signRequest = union(obj({
118
122
  network: caip2,
119
123
  account: accountRef,
120
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)
121
131
  }), obj({
122
132
  kind: literal("evm.typed-data"),
123
133
  network: caip2,
@@ -127,7 +137,7 @@ const signRequest = union(obj({
127
137
  kind: literal("solana.transaction"),
128
138
  network: caip2,
129
139
  account: accountRef,
130
- message: bytes(1, 1232),
140
+ message: bytes(1, 4096),
131
141
  lookupTables: opt(arr(obj({
132
142
  address: solanaAddress,
133
143
  addresses: arr(solanaAddress, 256)
@@ -146,6 +156,7 @@ const signRequest = union(obj({
146
156
  walletId,
147
157
  groupIndex
148
158
  }),
159
+ origin: union(literal("internal"), literal("external")),
149
160
  psbt: bytes(1, 131072),
150
161
  sign: arr(obj({
151
162
  index: int(0, 1024),
@@ -160,12 +171,27 @@ const signRequest = union(obj({
160
171
  format: union(literal("bip322-simple"), literal("legacy")),
161
172
  change: union(literal(0), literal(1)),
162
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)
163
189
  }));
164
190
  const signResult = union(obj({
165
191
  kind: literal("evm.transaction"),
166
192
  signedTransaction: bytes(1, 65536)
167
193
  }), obj({
168
- 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")),
169
195
  signature: bytes(65, 65)
170
196
  }), obj({
171
197
  kind: union(literal("solana.transaction"), literal("solana.message")),
@@ -176,7 +202,36 @@ const signResult = union(obj({
176
202
  }), obj({
177
203
  kind: literal("bitcoin.message"),
178
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)
179
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
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
+ });
180
235
  const CHAINS_METHODS = {
181
236
  "wallet.accounts": {
182
237
  session: true,
@@ -187,22 +242,269 @@ const CHAINS_METHODS = {
187
242
  template,
188
243
  network: caip2
189
244
  }),
190
- result: union(addressResult("evm.bip44"), addressResult("solana.bip44-change"), obj({
191
- template: union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84"), literal("btc.bip86")),
192
- network: caip2,
193
- xpub: str(111, /^[a-zA-Z0-9]{111}$/),
194
- fingerprint: str(8, /^[0-9a-f]{8}$/),
195
- path: str(11, /^m\/[0-9'/]+$/)
196
- }))
245
+ result: chainAccount
197
246
  },
198
247
  "chain.sign": {
199
248
  session: true,
200
249
  presence: true,
201
250
  params: obj({
202
251
  request: signRequest,
203
- verify: factor
252
+ verify: verifier
204
253
  }),
205
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
206
508
  }
207
509
  };
208
510
  // src/protocol/nostr.ts
@@ -288,7 +590,7 @@ const NOSTR_METHODS = {
288
590
  session: true,
289
591
  presence: true,
290
592
  params: obj({
291
- verify: factor,
593
+ verify: verifier,
292
594
  publicKey,
293
595
  format: nostrExportFormat
294
596
  }),
@@ -370,6 +672,75 @@ const NOSTR_METHODS = {
370
672
  result: textResult
371
673
  }
372
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
+ };
373
744
  // src/protocol/spark.ts
374
745
  /**
375
746
  * The spark module's method table and wire validators. The protocol stays free of @qntx/spark
@@ -443,7 +814,11 @@ const frostSignJob = obj({
443
814
  verifyingKey: bytes33,
444
815
  commitment: signingCommitment,
445
816
  operatorCommitments: arr(operatorCommitment, MAX_OPERATORS),
446
- adaptorPublicKey
817
+ adaptorPublicKey,
818
+ exit: opt(obj({
819
+ connectorTx: bytes(1, MAX_TX_BYTES),
820
+ exitTx: bytes(1, MAX_TX_BYTES)
821
+ }))
447
822
  });
448
823
  const frostAggregateJob = obj({
449
824
  key: sparkKey,
@@ -727,19 +1102,33 @@ const SPARK_METHODS = {
727
1102
  params: obj({
728
1103
  account,
729
1104
  intent: approveIntent,
730
- verify: factor
1105
+ verify: verifier
731
1106
  }),
732
1107
  result: approvalSummary
733
1108
  }
734
1109
  };
735
1110
  // src/protocol/index.ts
736
- const PROTOCOL_VERSION = 2;
1111
+ const PROTOCOL_VERSION = 3;
737
1112
  /**
738
1113
  * Responses to requests whose `id` cannot be parsed (malformed envelope) carry id 0. Main-side
739
1114
  * request ids start at 1, so a `0` is never a real pending request.
740
1115
  */
741
1116
  const UNATTRIBUTED_ID = 0;
742
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
+ /**
743
1132
  * The worst-case encoded size of one request, enforced by both sides: the host refuses to post a
744
1133
  * request over the cap and the kernel answers an oversized raw request with `invalid-input`.
745
1134
  * Responses are not capped.
@@ -748,13 +1137,15 @@ const MAX_REQUEST_BYTES = 1048576;
748
1137
  /**
749
1138
  * Upper-bound byte weight of a protocol value: a string costs `length * 3` (worst-case UTF-8), a
750
1139
  * Uint8Array its `byteLength`, every scalar and every array element 8, and every object key
751
- * `key.length * 3 + 8` plus its value. Iterative — a deeply nested value cannot overflow the
752
- * 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.
753
1143
  */
754
1144
  function requestBytes(value) {
755
1145
  let total = 0;
756
1146
  const stack = [value];
757
1147
  while (stack.length > 0) {
1148
+ if (total > 1048576) return total;
758
1149
  const item = stack.pop();
759
1150
  if (item === void 0) continue;
760
1151
  if (typeof item === "string") total += item.length * 3;
@@ -771,29 +1162,57 @@ function requestBytes(value) {
771
1162
  }
772
1163
  return total;
773
1164
  }
774
- /** 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
+ */
775
1172
  function isProtocolValue(value) {
776
- switch (typeof value) {
777
- case "boolean":
778
- case "string": return true;
779
- case "number": return Number.isSafeInteger(value);
780
- case "object": break;
781
- 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 });
782
1201
  }
783
- if (value === null || value instanceof Uint8Array) return true;
784
- if (Array.isArray(value)) return value.every(isProtocolValue);
785
- if (Object.getPrototypeOf(value) !== Object.prototype) return false;
786
- return Object.values(value).every(isProtocolValue);
1202
+ return true;
787
1203
  }
788
1204
  /** The status payload: core sections plus one object section per protocol module. */
789
1205
  const statusPayload = obj({
790
- protocol: literal(2),
1206
+ protocol: literal(3),
791
1207
  vault: union(literal("uninitialized"), literal("locked"), literal("unlocked"), literal("corrupted"), literal("unsupported"), literal("unavailable")),
792
1208
  factors: arr(factorInfo, MAX_SNAPSHOT_ITEMS),
1209
+ appLock: bool,
1210
+ verification: union(literal("available"), literal("unavailable")),
793
1211
  wallets: arr(walletInfo, MAX_SNAPSHOT_ITEMS),
794
1212
  nostr: nostrStatus,
795
1213
  importedKeys: arr(keyInfo, MAX_SNAPSHOT_ITEMS),
796
- backup: union(backupInfo, nullValue)
1214
+ backup: union(backupInfo, nullValue),
1215
+ blindSigning: bool
797
1216
  });
798
1217
  const METHODS = {
799
1218
  status: {
@@ -803,9 +1222,12 @@ const METHODS = {
803
1222
  result: statusPayload
804
1223
  },
805
1224
  ...CORE_METHODS,
1225
+ ...CARD_METHODS,
806
1226
  ...CHAINS_METHODS,
807
1227
  ...NOSTR_METHODS,
808
- ...SPARK_METHODS
1228
+ ...SPARK_METHODS,
1229
+ ...SESSIONS_METHODS,
1230
+ ...HARDWARE_METHODS
809
1231
  };
810
1232
  const lockReason = union(literal("cold-start"), literal("user"), literal("idle"), literal("background"), literal("expired"), literal("crashed"), literal("invalidated"));
811
1233
  const errorPayload = obj({
@@ -813,18 +1235,22 @@ const errorPayload = obj({
813
1235
  retryAt: opt(safeTime),
814
1236
  detail: opt(str(80, /^[A-Za-z0-9_.:-]+$/))
815
1237
  });
816
- /** Host-side validators: `kernelEvent` covers the two push messages. */
1238
+ /** Host-side validators: `kernelEvent` covers the push messages. */
817
1239
  const kernelEvent = union(obj({
818
- v: literal(2),
1240
+ v: literal(3),
819
1241
  event: literal("status"),
820
1242
  status: statusPayload
821
1243
  }), obj({
822
- v: literal(2),
1244
+ v: literal(3),
823
1245
  event: literal("locked"),
824
1246
  reason: lockReason
1247
+ }), obj({
1248
+ v: literal(3),
1249
+ event: literal("ceremony"),
1250
+ active: bool
825
1251
  }));
826
1252
  /** Validates the `err` payload of a response; `ok` is checked against `METHODS[m].result`. */
827
1253
  const responseError = errorPayload;
828
- 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 };
829
1255
 
830
- //# sourceMappingURL=protocol-fXHXJguP.mjs.map
1256
+ //# sourceMappingURL=protocol-DLE6lHmP.mjs.map