@adcp/sdk 16.0.0-beta.2 → 16.0.0-beta.3

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 (87) hide show
  1. package/README.md +54 -0
  2. package/dist/lib/core/ConversationTypes.d.mts +8 -3
  3. package/dist/lib/core/ConversationTypes.d.ts +8 -3
  4. package/dist/lib/core/SingleAgentClient.d.mts +5 -3
  5. package/dist/lib/core/SingleAgentClient.d.ts +5 -3
  6. package/dist/lib/core/TaskExecutor.js +5 -1
  7. package/dist/lib/core/TaskExecutor.mjs +5 -1
  8. package/dist/lib/errors/index.d.mts +9 -4
  9. package/dist/lib/errors/index.d.ts +9 -4
  10. package/dist/lib/index.d.mts +2 -2
  11. package/dist/lib/index.d.ts +2 -2
  12. package/dist/lib/index.js +6 -0
  13. package/dist/lib/index.mjs +7 -1
  14. package/dist/lib/negotiation/types.d.mts +20 -39
  15. package/dist/lib/negotiation/types.d.ts +20 -39
  16. package/dist/lib/protocols/index.d.mts +60 -24
  17. package/dist/lib/protocols/index.d.ts +60 -24
  18. package/dist/lib/protocols/index.js +9 -4
  19. package/dist/lib/protocols/index.mjs +3 -0
  20. package/dist/lib/protocols/mcp-modern.js +1 -0
  21. package/dist/lib/protocols/mcp-modern.mjs +2 -1
  22. package/dist/lib/protocols/mcp.js +1 -0
  23. package/dist/lib/protocols/mcp.mjs +2 -1
  24. package/dist/lib/protocols/responseSizeLimit.d.mts +91 -5
  25. package/dist/lib/protocols/responseSizeLimit.d.ts +91 -5
  26. package/dist/lib/protocols/responseSizeLimit.js +195 -31
  27. package/dist/lib/protocols/responseSizeLimit.mjs +192 -31
  28. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  29. package/dist/lib/signing/crypto.d.mts +15 -0
  30. package/dist/lib/signing/crypto.d.ts +15 -0
  31. package/dist/lib/signing/crypto.js +75 -3
  32. package/dist/lib/signing/crypto.mjs +78 -3
  33. package/dist/lib/signing/server.d.mts +1 -1
  34. package/dist/lib/signing/server.d.ts +1 -1
  35. package/dist/lib/signing/server.js +2 -0
  36. package/dist/lib/signing/server.mjs +2 -1
  37. package/dist/lib/signing/signer.js +2 -8
  38. package/dist/lib/signing/signer.mjs +3 -9
  39. package/dist/lib/signing/testing.js +2 -6
  40. package/dist/lib/signing/testing.mjs +3 -7
  41. package/dist/lib/signing/verifier.js +2 -2
  42. package/dist/lib/signing/verifier.mjs +3 -3
  43. package/dist/lib/signing/web-bot-auth.js +20 -7
  44. package/dist/lib/signing/web-bot-auth.mjs +21 -8
  45. package/dist/lib/signing/webhook-verifier.js +2 -2
  46. package/dist/lib/signing/webhook-verifier.mjs +3 -3
  47. package/dist/lib/substitution/compile.js +2 -1
  48. package/dist/lib/substitution/compile.mjs +2 -1
  49. package/dist/lib/substitution/consent-macros.d.mts +4 -0
  50. package/dist/lib/substitution/consent-macros.d.ts +4 -0
  51. package/dist/lib/substitution/consent-macros.js +45 -0
  52. package/dist/lib/substitution/consent-macros.mjs +20 -0
  53. package/dist/lib/substitution/index.d.mts +1 -1
  54. package/dist/lib/substitution/index.d.ts +1 -1
  55. package/dist/lib/substitution/index.js +2 -0
  56. package/dist/lib/substitution/index.mjs +2 -1
  57. package/dist/lib/substitution/translate.d.mts +15 -2
  58. package/dist/lib/substitution/translate.d.ts +15 -2
  59. package/dist/lib/substitution/translate.js +148 -26
  60. package/dist/lib/substitution/translate.mjs +147 -26
  61. package/dist/lib/testing/client.js +2 -1
  62. package/dist/lib/testing/client.mjs +2 -1
  63. package/dist/lib/testing/scenarios/capabilities.js +1 -1
  64. package/dist/lib/testing/scenarios/capabilities.mjs +1 -1
  65. package/dist/lib/testing/storyboard/request-signing/builder.js +2 -5
  66. package/dist/lib/testing/storyboard/request-signing/builder.mjs +3 -6
  67. package/dist/lib/testing/storyboard/signer-grader/grader.js +2 -7
  68. package/dist/lib/testing/storyboard/signer-grader/grader.mjs +2 -7
  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/types/enums.generated.d.mts +3 -0
  72. package/dist/lib/types/enums.generated.d.ts +3 -0
  73. package/dist/lib/types/enums.generated.js +9 -0
  74. package/dist/lib/types/enums.generated.mjs +6 -0
  75. package/dist/lib/validation/schema-loader.js +25 -0
  76. package/dist/lib/validation/schema-loader.mjs +24 -0
  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 +6 -1
  82. package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +3 -2
  83. package/docs/guides/UNIVERSAL-MACRO-COMPILATION.md +38 -0
  84. package/docs/guides/VALIDATE-YOUR-AGENT.md +12 -0
  85. package/docs/llms.txt +1 -1
  86. package/docs/migration-14.x-rc-worksheet.md +4 -4
  87. package/package.json +2 -1
@@ -19,7 +19,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var crypto_exports = {};
20
20
  __export(crypto_exports, {
21
21
  jwkToPublicKey: () => jwkToPublicKey,
22
- verifySignature: () => verifySignature
22
+ signWithPrivateJwk: () => signWithPrivateJwk,
23
+ signWithPrivateJwkAsync: () => signWithPrivateJwkAsync,
24
+ verifySignature: () => verifySignature,
25
+ verifySignatureAsync: () => verifySignatureAsync
23
26
  });
24
27
  module.exports = __toCommonJS(crypto_exports);
25
28
  var import_crypto = require("crypto");
@@ -45,7 +48,16 @@ function verifySignature(alg, publicKey, data, signature) {
45
48
  return (0, import_crypto.verify)(null, data, publicKey, signature);
46
49
  }
47
50
  if (alg === "ecdsa-p256-sha256") {
48
- return (0, import_crypto.verify)("sha256", data, { key: publicKey, dsaEncoding: "ieee-p1363" }, signature);
51
+ try {
52
+ return (0, import_crypto.verify)("sha256", data, { key: publicKey, dsaEncoding: "ieee-p1363" }, signature);
53
+ } catch {
54
+ return (0, import_crypto.verify)(
55
+ "sha256",
56
+ data,
57
+ { key: publicKey.export({ format: "jwk" }), format: "jwk", dsaEncoding: "ieee-p1363" },
58
+ signature
59
+ );
60
+ }
49
61
  }
50
62
  if (alg === "rsa-pss-sha512") {
51
63
  return (0, import_crypto.verify)(
@@ -60,8 +72,68 @@ function verifySignature(alg, publicKey, data, signature) {
60
72
  return false;
61
73
  }
62
74
  }
75
+ function subtleCrypto() {
76
+ const subtle = globalThis.crypto?.subtle;
77
+ return subtle && typeof subtle.importKey === "function" ? subtle : void 0;
78
+ }
79
+ const P256 = { name: "ECDSA", namedCurve: "P-256" };
80
+ const P256_SHA256 = { name: "ECDSA", hash: "SHA-256" };
81
+ function publicP256Jwk(jwk) {
82
+ return { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y };
83
+ }
84
+ function privateP256Jwk(jwk) {
85
+ return { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y, d: jwk.d };
86
+ }
87
+ async function verifySignatureAsync(alg, publicKey, data, signature) {
88
+ const subtle = subtleCrypto();
89
+ const keyObject = () => isKeyObject(publicKey) ? publicKey : jwkToPublicKey(publicKey);
90
+ if (alg !== "ecdsa-p256-sha256" || !subtle) return verifySignature(alg, keyObject(), data, signature);
91
+ try {
92
+ const jwk = isKeyObject(publicKey) ? publicKey.export({ format: "jwk" }) : publicKey;
93
+ const key = await importP256VerifyKey(subtle, jwk);
94
+ return await subtle.verify(P256_SHA256, key, toArrayBuffer(signature), toArrayBuffer(data));
95
+ } catch {
96
+ return false;
97
+ }
98
+ }
99
+ function isKeyObject(value) {
100
+ return typeof value?.export === "function" && "asymmetricKeyType" in value;
101
+ }
102
+ const p256VerifyKeys = /* @__PURE__ */ new Map();
103
+ function importP256VerifyKey(subtle, jwk) {
104
+ if (jwk.kty !== "EC" || jwk.crv !== "P-256" || typeof jwk.x !== "string" || typeof jwk.y !== "string")
105
+ return Promise.reject(new TypeError("Not a P-256 public key"));
106
+ const cacheKey = `${jwk.x}.${jwk.y}`;
107
+ let key = p256VerifyKeys.get(cacheKey);
108
+ if (!key) {
109
+ key = subtle.importKey("jwk", publicP256Jwk(jwk), P256, false, ["verify"]);
110
+ key.catch(() => p256VerifyKeys.delete(cacheKey));
111
+ if (p256VerifyKeys.size >= 256) p256VerifyKeys.delete(p256VerifyKeys.keys().next().value);
112
+ p256VerifyKeys.set(cacheKey, key);
113
+ }
114
+ return key;
115
+ }
116
+ function signWithPrivateJwk(alg, privateJwk, data) {
117
+ if (alg === "ed25519")
118
+ return new Uint8Array((0, import_crypto.sign)(null, data, (0, import_crypto.createPrivateKey)({ key: privateJwk, format: "jwk" })));
119
+ if (alg === "ecdsa-p256-sha256")
120
+ return new Uint8Array((0, import_crypto.sign)("sha256", data, { key: privateJwk, format: "jwk", dsaEncoding: "ieee-p1363" }));
121
+ throw new TypeError(`Unsupported signing algorithm: ${alg}`);
122
+ }
123
+ async function signWithPrivateJwkAsync(alg, privateJwk, data) {
124
+ const subtle = subtleCrypto();
125
+ if (alg !== "ecdsa-p256-sha256" || !subtle) return signWithPrivateJwk(alg, privateJwk, data);
126
+ const key = await subtle.importKey("jwk", privateP256Jwk(privateJwk), P256, false, ["sign"]);
127
+ return new Uint8Array(await subtle.sign(P256_SHA256, key, toArrayBuffer(data)));
128
+ }
129
+ function toArrayBuffer(bytes) {
130
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
131
+ }
63
132
  // Annotate the CommonJS export names for ESM import in node:
64
133
  0 && (module.exports = {
65
134
  jwkToPublicKey,
66
- verifySignature
135
+ signWithPrivateJwk,
136
+ signWithPrivateJwkAsync,
137
+ verifySignature,
138
+ verifySignatureAsync
67
139
  });
@@ -1,4 +1,10 @@
1
- import { constants, createPublicKey, verify as nodeVerify } from "crypto";
1
+ import {
2
+ constants,
3
+ createPrivateKey,
4
+ createPublicKey,
5
+ sign as nodeSign,
6
+ verify as nodeVerify
7
+ } from "crypto";
2
8
  import { RequestSignatureError } from "./errors.mjs";
3
9
  function jwkToPublicKey(jwk) {
4
10
  const publicJwk = { ...jwk };
@@ -21,7 +27,16 @@ function verifySignature(alg, publicKey, data, signature) {
21
27
  return nodeVerify(null, data, publicKey, signature);
22
28
  }
23
29
  if (alg === "ecdsa-p256-sha256") {
24
- return nodeVerify("sha256", data, { key: publicKey, dsaEncoding: "ieee-p1363" }, signature);
30
+ try {
31
+ return nodeVerify("sha256", data, { key: publicKey, dsaEncoding: "ieee-p1363" }, signature);
32
+ } catch {
33
+ return nodeVerify(
34
+ "sha256",
35
+ data,
36
+ { key: publicKey.export({ format: "jwk" }), format: "jwk", dsaEncoding: "ieee-p1363" },
37
+ signature
38
+ );
39
+ }
25
40
  }
26
41
  if (alg === "rsa-pss-sha512") {
27
42
  return nodeVerify(
@@ -36,7 +51,67 @@ function verifySignature(alg, publicKey, data, signature) {
36
51
  return false;
37
52
  }
38
53
  }
54
+ function subtleCrypto() {
55
+ const subtle = globalThis.crypto?.subtle;
56
+ return subtle && typeof subtle.importKey === "function" ? subtle : void 0;
57
+ }
58
+ const P256 = { name: "ECDSA", namedCurve: "P-256" };
59
+ const P256_SHA256 = { name: "ECDSA", hash: "SHA-256" };
60
+ function publicP256Jwk(jwk) {
61
+ return { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y };
62
+ }
63
+ function privateP256Jwk(jwk) {
64
+ return { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y, d: jwk.d };
65
+ }
66
+ async function verifySignatureAsync(alg, publicKey, data, signature) {
67
+ const subtle = subtleCrypto();
68
+ const keyObject = () => isKeyObject(publicKey) ? publicKey : jwkToPublicKey(publicKey);
69
+ if (alg !== "ecdsa-p256-sha256" || !subtle) return verifySignature(alg, keyObject(), data, signature);
70
+ try {
71
+ const jwk = isKeyObject(publicKey) ? publicKey.export({ format: "jwk" }) : publicKey;
72
+ const key = await importP256VerifyKey(subtle, jwk);
73
+ return await subtle.verify(P256_SHA256, key, toArrayBuffer(signature), toArrayBuffer(data));
74
+ } catch {
75
+ return false;
76
+ }
77
+ }
78
+ function isKeyObject(value) {
79
+ return typeof value?.export === "function" && "asymmetricKeyType" in value;
80
+ }
81
+ const p256VerifyKeys = /* @__PURE__ */ new Map();
82
+ function importP256VerifyKey(subtle, jwk) {
83
+ if (jwk.kty !== "EC" || jwk.crv !== "P-256" || typeof jwk.x !== "string" || typeof jwk.y !== "string")
84
+ return Promise.reject(new TypeError("Not a P-256 public key"));
85
+ const cacheKey = `${jwk.x}.${jwk.y}`;
86
+ let key = p256VerifyKeys.get(cacheKey);
87
+ if (!key) {
88
+ key = subtle.importKey("jwk", publicP256Jwk(jwk), P256, false, ["verify"]);
89
+ key.catch(() => p256VerifyKeys.delete(cacheKey));
90
+ if (p256VerifyKeys.size >= 256) p256VerifyKeys.delete(p256VerifyKeys.keys().next().value);
91
+ p256VerifyKeys.set(cacheKey, key);
92
+ }
93
+ return key;
94
+ }
95
+ function signWithPrivateJwk(alg, privateJwk, data) {
96
+ if (alg === "ed25519")
97
+ return new Uint8Array(nodeSign(null, data, createPrivateKey({ key: privateJwk, format: "jwk" })));
98
+ if (alg === "ecdsa-p256-sha256")
99
+ return new Uint8Array(nodeSign("sha256", data, { key: privateJwk, format: "jwk", dsaEncoding: "ieee-p1363" }));
100
+ throw new TypeError(`Unsupported signing algorithm: ${alg}`);
101
+ }
102
+ async function signWithPrivateJwkAsync(alg, privateJwk, data) {
103
+ const subtle = subtleCrypto();
104
+ if (alg !== "ecdsa-p256-sha256" || !subtle) return signWithPrivateJwk(alg, privateJwk, data);
105
+ const key = await subtle.importKey("jwk", privateP256Jwk(privateJwk), P256, false, ["sign"]);
106
+ return new Uint8Array(await subtle.sign(P256_SHA256, key, toArrayBuffer(data)));
107
+ }
108
+ function toArrayBuffer(bytes) {
109
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
110
+ }
39
111
  export {
40
112
  jwkToPublicKey,
41
- verifySignature
113
+ signWithPrivateJwk,
114
+ signWithPrivateJwkAsync,
115
+ verifySignature,
116
+ verifySignatureAsync
42
117
  };
@@ -12,7 +12,7 @@ export type { SsrfDnsLookup } from '../net/index.mjs';
12
12
  export { buildResponseSignatureBase, buildSignatureBase, canonicalAuthority, canonicalMethod, canonicalTargetUri, formatSignatureParams, getHeaderValue, type RequestLike, type RequestCanonicalizationProfile, type ResponseLike, type SignatureParams, } from './canonicalize.mjs';
13
13
  export { computeContentDigest, contentDigestMatches, parseContentDigest } from './content-digest.mjs';
14
14
  export { requestContextFromExpress, requestContextFromFetch, requestContextFromLambda, type ExpressRequestLike, type FetchRequestLike, type LambdaRequestEvent, type RequestContextFromExpressOptions, type RequestContextFromLambdaOptions, } from './request-context.mjs';
15
- export { jwkToPublicKey, verifySignature } from './crypto.mjs';
15
+ export { jwkToPublicKey, verifySignature, verifySignatureAsync } from './crypto.mjs';
16
16
  export { RequestSignatureError, RequestSigningErrorCodeMetadata, type RequestSignatureErrorCode, ResponseSignatureError, type ResponseSignatureErrorCode, WebhookSignatureError, type WebhookSignatureErrorCode, } from './errors.mjs';
17
17
  export { StaticJwksResolver, type JwksResolution, type JwksResolver } from './jwks.mjs';
18
18
  export { HttpsJwksResolver, type HttpsJwksResolverOptions } from './jwks-https.mjs';
@@ -12,7 +12,7 @@ export type { SsrfDnsLookup } from '../net';
12
12
  export { buildResponseSignatureBase, buildSignatureBase, canonicalAuthority, canonicalMethod, canonicalTargetUri, formatSignatureParams, getHeaderValue, type RequestLike, type RequestCanonicalizationProfile, type ResponseLike, type SignatureParams, } from './canonicalize';
13
13
  export { computeContentDigest, contentDigestMatches, parseContentDigest } from './content-digest';
14
14
  export { requestContextFromExpress, requestContextFromFetch, requestContextFromLambda, type ExpressRequestLike, type FetchRequestLike, type LambdaRequestEvent, type RequestContextFromExpressOptions, type RequestContextFromLambdaOptions, } from './request-context';
15
- export { jwkToPublicKey, verifySignature } from './crypto';
15
+ export { jwkToPublicKey, verifySignature, verifySignatureAsync } from './crypto';
16
16
  export { RequestSignatureError, RequestSigningErrorCodeMetadata, type RequestSignatureErrorCode, ResponseSignatureError, type ResponseSignatureErrorCode, WebhookSignatureError, type WebhookSignatureErrorCode, } from './errors';
17
17
  export { StaticJwksResolver, type JwksResolution, type JwksResolver } from './jwks';
18
18
  export { HttpsJwksResolver, type HttpsJwksResolverOptions } from './jwks-https';
@@ -83,6 +83,7 @@ __export(server_exports, {
83
83
  sweepExpiredReplays: () => import_postgres_replay_store.sweepExpiredReplays,
84
84
  verifyRequestSignature: () => import_verifier.verifyRequestSignature,
85
85
  verifySignature: () => import_crypto.verifySignature,
86
+ verifySignatureAsync: () => import_crypto.verifySignatureAsync,
86
87
  verifyWebhookSignature: () => import_webhook_verifier.verifyWebhookSignature
87
88
  });
88
89
  module.exports = __toCommonJS(server_exports);
@@ -175,5 +176,6 @@ var import_agent_resolver = require('./agent-resolver/index.js');
175
176
  sweepExpiredReplays,
176
177
  verifyRequestSignature,
177
178
  verifySignature,
179
+ verifySignatureAsync,
178
180
  verifyWebhookSignature
179
181
  });
@@ -13,7 +13,7 @@ import {
13
13
  requestContextFromFetch,
14
14
  requestContextFromLambda
15
15
  } from "./request-context.mjs";
16
- import { jwkToPublicKey, verifySignature } from "./crypto.mjs";
16
+ import { jwkToPublicKey, verifySignature, verifySignatureAsync } from "./crypto.mjs";
17
17
  import {
18
18
  RequestSignatureError,
19
19
  RequestSigningErrorCodeMetadata,
@@ -150,5 +150,6 @@ export {
150
150
  sweepExpiredReplays,
151
151
  verifyRequestSignature,
152
152
  verifySignature,
153
+ verifySignatureAsync,
153
154
  verifyWebhookSignature
154
155
  };
@@ -32,6 +32,7 @@ __export(signer_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(signer_exports);
34
34
  var import_crypto = require("crypto");
35
+ var import_crypto2 = require('./crypto.js');
35
36
  var import_canonicalize = require('./canonicalize.js');
36
37
  var import_content_digest = require('./content-digest.js');
37
38
  var import_errors = require('./errors.js');
@@ -203,14 +204,7 @@ function signResponse(response, key, options = {}) {
203
204
  return finalizeResponseSignature(prepared, signature);
204
205
  }
205
206
  function produceSignature(key, data) {
206
- const privateKey = (0, import_crypto.createPrivateKey)({
207
- key: key.privateKey,
208
- format: "jwk"
209
- });
210
- if (key.alg === "ed25519") {
211
- return new Uint8Array((0, import_crypto.sign)(null, data, privateKey));
212
- }
213
- return new Uint8Array((0, import_crypto.sign)("sha256", data, { key: privateKey, dsaEncoding: "ieee-p1363" }));
207
+ return (0, import_crypto2.signWithPrivateJwk)(key.alg, key.privateKey, data);
214
208
  }
215
209
  function flattenHeaders(headers) {
216
210
  const out = {};
@@ -1,4 +1,5 @@
1
- import { createPrivateKey, randomBytes, sign as nodeSign } from "crypto";
1
+ import { randomBytes } from "crypto";
2
+ import { signWithPrivateJwk } from "./crypto.mjs";
2
3
  import {
3
4
  buildResponseSignatureBase,
4
5
  buildSignatureBase,
@@ -180,14 +181,7 @@ function signResponse(response, key, options = {}) {
180
181
  return finalizeResponseSignature(prepared, signature);
181
182
  }
182
183
  function produceSignature(key, data) {
183
- const privateKey = createPrivateKey({
184
- key: key.privateKey,
185
- format: "jwk"
186
- });
187
- if (key.alg === "ed25519") {
188
- return new Uint8Array(nodeSign(null, data, privateKey));
189
- }
190
- return new Uint8Array(nodeSign("sha256", data, { key: privateKey, dsaEncoding: "ieee-p1363" }));
184
+ return signWithPrivateJwk(key.alg, key.privateKey, data);
191
185
  }
192
186
  function flattenHeaders(headers) {
193
187
  const out = {};
@@ -35,6 +35,7 @@ __export(testing_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(testing_exports);
37
37
  var import_node_crypto = require("node:crypto");
38
+ var import_crypto = require('./crypto.js');
38
39
  var import_jwks_helpers = require('./jwks-helpers.js');
39
40
  const ALLOW_IN_MEMORY_SIGNER_ENV = "ADCP_ALLOW_IN_MEMORY_SIGNER";
40
41
  class InMemorySigningProvider {
@@ -61,12 +62,7 @@ class InMemorySigningProvider {
61
62
  this.fingerprint = (0, import_node_crypto.createHash)("sha256").update(options.keyid).update("\0").update(options.privateKey.d).digest("hex").slice(0, 16);
62
63
  }
63
64
  async sign(payload) {
64
- const privateKey = (0, import_node_crypto.createPrivateKey)({ key: this.privateKey, format: "jwk" });
65
- const data = Buffer.from(payload);
66
- if (this.algorithm === "ed25519") {
67
- return new Uint8Array((0, import_node_crypto.sign)(null, data, privateKey));
68
- }
69
- return new Uint8Array((0, import_node_crypto.sign)("sha256", data, { key: privateKey, dsaEncoding: "ieee-p1363" }));
65
+ return (0, import_crypto.signWithPrivateJwkAsync)(this.algorithm, this.privateKey, payload);
70
66
  }
71
67
  }
72
68
  function signerKeyToProvider(key) {
@@ -1,4 +1,5 @@
1
- import { createHash, createPrivateKey, randomUUID, sign as nodeSign } from "node:crypto";
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { signWithPrivateJwkAsync } from "./crypto.mjs";
2
3
  import { assertAdcpUse } from "./jwks-helpers.mjs";
3
4
  const ALLOW_IN_MEMORY_SIGNER_ENV = "ADCP_ALLOW_IN_MEMORY_SIGNER";
4
5
  class InMemorySigningProvider {
@@ -25,12 +26,7 @@ class InMemorySigningProvider {
25
26
  this.fingerprint = createHash("sha256").update(options.keyid).update("\0").update(options.privateKey.d).digest("hex").slice(0, 16);
26
27
  }
27
28
  async sign(payload) {
28
- const privateKey = createPrivateKey({ key: this.privateKey, format: "jwk" });
29
- const data = Buffer.from(payload);
30
- if (this.algorithm === "ed25519") {
31
- return new Uint8Array(nodeSign(null, data, privateKey));
32
- }
33
- return new Uint8Array(nodeSign("sha256", data, { key: privateKey, dsaEncoding: "ieee-p1363" }));
29
+ return signWithPrivateJwkAsync(this.algorithm, this.privateKey, payload);
34
30
  }
35
31
  }
36
32
  function signerKeyToProvider(key) {
@@ -191,8 +191,8 @@ async function verifyRequestSignature(request, options) {
191
191
  parsedInput.signatureParamsValue,
192
192
  canonicalizationProfile
193
193
  );
194
- const publicKey = (0, import_crypto.jwkToPublicKey)(jwk);
195
- const valid = (0, import_crypto.verifySignature)(parsedInput.params.alg, publicKey, Buffer.from(base, "utf8"), parsedSig.bytes);
194
+ (0, import_crypto.jwkToPublicKey)(jwk);
195
+ const valid = await (0, import_crypto.verifySignatureAsync)(parsedInput.params.alg, jwk, Buffer.from(base, "utf8"), parsedSig.bytes);
196
196
  if (!valid) {
197
197
  throw new import_errors.RequestSignatureError(
198
198
  "request_signature_invalid",
@@ -16,7 +16,7 @@ import { RequestSignatureError } from "./errors.mjs";
16
16
  import { AgentResolverError } from "./agent-resolver/errors.mjs";
17
17
  import { parseStrictJson, StrictJsonError } from "./agent-resolver/strict-json.mjs";
18
18
  import { parseSignature, parseSignatureInput } from "./parser.mjs";
19
- import { jwkToPublicKey, verifySignature } from "./crypto.mjs";
19
+ import { jwkToPublicKey, verifySignatureAsync } from "./crypto.mjs";
20
20
  import { isUnresolvableOperation } from "./operation-resolution.mjs";
21
21
  import { containsWebhookAuthentication, WEBHOOK_AUTH_TRAVERSAL_DEPTH } from "./webhook-auth-detection.mjs";
22
22
  import {
@@ -180,8 +180,8 @@ async function verifyRequestSignature(request, options) {
180
180
  parsedInput.signatureParamsValue,
181
181
  canonicalizationProfile
182
182
  );
183
- const publicKey = jwkToPublicKey(jwk);
184
- const valid = verifySignature(parsedInput.params.alg, publicKey, Buffer.from(base, "utf8"), parsedSig.bytes);
183
+ jwkToPublicKey(jwk);
184
+ const valid = await verifySignatureAsync(parsedInput.params.alg, jwk, Buffer.from(base, "utf8"), parsedSig.bytes);
185
185
  if (!valid) {
186
186
  throw new RequestSignatureError(
187
187
  "request_signature_invalid",
@@ -237,17 +237,29 @@ function assertDigest(headers, body) {
237
237
  if (!digest || !(0, import_content_digest.contentDigestUsesEncoding)(digest, "rfc8941-base64") || !(0, import_content_digest.contentDigestMatches)(digest, body))
238
238
  denied("content_digest");
239
239
  }
240
- function verifyBytes(input, request, jwk, response) {
240
+ function signatureBytes(input, request, jwk, response) {
241
241
  const alg = algorithm(jwk);
242
242
  if (input.params.alg !== void 0 && input.params.alg !== alg) denied("algorithm");
243
243
  const signature = (0, import_canonicalize2.getHeaderValue)(response?.headers ?? request.headers, "signature");
244
244
  if (signature === void 0 || signature === "") denied("headers_missing");
245
- let bytes;
246
245
  try {
247
- bytes = (0, import_parser.parseSignature)(signature ?? "", input.label, "rfc8941-base64").bytes;
246
+ return { alg, bytes: (0, import_parser.parseSignature)(signature ?? "", input.label, "rfc8941-base64").bytes };
248
247
  } catch {
249
248
  return bad("signature");
250
249
  }
250
+ }
251
+ async function verifyBytesAsync(input, request, jwk) {
252
+ const { alg, bytes } = signatureBytes(input, request, jwk);
253
+ let valid = false;
254
+ try {
255
+ valid = await (0, import_crypto2.verifySignatureAsync)(alg, jwk, Buffer.from(buildWebBotAuthSignatureBase(input, request)), bytes);
256
+ } catch (error) {
257
+ if (error instanceof WebBotAuthError) throw error;
258
+ }
259
+ if (!valid) denied("signature_invalid");
260
+ }
261
+ function verifyBytes(input, request, jwk, response) {
262
+ const { alg, bytes } = signatureBytes(input, request, jwk, response);
251
263
  let valid = false;
252
264
  try {
253
265
  valid = (0, import_crypto2.verifySignature)(
@@ -419,7 +431,7 @@ async function verifyWebBotAuth(request, options) {
419
431
  denied("directory_key");
420
432
  const key = checkedDirectory.keys.find((key2) => key2.kid === keyid);
421
433
  if (!key || jwkThumbprint(key) !== keyid) denied("key");
422
- verifyBytes(input, request, key);
434
+ await verifyBytesAsync(input, request, key);
423
435
  if (options.isRevoked) await legacyRevocationCheck(options, origin, keyid);
424
436
  const nonceTuple = JSON.stringify([origin, nonce]);
425
437
  if (nonces.has(nonceTuple)) throw new WebBotAuthError(options.replayStatus ?? 429, "nonce_replayed");
@@ -665,14 +677,15 @@ async function signBase(base, key) {
665
677
  throw new TypeError("Web Bot Auth provider identity does not match its public key");
666
678
  return key.provider.sign(Buffer.from(base));
667
679
  }
668
- const privateKey = (0, import_crypto.createPrivateKey)({ key: jwk, format: "jwk" });
669
- if (alg === "rsa-pss-sha512")
680
+ if (alg === "rsa-pss-sha512") {
681
+ const privateKey = (0, import_crypto.createPrivateKey)({ key: jwk, format: "jwk" });
670
682
  return (0, import_crypto.sign)("sha512", Buffer.from(base), {
671
683
  key: privateKey,
672
684
  padding: import_crypto.constants.RSA_PKCS1_PSS_PADDING,
673
685
  saltLength: 64
674
686
  });
675
- return alg === "ed25519" ? (0, import_crypto.sign)(null, Buffer.from(base), privateKey) : (0, import_crypto.sign)("sha256", Buffer.from(base), { key: privateKey, dsaEncoding: "ieee-p1363" });
687
+ }
688
+ return (0, import_crypto2.signWithPrivateJwkAsync)(alg, jwk, Buffer.from(base));
676
689
  }
677
690
  async function signWebBotAuth(request, key, options) {
678
691
  const origin = (0, import_canonicalize.canonicalAgentOrigin)(options.origin);
@@ -14,7 +14,7 @@ import { canonicalAgentUrl } from "./agent-resolver/select-agent.mjs";
14
14
  import { parseStrictJson } from "./agent-resolver/strict-json.mjs";
15
15
  import { getHeaderValue } from "./canonicalize.mjs";
16
16
  import { computeContentDigest, contentDigestMatches, contentDigestUsesEncoding } from "./content-digest.mjs";
17
- import { jwkToPublicKey, verifySignature } from "./crypto.mjs";
17
+ import { jwkToPublicKey, signWithPrivateJwkAsync, verifySignature, verifySignatureAsync } from "./crypto.mjs";
18
18
  import {
19
19
  parseSignature,
20
20
  parseSignatureInput,
@@ -197,17 +197,29 @@ function assertDigest(headers, body) {
197
197
  if (!digest || !contentDigestUsesEncoding(digest, "rfc8941-base64") || !contentDigestMatches(digest, body))
198
198
  denied("content_digest");
199
199
  }
200
- function verifyBytes(input, request, jwk, response) {
200
+ function signatureBytes(input, request, jwk, response) {
201
201
  const alg = algorithm(jwk);
202
202
  if (input.params.alg !== void 0 && input.params.alg !== alg) denied("algorithm");
203
203
  const signature = getHeaderValue(response?.headers ?? request.headers, "signature");
204
204
  if (signature === void 0 || signature === "") denied("headers_missing");
205
- let bytes;
206
205
  try {
207
- bytes = parseSignature(signature ?? "", input.label, "rfc8941-base64").bytes;
206
+ return { alg, bytes: parseSignature(signature ?? "", input.label, "rfc8941-base64").bytes };
208
207
  } catch {
209
208
  return bad("signature");
210
209
  }
210
+ }
211
+ async function verifyBytesAsync(input, request, jwk) {
212
+ const { alg, bytes } = signatureBytes(input, request, jwk);
213
+ let valid = false;
214
+ try {
215
+ valid = await verifySignatureAsync(alg, jwk, Buffer.from(buildWebBotAuthSignatureBase(input, request)), bytes);
216
+ } catch (error) {
217
+ if (error instanceof WebBotAuthError) throw error;
218
+ }
219
+ if (!valid) denied("signature_invalid");
220
+ }
221
+ function verifyBytes(input, request, jwk, response) {
222
+ const { alg, bytes } = signatureBytes(input, request, jwk, response);
211
223
  let valid = false;
212
224
  try {
213
225
  valid = verifySignature(
@@ -379,7 +391,7 @@ async function verifyWebBotAuth(request, options) {
379
391
  denied("directory_key");
380
392
  const key = checkedDirectory.keys.find((key2) => key2.kid === keyid);
381
393
  if (!key || jwkThumbprint(key) !== keyid) denied("key");
382
- verifyBytes(input, request, key);
394
+ await verifyBytesAsync(input, request, key);
383
395
  if (options.isRevoked) await legacyRevocationCheck(options, origin, keyid);
384
396
  const nonceTuple = JSON.stringify([origin, nonce]);
385
397
  if (nonces.has(nonceTuple)) throw new WebBotAuthError(options.replayStatus ?? 429, "nonce_replayed");
@@ -625,14 +637,15 @@ async function signBase(base, key) {
625
637
  throw new TypeError("Web Bot Auth provider identity does not match its public key");
626
638
  return key.provider.sign(Buffer.from(base));
627
639
  }
628
- const privateKey = createPrivateKey({ key: jwk, format: "jwk" });
629
- if (alg === "rsa-pss-sha512")
640
+ if (alg === "rsa-pss-sha512") {
641
+ const privateKey = createPrivateKey({ key: jwk, format: "jwk" });
630
642
  return nodeSign("sha512", Buffer.from(base), {
631
643
  key: privateKey,
632
644
  padding: cryptoConstants.RSA_PKCS1_PSS_PADDING,
633
645
  saltLength: 64
634
646
  });
635
- return alg === "ed25519" ? nodeSign(null, Buffer.from(base), privateKey) : nodeSign("sha256", Buffer.from(base), { key: privateKey, dsaEncoding: "ieee-p1363" });
647
+ }
648
+ return signWithPrivateJwkAsync(alg, jwk, Buffer.from(base));
636
649
  }
637
650
  async function signWebBotAuth(request, key, options) {
638
651
  const origin = canonicalAgentOrigin(options.origin);
@@ -172,8 +172,8 @@ async function verifyWebhookSignature(request, options) {
172
172
  parsedInput.signatureParamsValue,
173
173
  "3.2"
174
174
  );
175
- const publicKey = (0, import_crypto.jwkToPublicKey)(jwk);
176
- const valid = (0, import_crypto.verifySignature)(parsedInput.params.alg, publicKey, Buffer.from(base, "utf8"), parsedSig.bytes);
175
+ (0, import_crypto.jwkToPublicKey)(jwk);
176
+ const valid = await (0, import_crypto.verifySignatureAsync)(parsedInput.params.alg, jwk, Buffer.from(base, "utf8"), parsedSig.bytes);
177
177
  if (!valid) {
178
178
  throw new import_errors.WebhookSignatureError(
179
179
  "webhook_signature_invalid",
@@ -4,7 +4,7 @@ import { RequestSignatureError, WebhookSignatureError } from "./errors.mjs";
4
4
  import { AgentResolverError } from "./agent-resolver/errors.mjs";
5
5
  import { BrandJsonResolverError } from "./brand-jwks.mjs";
6
6
  import { parseSignature, parseSignatureInput } from "./parser.mjs";
7
- import { jwkToPublicKey, verifySignature } from "./crypto.mjs";
7
+ import { jwkToPublicKey, verifySignatureAsync } from "./crypto.mjs";
8
8
  import { assertPublisherPins } from "./publisher-pins.mjs";
9
9
  import { InMemoryReplayStore } from "./replay.mjs";
10
10
  import { InMemoryRevocationStore } from "./revocation.mjs";
@@ -145,8 +145,8 @@ async function verifyWebhookSignature(request, options) {
145
145
  parsedInput.signatureParamsValue,
146
146
  "3.2"
147
147
  );
148
- const publicKey = jwkToPublicKey(jwk);
149
- const valid = verifySignature(parsedInput.params.alg, publicKey, Buffer.from(base, "utf8"), parsedSig.bytes);
148
+ jwkToPublicKey(jwk);
149
+ const valid = await verifySignatureAsync(parsedInput.params.alg, jwk, Buffer.from(base, "utf8"), parsedSig.bytes);
150
150
  if (!valid) {
151
151
  throw new WebhookSignatureError(
152
152
  "webhook_signature_invalid",
@@ -22,6 +22,7 @@ __export(compile_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(compile_exports);
24
24
  var import_enums = require('../types/enums.generated.js');
25
+ var import_consent_macros = require('./consent-macros.js');
25
26
  const BUILT_IN_SOURCE_SYNTAXES = /* @__PURE__ */ new Set([
26
27
  "adcp",
27
28
  "double_brace",
@@ -61,7 +62,7 @@ function universalMacroName(token) {
61
62
  }
62
63
  function isUniversalMacro(token) {
63
64
  const name = universalMacroName(token);
64
- return name !== null && UNIVERSAL_MACRO_NAMES.has(name);
65
+ return name !== null && (UNIVERSAL_MACRO_NAMES.has(name) || (0, import_consent_macros.isConsentMacro)(token));
65
66
  }
66
67
  function syntaxForExactToken(token, builtIns, customSyntaxes) {
67
68
  for (const syntax of customSyntaxes) {
@@ -1,4 +1,5 @@
1
1
  import { UniversalMacroValues } from "../types/enums.generated.mjs";
2
+ import { isConsentMacro } from "./consent-macros.mjs";
2
3
  const BUILT_IN_SOURCE_SYNTAXES = /* @__PURE__ */ new Set([
3
4
  "adcp",
4
5
  "double_brace",
@@ -38,7 +39,7 @@ function universalMacroName(token) {
38
39
  }
39
40
  function isUniversalMacro(token) {
40
41
  const name = universalMacroName(token);
41
- return name !== null && UNIVERSAL_MACRO_NAMES.has(name);
42
+ return name !== null && (UNIVERSAL_MACRO_NAMES.has(name) || isConsentMacro(token));
42
43
  }
43
44
  function syntaxForExactToken(token, builtIns, customSyntaxes) {
44
45
  for (const syntax of customSyntaxes) {
@@ -0,0 +1,4 @@
1
+ /** The complete token retains the receiving vendor's positive decimal GVL ID. */
2
+ export declare function isVendorScopedConsentMacro(token: string): boolean;
3
+ /** Recognize privacy signals for helper compilation and consent diagnostics. */
4
+ export declare function isConsentMacro(token: string): boolean;
@@ -0,0 +1,4 @@
1
+ /** The complete token retains the receiving vendor's positive decimal GVL ID. */
2
+ export declare function isVendorScopedConsentMacro(token: string): boolean;
3
+ /** Recognize privacy signals for helper compilation and consent diagnostics. */
4
+ export declare function isConsentMacro(token: string): boolean;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var consent_macros_exports = {};
20
+ __export(consent_macros_exports, {
21
+ isConsentMacro: () => isConsentMacro,
22
+ isVendorScopedConsentMacro: () => isVendorScopedConsentMacro
23
+ });
24
+ module.exports = __toCommonJS(consent_macros_exports);
25
+ const VENDOR_SCOPED_CONSENT_MACRO = /^\{GDPR_CONSENT_[1-9][0-9]*\}$/;
26
+ const CONSENT_MACROS = /* @__PURE__ */ new Set([
27
+ "{GDPR}",
28
+ "{GDPR_CONSENT}",
29
+ "{ADDTL_CONSENT}",
30
+ "{US_PRIVACY}",
31
+ "{GPP_STRING}",
32
+ "{GPP_SID}",
33
+ "{LIMIT_AD_TRACKING}"
34
+ ]);
35
+ function isVendorScopedConsentMacro(token) {
36
+ return VENDOR_SCOPED_CONSENT_MACRO.test(token);
37
+ }
38
+ function isConsentMacro(token) {
39
+ return CONSENT_MACROS.has(token) || isVendorScopedConsentMacro(token);
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ isConsentMacro,
44
+ isVendorScopedConsentMacro
45
+ });