kontext-sdk 0.8.0 → 0.10.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 +119 -0
- package/dist/index.d.mts +2067 -215
- package/dist/index.d.ts +2067 -215
- package/dist/index.js +3900 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3866 -114
- package/dist/index.mjs.map +1 -1
- package/package.json +24 -3
package/README.md
CHANGED
|
@@ -161,6 +161,61 @@ const chain = ctx.verifyDigestChain();
|
|
|
161
161
|
console.log(chain.valid); // true — no tampering
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
+
### Agent Provenance
|
|
165
|
+
|
|
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
|
+
const result = await ctx.verify({
|
|
179
|
+
txHash: '0xabc...',
|
|
180
|
+
chain: 'base',
|
|
181
|
+
amount: '5000',
|
|
182
|
+
token: 'USDC',
|
|
183
|
+
from: '0xAgent...',
|
|
184
|
+
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,
|
|
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
|
+
|
|
164
219
|
### Persist Across Restarts
|
|
165
220
|
|
|
166
221
|
```typescript
|
|
@@ -176,6 +231,68 @@ const ctx = Kontext.init({
|
|
|
176
231
|
// Call ctx.flush() to write, ctx.restore() to reload
|
|
177
232
|
```
|
|
178
233
|
|
|
234
|
+
## Auto-Instrumentation (viem)
|
|
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';
|
|
248
|
+
|
|
249
|
+
const kontext = Kontext.init(); // reads kontext.config.json
|
|
250
|
+
const client = withKontextCompliance(
|
|
251
|
+
createWalletClient({ chain: base, transport: http() }),
|
|
252
|
+
kontext,
|
|
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.
|
|
262
|
+
|
|
263
|
+
## Pluggable Sanctions Screening
|
|
264
|
+
|
|
265
|
+
Multi-provider screening with consensus strategies. Bring your own API keys, or use the built-in OFAC SDN list at zero cost.
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import {
|
|
269
|
+
ScreeningAggregator,
|
|
270
|
+
OFACAddressProvider,
|
|
271
|
+
UKOFSIProvider,
|
|
272
|
+
OpenSanctionsProvider,
|
|
273
|
+
ChainalysisOracleProvider,
|
|
274
|
+
} from 'kontext-sdk';
|
|
275
|
+
|
|
276
|
+
const screener = new ScreeningAggregator({
|
|
277
|
+
providers: [
|
|
278
|
+
new OFACAddressProvider(), // built-in, no API key
|
|
279
|
+
new UKOFSIProvider(), // built-in, no API key
|
|
280
|
+
new OpenSanctionsProvider({ apiKey: 'os_...' }), // 331+ sources
|
|
281
|
+
new ChainalysisOracleProvider({ apiKey: 'ch_...' }), // on-chain oracle
|
|
282
|
+
],
|
|
283
|
+
consensus: 'ANY_MATCH',
|
|
284
|
+
});
|
|
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
|
+
```
|
|
291
|
+
|
|
292
|
+
**Built-in providers (no API key):** OFAC SDN addresses, UK OFSI addresses
|
|
293
|
+
**API providers:** OpenSanctions (address + entity), Chainalysis Oracle (address), Chainalysis Free API (address)
|
|
294
|
+
**Local providers:** OpenSanctions local dataset (download via `kontext sync`)
|
|
295
|
+
|
|
179
296
|
## Compliance Thresholds
|
|
180
297
|
|
|
181
298
|
| Threshold | Amount | Trigger |
|
|
@@ -190,9 +307,11 @@ OFAC sanctions screening uses the built-in SDN list. No API key required.
|
|
|
190
307
|
|
|
191
308
|
- Tamper-evident audit trail (patented digest chain)
|
|
192
309
|
- OFAC sanctions screening (SDN list, no API key)
|
|
310
|
+
- Pluggable multi-provider screening (OFAC, UK OFSI, OpenSanctions, Chainalysis)
|
|
193
311
|
- Compliance certificates with SHA-256 proof
|
|
194
312
|
- Agent reasoning logs
|
|
195
313
|
- Trust scoring and anomaly detection
|
|
314
|
+
- Agent provenance — session delegation, action binding, human attestation
|
|
196
315
|
- MCP server mode for AI coding tools
|
|
197
316
|
- Zero runtime dependencies
|
|
198
317
|
|