@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
package/dist/host.mjs
CHANGED
|
@@ -1,7 +1,238 @@
|
|
|
1
1
|
import { WalletError } from "./types.mjs";
|
|
2
|
-
import { t as
|
|
3
|
-
import { n as registerInternals } from "./internal-
|
|
4
|
-
import {
|
|
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
|
+
}
|
|
5
236
|
// src/wallet.ts
|
|
6
237
|
/**
|
|
7
238
|
* The host-facing `Wallet` (design/entry.mdx "API"): snapshot state, the core API groups, and the
|
|
@@ -47,10 +278,14 @@ var KernelWallet = class KernelWallet {
|
|
|
47
278
|
vault: "uninitialized",
|
|
48
279
|
lockReason: void 0,
|
|
49
280
|
verifying: false,
|
|
281
|
+
appLock: false,
|
|
282
|
+
verification: "unavailable",
|
|
50
283
|
factors: [],
|
|
51
284
|
wallets: [],
|
|
52
285
|
nostr: { keys: [] },
|
|
53
|
-
|
|
286
|
+
importedKeys: [],
|
|
287
|
+
backup: null,
|
|
288
|
+
blindSigning: false
|
|
54
289
|
};
|
|
55
290
|
this.channel = new Channel(options.spawn, {
|
|
56
291
|
onStatus: (status) => {
|
|
@@ -69,16 +304,13 @@ var KernelWallet = class KernelWallet {
|
|
|
69
304
|
this.onPresence();
|
|
70
305
|
});
|
|
71
306
|
registerInternals(this, {
|
|
72
|
-
call: async (method, params
|
|
307
|
+
call: async (method, params) => this.channel.call(method, params),
|
|
308
|
+
secretCall: async (method, build) => this.secretCall(method, build),
|
|
73
309
|
ready: async () => this.channel.ready,
|
|
74
310
|
snapshot: () => this.snapshotValue,
|
|
75
311
|
verifyEvent: options.verifyEvent,
|
|
76
312
|
withVerifying: async (fn) => this.withVerifying(fn),
|
|
77
|
-
|
|
78
|
-
createFactorParam: async (factor, transfer) => this.createFactorParam(factor, transfer),
|
|
79
|
-
sessionOf: (result) => {
|
|
80
|
-
this.sessionOf(result);
|
|
81
|
-
}
|
|
313
|
+
resolveVerifyFactor: async (factor, wire) => resolveVerifyFactor(this.factorSource, factor, wire)
|
|
82
314
|
});
|
|
83
315
|
}
|
|
84
316
|
static async connect(options) {
|
|
@@ -86,17 +318,30 @@ var KernelWallet = class KernelWallet {
|
|
|
86
318
|
await wallet.channel.start();
|
|
87
319
|
return wallet;
|
|
88
320
|
}
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
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 {
|
|
92
339
|
ceremony: "host",
|
|
93
|
-
credentialId:
|
|
94
|
-
prfWallet:
|
|
340
|
+
credentialId: wire.bytes(result.credentialId),
|
|
341
|
+
prfWallet: wire.bytes(result.first, true),
|
|
95
342
|
synced: result.synced,
|
|
96
343
|
...factor === void 0 ? {} : { factor }
|
|
97
|
-
}
|
|
98
|
-
this.sessionOf(created);
|
|
99
|
-
return created.wallet;
|
|
344
|
+
};
|
|
100
345
|
}
|
|
101
346
|
/**
|
|
102
347
|
* Presence refresh, throttled to one touch per interval: once a touch fires, signals are ignored
|
|
@@ -144,13 +389,17 @@ var KernelWallet = class KernelWallet {
|
|
|
144
389
|
vault: status === void 0 ? "uninitialized" : status.vault,
|
|
145
390
|
lockReason: this.lockReason,
|
|
146
391
|
verifying: this.verifying > 0,
|
|
392
|
+
appLock: status === void 0 ? false : status.appLock,
|
|
393
|
+
verification: status === void 0 ? "unavailable" : status.verification,
|
|
147
394
|
factors: status === void 0 ? [] : status.factors,
|
|
148
395
|
wallets: status === void 0 ? [] : status.wallets,
|
|
149
396
|
nostr: { keys: status === void 0 ? [] : status.nostr.keys },
|
|
150
|
-
|
|
397
|
+
importedKeys: status === void 0 ? [] : status.importedKeys,
|
|
398
|
+
backup: status === void 0 ? null : status.backup,
|
|
399
|
+
blindSigning: status === void 0 ? false : status.blindSigning
|
|
151
400
|
};
|
|
152
401
|
const current = this.snapshotValue;
|
|
153
|
-
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;
|
|
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;
|
|
154
403
|
this.snapshotValue = next;
|
|
155
404
|
for (const listener of this.listeners) listener();
|
|
156
405
|
}
|
|
@@ -166,7 +415,8 @@ var KernelWallet = class KernelWallet {
|
|
|
166
415
|
mode: this.factorMode,
|
|
167
416
|
passkey: this.passkeyCfg,
|
|
168
417
|
ceremony: this.ceremony,
|
|
169
|
-
factors: () => this.snapshotValue.factors
|
|
418
|
+
factors: () => this.snapshotValue.factors,
|
|
419
|
+
appLock: () => this.snapshotValue.appLock
|
|
170
420
|
};
|
|
171
421
|
}
|
|
172
422
|
/** True while a ceremony or a factor-bearing request is in flight; drives `verifying`. */
|
|
@@ -183,132 +433,189 @@ var KernelWallet = class KernelWallet {
|
|
|
183
433
|
initialized() {
|
|
184
434
|
return this.snapshotValue.vault !== "uninitialized";
|
|
185
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
|
+
}
|
|
186
447
|
/** The factor gate on create/import commands; keeps useless ceremonies from firing. */
|
|
187
|
-
async createFactorParam(factor,
|
|
448
|
+
async createFactorParam(factor, wire) {
|
|
188
449
|
if (this.initialized()) {
|
|
189
450
|
if (factor !== void 0) throw new WalletError("invalid-input", "the vault is already initialized");
|
|
190
451
|
return;
|
|
191
452
|
}
|
|
192
453
|
if (factor === void 0 && this.factorMode === "software") throw new WalletError("invalid-input", "an initial factor is required");
|
|
193
|
-
return resolveInitialFactor(this.factorSource, factor,
|
|
454
|
+
return resolveInitialFactor(this.factorSource, factor, wire);
|
|
194
455
|
}
|
|
195
456
|
sessionOf(result) {
|
|
196
457
|
this.channel.session = result.session;
|
|
197
458
|
this.channel.flushStatus();
|
|
198
459
|
}
|
|
199
460
|
vault = {
|
|
200
|
-
unlock: async (factor) =>
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
+
},
|
|
206
469
|
lock: async () => {
|
|
207
470
|
this.channel.lockNow();
|
|
208
471
|
this.markLocked();
|
|
209
472
|
},
|
|
210
|
-
addFactor: async (factor, verify) => this.withVerifying(async () => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return this.channel.call("vault.addFactor", {
|
|
215
|
-
verify: wireVerify,
|
|
216
|
-
factor: wireFactor
|
|
217
|
-
}, transfer);
|
|
218
|
-
}),
|
|
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
|
+
}))),
|
|
219
477
|
removeFactor: async (id, verify) => this.withVerifying(async () => {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
await this.channel.call("vault.removeFactor", {
|
|
223
|
-
verify: wireVerify,
|
|
478
|
+
await this.secretCall("vault.removeFactor", async (wire) => ({
|
|
479
|
+
verify: await resolveVerifyFactor(this.factorSource, verify, wire),
|
|
224
480
|
id
|
|
225
|
-
}
|
|
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
|
+
}));
|
|
226
497
|
}),
|
|
227
498
|
reset: async () => {
|
|
228
499
|
await this.channel.call("vault.reset", null);
|
|
229
500
|
}
|
|
230
501
|
};
|
|
502
|
+
keys = {
|
|
503
|
+
import: async (family, secret) => this.withVerifying(async () => {
|
|
504
|
+
const decoded = decodeKeySecret(family, secret);
|
|
505
|
+
try {
|
|
506
|
+
return await this.secretCall("keys.import", (wire) => ({
|
|
507
|
+
family,
|
|
508
|
+
secret: wire.bytes(decoded)
|
|
509
|
+
}));
|
|
510
|
+
} finally {
|
|
511
|
+
if (decoded !== secret) decoded.fill(0);
|
|
512
|
+
}
|
|
513
|
+
}),
|
|
514
|
+
list: async () => this.channel.call("keys.list", null),
|
|
515
|
+
remove: async (keyId, verify) => this.withVerifying(async () => {
|
|
516
|
+
await this.secretCall("keys.remove", async (wire) => ({
|
|
517
|
+
verify: await resolveVerifyFactor(this.factorSource, verify, wire),
|
|
518
|
+
keyId
|
|
519
|
+
}));
|
|
520
|
+
}),
|
|
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
|
+
})))
|
|
525
|
+
};
|
|
231
526
|
wallets = {
|
|
232
527
|
createWithPasskey: async (options) => this.withVerifying(async () => {
|
|
233
528
|
const name = passkeyName(options.name);
|
|
234
|
-
const transfer = [];
|
|
235
529
|
if (this.factorMode === "hardware") {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
+
});
|
|
245
541
|
this.sessionOf(created);
|
|
246
542
|
return created.wallet;
|
|
247
543
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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);
|
|
254
562
|
}
|
|
255
563
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (options.factor !== void 0) throw new WalletError("invalid-input", "the vault is already initialized");
|
|
259
|
-
result.second?.fill(0);
|
|
260
|
-
} else factor = await resolveInitialFactor(this.factorSource, options.factor, transfer, result);
|
|
261
|
-
return this.hostPasskeyWallet("wallet.createWithPasskey", result, factor, transfer);
|
|
564
|
+
this.sessionOf(created);
|
|
565
|
+
return created.wallet;
|
|
262
566
|
}),
|
|
263
567
|
restoreWithPasskey: async (options) => this.withVerifying(async () => {
|
|
264
|
-
const transfer = [];
|
|
265
568
|
if (this.factorMode === "hardware") {
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
+
});
|
|
273
578
|
this.sessionOf(created);
|
|
274
579
|
return created.wallet;
|
|
275
580
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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;
|
|
291
600
|
}),
|
|
292
601
|
createMnemonic: async (options) => {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
+
});
|
|
299
609
|
const draftId = created.draft;
|
|
300
610
|
return {
|
|
301
611
|
words: new SingleUseSecret(created.words),
|
|
302
612
|
quiz: created.quiz,
|
|
303
613
|
confirm: async (answers, confirmOptions) => {
|
|
304
|
-
const
|
|
305
|
-
const encoded = answers.map((word) => wireSecretText(word, answerTransfer));
|
|
306
|
-
const passphrase = wirePassphrase(confirmOptions?.passphrase, answerTransfer);
|
|
307
|
-
const confirmed = await this.channel.call("wallet.confirmMnemonic", {
|
|
614
|
+
const confirmed = await this.secretCall("wallet.confirmMnemonic", (wire) => ({
|
|
308
615
|
draft: draftId,
|
|
309
|
-
answers:
|
|
310
|
-
...passphrase
|
|
311
|
-
}
|
|
616
|
+
answers: answers.map((word) => wire.text(word)),
|
|
617
|
+
...wire.passphrase(confirmOptions?.passphrase)
|
|
618
|
+
}));
|
|
312
619
|
this.sessionOf(confirmed);
|
|
313
620
|
return confirmed.wallet;
|
|
314
621
|
},
|
|
@@ -318,70 +625,68 @@ var KernelWallet = class KernelWallet {
|
|
|
318
625
|
};
|
|
319
626
|
},
|
|
320
627
|
importMnemonic: async (options) => {
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}, 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
|
+
});
|
|
330
636
|
this.sessionOf(created);
|
|
331
637
|
return created.wallet;
|
|
332
638
|
},
|
|
333
639
|
exportMnemonic: async (walletId, verify) => this.withVerifying(async () => {
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
const exported = await this.channel.call("wallet.exportMnemonic", {
|
|
337
|
-
verify: wireVerify,
|
|
640
|
+
const exported = await this.secretCall("wallet.exportMnemonic", async (wire) => ({
|
|
641
|
+
verify: await resolveVerifyFactor(this.factorSource, verify, wire),
|
|
338
642
|
walletId
|
|
339
|
-
}
|
|
643
|
+
}));
|
|
340
644
|
return {
|
|
341
645
|
mnemonic: new SingleUseSecret(exported.mnemonic),
|
|
342
646
|
...exported.passphrase === void 0 ? {} : { passphrase: new SingleUseSecret(exported.passphrase) }
|
|
343
647
|
};
|
|
344
648
|
}),
|
|
345
649
|
delete: async (walletId, verify) => this.withVerifying(async () => {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
await this.channel.call("wallet.delete", {
|
|
349
|
-
verify: wireVerify,
|
|
650
|
+
await this.secretCall("wallet.delete", async (wire) => ({
|
|
651
|
+
verify: await resolveVerifyFactor(this.factorSource, verify, wire),
|
|
350
652
|
walletId
|
|
351
|
-
}
|
|
653
|
+
}));
|
|
352
654
|
})
|
|
353
655
|
};
|
|
354
656
|
dataKeys = { get: async (purpose) => this.channel.call("dataKeys.get", { purpose }) };
|
|
355
657
|
backup = {
|
|
356
658
|
enable: async (options) => this.withVerifying(async () => {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
+
});
|
|
364
668
|
}),
|
|
365
669
|
update: async () => {
|
|
366
670
|
return (await this.channel.call("backup.update", null)).envelope;
|
|
367
671
|
},
|
|
368
|
-
disable: async () => {
|
|
369
|
-
await this.
|
|
370
|
-
},
|
|
672
|
+
disable: async (verify) => this.withVerifying(async () => {
|
|
673
|
+
await this.secretCall("backup.disable", async (wire) => ({ verify: await resolveVerifyFactor(this.factorSource, verify, wire) }));
|
|
674
|
+
}),
|
|
371
675
|
restore: async (options) => this.withVerifying(async () => {
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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
|
+
});
|
|
385
690
|
this.sessionOf(result);
|
|
386
691
|
return {
|
|
387
692
|
wallets: result.wallets,
|
|
@@ -399,6 +704,28 @@ var KernelWallet = class KernelWallet {
|
|
|
399
704
|
}
|
|
400
705
|
};
|
|
401
706
|
/**
|
|
707
|
+
* `keys.import`'s `secret` in bytes: a string is the family's canonical text encoding — `0x` hex
|
|
708
|
+
* for EVM, base58 for Solana, bare hex for TRON — while a Uint8Array passes straight through to the
|
|
709
|
+
* kernel's checks.
|
|
710
|
+
*/
|
|
711
|
+
function decodeKeySecret(family, secret) {
|
|
712
|
+
if (secret instanceof Uint8Array) return secret;
|
|
713
|
+
if (family === "evm") {
|
|
714
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(secret)) throw new WalletError("invalid-input", "an EVM private key is 0x-prefixed 64-hex");
|
|
715
|
+
return hex.decode(secret.slice(2));
|
|
716
|
+
}
|
|
717
|
+
if (family === "solana") try {
|
|
718
|
+
return base58.decode(secret);
|
|
719
|
+
} catch {
|
|
720
|
+
throw new WalletError("invalid-input", "a Solana private key is base58");
|
|
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
|
+
}
|
|
726
|
+
throw new WalletError("invalid-input", `keys are not supported on ${family}`);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
402
729
|
* Validates the passkey configuration: the RP identity and both PRF salts are permanent
|
|
403
730
|
* identifiers, so an empty or colliding value is rejected here rather than producing unrecoverable
|
|
404
731
|
* credentials later.
|
|
@@ -415,6 +742,6 @@ async function connectKernel(options) {
|
|
|
415
742
|
checkPasskeyConfig(options.passkey);
|
|
416
743
|
return KernelWallet.connect(options);
|
|
417
744
|
}
|
|
418
|
-
export { PASSKEY_PURPOSE_VAULT, PASSKEY_PURPOSE_WALLET, connectKernel };
|
|
745
|
+
export { MAX_IN_FLIGHT, PASSKEY_PURPOSE_VAULT, PASSKEY_PURPOSE_WALLET, connectKernel };
|
|
419
746
|
|
|
420
747
|
//# sourceMappingURL=host.mjs.map
|