kontext-sdk 0.9.0 → 0.11.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 CHANGED
@@ -1,180 +1,45 @@
1
1
  # kontext-sdk
2
2
 
3
- Compliance audit trail CLI and SDK for AI agents making stablecoin payments on Base.
3
+ The trust layer for agentic stablecoin and fiat payments.
4
4
 
5
- **USDC** · **USDT** · **DAI** · **EURC** · **USDP** · **USDG** · **x402** · **Circle Programmable Wallets**
6
-
7
- ---
8
-
9
- ## 30-Second Demo
10
-
11
- ```bash
12
- npx kontext-sdk check 0xAgentWallet 0xMerchant --amount 5000 --token USDC
13
- ```
14
-
15
- ```
16
- OFAC Sanctions: CLEAR
17
- Travel Rule: TRIGGERED ($5,000 >= $3,000 EDD threshold)
18
- CTR Threshold: CLEAR ($5,000 < $10,000)
19
- Large TX Alert: CLEAR ($5,000 < $50,000)
20
- Risk Level: medium
21
- ```
22
-
23
- No install. No config. No API key. One command.
5
+ Cryptographic verifiable intent for org-wide payments using one line of code and a CLI.
24
6
 
25
7
  ## Install
26
8
 
27
9
  ```bash
28
- npm install -g kontext-sdk
29
- ```
30
-
31
- Then run `kontext` from anywhere. Or use `npx kontext-sdk` for one-off checks.
32
-
33
- ## Claude Code / Cursor / Windsurf
34
-
35
- ```json
36
- {
37
- "mcpServers": {
38
- "kontext": {
39
- "command": "npx",
40
- "args": ["-y", "kontext-sdk", "mcp"]
41
- }
42
- }
43
- }
44
- ```
45
-
46
- Then ask: *"verify this USDC transaction for compliance"*
47
-
48
- ## CLI Commands
49
-
50
- ### `kontext check <from> <to>` — stateless compliance check
51
-
52
- ```bash
53
- npx kontext-sdk check 0xSender 0xReceiver --amount 5000 --token USDC
10
+ npm install kontext-sdk
54
11
  ```
55
12
 
56
- Instant OFAC screening + threshold checks. No state, no persistence.
57
-
58
- ### `kontext verify` — log + check + digest proof
13
+ ## Auto-instrumentation (recommended)
59
14
 
60
15
  ```bash
61
- npx kontext-sdk verify --tx 0xabc123 --amount 5000 --token USDC \
62
- --from 0xAgent --to 0xMerchant --agent my-bot
63
- ```
64
-
65
- Runs compliance checks, logs the transaction, appends to the tamper-evident digest chain. Persists to `.kontext/` in the current directory.
66
-
67
- ### `kontext reason` — log agent reasoning
68
-
69
- ```bash
70
- npx kontext-sdk reason "API returned data I need. Price within budget." \
71
- --agent my-bot --session sess_abc --step 1
72
- ```
73
-
74
- ### `kontext cert` — export compliance certificate
75
-
76
- ```bash
77
- npx kontext-sdk cert --agent my-bot --output cert.json
78
- ```
79
-
80
- ### `kontext audit` — verify digest chain integrity
81
-
82
- ```bash
83
- npx kontext-sdk audit --verify
84
- ```
85
-
86
- ### `kontext mcp` — MCP server mode
87
-
88
- ```bash
89
- npx kontext-sdk mcp
90
- ```
91
-
92
- Starts an MCP server on stdio for Claude Code, Cursor, and Windsurf.
93
-
94
- ### Flags
95
-
96
- - `--json` on any command outputs structured JSON
97
- - `--amount <number>` transaction amount in token units
98
- - `--token <symbol>` one of USDC, USDT, DAI, EURC, USDP, USDG
99
-
100
- ## SDK — Programmatic Usage
101
-
102
- For tighter integration, use the SDK directly:
103
-
104
- ```typescript
105
- import { Kontext, FileStorage } from 'kontext-sdk';
106
-
107
- const ctx = Kontext.init({
108
- projectId: 'my-agent',
109
- environment: 'production',
110
- storage: new FileStorage('.kontext'),
111
- });
112
-
113
- // One-call: compliance check + transaction log + digest proof
114
- const result = await ctx.verify({
115
- txHash: '0xabc...',
116
- chain: 'base',
117
- amount: '5000',
118
- token: 'USDC',
119
- from: '0xAgent...',
120
- to: '0xMerchant...',
121
- agentId: 'payment-agent',
122
- });
123
-
124
- // result.compliant = true/false
125
- // result.checks = [{ name: 'OFAC Sanctions', passed: true }, ...]
126
- // result.riskLevel = 'low' | 'medium' | 'high' | 'critical'
127
- // result.digestProof = 'sha256:a1b2c3...'
16
+ npx kontext init
17
+ # Creates kontext.config.json with your wallets, tokens, chains, and compliance mode
128
18
  ```
129
19
 
130
- ### Log Reasoning
131
-
132
20
  ```typescript
133
- await ctx.logReasoning({
134
- agentId: 'payment-agent',
135
- action: 'approve-transfer',
136
- reasoning: 'Price within budget. Merchant verified.',
137
- confidence: 0.95,
138
- });
139
- ```
21
+ import { Kontext, withKontextCompliance } from 'kontext-sdk';
140
22
 
141
- ### Compliance Certificate
23
+ const kontext = Kontext.init(); // reads kontext.config.json
24
+ const client = withKontextCompliance(walletClient, kontext);
142
25
 
143
- ```typescript
144
- const cert = await ctx.generateComplianceCertificate({
145
- agentId: 'payment-agent',
146
- includeReasoning: true,
147
- });
26
+ // Every USDC/USDT/DAI/EURC transfer is now auto-verified
27
+ await client.sendTransaction({ to: usdcAddress, data: transferCalldata });
148
28
  ```
149
29
 
150
- ### Trust Score
30
+ Two interception layers for full coverage:
31
+ - **Code wrap** -- intercepts `sendTransaction`/`writeContract` on your viem client
32
+ - **Chain listener** -- watches monitored wallets on-chain for all outgoing stablecoin transfers
151
33
 
152
- ```typescript
153
- const score = await ctx.getTrustScore('payment-agent');
154
- // score.score = 87, score.level = 'high'
155
- ```
34
+ ## Explicit verify
156
35
 
157
- ### Verify Digest Chain
36
+ For direct control over individual transactions:
158
37
 
159
38
  ```typescript
160
- const chain = ctx.verifyDigestChain();
161
- console.log(chain.valid); // true — no tampering
162
- ```
39
+ import { Kontext } from 'kontext-sdk';
163
40
 
164
- ### Agent Provenance
41
+ const ctx = Kontext.init({ projectId: 'my-agent' });
165
42
 
166
- Three layers of accountability: session delegation, action binding, and human attestation.
167
-
168
- ```typescript
169
- // Layer 1: Session delegation — record who authorized the agent
170
- const session = await ctx.createAgentSession({
171
- agentId: 'treasury-agent',
172
- delegatedBy: 'user:vinay',
173
- scope: ['transfer', 'approve'],
174
- expiresAt: new Date(Date.now() + 3600_000).toISOString(),
175
- });
176
-
177
- // Layer 2: Action binding — tie every call to the session
178
43
  const result = await ctx.verify({
179
44
  txHash: '0xabc...',
180
45
  chain: 'base',
@@ -182,109 +47,67 @@ const result = await ctx.verify({
182
47
  token: 'USDC',
183
48
  from: '0xAgent...',
184
49
  to: '0xMerchant...',
185
- agentId: 'treasury-agent',
186
- sessionId: session.sessionId,
187
- });
188
-
189
- // Layer 3: Human attestation — reviewer signs off
190
- const checkpoint = await ctx.createCheckpoint({
191
- sessionId: session.sessionId,
192
- actionIds: [result.transaction.id],
193
- summary: 'Reviewed $5K transfer to known vendor',
194
- });
195
-
196
- await ctx.attestCheckpoint({
197
- checkpointId: checkpoint.checkpointId,
198
- attestedBy: 'compliance@company.com',
199
- signature: reviewerSignature,
50
+ agentId: 'payment-agent',
200
51
  });
201
52
 
202
- // End session, list sessions, list checkpoints
203
- await ctx.endAgentSession(session.sessionId);
204
- const sessions = ctx.getAgentSessions('treasury-agent');
205
- const checkpoints = ctx.getCheckpoints(session.sessionId);
53
+ // result.compliant -- true/false
54
+ // result.checks -- OFAC, Travel Rule, CTR thresholds
55
+ // result.riskLevel -- low | medium | high | critical
56
+ // result.digestProof -- tamper-evident SHA-256 chain
206
57
  ```
207
58
 
208
- #### CLI Commands
59
+ ## What's verified
209
60
 
210
- ```bash
211
- npx kontext-sdk session create --agent treasury-agent --delegated-by user:vinay --scope transfer,approve
212
- npx kontext-sdk session list --agent treasury-agent
213
- npx kontext-sdk session end <sessionId>
214
- npx kontext-sdk checkpoint create --session <sessionId> --actions act_1,act_2 --summary "Reviewed transfers"
215
- npx kontext-sdk checkpoint attest <checkpointId> --attested-by compliance@company.com
216
- npx kontext-sdk checkpoint list --session <sessionId>
217
- ```
218
-
219
- ### Persist Across Restarts
220
-
221
- ```typescript
222
- import { FileStorage } from 'kontext-sdk';
223
-
224
- const ctx = Kontext.init({
225
- projectId: 'my-agent',
226
- environment: 'production',
227
- storage: new FileStorage('.kontext'),
228
- });
229
-
230
- // Data persists to .kontext/ directory
231
- // Call ctx.flush() to write, ctx.restore() to reload
232
- ```
61
+ Every stablecoin transfer gets:
62
+ - OFAC sanctions screening (built-in SDN list, no API key)
63
+ - Travel Rule threshold detection ($3K EDD, $10K CTR, $50K large tx)
64
+ - Tamper-evident audit trail (patented digest chain)
65
+ - Agent trust score (0-100)
66
+ - Compliance certificate with SHA-256 proof
233
67
 
234
- ## Pluggable Sanctions Screening
68
+ ## Pluggable screening
235
69
 
236
- Multi-provider screening with consensus strategies. Bring your own API keys, or use the built-in OFAC SDN list at zero cost.
70
+ Bring your own providers or use the built-in OFAC list:
237
71
 
238
72
  ```typescript
239
- import {
240
- ScreeningAggregator,
241
- OFACAddressProvider,
242
- UKOFSIProvider,
243
- OpenSanctionsProvider,
244
- ChainalysisOracleProvider,
245
- } from 'kontext-sdk';
73
+ import { ScreeningAggregator, OFACAddressProvider, OpenSanctionsProvider } from 'kontext-sdk';
246
74
 
247
75
  const screener = new ScreeningAggregator({
248
76
  providers: [
249
- new OFACAddressProvider(), // built-in, no API key
250
- new UKOFSIProvider(), // built-in, no API key
251
- new OpenSanctionsProvider({ apiKey: 'os_...' }), // 331+ sources
252
- new ChainalysisOracleProvider({ apiKey: 'ch_...' }), // on-chain oracle
77
+ new OFACAddressProvider(), // built-in, free
78
+ new OpenSanctionsProvider({ apiKey: 'os_...' }), // 331+ sources
253
79
  ],
254
80
  consensus: 'ANY_MATCH',
255
81
  });
256
-
257
- const result = await screener.screenAddress('0x...');
258
- // result.flagged = true/false
259
- // result.matches = [{ provider, list, matchType, confidence, ... }]
260
- // result.providerResults = per-provider breakdown
261
82
  ```
262
83
 
263
- **Built-in providers (no API key):** OFAC SDN addresses, UK OFSI addresses
264
- **API providers:** OpenSanctions (address + entity), Chainalysis Oracle (address), Chainalysis Free API (address)
265
- **Local providers:** OpenSanctions local dataset (download via `kontext sync`)
84
+ ## Agent reasoning
266
85
 
267
- ## Compliance Thresholds
86
+ ```typescript
87
+ await ctx.logReasoning({
88
+ agentId: 'payment-agent',
89
+ action: 'approve-transfer',
90
+ reasoning: 'Amount within daily limit. Recipient on allowlist.',
91
+ confidence: 0.95,
92
+ });
93
+ ```
268
94
 
269
- | Threshold | Amount | Trigger |
270
- |-----------|--------|---------|
271
- | **EDD / Travel Rule** | $3,000 | Enhanced Due Diligence required |
272
- | **CTR** | $10,000 | Currency Transaction Report |
273
- | **Large TX Alert** | $50,000 | Large Transaction Alert |
95
+ ## MCP server
274
96
 
275
- OFAC sanctions screening uses the built-in SDN list. No API key required.
97
+ ```json
98
+ {
99
+ "mcpServers": {
100
+ "kontext": {
101
+ "command": "npx",
102
+ "args": ["-y", "@kontext-sdk/cli", "mcp"]
103
+ }
104
+ }
105
+ }
106
+ ```
276
107
 
277
- ## What's Included
108
+ ## Zero runtime dependencies
278
109
 
279
- - Tamper-evident audit trail (patented digest chain)
280
- - OFAC sanctions screening (SDN list, no API key)
281
- - Pluggable multi-provider screening (OFAC, UK OFSI, OpenSanctions, Chainalysis)
282
- - Compliance certificates with SHA-256 proof
283
- - Agent reasoning logs
284
- - Trust scoring and anomaly detection
285
- - Agent provenance — session delegation, action binding, human attestation
286
- - MCP server mode for AI coding tools
287
- - Zero runtime dependencies
110
+ The SDK has no `dependencies`. Works in Node.js 18+, TypeScript 5.0+.
288
111
 
289
112
  ## License
290
113
 
@@ -292,6 +115,4 @@ MIT
292
115
 
293
116
  ---
294
117
 
295
- Kontext provides compliance logging tools. Regulatory responsibility remains with the operator. This software does not constitute legal advice and does not guarantee regulatory compliance. Consult qualified legal counsel for your specific obligations.
296
-
297
118
  Built by [Legaci Labs](https://www.getkontext.com)