@chitmark/sdk 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -172
- package/dist/edge.cjs +34 -8
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +2 -2
- package/dist/edge.d.ts +2 -2
- package/dist/edge.js +34 -8
- package/dist/edge.js.map +1 -1
- package/dist/index.cjs +34 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +34 -8
- package/dist/index.js.map +1 -1
- package/dist/{trusted-ip-BvSjdU80.d.cts → trusted-ip-DNO3xzCU.d.cts} +41 -9
- package/dist/{trusted-ip-BvSjdU80.d.ts → trusted-ip-DNO3xzCU.d.ts} +41 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,21 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
// src/attribution.ts
|
|
4
4
|
function attributionEvidence(options, mode) {
|
|
5
|
-
const { request, agentProof, session, piiMode = mode } = options;
|
|
5
|
+
const { request, agentProof, session, purpose, piiMode = mode } = options;
|
|
6
6
|
const headers = request.headers;
|
|
7
7
|
const header = typeof headers.get === "function" ? headers.get("chitmark-agent-proof") : Object.entries(headers).find(
|
|
8
8
|
([name]) => name.toLowerCase() === "chitmark-agent-proof"
|
|
9
9
|
)?.[1];
|
|
10
|
-
let
|
|
11
|
-
if (!site && request.url
|
|
12
|
-
let proof = agentProof;
|
|
13
|
-
if (!proof && typeof header === "string" && header.length <= 2048 && site) {
|
|
10
|
+
let url;
|
|
11
|
+
if (!options.site && request.url) {
|
|
14
12
|
try {
|
|
15
|
-
|
|
13
|
+
url = new URL(request.url);
|
|
16
14
|
} catch {
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
|
-
|
|
17
|
+
const site = options.site ?? (url?.protocol === "https:" ? url.origin : void 0);
|
|
18
|
+
const proof = agentProof ?? (site ? parseProof(header) : void 0);
|
|
19
|
+
return { site, session, piiMode, purpose, agentProof: proof };
|
|
20
|
+
}
|
|
21
|
+
function parseProof(header) {
|
|
22
|
+
if (typeof header !== "string" || header.length > 2048) return;
|
|
23
|
+
try {
|
|
24
|
+
const value = JSON.parse(header);
|
|
25
|
+
if (!value || typeof value.nonce !== "string" || value.nonce.length > 36 || typeof value.issuedAt !== "number" || !Number.isSafeInteger(value.issuedAt) || typeof value.signature !== "string" || value.signature.length > 86)
|
|
26
|
+
return;
|
|
27
|
+
const { nonce, issuedAt, signature } = value;
|
|
28
|
+
if ("iss" in value) {
|
|
29
|
+
const key = value.agentKey;
|
|
30
|
+
if (value.iss === "chitmark-agent-key-v1" && key?.kty === "OKP" && key.crv === "Ed25519" && typeof key.x === "string" && key.x.length === 43 && !("d" in key)) {
|
|
31
|
+
return {
|
|
32
|
+
iss: value.iss,
|
|
33
|
+
agentKey: { kty: key.kty, crv: key.crv, x: key.x },
|
|
34
|
+
nonce,
|
|
35
|
+
issuedAt,
|
|
36
|
+
signature
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value.linkId === "string" && value.linkId.length <= 36)
|
|
42
|
+
return { linkId: value.linkId, nonce, issuedAt, signature };
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
20
46
|
}
|
|
21
47
|
|
|
22
48
|
// src/credentials.ts
|
|
@@ -153,7 +179,7 @@ var DEFAULT_BASE_URLS = {
|
|
|
153
179
|
};
|
|
154
180
|
var DEFAULT_TIMEOUT_MS = 800;
|
|
155
181
|
var LOCAL_TIMEOUT_MS = 2e3;
|
|
156
|
-
var SDK_VERSION = "0.
|
|
182
|
+
var SDK_VERSION = "0.9.0";
|
|
157
183
|
function defaultTimeoutMs(baseUrl) {
|
|
158
184
|
try {
|
|
159
185
|
const host = new URL(baseUrl).hostname.replace(/^\[|\]$/g, "").toLowerCase();
|