@qntx/wallet 0.2.0 → 0.3.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 +43 -4
- package/dist/{protocol-D9_0sY_Y.mjs → core-QJ66nLLG.mjs} +91 -228
- package/dist/core-QJ66nLLG.mjs.map +1 -0
- package/dist/host.d.mts +19 -3
- package/dist/host.mjs +101 -11
- package/dist/host.mjs.map +1 -1
- package/dist/index-Dhf6wGjQ.d.mts +668 -0
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +35 -1
- package/dist/index.mjs.map +1 -0
- package/dist/internal-LBHal13j.mjs +25 -0
- package/dist/internal-LBHal13j.mjs.map +1 -0
- package/dist/nostr.d.mts +2 -2
- package/dist/nostr.mjs +13 -5
- package/dist/nostr.mjs.map +1 -1
- package/dist/protocol-D9xBuMzq.mjs +697 -0
- package/dist/protocol-D9xBuMzq.mjs.map +1 -0
- package/dist/protocol.d.mts +3 -3
- package/dist/protocol.mjs +3 -2
- package/dist/{secret-B-P3QOym.mjs → secret-IcTjjaX0.mjs} +113 -31
- package/dist/secret-IcTjjaX0.mjs.map +1 -0
- package/dist/spark.d.mts +30 -0
- package/dist/spark.mjs +303 -0
- package/dist/spark.mjs.map +1 -0
- package/dist/{types-CEy7At1l.d.mts → types-D4OUjGVS.d.mts} +62 -8
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs.map +1 -1
- package/package.json +16 -5
- package/dist/index-BJfyIwOZ.d.mts +0 -286
- package/dist/protocol-D9_0sY_Y.mjs.map +0 -1
- package/dist/secret-B-P3QOym.mjs.map +0 -1
package/dist/host.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WalletError } from "./types.mjs";
|
|
2
|
-
import { a as requireCeremony, c as
|
|
2
|
+
import { a as requireCeremony, c as resolveInitialFactor, d as wireBytes, f as wireSecretText, i as passkeyName, l as vaultSaltBytes, n as PASSKEY_PURPOSE_VAULT, o as resolveBackupFactor, p as Channel, r as PASSKEY_PURPOSE_WALLET, s as resolveFactor, t as SingleUseSecret, u as walletSaltBytes } from "./secret-IcTjjaX0.mjs";
|
|
3
|
+
import { n as registerInternals } from "./internal-LBHal13j.mjs";
|
|
3
4
|
//#region src/wallet.ts
|
|
4
5
|
/**
|
|
5
6
|
* The host-facing `Wallet` (design/entry.mdx "API"): snapshot state, the core API groups, and the
|
|
@@ -8,6 +9,8 @@ import { a as requireCeremony, c as vaultSaltBytes, d as wireSecretText, f as Ch
|
|
|
8
9
|
* (@qntx/wallet/nostr and future siblings) reach this wallet's channel through the registered
|
|
9
10
|
* internals in internal.ts — never through the public type.
|
|
10
11
|
*/
|
|
12
|
+
/** One `session.touch` at most per interval — the idle deadline slips at most this much early. */
|
|
13
|
+
const PRESENCE_TOUCH_INTERVAL_MS = 3e4;
|
|
11
14
|
/** Structural equality over plain snapshot data (validated protocol payloads only). */
|
|
12
15
|
function deepEqual(a, b) {
|
|
13
16
|
if (a === b) return true;
|
|
@@ -21,7 +24,11 @@ var KernelWallet = class KernelWallet {
|
|
|
21
24
|
channel;
|
|
22
25
|
passkeyCfg;
|
|
23
26
|
ceremony;
|
|
27
|
+
setTimer;
|
|
24
28
|
onDestroy;
|
|
29
|
+
unsubscribePresence;
|
|
30
|
+
presenceCooling = false;
|
|
31
|
+
cancelCooldown;
|
|
25
32
|
destroyed = false;
|
|
26
33
|
status;
|
|
27
34
|
lockReason;
|
|
@@ -31,6 +38,7 @@ var KernelWallet = class KernelWallet {
|
|
|
31
38
|
constructor(options) {
|
|
32
39
|
this.passkeyCfg = options.passkey;
|
|
33
40
|
this.ceremony = options.ceremony;
|
|
41
|
+
this.setTimer = options.setTimer;
|
|
34
42
|
this.onDestroy = options.onDestroy;
|
|
35
43
|
this.snapshotValue = {
|
|
36
44
|
vault: "uninitialized",
|
|
@@ -38,7 +46,8 @@ var KernelWallet = class KernelWallet {
|
|
|
38
46
|
verifying: false,
|
|
39
47
|
factors: [],
|
|
40
48
|
wallets: [],
|
|
41
|
-
nostr: { keys: [] }
|
|
49
|
+
nostr: { keys: [] },
|
|
50
|
+
backup: null
|
|
42
51
|
};
|
|
43
52
|
this.channel = new Channel(options.spawn, {
|
|
44
53
|
onStatus: (status) => {
|
|
@@ -50,8 +59,11 @@ var KernelWallet = class KernelWallet {
|
|
|
50
59
|
},
|
|
51
60
|
onCrashed: () => {
|
|
52
61
|
this.lockReason = "crashed";
|
|
53
|
-
this.
|
|
62
|
+
this.markLocked();
|
|
54
63
|
}
|
|
64
|
+
}, options.setTimer);
|
|
65
|
+
this.unsubscribePresence = options.presence?.(() => {
|
|
66
|
+
this.onPresence();
|
|
55
67
|
});
|
|
56
68
|
registerInternals(this, {
|
|
57
69
|
call: async (method, params, transfer) => this.channel.call(method, params, transfer),
|
|
@@ -70,6 +82,37 @@ var KernelWallet = class KernelWallet {
|
|
|
70
82
|
await wallet.channel.start();
|
|
71
83
|
return wallet;
|
|
72
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Presence refresh, throttled to one touch per interval: once a touch fires, signals are ignored
|
|
87
|
+
* until the cooldown elapses — no clock reads, just the injected timer. Touches only go out while
|
|
88
|
+
* a session is held; failures are silent (a lock or respawn needs no handling).
|
|
89
|
+
*/
|
|
90
|
+
onPresence() {
|
|
91
|
+
if (this.presenceCooling || this.destroyed || this.channel.session === void 0) return;
|
|
92
|
+
this.presenceCooling = true;
|
|
93
|
+
this.cancelCooldown = this.setTimer(PRESENCE_TOUCH_INTERVAL_MS, () => {
|
|
94
|
+
this.presenceCooling = false;
|
|
95
|
+
this.cancelCooldown = void 0;
|
|
96
|
+
});
|
|
97
|
+
this.touchSession();
|
|
98
|
+
}
|
|
99
|
+
async touchSession() {
|
|
100
|
+
try {
|
|
101
|
+
await this.channel.call("session.touch", null);
|
|
102
|
+
} catch {}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The worker is dead or replaced — no status will arrive from it, yet an unlocked vault is locked
|
|
106
|
+
* now. Reflect that in the snapshot without waiting for the respawned kernel; other states
|
|
107
|
+
* (uninitialized, corrupted, …) are the kernel's truth and stay untouched.
|
|
108
|
+
*/
|
|
109
|
+
markLocked() {
|
|
110
|
+
if (this.status !== void 0 && this.status.vault === "unlocked") this.status = {
|
|
111
|
+
...this.status,
|
|
112
|
+
vault: "locked"
|
|
113
|
+
};
|
|
114
|
+
this.emit();
|
|
115
|
+
}
|
|
73
116
|
onStatus(status) {
|
|
74
117
|
if (this.lockReason === void 0 && status.vault === "locked") this.lockReason = "cold-start";
|
|
75
118
|
this.status = status;
|
|
@@ -87,10 +130,11 @@ var KernelWallet = class KernelWallet {
|
|
|
87
130
|
verifying: this.verifying > 0,
|
|
88
131
|
factors: status === void 0 ? [] : status.factors,
|
|
89
132
|
wallets: status === void 0 ? [] : status.wallets,
|
|
90
|
-
nostr: { keys: status === void 0 ? [] : status.nostr.keys }
|
|
133
|
+
nostr: { keys: status === void 0 ? [] : status.nostr.keys },
|
|
134
|
+
backup: status === void 0 ? null : status.backup
|
|
91
135
|
};
|
|
92
136
|
const current = this.snapshotValue;
|
|
93
|
-
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)) return;
|
|
137
|
+
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.backup, next.backup)) return;
|
|
94
138
|
this.snapshotValue = next;
|
|
95
139
|
for (const listener of this.listeners) listener();
|
|
96
140
|
}
|
|
@@ -133,6 +177,7 @@ var KernelWallet = class KernelWallet {
|
|
|
133
177
|
}
|
|
134
178
|
sessionOf(result) {
|
|
135
179
|
this.channel.session = result.session;
|
|
180
|
+
this.channel.flushStatus();
|
|
136
181
|
}
|
|
137
182
|
vault = {
|
|
138
183
|
unlock: async (factor) => this.withVerifying(async () => {
|
|
@@ -142,11 +187,8 @@ var KernelWallet = class KernelWallet {
|
|
|
142
187
|
this.sessionOf(result);
|
|
143
188
|
}),
|
|
144
189
|
lock: async () => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
} catch (error) {
|
|
148
|
-
if (!(error instanceof WalletError) || error.code !== "locked") throw error;
|
|
149
|
-
}
|
|
190
|
+
this.channel.lockNow();
|
|
191
|
+
this.markLocked();
|
|
150
192
|
},
|
|
151
193
|
addFactor: async (factor, verify) => this.withVerifying(async () => {
|
|
152
194
|
const transfer = [];
|
|
@@ -190,6 +232,7 @@ var KernelWallet = class KernelWallet {
|
|
|
190
232
|
const created = await this.channel.call("wallet.createWithPasskey", {
|
|
191
233
|
credentialId: wireBytes(result.credentialId, transfer),
|
|
192
234
|
prfWallet: wireBytes(result.first, transfer, true),
|
|
235
|
+
synced: result.synced,
|
|
193
236
|
...factor === void 0 ? {} : { factor }
|
|
194
237
|
}, transfer);
|
|
195
238
|
this.sessionOf(created);
|
|
@@ -202,6 +245,11 @@ var KernelWallet = class KernelWallet {
|
|
|
202
245
|
first: walletSaltBytes(this.factorSource),
|
|
203
246
|
second: vaultSaltBytes(this.factorSource)
|
|
204
247
|
} });
|
|
248
|
+
if (result.userHandle?.[0] !== 1) {
|
|
249
|
+
result.first.fill(0);
|
|
250
|
+
result.second?.fill(0);
|
|
251
|
+
throw new WalletError("wrong-passkey", "the passkey is not a wallet credential");
|
|
252
|
+
}
|
|
205
253
|
let factor;
|
|
206
254
|
if (this.initialized()) {
|
|
207
255
|
if (options?.factor !== void 0) throw new WalletError("invalid-input", "the vault is already initialized");
|
|
@@ -210,6 +258,7 @@ var KernelWallet = class KernelWallet {
|
|
|
210
258
|
const created = await this.channel.call("wallet.restoreWithPasskey", {
|
|
211
259
|
credentialId: wireBytes(result.credentialId, transfer),
|
|
212
260
|
prfWallet: wireBytes(result.first, transfer, true),
|
|
261
|
+
synced: result.synced,
|
|
213
262
|
...factor === void 0 ? {} : { factor }
|
|
214
263
|
}, transfer);
|
|
215
264
|
this.sessionOf(created);
|
|
@@ -271,21 +320,62 @@ var KernelWallet = class KernelWallet {
|
|
|
271
320
|
})
|
|
272
321
|
};
|
|
273
322
|
dataKeys = { get: async (purpose) => this.channel.call("dataKeys.get", { purpose }) };
|
|
323
|
+
backup = {
|
|
324
|
+
enable: async (options) => this.withVerifying(async () => {
|
|
325
|
+
const transfer = [];
|
|
326
|
+
const wireVerify = await resolveFactor(this.factorSource, options.verify, transfer);
|
|
327
|
+
const wireFactors = await Promise.all(options.factors.map(async (factor) => resolveBackupFactor(this.factorSource, factor, transfer)));
|
|
328
|
+
await this.channel.call("backup.enable", {
|
|
329
|
+
verify: wireVerify,
|
|
330
|
+
factors: wireFactors
|
|
331
|
+
}, transfer);
|
|
332
|
+
}),
|
|
333
|
+
update: async () => {
|
|
334
|
+
return (await this.channel.call("backup.update", null)).envelope;
|
|
335
|
+
},
|
|
336
|
+
disable: async () => {
|
|
337
|
+
await this.channel.call("backup.disable", null);
|
|
338
|
+
},
|
|
339
|
+
restore: async (options) => this.withVerifying(async () => {
|
|
340
|
+
const transfer = [];
|
|
341
|
+
const backupFactor = await resolveBackupFactor(this.factorSource, options.backupFactor, transfer);
|
|
342
|
+
const factor = await this.createFactorParam(options.factor, transfer);
|
|
343
|
+
const result = await this.channel.call("backup.restore", {
|
|
344
|
+
envelope: options.envelope,
|
|
345
|
+
backupFactor,
|
|
346
|
+
...factor === void 0 ? {} : { factor }
|
|
347
|
+
}, transfer);
|
|
348
|
+
this.sessionOf(result);
|
|
349
|
+
return result.wallets;
|
|
350
|
+
})
|
|
351
|
+
};
|
|
274
352
|
async destroy() {
|
|
275
353
|
if (this.destroyed) return;
|
|
276
354
|
this.destroyed = true;
|
|
355
|
+
this.unsubscribePresence?.();
|
|
356
|
+
this.cancelCooldown?.();
|
|
277
357
|
this.onDestroy?.();
|
|
278
358
|
this.channel.destroy();
|
|
279
359
|
}
|
|
280
360
|
};
|
|
281
361
|
/**
|
|
362
|
+
* Validates the passkey configuration: the RP identity and both PRF salts are permanent
|
|
363
|
+
* identifiers, so an empty or colliding value is rejected here rather than producing unrecoverable
|
|
364
|
+
* credentials later.
|
|
365
|
+
*/
|
|
366
|
+
function checkPasskeyConfig(passkey) {
|
|
367
|
+
const { rpId, rpName, walletSalt, vaultSalt, backupSalt } = passkey;
|
|
368
|
+
if (rpId.length === 0 || rpName.length === 0 || walletSalt.length === 0 || vaultSalt.length === 0 || backupSalt.length === 0 || walletSalt === vaultSalt || backupSalt === vaultSalt || backupSalt === walletSalt) throw new WalletError("invalid-input", "passkey config requires a non-empty rpId, rpName and two different salts");
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
282
371
|
* Connects a kernel spawned by the host package and returns the host-facing `Wallet`. The first
|
|
283
372
|
* spawn must deliver a status event before this resolves.
|
|
284
373
|
*/
|
|
285
374
|
async function connectKernel(options) {
|
|
375
|
+
checkPasskeyConfig(options.passkey);
|
|
286
376
|
return KernelWallet.connect(options);
|
|
287
377
|
}
|
|
288
378
|
//#endregion
|
|
289
|
-
export { connectKernel };
|
|
379
|
+
export { PASSKEY_PURPOSE_VAULT, PASSKEY_PURPOSE_WALLET, connectKernel };
|
|
290
380
|
|
|
291
381
|
//# sourceMappingURL=host.mjs.map
|
package/dist/host.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.mjs","names":[],"sources":["../src/wallet.ts"],"sourcesContent":["/**\n * The host-facing `Wallet` (design/entry.mdx \"API\"): snapshot state, the core API groups, and the\n * glue between the kernel `Channel` and factor resolution. `connectKernel` is exported under the\n * `./host` subpath — reserved for host packages; applications must not use it. Protocol modules\n * (@qntx/wallet/nostr and future siblings) reach this wallet's channel through the registered\n * internals in internal.ts — never through the public type.\n */\nimport { Channel } from \"./channel.ts\";\nimport type { MainPort } from \"./channel.ts\";\nimport {\n passkeyName,\n requireCeremony,\n resolveFactor,\n resolveInitialFactor,\n vaultSaltBytes,\n walletSaltBytes,\n wireBytes,\n wireSecretText,\n} from \"./factors.ts\";\nimport type { FactorSource, PasskeyCeremony } from \"./factors.ts\";\nimport { registerInternals } from \"./internal.ts\";\nimport type { Factor } from \"./protocol/index.ts\";\nimport { SingleUseSecret } from \"./secret.ts\";\nimport { WalletError } from \"./types.ts\";\nimport type {\n DataKeyApi,\n ExportedSecret,\n FactorInfo,\n InitialFactor,\n LockReason,\n MnemonicDraft,\n PasskeyConfig,\n StatusPayload,\n UnlockFactor,\n VaultApi,\n Wallet,\n WalletInfo,\n WalletSnapshot,\n WalletsApi,\n} from \"./types.ts\";\n\nexport type ConnectOptions = {\n readonly spawn: () => MainPort;\n readonly passkey: PasskeyConfig;\n readonly ceremony: PasskeyCeremony | undefined;\n /** Runs once inside `destroy()` — host-side cleanup (page listeners, timers). */\n readonly onDestroy?: () => void;\n};\n\n/** Structural equality over plain snapshot data (validated protocol payloads only). */\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true;\n }\n if (typeof a !== \"object\" || a === null || typeof b !== \"object\" || b === null) {\n return false;\n }\n if (Array.isArray(a) || Array.isArray(b)) {\n return (\n Array.isArray(a) &&\n Array.isArray(b) &&\n a.length === b.length &&\n a.every((item, index) => deepEqual(item, b[index]))\n );\n }\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n return (\n aKeys.length === bKeys.length &&\n aKeys.every(\n (key) =>\n key in b &&\n deepEqual(\n (a as Record<string, unknown>)[key], // oxlint-disable-line typescript/no-unsafe-type-assertion -- plain-object records\n (b as Record<string, unknown>)[key], // oxlint-disable-line typescript/no-unsafe-type-assertion -- plain-object records\n ),\n )\n );\n}\n\nexport class KernelWallet implements Wallet {\n private readonly channel: Channel;\n private readonly passkeyCfg: PasskeyConfig;\n private readonly ceremony: PasskeyCeremony | undefined;\n private readonly onDestroy: (() => void) | undefined;\n private destroyed = false;\n\n private status: StatusPayload | undefined;\n private lockReason: LockReason | undefined;\n private verifying = 0;\n private snapshotValue: WalletSnapshot;\n private readonly listeners = new Set<() => void>();\n\n private constructor(options: ConnectOptions) {\n this.passkeyCfg = options.passkey;\n this.ceremony = options.ceremony;\n this.onDestroy = options.onDestroy;\n this.snapshotValue = {\n vault: \"uninitialized\",\n lockReason: undefined,\n verifying: false,\n factors: [],\n wallets: [],\n nostr: { keys: [] },\n };\n this.channel = new Channel(options.spawn, {\n onStatus: (status) => {\n this.onStatus(status);\n },\n onLocked: (reason) => {\n this.lockReason = reason;\n this.emit();\n },\n onCrashed: () => {\n this.lockReason = \"crashed\";\n this.emit();\n },\n });\n registerInternals(this, {\n call: async (method, params, transfer) => this.channel.call(method, params, transfer),\n ready: async () => this.channel.ready,\n snapshot: () => this.snapshotValue,\n withVerifying: async (fn) => this.withVerifying(fn),\n resolveFactor: async (factor, transfer) => resolveFactor(this.factorSource, factor, transfer),\n createFactorParam: async (factor, transfer) => this.createFactorParam(factor, transfer),\n sessionOf: (result) => {\n this.sessionOf(result);\n },\n });\n }\n\n static async connect(options: ConnectOptions): Promise<KernelWallet> {\n const wallet = new KernelWallet(options);\n await wallet.channel.start();\n return wallet;\n }\n\n private onStatus(status: StatusPayload): void {\n if (this.lockReason === undefined && status.vault === \"locked\") {\n this.lockReason = \"cold-start\"; // locked at first sight, not by an action of ours\n }\n this.status = status;\n this.emit();\n }\n\n /**\n * Rebuilds the immutable snapshot and notifies subscribers — only when the content actually\n * changed (identical status events produce no new reference and no notification).\n */\n private emit(): void {\n const { status } = this;\n const next: WalletSnapshot = {\n vault: status === undefined ? \"uninitialized\" : status.vault,\n lockReason: this.lockReason,\n verifying: this.verifying > 0,\n factors: status === undefined ? [] : status.factors,\n wallets: status === undefined ? [] : status.wallets,\n nostr: { keys: status === undefined ? [] : status.nostr.keys },\n };\n const current = this.snapshotValue;\n if (\n current.vault === next.vault &&\n current.lockReason === next.lockReason &&\n current.verifying === next.verifying &&\n deepEqual(current.factors, next.factors) &&\n deepEqual(current.wallets, next.wallets) &&\n deepEqual(current.nostr, next.nostr)\n ) {\n return;\n }\n this.snapshotValue = next;\n for (const listener of this.listeners) {\n listener();\n }\n }\n\n // Arrow properties: safe unbound, e.g. useSyncExternalStore(wallet.subscribe, wallet.getSnapshot).\n readonly getSnapshot = (): WalletSnapshot => this.snapshotValue;\n\n readonly subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n private get factorSource(): FactorSource {\n return {\n passkey: this.passkeyCfg,\n ceremony: this.ceremony,\n factors: () => this.snapshotValue.factors,\n };\n }\n\n /** True while a ceremony or a factor-bearing request is in flight; drives `verifying`. */\n private async withVerifying<T>(fn: () => Promise<T>): Promise<T> {\n this.verifying++;\n this.emit();\n try {\n return await fn();\n } finally {\n this.verifying--;\n this.emit();\n }\n }\n\n private initialized(): boolean {\n return this.snapshotValue.vault !== \"uninitialized\";\n }\n\n /** The factor gate on create/import commands; keeps useless ceremonies from firing. */\n private async createFactorParam(\n factor: InitialFactor | undefined,\n transfer: ArrayBuffer[],\n ): Promise<Factor | undefined> {\n if (this.initialized()) {\n if (factor !== undefined) {\n throw new WalletError(\"invalid-input\", \"the vault is already initialized\");\n }\n return undefined;\n }\n if (factor === undefined) {\n throw new WalletError(\"invalid-input\", \"an initial factor is required\");\n }\n return resolveInitialFactor(this.factorSource, factor, transfer);\n }\n\n private sessionOf(result: { readonly session: string }): void {\n this.channel.session = result.session;\n }\n\n readonly vault: VaultApi = {\n unlock: async (factor?: UnlockFactor): Promise<void> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wire = await resolveFactor(\n this.factorSource,\n factor ?? { kind: \"passkey\" },\n transfer,\n );\n const result = await this.channel.call(\"vault.unlock\", { factor: wire }, transfer);\n this.sessionOf(result);\n }),\n lock: async (): Promise<void> => {\n try {\n await this.channel.call(\"vault.lock\", null);\n } catch (error) {\n // Locking an already-locked (or just-locked) vault is the postcondition anyway.\n if (!(error instanceof WalletError) || error.code !== \"locked\") {\n throw error;\n }\n }\n },\n addFactor: async (factor: InitialFactor, verify: UnlockFactor): Promise<FactorInfo> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, verify, transfer);\n const wireFactor = await resolveInitialFactor(this.factorSource, factor, transfer);\n return this.channel.call(\n \"vault.addFactor\",\n { verify: wireVerify, factor: wireFactor },\n transfer,\n );\n }),\n removeFactor: async (id: string, verify: UnlockFactor): Promise<void> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, verify, transfer);\n await this.channel.call(\"vault.removeFactor\", { verify: wireVerify, id }, transfer);\n }),\n reset: async (): Promise<void> => {\n await this.channel.call(\"vault.reset\", null);\n },\n };\n\n readonly wallets: WalletsApi = {\n createWithPasskey: async (options: {\n readonly name: string;\n readonly factor?: InitialFactor;\n }): Promise<WalletInfo> =>\n this.withVerifying(async () => {\n const ceremony = requireCeremony(this.factorSource);\n const name = passkeyName(options.name);\n const transfer: ArrayBuffer[] = [];\n const result = await ceremony.create({\n purpose: \"wallet\",\n name,\n salts: {\n first: walletSaltBytes(this.factorSource),\n second: vaultSaltBytes(this.factorSource),\n },\n });\n let factor: Factor | undefined;\n if (this.initialized()) {\n if (options.factor !== undefined) {\n throw new WalletError(\"invalid-input\", \"the vault is already initialized\");\n }\n result.second?.fill(0); // the vault factor slot is not needed\n } else {\n factor = await resolveInitialFactor(this.factorSource, options.factor, transfer, result);\n }\n const created = await this.channel.call(\n \"wallet.createWithPasskey\",\n {\n credentialId: wireBytes(result.credentialId, transfer),\n prfWallet: wireBytes(result.first, transfer, true),\n ...(factor === undefined ? {} : { factor }),\n },\n transfer,\n );\n this.sessionOf(created);\n return created.wallet;\n }),\n restoreWithPasskey: async (options?: {\n readonly factor?: InitialFactor;\n }): Promise<WalletInfo> =>\n this.withVerifying(async () => {\n const ceremony = requireCeremony(this.factorSource);\n const transfer: ArrayBuffer[] = [];\n const result = await ceremony.assert({\n salts: {\n first: walletSaltBytes(this.factorSource),\n second: vaultSaltBytes(this.factorSource),\n },\n });\n let factor: Factor | undefined;\n if (this.initialized()) {\n if (options?.factor !== undefined) {\n throw new WalletError(\"invalid-input\", \"the vault is already initialized\");\n }\n result.second?.fill(0);\n } else {\n factor = await resolveInitialFactor(this.factorSource, options?.factor, transfer, result);\n }\n const created = await this.channel.call(\n \"wallet.restoreWithPasskey\",\n {\n credentialId: wireBytes(result.credentialId, transfer),\n prfWallet: wireBytes(result.first, transfer, true),\n ...(factor === undefined ? {} : { factor }),\n },\n transfer,\n );\n this.sessionOf(created);\n return created.wallet;\n }),\n createMnemonic: async (options: {\n readonly words: 12 | 24;\n readonly factor?: InitialFactor;\n }): Promise<MnemonicDraft> => {\n const transfer: ArrayBuffer[] = [];\n const factor = await this.createFactorParam(options.factor, transfer);\n const created = await this.channel.call(\n \"wallet.createMnemonic\",\n { words: options.words, ...(factor === undefined ? {} : { factor }) },\n transfer,\n );\n const draftId = created.draft;\n return {\n words: new SingleUseSecret(created.words),\n quiz: created.quiz,\n confirm: async (answers: ReadonlyArray<string>): Promise<WalletInfo> => {\n const answerTransfer: ArrayBuffer[] = [];\n const encoded = answers.map((word) => wireSecretText(word, answerTransfer));\n const confirmed = await this.channel.call(\n \"wallet.confirmMnemonic\",\n { draft: draftId, answers: encoded },\n answerTransfer,\n );\n this.sessionOf(confirmed);\n return confirmed.wallet;\n },\n discard: async (): Promise<void> => {\n await this.channel.call(\"wallet.discardMnemonic\", { draft: draftId });\n },\n };\n },\n importMnemonic: async (options: {\n readonly mnemonic: string;\n readonly factor?: InitialFactor;\n }): Promise<WalletInfo> => {\n const transfer: ArrayBuffer[] = [];\n const factor = await this.createFactorParam(options.factor, transfer);\n const mnemonic = wireSecretText(options.mnemonic, transfer);\n const created = await this.channel.call(\n \"wallet.importMnemonic\",\n { mnemonic, ...(factor === undefined ? {} : { factor }) },\n transfer,\n );\n this.sessionOf(created);\n return created.wallet;\n },\n exportMnemonic: async (walletId: string, verify: UnlockFactor): Promise<ExportedSecret> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, verify, transfer);\n const bytes = await this.channel.call(\n \"wallet.exportMnemonic\",\n { verify: wireVerify, walletId },\n transfer,\n );\n return new SingleUseSecret(bytes);\n }),\n delete: async (walletId: string, verify: UnlockFactor): Promise<void> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, verify, transfer);\n await this.channel.call(\"wallet.delete\", { verify: wireVerify, walletId }, transfer);\n }),\n };\n\n readonly dataKeys: DataKeyApi = {\n get: async (purpose: string): Promise<Uint8Array> =>\n this.channel.call(\"dataKeys.get\", { purpose }),\n };\n\n // oxlint-disable-next-line typescript/require-await -- the interface's Promise is resolved synchronously\n async destroy(): Promise<void> {\n if (this.destroyed) {\n return;\n }\n this.destroyed = true;\n this.onDestroy?.();\n this.channel.destroy();\n }\n}\n\n/**\n * Connects a kernel spawned by the host package and returns the host-facing `Wallet`. The first\n * spawn must deliver a status event before this resolves.\n */\nexport async function connectKernel(options: ConnectOptions): Promise<Wallet> {\n return KernelWallet.connect(options);\n}\n"],"mappings":";;;;;;;;;;;AAkDA,SAAS,UAAU,GAAY,GAAqB;CAClD,IAAI,MAAM,GACR,OAAO;CAET,IAAI,OAAO,MAAM,YAAY,MAAM,QAAQ,OAAO,MAAM,YAAY,MAAM,MACxE,OAAO;CAET,IAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GACrC,OACE,MAAM,QAAQ,CAAC,KACf,MAAM,QAAQ,CAAC,KACf,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,MAAM,UAAU,UAAU,MAAM,EAAE,MAAM,CAAC;CAGtD,MAAM,QAAQ,OAAO,KAAK,CAAC;CAC3B,MAAM,QAAQ,OAAO,KAAK,CAAC;CAC3B,OACE,MAAM,WAAW,MAAM,UACvB,MAAM,OACH,QACC,OAAO,KACP,UACG,EAA8B,MAC9B,EAA8B,IAC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,WAA0B,CAAC;GACjC,MAAM,aAAa,MAAM,cAAc,KAAK,cAAc,QAAQ,QAAQ;GAC1E,MAAM,QAAQ,MAAM,KAAK,QAAQ,KAC/B,yBACA;IAAE,QAAQ;IAAY;GAAS,GAC/B,QACF;GACA,OAAO,IAAI,gBAAgB,KAAK;EAClC,CAAC;EACH,QAAQ,OAAO,UAAkB,WAC/B,KAAK,cAAc,YAAY;GAC7B,MAAM,WAA0B,CAAC;GACjC,MAAM,aAAa,MAAM,cAAc,KAAK,cAAc,QAAQ,QAAQ;GAC1E,MAAM,KAAK,QAAQ,KAAK,iBAAiB;IAAE,QAAQ;IAAY;GAAS,GAAG,QAAQ;EACrF,CAAC;CACL;CAEA,WAAgC,EAC9B,KAAK,OAAO,YACV,KAAK,QAAQ,KAAK,gBAAgB,EAAE,QAAQ,CAAC,EACjD;CAGA,MAAM,UAAyB;EAC7B,IAAI,KAAK,WACP;EAEF,KAAK,YAAY;EACjB,KAAK,YAAY;EACjB,KAAK,QAAQ,QAAQ;CACvB;AACF;;;;;AAMA,eAAsB,cAAc,SAA0C;CAC5E,OAAO,aAAa,QAAQ,OAAO;AACrC"}
|
|
1
|
+
{"version":3,"file":"host.mjs","names":[],"sources":["../src/wallet.ts"],"sourcesContent":["/**\n * The host-facing `Wallet` (design/entry.mdx \"API\"): snapshot state, the core API groups, and the\n * glue between the kernel `Channel` and factor resolution. `connectKernel` is exported under the\n * `./host` subpath — reserved for host packages; applications must not use it. Protocol modules\n * (@qntx/wallet/nostr and future siblings) reach this wallet's channel through the registered\n * internals in internal.ts — never through the public type.\n */\nimport { Channel } from \"./channel.ts\";\nimport type { MainPort, SetTimer } from \"./channel.ts\";\nimport {\n PASSKEY_PURPOSE_WALLET,\n passkeyName,\n requireCeremony,\n resolveFactor,\n resolveInitialFactor,\n vaultSaltBytes,\n walletSaltBytes,\n wireBytes,\n wireSecretText,\n resolveBackupFactor,\n} from \"./factors.ts\";\nimport type { FactorSource, PasskeyCeremony } from \"./factors.ts\";\nimport { registerInternals } from \"./internal.ts\";\nimport type { Factor } from \"./protocol/index.ts\";\nimport { SingleUseSecret } from \"./secret.ts\";\nimport { WalletError } from \"./types.ts\";\nimport type {\n BackupApi,\n DataKeyApi,\n ExportedSecret,\n FactorInfo,\n InitialFactor,\n LockReason,\n MnemonicDraft,\n PasskeyConfig,\n StatusPayload,\n UnlockFactor,\n VaultApi,\n Wallet,\n WalletInfo,\n WalletSnapshot,\n WalletsApi,\n} from \"./types.ts\";\n\nexport type ConnectOptions = {\n readonly spawn: () => MainPort;\n readonly passkey: PasskeyConfig;\n readonly ceremony: PasskeyCeremony | undefined;\n /** Timer source injected by the host package (globalThis timers on web/node). */\n readonly setTimer: SetTimer;\n /**\n * User-presence source: subscribes to activity signals and returns an unsubscribe the wallet\n * owns. Absent means the host has no presence signals (the kernel policy decides what counts).\n */\n readonly presence?: (onActivity: () => void) => () => void;\n /** Runs once inside `destroy()` — host-side cleanup (page listeners, timers). */\n readonly onDestroy?: () => void;\n};\n\n/** One `session.touch` at most per interval — the idle deadline slips at most this much early. */\nexport const PRESENCE_TOUCH_INTERVAL_MS = 30_000;\n\n/** Structural equality over plain snapshot data (validated protocol payloads only). */\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true;\n }\n if (typeof a !== \"object\" || a === null || typeof b !== \"object\" || b === null) {\n return false;\n }\n if (Array.isArray(a) || Array.isArray(b)) {\n return (\n Array.isArray(a) &&\n Array.isArray(b) &&\n a.length === b.length &&\n a.every((item, index) => deepEqual(item, b[index]))\n );\n }\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n return (\n aKeys.length === bKeys.length &&\n aKeys.every(\n (key) =>\n key in b &&\n deepEqual(\n (a as Record<string, unknown>)[key], // oxlint-disable-line typescript/no-unsafe-type-assertion -- plain-object records\n (b as Record<string, unknown>)[key], // oxlint-disable-line typescript/no-unsafe-type-assertion -- plain-object records\n ),\n )\n );\n}\n\nexport class KernelWallet implements Wallet {\n private readonly channel: Channel;\n private readonly passkeyCfg: PasskeyConfig;\n private readonly ceremony: PasskeyCeremony | undefined;\n private readonly setTimer: SetTimer;\n private readonly onDestroy: (() => void) | undefined;\n private readonly unsubscribePresence: (() => void) | undefined;\n private presenceCooling = false;\n private cancelCooldown: (() => void) | undefined;\n private destroyed = false;\n\n private status: StatusPayload | undefined;\n private lockReason: LockReason | undefined;\n private verifying = 0;\n private snapshotValue: WalletSnapshot;\n private readonly listeners = new Set<() => void>();\n\n private constructor(options: ConnectOptions) {\n this.passkeyCfg = options.passkey;\n this.ceremony = options.ceremony;\n this.setTimer = options.setTimer;\n this.onDestroy = options.onDestroy;\n this.snapshotValue = {\n vault: \"uninitialized\",\n lockReason: undefined,\n verifying: false,\n factors: [],\n wallets: [],\n nostr: { keys: [] },\n backup: null,\n };\n this.channel = new Channel(\n options.spawn,\n {\n onStatus: (status) => {\n this.onStatus(status);\n },\n onLocked: (reason) => {\n this.lockReason = reason;\n this.emit();\n },\n onCrashed: () => {\n this.lockReason = \"crashed\";\n this.markLocked();\n },\n },\n options.setTimer,\n );\n // The wallet owns the subscription it creates: destroy() unsubscribes — no second owner.\n this.unsubscribePresence = options.presence?.(() => {\n this.onPresence();\n });\n registerInternals(this, {\n call: async (method, params, transfer) => this.channel.call(method, params, transfer),\n ready: async () => this.channel.ready,\n snapshot: () => this.snapshotValue,\n withVerifying: async (fn) => this.withVerifying(fn),\n resolveFactor: async (factor, transfer) => resolveFactor(this.factorSource, factor, transfer),\n createFactorParam: async (factor, transfer) => this.createFactorParam(factor, transfer),\n sessionOf: (result) => {\n this.sessionOf(result);\n },\n });\n }\n\n static async connect(options: ConnectOptions): Promise<KernelWallet> {\n const wallet = new KernelWallet(options);\n await wallet.channel.start();\n return wallet;\n }\n\n /**\n * Presence refresh, throttled to one touch per interval: once a touch fires, signals are ignored\n * until the cooldown elapses — no clock reads, just the injected timer. Touches only go out while\n * a session is held; failures are silent (a lock or respawn needs no handling).\n */\n private onPresence(): void {\n if (this.presenceCooling || this.destroyed || this.channel.session === undefined) {\n return;\n }\n this.presenceCooling = true;\n this.cancelCooldown = this.setTimer(PRESENCE_TOUCH_INTERVAL_MS, () => {\n this.presenceCooling = false;\n this.cancelCooldown = undefined;\n });\n void this.touchSession();\n }\n\n private async touchSession(): Promise<void> {\n try {\n await this.channel.call(\"session.touch\", null);\n } catch {\n // A racing lock or respawn needs no handling.\n }\n }\n\n /**\n * The worker is dead or replaced — no status will arrive from it, yet an unlocked vault is locked\n * now. Reflect that in the snapshot without waiting for the respawned kernel; other states\n * (uninitialized, corrupted, …) are the kernel's truth and stay untouched.\n */\n private markLocked(): void {\n if (this.status !== undefined && this.status.vault === \"unlocked\") {\n this.status = { ...this.status, vault: \"locked\" };\n }\n this.emit();\n }\n\n private onStatus(status: StatusPayload): void {\n if (this.lockReason === undefined && status.vault === \"locked\") {\n this.lockReason = \"cold-start\"; // locked at first sight, not by an action of ours\n }\n this.status = status;\n this.emit();\n }\n\n /**\n * Rebuilds the immutable snapshot and notifies subscribers — only when the content actually\n * changed (identical status events produce no new reference and no notification).\n */\n private emit(): void {\n const { status } = this;\n const next: WalletSnapshot = {\n vault: status === undefined ? \"uninitialized\" : status.vault,\n lockReason: this.lockReason,\n verifying: this.verifying > 0,\n factors: status === undefined ? [] : status.factors,\n wallets: status === undefined ? [] : status.wallets,\n nostr: { keys: status === undefined ? [] : status.nostr.keys },\n backup: status === undefined ? null : status.backup,\n };\n const current = this.snapshotValue;\n if (\n current.vault === next.vault &&\n current.lockReason === next.lockReason &&\n current.verifying === next.verifying &&\n deepEqual(current.factors, next.factors) &&\n deepEqual(current.wallets, next.wallets) &&\n deepEqual(current.nostr, next.nostr) &&\n deepEqual(current.backup, next.backup)\n ) {\n return;\n }\n this.snapshotValue = next;\n for (const listener of this.listeners) {\n listener();\n }\n }\n\n // Arrow properties: safe unbound, e.g. useSyncExternalStore(wallet.subscribe, wallet.getSnapshot).\n readonly getSnapshot = (): WalletSnapshot => this.snapshotValue;\n\n readonly subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n private get factorSource(): FactorSource {\n return {\n passkey: this.passkeyCfg,\n ceremony: this.ceremony,\n factors: () => this.snapshotValue.factors,\n };\n }\n\n /** True while a ceremony or a factor-bearing request is in flight; drives `verifying`. */\n private async withVerifying<T>(fn: () => Promise<T>): Promise<T> {\n this.verifying++;\n this.emit();\n try {\n return await fn();\n } finally {\n this.verifying--;\n this.emit();\n }\n }\n\n private initialized(): boolean {\n return this.snapshotValue.vault !== \"uninitialized\";\n }\n\n /** The factor gate on create/import commands; keeps useless ceremonies from firing. */\n private async createFactorParam(\n factor: InitialFactor | undefined,\n transfer: ArrayBuffer[],\n ): Promise<Factor | undefined> {\n if (this.initialized()) {\n if (factor !== undefined) {\n throw new WalletError(\"invalid-input\", \"the vault is already initialized\");\n }\n return undefined;\n }\n if (factor === undefined) {\n throw new WalletError(\"invalid-input\", \"an initial factor is required\");\n }\n return resolveInitialFactor(this.factorSource, factor, transfer);\n }\n\n private sessionOf(result: { readonly session: string }): void {\n this.channel.session = result.session;\n this.channel.flushStatus();\n }\n\n readonly vault: VaultApi = {\n unlock: async (factor?: UnlockFactor): Promise<void> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wire = await resolveFactor(\n this.factorSource,\n factor ?? { kind: \"passkey\" },\n transfer,\n );\n const result = await this.channel.call(\"vault.unlock\", { factor: wire }, transfer);\n this.sessionOf(result);\n }),\n // Host-side lock: immediate, no kernel round trip — fails pending calls, clears the session\n // and respawns the port. Idempotent: re-locking is a no-op.\n // oxlint-disable-next-line typescript/require-await -- the interface's Promise is resolved synchronously\n lock: async (): Promise<void> => {\n this.channel.lockNow();\n this.markLocked();\n },\n addFactor: async (factor: InitialFactor, verify: UnlockFactor): Promise<FactorInfo> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, verify, transfer);\n const wireFactor = await resolveInitialFactor(this.factorSource, factor, transfer);\n return this.channel.call(\n \"vault.addFactor\",\n { verify: wireVerify, factor: wireFactor },\n transfer,\n );\n }),\n removeFactor: async (id: string, verify: UnlockFactor): Promise<void> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, verify, transfer);\n await this.channel.call(\"vault.removeFactor\", { verify: wireVerify, id }, transfer);\n }),\n reset: async (): Promise<void> => {\n await this.channel.call(\"vault.reset\", null);\n },\n };\n\n readonly wallets: WalletsApi = {\n createWithPasskey: async (options: {\n readonly name: string;\n readonly factor?: InitialFactor;\n }): Promise<WalletInfo> =>\n this.withVerifying(async () => {\n const ceremony = requireCeremony(this.factorSource);\n const name = passkeyName(options.name);\n const transfer: ArrayBuffer[] = [];\n const result = await ceremony.create({\n purpose: \"wallet\",\n name,\n salts: {\n first: walletSaltBytes(this.factorSource),\n second: vaultSaltBytes(this.factorSource),\n },\n });\n let factor: Factor | undefined;\n if (this.initialized()) {\n if (options.factor !== undefined) {\n throw new WalletError(\"invalid-input\", \"the vault is already initialized\");\n }\n result.second?.fill(0); // the vault factor slot is not needed\n } else {\n factor = await resolveInitialFactor(this.factorSource, options.factor, transfer, result);\n }\n const created = await this.channel.call(\n \"wallet.createWithPasskey\",\n {\n credentialId: wireBytes(result.credentialId, transfer),\n prfWallet: wireBytes(result.first, transfer, true),\n synced: result.synced,\n ...(factor === undefined ? {} : { factor }),\n },\n transfer,\n );\n this.sessionOf(created);\n return created.wallet;\n }),\n restoreWithPasskey: async (options?: {\n readonly factor?: InitialFactor;\n }): Promise<WalletInfo> =>\n this.withVerifying(async () => {\n const ceremony = requireCeremony(this.factorSource);\n const transfer: ArrayBuffer[] = [];\n const result = await ceremony.assert({\n salts: {\n first: walletSaltBytes(this.factorSource),\n second: vaultSaltBytes(this.factorSource),\n },\n });\n // The asserted credential must be a wallet-purpose passkey: a vault-purpose credential\n // would silently derive a different wallet. Rejected assertions never reach the kernel.\n if (result.userHandle?.[0] !== PASSKEY_PURPOSE_WALLET) {\n result.first.fill(0);\n result.second?.fill(0);\n throw new WalletError(\"wrong-passkey\", \"the passkey is not a wallet credential\");\n }\n let factor: Factor | undefined;\n if (this.initialized()) {\n if (options?.factor !== undefined) {\n throw new WalletError(\"invalid-input\", \"the vault is already initialized\");\n }\n result.second?.fill(0);\n } else {\n factor = await resolveInitialFactor(this.factorSource, options?.factor, transfer, result);\n }\n const created = await this.channel.call(\n \"wallet.restoreWithPasskey\",\n {\n credentialId: wireBytes(result.credentialId, transfer),\n prfWallet: wireBytes(result.first, transfer, true),\n synced: result.synced,\n ...(factor === undefined ? {} : { factor }),\n },\n transfer,\n );\n this.sessionOf(created);\n return created.wallet;\n }),\n createMnemonic: async (options: {\n readonly words: 12 | 24;\n readonly factor?: InitialFactor;\n }): Promise<MnemonicDraft> => {\n const transfer: ArrayBuffer[] = [];\n const factor = await this.createFactorParam(options.factor, transfer);\n const created = await this.channel.call(\n \"wallet.createMnemonic\",\n { words: options.words, ...(factor === undefined ? {} : { factor }) },\n transfer,\n );\n const draftId = created.draft;\n return {\n words: new SingleUseSecret(created.words),\n quiz: created.quiz,\n confirm: async (answers: ReadonlyArray<string>): Promise<WalletInfo> => {\n const answerTransfer: ArrayBuffer[] = [];\n const encoded = answers.map((word) => wireSecretText(word, answerTransfer));\n const confirmed = await this.channel.call(\n \"wallet.confirmMnemonic\",\n { draft: draftId, answers: encoded },\n answerTransfer,\n );\n this.sessionOf(confirmed);\n return confirmed.wallet;\n },\n discard: async (): Promise<void> => {\n await this.channel.call(\"wallet.discardMnemonic\", { draft: draftId });\n },\n };\n },\n importMnemonic: async (options: {\n readonly mnemonic: string;\n readonly factor?: InitialFactor;\n }): Promise<WalletInfo> => {\n const transfer: ArrayBuffer[] = [];\n const factor = await this.createFactorParam(options.factor, transfer);\n const mnemonic = wireSecretText(options.mnemonic, transfer);\n const created = await this.channel.call(\n \"wallet.importMnemonic\",\n { mnemonic, ...(factor === undefined ? {} : { factor }) },\n transfer,\n );\n this.sessionOf(created);\n return created.wallet;\n },\n exportMnemonic: async (walletId: string, verify: UnlockFactor): Promise<ExportedSecret> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, verify, transfer);\n const bytes = await this.channel.call(\n \"wallet.exportMnemonic\",\n { verify: wireVerify, walletId },\n transfer,\n );\n return new SingleUseSecret(bytes);\n }),\n delete: async (walletId: string, verify: UnlockFactor): Promise<void> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, verify, transfer);\n await this.channel.call(\"wallet.delete\", { verify: wireVerify, walletId }, transfer);\n }),\n };\n\n readonly dataKeys: DataKeyApi = {\n get: async (purpose: string): Promise<Uint8Array> =>\n this.channel.call(\"dataKeys.get\", { purpose }),\n };\n\n readonly backup: BackupApi = {\n enable: async (options: {\n readonly verify: UnlockFactor;\n readonly factors: ReadonlyArray<UnlockFactor>;\n }): Promise<void> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const wireVerify = await resolveFactor(this.factorSource, options.verify, transfer);\n const wireFactors = await Promise.all(\n options.factors.map(async (factor) =>\n resolveBackupFactor(this.factorSource, factor, transfer),\n ),\n );\n await this.channel.call(\n \"backup.enable\",\n { verify: wireVerify, factors: wireFactors },\n transfer,\n );\n }),\n update: async (): Promise<string> => {\n const result = await this.channel.call(\"backup.update\", null);\n return result.envelope;\n },\n disable: async (): Promise<void> => {\n await this.channel.call(\"backup.disable\", null);\n },\n restore: async (options: {\n readonly envelope: string;\n readonly backupFactor: UnlockFactor;\n readonly factor?: InitialFactor;\n }): Promise<ReadonlyArray<WalletInfo>> =>\n this.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const backupFactor = await resolveBackupFactor(\n this.factorSource,\n options.backupFactor,\n transfer,\n );\n const factor = await this.createFactorParam(options.factor, transfer);\n const result = await this.channel.call(\n \"backup.restore\",\n {\n envelope: options.envelope,\n backupFactor,\n ...(factor === undefined ? {} : { factor }),\n },\n transfer,\n );\n this.sessionOf(result);\n return result.wallets;\n }),\n };\n\n // oxlint-disable-next-line typescript/require-await -- the interface's Promise is resolved synchronously\n async destroy(): Promise<void> {\n if (this.destroyed) {\n return;\n }\n this.destroyed = true;\n this.unsubscribePresence?.();\n this.cancelCooldown?.();\n this.onDestroy?.();\n this.channel.destroy();\n }\n}\n\n/**\n * Validates the passkey configuration: the RP identity and both PRF salts are permanent\n * identifiers, so an empty or colliding value is rejected here rather than producing unrecoverable\n * credentials later.\n */\nfunction checkPasskeyConfig(passkey: PasskeyConfig): void {\n const { rpId, rpName, walletSalt, vaultSalt, backupSalt } = passkey;\n if (\n rpId.length === 0 ||\n rpName.length === 0 ||\n walletSalt.length === 0 ||\n vaultSalt.length === 0 ||\n backupSalt.length === 0 ||\n walletSalt === vaultSalt ||\n backupSalt === vaultSalt ||\n backupSalt === walletSalt\n ) {\n throw new WalletError(\n \"invalid-input\",\n \"passkey config requires a non-empty rpId, rpName and two different salts\",\n );\n }\n}\n\n/**\n * Connects a kernel spawned by the host package and returns the host-facing `Wallet`. The first\n * spawn must deliver a status event before this resolves.\n */\nexport async function connectKernel(options: ConnectOptions): Promise<Wallet> {\n checkPasskeyConfig(options.passkey);\n return KernelWallet.connect(options);\n}\n"],"mappings":";;;;;;;;;;;;AA4DA,MAAa,6BAA6B;;AAG1C,SAAS,UAAU,GAAY,GAAqB;CAClD,IAAI,MAAM,GACR,OAAO;CAET,IAAI,OAAO,MAAM,YAAY,MAAM,QAAQ,OAAO,MAAM,YAAY,MAAM,MACxE,OAAO;CAET,IAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GACrC,OACE,MAAM,QAAQ,CAAC,KACf,MAAM,QAAQ,CAAC,KACf,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,MAAM,UAAU,UAAU,MAAM,EAAE,MAAM,CAAC;CAGtD,MAAM,QAAQ,OAAO,KAAK,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