kontext-sdk 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -0
- package/dist/index.d.mts +1713 -196
- package/dist/index.d.ts +1713 -196
- package/dist/index.js +3219 -138
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3198 -139
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -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,74 @@ 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
|
+
/** Screening configuration for pluggable multi-provider sanctions screening */
|
|
439
|
+
interface ScreeningConfig {
|
|
440
|
+
/** Screening providers to use */
|
|
441
|
+
providers: ScreeningProvider[];
|
|
442
|
+
/** How to combine results from multiple providers (default: 'ANY_MATCH') */
|
|
443
|
+
consensus?: 'ANY_MATCH' | 'ALL_MATCH' | 'MAJORITY';
|
|
444
|
+
/** Addresses or entity names to always block */
|
|
445
|
+
blocklist?: string[];
|
|
446
|
+
/** Addresses or entity names to always allow (overrides provider hits) */
|
|
447
|
+
allowlist?: string[];
|
|
448
|
+
/** Per-provider timeout in milliseconds (default: 5000) */
|
|
449
|
+
providerTimeoutMs?: number;
|
|
450
|
+
}
|
|
451
|
+
/** Compliance policy configuration */
|
|
452
|
+
interface PolicyConfig {
|
|
453
|
+
/** Customizable compliance thresholds */
|
|
454
|
+
thresholds?: {
|
|
455
|
+
/** Enhanced Due Diligence threshold (default: 3000) */
|
|
456
|
+
edd?: number;
|
|
457
|
+
/** CTR reporting threshold (default: 10000) */
|
|
458
|
+
reporting?: number;
|
|
459
|
+
/** Large transaction threshold (default: 50000) */
|
|
460
|
+
largeTransaction?: number;
|
|
461
|
+
};
|
|
462
|
+
/** Restrict to specific tokens */
|
|
463
|
+
allowedTokens?: Token[];
|
|
464
|
+
/** Restrict to specific currencies */
|
|
465
|
+
allowedCurrencies?: string[];
|
|
466
|
+
/** Blocked jurisdiction pairs */
|
|
467
|
+
corridors?: {
|
|
468
|
+
blocked?: Array<{
|
|
469
|
+
from: string;
|
|
470
|
+
to: string;
|
|
471
|
+
}>;
|
|
472
|
+
};
|
|
473
|
+
/** When true, refuse verify() if no screening provider is configured (default: false) */
|
|
474
|
+
requireScreening?: boolean;
|
|
327
475
|
}
|
|
328
476
|
/**
|
|
329
477
|
* Interface for metadata validation. Compatible with Zod schemas and any
|
|
@@ -769,6 +917,8 @@ interface VerifyInput extends LogTransactionInput {
|
|
|
769
917
|
anchor?: OnChainAnchorConfig;
|
|
770
918
|
/** Counterparty agent for bilateral A2A attestation exchange */
|
|
771
919
|
counterparty?: CounterpartyConfig;
|
|
920
|
+
/** ERC-8021 config: fetch and parse builder attribution from transaction calldata */
|
|
921
|
+
erc8021?: ERC8021Config;
|
|
772
922
|
}
|
|
773
923
|
/** Result of the verify() convenience method */
|
|
774
924
|
interface VerifyResult {
|
|
@@ -802,6 +952,8 @@ interface VerifyResult {
|
|
|
802
952
|
requiresApproval?: boolean;
|
|
803
953
|
/** The pending approval task (present when requiresApproval is true) */
|
|
804
954
|
task?: Task;
|
|
955
|
+
/** ERC-8021 builder attribution (present when erc8021 config provided and tx has attribution) */
|
|
956
|
+
attribution?: ERC8021Attribution;
|
|
805
957
|
}
|
|
806
958
|
/**
|
|
807
959
|
* Input for logging an agent's reasoning/decision step.
|
|
@@ -868,6 +1020,8 @@ interface OnChainAnchorConfig {
|
|
|
868
1020
|
contractAddress: string;
|
|
869
1021
|
/** Private key of the signer (hex with 0x prefix). Required for write operations. */
|
|
870
1022
|
privateKey?: string;
|
|
1023
|
+
/** ERC-8021 builder code for transaction attribution (default: 'kontext') */
|
|
1024
|
+
builderCode?: string;
|
|
871
1025
|
}
|
|
872
1026
|
/** Result of an on-chain anchor transaction */
|
|
873
1027
|
interface AnchorResult {
|
|
@@ -897,6 +1051,22 @@ interface AnchorVerification {
|
|
|
897
1051
|
/** Block timestamp (if anchored) */
|
|
898
1052
|
timestamp?: number;
|
|
899
1053
|
}
|
|
1054
|
+
/** ERC-8021 transaction attribution data parsed from calldata suffix */
|
|
1055
|
+
interface ERC8021Attribution {
|
|
1056
|
+
/** Builder/entity codes extracted from the calldata suffix */
|
|
1057
|
+
codes: string[];
|
|
1058
|
+
/** Schema ID (0 = canonical code registry) */
|
|
1059
|
+
schemaId: number;
|
|
1060
|
+
/** Raw suffix hex (with 0x prefix) */
|
|
1061
|
+
rawSuffix: string;
|
|
1062
|
+
}
|
|
1063
|
+
/** ERC-8021 configuration for verify() */
|
|
1064
|
+
interface ERC8021Config {
|
|
1065
|
+
/** JSON-RPC URL for fetching transaction calldata */
|
|
1066
|
+
rpcUrl: string;
|
|
1067
|
+
/** Registry contract address for resolving codes to payout addresses (future use) */
|
|
1068
|
+
registryAddress?: string;
|
|
1069
|
+
}
|
|
900
1070
|
/** Agent card served at /.well-known/kontext.json */
|
|
901
1071
|
interface AgentCard {
|
|
902
1072
|
/** Agent identifier */
|
|
@@ -956,6 +1126,193 @@ interface CounterpartyAttestation {
|
|
|
956
1126
|
/** Attestation timestamp */
|
|
957
1127
|
timestamp: string;
|
|
958
1128
|
}
|
|
1129
|
+
/** Session status */
|
|
1130
|
+
type SessionStatus = 'active' | 'ended' | 'expired';
|
|
1131
|
+
/** Checkpoint status */
|
|
1132
|
+
type CheckpointStatus = 'pending' | 'attested' | 'rejected' | 'expired';
|
|
1133
|
+
/** Attestation decision */
|
|
1134
|
+
type AttestationDecision = 'approved' | 'rejected';
|
|
1135
|
+
/** Constraints on what an agent session is authorized to do */
|
|
1136
|
+
interface SessionConstraints {
|
|
1137
|
+
/** Maximum single transaction amount */
|
|
1138
|
+
maxAmount?: string;
|
|
1139
|
+
/** Allowed blockchain networks */
|
|
1140
|
+
allowedChains?: Chain[];
|
|
1141
|
+
/** Allowed tokens */
|
|
1142
|
+
allowedTokens?: Token[];
|
|
1143
|
+
/** Allowed recipient addresses (normalized to lowercase) */
|
|
1144
|
+
allowedRecipients?: string[];
|
|
1145
|
+
}
|
|
1146
|
+
/** Input for creating a delegated agent session */
|
|
1147
|
+
interface CreateSessionInput {
|
|
1148
|
+
/** Agent being delegated authority */
|
|
1149
|
+
agentId: string;
|
|
1150
|
+
/** Human principal who authorized this session */
|
|
1151
|
+
delegatedBy: string;
|
|
1152
|
+
/** Scoped capabilities (e.g., ['transfer', 'approve', 'query']) */
|
|
1153
|
+
scope: string[];
|
|
1154
|
+
/** Optional constraints on the session */
|
|
1155
|
+
constraints?: SessionConstraints;
|
|
1156
|
+
/** Session TTL in milliseconds (default: no expiry) */
|
|
1157
|
+
expiresIn?: number;
|
|
1158
|
+
/** Arbitrary metadata */
|
|
1159
|
+
metadata?: Record<string, unknown>;
|
|
1160
|
+
}
|
|
1161
|
+
/** A delegated agent session with provenance data */
|
|
1162
|
+
interface AgentSession {
|
|
1163
|
+
/** Unique session identifier */
|
|
1164
|
+
sessionId: string;
|
|
1165
|
+
/** Agent ID */
|
|
1166
|
+
agentId: string;
|
|
1167
|
+
/** Human who delegated authority */
|
|
1168
|
+
delegatedBy: string;
|
|
1169
|
+
/** Authorized scope */
|
|
1170
|
+
scope: string[];
|
|
1171
|
+
/** Session constraints */
|
|
1172
|
+
constraints?: SessionConstraints;
|
|
1173
|
+
/** Session status */
|
|
1174
|
+
status: SessionStatus;
|
|
1175
|
+
/** Creation timestamp */
|
|
1176
|
+
createdAt: string;
|
|
1177
|
+
/** End timestamp (when explicitly ended) */
|
|
1178
|
+
endedAt?: string;
|
|
1179
|
+
/** Expiry timestamp */
|
|
1180
|
+
expiresAt?: string;
|
|
1181
|
+
/** Digest from the chain link that recorded session creation */
|
|
1182
|
+
digest?: string;
|
|
1183
|
+
/** Prior digest in the chain */
|
|
1184
|
+
priorDigest?: string;
|
|
1185
|
+
/** Arbitrary metadata */
|
|
1186
|
+
metadata: Record<string, unknown>;
|
|
1187
|
+
}
|
|
1188
|
+
/** Interface for external attestation providers (developer implements) */
|
|
1189
|
+
interface ProvenanceAttestor {
|
|
1190
|
+
/** Sign an attestation payload */
|
|
1191
|
+
sign(payload: AttestationPayload): Promise<AttestationSignature>;
|
|
1192
|
+
/** Get the verification key for signature checking */
|
|
1193
|
+
getVerificationKey(): Promise<VerificationKey>;
|
|
1194
|
+
}
|
|
1195
|
+
/** Payload presented to an attestor for signing */
|
|
1196
|
+
interface AttestationPayload {
|
|
1197
|
+
/** Checkpoint ID */
|
|
1198
|
+
checkpointId: string;
|
|
1199
|
+
/** SHA-256 of concatenated action digests */
|
|
1200
|
+
actionsDigest: string;
|
|
1201
|
+
/** Session this checkpoint belongs to */
|
|
1202
|
+
sessionId: string;
|
|
1203
|
+
/** Timestamp of checkpoint creation */
|
|
1204
|
+
timestamp: string;
|
|
1205
|
+
}
|
|
1206
|
+
/** Cryptographic signature from an attestor */
|
|
1207
|
+
interface AttestationSignature {
|
|
1208
|
+
/** The signature bytes (hex or base64) */
|
|
1209
|
+
signature: string;
|
|
1210
|
+
/** Algorithm used (e.g., 'ES256', 'Ed25519', 'RS256') */
|
|
1211
|
+
algorithm: string;
|
|
1212
|
+
/** Optional key identifier */
|
|
1213
|
+
keyId?: string;
|
|
1214
|
+
}
|
|
1215
|
+
/** Public verification key for checking attestation signatures */
|
|
1216
|
+
interface VerificationKey {
|
|
1217
|
+
/** Public key (PEM, JWK string, or hex) */
|
|
1218
|
+
publicKey: string;
|
|
1219
|
+
/** Algorithm */
|
|
1220
|
+
algorithm: string;
|
|
1221
|
+
/** Optional key identifier */
|
|
1222
|
+
keyId?: string;
|
|
1223
|
+
}
|
|
1224
|
+
/** A human attestation attached to a checkpoint */
|
|
1225
|
+
interface HumanAttestation {
|
|
1226
|
+
/** Unique attestation identifier */
|
|
1227
|
+
attestationId: string;
|
|
1228
|
+
/** Checkpoint this attestation covers */
|
|
1229
|
+
checkpointId: string;
|
|
1230
|
+
/** Human reviewer identifier */
|
|
1231
|
+
reviewerId: string;
|
|
1232
|
+
/** Decision */
|
|
1233
|
+
decision: AttestationDecision;
|
|
1234
|
+
/** Optional evidence or notes from the reviewer */
|
|
1235
|
+
evidence?: string;
|
|
1236
|
+
/** Cryptographic signature */
|
|
1237
|
+
signature: AttestationSignature;
|
|
1238
|
+
/** Verification key for the signature */
|
|
1239
|
+
verificationKey: VerificationKey;
|
|
1240
|
+
/** Attestation timestamp */
|
|
1241
|
+
timestamp: string;
|
|
1242
|
+
}
|
|
1243
|
+
/** Input for creating a provenance checkpoint */
|
|
1244
|
+
interface CreateCheckpointInput {
|
|
1245
|
+
/** Session this checkpoint belongs to */
|
|
1246
|
+
sessionId: string;
|
|
1247
|
+
/** Action IDs to include in this checkpoint */
|
|
1248
|
+
actionIds: string[];
|
|
1249
|
+
/** Human-readable summary of what the agent did */
|
|
1250
|
+
summary: string;
|
|
1251
|
+
/** Checkpoint TTL in milliseconds (default: no expiry) */
|
|
1252
|
+
expiresIn?: number;
|
|
1253
|
+
}
|
|
1254
|
+
/** A provenance checkpoint -- a review point in the action stream */
|
|
1255
|
+
interface ProvenanceCheckpoint {
|
|
1256
|
+
/** Unique checkpoint identifier */
|
|
1257
|
+
id: string;
|
|
1258
|
+
/** Session this checkpoint belongs to */
|
|
1259
|
+
sessionId: string;
|
|
1260
|
+
/** Action IDs covered by this checkpoint */
|
|
1261
|
+
actionIds: string[];
|
|
1262
|
+
/** Human-readable summary */
|
|
1263
|
+
summary: string;
|
|
1264
|
+
/** SHA-256 of concatenated action digests (proves which actions were reviewed) */
|
|
1265
|
+
actionsDigest: string;
|
|
1266
|
+
/** Checkpoint status */
|
|
1267
|
+
status: CheckpointStatus;
|
|
1268
|
+
/** Attached human attestation (present after attestation) */
|
|
1269
|
+
attestation?: HumanAttestation;
|
|
1270
|
+
/** Creation timestamp */
|
|
1271
|
+
createdAt: string;
|
|
1272
|
+
/** Expiry timestamp */
|
|
1273
|
+
expiresAt?: string;
|
|
1274
|
+
}
|
|
1275
|
+
/** A provenance action with session binding */
|
|
1276
|
+
interface ProvenanceAction {
|
|
1277
|
+
/** Action ID */
|
|
1278
|
+
actionId: string;
|
|
1279
|
+
/** Action type */
|
|
1280
|
+
type: string;
|
|
1281
|
+
/** Digest from the chain */
|
|
1282
|
+
digest: string;
|
|
1283
|
+
/** Prior digest */
|
|
1284
|
+
priorDigest: string;
|
|
1285
|
+
/** Session this action is bound to */
|
|
1286
|
+
sessionId: string;
|
|
1287
|
+
/** Action timestamp */
|
|
1288
|
+
timestamp: string;
|
|
1289
|
+
}
|
|
1290
|
+
/** Verification summary for a provenance bundle */
|
|
1291
|
+
interface ProvenanceBundleVerification {
|
|
1292
|
+
/** Whether the digest chain covering these actions is valid */
|
|
1293
|
+
digestChainValid: boolean;
|
|
1294
|
+
/** Total actions in the session */
|
|
1295
|
+
totalActions: number;
|
|
1296
|
+
/** Actions covered by an approved human attestation */
|
|
1297
|
+
humanAttested: number;
|
|
1298
|
+
/** Actions bound to the session */
|
|
1299
|
+
sessionScoped: number;
|
|
1300
|
+
/** Actions not yet covered by any checkpoint */
|
|
1301
|
+
unattested: number;
|
|
1302
|
+
}
|
|
1303
|
+
/** Complete provenance export for a session */
|
|
1304
|
+
interface ProvenanceBundle {
|
|
1305
|
+
/** The session record */
|
|
1306
|
+
session: AgentSession;
|
|
1307
|
+
/** All actions bound to this session */
|
|
1308
|
+
actions: ProvenanceAction[];
|
|
1309
|
+
/** All checkpoints for this session */
|
|
1310
|
+
checkpoints: ProvenanceCheckpoint[];
|
|
1311
|
+
/** Verification summary */
|
|
1312
|
+
verification: ProvenanceBundleVerification;
|
|
1313
|
+
/** Export timestamp */
|
|
1314
|
+
generatedAt: string;
|
|
1315
|
+
}
|
|
959
1316
|
/** Error codes for Kontext SDK */
|
|
960
1317
|
declare enum KontextErrorCode {
|
|
961
1318
|
INITIALIZATION_ERROR = "INITIALIZATION_ERROR",
|
|
@@ -1167,7 +1524,7 @@ interface PlanUsage {
|
|
|
1167
1524
|
seats: number;
|
|
1168
1525
|
/** Number of events logged in the current billing period */
|
|
1169
1526
|
eventCount: number;
|
|
1170
|
-
/** Maximum events allowed
|
|
1527
|
+
/** Maximum events allowed */
|
|
1171
1528
|
limit: number;
|
|
1172
1529
|
/** Remaining events before limit */
|
|
1173
1530
|
remainingEvents: number;
|
|
@@ -1356,162 +1713,767 @@ declare class FeatureFlagManager {
|
|
|
1356
1713
|
private triggerBackgroundRefresh;
|
|
1357
1714
|
}
|
|
1358
1715
|
|
|
1716
|
+
/** Entity type for an agent identity */
|
|
1717
|
+
type EntityType = 'individual' | 'organization' | 'bot' | 'unknown';
|
|
1718
|
+
/** KYC verification status */
|
|
1719
|
+
type KYCStatus = 'none' | 'pending' | 'verified' | 'rejected' | 'expired';
|
|
1720
|
+
/** A wallet mapping associated with an agent */
|
|
1721
|
+
interface WalletMapping {
|
|
1722
|
+
/** Wallet address (normalized to lowercase) */
|
|
1723
|
+
address: string;
|
|
1724
|
+
/** Blockchain network */
|
|
1725
|
+
chain: string;
|
|
1726
|
+
/** Whether this wallet was verified on-chain */
|
|
1727
|
+
verified: boolean;
|
|
1728
|
+
/** When the wallet was added */
|
|
1729
|
+
addedAt: string;
|
|
1730
|
+
/** Optional label for the wallet */
|
|
1731
|
+
label?: string;
|
|
1732
|
+
}
|
|
1733
|
+
/** Reference to an external KYC provider verification */
|
|
1734
|
+
interface KYCProviderReference {
|
|
1735
|
+
/** KYC provider name (e.g., 'jumio', 'onfido', 'sumsub') */
|
|
1736
|
+
provider: string;
|
|
1737
|
+
/** External reference/case ID from the provider */
|
|
1738
|
+
referenceId: string;
|
|
1739
|
+
/** Verification status */
|
|
1740
|
+
status: KYCStatus;
|
|
1741
|
+
/** When the verification was completed */
|
|
1742
|
+
verifiedAt: string | null;
|
|
1743
|
+
/** When the verification expires */
|
|
1744
|
+
expiresAt: string | null;
|
|
1745
|
+
/** Risk level assigned by the provider */
|
|
1746
|
+
riskLevel?: 'low' | 'medium' | 'high';
|
|
1747
|
+
}
|
|
1748
|
+
/** Declared agent identity */
|
|
1749
|
+
interface AgentIdentity {
|
|
1750
|
+
/** Agent ID (primary key) */
|
|
1751
|
+
agentId: string;
|
|
1752
|
+
/** Display name */
|
|
1753
|
+
displayName?: string;
|
|
1754
|
+
/** Entity type */
|
|
1755
|
+
entityType: EntityType;
|
|
1756
|
+
/** Wallet addresses associated with the agent */
|
|
1757
|
+
wallets: WalletMapping[];
|
|
1758
|
+
/** External KYC provider references */
|
|
1759
|
+
kycReferences: KYCProviderReference[];
|
|
1760
|
+
/** Contact URI (email, ENS, etc.) */
|
|
1761
|
+
contactUri?: string;
|
|
1762
|
+
/** Arbitrary metadata */
|
|
1763
|
+
metadata: Record<string, unknown>;
|
|
1764
|
+
/** When the identity was first registered */
|
|
1765
|
+
createdAt: string;
|
|
1766
|
+
/** When the identity was last updated */
|
|
1767
|
+
updatedAt: string;
|
|
1768
|
+
}
|
|
1769
|
+
/** Input for registering a new agent identity */
|
|
1770
|
+
interface RegisterIdentityInput {
|
|
1771
|
+
/** Agent ID */
|
|
1772
|
+
agentId: string;
|
|
1773
|
+
/** Display name */
|
|
1774
|
+
displayName?: string;
|
|
1775
|
+
/** Entity type */
|
|
1776
|
+
entityType?: EntityType;
|
|
1777
|
+
/** Initial wallet mappings */
|
|
1778
|
+
wallets?: Array<{
|
|
1779
|
+
address: string;
|
|
1780
|
+
chain: string;
|
|
1781
|
+
label?: string;
|
|
1782
|
+
}>;
|
|
1783
|
+
/** Contact URI */
|
|
1784
|
+
contactUri?: string;
|
|
1785
|
+
/** Arbitrary metadata */
|
|
1786
|
+
metadata?: Record<string, unknown>;
|
|
1787
|
+
}
|
|
1788
|
+
/** Input for updating an existing agent identity */
|
|
1789
|
+
interface UpdateIdentityInput {
|
|
1790
|
+
/** Updated display name */
|
|
1791
|
+
displayName?: string;
|
|
1792
|
+
/** Updated entity type */
|
|
1793
|
+
entityType?: EntityType;
|
|
1794
|
+
/** Updated contact URI */
|
|
1795
|
+
contactUri?: string;
|
|
1796
|
+
/** Metadata to merge */
|
|
1797
|
+
metadata?: Record<string, unknown>;
|
|
1798
|
+
}
|
|
1799
|
+
/** Heuristic used to cluster wallet addresses */
|
|
1800
|
+
type ClusteringHeuristic = 'common-agent' | 'funding-chain' | 'gas-sponsorship' | 'temporal-co-spending' | 'declared-wallets';
|
|
1801
|
+
/** Evidence for why two addresses were clustered */
|
|
1802
|
+
interface ClusteringEvidence {
|
|
1803
|
+
/** Heuristic that produced this evidence */
|
|
1804
|
+
heuristic: ClusteringHeuristic;
|
|
1805
|
+
/** Confidence of this particular heuristic (0-1) */
|
|
1806
|
+
confidence: number;
|
|
1807
|
+
/** Addresses involved */
|
|
1808
|
+
addresses: [string, string];
|
|
1809
|
+
/** When this evidence was detected */
|
|
1810
|
+
detectedAt: string;
|
|
1811
|
+
/** Additional detail */
|
|
1812
|
+
detail?: string;
|
|
1813
|
+
}
|
|
1814
|
+
/** A cluster of related wallet addresses */
|
|
1815
|
+
interface WalletCluster {
|
|
1816
|
+
/** Cluster ID */
|
|
1817
|
+
id: string;
|
|
1818
|
+
/** All addresses in the cluster (normalized lowercase) */
|
|
1819
|
+
addresses: string[];
|
|
1820
|
+
/** Agent IDs associated with this cluster */
|
|
1821
|
+
agentIds: string[];
|
|
1822
|
+
/** Evidence trail for this cluster */
|
|
1823
|
+
evidence: ClusteringEvidence[];
|
|
1824
|
+
/** Highest confidence from any evidence */
|
|
1825
|
+
confidence: number;
|
|
1826
|
+
/** When the cluster was formed */
|
|
1827
|
+
createdAt: string;
|
|
1828
|
+
}
|
|
1829
|
+
/** Configuration for wallet clustering */
|
|
1830
|
+
interface WalletClusteringConfig {
|
|
1831
|
+
/** Temporal co-spending window in seconds (default: 60) */
|
|
1832
|
+
temporalWindowSeconds?: number;
|
|
1833
|
+
/** Minimum destination overlap ratio for temporal heuristic (default: 0.3) */
|
|
1834
|
+
minDestinationOverlap?: number;
|
|
1835
|
+
/** Minimum number of sponsored wallets for gas sponsorship heuristic (default: 3) */
|
|
1836
|
+
minGasSponsoredWallets?: number;
|
|
1837
|
+
}
|
|
1838
|
+
/** Temporal features extracted from transaction patterns */
|
|
1839
|
+
interface TemporalFeatures {
|
|
1840
|
+
/** Mean inter-transaction interval in seconds */
|
|
1841
|
+
meanIntervalSeconds: number;
|
|
1842
|
+
/** Standard deviation of inter-transaction intervals */
|
|
1843
|
+
stddevIntervalSeconds: number;
|
|
1844
|
+
/** 24-bin hour-of-day histogram (normalized to sum=1) */
|
|
1845
|
+
hourHistogram: number[];
|
|
1846
|
+
/** 7-bin day-of-week histogram (normalized to sum=1) */
|
|
1847
|
+
dayHistogram: number[];
|
|
1848
|
+
}
|
|
1849
|
+
/** Financial features extracted from transaction amounts */
|
|
1850
|
+
interface FinancialFeatures {
|
|
1851
|
+
/** Mean transaction amount */
|
|
1852
|
+
meanAmount: number;
|
|
1853
|
+
/** Standard deviation of transaction amounts */
|
|
1854
|
+
stddevAmount: number;
|
|
1855
|
+
/** Median transaction amount */
|
|
1856
|
+
medianAmount: number;
|
|
1857
|
+
/** Ratio of round amounts (divisible by 100) */
|
|
1858
|
+
roundAmountRatio: number;
|
|
1859
|
+
/** Amount percentiles [p10, p25, p50, p75, p90] */
|
|
1860
|
+
percentiles: [number, number, number, number, number];
|
|
1861
|
+
}
|
|
1862
|
+
/** Network features from transaction graph */
|
|
1863
|
+
interface NetworkFeatures {
|
|
1864
|
+
/** Number of unique destination addresses */
|
|
1865
|
+
uniqueDestinations: number;
|
|
1866
|
+
/** Address reuse ratio: 1 - (unique / total) */
|
|
1867
|
+
reuseRatio: number;
|
|
1868
|
+
/** Herfindahl-Hirschman Index for destination concentration */
|
|
1869
|
+
concentrationIndex: number;
|
|
1870
|
+
/** Number of unique source addresses */
|
|
1871
|
+
uniqueSources: number;
|
|
1872
|
+
}
|
|
1873
|
+
/** Operational features from chain/token usage */
|
|
1874
|
+
interface OperationalFeatures {
|
|
1875
|
+
/** Distribution of transactions across chains (normalized) */
|
|
1876
|
+
chainDistribution: Record<string, number>;
|
|
1877
|
+
/** Distribution of transactions across tokens (normalized) */
|
|
1878
|
+
tokenDistribution: Record<string, number>;
|
|
1879
|
+
/** Primary chain (most used) */
|
|
1880
|
+
primaryChain: string;
|
|
1881
|
+
/** Primary token (most used) */
|
|
1882
|
+
primaryToken: string;
|
|
1883
|
+
}
|
|
1884
|
+
/** Complete behavioral embedding for an agent */
|
|
1885
|
+
interface BehavioralEmbedding {
|
|
1886
|
+
/** Agent ID */
|
|
1887
|
+
agentId: string;
|
|
1888
|
+
/** Temporal features */
|
|
1889
|
+
temporal: TemporalFeatures;
|
|
1890
|
+
/** Financial features */
|
|
1891
|
+
financial: FinancialFeatures;
|
|
1892
|
+
/** Network features */
|
|
1893
|
+
network: NetworkFeatures;
|
|
1894
|
+
/** Operational features */
|
|
1895
|
+
operational: OperationalFeatures;
|
|
1896
|
+
/** Number of transactions used to compute the embedding */
|
|
1897
|
+
sampleSize: number;
|
|
1898
|
+
/** When the embedding was computed */
|
|
1899
|
+
computedAt: string;
|
|
1900
|
+
}
|
|
1901
|
+
/** A signal contributing to an agent link */
|
|
1902
|
+
interface LinkSignal {
|
|
1903
|
+
/** Signal type */
|
|
1904
|
+
type: 'wallet-overlap' | 'behavioral-similarity' | 'declared-identity';
|
|
1905
|
+
/** Signal strength (0-1) */
|
|
1906
|
+
strength: number;
|
|
1907
|
+
/** Weight of this signal type (0-1) */
|
|
1908
|
+
weight: number;
|
|
1909
|
+
/** Detail about the signal */
|
|
1910
|
+
detail?: string;
|
|
1911
|
+
}
|
|
1912
|
+
/** Link status */
|
|
1913
|
+
type LinkStatus = 'inferred' | 'confirmed' | 'rejected';
|
|
1914
|
+
/** A link between two agents */
|
|
1915
|
+
interface AgentLink {
|
|
1916
|
+
/** Link ID */
|
|
1917
|
+
id: string;
|
|
1918
|
+
/** First agent ID */
|
|
1919
|
+
agentIdA: string;
|
|
1920
|
+
/** Second agent ID */
|
|
1921
|
+
agentIdB: string;
|
|
1922
|
+
/** Overall confidence (0-1) */
|
|
1923
|
+
confidence: number;
|
|
1924
|
+
/** Signals contributing to this link */
|
|
1925
|
+
signals: LinkSignal[];
|
|
1926
|
+
/** Link status */
|
|
1927
|
+
status: LinkStatus;
|
|
1928
|
+
/** When the link was created */
|
|
1929
|
+
createdAt: string;
|
|
1930
|
+
/** Who reviewed the link (if reviewed) */
|
|
1931
|
+
reviewedBy?: string;
|
|
1932
|
+
/** When the link was reviewed */
|
|
1933
|
+
reviewedAt?: string;
|
|
1934
|
+
}
|
|
1935
|
+
/** Configuration for cross-session linking */
|
|
1936
|
+
interface CrossSessionLinkerConfig {
|
|
1937
|
+
/** Minimum behavioral similarity to consider (default: 0.85) */
|
|
1938
|
+
minBehavioralSimilarity?: number;
|
|
1939
|
+
/** Minimum overall confidence to create a link (default: 0.6) */
|
|
1940
|
+
minLinkConfidence?: number;
|
|
1941
|
+
}
|
|
1942
|
+
/** A component contributing to the KYA confidence score */
|
|
1943
|
+
interface KYAScoreComponent {
|
|
1944
|
+
/** Component name */
|
|
1945
|
+
name: string;
|
|
1946
|
+
/** Raw component score (0-100) */
|
|
1947
|
+
score: number;
|
|
1948
|
+
/** Weight of this component (0-1) */
|
|
1949
|
+
weight: number;
|
|
1950
|
+
/** Weighted contribution to overall score */
|
|
1951
|
+
weightedScore: number;
|
|
1952
|
+
/** Human-readable detail */
|
|
1953
|
+
detail: string;
|
|
1954
|
+
}
|
|
1955
|
+
/** Confidence level label */
|
|
1956
|
+
type KYAConfidenceLevel = 'unknown' | 'low' | 'medium' | 'high' | 'verified';
|
|
1957
|
+
/** Complete KYA confidence score for an agent */
|
|
1958
|
+
interface KYAConfidenceScore {
|
|
1959
|
+
/** Agent ID */
|
|
1960
|
+
agentId: string;
|
|
1961
|
+
/** Overall score (0-100) */
|
|
1962
|
+
score: number;
|
|
1963
|
+
/** Confidence level */
|
|
1964
|
+
level: KYAConfidenceLevel;
|
|
1965
|
+
/** Component breakdown */
|
|
1966
|
+
components: KYAScoreComponent[];
|
|
1967
|
+
/** When the score was computed */
|
|
1968
|
+
computedAt: string;
|
|
1969
|
+
}
|
|
1970
|
+
/** Configuration for confidence scoring weights */
|
|
1971
|
+
interface KYAConfidenceScorerConfig {
|
|
1972
|
+
/** Weight for declared identity component (default: 0.20) */
|
|
1973
|
+
declaredIdentityWeight?: number;
|
|
1974
|
+
/** Weight for KYC verification component (default: 0.30) */
|
|
1975
|
+
kycVerificationWeight?: number;
|
|
1976
|
+
/** Weight for wallet graph component (default: 0.20) */
|
|
1977
|
+
walletGraphWeight?: number;
|
|
1978
|
+
/** Weight for behavioral consistency component (default: 0.20) */
|
|
1979
|
+
behavioralConsistencyWeight?: number;
|
|
1980
|
+
/** Weight for external enrichment component (default: 0.10) */
|
|
1981
|
+
externalEnrichmentWeight?: number;
|
|
1982
|
+
}
|
|
1983
|
+
/** Aggregated KYA data for inclusion in audit exports */
|
|
1984
|
+
interface KYAEnvelope {
|
|
1985
|
+
/** All registered identities */
|
|
1986
|
+
identities: AgentIdentity[];
|
|
1987
|
+
/** Wallet clusters */
|
|
1988
|
+
clusters: WalletCluster[];
|
|
1989
|
+
/** Behavioral embeddings (if enterprise) */
|
|
1990
|
+
embeddings: BehavioralEmbedding[];
|
|
1991
|
+
/** Agent links (if enterprise) */
|
|
1992
|
+
links: AgentLink[];
|
|
1993
|
+
/** Confidence scores */
|
|
1994
|
+
scores: KYAConfidenceScore[];
|
|
1995
|
+
/** When the envelope was generated */
|
|
1996
|
+
generatedAt: string;
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1359
1999
|
/**
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
* anomaly detection.
|
|
1363
|
-
*
|
|
1364
|
-
* Supports two operating modes:
|
|
1365
|
-
* - **Local mode** (no API key): All data stored locally, suitable for
|
|
1366
|
-
* open-source usage and development.
|
|
1367
|
-
* - **Cloud mode** (with API key): Data synced to Kontext API for
|
|
1368
|
-
* persistent storage and advanced features.
|
|
1369
|
-
*
|
|
1370
|
-
* @example
|
|
1371
|
-
* ```typescript
|
|
1372
|
-
* import { Kontext } from '@kontext/sdk';
|
|
1373
|
-
*
|
|
1374
|
-
* const kontext = Kontext.init({
|
|
1375
|
-
* projectId: 'my-project',
|
|
1376
|
-
* environment: 'development',
|
|
1377
|
-
* });
|
|
1378
|
-
*
|
|
1379
|
-
* await kontext.logTransaction({
|
|
1380
|
-
* txHash: '0x...',
|
|
1381
|
-
* chain: 'base',
|
|
1382
|
-
* amount: '100',
|
|
1383
|
-
* token: 'USDC',
|
|
1384
|
-
* from: '0xSender',
|
|
1385
|
-
* to: '0xReceiver',
|
|
1386
|
-
* agentId: 'agent-1',
|
|
1387
|
-
* });
|
|
1388
|
-
* ```
|
|
2000
|
+
* In-memory registry for agent identities.
|
|
2001
|
+
* Provides CRUD operations, wallet index lookups, and KYC reference management.
|
|
1389
2002
|
*/
|
|
1390
|
-
declare class
|
|
1391
|
-
|
|
1392
|
-
private readonly
|
|
1393
|
-
|
|
1394
|
-
private readonly
|
|
1395
|
-
private readonly auditExporter;
|
|
1396
|
-
private readonly mode;
|
|
1397
|
-
private readonly planManager;
|
|
1398
|
-
private readonly exporter;
|
|
1399
|
-
private readonly featureFlagManager;
|
|
1400
|
-
private readonly trustScorer;
|
|
1401
|
-
private readonly anomalyDetector;
|
|
1402
|
-
private constructor();
|
|
2003
|
+
declare class AgentIdentityRegistry {
|
|
2004
|
+
/** agentId -> AgentIdentity */
|
|
2005
|
+
private readonly identities;
|
|
2006
|
+
/** normalized address -> agentId (reverse index) */
|
|
2007
|
+
private readonly walletIndex;
|
|
1403
2008
|
/**
|
|
1404
|
-
*
|
|
1405
|
-
*
|
|
1406
|
-
* @param config - Configuration options
|
|
1407
|
-
* @returns Initialized Kontext client instance
|
|
1408
|
-
*
|
|
1409
|
-
* @example
|
|
1410
|
-
* ```typescript
|
|
1411
|
-
* // Local/OSS mode (no API key)
|
|
1412
|
-
* const kontext = Kontext.init({
|
|
1413
|
-
* projectId: 'my-project',
|
|
1414
|
-
* environment: 'development',
|
|
1415
|
-
* });
|
|
1416
|
-
*
|
|
1417
|
-
* // Cloud mode (with API key)
|
|
1418
|
-
* const kontext = Kontext.init({
|
|
1419
|
-
* apiKey: 'sk_live_...',
|
|
1420
|
-
* projectId: 'my-project',
|
|
1421
|
-
* environment: 'production',
|
|
1422
|
-
* });
|
|
1423
|
-
*
|
|
1424
|
-
* // With persistent file storage
|
|
1425
|
-
* const kontext = Kontext.init({
|
|
1426
|
-
* projectId: 'my-project',
|
|
1427
|
-
* environment: 'development',
|
|
1428
|
-
* storage: new FileStorage('./kontext-data'),
|
|
1429
|
-
* });
|
|
1430
|
-
* ```
|
|
2009
|
+
* Register a new agent identity.
|
|
1431
2010
|
*/
|
|
1432
|
-
|
|
2011
|
+
register(input: RegisterIdentityInput): AgentIdentity;
|
|
1433
2012
|
/**
|
|
1434
|
-
*
|
|
2013
|
+
* Update an existing agent identity.
|
|
1435
2014
|
*/
|
|
1436
|
-
|
|
2015
|
+
update(agentId: string, input: UpdateIdentityInput): AgentIdentity;
|
|
1437
2016
|
/**
|
|
1438
|
-
* Get
|
|
2017
|
+
* Get an agent identity by agent ID.
|
|
1439
2018
|
*/
|
|
1440
|
-
|
|
1441
|
-
apiKey?: string;
|
|
1442
|
-
};
|
|
2019
|
+
get(agentId: string): AgentIdentity | undefined;
|
|
1443
2020
|
/**
|
|
1444
|
-
*
|
|
1445
|
-
* No-op when metadataSchema is not configured.
|
|
2021
|
+
* Remove an agent identity and all wallet index entries.
|
|
1446
2022
|
*/
|
|
1447
|
-
|
|
2023
|
+
remove(agentId: string): boolean;
|
|
1448
2024
|
/**
|
|
1449
|
-
*
|
|
1450
|
-
*
|
|
1451
|
-
* @param input - Action details
|
|
1452
|
-
* @returns The created action log entry
|
|
2025
|
+
* Get all registered identities.
|
|
1453
2026
|
*/
|
|
1454
|
-
|
|
2027
|
+
getAll(): AgentIdentity[];
|
|
1455
2028
|
/**
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1458
|
-
* @param input - Transaction details
|
|
1459
|
-
* @returns The created transaction record
|
|
2029
|
+
* Add a wallet to an existing agent identity.
|
|
1460
2030
|
*/
|
|
1461
|
-
|
|
2031
|
+
addWallet(agentId: string, wallet: {
|
|
2032
|
+
address: string;
|
|
2033
|
+
chain: string;
|
|
2034
|
+
label?: string;
|
|
2035
|
+
}): AgentIdentity;
|
|
1462
2036
|
/**
|
|
1463
|
-
*
|
|
2037
|
+
* Remove a wallet from an agent identity.
|
|
1464
2038
|
*/
|
|
1465
|
-
|
|
2039
|
+
removeWallet(agentId: string, address: string): AgentIdentity;
|
|
1466
2040
|
/**
|
|
1467
|
-
*
|
|
1468
|
-
* No-op if no storage adapter is configured.
|
|
2041
|
+
* Look up an agent identity by wallet address.
|
|
1469
2042
|
*/
|
|
1470
|
-
|
|
2043
|
+
lookupByWallet(address: string): AgentIdentity | undefined;
|
|
1471
2044
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
* Loads previously persisted actions, transactions, tasks, and anomalies.
|
|
1474
|
-
* Also restores the digest chain's terminal digest so that new actions
|
|
1475
|
-
* chain correctly across process boundaries.
|
|
1476
|
-
* No-op if no storage adapter is configured.
|
|
2045
|
+
* Add a KYC provider reference to an agent identity.
|
|
1477
2046
|
*/
|
|
1478
|
-
|
|
2047
|
+
addKycReference(agentId: string, reference: KYCProviderReference): AgentIdentity;
|
|
1479
2048
|
/**
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1482
|
-
* @param input - Task details including required evidence types
|
|
1483
|
-
* @returns The created task
|
|
2049
|
+
* Get the overall KYC status for an agent.
|
|
2050
|
+
* Returns the best status from all references.
|
|
1484
2051
|
*/
|
|
1485
|
-
|
|
2052
|
+
getKycStatus(agentId: string): KYCStatus;
|
|
1486
2053
|
/**
|
|
1487
|
-
*
|
|
1488
|
-
*
|
|
1489
|
-
* @param input - Task ID and evidence data
|
|
1490
|
-
* @returns The confirmed task
|
|
2054
|
+
* Check if an agent has at least one verified and non-expired KYC reference.
|
|
1491
2055
|
*/
|
|
1492
|
-
|
|
2056
|
+
hasVerifiedKyc(agentId: string): boolean;
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
/**
|
|
2060
|
+
* In-memory data store for the Kontext SDK.
|
|
2061
|
+
* Holds all action logs, transactions, tasks, and anomaly events.
|
|
2062
|
+
*
|
|
2063
|
+
* When a StorageAdapter is provided, call `flush()` to persist state
|
|
2064
|
+
* and `restore()` to reload from storage.
|
|
2065
|
+
*/
|
|
2066
|
+
declare class KontextStore {
|
|
2067
|
+
private actions;
|
|
2068
|
+
private transactions;
|
|
2069
|
+
private tasks;
|
|
2070
|
+
private anomalies;
|
|
2071
|
+
private sessions;
|
|
2072
|
+
private checkpoints;
|
|
2073
|
+
private storageAdapter;
|
|
2074
|
+
private readonly maxEntries;
|
|
2075
|
+
constructor(maxEntries?: number);
|
|
1493
2076
|
/**
|
|
1494
|
-
*
|
|
2077
|
+
* Attach a storage adapter for persistence.
|
|
1495
2078
|
*
|
|
1496
|
-
* @param
|
|
1497
|
-
* @returns The task or undefined if not found
|
|
2079
|
+
* @param adapter - The storage backend to use
|
|
1498
2080
|
*/
|
|
1499
|
-
|
|
2081
|
+
setStorageAdapter(adapter: StorageAdapter): void;
|
|
1500
2082
|
/**
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
* @param taskId - Task identifier
|
|
1504
|
-
* @returns The updated task
|
|
2083
|
+
* Get the currently attached storage adapter (if any).
|
|
1505
2084
|
*/
|
|
1506
|
-
|
|
2085
|
+
getStorageAdapter(): StorageAdapter | null;
|
|
1507
2086
|
/**
|
|
1508
|
-
*
|
|
1509
|
-
*
|
|
1510
|
-
* @param taskId - Task identifier
|
|
1511
|
-
* @param reason - Reason for failure
|
|
1512
|
-
* @returns The updated task
|
|
2087
|
+
* Persist all current in-memory state to the attached storage adapter.
|
|
2088
|
+
* No-op if no adapter is attached.
|
|
1513
2089
|
*/
|
|
1514
|
-
|
|
2090
|
+
flush(): Promise<void>;
|
|
2091
|
+
/**
|
|
2092
|
+
* Restore in-memory state from the attached storage adapter.
|
|
2093
|
+
* Merges loaded data with any existing in-memory data.
|
|
2094
|
+
* No-op if no adapter is attached.
|
|
2095
|
+
*/
|
|
2096
|
+
restore(): Promise<void>;
|
|
2097
|
+
/** Append an action log entry. Evicts oldest 10% when maxEntries is exceeded. */
|
|
2098
|
+
addAction(action: ActionLog): void;
|
|
2099
|
+
/** Retrieve all action log entries. */
|
|
2100
|
+
getActions(): ActionLog[];
|
|
2101
|
+
/** Retrieve actions filtered by a predicate. */
|
|
2102
|
+
queryActions(predicate: (action: ActionLog) => boolean): ActionLog[];
|
|
2103
|
+
/** Get actions for a specific agent. */
|
|
2104
|
+
getActionsByAgent(agentId: string): ActionLog[];
|
|
2105
|
+
/** Get actions for a specific session (across all agents). */
|
|
2106
|
+
getActionsBySession(sessionId: string): ActionLog[];
|
|
2107
|
+
/** Append a transaction record. Evicts oldest 10% when maxEntries is exceeded. */
|
|
2108
|
+
addTransaction(tx: TransactionRecord): void;
|
|
2109
|
+
/** Retrieve all transaction records. */
|
|
2110
|
+
getTransactions(): TransactionRecord[];
|
|
2111
|
+
/** Retrieve transactions filtered by a predicate. */
|
|
2112
|
+
queryTransactions(predicate: (tx: TransactionRecord) => boolean): TransactionRecord[];
|
|
2113
|
+
/** Get transactions for a specific agent. */
|
|
2114
|
+
getTransactionsByAgent(agentId: string): TransactionRecord[];
|
|
2115
|
+
/** Get the most recent N transactions for an agent. */
|
|
2116
|
+
getRecentTransactions(agentId: string, limit: number): TransactionRecord[];
|
|
2117
|
+
/** Store a task. */
|
|
2118
|
+
addTask(task: Task): void;
|
|
2119
|
+
/** Retrieve a task by ID. */
|
|
2120
|
+
getTask(taskId: string): Task | undefined;
|
|
2121
|
+
/** Update a task. */
|
|
2122
|
+
updateTask(taskId: string, updates: Partial<Task>): Task | undefined;
|
|
2123
|
+
/** Retrieve all tasks. */
|
|
2124
|
+
getTasks(): Task[];
|
|
2125
|
+
/** Retrieve tasks filtered by a predicate. */
|
|
2126
|
+
queryTasks(predicate: (task: Task) => boolean): Task[];
|
|
2127
|
+
/** Append an anomaly event. Evicts oldest 10% when maxEntries is exceeded. */
|
|
2128
|
+
addAnomaly(anomaly: AnomalyEvent): void;
|
|
2129
|
+
/** Retrieve all anomaly events. */
|
|
2130
|
+
getAnomalies(): AnomalyEvent[];
|
|
2131
|
+
/** Retrieve anomalies filtered by a predicate. */
|
|
2132
|
+
queryAnomalies(predicate: (anomaly: AnomalyEvent) => boolean): AnomalyEvent[];
|
|
2133
|
+
/** Store a session. */
|
|
2134
|
+
addSession(session: AgentSession): void;
|
|
2135
|
+
/** Retrieve a session by ID. */
|
|
2136
|
+
getSession(sessionId: string): AgentSession | undefined;
|
|
2137
|
+
/** Update a session. */
|
|
2138
|
+
updateSession(sessionId: string, updates: Partial<AgentSession>): AgentSession | undefined;
|
|
2139
|
+
/** Retrieve all sessions. */
|
|
2140
|
+
getSessions(): AgentSession[];
|
|
2141
|
+
/** Retrieve sessions filtered by a predicate. */
|
|
2142
|
+
querySessions(predicate: (session: AgentSession) => boolean): AgentSession[];
|
|
2143
|
+
/** Store a checkpoint. */
|
|
2144
|
+
addCheckpoint(checkpoint: ProvenanceCheckpoint): void;
|
|
2145
|
+
/** Retrieve a checkpoint by ID. */
|
|
2146
|
+
getCheckpoint(checkpointId: string): ProvenanceCheckpoint | undefined;
|
|
2147
|
+
/** Update a checkpoint. */
|
|
2148
|
+
updateCheckpoint(checkpointId: string, updates: Partial<ProvenanceCheckpoint>): ProvenanceCheckpoint | undefined;
|
|
2149
|
+
/** Retrieve all checkpoints. */
|
|
2150
|
+
getCheckpoints(): ProvenanceCheckpoint[];
|
|
2151
|
+
/** Retrieve checkpoints filtered by a predicate. */
|
|
2152
|
+
queryCheckpoints(predicate: (cp: ProvenanceCheckpoint) => boolean): ProvenanceCheckpoint[];
|
|
2153
|
+
/** Get total record counts across all stores. */
|
|
2154
|
+
getCounts(): {
|
|
2155
|
+
actions: number;
|
|
2156
|
+
transactions: number;
|
|
2157
|
+
tasks: number;
|
|
2158
|
+
anomalies: number;
|
|
2159
|
+
sessions: number;
|
|
2160
|
+
checkpoints: number;
|
|
2161
|
+
};
|
|
2162
|
+
/** Clear all stored data. Useful for testing. */
|
|
2163
|
+
clear(): void;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
/**
|
|
2167
|
+
* Clusters wallet addresses using multiple heuristics.
|
|
2168
|
+
* Builds on UnionFind for efficient merging.
|
|
2169
|
+
*/
|
|
2170
|
+
declare class WalletClusterer {
|
|
2171
|
+
private readonly config;
|
|
2172
|
+
private cachedClusters;
|
|
2173
|
+
constructor(config?: WalletClusteringConfig);
|
|
2174
|
+
/**
|
|
2175
|
+
* Analyze transactions from the store and registry to produce wallet clusters.
|
|
2176
|
+
*/
|
|
2177
|
+
analyzeFromStore(store: KontextStore, registry?: AgentIdentityRegistry): WalletCluster[];
|
|
2178
|
+
/**
|
|
2179
|
+
* Get cached clusters (or empty if not analyzed yet).
|
|
2180
|
+
*/
|
|
2181
|
+
getClusters(): WalletCluster[];
|
|
2182
|
+
/**
|
|
2183
|
+
* Invalidate the cached clusters.
|
|
2184
|
+
*/
|
|
2185
|
+
invalidateCache(): void;
|
|
2186
|
+
/**
|
|
2187
|
+
* Heuristic 1: Common Agent (confidence 0.9)
|
|
2188
|
+
* Same agentId used multiple addresses -> union all from/to per agent.
|
|
2189
|
+
*/
|
|
2190
|
+
private applyCommonAgent;
|
|
2191
|
+
/**
|
|
2192
|
+
* Heuristic 2: Funding Chain (confidence 0.7)
|
|
2193
|
+
* If A sends to B, and A is agent-associated -> union A and B.
|
|
2194
|
+
*/
|
|
2195
|
+
private applyFundingChain;
|
|
2196
|
+
/**
|
|
2197
|
+
* Heuristic 3: Gas Sponsorship (confidence 0.75)
|
|
2198
|
+
* If G is from in transfers to 3+ distinct agent wallets -> union G with all.
|
|
2199
|
+
*/
|
|
2200
|
+
private applyGasSponsorship;
|
|
2201
|
+
/**
|
|
2202
|
+
* Heuristic 4: Temporal Co-Spending (confidence 0.6)
|
|
2203
|
+
* Addresses transacting within a window with destination overlap.
|
|
2204
|
+
*/
|
|
2205
|
+
private applyTemporalCoSpending;
|
|
2206
|
+
/**
|
|
2207
|
+
* Heuristic 5: Declared Wallets (confidence 1.0)
|
|
2208
|
+
* All wallets declared by the same identity are unioned.
|
|
2209
|
+
*/
|
|
2210
|
+
private applyDeclaredWallets;
|
|
2211
|
+
private buildClusters;
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
/**
|
|
2215
|
+
* Computes behavioral fingerprints (embeddings) from agent transaction patterns.
|
|
2216
|
+
* Used for cross-session linking and behavioral consistency scoring.
|
|
2217
|
+
*/
|
|
2218
|
+
declare class BehavioralFingerprinter {
|
|
2219
|
+
/**
|
|
2220
|
+
* Compute a behavioral embedding for an agent from their transaction history.
|
|
2221
|
+
* Returns null if the agent has fewer than MIN_SAMPLE_SIZE transactions.
|
|
2222
|
+
*/
|
|
2223
|
+
computeEmbedding(agentId: string, store: KontextStore): BehavioralEmbedding | null;
|
|
2224
|
+
/**
|
|
2225
|
+
* Compute cosine similarity between two behavioral embeddings.
|
|
2226
|
+
* Returns a value in [0, 1] where 1 means identical and 0 means orthogonal.
|
|
2227
|
+
*/
|
|
2228
|
+
cosineSimilarity(a: BehavioralEmbedding, b: BehavioralEmbedding): number;
|
|
2229
|
+
private extractTemporalFeatures;
|
|
2230
|
+
private extractFinancialFeatures;
|
|
2231
|
+
private extractNetworkFeatures;
|
|
2232
|
+
private extractOperationalFeatures;
|
|
2233
|
+
private percentile;
|
|
2234
|
+
/**
|
|
2235
|
+
* Flatten an embedding into a numeric vector for cosine similarity.
|
|
2236
|
+
* Log-scales magnitude values with log(1+x).
|
|
2237
|
+
*/
|
|
2238
|
+
private flattenEmbedding;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
/**
|
|
2242
|
+
* Links agents across sessions by analyzing wallet graph overlap,
|
|
2243
|
+
* behavioral similarity, and declared identity signals.
|
|
2244
|
+
*/
|
|
2245
|
+
declare class CrossSessionLinker {
|
|
2246
|
+
private readonly config;
|
|
2247
|
+
private readonly links;
|
|
2248
|
+
constructor(config?: CrossSessionLinkerConfig);
|
|
2249
|
+
/**
|
|
2250
|
+
* Analyze all agents and create links between those with sufficient signals.
|
|
2251
|
+
*/
|
|
2252
|
+
analyzeAndLink(store: KontextStore, registry: AgentIdentityRegistry, clusterer: WalletClusterer, fingerprinter: BehavioralFingerprinter): AgentLink[];
|
|
2253
|
+
/**
|
|
2254
|
+
* Manually link two agents.
|
|
2255
|
+
*/
|
|
2256
|
+
manualLink(agentIdA: string, agentIdB: string, reviewedBy: string): AgentLink;
|
|
2257
|
+
/**
|
|
2258
|
+
* Review a link (confirm or reject).
|
|
2259
|
+
*/
|
|
2260
|
+
reviewLink(linkId: string, decision: 'confirmed' | 'rejected', reviewedBy: string): AgentLink | undefined;
|
|
2261
|
+
/**
|
|
2262
|
+
* Get all agents linked to the given agent.
|
|
2263
|
+
*/
|
|
2264
|
+
getLinkedAgents(agentId: string): string[];
|
|
2265
|
+
/**
|
|
2266
|
+
* Get all links for a specific agent.
|
|
2267
|
+
*/
|
|
2268
|
+
getLinksForAgent(agentId: string): AgentLink[];
|
|
2269
|
+
/**
|
|
2270
|
+
* Get all links.
|
|
2271
|
+
*/
|
|
2272
|
+
getAllLinks(): AgentLink[];
|
|
2273
|
+
private getLinkKey;
|
|
2274
|
+
private computeWalletOverlap;
|
|
2275
|
+
private computeDeclaredIdentitySignal;
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
/**
|
|
2279
|
+
* Computes a composite KYA confidence score from 5 signal components.
|
|
2280
|
+
*/
|
|
2281
|
+
declare class KYAConfidenceScorer {
|
|
2282
|
+
private readonly weights;
|
|
2283
|
+
constructor(config?: KYAConfidenceScorerConfig);
|
|
2284
|
+
/**
|
|
2285
|
+
* Compute a composite confidence score for an agent.
|
|
2286
|
+
*/
|
|
2287
|
+
computeScore(agentId: string, registry: AgentIdentityRegistry, clusterer: WalletClusterer, fingerprinter: BehavioralFingerprinter, linker: CrossSessionLinker, store: KontextStore): KYAConfidenceScore;
|
|
2288
|
+
private scoreDeclaredIdentity;
|
|
2289
|
+
private scoreKycVerification;
|
|
2290
|
+
private scoreWalletGraph;
|
|
2291
|
+
private scoreBehavioralConsistency;
|
|
2292
|
+
private scoreExternalEnrichment;
|
|
2293
|
+
private scoreToLevel;
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
/**
|
|
2297
|
+
* Main Kontext SDK client. Provides a unified interface to all SDK features:
|
|
2298
|
+
* action logging, task confirmation, audit export, trust scoring, and
|
|
2299
|
+
* anomaly detection.
|
|
2300
|
+
*
|
|
2301
|
+
* Supports two operating modes:
|
|
2302
|
+
* - **Local mode** (no API key): All data stored locally, suitable for
|
|
2303
|
+
* open-source usage and development.
|
|
2304
|
+
* - **Cloud mode** (with API key): Data synced to Kontext API for
|
|
2305
|
+
* persistent storage and advanced features.
|
|
2306
|
+
*
|
|
2307
|
+
* @example
|
|
2308
|
+
* ```typescript
|
|
2309
|
+
* import { Kontext } from '@kontext/sdk';
|
|
2310
|
+
*
|
|
2311
|
+
* const kontext = Kontext.init({
|
|
2312
|
+
* projectId: 'my-project',
|
|
2313
|
+
* environment: 'development',
|
|
2314
|
+
* });
|
|
2315
|
+
*
|
|
2316
|
+
* await kontext.logTransaction({
|
|
2317
|
+
* txHash: '0x...',
|
|
2318
|
+
* chain: 'base',
|
|
2319
|
+
* amount: '100',
|
|
2320
|
+
* token: 'USDC',
|
|
2321
|
+
* from: '0xSender',
|
|
2322
|
+
* to: '0xReceiver',
|
|
2323
|
+
* agentId: 'agent-1',
|
|
2324
|
+
* });
|
|
2325
|
+
* ```
|
|
2326
|
+
*/
|
|
2327
|
+
declare class Kontext {
|
|
2328
|
+
private readonly config;
|
|
2329
|
+
private readonly store;
|
|
2330
|
+
private readonly logger;
|
|
2331
|
+
private readonly taskManager;
|
|
2332
|
+
private readonly auditExporter;
|
|
2333
|
+
private readonly mode;
|
|
2334
|
+
private readonly planManager;
|
|
2335
|
+
private readonly exporter;
|
|
2336
|
+
private readonly featureFlagManager;
|
|
2337
|
+
private readonly trustScorer;
|
|
2338
|
+
private readonly anomalyDetector;
|
|
2339
|
+
private readonly screeningAggregator;
|
|
2340
|
+
private provenanceManager;
|
|
2341
|
+
private identityRegistry;
|
|
2342
|
+
private walletClusterer;
|
|
2343
|
+
private behavioralFingerprinter;
|
|
2344
|
+
private crossSessionLinker;
|
|
2345
|
+
private confidenceScorer;
|
|
2346
|
+
private constructor();
|
|
2347
|
+
/**
|
|
2348
|
+
* Initialize the Kontext SDK.
|
|
2349
|
+
*
|
|
2350
|
+
* @param config - Configuration options
|
|
2351
|
+
* @returns Initialized Kontext client instance
|
|
2352
|
+
*
|
|
2353
|
+
* @example
|
|
2354
|
+
* ```typescript
|
|
2355
|
+
* // Local/OSS mode (no API key)
|
|
2356
|
+
* const kontext = Kontext.init({
|
|
2357
|
+
* projectId: 'my-project',
|
|
2358
|
+
* environment: 'development',
|
|
2359
|
+
* });
|
|
2360
|
+
*
|
|
2361
|
+
* // Cloud mode (with API key)
|
|
2362
|
+
* const kontext = Kontext.init({
|
|
2363
|
+
* apiKey: 'sk_live_...',
|
|
2364
|
+
* projectId: 'my-project',
|
|
2365
|
+
* environment: 'production',
|
|
2366
|
+
* });
|
|
2367
|
+
*
|
|
2368
|
+
* // With persistent file storage
|
|
2369
|
+
* const kontext = Kontext.init({
|
|
2370
|
+
* projectId: 'my-project',
|
|
2371
|
+
* environment: 'development',
|
|
2372
|
+
* storage: new FileStorage('./kontext-data'),
|
|
2373
|
+
* });
|
|
2374
|
+
* ```
|
|
2375
|
+
*/
|
|
2376
|
+
static init(config: KontextConfig): Kontext;
|
|
2377
|
+
/**
|
|
2378
|
+
* Get the current operating mode.
|
|
2379
|
+
*/
|
|
2380
|
+
getMode(): KontextMode;
|
|
2381
|
+
/**
|
|
2382
|
+
* Get the current configuration (API key is masked).
|
|
2383
|
+
*/
|
|
2384
|
+
getConfig(): Omit<KontextConfig, 'apiKey'> & {
|
|
2385
|
+
apiKey?: string;
|
|
2386
|
+
};
|
|
2387
|
+
/**
|
|
2388
|
+
* Validate metadata against the configured schema, if any.
|
|
2389
|
+
* No-op when metadataSchema is not configured.
|
|
2390
|
+
*/
|
|
2391
|
+
private validateMetadata;
|
|
2392
|
+
/**
|
|
2393
|
+
* Map aggregated screening results into UsdcComplianceCheck format.
|
|
2394
|
+
* Produces the same check/riskLevel/recommendations shape as
|
|
2395
|
+
* UsdcCompliance.checkTransaction() and PaymentCompliance.checkPayment().
|
|
2396
|
+
*/
|
|
2397
|
+
private buildComplianceFromScreening;
|
|
2398
|
+
/** Lazy-init ProvenanceManager on first use. */
|
|
2399
|
+
private getProvenanceManager;
|
|
2400
|
+
/** Lazy-init AgentIdentityRegistry on first use. */
|
|
2401
|
+
private getIdentityRegistry;
|
|
2402
|
+
/** Lazy-init WalletClusterer on first use. */
|
|
2403
|
+
private getWalletClusterer;
|
|
2404
|
+
/** Lazy-init BehavioralFingerprinter on first use. */
|
|
2405
|
+
private getBehavioralFingerprinter;
|
|
2406
|
+
/** Lazy-init CrossSessionLinker on first use. */
|
|
2407
|
+
private getCrossSessionLinker;
|
|
2408
|
+
/** Lazy-init KYAConfidenceScorer on first use. */
|
|
2409
|
+
private getConfidenceScorer;
|
|
2410
|
+
/**
|
|
2411
|
+
* Log a generic agent action.
|
|
2412
|
+
*
|
|
2413
|
+
* @param input - Action details
|
|
2414
|
+
* @returns The created action log entry
|
|
2415
|
+
*/
|
|
2416
|
+
log(input: LogActionInput): Promise<ActionLog>;
|
|
2417
|
+
/**
|
|
2418
|
+
* Log a cryptocurrency transaction with full chain details.
|
|
2419
|
+
*
|
|
2420
|
+
* @param input - Transaction details
|
|
2421
|
+
* @returns The created transaction record
|
|
2422
|
+
*/
|
|
2423
|
+
logTransaction(input: LogTransactionInput): Promise<TransactionRecord>;
|
|
2424
|
+
/**
|
|
2425
|
+
* Flush any pending log batches.
|
|
2426
|
+
*/
|
|
2427
|
+
flushLogs(): Promise<void>;
|
|
2428
|
+
/**
|
|
2429
|
+
* Persist all current in-memory state to the attached storage adapter.
|
|
2430
|
+
* No-op if no storage adapter is configured.
|
|
2431
|
+
*/
|
|
2432
|
+
flush(): Promise<void>;
|
|
2433
|
+
/**
|
|
2434
|
+
* Restore state from the attached storage adapter.
|
|
2435
|
+
* Loads previously persisted actions, transactions, tasks, and anomalies.
|
|
2436
|
+
* Also restores the digest chain's terminal digest so that new actions
|
|
2437
|
+
* chain correctly across process boundaries.
|
|
2438
|
+
* No-op if no storage adapter is configured.
|
|
2439
|
+
*/
|
|
2440
|
+
restore(): Promise<void>;
|
|
2441
|
+
/**
|
|
2442
|
+
* Create a new tracked task that requires evidence for confirmation.
|
|
2443
|
+
*
|
|
2444
|
+
* @param input - Task details including required evidence types
|
|
2445
|
+
* @returns The created task
|
|
2446
|
+
*/
|
|
2447
|
+
createTask(input: CreateTaskInput): Promise<Task>;
|
|
2448
|
+
/**
|
|
2449
|
+
* Confirm a task by providing evidence.
|
|
2450
|
+
*
|
|
2451
|
+
* @param input - Task ID and evidence data
|
|
2452
|
+
* @returns The confirmed task
|
|
2453
|
+
*/
|
|
2454
|
+
confirmTask(input: ConfirmTaskInput): Promise<Task>;
|
|
2455
|
+
/**
|
|
2456
|
+
* Get the current status of a task.
|
|
2457
|
+
*
|
|
2458
|
+
* @param taskId - Task identifier
|
|
2459
|
+
* @returns The task or undefined if not found
|
|
2460
|
+
*/
|
|
2461
|
+
getTaskStatus(taskId: string): Promise<Task | undefined>;
|
|
2462
|
+
/**
|
|
2463
|
+
* Mark a task as in-progress.
|
|
2464
|
+
*
|
|
2465
|
+
* @param taskId - Task identifier
|
|
2466
|
+
* @returns The updated task
|
|
2467
|
+
*/
|
|
2468
|
+
startTask(taskId: string): Promise<Task>;
|
|
2469
|
+
/**
|
|
2470
|
+
* Mark a task as failed.
|
|
2471
|
+
*
|
|
2472
|
+
* @param taskId - Task identifier
|
|
2473
|
+
* @param reason - Reason for failure
|
|
2474
|
+
* @returns The updated task
|
|
2475
|
+
*/
|
|
2476
|
+
failTask(taskId: string, reason: string): Promise<Task>;
|
|
1515
2477
|
/**
|
|
1516
2478
|
* Get all tasks, optionally filtered by status.
|
|
1517
2479
|
*
|
|
@@ -1727,7 +2689,121 @@ declare class Kontext {
|
|
|
1727
2689
|
* console.log(cert.contentHash); // sha256 of certificate
|
|
1728
2690
|
* ```
|
|
1729
2691
|
*/
|
|
1730
|
-
generateComplianceCertificate(input: GenerateComplianceCertificateInput): Promise<ComplianceCertificate>;
|
|
2692
|
+
generateComplianceCertificate(input: GenerateComplianceCertificateInput): Promise<ComplianceCertificate>;
|
|
2693
|
+
/**
|
|
2694
|
+
* Create a delegated agent session. Records the delegation in the
|
|
2695
|
+
* tamper-evident digest chain as the session's genesis event.
|
|
2696
|
+
*/
|
|
2697
|
+
createAgentSession(input: CreateSessionInput): Promise<AgentSession>;
|
|
2698
|
+
/**
|
|
2699
|
+
* Get an agent session by ID. Automatically marks expired sessions.
|
|
2700
|
+
*/
|
|
2701
|
+
getAgentSession(sessionId: string): AgentSession | undefined;
|
|
2702
|
+
/**
|
|
2703
|
+
* Get all agent sessions.
|
|
2704
|
+
*/
|
|
2705
|
+
getAgentSessions(): AgentSession[];
|
|
2706
|
+
/**
|
|
2707
|
+
* End an active agent session. Records the termination in the digest chain.
|
|
2708
|
+
*/
|
|
2709
|
+
endAgentSession(sessionId: string): Promise<AgentSession>;
|
|
2710
|
+
/**
|
|
2711
|
+
* Check whether an action is within a session's delegated scope.
|
|
2712
|
+
*/
|
|
2713
|
+
validateSessionScope(sessionId: string, action: string): boolean;
|
|
2714
|
+
/**
|
|
2715
|
+
* Get all actions bound to a session (via sessionId on log/verify calls).
|
|
2716
|
+
*/
|
|
2717
|
+
getSessionActions(sessionId: string): ActionLog[];
|
|
2718
|
+
/**
|
|
2719
|
+
* Create a provenance checkpoint -- a review point where a human
|
|
2720
|
+
* can attest to a batch of agent actions.
|
|
2721
|
+
*/
|
|
2722
|
+
createCheckpoint(input: CreateCheckpointInput): Promise<ProvenanceCheckpoint>;
|
|
2723
|
+
/**
|
|
2724
|
+
* Attach an externally-produced human attestation to a checkpoint.
|
|
2725
|
+
* The attestation includes a cryptographic signature that the agent
|
|
2726
|
+
* never touches -- key separation is the critical security property.
|
|
2727
|
+
*/
|
|
2728
|
+
attachAttestation(checkpointId: string, attestation: HumanAttestation): Promise<ProvenanceCheckpoint>;
|
|
2729
|
+
/**
|
|
2730
|
+
* Get a checkpoint by ID.
|
|
2731
|
+
*/
|
|
2732
|
+
getCheckpoint(checkpointId: string): ProvenanceCheckpoint | undefined;
|
|
2733
|
+
/**
|
|
2734
|
+
* Get all checkpoints, optionally filtered by session.
|
|
2735
|
+
*/
|
|
2736
|
+
getCheckpoints(sessionId?: string): ProvenanceCheckpoint[];
|
|
2737
|
+
/**
|
|
2738
|
+
* Export the full provenance bundle for a session: session record,
|
|
2739
|
+
* all bound actions, all checkpoints, and verification stats.
|
|
2740
|
+
*/
|
|
2741
|
+
getProvenanceBundle(sessionId: string): ProvenanceBundle;
|
|
2742
|
+
/**
|
|
2743
|
+
* Register a new agent identity with optional wallet mappings.
|
|
2744
|
+
* Requires Pro plan.
|
|
2745
|
+
*/
|
|
2746
|
+
registerAgentIdentity(input: RegisterIdentityInput): AgentIdentity;
|
|
2747
|
+
/**
|
|
2748
|
+
* Get a registered agent identity by ID.
|
|
2749
|
+
* Requires Pro plan.
|
|
2750
|
+
*/
|
|
2751
|
+
getAgentIdentity(agentId: string): AgentIdentity | undefined;
|
|
2752
|
+
/**
|
|
2753
|
+
* Update an existing agent identity.
|
|
2754
|
+
* Requires Pro plan.
|
|
2755
|
+
*/
|
|
2756
|
+
updateAgentIdentity(agentId: string, input: UpdateIdentityInput): AgentIdentity;
|
|
2757
|
+
/**
|
|
2758
|
+
* Remove an agent identity.
|
|
2759
|
+
* Requires Pro plan.
|
|
2760
|
+
*/
|
|
2761
|
+
removeAgentIdentity(agentId: string): boolean;
|
|
2762
|
+
/**
|
|
2763
|
+
* Add a wallet to an existing agent identity.
|
|
2764
|
+
* Requires Pro plan.
|
|
2765
|
+
*/
|
|
2766
|
+
addAgentWallet(agentId: string, wallet: {
|
|
2767
|
+
address: string;
|
|
2768
|
+
chain: string;
|
|
2769
|
+
label?: string;
|
|
2770
|
+
isPrimary?: boolean;
|
|
2771
|
+
}): AgentIdentity;
|
|
2772
|
+
/**
|
|
2773
|
+
* Look up which agent owns a wallet address.
|
|
2774
|
+
* Requires Pro plan.
|
|
2775
|
+
*/
|
|
2776
|
+
lookupAgentByWallet(address: string): AgentIdentity | undefined;
|
|
2777
|
+
/**
|
|
2778
|
+
* Compute wallet clusters from transaction patterns and declared identities.
|
|
2779
|
+
* Requires Pro plan.
|
|
2780
|
+
*/
|
|
2781
|
+
getWalletClusters(): WalletCluster[];
|
|
2782
|
+
/**
|
|
2783
|
+
* Export all KYA data as a single envelope.
|
|
2784
|
+
* Requires Pro plan.
|
|
2785
|
+
*/
|
|
2786
|
+
getKYAExport(): KYAEnvelope;
|
|
2787
|
+
/**
|
|
2788
|
+
* Compute a behavioral embedding for an agent from transaction history.
|
|
2789
|
+
* Returns null if insufficient data. Requires Enterprise plan.
|
|
2790
|
+
*/
|
|
2791
|
+
computeBehavioralEmbedding(agentId: string): BehavioralEmbedding | null;
|
|
2792
|
+
/**
|
|
2793
|
+
* Analyze all agents and create cross-session links.
|
|
2794
|
+
* Requires Enterprise plan.
|
|
2795
|
+
*/
|
|
2796
|
+
analyzeAgentLinks(): AgentLink[];
|
|
2797
|
+
/**
|
|
2798
|
+
* Get agents linked to a specific agent.
|
|
2799
|
+
* Requires Enterprise plan.
|
|
2800
|
+
*/
|
|
2801
|
+
getLinkedAgents(agentId: string): string[];
|
|
2802
|
+
/**
|
|
2803
|
+
* Compute a composite identity confidence score for an agent.
|
|
2804
|
+
* Requires Enterprise plan.
|
|
2805
|
+
*/
|
|
2806
|
+
getKYAConfidenceScore(agentId: string): KYAConfidenceScore;
|
|
1731
2807
|
/**
|
|
1732
2808
|
* Get current usage statistics for the plan.
|
|
1733
2809
|
*
|
|
@@ -1976,6 +3052,27 @@ declare class OnChainExporter implements EventExporter {
|
|
|
1976
3052
|
shutdown(): Promise<void>;
|
|
1977
3053
|
}
|
|
1978
3054
|
|
|
3055
|
+
/** Default builder code for Kontext anchor transactions */
|
|
3056
|
+
declare const KONTEXT_BUILDER_CODE = "kontext";
|
|
3057
|
+
/**
|
|
3058
|
+
* Encode an ERC-8021 data suffix for the given builder codes.
|
|
3059
|
+
* Returns hex string (no 0x prefix) to append directly to calldata.
|
|
3060
|
+
*
|
|
3061
|
+
* Layout: [codesLength (1 byte)][codes (ASCII, comma-delimited)][schemaId (1 byte)][marker (16 bytes)]
|
|
3062
|
+
*/
|
|
3063
|
+
declare function encodeERC8021Suffix(codes: string[]): string;
|
|
3064
|
+
/**
|
|
3065
|
+
* Parse an ERC-8021 data suffix from calldata.
|
|
3066
|
+
* Returns null if the calldata does not contain a valid ERC-8021 suffix.
|
|
3067
|
+
* Parses backward from the end of calldata.
|
|
3068
|
+
*/
|
|
3069
|
+
declare function parseERC8021Suffix(calldata: string): ERC8021Attribution | null;
|
|
3070
|
+
/**
|
|
3071
|
+
* Fetch a transaction's calldata and parse ERC-8021 attribution.
|
|
3072
|
+
* Uses eth_getTransactionByHash via JSON-RPC (zero dependencies).
|
|
3073
|
+
*/
|
|
3074
|
+
declare function fetchTransactionAttribution(rpcUrl: string, txHash: string): Promise<ERC8021Attribution | null>;
|
|
3075
|
+
|
|
1979
3076
|
/**
|
|
1980
3077
|
* Fetch the counterparty's agent card from /.well-known/kontext.json
|
|
1981
3078
|
*/
|
|
@@ -1993,86 +3090,164 @@ declare function fetchAgentCard(endpoint: string, timeoutMs?: number): Promise<A
|
|
|
1993
3090
|
declare function exchangeAttestation(config: CounterpartyConfig, request: AttestationRequest): Promise<CounterpartyAttestation>;
|
|
1994
3091
|
|
|
1995
3092
|
/**
|
|
1996
|
-
*
|
|
1997
|
-
* Holds all action logs, transactions, tasks, and anomaly events.
|
|
3093
|
+
* ActionLogger handles structured logging of all agent actions.
|
|
1998
3094
|
*
|
|
1999
|
-
*
|
|
2000
|
-
*
|
|
3095
|
+
* Supports two output modes:
|
|
3096
|
+
* - **Local mode** (no API key): Writes structured JSON logs to the local filesystem.
|
|
3097
|
+
* - **Cloud mode** (with API key): Batches and sends logs to the Kontext API.
|
|
3098
|
+
*
|
|
3099
|
+
* Logs include timestamps, agent IDs, correlation IDs, and arbitrary metadata
|
|
3100
|
+
* for full audit traceability.
|
|
2001
3101
|
*/
|
|
2002
|
-
declare class
|
|
2003
|
-
private
|
|
2004
|
-
private
|
|
2005
|
-
private
|
|
2006
|
-
private
|
|
2007
|
-
private
|
|
2008
|
-
private readonly
|
|
2009
|
-
|
|
3102
|
+
declare class ActionLogger {
|
|
3103
|
+
private readonly config;
|
|
3104
|
+
private readonly store;
|
|
3105
|
+
private readonly digestChain;
|
|
3106
|
+
private batch;
|
|
3107
|
+
private flushTimer;
|
|
3108
|
+
private readonly batchSize;
|
|
3109
|
+
private readonly flushIntervalMs;
|
|
3110
|
+
private readonly isCloudMode;
|
|
3111
|
+
private readonly logLevel;
|
|
3112
|
+
constructor(config: KontextConfig, store: KontextStore);
|
|
2010
3113
|
/**
|
|
2011
|
-
*
|
|
3114
|
+
* Log a generic agent action.
|
|
2012
3115
|
*
|
|
2013
|
-
* @param
|
|
3116
|
+
* @param input - Action details including type, description, agentId, and metadata
|
|
3117
|
+
* @returns The created ActionLog entry
|
|
3118
|
+
*
|
|
3119
|
+
* @example
|
|
3120
|
+
* ```typescript
|
|
3121
|
+
* const action = await logger.log({
|
|
3122
|
+
* type: 'approval',
|
|
3123
|
+
* description: 'Agent approved USDC spending',
|
|
3124
|
+
* agentId: 'agent-1',
|
|
3125
|
+
* metadata: { spender: '0x...', amount: '1000' },
|
|
3126
|
+
* });
|
|
3127
|
+
* ```
|
|
2014
3128
|
*/
|
|
2015
|
-
|
|
3129
|
+
log(input: LogActionInput): Promise<ActionLog>;
|
|
2016
3130
|
/**
|
|
2017
|
-
*
|
|
3131
|
+
* Log a cryptocurrency transaction with full chain details.
|
|
3132
|
+
*
|
|
3133
|
+
* @param input - Transaction details including txHash, chain, amount, token, from, to
|
|
3134
|
+
* @returns The created TransactionRecord
|
|
3135
|
+
*
|
|
3136
|
+
* @example
|
|
3137
|
+
* ```typescript
|
|
3138
|
+
* const tx = await logger.logTransaction({
|
|
3139
|
+
* txHash: '0xabc123...',
|
|
3140
|
+
* chain: 'base',
|
|
3141
|
+
* amount: '100.00',
|
|
3142
|
+
* token: 'USDC',
|
|
3143
|
+
* from: '0xSender...',
|
|
3144
|
+
* to: '0xReceiver...',
|
|
3145
|
+
* agentId: 'payment-agent-1',
|
|
3146
|
+
* });
|
|
3147
|
+
* ```
|
|
2018
3148
|
*/
|
|
2019
|
-
|
|
3149
|
+
logTransaction(input: LogTransactionInput): Promise<TransactionRecord>;
|
|
2020
3150
|
/**
|
|
2021
|
-
*
|
|
2022
|
-
*
|
|
3151
|
+
* Flush the current batch of logs.
|
|
3152
|
+
* In local mode, writes to a JSON file.
|
|
3153
|
+
* In cloud mode, sends to the Kontext API.
|
|
2023
3154
|
*/
|
|
2024
3155
|
flush(): Promise<void>;
|
|
2025
3156
|
/**
|
|
2026
|
-
*
|
|
2027
|
-
* Merges loaded data with any existing in-memory data.
|
|
2028
|
-
* No-op if no adapter is attached.
|
|
3157
|
+
* Stop the logger and flush any remaining logs.
|
|
2029
3158
|
*/
|
|
2030
|
-
|
|
2031
|
-
/**
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
/**
|
|
2075
|
-
|
|
3159
|
+
destroy(): Promise<void>;
|
|
3160
|
+
/**
|
|
3161
|
+
* Get the terminal digest — the latest SHA-256 digest in the chain.
|
|
3162
|
+
* Can be embedded in outgoing messages as tamper-evident proof.
|
|
3163
|
+
*/
|
|
3164
|
+
getTerminalDigest(): string;
|
|
3165
|
+
/**
|
|
3166
|
+
* Get the full digest chain for export or verification.
|
|
3167
|
+
*/
|
|
3168
|
+
getDigestChain(): DigestChain;
|
|
3169
|
+
/**
|
|
3170
|
+
* Verify the integrity of the digest chain against stored actions.
|
|
3171
|
+
*/
|
|
3172
|
+
verifyChain(actions: ActionLog[]): ReturnType<DigestChain['verify']>;
|
|
3173
|
+
/**
|
|
3174
|
+
* Restore chain state from persisted actions so that new actions
|
|
3175
|
+
* chain correctly across process boundaries.
|
|
3176
|
+
*/
|
|
3177
|
+
restoreChainState(terminalDigest: string): void;
|
|
3178
|
+
private validateTransactionInput;
|
|
3179
|
+
private flushToFile;
|
|
3180
|
+
private flushToApi;
|
|
3181
|
+
/**
|
|
3182
|
+
* Emit a log message at the specified severity level.
|
|
3183
|
+
* Only outputs if the message level meets or exceeds the configured logLevel.
|
|
3184
|
+
*/
|
|
3185
|
+
emitLog(level: LogLevel, message: string, data?: unknown): void;
|
|
3186
|
+
}
|
|
3187
|
+
|
|
3188
|
+
/**
|
|
3189
|
+
* Manages agent provenance across three layers:
|
|
3190
|
+
* - Layer 1: Session delegation (who authorized the agent)
|
|
3191
|
+
* - Layer 2: Action binding (actions linked to sessions via sessionId)
|
|
3192
|
+
* - Layer 3: Human attestation checkpoints (cryptographic review proof)
|
|
3193
|
+
*/
|
|
3194
|
+
declare class ProvenanceManager {
|
|
3195
|
+
private readonly store;
|
|
3196
|
+
private readonly logger;
|
|
3197
|
+
constructor(store: KontextStore, logger: ActionLogger);
|
|
3198
|
+
/**
|
|
3199
|
+
* Create a delegated agent session. Records the delegation in the
|
|
3200
|
+
* tamper-evident digest chain as the session's genesis event.
|
|
3201
|
+
*/
|
|
3202
|
+
createSession(input: CreateSessionInput): Promise<AgentSession>;
|
|
3203
|
+
/**
|
|
3204
|
+
* Get an agent session by ID. Automatically marks expired sessions.
|
|
3205
|
+
*/
|
|
3206
|
+
getSession(sessionId: string): AgentSession | undefined;
|
|
3207
|
+
/**
|
|
3208
|
+
* Get all agent sessions.
|
|
3209
|
+
*/
|
|
3210
|
+
getSessions(): AgentSession[];
|
|
3211
|
+
/**
|
|
3212
|
+
* End an active agent session. Records the termination in the digest chain.
|
|
3213
|
+
*/
|
|
3214
|
+
endSession(sessionId: string): Promise<AgentSession>;
|
|
3215
|
+
/**
|
|
3216
|
+
* Check whether an action is within a session's delegated scope.
|
|
3217
|
+
*/
|
|
3218
|
+
validateScope(sessionId: string, action: string): boolean;
|
|
3219
|
+
/**
|
|
3220
|
+
* Check whether a transaction meets session constraints.
|
|
3221
|
+
*/
|
|
3222
|
+
validateConstraints(sessionId: string, input: {
|
|
3223
|
+
amount?: string;
|
|
3224
|
+
chain?: string;
|
|
3225
|
+
token?: string;
|
|
3226
|
+
to?: string;
|
|
3227
|
+
}): boolean;
|
|
3228
|
+
/**
|
|
3229
|
+
* Create a provenance checkpoint -- a review point where a human
|
|
3230
|
+
* can attest to a batch of agent actions.
|
|
3231
|
+
*/
|
|
3232
|
+
createCheckpoint(input: CreateCheckpointInput): Promise<ProvenanceCheckpoint>;
|
|
3233
|
+
/**
|
|
3234
|
+
* Attach an externally-produced human attestation to a checkpoint.
|
|
3235
|
+
* The attestation includes a cryptographic signature that the agent
|
|
3236
|
+
* never touches -- key separation is the critical security property.
|
|
3237
|
+
*/
|
|
3238
|
+
attachAttestation(checkpointId: string, attestation: HumanAttestation): Promise<ProvenanceCheckpoint>;
|
|
3239
|
+
/**
|
|
3240
|
+
* Get a checkpoint by ID. Automatically marks expired checkpoints.
|
|
3241
|
+
*/
|
|
3242
|
+
getCheckpoint(checkpointId: string): ProvenanceCheckpoint | undefined;
|
|
3243
|
+
/**
|
|
3244
|
+
* Get all checkpoints, optionally filtered by session.
|
|
3245
|
+
*/
|
|
3246
|
+
getCheckpoints(sessionId?: string): ProvenanceCheckpoint[];
|
|
3247
|
+
/**
|
|
3248
|
+
* Export the full provenance bundle for a session.
|
|
3249
|
+
*/
|
|
3250
|
+
getProvenanceBundle(sessionId: string): ProvenanceBundle;
|
|
2076
3251
|
}
|
|
2077
3252
|
|
|
2078
3253
|
/** Pre-fetched data for a single agent, passed to factor methods to avoid redundant store queries. */
|
|
@@ -2337,4 +3512,346 @@ declare class AnomalyDetector {
|
|
|
2337
3512
|
private notifyCallbacks;
|
|
2338
3513
|
}
|
|
2339
3514
|
|
|
2340
|
-
|
|
3515
|
+
/**
|
|
3516
|
+
* OFAC SDN Address Provider.
|
|
3517
|
+
*
|
|
3518
|
+
* Screens blockchain addresses against the U.S. Treasury OFAC Specially
|
|
3519
|
+
* Designated Nationals (SDN) list. Uses ~33 hardcoded addresses from
|
|
3520
|
+
* the public SDN list. Distinguishes between actively sanctioned and
|
|
3521
|
+
* delisted (formerly sanctioned) addresses.
|
|
3522
|
+
*
|
|
3523
|
+
* - **Free tier**, no API key required
|
|
3524
|
+
* - **Browser-safe** — pure in-memory lookups
|
|
3525
|
+
* - O(1) Set lookup, case-insensitive
|
|
3526
|
+
*
|
|
3527
|
+
* @example
|
|
3528
|
+
* ```typescript
|
|
3529
|
+
* const provider = new OFACAddressProvider();
|
|
3530
|
+
* const result = await provider.screen('0x098B716B8Aaf21512996dC57EB0615e2383E2f96');
|
|
3531
|
+
* // result.hit === true (Lazarus Group, OFAC sanctioned)
|
|
3532
|
+
* ```
|
|
3533
|
+
*/
|
|
3534
|
+
declare class OFACAddressProvider implements ScreeningProvider {
|
|
3535
|
+
readonly id = "ofac-sdn-address";
|
|
3536
|
+
readonly name = "OFAC SDN Address Screener";
|
|
3537
|
+
readonly lists: readonly SanctionsList[];
|
|
3538
|
+
readonly requiresApiKey = false;
|
|
3539
|
+
readonly browserCompatible = true;
|
|
3540
|
+
readonly queryTypes: readonly QueryType[];
|
|
3541
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3542
|
+
isAvailable(): boolean;
|
|
3543
|
+
getEntryCount(): number;
|
|
3544
|
+
}
|
|
3545
|
+
|
|
3546
|
+
/**
|
|
3547
|
+
* OFAC SDN Entity Name Provider.
|
|
3548
|
+
*
|
|
3549
|
+
* Screens entity/person names against the full OFAC SDN entity database
|
|
3550
|
+
* (18,664 entities) using fuzzy string matching. Wraps the existing
|
|
3551
|
+
* `OFACSanctionsScreener` from `ofac-sanctions.ts`.
|
|
3552
|
+
*
|
|
3553
|
+
* - **Free tier**, no API key required
|
|
3554
|
+
* - **Node.js only** — loads full SDN data, too large for browser
|
|
3555
|
+
* - Fuzzy matching at 0.85 threshold with minimum 4-char match length
|
|
3556
|
+
* - Distinguishes between active and delisted entities
|
|
3557
|
+
*
|
|
3558
|
+
* @example
|
|
3559
|
+
* ```typescript
|
|
3560
|
+
* const provider = new OFACEntityProvider();
|
|
3561
|
+
* if (provider.isAvailable()) {
|
|
3562
|
+
* const result = await provider.screen('Lazarus Group');
|
|
3563
|
+
* // result.hit === true
|
|
3564
|
+
* }
|
|
3565
|
+
* ```
|
|
3566
|
+
*/
|
|
3567
|
+
declare class OFACEntityProvider implements ScreeningProvider {
|
|
3568
|
+
readonly id = "ofac-sdn-entity";
|
|
3569
|
+
readonly name = "OFAC SDN Entity Screener";
|
|
3570
|
+
readonly lists: readonly SanctionsList[];
|
|
3571
|
+
readonly requiresApiKey = false;
|
|
3572
|
+
readonly browserCompatible = false;
|
|
3573
|
+
readonly queryTypes: readonly QueryType[];
|
|
3574
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3575
|
+
isAvailable(): boolean;
|
|
3576
|
+
getEntryCount(): number;
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3579
|
+
/**
|
|
3580
|
+
* UK OFSI Address Provider.
|
|
3581
|
+
*
|
|
3582
|
+
* Screens blockchain addresses against the UK OFSI Consolidated List.
|
|
3583
|
+
* Coverage is limited compared to OFAC — most UK sanctions are entity-name-based.
|
|
3584
|
+
* For comprehensive UK entity screening, use OpenSanctionsProvider.
|
|
3585
|
+
*
|
|
3586
|
+
* - **Free tier**, no API key required
|
|
3587
|
+
* - **Browser-safe** — pure in-memory lookups
|
|
3588
|
+
*
|
|
3589
|
+
* @example
|
|
3590
|
+
* ```typescript
|
|
3591
|
+
* const provider = new UKOFSIProvider();
|
|
3592
|
+
* const result = await provider.screen('0x098B716B8Aaf21512996dC57EB0615e2383E2f96');
|
|
3593
|
+
* // result.hit === true (Lazarus Group, OFSI designated)
|
|
3594
|
+
* ```
|
|
3595
|
+
*/
|
|
3596
|
+
declare class UKOFSIProvider implements ScreeningProvider {
|
|
3597
|
+
readonly id = "uk-ofsi-address";
|
|
3598
|
+
readonly name = "UK OFSI Address Screener";
|
|
3599
|
+
readonly lists: readonly SanctionsList[];
|
|
3600
|
+
readonly requiresApiKey = false;
|
|
3601
|
+
readonly browserCompatible = true;
|
|
3602
|
+
readonly queryTypes: readonly QueryType[];
|
|
3603
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3604
|
+
isAvailable(): boolean;
|
|
3605
|
+
getEntryCount(): number;
|
|
3606
|
+
}
|
|
3607
|
+
|
|
3608
|
+
/**
|
|
3609
|
+
* OpenSanctions Local Provider.
|
|
3610
|
+
*
|
|
3611
|
+
* Screens addresses and entity names against locally-synced OpenSanctions
|
|
3612
|
+
* bulk data (331+ sources including APAC domestic lists).
|
|
3613
|
+
*
|
|
3614
|
+
* Data is NOT bundled — developers download via `kontext sync` and handle
|
|
3615
|
+
* their own OpenSanctions licensing (CC-BY-NC 4.0 for non-commercial,
|
|
3616
|
+
* commercial license for business use).
|
|
3617
|
+
*
|
|
3618
|
+
* - **Free tier**, no API key required
|
|
3619
|
+
* - **Node.js only** — reads from local filesystem
|
|
3620
|
+
* - Supports address + entity name queries
|
|
3621
|
+
*
|
|
3622
|
+
* @example
|
|
3623
|
+
* ```typescript
|
|
3624
|
+
* const provider = new OpenSanctionsLocalProvider();
|
|
3625
|
+
* if (provider.isAvailable()) {
|
|
3626
|
+
* const result = await provider.screen('Lazarus Group');
|
|
3627
|
+
* // result.hit === true if match found in local data
|
|
3628
|
+
* }
|
|
3629
|
+
* ```
|
|
3630
|
+
*/
|
|
3631
|
+
declare class OpenSanctionsLocalProvider implements ScreeningProvider {
|
|
3632
|
+
readonly id = "opensanctions-local";
|
|
3633
|
+
readonly name = "OpenSanctions (Local Data)";
|
|
3634
|
+
readonly lists: readonly SanctionsList[];
|
|
3635
|
+
readonly requiresApiKey = false;
|
|
3636
|
+
readonly browserCompatible = false;
|
|
3637
|
+
readonly queryTypes: readonly QueryType[];
|
|
3638
|
+
private dataDir;
|
|
3639
|
+
private entities;
|
|
3640
|
+
private addressSet;
|
|
3641
|
+
private addressToEntity;
|
|
3642
|
+
private loaded;
|
|
3643
|
+
constructor(dataDir?: string);
|
|
3644
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3645
|
+
isAvailable(): boolean;
|
|
3646
|
+
getEntryCount(): number;
|
|
3647
|
+
sync(): Promise<{
|
|
3648
|
+
updated: boolean;
|
|
3649
|
+
count: number;
|
|
3650
|
+
}>;
|
|
3651
|
+
private screenAddress;
|
|
3652
|
+
private screenEntityName;
|
|
3653
|
+
private entityToMatch;
|
|
3654
|
+
private getEntityStatus;
|
|
3655
|
+
private loadData;
|
|
3656
|
+
private resolveDataDir;
|
|
3657
|
+
}
|
|
3658
|
+
|
|
3659
|
+
/**
|
|
3660
|
+
* OpenSanctions REST API Provider.
|
|
3661
|
+
*
|
|
3662
|
+
* Screens both blockchain addresses AND entity names via the OpenSanctions
|
|
3663
|
+
* `/match` endpoint. Covers 331+ sanctions sources worldwide including
|
|
3664
|
+
* OFAC, EU, UN, UK, and APAC domestic lists.
|
|
3665
|
+
*
|
|
3666
|
+
* - **Free tier** in Kontext (metered by events)
|
|
3667
|
+
* - **Requires API key** from OpenSanctions (developer brings own key)
|
|
3668
|
+
* - **NOT browser-compatible** — requires server-side API calls
|
|
3669
|
+
*
|
|
3670
|
+
* @example
|
|
3671
|
+
* ```typescript
|
|
3672
|
+
* const provider = new OpenSanctionsProvider({
|
|
3673
|
+
* apiKey: process.env.OPENSANCTIONS_API_KEY!,
|
|
3674
|
+
* });
|
|
3675
|
+
* const result = await provider.screen('Lazarus Group');
|
|
3676
|
+
* ```
|
|
3677
|
+
*/
|
|
3678
|
+
declare class OpenSanctionsProvider implements ScreeningProvider {
|
|
3679
|
+
readonly id = "opensanctions-api";
|
|
3680
|
+
readonly name = "OpenSanctions (API)";
|
|
3681
|
+
readonly lists: readonly SanctionsList[];
|
|
3682
|
+
readonly requiresApiKey = true;
|
|
3683
|
+
readonly browserCompatible = false;
|
|
3684
|
+
readonly queryTypes: readonly QueryType[];
|
|
3685
|
+
private readonly apiKey;
|
|
3686
|
+
private readonly baseUrl;
|
|
3687
|
+
private readonly dataset;
|
|
3688
|
+
constructor(config: {
|
|
3689
|
+
apiKey: string;
|
|
3690
|
+
baseUrl?: string;
|
|
3691
|
+
dataset?: string;
|
|
3692
|
+
});
|
|
3693
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3694
|
+
isAvailable(): boolean;
|
|
3695
|
+
}
|
|
3696
|
+
/**
|
|
3697
|
+
* Chainalysis Free API Provider.
|
|
3698
|
+
*
|
|
3699
|
+
* Screens blockchain addresses via the Chainalysis free screening API.
|
|
3700
|
+
* Address-only — does not support entity name screening.
|
|
3701
|
+
*
|
|
3702
|
+
* - **Free tier** in Kontext (metered by events)
|
|
3703
|
+
* - **Requires API key** from Chainalysis (developer brings own key)
|
|
3704
|
+
* - **NOT browser-compatible** — requires server-side API calls
|
|
3705
|
+
*
|
|
3706
|
+
* @example
|
|
3707
|
+
* ```typescript
|
|
3708
|
+
* const provider = new ChainalysisFreeAPIProvider({
|
|
3709
|
+
* apiKey: process.env.CHAINALYSIS_API_KEY!,
|
|
3710
|
+
* });
|
|
3711
|
+
* const result = await provider.screen('0x098B716B8Aaf21512996dC57EB0615e2383E2f96');
|
|
3712
|
+
* ```
|
|
3713
|
+
*/
|
|
3714
|
+
declare class ChainalysisFreeAPIProvider implements ScreeningProvider {
|
|
3715
|
+
readonly id = "chainalysis-free-api";
|
|
3716
|
+
readonly name = "Chainalysis Free API";
|
|
3717
|
+
readonly lists: readonly SanctionsList[];
|
|
3718
|
+
readonly requiresApiKey = true;
|
|
3719
|
+
readonly browserCompatible = false;
|
|
3720
|
+
readonly queryTypes: readonly QueryType[];
|
|
3721
|
+
private readonly apiKey;
|
|
3722
|
+
private readonly baseUrl;
|
|
3723
|
+
constructor(config: {
|
|
3724
|
+
apiKey: string;
|
|
3725
|
+
baseUrl?: string;
|
|
3726
|
+
});
|
|
3727
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3728
|
+
isAvailable(): boolean;
|
|
3729
|
+
}
|
|
3730
|
+
|
|
3731
|
+
/**
|
|
3732
|
+
* Chainalysis OFAC Oracle Provider.
|
|
3733
|
+
*
|
|
3734
|
+
* Screens blockchain addresses against the Chainalysis sanctions oracle,
|
|
3735
|
+
* which tracks OFAC SDN addresses. Supports two modes:
|
|
3736
|
+
*
|
|
3737
|
+
* 1. **REST API mode** (default): Queries the Chainalysis screening API
|
|
3738
|
+
* 2. **On-chain mode**: Queries the on-chain oracle contract via eth_call
|
|
3739
|
+
* (requires an Ethereum RPC URL)
|
|
3740
|
+
*
|
|
3741
|
+
* - **Free tier** in Kontext (metered by events)
|
|
3742
|
+
* - **Requires API key** (REST mode) or **RPC URL** (on-chain mode)
|
|
3743
|
+
* - **NOT browser-compatible** — requires server-side calls
|
|
3744
|
+
*
|
|
3745
|
+
* @example
|
|
3746
|
+
* ```typescript
|
|
3747
|
+
* // REST API mode
|
|
3748
|
+
* const provider = new ChainalysisOracleProvider({
|
|
3749
|
+
* apiKey: process.env.CHAINALYSIS_API_KEY!,
|
|
3750
|
+
* });
|
|
3751
|
+
*
|
|
3752
|
+
* // On-chain mode
|
|
3753
|
+
* const provider = new ChainalysisOracleProvider({
|
|
3754
|
+
* rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY',
|
|
3755
|
+
* });
|
|
3756
|
+
* ```
|
|
3757
|
+
*/
|
|
3758
|
+
declare class ChainalysisOracleProvider implements ScreeningProvider {
|
|
3759
|
+
readonly id = "chainalysis-oracle";
|
|
3760
|
+
readonly name = "Chainalysis OFAC Oracle";
|
|
3761
|
+
readonly lists: readonly SanctionsList[];
|
|
3762
|
+
readonly requiresApiKey = true;
|
|
3763
|
+
readonly browserCompatible = false;
|
|
3764
|
+
readonly queryTypes: readonly QueryType[];
|
|
3765
|
+
private readonly apiKey;
|
|
3766
|
+
private readonly rpcUrl;
|
|
3767
|
+
private readonly apiBaseUrl;
|
|
3768
|
+
constructor(config: {
|
|
3769
|
+
apiKey?: string;
|
|
3770
|
+
rpcUrl?: string;
|
|
3771
|
+
apiBaseUrl?: string;
|
|
3772
|
+
});
|
|
3773
|
+
screen(query: string, _context?: ScreeningContext): Promise<ScreeningResult>;
|
|
3774
|
+
isAvailable(): boolean;
|
|
3775
|
+
private screenOnChain;
|
|
3776
|
+
private screenApi;
|
|
3777
|
+
private errorResult;
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
type ConsensusStrategy = 'ANY_MATCH' | 'ALL_MATCH' | 'MAJORITY';
|
|
3781
|
+
interface ScreeningAggregatorConfig {
|
|
3782
|
+
providers: ScreeningProvider[];
|
|
3783
|
+
consensus?: ConsensusStrategy;
|
|
3784
|
+
blocklist?: string[];
|
|
3785
|
+
allowlist?: string[];
|
|
3786
|
+
continueOnError?: boolean;
|
|
3787
|
+
providerTimeoutMs?: number;
|
|
3788
|
+
onEvent?: () => void;
|
|
3789
|
+
providerRateLimitPerSec?: number;
|
|
3790
|
+
}
|
|
3791
|
+
interface AggregatedScreeningResult {
|
|
3792
|
+
providerId: string;
|
|
3793
|
+
hit: boolean;
|
|
3794
|
+
matches: ScreeningMatch[];
|
|
3795
|
+
listsChecked: readonly SanctionsList[];
|
|
3796
|
+
entriesSearched: number;
|
|
3797
|
+
durationMs: number;
|
|
3798
|
+
queryType: QueryType;
|
|
3799
|
+
totalProviders: number;
|
|
3800
|
+
hitCount: number;
|
|
3801
|
+
consensus: ConsensusStrategy;
|
|
3802
|
+
blocklisted?: boolean;
|
|
3803
|
+
allowlisted?: boolean;
|
|
3804
|
+
errors: Array<{
|
|
3805
|
+
providerId: string;
|
|
3806
|
+
error: string;
|
|
3807
|
+
}>;
|
|
3808
|
+
uncoveredLists: SanctionsList[];
|
|
3809
|
+
providerResults: ScreeningResult[];
|
|
3810
|
+
}
|
|
3811
|
+
/**
|
|
3812
|
+
* Multi-provider screening orchestrator.
|
|
3813
|
+
*
|
|
3814
|
+
* Routes queries to compatible providers based on auto-detected query type,
|
|
3815
|
+
* applies consensus strategy, and tracks jurisdiction coverage.
|
|
3816
|
+
*
|
|
3817
|
+
* @example
|
|
3818
|
+
* ```typescript
|
|
3819
|
+
* const agg = new ScreeningAggregator({
|
|
3820
|
+
* providers: [new OFACAddressProvider(), new UKOFSIProvider()],
|
|
3821
|
+
* consensus: 'ANY_MATCH',
|
|
3822
|
+
* onEvent: () => planManager.recordEvent(),
|
|
3823
|
+
* });
|
|
3824
|
+
*
|
|
3825
|
+
* const result = await agg.screen('0x098B716B8Aaf21512996dC57EB0615e2383E2f96');
|
|
3826
|
+
* ```
|
|
3827
|
+
*/
|
|
3828
|
+
declare class ScreeningAggregator {
|
|
3829
|
+
private readonly providers;
|
|
3830
|
+
private readonly consensus;
|
|
3831
|
+
private readonly blocklistSet;
|
|
3832
|
+
private readonly allowlistSet;
|
|
3833
|
+
private readonly continueOnError;
|
|
3834
|
+
private readonly providerTimeoutMs;
|
|
3835
|
+
private readonly onEvent;
|
|
3836
|
+
constructor(config: ScreeningAggregatorConfig);
|
|
3837
|
+
/**
|
|
3838
|
+
* Screen a single query (address or entity name).
|
|
3839
|
+
*/
|
|
3840
|
+
screen(query: string, context?: ScreeningContext): Promise<AggregatedScreeningResult>;
|
|
3841
|
+
/**
|
|
3842
|
+
* Screen multiple queries in batch.
|
|
3843
|
+
*/
|
|
3844
|
+
screenBatch(queries: string[], context?: ScreeningContext): Promise<Map<string, AggregatedScreeningResult>>;
|
|
3845
|
+
/**
|
|
3846
|
+
* Get available providers, optionally filtered by query type.
|
|
3847
|
+
*/
|
|
3848
|
+
getAvailableProviders(queryType?: QueryType): ScreeningProvider[];
|
|
3849
|
+
/**
|
|
3850
|
+
* Get the union of all sanctions lists covered by available providers.
|
|
3851
|
+
*/
|
|
3852
|
+
getCoveredLists(): SanctionsList[];
|
|
3853
|
+
private runWithTimeout;
|
|
3854
|
+
private buildResult;
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3857
|
+
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, 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, 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, type WalletCluster, WalletClusterer, type WalletClusteringConfig, type WalletMapping, anchorDigest, encodeERC8021Suffix, exchangeAttestation, fetchAgentCard, fetchTransactionAttribution, getAnchor, getRequiredLists, isBlockchainAddress, isCryptoTransaction, isFeatureAvailable, parseERC8021Suffix, providerSupportsQuery, requirePlan, verifyAnchor, verifyExportedChain };
|