@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.
- package/README.md +145 -22
- package/dist/backup-CLzMs8DP.mjs +51 -0
- package/dist/backup-CLzMs8DP.mjs.map +1 -0
- package/dist/card.d.mts +12 -0
- package/dist/card.mjs +119 -0
- package/dist/card.mjs.map +1 -0
- package/dist/{chains-BSP0x9RI.d.mts → chains-u1M0CWkT.d.mts} +175 -26
- package/dist/chains.d.mts +11 -4
- package/dist/chains.mjs +19 -62
- package/dist/chains.mjs.map +1 -1
- package/dist/{channel-BQg--l_3.mjs → channel-BCZXU3pt.mjs} +105 -44
- package/dist/channel-BCZXU3pt.mjs.map +1 -0
- package/dist/check-C1fUpgva.mjs +193 -0
- package/dist/check-C1fUpgva.mjs.map +1 -0
- package/dist/{core-DDfzuSIa.mjs → core-Cx7p-0nG.mjs} +136 -15
- package/dist/core-Cx7p-0nG.mjs.map +1 -0
- package/dist/hardware-BL6zvhQh.d.mts +107 -0
- package/dist/hardware.d.mts +81 -0
- package/dist/hardware.mjs +446 -0
- package/dist/hardware.mjs.map +1 -0
- package/dist/host.d.mts +27 -19
- package/dist/host.mjs +471 -144
- package/dist/host.mjs.map +1 -1
- package/dist/{index-DDyJ9KqA.d.mts → index-UclKfprm.d.mts} +274 -18
- package/dist/index.d.mts +5 -3
- package/dist/index.mjs +3 -33
- package/dist/{internal-CAKfHjIg.mjs → internal-DwCus_Ws.mjs} +1 -6
- package/dist/internal-DwCus_Ws.mjs.map +1 -0
- package/dist/nostr.d.mts +2 -2
- package/dist/nostr.mjs +14 -14
- package/dist/nostr.mjs.map +1 -1
- package/dist/{protocol-C8x0H3Rr.mjs → protocol-DLE6lHmP.mjs} +493 -52
- package/dist/protocol-DLE6lHmP.mjs.map +1 -0
- package/dist/protocol.d.mts +5 -4
- package/dist/protocol.mjs +3 -3
- package/dist/secret-CbjbY5-f.mjs +25 -0
- package/dist/secret-CbjbY5-f.mjs.map +1 -0
- package/dist/sessions.d.mts +52 -0
- package/dist/sessions.mjs +71 -0
- package/dist/sessions.mjs.map +1 -0
- package/dist/spark.d.mts +3 -3
- package/dist/spark.mjs +5 -8
- package/dist/spark.mjs.map +1 -1
- package/dist/types-CRnacSqJ.d.mts +390 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +7 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +27 -13
- package/dist/channel-BQg--l_3.mjs.map +0 -1
- package/dist/core-DDfzuSIa.mjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/internal-CAKfHjIg.mjs.map +0 -1
- package/dist/protocol-C8x0H3Rr.mjs.map +0 -1
- package/dist/secret-CcjyF8D3.mjs +0 -205
- package/dist/secret-CcjyF8D3.mjs.map +0 -1
- package/dist/types-Dub5eUl3.d.mts +0 -239
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HARDWARE_DEVICES } from "./types.mjs";
|
|
1
2
|
// src/protocol/validate.ts
|
|
2
3
|
/**
|
|
3
4
|
* Strict validator combinators for the secret-area protocol. Both sides share them: the kernel
|
|
@@ -123,6 +124,16 @@ function validate(validator, value) {
|
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
// src/protocol/core.ts
|
|
127
|
+
/**
|
|
128
|
+
* The core method table: vault, wallet and data-key commands — nothing protocol-specific. "Create
|
|
129
|
+
* or import" commands (createWithPasskey/restoreWithPasskey/createMnemonic/importMnemonic) are
|
|
130
|
+
* `session: false` here because the rule is dynamic: with an uninitialized vault they carry
|
|
131
|
+
* `factor` and establish the vault in one commit; with an established vault `factor` must be absent
|
|
132
|
+
* and a valid session is required.
|
|
133
|
+
*
|
|
134
|
+
* The shared wire validators (factor, wallet info, ids) live here too so the nostr module's table
|
|
135
|
+
* can reuse them — `protocol/nostr.ts` imports only from this file.
|
|
136
|
+
*/
|
|
126
137
|
const MAX_TEXT = 262144;
|
|
127
138
|
const MAX_TAGS = 1024;
|
|
128
139
|
const MAX_TAG_ITEM = 4096;
|
|
@@ -130,13 +141,31 @@ const MAX_SNAPSHOT_ITEMS = 4096;
|
|
|
130
141
|
const sessionId = str(32, /^[0-9a-f]{32}$/);
|
|
131
142
|
const draftId = str(32, /^[0-9a-f]{32}$/);
|
|
132
143
|
const walletId = str(16, /^[0-9a-f]{16}$/);
|
|
144
|
+
const keyId = str(16, /^[0-9a-f]{16}$/);
|
|
145
|
+
const keyFamily = union(literal("evm"), literal("solana"), literal("bitcoin"), literal("tron"));
|
|
133
146
|
const publicKey = str(64, /^[0-9a-f]{64}$/);
|
|
134
147
|
const credentialId = str(1364, /^[A-Za-z0-9_-]+$/);
|
|
135
148
|
const safeTime = int(0, Number.MAX_SAFE_INTEGER);
|
|
136
149
|
const groupIndex = int(0, 2147483647);
|
|
150
|
+
/** A card's `ID(A)`: 16 bytes as 32 lowercase hex. */
|
|
151
|
+
const cardId = str(32, /^[0-9a-f]{32}$/);
|
|
152
|
+
const keyInfo = obj({
|
|
153
|
+
keyId,
|
|
154
|
+
family: keyFamily,
|
|
155
|
+
address: str(90, /^.+$/),
|
|
156
|
+
createdAt: safeTime
|
|
157
|
+
});
|
|
137
158
|
/** Identity indices stop below 2^31 - 1 — the top segment derives the wallet sync key. */
|
|
138
159
|
const identityIndex = int(0, 2147483646);
|
|
139
|
-
const factor = union(obj({ kind: literal("hardware") }), obj({
|
|
160
|
+
const factor = union(obj({ kind: literal("device") }), obj({ kind: literal("hardware") }), obj({
|
|
161
|
+
kind: literal("password"),
|
|
162
|
+
password: bytes(1, 1024)
|
|
163
|
+
}), obj({
|
|
164
|
+
kind: literal("passkey"),
|
|
165
|
+
credentialId: bytes(1, 1023),
|
|
166
|
+
prf: bytes(32)
|
|
167
|
+
}));
|
|
168
|
+
const verifier = union(obj({ kind: literal("hardware") }), obj({
|
|
140
169
|
kind: literal("password"),
|
|
141
170
|
password: bytes(1, 1024)
|
|
142
171
|
}), obj({
|
|
@@ -145,6 +174,10 @@ const factor = union(obj({ kind: literal("hardware") }), obj({
|
|
|
145
174
|
prf: bytes(32)
|
|
146
175
|
}));
|
|
147
176
|
const factorInfo = union(obj({
|
|
177
|
+
kind: literal("device"),
|
|
178
|
+
id: sessionId,
|
|
179
|
+
createdAt: safeTime
|
|
180
|
+
}), obj({
|
|
148
181
|
kind: literal("hardware"),
|
|
149
182
|
id: sessionId,
|
|
150
183
|
createdAt: safeTime
|
|
@@ -187,10 +220,13 @@ const hostBackupPasskey = obj({
|
|
|
187
220
|
credentialId: bytes(1, 1023),
|
|
188
221
|
prfBackup: bytes(32)
|
|
189
222
|
});
|
|
190
|
-
const backupPassword = obj({
|
|
223
|
+
const backupPassword = union(obj({
|
|
191
224
|
kind: literal("password"),
|
|
192
225
|
password: bytes(1, 1024)
|
|
193
|
-
})
|
|
226
|
+
}), obj({
|
|
227
|
+
kind: literal("password"),
|
|
228
|
+
ceremony: literal("kernel")
|
|
229
|
+
}));
|
|
194
230
|
const backupFactor = union(backupPassword, hostBackupPasskey, obj({
|
|
195
231
|
kind: literal("passkey"),
|
|
196
232
|
ceremony: literal("kernel"),
|
|
@@ -204,7 +240,11 @@ const backupUnlockFactor = union(backupPassword, hostBackupPasskey, obj({
|
|
|
204
240
|
rpId: str(253, RP_ID),
|
|
205
241
|
backupSalt: label(64)
|
|
206
242
|
}));
|
|
207
|
-
|
|
243
|
+
/** A hardware-signing device family on the wire; each signer adds a literal to HARDWARE_DEVICES. */
|
|
244
|
+
const hardwareDevice = union(...HARDWARE_DEVICES.map((device) => literal(device)));
|
|
245
|
+
const DEVICE_TEXT = /^[\u0020-\u007E]{1,64}$/;
|
|
246
|
+
const vaultWalletInfo = obj({
|
|
247
|
+
custody: literal("vault"),
|
|
208
248
|
walletId,
|
|
209
249
|
origin: union(literal("passkey"), literal("mnemonic")),
|
|
210
250
|
words: union(literal(12), literal(15), literal(18), literal(21), literal(24)),
|
|
@@ -212,11 +252,35 @@ const walletInfo = obj({
|
|
|
212
252
|
passphrase: bool,
|
|
213
253
|
createdAt: safeTime
|
|
214
254
|
});
|
|
255
|
+
const walletInfo = union(vaultWalletInfo, obj({
|
|
256
|
+
custody: literal("hardware"),
|
|
257
|
+
walletId,
|
|
258
|
+
device: str(32, /^[a-z][a-z0-9-]{1,31}$/),
|
|
259
|
+
supported: bool,
|
|
260
|
+
fingerprint: str(8, /^[0-9a-f]{8}$/),
|
|
261
|
+
model: opt(str(64, DEVICE_TEXT)),
|
|
262
|
+
firmware: opt(str(64, DEVICE_TEXT)),
|
|
263
|
+
createdAt: safeTime
|
|
264
|
+
}), obj({
|
|
265
|
+
custody: literal("card"),
|
|
266
|
+
walletId,
|
|
267
|
+
origin: union(literal("card-generated"), literal("card-imported")),
|
|
268
|
+
backup: literal("cards"),
|
|
269
|
+
createdAt: safeTime,
|
|
270
|
+
members: int(1, 3),
|
|
271
|
+
cards: arr(obj({
|
|
272
|
+
cardId,
|
|
273
|
+
shortId: opt(str(9, /^[0-9A-F]{4}-[0-9A-F]{4}$/)),
|
|
274
|
+
state: union(literal("ready"), literal("unknown"), literal("pending")),
|
|
275
|
+
tries: opt(int(0, 10)),
|
|
276
|
+
verifiedAt: opt(safeTime)
|
|
277
|
+
}), 3, 1)
|
|
278
|
+
}));
|
|
215
279
|
/** A BIP-39 passphrase on the wire: raw UTF-8 bytes, never empty (the host omits "none"). */
|
|
216
280
|
const passphraseBytes = bytes(1, 1024);
|
|
217
|
-
const walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-invalidated"), literal("
|
|
281
|
+
const walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-invalidated"), literal("verification-unavailable"), literal("blind-signing-disabled"), literal("passkey-not-configured"), literal("passkey-prf-unsupported"), literal("wrong-password"), literal("wrong-passkey"), literal("rate-limited"), literal("invalid-input"), literal("not-found"), literal("already-exists"), literal("conflict"), literal("unsupported"), literal("unavailable"), literal("integrity"), literal("approval-required"), literal("card-not-genuine"), literal("card-id-mismatch"), literal("card-erased"), literal("card-locked"), literal("card-tampered"), literal("card-fault"), literal("card-unsupported"), literal("app-lock-required"), literal("limit-exceeded"), literal("crashed"), literal("device-required"), literal("device-locked"), literal("device-app-closed"), literal("device-rejected"), literal("wrong-device"));
|
|
218
282
|
const createdResult = obj({
|
|
219
|
-
wallet:
|
|
283
|
+
wallet: vaultWalletInfo,
|
|
220
284
|
session: sessionId
|
|
221
285
|
});
|
|
222
286
|
const CORE_METHODS = {
|
|
@@ -242,7 +306,7 @@ const CORE_METHODS = {
|
|
|
242
306
|
session: true,
|
|
243
307
|
presence: true,
|
|
244
308
|
params: obj({
|
|
245
|
-
verify:
|
|
309
|
+
verify: verifier,
|
|
246
310
|
factor
|
|
247
311
|
}),
|
|
248
312
|
result: factorInfo
|
|
@@ -251,11 +315,35 @@ const CORE_METHODS = {
|
|
|
251
315
|
session: true,
|
|
252
316
|
presence: true,
|
|
253
317
|
params: obj({
|
|
254
|
-
verify:
|
|
318
|
+
verify: verifier,
|
|
255
319
|
id: sessionId
|
|
256
320
|
}),
|
|
257
321
|
result: nullValue
|
|
258
322
|
},
|
|
323
|
+
"vault.enrolVerification": {
|
|
324
|
+
session: true,
|
|
325
|
+
presence: true,
|
|
326
|
+
params: nullValue,
|
|
327
|
+
result: nullValue
|
|
328
|
+
},
|
|
329
|
+
"vault.setAppLock": {
|
|
330
|
+
session: true,
|
|
331
|
+
presence: true,
|
|
332
|
+
params: obj({
|
|
333
|
+
enabled: bool,
|
|
334
|
+
verify: verifier
|
|
335
|
+
}),
|
|
336
|
+
result: nullValue
|
|
337
|
+
},
|
|
338
|
+
"vault.setBlindSigning": {
|
|
339
|
+
session: true,
|
|
340
|
+
presence: true,
|
|
341
|
+
params: obj({
|
|
342
|
+
enabled: bool,
|
|
343
|
+
verify: verifier
|
|
344
|
+
}),
|
|
345
|
+
result: nullValue
|
|
346
|
+
},
|
|
259
347
|
"wallet.createWithPasskey": {
|
|
260
348
|
session: false,
|
|
261
349
|
presence: true,
|
|
@@ -301,7 +389,7 @@ const CORE_METHODS = {
|
|
|
301
389
|
session: true,
|
|
302
390
|
presence: true,
|
|
303
391
|
params: obj({
|
|
304
|
-
verify:
|
|
392
|
+
verify: verifier,
|
|
305
393
|
factors: arr(backupFactor, 5, 1)
|
|
306
394
|
}),
|
|
307
395
|
result: nullValue
|
|
@@ -315,7 +403,7 @@ const CORE_METHODS = {
|
|
|
315
403
|
"backup.disable": {
|
|
316
404
|
session: true,
|
|
317
405
|
presence: true,
|
|
318
|
-
params:
|
|
406
|
+
params: obj({ verify: verifier }),
|
|
319
407
|
result: nullValue
|
|
320
408
|
},
|
|
321
409
|
"backup.restore": {
|
|
@@ -331,7 +419,7 @@ const CORE_METHODS = {
|
|
|
331
419
|
factor: opt(factor)
|
|
332
420
|
}),
|
|
333
421
|
result: obj({
|
|
334
|
-
wallets: arr(
|
|
422
|
+
wallets: arr(vaultWalletInfo, 1e3),
|
|
335
423
|
passphraseRequired: arr(str(128), 1e3),
|
|
336
424
|
session: sessionId
|
|
337
425
|
})
|
|
@@ -350,7 +438,7 @@ const CORE_METHODS = {
|
|
|
350
438
|
session: true,
|
|
351
439
|
presence: true,
|
|
352
440
|
params: obj({
|
|
353
|
-
verify:
|
|
441
|
+
verify: verifier,
|
|
354
442
|
walletId
|
|
355
443
|
}),
|
|
356
444
|
result: obj({
|
|
@@ -362,7 +450,7 @@ const CORE_METHODS = {
|
|
|
362
450
|
session: true,
|
|
363
451
|
presence: true,
|
|
364
452
|
params: obj({
|
|
365
|
-
verify:
|
|
453
|
+
verify: verifier,
|
|
366
454
|
walletId
|
|
367
455
|
}),
|
|
368
456
|
result: nullValue
|
|
@@ -372,8 +460,41 @@ const CORE_METHODS = {
|
|
|
372
460
|
presence: false,
|
|
373
461
|
params: obj({ purpose: str(32, /^[a-z0-9-]{1,32}$/) }),
|
|
374
462
|
result: bytes(32)
|
|
463
|
+
},
|
|
464
|
+
"keys.import": {
|
|
465
|
+
session: true,
|
|
466
|
+
presence: true,
|
|
467
|
+
params: obj({
|
|
468
|
+
family: keyFamily,
|
|
469
|
+
secret: bytes(32, 64)
|
|
470
|
+
}),
|
|
471
|
+
result: keyInfo
|
|
472
|
+
},
|
|
473
|
+
"keys.list": {
|
|
474
|
+
session: true,
|
|
475
|
+
presence: false,
|
|
476
|
+
params: nullValue,
|
|
477
|
+
result: arr(keyInfo, 256)
|
|
478
|
+
},
|
|
479
|
+
"keys.remove": {
|
|
480
|
+
session: true,
|
|
481
|
+
presence: true,
|
|
482
|
+
params: obj({
|
|
483
|
+
verify: verifier,
|
|
484
|
+
keyId
|
|
485
|
+
}),
|
|
486
|
+
result: nullValue
|
|
487
|
+
},
|
|
488
|
+
"keys.export": {
|
|
489
|
+
session: true,
|
|
490
|
+
presence: true,
|
|
491
|
+
params: obj({
|
|
492
|
+
verify: verifier,
|
|
493
|
+
keyId
|
|
494
|
+
}),
|
|
495
|
+
result: bytes(1, 256)
|
|
375
496
|
}
|
|
376
497
|
};
|
|
377
|
-
export {
|
|
498
|
+
export { validate as A, literal as C, record as D, opt as E, str as O, int as S, obj as T, walletInfo as _, MAX_TEXT as a, bool as b, groupIndex as c, keyInfo as d, publicKey as f, walletId as g, walletErrorCode as h, MAX_TAG_ITEM as i, union as k, hardwareDevice as l, verifier as m, MAX_SNAPSHOT_ITEMS as n, cardId as o, safeTime as p, MAX_TAGS as r, factorInfo as s, CORE_METHODS as t, identityIndex as u, ValidationError as v, nullValue as w, bytes as x, arr as y };
|
|
378
499
|
|
|
379
|
-
//# sourceMappingURL=core-
|
|
500
|
+
//# sourceMappingURL=core-Cx7p-0nG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-Cx7p-0nG.mjs","names":[],"sources":["../src/protocol/validate.ts","../src/protocol/core.ts"],"sourcesContent":["/**\n * Strict validator combinators for the secret-area protocol. Both sides share them: the kernel\n * validates every request, the host validates every response. Anything that does not match is a\n * `ValidationError` — never a partially-accepted value.\n */\n\nexport class ValidationError extends Error {\n override name = \"ValidationError\";\n}\n\nexport type Validator<T> = (value: unknown) => T;\n\nfunction fail(): never {\n throw new ValidationError();\n}\n\n// oxlint-disable-next-line typescript/no-restricted-types -- JSON null is a protocol value\nexport type NullValue = null;\n\nexport type ProtocolValue =\n | NullValue\n | boolean\n | number // safe integer\n | string\n | Uint8Array\n | ReadonlyArray<ProtocolValue>\n | { readonly [key: string]: ProtocolValue };\n\nexport function literal<T extends NullValue | boolean | number | string>(\n expected: T,\n): Validator<T> {\n return (value) => {\n if (value !== expected) {\n fail();\n }\n return expected;\n };\n}\n\nexport const nullValue: Validator<NullValue> = literal(null);\nexport const bool: Validator<boolean> = (value) => {\n if (typeof value !== \"boolean\") {\n fail();\n }\n return value;\n};\n\nexport function int(min: number, max: number): Validator<number> {\n return (value) => {\n if (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < min || value > max) {\n fail();\n }\n return value;\n };\n}\n\nexport function str(max: number, pattern?: RegExp): Validator<string> {\n return (value) => {\n if (\n typeof value !== \"string\" ||\n value.length > max ||\n (pattern !== undefined && !pattern.test(value))\n ) {\n fail();\n }\n return value;\n };\n}\n\nexport function bytes(min: number, max?: number): Validator<Uint8Array> {\n const high = max ?? min;\n return (value) => {\n if (!(value instanceof Uint8Array) || value.length < min || value.length > high) {\n fail();\n }\n return value;\n };\n}\n\nexport function arr<T>(item: Validator<T>, max: number, min = 0): Validator<ReadonlyArray<T>> {\n return (value) => {\n if (!Array.isArray(value) || value.length < min || value.length > max) {\n fail();\n }\n const out: T[] = [];\n for (const element of value) {\n out.push(item(element));\n }\n return out;\n };\n}\n\nclass Opt<T> {\n readonly validator: Validator<T>;\n\n constructor(validator: Validator<T>) {\n this.validator = validator;\n }\n}\n\nexport function opt<T>(validator: Validator<T>): Opt<T> {\n return new Opt(validator);\n}\n\ntype Field = Validator<unknown> | Opt<unknown>;\ntype Shape = Record<string, Field>;\n\ntype RequiredKeys<S extends Shape> = {\n readonly [K in keyof S as S[K] extends Opt<unknown> ? never : K]: S[K] extends Validator<infer T>\n ? T\n : never;\n};\ntype OptionalKeys<S extends Shape> = {\n readonly [K in keyof S as S[K] extends Opt<unknown> ? K : never]?: S[K] extends Opt<infer T>\n ? T\n : never;\n};\ntype ShapeResult<S extends Shape> = RequiredKeys<S> & OptionalKeys<S>;\n\n/** Exact key set: required keys present, optional keys allowed, nothing else. */\nexport function obj<S extends Shape>(shape: S): Validator<ShapeResult<S>> {\n const keys = Object.keys(shape);\n return (value) => {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n value instanceof Uint8Array\n ) {\n fail();\n }\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- narrowed to a plain object above\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (!Object.hasOwn(shape, key)) {\n fail();\n }\n }\n const out: Record<string, unknown> = {};\n for (const key of keys) {\n const field = shape[key];\n if (field === undefined) {\n fail();\n }\n const raw = record[key];\n if (field instanceof Opt) {\n if (raw !== undefined) {\n out[key] = field.validator(raw);\n }\n } else {\n if (!Object.hasOwn(record, key)) {\n fail();\n }\n out[key] = field(raw);\n }\n }\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the shape guarantees the keys\n return out as ShapeResult<S>;\n };\n}\n\nconst FORBIDDEN_RECORD_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * A `Record<K, V>` wire value: plain objects only, every key checked by `key`, every value by\n * `value`, at most `max` entries. Prototype-polluting keys are rejected outright — a validated\n * record must be safe to copy key-by-key.\n */\nexport function record<K extends string, V>(\n key: Validator<K>,\n value: Validator<V>,\n max: number,\n): Validator<Record<K, V>> {\n return (input) => {\n if (\n typeof input !== \"object\" ||\n input === null ||\n Array.isArray(input) ||\n input instanceof Uint8Array ||\n Object.getPrototypeOf(input) !== Object.prototype\n ) {\n fail();\n }\n const out: Record<string, V> = {};\n const entries = Object.entries(input);\n if (entries.length > max) {\n fail();\n }\n for (const [name, item] of entries) {\n if (FORBIDDEN_RECORD_KEYS.has(name)) {\n fail();\n }\n out[key(name)] = value(item);\n }\n return out;\n };\n}\n\n/** Tries each branch in order; the first match wins. */\nexport function union<Vs extends ReadonlyArray<Validator<unknown>>>(\n ...branches: Vs\n): Validator<ReturnType<Vs[number]>> {\n return (value) => {\n for (const branch of branches) {\n try {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- ReturnType of the branch union\n return branch(value) as ReturnType<Vs[number]>;\n } catch (error) {\n if (!(error instanceof ValidationError)) {\n throw error;\n }\n }\n }\n return fail();\n };\n}\n\n/** Validates a value and returns it, or undefined on a shape mismatch. */\nexport function validate<T>(validator: Validator<T>, value: unknown): T | undefined {\n try {\n return validator(value);\n } catch (error) {\n if (error instanceof ValidationError) {\n return undefined;\n }\n throw error;\n }\n}\n","/**\n * The core method table: vault, wallet and data-key commands — nothing protocol-specific. \"Create\n * or import\" commands (createWithPasskey/restoreWithPasskey/createMnemonic/importMnemonic) are\n * `session: false` here because the rule is dynamic: with an uninitialized vault they carry\n * `factor` and establish the vault in one commit; with an established vault `factor` must be absent\n * and a valid session is required.\n *\n * The shared wire validators (factor, wallet info, ids) live here too so the nostr module's table\n * can reuse them — `protocol/nostr.ts` imports only from this file.\n */\nimport { HARDWARE_DEVICES } from \"../types.ts\";\nimport type {\n FactorInfo,\n HardwareDevice,\n VaultWalletInfo,\n WalletErrorCode,\n WalletInfo,\n} from \"../types.ts\";\nimport type { NullValue, Validator } from \"./validate.ts\";\nimport { arr, bool, bytes, int, literal, nullValue, obj, opt, str, union } from \"./validate.ts\";\n\nexport type MethodSpec<P, R> = {\n readonly session: boolean;\n /**\n * Whether a successful call counts as user presence for the idle timer. It refreshes the deadline\n * only on a host without a platform keystore (Web, Node); on a keystore host only a successful\n * factor verification does.\n */\n readonly presence: boolean;\n readonly params: Validator<P>;\n readonly result: Validator<R>;\n};\n\n// Size caps (UTF-16 units for strings, bytes for Uint8Array). These bound individual fields; the\n// whole-request cap MAX_REQUEST_BYTES (protocol/index.ts) is enforced by host and kernel.\nexport const MAX_TEXT = 262_144;\nexport const MAX_TAGS = 1024;\nexport const MAX_TAG_ITEMS = 64;\nexport const MAX_TAG_ITEM = 4096;\nexport const MAX_BATCH = 64;\nexport const MAX_SNAPSHOT_ITEMS = 4096;\n\nexport const sessionId: Validator<string> = str(32, /^[0-9a-f]{32}$/);\nexport const draftId: Validator<string> = str(32, /^[0-9a-f]{32}$/);\nexport const walletId: Validator<string> = str(16, /^[0-9a-f]{16}$/);\nexport const keyId: Validator<string> = str(16, /^[0-9a-f]{16}$/);\nexport const keyFamily: Validator<\"evm\" | \"solana\" | \"bitcoin\" | \"tron\"> = union(\n literal(\"evm\"),\n literal(\"solana\"),\n literal(\"bitcoin\"),\n literal(\"tron\"),\n);\n\nexport const publicKey: Validator<string> = str(64, /^[0-9a-f]{64}$/);\nexport const credentialId: Validator<string> = str(1364, /^[A-Za-z0-9_-]+$/);\nexport const safeTime: Validator<number> = int(0, Number.MAX_SAFE_INTEGER);\nexport const groupIndex: Validator<number> = int(0, 0x7fffffff);\n/** A card's `ID(A)`: 16 bytes as 32 lowercase hex. */\nexport const cardId: Validator<string> = str(32, /^[0-9a-f]{32}$/);\nexport const keyInfo: Validator<{\n readonly keyId: string;\n readonly family: \"evm\" | \"solana\" | \"bitcoin\" | \"tron\";\n readonly address: string;\n readonly createdAt: number;\n}> = obj({ keyId, family: keyFamily, address: str(90, /^.+$/), createdAt: safeTime });\n/** Identity indices stop below 2^31 - 1 — the top segment derives the wallet sync key. */\nexport const identityIndex: Validator<number> = int(0, 0x7ffffffe);\n\n/**\n * Vault factor material on the wire. `device` and `hardware` carry nothing: the kernel runs the\n * platform keystore operations itself, so the main runtime never touches the KEK. `device` opens a\n * session without user presence — it can never appear in a `verify` field.\n */\nexport type Factor =\n | { readonly kind: \"device\" }\n | { readonly kind: \"hardware\" }\n | { readonly kind: \"password\"; readonly password: Uint8Array }\n | { readonly kind: \"passkey\"; readonly credentialId: Uint8Array; readonly prf: Uint8Array };\n\nexport const factor: Validator<Factor> = union(\n obj({ kind: literal(\"device\") }),\n obj({ kind: literal(\"hardware\") }),\n obj({ kind: literal(\"password\"), password: bytes(1, 1024) }),\n obj({ kind: literal(\"passkey\"), credentialId: bytes(1, 1023), prf: bytes(32) }),\n);\n\n/**\n * A factor that may prove user presence — every `verify` field uses this validator, so a device\n * factor never reaches `verifyFactor` through the protocol (the kernel rejects it again anyway).\n */\nexport type VerifyFactor = Exclude<Factor, { readonly kind: \"device\" }>;\n\nexport const verifier: Validator<VerifyFactor> = union(\n obj({ kind: literal(\"hardware\") }),\n obj({ kind: literal(\"password\"), password: bytes(1, 1024) }),\n obj({ kind: literal(\"passkey\"), credentialId: bytes(1, 1023), prf: bytes(32) }),\n);\n\n/** A host-run backup passkey ceremony's evidence: the PRF over `backupSalt` (web). */\ntype HostBackupPasskey = {\n readonly kind: \"passkey\";\n readonly ceremony: \"host\";\n readonly credentialId: Uint8Array;\n readonly prfBackup: Uint8Array;\n};\n\n/**\n * The backup password arm: the wire carries the bytes only on hosts without a keystore — on React\n * Native the kernel collects the password through its secure input (`kernel`), so the main runtime\n * never holds it.\n */\nexport type BackupPasswordFactor =\n | { readonly kind: \"password\"; readonly password: Uint8Array }\n | { readonly kind: \"password\"; readonly ceremony: \"kernel\" };\n\n/**\n * A factor that seals a new backup key. On React Native the kernel registers a protection\n * credential (`kernel`) itself and names it; on the web the host hands over its ceremony's\n * evidence.\n */\nexport type BackupFactor =\n | BackupPasswordFactor\n | HostBackupPasskey\n | {\n readonly kind: \"passkey\";\n readonly ceremony: \"kernel\";\n readonly rpId: string;\n readonly rpName: string;\n readonly backupSalt: string;\n };\n\n/**\n * A factor that opens a backup envelope. The `kernel` passkey arm asserts one of the envelope's own\n * credentials.\n */\nexport type BackupUnlockFactor =\n | BackupPasswordFactor\n | HostBackupPasskey\n | {\n readonly kind: \"passkey\";\n readonly ceremony: \"kernel\";\n readonly rpId: string;\n readonly backupSalt: string;\n };\n\nexport const factorInfo: Validator<FactorInfo> = union(\n obj({ kind: literal(\"device\"), id: sessionId, createdAt: safeTime }),\n obj({ kind: literal(\"hardware\"), id: sessionId, createdAt: safeTime }),\n obj({\n kind: literal(\"passkey\"),\n id: sessionId,\n credentialId,\n createdAt: safeTime,\n }),\n obj({ kind: literal(\"password\"), id: sessionId, createdAt: safeTime }),\n);\n\n/**\n * Passkey wallet creation. `host`: the host ran the WebAuthn ceremony and hands over the PRF\n * evidence (web). `kernel`: the kernel runs the platform ceremony itself and nothing secret crosses\n * the channel (React Native). The kernel accepts exactly the shape its platform supports.\n */\nexport type CreateWithPasskeyParams =\n | {\n readonly ceremony: \"host\";\n readonly credentialId: Uint8Array;\n readonly prfWallet: Uint8Array;\n readonly synced: boolean;\n readonly factor?: Factor;\n }\n | {\n readonly ceremony: \"kernel\";\n readonly rpId: string;\n readonly rpName: string;\n readonly name: string;\n readonly walletSalt: string;\n readonly factor?: Factor;\n };\n\nexport type RestoreWithPasskeyParams =\n | {\n readonly ceremony: \"host\";\n readonly credentialId: Uint8Array;\n readonly prfWallet: Uint8Array;\n readonly synced: boolean;\n readonly factor?: Factor;\n }\n | {\n readonly ceremony: \"kernel\";\n readonly rpId: string;\n readonly walletSalt: string;\n readonly factor?: Factor;\n };\n\n// An RP id is a lowercase DNS name; the platform rejects anything its associated domains do not\n// list, so this only bounds the shape.\nconst RP_ID =\n /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;\nconst label = (max: number): Validator<string> => str(max, /^\\S(?:.*\\S)?$/su);\n\nconst hostEvidence = {\n ceremony: literal(\"host\"),\n credentialId: bytes(1, 1023),\n prfWallet: bytes(32),\n synced: bool,\n factor: opt(factor),\n};\n\nconst createWithPasskeyParams: Validator<CreateWithPasskeyParams> = union(\n obj(hostEvidence),\n obj({\n ceremony: literal(\"kernel\"),\n rpId: str(253, RP_ID),\n rpName: label(64),\n name: label(64),\n walletSalt: label(64),\n factor: opt(factor),\n }),\n);\n\nconst restoreWithPasskeyParams: Validator<RestoreWithPasskeyParams> = union(\n obj(hostEvidence),\n obj({\n ceremony: literal(\"kernel\"),\n rpId: str(253, RP_ID),\n walletSalt: label(64),\n factor: opt(factor),\n }),\n);\n\nconst hostBackupPasskey = obj({\n kind: literal(\"passkey\"),\n ceremony: literal(\"host\"),\n credentialId: bytes(1, 1023),\n prfBackup: bytes(32),\n});\nconst backupPassword = union(\n obj({ kind: literal(\"password\"), password: bytes(1, 1024) }),\n obj({ kind: literal(\"password\"), ceremony: literal(\"kernel\") }),\n);\n\nexport const backupFactor: Validator<BackupFactor> = union(\n backupPassword,\n hostBackupPasskey,\n obj({\n kind: literal(\"passkey\"),\n ceremony: literal(\"kernel\"),\n rpId: str(253, RP_ID),\n rpName: label(64),\n backupSalt: label(64),\n }),\n);\n\nexport const backupUnlockFactor: Validator<BackupUnlockFactor> = union(\n backupPassword,\n hostBackupPasskey,\n obj({\n kind: literal(\"passkey\"),\n ceremony: literal(\"kernel\"),\n rpId: str(253, RP_ID),\n backupSalt: label(64),\n }),\n);\n\n/** A hardware-signing device family on the wire; each signer adds a literal to HARDWARE_DEVICES. */\nexport const hardwareDevice: Validator<HardwareDevice> = union(\n ...HARDWARE_DEVICES.map((device) => literal(device)),\n);\n\nconst DEVICE_TEXT = /^[\\u0020-\\u007E]{1,64}$/;\n\nexport const vaultWalletInfo: Validator<VaultWalletInfo> = obj({\n custody: literal(\"vault\"),\n walletId,\n origin: union(literal(\"passkey\"), literal(\"mnemonic\")),\n words: union(literal(12), literal(15), literal(18), literal(21), literal(24)),\n backup: union(literal(\"none\"), literal(\"passkey\"), literal(\"mnemonic\")),\n passphrase: bool,\n createdAt: safeTime,\n});\n\nexport const walletInfo: Validator<WalletInfo> = union(\n vaultWalletInfo,\n obj({\n custody: literal(\"hardware\"),\n walletId,\n device: str(32, /^[a-z][a-z0-9-]{1,31}$/),\n supported: bool,\n fingerprint: str(8, /^[0-9a-f]{8}$/),\n model: opt(str(64, DEVICE_TEXT)),\n firmware: opt(str(64, DEVICE_TEXT)),\n createdAt: safeTime,\n }),\n obj({\n custody: literal(\"card\"),\n walletId,\n origin: union(literal(\"card-generated\"), literal(\"card-imported\")),\n backup: literal(\"cards\"),\n createdAt: safeTime,\n members: int(1, 3),\n cards: arr(\n obj({\n cardId,\n shortId: opt(str(9, /^[0-9A-F]{4}-[0-9A-F]{4}$/)),\n state: union(literal(\"ready\"), literal(\"unknown\"), literal(\"pending\")),\n tries: opt(int(0, 10)),\n verifiedAt: opt(safeTime),\n }),\n 3,\n 1,\n ),\n }),\n);\n\n/** A BIP-39 passphrase on the wire: raw UTF-8 bytes, never empty (the host omits \"none\"). */\nconst passphraseBytes: Validator<Uint8Array> = bytes(1, 1024);\n\nexport const walletErrorCode: Validator<WalletErrorCode> = union(\n literal(\"locked\"),\n literal(\"cancelled\"),\n literal(\"factor-invalidated\"),\n literal(\"verification-unavailable\"),\n literal(\"blind-signing-disabled\"),\n literal(\"passkey-not-configured\"),\n literal(\"passkey-prf-unsupported\"),\n literal(\"wrong-password\"),\n literal(\"wrong-passkey\"),\n literal(\"rate-limited\"),\n literal(\"invalid-input\"),\n literal(\"not-found\"),\n literal(\"already-exists\"),\n literal(\"conflict\"),\n literal(\"unsupported\"),\n literal(\"unavailable\"),\n literal(\"integrity\"),\n literal(\"approval-required\"),\n literal(\"card-not-genuine\"),\n literal(\"card-id-mismatch\"),\n literal(\"card-erased\"),\n literal(\"card-locked\"),\n literal(\"card-tampered\"),\n literal(\"card-fault\"),\n literal(\"card-unsupported\"),\n literal(\"app-lock-required\"),\n literal(\"limit-exceeded\"),\n literal(\"crashed\"),\n literal(\"device-required\"),\n literal(\"device-locked\"),\n literal(\"device-app-closed\"),\n literal(\"device-rejected\"),\n literal(\"wrong-device\"),\n);\n\n/**\n * The result of every \"create or import\" wallet command: the new wallet's public info plus the\n * session it opened. Creating a wallet derives no protocol keys — modules add keys separately.\n */\nexport type CreatedResult = {\n readonly wallet: VaultWalletInfo;\n readonly session: string;\n};\n\nconst createdResult: Validator<CreatedResult> = obj({\n wallet: vaultWalletInfo,\n session: sessionId,\n});\n\n// `status` itself is a core method, but its result validator composes every module's status\n// section — it is wired in protocol/index.ts, not here.\nexport const CORE_METHODS: {\n readonly \"vault.unlock\": MethodSpec<{ readonly factor: Factor }, { readonly session: string }>;\n readonly \"vault.reset\": MethodSpec<NullValue, NullValue>;\n readonly \"vault.addFactor\": MethodSpec<\n { readonly verify: VerifyFactor; readonly factor: Factor },\n FactorInfo\n >;\n readonly \"vault.removeFactor\": MethodSpec<\n { readonly verify: VerifyFactor; readonly id: string },\n NullValue\n >;\n readonly \"vault.enrolVerification\": MethodSpec<NullValue, NullValue>;\n readonly \"vault.setAppLock\": MethodSpec<\n { readonly enabled: boolean; readonly verify: VerifyFactor },\n NullValue\n >;\n readonly \"vault.setBlindSigning\": MethodSpec<\n { readonly enabled: boolean; readonly verify: VerifyFactor },\n NullValue\n >;\n readonly \"session.touch\": MethodSpec<NullValue, NullValue>;\n readonly \"wallet.createWithPasskey\": MethodSpec<CreateWithPasskeyParams, CreatedResult>;\n readonly \"wallet.restoreWithPasskey\": MethodSpec<RestoreWithPasskeyParams, CreatedResult>;\n readonly \"wallet.createMnemonic\": MethodSpec<\n { readonly words: 12 | 24; readonly factor?: Factor },\n { readonly draft: string; readonly words: Uint8Array; readonly quiz: ReadonlyArray<number> }\n >;\n readonly \"wallet.confirmMnemonic\": MethodSpec<\n {\n readonly draft: string;\n readonly answers: ReadonlyArray<Uint8Array>;\n readonly passphrase?: Uint8Array;\n },\n CreatedResult\n >;\n readonly \"wallet.discardMnemonic\": MethodSpec<{ readonly draft: string }, NullValue>;\n readonly \"backup.enable\": MethodSpec<\n {\n readonly verify: VerifyFactor;\n readonly factors: ReadonlyArray<BackupFactor>;\n },\n NullValue\n >;\n readonly \"backup.update\": MethodSpec<NullValue, { readonly envelope: string }>;\n readonly \"backup.disable\": MethodSpec<{ readonly verify: VerifyFactor }, NullValue>;\n readonly \"backup.restore\": MethodSpec<\n {\n readonly envelope: string;\n readonly backupFactor: BackupUnlockFactor;\n readonly passphrases?: ReadonlyArray<{\n readonly walletId: string;\n readonly passphrase: Uint8Array;\n }>;\n readonly factor?: Factor;\n },\n {\n readonly wallets: ReadonlyArray<VaultWalletInfo>;\n readonly passphraseRequired: ReadonlyArray<string>;\n readonly session: string;\n }\n >;\n readonly \"wallet.importMnemonic\": MethodSpec<\n { readonly mnemonic: Uint8Array; readonly passphrase?: Uint8Array; readonly factor?: Factor },\n CreatedResult\n >;\n readonly \"wallet.exportMnemonic\": MethodSpec<\n { readonly verify: VerifyFactor; readonly walletId: string },\n { readonly mnemonic: Uint8Array; readonly passphrase?: Uint8Array }\n >;\n readonly \"wallet.delete\": MethodSpec<\n { readonly verify: VerifyFactor; readonly walletId: string },\n NullValue\n >;\n readonly \"dataKeys.get\": MethodSpec<{ readonly purpose: string }, Uint8Array>;\n readonly \"keys.import\": MethodSpec<\n { readonly family: \"evm\" | \"solana\" | \"bitcoin\" | \"tron\"; readonly secret: Uint8Array },\n {\n readonly keyId: string;\n readonly family: \"evm\" | \"solana\" | \"bitcoin\" | \"tron\";\n readonly address: string;\n readonly createdAt: number;\n }\n >;\n readonly \"keys.list\": MethodSpec<\n NullValue,\n ReadonlyArray<{\n readonly keyId: string;\n readonly family: \"evm\" | \"solana\" | \"bitcoin\" | \"tron\";\n readonly address: string;\n readonly createdAt: number;\n }>\n >;\n readonly \"keys.remove\": MethodSpec<\n { readonly verify: VerifyFactor; readonly keyId: string },\n NullValue\n >;\n readonly \"keys.export\": MethodSpec<\n { readonly verify: VerifyFactor; readonly keyId: string },\n Uint8Array\n >;\n} = {\n \"session.touch\": {\n session: true,\n presence: true,\n params: nullValue,\n result: nullValue,\n },\n \"vault.unlock\": {\n session: false,\n presence: true,\n params: obj({ factor }),\n result: obj({ session: sessionId }),\n },\n \"vault.reset\": { session: false, presence: false, params: nullValue, result: nullValue },\n \"vault.addFactor\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier, factor }),\n result: factorInfo,\n },\n \"vault.removeFactor\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier, id: sessionId }),\n result: nullValue,\n },\n \"vault.enrolVerification\": {\n session: true,\n presence: true,\n params: nullValue,\n result: nullValue,\n },\n \"vault.setAppLock\": {\n session: true,\n presence: true,\n params: obj({ enabled: bool, verify: verifier }),\n result: nullValue,\n },\n \"vault.setBlindSigning\": {\n session: true,\n presence: true,\n params: obj({ enabled: bool, verify: verifier }),\n result: nullValue,\n },\n \"wallet.createWithPasskey\": {\n session: false,\n presence: true,\n params: createWithPasskeyParams,\n result: createdResult,\n },\n \"wallet.restoreWithPasskey\": {\n session: false,\n presence: true,\n params: restoreWithPasskeyParams,\n result: createdResult,\n },\n \"wallet.createMnemonic\": {\n session: false,\n presence: true,\n params: obj({ words: union(literal(12), literal(24)), factor: opt(factor) }),\n result: obj({\n draft: draftId,\n words: bytes(16, 1024),\n quiz: arr(int(0, 23), 3, 3),\n }),\n },\n \"wallet.confirmMnemonic\": {\n session: false,\n presence: true,\n params: obj({\n draft: draftId,\n answers: arr(bytes(1, 64), 3, 3),\n passphrase: opt(passphraseBytes),\n }),\n result: createdResult,\n },\n \"wallet.discardMnemonic\": {\n session: false,\n presence: false,\n params: obj({ draft: draftId }),\n result: nullValue,\n },\n \"backup.enable\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier, factors: arr(backupFactor, 5, 1) }),\n result: nullValue,\n },\n \"backup.update\": {\n session: true,\n presence: false,\n params: nullValue,\n result: obj({ envelope: str(4_000_000) }),\n },\n \"backup.disable\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier }),\n result: nullValue,\n },\n \"backup.restore\": {\n session: false,\n presence: true,\n params: obj({\n envelope: str(4_000_000),\n backupFactor: backupUnlockFactor,\n passphrases: opt(arr(obj({ walletId, passphrase: passphraseBytes }), 1000)),\n factor: opt(factor),\n }),\n result: obj({\n wallets: arr(vaultWalletInfo, 1000),\n passphraseRequired: arr(str(128), 1000),\n session: sessionId,\n }),\n },\n \"wallet.importMnemonic\": {\n session: false,\n presence: true,\n params: obj({\n mnemonic: bytes(1, 1024),\n passphrase: opt(passphraseBytes),\n factor: opt(factor),\n }),\n result: createdResult,\n },\n \"wallet.exportMnemonic\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier, walletId }),\n result: obj({ mnemonic: bytes(16, 1024), passphrase: opt(passphraseBytes) }),\n },\n \"wallet.delete\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier, walletId }),\n result: nullValue,\n },\n \"dataKeys.get\": {\n session: true,\n presence: false,\n params: obj({ purpose: str(32, /^[a-z0-9-]{1,32}$/) }),\n result: bytes(32),\n },\n \"keys.import\": {\n session: true,\n presence: true,\n params: obj({ family: keyFamily, secret: bytes(32, 64) }),\n result: keyInfo,\n },\n \"keys.list\": {\n session: true,\n presence: false,\n params: nullValue,\n result: arr(keyInfo, 256),\n },\n \"keys.remove\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier, keyId }),\n result: nullValue,\n },\n \"keys.export\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier, keyId }),\n result: bytes(1, 256),\n },\n};\n"],"mappings":";;;;;;;AAMA,IAAa,kBAAb,cAAqC,MAAM;CACzC,OAAgB;AAClB;AAIA,SAAS,OAAc;CACrB,MAAM,IAAI,gBAAgB;AAC5B;AAcA,SAAgB,QACd,UACc;CACd,QAAQ,UAAU;EAChB,IAAI,UAAU,UACZ,KAAK;EAEP,OAAO;CACT;AACF;AAEA,MAAa,YAAkC,QAAQ,IAAI;AAC3D,MAAa,QAA4B,UAAU;CACjD,IAAI,OAAO,UAAU,WACnB,KAAK;CAEP,OAAO;AACT;AAEA,SAAgB,IAAI,KAAa,KAAgC;CAC/D,QAAQ,UAAU;EAChB,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,OAAO,QAAQ,KACtF,KAAK;EAEP,OAAO;CACT;AACF;AAEA,SAAgB,IAAI,KAAa,SAAqC;C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;EACR,QAAQ,IAAI,SAAS,GAAG;CAC1B;CACA,eAAe;EACb,SAAS;EACT,UAAU;EACV,QAAQ,IAAI;GAAE,QAAQ;GAAU;EAAM,CAAC;EACvC,QAAQ;CACV;CACA,eAAe;EACb,SAAS;EACT,UAAU;EACV,QAAQ,IAAI;GAAE,QAAQ;GAAU;EAAM,CAAC;EACvC,QAAQ,MAAM,GAAG,GAAG;CACtB;AACF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { P as WalletInfo, p as HardwareDevice } from "./types-CRnacSqJ.mjs";
|
|
2
|
+
import { S as NullValue, _ as MethodSpec, c as ChainSignRequest, l as ChainSignResult, n as ChainAccount, u as ChainTemplate, y as VerifyFactor } from "./chains-u1M0CWkT.mjs";
|
|
3
|
+
type QrPayload = {
|
|
4
|
+
readonly type: string;
|
|
5
|
+
readonly cbor: Uint8Array;
|
|
6
|
+
};
|
|
7
|
+
type DeviceRequest = {
|
|
8
|
+
readonly kind: "qr";
|
|
9
|
+
readonly show?: QrPayload;
|
|
10
|
+
readonly scan: ReadonlyArray<string>;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "message";
|
|
13
|
+
readonly data: Uint8Array;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: "compare";
|
|
16
|
+
readonly address: string;
|
|
17
|
+
readonly path: string;
|
|
18
|
+
};
|
|
19
|
+
type DeviceResponse = {
|
|
20
|
+
readonly kind: "qr";
|
|
21
|
+
readonly ur: QrPayload;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "message";
|
|
24
|
+
readonly data: Uint8Array;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: "compare";
|
|
27
|
+
readonly matched: boolean;
|
|
28
|
+
};
|
|
29
|
+
type DeviceDisplay = "clear" | "blind";
|
|
30
|
+
/** The host transport for one device operation. */
|
|
31
|
+
type DeviceIo = {
|
|
32
|
+
/**
|
|
33
|
+
* Carries one kernel-produced exchange: show `request.show` / send `request.data`, then resolve
|
|
34
|
+
* with what the device answered. Rejecting aborts the operation.
|
|
35
|
+
*/
|
|
36
|
+
readonly exchange: (request: DeviceRequest, context: {
|
|
37
|
+
readonly device: HardwareDevice;
|
|
38
|
+
readonly display?: DeviceDisplay;
|
|
39
|
+
}) => Promise<DeviceResponse>;
|
|
40
|
+
};
|
|
41
|
+
type HardwareOperation = {
|
|
42
|
+
readonly kind: "pair";
|
|
43
|
+
readonly device: HardwareDevice;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "accounts";
|
|
46
|
+
readonly walletId: string;
|
|
47
|
+
readonly groupIndex: number;
|
|
48
|
+
readonly templates: ReadonlyArray<ChainTemplate>;
|
|
49
|
+
readonly network: string;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: "sign";
|
|
52
|
+
readonly request: ChainSignRequest;
|
|
53
|
+
/**
|
|
54
|
+
* Acknowledge sending to a key the device never confirmed on-screen — the prompt shows a
|
|
55
|
+
* danger row for the output. Absent, such a send refuses with `approval-required`.
|
|
56
|
+
*/
|
|
57
|
+
readonly acknowledgeUnconfirmed?: true;
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: "verify-address";
|
|
60
|
+
readonly walletId: string;
|
|
61
|
+
readonly groupIndex: number;
|
|
62
|
+
readonly template: ChainTemplate;
|
|
63
|
+
readonly network: string;
|
|
64
|
+
/** The Bitcoin receive-address index; meaningful only for btc.* templates. */
|
|
65
|
+
readonly index?: number;
|
|
66
|
+
};
|
|
67
|
+
type HardwareResult = {
|
|
68
|
+
readonly kind: "pair";
|
|
69
|
+
readonly wallet: WalletInfo;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: "accounts";
|
|
72
|
+
readonly accounts: ReadonlyArray<ChainAccount>;
|
|
73
|
+
} | {
|
|
74
|
+
readonly kind: "sign";
|
|
75
|
+
readonly result: ChainSignResult;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: "verify-address";
|
|
78
|
+
readonly address: string;
|
|
79
|
+
readonly method: "device" | "compare";
|
|
80
|
+
};
|
|
81
|
+
type HardwareStep = {
|
|
82
|
+
readonly kind: "exchange";
|
|
83
|
+
readonly device: HardwareDevice;
|
|
84
|
+
readonly request: DeviceRequest;
|
|
85
|
+
readonly display?: DeviceDisplay;
|
|
86
|
+
} | {
|
|
87
|
+
readonly kind: "done";
|
|
88
|
+
readonly result: HardwareResult;
|
|
89
|
+
};
|
|
90
|
+
declare const HARDWARE_METHODS: {
|
|
91
|
+
readonly "hardware.begin": MethodSpec<{
|
|
92
|
+
readonly op: HardwareOperation;
|
|
93
|
+
readonly verify?: VerifyFactor;
|
|
94
|
+
}, {
|
|
95
|
+
readonly opId: string;
|
|
96
|
+
readonly step: HardwareStep;
|
|
97
|
+
}>;
|
|
98
|
+
readonly "hardware.step": MethodSpec<{
|
|
99
|
+
readonly opId: string;
|
|
100
|
+
readonly response: DeviceResponse;
|
|
101
|
+
}, HardwareStep>;
|
|
102
|
+
readonly "hardware.cancel": MethodSpec<{
|
|
103
|
+
readonly opId: string;
|
|
104
|
+
}, NullValue>;
|
|
105
|
+
};
|
|
106
|
+
export { HARDWARE_METHODS as a, HardwareStep as c, DeviceResponse as i, QrPayload as l, DeviceIo as n, HardwareOperation as o, DeviceRequest as r, HardwareResult as s, DeviceDisplay as t };
|
|
107
|
+
//# sourceMappingURL=hardware-BL6zvhQh.d.mts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { A as VerifyFactor, j as Wallet, p as HardwareDevice, w as SignerTask } from "./types-CRnacSqJ.mjs";
|
|
2
|
+
import { c as HardwareStep, i as DeviceResponse, l as QrPayload, n as DeviceIo, o as HardwareOperation, r as DeviceRequest, s as HardwareResult, t as DeviceDisplay } from "./hardware-BL6zvhQh.mjs";
|
|
3
|
+
/** The byte-oriented host ports the hardware transports run on: one write, one read. */
|
|
4
|
+
/** A byte-oriented HID port: report writes and reads (64 bytes for the current drivers). */
|
|
5
|
+
type HidPort = {
|
|
6
|
+
write: (report: Uint8Array) => Promise<void>;
|
|
7
|
+
read: () => Promise<Uint8Array>;
|
|
8
|
+
};
|
|
9
|
+
/** A byte-oriented BLE port: characteristic writes and notification reads. */
|
|
10
|
+
type BlePort = {
|
|
11
|
+
write: (frame: Uint8Array) => Promise<void>;
|
|
12
|
+
read: () => Promise<Uint8Array>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* One APDU exchange over HID: frames the request, reassembles the response. One call at a time — an
|
|
16
|
+
* interleaved call while a previous one is in flight is `invalid-input`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ledgerHidExchange(port: HidPort, channel: number): (apdu: Uint8Array) => Promise<Uint8Array>;
|
|
19
|
+
/** Negotiates the BLE MTU once, then returns the framed exchange. */
|
|
20
|
+
export declare function ledgerBleExchange(port: BlePort): Promise<(apdu: Uint8Array) => Promise<Uint8Array>>;
|
|
21
|
+
/**
|
|
22
|
+
* A `DeviceIo` backed by a raw APDU exchange: `message` requests are answered with `apdu`, any
|
|
23
|
+
* other request kind is `unsupported` — a Ledger device cannot take a QR or compare exchange.
|
|
24
|
+
*/
|
|
25
|
+
export declare function ledgerIo(apdu: (apdu: Uint8Array) => Promise<Uint8Array>): DeviceIo;
|
|
26
|
+
/**
|
|
27
|
+
* One framed command exchange over USB HID: writes `data` report by report, then collects the whole
|
|
28
|
+
* report sequence of the answer. One call at a time — an interleaved call while a previous one is
|
|
29
|
+
* in flight is `invalid-input`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function oneKeyHidExchange(port: HidPort): (data: Uint8Array) => Promise<Uint8Array>;
|
|
32
|
+
/**
|
|
33
|
+
* The same exchange over BLE: `data` — the same 64-byte report sequence — is split into writes of
|
|
34
|
+
* at most `mtu` bytes (the chip counts reports, not write calls), and the answer is the
|
|
35
|
+
* concatenated notification stream. One call at a time — interleaving is `invalid-input`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function oneKeyBleExchange(port: BlePort, mtu: number): (data: Uint8Array) => Promise<Uint8Array>;
|
|
38
|
+
/**
|
|
39
|
+
* A `DeviceIo` backed by a framed exchange: `message` requests are written verbatim, any other
|
|
40
|
+
* request kind is `unsupported` — a OneKey device cannot take a QR or compare exchange.
|
|
41
|
+
*/
|
|
42
|
+
export declare function oneKeyIo(exchange: (data: Uint8Array) => Promise<Uint8Array>): DeviceIo;
|
|
43
|
+
/** One running device operation: observe every exchange (and the verified `done`), cancel ends it. */
|
|
44
|
+
export type HardwareTask = SignerTask<HardwareStep, HardwareResult>;
|
|
45
|
+
export type HardwareApi = {
|
|
46
|
+
/**
|
|
47
|
+
* Runs one device operation — pair, accounts, sign or verify-address — begin, then fold each
|
|
48
|
+
* `exchange` step through `options.io.exchange` until `done`. A second `start` cancels the
|
|
49
|
+
* running task. A `sign` result is verified (`chains().sign` rules) before `done` is emitted; a
|
|
50
|
+
* rejected exchange or a kernel error cancels the operation best-effort and rejects `result`;
|
|
51
|
+
* `cancel` answers `cancelled`.
|
|
52
|
+
*/
|
|
53
|
+
readonly start: (op: HardwareOperation, options: {
|
|
54
|
+
readonly io: DeviceIo;
|
|
55
|
+
readonly verify?: VerifyFactor;
|
|
56
|
+
}) => HardwareTask;
|
|
57
|
+
};
|
|
58
|
+
export declare function hardware(wallet: Wallet): HardwareApi;
|
|
59
|
+
/**
|
|
60
|
+
* Endless, cyclic fountain parts for one QR payload: each call returns the next uppercase UR string
|
|
61
|
+
* (`UR:<type>/…`), ready for an animated QR. For single-part payloads the same frame repeats — the
|
|
62
|
+
* loop is safe to drive on a timer.
|
|
63
|
+
*/
|
|
64
|
+
export declare const qrParts: (payload: QrPayload, options?: {
|
|
65
|
+
readonly maxFragmentLength?: number;
|
|
66
|
+
}) => (() => string);
|
|
67
|
+
export type QrReader = {
|
|
68
|
+
/**
|
|
69
|
+
* Feeds one scanned string. `progress` is the fountain decode ratio in [0, 1]; `payload` appears
|
|
70
|
+
* once complete. Frames of a type outside `scan`, duplicates and out-of-order parts leave the
|
|
71
|
+
* session unchanged; a fatal decoder failure throws `invalid-input`.
|
|
72
|
+
*/
|
|
73
|
+
readonly receive: (part: string) => {
|
|
74
|
+
readonly progress: number;
|
|
75
|
+
readonly payload?: QrPayload;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/** An incremental reader for the frames a device shows back; only `scan` types are admitted. */
|
|
79
|
+
export declare const qrReader: (scan: ReadonlyArray<string>) => QrReader;
|
|
80
|
+
export type { BlePort, DeviceDisplay, DeviceIo, DeviceRequest, DeviceResponse, HardwareDevice, HardwareOperation, HardwareResult, HardwareStep, HidPort, QrPayload };
|
|
81
|
+
//# sourceMappingURL=hardware.d.mts.map
|