@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
package/dist/host.mjs CHANGED
@@ -1,8 +1,238 @@
1
1
  import { WalletError } from "./types.mjs";
2
- import { t as Channel } from "./channel-BLwce5hh.mjs";
3
- import { n as registerInternals } from "./internal-CAKfHjIg.mjs";
4
- import { a as passkeyName, c as resolveBackupUnlockFactor, d as vaultSaltBytes, f as walletSaltBytes, h as wireSecretText, i as defaultUnlockFactor, l as resolveFactor, m as wirePassphrase, n as PASSKEY_PURPOSE_VAULT, o as requireCeremony, p as wireBytes, r as PASSKEY_PURPOSE_WALLET, s as resolveBackupFactor, t as SingleUseSecret, u as resolveInitialFactor } from "./secret-CcjyF8D3.mjs";
5
- import { base58, hex } from "@scure/base";
2
+ import { t as backupPasskeyCredentialIds } from "./backup-CLzMs8DP.mjs";
3
+ import { n as registerInternals } from "./internal-DwCus_Ws.mjs";
4
+ import { n as MAX_IN_FLIGHT, t as Channel } from "./channel-BCZXU3pt.mjs";
5
+ import { t as SingleUseSecret } from "./secret-CbjbY5-f.mjs";
6
+ import { base58, base64urlnopad, hex } from "@scure/base";
7
+ // src/factors.ts
8
+ /**
9
+ * Factor plumbing for the host connector: public `UnlockFactor`/`InitialFactor` inputs become wire
10
+ * `Factor` material, passkey material comes from the host's WebAuthn ceremony, and every secret
11
+ * byte travels in a fresh exact-size buffer on the transfer list.
12
+ */
13
+ /** Purpose bytes stamped into the first byte of a credential's WebAuthn user handle. */
14
+ const PASSKEY_PURPOSE_WALLET = 1;
15
+ const PASSKEY_PURPOSE_VAULT = 2;
16
+ function hardwareOnly() {
17
+ return new WalletError("unsupported", "this host unlocks only with the keystore factors");
18
+ }
19
+ function noHardware() {
20
+ return new WalletError("unsupported", "keystore factors exist only on React Native");
21
+ }
22
+ /** The factor `vault.unlock()` uses when the caller passes none. */
23
+ function defaultUnlockFactor(source) {
24
+ if (source.mode === "hardware") return source.appLock() ? { kind: "hardware" } : { kind: "device" };
25
+ return { kind: "passkey" };
26
+ }
27
+ function vaultSaltBytes(source) {
28
+ return new TextEncoder().encode(source.passkey.vaultSalt);
29
+ }
30
+ function walletSaltBytes(source) {
31
+ return new TextEncoder().encode(source.passkey.walletSalt);
32
+ }
33
+ function backupSaltBytes(source) {
34
+ return new TextEncoder().encode(source.passkey.backupSalt);
35
+ }
36
+ /**
37
+ * The host-run backup passkey ceremony (web): the PRF is evaluated over `backupSalt`, producing
38
+ * `prfBackup` instead of the vault `prf`. `credentialIds` scopes the assertion — sealing uses the
39
+ * vault's own credentials; opening uses the envelope's.
40
+ */
41
+ async function hostBackupPasskey(source, wire, credentialIds) {
42
+ const result = await requireCeremony(source).assert({
43
+ credentialIds: credentialIds ?? passkeyCredentialIds(source),
44
+ salts: { first: backupSaltBytes(source) }
45
+ });
46
+ return {
47
+ kind: "passkey",
48
+ ceremony: "host",
49
+ credentialId: wire.bytes(result.credentialId),
50
+ prfBackup: wire.bytes(result.first, true)
51
+ };
52
+ }
53
+ /**
54
+ * Resolves a public `BackupFactorInput` password arm. On a hardware host (React Native) the kernel
55
+ * collects the password through its secure input — a supplied string is refused so the main runtime
56
+ * never holds it, an absent one resolves to the `kernel` ceremony arm. On a software host the wire
57
+ * carries the bytes and the string is required.
58
+ */
59
+ function backupPassword(source, factor, wire) {
60
+ if (source.mode === "hardware") {
61
+ if (factor.password !== void 0) throw new WalletError("unsupported", "on React Native the kernel collects the backup password itself");
62
+ return {
63
+ kind: "password",
64
+ ceremony: "kernel"
65
+ };
66
+ }
67
+ if (factor.password === void 0) throw new WalletError("invalid-input", "backup password factors need a password");
68
+ return {
69
+ kind: "password",
70
+ password: wire.text(factor.password)
71
+ };
72
+ }
73
+ /**
74
+ * Resolves a public `BackupFactorInput` to a factor that seals a new backup key. A hardware host
75
+ * lets the kernel register the protection credential itself; nothing secret crosses the channel.
76
+ */
77
+ async function resolveBackupFactor(source, factor, wire) {
78
+ if (factor.kind === "password") return backupPassword(source, factor, wire);
79
+ if (source.mode === "hardware") return {
80
+ kind: "passkey",
81
+ ceremony: "kernel",
82
+ rpId: source.passkey.rpId,
83
+ rpName: source.passkey.rpName,
84
+ backupSalt: source.passkey.backupSalt
85
+ };
86
+ return hostBackupPasskey(source, wire);
87
+ }
88
+ /**
89
+ * Resolves a public `UnlockFactor` to a factor that opens a backup envelope. `credentialIds` is the
90
+ * envelope's own allow-list — a restored vault's passkey credentials are a different set (a fresh
91
+ * vault has none).
92
+ */
93
+ async function resolveBackupUnlockFactor(source, factor, wire, credentialIds) {
94
+ if (factor.kind === "password") return backupPassword(source, factor, wire);
95
+ if (source.mode === "hardware") return {
96
+ kind: "passkey",
97
+ ceremony: "kernel",
98
+ rpId: source.passkey.rpId,
99
+ backupSalt: source.passkey.backupSalt
100
+ };
101
+ return hostBackupPasskey(source, wire, credentialIds);
102
+ }
103
+ /** Passkey credential ids of the current vault factors, for `assert`'s allowCredentials. */
104
+ function passkeyCredentialIds(source) {
105
+ return source.factors().flatMap((factor) => factor.kind === "passkey" ? [base64urlnopad.decode(factor.credentialId)] : []);
106
+ }
107
+ /**
108
+ * The secret buffers of one request. Every byte array that carries a secret to the kernel is placed
109
+ * here in a fresh exact-size buffer (transferring must never detach caller-owned memory, and a
110
+ * secret source is zeroed once copied); the channel either moves the whole set on the post's
111
+ * transfer list or calls `wipe()`. A wire is never half-detached and never left resident.
112
+ */
113
+ var SecretWire = class {
114
+ buffers = [];
115
+ wiped = false;
116
+ /**
117
+ * A wire copy of `source`; `wipeSource` zeroes a secret original after copying. Once the wire is
118
+ * wiped its request is over, so a late copy (a ceremony that settled after the build failed) is
119
+ * zeroed at once instead of staying resident with nothing left to wipe it.
120
+ */
121
+ bytes(source, wipeSource = false) {
122
+ const wire = new Uint8Array(source);
123
+ if (wipeSource) source.fill(0);
124
+ if (this.wiped) {
125
+ wire.fill(0);
126
+ return wire;
127
+ }
128
+ this.buffers.push(wire.buffer);
129
+ return wire;
130
+ }
131
+ /** A wire copy of a secret string (passwords, mnemonics, passphrases). */
132
+ text(text) {
133
+ return this.bytes(new TextEncoder().encode(text));
134
+ }
135
+ /** The `passphrase` wire field for a BIP-39 passphrase: absent for none (undefined or ""). */
136
+ passphrase(text) {
137
+ return text === void 0 || text === "" ? {} : { passphrase: this.text(text) };
138
+ }
139
+ /** Every buffer this wire recorded — the post's transfer list. */
140
+ get transfer() {
141
+ return this.buffers;
142
+ }
143
+ /** Zeroes every recorded buffer still attached — already-transferred ones are gone. */
144
+ wipe() {
145
+ this.wiped = true;
146
+ for (const buffer of this.buffers) if (buffer.byteLength > 0) new Uint8Array(buffer).fill(0);
147
+ }
148
+ };
149
+ function requireCeremony(source) {
150
+ if (source.ceremony === void 0) throw new WalletError("unsupported", "no passkey ceremony is configured");
151
+ return source.ceremony;
152
+ }
153
+ /** A passkey credential's display name: trimmed, 1–64 UTF-16 code units, else invalid-input. */
154
+ function passkeyName(name) {
155
+ const trimmed = name.trim();
156
+ if (trimmed.length === 0 || trimmed.length > 64) throw new WalletError("invalid-input", "the passkey name must be 1–64 characters");
157
+ return trimmed;
158
+ }
159
+ /**
160
+ * Resolves a public `UnlockFactor` to wire factor material. `wire` collects every buffer the port
161
+ * must move. Ceremony errors surface as they are (cancelled / passkey-prf-unsupported).
162
+ */
163
+ async function resolveFactor(source, factor, wire) {
164
+ if (source.mode === "hardware") {
165
+ if (factor.kind !== "device" && factor.kind !== "hardware") throw hardwareOnly();
166
+ return { kind: factor.kind };
167
+ }
168
+ if (factor.kind === "hardware" || factor.kind === "device") throw noHardware();
169
+ if (factor.kind === "password") return {
170
+ kind: "password",
171
+ password: wire.text(factor.password)
172
+ };
173
+ const result = await requireCeremony(source).assert({
174
+ credentialIds: passkeyCredentialIds(source),
175
+ salts: { first: vaultSaltBytes(source) }
176
+ });
177
+ return {
178
+ kind: "passkey",
179
+ credentialId: wire.bytes(result.credentialId),
180
+ prf: wire.bytes(result.first, true)
181
+ };
182
+ }
183
+ /**
184
+ * The fail-closed gate on every verify parameter: a `device` factor proves no presence, so it can
185
+ * never verify — rejected here before any ceremony, and again by the wire validator and the
186
+ * kernel's `verifyFactor`.
187
+ */
188
+ async function resolveVerifyFactor(source, factor, wire) {
189
+ if (factor.kind === "device") throw new WalletError("invalid-input", "the device factor cannot verify");
190
+ return await resolveFactor(source, factor, wire);
191
+ }
192
+ /**
193
+ * Resolves a public `InitialFactor` (a factor being created). For `create/restoreWithPasskey` the
194
+ * default passkey factor reuses the wallet ceremony's own credential and `second` PRF output; a
195
+ * hardware host chooses its own vault factors (the wire `device` marker lets the kernel build the
196
+ * device + hardware set) and drops that output.
197
+ */
198
+ async function resolveInitialFactor(source, factor, wire, walletCeremony) {
199
+ if (source.mode === "hardware") {
200
+ walletCeremony?.second?.fill(0);
201
+ if (factor !== void 0) throw new WalletError("unsupported", "this host chooses its own vault factors");
202
+ return { kind: "device" };
203
+ }
204
+ if (factor === void 0 || factor.kind === "passkey") {
205
+ const name = factor === void 0 ? void 0 : passkeyName(factor.name);
206
+ if (walletCeremony !== void 0) {
207
+ const { second } = walletCeremony;
208
+ if (second === void 0) throw new WalletError("passkey-prf-unsupported", "the ceremony returned no vault PRF output");
209
+ return {
210
+ kind: "passkey",
211
+ credentialId: wire.bytes(walletCeremony.credentialId),
212
+ prf: wire.bytes(second, true)
213
+ };
214
+ }
215
+ if (name === void 0) throw new WalletError("invalid-input", "a passkey factor requires a name");
216
+ const result = await requireCeremony(source).create({
217
+ purpose: "vault",
218
+ name,
219
+ salts: { first: vaultSaltBytes(source) }
220
+ });
221
+ return {
222
+ kind: "passkey",
223
+ credentialId: wire.bytes(result.credentialId),
224
+ prf: wire.bytes(result.first, true)
225
+ };
226
+ }
227
+ if (factor.kind === "password") {
228
+ walletCeremony?.second?.fill(0);
229
+ return {
230
+ kind: "password",
231
+ password: wire.text(factor.password)
232
+ };
233
+ }
234
+ throw noHardware();
235
+ }
6
236
  // src/wallet.ts
7
237
  /**
8
238
  * The host-facing `Wallet` (design/entry.mdx "API"): snapshot state, the core API groups, and the
@@ -48,11 +278,14 @@ var KernelWallet = class KernelWallet {
48
278
  vault: "uninitialized",
49
279
  lockReason: void 0,
50
280
  verifying: false,
281
+ appLock: false,
282
+ verification: "unavailable",
51
283
  factors: [],
52
284
  wallets: [],
53
285
  nostr: { keys: [] },
54
286
  importedKeys: [],
55
- backup: null
287
+ backup: null,
288
+ blindSigning: false
56
289
  };
57
290
  this.channel = new Channel(options.spawn, {
58
291
  onStatus: (status) => {
@@ -71,16 +304,13 @@ var KernelWallet = class KernelWallet {
71
304
  this.onPresence();
72
305
  });
73
306
  registerInternals(this, {
74
- call: async (method, params, transfer) => this.channel.call(method, params, transfer),
307
+ call: async (method, params) => this.channel.call(method, params),
308
+ secretCall: async (method, build) => this.secretCall(method, build),
75
309
  ready: async () => this.channel.ready,
76
310
  snapshot: () => this.snapshotValue,
77
311
  verifyEvent: options.verifyEvent,
78
312
  withVerifying: async (fn) => this.withVerifying(fn),
79
- resolveFactor: async (factor, transfer) => resolveFactor(this.factorSource, factor, transfer),
80
- createFactorParam: async (factor, transfer) => this.createFactorParam(factor, transfer),
81
- sessionOf: (result) => {
82
- this.sessionOf(result);
83
- }
313
+ resolveVerifyFactor: async (factor, wire) => resolveVerifyFactor(this.factorSource, factor, wire)
84
314
  });
85
315
  }
86
316
  static async connect(options) {
@@ -88,17 +318,30 @@ var KernelWallet = class KernelWallet {
88
318
  await wallet.channel.start();
89
319
  return wallet;
90
320
  }
91
- /** Runs a host-ceremony passkey call and adopts the returned session and wallet info. */
92
- async hostPasskeyWallet(method, result, factor, transfer) {
93
- const created = await this.channel.call(method, {
321
+ /**
322
+ * One request whose params carry secret bytes: `build` places them on a fresh wire, a build
323
+ * failure wipes it, and the channel either transfers it or wipes it from there.
324
+ */
325
+ async secretCall(method, build) {
326
+ const wire = new SecretWire();
327
+ let params;
328
+ try {
329
+ params = await build(wire);
330
+ } catch (error) {
331
+ wire.wipe();
332
+ throw error;
333
+ }
334
+ return this.channel.callWithSecrets(method, params, wire);
335
+ }
336
+ /** The host-ceremony arm of a create/restoreWithPasskey request, with `result` on the wire. */
337
+ hostPasskeyParams(wire, result, factor) {
338
+ return {
94
339
  ceremony: "host",
95
- credentialId: wireBytes(result.credentialId, transfer),
96
- prfWallet: wireBytes(result.first, transfer, true),
340
+ credentialId: wire.bytes(result.credentialId),
341
+ prfWallet: wire.bytes(result.first, true),
97
342
  synced: result.synced,
98
343
  ...factor === void 0 ? {} : { factor }
99
- }, transfer);
100
- this.sessionOf(created);
101
- return created.wallet;
344
+ };
102
345
  }
103
346
  /**
104
347
  * Presence refresh, throttled to one touch per interval: once a touch fires, signals are ignored
@@ -146,14 +389,17 @@ var KernelWallet = class KernelWallet {
146
389
  vault: status === void 0 ? "uninitialized" : status.vault,
147
390
  lockReason: this.lockReason,
148
391
  verifying: this.verifying > 0,
392
+ appLock: status === void 0 ? false : status.appLock,
393
+ verification: status === void 0 ? "unavailable" : status.verification,
149
394
  factors: status === void 0 ? [] : status.factors,
150
395
  wallets: status === void 0 ? [] : status.wallets,
151
396
  nostr: { keys: status === void 0 ? [] : status.nostr.keys },
152
397
  importedKeys: status === void 0 ? [] : status.importedKeys,
153
- backup: status === void 0 ? null : status.backup
398
+ backup: status === void 0 ? null : status.backup,
399
+ blindSigning: status === void 0 ? false : status.blindSigning
154
400
  };
155
401
  const current = this.snapshotValue;
156
- if (current.vault === next.vault && current.lockReason === next.lockReason && current.verifying === next.verifying && deepEqual(current.factors, next.factors) && deepEqual(current.wallets, next.wallets) && deepEqual(current.nostr, next.nostr) && deepEqual(current.importedKeys, next.importedKeys) && deepEqual(current.backup, next.backup)) return;
402
+ if (current.vault === next.vault && current.lockReason === next.lockReason && current.verifying === next.verifying && current.appLock === next.appLock && current.verification === next.verification && deepEqual(current.factors, next.factors) && deepEqual(current.wallets, next.wallets) && deepEqual(current.nostr, next.nostr) && deepEqual(current.importedKeys, next.importedKeys) && deepEqual(current.backup, next.backup) && current.blindSigning === next.blindSigning) return;
157
403
  this.snapshotValue = next;
158
404
  for (const listener of this.listeners) listener();
159
405
  }
@@ -169,7 +415,8 @@ var KernelWallet = class KernelWallet {
169
415
  mode: this.factorMode,
170
416
  passkey: this.passkeyCfg,
171
417
  ceremony: this.ceremony,
172
- factors: () => this.snapshotValue.factors
418
+ factors: () => this.snapshotValue.factors,
419
+ appLock: () => this.snapshotValue.appLock
173
420
  };
174
421
  }
175
422
  /** True while a ceremony or a factor-bearing request is in flight; drives `verifying`. */
@@ -186,46 +433,67 @@ var KernelWallet = class KernelWallet {
186
433
  initialized() {
187
434
  return this.snapshotValue.vault !== "uninitialized";
188
435
  }
436
+ /**
437
+ * Locally decidable rejections for a software host's create/restore factor. Runs before the
438
+ * WebAuthn ceremony so a doomed call never prompts — and again inside the request build, because
439
+ * the vault may have initialized while the ceremony was pending.
440
+ */
441
+ checkSoftwareFactor(factor) {
442
+ if (factor === void 0) return;
443
+ if (this.initialized()) throw new WalletError("invalid-input", "the vault is already initialized");
444
+ if (factor.kind !== "passkey" && factor.kind !== "password") throw noHardware();
445
+ if (factor.kind === "passkey") passkeyName(factor.name);
446
+ }
189
447
  /** The factor gate on create/import commands; keeps useless ceremonies from firing. */
190
- async createFactorParam(factor, transfer) {
448
+ async createFactorParam(factor, wire) {
191
449
  if (this.initialized()) {
192
450
  if (factor !== void 0) throw new WalletError("invalid-input", "the vault is already initialized");
193
451
  return;
194
452
  }
195
453
  if (factor === void 0 && this.factorMode === "software") throw new WalletError("invalid-input", "an initial factor is required");
196
- return resolveInitialFactor(this.factorSource, factor, transfer);
454
+ return resolveInitialFactor(this.factorSource, factor, wire);
197
455
  }
198
456
  sessionOf(result) {
199
457
  this.channel.session = result.session;
200
458
  this.channel.flushStatus();
201
459
  }
202
460
  vault = {
203
- unlock: async (factor) => this.withVerifying(async () => {
204
- const transfer = [];
205
- const wire = await resolveFactor(this.factorSource, factor ?? defaultUnlockFactor(this.factorSource), transfer);
206
- const result = await this.channel.call("vault.unlock", { factor: wire }, transfer);
207
- this.sessionOf(result);
208
- }),
461
+ unlock: async (factor) => {
462
+ const resolved = factor ?? defaultUnlockFactor(this.factorSource);
463
+ const run = async () => {
464
+ const result = await this.secretCall("vault.unlock", async (wire) => ({ factor: await resolveFactor(this.factorSource, resolved, wire) }));
465
+ this.sessionOf(result);
466
+ };
467
+ await (resolved.kind === "device" ? run() : this.withVerifying(run));
468
+ },
209
469
  lock: async () => {
210
470
  this.channel.lockNow();
211
471
  this.markLocked();
212
472
  },
213
- addFactor: async (factor, verify) => this.withVerifying(async () => {
214
- const transfer = [];
215
- const wireVerify = await resolveFactor(this.factorSource, verify, transfer);
216
- const wireFactor = await resolveInitialFactor(this.factorSource, factor, transfer);
217
- return this.channel.call("vault.addFactor", {
218
- verify: wireVerify,
219
- factor: wireFactor
220
- }, transfer);
221
- }),
473
+ addFactor: async (factor, verify) => this.withVerifying(async () => this.secretCall("vault.addFactor", async (wire) => ({
474
+ verify: await resolveVerifyFactor(this.factorSource, verify, wire),
475
+ factor: await resolveInitialFactor(this.factorSource, factor, wire)
476
+ }))),
222
477
  removeFactor: async (id, verify) => this.withVerifying(async () => {
223
- const transfer = [];
224
- const wireVerify = await resolveFactor(this.factorSource, verify, transfer);
225
- await this.channel.call("vault.removeFactor", {
226
- verify: wireVerify,
478
+ await this.secretCall("vault.removeFactor", async (wire) => ({
479
+ verify: await resolveVerifyFactor(this.factorSource, verify, wire),
227
480
  id
228
- }, transfer);
481
+ }));
482
+ }),
483
+ enrolVerification: async () => this.withVerifying(async () => {
484
+ await this.channel.call("vault.enrolVerification", null);
485
+ }),
486
+ setAppLock: async (enabled, verify) => this.withVerifying(async () => {
487
+ await this.secretCall("vault.setAppLock", async (wire) => ({
488
+ enabled,
489
+ verify: await resolveVerifyFactor(this.factorSource, verify, wire)
490
+ }));
491
+ }),
492
+ setBlindSigning: async (enabled, verify) => this.withVerifying(async () => {
493
+ await this.secretCall("vault.setBlindSigning", async (wire) => ({
494
+ enabled,
495
+ verify: await resolveVerifyFactor(this.factorSource, verify, wire)
496
+ }));
229
497
  }),
230
498
  reset: async () => {
231
499
  await this.channel.call("vault.reset", null);
@@ -233,116 +501,121 @@ var KernelWallet = class KernelWallet {
233
501
  };
234
502
  keys = {
235
503
  import: async (family, secret) => this.withVerifying(async () => {
236
- const transfer = [];
237
504
  const decoded = decodeKeySecret(family, secret);
238
505
  try {
239
- return await this.channel.call("keys.import", {
506
+ return await this.secretCall("keys.import", (wire) => ({
240
507
  family,
241
- secret: wireBytes(decoded, transfer)
242
- }, transfer);
508
+ secret: wire.bytes(decoded)
509
+ }));
243
510
  } finally {
244
511
  if (decoded !== secret) decoded.fill(0);
245
512
  }
246
513
  }),
247
- list: async () => this.channel.call("keys.list", null, []),
514
+ list: async () => this.channel.call("keys.list", null),
248
515
  remove: async (keyId, verify) => this.withVerifying(async () => {
249
- const transfer = [];
250
- const wireVerify = await resolveFactor(this.factorSource, verify, transfer);
251
- await this.channel.call("keys.remove", {
252
- verify: wireVerify,
516
+ await this.secretCall("keys.remove", async (wire) => ({
517
+ verify: await resolveVerifyFactor(this.factorSource, verify, wire),
253
518
  keyId
254
- }, transfer);
519
+ }));
255
520
  }),
256
- export: async (keyId, verify) => this.withVerifying(async () => {
257
- const transfer = [];
258
- const wireVerify = await resolveFactor(this.factorSource, verify, transfer);
259
- return this.channel.call("keys.export", {
260
- verify: wireVerify,
261
- keyId
262
- }, transfer);
263
- })
521
+ export: async (keyId, verify) => this.withVerifying(async () => this.secretCall("keys.export", async (wire) => ({
522
+ verify: await resolveVerifyFactor(this.factorSource, verify, wire),
523
+ keyId
524
+ })))
264
525
  };
265
526
  wallets = {
266
527
  createWithPasskey: async (options) => this.withVerifying(async () => {
267
528
  const name = passkeyName(options.name);
268
- const transfer = [];
269
529
  if (this.factorMode === "hardware") {
270
- const factor = await this.createFactorParam(options.factor, transfer);
271
- const created = await this.channel.call("wallet.createWithPasskey", {
272
- ceremony: "kernel",
273
- rpId: this.passkeyCfg.rpId,
274
- rpName: this.passkeyCfg.rpName,
275
- name,
276
- walletSalt: this.passkeyCfg.walletSalt,
277
- ...factor === void 0 ? {} : { factor }
278
- }, transfer);
530
+ const created = await this.secretCall("wallet.createWithPasskey", async (wire) => {
531
+ const factor = await this.createFactorParam(options.factor, wire);
532
+ return {
533
+ ceremony: "kernel",
534
+ rpId: this.passkeyCfg.rpId,
535
+ rpName: this.passkeyCfg.rpName,
536
+ name,
537
+ walletSalt: this.passkeyCfg.walletSalt,
538
+ ...factor === void 0 ? {} : { factor }
539
+ };
540
+ });
279
541
  this.sessionOf(created);
280
542
  return created.wallet;
281
543
  }
282
- const result = await requireCeremony(this.factorSource).create({
283
- purpose: "wallet",
284
- name,
285
- salts: {
286
- first: walletSaltBytes(this.factorSource),
287
- second: vaultSaltBytes(this.factorSource)
544
+ this.checkSoftwareFactor(options.factor);
545
+ const ceremony = requireCeremony(this.factorSource);
546
+ const created = await this.secretCall("wallet.createWithPasskey", async (wire) => {
547
+ const result = await ceremony.create({
548
+ purpose: "wallet",
549
+ name,
550
+ salts: {
551
+ first: walletSaltBytes(this.factorSource),
552
+ second: vaultSaltBytes(this.factorSource)
553
+ }
554
+ });
555
+ try {
556
+ this.checkSoftwareFactor(options.factor);
557
+ const factor = this.initialized() ? void 0 : await resolveInitialFactor(this.factorSource, options.factor, wire, result);
558
+ return this.hostPasskeyParams(wire, result, factor);
559
+ } finally {
560
+ result.first.fill(0);
561
+ result.second?.fill(0);
288
562
  }
289
563
  });
290
- let factor;
291
- if (this.initialized()) {
292
- if (options.factor !== void 0) throw new WalletError("invalid-input", "the vault is already initialized");
293
- result.second?.fill(0);
294
- } else factor = await resolveInitialFactor(this.factorSource, options.factor, transfer, result);
295
- return this.hostPasskeyWallet("wallet.createWithPasskey", result, factor, transfer);
564
+ this.sessionOf(created);
565
+ return created.wallet;
296
566
  }),
297
567
  restoreWithPasskey: async (options) => this.withVerifying(async () => {
298
- const transfer = [];
299
568
  if (this.factorMode === "hardware") {
300
- const factor = await this.createFactorParam(options?.factor, transfer);
301
- const created = await this.channel.call("wallet.restoreWithPasskey", {
302
- ceremony: "kernel",
303
- rpId: this.passkeyCfg.rpId,
304
- walletSalt: this.passkeyCfg.walletSalt,
305
- ...factor === void 0 ? {} : { factor }
306
- }, transfer);
569
+ const created = await this.secretCall("wallet.restoreWithPasskey", async (wire) => {
570
+ const factor = await this.createFactorParam(options?.factor, wire);
571
+ return {
572
+ ceremony: "kernel",
573
+ rpId: this.passkeyCfg.rpId,
574
+ walletSalt: this.passkeyCfg.walletSalt,
575
+ ...factor === void 0 ? {} : { factor }
576
+ };
577
+ });
307
578
  this.sessionOf(created);
308
579
  return created.wallet;
309
580
  }
310
- const result = await requireCeremony(this.factorSource).assert({ salts: {
311
- first: walletSaltBytes(this.factorSource),
312
- second: vaultSaltBytes(this.factorSource)
313
- } });
314
- if (result.userHandle?.[0] !== 1) {
315
- result.first.fill(0);
316
- result.second?.fill(0);
317
- throw new WalletError("wrong-passkey", "the passkey is not a wallet credential");
318
- }
319
- let factor;
320
- if (this.initialized()) {
321
- if (options?.factor !== void 0) throw new WalletError("invalid-input", "the vault is already initialized");
322
- result.second?.fill(0);
323
- } else factor = await resolveInitialFactor(this.factorSource, options?.factor, transfer, result);
324
- return this.hostPasskeyWallet("wallet.restoreWithPasskey", result, factor, transfer);
581
+ this.checkSoftwareFactor(options?.factor);
582
+ const ceremony = requireCeremony(this.factorSource);
583
+ const created = await this.secretCall("wallet.restoreWithPasskey", async (wire) => {
584
+ const result = await ceremony.assert({ salts: {
585
+ first: walletSaltBytes(this.factorSource),
586
+ second: vaultSaltBytes(this.factorSource)
587
+ } });
588
+ try {
589
+ if (result.userHandle?.[0] !== 1) throw new WalletError("wrong-passkey", "the passkey is not a wallet credential");
590
+ this.checkSoftwareFactor(options?.factor);
591
+ const factor = this.initialized() ? void 0 : await resolveInitialFactor(this.factorSource, options?.factor, wire, result);
592
+ return this.hostPasskeyParams(wire, result, factor);
593
+ } finally {
594
+ result.first.fill(0);
595
+ result.second?.fill(0);
596
+ }
597
+ });
598
+ this.sessionOf(created);
599
+ return created.wallet;
325
600
  }),
326
601
  createMnemonic: async (options) => {
327
- const transfer = [];
328
- const factor = await this.createFactorParam(options.factor, transfer);
329
- const created = await this.channel.call("wallet.createMnemonic", {
330
- words: options.words,
331
- ...factor === void 0 ? {} : { factor }
332
- }, transfer);
602
+ const created = await this.secretCall("wallet.createMnemonic", async (wire) => {
603
+ const factor = await this.createFactorParam(options.factor, wire);
604
+ return {
605
+ words: options.words,
606
+ ...factor === void 0 ? {} : { factor }
607
+ };
608
+ });
333
609
  const draftId = created.draft;
334
610
  return {
335
611
  words: new SingleUseSecret(created.words),
336
612
  quiz: created.quiz,
337
613
  confirm: async (answers, confirmOptions) => {
338
- const answerTransfer = [];
339
- const encoded = answers.map((word) => wireSecretText(word, answerTransfer));
340
- const passphrase = wirePassphrase(confirmOptions?.passphrase, answerTransfer);
341
- const confirmed = await this.channel.call("wallet.confirmMnemonic", {
614
+ const confirmed = await this.secretCall("wallet.confirmMnemonic", (wire) => ({
342
615
  draft: draftId,
343
- answers: encoded,
344
- ...passphrase
345
- }, answerTransfer);
616
+ answers: answers.map((word) => wire.text(word)),
617
+ ...wire.passphrase(confirmOptions?.passphrase)
618
+ }));
346
619
  this.sessionOf(confirmed);
347
620
  return confirmed.wallet;
348
621
  },
@@ -352,70 +625,68 @@ var KernelWallet = class KernelWallet {
352
625
  };
353
626
  },
354
627
  importMnemonic: async (options) => {
355
- const transfer = [];
356
- const factor = await this.createFactorParam(options.factor, transfer);
357
- const mnemonic = wireSecretText(options.mnemonic, transfer);
358
- const passphrase = wirePassphrase(options.passphrase, transfer);
359
- const created = await this.channel.call("wallet.importMnemonic", {
360
- mnemonic,
361
- ...passphrase,
362
- ...factor === void 0 ? {} : { factor }
363
- }, transfer);
628
+ const created = await this.secretCall("wallet.importMnemonic", async (wire) => {
629
+ const factor = await this.createFactorParam(options.factor, wire);
630
+ return {
631
+ mnemonic: wire.text(options.mnemonic),
632
+ ...wire.passphrase(options.passphrase),
633
+ ...factor === void 0 ? {} : { factor }
634
+ };
635
+ });
364
636
  this.sessionOf(created);
365
637
  return created.wallet;
366
638
  },
367
639
  exportMnemonic: async (walletId, verify) => this.withVerifying(async () => {
368
- const transfer = [];
369
- const wireVerify = await resolveFactor(this.factorSource, verify, transfer);
370
- const exported = await this.channel.call("wallet.exportMnemonic", {
371
- verify: wireVerify,
640
+ const exported = await this.secretCall("wallet.exportMnemonic", async (wire) => ({
641
+ verify: await resolveVerifyFactor(this.factorSource, verify, wire),
372
642
  walletId
373
- }, transfer);
643
+ }));
374
644
  return {
375
645
  mnemonic: new SingleUseSecret(exported.mnemonic),
376
646
  ...exported.passphrase === void 0 ? {} : { passphrase: new SingleUseSecret(exported.passphrase) }
377
647
  };
378
648
  }),
379
649
  delete: async (walletId, verify) => this.withVerifying(async () => {
380
- const transfer = [];
381
- const wireVerify = await resolveFactor(this.factorSource, verify, transfer);
382
- await this.channel.call("wallet.delete", {
383
- verify: wireVerify,
650
+ await this.secretCall("wallet.delete", async (wire) => ({
651
+ verify: await resolveVerifyFactor(this.factorSource, verify, wire),
384
652
  walletId
385
- }, transfer);
653
+ }));
386
654
  })
387
655
  };
388
656
  dataKeys = { get: async (purpose) => this.channel.call("dataKeys.get", { purpose }) };
389
657
  backup = {
390
658
  enable: async (options) => this.withVerifying(async () => {
391
- const transfer = [];
392
- const wireVerify = await resolveFactor(this.factorSource, options.verify, transfer);
393
- const wireFactors = await Promise.all(options.factors.map(async (factor) => resolveBackupFactor(this.factorSource, factor, transfer)));
394
- await this.channel.call("backup.enable", {
395
- verify: wireVerify,
396
- factors: wireFactors
397
- }, transfer);
659
+ await this.secretCall("backup.enable", async (wire) => {
660
+ const verify = await resolveVerifyFactor(this.factorSource, options.verify, wire);
661
+ const factors = [];
662
+ for (const factor of options.factors) factors.push(await resolveBackupFactor(this.factorSource, factor, wire));
663
+ return {
664
+ verify,
665
+ factors
666
+ };
667
+ });
398
668
  }),
399
669
  update: async () => {
400
670
  return (await this.channel.call("backup.update", null)).envelope;
401
671
  },
402
- disable: async () => {
403
- await this.channel.call("backup.disable", null);
404
- },
672
+ disable: async (verify) => this.withVerifying(async () => {
673
+ await this.secretCall("backup.disable", async (wire) => ({ verify: await resolveVerifyFactor(this.factorSource, verify, wire) }));
674
+ }),
405
675
  restore: async (options) => this.withVerifying(async () => {
406
- const transfer = [];
407
- const backupFactor = await resolveBackupUnlockFactor(this.factorSource, options.backupFactor, transfer);
408
- const factor = await this.createFactorParam(options.factor, transfer);
409
- const passphrases = options.passphrases?.map(({ walletId, passphrase }) => ({
410
- walletId,
411
- passphrase: wireSecretText(passphrase, transfer)
412
- }));
413
- const result = await this.channel.call("backup.restore", {
414
- envelope: options.envelope,
415
- backupFactor,
416
- ...passphrases === void 0 ? {} : { passphrases },
417
- ...factor === void 0 ? {} : { factor }
418
- }, transfer);
676
+ const result = await this.secretCall("backup.restore", async (wire) => {
677
+ const backupFactor = await resolveBackupUnlockFactor(this.factorSource, options.backupFactor, wire, options.backupFactor.kind === "passkey" ? backupPasskeyCredentialIds(options.envelope) : void 0);
678
+ const factor = await this.createFactorParam(options.factor, wire);
679
+ const passphrases = options.passphrases?.map(({ walletId, passphrase }) => ({
680
+ walletId,
681
+ passphrase: wire.text(passphrase)
682
+ }));
683
+ return {
684
+ envelope: options.envelope,
685
+ backupFactor,
686
+ ...passphrases === void 0 ? {} : { passphrases },
687
+ ...factor === void 0 ? {} : { factor }
688
+ };
689
+ });
419
690
  this.sessionOf(result);
420
691
  return {
421
692
  wallets: result.wallets,
@@ -434,7 +705,8 @@ var KernelWallet = class KernelWallet {
434
705
  };
435
706
  /**
436
707
  * `keys.import`'s `secret` in bytes: a string is the family's canonical text encoding — `0x` hex
437
- * for EVM, base58 for Solana — while a Uint8Array passes straight through to the kernel's checks.
708
+ * for EVM, base58 for Solana, bare hex for TRON — while a Uint8Array passes straight through to the
709
+ * kernel's checks.
438
710
  */
439
711
  function decodeKeySecret(family, secret) {
440
712
  if (secret instanceof Uint8Array) return secret;
@@ -447,6 +719,10 @@ function decodeKeySecret(family, secret) {
447
719
  } catch {
448
720
  throw new WalletError("invalid-input", "a Solana private key is base58");
449
721
  }
722
+ if (family === "tron") {
723
+ if (!/^[0-9a-fA-F]{64}$/.test(secret)) throw new WalletError("invalid-input", "a TRON private key is 64-hex without 0x");
724
+ return hex.decode(secret);
725
+ }
450
726
  throw new WalletError("invalid-input", `keys are not supported on ${family}`);
451
727
  }
452
728
  /**
@@ -466,6 +742,6 @@ async function connectKernel(options) {
466
742
  checkPasskeyConfig(options.passkey);
467
743
  return KernelWallet.connect(options);
468
744
  }
469
- export { PASSKEY_PURPOSE_VAULT, PASSKEY_PURPOSE_WALLET, connectKernel };
745
+ export { MAX_IN_FLIGHT, PASSKEY_PURPOSE_VAULT, PASSKEY_PURPOSE_WALLET, connectKernel };
470
746
 
471
747
  //# sourceMappingURL=host.mjs.map