@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/README.md
CHANGED
|
@@ -53,9 +53,19 @@ const event = await signer.signEvent({
|
|
|
53
53
|
import { useSyncExternalStore } from "react";
|
|
54
54
|
|
|
55
55
|
const snapshot = useSyncExternalStore(wallet.subscribe, wallet.getSnapshot);
|
|
56
|
-
// snapshot.vault: "uninitialized" | "locked" | "unlocked" | "corrupted"
|
|
56
|
+
// snapshot.vault: "uninitialized" | "locked" | "unlocked" | "corrupted" | "unsupported" | "unavailable"
|
|
57
|
+
// snapshot.lockReason: "cold-start" | "user" | "idle" | "background" | "expired" | "crashed" | "invalidated"
|
|
57
58
|
```
|
|
58
59
|
|
|
60
|
+
What to do with each vault state:
|
|
61
|
+
|
|
62
|
+
- `corrupted` — stored ciphertext or a public header failed authentication. Confirm it is real
|
|
63
|
+
(a reload that keeps reporting `corrupted`), then `wallet.vault.reset()` is the only way
|
|
64
|
+
forward and destroys the vault. Never reset on a single sighting.
|
|
65
|
+
- `unsupported` — the vault was written by a newer build. Update the app; do not reset.
|
|
66
|
+
- `unavailable` — the vault store failed transiently. Retry; the kernel retries a load on the
|
|
67
|
+
next request itself.
|
|
68
|
+
|
|
59
69
|
## Security notes
|
|
60
70
|
|
|
61
71
|
- Secrets (seed, keys, DEK, PRF output) exist only inside the kernel's Web Worker; the host
|
|
@@ -64,10 +74,39 @@ const snapshot = useSyncExternalStore(wallet.subscribe, wallet.getSnapshot);
|
|
|
64
74
|
against a compromised browser or device.
|
|
65
75
|
- Your CSP must allow the bundled worker: `worker-src 'self'` (the worker loads from your own
|
|
66
76
|
origin — a stricter policy breaks the wallet).
|
|
67
|
-
- Vite users: set `optimizeDeps.exclude: ["@qntx/wallet-worker"]` so the worker URL survives dev
|
|
77
|
+
- Vite users: set `optimizeDeps.exclude: ["@qntx/wallet-worker"]` so the worker URL survives dev;
|
|
78
|
+
production builds need nothing — `vite build` emits `kernel.worker.js` as an asset.
|
|
68
79
|
- `@qntx/wallet/host` is reserved for host packages — applications must not use it.
|
|
69
|
-
-
|
|
70
|
-
|
|
80
|
+
- `wallet.vault.lock()` resolves immediately and terminates the worker — it never waits on the
|
|
81
|
+
kernel queue. A kernel request that stalls at the head of the queue surfaces `crashed` after
|
|
82
|
+
60 s and the worker respawns; requests still queued behind it are not timed.
|
|
83
|
+
- Password unlock is rate-limited inside the kernel: five counted misses arm a backoff
|
|
84
|
+
(30 s → 60 s → 300 s), a `rate-limited` error carries `retryAt`, and retrying during backoff
|
|
85
|
+
does not push the deadline. Passkey unlocks are never gated by it.
|
|
86
|
+
- Sessions idle-lock after 5, 15 or 60 minutes (`autoLock.idleMinutes`, worker-enforced) with a
|
|
87
|
+
fixed 12-hour maximum, measured on a monotonic clock — a wall-clock jump can neither extend
|
|
88
|
+
nor shorten a session. On the Web only user presence refreshes the idle timer (input events
|
|
89
|
+
and tab visibility, throttled to one `session.touch` per 30 s); signing and other background
|
|
90
|
+
traffic cannot hold a session open. On Node every successful request counts.
|
|
91
|
+
- `WalletInfo.backup` tells the UI whether the wallet survives losing this device: `"mnemonic"`
|
|
92
|
+
(the user passed the quiz, imported a phrase, or exported it at least once — `exportMnemonic`
|
|
93
|
+
upgrades the record), `"passkey"` (a synced passkey — still lost with the password-manager
|
|
94
|
+
account, so prompt to export), or `"none"` (a device-bound passkey — lost with the device).
|
|
95
|
+
- Changing the password or removing a factor rotates the vault DEK: sessions in other tabs lock
|
|
96
|
+
with reason `invalidated` and must re-unlock. Adding a passkey factor keeps the current DEK.
|
|
97
|
+
- `passkey.rpId`, `walletSalt` and `vaultSalt` are permanent identifiers — changing any of them
|
|
98
|
+
makes every existing passkey factor and passkey-derived wallet unrecoverable, and the salts
|
|
99
|
+
must differ. Moving domains requires WebAuthn related origins (`/.well-known/webauthn`); offer
|
|
100
|
+
`exportMnemonic` for passkey-derived wallets so they survive an RP migration. `connectKernel`
|
|
101
|
+
rejects an empty or colliding config before the worker spawns.
|
|
102
|
+
- Standalone Nostr keys carry `backedUp`: imports start `true`, generated keys `false`, and a
|
|
103
|
+
successful `nostr.exportKey` marks the record — surface the flag so users actually back up.
|
|
104
|
+
`ncryptsec` always carries NIP-49 key-security byte `0x02` and its scrypt `logN` is capped
|
|
105
|
+
(18 on Web, 20 on Node); oversized values fail `unsupported` before scrypt runs.
|
|
106
|
+
- Requests are capped at 1 MiB on both sides of the channel; larger calls fail `invalid-input`
|
|
107
|
+
without reaching the kernel.
|
|
108
|
+
- `dist/kernel.manifest.json` in `@qntx/wallet-worker` records the protocol version, vault
|
|
109
|
+
format, pinned dependency versions/integrities and the SHA-256 of each kernel bundle.
|
|
71
110
|
|
|
72
111
|
## License
|
|
73
112
|
|
|
@@ -58,7 +58,7 @@ function obj(shape) {
|
|
|
58
58
|
return (value) => {
|
|
59
59
|
if (typeof value !== "object" || value === null || Array.isArray(value) || value instanceof Uint8Array) fail();
|
|
60
60
|
const record = value;
|
|
61
|
-
for (const key of Object.keys(record)) if (!(key
|
|
61
|
+
for (const key of Object.keys(record)) if (!Object.hasOwn(shape, key)) fail();
|
|
62
62
|
const out = {};
|
|
63
63
|
for (const key of keys) {
|
|
64
64
|
const field = shape[key];
|
|
@@ -67,13 +67,36 @@ function obj(shape) {
|
|
|
67
67
|
if (field instanceof Opt) {
|
|
68
68
|
if (raw !== void 0) out[key] = field.validator(raw);
|
|
69
69
|
} else {
|
|
70
|
-
if (!(key
|
|
70
|
+
if (!Object.hasOwn(record, key)) fail();
|
|
71
71
|
out[key] = field(raw);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
return out;
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
+
const FORBIDDEN_RECORD_KEYS = /* @__PURE__ */ new Set([
|
|
78
|
+
"__proto__",
|
|
79
|
+
"constructor",
|
|
80
|
+
"prototype"
|
|
81
|
+
]);
|
|
82
|
+
/**
|
|
83
|
+
* A `Record<K, V>` wire value: plain objects only, every key checked by `key`, every value by
|
|
84
|
+
* `value`, at most `max` entries. Prototype-polluting keys are rejected outright — a validated
|
|
85
|
+
* record must be safe to copy key-by-key.
|
|
86
|
+
*/
|
|
87
|
+
function record(key, value, max) {
|
|
88
|
+
return (input) => {
|
|
89
|
+
if (typeof input !== "object" || input === null || Array.isArray(input) || input instanceof Uint8Array || Object.getPrototypeOf(input) !== Object.prototype) fail();
|
|
90
|
+
const out = {};
|
|
91
|
+
const entries = Object.entries(input);
|
|
92
|
+
if (entries.length > max) fail();
|
|
93
|
+
for (const [name, item] of entries) {
|
|
94
|
+
if (FORBIDDEN_RECORD_KEYS.has(name)) fail();
|
|
95
|
+
out[key(name)] = value(item);
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
77
100
|
/** Tries each branch in order; the first match wins. */
|
|
78
101
|
function union(...branches) {
|
|
79
102
|
return (value) => {
|
|
@@ -115,6 +138,14 @@ const factor = union(obj({
|
|
|
115
138
|
credentialId: bytes(1, 1023),
|
|
116
139
|
prf: bytes(32)
|
|
117
140
|
}));
|
|
141
|
+
const backupFactor = union(obj({
|
|
142
|
+
kind: literal("password"),
|
|
143
|
+
password: bytes(1, 1024)
|
|
144
|
+
}), obj({
|
|
145
|
+
kind: literal("passkey"),
|
|
146
|
+
credentialId: bytes(1, 1023),
|
|
147
|
+
prfBackup: bytes(32)
|
|
148
|
+
}));
|
|
118
149
|
const factorInfo = union(obj({ kind: literal("hardware") }), obj({
|
|
119
150
|
kind: literal("passkey"),
|
|
120
151
|
id: sessionId,
|
|
@@ -129,32 +160,36 @@ const walletInfo = obj({
|
|
|
129
160
|
walletId,
|
|
130
161
|
origin: union(literal("passkey"), literal("mnemonic")),
|
|
131
162
|
words: union(literal(12), literal(15), literal(18), literal(21), literal(24)),
|
|
132
|
-
|
|
163
|
+
backup: union(literal("none"), literal("passkey"), literal("mnemonic")),
|
|
133
164
|
createdAt: safeTime
|
|
134
165
|
});
|
|
135
|
-
const walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-unavailable"), literal("factor-invalidated"), literal("wrong-password"), literal("rate-limited"), literal("invalid-input"), literal("not-found"), literal("already-exists"), literal("integrity"), literal("crashed"));
|
|
166
|
+
const walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-unavailable"), literal("factor-invalidated"), literal("wrong-password"), literal("wrong-passkey"), literal("rate-limited"), literal("invalid-input"), literal("not-found"), literal("already-exists"), literal("conflict"), literal("unsupported"), literal("unavailable"), literal("integrity"), literal("approval-required"), literal("crashed"));
|
|
136
167
|
const createdResult = obj({
|
|
137
168
|
wallet: walletInfo,
|
|
138
169
|
session: sessionId
|
|
139
170
|
});
|
|
140
171
|
const CORE_METHODS = {
|
|
172
|
+
"session.touch": {
|
|
173
|
+
session: true,
|
|
174
|
+
presence: true,
|
|
175
|
+
params: nullValue,
|
|
176
|
+
result: nullValue
|
|
177
|
+
},
|
|
141
178
|
"vault.unlock": {
|
|
142
179
|
session: false,
|
|
180
|
+
presence: true,
|
|
143
181
|
params: obj({ factor }),
|
|
144
182
|
result: obj({ session: sessionId })
|
|
145
183
|
},
|
|
146
|
-
"vault.lock": {
|
|
147
|
-
session: false,
|
|
148
|
-
params: nullValue,
|
|
149
|
-
result: nullValue
|
|
150
|
-
},
|
|
151
184
|
"vault.reset": {
|
|
152
185
|
session: false,
|
|
186
|
+
presence: false,
|
|
153
187
|
params: nullValue,
|
|
154
188
|
result: nullValue
|
|
155
189
|
},
|
|
156
190
|
"vault.addFactor": {
|
|
157
191
|
session: true,
|
|
192
|
+
presence: true,
|
|
158
193
|
params: obj({
|
|
159
194
|
verify: factor,
|
|
160
195
|
factor
|
|
@@ -163,6 +198,7 @@ const CORE_METHODS = {
|
|
|
163
198
|
},
|
|
164
199
|
"vault.removeFactor": {
|
|
165
200
|
session: true,
|
|
201
|
+
presence: true,
|
|
166
202
|
params: obj({
|
|
167
203
|
verify: factor,
|
|
168
204
|
id: sessionId
|
|
@@ -171,24 +207,29 @@ const CORE_METHODS = {
|
|
|
171
207
|
},
|
|
172
208
|
"wallet.createWithPasskey": {
|
|
173
209
|
session: false,
|
|
210
|
+
presence: true,
|
|
174
211
|
params: obj({
|
|
175
212
|
credentialId: bytes(1, 1023),
|
|
176
213
|
prfWallet: bytes(32),
|
|
214
|
+
synced: bool,
|
|
177
215
|
factor: opt(factor)
|
|
178
216
|
}),
|
|
179
217
|
result: createdResult
|
|
180
218
|
},
|
|
181
219
|
"wallet.restoreWithPasskey": {
|
|
182
220
|
session: false,
|
|
221
|
+
presence: true,
|
|
183
222
|
params: obj({
|
|
184
223
|
credentialId: bytes(1, 1023),
|
|
185
224
|
prfWallet: bytes(32),
|
|
225
|
+
synced: bool,
|
|
186
226
|
factor: opt(factor)
|
|
187
227
|
}),
|
|
188
228
|
result: createdResult
|
|
189
229
|
},
|
|
190
230
|
"wallet.createMnemonic": {
|
|
191
231
|
session: false,
|
|
232
|
+
presence: true,
|
|
192
233
|
params: obj({
|
|
193
234
|
words: union(literal(12), literal(24)),
|
|
194
235
|
factor: opt(factor)
|
|
@@ -201,6 +242,7 @@ const CORE_METHODS = {
|
|
|
201
242
|
},
|
|
202
243
|
"wallet.confirmMnemonic": {
|
|
203
244
|
session: false,
|
|
245
|
+
presence: true,
|
|
204
246
|
params: obj({
|
|
205
247
|
draft: draftId,
|
|
206
248
|
answers: arr(bytes(1, 64), 3, 3)
|
|
@@ -209,258 +251,79 @@ const CORE_METHODS = {
|
|
|
209
251
|
},
|
|
210
252
|
"wallet.discardMnemonic": {
|
|
211
253
|
session: false,
|
|
254
|
+
presence: false,
|
|
212
255
|
params: obj({ draft: draftId }),
|
|
213
256
|
result: nullValue
|
|
214
257
|
},
|
|
215
|
-
"
|
|
216
|
-
session: false,
|
|
217
|
-
params: obj({
|
|
218
|
-
mnemonic: bytes(1, 1024),
|
|
219
|
-
factor: opt(factor)
|
|
220
|
-
}),
|
|
221
|
-
result: createdResult
|
|
222
|
-
},
|
|
223
|
-
"wallet.exportMnemonic": {
|
|
224
|
-
session: true,
|
|
225
|
-
params: obj({
|
|
226
|
-
verify: factor,
|
|
227
|
-
walletId
|
|
228
|
-
}),
|
|
229
|
-
result: bytes(16, 1024)
|
|
230
|
-
},
|
|
231
|
-
"wallet.delete": {
|
|
258
|
+
"backup.enable": {
|
|
232
259
|
session: true,
|
|
260
|
+
presence: true,
|
|
233
261
|
params: obj({
|
|
234
262
|
verify: factor,
|
|
235
|
-
|
|
263
|
+
factors: arr(backupFactor, 5, 1)
|
|
236
264
|
}),
|
|
237
265
|
result: nullValue
|
|
238
266
|
},
|
|
239
|
-
"
|
|
240
|
-
session: true,
|
|
241
|
-
params: obj({ purpose: str(32, /^[a-z0-9-]{1,32}$/) }),
|
|
242
|
-
result: bytes(32)
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
//#endregion
|
|
246
|
-
//#region src/protocol/nostr.ts
|
|
247
|
-
const hex128 = str(128, /^[0-9a-f]{128}$/);
|
|
248
|
-
const nostrKeyInfo = obj({
|
|
249
|
-
ref: union(obj({
|
|
250
|
-
kind: literal("derived"),
|
|
251
|
-
walletId,
|
|
252
|
-
groupIndex
|
|
253
|
-
}), obj({
|
|
254
|
-
kind: literal("standalone"),
|
|
255
|
-
id: publicKey
|
|
256
|
-
}), obj({
|
|
257
|
-
kind: literal("nip46-client"),
|
|
258
|
-
id: publicKey
|
|
259
|
-
})),
|
|
260
|
-
publicKey,
|
|
261
|
-
origin: union(literal("derived"), literal("nsec"), literal("ncryptsec"), literal("generated"), literal("nip46-client")),
|
|
262
|
-
createdAt: safeTime
|
|
263
|
-
});
|
|
264
|
-
/** The nostr section of the status payload, composed by protocol/index.ts. */
|
|
265
|
-
const nostrStatus = obj({ keys: arr(nostrKeyInfo, MAX_SNAPSHOT_ITEMS) });
|
|
266
|
-
const keyResult = obj({
|
|
267
|
-
key: nostrKeyInfo,
|
|
268
|
-
session: sessionId
|
|
269
|
-
});
|
|
270
|
-
const derivedNostrKey = obj({
|
|
271
|
-
groupIndex,
|
|
272
|
-
publicKey
|
|
273
|
-
});
|
|
274
|
-
const tags = arr(arr(str(MAX_TAG_ITEM), 64), MAX_TAGS);
|
|
275
|
-
const signEventInput = obj({
|
|
276
|
-
kind: int(0, 65535),
|
|
277
|
-
created_at: safeTime,
|
|
278
|
-
tags,
|
|
279
|
-
content: str(MAX_TEXT),
|
|
280
|
-
pubkey: opt(publicKey)
|
|
281
|
-
});
|
|
282
|
-
const signedEvent = obj({
|
|
283
|
-
id: publicKey,
|
|
284
|
-
pubkey: publicKey,
|
|
285
|
-
sig: hex128,
|
|
286
|
-
kind: int(0, 65535),
|
|
287
|
-
created_at: safeTime,
|
|
288
|
-
tags,
|
|
289
|
-
content: str(MAX_TEXT)
|
|
290
|
-
});
|
|
291
|
-
const rumor = obj({
|
|
292
|
-
id: publicKey,
|
|
293
|
-
pubkey: publicKey,
|
|
294
|
-
kind: int(0, 65535),
|
|
295
|
-
created_at: safeTime,
|
|
296
|
-
tags,
|
|
297
|
-
content: str(MAX_TEXT)
|
|
298
|
-
});
|
|
299
|
-
const nostrImportInput = union(obj({
|
|
300
|
-
kind: literal("nsec"),
|
|
301
|
-
nsec: bytes(1, 256)
|
|
302
|
-
}), obj({
|
|
303
|
-
kind: literal("ncryptsec"),
|
|
304
|
-
ncryptsec: str(512, /^ncryptsec1/),
|
|
305
|
-
password: bytes(1, 1024)
|
|
306
|
-
}));
|
|
307
|
-
const nostrExportFormat = union(obj({ kind: literal("nsec") }), obj({
|
|
308
|
-
kind: literal("ncryptsec"),
|
|
309
|
-
password: bytes(1, 1024)
|
|
310
|
-
}));
|
|
311
|
-
const textParams = obj({
|
|
312
|
-
publicKey,
|
|
313
|
-
peer: publicKey,
|
|
314
|
-
text: str(MAX_TEXT)
|
|
315
|
-
});
|
|
316
|
-
const textResult = str(MAX_TEXT * 4);
|
|
317
|
-
const NOSTR_METHODS = {
|
|
318
|
-
"nostr.discover": {
|
|
267
|
+
"backup.update": {
|
|
319
268
|
session: true,
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
count: int(1, 20)
|
|
324
|
-
}),
|
|
325
|
-
result: obj({ keys: arr(derivedNostrKey, 20) })
|
|
269
|
+
presence: false,
|
|
270
|
+
params: nullValue,
|
|
271
|
+
result: obj({ envelope: str(4e6) })
|
|
326
272
|
},
|
|
327
|
-
"
|
|
273
|
+
"backup.disable": {
|
|
328
274
|
session: true,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}),
|
|
333
|
-
result: nostrKeyInfo
|
|
275
|
+
presence: true,
|
|
276
|
+
params: nullValue,
|
|
277
|
+
result: nullValue
|
|
334
278
|
},
|
|
335
|
-
"
|
|
279
|
+
"backup.restore": {
|
|
336
280
|
session: false,
|
|
281
|
+
presence: true,
|
|
337
282
|
params: obj({
|
|
338
|
-
|
|
283
|
+
envelope: str(4e6),
|
|
284
|
+
backupFactor,
|
|
339
285
|
factor: opt(factor)
|
|
340
286
|
}),
|
|
341
|
-
result:
|
|
287
|
+
result: obj({
|
|
288
|
+
wallets: arr(walletInfo, 1e3),
|
|
289
|
+
session: sessionId
|
|
290
|
+
})
|
|
342
291
|
},
|
|
343
|
-
"
|
|
292
|
+
"wallet.importMnemonic": {
|
|
344
293
|
session: false,
|
|
345
|
-
|
|
346
|
-
result: keyResult
|
|
347
|
-
},
|
|
348
|
-
"nostr.createNip46ClientKey": {
|
|
349
|
-
session: true,
|
|
350
|
-
params: nullValue,
|
|
351
|
-
result: nostrKeyInfo
|
|
352
|
-
},
|
|
353
|
-
"nostr.removeKey": {
|
|
354
|
-
session: true,
|
|
294
|
+
presence: true,
|
|
355
295
|
params: obj({
|
|
356
|
-
|
|
357
|
-
|
|
296
|
+
mnemonic: bytes(1, 1024),
|
|
297
|
+
factor: opt(factor)
|
|
358
298
|
}),
|
|
359
|
-
result:
|
|
299
|
+
result: createdResult
|
|
360
300
|
},
|
|
361
|
-
"
|
|
301
|
+
"wallet.exportMnemonic": {
|
|
362
302
|
session: true,
|
|
303
|
+
presence: true,
|
|
363
304
|
params: obj({
|
|
364
305
|
verify: factor,
|
|
365
|
-
|
|
366
|
-
format: nostrExportFormat
|
|
306
|
+
walletId
|
|
367
307
|
}),
|
|
368
|
-
result: bytes(16,
|
|
308
|
+
result: bytes(16, 1024)
|
|
369
309
|
},
|
|
370
|
-
"
|
|
310
|
+
"wallet.delete": {
|
|
371
311
|
session: true,
|
|
312
|
+
presence: true,
|
|
372
313
|
params: obj({
|
|
373
|
-
|
|
374
|
-
|
|
314
|
+
verify: factor,
|
|
315
|
+
walletId
|
|
375
316
|
}),
|
|
376
|
-
result:
|
|
377
|
-
},
|
|
378
|
-
"nostr.nip04Encrypt": {
|
|
379
|
-
session: true,
|
|
380
|
-
params: textParams,
|
|
381
|
-
result: textResult
|
|
382
|
-
},
|
|
383
|
-
"nostr.nip04Decrypt": {
|
|
384
|
-
session: true,
|
|
385
|
-
params: textParams,
|
|
386
|
-
result: textResult
|
|
387
|
-
},
|
|
388
|
-
"nostr.nip44Encrypt": {
|
|
389
|
-
session: true,
|
|
390
|
-
params: textParams,
|
|
391
|
-
result: textResult
|
|
392
|
-
},
|
|
393
|
-
"nostr.nip44Decrypt": {
|
|
394
|
-
session: true,
|
|
395
|
-
params: textParams,
|
|
396
|
-
result: textResult
|
|
317
|
+
result: nullValue
|
|
397
318
|
},
|
|
398
|
-
"
|
|
319
|
+
"dataKeys.get": {
|
|
399
320
|
session: true,
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}),
|
|
404
|
-
result: obj({ results: arr(union(obj({ ok: rumor }), obj({ err: walletErrorCode })), 256) })
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
//#endregion
|
|
408
|
-
//#region src/protocol/index.ts
|
|
409
|
-
const PROTOCOL_VERSION = 1;
|
|
410
|
-
/**
|
|
411
|
-
* Responses to requests whose `id` cannot be parsed (malformed envelope) carry id 0. Main-side
|
|
412
|
-
* request ids start at 1, so a `0` is never a real pending request.
|
|
413
|
-
*/
|
|
414
|
-
const UNATTRIBUTED_ID = 0;
|
|
415
|
-
/** Deep check that a structured-cloned value is a strict ProtocolValue (no cycles detected). */
|
|
416
|
-
function isProtocolValue(value) {
|
|
417
|
-
switch (typeof value) {
|
|
418
|
-
case "boolean":
|
|
419
|
-
case "string": return true;
|
|
420
|
-
case "number": return Number.isSafeInteger(value);
|
|
421
|
-
case "object": break;
|
|
422
|
-
default: return false;
|
|
321
|
+
presence: false,
|
|
322
|
+
params: obj({ purpose: str(32, /^[a-z0-9-]{1,32}$/) }),
|
|
323
|
+
result: bytes(32)
|
|
423
324
|
}
|
|
424
|
-
if (value === null || value instanceof Uint8Array) return true;
|
|
425
|
-
if (Array.isArray(value)) return value.every(isProtocolValue);
|
|
426
|
-
if (Object.getPrototypeOf(value) !== Object.prototype) return false;
|
|
427
|
-
return Object.values(value).every(isProtocolValue);
|
|
428
|
-
}
|
|
429
|
-
/** The status payload: core sections plus one object section per protocol module. */
|
|
430
|
-
const statusPayload = obj({
|
|
431
|
-
protocol: literal(1),
|
|
432
|
-
vault: union(literal("uninitialized"), literal("locked"), literal("unlocked"), literal("corrupted")),
|
|
433
|
-
factors: arr(factorInfo, MAX_SNAPSHOT_ITEMS),
|
|
434
|
-
wallets: arr(walletInfo, MAX_SNAPSHOT_ITEMS),
|
|
435
|
-
nostr: nostrStatus
|
|
436
|
-
});
|
|
437
|
-
const METHODS = {
|
|
438
|
-
status: {
|
|
439
|
-
session: false,
|
|
440
|
-
params: nullValue,
|
|
441
|
-
result: statusPayload
|
|
442
|
-
},
|
|
443
|
-
...CORE_METHODS,
|
|
444
|
-
...NOSTR_METHODS
|
|
445
325
|
};
|
|
446
|
-
const lockReason = union(literal("cold-start"), literal("user"), literal("idle"), literal("background"), literal("expired"), literal("crashed"));
|
|
447
|
-
const errorPayload = obj({
|
|
448
|
-
code: walletErrorCode,
|
|
449
|
-
retryAt: opt(safeTime)
|
|
450
|
-
});
|
|
451
|
-
/** Host-side validators: `kernelEvent` covers the two push messages. */
|
|
452
|
-
const kernelEvent = union(obj({
|
|
453
|
-
v: literal(1),
|
|
454
|
-
event: literal("status"),
|
|
455
|
-
status: statusPayload
|
|
456
|
-
}), obj({
|
|
457
|
-
v: literal(1),
|
|
458
|
-
event: literal("locked"),
|
|
459
|
-
reason: lockReason
|
|
460
|
-
}));
|
|
461
|
-
/** Validates the `err` payload of a response; `ok` is checked against `METHODS[m].result`. */
|
|
462
|
-
const responseError = errorPayload;
|
|
463
326
|
//#endregion
|
|
464
|
-
export { opt as _,
|
|
327
|
+
export { opt as C, validate as D, union as E, obj as S, str as T, bool as _, MAX_TEXT as a, literal as b, groupIndex as c, sessionId as d, walletErrorCode as f, arr as g, ValidationError as h, MAX_TAG_ITEM as i, publicKey as l, walletInfo as m, MAX_SNAPSHOT_ITEMS as n, factor as o, walletId as p, MAX_TAGS as r, factorInfo as s, CORE_METHODS as t, safeTime as u, bytes as v, record as w, nullValue as x, int as y };
|
|
465
328
|
|
|
466
|
-
//# sourceMappingURL=
|
|
329
|
+
//# sourceMappingURL=core-QJ66nLLG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-QJ66nLLG.mjs","names":[],"sources":["../src/protocol/validate.ts","../src/protocol/core.ts"],"sourcesContent":["/**\n * Strict validator combinators for the secret-area protocol. Both sides share them: the kernel\n * validates every request, the host validates every response. Anything that does not match is a\n * `ValidationError` — never a partially-accepted value.\n */\nimport type { NullValue } from \"./index.ts\";\n\nexport class ValidationError extends Error {\n override name = \"ValidationError\";\n}\n\nexport type Validator<T> = (value: unknown) => T;\n\nfunction fail(): never {\n throw new ValidationError();\n}\n\nexport function literal<T extends NullValue | boolean | number | string>(\n expected: T,\n): Validator<T> {\n return (value) => {\n if (value !== expected) {\n fail();\n }\n return expected;\n };\n}\n\nexport const nullValue: Validator<NullValue> = literal(null);\nexport const bool: Validator<boolean> = (value) => {\n if (typeof value !== \"boolean\") {\n fail();\n }\n return value;\n};\n\nexport function int(min: number, max: number): Validator<number> {\n return (value) => {\n if (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < min || value > max) {\n fail();\n }\n return value;\n };\n}\n\nexport function str(max: number, pattern?: RegExp): Validator<string> {\n return (value) => {\n if (\n typeof value !== \"string\" ||\n value.length > max ||\n (pattern !== undefined && !pattern.test(value))\n ) {\n fail();\n }\n return value;\n };\n}\n\nexport function bytes(min: number, max?: number): Validator<Uint8Array> {\n const high = max ?? min;\n return (value) => {\n if (!(value instanceof Uint8Array) || value.length < min || value.length > high) {\n fail();\n }\n return value;\n };\n}\n\nexport function arr<T>(item: Validator<T>, max: number, min = 0): Validator<ReadonlyArray<T>> {\n return (value) => {\n if (!Array.isArray(value) || value.length < min || value.length > max) {\n fail();\n }\n const out: T[] = [];\n for (const element of value) {\n out.push(item(element));\n }\n return out;\n };\n}\n\nclass Opt<T> {\n readonly validator: Validator<T>;\n\n constructor(validator: Validator<T>) {\n this.validator = validator;\n }\n}\n\nexport function opt<T>(validator: Validator<T>): Opt<T> {\n return new Opt(validator);\n}\n\ntype Field = Validator<unknown> | Opt<unknown>;\ntype Shape = Record<string, Field>;\n\ntype RequiredKeys<S extends Shape> = {\n readonly [K in keyof S as S[K] extends Opt<unknown> ? never : K]: S[K] extends Validator<infer T>\n ? T\n : never;\n};\ntype OptionalKeys<S extends Shape> = {\n readonly [K in keyof S as S[K] extends Opt<unknown> ? K : never]?: S[K] extends Opt<infer T>\n ? T\n : never;\n};\ntype ShapeResult<S extends Shape> = RequiredKeys<S> & OptionalKeys<S>;\n\n/** Exact key set: required keys present, optional keys allowed, nothing else. */\nexport function obj<S extends Shape>(shape: S): Validator<ShapeResult<S>> {\n const keys = Object.keys(shape);\n return (value) => {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n value instanceof Uint8Array\n ) {\n fail();\n }\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- narrowed to a plain object above\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (!Object.hasOwn(shape, key)) {\n fail();\n }\n }\n const out: Record<string, unknown> = {};\n for (const key of keys) {\n const field = shape[key];\n if (field === undefined) {\n fail();\n }\n const raw = record[key];\n if (field instanceof Opt) {\n if (raw !== undefined) {\n out[key] = field.validator(raw);\n }\n } else {\n if (!Object.hasOwn(record, key)) {\n fail();\n }\n out[key] = field(raw);\n }\n }\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the shape guarantees the keys\n return out as ShapeResult<S>;\n };\n}\n\nconst FORBIDDEN_RECORD_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * A `Record<K, V>` wire value: plain objects only, every key checked by `key`, every value by\n * `value`, at most `max` entries. Prototype-polluting keys are rejected outright — a validated\n * record must be safe to copy key-by-key.\n */\nexport function record<K extends string, V>(\n key: Validator<K>,\n value: Validator<V>,\n max: number,\n): Validator<Record<K, V>> {\n return (input) => {\n if (\n typeof input !== \"object\" ||\n input === null ||\n Array.isArray(input) ||\n input instanceof Uint8Array ||\n Object.getPrototypeOf(input) !== Object.prototype\n ) {\n fail();\n }\n const out: Record<string, V> = {};\n const entries = Object.entries(input);\n if (entries.length > max) {\n fail();\n }\n for (const [name, item] of entries) {\n if (FORBIDDEN_RECORD_KEYS.has(name)) {\n fail();\n }\n out[key(name)] = value(item);\n }\n return out;\n };\n}\n\n/** Tries each branch in order; the first match wins. */\nexport function union<Vs extends ReadonlyArray<Validator<unknown>>>(\n ...branches: Vs\n): Validator<ReturnType<Vs[number]>> {\n return (value) => {\n for (const branch of branches) {\n try {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- ReturnType of the branch union\n return branch(value) as ReturnType<Vs[number]>;\n } catch (error) {\n if (!(error instanceof ValidationError)) {\n throw error;\n }\n }\n }\n return fail();\n };\n}\n\n/** Validates a value and returns it, or undefined on a shape mismatch. */\nexport function validate<T>(validator: Validator<T>, value: unknown): T | undefined {\n try {\n return validator(value);\n } catch (error) {\n if (error instanceof ValidationError) {\n return undefined;\n }\n throw error;\n }\n}\n","/**\n * The core method table: vault, wallet and data-key commands — nothing protocol-specific. \"Create\n * or import\" commands (createWithPasskey/restoreWithPasskey/createMnemonic/importMnemonic) are\n * `session: false` here because the rule is dynamic: with an uninitialized vault they carry\n * `factor` and establish the vault in one commit; with an established vault `factor` must be absent\n * and a valid session is required.\n *\n * The shared wire validators (factor, wallet info, ids) live here too so the nostr module's table\n * can reuse them — `protocol/nostr.ts` imports only from this file.\n */\nimport type { FactorInfo, WalletErrorCode, WalletInfo } from \"../types.ts\";\nimport type { NullValue } from \"./index.ts\";\nimport type { Validator } from \"./validate.ts\";\nimport { arr, bool, bytes, int, literal, nullValue, obj, opt, str, union } from \"./validate.ts\";\n\nexport type MethodSpec<P, R> = {\n readonly session: boolean;\n /** Whether a successful call refreshes the idle timer — presence-bearing methods only. */\n readonly presence: boolean;\n readonly params: Validator<P>;\n readonly result: Validator<R>;\n};\n\n// Size caps (UTF-16 units for strings, bytes for Uint8Array). These bound individual fields; the\n// whole-request cap MAX_REQUEST_BYTES (protocol/index.ts) is enforced by host and kernel.\nexport const MAX_TEXT = 262_144;\nexport const MAX_TAGS = 1024;\nexport const MAX_TAG_ITEMS = 64;\nexport const MAX_TAG_ITEM = 4096;\nexport const MAX_BATCH = 64;\nexport const MAX_SNAPSHOT_ITEMS = 4096;\n\nexport const sessionId: Validator<string> = str(32, /^[0-9a-f]{32}$/);\nexport const draftId: Validator<string> = str(32, /^[0-9a-f]{32}$/);\nexport const walletId: Validator<string> = str(16, /^[0-9a-f]{16}$/);\nexport const publicKey: Validator<string> = str(64, /^[0-9a-f]{64}$/);\nexport const credentialId: Validator<string> = str(1364, /^[A-Za-z0-9_-]+$/);\nexport const safeTime: Validator<number> = int(0, Number.MAX_SAFE_INTEGER);\nexport const groupIndex: Validator<number> = int(0, 0x7fffffff);\n\nexport type Factor =\n | { readonly kind: \"password\"; readonly password: Uint8Array }\n | { readonly kind: \"passkey\"; readonly credentialId: Uint8Array; readonly prf: Uint8Array };\n\nexport const factor: Validator<Factor> = union(\n obj({ kind: literal(\"password\"), password: bytes(1, 1024) }),\n obj({ kind: literal(\"passkey\"), credentialId: bytes(1, 1023), prf: bytes(32) }),\n);\n\n/**\n * A backup-envelope factor: same shapes as `Factor`, except the passkey arm carries `prfBackup` —\n * the PRF evaluated over `backupSalt`, not the vault or wallet salt.\n */\nexport type BackupFactor =\n | { readonly kind: \"password\"; readonly password: Uint8Array }\n | {\n readonly kind: \"passkey\";\n readonly credentialId: Uint8Array;\n readonly prfBackup: Uint8Array;\n };\n\nexport const backupFactor: Validator<BackupFactor> = union(\n obj({ kind: literal(\"password\"), password: bytes(1, 1024) }),\n obj({ kind: literal(\"passkey\"), credentialId: bytes(1, 1023), prfBackup: bytes(32) }),\n);\n\nexport const factorInfo: Validator<FactorInfo> = union(\n obj({ kind: literal(\"hardware\") }),\n obj({\n kind: literal(\"passkey\"),\n id: sessionId,\n credentialId,\n createdAt: safeTime,\n }),\n obj({ kind: literal(\"password\"), id: sessionId, createdAt: safeTime }),\n);\n\nexport const walletInfo: Validator<WalletInfo> = obj({\n walletId,\n origin: union(literal(\"passkey\"), literal(\"mnemonic\")),\n words: union(literal(12), literal(15), literal(18), literal(21), literal(24)),\n backup: union(literal(\"none\"), literal(\"passkey\"), literal(\"mnemonic\")),\n createdAt: safeTime,\n});\n\nexport const walletErrorCode: Validator<WalletErrorCode> = union(\n literal(\"locked\"),\n literal(\"cancelled\"),\n literal(\"factor-unavailable\"),\n literal(\"factor-invalidated\"),\n literal(\"wrong-password\"),\n literal(\"wrong-passkey\"),\n literal(\"rate-limited\"),\n literal(\"invalid-input\"),\n literal(\"not-found\"),\n literal(\"already-exists\"),\n literal(\"conflict\"),\n literal(\"unsupported\"),\n literal(\"unavailable\"),\n literal(\"integrity\"),\n literal(\"approval-required\"),\n literal(\"crashed\"),\n);\n\n/**\n * The result of every \"create or import\" wallet command: the new wallet's public info plus the\n * session it opened. Creating a wallet derives no protocol keys — modules add keys separately.\n */\nexport type CreatedResult = {\n readonly wallet: WalletInfo;\n readonly session: string;\n};\n\nconst createdResult: Validator<CreatedResult> = obj({ wallet: walletInfo, session: sessionId });\n\n// `status` itself is a core method, but its result validator composes every module's status\n// section — it is wired in protocol/index.ts, not here.\nexport const CORE_METHODS: {\n readonly \"vault.unlock\": MethodSpec<{ readonly factor: Factor }, { readonly session: string }>;\n readonly \"vault.reset\": MethodSpec<NullValue, NullValue>;\n readonly \"vault.addFactor\": MethodSpec<\n { readonly verify: Factor; readonly factor: Factor },\n FactorInfo\n >;\n readonly \"vault.removeFactor\": MethodSpec<\n { readonly verify: Factor; readonly id: string },\n NullValue\n >;\n readonly \"session.touch\": MethodSpec<NullValue, NullValue>;\n readonly \"wallet.createWithPasskey\": MethodSpec<\n {\n readonly credentialId: Uint8Array;\n readonly prfWallet: Uint8Array;\n readonly synced: boolean;\n readonly factor?: Factor;\n },\n CreatedResult\n >;\n readonly \"wallet.restoreWithPasskey\": MethodSpec<\n {\n readonly credentialId: Uint8Array;\n readonly prfWallet: Uint8Array;\n readonly synced: boolean;\n readonly factor?: Factor;\n },\n CreatedResult\n >;\n readonly \"wallet.createMnemonic\": MethodSpec<\n { readonly words: 12 | 24; readonly factor?: Factor },\n { readonly draft: string; readonly words: Uint8Array; readonly quiz: ReadonlyArray<number> }\n >;\n readonly \"wallet.confirmMnemonic\": MethodSpec<\n { readonly draft: string; readonly answers: ReadonlyArray<Uint8Array> },\n CreatedResult\n >;\n readonly \"wallet.discardMnemonic\": MethodSpec<{ readonly draft: string }, NullValue>;\n readonly \"backup.enable\": MethodSpec<\n {\n readonly verify: Factor;\n readonly factors: ReadonlyArray<BackupFactor>;\n },\n NullValue\n >;\n readonly \"backup.update\": MethodSpec<NullValue, { readonly envelope: string }>;\n readonly \"backup.disable\": MethodSpec<NullValue, NullValue>;\n readonly \"backup.restore\": MethodSpec<\n {\n readonly envelope: string;\n readonly backupFactor: BackupFactor;\n readonly factor?: Factor;\n },\n { readonly wallets: ReadonlyArray<WalletInfo>; readonly session: string }\n >;\n readonly \"wallet.importMnemonic\": MethodSpec<\n { readonly mnemonic: Uint8Array; readonly factor?: Factor },\n CreatedResult\n >;\n readonly \"wallet.exportMnemonic\": MethodSpec<\n { readonly verify: Factor; readonly walletId: string },\n Uint8Array\n >;\n readonly \"wallet.delete\": MethodSpec<\n { readonly verify: Factor; readonly walletId: string },\n NullValue\n >;\n readonly \"dataKeys.get\": MethodSpec<{ readonly purpose: string }, Uint8Array>;\n} = {\n \"session.touch\": {\n session: true,\n presence: true,\n params: nullValue,\n result: nullValue,\n },\n \"vault.unlock\": {\n session: false,\n presence: true,\n params: obj({ factor }),\n result: obj({ session: sessionId }),\n },\n \"vault.reset\": { session: false, presence: false, params: nullValue, result: nullValue },\n \"vault.addFactor\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, factor }),\n result: factorInfo,\n },\n \"vault.removeFactor\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, id: sessionId }),\n result: nullValue,\n },\n \"wallet.createWithPasskey\": {\n session: false,\n presence: true,\n params: obj({\n credentialId: bytes(1, 1023),\n prfWallet: bytes(32),\n synced: bool,\n factor: opt(factor),\n }),\n result: createdResult,\n },\n \"wallet.restoreWithPasskey\": {\n session: false,\n presence: true,\n params: obj({\n credentialId: bytes(1, 1023),\n prfWallet: bytes(32),\n synced: bool,\n factor: opt(factor),\n }),\n result: createdResult,\n },\n \"wallet.createMnemonic\": {\n session: false,\n presence: true,\n params: obj({ words: union(literal(12), literal(24)), factor: opt(factor) }),\n result: obj({\n draft: draftId,\n words: bytes(16, 1024),\n quiz: arr(int(0, 23), 3, 3),\n }),\n },\n \"wallet.confirmMnemonic\": {\n session: false,\n presence: true,\n params: obj({ draft: draftId, answers: arr(bytes(1, 64), 3, 3) }),\n result: createdResult,\n },\n \"wallet.discardMnemonic\": {\n session: false,\n presence: false,\n params: obj({ draft: draftId }),\n result: nullValue,\n },\n \"backup.enable\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, factors: arr(backupFactor, 5, 1) }),\n result: nullValue,\n },\n \"backup.update\": {\n session: true,\n presence: false,\n params: nullValue,\n result: obj({ envelope: str(4_000_000) }),\n },\n \"backup.disable\": {\n session: true,\n presence: true,\n params: nullValue,\n result: nullValue,\n },\n \"backup.restore\": {\n session: false,\n presence: true,\n params: obj({ envelope: str(4_000_000), backupFactor, factor: opt(factor) }),\n result: obj({ wallets: arr(walletInfo, 1000), session: sessionId }),\n },\n \"wallet.importMnemonic\": {\n session: false,\n presence: true,\n params: obj({ mnemonic: bytes(1, 1024), factor: opt(factor) }),\n result: createdResult,\n },\n \"wallet.exportMnemonic\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, walletId }),\n result: bytes(16, 1024),\n },\n \"wallet.delete\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, walletId }),\n result: nullValue,\n },\n \"dataKeys.get\": {\n session: true,\n presence: false,\n params: obj({ purpose: str(32, /^[a-z0-9-]{1,32}$/) }),\n result: bytes(32),\n },\n};\n"],"mappings":";AAOA,IAAa,kBAAb,cAAqC,MAAM;CACzC,OAAgB;AAClB;AAIA,SAAS,OAAc;CACrB,MAAM,IAAI,gBAAgB;AAC5B;AAEA,SAAgB,QACd,UACc;CACd,QAAQ,UAAU;EAChB,IAAI,UAAU,UACZ,KAAK;EAEP,OAAO;CACT;AACF;AAEA,MAAa,YAAkC,QAAQ,IAAI;AAC3D,MAAa,QAA4B,UAAU;CACjD,IAAI,OAAO,UAAU,WACnB,KAAK;CAEP,OAAO;AACT;AAEA,SAAgB,IAAI,KAAa,KAAgC;CAC/D,QAAQ,UAAU;EAChB,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,OAAO,QAAQ,KACtF,KAAK;EAEP,OAAO;CACT;AACF;AAEA,SAAgB,IAAI,KAAa,SAAqC;CACpE,QAAQ,UAAU;EAChB,IACE,OAAO,UAAU,YACjB,MAAM,SAAS,OACd,YAAY,KAAA,KAAa,CAAC,QAAQ,KAAK,KAAK,GAE7C,KAAK;EAEP,OAAO;CACT;AACF;AAEA,SAAgB,MAAM,KAAa,KAAqC;CACtE,MAAM,OAAO,OAAO;CACpB,QAAQ,UAAU;EAChB,IAAI,EAAE,iBAAiB,eAAe,MAAM,SAAS,OAAO,MAAM,SAAS,MACzE,KAAK;EAEP,OAAO;CACT;AACF;AAEA,SAAgB,IAAO,MAAoB,KAAa,MAAM,GAAgC;CAC5F,QAAQ,UAAU;EAChB,IAAI,CAAC,MAAM,QAAQ,KAAK,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;GAAQ,SAAS,IAAI,cAAc,GAAG,CAAC;EAAE,CAAC;EAChE,QAAQ;CACV;CACA,iBAAiB;EACf,SAAS;EACT,UAAU;EACV,QAAQ;EACR,QAAQ,IAAI,EAAE,UAAU,IAAI,GAAS,EAAE,CAAC;CAC1C;CACA,kBAAkB;EAChB,SAAS;EACT,UAAU;EACV,QAAQ;EACR,QAAQ;CACV;CACA,kBAAkB;EAChB,SAAS;EACT,UAAU;EACV,QAAQ,IAAI;GAAE,UAAU,IAAI,GAAS;GAAG;GAAc,QAAQ,IAAI,MAAM;EAAE,CAAC;EAC3E,QAAQ,IAAI;GAAE,SAAS,IAAI,YAAY,GAAI;GAAG,SAAS;EAAU,CAAC;CACpE;CACA,yBAAyB;EACvB,SAAS;EACT,UAAU;EACV,QAAQ,IAAI;GAAE,UAAU,MAAM,GAAG,IAAI;GAAG,QAAQ,IAAI,MAAM;EAAE,CAAC;EAC7D,QAAQ;CACV;CACA,yBAAyB;EACvB,SAAS;EACT,UAAU;EACV,QAAQ,IAAI;GAAE,QAAQ;GAAQ;EAAS,CAAC;EACxC,QAAQ,MAAM,IAAI,IAAI;CACxB;CACA,iBAAiB;EACf,SAAS;EACT,UAAU;EACV,QAAQ,IAAI;GAAE,QAAQ;GAAQ;EAAS,CAAC;EACxC,QAAQ;CACV;CACA,gBAAgB;EACd,SAAS;EACT,UAAU;EACV,QAAQ,IAAI,EAAE,SAAS,IAAI,IAAI,mBAAmB,EAAE,CAAC;EACrD,QAAQ,MAAM,EAAE;CAClB;AACF"}
|
package/dist/host.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { p as PasskeyConfig, v as Wallet } from "./types-D4OUjGVS.mjs";
|
|
2
|
+
import { u as ProtocolValue } from "./index-Dhf6wGjQ.mjs";
|
|
3
3
|
//#region src/channel.d.ts
|
|
4
4
|
/** The host packages' side of the kernel channel (worker, JSI runtime, in-process test port). */
|
|
5
5
|
type MainPort = {
|
|
@@ -8,16 +8,25 @@ type MainPort = {
|
|
|
8
8
|
readonly onExit: (handler: () => void) => () => void;
|
|
9
9
|
readonly terminate: () => void;
|
|
10
10
|
};
|
|
11
|
+
/** Schedules `fn` after `delayMs` and returns a cancel function — injected by the host package. */
|
|
12
|
+
type SetTimer = (delayMs: number, fn: () => void) => () => void;
|
|
11
13
|
//#endregion
|
|
12
14
|
//#region src/factors.d.ts
|
|
13
15
|
type PrfSalts = {
|
|
14
16
|
readonly first: Uint8Array;
|
|
15
17
|
readonly second?: Uint8Array;
|
|
16
18
|
};
|
|
19
|
+
/** Purpose bytes stamped into the first byte of a credential's WebAuthn user handle. */
|
|
20
|
+
export declare const PASSKEY_PURPOSE_WALLET = 1;
|
|
21
|
+
export declare const PASSKEY_PURPOSE_VAULT = 2;
|
|
17
22
|
type PrfResult = {
|
|
18
23
|
readonly credentialId: Uint8Array;
|
|
19
24
|
readonly first: Uint8Array;
|
|
20
25
|
readonly second?: Uint8Array;
|
|
26
|
+
/** The assertion's `userHandle` — its first byte declares the credential's purpose. */
|
|
27
|
+
readonly userHandle?: Uint8Array;
|
|
28
|
+
/** The credential survives this device: the authenticator data's BE and BS flags are both set. */
|
|
29
|
+
readonly synced: boolean;
|
|
21
30
|
};
|
|
22
31
|
/**
|
|
23
32
|
* The WebAuthn ceremony the host performs. Implementations throw `WalletError` — "cancelled" when
|
|
@@ -41,6 +50,13 @@ type ConnectOptions = {
|
|
|
41
50
|
readonly spawn: () => MainPort;
|
|
42
51
|
readonly passkey: PasskeyConfig;
|
|
43
52
|
readonly ceremony: PasskeyCeremony | undefined;
|
|
53
|
+
/** Timer source injected by the host package (globalThis timers on web/node). */
|
|
54
|
+
readonly setTimer: SetTimer;
|
|
55
|
+
/**
|
|
56
|
+
* User-presence source: subscribes to activity signals and returns an unsubscribe the wallet
|
|
57
|
+
* owns. Absent means the host has no presence signals (the kernel policy decides what counts).
|
|
58
|
+
*/
|
|
59
|
+
readonly presence?: (onActivity: () => void) => () => void;
|
|
44
60
|
/** Runs once inside `destroy()` — host-side cleanup (page listeners, timers). */
|
|
45
61
|
readonly onDestroy?: () => void;
|
|
46
62
|
};
|
|
@@ -50,5 +66,5 @@ type ConnectOptions = {
|
|
|
50
66
|
*/
|
|
51
67
|
export declare function connectKernel(options: ConnectOptions): Promise<Wallet>;
|
|
52
68
|
//#endregion
|
|
53
|
-
export type { ConnectOptions, MainPort, PasskeyCeremony, PrfResult, PrfSalts };
|
|
69
|
+
export type { ConnectOptions, MainPort, PasskeyCeremony, PrfResult, PrfSalts, SetTimer };
|
|
54
70
|
//# sourceMappingURL=host.d.mts.map
|