@johnhenry/browsermesh-realm 0.0.0-stage → 0.0.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/src/store.mjs ADDED
@@ -0,0 +1,137 @@
1
+ // The descriptor store (docs/design/realms.md 5.2 and 5.5): the one place a realm descriptor is held, offered and adopted.
2
+ //
3
+ // A peer announcing a high serial must not be able to cost more than a bounded amount of work, so an offer is gated
4
+ // before it is verified: size, then (only when something is held) a cheap JSON read of the serial, then a per-link and a
5
+ // global rate limit. Only then is the full verification (`adoptDescriptor`: canonical parse, chain, signature) run, and
6
+ // only the verified, strictly higher descriptor replaces the held one. Offers are serialised, so two links racing each
7
+ // other cannot adopt out of order.
8
+ import { adoptDescriptor } from "./adopt.mjs";
9
+ import { verifyDescriptor } from "./descriptor.mjs";
10
+ import { MAX_DESCRIPTOR_BYTES } from "./limits.mjs";
11
+ import { resolveNow } from "./keys.mjs";
12
+ import { need, utf8Length } from "./validate.mjs";
13
+
14
+ const DEFAULTS = Object.freeze({
15
+ maxBytes: MAX_DESCRIPTOR_BYTES,
16
+ /** Offers one link may make (verified or not). */
17
+ maxOffersPerLink: 4,
18
+ /** Offers one link may have fully verified. */
19
+ maxVerifiesPerLink: 2,
20
+ /** Full verifications across all links within `windowSeconds`. */
21
+ maxVerifiesPerWindow: 16,
22
+ windowSeconds: 60,
23
+ /** Links whose counters are remembered at once (oldest forgotten first). */
24
+ maxLinks: 1024,
25
+ });
26
+
27
+ /**
28
+ * @param {object} opts
29
+ * @param {string} opts.pinnedId the realm id this store is for
30
+ * @param {string} [opts.held] a descriptor text to start from (the baked one, or an earlier `export()`); verified before it
31
+ * counts, so a bad one leaves the store empty
32
+ * @param {unknown[]} [opts.heldChain] a rotation chain already seen, pinned while no descriptor is held
33
+ * @param {number | (() => number)} [opts.now] whole seconds
34
+ * @param {Partial<typeof DEFAULTS>} [opts.limits]
35
+ * @param {(descriptor: object, previous: object | null) => void} [opts.onAdopt]
36
+ */
37
+ export function createDescriptorStore({ pinnedId, held, heldChain, now, limits, onAdopt } = {}) {
38
+ need(typeof pinnedId === "string" && pinnedId !== "", "createDescriptorStore needs a pinnedId");
39
+ const L = { ...DEFAULTS, ...limits };
40
+ let current = null;
41
+ let currentText = null;
42
+ const listeners = new Set();
43
+ if (typeof onAdopt === "function") listeners.add(onAdopt);
44
+ const stats = { verifies: 0, adopted: 0, rejected: 0 };
45
+ /** @type {Map<unknown, { offers: number, verifies: number }>} */
46
+ const links = new Map();
47
+ /** @type {number[]} */
48
+ const window = [];
49
+ let queue = Promise.resolve();
50
+
51
+ const ready = (async () => {
52
+ if (held === undefined || held === null) return { ok: true };
53
+ const v = await verifyDescriptor(held, { pinnedId, now, maxBytes: L.maxBytes, heldChain });
54
+ if (!v.ok) return v;
55
+ current = v.descriptor;
56
+ currentText = v.text;
57
+ return { ok: true };
58
+ })();
59
+
60
+ function linkEntry(linkId) {
61
+ let e = links.get(linkId);
62
+ if (!e) {
63
+ if (links.size >= L.maxLinks) links.delete(links.keys().next().value);
64
+ e = { offers: 0, verifies: 0 };
65
+ links.set(linkId, e);
66
+ }
67
+ return e;
68
+ }
69
+
70
+ const reject = (reason, detail) => {
71
+ stats.rejected++;
72
+ return { ok: false, reason, ...(detail ? { detail } : {}) };
73
+ };
74
+
75
+ async function run(text, linkId) {
76
+ await ready;
77
+ if (typeof text !== "string") return reject("malformed", "a descriptor is text");
78
+ if (utf8Length(text) > L.maxBytes) return reject("too-large", "descriptor is too large");
79
+ const entry = linkEntry(linkId);
80
+ if (++entry.offers > L.maxOffersPerLink) return reject("rate-limited", "too many offers on this link");
81
+ if (current) {
82
+ // A cheap read: only a serial above ours is worth an Ed25519 verification.
83
+ let serial;
84
+ try { serial = JSON.parse(text)?.serial; } catch { return reject("malformed", "not JSON"); }
85
+ if (!Number.isSafeInteger(serial)) return reject("malformed", "no serial");
86
+ if (serial <= current.serial) return reject("stale-serial", "serial is not higher than the one held");
87
+ }
88
+ if (entry.verifies >= L.maxVerifiesPerLink) return reject("rate-limited", "too many verifications on this link");
89
+ const t = resolveNow(now);
90
+ while (window.length && window[0] <= t - L.windowSeconds) window.shift();
91
+ if (window.length >= L.maxVerifiesPerWindow) return reject("rate-limited", "too many verifications");
92
+ window.push(t);
93
+ entry.verifies++;
94
+ stats.verifies++;
95
+
96
+ const opts = { pinnedId, now, maxBytes: L.maxBytes };
97
+ const v = current ? await adoptDescriptor(current, text, opts) : await verifyDescriptor(text, { ...opts, heldChain });
98
+ if (!v.ok) return reject(v.reason, v.detail);
99
+ const previous = current;
100
+ current = v.descriptor;
101
+ currentText = v.text;
102
+ stats.adopted++;
103
+ for (const fn of [...listeners]) {
104
+ try { fn(current, previous); } catch { /* a listener may not break adoption */ }
105
+ }
106
+ return { ok: true, adopted: true, descriptor: current, text: currentText };
107
+ }
108
+
109
+ return {
110
+ /** Resolves `{ ok }` once the `held` descriptor has been checked. */
111
+ ready,
112
+ /** The verified descriptor held now, or null. */
113
+ current: () => current,
114
+ /** Its exact canonical text (what to persist, and to send to a peer that asks), or null. Feed it back as `held`. */
115
+ export: () => currentText,
116
+ /**
117
+ * Offer a descriptor from a peer. Adopted only if it verifies end to end and its serial is higher; never throws.
118
+ * @param {unknown} text
119
+ * @param {{ linkId?: unknown }} [o] the link it came from, for the per-link limits
120
+ */
121
+ offer(text, { linkId = "anonymous" } = {}) {
122
+ const result = queue.then(() => run(text, linkId));
123
+ queue = result.then(() => undefined, () => undefined);
124
+ return result.catch(() => reject("malformed", "unexpected input"));
125
+ },
126
+ /** Subscribe to adoptions. Returns the unsubscribe function. */
127
+ onAdopt(fn) {
128
+ listeners.add(fn);
129
+ return () => listeners.delete(fn);
130
+ },
131
+ /** Free a link's counters (call when the link ends). */
132
+ forget(linkId) {
133
+ links.delete(linkId);
134
+ },
135
+ stats: () => ({ ...stats, links: links.size }),
136
+ };
137
+ }
@@ -0,0 +1,65 @@
1
+ // Monotonic checks. `PeerRegistry` replaces grants by (realm, peer, role) and does not order serials, so this package
2
+ // refuses a credential older than what the verifier already holds. Serials are per issuing ledger, so the key includes
3
+ // the issuer.
4
+ import { MAX_TRACKER_ENTRIES, MAX_SKEW } from "./limits.mjs";
5
+ import { resolveNow } from "./keys.mjs";
6
+
7
+ /**
8
+ * @param {{ maxEntries?: number }} [opts]
9
+ */
10
+ export function createCredentialTracker({ maxEntries = MAX_TRACKER_ENTRIES } = {}) {
11
+ /** @type {Map<string, { serial: number, notAfter: number }>} */
12
+ const held = new Map();
13
+ /** @type {Map<string, number>} */
14
+ const epochs = new Map();
15
+
16
+ const keyOf = (c) => `${c.realm}|${c.issuer}|${c.subject}|${c.role}`;
17
+ const expired = (e, now) => e.notAfter + MAX_SKEW < now;
18
+
19
+ function evict(now) {
20
+ for (const [k, e] of held) if (expired(e, now)) held.delete(k);
21
+ }
22
+
23
+ function inspect(verified, opts) {
24
+ if (!verified || verified.ok !== true || !verified.credential) return { ok: false, reason: "unverified" };
25
+ const c = verified.credential;
26
+ const e = epochs.get(c.realm);
27
+ if (e !== undefined && c.epoch < e) return { ok: false, reason: "epoch-too-old" };
28
+ const h = held.get(keyOf(c));
29
+ if (h && c.serial < h.serial) return { ok: false, reason: "stale-serial" };
30
+ if (!h && held.size >= maxEntries) {
31
+ const now = resolveNow(opts?.now);
32
+ let room = false;
33
+ for (const x of held.values()) if (expired(x, now)) { room = true; break; }
34
+ if (!room) return { ok: false, reason: "tracker-full" };
35
+ }
36
+ return { ok: true };
37
+ }
38
+
39
+ return {
40
+ /** Record that a realm's descriptor (or any trusted source) reached this epoch. Never lowers it. */
41
+ noteEpoch(realm, epoch) {
42
+ if (Number.isSafeInteger(epoch) && epoch > (epochs.get(realm) ?? -1)) epochs.set(realm, epoch);
43
+ },
44
+ epochOf(realm) {
45
+ return epochs.get(realm);
46
+ },
47
+ /** Would this verified credential be admitted? (No state change.) */
48
+ check(verified, opts) {
49
+ return inspect(verified, opts);
50
+ },
51
+ /** Check, and on success remember the serial. */
52
+ admit(verified, opts) {
53
+ const r = inspect(verified, opts);
54
+ if (!r.ok) return r;
55
+ const c = verified.credential;
56
+ const k = keyOf(c);
57
+ if (!held.has(k) && held.size >= maxEntries) evict(resolveNow(opts?.now));
58
+ held.set(k, { serial: c.serial, notAfter: verified.effective?.notAfter ?? c.notAfter });
59
+ return { ok: true };
60
+ },
61
+ get size() {
62
+ return held.size;
63
+ },
64
+ };
65
+ }
@@ -0,0 +1,28 @@
1
+ import { fail } from "./errors.mjs";
2
+ import { MAX_TIME } from "./limits.mjs";
3
+
4
+ export const isPlainObject = (v) => {
5
+ if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
6
+ const p = Object.getPrototypeOf(v);
7
+ return p === Object.prototype || p === null;
8
+ };
9
+
10
+ export const isInt = (v, min = 0, max = Number.MAX_SAFE_INTEGER) => Number.isSafeInteger(v) && v >= min && v <= max;
11
+ export const isTime = (v) => isInt(v, 0, MAX_TIME);
12
+
13
+ /** Reject any key outside `required` + `optional`, and any missing required key. */
14
+ export function exactKeys(obj, required, optional, what) {
15
+ if (!isPlainObject(obj)) fail("malformed", `${what} must be an object`);
16
+ for (const k of Object.keys(obj)) {
17
+ if (!required.includes(k) && !optional.includes(k)) fail("malformed", `${what}: unknown field ${JSON.stringify(k)}`);
18
+ }
19
+ for (const k of required) if (!(k in obj)) fail("malformed", `${what}: missing field ${k}`);
20
+ }
21
+
22
+ export function need(cond, detail) {
23
+ if (!cond) fail("malformed", detail);
24
+ }
25
+
26
+ export const utf8Length = (s) => new TextEncoder().encode(s).length;
27
+
28
+ export const hasControl = (s) => /[\u0000-\u001f\u007f]/.test(s);
@@ -0,0 +1,230 @@
1
+ // The verifier's half of the realm exchange (docs/design/realms.md 5.5): the handler a host plugs into its link-admission
2
+ // seam (`createLinkAdmission({ handler })`). It runs on a RESTRICTED link: a link whose peer key is not yet known to the
3
+ // host, carrying nothing but this conversation.
4
+ //
5
+ // verifier peer
6
+ // hello (serial, epoch) ------>
7
+ // <------ hello (sent again in answer to the peer's: the first can be lost on a link the
8
+ // peer has not finished adopting)
9
+ // [peer's serial is higher] need-descriptor ------> (verify it, adopt it, never trust it)
10
+ // <------ descriptor
11
+ // <------ credential (or null, for the open-mode guest role)
12
+ // verify, check subject = the key the LINK proved, check order (tracker), compute scopes from the descriptor,
13
+ // registry.grantRealmScopes(...) <- strictly BEFORE the result and the promote, or the registry's default
14
+ // access watcher closes the promoted peer at its next access change
15
+ // result { ok: true, role, notAfter } ------> then link.promote()
16
+ //
17
+ // Any failure: `realm:result { ok: false, reason }`, then `link.close(reason)`. A peer that goes quiet is the seam's
18
+ // deadline's problem, not ours: this handler holds no timer.
19
+ //
20
+ // Reasons (stable; also the `reason` of the `refused` event):
21
+ // protocol: bad-frame, unexpected-frame, too-many-frames, wrong-realm, unproven
22
+ // descriptor: descriptor-rejected (a peer's descriptor did not verify or was not higher; detail goes to onEvent),
23
+ // rate-limited, no-descriptor, descriptor-stale
24
+ // credential: no-credential, credential-rejected, and the package's own: malformed, too-large, not-canonical,
25
+ // unsupported-version, issuer-not-listed, bad-signature, unknown-role, epoch-too-old, revoked,
26
+ // not-yet-valid, expired, stale-serial, tracker-full, subject-mismatch
27
+ // grant: no-grant (the registry granted nothing), grant-error (it threw)
28
+ // internal: internal-error
29
+ //
30
+ // The registry is DUCK-TYPED (`grantRealmScopes`, `revokeRealmGrants`): this package never imports browsermesh-apps.
31
+ import { createCredentialTracker } from "./tracker.mjs";
32
+ import { verifyCredential, checkSubject } from "./credential.mjs";
33
+ import { isStale } from "./descriptor.mjs";
34
+ import { defaultRole } from "./roles.mjs";
35
+ import { resolveNow } from "./keys.mjs";
36
+ import { parseFrame } from "./frames.mjs";
37
+ import { need } from "./validate.mjs";
38
+
39
+ const DEFAULTS = Object.freeze({
40
+ /** Frames accepted from one peer on one link before it is cut off. */
41
+ maxFrames: 16,
42
+ /** Descriptors sent to one peer on one link. */
43
+ maxDescriptorReplies: 2,
44
+ /** Seconds an open-mode guest grant lasts (capped by the descriptor's ttl). */
45
+ guestTtl: 3600,
46
+ });
47
+
48
+ /** Reasons from `verifyCredential` that are passed to the peer as they are; anything else is `credential-rejected`. */
49
+ const CREDENTIAL_REASONS = new Set([
50
+ "malformed", "too-large", "not-canonical", "unsupported-version", "wrong-realm", "descriptor-stale", "issuer-not-listed",
51
+ "bad-signature", "unknown-role", "epoch-too-old", "revoked", "not-yet-valid", "expired", "stale-serial", "tracker-full",
52
+ ]);
53
+
54
+ /**
55
+ * @param {object} opts
56
+ * @param {string} opts.pinnedId the realm id this host honours
57
+ * @param {ReturnType<import("./store.mjs").createDescriptorStore>} opts.store
58
+ * @param {{ grantRealmScopes: Function, revokeRealmGrants: Function }} opts.registry duck-typed (a `PeerRegistry`)
59
+ * @param {number | (() => number)} [opts.now] whole seconds
60
+ * @param {number} [opts.skew] clock-skew tolerance in seconds (capped at 300 by the package)
61
+ * @param {ReturnType<typeof createCredentialTracker>} [opts.tracker] share one across verifiers; default a private one
62
+ * @param {Partial<typeof DEFAULTS>} [opts.limits]
63
+ * @param {(event: object) => void} [opts.onEvent] `refused` {peerKey, reason, detail?}, `granted` {peerKey, role, serial,
64
+ * granted, dropped}, `promoted`, `descriptor-adopted` {serial, epoch}
65
+ * @returns {{ handler: (link: object) => Promise<void>, tracker: object }}
66
+ */
67
+ export function createRealmVerifier({ pinnedId, store, registry, now, skew, tracker = createCredentialTracker(), limits, onEvent } = {}) {
68
+ need(typeof pinnedId === "string" && pinnedId !== "", "createRealmVerifier needs a pinnedId");
69
+ need(store && typeof store.offer === "function" && typeof store.current === "function", "createRealmVerifier needs a descriptor store");
70
+ need(registry && typeof registry.grantRealmScopes === "function" && typeof registry.revokeRealmGrants === "function",
71
+ "createRealmVerifier needs a registry with grantRealmScopes and revokeRealmGrants");
72
+ const L = { ...DEFAULTS, ...limits };
73
+ const emit = (event) => { try { onEvent?.(event); } catch { /* a listener may not break a link */ } };
74
+ let nextLink = 0;
75
+
76
+ // A newer descriptor can end grants: a higher epoch ends every grant issued under an older one, and a newly listed
77
+ // revoked serial ends that credential's grant. The registry announces the access change, so open links re-check.
78
+ store.onAdopt((d, prev) => {
79
+ tracker.noteEpoch(d.id, d.epoch);
80
+ emit({ type: "descriptor-adopted", serial: d.serial, epoch: d.epoch });
81
+ try {
82
+ if (d.epoch > (prev?.epoch ?? 0)) registry.revokeRealmGrants({ realmId: d.id, belowEpoch: d.epoch });
83
+ const had = new Set(prev?.revoked ?? []);
84
+ for (const serial of d.revoked) if (!had.has(serial)) registry.revokeRealmGrants({ realmId: d.id, serial });
85
+ } catch { /* the registry's own failure may not break adoption */ }
86
+ });
87
+
88
+ function handler(link) {
89
+ const linkId = ++nextLink;
90
+ const peerKey = link.peerKey;
91
+ const st = { frames: 0, replies: 0, peer: null, awaiting: false, credentialSeen: false, finished: false };
92
+ let settle;
93
+ const done = new Promise((resolve) => { settle = resolve; });
94
+
95
+ const end = () => {
96
+ st.finished = true;
97
+ store.forget?.(linkId);
98
+ };
99
+
100
+ async function refuse(reason, detail) {
101
+ if (st.finished) return;
102
+ end();
103
+ emit({ type: "refused", peerKey, reason, ...(detail ? { detail } : {}) });
104
+ try { await link.send({ t: "realm:result", ok: false, reason }); } catch { /* the link may already be gone */ }
105
+ link.close(reason);
106
+ settle();
107
+ }
108
+
109
+ const send = (frame) => link.send(frame);
110
+ const t = () => resolveNow(now);
111
+
112
+ async function present(text) {
113
+ st.credentialSeen = true;
114
+ const d = store.current();
115
+ if (!d) return refuse("no-descriptor");
116
+ if (isStale(d, t())) return refuse("descriptor-stale");
117
+ tracker.noteEpoch(d.id, d.epoch);
118
+
119
+ let role, serial, epoch, notAfter, verified = null;
120
+ if (text === null) {
121
+ role = defaultRole(d);
122
+ if (role === null) return refuse("no-credential");
123
+ serial = 0;
124
+ epoch = d.epoch;
125
+ notAfter = t() + Math.min(d.ttl, L.guestTtl);
126
+ if (d.validUntil !== undefined) notAfter = Math.min(notAfter, d.validUntil);
127
+ } else {
128
+ // No tracker here: a serial is remembered only once the subject is proven and the grant made, so a stolen
129
+ // credential presented by the wrong key advances nothing.
130
+ verified = await verifyCredential(text, d, { now, skew });
131
+ if (st.finished) return;
132
+ if (!verified.ok) return refuse(CREDENTIAL_REASONS.has(verified.reason) ? verified.reason : "credential-rejected", verified.reason);
133
+ const subject = checkSubject(verified, peerKey);
134
+ if (!subject.ok) return refuse("subject-mismatch");
135
+ const order = tracker.check(verified, { now });
136
+ if (!order.ok) return refuse(CREDENTIAL_REASONS.has(order.reason) ? order.reason : "credential-rejected", order.reason);
137
+ ({ role, serial, epoch } = { role: verified.credential.role, serial: verified.credential.serial, epoch: verified.credential.epoch });
138
+ notAfter = verified.effective.notAfter;
139
+ }
140
+
141
+ // Grant, then remember the serial, with nothing awaited in between.
142
+ let res;
143
+ try {
144
+ res = registry.grantRealmScopes({
145
+ realmId: d.id, serial, peerKey, role, scopes: [...d.roles[role]], notAfter: notAfter * 1000, epoch,
146
+ });
147
+ } catch (err) {
148
+ return refuse("grant-error", String(err?.message ?? err));
149
+ }
150
+ if (!Array.isArray(res?.granted) || res.granted.length === 0) return refuse("no-grant");
151
+ if (verified) tracker.admit(verified, { now });
152
+ emit({ type: "granted", peerKey, role, serial, granted: res.granted, dropped: res.dropped ?? [] });
153
+
154
+ end();
155
+ try {
156
+ await send({ t: "realm:result", ok: true, role, notAfter });
157
+ } catch {
158
+ link.close("send-failed");
159
+ settle();
160
+ return;
161
+ }
162
+ if (link.promote()) emit({ type: "promoted", peerKey, role });
163
+ settle();
164
+ }
165
+
166
+ async function onFrame(raw) {
167
+ if (st.finished) return;
168
+ if (++st.frames > L.maxFrames) return refuse("too-many-frames");
169
+ const parsed = parseFrame(raw);
170
+ if (!parsed.ok) return refuse("bad-frame");
171
+ const f = parsed.frame;
172
+ const cur = store.current();
173
+ switch (f.t) {
174
+ case "realm:hello":
175
+ if (f.id !== pinnedId) return refuse("wrong-realm");
176
+ // The prover says hello again before its credential (its first may have been lost): the same hello twice is one.
177
+ if (st.peer) return f.serial === st.peer.serial && f.epoch === st.peer.epoch ? undefined : refuse("unexpected-frame");
178
+ st.peer = f;
179
+ // Said again, in answer: the first hello can be sent before the peer's side of the link has a session to receive it
180
+ // (a WebRTC data channel the dialler has not finished adopting), and a prover waits for it. The prover ignores a repeat.
181
+ await send({ t: "realm:hello", id: pinnedId, serial: cur?.serial ?? 0, epoch: cur?.epoch ?? 0 });
182
+ if (f.serial > (cur?.serial ?? 0)) {
183
+ st.awaiting = true;
184
+ await send({ t: "realm:need-descriptor", have: cur?.serial ?? 0 });
185
+ }
186
+ return;
187
+ case "realm:need-descriptor": {
188
+ const text = store.export?.();
189
+ if (!cur || !text || f.have >= cur.serial) return;
190
+ if (++st.replies > L.maxDescriptorReplies) return refuse("too-many-frames");
191
+ await send({ t: "realm:descriptor", text });
192
+ return;
193
+ }
194
+ case "realm:descriptor": {
195
+ if (!st.awaiting) return refuse("unexpected-frame");
196
+ st.awaiting = false;
197
+ const v = await store.offer(f.text, { linkId });
198
+ if (st.finished) return;
199
+ if (v.ok) return;
200
+ if (v.reason === "rate-limited") return refuse("rate-limited");
201
+ // Someone else adopted at least what this peer announced while we waited: nothing was lost.
202
+ if (v.reason === "stale-serial" && (store.current()?.serial ?? 0) >= st.peer.serial) return;
203
+ return refuse("descriptor-rejected", v.reason);
204
+ }
205
+ case "realm:credential":
206
+ if (!st.peer || st.awaiting || st.credentialSeen) return refuse("unexpected-frame");
207
+ return present(f.text);
208
+ default:
209
+ return refuse("unexpected-frame"); // realm:result flows the other way
210
+ }
211
+ }
212
+
213
+ // Registered synchronously: the seam may deliver a frame the moment the handler returns.
214
+ let chain = (async () => {
215
+ if (!link.proven) return refuse("unproven");
216
+ await store.ready;
217
+ if (st.finished) return;
218
+ const cur = store.current();
219
+ await send({ t: "realm:hello", id: pinnedId, serial: cur?.serial ?? 0, epoch: cur?.epoch ?? 0 });
220
+ })().catch(() => refuse("internal-error"));
221
+ link.onFrame((raw) => {
222
+ chain = chain.then(() => onFrame(raw)).catch(() => refuse("internal-error"));
223
+ return chain;
224
+ });
225
+ link.onClose(() => { if (!st.finished) end(); settle(); });
226
+ return done;
227
+ }
228
+
229
+ return { handler, tracker };
230
+ }