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/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
+
/** What kind of queries a provider can handle */
|
|
2
|
+
type QueryType = 'address' | 'entity_name' | 'both';
|
|
3
|
+
/** Jurisdictions for sanctions list mapping */
|
|
4
|
+
type Jurisdiction = 'US' | 'EU' | 'UK' | 'UN' | 'UAE' | 'SG' | 'HK' | 'IN' | 'KR' | 'MY' | 'TH' | 'NZ' | 'CN' | 'GLOBAL';
|
|
5
|
+
/** Known sanctions lists */
|
|
6
|
+
type SanctionsList = 'OFAC_SDN' | 'OFAC_NON_SDN' | 'EU_CONSOLIDATED' | 'UN_SECURITY_COUNCIL' | 'UK_OFSI' | 'UAE_LOCAL' | 'MAS_TFS' | 'HK_UNSO' | 'INDIA_DOMESTIC' | 'KOFIU_DOMESTIC' | 'BNM_DOMESTIC' | 'AMLO_DOMESTIC' | 'NZ_DESIGNATED' | 'OPENSANCTIONS' | 'CHAINALYSIS' | 'CUSTOM';
|
|
7
|
+
/** How a match was determined */
|
|
8
|
+
type MatchType = 'exact_address' | 'fuzzy_name' | 'alias_match' | 'associated' | 'partial';
|
|
9
|
+
/** Entity sanctioning status */
|
|
10
|
+
type EntityStatus = 'active' | 'delisted';
|
|
11
|
+
/** Context passed to providers for jurisdiction-aware routing */
|
|
12
|
+
interface ScreeningContext {
|
|
13
|
+
token?: Token | string;
|
|
14
|
+
currency?: string;
|
|
15
|
+
amount?: string;
|
|
16
|
+
chain?: Chain | string;
|
|
17
|
+
agentId?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/** A single match from a screening provider */
|
|
21
|
+
interface ScreeningMatch {
|
|
22
|
+
list: SanctionsList;
|
|
23
|
+
matchType: MatchType;
|
|
24
|
+
similarity: number;
|
|
25
|
+
matchedValue: string;
|
|
26
|
+
entityStatus: EntityStatus;
|
|
27
|
+
entityName?: string;
|
|
28
|
+
program?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Result from a single screening provider */
|
|
31
|
+
interface ScreeningResult {
|
|
32
|
+
providerId: string;
|
|
33
|
+
hit: boolean;
|
|
34
|
+
matches: ScreeningMatch[];
|
|
35
|
+
listsChecked: readonly SanctionsList[];
|
|
36
|
+
entriesSearched: number;
|
|
37
|
+
durationMs: number;
|
|
38
|
+
error?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pluggable screening provider interface.
|
|
42
|
+
*
|
|
43
|
+
* Providers declare what query types they support via `queryTypes`.
|
|
44
|
+
* The ScreeningAggregator uses this to route queries: addresses go
|
|
45
|
+
* to `'address'` or `'both'` providers; entity names go to
|
|
46
|
+
* `'entity_name'` or `'both'` providers.
|
|
47
|
+
*/
|
|
48
|
+
interface ScreeningProvider {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly lists: readonly SanctionsList[];
|
|
52
|
+
readonly requiresApiKey: boolean;
|
|
53
|
+
readonly browserCompatible: boolean;
|
|
54
|
+
readonly queryTypes: readonly QueryType[];
|
|
55
|
+
/** Screen an address or entity name */
|
|
56
|
+
screen(query: string, context?: ScreeningContext): Promise<ScreeningResult>;
|
|
57
|
+
/** Whether this provider is currently available */
|
|
58
|
+
isAvailable(): boolean;
|
|
59
|
+
/** Sync local data (optional — only for providers with local cache) */
|
|
60
|
+
sync?(): Promise<{
|
|
61
|
+
updated: boolean;
|
|
62
|
+
count: number;
|
|
63
|
+
}>;
|
|
64
|
+
/** Number of entries in the provider's dataset (optional) */
|
|
65
|
+
getEntryCount?(): number;
|
|
66
|
+
}
|
|
67
|
+
/** Check if a query string is a blockchain address */
|
|
68
|
+
declare function isBlockchainAddress(query: string): boolean;
|
|
69
|
+
/** Check if a provider supports the detected query type */
|
|
70
|
+
declare function providerSupportsQuery(provider: ScreeningProvider, query: string): boolean;
|
|
71
|
+
/** Required sanctions lists by crypto token */
|
|
72
|
+
declare const TOKEN_REQUIRED_LISTS: Record<string, readonly SanctionsList[]>;
|
|
73
|
+
/** Required sanctions lists by fiat currency */
|
|
74
|
+
declare const CURRENCY_REQUIRED_LISTS: Record<string, readonly SanctionsList[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Get the required sanctions lists for a given screening context.
|
|
77
|
+
* Token takes precedence over currency when both are provided.
|
|
78
|
+
*/
|
|
79
|
+
declare function getRequiredLists(context?: ScreeningContext): readonly SanctionsList[];
|
|
80
|
+
|
|
1
81
|
/**
|
|
2
82
|
* Result of an export operation.
|
|
3
83
|
*/
|
|
@@ -324,6 +404,101 @@ interface KontextConfig {
|
|
|
324
404
|
* ```
|
|
325
405
|
*/
|
|
326
406
|
approvalThreshold?: string;
|
|
407
|
+
/**
|
|
408
|
+
* Pluggable sanctions screening configuration. When provided, verify()
|
|
409
|
+
* uses the ScreeningAggregator instead of the built-in UsdcCompliance /
|
|
410
|
+
* PaymentCompliance code paths.
|
|
411
|
+
*
|
|
412
|
+
* Free tier — no plan gating. Each screen() call counts as 1 event.
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* import { Kontext, OFACAddressProvider, UKOFSIProvider } from 'kontext-sdk';
|
|
417
|
+
*
|
|
418
|
+
* const ctx = Kontext.init({
|
|
419
|
+
* projectId: 'my-app',
|
|
420
|
+
* environment: 'production',
|
|
421
|
+
* screening: {
|
|
422
|
+
* providers: [new OFACAddressProvider(), new UKOFSIProvider()],
|
|
423
|
+
* consensus: 'ANY_MATCH',
|
|
424
|
+
* },
|
|
425
|
+
* });
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
screening?: ScreeningConfig;
|
|
429
|
+
/**
|
|
430
|
+
* Compliance policy configuration. Customizes thresholds, allowed
|
|
431
|
+
* tokens/currencies, and blocked corridors.
|
|
432
|
+
*
|
|
433
|
+
* All fields optional — defaults match current behavior ($3K EDD,
|
|
434
|
+
* $10K CTR, $50K large transaction).
|
|
435
|
+
*/
|
|
436
|
+
policy?: PolicyConfig;
|
|
437
|
+
/**
|
|
438
|
+
* Default agent ID for verify/log calls when not specified per-call.
|
|
439
|
+
* Set automatically when loading from kontext.config.json.
|
|
440
|
+
*/
|
|
441
|
+
agentId?: string;
|
|
442
|
+
/**
|
|
443
|
+
* Wallet monitoring configuration. When provided, SDK watches these
|
|
444
|
+
* addresses on-chain for stablecoin transfers and auto-calls verify().
|
|
445
|
+
* Requires viem as a peer dependency.
|
|
446
|
+
*/
|
|
447
|
+
walletMonitoring?: WalletMonitoringConfig;
|
|
448
|
+
/**
|
|
449
|
+
* Viem interceptor mode for withKontextCompliance() (default: 'post-send').
|
|
450
|
+
* - 'post-send': verify() runs after tx succeeds, never blocks
|
|
451
|
+
* - 'pre-send': verify() runs before tx, throws if non-compliant
|
|
452
|
+
* - 'both': pre-send screening + post-send full verify
|
|
453
|
+
*/
|
|
454
|
+
interceptorMode?: 'post-send' | 'pre-send' | 'both';
|
|
455
|
+
}
|
|
456
|
+
/** Screening configuration for pluggable multi-provider sanctions screening */
|
|
457
|
+
interface ScreeningConfig {
|
|
458
|
+
/** Screening providers to use */
|
|
459
|
+
providers: ScreeningProvider[];
|
|
460
|
+
/** How to combine results from multiple providers (default: 'ANY_MATCH') */
|
|
461
|
+
consensus?: 'ANY_MATCH' | 'ALL_MATCH' | 'MAJORITY';
|
|
462
|
+
/** Addresses or entity names to always block */
|
|
463
|
+
blocklist?: string[];
|
|
464
|
+
/** Addresses or entity names to always allow (overrides provider hits) */
|
|
465
|
+
allowlist?: string[];
|
|
466
|
+
/** Per-provider timeout in milliseconds (default: 5000) */
|
|
467
|
+
providerTimeoutMs?: number;
|
|
468
|
+
}
|
|
469
|
+
/** Compliance policy configuration */
|
|
470
|
+
interface PolicyConfig {
|
|
471
|
+
/** Customizable compliance thresholds */
|
|
472
|
+
thresholds?: {
|
|
473
|
+
/** Enhanced Due Diligence threshold (default: 3000) */
|
|
474
|
+
edd?: number;
|
|
475
|
+
/** CTR reporting threshold (default: 10000) */
|
|
476
|
+
reporting?: number;
|
|
477
|
+
/** Large transaction threshold (default: 50000) */
|
|
478
|
+
largeTransaction?: number;
|
|
479
|
+
};
|
|
480
|
+
/** Restrict to specific tokens */
|
|
481
|
+
allowedTokens?: Token[];
|
|
482
|
+
/** Restrict to specific currencies */
|
|
483
|
+
allowedCurrencies?: string[];
|
|
484
|
+
/** Blocked jurisdiction pairs */
|
|
485
|
+
corridors?: {
|
|
486
|
+
blocked?: Array<{
|
|
487
|
+
from: string;
|
|
488
|
+
to: string;
|
|
489
|
+
}>;
|
|
490
|
+
};
|
|
491
|
+
/** When true, refuse verify() if no screening provider is configured (default: false) */
|
|
492
|
+
requireScreening?: boolean;
|
|
493
|
+
}
|
|
494
|
+
/** Wallet monitoring configuration for on-chain event listening */
|
|
495
|
+
interface WalletMonitoringConfig {
|
|
496
|
+
/** Wallet addresses to watch for outgoing stablecoin transfers */
|
|
497
|
+
wallets: string[];
|
|
498
|
+
/** RPC endpoints per chain (required for on-chain listening) */
|
|
499
|
+
rpcEndpoints: Partial<Record<Chain, string>>;
|
|
500
|
+
/** Polling interval in ms for HTTP transports (default: 12000) */
|
|
501
|
+
pollingIntervalMs?: number;
|
|
327
502
|
}
|
|
328
503
|
/**
|
|
329
504
|
* Interface for metadata validation. Compatible with Zod schemas and any
|
|
@@ -765,6 +940,12 @@ interface VerifyInput extends LogTransactionInput {
|
|
|
765
940
|
confidence?: number;
|
|
766
941
|
/** Additional reasoning context */
|
|
767
942
|
context?: Record<string, unknown>;
|
|
943
|
+
/** When provided, anchors the terminal digest on-chain after compliance checks */
|
|
944
|
+
anchor?: OnChainAnchorConfig;
|
|
945
|
+
/** Counterparty agent for bilateral A2A attestation exchange */
|
|
946
|
+
counterparty?: CounterpartyConfig;
|
|
947
|
+
/** ERC-8021 config: fetch and parse builder attribution from transaction calldata */
|
|
948
|
+
erc8021?: ERC8021Config;
|
|
768
949
|
}
|
|
769
950
|
/** Result of the verify() convenience method */
|
|
770
951
|
interface VerifyResult {
|
|
@@ -790,10 +971,16 @@ interface VerifyResult {
|
|
|
790
971
|
};
|
|
791
972
|
/** Reasoning entry ID (present when reasoning was provided in input) */
|
|
792
973
|
reasoningId?: string;
|
|
974
|
+
/** On-chain anchor proof (present when anchor config provided in input) */
|
|
975
|
+
anchorProof?: AnchorResult;
|
|
976
|
+
/** Counterparty attestation (present when counterparty config provided in input) */
|
|
977
|
+
counterparty?: CounterpartyAttestation;
|
|
793
978
|
/** True when the transaction amount exceeds the approvalThreshold */
|
|
794
979
|
requiresApproval?: boolean;
|
|
795
980
|
/** The pending approval task (present when requiresApproval is true) */
|
|
796
981
|
task?: Task;
|
|
982
|
+
/** ERC-8021 builder attribution (present when erc8021 config provided and tx has attribution) */
|
|
983
|
+
attribution?: ERC8021Attribution;
|
|
797
984
|
}
|
|
798
985
|
/**
|
|
799
986
|
* Input for logging an agent's reasoning/decision step.
|
|
@@ -852,6 +1039,307 @@ interface ReasoningEntry {
|
|
|
852
1039
|
/** Context */
|
|
853
1040
|
context: Record<string, unknown>;
|
|
854
1041
|
}
|
|
1042
|
+
/** Configuration for on-chain digest anchoring */
|
|
1043
|
+
interface OnChainAnchorConfig {
|
|
1044
|
+
/** JSON-RPC URL for the target chain */
|
|
1045
|
+
rpcUrl: string;
|
|
1046
|
+
/** KontextAnchor contract address */
|
|
1047
|
+
contractAddress: string;
|
|
1048
|
+
/** Private key of the signer (hex with 0x prefix). Required for write operations. */
|
|
1049
|
+
privateKey?: string;
|
|
1050
|
+
/** ERC-8021 builder code for transaction attribution (default: 'kontext') */
|
|
1051
|
+
builderCode?: string;
|
|
1052
|
+
}
|
|
1053
|
+
/** Result of an on-chain anchor transaction */
|
|
1054
|
+
interface AnchorResult {
|
|
1055
|
+
/** The digest that was anchored */
|
|
1056
|
+
digest: string;
|
|
1057
|
+
/** The on-chain transaction hash */
|
|
1058
|
+
txHash: string;
|
|
1059
|
+
/** The block number containing the anchor */
|
|
1060
|
+
blockNumber: number;
|
|
1061
|
+
/** Block timestamp (unix seconds) */
|
|
1062
|
+
timestamp: number;
|
|
1063
|
+
/** Contract address used */
|
|
1064
|
+
contractAddress: string;
|
|
1065
|
+
/** Chain the anchor was submitted to */
|
|
1066
|
+
chain: string;
|
|
1067
|
+
}
|
|
1068
|
+
/** Result of verifying an anchor on-chain */
|
|
1069
|
+
interface AnchorVerification {
|
|
1070
|
+
/** Whether the digest was found on-chain */
|
|
1071
|
+
anchored: boolean;
|
|
1072
|
+
/** The digest that was checked */
|
|
1073
|
+
digest: string;
|
|
1074
|
+
/** Anchorer address (if anchored) */
|
|
1075
|
+
anchorer?: string;
|
|
1076
|
+
/** Project hash (if anchored) */
|
|
1077
|
+
projectHash?: string;
|
|
1078
|
+
/** Block timestamp (if anchored) */
|
|
1079
|
+
timestamp?: number;
|
|
1080
|
+
}
|
|
1081
|
+
/** ERC-8021 transaction attribution data parsed from calldata suffix */
|
|
1082
|
+
interface ERC8021Attribution {
|
|
1083
|
+
/** Builder/entity codes extracted from the calldata suffix */
|
|
1084
|
+
codes: string[];
|
|
1085
|
+
/** Schema ID (0 = canonical code registry) */
|
|
1086
|
+
schemaId: number;
|
|
1087
|
+
/** Raw suffix hex (with 0x prefix) */
|
|
1088
|
+
rawSuffix: string;
|
|
1089
|
+
}
|
|
1090
|
+
/** ERC-8021 configuration for verify() */
|
|
1091
|
+
interface ERC8021Config {
|
|
1092
|
+
/** JSON-RPC URL for fetching transaction calldata */
|
|
1093
|
+
rpcUrl: string;
|
|
1094
|
+
/** Registry contract address for resolving codes to payout addresses (future use) */
|
|
1095
|
+
registryAddress?: string;
|
|
1096
|
+
}
|
|
1097
|
+
/** Agent card served at /.well-known/kontext.json */
|
|
1098
|
+
interface AgentCard {
|
|
1099
|
+
/** Agent identifier */
|
|
1100
|
+
agentId: string;
|
|
1101
|
+
/** Kontext SDK version */
|
|
1102
|
+
kontextVersion: string;
|
|
1103
|
+
/** Supported capabilities (e.g., ['verify', 'attest']) */
|
|
1104
|
+
capabilities: string[];
|
|
1105
|
+
/** Attestation endpoint path (relative to host) */
|
|
1106
|
+
attestEndpoint: string;
|
|
1107
|
+
}
|
|
1108
|
+
/** Counterparty configuration for verify() */
|
|
1109
|
+
interface CounterpartyConfig {
|
|
1110
|
+
/** Base URL of the counterparty agent (e.g., https://agent.example.com) */
|
|
1111
|
+
endpoint: string;
|
|
1112
|
+
/** Expected agent ID (optional, verified against agent card) */
|
|
1113
|
+
agentId?: string;
|
|
1114
|
+
/** Timeout for attestation exchange in milliseconds (default: 10000) */
|
|
1115
|
+
timeoutMs?: number;
|
|
1116
|
+
}
|
|
1117
|
+
/** Attestation request sent to counterparty */
|
|
1118
|
+
interface AttestationRequest {
|
|
1119
|
+
/** Sender's terminal digest */
|
|
1120
|
+
senderDigest: string;
|
|
1121
|
+
/** Sender's agent ID */
|
|
1122
|
+
senderAgentId: string;
|
|
1123
|
+
/** Transaction hash */
|
|
1124
|
+
txHash?: string;
|
|
1125
|
+
/** Chain */
|
|
1126
|
+
chain?: string;
|
|
1127
|
+
/** Transfer amount */
|
|
1128
|
+
amount: string;
|
|
1129
|
+
/** Token */
|
|
1130
|
+
token?: string;
|
|
1131
|
+
/** Timestamp of the request */
|
|
1132
|
+
timestamp: string;
|
|
1133
|
+
}
|
|
1134
|
+
/** Attestation response from counterparty */
|
|
1135
|
+
interface AttestationResponse {
|
|
1136
|
+
/** Whether the counterparty attested */
|
|
1137
|
+
attested: boolean;
|
|
1138
|
+
/** Counterparty's terminal digest */
|
|
1139
|
+
receiverDigest: string;
|
|
1140
|
+
/** Counterparty's agent ID */
|
|
1141
|
+
receiverAgentId: string;
|
|
1142
|
+
/** Timestamp of attestation */
|
|
1143
|
+
timestamp: string;
|
|
1144
|
+
}
|
|
1145
|
+
/** Counterparty attestation result included in VerifyResult */
|
|
1146
|
+
interface CounterpartyAttestation {
|
|
1147
|
+
/** Whether the counterparty successfully attested */
|
|
1148
|
+
attested: boolean;
|
|
1149
|
+
/** Counterparty's digest (proof they ran compliance) */
|
|
1150
|
+
digest: string;
|
|
1151
|
+
/** Counterparty's agent ID */
|
|
1152
|
+
agentId: string;
|
|
1153
|
+
/** Attestation timestamp */
|
|
1154
|
+
timestamp: string;
|
|
1155
|
+
}
|
|
1156
|
+
/** Session status */
|
|
1157
|
+
type SessionStatus = 'active' | 'ended' | 'expired';
|
|
1158
|
+
/** Checkpoint status */
|
|
1159
|
+
type CheckpointStatus = 'pending' | 'attested' | 'rejected' | 'expired';
|
|
1160
|
+
/** Attestation decision */
|
|
1161
|
+
type AttestationDecision = 'approved' | 'rejected';
|
|
1162
|
+
/** Constraints on what an agent session is authorized to do */
|
|
1163
|
+
interface SessionConstraints {
|
|
1164
|
+
/** Maximum single transaction amount */
|
|
1165
|
+
maxAmount?: string;
|
|
1166
|
+
/** Allowed blockchain networks */
|
|
1167
|
+
allowedChains?: Chain[];
|
|
1168
|
+
/** Allowed tokens */
|
|
1169
|
+
allowedTokens?: Token[];
|
|
1170
|
+
/** Allowed recipient addresses (normalized to lowercase) */
|
|
1171
|
+
allowedRecipients?: string[];
|
|
1172
|
+
}
|
|
1173
|
+
/** Input for creating a delegated agent session */
|
|
1174
|
+
interface CreateSessionInput {
|
|
1175
|
+
/** Agent being delegated authority */
|
|
1176
|
+
agentId: string;
|
|
1177
|
+
/** Human principal who authorized this session */
|
|
1178
|
+
delegatedBy: string;
|
|
1179
|
+
/** Scoped capabilities (e.g., ['transfer', 'approve', 'query']) */
|
|
1180
|
+
scope: string[];
|
|
1181
|
+
/** Optional constraints on the session */
|
|
1182
|
+
constraints?: SessionConstraints;
|
|
1183
|
+
/** Session TTL in milliseconds (default: no expiry) */
|
|
1184
|
+
expiresIn?: number;
|
|
1185
|
+
/** Arbitrary metadata */
|
|
1186
|
+
metadata?: Record<string, unknown>;
|
|
1187
|
+
}
|
|
1188
|
+
/** A delegated agent session with provenance data */
|
|
1189
|
+
interface AgentSession {
|
|
1190
|
+
/** Unique session identifier */
|
|
1191
|
+
sessionId: string;
|
|
1192
|
+
/** Agent ID */
|
|
1193
|
+
agentId: string;
|
|
1194
|
+
/** Human who delegated authority */
|
|
1195
|
+
delegatedBy: string;
|
|
1196
|
+
/** Authorized scope */
|
|
1197
|
+
scope: string[];
|
|
1198
|
+
/** Session constraints */
|
|
1199
|
+
constraints?: SessionConstraints;
|
|
1200
|
+
/** Session status */
|
|
1201
|
+
status: SessionStatus;
|
|
1202
|
+
/** Creation timestamp */
|
|
1203
|
+
createdAt: string;
|
|
1204
|
+
/** End timestamp (when explicitly ended) */
|
|
1205
|
+
endedAt?: string;
|
|
1206
|
+
/** Expiry timestamp */
|
|
1207
|
+
expiresAt?: string;
|
|
1208
|
+
/** Digest from the chain link that recorded session creation */
|
|
1209
|
+
digest?: string;
|
|
1210
|
+
/** Prior digest in the chain */
|
|
1211
|
+
priorDigest?: string;
|
|
1212
|
+
/** Arbitrary metadata */
|
|
1213
|
+
metadata: Record<string, unknown>;
|
|
1214
|
+
}
|
|
1215
|
+
/** Interface for external attestation providers (developer implements) */
|
|
1216
|
+
interface ProvenanceAttestor {
|
|
1217
|
+
/** Sign an attestation payload */
|
|
1218
|
+
sign(payload: AttestationPayload): Promise<AttestationSignature>;
|
|
1219
|
+
/** Get the verification key for signature checking */
|
|
1220
|
+
getVerificationKey(): Promise<VerificationKey>;
|
|
1221
|
+
}
|
|
1222
|
+
/** Payload presented to an attestor for signing */
|
|
1223
|
+
interface AttestationPayload {
|
|
1224
|
+
/** Checkpoint ID */
|
|
1225
|
+
checkpointId: string;
|
|
1226
|
+
/** SHA-256 of concatenated action digests */
|
|
1227
|
+
actionsDigest: string;
|
|
1228
|
+
/** Session this checkpoint belongs to */
|
|
1229
|
+
sessionId: string;
|
|
1230
|
+
/** Timestamp of checkpoint creation */
|
|
1231
|
+
timestamp: string;
|
|
1232
|
+
}
|
|
1233
|
+
/** Cryptographic signature from an attestor */
|
|
1234
|
+
interface AttestationSignature {
|
|
1235
|
+
/** The signature bytes (hex or base64) */
|
|
1236
|
+
signature: string;
|
|
1237
|
+
/** Algorithm used (e.g., 'ES256', 'Ed25519', 'RS256') */
|
|
1238
|
+
algorithm: string;
|
|
1239
|
+
/** Optional key identifier */
|
|
1240
|
+
keyId?: string;
|
|
1241
|
+
}
|
|
1242
|
+
/** Public verification key for checking attestation signatures */
|
|
1243
|
+
interface VerificationKey {
|
|
1244
|
+
/** Public key (PEM, JWK string, or hex) */
|
|
1245
|
+
publicKey: string;
|
|
1246
|
+
/** Algorithm */
|
|
1247
|
+
algorithm: string;
|
|
1248
|
+
/** Optional key identifier */
|
|
1249
|
+
keyId?: string;
|
|
1250
|
+
}
|
|
1251
|
+
/** A human attestation attached to a checkpoint */
|
|
1252
|
+
interface HumanAttestation {
|
|
1253
|
+
/** Unique attestation identifier */
|
|
1254
|
+
attestationId: string;
|
|
1255
|
+
/** Checkpoint this attestation covers */
|
|
1256
|
+
checkpointId: string;
|
|
1257
|
+
/** Human reviewer identifier */
|
|
1258
|
+
reviewerId: string;
|
|
1259
|
+
/** Decision */
|
|
1260
|
+
decision: AttestationDecision;
|
|
1261
|
+
/** Optional evidence or notes from the reviewer */
|
|
1262
|
+
evidence?: string;
|
|
1263
|
+
/** Cryptographic signature */
|
|
1264
|
+
signature: AttestationSignature;
|
|
1265
|
+
/** Verification key for the signature */
|
|
1266
|
+
verificationKey: VerificationKey;
|
|
1267
|
+
/** Attestation timestamp */
|
|
1268
|
+
timestamp: string;
|
|
1269
|
+
}
|
|
1270
|
+
/** Input for creating a provenance checkpoint */
|
|
1271
|
+
interface CreateCheckpointInput {
|
|
1272
|
+
/** Session this checkpoint belongs to */
|
|
1273
|
+
sessionId: string;
|
|
1274
|
+
/** Action IDs to include in this checkpoint */
|
|
1275
|
+
actionIds: string[];
|
|
1276
|
+
/** Human-readable summary of what the agent did */
|
|
1277
|
+
summary: string;
|
|
1278
|
+
/** Checkpoint TTL in milliseconds (default: no expiry) */
|
|
1279
|
+
expiresIn?: number;
|
|
1280
|
+
}
|
|
1281
|
+
/** A provenance checkpoint -- a review point in the action stream */
|
|
1282
|
+
interface ProvenanceCheckpoint {
|
|
1283
|
+
/** Unique checkpoint identifier */
|
|
1284
|
+
id: string;
|
|
1285
|
+
/** Session this checkpoint belongs to */
|
|
1286
|
+
sessionId: string;
|
|
1287
|
+
/** Action IDs covered by this checkpoint */
|
|
1288
|
+
actionIds: string[];
|
|
1289
|
+
/** Human-readable summary */
|
|
1290
|
+
summary: string;
|
|
1291
|
+
/** SHA-256 of concatenated action digests (proves which actions were reviewed) */
|
|
1292
|
+
actionsDigest: string;
|
|
1293
|
+
/** Checkpoint status */
|
|
1294
|
+
status: CheckpointStatus;
|
|
1295
|
+
/** Attached human attestation (present after attestation) */
|
|
1296
|
+
attestation?: HumanAttestation;
|
|
1297
|
+
/** Creation timestamp */
|
|
1298
|
+
createdAt: string;
|
|
1299
|
+
/** Expiry timestamp */
|
|
1300
|
+
expiresAt?: string;
|
|
1301
|
+
}
|
|
1302
|
+
/** A provenance action with session binding */
|
|
1303
|
+
interface ProvenanceAction {
|
|
1304
|
+
/** Action ID */
|
|
1305
|
+
actionId: string;
|
|
1306
|
+
/** Action type */
|
|
1307
|
+
type: string;
|
|
1308
|
+
/** Digest from the chain */
|
|
1309
|
+
digest: string;
|
|
1310
|
+
/** Prior digest */
|
|
1311
|
+
priorDigest: string;
|
|
1312
|
+
/** Session this action is bound to */
|
|
1313
|
+
sessionId: string;
|
|
1314
|
+
/** Action timestamp */
|
|
1315
|
+
timestamp: string;
|
|
1316
|
+
}
|
|
1317
|
+
/** Verification summary for a provenance bundle */
|
|
1318
|
+
interface ProvenanceBundleVerification {
|
|
1319
|
+
/** Whether the digest chain covering these actions is valid */
|
|
1320
|
+
digestChainValid: boolean;
|
|
1321
|
+
/** Total actions in the session */
|
|
1322
|
+
totalActions: number;
|
|
1323
|
+
/** Actions covered by an approved human attestation */
|
|
1324
|
+
humanAttested: number;
|
|
1325
|
+
/** Actions bound to the session */
|
|
1326
|
+
sessionScoped: number;
|
|
1327
|
+
/** Actions not yet covered by any checkpoint */
|
|
1328
|
+
unattested: number;
|
|
1329
|
+
}
|
|
1330
|
+
/** Complete provenance export for a session */
|
|
1331
|
+
interface ProvenanceBundle {
|
|
1332
|
+
/** The session record */
|
|
1333
|
+
session: AgentSession;
|
|
1334
|
+
/** All actions bound to this session */
|
|
1335
|
+
actions: ProvenanceAction[];
|
|
1336
|
+
/** All checkpoints for this session */
|
|
1337
|
+
checkpoints: ProvenanceCheckpoint[];
|
|
1338
|
+
/** Verification summary */
|
|
1339
|
+
verification: ProvenanceBundleVerification;
|
|
1340
|
+
/** Export timestamp */
|
|
1341
|
+
generatedAt: string;
|
|
1342
|
+
}
|
|
855
1343
|
/** Error codes for Kontext SDK */
|
|
856
1344
|
declare enum KontextErrorCode {
|
|
857
1345
|
INITIALIZATION_ERROR = "INITIALIZATION_ERROR",
|
|
@@ -1063,7 +1551,7 @@ interface PlanUsage {
|
|
|
1063
1551
|
seats: number;
|
|
1064
1552
|
/** Number of events logged in the current billing period */
|
|
1065
1553
|
eventCount: number;
|
|
1066
|
-
/** Maximum events allowed
|
|
1554
|
+
/** Maximum events allowed */
|
|
1067
1555
|
limit: number;
|
|
1068
1556
|
/** Remaining events before limit */
|
|
1069
1557
|
remainingEvents: number;
|
|
@@ -1252,123 +1740,768 @@ declare class FeatureFlagManager {
|
|
|
1252
1740
|
private triggerBackgroundRefresh;
|
|
1253
1741
|
}
|
|
1254
1742
|
|
|
1743
|
+
/** Minimal Kontext interface needed by the monitor */
|
|
1744
|
+
interface KontextForMonitor {
|
|
1745
|
+
verify(input: VerifyInput): Promise<VerifyResult>;
|
|
1746
|
+
}
|
|
1255
1747
|
/**
|
|
1256
|
-
*
|
|
1257
|
-
*
|
|
1258
|
-
* anomaly detection.
|
|
1259
|
-
*
|
|
1260
|
-
* Supports two operating modes:
|
|
1261
|
-
* - **Local mode** (no API key): All data stored locally, suitable for
|
|
1262
|
-
* open-source usage and development.
|
|
1263
|
-
* - **Cloud mode** (with API key): Data synced to Kontext API for
|
|
1264
|
-
* persistent storage and advanced features.
|
|
1265
|
-
*
|
|
1266
|
-
* @example
|
|
1267
|
-
* ```typescript
|
|
1268
|
-
* import { Kontext } from '@kontext/sdk';
|
|
1269
|
-
*
|
|
1270
|
-
* const kontext = Kontext.init({
|
|
1271
|
-
* projectId: 'my-project',
|
|
1272
|
-
* environment: 'development',
|
|
1273
|
-
* });
|
|
1274
|
-
*
|
|
1275
|
-
* await kontext.logTransaction({
|
|
1276
|
-
* txHash: '0x...',
|
|
1277
|
-
* chain: 'base',
|
|
1278
|
-
* amount: '100',
|
|
1279
|
-
* token: 'USDC',
|
|
1280
|
-
* from: '0xSender',
|
|
1281
|
-
* to: '0xReceiver',
|
|
1282
|
-
* agentId: 'agent-1',
|
|
1283
|
-
* });
|
|
1284
|
-
* ```
|
|
1748
|
+
* Watches monitored wallets on-chain for stablecoin Transfer events.
|
|
1749
|
+
* Uses viem's watchEvent with HTTP polling (works with any RPC endpoint).
|
|
1285
1750
|
*/
|
|
1286
|
-
declare class
|
|
1751
|
+
declare class WalletMonitor {
|
|
1752
|
+
private readonly kontext;
|
|
1287
1753
|
private readonly config;
|
|
1288
|
-
private readonly
|
|
1289
|
-
private readonly
|
|
1290
|
-
private readonly
|
|
1291
|
-
private
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
private
|
|
1295
|
-
private readonly
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1754
|
+
private readonly agentId;
|
|
1755
|
+
private readonly tokens;
|
|
1756
|
+
private readonly unwatchers;
|
|
1757
|
+
private running;
|
|
1758
|
+
/** Shared dedup set — tracks recently verified txHashes (populated by both layers) */
|
|
1759
|
+
readonly verifiedTxHashes: Set<string>;
|
|
1760
|
+
private cleanupTimer;
|
|
1761
|
+
private readonly txTimestamps;
|
|
1762
|
+
constructor(kontext: KontextForMonitor, config: WalletMonitoringConfig, options?: {
|
|
1763
|
+
agentId?: string;
|
|
1764
|
+
tokens?: Token[];
|
|
1765
|
+
});
|
|
1299
1766
|
/**
|
|
1300
|
-
*
|
|
1301
|
-
*
|
|
1302
|
-
* @param config - Configuration options
|
|
1303
|
-
* @returns Initialized Kontext client instance
|
|
1304
|
-
*
|
|
1305
|
-
* @example
|
|
1306
|
-
* ```typescript
|
|
1307
|
-
* // Local/OSS mode (no API key)
|
|
1308
|
-
* const kontext = Kontext.init({
|
|
1309
|
-
* projectId: 'my-project',
|
|
1310
|
-
* environment: 'development',
|
|
1311
|
-
* });
|
|
1312
|
-
*
|
|
1313
|
-
* // Cloud mode (with API key)
|
|
1314
|
-
* const kontext = Kontext.init({
|
|
1315
|
-
* apiKey: 'sk_live_...',
|
|
1316
|
-
* projectId: 'my-project',
|
|
1317
|
-
* environment: 'production',
|
|
1318
|
-
* });
|
|
1319
|
-
*
|
|
1320
|
-
* // With persistent file storage
|
|
1321
|
-
* const kontext = Kontext.init({
|
|
1322
|
-
* projectId: 'my-project',
|
|
1323
|
-
* environment: 'development',
|
|
1324
|
-
* storage: new FileStorage('./kontext-data'),
|
|
1325
|
-
* });
|
|
1326
|
-
* ```
|
|
1767
|
+
* Mark a txHash as already verified (called by the viem interceptor layer).
|
|
1768
|
+
* The monitor will skip this tx if it later sees it on-chain.
|
|
1327
1769
|
*/
|
|
1328
|
-
|
|
1770
|
+
markVerified(txHash: string): void;
|
|
1329
1771
|
/**
|
|
1330
|
-
*
|
|
1772
|
+
* Start watching all configured chains for stablecoin transfers.
|
|
1773
|
+
* Dynamically imports viem — requires viem as a peer dependency.
|
|
1331
1774
|
*/
|
|
1332
|
-
|
|
1775
|
+
start(): Promise<void>;
|
|
1776
|
+
/** Stop all watchers and cleanup */
|
|
1777
|
+
stop(): void;
|
|
1778
|
+
isRunning(): boolean;
|
|
1779
|
+
private handleTransferLog;
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
/** Entity type for an agent identity */
|
|
1783
|
+
type EntityType = 'individual' | 'organization' | 'bot' | 'unknown';
|
|
1784
|
+
/** KYC verification status */
|
|
1785
|
+
type KYCStatus = 'none' | 'pending' | 'verified' | 'rejected' | 'expired';
|
|
1786
|
+
/** A wallet mapping associated with an agent */
|
|
1787
|
+
interface WalletMapping {
|
|
1788
|
+
/** Wallet address (normalized to lowercase) */
|
|
1789
|
+
address: string;
|
|
1790
|
+
/** Blockchain network */
|
|
1791
|
+
chain: string;
|
|
1792
|
+
/** Whether this wallet was verified on-chain */
|
|
1793
|
+
verified: boolean;
|
|
1794
|
+
/** When the wallet was added */
|
|
1795
|
+
addedAt: string;
|
|
1796
|
+
/** Optional label for the wallet */
|
|
1797
|
+
label?: string;
|
|
1798
|
+
}
|
|
1799
|
+
/** Reference to an external KYC provider verification */
|
|
1800
|
+
interface KYCProviderReference {
|
|
1801
|
+
/** KYC provider name (e.g., 'jumio', 'onfido', 'sumsub') */
|
|
1802
|
+
provider: string;
|
|
1803
|
+
/** External reference/case ID from the provider */
|
|
1804
|
+
referenceId: string;
|
|
1805
|
+
/** Verification status */
|
|
1806
|
+
status: KYCStatus;
|
|
1807
|
+
/** When the verification was completed */
|
|
1808
|
+
verifiedAt: string | null;
|
|
1809
|
+
/** When the verification expires */
|
|
1810
|
+
expiresAt: string | null;
|
|
1811
|
+
/** Risk level assigned by the provider */
|
|
1812
|
+
riskLevel?: 'low' | 'medium' | 'high';
|
|
1813
|
+
}
|
|
1814
|
+
/** Declared agent identity */
|
|
1815
|
+
interface AgentIdentity {
|
|
1816
|
+
/** Agent ID (primary key) */
|
|
1817
|
+
agentId: string;
|
|
1818
|
+
/** Display name */
|
|
1819
|
+
displayName?: string;
|
|
1820
|
+
/** Entity type */
|
|
1821
|
+
entityType: EntityType;
|
|
1822
|
+
/** Wallet addresses associated with the agent */
|
|
1823
|
+
wallets: WalletMapping[];
|
|
1824
|
+
/** External KYC provider references */
|
|
1825
|
+
kycReferences: KYCProviderReference[];
|
|
1826
|
+
/** Contact URI (email, ENS, etc.) */
|
|
1827
|
+
contactUri?: string;
|
|
1828
|
+
/** Arbitrary metadata */
|
|
1829
|
+
metadata: Record<string, unknown>;
|
|
1830
|
+
/** When the identity was first registered */
|
|
1831
|
+
createdAt: string;
|
|
1832
|
+
/** When the identity was last updated */
|
|
1833
|
+
updatedAt: string;
|
|
1834
|
+
}
|
|
1835
|
+
/** Input for registering a new agent identity */
|
|
1836
|
+
interface RegisterIdentityInput {
|
|
1837
|
+
/** Agent ID */
|
|
1838
|
+
agentId: string;
|
|
1839
|
+
/** Display name */
|
|
1840
|
+
displayName?: string;
|
|
1841
|
+
/** Entity type */
|
|
1842
|
+
entityType?: EntityType;
|
|
1843
|
+
/** Initial wallet mappings */
|
|
1844
|
+
wallets?: Array<{
|
|
1845
|
+
address: string;
|
|
1846
|
+
chain: string;
|
|
1847
|
+
label?: string;
|
|
1848
|
+
}>;
|
|
1849
|
+
/** Contact URI */
|
|
1850
|
+
contactUri?: string;
|
|
1851
|
+
/** Arbitrary metadata */
|
|
1852
|
+
metadata?: Record<string, unknown>;
|
|
1853
|
+
}
|
|
1854
|
+
/** Input for updating an existing agent identity */
|
|
1855
|
+
interface UpdateIdentityInput {
|
|
1856
|
+
/** Updated display name */
|
|
1857
|
+
displayName?: string;
|
|
1858
|
+
/** Updated entity type */
|
|
1859
|
+
entityType?: EntityType;
|
|
1860
|
+
/** Updated contact URI */
|
|
1861
|
+
contactUri?: string;
|
|
1862
|
+
/** Metadata to merge */
|
|
1863
|
+
metadata?: Record<string, unknown>;
|
|
1864
|
+
}
|
|
1865
|
+
/** Heuristic used to cluster wallet addresses */
|
|
1866
|
+
type ClusteringHeuristic = 'common-agent' | 'funding-chain' | 'gas-sponsorship' | 'temporal-co-spending' | 'declared-wallets';
|
|
1867
|
+
/** Evidence for why two addresses were clustered */
|
|
1868
|
+
interface ClusteringEvidence {
|
|
1869
|
+
/** Heuristic that produced this evidence */
|
|
1870
|
+
heuristic: ClusteringHeuristic;
|
|
1871
|
+
/** Confidence of this particular heuristic (0-1) */
|
|
1872
|
+
confidence: number;
|
|
1873
|
+
/** Addresses involved */
|
|
1874
|
+
addresses: [string, string];
|
|
1875
|
+
/** When this evidence was detected */
|
|
1876
|
+
detectedAt: string;
|
|
1877
|
+
/** Additional detail */
|
|
1878
|
+
detail?: string;
|
|
1879
|
+
}
|
|
1880
|
+
/** A cluster of related wallet addresses */
|
|
1881
|
+
interface WalletCluster {
|
|
1882
|
+
/** Cluster ID */
|
|
1883
|
+
id: string;
|
|
1884
|
+
/** All addresses in the cluster (normalized lowercase) */
|
|
1885
|
+
addresses: string[];
|
|
1886
|
+
/** Agent IDs associated with this cluster */
|
|
1887
|
+
agentIds: string[];
|
|
1888
|
+
/** Evidence trail for this cluster */
|
|
1889
|
+
evidence: ClusteringEvidence[];
|
|
1890
|
+
/** Highest confidence from any evidence */
|
|
1891
|
+
confidence: number;
|
|
1892
|
+
/** When the cluster was formed */
|
|
1893
|
+
createdAt: string;
|
|
1894
|
+
}
|
|
1895
|
+
/** Configuration for wallet clustering */
|
|
1896
|
+
interface WalletClusteringConfig {
|
|
1897
|
+
/** Temporal co-spending window in seconds (default: 60) */
|
|
1898
|
+
temporalWindowSeconds?: number;
|
|
1899
|
+
/** Minimum destination overlap ratio for temporal heuristic (default: 0.3) */
|
|
1900
|
+
minDestinationOverlap?: number;
|
|
1901
|
+
/** Minimum number of sponsored wallets for gas sponsorship heuristic (default: 3) */
|
|
1902
|
+
minGasSponsoredWallets?: number;
|
|
1903
|
+
}
|
|
1904
|
+
/** Temporal features extracted from transaction patterns */
|
|
1905
|
+
interface TemporalFeatures {
|
|
1906
|
+
/** Mean inter-transaction interval in seconds */
|
|
1907
|
+
meanIntervalSeconds: number;
|
|
1908
|
+
/** Standard deviation of inter-transaction intervals */
|
|
1909
|
+
stddevIntervalSeconds: number;
|
|
1910
|
+
/** 24-bin hour-of-day histogram (normalized to sum=1) */
|
|
1911
|
+
hourHistogram: number[];
|
|
1912
|
+
/** 7-bin day-of-week histogram (normalized to sum=1) */
|
|
1913
|
+
dayHistogram: number[];
|
|
1914
|
+
}
|
|
1915
|
+
/** Financial features extracted from transaction amounts */
|
|
1916
|
+
interface FinancialFeatures {
|
|
1917
|
+
/** Mean transaction amount */
|
|
1918
|
+
meanAmount: number;
|
|
1919
|
+
/** Standard deviation of transaction amounts */
|
|
1920
|
+
stddevAmount: number;
|
|
1921
|
+
/** Median transaction amount */
|
|
1922
|
+
medianAmount: number;
|
|
1923
|
+
/** Ratio of round amounts (divisible by 100) */
|
|
1924
|
+
roundAmountRatio: number;
|
|
1925
|
+
/** Amount percentiles [p10, p25, p50, p75, p90] */
|
|
1926
|
+
percentiles: [number, number, number, number, number];
|
|
1927
|
+
}
|
|
1928
|
+
/** Network features from transaction graph */
|
|
1929
|
+
interface NetworkFeatures {
|
|
1930
|
+
/** Number of unique destination addresses */
|
|
1931
|
+
uniqueDestinations: number;
|
|
1932
|
+
/** Address reuse ratio: 1 - (unique / total) */
|
|
1933
|
+
reuseRatio: number;
|
|
1934
|
+
/** Herfindahl-Hirschman Index for destination concentration */
|
|
1935
|
+
concentrationIndex: number;
|
|
1936
|
+
/** Number of unique source addresses */
|
|
1937
|
+
uniqueSources: number;
|
|
1938
|
+
}
|
|
1939
|
+
/** Operational features from chain/token usage */
|
|
1940
|
+
interface OperationalFeatures {
|
|
1941
|
+
/** Distribution of transactions across chains (normalized) */
|
|
1942
|
+
chainDistribution: Record<string, number>;
|
|
1943
|
+
/** Distribution of transactions across tokens (normalized) */
|
|
1944
|
+
tokenDistribution: Record<string, number>;
|
|
1945
|
+
/** Primary chain (most used) */
|
|
1946
|
+
primaryChain: string;
|
|
1947
|
+
/** Primary token (most used) */
|
|
1948
|
+
primaryToken: string;
|
|
1949
|
+
}
|
|
1950
|
+
/** Complete behavioral embedding for an agent */
|
|
1951
|
+
interface BehavioralEmbedding {
|
|
1952
|
+
/** Agent ID */
|
|
1953
|
+
agentId: string;
|
|
1954
|
+
/** Temporal features */
|
|
1955
|
+
temporal: TemporalFeatures;
|
|
1956
|
+
/** Financial features */
|
|
1957
|
+
financial: FinancialFeatures;
|
|
1958
|
+
/** Network features */
|
|
1959
|
+
network: NetworkFeatures;
|
|
1960
|
+
/** Operational features */
|
|
1961
|
+
operational: OperationalFeatures;
|
|
1962
|
+
/** Number of transactions used to compute the embedding */
|
|
1963
|
+
sampleSize: number;
|
|
1964
|
+
/** When the embedding was computed */
|
|
1965
|
+
computedAt: string;
|
|
1966
|
+
}
|
|
1967
|
+
/** A signal contributing to an agent link */
|
|
1968
|
+
interface LinkSignal {
|
|
1969
|
+
/** Signal type */
|
|
1970
|
+
type: 'wallet-overlap' | 'behavioral-similarity' | 'declared-identity';
|
|
1971
|
+
/** Signal strength (0-1) */
|
|
1972
|
+
strength: number;
|
|
1973
|
+
/** Weight of this signal type (0-1) */
|
|
1974
|
+
weight: number;
|
|
1975
|
+
/** Detail about the signal */
|
|
1976
|
+
detail?: string;
|
|
1977
|
+
}
|
|
1978
|
+
/** Link status */
|
|
1979
|
+
type LinkStatus = 'inferred' | 'confirmed' | 'rejected';
|
|
1980
|
+
/** A link between two agents */
|
|
1981
|
+
interface AgentLink {
|
|
1982
|
+
/** Link ID */
|
|
1983
|
+
id: string;
|
|
1984
|
+
/** First agent ID */
|
|
1985
|
+
agentIdA: string;
|
|
1986
|
+
/** Second agent ID */
|
|
1987
|
+
agentIdB: string;
|
|
1988
|
+
/** Overall confidence (0-1) */
|
|
1989
|
+
confidence: number;
|
|
1990
|
+
/** Signals contributing to this link */
|
|
1991
|
+
signals: LinkSignal[];
|
|
1992
|
+
/** Link status */
|
|
1993
|
+
status: LinkStatus;
|
|
1994
|
+
/** When the link was created */
|
|
1995
|
+
createdAt: string;
|
|
1996
|
+
/** Who reviewed the link (if reviewed) */
|
|
1997
|
+
reviewedBy?: string;
|
|
1998
|
+
/** When the link was reviewed */
|
|
1999
|
+
reviewedAt?: string;
|
|
2000
|
+
}
|
|
2001
|
+
/** Configuration for cross-session linking */
|
|
2002
|
+
interface CrossSessionLinkerConfig {
|
|
2003
|
+
/** Minimum behavioral similarity to consider (default: 0.85) */
|
|
2004
|
+
minBehavioralSimilarity?: number;
|
|
2005
|
+
/** Minimum overall confidence to create a link (default: 0.6) */
|
|
2006
|
+
minLinkConfidence?: number;
|
|
2007
|
+
}
|
|
2008
|
+
/** A component contributing to the KYA confidence score */
|
|
2009
|
+
interface KYAScoreComponent {
|
|
2010
|
+
/** Component name */
|
|
2011
|
+
name: string;
|
|
2012
|
+
/** Raw component score (0-100) */
|
|
2013
|
+
score: number;
|
|
2014
|
+
/** Weight of this component (0-1) */
|
|
2015
|
+
weight: number;
|
|
2016
|
+
/** Weighted contribution to overall score */
|
|
2017
|
+
weightedScore: number;
|
|
2018
|
+
/** Human-readable detail */
|
|
2019
|
+
detail: string;
|
|
2020
|
+
}
|
|
2021
|
+
/** Confidence level label */
|
|
2022
|
+
type KYAConfidenceLevel = 'unknown' | 'low' | 'medium' | 'high' | 'verified';
|
|
2023
|
+
/** Complete KYA confidence score for an agent */
|
|
2024
|
+
interface KYAConfidenceScore {
|
|
2025
|
+
/** Agent ID */
|
|
2026
|
+
agentId: string;
|
|
2027
|
+
/** Overall score (0-100) */
|
|
2028
|
+
score: number;
|
|
2029
|
+
/** Confidence level */
|
|
2030
|
+
level: KYAConfidenceLevel;
|
|
2031
|
+
/** Component breakdown */
|
|
2032
|
+
components: KYAScoreComponent[];
|
|
2033
|
+
/** When the score was computed */
|
|
2034
|
+
computedAt: string;
|
|
2035
|
+
}
|
|
2036
|
+
/** Configuration for confidence scoring weights */
|
|
2037
|
+
interface KYAConfidenceScorerConfig {
|
|
2038
|
+
/** Weight for declared identity component (default: 0.20) */
|
|
2039
|
+
declaredIdentityWeight?: number;
|
|
2040
|
+
/** Weight for KYC verification component (default: 0.30) */
|
|
2041
|
+
kycVerificationWeight?: number;
|
|
2042
|
+
/** Weight for wallet graph component (default: 0.20) */
|
|
2043
|
+
walletGraphWeight?: number;
|
|
2044
|
+
/** Weight for behavioral consistency component (default: 0.20) */
|
|
2045
|
+
behavioralConsistencyWeight?: number;
|
|
2046
|
+
/** Weight for external enrichment component (default: 0.10) */
|
|
2047
|
+
externalEnrichmentWeight?: number;
|
|
2048
|
+
}
|
|
2049
|
+
/** Aggregated KYA data for inclusion in audit exports */
|
|
2050
|
+
interface KYAEnvelope {
|
|
2051
|
+
/** All registered identities */
|
|
2052
|
+
identities: AgentIdentity[];
|
|
2053
|
+
/** Wallet clusters */
|
|
2054
|
+
clusters: WalletCluster[];
|
|
2055
|
+
/** Behavioral embeddings (if enterprise) */
|
|
2056
|
+
embeddings: BehavioralEmbedding[];
|
|
2057
|
+
/** Agent links (if enterprise) */
|
|
2058
|
+
links: AgentLink[];
|
|
2059
|
+
/** Confidence scores */
|
|
2060
|
+
scores: KYAConfidenceScore[];
|
|
2061
|
+
/** When the envelope was generated */
|
|
2062
|
+
generatedAt: string;
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
/**
|
|
2066
|
+
* In-memory registry for agent identities.
|
|
2067
|
+
* Provides CRUD operations, wallet index lookups, and KYC reference management.
|
|
2068
|
+
*/
|
|
2069
|
+
declare class AgentIdentityRegistry {
|
|
2070
|
+
/** agentId -> AgentIdentity */
|
|
2071
|
+
private readonly identities;
|
|
2072
|
+
/** normalized address -> agentId (reverse index) */
|
|
2073
|
+
private readonly walletIndex;
|
|
1333
2074
|
/**
|
|
1334
|
-
*
|
|
2075
|
+
* Register a new agent identity.
|
|
1335
2076
|
*/
|
|
1336
|
-
|
|
1337
|
-
apiKey?: string;
|
|
1338
|
-
};
|
|
2077
|
+
register(input: RegisterIdentityInput): AgentIdentity;
|
|
1339
2078
|
/**
|
|
1340
|
-
*
|
|
1341
|
-
* No-op when metadataSchema is not configured.
|
|
2079
|
+
* Update an existing agent identity.
|
|
1342
2080
|
*/
|
|
1343
|
-
|
|
2081
|
+
update(agentId: string, input: UpdateIdentityInput): AgentIdentity;
|
|
1344
2082
|
/**
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
* @param input - Action details
|
|
1348
|
-
* @returns The created action log entry
|
|
2083
|
+
* Get an agent identity by agent ID.
|
|
1349
2084
|
*/
|
|
1350
|
-
|
|
2085
|
+
get(agentId: string): AgentIdentity | undefined;
|
|
1351
2086
|
/**
|
|
1352
|
-
*
|
|
1353
|
-
*
|
|
1354
|
-
* @param input - Transaction details
|
|
1355
|
-
* @returns The created transaction record
|
|
2087
|
+
* Remove an agent identity and all wallet index entries.
|
|
1356
2088
|
*/
|
|
1357
|
-
|
|
2089
|
+
remove(agentId: string): boolean;
|
|
1358
2090
|
/**
|
|
1359
|
-
*
|
|
2091
|
+
* Get all registered identities.
|
|
1360
2092
|
*/
|
|
1361
|
-
|
|
2093
|
+
getAll(): AgentIdentity[];
|
|
1362
2094
|
/**
|
|
1363
|
-
*
|
|
1364
|
-
* No-op if no storage adapter is configured.
|
|
2095
|
+
* Add a wallet to an existing agent identity.
|
|
1365
2096
|
*/
|
|
1366
|
-
|
|
2097
|
+
addWallet(agentId: string, wallet: {
|
|
2098
|
+
address: string;
|
|
2099
|
+
chain: string;
|
|
2100
|
+
label?: string;
|
|
2101
|
+
}): AgentIdentity;
|
|
1367
2102
|
/**
|
|
1368
|
-
*
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
2103
|
+
* Remove a wallet from an agent identity.
|
|
2104
|
+
*/
|
|
2105
|
+
removeWallet(agentId: string, address: string): AgentIdentity;
|
|
2106
|
+
/**
|
|
2107
|
+
* Look up an agent identity by wallet address.
|
|
2108
|
+
*/
|
|
2109
|
+
lookupByWallet(address: string): AgentIdentity | undefined;
|
|
2110
|
+
/**
|
|
2111
|
+
* Add a KYC provider reference to an agent identity.
|
|
2112
|
+
*/
|
|
2113
|
+
addKycReference(agentId: string, reference: KYCProviderReference): AgentIdentity;
|
|
2114
|
+
/**
|
|
2115
|
+
* Get the overall KYC status for an agent.
|
|
2116
|
+
* Returns the best status from all references.
|
|
2117
|
+
*/
|
|
2118
|
+
getKycStatus(agentId: string): KYCStatus;
|
|
2119
|
+
/**
|
|
2120
|
+
* Check if an agent has at least one verified and non-expired KYC reference.
|
|
2121
|
+
*/
|
|
2122
|
+
hasVerifiedKyc(agentId: string): boolean;
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
/**
|
|
2126
|
+
* In-memory data store for the Kontext SDK.
|
|
2127
|
+
* Holds all action logs, transactions, tasks, and anomaly events.
|
|
2128
|
+
*
|
|
2129
|
+
* When a StorageAdapter is provided, call `flush()` to persist state
|
|
2130
|
+
* and `restore()` to reload from storage.
|
|
2131
|
+
*/
|
|
2132
|
+
declare class KontextStore {
|
|
2133
|
+
private actions;
|
|
2134
|
+
private transactions;
|
|
2135
|
+
private tasks;
|
|
2136
|
+
private anomalies;
|
|
2137
|
+
private sessions;
|
|
2138
|
+
private checkpoints;
|
|
2139
|
+
private storageAdapter;
|
|
2140
|
+
private readonly maxEntries;
|
|
2141
|
+
constructor(maxEntries?: number);
|
|
2142
|
+
/**
|
|
2143
|
+
* Attach a storage adapter for persistence.
|
|
2144
|
+
*
|
|
2145
|
+
* @param adapter - The storage backend to use
|
|
2146
|
+
*/
|
|
2147
|
+
setStorageAdapter(adapter: StorageAdapter): void;
|
|
2148
|
+
/**
|
|
2149
|
+
* Get the currently attached storage adapter (if any).
|
|
2150
|
+
*/
|
|
2151
|
+
getStorageAdapter(): StorageAdapter | null;
|
|
2152
|
+
/**
|
|
2153
|
+
* Persist all current in-memory state to the attached storage adapter.
|
|
2154
|
+
* No-op if no adapter is attached.
|
|
2155
|
+
*/
|
|
2156
|
+
flush(): Promise<void>;
|
|
2157
|
+
/**
|
|
2158
|
+
* Restore in-memory state from the attached storage adapter.
|
|
2159
|
+
* Merges loaded data with any existing in-memory data.
|
|
2160
|
+
* No-op if no adapter is attached.
|
|
2161
|
+
*/
|
|
2162
|
+
restore(): Promise<void>;
|
|
2163
|
+
/** Append an action log entry. Evicts oldest 10% when maxEntries is exceeded. */
|
|
2164
|
+
addAction(action: ActionLog): void;
|
|
2165
|
+
/** Retrieve all action log entries. */
|
|
2166
|
+
getActions(): ActionLog[];
|
|
2167
|
+
/** Retrieve actions filtered by a predicate. */
|
|
2168
|
+
queryActions(predicate: (action: ActionLog) => boolean): ActionLog[];
|
|
2169
|
+
/** Get actions for a specific agent. */
|
|
2170
|
+
getActionsByAgent(agentId: string): ActionLog[];
|
|
2171
|
+
/** Get actions for a specific session (across all agents). */
|
|
2172
|
+
getActionsBySession(sessionId: string): ActionLog[];
|
|
2173
|
+
/** Append a transaction record. Evicts oldest 10% when maxEntries is exceeded. */
|
|
2174
|
+
addTransaction(tx: TransactionRecord): void;
|
|
2175
|
+
/** Retrieve all transaction records. */
|
|
2176
|
+
getTransactions(): TransactionRecord[];
|
|
2177
|
+
/** Retrieve transactions filtered by a predicate. */
|
|
2178
|
+
queryTransactions(predicate: (tx: TransactionRecord) => boolean): TransactionRecord[];
|
|
2179
|
+
/** Get transactions for a specific agent. */
|
|
2180
|
+
getTransactionsByAgent(agentId: string): TransactionRecord[];
|
|
2181
|
+
/** Get the most recent N transactions for an agent. */
|
|
2182
|
+
getRecentTransactions(agentId: string, limit: number): TransactionRecord[];
|
|
2183
|
+
/** Store a task. */
|
|
2184
|
+
addTask(task: Task): void;
|
|
2185
|
+
/** Retrieve a task by ID. */
|
|
2186
|
+
getTask(taskId: string): Task | undefined;
|
|
2187
|
+
/** Update a task. */
|
|
2188
|
+
updateTask(taskId: string, updates: Partial<Task>): Task | undefined;
|
|
2189
|
+
/** Retrieve all tasks. */
|
|
2190
|
+
getTasks(): Task[];
|
|
2191
|
+
/** Retrieve tasks filtered by a predicate. */
|
|
2192
|
+
queryTasks(predicate: (task: Task) => boolean): Task[];
|
|
2193
|
+
/** Append an anomaly event. Evicts oldest 10% when maxEntries is exceeded. */
|
|
2194
|
+
addAnomaly(anomaly: AnomalyEvent): void;
|
|
2195
|
+
/** Retrieve all anomaly events. */
|
|
2196
|
+
getAnomalies(): AnomalyEvent[];
|
|
2197
|
+
/** Retrieve anomalies filtered by a predicate. */
|
|
2198
|
+
queryAnomalies(predicate: (anomaly: AnomalyEvent) => boolean): AnomalyEvent[];
|
|
2199
|
+
/** Store a session. */
|
|
2200
|
+
addSession(session: AgentSession): void;
|
|
2201
|
+
/** Retrieve a session by ID. */
|
|
2202
|
+
getSession(sessionId: string): AgentSession | undefined;
|
|
2203
|
+
/** Update a session. */
|
|
2204
|
+
updateSession(sessionId: string, updates: Partial<AgentSession>): AgentSession | undefined;
|
|
2205
|
+
/** Retrieve all sessions. */
|
|
2206
|
+
getSessions(): AgentSession[];
|
|
2207
|
+
/** Retrieve sessions filtered by a predicate. */
|
|
2208
|
+
querySessions(predicate: (session: AgentSession) => boolean): AgentSession[];
|
|
2209
|
+
/** Store a checkpoint. */
|
|
2210
|
+
addCheckpoint(checkpoint: ProvenanceCheckpoint): void;
|
|
2211
|
+
/** Retrieve a checkpoint by ID. */
|
|
2212
|
+
getCheckpoint(checkpointId: string): ProvenanceCheckpoint | undefined;
|
|
2213
|
+
/** Update a checkpoint. */
|
|
2214
|
+
updateCheckpoint(checkpointId: string, updates: Partial<ProvenanceCheckpoint>): ProvenanceCheckpoint | undefined;
|
|
2215
|
+
/** Retrieve all checkpoints. */
|
|
2216
|
+
getCheckpoints(): ProvenanceCheckpoint[];
|
|
2217
|
+
/** Retrieve checkpoints filtered by a predicate. */
|
|
2218
|
+
queryCheckpoints(predicate: (cp: ProvenanceCheckpoint) => boolean): ProvenanceCheckpoint[];
|
|
2219
|
+
/** Get total record counts across all stores. */
|
|
2220
|
+
getCounts(): {
|
|
2221
|
+
actions: number;
|
|
2222
|
+
transactions: number;
|
|
2223
|
+
tasks: number;
|
|
2224
|
+
anomalies: number;
|
|
2225
|
+
sessions: number;
|
|
2226
|
+
checkpoints: number;
|
|
2227
|
+
};
|
|
2228
|
+
/** Clear all stored data. Useful for testing. */
|
|
2229
|
+
clear(): void;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
/**
|
|
2233
|
+
* Clusters wallet addresses using multiple heuristics.
|
|
2234
|
+
* Builds on UnionFind for efficient merging.
|
|
2235
|
+
*/
|
|
2236
|
+
declare class WalletClusterer {
|
|
2237
|
+
private readonly config;
|
|
2238
|
+
private cachedClusters;
|
|
2239
|
+
constructor(config?: WalletClusteringConfig);
|
|
2240
|
+
/**
|
|
2241
|
+
* Analyze transactions from the store and registry to produce wallet clusters.
|
|
2242
|
+
*/
|
|
2243
|
+
analyzeFromStore(store: KontextStore, registry?: AgentIdentityRegistry): WalletCluster[];
|
|
2244
|
+
/**
|
|
2245
|
+
* Get cached clusters (or empty if not analyzed yet).
|
|
2246
|
+
*/
|
|
2247
|
+
getClusters(): WalletCluster[];
|
|
2248
|
+
/**
|
|
2249
|
+
* Invalidate the cached clusters.
|
|
2250
|
+
*/
|
|
2251
|
+
invalidateCache(): void;
|
|
2252
|
+
/**
|
|
2253
|
+
* Heuristic 1: Common Agent (confidence 0.9)
|
|
2254
|
+
* Same agentId used multiple addresses -> union all from/to per agent.
|
|
2255
|
+
*/
|
|
2256
|
+
private applyCommonAgent;
|
|
2257
|
+
/**
|
|
2258
|
+
* Heuristic 2: Funding Chain (confidence 0.7)
|
|
2259
|
+
* If A sends to B, and A is agent-associated -> union A and B.
|
|
2260
|
+
*/
|
|
2261
|
+
private applyFundingChain;
|
|
2262
|
+
/**
|
|
2263
|
+
* Heuristic 3: Gas Sponsorship (confidence 0.75)
|
|
2264
|
+
* If G is from in transfers to 3+ distinct agent wallets -> union G with all.
|
|
2265
|
+
*/
|
|
2266
|
+
private applyGasSponsorship;
|
|
2267
|
+
/**
|
|
2268
|
+
* Heuristic 4: Temporal Co-Spending (confidence 0.6)
|
|
2269
|
+
* Addresses transacting within a window with destination overlap.
|
|
2270
|
+
*/
|
|
2271
|
+
private applyTemporalCoSpending;
|
|
2272
|
+
/**
|
|
2273
|
+
* Heuristic 5: Declared Wallets (confidence 1.0)
|
|
2274
|
+
* All wallets declared by the same identity are unioned.
|
|
2275
|
+
*/
|
|
2276
|
+
private applyDeclaredWallets;
|
|
2277
|
+
private buildClusters;
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
/**
|
|
2281
|
+
* Computes behavioral fingerprints (embeddings) from agent transaction patterns.
|
|
2282
|
+
* Used for cross-session linking and behavioral consistency scoring.
|
|
2283
|
+
*/
|
|
2284
|
+
declare class BehavioralFingerprinter {
|
|
2285
|
+
/**
|
|
2286
|
+
* Compute a behavioral embedding for an agent from their transaction history.
|
|
2287
|
+
* Returns null if the agent has fewer than MIN_SAMPLE_SIZE transactions.
|
|
2288
|
+
*/
|
|
2289
|
+
computeEmbedding(agentId: string, store: KontextStore): BehavioralEmbedding | null;
|
|
2290
|
+
/**
|
|
2291
|
+
* Compute cosine similarity between two behavioral embeddings.
|
|
2292
|
+
* Returns a value in [0, 1] where 1 means identical and 0 means orthogonal.
|
|
2293
|
+
*/
|
|
2294
|
+
cosineSimilarity(a: BehavioralEmbedding, b: BehavioralEmbedding): number;
|
|
2295
|
+
private extractTemporalFeatures;
|
|
2296
|
+
private extractFinancialFeatures;
|
|
2297
|
+
private extractNetworkFeatures;
|
|
2298
|
+
private extractOperationalFeatures;
|
|
2299
|
+
private percentile;
|
|
2300
|
+
/**
|
|
2301
|
+
* Flatten an embedding into a numeric vector for cosine similarity.
|
|
2302
|
+
* Log-scales magnitude values with log(1+x).
|
|
2303
|
+
*/
|
|
2304
|
+
private flattenEmbedding;
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
/**
|
|
2308
|
+
* Links agents across sessions by analyzing wallet graph overlap,
|
|
2309
|
+
* behavioral similarity, and declared identity signals.
|
|
2310
|
+
*/
|
|
2311
|
+
declare class CrossSessionLinker {
|
|
2312
|
+
private readonly config;
|
|
2313
|
+
private readonly links;
|
|
2314
|
+
constructor(config?: CrossSessionLinkerConfig);
|
|
2315
|
+
/**
|
|
2316
|
+
* Analyze all agents and create links between those with sufficient signals.
|
|
2317
|
+
*/
|
|
2318
|
+
analyzeAndLink(store: KontextStore, registry: AgentIdentityRegistry, clusterer: WalletClusterer, fingerprinter: BehavioralFingerprinter): AgentLink[];
|
|
2319
|
+
/**
|
|
2320
|
+
* Manually link two agents.
|
|
2321
|
+
*/
|
|
2322
|
+
manualLink(agentIdA: string, agentIdB: string, reviewedBy: string): AgentLink;
|
|
2323
|
+
/**
|
|
2324
|
+
* Review a link (confirm or reject).
|
|
2325
|
+
*/
|
|
2326
|
+
reviewLink(linkId: string, decision: 'confirmed' | 'rejected', reviewedBy: string): AgentLink | undefined;
|
|
2327
|
+
/**
|
|
2328
|
+
* Get all agents linked to the given agent.
|
|
2329
|
+
*/
|
|
2330
|
+
getLinkedAgents(agentId: string): string[];
|
|
2331
|
+
/**
|
|
2332
|
+
* Get all links for a specific agent.
|
|
2333
|
+
*/
|
|
2334
|
+
getLinksForAgent(agentId: string): AgentLink[];
|
|
2335
|
+
/**
|
|
2336
|
+
* Get all links.
|
|
2337
|
+
*/
|
|
2338
|
+
getAllLinks(): AgentLink[];
|
|
2339
|
+
private getLinkKey;
|
|
2340
|
+
private computeWalletOverlap;
|
|
2341
|
+
private computeDeclaredIdentitySignal;
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
/**
|
|
2345
|
+
* Computes a composite KYA confidence score from 5 signal components.
|
|
2346
|
+
*/
|
|
2347
|
+
declare class KYAConfidenceScorer {
|
|
2348
|
+
private readonly weights;
|
|
2349
|
+
constructor(config?: KYAConfidenceScorerConfig);
|
|
2350
|
+
/**
|
|
2351
|
+
* Compute a composite confidence score for an agent.
|
|
2352
|
+
*/
|
|
2353
|
+
computeScore(agentId: string, registry: AgentIdentityRegistry, clusterer: WalletClusterer, fingerprinter: BehavioralFingerprinter, linker: CrossSessionLinker, store: KontextStore): KYAConfidenceScore;
|
|
2354
|
+
private scoreDeclaredIdentity;
|
|
2355
|
+
private scoreKycVerification;
|
|
2356
|
+
private scoreWalletGraph;
|
|
2357
|
+
private scoreBehavioralConsistency;
|
|
2358
|
+
private scoreExternalEnrichment;
|
|
2359
|
+
private scoreToLevel;
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
/**
|
|
2363
|
+
* Main Kontext SDK client. Provides a unified interface to all SDK features:
|
|
2364
|
+
* action logging, task confirmation, audit export, trust scoring, and
|
|
2365
|
+
* anomaly detection.
|
|
2366
|
+
*
|
|
2367
|
+
* Supports two operating modes:
|
|
2368
|
+
* - **Local mode** (no API key): All data stored locally, suitable for
|
|
2369
|
+
* open-source usage and development.
|
|
2370
|
+
* - **Cloud mode** (with API key): Data synced to Kontext API for
|
|
2371
|
+
* persistent storage and advanced features.
|
|
2372
|
+
*
|
|
2373
|
+
* @example
|
|
2374
|
+
* ```typescript
|
|
2375
|
+
* import { Kontext } from '@kontext/sdk';
|
|
2376
|
+
*
|
|
2377
|
+
* const kontext = Kontext.init({
|
|
2378
|
+
* projectId: 'my-project',
|
|
2379
|
+
* environment: 'development',
|
|
2380
|
+
* });
|
|
2381
|
+
*
|
|
2382
|
+
* await kontext.logTransaction({
|
|
2383
|
+
* txHash: '0x...',
|
|
2384
|
+
* chain: 'base',
|
|
2385
|
+
* amount: '100',
|
|
2386
|
+
* token: 'USDC',
|
|
2387
|
+
* from: '0xSender',
|
|
2388
|
+
* to: '0xReceiver',
|
|
2389
|
+
* agentId: 'agent-1',
|
|
2390
|
+
* });
|
|
2391
|
+
* ```
|
|
2392
|
+
*/
|
|
2393
|
+
declare class Kontext {
|
|
2394
|
+
private readonly config;
|
|
2395
|
+
private readonly store;
|
|
2396
|
+
private readonly logger;
|
|
2397
|
+
private readonly taskManager;
|
|
2398
|
+
private readonly auditExporter;
|
|
2399
|
+
private readonly mode;
|
|
2400
|
+
private readonly planManager;
|
|
2401
|
+
private readonly exporter;
|
|
2402
|
+
private readonly featureFlagManager;
|
|
2403
|
+
private readonly trustScorer;
|
|
2404
|
+
private readonly anomalyDetector;
|
|
2405
|
+
private readonly screeningAggregator;
|
|
2406
|
+
private walletMonitor;
|
|
2407
|
+
private provenanceManager;
|
|
2408
|
+
private identityRegistry;
|
|
2409
|
+
private walletClusterer;
|
|
2410
|
+
private behavioralFingerprinter;
|
|
2411
|
+
private crossSessionLinker;
|
|
2412
|
+
private confidenceScorer;
|
|
2413
|
+
private constructor();
|
|
2414
|
+
/**
|
|
2415
|
+
* Initialize the Kontext SDK.
|
|
2416
|
+
*
|
|
2417
|
+
* @param config - Configuration options
|
|
2418
|
+
* @returns Initialized Kontext client instance
|
|
2419
|
+
*
|
|
2420
|
+
* @example
|
|
2421
|
+
* ```typescript
|
|
2422
|
+
* // Local/OSS mode (no API key)
|
|
2423
|
+
* const kontext = Kontext.init({
|
|
2424
|
+
* projectId: 'my-project',
|
|
2425
|
+
* environment: 'development',
|
|
2426
|
+
* });
|
|
2427
|
+
*
|
|
2428
|
+
* // Cloud mode (with API key)
|
|
2429
|
+
* const kontext = Kontext.init({
|
|
2430
|
+
* apiKey: 'sk_live_...',
|
|
2431
|
+
* projectId: 'my-project',
|
|
2432
|
+
* environment: 'production',
|
|
2433
|
+
* });
|
|
2434
|
+
*
|
|
2435
|
+
* // With persistent file storage
|
|
2436
|
+
* const kontext = Kontext.init({
|
|
2437
|
+
* projectId: 'my-project',
|
|
2438
|
+
* environment: 'development',
|
|
2439
|
+
* storage: new FileStorage('./kontext-data'),
|
|
2440
|
+
* });
|
|
2441
|
+
* ```
|
|
2442
|
+
*/
|
|
2443
|
+
static init(config?: KontextConfig): Kontext;
|
|
2444
|
+
/**
|
|
2445
|
+
* Get the current operating mode.
|
|
2446
|
+
*/
|
|
2447
|
+
getMode(): KontextMode;
|
|
2448
|
+
/**
|
|
2449
|
+
* Get the current configuration (API key is masked).
|
|
2450
|
+
*/
|
|
2451
|
+
getConfig(): Omit<KontextConfig, 'apiKey'> & {
|
|
2452
|
+
apiKey?: string;
|
|
2453
|
+
};
|
|
2454
|
+
/**
|
|
2455
|
+
* Validate metadata against the configured schema, if any.
|
|
2456
|
+
* No-op when metadataSchema is not configured.
|
|
2457
|
+
*/
|
|
2458
|
+
private validateMetadata;
|
|
2459
|
+
/**
|
|
2460
|
+
* Map aggregated screening results into UsdcComplianceCheck format.
|
|
2461
|
+
* Produces the same check/riskLevel/recommendations shape as
|
|
2462
|
+
* UsdcCompliance.checkTransaction() and PaymentCompliance.checkPayment().
|
|
2463
|
+
*/
|
|
2464
|
+
private buildComplianceFromScreening;
|
|
2465
|
+
/** Lazy-init ProvenanceManager on first use. */
|
|
2466
|
+
private getProvenanceManager;
|
|
2467
|
+
/** Lazy-init AgentIdentityRegistry on first use. */
|
|
2468
|
+
private getIdentityRegistry;
|
|
2469
|
+
/** Lazy-init WalletClusterer on first use. */
|
|
2470
|
+
private getWalletClusterer;
|
|
2471
|
+
/** Lazy-init BehavioralFingerprinter on first use. */
|
|
2472
|
+
private getBehavioralFingerprinter;
|
|
2473
|
+
/** Lazy-init CrossSessionLinker on first use. */
|
|
2474
|
+
private getCrossSessionLinker;
|
|
2475
|
+
/** Lazy-init KYAConfidenceScorer on first use. */
|
|
2476
|
+
private getConfidenceScorer;
|
|
2477
|
+
/**
|
|
2478
|
+
* Log a generic agent action.
|
|
2479
|
+
*
|
|
2480
|
+
* @param input - Action details
|
|
2481
|
+
* @returns The created action log entry
|
|
2482
|
+
*/
|
|
2483
|
+
log(input: LogActionInput): Promise<ActionLog>;
|
|
2484
|
+
/**
|
|
2485
|
+
* Log a cryptocurrency transaction with full chain details.
|
|
2486
|
+
*
|
|
2487
|
+
* @param input - Transaction details
|
|
2488
|
+
* @returns The created transaction record
|
|
2489
|
+
*/
|
|
2490
|
+
logTransaction(input: LogTransactionInput): Promise<TransactionRecord>;
|
|
2491
|
+
/**
|
|
2492
|
+
* Flush any pending log batches.
|
|
2493
|
+
*/
|
|
2494
|
+
flushLogs(): Promise<void>;
|
|
2495
|
+
/**
|
|
2496
|
+
* Persist all current in-memory state to the attached storage adapter.
|
|
2497
|
+
* No-op if no storage adapter is configured.
|
|
2498
|
+
*/
|
|
2499
|
+
flush(): Promise<void>;
|
|
2500
|
+
/**
|
|
2501
|
+
* Restore state from the attached storage adapter.
|
|
2502
|
+
* Loads previously persisted actions, transactions, tasks, and anomalies.
|
|
2503
|
+
* Also restores the digest chain's terminal digest so that new actions
|
|
2504
|
+
* chain correctly across process boundaries.
|
|
1372
2505
|
* No-op if no storage adapter is configured.
|
|
1373
2506
|
*/
|
|
1374
2507
|
restore(): Promise<void>;
|
|
@@ -1624,6 +2757,120 @@ declare class Kontext {
|
|
|
1624
2757
|
* ```
|
|
1625
2758
|
*/
|
|
1626
2759
|
generateComplianceCertificate(input: GenerateComplianceCertificateInput): Promise<ComplianceCertificate>;
|
|
2760
|
+
/**
|
|
2761
|
+
* Create a delegated agent session. Records the delegation in the
|
|
2762
|
+
* tamper-evident digest chain as the session's genesis event.
|
|
2763
|
+
*/
|
|
2764
|
+
createAgentSession(input: CreateSessionInput): Promise<AgentSession>;
|
|
2765
|
+
/**
|
|
2766
|
+
* Get an agent session by ID. Automatically marks expired sessions.
|
|
2767
|
+
*/
|
|
2768
|
+
getAgentSession(sessionId: string): AgentSession | undefined;
|
|
2769
|
+
/**
|
|
2770
|
+
* Get all agent sessions.
|
|
2771
|
+
*/
|
|
2772
|
+
getAgentSessions(): AgentSession[];
|
|
2773
|
+
/**
|
|
2774
|
+
* End an active agent session. Records the termination in the digest chain.
|
|
2775
|
+
*/
|
|
2776
|
+
endAgentSession(sessionId: string): Promise<AgentSession>;
|
|
2777
|
+
/**
|
|
2778
|
+
* Check whether an action is within a session's delegated scope.
|
|
2779
|
+
*/
|
|
2780
|
+
validateSessionScope(sessionId: string, action: string): boolean;
|
|
2781
|
+
/**
|
|
2782
|
+
* Get all actions bound to a session (via sessionId on log/verify calls).
|
|
2783
|
+
*/
|
|
2784
|
+
getSessionActions(sessionId: string): ActionLog[];
|
|
2785
|
+
/**
|
|
2786
|
+
* Create a provenance checkpoint -- a review point where a human
|
|
2787
|
+
* can attest to a batch of agent actions.
|
|
2788
|
+
*/
|
|
2789
|
+
createCheckpoint(input: CreateCheckpointInput): Promise<ProvenanceCheckpoint>;
|
|
2790
|
+
/**
|
|
2791
|
+
* Attach an externally-produced human attestation to a checkpoint.
|
|
2792
|
+
* The attestation includes a cryptographic signature that the agent
|
|
2793
|
+
* never touches -- key separation is the critical security property.
|
|
2794
|
+
*/
|
|
2795
|
+
attachAttestation(checkpointId: string, attestation: HumanAttestation): Promise<ProvenanceCheckpoint>;
|
|
2796
|
+
/**
|
|
2797
|
+
* Get a checkpoint by ID.
|
|
2798
|
+
*/
|
|
2799
|
+
getCheckpoint(checkpointId: string): ProvenanceCheckpoint | undefined;
|
|
2800
|
+
/**
|
|
2801
|
+
* Get all checkpoints, optionally filtered by session.
|
|
2802
|
+
*/
|
|
2803
|
+
getCheckpoints(sessionId?: string): ProvenanceCheckpoint[];
|
|
2804
|
+
/**
|
|
2805
|
+
* Export the full provenance bundle for a session: session record,
|
|
2806
|
+
* all bound actions, all checkpoints, and verification stats.
|
|
2807
|
+
*/
|
|
2808
|
+
getProvenanceBundle(sessionId: string): ProvenanceBundle;
|
|
2809
|
+
/**
|
|
2810
|
+
* Register a new agent identity with optional wallet mappings.
|
|
2811
|
+
* Requires Pro plan.
|
|
2812
|
+
*/
|
|
2813
|
+
registerAgentIdentity(input: RegisterIdentityInput): AgentIdentity;
|
|
2814
|
+
/**
|
|
2815
|
+
* Get a registered agent identity by ID.
|
|
2816
|
+
* Requires Pro plan.
|
|
2817
|
+
*/
|
|
2818
|
+
getAgentIdentity(agentId: string): AgentIdentity | undefined;
|
|
2819
|
+
/**
|
|
2820
|
+
* Update an existing agent identity.
|
|
2821
|
+
* Requires Pro plan.
|
|
2822
|
+
*/
|
|
2823
|
+
updateAgentIdentity(agentId: string, input: UpdateIdentityInput): AgentIdentity;
|
|
2824
|
+
/**
|
|
2825
|
+
* Remove an agent identity.
|
|
2826
|
+
* Requires Pro plan.
|
|
2827
|
+
*/
|
|
2828
|
+
removeAgentIdentity(agentId: string): boolean;
|
|
2829
|
+
/**
|
|
2830
|
+
* Add a wallet to an existing agent identity.
|
|
2831
|
+
* Requires Pro plan.
|
|
2832
|
+
*/
|
|
2833
|
+
addAgentWallet(agentId: string, wallet: {
|
|
2834
|
+
address: string;
|
|
2835
|
+
chain: string;
|
|
2836
|
+
label?: string;
|
|
2837
|
+
isPrimary?: boolean;
|
|
2838
|
+
}): AgentIdentity;
|
|
2839
|
+
/**
|
|
2840
|
+
* Look up which agent owns a wallet address.
|
|
2841
|
+
* Requires Pro plan.
|
|
2842
|
+
*/
|
|
2843
|
+
lookupAgentByWallet(address: string): AgentIdentity | undefined;
|
|
2844
|
+
/**
|
|
2845
|
+
* Compute wallet clusters from transaction patterns and declared identities.
|
|
2846
|
+
* Requires Pro plan.
|
|
2847
|
+
*/
|
|
2848
|
+
getWalletClusters(): WalletCluster[];
|
|
2849
|
+
/**
|
|
2850
|
+
* Export all KYA data as a single envelope.
|
|
2851
|
+
* Requires Pro plan.
|
|
2852
|
+
*/
|
|
2853
|
+
getKYAExport(): KYAEnvelope;
|
|
2854
|
+
/**
|
|
2855
|
+
* Compute a behavioral embedding for an agent from transaction history.
|
|
2856
|
+
* Returns null if insufficient data. Requires Enterprise plan.
|
|
2857
|
+
*/
|
|
2858
|
+
computeBehavioralEmbedding(agentId: string): BehavioralEmbedding | null;
|
|
2859
|
+
/**
|
|
2860
|
+
* Analyze all agents and create cross-session links.
|
|
2861
|
+
* Requires Enterprise plan.
|
|
2862
|
+
*/
|
|
2863
|
+
analyzeAgentLinks(): AgentLink[];
|
|
2864
|
+
/**
|
|
2865
|
+
* Get agents linked to a specific agent.
|
|
2866
|
+
* Requires Enterprise plan.
|
|
2867
|
+
*/
|
|
2868
|
+
getLinkedAgents(agentId: string): string[];
|
|
2869
|
+
/**
|
|
2870
|
+
* Compute a composite identity confidence score for an agent.
|
|
2871
|
+
* Requires Enterprise plan.
|
|
2872
|
+
*/
|
|
2873
|
+
getKYAConfidenceScore(agentId: string): KYAConfidenceScore;
|
|
1627
2874
|
/**
|
|
1628
2875
|
* Get current usage statistics for the plan.
|
|
1629
2876
|
*
|
|
@@ -1683,7 +2930,12 @@ declare class Kontext {
|
|
|
1683
2930
|
*/
|
|
1684
2931
|
getFeatureFlagManager(): FeatureFlagManager | null;
|
|
1685
2932
|
/**
|
|
1686
|
-
*
|
|
2933
|
+
* Get the wallet monitor instance (or null if not configured).
|
|
2934
|
+
* Used by the viem interceptor for dedup registration.
|
|
2935
|
+
*/
|
|
2936
|
+
getWalletMonitor(): WalletMonitor | null;
|
|
2937
|
+
/**
|
|
2938
|
+
* Gracefully shut down the SDK, flushing any pending data and stopping watchers.
|
|
1687
2939
|
*/
|
|
1688
2940
|
destroy(): Promise<void>;
|
|
1689
2941
|
}
|
|
@@ -1785,139 +3037,289 @@ declare class UsdcCompliance {
|
|
|
1785
3037
|
* @param chain - The blockchain network
|
|
1786
3038
|
* @returns The USDC contract address, or undefined for unsupported chains
|
|
1787
3039
|
*/
|
|
1788
|
-
static getContractAddress(chain: Chain): string | undefined;
|
|
3040
|
+
static getContractAddress(chain: Chain): string | undefined;
|
|
3041
|
+
/**
|
|
3042
|
+
* Get the chains supported for USDC compliance monitoring.
|
|
3043
|
+
*/
|
|
3044
|
+
static getSupportedChains(): Chain[];
|
|
3045
|
+
/**
|
|
3046
|
+
* Add new sanctioned addresses at runtime.
|
|
3047
|
+
* Normalizes all addresses to lowercase for consistent matching.
|
|
3048
|
+
* Skips addresses that are already in the list.
|
|
3049
|
+
*
|
|
3050
|
+
* @param addresses - Array of Ethereum addresses to add
|
|
3051
|
+
* @returns The count of newly added addresses (excluding duplicates)
|
|
3052
|
+
*/
|
|
3053
|
+
static addSanctionedAddresses(addresses: string[]): number;
|
|
3054
|
+
/**
|
|
3055
|
+
* Replace the entire sanctioned addresses list at runtime.
|
|
3056
|
+
* Clears existing entries and rebuilds from the provided array.
|
|
3057
|
+
*
|
|
3058
|
+
* @param addresses - The new complete list of sanctioned addresses
|
|
3059
|
+
*/
|
|
3060
|
+
static replaceSanctionedAddresses(addresses: string[]): void;
|
|
3061
|
+
/**
|
|
3062
|
+
* Get the current number of addresses in the sanctions list.
|
|
3063
|
+
*
|
|
3064
|
+
* @returns The size of the current sanctions list
|
|
3065
|
+
*/
|
|
3066
|
+
static getSanctionsListSize(): number;
|
|
3067
|
+
private static checkTokenType;
|
|
3068
|
+
private static checkChainSupport;
|
|
3069
|
+
private static checkAddressFormat;
|
|
3070
|
+
private static checkAmountValid;
|
|
3071
|
+
private static checkSanctions;
|
|
3072
|
+
private static checkEnhancedDueDiligence;
|
|
3073
|
+
private static checkReportingThreshold;
|
|
3074
|
+
private static generateRecommendations;
|
|
3075
|
+
}
|
|
3076
|
+
|
|
3077
|
+
declare class PaymentCompliance {
|
|
3078
|
+
/**
|
|
3079
|
+
* Run compliance checks on a general payment.
|
|
3080
|
+
*
|
|
3081
|
+
* @param input - Payment to evaluate
|
|
3082
|
+
* @returns UsdcComplianceCheck with pass/fail results and recommendations
|
|
3083
|
+
*/
|
|
3084
|
+
static checkPayment(input: LogTransactionInput): UsdcComplianceCheck;
|
|
3085
|
+
private static checkAmountValid;
|
|
3086
|
+
private static checkEntityScreening;
|
|
3087
|
+
private static checkEnhancedDueDiligence;
|
|
3088
|
+
private static checkReportingThreshold;
|
|
3089
|
+
private static generateRecommendations;
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
/**
|
|
3093
|
+
* Verify whether a digest has been anchored on-chain.
|
|
3094
|
+
* Uses eth_call — no signing required, no dependencies.
|
|
3095
|
+
*/
|
|
3096
|
+
declare function verifyAnchor(rpcUrl: string, contractAddress: string, digest: string): Promise<AnchorVerification>;
|
|
3097
|
+
/**
|
|
3098
|
+
* Get full anchor details for a digest.
|
|
3099
|
+
* Returns null if the digest is not anchored.
|
|
3100
|
+
*/
|
|
3101
|
+
declare function getAnchor(rpcUrl: string, contractAddress: string, digest: string): Promise<{
|
|
3102
|
+
anchorer: string;
|
|
3103
|
+
projectHash: string;
|
|
3104
|
+
timestamp: number;
|
|
3105
|
+
} | null>;
|
|
3106
|
+
/**
|
|
3107
|
+
* Anchor a digest hash on-chain via the KontextAnchor contract.
|
|
3108
|
+
* Requires viem: `npm install viem`
|
|
3109
|
+
*/
|
|
3110
|
+
declare function anchorDigest(config: OnChainAnchorConfig, digest: string, projectId: string): Promise<AnchorResult>;
|
|
3111
|
+
/**
|
|
3112
|
+
* Exporter that anchors terminal digest hashes on Base chain.
|
|
3113
|
+
* Buffers events and anchors when batchSize is reached.
|
|
3114
|
+
*/
|
|
3115
|
+
declare class OnChainExporter implements EventExporter {
|
|
3116
|
+
private readonly config;
|
|
3117
|
+
private readonly projectId;
|
|
3118
|
+
private readonly batchSize;
|
|
3119
|
+
private readonly getTerminalDigest;
|
|
3120
|
+
private eventCount;
|
|
3121
|
+
constructor(config: OnChainAnchorConfig, projectId: string, getTerminalDigest: () => string);
|
|
3122
|
+
export(events: ActionLog[]): Promise<ExporterResult>;
|
|
3123
|
+
flush(): Promise<void>;
|
|
3124
|
+
shutdown(): Promise<void>;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
/** Default builder code for Kontext anchor transactions */
|
|
3128
|
+
declare const KONTEXT_BUILDER_CODE = "kontext";
|
|
3129
|
+
/**
|
|
3130
|
+
* Encode an ERC-8021 data suffix for the given builder codes.
|
|
3131
|
+
* Returns hex string (no 0x prefix) to append directly to calldata.
|
|
3132
|
+
*
|
|
3133
|
+
* Layout: [codesLength (1 byte)][codes (ASCII, comma-delimited)][schemaId (1 byte)][marker (16 bytes)]
|
|
3134
|
+
*/
|
|
3135
|
+
declare function encodeERC8021Suffix(codes: string[]): string;
|
|
3136
|
+
/**
|
|
3137
|
+
* Parse an ERC-8021 data suffix from calldata.
|
|
3138
|
+
* Returns null if the calldata does not contain a valid ERC-8021 suffix.
|
|
3139
|
+
* Parses backward from the end of calldata.
|
|
3140
|
+
*/
|
|
3141
|
+
declare function parseERC8021Suffix(calldata: string): ERC8021Attribution | null;
|
|
3142
|
+
/**
|
|
3143
|
+
* Fetch a transaction's calldata and parse ERC-8021 attribution.
|
|
3144
|
+
* Uses eth_getTransactionByHash via JSON-RPC (zero dependencies).
|
|
3145
|
+
*/
|
|
3146
|
+
declare function fetchTransactionAttribution(rpcUrl: string, txHash: string): Promise<ERC8021Attribution | null>;
|
|
3147
|
+
|
|
3148
|
+
/**
|
|
3149
|
+
* Fetch the counterparty's agent card from /.well-known/kontext.json
|
|
3150
|
+
*/
|
|
3151
|
+
declare function fetchAgentCard(endpoint: string, timeoutMs?: number): Promise<AgentCard>;
|
|
3152
|
+
/**
|
|
3153
|
+
* Exchange compliance attestation with a counterparty agent.
|
|
3154
|
+
*
|
|
3155
|
+
* Flow:
|
|
3156
|
+
* 1. Fetch counterparty's agent card from /.well-known/kontext.json
|
|
3157
|
+
* 2. Validate agent ID if specified
|
|
3158
|
+
* 3. Verify counterparty supports attestation
|
|
3159
|
+
* 4. POST attestation request to counterparty's attest endpoint
|
|
3160
|
+
* 5. Return counterparty's attestation response
|
|
3161
|
+
*/
|
|
3162
|
+
declare function exchangeAttestation(config: CounterpartyConfig, request: AttestationRequest): Promise<CounterpartyAttestation>;
|
|
3163
|
+
|
|
3164
|
+
/**
|
|
3165
|
+
* ActionLogger handles structured logging of all agent actions.
|
|
3166
|
+
*
|
|
3167
|
+
* Supports two output modes:
|
|
3168
|
+
* - **Local mode** (no API key): Writes structured JSON logs to the local filesystem.
|
|
3169
|
+
* - **Cloud mode** (with API key): Batches and sends logs to the Kontext API.
|
|
3170
|
+
*
|
|
3171
|
+
* Logs include timestamps, agent IDs, correlation IDs, and arbitrary metadata
|
|
3172
|
+
* for full audit traceability.
|
|
3173
|
+
*/
|
|
3174
|
+
declare class ActionLogger {
|
|
3175
|
+
private readonly config;
|
|
3176
|
+
private readonly store;
|
|
3177
|
+
private readonly digestChain;
|
|
3178
|
+
private batch;
|
|
3179
|
+
private flushTimer;
|
|
3180
|
+
private readonly batchSize;
|
|
3181
|
+
private readonly flushIntervalMs;
|
|
3182
|
+
private readonly isCloudMode;
|
|
3183
|
+
private readonly logLevel;
|
|
3184
|
+
constructor(config: KontextConfig, store: KontextStore);
|
|
3185
|
+
/**
|
|
3186
|
+
* Log a generic agent action.
|
|
3187
|
+
*
|
|
3188
|
+
* @param input - Action details including type, description, agentId, and metadata
|
|
3189
|
+
* @returns The created ActionLog entry
|
|
3190
|
+
*
|
|
3191
|
+
* @example
|
|
3192
|
+
* ```typescript
|
|
3193
|
+
* const action = await logger.log({
|
|
3194
|
+
* type: 'approval',
|
|
3195
|
+
* description: 'Agent approved USDC spending',
|
|
3196
|
+
* agentId: 'agent-1',
|
|
3197
|
+
* metadata: { spender: '0x...', amount: '1000' },
|
|
3198
|
+
* });
|
|
3199
|
+
* ```
|
|
3200
|
+
*/
|
|
3201
|
+
log(input: LogActionInput): Promise<ActionLog>;
|
|
3202
|
+
/**
|
|
3203
|
+
* Log a cryptocurrency transaction with full chain details.
|
|
3204
|
+
*
|
|
3205
|
+
* @param input - Transaction details including txHash, chain, amount, token, from, to
|
|
3206
|
+
* @returns The created TransactionRecord
|
|
3207
|
+
*
|
|
3208
|
+
* @example
|
|
3209
|
+
* ```typescript
|
|
3210
|
+
* const tx = await logger.logTransaction({
|
|
3211
|
+
* txHash: '0xabc123...',
|
|
3212
|
+
* chain: 'base',
|
|
3213
|
+
* amount: '100.00',
|
|
3214
|
+
* token: 'USDC',
|
|
3215
|
+
* from: '0xSender...',
|
|
3216
|
+
* to: '0xReceiver...',
|
|
3217
|
+
* agentId: 'payment-agent-1',
|
|
3218
|
+
* });
|
|
3219
|
+
* ```
|
|
3220
|
+
*/
|
|
3221
|
+
logTransaction(input: LogTransactionInput): Promise<TransactionRecord>;
|
|
3222
|
+
/**
|
|
3223
|
+
* Flush the current batch of logs.
|
|
3224
|
+
* In local mode, writes to a JSON file.
|
|
3225
|
+
* In cloud mode, sends to the Kontext API.
|
|
3226
|
+
*/
|
|
3227
|
+
flush(): Promise<void>;
|
|
3228
|
+
/**
|
|
3229
|
+
* Stop the logger and flush any remaining logs.
|
|
3230
|
+
*/
|
|
3231
|
+
destroy(): Promise<void>;
|
|
3232
|
+
/**
|
|
3233
|
+
* Get the terminal digest — the latest SHA-256 digest in the chain.
|
|
3234
|
+
* Can be embedded in outgoing messages as tamper-evident proof.
|
|
3235
|
+
*/
|
|
3236
|
+
getTerminalDigest(): string;
|
|
3237
|
+
/**
|
|
3238
|
+
* Get the full digest chain for export or verification.
|
|
3239
|
+
*/
|
|
3240
|
+
getDigestChain(): DigestChain;
|
|
3241
|
+
/**
|
|
3242
|
+
* Verify the integrity of the digest chain against stored actions.
|
|
3243
|
+
*/
|
|
3244
|
+
verifyChain(actions: ActionLog[]): ReturnType<DigestChain['verify']>;
|
|
3245
|
+
/**
|
|
3246
|
+
* Restore chain state from persisted actions so that new actions
|
|
3247
|
+
* chain correctly across process boundaries.
|
|
3248
|
+
*/
|
|
3249
|
+
restoreChainState(terminalDigest: string): void;
|
|
3250
|
+
private validateTransactionInput;
|
|
3251
|
+
private flushToFile;
|
|
3252
|
+
private flushToApi;
|
|
3253
|
+
/**
|
|
3254
|
+
* Emit a log message at the specified severity level.
|
|
3255
|
+
* Only outputs if the message level meets or exceeds the configured logLevel.
|
|
3256
|
+
*/
|
|
3257
|
+
emitLog(level: LogLevel, message: string, data?: unknown): void;
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
/**
|
|
3261
|
+
* Manages agent provenance across three layers:
|
|
3262
|
+
* - Layer 1: Session delegation (who authorized the agent)
|
|
3263
|
+
* - Layer 2: Action binding (actions linked to sessions via sessionId)
|
|
3264
|
+
* - Layer 3: Human attestation checkpoints (cryptographic review proof)
|
|
3265
|
+
*/
|
|
3266
|
+
declare class ProvenanceManager {
|
|
3267
|
+
private readonly store;
|
|
3268
|
+
private readonly logger;
|
|
3269
|
+
constructor(store: KontextStore, logger: ActionLogger);
|
|
3270
|
+
/**
|
|
3271
|
+
* Create a delegated agent session. Records the delegation in the
|
|
3272
|
+
* tamper-evident digest chain as the session's genesis event.
|
|
3273
|
+
*/
|
|
3274
|
+
createSession(input: CreateSessionInput): Promise<AgentSession>;
|
|
1789
3275
|
/**
|
|
1790
|
-
* Get
|
|
3276
|
+
* Get an agent session by ID. Automatically marks expired sessions.
|
|
1791
3277
|
*/
|
|
1792
|
-
|
|
3278
|
+
getSession(sessionId: string): AgentSession | undefined;
|
|
1793
3279
|
/**
|
|
1794
|
-
*
|
|
1795
|
-
* Normalizes all addresses to lowercase for consistent matching.
|
|
1796
|
-
* Skips addresses that are already in the list.
|
|
1797
|
-
*
|
|
1798
|
-
* @param addresses - Array of Ethereum addresses to add
|
|
1799
|
-
* @returns The count of newly added addresses (excluding duplicates)
|
|
3280
|
+
* Get all agent sessions.
|
|
1800
3281
|
*/
|
|
1801
|
-
|
|
3282
|
+
getSessions(): AgentSession[];
|
|
1802
3283
|
/**
|
|
1803
|
-
*
|
|
1804
|
-
* Clears existing entries and rebuilds from the provided array.
|
|
1805
|
-
*
|
|
1806
|
-
* @param addresses - The new complete list of sanctioned addresses
|
|
3284
|
+
* End an active agent session. Records the termination in the digest chain.
|
|
1807
3285
|
*/
|
|
1808
|
-
|
|
3286
|
+
endSession(sessionId: string): Promise<AgentSession>;
|
|
1809
3287
|
/**
|
|
1810
|
-
*
|
|
1811
|
-
*
|
|
1812
|
-
* @returns The size of the current sanctions list
|
|
3288
|
+
* Check whether an action is within a session's delegated scope.
|
|
1813
3289
|
*/
|
|
1814
|
-
|
|
1815
|
-
private static checkTokenType;
|
|
1816
|
-
private static checkChainSupport;
|
|
1817
|
-
private static checkAddressFormat;
|
|
1818
|
-
private static checkAmountValid;
|
|
1819
|
-
private static checkSanctions;
|
|
1820
|
-
private static checkEnhancedDueDiligence;
|
|
1821
|
-
private static checkReportingThreshold;
|
|
1822
|
-
private static generateRecommendations;
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
declare class PaymentCompliance {
|
|
3290
|
+
validateScope(sessionId: string, action: string): boolean;
|
|
1826
3291
|
/**
|
|
1827
|
-
*
|
|
1828
|
-
*
|
|
1829
|
-
* @param input - Payment to evaluate
|
|
1830
|
-
* @returns UsdcComplianceCheck with pass/fail results and recommendations
|
|
3292
|
+
* Check whether a transaction meets session constraints.
|
|
1831
3293
|
*/
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
/**
|
|
1841
|
-
* In-memory data store for the Kontext SDK.
|
|
1842
|
-
* Holds all action logs, transactions, tasks, and anomaly events.
|
|
1843
|
-
*
|
|
1844
|
-
* When a StorageAdapter is provided, call `flush()` to persist state
|
|
1845
|
-
* and `restore()` to reload from storage.
|
|
1846
|
-
*/
|
|
1847
|
-
declare class KontextStore {
|
|
1848
|
-
private actions;
|
|
1849
|
-
private transactions;
|
|
1850
|
-
private tasks;
|
|
1851
|
-
private anomalies;
|
|
1852
|
-
private storageAdapter;
|
|
1853
|
-
private readonly maxEntries;
|
|
1854
|
-
constructor(maxEntries?: number);
|
|
3294
|
+
validateConstraints(sessionId: string, input: {
|
|
3295
|
+
amount?: string;
|
|
3296
|
+
chain?: string;
|
|
3297
|
+
token?: string;
|
|
3298
|
+
to?: string;
|
|
3299
|
+
}): boolean;
|
|
1855
3300
|
/**
|
|
1856
|
-
*
|
|
1857
|
-
*
|
|
1858
|
-
* @param adapter - The storage backend to use
|
|
3301
|
+
* Create a provenance checkpoint -- a review point where a human
|
|
3302
|
+
* can attest to a batch of agent actions.
|
|
1859
3303
|
*/
|
|
1860
|
-
|
|
3304
|
+
createCheckpoint(input: CreateCheckpointInput): Promise<ProvenanceCheckpoint>;
|
|
1861
3305
|
/**
|
|
1862
|
-
*
|
|
3306
|
+
* Attach an externally-produced human attestation to a checkpoint.
|
|
3307
|
+
* The attestation includes a cryptographic signature that the agent
|
|
3308
|
+
* never touches -- key separation is the critical security property.
|
|
1863
3309
|
*/
|
|
1864
|
-
|
|
3310
|
+
attachAttestation(checkpointId: string, attestation: HumanAttestation): Promise<ProvenanceCheckpoint>;
|
|
1865
3311
|
/**
|
|
1866
|
-
*
|
|
1867
|
-
* No-op if no adapter is attached.
|
|
3312
|
+
* Get a checkpoint by ID. Automatically marks expired checkpoints.
|
|
1868
3313
|
*/
|
|
1869
|
-
|
|
3314
|
+
getCheckpoint(checkpointId: string): ProvenanceCheckpoint | undefined;
|
|
1870
3315
|
/**
|
|
1871
|
-
*
|
|
1872
|
-
* Merges loaded data with any existing in-memory data.
|
|
1873
|
-
* No-op if no adapter is attached.
|
|
3316
|
+
* Get all checkpoints, optionally filtered by session.
|
|
1874
3317
|
*/
|
|
1875
|
-
|
|
1876
|
-
/**
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
/** Retrieve actions filtered by a predicate. */
|
|
1881
|
-
queryActions(predicate: (action: ActionLog) => boolean): ActionLog[];
|
|
1882
|
-
/** Get actions for a specific agent. */
|
|
1883
|
-
getActionsByAgent(agentId: string): ActionLog[];
|
|
1884
|
-
/** Get actions for a specific session (across all agents). */
|
|
1885
|
-
getActionsBySession(sessionId: string): ActionLog[];
|
|
1886
|
-
/** Append a transaction record. Evicts oldest 10% when maxEntries is exceeded. */
|
|
1887
|
-
addTransaction(tx: TransactionRecord): void;
|
|
1888
|
-
/** Retrieve all transaction records. */
|
|
1889
|
-
getTransactions(): TransactionRecord[];
|
|
1890
|
-
/** Retrieve transactions filtered by a predicate. */
|
|
1891
|
-
queryTransactions(predicate: (tx: TransactionRecord) => boolean): TransactionRecord[];
|
|
1892
|
-
/** Get transactions for a specific agent. */
|
|
1893
|
-
getTransactionsByAgent(agentId: string): TransactionRecord[];
|
|
1894
|
-
/** Get the most recent N transactions for an agent. */
|
|
1895
|
-
getRecentTransactions(agentId: string, limit: number): TransactionRecord[];
|
|
1896
|
-
/** Store a task. */
|
|
1897
|
-
addTask(task: Task): void;
|
|
1898
|
-
/** Retrieve a task by ID. */
|
|
1899
|
-
getTask(taskId: string): Task | undefined;
|
|
1900
|
-
/** Update a task. */
|
|
1901
|
-
updateTask(taskId: string, updates: Partial<Task>): Task | undefined;
|
|
1902
|
-
/** Retrieve all tasks. */
|
|
1903
|
-
getTasks(): Task[];
|
|
1904
|
-
/** Retrieve tasks filtered by a predicate. */
|
|
1905
|
-
queryTasks(predicate: (task: Task) => boolean): Task[];
|
|
1906
|
-
/** Append an anomaly event. Evicts oldest 10% when maxEntries is exceeded. */
|
|
1907
|
-
addAnomaly(anomaly: AnomalyEvent): void;
|
|
1908
|
-
/** Retrieve all anomaly events. */
|
|
1909
|
-
getAnomalies(): AnomalyEvent[];
|
|
1910
|
-
/** Retrieve anomalies filtered by a predicate. */
|
|
1911
|
-
queryAnomalies(predicate: (anomaly: AnomalyEvent) => boolean): AnomalyEvent[];
|
|
1912
|
-
/** Get total record counts across all stores. */
|
|
1913
|
-
getCounts(): {
|
|
1914
|
-
actions: number;
|
|
1915
|
-
transactions: number;
|
|
1916
|
-
tasks: number;
|
|
1917
|
-
anomalies: number;
|
|
1918
|
-
};
|
|
1919
|
-
/** Clear all stored data. Useful for testing. */
|
|
1920
|
-
clear(): void;
|
|
3318
|
+
getCheckpoints(sessionId?: string): ProvenanceCheckpoint[];
|
|
3319
|
+
/**
|
|
3320
|
+
* Export the full provenance bundle for a session.
|
|
3321
|
+
*/
|
|
3322
|
+
getProvenanceBundle(sessionId: string): ProvenanceBundle;
|
|
1921
3323
|
}
|
|
1922
3324
|
|
|
1923
3325
|
/** Pre-fetched data for a single agent, passed to factor methods to avoid redundant store queries. */
|
|
@@ -2182,4 +3584,454 @@ declare class AnomalyDetector {
|
|
|
2182
3584
|
private notifyCallbacks;
|
|
2183
3585
|
}
|
|
2184
3586
|
|
|
2185
|
-
|
|
3587
|
+
/**
|
|
3588
|
+
* OFAC SDN Address Provider.
|
|
3589
|
+
*
|
|
3590
|
+
* Screens blockchain addresses against the U.S. Treasury OFAC Specially
|
|
3591
|
+
* Designated Nationals (SDN) list. Uses ~33 hardcoded addresses from
|
|
3592
|
+
* the public SDN list. Distinguishes between actively sanctioned and
|
|
3593
|
+
* delisted (formerly sanctioned) addresses.
|
|
3594
|
+
*
|
|
3595
|
+
* - **Free tier**, no API key required
|
|
3596
|
+
* - **Browser-safe** — pure in-memory lookups
|
|
3597
|
+
* - O(1) Set lookup, case-insensitive
|
|
3598
|
+
*
|
|
3599
|
+
* @example
|
|
3600
|
+
* ```typescript
|
|
3601
|
+
* const provider = new OFACAddressProvider();
|
|
3602
|
+
* const result = await provider.screen('0x098B716B8Aaf21512996dC57EB0615e2383E2f96');
|
|
3603
|
+
* // result.hit === true (Lazarus Group, OFAC sanctioned)
|
|
3604
|
+
* ```
|
|
3605
|
+
*/
|
|
3606
|
+
declare class OFACAddressProvider implements ScreeningProvider {
|
|
3607
|
+
readonly id = "ofac-sdn-address";
|
|
3608
|
+
readonly name = "OFAC SDN Address Screener";
|
|
3609
|
+
readonly lists: readonly SanctionsList[];
|
|
3610
|
+
readonly requiresApiKey = false;
|
|
3611
|
+
readonly browserCompatible = true;
|
|
3612
|
+
readonly queryTypes: readonly QueryType[];
|
|
3613
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3614
|
+
isAvailable(): boolean;
|
|
3615
|
+
getEntryCount(): number;
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
/**
|
|
3619
|
+
* OFAC SDN Entity Name Provider.
|
|
3620
|
+
*
|
|
3621
|
+
* Screens entity/person names against the full OFAC SDN entity database
|
|
3622
|
+
* (18,664 entities) using fuzzy string matching. Wraps the existing
|
|
3623
|
+
* `OFACSanctionsScreener` from `ofac-sanctions.ts`.
|
|
3624
|
+
*
|
|
3625
|
+
* - **Free tier**, no API key required
|
|
3626
|
+
* - **Node.js only** — loads full SDN data, too large for browser
|
|
3627
|
+
* - Fuzzy matching at 0.85 threshold with minimum 4-char match length
|
|
3628
|
+
* - Distinguishes between active and delisted entities
|
|
3629
|
+
*
|
|
3630
|
+
* @example
|
|
3631
|
+
* ```typescript
|
|
3632
|
+
* const provider = new OFACEntityProvider();
|
|
3633
|
+
* if (provider.isAvailable()) {
|
|
3634
|
+
* const result = await provider.screen('Lazarus Group');
|
|
3635
|
+
* // result.hit === true
|
|
3636
|
+
* }
|
|
3637
|
+
* ```
|
|
3638
|
+
*/
|
|
3639
|
+
declare class OFACEntityProvider implements ScreeningProvider {
|
|
3640
|
+
readonly id = "ofac-sdn-entity";
|
|
3641
|
+
readonly name = "OFAC SDN Entity Screener";
|
|
3642
|
+
readonly lists: readonly SanctionsList[];
|
|
3643
|
+
readonly requiresApiKey = false;
|
|
3644
|
+
readonly browserCompatible = false;
|
|
3645
|
+
readonly queryTypes: readonly QueryType[];
|
|
3646
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3647
|
+
isAvailable(): boolean;
|
|
3648
|
+
getEntryCount(): number;
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
/**
|
|
3652
|
+
* UK OFSI Address Provider.
|
|
3653
|
+
*
|
|
3654
|
+
* Screens blockchain addresses against the UK OFSI Consolidated List.
|
|
3655
|
+
* Coverage is limited compared to OFAC — most UK sanctions are entity-name-based.
|
|
3656
|
+
* For comprehensive UK entity screening, use OpenSanctionsProvider.
|
|
3657
|
+
*
|
|
3658
|
+
* - **Free tier**, no API key required
|
|
3659
|
+
* - **Browser-safe** — pure in-memory lookups
|
|
3660
|
+
*
|
|
3661
|
+
* @example
|
|
3662
|
+
* ```typescript
|
|
3663
|
+
* const provider = new UKOFSIProvider();
|
|
3664
|
+
* const result = await provider.screen('0x098B716B8Aaf21512996dC57EB0615e2383E2f96');
|
|
3665
|
+
* // result.hit === true (Lazarus Group, OFSI designated)
|
|
3666
|
+
* ```
|
|
3667
|
+
*/
|
|
3668
|
+
declare class UKOFSIProvider implements ScreeningProvider {
|
|
3669
|
+
readonly id = "uk-ofsi-address";
|
|
3670
|
+
readonly name = "UK OFSI Address Screener";
|
|
3671
|
+
readonly lists: readonly SanctionsList[];
|
|
3672
|
+
readonly requiresApiKey = false;
|
|
3673
|
+
readonly browserCompatible = true;
|
|
3674
|
+
readonly queryTypes: readonly QueryType[];
|
|
3675
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3676
|
+
isAvailable(): boolean;
|
|
3677
|
+
getEntryCount(): number;
|
|
3678
|
+
}
|
|
3679
|
+
|
|
3680
|
+
/**
|
|
3681
|
+
* OpenSanctions Local Provider.
|
|
3682
|
+
*
|
|
3683
|
+
* Screens addresses and entity names against locally-synced OpenSanctions
|
|
3684
|
+
* bulk data (331+ sources including APAC domestic lists).
|
|
3685
|
+
*
|
|
3686
|
+
* Data is NOT bundled — developers download via `kontext sync` and handle
|
|
3687
|
+
* their own OpenSanctions licensing (CC-BY-NC 4.0 for non-commercial,
|
|
3688
|
+
* commercial license for business use).
|
|
3689
|
+
*
|
|
3690
|
+
* - **Free tier**, no API key required
|
|
3691
|
+
* - **Node.js only** — reads from local filesystem
|
|
3692
|
+
* - Supports address + entity name queries
|
|
3693
|
+
*
|
|
3694
|
+
* @example
|
|
3695
|
+
* ```typescript
|
|
3696
|
+
* const provider = new OpenSanctionsLocalProvider();
|
|
3697
|
+
* if (provider.isAvailable()) {
|
|
3698
|
+
* const result = await provider.screen('Lazarus Group');
|
|
3699
|
+
* // result.hit === true if match found in local data
|
|
3700
|
+
* }
|
|
3701
|
+
* ```
|
|
3702
|
+
*/
|
|
3703
|
+
declare class OpenSanctionsLocalProvider implements ScreeningProvider {
|
|
3704
|
+
readonly id = "opensanctions-local";
|
|
3705
|
+
readonly name = "OpenSanctions (Local Data)";
|
|
3706
|
+
readonly lists: readonly SanctionsList[];
|
|
3707
|
+
readonly requiresApiKey = false;
|
|
3708
|
+
readonly browserCompatible = false;
|
|
3709
|
+
readonly queryTypes: readonly QueryType[];
|
|
3710
|
+
private dataDir;
|
|
3711
|
+
private entities;
|
|
3712
|
+
private addressSet;
|
|
3713
|
+
private addressToEntity;
|
|
3714
|
+
private loaded;
|
|
3715
|
+
constructor(dataDir?: string);
|
|
3716
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3717
|
+
isAvailable(): boolean;
|
|
3718
|
+
getEntryCount(): number;
|
|
3719
|
+
sync(): Promise<{
|
|
3720
|
+
updated: boolean;
|
|
3721
|
+
count: number;
|
|
3722
|
+
}>;
|
|
3723
|
+
private screenAddress;
|
|
3724
|
+
private screenEntityName;
|
|
3725
|
+
private entityToMatch;
|
|
3726
|
+
private getEntityStatus;
|
|
3727
|
+
private loadData;
|
|
3728
|
+
private resolveDataDir;
|
|
3729
|
+
}
|
|
3730
|
+
|
|
3731
|
+
/**
|
|
3732
|
+
* OpenSanctions REST API Provider.
|
|
3733
|
+
*
|
|
3734
|
+
* Screens both blockchain addresses AND entity names via the OpenSanctions
|
|
3735
|
+
* `/match` endpoint. Covers 331+ sanctions sources worldwide including
|
|
3736
|
+
* OFAC, EU, UN, UK, and APAC domestic lists.
|
|
3737
|
+
*
|
|
3738
|
+
* - **Free tier** in Kontext (metered by events)
|
|
3739
|
+
* - **Requires API key** from OpenSanctions (developer brings own key)
|
|
3740
|
+
* - **NOT browser-compatible** — requires server-side API calls
|
|
3741
|
+
*
|
|
3742
|
+
* @example
|
|
3743
|
+
* ```typescript
|
|
3744
|
+
* const provider = new OpenSanctionsProvider({
|
|
3745
|
+
* apiKey: process.env.OPENSANCTIONS_API_KEY!,
|
|
3746
|
+
* });
|
|
3747
|
+
* const result = await provider.screen('Lazarus Group');
|
|
3748
|
+
* ```
|
|
3749
|
+
*/
|
|
3750
|
+
declare class OpenSanctionsProvider implements ScreeningProvider {
|
|
3751
|
+
readonly id = "opensanctions-api";
|
|
3752
|
+
readonly name = "OpenSanctions (API)";
|
|
3753
|
+
readonly lists: readonly SanctionsList[];
|
|
3754
|
+
readonly requiresApiKey = true;
|
|
3755
|
+
readonly browserCompatible = false;
|
|
3756
|
+
readonly queryTypes: readonly QueryType[];
|
|
3757
|
+
private readonly apiKey;
|
|
3758
|
+
private readonly baseUrl;
|
|
3759
|
+
private readonly dataset;
|
|
3760
|
+
constructor(config: {
|
|
3761
|
+
apiKey: string;
|
|
3762
|
+
baseUrl?: string;
|
|
3763
|
+
dataset?: string;
|
|
3764
|
+
});
|
|
3765
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3766
|
+
isAvailable(): boolean;
|
|
3767
|
+
}
|
|
3768
|
+
/**
|
|
3769
|
+
* Chainalysis Free API Provider.
|
|
3770
|
+
*
|
|
3771
|
+
* Screens blockchain addresses via the Chainalysis free screening API.
|
|
3772
|
+
* Address-only — does not support entity name screening.
|
|
3773
|
+
*
|
|
3774
|
+
* - **Free tier** in Kontext (metered by events)
|
|
3775
|
+
* - **Requires API key** from Chainalysis (developer brings own key)
|
|
3776
|
+
* - **NOT browser-compatible** — requires server-side API calls
|
|
3777
|
+
*
|
|
3778
|
+
* @example
|
|
3779
|
+
* ```typescript
|
|
3780
|
+
* const provider = new ChainalysisFreeAPIProvider({
|
|
3781
|
+
* apiKey: process.env.CHAINALYSIS_API_KEY!,
|
|
3782
|
+
* });
|
|
3783
|
+
* const result = await provider.screen('0x098B716B8Aaf21512996dC57EB0615e2383E2f96');
|
|
3784
|
+
* ```
|
|
3785
|
+
*/
|
|
3786
|
+
declare class ChainalysisFreeAPIProvider implements ScreeningProvider {
|
|
3787
|
+
readonly id = "chainalysis-free-api";
|
|
3788
|
+
readonly name = "Chainalysis Free API";
|
|
3789
|
+
readonly lists: readonly SanctionsList[];
|
|
3790
|
+
readonly requiresApiKey = true;
|
|
3791
|
+
readonly browserCompatible = false;
|
|
3792
|
+
readonly queryTypes: readonly QueryType[];
|
|
3793
|
+
private readonly apiKey;
|
|
3794
|
+
private readonly baseUrl;
|
|
3795
|
+
constructor(config: {
|
|
3796
|
+
apiKey: string;
|
|
3797
|
+
baseUrl?: string;
|
|
3798
|
+
});
|
|
3799
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3800
|
+
isAvailable(): boolean;
|
|
3801
|
+
}
|
|
3802
|
+
|
|
3803
|
+
/**
|
|
3804
|
+
* Chainalysis OFAC Oracle Provider.
|
|
3805
|
+
*
|
|
3806
|
+
* Screens blockchain addresses against the Chainalysis sanctions oracle,
|
|
3807
|
+
* which tracks OFAC SDN addresses. Supports two modes:
|
|
3808
|
+
*
|
|
3809
|
+
* 1. **REST API mode** (default): Queries the Chainalysis screening API
|
|
3810
|
+
* 2. **On-chain mode**: Queries the on-chain oracle contract via eth_call
|
|
3811
|
+
* (requires an Ethereum RPC URL)
|
|
3812
|
+
*
|
|
3813
|
+
* - **Free tier** in Kontext (metered by events)
|
|
3814
|
+
* - **Requires API key** (REST mode) or **RPC URL** (on-chain mode)
|
|
3815
|
+
* - **NOT browser-compatible** — requires server-side calls
|
|
3816
|
+
*
|
|
3817
|
+
* @example
|
|
3818
|
+
* ```typescript
|
|
3819
|
+
* // REST API mode
|
|
3820
|
+
* const provider = new ChainalysisOracleProvider({
|
|
3821
|
+
* apiKey: process.env.CHAINALYSIS_API_KEY!,
|
|
3822
|
+
* });
|
|
3823
|
+
*
|
|
3824
|
+
* // On-chain mode
|
|
3825
|
+
* const provider = new ChainalysisOracleProvider({
|
|
3826
|
+
* rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY',
|
|
3827
|
+
* });
|
|
3828
|
+
* ```
|
|
3829
|
+
*/
|
|
3830
|
+
declare class ChainalysisOracleProvider implements ScreeningProvider {
|
|
3831
|
+
readonly id = "chainalysis-oracle";
|
|
3832
|
+
readonly name = "Chainalysis OFAC Oracle";
|
|
3833
|
+
readonly lists: readonly SanctionsList[];
|
|
3834
|
+
readonly requiresApiKey = true;
|
|
3835
|
+
readonly browserCompatible = false;
|
|
3836
|
+
readonly queryTypes: readonly QueryType[];
|
|
3837
|
+
private readonly apiKey;
|
|
3838
|
+
private readonly rpcUrl;
|
|
3839
|
+
private readonly apiBaseUrl;
|
|
3840
|
+
constructor(config: {
|
|
3841
|
+
apiKey?: string;
|
|
3842
|
+
rpcUrl?: string;
|
|
3843
|
+
apiBaseUrl?: string;
|
|
3844
|
+
});
|
|
3845
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3846
|
+
isAvailable(): boolean;
|
|
3847
|
+
private screenOnChain;
|
|
3848
|
+
private screenApi;
|
|
3849
|
+
private errorResult;
|
|
3850
|
+
}
|
|
3851
|
+
|
|
3852
|
+
type ConsensusStrategy = 'ANY_MATCH' | 'ALL_MATCH' | 'MAJORITY';
|
|
3853
|
+
interface ScreeningAggregatorConfig {
|
|
3854
|
+
providers: ScreeningProvider[];
|
|
3855
|
+
consensus?: ConsensusStrategy;
|
|
3856
|
+
blocklist?: string[];
|
|
3857
|
+
allowlist?: string[];
|
|
3858
|
+
continueOnError?: boolean;
|
|
3859
|
+
providerTimeoutMs?: number;
|
|
3860
|
+
onEvent?: () => void;
|
|
3861
|
+
providerRateLimitPerSec?: number;
|
|
3862
|
+
}
|
|
3863
|
+
interface AggregatedScreeningResult {
|
|
3864
|
+
providerId: string;
|
|
3865
|
+
hit: boolean;
|
|
3866
|
+
matches: ScreeningMatch[];
|
|
3867
|
+
listsChecked: readonly SanctionsList[];
|
|
3868
|
+
entriesSearched: number;
|
|
3869
|
+
durationMs: number;
|
|
3870
|
+
queryType: QueryType;
|
|
3871
|
+
totalProviders: number;
|
|
3872
|
+
hitCount: number;
|
|
3873
|
+
consensus: ConsensusStrategy;
|
|
3874
|
+
blocklisted?: boolean;
|
|
3875
|
+
allowlisted?: boolean;
|
|
3876
|
+
errors: Array<{
|
|
3877
|
+
providerId: string;
|
|
3878
|
+
error: string;
|
|
3879
|
+
}>;
|
|
3880
|
+
uncoveredLists: SanctionsList[];
|
|
3881
|
+
providerResults: ScreeningResult[];
|
|
3882
|
+
}
|
|
3883
|
+
/**
|
|
3884
|
+
* Multi-provider screening orchestrator.
|
|
3885
|
+
*
|
|
3886
|
+
* Routes queries to compatible providers based on auto-detected query type,
|
|
3887
|
+
* applies consensus strategy, and tracks jurisdiction coverage.
|
|
3888
|
+
*
|
|
3889
|
+
* @example
|
|
3890
|
+
* ```typescript
|
|
3891
|
+
* const agg = new ScreeningAggregator({
|
|
3892
|
+
* providers: [new OFACAddressProvider(), new UKOFSIProvider()],
|
|
3893
|
+
* consensus: 'ANY_MATCH',
|
|
3894
|
+
* onEvent: () => planManager.recordEvent(),
|
|
3895
|
+
* });
|
|
3896
|
+
*
|
|
3897
|
+
* const result = await agg.screen('0x098B716B8Aaf21512996dC57EB0615e2383E2f96');
|
|
3898
|
+
* ```
|
|
3899
|
+
*/
|
|
3900
|
+
declare class ScreeningAggregator {
|
|
3901
|
+
private readonly providers;
|
|
3902
|
+
private readonly consensus;
|
|
3903
|
+
private readonly blocklistSet;
|
|
3904
|
+
private readonly allowlistSet;
|
|
3905
|
+
private readonly continueOnError;
|
|
3906
|
+
private readonly providerTimeoutMs;
|
|
3907
|
+
private readonly onEvent;
|
|
3908
|
+
constructor(config: ScreeningAggregatorConfig);
|
|
3909
|
+
/**
|
|
3910
|
+
* Screen a single query (address or entity name).
|
|
3911
|
+
*/
|
|
3912
|
+
screen(query: string, context?: ScreeningContext): Promise<AggregatedScreeningResult>;
|
|
3913
|
+
/**
|
|
3914
|
+
* Screen multiple queries in batch.
|
|
3915
|
+
*/
|
|
3916
|
+
screenBatch(queries: string[], context?: ScreeningContext): Promise<Map<string, AggregatedScreeningResult>>;
|
|
3917
|
+
/**
|
|
3918
|
+
* Get available providers, optionally filtered by query type.
|
|
3919
|
+
*/
|
|
3920
|
+
getAvailableProviders(queryType?: QueryType): ScreeningProvider[];
|
|
3921
|
+
/**
|
|
3922
|
+
* Get the union of all sanctions lists covered by available providers.
|
|
3923
|
+
*/
|
|
3924
|
+
getCoveredLists(): SanctionsList[];
|
|
3925
|
+
private runWithTimeout;
|
|
3926
|
+
private buildResult;
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3929
|
+
/** Minimal WalletClient shape — avoids hard type dependency on viem */
|
|
3930
|
+
interface WalletClientLike {
|
|
3931
|
+
sendTransaction: (args: any) => Promise<`0x${string}`>;
|
|
3932
|
+
writeContract?: (args: any) => Promise<`0x${string}`>;
|
|
3933
|
+
chain?: {
|
|
3934
|
+
id: number;
|
|
3935
|
+
name?: string;
|
|
3936
|
+
};
|
|
3937
|
+
account?: {
|
|
3938
|
+
address: `0x${string}`;
|
|
3939
|
+
};
|
|
3940
|
+
extend: <T>(fn: (client: any) => T) => any;
|
|
3941
|
+
}
|
|
3942
|
+
/** Minimal Kontext interface needed by the interceptor */
|
|
3943
|
+
interface KontextForInterceptor {
|
|
3944
|
+
verify(input: VerifyInput): Promise<VerifyResult>;
|
|
3945
|
+
getConfig(): {
|
|
3946
|
+
agentId?: string;
|
|
3947
|
+
interceptorMode?: string;
|
|
3948
|
+
policy?: {
|
|
3949
|
+
allowedTokens?: Token[];
|
|
3950
|
+
};
|
|
3951
|
+
};
|
|
3952
|
+
getWalletMonitor?(): WalletMonitor | null;
|
|
3953
|
+
}
|
|
3954
|
+
/** Options for the viem auto-instrumentation decorator */
|
|
3955
|
+
interface ViemInstrumentationOptions {
|
|
3956
|
+
/** Agent ID to attribute transactions to */
|
|
3957
|
+
agentId?: string;
|
|
3958
|
+
/** Session ID for grouping transactions */
|
|
3959
|
+
sessionId?: string;
|
|
3960
|
+
/** Tokens to instrument (default: all known) */
|
|
3961
|
+
tokens?: Token[];
|
|
3962
|
+
/** Chains to instrument (default: all known) */
|
|
3963
|
+
chains?: Chain[];
|
|
3964
|
+
/** Compliance mode (default: reads from config, falls back to 'post-send') */
|
|
3965
|
+
mode?: 'post-send' | 'pre-send' | 'both';
|
|
3966
|
+
/** Called after verify() succeeds */
|
|
3967
|
+
onVerify?: (result: VerifyResult, txHash: string) => void | Promise<void>;
|
|
3968
|
+
/** Called when verify() fails */
|
|
3969
|
+
onError?: (error: Error, txHash: string) => void | Promise<void>;
|
|
3970
|
+
/** Additional metadata for every verify() call */
|
|
3971
|
+
metadata?: Record<string, unknown>;
|
|
3972
|
+
}
|
|
3973
|
+
/**
|
|
3974
|
+
* Thrown in pre-send mode when compliance screening fails.
|
|
3975
|
+
*/
|
|
3976
|
+
declare class ViemComplianceError extends Error {
|
|
3977
|
+
readonly result: VerifyResult;
|
|
3978
|
+
readonly from: string;
|
|
3979
|
+
readonly to: string;
|
|
3980
|
+
readonly amount: string;
|
|
3981
|
+
constructor(message: string, result: VerifyResult, details: {
|
|
3982
|
+
from: string;
|
|
3983
|
+
to: string;
|
|
3984
|
+
amount: string;
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
/**
|
|
3988
|
+
* Wraps a viem WalletClient with Kontext auto-instrumentation.
|
|
3989
|
+
* Every stablecoin transfer is automatically compliance-checked via verify().
|
|
3990
|
+
*
|
|
3991
|
+
* Reads defaults from kontext.getConfig() — options override config values.
|
|
3992
|
+
*/
|
|
3993
|
+
declare function withKontextCompliance<TClient extends WalletClientLike>(client: TClient, kontext: KontextForInterceptor, options?: Partial<ViemInstrumentationOptions>): TClient;
|
|
3994
|
+
|
|
3995
|
+
interface StablecoinContractInfo {
|
|
3996
|
+
token: Token;
|
|
3997
|
+
chain: Chain;
|
|
3998
|
+
decimals: number;
|
|
3999
|
+
}
|
|
4000
|
+
/**
|
|
4001
|
+
* Known stablecoin contract addresses indexed by lowercased address.
|
|
4002
|
+
* Used for O(1) detection of whether a transaction targets a stablecoin.
|
|
4003
|
+
*/
|
|
4004
|
+
declare const STABLECOIN_CONTRACTS: Record<string, StablecoinContractInfo>;
|
|
4005
|
+
/**
|
|
4006
|
+
* Maps viem chain IDs to Kontext Chain strings.
|
|
4007
|
+
*/
|
|
4008
|
+
declare const CHAIN_ID_MAP: Record<number, Chain>;
|
|
4009
|
+
|
|
4010
|
+
/** Shape of the kontext.config.json file */
|
|
4011
|
+
interface KontextConfigFile {
|
|
4012
|
+
$schema?: string;
|
|
4013
|
+
projectId: string;
|
|
4014
|
+
agentId?: string;
|
|
4015
|
+
environment?: Environment;
|
|
4016
|
+
wallets?: string[];
|
|
4017
|
+
tokens?: Token[];
|
|
4018
|
+
chains?: Chain[];
|
|
4019
|
+
rpcEndpoints?: Partial<Record<Chain, string>>;
|
|
4020
|
+
mode?: 'post-send' | 'pre-send' | 'both';
|
|
4021
|
+
corridors?: {
|
|
4022
|
+
from?: string;
|
|
4023
|
+
to?: string;
|
|
4024
|
+
};
|
|
4025
|
+
thresholds?: {
|
|
4026
|
+
alertAmount?: string;
|
|
4027
|
+
ctrAmount?: string;
|
|
4028
|
+
};
|
|
4029
|
+
apiKey?: string;
|
|
4030
|
+
}
|
|
4031
|
+
/**
|
|
4032
|
+
* Discover and load kontext.config.json by walking up from startDir.
|
|
4033
|
+
* Returns the parsed config file contents, or null if not found.
|
|
4034
|
+
*/
|
|
4035
|
+
declare function loadConfigFile(startDir?: string): KontextConfigFile | null;
|
|
4036
|
+
|
|
4037
|
+
export { type ActionLog, type AgentCard, type AgentData, type AgentIdentity, AgentIdentityRegistry, type AgentLink, type AgentSession, type AggregatedScreeningResult, type AnchorResult, type AnchorVerification, type AnomalyCallback, type AnomalyDetectionConfig, AnomalyDetector, type AnomalyEvent, type AnomalyRuleType, type AnomalySeverity, type AnomalyThresholds, type AttestationDecision, type AttestationPayload, type AttestationRequest, type AttestationResponse, type AttestationSignature, type BehavioralEmbedding, BehavioralFingerprinter, CHAIN_ID_MAP, CURRENCY_REQUIRED_LISTS, type Chain, ChainalysisFreeAPIProvider, ChainalysisOracleProvider, type CheckpointStatus, type ClusteringEvidence, type ClusteringHeuristic, type ComplianceCertificate, type ComplianceCheckResult, type ComplianceReport, type ConfirmTaskInput, type ConsensusStrategy, ConsoleExporter, type CounterpartyAttestation, type CounterpartyConfig, type CreateCheckpointInput, type CreateSessionInput, type CreateTaskInput, CrossSessionLinker, type CrossSessionLinkerConfig, type DateRange, DigestChain, type DigestLink, type DigestVerification, type ERC8021Attribution, type ERC8021Config, type EntityStatus, type EntityType, type Environment, type EventExporter, type ExportFormat, type ExportOptions, type ExportResult, type ExporterResult, type FeatureFlag, type FeatureFlagConfig, FeatureFlagManager, FileStorage, type FinancialFeatures, type FlagPlanTargeting, type FlagScope, type FlagTargeting, type GatedFeature, type GenerateComplianceCertificateInput, type HumanAttestation, JsonFileExporter, type Jurisdiction, KONTEXT_BUILDER_CODE, type KYAConfidenceLevel, type KYAConfidenceScore, KYAConfidenceScorer, type KYAConfidenceScorerConfig, type KYAEnvelope, type KYAScoreComponent, type KYCProviderReference, type KYCStatus, Kontext, type KontextConfig, KontextError, KontextErrorCode, type KontextMode, type LimitEvent, type LinkSignal, type LinkStatus, type LogActionInput, type LogLevel, type LogReasoningInput, type LogTransactionInput, type MatchType, MemoryStorage, type MetadataValidator, type NetworkFeatures, NoopExporter, OFACAddressProvider, OFACEntityProvider, type OnChainAnchorConfig, OnChainExporter, OpenSanctionsLocalProvider, OpenSanctionsProvider, type OperationalFeatures, PLAN_LIMITS, PaymentCompliance, type PlanConfig, PlanManager, type PlanTier, type PlanUsage, type PolicyConfig, type PrecisionTimestamp, type ProvenanceAction, type ProvenanceAttestor, type ProvenanceBundle, type ProvenanceBundleVerification, type ProvenanceCheckpoint, ProvenanceManager, type QueryType, type ReasoningEntry, type RegisterIdentityInput, type ReportOptions, type ReportType, type RiskFactor, STABLECOIN_CONTRACTS, type SanctionsCheckResult, type SanctionsList, ScreeningAggregator, type ScreeningAggregatorConfig, type ScreeningConfig, type ScreeningContext, type ScreeningMatch, type ScreeningProvider, type ScreeningResult, type SessionConstraints, type SessionStatus, type StorageAdapter, TOKEN_REQUIRED_LISTS, type Task, type TaskEvidence, type TaskStatus, type TemporalFeatures, type Token, type TransactionEvaluation, type TransactionRecord, type TrustFactor, type TrustScore, TrustScorer, UKOFSIProvider, type UpdateIdentityInput, UsdcCompliance, type UsdcComplianceCheck, type VerificationKey, type VerifyInput, type VerifyResult, ViemComplianceError, type ViemInstrumentationOptions, type WalletClientLike, type WalletCluster, WalletClusterer, type WalletClusteringConfig, type WalletMapping, WalletMonitor, type WalletMonitoringConfig, anchorDigest, encodeERC8021Suffix, exchangeAttestation, fetchAgentCard, fetchTransactionAttribution, getAnchor, getRequiredLists, isBlockchainAddress, isCryptoTransaction, isFeatureAvailable, loadConfigFile, parseERC8021Suffix, providerSupportsQuery, requirePlan, verifyAnchor, verifyExportedChain, withKontextCompliance };
|