@chitmark/sdk 0.7.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 -155
- package/dist/edge.cjs +601 -12
- 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 +584 -13
- package/dist/edge.js.map +1 -1
- package/dist/index.cjs +634 -12
- 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 +616 -13
- package/dist/index.js.map +1 -1
- package/dist/{trusted-ip-DnCZnqQx.d.cts → trusted-ip-DNO3xzCU.d.cts} +490 -9
- package/dist/{trusted-ip-DnCZnqQx.d.ts → trusted-ip-DNO3xzCU.d.ts} +490 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,191 +1,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Chitmark SDK for TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
AI agents and multi-account farms drain free tiers, trial credits, and API allowances while looking exactly like your best customers. Chitmark scores each action in under 50 ms and returns `allow`, `challenge`, or `deny`. Then your outcomes (conversion, credit burn, chargeback) come back through `feedback` and tune the next decision.
|
|
3
|
+
Use Chitmark from your backend to screen costly actions, recognize enrolled agents with signed proof, and manage paid API access.
|
|
6
4
|
|
|
7
5
|
[](https://www.npmjs.com/package/@chitmark/sdk)
|
|
8
6
|
|
|
9
|
-
Try it without a key: [run the playground](https://chitmark.com/playground). Live service health: [chitmark.com/status](https://chitmark.com/status).
|
|
10
|
-
|
|
11
7
|
## Install
|
|
12
8
|
|
|
9
|
+
Requires Node.js 24 or later. The package ships TypeScript declarations and supports ESM and CommonJS.
|
|
10
|
+
|
|
13
11
|
```bash
|
|
14
12
|
npm install @chitmark/sdk
|
|
15
|
-
# or
|
|
16
|
-
pnpm add @chitmark/sdk
|
|
17
13
|
```
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
Create a scoped API key in the [Chitmark dashboard](https://chitmark.com/dashboard) and set `CHITMARK_API_KEY` in your server environment.
|
|
20
16
|
|
|
21
|
-
##
|
|
17
|
+
## Resolve agent attribution
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
import { Chitmark } from "@chitmark/sdk";
|
|
19
|
+
Use a key with `attribution:read`. Replace the sample request with the inbound request from your server.
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// Optional, defaults shown
|
|
29
|
-
onDegraded: "challenge", // timeouts return a challenge, they never throw or allow
|
|
30
|
-
timeoutMs: 800, // local base URLs default to 2000ms
|
|
31
|
-
piiMode: "hashed", // 'hashed' | 'none' | 'raw'
|
|
32
|
-
env: "production",
|
|
33
|
-
});
|
|
21
|
+
```ts
|
|
22
|
+
import { Chitmark } from "@chitmark/sdk";
|
|
34
23
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
surface: "app.acme.com/signup",
|
|
39
|
-
subject: {
|
|
40
|
-
email: "buyer@acmecorp.com", // hashed client-side before the wire
|
|
41
|
-
ip: "203.0.113.7", // truncated to /24 client-side
|
|
42
|
-
userAgent: req.headers["user-agent"],
|
|
43
|
-
headers: req.headers,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
24
|
+
const chitmark = new Chitmark({ apiKey: process.env.CHITMARK_API_KEY! });
|
|
25
|
+
const request = new Request("https://app.example.com/agent-task");
|
|
26
|
+
const result = await chitmark.attribution.resolve({ request });
|
|
46
27
|
|
|
47
|
-
|
|
48
|
-
// stop and run the challenge flow (below)
|
|
49
|
-
}
|
|
50
|
-
// Persist verdict.eventId on the account row: feedback joins only on that id.
|
|
28
|
+
console.log(result.identity.recognized, result.principal.email);
|
|
51
29
|
```
|
|
52
30
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
| Verb | Method | Endpoint | When |
|
|
56
|
-
| :------------ | :--------------------- | :------------------- | :--------------------------- |
|
|
57
|
-
| **verify** | `chitmark.verify()` | `POST /v1/verify` | At signup / trial / action |
|
|
58
|
-
| **feedback** | `chitmark.feedback()` | `POST /v1/feedback` | After an outcome is known |
|
|
59
|
-
| **challenge** | `chitmark.challenge()` | `POST /v1/challenge` | On `challenge` or `degraded` |
|
|
31
|
+
The SDK reads fresh signed evidence from `Chitmark-Agent-Proof`. Without evidence, the sample returns an unknown identity and null email. An enrolled agent can sign for different recipients in a network-enabled deployment. Each site receives its own subject, and principal claims require a current grant for the recipient and purpose. Email also requires consent, `attribution:email`, and raw mode on an eligible plan.
|
|
60
32
|
|
|
61
|
-
|
|
62
|
-
(`degraded: true`); the SDK deserializes it like any other Verdict. Verify
|
|
63
|
-
never returns HTTP 503. Timeouts and transport errors synthesize a local
|
|
64
|
-
degraded challenge Verdict and never throw on `verify`. HTTP 4xx / 429 Error
|
|
65
|
-
responses throw `ChitmarkApiError`. Set `onDegraded` to `challenge` (the only
|
|
66
|
-
supported value), never allow on degraded.
|
|
33
|
+
For relative request URLs, pass your configured HTTPS origin as `site`. See the [Attribution quickstart](https://chitmark.com/docs/guides/agent-attribution/) and [network proof guide](https://chitmark.com/docs/guides/agent-attribution-network/).
|
|
67
34
|
|
|
68
|
-
|
|
35
|
+
## Screen a signup
|
|
69
36
|
|
|
70
|
-
|
|
37
|
+
Use a key with `verify:write`. Generate and retain a session ID on your server for the attempt.
|
|
71
38
|
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
39
|
+
```ts
|
|
40
|
+
import { randomUUID } from "node:crypto";
|
|
41
|
+
import { Chitmark, isEligibleAllow } from "@chitmark/sdk";
|
|
75
42
|
|
|
76
|
-
|
|
77
|
-
await chitmark.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Exact duplicate feedback bodies derive the same warehouse id (`eventId` + `outcome` + `value` + `unit` + `observedAt`), so connector retries with a stable business timestamp never double-count a burned value. Prefer an `Idempotency-Key` anyway; omitting `observedAt` uses server time and is not safe for bare retries.
|
|
86
|
-
|
|
87
|
-
### Handle a challenge
|
|
88
|
-
|
|
89
|
-
When verify returns `challenge`, issue one, solve it on the client, and complete it. Proof-of-work difficulty is server-issued (4 by default, up to 6 at higher risk tiers): about 65k hashes, milliseconds for one real user, costly at farm scale.
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
import { createHash } from "node:crypto";
|
|
93
|
-
|
|
94
|
-
const issued = await chitmark.challenge({
|
|
95
|
-
eventId: verdict.eventId,
|
|
96
|
-
session: "sess_9f3a", // the challenge binds to this session
|
|
43
|
+
const chitmark = new Chitmark({ apiKey: process.env.CHITMARK_API_KEY! });
|
|
44
|
+
const verdict = await chitmark.verify({
|
|
45
|
+
action: "signup",
|
|
46
|
+
session: randomUUID(),
|
|
47
|
+
surface: "app.example.com/signup",
|
|
48
|
+
subject: { email: "buyer@example.com" },
|
|
97
49
|
});
|
|
98
50
|
|
|
99
|
-
|
|
100
|
-
const { challengeId, instructions } = issued;
|
|
101
|
-
const prefix = "0".repeat(instructions.difficulty);
|
|
102
|
-
let nonce = 0;
|
|
103
|
-
for (; ; nonce++) {
|
|
104
|
-
const hex = createHash("sha256")
|
|
105
|
-
.update(`${challengeId}:${instructions.seed}:${nonce}`)
|
|
106
|
-
.digest("hex");
|
|
107
|
-
if (hex.startsWith(prefix)) break;
|
|
108
|
-
}
|
|
109
|
-
await chitmark.completeChallenge({
|
|
110
|
-
eventId: verdict.eventId,
|
|
111
|
-
challengeId,
|
|
112
|
-
session: "sess_9f3a",
|
|
113
|
-
proof: { type: "proof_of_work", nonce: String(nonce) },
|
|
114
|
-
});
|
|
115
|
-
// Re-verify with context: { challengeId }; completion alone does not authorize.
|
|
116
|
-
}
|
|
51
|
+
console.log(verdict.decision, isEligibleAllow(verdict), verdict.eventId);
|
|
117
52
|
```
|
|
118
53
|
|
|
119
|
-
|
|
54
|
+
Grant value only after an explicit, non-degraded allow. Timeouts and transport failures on `verify` produce a degraded challenge. The default data mode hashes email before sending it. Store the returned `eventId` for outcome reporting.
|
|
120
55
|
|
|
121
|
-
|
|
56
|
+
| Method | Use |
|
|
57
|
+
| --------------------------------- | --------------------------------------------------------------------------- |
|
|
58
|
+
| `verify` | Get an allow, challenge, or deny verdict. |
|
|
59
|
+
| `challenge` / `completeChallenge` | Issue and complete an additional check. Reuse the attempt's session. |
|
|
60
|
+
| `feedback` | Report an outcome against the stored `eventId` with a `feedback:write` key. |
|
|
61
|
+
| `verifyVerdictToken` | Verify a signed receipt against the expected session and tenant. |
|
|
122
62
|
|
|
123
|
-
|
|
124
|
-
const claims = await chitmark.verifyVerdictToken(verdict.verdictToken, {
|
|
125
|
-
session: "sess_9f3a",
|
|
126
|
-
tenantId: "org_acme",
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
if (claims.degraded || claims.decision !== "allow") {
|
|
130
|
-
throw new ChallengeRequiredError(); // HTTP 428 / challenge response
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Only now trust the allow.
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Rejects expired tokens, unknown keys, bad signatures, and session or origin mismatches with typed `VerdictTokenError` codes. A verified token that is not a non-degraded `allow` must still fail closed.
|
|
63
|
+
See the [Trust Decisions quickstart](https://chitmark.com/docs/quickstart/trust-decisions/), [challenge flow](https://chitmark.com/docs/api/challenge/), and [verdict token guide](https://chitmark.com/docs/guides/verdict-tokens/).
|
|
137
64
|
|
|
138
|
-
|
|
65
|
+
## Agent Paid Access
|
|
139
66
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
| Mode | Behavior |
|
|
143
|
-
| :----------------- | :--------------------------------------------------------- |
|
|
144
|
-
| `hashed` (default) | SHA-256 email, /24 IP truncation, allowlisted form fields |
|
|
145
|
-
| `none` | Derived/header-shape signals only (Web Bot Auth preserved) |
|
|
146
|
-
| `raw` | Tenant opt-in only; triggers higher compliance review |
|
|
67
|
+
Use `chitmark.charge(request)` to request a quote, continue checkout, or read purchase status. Sellers use separate scopes to reserve execution and record delivery. See the [Agent Paid Access guide](https://chitmark.com/docs/guides/agent-paid-access/).
|
|
147
68
|
|
|
148
69
|
## Framework integrations
|
|
149
70
|
|
|
150
|
-
Express
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
// Express: 403 on deny, 428 + challenge payload on challenge
|
|
154
|
-
// 428 means the request is not rejected permanently; a required verification
|
|
155
|
-
// precondition must be satisfied before the action can proceed.
|
|
156
|
-
import { chitmarkGate } from "@chitmark/sdk";
|
|
157
|
-
app.post("/signup", chitmarkGate(chitmark, "signup"), signupHandler);
|
|
158
|
-
|
|
159
|
-
// Next.js App Router
|
|
160
|
-
import { verifyNextRequest } from "@chitmark/sdk";
|
|
161
|
-
const verdict = await verifyNextRequest(req, chitmark, { action: "signup" });
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## Cloudflare Workers
|
|
165
|
-
|
|
166
|
-
The `/edge` entrypoint is the same client with a request-first helper:
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
import { Chitmark } from "@chitmark/sdk/edge";
|
|
170
|
-
|
|
171
|
-
const chitmark = new Chitmark({ apiKey: env.CHITMARK_API_KEY });
|
|
172
|
-
const verdict = await chitmark.verifyRequest(req, { action: "signup" });
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Agent integration
|
|
176
|
-
|
|
177
|
-
Using Cursor, Claude Code, Codex, or another coding agent? Point it at
|
|
178
|
-
[chitmark.com/SKILL.md](https://chitmark.com/SKILL.md), or paste this into your
|
|
179
|
-
prompt: `Integrate Chitmark into my app following https://chitmark.com/SKILL.md`.
|
|
180
|
-
|
|
181
|
-
## Resources
|
|
182
|
-
|
|
183
|
-
- [Agent integration skill](https://chitmark.com/SKILL.md)
|
|
184
|
-
- [API reference](https://chitmark.com/docs)
|
|
185
|
-
- [Quickstart](https://chitmark.com/docs/quickstart)
|
|
186
|
-
- [OpenAPI contract](https://chitmark.com/openapi.yaml)
|
|
187
|
-
- [Examples repository](https://github.com/nonameuserd/chitmark-examples)
|
|
71
|
+
- Express and Next.js use `chitmarkGate` and `verifyNextRequest`. [Framework guide](https://chitmark.com/docs/guides/drop-ins/)
|
|
72
|
+
- Workers use `ChitmarkEdge` from `@chitmark/sdk/edge`. [TypeScript reference](https://chitmark.com/docs/sdk/typescript/)
|
|
73
|
+
- Try a verdict without an API key in the [playground](https://chitmark.com/playground/).
|
|
188
74
|
|
|
189
75
|
## License
|
|
190
76
|
|
|
191
|
-
Proprietary
|
|
77
|
+
Proprietary. The package includes the license terms in `LICENSE`.
|