@lumoauth/agent 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -24,6 +24,9 @@ __export(index_exports, {
24
24
  AAuthClient: () => AAuthClient,
25
25
  AAuthError: () => AAuthError,
26
26
  AccessTokenError: () => AccessTokenError,
27
+ CLIENT_ASSERTION_TYP: () => CLIENT_ASSERTION_TYP,
28
+ CLIENT_ASSERTION_TYPE: () => CLIENT_ASSERTION_TYPE,
29
+ ClientAssertionSigner: () => ClientAssertionSigner,
27
30
  DPOP_NONCE_HEADER: () => import_shared7.DPOP_NONCE_HEADER,
28
31
  DPOP_SCHEME: () => import_shared7.DPOP_SCHEME,
29
32
  DpopProofSigner: () => DpopProofSigner,
@@ -43,6 +46,7 @@ __export(index_exports, {
43
46
  LumoAuthPermissionDeniedError: () => import_shared8.LumoAuthPermissionDeniedError,
44
47
  LumoAuthRateLimitError: () => import_shared8.LumoAuthRateLimitError,
45
48
  LumoAuthValidationError: () => import_shared8.LumoAuthValidationError,
49
+ MAX_ASSERTION_LIFETIME_SECONDS: () => MAX_ASSERTION_LIFETIME_SECONDS,
46
50
  USE_DPOP_NONCE: () => import_shared7.USE_DPOP_NONCE,
47
51
  accessTokenScopes: () => accessTokenScopes,
48
52
  attestWorkload: () => attestWorkload,
@@ -56,6 +60,7 @@ __export(index_exports, {
56
60
  fetchWithDpop: () => import_shared7.fetchWithDpop,
57
61
  generateKeypair: () => generateKeypair,
58
62
  generateNonce: () => generateNonce,
63
+ issuerFor: () => issuerFor,
59
64
  jwkThumbprint: () => jwkThumbprint,
60
65
  parseAuthorizationHeader: () => parseAuthorizationHeader,
61
66
  publicJwkFromPrivateKey: () => publicJwkFromPrivateKey,
@@ -71,6 +76,157 @@ module.exports = __toCommonJS(index_exports);
71
76
 
72
77
  // src/agent.ts
73
78
  var import_shared = require("@lumoauth/shared");
79
+
80
+ // src/client-assertion.ts
81
+ var import_node_crypto = require("crypto");
82
+ var CLIENT_ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer";
83
+ var CLIENT_ASSERTION_TYP = "client-authentication+jwt";
84
+ var MAX_ASSERTION_LIFETIME_SECONDS = 600;
85
+ var RSA_ALGORITHMS = ["RS256", "RS384", "RS512", "PS256", "PS384", "PS512"];
86
+ var EC_ALGORITHM_BY_CURVE = {
87
+ prime256v1: "ES256",
88
+ "P-256": "ES256",
89
+ secp384r1: "ES384",
90
+ "P-384": "ES384",
91
+ secp521r1: "ES512",
92
+ "P-521": "ES512"
93
+ };
94
+ var ClientAssertionSigner = class _ClientAssertionSigner {
95
+ /** Generate a new key: ES256 (default), ES384, ES512, EdDSA, or an RSA algorithm (2048-bit key). */
96
+ static generate(algorithm = "ES256", keyId) {
97
+ let privateKey;
98
+ if (algorithm === "ES256" || algorithm === "ES384" || algorithm === "ES512") {
99
+ const namedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[algorithm];
100
+ privateKey = (0, import_node_crypto.generateKeyPairSync)("ec", { namedCurve }).privateKey;
101
+ } else if (algorithm === "EdDSA") {
102
+ privateKey = (0, import_node_crypto.generateKeyPairSync)("ed25519").privateKey;
103
+ } else if (RSA_ALGORITHMS.includes(algorithm)) {
104
+ privateKey = (0, import_node_crypto.generateKeyPairSync)("rsa", { modulusLength: 2048 }).privateKey;
105
+ } else {
106
+ throw new Error(`Unsupported client assertion algorithm: ${String(algorithm)}`);
107
+ }
108
+ return new _ClientAssertionSigner({ privateKey, keyId, algorithm });
109
+ }
110
+ /** Load a PEM private key. */
111
+ static fromPem(pem, options = {}) {
112
+ return new _ClientAssertionSigner({ ...options, privateKeyPem: pem });
113
+ }
114
+ constructor(options) {
115
+ if (options.privateKey) {
116
+ this.key = options.privateKey;
117
+ } else if (options.privateKeyPem) {
118
+ this.key = (0, import_node_crypto.createPrivateKey)(options.privateKeyPem);
119
+ } else {
120
+ throw new Error("ClientAssertionSigner needs privateKeyPem or privateKey");
121
+ }
122
+ if (this.key.type !== "private") {
123
+ throw new Error("ClientAssertionSigner needs a private key");
124
+ }
125
+ const natural = naturalAlgorithm(this.key);
126
+ const chosen = options.algorithm ?? natural;
127
+ if (this.key.asymmetricKeyType === "rsa") {
128
+ if (!RSA_ALGORITHMS.includes(chosen)) {
129
+ throw new Error(`${chosen} does not fit an RSA key; use one of ${RSA_ALGORITHMS.join(", ")}`);
130
+ }
131
+ const bits = this.key.asymmetricKeyDetails?.modulusLength ?? 0;
132
+ if (bits < 2048) throw new Error("RSA keys must be at least 2048 bits");
133
+ } else if (chosen !== natural) {
134
+ throw new Error(`${chosen} does not fit this key; it signs with ${natural}`);
135
+ }
136
+ const lifetime = options.lifetimeSeconds ?? 60;
137
+ if (!Number.isInteger(lifetime) || lifetime < 1 || lifetime > MAX_ASSERTION_LIFETIME_SECONDS) {
138
+ throw new Error(`lifetimeSeconds must be an integer from 1 to ${MAX_ASSERTION_LIFETIME_SECONDS}`);
139
+ }
140
+ this.algorithm = chosen;
141
+ this.keyId = options.keyId;
142
+ this.lifetimeSeconds = lifetime;
143
+ this.now = options.now ?? (() => Math.floor(Date.now() / 1e3));
144
+ }
145
+ /** Sign one assertion for `clientId` (the agent ID) and `audience` (the organization's issuer). */
146
+ create(clientId, audience) {
147
+ if (!clientId || !audience) {
148
+ throw new Error("clientId and audience are required for a client assertion");
149
+ }
150
+ const iat = this.now();
151
+ const header = { alg: this.algorithm, typ: CLIENT_ASSERTION_TYP };
152
+ if (this.keyId) header.kid = this.keyId;
153
+ const claims = {
154
+ iss: clientId,
155
+ sub: clientId,
156
+ aud: audience,
157
+ iat,
158
+ exp: iat + this.lifetimeSeconds,
159
+ jti: (0, import_node_crypto.randomBytes)(24).toString("base64url")
160
+ };
161
+ const signingInput = `${b64url(JSON.stringify(header))}.${b64url(JSON.stringify(claims))}`;
162
+ return `${signingInput}.${signAssertion(this.algorithm, Buffer.from(signingInput, "utf8"), this.key).toString("base64url")}`;
163
+ }
164
+ /** The public key as a JWK with `kid` (when set), `alg` and `use: "sig"`. */
165
+ get jwk() {
166
+ const pub = (0, import_node_crypto.createPublicKey)(this.key).export({ format: "jwk" });
167
+ const out = { kty: pub.kty };
168
+ for (const member of ["crv", "x", "y", "n", "e"]) {
169
+ if (typeof pub[member] === "string") out[member] = pub[member];
170
+ }
171
+ if (this.keyId) out.kid = this.keyId;
172
+ out.alg = this.algorithm;
173
+ out.use = "sig";
174
+ return out;
175
+ }
176
+ /** `{ keys: [jwk] }`: what to register on the agent. */
177
+ get jwks() {
178
+ return { keys: [this.jwk] };
179
+ }
180
+ /** The private key as PKCS#8 PEM, for your secret store. */
181
+ get privateKeyPem() {
182
+ return this.key.export({ type: "pkcs8", format: "pem" }).toString();
183
+ }
184
+ };
185
+ function issuerFor(baseUrl, orgId) {
186
+ return `${baseUrl.replace(/\/+$/, "")}/orgs/${orgId}/api/v1`;
187
+ }
188
+ function naturalAlgorithm(key) {
189
+ switch (key.asymmetricKeyType) {
190
+ case "ec": {
191
+ const curve = String(key.asymmetricKeyDetails?.namedCurve ?? "");
192
+ const alg = EC_ALGORITHM_BY_CURVE[curve];
193
+ if (!alg) throw new Error(`EC keys must use P-256, P-384 or P-521 (got ${curve})`);
194
+ return alg;
195
+ }
196
+ case "ed25519":
197
+ return "EdDSA";
198
+ case "rsa":
199
+ return "RS256";
200
+ default:
201
+ throw new Error(`Unsupported key type: ${String(key.asymmetricKeyType)}`);
202
+ }
203
+ }
204
+ function signAssertion(alg, data, key) {
205
+ const hash = `sha${alg.slice(2)}`;
206
+ switch (alg) {
207
+ case "ES256":
208
+ case "ES384":
209
+ case "ES512":
210
+ return (0, import_node_crypto.sign)(hash, data, { key, dsaEncoding: "ieee-p1363" });
211
+ case "EdDSA":
212
+ return (0, import_node_crypto.sign)(null, data, key);
213
+ case "PS256":
214
+ case "PS384":
215
+ case "PS512":
216
+ return (0, import_node_crypto.sign)(hash, data, {
217
+ key,
218
+ padding: import_node_crypto.constants.RSA_PKCS1_PSS_PADDING,
219
+ saltLength: import_node_crypto.constants.RSA_PSS_SALTLEN_DIGEST
220
+ });
221
+ default:
222
+ return (0, import_node_crypto.sign)(hash, data, key);
223
+ }
224
+ }
225
+ function b64url(text) {
226
+ return Buffer.from(text, "utf8").toString("base64url");
227
+ }
228
+
229
+ // src/agent.ts
74
230
  function envVar(name) {
75
231
  return typeof process !== "undefined" && process.env ? process.env[name] : void 0;
76
232
  }
@@ -82,13 +238,22 @@ var LumoAgent = class {
82
238
  this.baseUrl = (options.baseUrl ?? envVar("LUMOAUTH_URL") ?? "https://app.lumoauth.dev").replace(/\/+$/, "");
83
239
  this.orgId = options.orgId ?? envVar("LUMOAUTH_ORG_ID") ?? "";
84
240
  this.clientId = options.clientId ?? envVar("AGENT_CLIENT_ID") ?? "";
85
- this.clientSecret = options.clientSecret ?? envVar("AGENT_CLIENT_SECRET") ?? "";
241
+ const privateKey = options.privateKey ?? envVar("AGENT_PRIVATE_KEY");
242
+ const keyId = options.keyId ?? envVar("AGENT_KEY_ID");
243
+ this.assertionSigner = privateKey === void 0 || privateKey === "" ? void 0 : privateKey instanceof ClientAssertionSigner ? privateKey : ClientAssertionSigner.fromPem(privateKey, { keyId });
244
+ this.clientSecret = options.clientSecret ?? (this.assertionSigner ? "" : envVar("AGENT_CLIENT_SECRET") ?? "");
245
+ this.issuer = options.issuer;
86
246
  this.scopes = options.scopes;
87
247
  this.fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
88
248
  this.dpop = options.dpop;
89
- if (!this.clientId || !this.clientSecret) {
249
+ if (!this.clientId || !this.clientSecret && !this.assertionSigner) {
250
+ throw new import_shared.LumoAuthConfigError(
251
+ "Agent credentials required. Set AGENT_CLIENT_ID and AGENT_CLIENT_SECRET (or AGENT_PRIVATE_KEY for a private key JWT agent), or pass clientId with clientSecret or privateKey to the constructor."
252
+ );
253
+ }
254
+ if (this.clientSecret && this.assertionSigner) {
90
255
  throw new import_shared.LumoAuthConfigError(
91
- "Agent credentials required. Set AGENT_CLIENT_ID and AGENT_CLIENT_SECRET environment variables or pass clientId/clientSecret to the constructor."
256
+ "Pass clientSecret or privateKey, not both: an agent authenticates with one method."
92
257
  );
93
258
  }
94
259
  const tokenProvider = () => this.getAccessToken();
@@ -130,9 +295,14 @@ var LumoAgent = class {
130
295
  async authenticate(scopes) {
131
296
  const form = {
132
297
  grant_type: "client_credentials",
133
- client_id: this.clientId,
134
- client_secret: this.clientSecret
298
+ client_id: this.clientId
135
299
  };
300
+ if (this.assertionSigner) {
301
+ form.client_assertion_type = CLIENT_ASSERTION_TYPE;
302
+ form.client_assertion = this.createClientAssertion();
303
+ } else {
304
+ form.client_secret = this.clientSecret;
305
+ }
136
306
  const requested = scopes ?? this.scopes;
137
307
  if (requested?.length) form.scope = requested.join(" ");
138
308
  const url = `${this.baseUrl}${(0, import_shared.buildPath)(import_shared.ROUTES["oauth.token"].path, { orgId: this.requireOrgId() })}`;
@@ -176,6 +346,21 @@ var LumoAgent = class {
176
346
  get tokenType() {
177
347
  return this.token?.tokenType ?? null;
178
348
  }
349
+ /**
350
+ * A new `private_key_jwt` client assertion for this agent (single-use),
351
+ * addressed to `issuer` or `{baseUrl}/orgs/{orgId}/api/v1`.
352
+ */
353
+ createClientAssertion() {
354
+ if (!this.assertionSigner) {
355
+ throw new import_shared.LumoAuthConfigError("This agent signs no client assertions: create it with privateKey.");
356
+ }
357
+ const audience = this.issuer ?? issuerFor(this.baseUrl, this.requireOrgId());
358
+ return this.assertionSigner.create(this.clientId, audience);
359
+ }
360
+ /** The client assertion signer this agent was configured with, if any. */
361
+ get clientAssertionSigner() {
362
+ return this.assertionSigner;
363
+ }
179
364
  /** The DPoP proof signer this agent was configured with, if any. */
180
365
  get dpopSigner() {
181
366
  return this.dpop;
@@ -240,9 +425,9 @@ var LumoAgent = class {
240
425
  };
241
426
 
242
427
  // src/keys.ts
243
- var import_node_crypto = require("crypto");
428
+ var import_node_crypto2 = require("crypto");
244
429
  function generateKeypair(kid = "key-1") {
245
- const { privateKey, publicKey } = (0, import_node_crypto.generateKeyPairSync)("ed25519");
430
+ const { privateKey, publicKey } = (0, import_node_crypto2.generateKeyPairSync)("ed25519");
246
431
  const privateKeyPem = privateKey.export({ type: "pkcs8", format: "pem" }).toString();
247
432
  const publicKeyPem = publicKey.export({ type: "spki", format: "pem" }).toString();
248
433
  const rawJwk = publicKey.export({ format: "jwk" });
@@ -270,10 +455,10 @@ function jwkThumbprint(jwk) {
270
455
  default:
271
456
  throw new Error(`Unsupported key type for thumbprint: ${jwk.kty}`);
272
457
  }
273
- return (0, import_node_crypto.createHash)("sha256").update(canonical, "utf8").digest("base64url");
458
+ return (0, import_node_crypto2.createHash)("sha256").update(canonical, "utf8").digest("base64url");
274
459
  }
275
460
  function loadPrivateKey(pem) {
276
- const key = (0, import_node_crypto.createPrivateKey)(pem);
461
+ const key = (0, import_node_crypto2.createPrivateKey)(pem);
277
462
  if (key.asymmetricKeyType === "ed25519") {
278
463
  return { key, type: "ed25519" };
279
464
  }
@@ -285,15 +470,15 @@ function loadPrivateKey(pem) {
285
470
  );
286
471
  }
287
472
  function publicJwkFromPrivateKey(pem, kid) {
288
- const priv = (0, import_node_crypto.createPrivateKey)(pem);
289
- const pub = (0, import_node_crypto.createPublicKey)(priv);
473
+ const priv = (0, import_node_crypto2.createPrivateKey)(pem);
474
+ const pub = (0, import_node_crypto2.createPublicKey)(priv);
290
475
  const jwk = pub.export({ format: "jwk" });
291
476
  if (kid) jwk.kid = kid;
292
477
  return jwk;
293
478
  }
294
479
 
295
480
  // src/signing.ts
296
- var import_node_crypto2 = require("crypto");
481
+ var import_node_crypto3 = require("crypto");
297
482
  var AAUTH_COVERED_COMPONENTS = [
298
483
  "@method",
299
484
  "@authority",
@@ -305,11 +490,11 @@ var AAUTH_COVERED_COMPONENTS = [
305
490
  ];
306
491
  var SIGNATURE_LABEL = "sig1";
307
492
  function contentDigestSha256(body) {
308
- const digest = (0, import_node_crypto2.createHash)("sha256").update(body).digest("base64");
493
+ const digest = (0, import_node_crypto3.createHash)("sha256").update(body).digest("base64");
309
494
  return `sha-256=:${digest}:`;
310
495
  }
311
496
  function generateNonce() {
312
- return (0, import_node_crypto2.randomBytes)(16).toString("base64url");
497
+ return (0, import_node_crypto3.randomBytes)(16).toString("base64url");
313
498
  }
314
499
  function buildSignatureBase(components, values, created, nonce) {
315
500
  const lines = components.map((c) => `"${c}": ${values[c] ?? ""}`);
@@ -324,12 +509,12 @@ function signSignatureBase(signatureBase, privateKey) {
324
509
  const data = Buffer.from(signatureBase, "utf8");
325
510
  let signature;
326
511
  if (privateKey.asymmetricKeyType === "ed25519") {
327
- signature = (0, import_node_crypto2.sign)(null, data, privateKey);
512
+ signature = (0, import_node_crypto3.sign)(null, data, privateKey);
328
513
  } else {
329
- signature = (0, import_node_crypto2.sign)("sha512", data, {
514
+ signature = (0, import_node_crypto3.sign)("sha512", data, {
330
515
  key: privateKey,
331
- padding: import_node_crypto2.constants.RSA_PKCS1_PSS_PADDING,
332
- saltLength: import_node_crypto2.constants.RSA_PSS_SALTLEN_DIGEST
516
+ padding: import_node_crypto3.constants.RSA_PKCS1_PSS_PADDING,
517
+ saltLength: import_node_crypto3.constants.RSA_PSS_SALTLEN_DIGEST
333
518
  // 64 bytes for SHA-512
334
519
  });
335
520
  }
@@ -339,12 +524,12 @@ function verifySignatureBase(signatureBase, signatureB64url, publicKey) {
339
524
  const data = Buffer.from(signatureBase, "utf8");
340
525
  const sig = Buffer.from(signatureB64url, "base64url");
341
526
  if (publicKey.asymmetricKeyType === "ed25519") {
342
- return (0, import_node_crypto2.verify)(null, data, publicKey, sig);
527
+ return (0, import_node_crypto3.verify)(null, data, publicKey, sig);
343
528
  }
344
- return (0, import_node_crypto2.verify)("sha512", data, {
529
+ return (0, import_node_crypto3.verify)("sha512", data, {
345
530
  key: publicKey,
346
- padding: import_node_crypto2.constants.RSA_PKCS1_PSS_PADDING,
347
- saltLength: import_node_crypto2.constants.RSA_PSS_SALTLEN_DIGEST
531
+ padding: import_node_crypto3.constants.RSA_PKCS1_PSS_PADDING,
532
+ saltLength: import_node_crypto3.constants.RSA_PSS_SALTLEN_DIGEST
348
533
  }, sig);
349
534
  }
350
535
  function signRequest(privateKeyPem, method, url, options = {}) {
@@ -389,7 +574,7 @@ function signRequest(privateKeyPem, method, url, options = {}) {
389
574
  }
390
575
 
391
576
  // src/verify.ts
392
- var import_node_crypto3 = require("crypto");
577
+ var import_node_crypto4 = require("crypto");
393
578
 
394
579
  // src/errors.ts
395
580
  var import_shared2 = require("@lumoauth/shared");
@@ -403,19 +588,19 @@ var AAuthError = class extends import_shared2.LumoAuthError {
403
588
 
404
589
  // src/verify.ts
405
590
  var JWS_VERIFIERS = {
406
- RS256: (d, k, s) => (0, import_node_crypto3.verify)("sha256", d, k, s),
407
- RS384: (d, k, s) => (0, import_node_crypto3.verify)("sha384", d, k, s),
408
- RS512: (d, k, s) => (0, import_node_crypto3.verify)("sha512", d, k, s),
409
- PS256: (d, k, s) => (0, import_node_crypto3.verify)("sha256", d, pss(k), s),
410
- PS384: (d, k, s) => (0, import_node_crypto3.verify)("sha384", d, pss(k), s),
411
- PS512: (d, k, s) => (0, import_node_crypto3.verify)("sha512", d, pss(k), s),
412
- ES256: (d, k, s) => (0, import_node_crypto3.verify)("sha256", d, p1363(k), s),
413
- ES384: (d, k, s) => (0, import_node_crypto3.verify)("sha384", d, p1363(k), s),
414
- ES512: (d, k, s) => (0, import_node_crypto3.verify)("sha512", d, p1363(k), s),
415
- EdDSA: (d, k, s) => (0, import_node_crypto3.verify)(null, d, k, s)
591
+ RS256: (d, k, s) => (0, import_node_crypto4.verify)("sha256", d, k, s),
592
+ RS384: (d, k, s) => (0, import_node_crypto4.verify)("sha384", d, k, s),
593
+ RS512: (d, k, s) => (0, import_node_crypto4.verify)("sha512", d, k, s),
594
+ PS256: (d, k, s) => (0, import_node_crypto4.verify)("sha256", d, pss(k), s),
595
+ PS384: (d, k, s) => (0, import_node_crypto4.verify)("sha384", d, pss(k), s),
596
+ PS512: (d, k, s) => (0, import_node_crypto4.verify)("sha512", d, pss(k), s),
597
+ ES256: (d, k, s) => (0, import_node_crypto4.verify)("sha256", d, p1363(k), s),
598
+ ES384: (d, k, s) => (0, import_node_crypto4.verify)("sha384", d, p1363(k), s),
599
+ ES512: (d, k, s) => (0, import_node_crypto4.verify)("sha512", d, p1363(k), s),
600
+ EdDSA: (d, k, s) => (0, import_node_crypto4.verify)(null, d, k, s)
416
601
  };
417
602
  function pss(key) {
418
- return { key, padding: import_node_crypto3.constants.RSA_PKCS1_PSS_PADDING, saltLength: import_node_crypto3.constants.RSA_PSS_SALTLEN_DIGEST };
603
+ return { key, padding: import_node_crypto4.constants.RSA_PKCS1_PSS_PADDING, saltLength: import_node_crypto4.constants.RSA_PSS_SALTLEN_DIGEST };
419
604
  }
420
605
  function p1363(key) {
421
606
  return { key, dsaEncoding: "ieee-p1363" };
@@ -461,7 +646,7 @@ async function verifyAuthToken(token, options) {
461
646
  throw new AAuthError(`Key not found: kid=${kid}`, "invalid_token");
462
647
  }
463
648
  assertAlgMatchesKey(alg, jwk);
464
- const publicKey = (0, import_node_crypto3.createPublicKey)({ key: jwk, format: "jwk" });
649
+ const publicKey = (0, import_node_crypto4.createPublicKey)({ key: jwk, format: "jwk" });
465
650
  const data = Buffer.from(`${parts[0]}.${parts[1]}`, "utf8");
466
651
  const signature = Buffer.from(parts[2], "base64url");
467
652
  if (!verifier(data, publicKey, signature)) {
@@ -777,7 +962,7 @@ var AAuthClient = class {
777
962
  AAuthClient.generateKeypair = generateKeypair;
778
963
 
779
964
  // src/dpop.ts
780
- var import_node_crypto4 = require("crypto");
965
+ var import_node_crypto5 = require("crypto");
781
966
  var import_shared4 = require("@lumoauth/shared");
782
967
  var DpopProofSigner = class _DpopProofSigner {
783
968
  constructor(options) {
@@ -785,7 +970,7 @@ var DpopProofSigner = class _DpopProofSigner {
785
970
  if (options.privateKey) {
786
971
  this.key = options.privateKey;
787
972
  } else if (options.privateKeyPem) {
788
- this.key = (0, import_node_crypto4.createPrivateKey)(options.privateKeyPem);
973
+ this.key = (0, import_node_crypto5.createPrivateKey)(options.privateKeyPem);
789
974
  } else {
790
975
  throw new Error("DpopProofSigner needs privateKeyPem or privateKey");
791
976
  }
@@ -794,7 +979,7 @@ var DpopProofSigner = class _DpopProofSigner {
794
979
  }
795
980
  this.algorithm = algorithmFor(this.key);
796
981
  this.now = options.now ?? (() => Math.floor(Date.now() / 1e3));
797
- const pub = (0, import_node_crypto4.createPublicKey)(this.key).export({ format: "jwk" });
982
+ const pub = (0, import_node_crypto5.createPublicKey)(this.key).export({ format: "jwk" });
798
983
  this.jwk = publicMembers(pub);
799
984
  this.thumbprint = jwkThumbprint(this.jwk);
800
985
  }
@@ -806,13 +991,13 @@ var DpopProofSigner = class _DpopProofSigner {
806
991
  let privateKey;
807
992
  switch (algorithm) {
808
993
  case "ES256":
809
- privateKey = (0, import_node_crypto4.generateKeyPairSync)("ec", { namedCurve: "P-256" }).privateKey;
994
+ privateKey = (0, import_node_crypto5.generateKeyPairSync)("ec", { namedCurve: "P-256" }).privateKey;
810
995
  break;
811
996
  case "EdDSA":
812
- privateKey = (0, import_node_crypto4.generateKeyPairSync)("ed25519").privateKey;
997
+ privateKey = (0, import_node_crypto5.generateKeyPairSync)("ed25519").privateKey;
813
998
  break;
814
999
  case "RS256":
815
- privateKey = (0, import_node_crypto4.generateKeyPairSync)("rsa", { modulusLength: 2048 }).privateKey;
1000
+ privateKey = (0, import_node_crypto5.generateKeyPairSync)("rsa", { modulusLength: 2048 }).privateKey;
816
1001
  break;
817
1002
  default:
818
1003
  throw new Error(`Unsupported DPoP algorithm: ${String(algorithm)}`);
@@ -830,14 +1015,14 @@ var DpopProofSigner = class _DpopProofSigner {
830
1015
  const nonce = input.nonce ?? this.getNonce(input.url);
831
1016
  const header = { typ: "dpop+jwt", alg: this.algorithm, jwk: this.jwk };
832
1017
  const claims = {
833
- jti: (0, import_node_crypto4.randomBytes)(24).toString("base64url"),
1018
+ jti: (0, import_node_crypto5.randomBytes)(24).toString("base64url"),
834
1019
  htm: method,
835
1020
  htu,
836
1021
  iat: this.now()
837
1022
  };
838
1023
  if (input.accessToken) claims.ath = dpopAth(input.accessToken);
839
1024
  if (nonce) claims.nonce = nonce;
840
- const signingInput = `${b64url(JSON.stringify(header))}.${b64url(JSON.stringify(claims))}`;
1025
+ const signingInput = `${b64url2(JSON.stringify(header))}.${b64url2(JSON.stringify(claims))}`;
841
1026
  const signature = signJws(this.algorithm, Buffer.from(signingInput, "utf8"), this.key);
842
1027
  return `${signingInput}.${signature.toString("base64url")}`;
843
1028
  }
@@ -855,16 +1040,16 @@ var DpopProofSigner = class _DpopProofSigner {
855
1040
  }
856
1041
  };
857
1042
  function dpopAth(accessToken) {
858
- return (0, import_node_crypto4.createHash)("sha256").update(accessToken, "ascii").digest("base64url");
1043
+ return (0, import_node_crypto5.createHash)("sha256").update(accessToken, "ascii").digest("base64url");
859
1044
  }
860
1045
  function signJws(alg, data, key) {
861
1046
  switch (alg) {
862
1047
  case "ES256":
863
- return (0, import_node_crypto4.sign)("sha256", data, { key, dsaEncoding: "ieee-p1363" });
1048
+ return (0, import_node_crypto5.sign)("sha256", data, { key, dsaEncoding: "ieee-p1363" });
864
1049
  case "EdDSA":
865
- return (0, import_node_crypto4.sign)(null, data, key);
1050
+ return (0, import_node_crypto5.sign)(null, data, key);
866
1051
  case "RS256":
867
- return (0, import_node_crypto4.sign)("sha256", data, key);
1052
+ return (0, import_node_crypto5.sign)("sha256", data, key);
868
1053
  default:
869
1054
  throw new Error(`Unsupported DPoP algorithm: ${String(alg)}`);
870
1055
  }
@@ -896,7 +1081,7 @@ function publicMembers(jwk) {
896
1081
  function originOf(url) {
897
1082
  return new URL(url).origin;
898
1083
  }
899
- function b64url(text) {
1084
+ function b64url2(text) {
900
1085
  return Buffer.from(text, "utf8").toString("base64url");
901
1086
  }
902
1087
 
@@ -952,7 +1137,7 @@ async function attestWorkload(options) {
952
1137
  }
953
1138
 
954
1139
  // src/access-token.ts
955
- var import_node_crypto5 = require("crypto");
1140
+ var import_node_crypto6 = require("crypto");
956
1141
  var import_shared6 = require("@lumoauth/shared");
957
1142
  var AccessTokenError = class extends import_shared6.LumoAuthError {
958
1143
  constructor(message, code, statusCode = 401) {
@@ -968,16 +1153,16 @@ var DPOP_JTI_TTL_SECONDS = 300;
968
1153
  var DPOP_JTI_MIN_LENGTH = 16;
969
1154
  var JWKS_REFETCH_INTERVAL_MS = 3e4;
970
1155
  var JWS_VERIFIERS2 = {
971
- RS256: (d, k, s) => (0, import_node_crypto5.verify)("sha256", d, k, s),
972
- RS384: (d, k, s) => (0, import_node_crypto5.verify)("sha384", d, k, s),
973
- RS512: (d, k, s) => (0, import_node_crypto5.verify)("sha512", d, k, s),
974
- PS256: (d, k, s) => (0, import_node_crypto5.verify)("sha256", d, pss2(k), s),
975
- PS384: (d, k, s) => (0, import_node_crypto5.verify)("sha384", d, pss2(k), s),
976
- PS512: (d, k, s) => (0, import_node_crypto5.verify)("sha512", d, pss2(k), s),
977
- ES256: (d, k, s) => (0, import_node_crypto5.verify)("sha256", d, p13632(k), s),
978
- ES384: (d, k, s) => (0, import_node_crypto5.verify)("sha384", d, p13632(k), s),
979
- ES512: (d, k, s) => (0, import_node_crypto5.verify)("sha512", d, p13632(k), s),
980
- EdDSA: (d, k, s) => (0, import_node_crypto5.verify)(null, d, k, s)
1156
+ RS256: (d, k, s) => (0, import_node_crypto6.verify)("sha256", d, k, s),
1157
+ RS384: (d, k, s) => (0, import_node_crypto6.verify)("sha384", d, k, s),
1158
+ RS512: (d, k, s) => (0, import_node_crypto6.verify)("sha512", d, k, s),
1159
+ PS256: (d, k, s) => (0, import_node_crypto6.verify)("sha256", d, pss2(k), s),
1160
+ PS384: (d, k, s) => (0, import_node_crypto6.verify)("sha384", d, pss2(k), s),
1161
+ PS512: (d, k, s) => (0, import_node_crypto6.verify)("sha512", d, pss2(k), s),
1162
+ ES256: (d, k, s) => (0, import_node_crypto6.verify)("sha256", d, p13632(k), s),
1163
+ ES384: (d, k, s) => (0, import_node_crypto6.verify)("sha384", d, p13632(k), s),
1164
+ ES512: (d, k, s) => (0, import_node_crypto6.verify)("sha512", d, p13632(k), s),
1165
+ EdDSA: (d, k, s) => (0, import_node_crypto6.verify)(null, d, k, s)
981
1166
  };
982
1167
  var DPOP_ALG_KEYS = {
983
1168
  ES256: { kty: "EC", crv: "P-256" },
@@ -992,7 +1177,7 @@ var DPOP_ALG_KEYS = {
992
1177
  EdDSA: { kty: "OKP", crv: "Ed25519" }
993
1178
  };
994
1179
  function pss2(key) {
995
- return { key, padding: import_node_crypto5.constants.RSA_PKCS1_PSS_PADDING, saltLength: import_node_crypto5.constants.RSA_PSS_SALTLEN_DIGEST };
1180
+ return { key, padding: import_node_crypto6.constants.RSA_PKCS1_PSS_PADDING, saltLength: import_node_crypto6.constants.RSA_PSS_SALTLEN_DIGEST };
996
1181
  }
997
1182
  function p13632(key) {
998
1183
  return { key, dsaEncoding: "ieee-p1363" };
@@ -1126,7 +1311,7 @@ async function verifyAccessToken(token, options) {
1126
1311
  throw new AccessTokenError(`Key not found: kid=${kid}`, "invalid_token");
1127
1312
  }
1128
1313
  assertAlgMatchesKey2(alg, jwk);
1129
- const publicKey = (0, import_node_crypto5.createPublicKey)({ key: jwk, format: "jwk" });
1314
+ const publicKey = (0, import_node_crypto6.createPublicKey)({ key: jwk, format: "jwk" });
1130
1315
  const data = Buffer.from(`${parts[0]}.${parts[1]}`, "utf8");
1131
1316
  const signature = Buffer.from(parts[2], "base64url");
1132
1317
  if (!verifier(data, publicKey, signature)) {
@@ -1235,7 +1420,7 @@ async function verifyDpopProof(proof, options) {
1235
1420
  }
1236
1421
  let publicKey;
1237
1422
  try {
1238
- publicKey = (0, import_node_crypto5.createPublicKey)({ key: jwk, format: "jwk" });
1423
+ publicKey = (0, import_node_crypto6.createPublicKey)({ key: jwk, format: "jwk" });
1239
1424
  } catch {
1240
1425
  throw new AccessTokenError("DPoP proof jwk is not a valid public key", "invalid_dpop_proof");
1241
1426
  }
@@ -1267,7 +1452,7 @@ async function verifyDpopProof(proof, options) {
1267
1452
  throw new AccessTokenError("DPoP proof nonce does not match", "invalid_dpop_proof");
1268
1453
  }
1269
1454
  if (options.accessToken !== void 0) {
1270
- const expectedAth = (0, import_node_crypto5.createHash)("sha256").update(options.accessToken, "ascii").digest("base64url");
1455
+ const expectedAth = (0, import_node_crypto6.createHash)("sha256").update(options.accessToken, "ascii").digest("base64url");
1271
1456
  if (claims.ath !== expectedAth) {
1272
1457
  throw new AccessTokenError("DPoP proof ath does not match the access token", "invalid_dpop_proof");
1273
1458
  }
@@ -1335,6 +1520,9 @@ var import_shared8 = require("@lumoauth/shared");
1335
1520
  AAuthClient,
1336
1521
  AAuthError,
1337
1522
  AccessTokenError,
1523
+ CLIENT_ASSERTION_TYP,
1524
+ CLIENT_ASSERTION_TYPE,
1525
+ ClientAssertionSigner,
1338
1526
  DPOP_NONCE_HEADER,
1339
1527
  DPOP_SCHEME,
1340
1528
  DpopProofSigner,
@@ -1354,6 +1542,7 @@ var import_shared8 = require("@lumoauth/shared");
1354
1542
  LumoAuthPermissionDeniedError,
1355
1543
  LumoAuthRateLimitError,
1356
1544
  LumoAuthValidationError,
1545
+ MAX_ASSERTION_LIFETIME_SECONDS,
1357
1546
  USE_DPOP_NONCE,
1358
1547
  accessTokenScopes,
1359
1548
  attestWorkload,
@@ -1367,6 +1556,7 @@ var import_shared8 = require("@lumoauth/shared");
1367
1556
  fetchWithDpop,
1368
1557
  generateKeypair,
1369
1558
  generateNonce,
1559
+ issuerFor,
1370
1560
  jwkThumbprint,
1371
1561
  parseAuthorizationHeader,
1372
1562
  publicJwkFromPrivateKey,