@evolustr/signer 0.0.0-stage → 0.1.1
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 +29 -2
- package/dist/adapters.d.ts +55 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +52 -0
- package/dist/adapters.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/signer.d.ts +235 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +715 -0
- package/dist/signer.js.map +1 -0
- package/package.json +41 -4
- package/src/adapters.ts +104 -0
- package/src/index.ts +2 -0
- package/src/signer.ts +923 -0
package/dist/signer.js
ADDED
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@evolustr/signer` (SPEC §5): the signer side of Evolustr, embedded by a
|
|
3
|
+
* host signer (iframe signer, browser extension, NIP-46 bunker, Android signer).
|
|
4
|
+
*
|
|
5
|
+
* The host supplies what only it knows: who is calling, how to sign, its nsec
|
|
6
|
+
* (if it holds one), and how to ask the user. Everything else lives here.
|
|
7
|
+
*/
|
|
8
|
+
import { MASTER_SECRET_LENGTH, VAULT_KIND, appIdFromOrigin, bytesEqual, error, fromHex, hmacSha256, signerWrapAuthKey, signerMId, signerPreviousKey, signerRotateKey, toHex, fetchReplaceable, isProtectedDTag, ok, open, publishReplaceable, randomBytes as defaultRandomBytes, seal, sha256, utf8, signerAppKey, hostSecret, isHostSecretLabel, signerId as computeSignerId, signerPasskeyWrapKey, signerPrfInput, signerSkWrapKey, signerVaultDTag, signerWrapAad, toBase64Url, } from "@evolustr/core";
|
|
9
|
+
/** How many earlier Ms a signer vault keeps (`previous` plus `older`, #58). */
|
|
10
|
+
export const MAX_PREVIOUS_MASTERS = 16;
|
|
11
|
+
export const METHODS = ["evolustr_capabilities", "evolustr_get_wrap_key", "evolustr_get_previous_wrap_key", "evolustr_enroll_passkey"];
|
|
12
|
+
// ── Pure helpers ────────────────────────────────────────────────────────────
|
|
13
|
+
const isRecord = (x) => typeof x === "object" && x !== null;
|
|
14
|
+
export const parseSignerVault = (json) => {
|
|
15
|
+
let data;
|
|
16
|
+
try {
|
|
17
|
+
data = JSON.parse(json);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return error("invalidSignerVault", "Not JSON");
|
|
21
|
+
}
|
|
22
|
+
if (!isRecord(data) || data["v"] !== 1 || !Array.isArray(data["wraps"])) {
|
|
23
|
+
return error("invalidSignerVault", "Unknown format");
|
|
24
|
+
}
|
|
25
|
+
const wraps = [];
|
|
26
|
+
for (const w of data["wraps"]) {
|
|
27
|
+
// A malformed wrap is an error, never skipped: republishing without it
|
|
28
|
+
// would drop someone's way to unlock M (#28).
|
|
29
|
+
if (!isRecord(w) || typeof w["iv"] !== "string" || typeof w["ct"] !== "string") {
|
|
30
|
+
return error("invalidSignerVault", "Malformed wrap");
|
|
31
|
+
}
|
|
32
|
+
if (w["tag"] !== undefined && typeof w["tag"] !== "string")
|
|
33
|
+
return error("invalidSignerVault", "Malformed wrap");
|
|
34
|
+
const sealed = { iv: w["iv"], ct: w["ct"], ...(typeof w["tag"] === "string" ? { tag: w["tag"] } : {}) };
|
|
35
|
+
if (w["type"] === "sk")
|
|
36
|
+
wraps.push({ type: "sk", ...sealed });
|
|
37
|
+
else if (w["type"] === "passkey" && typeof w["rpId"] === "string" && typeof w["credId"] === "string") {
|
|
38
|
+
wraps.push({
|
|
39
|
+
type: "passkey",
|
|
40
|
+
rpId: w["rpId"],
|
|
41
|
+
credId: w["credId"],
|
|
42
|
+
...(typeof w["synced"] === "boolean" ? { synced: w["synced"] } : {}),
|
|
43
|
+
...sealed,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
return error("invalidSignerVault", "Unknown wrap type");
|
|
48
|
+
}
|
|
49
|
+
const dropped = data["skDroppedAt"];
|
|
50
|
+
if (dropped !== undefined && (typeof dropped !== "number" || !Number.isFinite(dropped))) {
|
|
51
|
+
return error("invalidSignerVault", "Malformed skDroppedAt");
|
|
52
|
+
}
|
|
53
|
+
const mId = data["mId"];
|
|
54
|
+
const rotatedFrom = data["rotatedFrom"];
|
|
55
|
+
const previous = data["previous"];
|
|
56
|
+
const older = data["older"];
|
|
57
|
+
if (mId !== undefined && typeof mId !== "string")
|
|
58
|
+
return error("invalidSignerVault", "Malformed mId");
|
|
59
|
+
if (rotatedFrom !== undefined && !(isRecord(rotatedFrom) && typeof rotatedFrom["mId"] === "string" && typeof rotatedFrom["proof"] === "string")) {
|
|
60
|
+
return error("invalidSignerVault", "Malformed rotatedFrom");
|
|
61
|
+
}
|
|
62
|
+
if (previous !== undefined && !isPreviousMaster(previous))
|
|
63
|
+
return error("invalidSignerVault", "Malformed previous");
|
|
64
|
+
if (older !== undefined && !(Array.isArray(older) && older.length < MAX_PREVIOUS_MASTERS && older.every(isPreviousMaster))) {
|
|
65
|
+
return error("invalidSignerVault", "Malformed older");
|
|
66
|
+
}
|
|
67
|
+
const extra = {
|
|
68
|
+
...(typeof mId === "string" ? { mId } : {}),
|
|
69
|
+
...(isRecord(rotatedFrom) ? { rotatedFrom: { mId: rotatedFrom["mId"], proof: rotatedFrom["proof"] } } : {}),
|
|
70
|
+
...(isPreviousMaster(previous) ? { previous: previousMaster(previous) } : {}),
|
|
71
|
+
...(isPreviousMaster(previous) && Array.isArray(older) && older.length > 0 ? { older: older.map(previousMaster) } : {}),
|
|
72
|
+
};
|
|
73
|
+
// A vault that exists but has no wraps isn't "first use" (#28).
|
|
74
|
+
if (wraps.length === 0)
|
|
75
|
+
return error("invalidSignerVault", "The signer vault has no wraps");
|
|
76
|
+
if (wraps.length > MAX_SIGNER_WRAPS)
|
|
77
|
+
return error("invalidSignerVault", "Too many wraps");
|
|
78
|
+
return ok({ v: 1, wraps, ...(typeof dropped === "number" ? { skDroppedAt: dropped } : {}), ...extra });
|
|
79
|
+
};
|
|
80
|
+
const isPreviousMaster = (x) => isRecord(x) && typeof x["mId"] === "string" && typeof x["iv"] === "string" && typeof x["ct"] === "string";
|
|
81
|
+
const previousMaster = (x) => ({ mId: x.mId, iv: x.iv, ct: x.ct });
|
|
82
|
+
const wrapId = (w) => (w.type === "sk" ? "sk" : w.credId);
|
|
83
|
+
export const MAX_SIGNER_WRAPS = 32;
|
|
84
|
+
/** Above this many wraps, untagged ones are dropped once M is unlocked (#54). */
|
|
85
|
+
export const UNTAGGED_SIGNER_WRAP_LIMIT = 16;
|
|
86
|
+
/**
|
|
87
|
+
* Union of two signer vaults by wrap id; `local` wins on the same id (#41).
|
|
88
|
+
* With `dropSk`, `sk` wraps are left out (#52): a relay vault without one is
|
|
89
|
+
* never "healed" back to one by a device that may not use it.
|
|
90
|
+
*/
|
|
91
|
+
export const mergeSignerVaults = (local, fetched, opts) => {
|
|
92
|
+
const byId = new Map();
|
|
93
|
+
const keep = (w) => opts?.dropSk !== true || w.type !== "sk";
|
|
94
|
+
for (const w of local.wraps)
|
|
95
|
+
if (keep(w))
|
|
96
|
+
byId.set(`${w.type}:${wrapId(w)}`, w);
|
|
97
|
+
for (const w of fetched.wraps) {
|
|
98
|
+
const k = `${w.type}:${wrapId(w)}`;
|
|
99
|
+
if (keep(w) && !byId.has(k) && byId.size < MAX_SIGNER_WRAPS)
|
|
100
|
+
byId.set(k, w);
|
|
101
|
+
}
|
|
102
|
+
const dropped = Math.max(local.skDroppedAt ?? -1, fetched.skDroppedAt ?? -1);
|
|
103
|
+
const mId = local.mId ?? fetched.mId;
|
|
104
|
+
const rotatedFrom = local.rotatedFrom ?? fetched.rotatedFrom;
|
|
105
|
+
const previous = local.previous ?? fetched.previous;
|
|
106
|
+
// The chain behind that previous M: the longer of the two sides that have it (#58).
|
|
107
|
+
const olderOf = (v) => (v.previous?.mId === previous?.mId ? (v.older ?? []) : []);
|
|
108
|
+
const [a, b] = [olderOf(local), olderOf(fetched)];
|
|
109
|
+
const older = b.length > a.length ? b : a;
|
|
110
|
+
return {
|
|
111
|
+
v: 1,
|
|
112
|
+
wraps: [...byId.values()],
|
|
113
|
+
...(dropped >= 0 ? { skDroppedAt: dropped } : {}),
|
|
114
|
+
...(mId === undefined ? {} : { mId }),
|
|
115
|
+
...(rotatedFrom === undefined ? {} : { rotatedFrom }),
|
|
116
|
+
...(previous === undefined ? {} : { previous }),
|
|
117
|
+
...(previous === undefined || older.length === 0 ? {} : { older }),
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
/** Two versions of the signer vault hold different master secrets: never merge them (#52 phase B). */
|
|
121
|
+
export const differentMaster = (a, b) => (a.mId !== undefined && b.mId !== undefined && a.mId !== b.mId) ||
|
|
122
|
+
(b.rotatedFrom !== undefined && a.mId !== b.mId) ||
|
|
123
|
+
(a.rotatedFrom !== undefined && a.mId !== b.mId);
|
|
124
|
+
/** Proof that the M behind `oldMId` authorised `newMId` (#52 phase B). */
|
|
125
|
+
export const masterRotationProof = (oldM, newMId) => toHex(hmacSha256(signerRotateKey(oldM), utf8(newMId)));
|
|
126
|
+
const rotationValid = (v, oldM) => {
|
|
127
|
+
if (v.rotatedFrom === undefined || v.mId === undefined || v.rotatedFrom.mId !== signerMId(oldM))
|
|
128
|
+
return false;
|
|
129
|
+
const expected = fromHex(masterRotationProof(oldM, v.mId));
|
|
130
|
+
const given = fromHex(v.rotatedFrom.proof);
|
|
131
|
+
return expected !== null && given !== null && bytesEqual(expected, given);
|
|
132
|
+
};
|
|
133
|
+
/** HMAC tag of a signer-vault wrap under a key derived from M (#54). Covers `synced` too. */
|
|
134
|
+
export const signerWrapTag = (pubkey, signerKey, m, w) => {
|
|
135
|
+
const id = w.type === "sk" ? "sk" : w.credId;
|
|
136
|
+
const extra = w.type === "passkey" ? `${w.rpId}|${w.synced === undefined ? "" : String(w.synced)}` : "|";
|
|
137
|
+
const message = `${signerWrapAad(pubkey, signerKey, w.type, id)}|${extra}|${w.iv}|${w.ct}`;
|
|
138
|
+
return toHex(hmacSha256(signerWrapAuthKey(m), utf8(message)));
|
|
139
|
+
};
|
|
140
|
+
const tagValid = (pubkey, signerKey, m, w) => {
|
|
141
|
+
if (w.tag === undefined)
|
|
142
|
+
return false;
|
|
143
|
+
const { tag, ...rest } = w;
|
|
144
|
+
const expected = fromHex(signerWrapTag(pubkey, signerKey, m, rest));
|
|
145
|
+
const given = fromHex(tag);
|
|
146
|
+
return expected !== null && given !== null && bytesEqual(expected, given);
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Once M is known (#54): drops wraps whose tag is wrong. Untagged wraps from
|
|
150
|
+
* older versions are kept, unless the vault has more than
|
|
151
|
+
* {@link UNTAGGED_SIGNER_WRAP_LIMIT} wraps: then only the one just opened stays.
|
|
152
|
+
*/
|
|
153
|
+
export const pruneSignerVault = (vault, pubkey, signerKey, m, openedId) => {
|
|
154
|
+
const kept = vault.wraps.filter((w) => w.tag === undefined || tagValid(pubkey, signerKey, m, w));
|
|
155
|
+
const wraps = kept.length > UNTAGGED_SIGNER_WRAP_LIMIT
|
|
156
|
+
? kept.filter((w) => w.tag !== undefined || `${w.type}:${wrapId(w)}` === openedId)
|
|
157
|
+
: kept;
|
|
158
|
+
return { ...vault, wraps };
|
|
159
|
+
};
|
|
160
|
+
const PACKAGE_NAME = /^[A-Za-z][\w]*(\.[A-Za-z][\w]*)+$/;
|
|
161
|
+
const HEX_PUBKEY = /^[0-9a-f]{64}$/;
|
|
162
|
+
/** App identity from the caller only (SPEC §5.2); insecure or malformed callers get none (#30). */
|
|
163
|
+
export const appIdForCaller = (caller, knownNsiteGateways = []) => {
|
|
164
|
+
if (caller.identity === "connection") {
|
|
165
|
+
return HEX_PUBKEY.test(caller.clientPubkey) ? ok(`nip46:${caller.clientPubkey}`) : error("invalidCaller", "Bad client pubkey");
|
|
166
|
+
}
|
|
167
|
+
if ("androidPackage" in caller) {
|
|
168
|
+
return PACKAGE_NAME.test(caller.androidPackage) ? ok(`android:${caller.androidPackage}`) : error("invalidCaller", "Bad package name");
|
|
169
|
+
}
|
|
170
|
+
return appIdFromOrigin(caller.origin, knownNsiteGateways);
|
|
171
|
+
};
|
|
172
|
+
export const isProtectedEvent = (event) => event.kind === VAULT_KIND && event.tags.some((t) => t[0] === "d" && typeof t[1] === "string" && isProtectedDTag(t[1]));
|
|
173
|
+
// ── Implementation ──────────────────────────────────────────────────────────
|
|
174
|
+
export const createEvolustrSigner = (host) => {
|
|
175
|
+
const now = host.now ?? (() => Math.floor(Date.now() / 1000));
|
|
176
|
+
const random = host.randomBytes ?? defaultRandomBytes;
|
|
177
|
+
const timeoutMs = host.timeoutMs ?? 5000;
|
|
178
|
+
const allowSk = () => (typeof host.allowSkWrap === "function" ? host.allowSkWrap() : host.allowSkWrap !== false);
|
|
179
|
+
let m = null;
|
|
180
|
+
let vault = null;
|
|
181
|
+
/** True once the signer vault was read from the relays this session (#40). */
|
|
182
|
+
let vaultLoaded = false;
|
|
183
|
+
/** That read waited for every relay, not a quorum (#62): safe to write on top of. */
|
|
184
|
+
let vaultFull = false;
|
|
185
|
+
/** The relays lack wraps the local copy has (#41); fixed after an approved key request. */
|
|
186
|
+
let needsHeal = false;
|
|
187
|
+
let lastEventAt = 0;
|
|
188
|
+
/** A relay vault with another M than the local copy, checked once M is known (#52 phase B). */
|
|
189
|
+
let candidate = null;
|
|
190
|
+
/** The previous M after a rotation, for old app keys. */
|
|
191
|
+
let previousM = null;
|
|
192
|
+
/** Every earlier M opened from the vault, newest first (#58); null until read. */
|
|
193
|
+
let earlierMs = null;
|
|
194
|
+
const appIdFor = (caller) => appIdForCaller(caller, host.knownNsiteGateways);
|
|
195
|
+
/** `full`: wait for every relay, for a read a write builds on (#62). */
|
|
196
|
+
const fetchVault = async (pubkey, full) => {
|
|
197
|
+
const f = await fetchReplaceable(host.relays, host.relayUrls, { author: pubkey, kind: VAULT_KIND, d: signerVaultDTag(pubkey, host.signerKey) }, timeoutMs, full ? undefined : host.relayQuorum);
|
|
198
|
+
if (f.kind === "none")
|
|
199
|
+
return ok(null);
|
|
200
|
+
if (f.kind === "incomplete")
|
|
201
|
+
return error("relaysUnavailable", "Not every relay answered");
|
|
202
|
+
lastEventAt = Math.max(lastEventAt, f.event.created_at);
|
|
203
|
+
return parseSignerVault(f.event.content);
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Loads the signer vault once per session; null when none exists (#40). With a
|
|
207
|
+
* local copy (#41), it's merged with the relay version, or used instead of a
|
|
208
|
+
* missing or invalid one; `needsHeal` marks wraps the relays lack. With
|
|
209
|
+
* `forWrite`, a version read at the quorum is read again from every relay
|
|
210
|
+
* (#62): it may be stale, and a write on it would undo a newer one.
|
|
211
|
+
*/
|
|
212
|
+
const loadVault = async (pubkey, forWrite = false) => {
|
|
213
|
+
if (vaultLoaded && (vaultFull || !forWrite))
|
|
214
|
+
return ok(vault);
|
|
215
|
+
const full = forWrite || host.relayQuorum === undefined;
|
|
216
|
+
const fetched = await fetchVault(pubkey, full);
|
|
217
|
+
if (!fetched.ok && fetched.error.type !== "invalidSignerVault")
|
|
218
|
+
return fetched;
|
|
219
|
+
const copyText = (await host.cache?.getVault?.(pubkey)) ?? null;
|
|
220
|
+
const copy = copyText === null ? null : parseSignerVault(copyText);
|
|
221
|
+
const local = copy?.ok ? copy.value : null;
|
|
222
|
+
if (local === null) {
|
|
223
|
+
if (!fetched.ok)
|
|
224
|
+
return fetched;
|
|
225
|
+
vault = fetched.value;
|
|
226
|
+
}
|
|
227
|
+
else if (!fetched.ok || fetched.value === null) {
|
|
228
|
+
vault = local;
|
|
229
|
+
needsHeal = true;
|
|
230
|
+
}
|
|
231
|
+
else if (differentMaster(local, fetched.value)) {
|
|
232
|
+
// Another M on the relays (a rotation, or a forgery): keep the local copy
|
|
233
|
+
// until M is unlocked and can check it; never heal over it (#52 phase B).
|
|
234
|
+
vault = local;
|
|
235
|
+
candidate = fetched.value;
|
|
236
|
+
needsHeal = false;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
// The relay vault has no sk wrap and this device may not use one: keep it that way (#52).
|
|
240
|
+
const dropSk = !allowSk() && !fetched.value.wraps.some((w) => w.type === "sk");
|
|
241
|
+
vault = mergeSignerVaults(local, fetched.value, { dropSk });
|
|
242
|
+
const onRelays = new Set(fetched.value.wraps.map((w) => JSON.stringify(w)));
|
|
243
|
+
needsHeal = vault.wraps.some((w) => !onRelays.has(JSON.stringify(w)));
|
|
244
|
+
}
|
|
245
|
+
vaultLoaded = true;
|
|
246
|
+
vaultFull = full;
|
|
247
|
+
return ok(vault);
|
|
248
|
+
};
|
|
249
|
+
const publish = async (pubkey, next) => {
|
|
250
|
+
// Never publish from an unknown state: it would drop wraps added elsewhere (#40).
|
|
251
|
+
if (!vaultLoaded)
|
|
252
|
+
return error("signerVaultUnknown", "Load the signer vault before changing it");
|
|
253
|
+
// Read at the quorum: check every relay first, and don't write over a newer version (#62).
|
|
254
|
+
if (!vaultFull) {
|
|
255
|
+
const before = JSON.stringify(vault);
|
|
256
|
+
const reread = await loadVault(pubkey, true);
|
|
257
|
+
if (!reread.ok)
|
|
258
|
+
return reread;
|
|
259
|
+
if (JSON.stringify(vault) !== before)
|
|
260
|
+
return error("signerVaultChanged", "The signer vault changed on another device; try again");
|
|
261
|
+
}
|
|
262
|
+
const at = Math.max(now(), lastEventAt + 1);
|
|
263
|
+
const signer = {
|
|
264
|
+
getPublicKey: host.getPublicKey,
|
|
265
|
+
signEvent: host.sign,
|
|
266
|
+
nip44Encrypt: () => Promise.reject(new Error("unused")),
|
|
267
|
+
nip44Decrypt: () => Promise.reject(new Error("unused")),
|
|
268
|
+
};
|
|
269
|
+
try {
|
|
270
|
+
await publishReplaceable(host.relays, host.relayUrls, signer, { kind: VAULT_KIND, created_at: at, tags: [["d", signerVaultDTag(pubkey, host.signerKey)]], content: JSON.stringify(next) }, timeoutMs);
|
|
271
|
+
}
|
|
272
|
+
catch (e) {
|
|
273
|
+
return error("publishFailed", e instanceof Error ? e.message : String(e));
|
|
274
|
+
}
|
|
275
|
+
lastEventAt = at;
|
|
276
|
+
vault = next;
|
|
277
|
+
needsHeal = false;
|
|
278
|
+
await host.cache?.setVault?.(pubkey, JSON.stringify(next));
|
|
279
|
+
return ok(next);
|
|
280
|
+
};
|
|
281
|
+
const sealM = (pubkey, key, w, secret) => {
|
|
282
|
+
const id = w.type === "sk" ? "sk" : w.credId;
|
|
283
|
+
const sealed = { ...w, ...seal(key, secret, signerWrapAad(pubkey, host.signerKey, w.type, id)) };
|
|
284
|
+
return { ...sealed, tag: signerWrapTag(pubkey, host.signerKey, secret, sealed) };
|
|
285
|
+
};
|
|
286
|
+
const openM = (pubkey, w, key) => {
|
|
287
|
+
const r = open(key, w, signerWrapAad(pubkey, host.signerKey, w.type, wrapId(w)));
|
|
288
|
+
return r.ok && r.value.length !== MASTER_SECRET_LENGTH ? error("invalidSignerVault", "Wrong secret length") : r;
|
|
289
|
+
};
|
|
290
|
+
const withWrap = (v, w) => ({
|
|
291
|
+
...(v ?? {}),
|
|
292
|
+
v: 1,
|
|
293
|
+
wraps: [...(v?.wraps ?? []).filter((x) => !(x.type === w.type && wrapId(x) === wrapId(w))), w],
|
|
294
|
+
});
|
|
295
|
+
/** With M known, drops forged wraps; a change is published on the next approved request (#54). */
|
|
296
|
+
const prune = (pubkey, secret, openedId) => {
|
|
297
|
+
// Never touch a vault that holds another M (#52 phase B).
|
|
298
|
+
if (vault === null || (vault.mId !== undefined && vault.mId !== signerMId(secret)))
|
|
299
|
+
return;
|
|
300
|
+
const pruned = pruneSignerVault(vault, pubkey, host.signerKey, secret, openedId);
|
|
301
|
+
if (pruned.wraps.length !== vault.wraps.length) {
|
|
302
|
+
vault = pruned;
|
|
303
|
+
needsHeal = true;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* With M known: if the relays hold a rotation this M authorised, switch to it
|
|
308
|
+
* and forget this M (it must not make new app keys). "rotated" means M must
|
|
309
|
+
* now be unlocked again, from the new vault (#52 phase B).
|
|
310
|
+
*/
|
|
311
|
+
const reconcile = async (pubkey) => {
|
|
312
|
+
if (m === null)
|
|
313
|
+
return "same";
|
|
314
|
+
const myId = signerMId(m);
|
|
315
|
+
const other = candidate ?? (vault?.mId !== undefined && vault.mId !== myId ? vault : null);
|
|
316
|
+
if (other === null)
|
|
317
|
+
return "same";
|
|
318
|
+
candidate = null;
|
|
319
|
+
if (!rotationValid(other, m))
|
|
320
|
+
return "foreign";
|
|
321
|
+
previousM = m;
|
|
322
|
+
earlierMs = null;
|
|
323
|
+
vault = other;
|
|
324
|
+
m = null;
|
|
325
|
+
needsHeal = false;
|
|
326
|
+
await host.cache?.remove(pubkey);
|
|
327
|
+
await host.cache?.setVault?.(pubkey, JSON.stringify(other));
|
|
328
|
+
return "rotated";
|
|
329
|
+
};
|
|
330
|
+
/** Called after a wrap opened to M, or after creating M: the vault is good (#41). */
|
|
331
|
+
const remember = async (pubkey, secret, openedId) => {
|
|
332
|
+
m = secret;
|
|
333
|
+
if ((await reconcile(pubkey)) === "rotated")
|
|
334
|
+
return;
|
|
335
|
+
prune(pubkey, secret, openedId);
|
|
336
|
+
// Older vaults have no mId: add it, since a wrap of this vault just opened to M.
|
|
337
|
+
if (openedId !== undefined && vault !== null && vault.mId === undefined) {
|
|
338
|
+
vault = { ...vault, mId: signerMId(secret) };
|
|
339
|
+
needsHeal = true;
|
|
340
|
+
}
|
|
341
|
+
await host.cache?.set(pubkey, secret);
|
|
342
|
+
if (vault !== null)
|
|
343
|
+
await host.cache?.setVault?.(pubkey, JSON.stringify(vault));
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* The earlier Ms, newest first, opened from the vault with the current one:
|
|
347
|
+
* `previous` with M, each `older` entry with the one before it (#58). Stops
|
|
348
|
+
* at the first entry that doesn't open.
|
|
349
|
+
*/
|
|
350
|
+
const earlierOf = (pubkey) => {
|
|
351
|
+
if (earlierMs !== null)
|
|
352
|
+
return earlierMs;
|
|
353
|
+
const first = vault?.previous;
|
|
354
|
+
if (m === null || first === undefined || vault?.mId !== signerMId(m))
|
|
355
|
+
return previousM === null ? [] : [previousM];
|
|
356
|
+
const found = [];
|
|
357
|
+
let key = m;
|
|
358
|
+
for (const p of [first, ...(vault?.older ?? [])]) {
|
|
359
|
+
const opened = open(signerPreviousKey(key), p, signerWrapAad(pubkey, host.signerKey, "previous", p.mId));
|
|
360
|
+
if (!opened.ok || opened.value.length !== MASTER_SECRET_LENGTH || signerMId(opened.value) !== p.mId)
|
|
361
|
+
break;
|
|
362
|
+
found.push(opened.value);
|
|
363
|
+
key = opened.value;
|
|
364
|
+
}
|
|
365
|
+
if (found.length === 0 && previousM !== null)
|
|
366
|
+
found.push(previousM);
|
|
367
|
+
earlierMs = found;
|
|
368
|
+
return found;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Unlocks M without a click if possible: cache, then the nsec. Creates M only
|
|
372
|
+
* when `create` is set and no signer vault exists at all (#28, #29).
|
|
373
|
+
*/
|
|
374
|
+
const unlockQuiet = async (pubkey, create) => {
|
|
375
|
+
if (m !== null)
|
|
376
|
+
return ok(true);
|
|
377
|
+
const cached = await host.cache?.get(pubkey);
|
|
378
|
+
if (cached != null && cached.length === MASTER_SECRET_LENGTH) {
|
|
379
|
+
m = cached;
|
|
380
|
+
// Relays down: keep using the cached M. A rotation it authorised: unlock the new one.
|
|
381
|
+
const read = await loadVault(pubkey);
|
|
382
|
+
if (!read.ok || (await reconcile(pubkey)) !== "rotated")
|
|
383
|
+
return ok(true);
|
|
384
|
+
}
|
|
385
|
+
const loaded = await loadVault(pubkey);
|
|
386
|
+
if (!loaded.ok)
|
|
387
|
+
return loaded;
|
|
388
|
+
const sk = host.getSecretKey?.() ?? null;
|
|
389
|
+
if (sk !== null && allowSk()) {
|
|
390
|
+
const skWrap = vault?.wraps.find((w) => w.type === "sk");
|
|
391
|
+
if (skWrap !== undefined) {
|
|
392
|
+
const opened = openM(pubkey, skWrap, signerSkWrapKey(sk));
|
|
393
|
+
if (opened.ok) {
|
|
394
|
+
await remember(pubkey, opened.value, "sk:sk");
|
|
395
|
+
return ok(true);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (vault === null && create) {
|
|
399
|
+
// First use: create M and protect it with the nsec.
|
|
400
|
+
const fresh = random(MASTER_SECRET_LENGTH);
|
|
401
|
+
const published = await publish(pubkey, { ...withWrap(vault, sealM(pubkey, signerSkWrapKey(sk), { type: "sk" }, fresh)), mId: signerMId(fresh) });
|
|
402
|
+
if (!published.ok)
|
|
403
|
+
return published;
|
|
404
|
+
await remember(pubkey, fresh);
|
|
405
|
+
return ok(true);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return ok(false);
|
|
409
|
+
};
|
|
410
|
+
/** Unlocks M with a signer passkey, after a click inside the signer. */
|
|
411
|
+
const unlockWithPasskey = async (pubkey) => {
|
|
412
|
+
const passkeys = host.passkeys;
|
|
413
|
+
const wraps = (vault?.wraps ?? []).filter((w) => w.type === "passkey" && passkeys !== undefined && w.rpId === passkeys.rpId);
|
|
414
|
+
if (passkeys === undefined || wraps.length === 0) {
|
|
415
|
+
return error("signerLocked", "No way to unlock this signer's Evolustr key here; enroll a signer passkey");
|
|
416
|
+
}
|
|
417
|
+
await host.ui.requestGesture("unlock");
|
|
418
|
+
let result;
|
|
419
|
+
try {
|
|
420
|
+
result = await passkeys.get({ allowCredIds: wraps.map((w) => w.credId), prfInput: signerPrfInput(pubkey) });
|
|
421
|
+
}
|
|
422
|
+
catch (e) {
|
|
423
|
+
return error("passkeyFailed", e instanceof Error ? e.message : String(e));
|
|
424
|
+
}
|
|
425
|
+
const wrap = wraps.find((w) => w.credId === result.credId);
|
|
426
|
+
if (wrap === undefined || result.prfOutput === null)
|
|
427
|
+
return error("passkeyFailed", "The passkey gave no usable result");
|
|
428
|
+
const opened = openM(pubkey, wrap, signerPasskeyWrapKey(result.prfOutput));
|
|
429
|
+
if (!opened.ok)
|
|
430
|
+
return opened;
|
|
431
|
+
await remember(pubkey, opened.value, `passkey:${wrap.credId}`);
|
|
432
|
+
return ok(undefined);
|
|
433
|
+
};
|
|
434
|
+
const ensureM = async () => {
|
|
435
|
+
const pubkey = await host.getPublicKey();
|
|
436
|
+
const quiet = await unlockQuiet(pubkey, true);
|
|
437
|
+
if (!quiet.ok)
|
|
438
|
+
return quiet;
|
|
439
|
+
if (!quiet.value) {
|
|
440
|
+
const viaPasskey = await unlockWithPasskey(pubkey);
|
|
441
|
+
if (!viaPasskey.ok)
|
|
442
|
+
return viaPasskey;
|
|
443
|
+
// That opened the previous M, and the vault moved on to its successor (#52 phase B).
|
|
444
|
+
if (m === null && previousM !== null) {
|
|
445
|
+
const again = await unlockWithPasskey(pubkey);
|
|
446
|
+
if (!again.ok)
|
|
447
|
+
return again;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return m === null ? error("signerLocked", "Locked") : ok({ pubkey, m });
|
|
451
|
+
};
|
|
452
|
+
const capabilities = async (caller) => {
|
|
453
|
+
const appId = appIdFor(caller);
|
|
454
|
+
if (!appId.ok)
|
|
455
|
+
return appId;
|
|
456
|
+
const pubkey = await host.getPublicKey();
|
|
457
|
+
if (m === null)
|
|
458
|
+
await unlockQuiet(pubkey, false);
|
|
459
|
+
// M may come from the cache without the vault being read: read it, ignoring
|
|
460
|
+
// failures (still never creates or publishes anything, #29).
|
|
461
|
+
if (!vaultLoaded)
|
|
462
|
+
await loadVault(pubkey);
|
|
463
|
+
return ok({
|
|
464
|
+
identity: caller.identity,
|
|
465
|
+
appId: appId.value,
|
|
466
|
+
signerId: m === null ? null : computeSignerId(m, appId.value),
|
|
467
|
+
ready: m !== null,
|
|
468
|
+
signerPasskey: (vault?.wraps ?? []).some((w) => w.type === "passkey"),
|
|
469
|
+
recoverable: (vault?.wraps ?? []).some((w) => w.type === "sk" || (w.type === "passkey" && w.synced === true)),
|
|
470
|
+
nsecProtected: (vault?.wraps ?? []).some((w) => w.type === "sk"),
|
|
471
|
+
nsecExposed: (vault?.wraps ?? []).some((w) => w.type === "sk") || vault?.skDroppedAt !== undefined,
|
|
472
|
+
...(() => {
|
|
473
|
+
const ids = earlierOf(pubkey).map((x) => computeSignerId(x, appId.value));
|
|
474
|
+
return { previousSignerId: ids[0] ?? null, previousSignerIds: ids };
|
|
475
|
+
})(),
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
const getWrapKey = async (caller) => {
|
|
479
|
+
const appId = appIdFor(caller);
|
|
480
|
+
if (!appId.ok)
|
|
481
|
+
return appId;
|
|
482
|
+
const allowed = await host.ui.confirm({ kind: "appKey", appId: appId.value, identity: caller.identity });
|
|
483
|
+
if (!allowed)
|
|
484
|
+
return error("userRefused", "The user didn't allow this app");
|
|
485
|
+
const unlocked = await ensureM();
|
|
486
|
+
if (!unlocked.ok)
|
|
487
|
+
return unlocked;
|
|
488
|
+
// Self-heal (#41): the user just approved this app and M is unlocked. With M
|
|
489
|
+
// from the cache the vault may not be loaded yet; a failure here doesn't block.
|
|
490
|
+
if (!vaultLoaded)
|
|
491
|
+
await loadVault(unlocked.value.pubkey);
|
|
492
|
+
prune(unlocked.value.pubkey, unlocked.value.m);
|
|
493
|
+
if (needsHeal && vault !== null)
|
|
494
|
+
await publish(unlocked.value.pubkey, vault);
|
|
495
|
+
return ok(signerAppKey(unlocked.value.m, appId.value));
|
|
496
|
+
};
|
|
497
|
+
const getHostSecret = async (label) => {
|
|
498
|
+
if (!isHostSecretLabel(label))
|
|
499
|
+
return error("badRequest", "A host secret label is 1–200 characters without '|'");
|
|
500
|
+
const unlocked = await ensureM();
|
|
501
|
+
if (!unlocked.ok)
|
|
502
|
+
return unlocked;
|
|
503
|
+
return ok(hostSecret(unlocked.value.m, label));
|
|
504
|
+
};
|
|
505
|
+
const enrollPasskey = async () => {
|
|
506
|
+
const passkeys = host.passkeys;
|
|
507
|
+
if (passkeys === undefined)
|
|
508
|
+
return error("noPasskeys", "This signer has no passkey support");
|
|
509
|
+
const pubkey = await host.getPublicKey();
|
|
510
|
+
// The current wrap list must be known before adding to it (#40), from every relay (#62).
|
|
511
|
+
const loaded = await loadVault(pubkey, true);
|
|
512
|
+
if (!loaded.ok)
|
|
513
|
+
return loaded;
|
|
514
|
+
const quiet = await unlockQuiet(pubkey, false);
|
|
515
|
+
if (!quiet.ok)
|
|
516
|
+
return quiet;
|
|
517
|
+
if (!(await host.ui.confirm({ kind: "enrollPasskey" })))
|
|
518
|
+
return error("userRefused", "Cancelled");
|
|
519
|
+
// Moving from the nsec to a passkey: with the sk wrap no longer allowed, it
|
|
520
|
+
// may still open M once, so the passkey wraps the same M and app keys stay.
|
|
521
|
+
if (m === null && !allowSk()) {
|
|
522
|
+
const sk = host.getSecretKey?.() ?? null;
|
|
523
|
+
const skWrap = vault?.wraps.find((w) => w.type === "sk");
|
|
524
|
+
if (sk !== null && skWrap !== undefined) {
|
|
525
|
+
const opened = openM(pubkey, skWrap, signerSkWrapKey(sk));
|
|
526
|
+
if (opened.ok)
|
|
527
|
+
await remember(pubkey, opened.value, "sk:sk");
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
// A signer vault already exists: unlock M first, never create a second one (#28).
|
|
531
|
+
if (m === null && vault !== null) {
|
|
532
|
+
const unlocked = await unlockWithPasskey(pubkey);
|
|
533
|
+
if (!unlocked.ok)
|
|
534
|
+
return error("signerLocked", "Unlock this signer's existing Evolustr key before adding a passkey");
|
|
535
|
+
}
|
|
536
|
+
await host.ui.requestGesture("enrollPasskey");
|
|
537
|
+
let created;
|
|
538
|
+
try {
|
|
539
|
+
created = await passkeys.create({
|
|
540
|
+
userId: sha256(utf8(`evolustr-signer|${pubkey}`)),
|
|
541
|
+
userName: pubkey.slice(0, 16),
|
|
542
|
+
excludeCredIds: (vault?.wraps ?? []).flatMap((w) => (w.type === "passkey" && w.rpId === passkeys.rpId ? [w.credId] : [])),
|
|
543
|
+
prfInput: signerPrfInput(pubkey),
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
catch (e) {
|
|
547
|
+
return error("passkeyFailed", e instanceof Error ? e.message : String(e));
|
|
548
|
+
}
|
|
549
|
+
if (!created.prfEnabled)
|
|
550
|
+
return error("prfUnsupported", "This authenticator has no PRF support");
|
|
551
|
+
let prfOutput = created.prfOutput;
|
|
552
|
+
if (prfOutput === null) {
|
|
553
|
+
await host.ui.requestGesture("enrollPasskey");
|
|
554
|
+
prfOutput = (await passkeys.get({ allowCredIds: [created.credId], prfInput: signerPrfInput(pubkey) })).prfOutput;
|
|
555
|
+
}
|
|
556
|
+
if (prfOutput === null)
|
|
557
|
+
return error("prfUnsupported", "The passkey gave no PRF output");
|
|
558
|
+
// Only when no signer vault exists at all: create M now.
|
|
559
|
+
const secret = m ?? random(MASTER_SECRET_LENGTH);
|
|
560
|
+
let next = withWrap(vault, sealM(pubkey, signerPasskeyWrapKey(prfOutput), { type: "passkey", rpId: passkeys.rpId, credId: created.credId, synced: created.synced }, secret));
|
|
561
|
+
if (!allowSk() && next.wraps.some((w) => w.type === "sk")) {
|
|
562
|
+
// M stays the same: whoever can recover the nsec may still have it (#52).
|
|
563
|
+
next = { ...next, wraps: next.wraps.filter((w) => w.type !== "sk"), skDroppedAt: now() };
|
|
564
|
+
}
|
|
565
|
+
if (next.wraps.length > MAX_SIGNER_WRAPS)
|
|
566
|
+
return error("signerVaultFull", "The signer vault has no room for another wrap");
|
|
567
|
+
next = { ...next, mId: signerMId(secret) };
|
|
568
|
+
const published = await publish(pubkey, next);
|
|
569
|
+
if (!published.ok)
|
|
570
|
+
return published;
|
|
571
|
+
await remember(pubkey, secret);
|
|
572
|
+
return ok(undefined);
|
|
573
|
+
};
|
|
574
|
+
const getPreviousWrapKey = async (caller, signerId) => {
|
|
575
|
+
const appId = appIdFor(caller);
|
|
576
|
+
if (!appId.ok)
|
|
577
|
+
return appId;
|
|
578
|
+
const allowed = await host.ui.confirm({ kind: "appKey", appId: appId.value, identity: caller.identity });
|
|
579
|
+
if (!allowed)
|
|
580
|
+
return error("userRefused", "The user didn't allow this app");
|
|
581
|
+
const unlocked = await ensureM();
|
|
582
|
+
if (!unlocked.ok)
|
|
583
|
+
return unlocked;
|
|
584
|
+
const earlier = earlierOf(unlocked.value.pubkey);
|
|
585
|
+
if (earlier.length === 0)
|
|
586
|
+
return error("noPreviousKey", "This signer hasn't replaced its key");
|
|
587
|
+
const prev = signerId === undefined ? earlier[0] : earlier.find((x) => computeSignerId(x, appId.value) === signerId);
|
|
588
|
+
return prev === undefined ? error("noPreviousKey", "This signer has no earlier key with that id") : ok(signerAppKey(prev, appId.value));
|
|
589
|
+
};
|
|
590
|
+
const getPreviousHostSecret = async (label) => {
|
|
591
|
+
if (!isHostSecretLabel(label))
|
|
592
|
+
return error("badRequest", "A host secret label is 1–200 characters without '|'");
|
|
593
|
+
const unlocked = await ensureM();
|
|
594
|
+
if (!unlocked.ok)
|
|
595
|
+
return unlocked;
|
|
596
|
+
const prev = earlierOf(unlocked.value.pubkey)[0];
|
|
597
|
+
return prev === undefined ? error("noPreviousKey", "This signer hasn't replaced its key") : ok(hostSecret(prev, label));
|
|
598
|
+
};
|
|
599
|
+
const getPreviousHostSecrets = async (label) => {
|
|
600
|
+
if (!isHostSecretLabel(label))
|
|
601
|
+
return error("badRequest", "A host secret label is 1–200 characters without '|'");
|
|
602
|
+
const unlocked = await ensureM();
|
|
603
|
+
if (!unlocked.ok)
|
|
604
|
+
return unlocked;
|
|
605
|
+
return ok(earlierOf(unlocked.value.pubkey).map((x) => hostSecret(x, label)));
|
|
606
|
+
};
|
|
607
|
+
const rotateMaster = async () => {
|
|
608
|
+
const passkeys = host.passkeys;
|
|
609
|
+
if (passkeys === undefined)
|
|
610
|
+
return error("noPasskeys", "This signer has no passkey support");
|
|
611
|
+
// The point is to cut off whoever can recover the nsec: an sk wrap would bring it back.
|
|
612
|
+
if (allowSk())
|
|
613
|
+
return error("nsecAllowed", "Turn off the nsec protection (allowSkWrap) before replacing the key");
|
|
614
|
+
const pubkey = await host.getPublicKey();
|
|
615
|
+
const loaded = await loadVault(pubkey, true); // a write: from every relay (#62)
|
|
616
|
+
if (!loaded.ok)
|
|
617
|
+
return loaded;
|
|
618
|
+
if (vault === null)
|
|
619
|
+
return error("noSignerVault", "This signer has no key to replace yet");
|
|
620
|
+
const wraps = vault.wraps.filter((w) => w.type === "passkey" && w.rpId === passkeys.rpId);
|
|
621
|
+
if (wraps.length === 0)
|
|
622
|
+
return error("noSignerPasskey", "Enroll a signer passkey first");
|
|
623
|
+
if (!(await host.ui.confirm({ kind: "rotateMaster" })))
|
|
624
|
+
return error("userRefused", "Cancelled");
|
|
625
|
+
await host.ui.requestGesture("rotateMaster");
|
|
626
|
+
let result;
|
|
627
|
+
try {
|
|
628
|
+
result = await passkeys.get({ allowCredIds: wraps.map((w) => w.credId), prfInput: signerPrfInput(pubkey) });
|
|
629
|
+
}
|
|
630
|
+
catch (e) {
|
|
631
|
+
return error("passkeyFailed", e instanceof Error ? e.message : String(e));
|
|
632
|
+
}
|
|
633
|
+
const wrap = wraps.find((w) => w.credId === result.credId);
|
|
634
|
+
if (wrap === undefined || result.prfOutput === null)
|
|
635
|
+
return error("passkeyFailed", "The passkey gave no usable result");
|
|
636
|
+
const key = signerPasskeyWrapKey(result.prfOutput);
|
|
637
|
+
// The passkey in hand proves the user holds the current M.
|
|
638
|
+
const oldM = openM(pubkey, wrap, key);
|
|
639
|
+
if (!oldM.ok)
|
|
640
|
+
return oldM;
|
|
641
|
+
const newM = random(MASTER_SECRET_LENGTH);
|
|
642
|
+
const oldMId = signerMId(oldM.value);
|
|
643
|
+
const newMId = signerMId(newM);
|
|
644
|
+
// The chain so far moves down one place, unchanged: each entry still opens with the one before it (#58).
|
|
645
|
+
const older = vault.previous === undefined ? [] : [vault.previous, ...(vault.older ?? [])].slice(0, MAX_PREVIOUS_MASTERS - 1);
|
|
646
|
+
const next = {
|
|
647
|
+
v: 1,
|
|
648
|
+
wraps: [sealM(pubkey, key, { type: "passkey", rpId: wrap.rpId, credId: wrap.credId, ...(wrap.synced === undefined ? {} : { synced: wrap.synced }) }, newM)],
|
|
649
|
+
mId: newMId,
|
|
650
|
+
rotatedFrom: { mId: oldMId, proof: masterRotationProof(oldM.value, newMId) },
|
|
651
|
+
previous: { mId: oldMId, ...seal(signerPreviousKey(newM), oldM.value, signerWrapAad(pubkey, host.signerKey, "previous", oldMId)) },
|
|
652
|
+
...(older.length > 0 ? { older } : {}),
|
|
653
|
+
};
|
|
654
|
+
const droppedWraps = vault.wraps.length - 1;
|
|
655
|
+
const published = await publish(pubkey, next);
|
|
656
|
+
if (!published.ok)
|
|
657
|
+
return published;
|
|
658
|
+
candidate = null;
|
|
659
|
+
previousM = oldM.value;
|
|
660
|
+
earlierMs = null;
|
|
661
|
+
m = newM;
|
|
662
|
+
await host.cache?.set(pubkey, newM);
|
|
663
|
+
return ok({ droppedWraps });
|
|
664
|
+
};
|
|
665
|
+
const handle = async (method, params, caller) => {
|
|
666
|
+
switch (method) {
|
|
667
|
+
case "evolustr_capabilities":
|
|
668
|
+
return capabilities(caller);
|
|
669
|
+
case "evolustr_get_wrap_key": {
|
|
670
|
+
const key = await getWrapKey(caller);
|
|
671
|
+
return key.ok ? ok(toBase64Url(key.value)) : key;
|
|
672
|
+
}
|
|
673
|
+
case "evolustr_get_previous_wrap_key": {
|
|
674
|
+
// Optional: the signer id the app's wrap was made with (#58).
|
|
675
|
+
const signerId = params[0];
|
|
676
|
+
if (signerId !== undefined && signerId !== null && (typeof signerId !== "string" || !/^[0-9a-f]{16}$/.test(signerId))) {
|
|
677
|
+
return error("badRequest", "signerId must be 16 hex characters");
|
|
678
|
+
}
|
|
679
|
+
const key = await getPreviousWrapKey(caller, typeof signerId === "string" ? signerId : undefined);
|
|
680
|
+
return key.ok ? ok(toBase64Url(key.value)) : key;
|
|
681
|
+
}
|
|
682
|
+
case "evolustr_enroll_passkey":
|
|
683
|
+
return enrollPasskey();
|
|
684
|
+
default:
|
|
685
|
+
return error("unknownMethod", `Unknown method ${method}`);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
const lock = async () => {
|
|
689
|
+
const pubkey = await host.getPublicKey().catch(() => null);
|
|
690
|
+
m = null;
|
|
691
|
+
vault = null;
|
|
692
|
+
vaultLoaded = false;
|
|
693
|
+
needsHeal = false;
|
|
694
|
+
candidate = null;
|
|
695
|
+
previousM = null;
|
|
696
|
+
earlierMs = null;
|
|
697
|
+
if (pubkey !== null)
|
|
698
|
+
await host.cache?.remove(pubkey);
|
|
699
|
+
};
|
|
700
|
+
return {
|
|
701
|
+
handle,
|
|
702
|
+
capabilities,
|
|
703
|
+
getWrapKey,
|
|
704
|
+
getPreviousWrapKey,
|
|
705
|
+
enrollPasskey,
|
|
706
|
+
rotateMaster,
|
|
707
|
+
getHostSecret,
|
|
708
|
+
getPreviousHostSecret,
|
|
709
|
+
getPreviousHostSecrets,
|
|
710
|
+
isProtectedEvent,
|
|
711
|
+
appIdFor,
|
|
712
|
+
lock,
|
|
713
|
+
};
|
|
714
|
+
};
|
|
715
|
+
//# sourceMappingURL=signer.js.map
|