wb-auth 0.2.0 → 0.4.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/dist/index.js CHANGED
@@ -1,19 +1,360 @@
1
1
  // src/signer.ts
2
- import { signatureHeaders } from "web-bot-auth";
2
+ import { randomBytes } from "crypto";
3
+
4
+ // src/identity.ts
5
+ import {
6
+ createHash,
7
+ createPrivateKey,
8
+ createPublicKey,
9
+ sign as cryptoSign,
10
+ generateKeyPairSync
11
+ } from "crypto";
12
+ import { mkdir, open, readFile, rename, stat } from "fs/promises";
13
+ import { homedir } from "os";
14
+ import { dirname, join, resolve } from "path";
15
+ var DEFAULT_KEY_PATH = resolve(
16
+ homedir(),
17
+ ".config",
18
+ "wbauth",
19
+ "key.pem"
20
+ );
21
+ var KEY_PASSWORD_ENV = "WBAUTH_KEY_PASSWORD";
22
+ var KEYRING_ACTIVE = "active.pem";
23
+ var KEYRING_RETIRING = "retiring.pem";
24
+ var TEST_KEY_JWK = {
25
+ kty: "OKP",
26
+ crv: "Ed25519",
27
+ d: "n4Ni-HpISpVObnQMW0wOhCKROaIKqKtW_2ZYb2p9KcU",
28
+ x: "JrQLj5P_89iXES9-vFgrIy29clF9CC_oPPsw3c5D0bs"
29
+ };
30
+ var warnedWindows = false;
31
+ function validateSignatureAgentUrl(url) {
32
+ if (typeof url !== "string" || !url.startsWith("https://")) {
33
+ throw new Error(`signatureAgentUrl must be https://, got: ${String(url)}`);
34
+ }
35
+ for (const ch of url) {
36
+ const c = ch.charCodeAt(0);
37
+ if (c < 33 || c > 126 || ch === '"' || ch === "\\") {
38
+ throw new Error(
39
+ `signatureAgentUrl must be printable ASCII without spaces, quotes or backslashes, got: ${JSON.stringify(url)}`
40
+ );
41
+ }
42
+ }
43
+ let host = "";
44
+ try {
45
+ host = new URL(url).hostname;
46
+ } catch {
47
+ }
48
+ if (!host) throw new Error(`signatureAgentUrl has no host: ${url}`);
49
+ return url;
50
+ }
51
+ function validateUserAgent(ua) {
52
+ if (ua !== void 0 && [...ua].some((c) => c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127)) {
53
+ throw new Error(
54
+ `userAgent must not contain control characters: ${JSON.stringify(ua)}`
55
+ );
56
+ }
57
+ return ua;
58
+ }
59
+ var Identity = class _Identity {
60
+ #active;
61
+ #retiring;
62
+ #signatureAgentUrl;
63
+ #userAgent;
64
+ constructor(active, opts, retiring = null) {
65
+ this.#signatureAgentUrl = validateSignatureAgentUrl(opts.signatureAgentUrl);
66
+ this.#userAgent = validateUserAgent(opts.userAgent);
67
+ this.#active = active;
68
+ this.#retiring = retiring;
69
+ }
70
+ // ---------- Public read-only API ----------
71
+ get signatureAgentUrl() {
72
+ return this.#signatureAgentUrl;
73
+ }
74
+ get userAgent() {
75
+ return this.#userAgent;
76
+ }
77
+ /** The active key's kid (used as `keyid=` param in Signature-Input). */
78
+ get kid() {
79
+ return this.#active.kid;
80
+ }
81
+ /** The active key's public JWK (copy; never contains private material). */
82
+ get publicJwk() {
83
+ return { ...this.#active.publicJwk };
84
+ }
85
+ /** Module-internal: returns the active Signer for sign() to use. */
86
+ _signer() {
87
+ return this.#active.signer;
88
+ }
89
+ /** Public JWKS: active first, then the retiring key (if any). */
90
+ exportJwks() {
91
+ const keys = [{ ...this.#active.publicJwk }];
92
+ if (this.#retiring) keys.push({ ...this.#retiring.publicJwk });
93
+ return { keys };
94
+ }
95
+ /**
96
+ * IDENT-07: generate a new active key, demote current to retiring.
97
+ * In-memory only — use `rotateKeyring()` to persist. The default path is
98
+ * a fresh timestamped file next to DEFAULT_KEY_PATH (never collides).
99
+ */
100
+ async rotate(newPath, keyOpts = {}) {
101
+ const path = newPath ? expandUser(newPath) : join(
102
+ dirname(DEFAULT_KEY_PATH),
103
+ `key-${Math.floor(Date.now() / 1e3)}.pem`
104
+ );
105
+ const newPair = await generateKeypairTo(path, keyOpts);
106
+ return new _Identity(newPair, this.#opts(), this.#active);
107
+ }
108
+ /**
109
+ * Persisted rotation: `<dir>/active.pem` → `retiring.pem` (replacing the
110
+ * previous retiring key), then a fresh `active.pem` is generated.
111
+ */
112
+ async rotateKeyring(dir, keyOpts = {}) {
113
+ const d = expandUser(dir);
114
+ const active = join(d, KEYRING_ACTIVE);
115
+ const retiring = join(d, KEYRING_RETIRING);
116
+ await stat(active);
117
+ await rename(active, retiring);
118
+ let pair;
119
+ try {
120
+ pair = await generateKeypairTo(active, keyOpts);
121
+ } catch (e) {
122
+ await rename(retiring, active);
123
+ throw e;
124
+ }
125
+ return new _Identity(
126
+ pair,
127
+ this.#opts(),
128
+ await loadKeypair(retiring, keyOpts)
129
+ );
130
+ }
131
+ #opts() {
132
+ return {
133
+ signatureAgentUrl: this.#signatureAgentUrl,
134
+ userAgent: this.#userAgent
135
+ };
136
+ }
137
+ // ---------- Constructors ----------
138
+ /**
139
+ * Loads `path` if it exists, generates a fresh key there otherwise.
140
+ * Concurrent first starts are safe: the loser of the O_EXCL race loads the
141
+ * winner's key. `retiringPath` optionally loads the previous key.
142
+ */
143
+ static async loadOrGenerate(path = DEFAULT_KEY_PATH, opts) {
144
+ validateSignatureAgentUrl(opts.signatureAgentUrl);
145
+ const resolved = expandUser(path);
146
+ let pair = null;
147
+ if (!await exists(resolved)) {
148
+ try {
149
+ pair = await generateKeypairTo(resolved, opts);
150
+ } catch (e) {
151
+ if (e.code !== "EEXIST" && !await exists(resolved))
152
+ throw e;
153
+ }
154
+ }
155
+ pair ??= await loadKeypair(resolved, opts);
156
+ let retiring = null;
157
+ if (opts.retiringPath && await exists(expandUser(opts.retiringPath))) {
158
+ retiring = await loadKeypair(expandUser(opts.retiringPath), opts);
159
+ }
160
+ return new _Identity(pair, opts, retiring);
161
+ }
162
+ /** Load an existing key; never creates one. */
163
+ static async load(path, opts) {
164
+ return new _Identity(await loadKeypair(expandUser(path), opts), opts);
165
+ }
166
+ /** Generate a new key at `path`; never overwrites. */
167
+ static async generate(path, opts) {
168
+ validateSignatureAgentUrl(opts.signatureAgentUrl);
169
+ return new _Identity(await generateKeypairTo(expandUser(path), opts), opts);
170
+ }
171
+ /** `<dir>/active.pem` (+ `retiring.pem`), generating active on first use. */
172
+ static async loadKeyring(dir, opts) {
173
+ const d = expandUser(dir);
174
+ return _Identity.loadOrGenerate(join(d, KEYRING_ACTIVE), {
175
+ ...opts,
176
+ retiringPath: join(d, KEYRING_RETIRING)
177
+ });
178
+ }
179
+ /** Wrap an external signer (KMS, HSM, keychain). */
180
+ static async fromSigner(backend, opts) {
181
+ const jwk = backend.publicJwk;
182
+ if (jwk.kty !== "OKP" || jwk.crv !== "Ed25519" || !jwk.x) {
183
+ throw new TypeError("fromSigner: publicJwk must be an Ed25519 OKP JWK");
184
+ }
185
+ const kid = thumbprint(jwk);
186
+ const enc = new TextEncoder();
187
+ return new _Identity(
188
+ {
189
+ kid,
190
+ publicJwk: { kty: "OKP", crv: "Ed25519", x: jwk.x, kid },
191
+ signer: {
192
+ alg: "ed25519",
193
+ keyid: kid,
194
+ sign: async (data) => backend.sign(enc.encode(data))
195
+ }
196
+ },
197
+ opts
198
+ );
199
+ }
200
+ /** RFC 9421 Appendix B.1.4 test key. NEVER use in production. */
201
+ static async fromTestKey(signatureAgentUrl, opts = {}) {
202
+ const key = createPrivateKey({ key: TEST_KEY_JWK, format: "jwk" });
203
+ return new _Identity(keyPairFromKeyObject(key), {
204
+ ...opts,
205
+ signatureAgentUrl
206
+ });
207
+ }
208
+ // ---------- Redaction guarantees (IDENT-08) ----------
209
+ toString() {
210
+ return `<Identity REDACTED kid='${this.kid}' sig_agent='${this.#signatureAgentUrl}'>`;
211
+ }
212
+ /** JSON.stringify(identity) → public data only. */
213
+ toJSON() {
214
+ return {
215
+ kid: this.kid,
216
+ signatureAgentUrl: this.#signatureAgentUrl,
217
+ ...this.#userAgent !== void 0 ? { userAgent: this.#userAgent } : {},
218
+ jwks: this.exportJwks()
219
+ };
220
+ }
221
+ /** util.inspect / console.log render the same REDACTED form (IDENT-08). */
222
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
223
+ return this.toString();
224
+ }
225
+ };
226
+ function expandUser(path) {
227
+ if (path === "~") return homedir();
228
+ if (path.startsWith("~/") || path.startsWith("~\\")) {
229
+ return resolve(homedir(), path.slice(2));
230
+ }
231
+ return resolve(path);
232
+ }
233
+ async function exists(path) {
234
+ try {
235
+ await stat(path);
236
+ return true;
237
+ } catch {
238
+ return false;
239
+ }
240
+ }
241
+ function b64url(buf) {
242
+ return buf.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
243
+ }
244
+ function thumbprint(jwk) {
245
+ const canonical = JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x });
246
+ return b64url(createHash("sha256").update(canonical).digest());
247
+ }
248
+ function keyPairFromKeyObject(privateKey) {
249
+ const pub = createPublicKey(privateKey).export({
250
+ format: "jwk"
251
+ });
252
+ if (pub.kty !== "OKP" || pub.crv !== "Ed25519") {
253
+ throw new TypeError(`Expected Ed25519, got kty=${pub.kty}, crv=${pub.crv}`);
254
+ }
255
+ const kid = thumbprint(pub);
256
+ return {
257
+ kid,
258
+ publicJwk: { kty: "OKP", crv: "Ed25519", x: pub.x, kid },
259
+ signer: {
260
+ alg: "ed25519",
261
+ keyid: kid,
262
+ // Sync node:crypto Ed25519 — no WebCrypto import / promise hop.
263
+ sign: async (data) => new Uint8Array(cryptoSign(null, Buffer.from(data, "utf8"), privateKey))
264
+ }
265
+ };
266
+ }
267
+ function passwordFor(opts) {
268
+ return opts.password ?? (process.env[KEY_PASSWORD_ENV] || void 0);
269
+ }
270
+ async function loadKeypair(path, opts = {}) {
271
+ if (process.platform !== "win32") {
272
+ const mode = (await stat(path)).mode & 511;
273
+ if ((mode & 63) !== 0) {
274
+ throw new Error(
275
+ `Key file ${path} has mode 0o${mode.toString(8)}; expected 0o600. Fix: chmod 600 ${path}`
276
+ );
277
+ }
278
+ } else if (!warnedWindows) {
279
+ warnedWindows = true;
280
+ process.emitWarning(
281
+ `Windows detected \u2014 file permissions on ${path} cannot be enforced via POSIX mode. Use NTFS ACLs or store the key in a per-user secrets vault.`
282
+ );
283
+ }
284
+ const pem = await readFile(path, "utf8");
285
+ const encrypted = pem.includes("ENCRYPTED");
286
+ const passphrase = passwordFor(opts);
287
+ if (encrypted && !passphrase) {
288
+ throw new TypeError(
289
+ `Key file ${path} is encrypted; pass { password } or set $${KEY_PASSWORD_ENV}`
290
+ );
291
+ }
292
+ const key = createPrivateKey(
293
+ encrypted ? { key: pem, format: "pem", passphrase } : pem
294
+ );
295
+ return keyPairFromKeyObject(key);
296
+ }
297
+ async function generateKeypairTo(path, opts = {}) {
298
+ await mkdir(dirname(path), { recursive: true });
299
+ if (await exists(path)) {
300
+ const err = new Error(
301
+ `Key already exists at ${path}; refuse overwrite`
302
+ );
303
+ err.code = "EEXIST";
304
+ throw err;
305
+ }
306
+ const { privateKey } = generateKeyPairSync("ed25519");
307
+ const passphrase = passwordFor(opts);
308
+ const pem = privateKey.export(
309
+ passphrase ? { format: "pem", type: "pkcs8", cipher: "aes-256-cbc", passphrase } : { format: "pem", type: "pkcs8" }
310
+ );
311
+ const fh = await open(path, "wx", 384);
312
+ try {
313
+ await fh.writeFile(pem);
314
+ await fh.sync();
315
+ } finally {
316
+ await fh.close();
317
+ }
318
+ return keyPairFromKeyObject(privateKey);
319
+ }
320
+
321
+ // src/signer.ts
322
+ var WEB_BOT_AUTH_TAG = "web-bot-auth";
3
323
  var DEFAULT_LABEL = "sig1";
4
324
  var DEFAULT_EXPIRES_SECONDS = 60;
5
- var DIGEST_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
6
- function componentsFor(method, hasBody) {
7
- const base = ["@authority", "signature-agent"];
8
- if (hasBody && DIGEST_METHODS.has(method.toUpperCase())) {
9
- base.push("content-digest");
325
+ var MAX_EXPIRES_SECONDS = 3600;
326
+ var NONCE_BYTES = 64;
327
+ var SF_KEY_RE = /^[a-z*][a-z0-9_\-.*]*$/;
328
+ var DEFAULT_PORTS = {
329
+ "https:": "443",
330
+ "http:": "80"
331
+ };
332
+ function sfString(value) {
333
+ for (const ch of value) {
334
+ const c = ch.charCodeAt(0);
335
+ if (c < 32 || c > 126) {
336
+ throw new Error(
337
+ `value is not a valid structured-field string: ${JSON.stringify(value)}`
338
+ );
339
+ }
10
340
  }
11
- return base;
341
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
342
+ }
343
+ function normalizeAuthority(url) {
344
+ const u = new URL(url);
345
+ if (!u.hostname) throw new Error(`URL has no host: ${url}`);
346
+ const host = u.hostname.toLowerCase();
347
+ const port = u.port && u.port !== DEFAULT_PORTS[u.protocol] ? `:${u.port}` : "";
348
+ return `${host}${port}`;
349
+ }
350
+ function componentsFor(hasBody) {
351
+ return hasBody ? ["@authority", "signature-agent", "content-digest"] : ["@authority", "signature-agent"];
12
352
  }
13
353
  var RESIGN_HEADERS = ["signature", "signature-input", "signature-agent"];
14
- function hasHeader(headers, name) {
354
+ function getHeader(headers, name) {
15
355
  const n = name.toLowerCase();
16
- return Object.keys(headers).some((k) => k.toLowerCase() === n);
356
+ const k = Object.keys(headers).find((key) => key.toLowerCase() === n);
357
+ return k === void 0 ? void 0 : headers[k];
17
358
  }
18
359
  function removeHeaders(headers, names) {
19
360
  for (const k of Object.keys(headers)) {
@@ -21,55 +362,54 @@ function removeHeaders(headers, names) {
21
362
  }
22
363
  }
23
364
  async function sign(request, identity, opts = {}) {
24
- if (!identity.signatureAgentUrl.startsWith("https://")) {
25
- throw new Error(
26
- `signatureAgentUrl must be https://, got: ${identity.signatureAgentUrl}`
27
- );
28
- }
365
+ validateSignatureAgentUrl(identity.signatureAgentUrl);
29
366
  const expiresAfterSeconds = opts.expiresAfterSeconds ?? DEFAULT_EXPIRES_SECONDS;
30
- if (!Number.isFinite(expiresAfterSeconds) || expiresAfterSeconds <= 0) {
367
+ if (typeof expiresAfterSeconds !== "number" || !Number.isFinite(expiresAfterSeconds) || expiresAfterSeconds <= 0 || expiresAfterSeconds > MAX_EXPIRES_SECONDS) {
31
368
  throw new RangeError(
32
- `expiresAfterSeconds must be a positive number, got: ${expiresAfterSeconds}`
369
+ `expiresAfterSeconds must be a number in (0, ${MAX_EXPIRES_SECONDS}], got: ${expiresAfterSeconds}`
33
370
  );
34
371
  }
35
- removeHeaders(request.headers, RESIGN_HEADERS);
36
- const signatureAgentHeader = `"${identity.signatureAgentUrl}"`;
37
- request.headers["Signature-Agent"] = signatureAgentHeader;
38
- const created = opts.created ?? /* @__PURE__ */ new Date();
39
- const expires = new Date(created.getTime() + expiresAfterSeconds * 1e3);
40
372
  const label = opts.label ?? DEFAULT_LABEL;
41
- const hasBody = request.body !== null && request.body !== void 0 && request.body.byteLength > 0;
42
- const components = componentsFor(request.method, hasBody);
43
- if (components.includes("content-digest") && !hasHeader(request.headers, "content-digest")) {
373
+ if (!SF_KEY_RE.test(label)) {
44
374
  throw new Error(
45
- 'Covered header field "content-digest" not found in the message. Call ensureContentDigest() or use createSignedFetch()/applyTo(), which add it automatically.'
375
+ `label must be an RFC 8941 key, got: ${JSON.stringify(label)}`
46
376
  );
47
377
  }
48
- const headers = new Headers();
49
- for (const [k, v] of Object.entries(request.headers)) headers.set(k, v);
50
- const init = { method: request.method, headers };
51
- if (hasBody) init.body = request.body;
52
- const req = new Request(request.url, init);
53
- const params = {
54
- created,
55
- expires,
56
- key: label,
57
- components,
58
- ...opts.nonce !== void 0 ? { nonce: opts.nonce } : {}
59
- };
60
- const result = await signatureHeaders(req, identity._signer(), params);
61
- request.headers.Signature = result.Signature;
62
- request.headers["Signature-Input"] = result["Signature-Input"];
63
- return {
64
- signature: result.Signature,
65
- signatureInput: result["Signature-Input"],
66
- signatureAgent: signatureAgentHeader
378
+ removeHeaders(request.headers, RESIGN_HEADERS);
379
+ const signatureAgentHeader = sfString(identity.signatureAgentUrl);
380
+ request.headers["Signature-Agent"] = signatureAgentHeader;
381
+ const created = Math.floor((opts.created ?? /* @__PURE__ */ new Date()).getTime() / 1e3);
382
+ const expires = created + Math.floor(expiresAfterSeconds);
383
+ const nonce = opts.nonce ?? randomBytes(NONCE_BYTES).toString("base64");
384
+ const hasBody = request.body != null && request.body.byteLength > 0;
385
+ const components = componentsFor(hasBody);
386
+ const values = {
387
+ "@authority": normalizeAuthority(request.url),
388
+ "signature-agent": signatureAgentHeader
67
389
  };
390
+ if (hasBody) {
391
+ const cd = getHeader(request.headers, "content-digest");
392
+ if (cd === void 0) {
393
+ throw new Error(
394
+ 'Covered header field "content-digest" not found in the message. Call ensureContentDigest() or use createSignedFetch()/applyTo(), which add it automatically.'
395
+ );
396
+ }
397
+ values["content-digest"] = cd.trim();
398
+ }
399
+ const signer = identity._signer();
400
+ const params = `(${components.map((c) => `"${c}"`).join(" ")});created=${created};keyid=${sfString(signer.keyid)};alg="ed25519";expires=${expires};nonce=${sfString(nonce)};tag=${sfString(WEB_BOT_AUTH_TAG)}`;
401
+ const base = `${components.map((c) => `"${c}": ${values[c]}`).join("\n")}
402
+ "@signature-params": ${params}`;
403
+ const raw = await signer.sign(base);
404
+ const signatureInput = `${label}=${params}`;
405
+ const signature = `${label}=:${Buffer.from(raw).toString("base64")}:`;
406
+ request.headers["Signature-Input"] = signatureInput;
407
+ request.headers.Signature = signature;
408
+ return { signature, signatureInput, signatureAgent: signatureAgentHeader };
68
409
  }
69
410
 
70
411
  // src/adapters/_utils.ts
71
- import { createHash } from "crypto";
72
- var DIGEST_METHODS2 = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
412
+ import { createHash as createHash2 } from "crypto";
73
413
  var LIBRARY_DEFAULT_UA = /^(node|undici|node-fetch)(\/|$)/i;
74
414
  function findHeader(headers, name) {
75
415
  const n = name.toLowerCase();
@@ -77,11 +417,42 @@ function findHeader(headers, name) {
77
417
  }
78
418
  function ensureContentDigest(method, headers, body) {
79
419
  if (!body || body.byteLength === 0) return;
80
- if (!DIGEST_METHODS2.has(method.toUpperCase())) return;
81
- if (findHeader(headers, "content-digest")) return;
82
- const b64 = createHash("sha256").update(body).digest("base64");
420
+ void method;
421
+ const b64 = createHash2("sha256").update(body).digest("base64");
422
+ const key = findHeader(headers, "content-digest");
423
+ if (key !== void 0) {
424
+ const m = /(?:^|,)\s*sha-256=:([A-Za-z0-9+/=]+):/.exec(headers[key] ?? "");
425
+ if (m === null || m[1] === b64) return;
426
+ delete headers[key];
427
+ }
83
428
  headers["Content-Digest"] = `sha-256=:${b64}:`;
84
429
  }
430
+ var SIGNATURE_HEADERS = /* @__PURE__ */ new Set([
431
+ "signature",
432
+ "signature-input",
433
+ "signature-agent"
434
+ ]);
435
+ function stripSignatureHeaders(headers) {
436
+ for (const k of Object.keys(headers)) {
437
+ if (SIGNATURE_HEADERS.has(k.toLowerCase())) delete headers[k];
438
+ }
439
+ }
440
+ function makeSignDecider(opts = {}) {
441
+ return (raw) => {
442
+ let u;
443
+ try {
444
+ u = new URL(raw);
445
+ } catch {
446
+ return false;
447
+ }
448
+ if (u.protocol !== "https:" && u.protocol !== "http:") return false;
449
+ if (!u.hostname) return false;
450
+ if (u.protocol === "http:" && !opts.allowInsecure) return false;
451
+ if (opts.shouldSign) return opts.shouldSign(u);
452
+ if (opts.hosts) return hostMatches(u.hostname, opts.hosts);
453
+ return true;
454
+ };
455
+ }
85
456
  function applyUserAgent(headers, userAgent) {
86
457
  if (!userAgent) return;
87
458
  const key = findHeader(headers, "user-agent");
@@ -107,60 +478,100 @@ function hostMatches(hostname, allow) {
107
478
  }
108
479
 
109
480
  // src/adapters/fetch.ts
481
+ var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
482
+ var CROSS_ORIGIN_STRIP = /* @__PURE__ */ new Set([
483
+ "authorization",
484
+ "cookie",
485
+ "proxy-authorization"
486
+ ]);
487
+ var BODY_HEADERS = /* @__PURE__ */ new Set([
488
+ "content-type",
489
+ "content-length",
490
+ "content-encoding",
491
+ "content-language",
492
+ "content-location",
493
+ "content-digest"
494
+ ]);
495
+ function dropHeaders(headers, names) {
496
+ for (const k of Object.keys(headers)) {
497
+ if (names.has(k.toLowerCase())) delete headers[k];
498
+ }
499
+ }
110
500
  function createSignedFetch(identity, options = {}) {
501
+ const decide = makeSignDecider(options);
111
502
  return async function signedFetch(input, init = {}) {
112
503
  const req = new Request(input, init);
113
- const method = req.method;
114
- const url = req.url;
504
+ let method = req.method;
505
+ let url = req.url;
115
506
  let body = null;
116
507
  if (req.body) {
117
508
  const buf = await req.clone().arrayBuffer();
118
509
  body = buf.byteLength > 0 ? new Uint8Array(buf) : null;
119
510
  }
120
- const headers = {};
511
+ const baseHeaders = {};
121
512
  req.headers.forEach((value, key) => {
122
- headers[key] = value;
513
+ baseHeaders[key] = value;
123
514
  });
124
- ensureContentDigest(method, headers, body);
125
- await sign({ method, url, headers, body }, identity);
126
- applyUserAgent(headers, identity.userAgent);
127
- const outInit = {
128
- ...init,
129
- method,
130
- headers,
131
- // Uint8Array is a valid BodyInit at runtime; DOM typings disagree.
132
- body: body ?? void 0,
133
- signal: init.signal ?? req.signal,
134
- redirect: init.redirect ?? req.redirect,
135
- credentials: init.credentials ?? req.credentials,
136
- cache: init.cache ?? req.cache,
137
- keepalive: init.keepalive ?? req.keepalive
138
- };
139
- const integrity = init.integrity ?? req.integrity;
140
- if (integrity) outInit.integrity = integrity;
141
- const referrerPolicy = init.referrerPolicy ?? req.referrerPolicy;
142
- if (referrerPolicy) outInit.referrerPolicy = referrerPolicy;
515
+ const redirectMode = init.redirect ?? req.redirect;
516
+ const followHere = redirectMode === "follow";
517
+ const maxRedirects = options.maxRedirects ?? 20;
143
518
  const doFetch = options.fetch ?? globalThis.fetch;
144
- return doFetch(url, outInit);
519
+ for (let hop = 0; ; hop++) {
520
+ const headers = { ...baseHeaders };
521
+ if (decide(url)) {
522
+ ensureContentDigest(method, headers, body);
523
+ await sign({ method, url, headers, body }, identity);
524
+ } else {
525
+ stripSignatureHeaders(headers);
526
+ }
527
+ applyUserAgent(headers, identity.userAgent);
528
+ const outInit = {
529
+ ...init,
530
+ method,
531
+ headers,
532
+ body: body ?? void 0,
533
+ signal: init.signal ?? req.signal,
534
+ redirect: followHere ? "manual" : redirectMode,
535
+ credentials: init.credentials ?? req.credentials,
536
+ cache: init.cache ?? req.cache,
537
+ keepalive: init.keepalive ?? req.keepalive
538
+ };
539
+ const integrity = init.integrity ?? req.integrity;
540
+ if (integrity) outInit.integrity = integrity;
541
+ const referrerPolicy = init.referrerPolicy ?? req.referrerPolicy;
542
+ if (referrerPolicy) outInit.referrerPolicy = referrerPolicy;
543
+ const res = await doFetch(url, outInit);
544
+ if (!followHere || !REDIRECT_STATUSES.has(res.status)) return res;
545
+ const location = res.headers.get("location");
546
+ if (location === null) return res;
547
+ if (hop >= maxRedirects) {
548
+ throw new TypeError(`redirect count exceeded (${maxRedirects})`);
549
+ }
550
+ const next = new URL(location, url);
551
+ if (next.protocol !== "http:" && next.protocol !== "https:") {
552
+ throw new TypeError(`unsupported redirect scheme: ${next.protocol}`);
553
+ }
554
+ const upper = method.toUpperCase();
555
+ if (res.status === 303 && upper !== "GET" && upper !== "HEAD" || (res.status === 301 || res.status === 302) && upper === "POST") {
556
+ method = "GET";
557
+ body = null;
558
+ dropHeaders(baseHeaders, BODY_HEADERS);
559
+ }
560
+ if (new URL(url).origin !== next.origin) {
561
+ dropHeaders(baseHeaders, CROSS_ORIGIN_STRIP);
562
+ }
563
+ await res.body?.cancel().catch(() => {
564
+ });
565
+ url = next.href;
566
+ }
145
567
  };
146
568
  }
147
569
 
148
570
  // src/adapters/playwright.ts
149
571
  async function applyTo(page, identity, options = {}) {
150
572
  const pattern = options.pattern ?? "**/*";
151
- const decide = (raw) => {
152
- let u;
153
- try {
154
- u = new URL(raw);
155
- } catch {
156
- return false;
157
- }
158
- if (u.protocol !== "https:" && u.protocol !== "http:") return false;
159
- if (options.shouldSign) return options.shouldSign(u);
160
- if (options.hosts) return hostMatches(u.hostname, options.hosts);
161
- return true;
162
- };
163
- await page.route(pattern, async (route, request) => {
573
+ const decide = makeSignDecider(options);
574
+ const handler = async (route, request) => {
164
575
  const url = request.url();
165
576
  if (!decide(url)) {
166
577
  const r = route;
@@ -174,175 +585,320 @@ async function applyTo(page, identity, options = {}) {
174
585
  await sign({ method: request.method(), url, headers, body }, identity);
175
586
  applyUserAgent(headers, identity.userAgent);
176
587
  await route.continue({ headers });
177
- });
588
+ };
589
+ await page.route(pattern, handler);
590
+ return async () => {
591
+ await page.unroute(pattern, handler);
592
+ };
178
593
  }
179
594
 
180
- // src/identity.ts
181
- import { createPrivateKey, generateKeyPairSync } from "crypto";
595
+ // src/verifier.ts
182
596
  import {
183
- closeSync,
184
- existsSync,
185
- mkdirSync,
186
- openSync,
187
- readFileSync,
188
- statSync,
189
- writeFileSync
190
- } from "fs";
191
- import { homedir } from "os";
192
- import { dirname, resolve } from "path";
193
- import { signerFromJWK } from "web-bot-auth/crypto";
194
- var DEFAULT_KEY_PATH = resolve(
195
- homedir(),
196
- ".config",
197
- "wbauth",
198
- "key.pem"
199
- );
200
- var TEST_KEY_JWK = {
201
- kty: "OKP",
202
- crv: "Ed25519",
203
- d: "n4Ni-HpISpVObnQMW0wOhCKROaIKqKtW_2ZYb2p9KcU",
204
- x: "JrQLj5P_89iXES9-vFgrIy29clF9CC_oPPsw3c5D0bs"
597
+ createHash as createHash3,
598
+ createPublicKey as createPublicKey2,
599
+ verify as cryptoVerify
600
+ } from "crypto";
601
+ var DIRECTORY_PATH = "/.well-known/http-message-signatures-directory";
602
+ var DIRECTORY_MAX_BYTES = 64 * 1024;
603
+ var VerificationError = class extends Error {
604
+ name = "VerificationError";
205
605
  };
206
- var Identity = class _Identity {
207
- _active;
208
- _retiring;
209
- signatureAgentUrl;
210
- userAgent;
211
- constructor(active, opts, retiring = null) {
212
- if (!opts.signatureAgentUrl.startsWith("https://")) {
213
- throw new Error(
214
- `signatureAgentUrl must be https://, got: ${opts.signatureAgentUrl}`
215
- );
216
- }
217
- this._active = active;
218
- this._retiring = retiring;
219
- this.signatureAgentUrl = opts.signatureAgentUrl;
220
- this.userAgent = opts.userAgent;
606
+ var NonceStore = class {
607
+ constructor(maxSize = 1e5) {
608
+ this.maxSize = maxSize;
221
609
  }
222
- // ---------- Public read-only API ----------
223
- /** The active key's kid (used as `keyid=` param in Signature-Input). */
224
- get kid() {
225
- return this._active.kid;
226
- }
227
- /** Module-internal: returns the resolved Signer for sign() to use. */
228
- _signer() {
229
- return this._active.signer;
610
+ maxSize;
611
+ #seen = /* @__PURE__ */ new Map();
612
+ seen(nonce, expiresAt) {
613
+ const now = Date.now() / 1e3;
614
+ if (this.#seen.size >= this.maxSize) {
615
+ for (const [n, e] of this.#seen) if (e <= now) this.#seen.delete(n);
616
+ for (const n of [...this.#seen.keys()].slice(
617
+ 0,
618
+ Math.ceil(this.maxSize / 10)
619
+ )) {
620
+ if (this.#seen.size < this.maxSize) break;
621
+ this.#seen.delete(n);
622
+ }
623
+ }
624
+ const prev = this.#seen.get(nonce);
625
+ if (prev !== void 0 && prev > now) return true;
626
+ this.#seen.set(nonce, expiresAt);
627
+ return false;
230
628
  }
231
- /**
232
- * Export the public JWKS document.
233
- *
234
- * Returns `{keys: [active_jwk]}` if no retiring key is held, or
235
- * `{keys: [active_jwk, retiring_jwk]}` after a rotation. Active is always
236
- * first. Verifiers select by `kid`. Mirror of Python `export_jwks`.
237
- */
238
- exportJwks() {
239
- const keys = [this._active.publicJwk];
240
- if (this._retiring) keys.push(this._retiring.publicJwk);
241
- return { keys };
629
+ };
630
+ var SF_STRING = String.raw`"(?:[^"\\]|\\.)*"`;
631
+ var PARAM = String.raw`;\s*([a-z*][a-z0-9_.*-]*)(?:=(${SF_STRING}|-?\d+(?:\.\d+)?|\?[01]|[A-Za-z*][^;,\s]*))?`;
632
+ var SIG_INPUT_RE = new RegExp(
633
+ String.raw`\s*([a-z*][a-z0-9_.*-]*)=(\((?:\s*${SF_STRING}(?:;[^\s)"]+)*)*\s*\))((?:${PARAM})*)`,
634
+ "y"
635
+ );
636
+ var unquote = (v) => v.startsWith('"') ? v.slice(1, -1).replace(/\\(.)/g, "$1") : v;
637
+ function parseSignatureInput(value) {
638
+ const out = [];
639
+ let pos = 0;
640
+ while (pos < value.length) {
641
+ SIG_INPUT_RE.lastIndex = pos;
642
+ const m = SIG_INPUT_RE.exec(value);
643
+ if (!m) throw new VerificationError("malformed Signature-Input");
644
+ const [, label = "", inner = "", rest = ""] = m;
645
+ if (/"\s*;/.test(inner))
646
+ throw new VerificationError("component parameters are not supported");
647
+ const params = {};
648
+ for (const p of rest.matchAll(new RegExp(PARAM, "g"))) {
649
+ const k = p[1];
650
+ const v = p[2];
651
+ params[k] = v === void 0 ? true : v.startsWith('"') ? unquote(v) : /^-?\d+$/.test(v) ? Number(v) : v;
652
+ }
653
+ out.push({
654
+ label,
655
+ rawParams: inner + rest,
656
+ components: [...inner.matchAll(new RegExp(SF_STRING, "g"))].map(
657
+ (x) => unquote(x[0])
658
+ ),
659
+ params
660
+ });
661
+ pos = SIG_INPUT_RE.lastIndex;
662
+ while (pos < value.length && (value[pos] === " " || value[pos] === ","))
663
+ pos++;
242
664
  }
243
- /**
244
- * IDENT-07: generate a new active key, demote current to retiring.
245
- *
246
- * Returns a NEW Identity (immutable update — the old Identity is unchanged).
247
- * Any previously-retiring key is dropped (only one overlap window).
248
- */
249
- async rotate(newPath = DEFAULT_KEY_PATH) {
250
- const newPair = await generateKeypairTo(expandUser(newPath));
251
- return new _Identity(
252
- newPair,
253
- { signatureAgentUrl: this.signatureAgentUrl, userAgent: this.userAgent },
254
- this._active
255
- );
665
+ return out;
666
+ }
667
+ function parseSignature(value) {
668
+ const out = /* @__PURE__ */ new Map();
669
+ for (const m of value.matchAll(
670
+ /\s*([a-z*][a-z0-9_.*-]*)=:([A-Za-z0-9+/=]*):/g
671
+ )) {
672
+ out.set(m[1], Buffer.from(m[2], "base64"));
256
673
  }
257
- // ---------- Constructors ----------
258
- /**
259
- * Primary entry point. Loads `path` if it exists, generates a fresh key
260
- * there otherwise. The on-disk file is PKCS8 NoEncryption PEM at 0o600,
261
- * byte-equal to what Python's `Identity.load_or_generate` writes (D-60).
262
- */
263
- static async loadOrGenerate(path = DEFAULT_KEY_PATH, opts) {
264
- const resolved = expandUser(path);
265
- const pair = existsSync(resolved) ? await loadKeypair(resolved) : await generateKeypairTo(resolved);
266
- return new _Identity(pair, opts);
674
+ return out;
675
+ }
676
+ function componentValue(name, req, headers, authority) {
677
+ const u = new URL(req.url);
678
+ switch (name) {
679
+ case "@authority":
680
+ return authority ?? normalizeAuthority(req.url);
681
+ case "@method":
682
+ return req.method.toUpperCase();
683
+ case "@scheme":
684
+ return u.protocol.slice(0, -1);
685
+ case "@target-uri":
686
+ return u.href;
687
+ case "@path":
688
+ return u.pathname || "/";
689
+ case "@query":
690
+ return u.search || "?";
267
691
  }
268
- /**
269
- * Construct from the RFC 9421 Appendix B.1.4 publicly-known test key.
270
- * For tests + Cloudflare debug smoke checks. NEVER use in production.
271
- * Does NOT write any file to disk.
272
- */
273
- static async fromTestKey(signatureAgentUrl, opts = {}) {
274
- const pair = await keyPairFromJwk(TEST_KEY_JWK);
275
- return new _Identity(pair, { ...opts, signatureAgentUrl });
692
+ if (name.startsWith("@"))
693
+ throw new VerificationError(`unsupported derived component ${name}`);
694
+ const v = headers.get(name);
695
+ if (v === null) throw new VerificationError(`covered header ${name} missing`);
696
+ return v.trim();
697
+ }
698
+ function directoryUrl(signatureAgent) {
699
+ const u = new URL(signatureAgent);
700
+ if (u.protocol !== "https:")
701
+ throw new VerificationError("Signature-Agent must be https://");
702
+ if (u.pathname === "/" || u.pathname === "") {
703
+ u.pathname = DIRECTORY_PATH;
704
+ u.search = "";
276
705
  }
277
- // ---------- Redaction guarantees (IDENT-08) ----------
278
- toString() {
279
- return `<Identity REDACTED kid='${this.kid}' sig_agent='${this.signatureAgentUrl}'>`;
706
+ u.hash = "";
707
+ return u.href;
708
+ }
709
+ var Verifier = class {
710
+ #opts;
711
+ #nonces;
712
+ #jwks = /* @__PURE__ */ new Map();
713
+ constructor(opts = {}) {
714
+ this.#opts = opts;
715
+ this.#nonces = opts.nonceStore ?? new NonceStore();
280
716
  }
281
- /** util.inspect / console.log render the same REDACTED form (IDENT-08). */
282
- [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
283
- return this.toString();
717
+ async #directoryKeys(url) {
718
+ const hit = this.#jwks.get(url);
719
+ if (hit && hit.until > Date.now()) return hit.keys;
720
+ const f = this.#opts.fetch ?? globalThis.fetch;
721
+ let res;
722
+ try {
723
+ res = await f(url, {
724
+ headers: {
725
+ accept: "application/http-message-signatures-directory+json, application/json"
726
+ },
727
+ redirect: "error",
728
+ signal: AbortSignal.timeout(3e3)
729
+ });
730
+ } catch (e) {
731
+ throw new VerificationError(`directory unreachable: ${String(e)}`);
732
+ }
733
+ if (res.status !== 200)
734
+ throw new VerificationError(`directory ${url} answered ${res.status}`);
735
+ const buf = await res.arrayBuffer();
736
+ if (buf.byteLength > DIRECTORY_MAX_BYTES)
737
+ throw new VerificationError("directory too large");
738
+ let keys;
739
+ try {
740
+ keys = JSON.parse(new TextDecoder().decode(buf)).keys;
741
+ } catch {
742
+ throw new VerificationError("directory is not a JWKS");
743
+ }
744
+ if (!Array.isArray(keys))
745
+ throw new VerificationError("directory is not a JWKS");
746
+ this.#jwks.set(url, {
747
+ until: Date.now() + (this.#opts.jwksTtlSeconds ?? 300) * 1e3,
748
+ keys
749
+ });
750
+ return keys;
284
751
  }
285
- };
286
- function expandUser(path) {
287
- return resolve(path.startsWith("~") ? path.replace(/^~/, homedir()) : path);
288
- }
289
- async function keyPairFromJwk(privateJwk) {
290
- const signer = await signerFromJWK(privateJwk);
291
- const kid = signer.keyid;
292
- const publicJwk = {
293
- kty: privateJwk.kty,
294
- crv: privateJwk.crv,
295
- x: privateJwk.x,
296
- kid
297
- };
298
- return { privateJwk, publicJwk, kid, signer };
299
- }
300
- async function loadKeypair(path) {
301
- if (process.platform !== "win32") {
302
- const mode = statSync(path).mode & 511;
303
- if ((mode & 63) !== 0) {
304
- throw new Error(
305
- `Key file ${path} has mode 0o${mode.toString(8)}; expected 0o600. Fix: chmod 600 ${path}`
752
+ async #resolve(kid, signatureAgent) {
753
+ if (this.#opts.keyResolver) {
754
+ const jwk = await this.#opts.keyResolver(kid, signatureAgent);
755
+ if (!jwk) throw new VerificationError(`unknown keyid ${kid}`);
756
+ return jwk;
757
+ }
758
+ if (!signatureAgent)
759
+ throw new VerificationError(
760
+ "no Signature-Agent and no keyResolver configured"
306
761
  );
762
+ for (const k of await this.#directoryKeys(directoryUrl(signatureAgent))) {
763
+ if (k && k.kty === "OKP" && k.crv === "Ed25519" && k.x && thumbprint(k) === kid)
764
+ return k;
307
765
  }
308
- } else {
309
- process.emitWarning(
310
- `Windows detected \u2014 file permissions on ${path} cannot be enforced via POSIX mode. Use NTFS ACLs or store the key in a per-user secrets vault.`
766
+ throw new VerificationError(
767
+ `keyid ${kid} not published by ${signatureAgent}`
311
768
  );
312
769
  }
313
- const pem = readFileSync(path, "utf8");
314
- const jwk = createPrivateKey(pem).export({ format: "jwk" });
315
- if (jwk.kty !== "OKP" || jwk.crv !== "Ed25519") {
316
- throw new TypeError(`Expected Ed25519, got kty=${jwk.kty}, crv=${jwk.crv}`);
317
- }
318
- return keyPairFromJwk(jwk);
319
- }
320
- async function generateKeypairTo(path) {
321
- const dir = dirname(path);
322
- mkdirSync(dir, { recursive: true });
323
- if (existsSync(path)) {
324
- throw new Error(`Key already exists at ${path}; refuse overwrite`);
325
- }
326
- const { privateKey } = generateKeyPairSync("ed25519");
327
- const pem = privateKey.export({ format: "pem", type: "pkcs8" });
328
- const fd = openSync(path, "wx", 384);
329
- try {
330
- writeFileSync(fd, pem);
331
- } finally {
332
- closeSync(fd);
770
+ /**
771
+ * Verify a WHATWG Request (body is read from a clone). `authority`
772
+ * overrides the value derived from the URL (e.g. behind a proxy).
773
+ */
774
+ async verify(request, opts = {}) {
775
+ const h = request.headers;
776
+ const sigInput = h.get("signature-input");
777
+ const sigHeader = h.get("signature");
778
+ if (!sigInput || !sigHeader)
779
+ throw new VerificationError("request is not signed");
780
+ const sigs = parseSignature(sigHeader);
781
+ const cand = parseSignatureInput(sigInput).find(
782
+ (c) => c.params.tag === WEB_BOT_AUTH_TAG
783
+ );
784
+ if (!cand)
785
+ throw new VerificationError('no signature with tag="web-bot-auth"');
786
+ const { label, rawParams, components, params } = cand;
787
+ const raw = sigs.get(label);
788
+ if (!raw) throw new VerificationError(`Signature has no ${label} member`);
789
+ if ((params.alg ?? "ed25519") !== "ed25519")
790
+ throw new VerificationError("only alg=ed25519 is supported");
791
+ const { created, expires, keyid } = params;
792
+ if (typeof created !== "number" || typeof expires !== "number" || typeof keyid !== "string") {
793
+ throw new VerificationError("created, expires and keyid are required");
794
+ }
795
+ const skew = this.#opts.maxSkew ?? 5;
796
+ const now = opts.now ?? Date.now() / 1e3;
797
+ if (created > now + skew)
798
+ throw new VerificationError("signature created in the future");
799
+ if (expires < now - skew) throw new VerificationError("signature expired");
800
+ if (expires <= created || expires - created > MAX_EXPIRES_SECONDS) {
801
+ throw new VerificationError("invalid validity window");
802
+ }
803
+ if (!components.includes("@authority"))
804
+ throw new VerificationError("@authority must be covered");
805
+ let signatureAgent = null;
806
+ const sa = h.get("signature-agent");
807
+ if (sa !== null) {
808
+ if (!components.includes("signature-agent")) {
809
+ throw new VerificationError("Signature-Agent sent but not covered");
810
+ }
811
+ signatureAgent = unquote(sa.trim());
812
+ }
813
+ const body = request.body ? new Uint8Array(await request.clone().arrayBuffer()) : new Uint8Array();
814
+ if (body.byteLength > 0) {
815
+ if (!components.includes("content-digest")) {
816
+ throw new VerificationError(
817
+ "request has a body but content-digest is not covered"
818
+ );
819
+ }
820
+ const m = /(?:^|,)\s*sha-256=:([A-Za-z0-9+/=]+):/.exec(
821
+ h.get("content-digest") ?? ""
822
+ );
823
+ const actual = createHash3("sha256").update(body).digest("base64");
824
+ if (!m || m[1] !== actual)
825
+ throw new VerificationError("Content-Digest does not match the body");
826
+ }
827
+ const nonce = typeof params.nonce === "string" ? params.nonce : null;
828
+ if (this.#opts.requireNonce && !nonce)
829
+ throw new VerificationError("nonce required");
830
+ const base = [
831
+ ...components.map(
832
+ (c) => `"${c}": ${componentValue(c, request, h, opts.authority)}`
833
+ ),
834
+ `"@signature-params": ${rawParams}`
835
+ ].join("\n");
836
+ const jwk = await this.#resolve(keyid, signatureAgent);
837
+ let ok = false;
838
+ try {
839
+ const key = createPublicKey2({
840
+ key: { kty: "OKP", crv: "Ed25519", x: jwk.x },
841
+ format: "jwk"
842
+ });
843
+ ok = cryptoVerify(null, Buffer.from(base, "utf8"), key, raw);
844
+ } catch {
845
+ ok = false;
846
+ }
847
+ if (!ok) throw new VerificationError("signature does not verify");
848
+ if (nonce && this.#nonces.seen(nonce, expires + skew))
849
+ throw new VerificationError("nonce replayed");
850
+ return {
851
+ kid: keyid,
852
+ signatureAgentUrl: signatureAgent,
853
+ label,
854
+ created,
855
+ expires,
856
+ nonce,
857
+ covered: components,
858
+ jwk
859
+ };
333
860
  }
334
- const jwk = privateKey.export({ format: "jwk" });
335
- return keyPairFromJwk(jwk);
861
+ };
862
+ function createVerifierMiddleware(opts = {}) {
863
+ const verifier = new Verifier(opts);
864
+ return async (request) => {
865
+ const signed = request.headers.has("signature-input");
866
+ if (!signed && !opts.required) return null;
867
+ try {
868
+ if (!signed) throw new VerificationError("request is not signed");
869
+ return await verifier.verify(request);
870
+ } catch (e) {
871
+ if (!opts.required) return null;
872
+ return new Response(
873
+ JSON.stringify({
874
+ error: "web_bot_auth",
875
+ reason: String(e.message)
876
+ }),
877
+ {
878
+ status: 401,
879
+ headers: { "content-type": "application/json" }
880
+ }
881
+ );
882
+ }
883
+ };
336
884
  }
337
885
 
338
886
  // src/index.ts
339
- var VERSION = "0.2.0";
887
+ var VERSION = "0.4.0";
340
888
  export {
341
889
  DEFAULT_KEY_PATH,
342
890
  Identity,
891
+ KEY_PASSWORD_ENV,
892
+ NonceStore,
343
893
  VERSION,
894
+ VerificationError,
895
+ Verifier,
344
896
  applyTo,
345
897
  createSignedFetch,
346
- sign
898
+ createVerifierMiddleware,
899
+ normalizeAuthority,
900
+ sign,
901
+ thumbprint,
902
+ validateSignatureAgentUrl
347
903
  };
348
904
  //# sourceMappingURL=index.js.map