kontext-sdk 0.10.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 +57 -265
- package/dist/index.d.mts +309 -2
- package/dist/index.d.ts +309 -2
- package/dist/index.js +721 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +719 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,180 +1,45 @@
|
|
|
1
1
|
# kontext-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The trust layer for agentic stablecoin and fiat payments.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
|
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
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
Instant OFAC screening + threshold checks. No state, no persistence.
|
|
57
|
-
|
|
58
|
-
### `kontext verify` — log + check + digest proof
|
|
59
|
-
|
|
60
|
-
```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
|
|
10
|
+
npm install kontext-sdk
|
|
72
11
|
```
|
|
73
12
|
|
|
74
|
-
|
|
13
|
+
## Auto-instrumentation (recommended)
|
|
75
14
|
|
|
76
15
|
```bash
|
|
77
|
-
npx kontext
|
|
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
|
|
16
|
+
npx kontext init
|
|
17
|
+
# Creates kontext.config.json with your wallets, tokens, chains, and compliance mode
|
|
90
18
|
```
|
|
91
19
|
|
|
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
20
|
```typescript
|
|
105
|
-
import { Kontext,
|
|
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...'
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Log Reasoning
|
|
131
|
-
|
|
132
|
-
```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
|
-
|
|
23
|
+
const kontext = Kontext.init(); // reads kontext.config.json
|
|
24
|
+
const client = withKontextCompliance(walletClient, kontext);
|
|
142
25
|
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
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
|
-
|
|
153
|
-
const score = await ctx.getTrustScore('payment-agent');
|
|
154
|
-
// score.score = 87, score.level = 'high'
|
|
155
|
-
```
|
|
34
|
+
## Explicit verify
|
|
156
35
|
|
|
157
|
-
|
|
36
|
+
For direct control over individual transactions:
|
|
158
37
|
|
|
159
38
|
```typescript
|
|
160
|
-
|
|
161
|
-
console.log(chain.valid); // true — no tampering
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### Agent Provenance
|
|
165
|
-
|
|
166
|
-
Three layers of accountability: session delegation, action binding, and human attestation.
|
|
39
|
+
import { Kontext } from 'kontext-sdk';
|
|
167
40
|
|
|
168
|
-
|
|
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
|
-
});
|
|
41
|
+
const ctx = Kontext.init({ projectId: 'my-agent' });
|
|
176
42
|
|
|
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,138 +47,67 @@ const result = await ctx.verify({
|
|
|
182
47
|
token: 'USDC',
|
|
183
48
|
from: '0xAgent...',
|
|
184
49
|
to: '0xMerchant...',
|
|
185
|
-
agentId: '
|
|
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,
|
|
200
|
-
});
|
|
201
|
-
|
|
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);
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
#### CLI Commands
|
|
209
|
-
|
|
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'),
|
|
50
|
+
agentId: 'payment-agent',
|
|
228
51
|
});
|
|
229
52
|
|
|
230
|
-
//
|
|
231
|
-
//
|
|
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
|
|
232
57
|
```
|
|
233
58
|
|
|
234
|
-
##
|
|
235
|
-
|
|
236
|
-
Run `npx kontext init` to generate a config file, then wrap your viem client — every stablecoin transfer is automatically logged.
|
|
237
|
-
|
|
238
|
-
```bash
|
|
239
|
-
npx kontext init
|
|
240
|
-
# Wizard asks: project name, agent ID, wallets to monitor, tokens, chains, mode
|
|
241
|
-
# Creates kontext.config.json
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
```typescript
|
|
245
|
-
import { Kontext, withKontextCompliance } from 'kontext-sdk';
|
|
246
|
-
import { createWalletClient, http } from 'viem';
|
|
247
|
-
import { base } from 'viem/chains';
|
|
59
|
+
## What's verified
|
|
248
60
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
)
|
|
254
|
-
|
|
255
|
-
// Every USDC/USDT/DAI/EURC transfer now auto-logged with compliance proof
|
|
256
|
-
await client.sendTransaction({ to: USDC_ADDRESS, data: transferCalldata });
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
**Two interception layers:**
|
|
260
|
-
- **Code wrap:** `withKontextCompliance()` intercepts `sendTransaction`/`writeContract` calls. Can block pre-send if non-compliant.
|
|
261
|
-
- **Chain listener:** SDK watches monitored wallet addresses on-chain for ERC-20 Transfer events — catches ALL outgoing stablecoin transfers regardless of origin.
|
|
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
|
|
262
67
|
|
|
263
|
-
## Pluggable
|
|
68
|
+
## Pluggable screening
|
|
264
69
|
|
|
265
|
-
|
|
70
|
+
Bring your own providers or use the built-in OFAC list:
|
|
266
71
|
|
|
267
72
|
```typescript
|
|
268
|
-
import {
|
|
269
|
-
ScreeningAggregator,
|
|
270
|
-
OFACAddressProvider,
|
|
271
|
-
UKOFSIProvider,
|
|
272
|
-
OpenSanctionsProvider,
|
|
273
|
-
ChainalysisOracleProvider,
|
|
274
|
-
} from 'kontext-sdk';
|
|
73
|
+
import { ScreeningAggregator, OFACAddressProvider, OpenSanctionsProvider } from 'kontext-sdk';
|
|
275
74
|
|
|
276
75
|
const screener = new ScreeningAggregator({
|
|
277
76
|
providers: [
|
|
278
|
-
new OFACAddressProvider(),
|
|
279
|
-
new
|
|
280
|
-
new OpenSanctionsProvider({ apiKey: 'os_...' }), // 331+ sources
|
|
281
|
-
new ChainalysisOracleProvider({ apiKey: 'ch_...' }), // on-chain oracle
|
|
77
|
+
new OFACAddressProvider(), // built-in, free
|
|
78
|
+
new OpenSanctionsProvider({ apiKey: 'os_...' }), // 331+ sources
|
|
282
79
|
],
|
|
283
80
|
consensus: 'ANY_MATCH',
|
|
284
81
|
});
|
|
285
|
-
|
|
286
|
-
const result = await screener.screenAddress('0x...');
|
|
287
|
-
// result.flagged = true/false
|
|
288
|
-
// result.matches = [{ provider, list, matchType, confidence, ... }]
|
|
289
|
-
// result.providerResults = per-provider breakdown
|
|
290
82
|
```
|
|
291
83
|
|
|
292
|
-
|
|
293
|
-
**API providers:** OpenSanctions (address + entity), Chainalysis Oracle (address), Chainalysis Free API (address)
|
|
294
|
-
**Local providers:** OpenSanctions local dataset (download via `kontext sync`)
|
|
84
|
+
## Agent reasoning
|
|
295
85
|
|
|
296
|
-
|
|
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
|
+
```
|
|
297
94
|
|
|
298
|
-
|
|
299
|
-
|-----------|--------|---------|
|
|
300
|
-
| **EDD / Travel Rule** | $3,000 | Enhanced Due Diligence required |
|
|
301
|
-
| **CTR** | $10,000 | Currency Transaction Report |
|
|
302
|
-
| **Large TX Alert** | $50,000 | Large Transaction Alert |
|
|
95
|
+
## MCP server
|
|
303
96
|
|
|
304
|
-
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"mcpServers": {
|
|
100
|
+
"kontext": {
|
|
101
|
+
"command": "npx",
|
|
102
|
+
"args": ["-y", "@kontext-sdk/cli", "mcp"]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
305
107
|
|
|
306
|
-
##
|
|
108
|
+
## Zero runtime dependencies
|
|
307
109
|
|
|
308
|
-
|
|
309
|
-
- OFAC sanctions screening (SDN list, no API key)
|
|
310
|
-
- Pluggable multi-provider screening (OFAC, UK OFSI, OpenSanctions, Chainalysis)
|
|
311
|
-
- Compliance certificates with SHA-256 proof
|
|
312
|
-
- Agent reasoning logs
|
|
313
|
-
- Trust scoring and anomaly detection
|
|
314
|
-
- Agent provenance — session delegation, action binding, human attestation
|
|
315
|
-
- MCP server mode for AI coding tools
|
|
316
|
-
- Zero runtime dependencies
|
|
110
|
+
The SDK has no `dependencies`. Works in Node.js 18+, TypeScript 5.0+.
|
|
317
111
|
|
|
318
112
|
## License
|
|
319
113
|
|
|
@@ -321,6 +115,4 @@ MIT
|
|
|
321
115
|
|
|
322
116
|
---
|
|
323
117
|
|
|
324
|
-
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.
|
|
325
|
-
|
|
326
118
|
Built by [Legaci Labs](https://www.getkontext.com)
|