@adcp/sdk 16.0.0 → 16.2.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.
Files changed (85) hide show
  1. package/README.md +52 -0
  2. package/bin/adcp-identity.js +3 -2
  3. package/dist/lib/client/core.d.mts +1 -1
  4. package/dist/lib/client/core.d.ts +1 -1
  5. package/dist/lib/core/AgentClient.d.mts +8 -1
  6. package/dist/lib/core/AgentClient.d.ts +8 -1
  7. package/dist/lib/core/AgentClient.js +10 -0
  8. package/dist/lib/core/AgentClient.mjs +10 -0
  9. package/dist/lib/core/AsyncHandler.d.mts +2 -0
  10. package/dist/lib/core/AsyncHandler.d.ts +2 -0
  11. package/dist/lib/core/AsyncHandler.js +1 -1
  12. package/dist/lib/core/AsyncHandler.mjs +1 -1
  13. package/dist/lib/core/ConversationTypes.d.mts +32 -0
  14. package/dist/lib/core/ConversationTypes.d.ts +32 -0
  15. package/dist/lib/core/SingleAgentClient.d.mts +11 -1
  16. package/dist/lib/core/SingleAgentClient.d.ts +11 -1
  17. package/dist/lib/core/SingleAgentClient.js +25 -6
  18. package/dist/lib/core/SingleAgentClient.mjs +26 -7
  19. package/dist/lib/core/TaskExecutor.d.mts +3 -1
  20. package/dist/lib/core/TaskExecutor.d.ts +3 -1
  21. package/dist/lib/core/TaskExecutor.js +127 -34
  22. package/dist/lib/core/TaskExecutor.mjs +127 -34
  23. package/dist/lib/core/task-deadline.d.mts +2 -0
  24. package/dist/lib/core/task-deadline.d.ts +2 -0
  25. package/dist/lib/core/task-deadline.js +20 -2
  26. package/dist/lib/core/task-deadline.mjs +19 -2
  27. package/dist/lib/governance/authorization.d.mts +66 -0
  28. package/dist/lib/governance/authorization.d.ts +66 -0
  29. package/dist/lib/governance/authorization.js +181 -37
  30. package/dist/lib/governance/authorization.mjs +183 -36
  31. package/dist/lib/governance/index.d.mts +2 -2
  32. package/dist/lib/governance/index.d.ts +2 -2
  33. package/dist/lib/governance/index.js +4 -2
  34. package/dist/lib/governance/index.mjs +3 -1
  35. package/dist/lib/identity-3.3/index.d.mts +1 -0
  36. package/dist/lib/identity-3.3/index.d.ts +1 -0
  37. package/dist/lib/identity-3.3/index.js +3 -1
  38. package/dist/lib/identity-3.3/index.mjs +1 -0
  39. package/dist/lib/identity-3.3/jws-artifacts.d.mts +147 -0
  40. package/dist/lib/identity-3.3/jws-artifacts.d.ts +147 -0
  41. package/dist/lib/identity-3.3/jws-artifacts.js +258 -0
  42. package/dist/lib/identity-3.3/jws-artifacts.mjs +234 -0
  43. package/dist/lib/identity-3.3/revocation.d.mts +7 -0
  44. package/dist/lib/identity-3.3/revocation.d.ts +7 -0
  45. package/dist/lib/identity-3.3/revocation.js +13 -0
  46. package/dist/lib/identity-3.3/revocation.mjs +13 -0
  47. package/dist/lib/identity-3.3/schemas.draft.js +1 -1
  48. package/dist/lib/identity-3.3/schemas.draft.mjs +1 -1
  49. package/dist/lib/identity-3.3/trust.d.mts +8 -0
  50. package/dist/lib/identity-3.3/trust.d.ts +8 -0
  51. package/dist/lib/identity-3.3/trust.js +41 -12
  52. package/dist/lib/identity-3.3/trust.mjs +40 -12
  53. package/dist/lib/index.d.mts +3 -3
  54. package/dist/lib/index.d.ts +3 -3
  55. package/dist/lib/index.js +2 -0
  56. package/dist/lib/index.mjs +2 -0
  57. package/dist/lib/registry/types.generated.d.mts +24 -1
  58. package/dist/lib/registry/types.generated.d.ts +24 -1
  59. package/dist/lib/server/account-sync-contract.js +4 -1
  60. package/dist/lib/server/account-sync-contract.mjs +4 -1
  61. package/dist/lib/server/decisioning/runtime/from-platform.js +22 -17
  62. package/dist/lib/server/decisioning/runtime/from-platform.mjs +22 -17
  63. package/dist/lib/server/index.d.mts +2 -2
  64. package/dist/lib/server/index.d.ts +2 -2
  65. package/dist/lib/server/index.js +2 -0
  66. package/dist/lib/server/index.mjs +2 -0
  67. package/dist/lib/signing/web-bot-auth.js +25 -5
  68. package/dist/lib/signing/web-bot-auth.mjs +25 -6
  69. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  70. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  71. package/dist/lib/v2/projection/catalog.d.mts +6 -0
  72. package/dist/lib/v2/projection/catalog.d.ts +6 -0
  73. package/dist/lib/v2/projection/catalog.js +5 -0
  74. package/dist/lib/v2/projection/catalog.mjs +4 -0
  75. package/dist/lib/v2/projection/v1-to-v2.js +3 -2
  76. package/dist/lib/v2/projection/v1-to-v2.mjs +4 -3
  77. package/dist/lib/version.d.mts +3 -3
  78. package/dist/lib/version.d.ts +3 -3
  79. package/dist/lib/version.js +3 -3
  80. package/dist/lib/version.mjs +3 -3
  81. package/docs/TYPE-SUMMARY.md +12 -2
  82. package/docs/llms.txt +3 -3
  83. package/docs/migration-14.x-rc-worksheet.md +4 -4
  84. package/docs/migration-agent-identity-3.3.md +72 -19
  85. package/package.json +6 -4
@@ -35,7 +35,8 @@ __export(authorization_exports, {
35
35
  governanceTaskRequiresProposedCommitment: () => governanceTaskRequiresProposedCommitment,
36
36
  targetDeclaresGovernanceEnforcement: () => targetDeclaresGovernanceEnforcement,
37
37
  targetDeclaresLegacyGovernanceAwareness: () => targetDeclaresLegacyGovernanceAwareness,
38
- verifyGovernanceAuthorization: () => verifyGovernanceAuthorization
38
+ verifyGovernanceAuthorization: () => verifyGovernanceAuthorization,
39
+ verifyHistoricalGovernanceContext: () => verifyHistoricalGovernanceContext
39
40
  });
40
41
  module.exports = __toCommonJS(authorization_exports);
41
42
  var import_node_crypto = require("node:crypto");
@@ -44,11 +45,18 @@ var import_jcs = require('../utils/jcs.js');
44
45
  var import_jwks_https = require('../signing/jwks-https.js');
45
46
  var import_select_agent = require('../signing/agent-resolver/select-agent.js');
46
47
  var import_strict_json = require('../signing/agent-resolver/strict-json.js');
48
+ var import_jws_artifacts = require('../identity-3.3/jws-artifacts.js');
47
49
  const GOVERNANCE_AUTHORIZATION_CRITICAL_CLAIMS = Object.freeze([
48
50
  "authorized_commitment",
49
51
  "authorized_task",
50
52
  "authorized_payload_hash"
51
53
  ]);
54
+ const GOVERNANCE_JWS_TYP = "adcp-gov+jws";
55
+ const GOVERNANCE_CRIT = {
56
+ authorized_commitment: true,
57
+ authorized_task: true,
58
+ authorized_payload_hash: true
59
+ };
52
60
  class GovernanceReplayStoreAdapter {
53
61
  constructor(replayStore) {
54
62
  this.replayStore = replayStore;
@@ -282,27 +290,19 @@ function targetDeclaresLegacyGovernanceAwareness(capabilities, task) {
282
290
  const mediaBuy = isRecord(root?.media_buy) ? root.media_buy : void 0;
283
291
  return mediaBuy?.governance_aware === true;
284
292
  }
285
- async function verifyGovernanceAuthorization(options) {
293
+ function parseGovernanceJws(token, expectedIssuer) {
286
294
  const reject = (error, message) => ({
287
295
  ok: false,
288
296
  error,
289
297
  message
290
298
  });
291
- if (!options.authenticatedCaller) {
292
- return reject("governance_token_invalid", "Authenticated caller is required");
293
- }
294
- try {
295
- buildGovernanceCommitment(options.actualCommitment.amount, options.actualCommitment.currency);
296
- } catch (error) {
297
- return reject("governance_token_invalid", error.message);
298
- }
299
- if (typeof options.token !== "string" || options.token.length === 0) {
299
+ if (typeof token !== "string" || token.length === 0) {
300
300
  return reject("governance_token_invalid", "governance_context is required");
301
301
  }
302
- if (options.token.length > 4096) {
302
+ if (token.length > 4096) {
303
303
  return reject("governance_token_invalid", "governance_context exceeds the protocol size limit");
304
304
  }
305
- const parts = options.token.split(".");
305
+ const parts = token.split(".");
306
306
  if (parts.length !== 3 || parts.some((part) => !part || !/^[A-Za-z0-9_-]+$/.test(part))) {
307
307
  return reject("governance_token_invalid", "governance_context is not a compact JWS");
308
308
  }
@@ -315,7 +315,7 @@ async function verifyGovernanceAuthorization(options) {
315
315
  if (alg !== "EdDSA" && alg !== "ES256") {
316
316
  return reject("governance_token_invalid", "Unsupported governance JWS algorithm");
317
317
  }
318
- if (protectedHeader.typ !== "adcp-gov+jws") {
318
+ if (protectedHeader.typ !== GOVERNANCE_JWS_TYP) {
319
319
  return reject("governance_token_invalid", "Invalid governance JWS typ");
320
320
  }
321
321
  const critical = protectedHeader.crit;
@@ -343,35 +343,71 @@ async function verifyGovernanceAuthorization(options) {
343
343
  try {
344
344
  if (typeof decodedClaims.iss !== "string") throw new TypeError("Missing issuer");
345
345
  canonicalIssuer = (0, import_select_agent.canonicalAgentUrl)(decodedClaims.iss);
346
- if (canonicalIssuer !== (0, import_select_agent.canonicalAgentUrl)(options.expectedIssuer)) throw new TypeError("Issuer mismatch");
346
+ if (canonicalIssuer !== (0, import_select_agent.canonicalAgentUrl)(expectedIssuer)) throw new TypeError("Issuer mismatch");
347
347
  } catch {
348
348
  return reject("governance_token_invalid", "Governance token issuer mismatch");
349
349
  }
350
- const kid = typeof protectedHeader.kid === "string" ? protectedHeader.kid : "";
351
- if (!kid) return reject("governance_key_unknown", "Governance signing kid is missing");
352
- let jwk;
350
+ return { ok: true, token, protectedHeader, decodedClaims, canonicalIssuer, alg };
351
+ }
352
+ async function verifyGovernanceAuthorization(options) {
353
+ const reject = (error, message) => ({
354
+ ok: false,
355
+ error,
356
+ message
357
+ });
358
+ if (!options.authenticatedCaller) {
359
+ return reject("governance_token_invalid", "Authenticated caller is required");
360
+ }
353
361
  try {
354
- const resolver = options.buyerIdentity ? createGovernanceAgentJwksResolver(canonicalIssuer, options.buyerIdentity) : options.jwks;
355
- if (!resolver) return reject("governance_key_unknown", "No governance key resolver or buyer identity configured");
356
- jwk = await resolver.resolve(kid);
357
- } catch {
358
- return reject("governance_key_unknown", "Governance signing key could not be resolved");
362
+ buildGovernanceCommitment(options.actualCommitment.amount, options.actualCommitment.currency);
363
+ } catch (error) {
364
+ return reject("governance_token_invalid", error.message);
359
365
  }
360
- if (!jwk || jwk.adcp_use !== "governance-signing" || jwk.use !== "sig" || !jwk.key_ops?.includes("verify") || jwk.alg !== void 0 && jwk.alg !== alg) {
361
- return reject("governance_key_unknown", "Governance signing key is unknown or not authorized");
366
+ const parsed = parseGovernanceJws(options.token, options.expectedIssuer);
367
+ if (!parsed.ok) return parsed;
368
+ const { protectedHeader, decodedClaims, canonicalIssuer, alg } = parsed;
369
+ const kid = typeof protectedHeader.kid === "string" ? protectedHeader.kid : "";
370
+ if (!kid) return reject("governance_key_unknown", "Governance signing kid is missing");
371
+ let profile;
372
+ if (options.webBotAuth) {
373
+ try {
374
+ profile = await (0, import_jws_artifacts.selectJwsArtifactProfile)(options.expectedIssuer, options.webBotAuth.trust);
375
+ } catch {
376
+ return { ...reject("governance_key_unknown", "Governance issuer trust record is unavailable"), retryable: true };
377
+ }
362
378
  }
363
- try {
364
- const key = await (0, import_jose.importJWK)(jwk, alg);
365
- await (0, import_jose.compactVerify)(options.token, key, {
366
- algorithms: [alg],
367
- crit: {
368
- authorized_commitment: true,
369
- authorized_task: true,
370
- authorized_payload_hash: true
379
+ if (profile?.profile === "web-bot-auth") {
380
+ if (options.buyerIdentity) {
381
+ try {
382
+ const record = (0, import_select_agent.relyingPartyAgentRecord)(options.buyerIdentity.brandJson, options.buyerIdentity.brandDomain);
383
+ (0, import_select_agent.selectAgentByUrl)(record, canonicalIssuer, { agentType: "governance" });
384
+ } catch {
385
+ return reject("governance_key_unknown", "Governance issuer is not the buyer's governance agent");
371
386
  }
372
- });
373
- } catch {
374
- return reject("governance_token_invalid", "Governance token signature verification failed");
387
+ }
388
+ const failure = await verifyGovernanceJwsOnWebBotAuth(options.token, profile.origin, options.webBotAuth);
389
+ if (failure) return failure;
390
+ } else {
391
+ let jwk;
392
+ try {
393
+ const resolver = options.buyerIdentity ? createGovernanceAgentJwksResolver(canonicalIssuer, options.buyerIdentity) : options.jwks;
394
+ if (!resolver) return reject("governance_key_unknown", "No governance key resolver or buyer identity configured");
395
+ jwk = await resolver.resolve(kid);
396
+ } catch {
397
+ return reject("governance_key_unknown", "Governance signing key could not be resolved");
398
+ }
399
+ if (!jwk || jwk.adcp_use !== "governance-signing" || jwk.use !== "sig" || !jwk.key_ops?.includes("verify") || jwk.alg !== void 0 && jwk.alg !== alg) {
400
+ return reject("governance_key_unknown", "Governance signing key is unknown or not authorized");
401
+ }
402
+ try {
403
+ const key = await (0, import_jose.importJWK)(jwk, alg);
404
+ await (0, import_jose.compactVerify)(options.token, key, {
405
+ algorithms: [alg],
406
+ crit: GOVERNANCE_CRIT
407
+ });
408
+ } catch {
409
+ return reject("governance_token_invalid", "Governance token signature verification failed");
410
+ }
375
411
  }
376
412
  try {
377
413
  if (options.revocationStore && await options.revocationStore.isRevoked(kid)) {
@@ -529,6 +565,113 @@ async function verifyGovernanceAuthorization(options) {
529
565
  payloadHash
530
566
  };
531
567
  }
568
+ function governanceFailureFromJwsArtifact(error) {
569
+ if (!(error instanceof import_jws_artifacts.JwsArtifactError))
570
+ return {
571
+ ok: false,
572
+ error: "governance_key_unknown",
573
+ message: "Governance signing key could not be resolved",
574
+ retryable: true
575
+ };
576
+ switch (error.code) {
577
+ case "jws_key_revoked":
578
+ return { ok: false, error: "governance_token_revoked", message: "Governance signing key is revoked" };
579
+ case "jws_revocation_unavailable":
580
+ return {
581
+ ok: false,
582
+ error: "governance_token_revoked",
583
+ message: "Governance revocation status could not be established",
584
+ retryable: true
585
+ };
586
+ case "jws_invalid":
587
+ return {
588
+ ok: false,
589
+ error: "governance_token_invalid",
590
+ message: `Governance token verification failed: ${error.message}`
591
+ };
592
+ case "jws_key_unavailable":
593
+ return {
594
+ ok: false,
595
+ error: "governance_key_unknown",
596
+ message: "Governance signing key could not be resolved",
597
+ retryable: true
598
+ };
599
+ default:
600
+ return { ok: false, error: "governance_key_unknown", message: "Governance signing key could not be resolved" };
601
+ }
602
+ }
603
+ const NO_ORIGIN_REVOCATION = Object.freeze({
604
+ ok: false,
605
+ error: "governance_token_revoked",
606
+ message: "No origin revocation source is configured for the Web Bot Auth path"
607
+ });
608
+ async function verifyGovernanceJwsOnWebBotAuth(token, origin, webBotAuth) {
609
+ if (!webBotAuth.revocation) return { ...NO_ORIGIN_REVOCATION };
610
+ try {
611
+ await (0, import_jws_artifacts.verifyWebBotAuthJwsArtifact)(token, origin, {
612
+ typ: GOVERNANCE_JWS_TYP,
613
+ directory: webBotAuth.directory,
614
+ revocation: webBotAuth.revocation,
615
+ // A governance context authorizes spend: an origin that serves no list fails closed.
616
+ revocationAbsent: "reject",
617
+ crit: GOVERNANCE_CRIT
618
+ });
619
+ return void 0;
620
+ } catch (error) {
621
+ return governanceFailureFromJwsArtifact(error);
622
+ }
623
+ }
624
+ async function verifyHistoricalGovernanceContext(options) {
625
+ const parsed = parseGovernanceJws(options.token, options.expectedIssuer);
626
+ if (!parsed.ok) return parsed;
627
+ if (parsed.alg !== "EdDSA")
628
+ return {
629
+ ok: false,
630
+ error: "governance_token_invalid",
631
+ message: "A Web Bot Auth governance context uses alg EdDSA"
632
+ };
633
+ if (!options.webBotAuth.revocation) return { ...NO_ORIGIN_REVOCATION };
634
+ let profile;
635
+ try {
636
+ profile = await (0, import_jws_artifacts.selectJwsArtifactProfile)(options.expectedIssuer, options.webBotAuth.trust);
637
+ } catch {
638
+ return {
639
+ ok: false,
640
+ error: "governance_key_unknown",
641
+ message: "Governance issuer trust record is unavailable",
642
+ retryable: true
643
+ };
644
+ }
645
+ if (profile.profile !== "web-bot-auth")
646
+ return {
647
+ ok: false,
648
+ error: "governance_key_unknown",
649
+ message: "Governance issuer is on the 3.2 profile; its trust record does not list its origin",
650
+ profile: "3.2"
651
+ };
652
+ try {
653
+ const verified = await (0, import_jws_artifacts.verifyWebBotAuthJwsArtifact)(parsed.token, profile.origin, {
654
+ typ: GOVERNANCE_JWS_TYP,
655
+ directory: options.webBotAuth.directory,
656
+ archive: options.webBotAuth.archive,
657
+ revocation: options.webBotAuth.revocation,
658
+ // No spend rides on an audit: an origin that serves no list has revoked nothing.
659
+ revocationAbsent: "accept",
660
+ revokedKey: "report",
661
+ crit: GOVERNANCE_CRIT
662
+ });
663
+ return {
664
+ ok: true,
665
+ claims: parsed.decodedClaims,
666
+ protectedHeader: parsed.protectedHeader,
667
+ keySource: verified.keySource,
668
+ revocation: verified.revocation,
669
+ ...verified.revocationDetail ? { revocationDetail: verified.revocationDetail } : {}
670
+ };
671
+ } catch (error) {
672
+ return governanceFailureFromJwsArtifact(error);
673
+ }
674
+ }
532
675
  class GovernanceAuthorizationError extends Error {
533
676
  code;
534
677
  constructor(result) {
@@ -585,5 +728,6 @@ function decodeJsonObject(segment) {
585
728
  governanceTaskRequiresProposedCommitment,
586
729
  targetDeclaresGovernanceEnforcement,
587
730
  targetDeclaresLegacyGovernanceAwareness,
588
- verifyGovernanceAuthorization
731
+ verifyGovernanceAuthorization,
732
+ verifyHistoricalGovernanceContext
589
733
  });
@@ -9,11 +9,22 @@ import {
9
9
  canonicalAgentUrl
10
10
  } from "../signing/agent-resolver/select-agent.mjs";
11
11
  import { parseStrictJson } from "../signing/agent-resolver/strict-json.mjs";
12
+ import {
13
+ JwsArtifactError,
14
+ selectJwsArtifactProfile,
15
+ verifyWebBotAuthJwsArtifact
16
+ } from "../identity-3.3/jws-artifacts.mjs";
12
17
  const GOVERNANCE_AUTHORIZATION_CRITICAL_CLAIMS = Object.freeze([
13
18
  "authorized_commitment",
14
19
  "authorized_task",
15
20
  "authorized_payload_hash"
16
21
  ]);
22
+ const GOVERNANCE_JWS_TYP = "adcp-gov+jws";
23
+ const GOVERNANCE_CRIT = {
24
+ authorized_commitment: true,
25
+ authorized_task: true,
26
+ authorized_payload_hash: true
27
+ };
17
28
  class GovernanceReplayStoreAdapter {
18
29
  constructor(replayStore) {
19
30
  this.replayStore = replayStore;
@@ -247,27 +258,19 @@ function targetDeclaresLegacyGovernanceAwareness(capabilities, task) {
247
258
  const mediaBuy = isRecord(root?.media_buy) ? root.media_buy : void 0;
248
259
  return mediaBuy?.governance_aware === true;
249
260
  }
250
- async function verifyGovernanceAuthorization(options) {
261
+ function parseGovernanceJws(token, expectedIssuer) {
251
262
  const reject = (error, message) => ({
252
263
  ok: false,
253
264
  error,
254
265
  message
255
266
  });
256
- if (!options.authenticatedCaller) {
257
- return reject("governance_token_invalid", "Authenticated caller is required");
258
- }
259
- try {
260
- buildGovernanceCommitment(options.actualCommitment.amount, options.actualCommitment.currency);
261
- } catch (error) {
262
- return reject("governance_token_invalid", error.message);
263
- }
264
- if (typeof options.token !== "string" || options.token.length === 0) {
267
+ if (typeof token !== "string" || token.length === 0) {
265
268
  return reject("governance_token_invalid", "governance_context is required");
266
269
  }
267
- if (options.token.length > 4096) {
270
+ if (token.length > 4096) {
268
271
  return reject("governance_token_invalid", "governance_context exceeds the protocol size limit");
269
272
  }
270
- const parts = options.token.split(".");
273
+ const parts = token.split(".");
271
274
  if (parts.length !== 3 || parts.some((part) => !part || !/^[A-Za-z0-9_-]+$/.test(part))) {
272
275
  return reject("governance_token_invalid", "governance_context is not a compact JWS");
273
276
  }
@@ -280,7 +283,7 @@ async function verifyGovernanceAuthorization(options) {
280
283
  if (alg !== "EdDSA" && alg !== "ES256") {
281
284
  return reject("governance_token_invalid", "Unsupported governance JWS algorithm");
282
285
  }
283
- if (protectedHeader.typ !== "adcp-gov+jws") {
286
+ if (protectedHeader.typ !== GOVERNANCE_JWS_TYP) {
284
287
  return reject("governance_token_invalid", "Invalid governance JWS typ");
285
288
  }
286
289
  const critical = protectedHeader.crit;
@@ -308,35 +311,71 @@ async function verifyGovernanceAuthorization(options) {
308
311
  try {
309
312
  if (typeof decodedClaims.iss !== "string") throw new TypeError("Missing issuer");
310
313
  canonicalIssuer = canonicalAgentUrl(decodedClaims.iss);
311
- if (canonicalIssuer !== canonicalAgentUrl(options.expectedIssuer)) throw new TypeError("Issuer mismatch");
314
+ if (canonicalIssuer !== canonicalAgentUrl(expectedIssuer)) throw new TypeError("Issuer mismatch");
312
315
  } catch {
313
316
  return reject("governance_token_invalid", "Governance token issuer mismatch");
314
317
  }
315
- const kid = typeof protectedHeader.kid === "string" ? protectedHeader.kid : "";
316
- if (!kid) return reject("governance_key_unknown", "Governance signing kid is missing");
317
- let jwk;
318
+ return { ok: true, token, protectedHeader, decodedClaims, canonicalIssuer, alg };
319
+ }
320
+ async function verifyGovernanceAuthorization(options) {
321
+ const reject = (error, message) => ({
322
+ ok: false,
323
+ error,
324
+ message
325
+ });
326
+ if (!options.authenticatedCaller) {
327
+ return reject("governance_token_invalid", "Authenticated caller is required");
328
+ }
318
329
  try {
319
- const resolver = options.buyerIdentity ? createGovernanceAgentJwksResolver(canonicalIssuer, options.buyerIdentity) : options.jwks;
320
- if (!resolver) return reject("governance_key_unknown", "No governance key resolver or buyer identity configured");
321
- jwk = await resolver.resolve(kid);
322
- } catch {
323
- return reject("governance_key_unknown", "Governance signing key could not be resolved");
330
+ buildGovernanceCommitment(options.actualCommitment.amount, options.actualCommitment.currency);
331
+ } catch (error) {
332
+ return reject("governance_token_invalid", error.message);
324
333
  }
325
- if (!jwk || jwk.adcp_use !== "governance-signing" || jwk.use !== "sig" || !jwk.key_ops?.includes("verify") || jwk.alg !== void 0 && jwk.alg !== alg) {
326
- return reject("governance_key_unknown", "Governance signing key is unknown or not authorized");
334
+ const parsed = parseGovernanceJws(options.token, options.expectedIssuer);
335
+ if (!parsed.ok) return parsed;
336
+ const { protectedHeader, decodedClaims, canonicalIssuer, alg } = parsed;
337
+ const kid = typeof protectedHeader.kid === "string" ? protectedHeader.kid : "";
338
+ if (!kid) return reject("governance_key_unknown", "Governance signing kid is missing");
339
+ let profile;
340
+ if (options.webBotAuth) {
341
+ try {
342
+ profile = await selectJwsArtifactProfile(options.expectedIssuer, options.webBotAuth.trust);
343
+ } catch {
344
+ return { ...reject("governance_key_unknown", "Governance issuer trust record is unavailable"), retryable: true };
345
+ }
327
346
  }
328
- try {
329
- const key = await importJWK(jwk, alg);
330
- await compactVerify(options.token, key, {
331
- algorithms: [alg],
332
- crit: {
333
- authorized_commitment: true,
334
- authorized_task: true,
335
- authorized_payload_hash: true
347
+ if (profile?.profile === "web-bot-auth") {
348
+ if (options.buyerIdentity) {
349
+ try {
350
+ const record = relyingPartyAgentRecord(options.buyerIdentity.brandJson, options.buyerIdentity.brandDomain);
351
+ selectAgentByUrl(record, canonicalIssuer, { agentType: "governance" });
352
+ } catch {
353
+ return reject("governance_key_unknown", "Governance issuer is not the buyer's governance agent");
336
354
  }
337
- });
338
- } catch {
339
- return reject("governance_token_invalid", "Governance token signature verification failed");
355
+ }
356
+ const failure = await verifyGovernanceJwsOnWebBotAuth(options.token, profile.origin, options.webBotAuth);
357
+ if (failure) return failure;
358
+ } else {
359
+ let jwk;
360
+ try {
361
+ const resolver = options.buyerIdentity ? createGovernanceAgentJwksResolver(canonicalIssuer, options.buyerIdentity) : options.jwks;
362
+ if (!resolver) return reject("governance_key_unknown", "No governance key resolver or buyer identity configured");
363
+ jwk = await resolver.resolve(kid);
364
+ } catch {
365
+ return reject("governance_key_unknown", "Governance signing key could not be resolved");
366
+ }
367
+ if (!jwk || jwk.adcp_use !== "governance-signing" || jwk.use !== "sig" || !jwk.key_ops?.includes("verify") || jwk.alg !== void 0 && jwk.alg !== alg) {
368
+ return reject("governance_key_unknown", "Governance signing key is unknown or not authorized");
369
+ }
370
+ try {
371
+ const key = await importJWK(jwk, alg);
372
+ await compactVerify(options.token, key, {
373
+ algorithms: [alg],
374
+ crit: GOVERNANCE_CRIT
375
+ });
376
+ } catch {
377
+ return reject("governance_token_invalid", "Governance token signature verification failed");
378
+ }
340
379
  }
341
380
  try {
342
381
  if (options.revocationStore && await options.revocationStore.isRevoked(kid)) {
@@ -494,6 +533,113 @@ async function verifyGovernanceAuthorization(options) {
494
533
  payloadHash
495
534
  };
496
535
  }
536
+ function governanceFailureFromJwsArtifact(error) {
537
+ if (!(error instanceof JwsArtifactError))
538
+ return {
539
+ ok: false,
540
+ error: "governance_key_unknown",
541
+ message: "Governance signing key could not be resolved",
542
+ retryable: true
543
+ };
544
+ switch (error.code) {
545
+ case "jws_key_revoked":
546
+ return { ok: false, error: "governance_token_revoked", message: "Governance signing key is revoked" };
547
+ case "jws_revocation_unavailable":
548
+ return {
549
+ ok: false,
550
+ error: "governance_token_revoked",
551
+ message: "Governance revocation status could not be established",
552
+ retryable: true
553
+ };
554
+ case "jws_invalid":
555
+ return {
556
+ ok: false,
557
+ error: "governance_token_invalid",
558
+ message: `Governance token verification failed: ${error.message}`
559
+ };
560
+ case "jws_key_unavailable":
561
+ return {
562
+ ok: false,
563
+ error: "governance_key_unknown",
564
+ message: "Governance signing key could not be resolved",
565
+ retryable: true
566
+ };
567
+ default:
568
+ return { ok: false, error: "governance_key_unknown", message: "Governance signing key could not be resolved" };
569
+ }
570
+ }
571
+ const NO_ORIGIN_REVOCATION = Object.freeze({
572
+ ok: false,
573
+ error: "governance_token_revoked",
574
+ message: "No origin revocation source is configured for the Web Bot Auth path"
575
+ });
576
+ async function verifyGovernanceJwsOnWebBotAuth(token, origin, webBotAuth) {
577
+ if (!webBotAuth.revocation) return { ...NO_ORIGIN_REVOCATION };
578
+ try {
579
+ await verifyWebBotAuthJwsArtifact(token, origin, {
580
+ typ: GOVERNANCE_JWS_TYP,
581
+ directory: webBotAuth.directory,
582
+ revocation: webBotAuth.revocation,
583
+ // A governance context authorizes spend: an origin that serves no list fails closed.
584
+ revocationAbsent: "reject",
585
+ crit: GOVERNANCE_CRIT
586
+ });
587
+ return void 0;
588
+ } catch (error) {
589
+ return governanceFailureFromJwsArtifact(error);
590
+ }
591
+ }
592
+ async function verifyHistoricalGovernanceContext(options) {
593
+ const parsed = parseGovernanceJws(options.token, options.expectedIssuer);
594
+ if (!parsed.ok) return parsed;
595
+ if (parsed.alg !== "EdDSA")
596
+ return {
597
+ ok: false,
598
+ error: "governance_token_invalid",
599
+ message: "A Web Bot Auth governance context uses alg EdDSA"
600
+ };
601
+ if (!options.webBotAuth.revocation) return { ...NO_ORIGIN_REVOCATION };
602
+ let profile;
603
+ try {
604
+ profile = await selectJwsArtifactProfile(options.expectedIssuer, options.webBotAuth.trust);
605
+ } catch {
606
+ return {
607
+ ok: false,
608
+ error: "governance_key_unknown",
609
+ message: "Governance issuer trust record is unavailable",
610
+ retryable: true
611
+ };
612
+ }
613
+ if (profile.profile !== "web-bot-auth")
614
+ return {
615
+ ok: false,
616
+ error: "governance_key_unknown",
617
+ message: "Governance issuer is on the 3.2 profile; its trust record does not list its origin",
618
+ profile: "3.2"
619
+ };
620
+ try {
621
+ const verified = await verifyWebBotAuthJwsArtifact(parsed.token, profile.origin, {
622
+ typ: GOVERNANCE_JWS_TYP,
623
+ directory: options.webBotAuth.directory,
624
+ archive: options.webBotAuth.archive,
625
+ revocation: options.webBotAuth.revocation,
626
+ // No spend rides on an audit: an origin that serves no list has revoked nothing.
627
+ revocationAbsent: "accept",
628
+ revokedKey: "report",
629
+ crit: GOVERNANCE_CRIT
630
+ });
631
+ return {
632
+ ok: true,
633
+ claims: parsed.decodedClaims,
634
+ protectedHeader: parsed.protectedHeader,
635
+ keySource: verified.keySource,
636
+ revocation: verified.revocation,
637
+ ...verified.revocationDetail ? { revocationDetail: verified.revocationDetail } : {}
638
+ };
639
+ } catch (error) {
640
+ return governanceFailureFromJwsArtifact(error);
641
+ }
642
+ }
497
643
  class GovernanceAuthorizationError extends Error {
498
644
  code;
499
645
  constructor(result) {
@@ -549,5 +695,6 @@ export {
549
695
  governanceTaskRequiresProposedCommitment,
550
696
  targetDeclaresGovernanceEnforcement,
551
697
  targetDeclaresLegacyGovernanceAwareness,
552
- verifyGovernanceAuthorization
698
+ verifyGovernanceAuthorization,
699
+ verifyHistoricalGovernanceContext
553
700
  };
@@ -13,8 +13,8 @@
13
13
  * advisory — the authoritative check happens in the governance agent, which
14
14
  * resolves category synonyms and custom policies server-side.
15
15
  */
16
- export { GOVERNANCE_AUTHORIZATION_CRITICAL_CLAIMS, GovernanceAuthorizationError, GovernanceReplayStoreAdapter, InMemoryGovernanceReplayStore, buildGovernanceCommitment, buildGovernanceExecutionCommitment, buildGovernanceExecutionRequest, buildGovernanceIntentRequest, buildGovernanceProposedCommitment, computeGovernedPayloadHash, createGovernanceEnforcementMiddleware, getGovernanceEnforcementTasks, governancePurchaseTypeForTask, governanceTaskRequiresProposedCommitment, targetDeclaresGovernanceEnforcement, targetDeclaresLegacyGovernanceAwareness, verifyGovernanceAuthorization, createGovernanceAgentJwksResolver, } from './authorization.mjs';
17
- export type { BuildGovernanceExecutionRequestInput, BuildGovernanceIntentRequestInput, GovernanceAuthorizationClaims, GovernanceAuthorizationCriticalClaim, GovernanceAuthorizationErrorCode, GovernanceAuthorizationFailure, GovernanceAuthorizationResult, GovernanceAuthorizationSuccess, GovernanceCommitment, GovernanceEnforcementMiddleware, GovernanceEnforcementMiddlewareConfig, GovernanceEnforcementMiddlewareInput, GovernanceEnforcementMode, GovernanceEnforcementTask, GovernanceReplayStore, GovernanceReplayBinding, GovernanceRevocationResolver, GovernanceRevocationStatus, InMemoryGovernanceReplayStoreOptions, VerifyGovernanceAuthorizationOptions, GovernanceBuyerIdentity, } from './authorization.mjs';
16
+ export { GOVERNANCE_AUTHORIZATION_CRITICAL_CLAIMS, GovernanceAuthorizationError, GovernanceReplayStoreAdapter, InMemoryGovernanceReplayStore, buildGovernanceCommitment, buildGovernanceExecutionCommitment, buildGovernanceExecutionRequest, buildGovernanceIntentRequest, buildGovernanceProposedCommitment, computeGovernedPayloadHash, createGovernanceEnforcementMiddleware, getGovernanceEnforcementTasks, governancePurchaseTypeForTask, governanceTaskRequiresProposedCommitment, targetDeclaresGovernanceEnforcement, targetDeclaresLegacyGovernanceAwareness, verifyGovernanceAuthorization, verifyHistoricalGovernanceContext, createGovernanceAgentJwksResolver, } from './authorization.mjs';
17
+ export type { BuildGovernanceExecutionRequestInput, BuildGovernanceIntentRequestInput, GovernanceAuthorizationClaims, GovernanceAuthorizationCriticalClaim, GovernanceAuthorizationErrorCode, GovernanceAuthorizationFailure, GovernanceAuthorizationResult, GovernanceAuthorizationSuccess, GovernanceCommitment, GovernanceEnforcementMiddleware, GovernanceEnforcementMiddlewareConfig, GovernanceEnforcementMiddlewareInput, GovernanceEnforcementMode, GovernanceEnforcementTask, GovernanceReplayStore, GovernanceReplayBinding, GovernanceRevocationResolver, GovernanceRevocationStatus, InMemoryGovernanceReplayStoreOptions, VerifyGovernanceAuthorizationOptions, VerifyHistoricalGovernanceContextOptions, HistoricalGovernanceContextResult, GovernanceBuyerIdentity, } from './authorization.mjs';
18
18
  /**
19
19
  * `policy_categories` values that MUST set `human_review_required: true`
20
20
  * under GDPR Art 22 / EU AI Act Annex III. Matches the schema's `if/then`
@@ -13,8 +13,8 @@
13
13
  * advisory — the authoritative check happens in the governance agent, which
14
14
  * resolves category synonyms and custom policies server-side.
15
15
  */
16
- export { GOVERNANCE_AUTHORIZATION_CRITICAL_CLAIMS, GovernanceAuthorizationError, GovernanceReplayStoreAdapter, InMemoryGovernanceReplayStore, buildGovernanceCommitment, buildGovernanceExecutionCommitment, buildGovernanceExecutionRequest, buildGovernanceIntentRequest, buildGovernanceProposedCommitment, computeGovernedPayloadHash, createGovernanceEnforcementMiddleware, getGovernanceEnforcementTasks, governancePurchaseTypeForTask, governanceTaskRequiresProposedCommitment, targetDeclaresGovernanceEnforcement, targetDeclaresLegacyGovernanceAwareness, verifyGovernanceAuthorization, createGovernanceAgentJwksResolver, } from './authorization';
17
- export type { BuildGovernanceExecutionRequestInput, BuildGovernanceIntentRequestInput, GovernanceAuthorizationClaims, GovernanceAuthorizationCriticalClaim, GovernanceAuthorizationErrorCode, GovernanceAuthorizationFailure, GovernanceAuthorizationResult, GovernanceAuthorizationSuccess, GovernanceCommitment, GovernanceEnforcementMiddleware, GovernanceEnforcementMiddlewareConfig, GovernanceEnforcementMiddlewareInput, GovernanceEnforcementMode, GovernanceEnforcementTask, GovernanceReplayStore, GovernanceReplayBinding, GovernanceRevocationResolver, GovernanceRevocationStatus, InMemoryGovernanceReplayStoreOptions, VerifyGovernanceAuthorizationOptions, GovernanceBuyerIdentity, } from './authorization';
16
+ export { GOVERNANCE_AUTHORIZATION_CRITICAL_CLAIMS, GovernanceAuthorizationError, GovernanceReplayStoreAdapter, InMemoryGovernanceReplayStore, buildGovernanceCommitment, buildGovernanceExecutionCommitment, buildGovernanceExecutionRequest, buildGovernanceIntentRequest, buildGovernanceProposedCommitment, computeGovernedPayloadHash, createGovernanceEnforcementMiddleware, getGovernanceEnforcementTasks, governancePurchaseTypeForTask, governanceTaskRequiresProposedCommitment, targetDeclaresGovernanceEnforcement, targetDeclaresLegacyGovernanceAwareness, verifyGovernanceAuthorization, verifyHistoricalGovernanceContext, createGovernanceAgentJwksResolver, } from './authorization';
17
+ export type { BuildGovernanceExecutionRequestInput, BuildGovernanceIntentRequestInput, GovernanceAuthorizationClaims, GovernanceAuthorizationCriticalClaim, GovernanceAuthorizationErrorCode, GovernanceAuthorizationFailure, GovernanceAuthorizationResult, GovernanceAuthorizationSuccess, GovernanceCommitment, GovernanceEnforcementMiddleware, GovernanceEnforcementMiddlewareConfig, GovernanceEnforcementMiddlewareInput, GovernanceEnforcementMode, GovernanceEnforcementTask, GovernanceReplayStore, GovernanceReplayBinding, GovernanceRevocationResolver, GovernanceRevocationStatus, InMemoryGovernanceReplayStoreOptions, VerifyGovernanceAuthorizationOptions, VerifyHistoricalGovernanceContextOptions, HistoricalGovernanceContextResult, GovernanceBuyerIdentity, } from './authorization';
18
18
  /**
19
19
  * `policy_categories` values that MUST set `human_review_required: true`
20
20
  * under GDPR Art 22 / EU AI Act Annex III. Matches the schema's `if/then`
@@ -40,7 +40,8 @@ __export(governance_exports, {
40
40
  targetDeclaresGovernanceEnforcement: () => import_authorization.targetDeclaresGovernanceEnforcement,
41
41
  targetDeclaresLegacyGovernanceAwareness: () => import_authorization.targetDeclaresLegacyGovernanceAwareness,
42
42
  validateGovernancePlan: () => validateGovernancePlan,
43
- verifyGovernanceAuthorization: () => import_authorization.verifyGovernanceAuthorization
43
+ verifyGovernanceAuthorization: () => import_authorization.verifyGovernanceAuthorization,
44
+ verifyHistoricalGovernanceContext: () => import_authorization.verifyHistoricalGovernanceContext
44
45
  });
45
46
  module.exports = __toCommonJS(governance_exports);
46
47
  var import_authorization = require('./authorization.js');
@@ -165,5 +166,6 @@ function validateGovernancePlan(plan) {
165
166
  targetDeclaresGovernanceEnforcement,
166
167
  targetDeclaresLegacyGovernanceAwareness,
167
168
  validateGovernancePlan,
168
- verifyGovernanceAuthorization
169
+ verifyGovernanceAuthorization,
170
+ verifyHistoricalGovernanceContext
169
171
  });
@@ -16,6 +16,7 @@ import {
16
16
  targetDeclaresGovernanceEnforcement,
17
17
  targetDeclaresLegacyGovernanceAwareness,
18
18
  verifyGovernanceAuthorization,
19
+ verifyHistoricalGovernanceContext,
19
20
  createGovernanceAgentJwksResolver
20
21
  } from "./authorization.mjs";
21
22
  const REGULATED_HUMAN_REVIEW_CATEGORIES = Object.freeze([
@@ -138,5 +139,6 @@ export {
138
139
  targetDeclaresGovernanceEnforcement,
139
140
  targetDeclaresLegacyGovernanceAwareness,
140
141
  validateGovernancePlan,
141
- verifyGovernanceAuthorization
142
+ verifyGovernanceAuthorization,
143
+ verifyHistoricalGovernanceContext
142
144
  };
@@ -2,6 +2,7 @@ export * from './types.mjs';
2
2
  export * from './trust.mjs';
3
3
  export * from './lifecycle.mjs';
4
4
  export * from './revocation.mjs';
5
+ export * from './jws-artifacts.mjs';
5
6
  export { WEB_BOT_AUTH_DRAFT_REVISION, verifyWebBotAuth, signWebBotAuth, createWebBotAuthFetch, createSignedSignatureDirectory, SignatureDirectoryResolver, verifySignatureDirectory, verifyKeyDirectory, selectSignatureProfile, jwkThumbprint, WebBotAuthError, WebBotAuthUnavailableError, } from '../signing/web-bot-auth.mjs';
6
7
  export type { WebBotSigningKey, WebBotSigningOptions, VerifiedWebBotSigner, VerifyWebBotAuthOptions, VerifiedSignatureDirectory, SignatureDirectoryResolverOptions, } from '../signing/web-bot-auth.mjs';
7
8
  export { validateIdentity33Payload } from './validation.mjs';
@@ -2,6 +2,7 @@ export * from './types';
2
2
  export * from './trust';
3
3
  export * from './lifecycle';
4
4
  export * from './revocation';
5
+ export * from './jws-artifacts';
5
6
  export { WEB_BOT_AUTH_DRAFT_REVISION, verifyWebBotAuth, signWebBotAuth, createWebBotAuthFetch, createSignedSignatureDirectory, SignatureDirectoryResolver, verifySignatureDirectory, verifyKeyDirectory, selectSignatureProfile, jwkThumbprint, WebBotAuthError, WebBotAuthUnavailableError, } from '../signing/web-bot-auth';
6
7
  export type { WebBotSigningKey, WebBotSigningOptions, VerifiedWebBotSigner, VerifyWebBotAuthOptions, VerifiedSignatureDirectory, SignatureDirectoryResolverOptions, } from '../signing/web-bot-auth';
7
8
  export { validateIdentity33Payload } from './validation';