@adcp/sdk 16.0.0-beta.2 → 16.0.0-beta.4
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/README.md +54 -0
- package/dist/lib/auth/oauth/diagnose.js +3 -11
- package/dist/lib/auth/oauth/diagnose.mjs +4 -12
- package/dist/lib/auth/oauth/diagnostics.d.mts +2 -1
- package/dist/lib/auth/oauth/diagnostics.d.ts +2 -1
- package/dist/lib/auth/oauth/diagnostics.js +8 -10
- package/dist/lib/auth/oauth/diagnostics.mjs +7 -10
- package/dist/lib/core/ConversationTypes.d.mts +8 -3
- package/dist/lib/core/ConversationTypes.d.ts +8 -3
- package/dist/lib/core/SingleAgentClient.d.mts +5 -3
- package/dist/lib/core/SingleAgentClient.d.ts +5 -3
- package/dist/lib/core/TaskExecutor.js +5 -1
- package/dist/lib/core/TaskExecutor.mjs +5 -1
- package/dist/lib/errors/index.d.mts +9 -4
- package/dist/lib/errors/index.d.ts +9 -4
- package/dist/lib/index.d.mts +3 -3
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +8 -0
- package/dist/lib/index.mjs +14 -2
- package/dist/lib/negotiation/types.d.mts +20 -39
- package/dist/lib/negotiation/types.d.ts +20 -39
- package/dist/lib/protocols/index.d.mts +60 -24
- package/dist/lib/protocols/index.d.ts +60 -24
- package/dist/lib/protocols/index.js +9 -4
- package/dist/lib/protocols/index.mjs +3 -0
- package/dist/lib/protocols/mcp-modern.js +1 -0
- package/dist/lib/protocols/mcp-modern.mjs +2 -1
- package/dist/lib/protocols/mcp.js +1 -0
- package/dist/lib/protocols/mcp.mjs +2 -1
- package/dist/lib/protocols/responseSizeLimit.d.mts +91 -5
- package/dist/lib/protocols/responseSizeLimit.d.ts +91 -5
- package/dist/lib/protocols/responseSizeLimit.js +195 -31
- package/dist/lib/protocols/responseSizeLimit.mjs +192 -31
- package/dist/lib/reporting/consumer-runtime.js +2 -1
- package/dist/lib/reporting/consumer-runtime.mjs +2 -1
- package/dist/lib/reporting/ledger/handler.js +50 -11
- package/dist/lib/reporting/ledger/handler.mjs +50 -12
- package/dist/lib/reporting/ledger/index.d.mts +17 -14
- package/dist/lib/reporting/ledger/index.d.ts +17 -14
- package/dist/lib/reporting/ledger/index.js +32 -20
- package/dist/lib/reporting/ledger/index.mjs +21 -10
- package/dist/lib/reporting/ledger/offering-validation.d.mts +9 -0
- package/dist/lib/reporting/ledger/offering-validation.d.ts +9 -0
- package/dist/lib/reporting/{gcs/bucket-policy.js → ledger/offering-validation.js} +9 -8
- package/dist/lib/reporting/ledger/offering-validation.mjs +8 -0
- package/dist/lib/reporting/ledger/receipts.d.mts +48 -0
- package/dist/lib/reporting/ledger/receipts.d.ts +48 -0
- package/dist/lib/reporting/ledger/receipts.js +186 -0
- package/dist/lib/reporting/ledger/receipts.mjs +161 -0
- package/dist/lib/reporting/ledger/status-ingest.js +3 -3
- package/dist/lib/reporting/ledger/status-ingest.mjs +4 -5
- package/dist/lib/reporting/ledger/types.d.mts +43 -0
- package/dist/lib/reporting/ledger/types.d.ts +43 -0
- package/dist/lib/reporting/ledger/types.js +31 -2
- package/dist/lib/reporting/ledger/types.mjs +26 -1
- package/dist/lib/reporting/pagination.d.mts +6 -0
- package/dist/lib/reporting/pagination.d.ts +6 -0
- package/dist/lib/reporting/{gcs/errors.js → pagination.js} +12 -17
- package/dist/lib/reporting/pagination.mjs +12 -0
- package/dist/lib/reporting/reconciliation.d.mts +1 -0
- package/dist/lib/reporting/reconciliation.d.ts +1 -0
- package/dist/lib/reporting/reconciliation.js +3 -2
- package/dist/lib/reporting/reconciliation.mjs +3 -2
- package/dist/lib/reporting/service/index.d.mts +79 -153
- package/dist/lib/reporting/service/index.d.ts +79 -153
- package/dist/lib/reporting/service/index.js +34 -491
- package/dist/lib/reporting/service/index.mjs +36 -510
- package/dist/lib/reporting/service/scheduler-support.d.mts +43 -0
- package/dist/lib/reporting/service/scheduler-support.d.ts +43 -0
- package/dist/lib/reporting/service/scheduler-support.js +125 -0
- package/dist/lib/reporting/service/scheduler-support.mjs +96 -0
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/signing/canonicalize.d.mts +4 -0
- package/dist/lib/signing/canonicalize.d.ts +4 -0
- package/dist/lib/signing/canonicalize.js +14 -8
- package/dist/lib/signing/canonicalize.mjs +14 -8
- package/dist/lib/signing/content-digest.d.mts +8 -0
- package/dist/lib/signing/content-digest.d.ts +8 -0
- package/dist/lib/signing/content-digest.js +11 -5
- package/dist/lib/signing/content-digest.mjs +10 -5
- package/dist/lib/signing/crypto.d.mts +15 -0
- package/dist/lib/signing/crypto.d.ts +15 -0
- package/dist/lib/signing/crypto.js +75 -3
- package/dist/lib/signing/crypto.mjs +78 -3
- package/dist/lib/signing/server.d.mts +1 -1
- package/dist/lib/signing/server.d.ts +1 -1
- package/dist/lib/signing/server.js +2 -0
- package/dist/lib/signing/server.mjs +2 -1
- package/dist/lib/signing/signer.js +11 -14
- package/dist/lib/signing/signer.mjs +13 -16
- package/dist/lib/signing/testing.js +2 -6
- package/dist/lib/signing/testing.mjs +3 -7
- package/dist/lib/signing/verifier.js +2 -2
- package/dist/lib/signing/verifier.mjs +3 -3
- package/dist/lib/signing/web-bot-auth.js +122 -43
- package/dist/lib/signing/web-bot-auth.mjs +128 -44
- package/dist/lib/signing/webhook-verifier.js +2 -2
- package/dist/lib/signing/webhook-verifier.mjs +3 -3
- package/dist/lib/substitution/compile.js +2 -1
- package/dist/lib/substitution/compile.mjs +2 -1
- package/dist/lib/substitution/consent-macros.d.mts +4 -0
- package/dist/lib/substitution/consent-macros.d.ts +4 -0
- package/dist/lib/substitution/consent-macros.js +45 -0
- package/dist/lib/substitution/consent-macros.mjs +20 -0
- package/dist/lib/substitution/index.d.mts +1 -1
- package/dist/lib/substitution/index.d.ts +1 -1
- package/dist/lib/substitution/index.js +2 -0
- package/dist/lib/substitution/index.mjs +2 -1
- package/dist/lib/substitution/translate.d.mts +15 -2
- package/dist/lib/substitution/translate.d.ts +15 -2
- package/dist/lib/substitution/translate.js +148 -26
- package/dist/lib/substitution/translate.mjs +147 -26
- package/dist/lib/testing/client.js +2 -1
- package/dist/lib/testing/client.mjs +2 -1
- package/dist/lib/testing/scenarios/capabilities.js +1 -1
- package/dist/lib/testing/scenarios/capabilities.mjs +1 -1
- package/dist/lib/testing/storyboard/junit.js +16 -3
- package/dist/lib/testing/storyboard/junit.mjs +16 -3
- package/dist/lib/testing/storyboard/request-signing/builder.js +12 -14
- package/dist/lib/testing/storyboard/request-signing/builder.mjs +13 -15
- package/dist/lib/testing/storyboard/runner.js +94 -25
- package/dist/lib/testing/storyboard/runner.mjs +94 -25
- package/dist/lib/testing/storyboard/signer-grader/grader.js +2 -7
- package/dist/lib/testing/storyboard/signer-grader/grader.mjs +2 -7
- package/dist/lib/testing/storyboard/types.d.mts +6 -0
- package/dist/lib/testing/storyboard/types.d.ts +6 -0
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/types/enums.generated.d.mts +3 -0
- package/dist/lib/types/enums.generated.d.ts +3 -0
- package/dist/lib/types/enums.generated.js +9 -0
- package/dist/lib/types/enums.generated.mjs +6 -0
- package/dist/lib/validation/schema-loader.js +25 -0
- package/dist/lib/validation/schema-loader.mjs +24 -0
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.mjs +3 -3
- package/docs/TYPE-SUMMARY.md +28 -5
- package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +3 -2
- package/docs/guides/REPORTING-GCS-FENCE.md +3 -3
- package/docs/guides/REPORTING-GCS-MANAGED.md +4 -4
- package/docs/guides/REPORTING-LEDGER-CUTOVER.md +7 -7
- package/docs/guides/REPORTING-LEDGER.md +107 -51
- package/docs/guides/REPORTING-OPERATIONS.md +66 -5
- package/docs/guides/REPORTING-STABILITY.md +36 -32
- package/docs/guides/UNIVERSAL-MACRO-COMPILATION.md +38 -0
- package/docs/guides/VALIDATE-YOUR-AGENT.md +12 -0
- package/docs/llms.txt +4 -3
- package/docs/migration-14.x-rc-worksheet.md +4 -7
- package/docs/migration-reporting-storage-package.md +186 -0
- package/examples/README.md +1 -1
- package/package.json +14 -78
- package/dist/lib/reporting/azure/index.d.mts +0 -31
- package/dist/lib/reporting/azure/index.d.ts +0 -31
- package/dist/lib/reporting/azure/index.js +0 -266
- package/dist/lib/reporting/azure/index.mjs +0 -249
- package/dist/lib/reporting/bigquery/index.d.mts +0 -246
- package/dist/lib/reporting/bigquery/index.d.ts +0 -246
- package/dist/lib/reporting/bigquery/index.js +0 -633
- package/dist/lib/reporting/bigquery/index.mjs +0 -594
- package/dist/lib/reporting/gcs/adapter.d.mts +0 -38
- package/dist/lib/reporting/gcs/adapter.d.ts +0 -38
- package/dist/lib/reporting/gcs/adapter.js +0 -342
- package/dist/lib/reporting/gcs/adapter.mjs +0 -325
- package/dist/lib/reporting/gcs/bucket-policy.d.mts +0 -3
- package/dist/lib/reporting/gcs/bucket-policy.d.ts +0 -3
- package/dist/lib/reporting/gcs/bucket-policy.mjs +0 -7
- package/dist/lib/reporting/gcs/errors.d.mts +0 -11
- package/dist/lib/reporting/gcs/errors.d.ts +0 -11
- package/dist/lib/reporting/gcs/errors.mjs +0 -16
- package/dist/lib/reporting/gcs/fence.d.mts +0 -41
- package/dist/lib/reporting/gcs/fence.d.ts +0 -41
- package/dist/lib/reporting/gcs/fence.js +0 -250
- package/dist/lib/reporting/gcs/fence.mjs +0 -230
- package/dist/lib/reporting/gcs/index.d.mts +0 -18
- package/dist/lib/reporting/gcs/index.d.ts +0 -18
- package/dist/lib/reporting/gcs/index.js +0 -44
- package/dist/lib/reporting/gcs/index.mjs +0 -14
- package/dist/lib/reporting/gcs/io.d.mts +0 -7
- package/dist/lib/reporting/gcs/io.d.ts +0 -7
- package/dist/lib/reporting/gcs/io.js +0 -95
- package/dist/lib/reporting/gcs/io.mjs +0 -69
- package/dist/lib/reporting/gcs/reader.d.mts +0 -67
- package/dist/lib/reporting/gcs/reader.d.ts +0 -67
- package/dist/lib/reporting/gcs/reader.js +0 -193
- package/dist/lib/reporting/gcs/reader.mjs +0 -169
- package/dist/lib/reporting/gcs/row-provider.d.mts +0 -39
- package/dist/lib/reporting/gcs/row-provider.d.ts +0 -39
- package/dist/lib/reporting/gcs/row-provider.js +0 -225
- package/dist/lib/reporting/gcs/row-provider.mjs +0 -208
- package/dist/lib/reporting/gcs/validation.d.mts +0 -5
- package/dist/lib/reporting/gcs/validation.d.ts +0 -5
- package/dist/lib/reporting/gcs/validation.js +0 -49
- package/dist/lib/reporting/gcs/validation.mjs +0 -25
- package/dist/lib/reporting/ledger/change-feed.d.mts +0 -69
- package/dist/lib/reporting/ledger/change-feed.d.ts +0 -69
- package/dist/lib/reporting/ledger/change-feed.js +0 -107
- package/dist/lib/reporting/ledger/change-feed.mjs +0 -80
- package/dist/lib/reporting/ledger/managed-postgres.d.mts +0 -293
- package/dist/lib/reporting/ledger/managed-postgres.d.ts +0 -293
- package/dist/lib/reporting/ledger/managed-postgres.js +0 -2346
- package/dist/lib/reporting/ledger/managed-postgres.mjs +0 -2332
- package/dist/lib/reporting/ledger/managed-router.d.mts +0 -148
- package/dist/lib/reporting/ledger/managed-router.d.ts +0 -148
- package/dist/lib/reporting/ledger/managed-router.js +0 -280
- package/dist/lib/reporting/ledger/managed-router.mjs +0 -258
- package/dist/lib/reporting/ledger/managed.d.mts +0 -535
- package/dist/lib/reporting/ledger/managed.d.ts +0 -535
- package/dist/lib/reporting/ledger/managed.js +0 -761
- package/dist/lib/reporting/ledger/managed.mjs +0 -729
- package/dist/lib/reporting/ledger/notification-activity.d.mts +0 -332
- package/dist/lib/reporting/ledger/notification-activity.d.ts +0 -332
- package/dist/lib/reporting/ledger/notification-activity.js +0 -1366
- package/dist/lib/reporting/ledger/notification-activity.mjs +0 -1337
- package/dist/lib/reporting/ledger/object-writes.d.mts +0 -128
- package/dist/lib/reporting/ledger/object-writes.d.ts +0 -128
- package/dist/lib/reporting/ledger/object-writes.js +0 -147
- package/dist/lib/reporting/ledger/object-writes.mjs +0 -114
- package/dist/lib/reporting/ledger/postgres.d.mts +0 -689
- package/dist/lib/reporting/ledger/postgres.d.ts +0 -689
- package/dist/lib/reporting/ledger/postgres.js +0 -4462
- package/dist/lib/reporting/ledger/postgres.mjs +0 -4462
- package/dist/lib/reporting/ledger/row-storage-migration.d.mts +0 -59
- package/dist/lib/reporting/ledger/row-storage-migration.d.ts +0 -59
- package/dist/lib/reporting/ledger/row-storage-migration.js +0 -365
- package/dist/lib/reporting/ledger/row-storage-migration.mjs +0 -339
- package/dist/lib/reporting/ledger/row-storage-object.d.mts +0 -203
- package/dist/lib/reporting/ledger/row-storage-object.d.ts +0 -203
- package/dist/lib/reporting/ledger/row-storage-object.js +0 -379
- package/dist/lib/reporting/ledger/row-storage-object.mjs +0 -335
- package/dist/lib/reporting/ledger/row-storage-provider-io.d.mts +0 -44
- package/dist/lib/reporting/ledger/row-storage-provider-io.d.ts +0 -44
- package/dist/lib/reporting/ledger/row-storage-provider-io.js +0 -142
- package/dist/lib/reporting/ledger/row-storage-provider-io.mjs +0 -111
- package/dist/lib/reporting/ledger/row-storage.d.mts +0 -316
- package/dist/lib/reporting/ledger/row-storage.d.ts +0 -316
- package/dist/lib/reporting/ledger/row-storage.js +0 -812
- package/dist/lib/reporting/ledger/row-storage.mjs +0 -802
- package/dist/lib/reporting/s3/index.d.mts +0 -34
- package/dist/lib/reporting/s3/index.d.ts +0 -34
- package/dist/lib/reporting/s3/index.js +0 -347
- package/dist/lib/reporting/s3/index.mjs +0 -340
- package/dist/lib/reporting/service/maintenance.d.mts +0 -148
- package/dist/lib/reporting/service/maintenance.d.ts +0 -148
- package/dist/lib/reporting/service/maintenance.js +0 -185
- package/dist/lib/reporting/service/maintenance.mjs +0 -159
- package/examples/reliable-reporting-service/README.md +0 -169
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
135
|
+
signWithPrivateJwk,
|
|
136
|
+
signWithPrivateJwkAsync,
|
|
137
|
+
verifySignature,
|
|
138
|
+
verifySignatureAsync
|
|
67
139
|
});
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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');
|
|
@@ -81,6 +82,7 @@ function prepareRequestSignature(request, identity, options = {}) {
|
|
|
81
82
|
const windowSeconds = Math.min(options.windowSeconds ?? 300, import_types.MAX_SIGNATURE_WINDOW_SECONDS);
|
|
82
83
|
const nonce = options.nonce ?? base64UrlRandom(16);
|
|
83
84
|
const label = options.label ?? "sig1";
|
|
85
|
+
assertLabelAndClock(label, now);
|
|
84
86
|
const hasBody = (request.body ?? "").length > 0;
|
|
85
87
|
const binaryEncoding = options.binaryEncoding ?? "legacy-base64url";
|
|
86
88
|
const coverDigest = options.coverContentDigest ?? binaryEncoding === "rfc8941-base64";
|
|
@@ -111,11 +113,8 @@ function prepareRequestSignature(request, identity, options = {}) {
|
|
|
111
113
|
}
|
|
112
114
|
function finalizeRequestSignature(prepared, signature) {
|
|
113
115
|
const headers = { ...prepared.headers };
|
|
114
|
-
const sigB64 = Buffer.from(signature).toString(
|
|
115
|
-
prepared.binaryEncoding === "legacy-base64url" ? "base64url" : "base64"
|
|
116
|
-
);
|
|
117
116
|
headers["Signature-Input"] = `${prepared.label}=${(0, import_canonicalize.formatSignatureParams)(prepared.components, prepared.params)}`;
|
|
118
|
-
headers["Signature"] =
|
|
117
|
+
headers["Signature"] = (0, import_content_digest.serializeByteSequenceMember)(prepared.label, signature, prepared.binaryEncoding);
|
|
119
118
|
return { headers, signatureBase: prepared.base, params: prepared.params };
|
|
120
119
|
}
|
|
121
120
|
function signRequest(request, key, options = {}) {
|
|
@@ -137,6 +136,7 @@ function prepareWebhookSignature(request, identity, options = {}) {
|
|
|
137
136
|
const windowSeconds = Math.min(options.windowSeconds ?? 300, import_types.MAX_SIGNATURE_WINDOW_SECONDS);
|
|
138
137
|
const nonce = options.nonce ?? base64UrlRandom(16);
|
|
139
138
|
const label = options.label ?? "sig1";
|
|
139
|
+
assertLabelAndClock(label, now);
|
|
140
140
|
const headers = { ...flattenHeaders(request.headers) };
|
|
141
141
|
headers["Content-Digest"] = (0, import_content_digest.computeContentDigest)(request.body ?? "", "legacy-base64url");
|
|
142
142
|
const components = [...import_webhook_verifier.WEBHOOK_MANDATORY_COMPONENTS];
|
|
@@ -163,6 +163,7 @@ function prepareResponseSignature(response, identity, options = {}) {
|
|
|
163
163
|
const windowSeconds = Math.min(options.windowSeconds ?? 300, import_types.MAX_SIGNATURE_WINDOW_SECONDS);
|
|
164
164
|
const nonce = options.nonce ?? base64UrlRandom(16);
|
|
165
165
|
const label = options.label ?? "sig1";
|
|
166
|
+
assertLabelAndClock(label, now);
|
|
166
167
|
const hasBody = (response.body ?? "").length > 0;
|
|
167
168
|
const coverDigest = (options.coverContentDigest ?? true) && hasBody;
|
|
168
169
|
const headers = { ...flattenHeaders(response.headers) };
|
|
@@ -191,9 +192,8 @@ function prepareResponseSignature(response, identity, options = {}) {
|
|
|
191
192
|
}
|
|
192
193
|
function finalizeResponseSignature(prepared, signature) {
|
|
193
194
|
const headers = { ...prepared.headers };
|
|
194
|
-
const sigB64 = Buffer.from(signature).toString("base64url");
|
|
195
195
|
headers["Signature-Input"] = `${prepared.label}=${(0, import_canonicalize.formatSignatureParams)(prepared.components, prepared.params)}`;
|
|
196
|
-
headers["Signature"] =
|
|
196
|
+
headers["Signature"] = (0, import_content_digest.serializeByteSequenceMember)(prepared.label, signature, "legacy-base64url");
|
|
197
197
|
return { status: prepared.status, headers, signatureBase: prepared.base, params: prepared.params };
|
|
198
198
|
}
|
|
199
199
|
function signResponse(response, key, options = {}) {
|
|
@@ -203,14 +203,7 @@ function signResponse(response, key, options = {}) {
|
|
|
203
203
|
return finalizeResponseSignature(prepared, signature);
|
|
204
204
|
}
|
|
205
205
|
function produceSignature(key, data) {
|
|
206
|
-
|
|
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" }));
|
|
206
|
+
return (0, import_crypto2.signWithPrivateJwk)(key.alg, key.privateKey, data);
|
|
214
207
|
}
|
|
215
208
|
function flattenHeaders(headers) {
|
|
216
209
|
const out = {};
|
|
@@ -220,6 +213,10 @@ function flattenHeaders(headers) {
|
|
|
220
213
|
}
|
|
221
214
|
return out;
|
|
222
215
|
}
|
|
216
|
+
function assertLabelAndClock(label, now) {
|
|
217
|
+
if (!/^[a-z*][a-z0-9_.*-]*$/.test(label)) throw new TypeError(`Signature label "${label}" is not an RFC 8941 key`);
|
|
218
|
+
if (!Number.isSafeInteger(now)) throw new TypeError("Signature clock must return integer epoch seconds");
|
|
219
|
+
}
|
|
223
220
|
function base64UrlRandom(byteLength) {
|
|
224
221
|
return (0, import_crypto.randomBytes)(byteLength).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
225
222
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomBytes } from "crypto";
|
|
2
|
+
import { signWithPrivateJwk } from "./crypto.mjs";
|
|
2
3
|
import {
|
|
3
4
|
buildResponseSignatureBase,
|
|
4
5
|
buildSignatureBase,
|
|
5
6
|
formatSignatureParams
|
|
6
7
|
} from "./canonicalize.mjs";
|
|
7
|
-
import { computeContentDigest } from "./content-digest.mjs";
|
|
8
|
+
import { computeContentDigest, serializeByteSequenceMember } from "./content-digest.mjs";
|
|
8
9
|
import { RequestSignatureError, ResponseSignatureError, WebhookSignatureError } from "./errors.mjs";
|
|
9
10
|
import {
|
|
10
11
|
MANDATORY_COMPONENTS,
|
|
@@ -58,6 +59,7 @@ function prepareRequestSignature(request, identity, options = {}) {
|
|
|
58
59
|
const windowSeconds = Math.min(options.windowSeconds ?? 300, MAX_SIGNATURE_WINDOW_SECONDS);
|
|
59
60
|
const nonce = options.nonce ?? base64UrlRandom(16);
|
|
60
61
|
const label = options.label ?? "sig1";
|
|
62
|
+
assertLabelAndClock(label, now);
|
|
61
63
|
const hasBody = (request.body ?? "").length > 0;
|
|
62
64
|
const binaryEncoding = options.binaryEncoding ?? "legacy-base64url";
|
|
63
65
|
const coverDigest = options.coverContentDigest ?? binaryEncoding === "rfc8941-base64";
|
|
@@ -88,11 +90,8 @@ function prepareRequestSignature(request, identity, options = {}) {
|
|
|
88
90
|
}
|
|
89
91
|
function finalizeRequestSignature(prepared, signature) {
|
|
90
92
|
const headers = { ...prepared.headers };
|
|
91
|
-
const sigB64 = Buffer.from(signature).toString(
|
|
92
|
-
prepared.binaryEncoding === "legacy-base64url" ? "base64url" : "base64"
|
|
93
|
-
);
|
|
94
93
|
headers["Signature-Input"] = `${prepared.label}=${formatSignatureParams(prepared.components, prepared.params)}`;
|
|
95
|
-
headers["Signature"] =
|
|
94
|
+
headers["Signature"] = serializeByteSequenceMember(prepared.label, signature, prepared.binaryEncoding);
|
|
96
95
|
return { headers, signatureBase: prepared.base, params: prepared.params };
|
|
97
96
|
}
|
|
98
97
|
function signRequest(request, key, options = {}) {
|
|
@@ -114,6 +113,7 @@ function prepareWebhookSignature(request, identity, options = {}) {
|
|
|
114
113
|
const windowSeconds = Math.min(options.windowSeconds ?? 300, MAX_SIGNATURE_WINDOW_SECONDS);
|
|
115
114
|
const nonce = options.nonce ?? base64UrlRandom(16);
|
|
116
115
|
const label = options.label ?? "sig1";
|
|
116
|
+
assertLabelAndClock(label, now);
|
|
117
117
|
const headers = { ...flattenHeaders(request.headers) };
|
|
118
118
|
headers["Content-Digest"] = computeContentDigest(request.body ?? "", "legacy-base64url");
|
|
119
119
|
const components = [...WEBHOOK_MANDATORY_COMPONENTS];
|
|
@@ -140,6 +140,7 @@ function prepareResponseSignature(response, identity, options = {}) {
|
|
|
140
140
|
const windowSeconds = Math.min(options.windowSeconds ?? 300, MAX_SIGNATURE_WINDOW_SECONDS);
|
|
141
141
|
const nonce = options.nonce ?? base64UrlRandom(16);
|
|
142
142
|
const label = options.label ?? "sig1";
|
|
143
|
+
assertLabelAndClock(label, now);
|
|
143
144
|
const hasBody = (response.body ?? "").length > 0;
|
|
144
145
|
const coverDigest = (options.coverContentDigest ?? true) && hasBody;
|
|
145
146
|
const headers = { ...flattenHeaders(response.headers) };
|
|
@@ -168,9 +169,8 @@ function prepareResponseSignature(response, identity, options = {}) {
|
|
|
168
169
|
}
|
|
169
170
|
function finalizeResponseSignature(prepared, signature) {
|
|
170
171
|
const headers = { ...prepared.headers };
|
|
171
|
-
const sigB64 = Buffer.from(signature).toString("base64url");
|
|
172
172
|
headers["Signature-Input"] = `${prepared.label}=${formatSignatureParams(prepared.components, prepared.params)}`;
|
|
173
|
-
headers["Signature"] =
|
|
173
|
+
headers["Signature"] = serializeByteSequenceMember(prepared.label, signature, "legacy-base64url");
|
|
174
174
|
return { status: prepared.status, headers, signatureBase: prepared.base, params: prepared.params };
|
|
175
175
|
}
|
|
176
176
|
function signResponse(response, key, options = {}) {
|
|
@@ -180,14 +180,7 @@ function signResponse(response, key, options = {}) {
|
|
|
180
180
|
return finalizeResponseSignature(prepared, signature);
|
|
181
181
|
}
|
|
182
182
|
function produceSignature(key, data) {
|
|
183
|
-
|
|
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" }));
|
|
183
|
+
return signWithPrivateJwk(key.alg, key.privateKey, data);
|
|
191
184
|
}
|
|
192
185
|
function flattenHeaders(headers) {
|
|
193
186
|
const out = {};
|
|
@@ -197,6 +190,10 @@ function flattenHeaders(headers) {
|
|
|
197
190
|
}
|
|
198
191
|
return out;
|
|
199
192
|
}
|
|
193
|
+
function assertLabelAndClock(label, now) {
|
|
194
|
+
if (!/^[a-z*][a-z0-9_.*-]*$/.test(label)) throw new TypeError(`Signature label "${label}" is not an RFC 8941 key`);
|
|
195
|
+
if (!Number.isSafeInteger(now)) throw new TypeError("Signature clock must return integer epoch seconds");
|
|
196
|
+
}
|
|
200
197
|
function base64UrlRandom(byteLength) {
|
|
201
198
|
return randomBytes(byteLength).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
202
199
|
}
|
|
@@ -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
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
195
|
-
const valid = (0, import_crypto.
|
|
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,
|
|
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
|
-
|
|
184
|
-
const valid =
|
|
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",
|