@obelyzk/sdk 1.0.1 → 1.2.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 +110 -405
- package/bin/bitsage-demo.ts +0 -0
- package/dist/chunk-BHUXKNDT.mjs +206 -0
- package/dist/chunk-MDF4P52S.mjs +697 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/firewall/index.d.mts +166 -0
- package/dist/firewall/index.d.ts +166 -0
- package/dist/firewall/index.js +232 -0
- package/dist/firewall/index.mjs +7 -0
- package/dist/index.d.mts +54 -8
- package/dist/index.d.ts +54 -8
- package/dist/index.js +251 -6
- package/dist/index.mjs +52 -7
- package/dist/obelysk/index.mjs +4 -2
- package/dist/privacy/index.d.mts +1 -1
- package/dist/privacy/index.d.ts +1 -1
- package/dist/privacy/index.mjs +2 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.mjs +2 -1
- package/package.json +11 -2
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import * as starknet from 'starknet';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Types for the ZKML Agent Firewall SDK.
|
|
5
|
+
*
|
|
6
|
+
* These types map 1:1 to the Rust classifier and Cairo AgentFirewallZK contract.
|
|
7
|
+
*/
|
|
8
|
+
/** Transaction features sent to the classifier. */
|
|
9
|
+
interface TransactionFeatures {
|
|
10
|
+
/** Target contract address (hex, 0x-prefixed). */
|
|
11
|
+
target: string;
|
|
12
|
+
/** Transaction value (decimal string, u256). */
|
|
13
|
+
value?: string;
|
|
14
|
+
/** Function selector (hex, 4 bytes, 0x-prefixed). */
|
|
15
|
+
selector?: string;
|
|
16
|
+
/** Calldata (hex, after selector, 0x-prefixed). */
|
|
17
|
+
calldata?: string;
|
|
18
|
+
/** Agent's current trust score (0-100000). */
|
|
19
|
+
agentTrustScore?: number;
|
|
20
|
+
/** Agent's current strike count. */
|
|
21
|
+
agentStrikes?: number;
|
|
22
|
+
/** Agent age in blocks since registration. */
|
|
23
|
+
agentAgeBlocks?: number;
|
|
24
|
+
/** Target contract metadata. */
|
|
25
|
+
targetVerified?: boolean;
|
|
26
|
+
targetIsProxy?: boolean;
|
|
27
|
+
targetHasSource?: boolean;
|
|
28
|
+
targetInteractionCount?: number;
|
|
29
|
+
/** Behavioral features. */
|
|
30
|
+
txFrequency?: number;
|
|
31
|
+
uniqueTargets24h?: number;
|
|
32
|
+
avgValue24h?: number;
|
|
33
|
+
maxValue24h?: number;
|
|
34
|
+
}
|
|
35
|
+
/** Classifier decision. */
|
|
36
|
+
type Decision = "approve" | "escalate" | "block";
|
|
37
|
+
/** Result from evaluating a transaction through the ZKML classifier. */
|
|
38
|
+
interface ClassifyResult {
|
|
39
|
+
/** Unique request ID. */
|
|
40
|
+
requestId: string;
|
|
41
|
+
/** Classifier decision. */
|
|
42
|
+
decision: Decision;
|
|
43
|
+
/** Threat score (0-100000). */
|
|
44
|
+
threatScore: number;
|
|
45
|
+
/** Raw output scores: [safe, suspicious, malicious]. */
|
|
46
|
+
scores: [number, number, number];
|
|
47
|
+
/** IO commitment (Poseidon hash of classifier input + output). */
|
|
48
|
+
ioCommitment: string;
|
|
49
|
+
/** Policy commitment (strict policy hash). */
|
|
50
|
+
policyCommitment: string;
|
|
51
|
+
/** Proving time in milliseconds. */
|
|
52
|
+
proveTimeMs: number;
|
|
53
|
+
}
|
|
54
|
+
/** Result from submitting an action to the firewall contract. */
|
|
55
|
+
interface SubmitActionResult {
|
|
56
|
+
/** Action ID assigned by the contract. */
|
|
57
|
+
actionId: number;
|
|
58
|
+
/** Transaction hash. */
|
|
59
|
+
txHash: string;
|
|
60
|
+
}
|
|
61
|
+
/** Result from resolving an action with a verified proof. */
|
|
62
|
+
interface ResolveResult {
|
|
63
|
+
/** Final decision after proof verification. */
|
|
64
|
+
decision: Decision;
|
|
65
|
+
/** Threat score applied to the agent. */
|
|
66
|
+
threatScore: number;
|
|
67
|
+
/** Transaction hash. */
|
|
68
|
+
txHash: string;
|
|
69
|
+
}
|
|
70
|
+
/** Agent trust status. */
|
|
71
|
+
interface AgentStatus {
|
|
72
|
+
/** Whether the agent is registered. */
|
|
73
|
+
registered: boolean;
|
|
74
|
+
/** Whether the agent is active (not frozen). */
|
|
75
|
+
active: boolean;
|
|
76
|
+
/** Current trust score (0-100000, EMA smoothed). */
|
|
77
|
+
trustScore: number;
|
|
78
|
+
/** Current strike count. */
|
|
79
|
+
strikes: number;
|
|
80
|
+
/** Whether the agent is trusted (active + score < threshold + strikes < max). */
|
|
81
|
+
trusted: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** Firewall SDK configuration. */
|
|
84
|
+
interface FirewallConfig {
|
|
85
|
+
/** Prover server URL (for /api/v1/classify). */
|
|
86
|
+
proverUrl: string;
|
|
87
|
+
/** AgentFirewallZK contract address on Starknet. */
|
|
88
|
+
firewallContract: string;
|
|
89
|
+
/** ObelyskVerifier contract address on Starknet. */
|
|
90
|
+
verifierContract: string;
|
|
91
|
+
/** Starknet RPC URL. */
|
|
92
|
+
rpcUrl: string;
|
|
93
|
+
/** Starknet account for signing transactions. */
|
|
94
|
+
account?: starknet.Account;
|
|
95
|
+
/** API key for the prover server (optional). */
|
|
96
|
+
apiKey?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* AgentFirewallSDK — ZKML-powered transaction guardrails for AI agents.
|
|
101
|
+
*
|
|
102
|
+
* Wraps the full flow:
|
|
103
|
+
* 1. Classify transaction via prove-server (/api/v1/classify)
|
|
104
|
+
* 2. Submit action to AgentFirewallZK contract
|
|
105
|
+
* 3. Submit ZKML proof to ObelyskVerifier (streaming or recursive)
|
|
106
|
+
* 4. Resolve action with proven threat score
|
|
107
|
+
* 5. Query approval status
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import { AgentFirewallSDK } from '@obelyzk/sdk/firewall';
|
|
112
|
+
*
|
|
113
|
+
* const firewall = new AgentFirewallSDK({
|
|
114
|
+
* proverUrl: 'https://prover.bitsage.network',
|
|
115
|
+
* firewallContract: '0x...',
|
|
116
|
+
* verifierContract: '0x...',
|
|
117
|
+
* rpcUrl: process.env.STARKNET_RPC!,
|
|
118
|
+
* account: myAccount,
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* const result = await firewall.evaluateAction({
|
|
122
|
+
* target: '0x1234...',
|
|
123
|
+
* value: '1000000000',
|
|
124
|
+
* selector: '0xa9059cbb',
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* if (result.decision === 'approve') {
|
|
128
|
+
* // safe to execute
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
declare class AgentFirewallSDK {
|
|
134
|
+
private config;
|
|
135
|
+
private provider;
|
|
136
|
+
constructor(config: FirewallConfig);
|
|
137
|
+
/**
|
|
138
|
+
* Classify a transaction through the ZKML classifier.
|
|
139
|
+
*
|
|
140
|
+
* Sends the transaction features to the prove-server, which runs
|
|
141
|
+
* the MLP classifier and generates a GKR+STARK proof. Returns the
|
|
142
|
+
* proven threat score and decision.
|
|
143
|
+
*
|
|
144
|
+
* Does NOT submit anything on-chain — use `evaluateAction()` for
|
|
145
|
+
* the full flow including on-chain submission.
|
|
146
|
+
*/
|
|
147
|
+
classify(tx: TransactionFeatures): Promise<ClassifyResult>;
|
|
148
|
+
/**
|
|
149
|
+
* Register a new agent on the firewall contract.
|
|
150
|
+
* The calling account becomes the agent owner.
|
|
151
|
+
*/
|
|
152
|
+
registerAgent(agentId: string): Promise<string>;
|
|
153
|
+
/** Deactivate an agent (owner or contract admin). */
|
|
154
|
+
deactivateAgent(agentId: string): Promise<string>;
|
|
155
|
+
/** Reactivate an agent and reset strikes (agent owner only). */
|
|
156
|
+
reactivateAgent(agentId: string): Promise<string>;
|
|
157
|
+
/** Get the full status of an agent. */
|
|
158
|
+
getAgentStatus(agentId: string): Promise<AgentStatus>;
|
|
159
|
+
/** Check if a specific action has been approved. */
|
|
160
|
+
isActionApproved(actionId: number): Promise<boolean>;
|
|
161
|
+
/** Check if an agent is trusted. */
|
|
162
|
+
isAgentTrusted(agentId: string): Promise<boolean>;
|
|
163
|
+
private requireAccount;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { AgentFirewallSDK, type AgentStatus, type ClassifyResult, type Decision, type FirewallConfig, type ResolveResult, type SubmitActionResult, type TransactionFeatures };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import * as starknet from 'starknet';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Types for the ZKML Agent Firewall SDK.
|
|
5
|
+
*
|
|
6
|
+
* These types map 1:1 to the Rust classifier and Cairo AgentFirewallZK contract.
|
|
7
|
+
*/
|
|
8
|
+
/** Transaction features sent to the classifier. */
|
|
9
|
+
interface TransactionFeatures {
|
|
10
|
+
/** Target contract address (hex, 0x-prefixed). */
|
|
11
|
+
target: string;
|
|
12
|
+
/** Transaction value (decimal string, u256). */
|
|
13
|
+
value?: string;
|
|
14
|
+
/** Function selector (hex, 4 bytes, 0x-prefixed). */
|
|
15
|
+
selector?: string;
|
|
16
|
+
/** Calldata (hex, after selector, 0x-prefixed). */
|
|
17
|
+
calldata?: string;
|
|
18
|
+
/** Agent's current trust score (0-100000). */
|
|
19
|
+
agentTrustScore?: number;
|
|
20
|
+
/** Agent's current strike count. */
|
|
21
|
+
agentStrikes?: number;
|
|
22
|
+
/** Agent age in blocks since registration. */
|
|
23
|
+
agentAgeBlocks?: number;
|
|
24
|
+
/** Target contract metadata. */
|
|
25
|
+
targetVerified?: boolean;
|
|
26
|
+
targetIsProxy?: boolean;
|
|
27
|
+
targetHasSource?: boolean;
|
|
28
|
+
targetInteractionCount?: number;
|
|
29
|
+
/** Behavioral features. */
|
|
30
|
+
txFrequency?: number;
|
|
31
|
+
uniqueTargets24h?: number;
|
|
32
|
+
avgValue24h?: number;
|
|
33
|
+
maxValue24h?: number;
|
|
34
|
+
}
|
|
35
|
+
/** Classifier decision. */
|
|
36
|
+
type Decision = "approve" | "escalate" | "block";
|
|
37
|
+
/** Result from evaluating a transaction through the ZKML classifier. */
|
|
38
|
+
interface ClassifyResult {
|
|
39
|
+
/** Unique request ID. */
|
|
40
|
+
requestId: string;
|
|
41
|
+
/** Classifier decision. */
|
|
42
|
+
decision: Decision;
|
|
43
|
+
/** Threat score (0-100000). */
|
|
44
|
+
threatScore: number;
|
|
45
|
+
/** Raw output scores: [safe, suspicious, malicious]. */
|
|
46
|
+
scores: [number, number, number];
|
|
47
|
+
/** IO commitment (Poseidon hash of classifier input + output). */
|
|
48
|
+
ioCommitment: string;
|
|
49
|
+
/** Policy commitment (strict policy hash). */
|
|
50
|
+
policyCommitment: string;
|
|
51
|
+
/** Proving time in milliseconds. */
|
|
52
|
+
proveTimeMs: number;
|
|
53
|
+
}
|
|
54
|
+
/** Result from submitting an action to the firewall contract. */
|
|
55
|
+
interface SubmitActionResult {
|
|
56
|
+
/** Action ID assigned by the contract. */
|
|
57
|
+
actionId: number;
|
|
58
|
+
/** Transaction hash. */
|
|
59
|
+
txHash: string;
|
|
60
|
+
}
|
|
61
|
+
/** Result from resolving an action with a verified proof. */
|
|
62
|
+
interface ResolveResult {
|
|
63
|
+
/** Final decision after proof verification. */
|
|
64
|
+
decision: Decision;
|
|
65
|
+
/** Threat score applied to the agent. */
|
|
66
|
+
threatScore: number;
|
|
67
|
+
/** Transaction hash. */
|
|
68
|
+
txHash: string;
|
|
69
|
+
}
|
|
70
|
+
/** Agent trust status. */
|
|
71
|
+
interface AgentStatus {
|
|
72
|
+
/** Whether the agent is registered. */
|
|
73
|
+
registered: boolean;
|
|
74
|
+
/** Whether the agent is active (not frozen). */
|
|
75
|
+
active: boolean;
|
|
76
|
+
/** Current trust score (0-100000, EMA smoothed). */
|
|
77
|
+
trustScore: number;
|
|
78
|
+
/** Current strike count. */
|
|
79
|
+
strikes: number;
|
|
80
|
+
/** Whether the agent is trusted (active + score < threshold + strikes < max). */
|
|
81
|
+
trusted: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** Firewall SDK configuration. */
|
|
84
|
+
interface FirewallConfig {
|
|
85
|
+
/** Prover server URL (for /api/v1/classify). */
|
|
86
|
+
proverUrl: string;
|
|
87
|
+
/** AgentFirewallZK contract address on Starknet. */
|
|
88
|
+
firewallContract: string;
|
|
89
|
+
/** ObelyskVerifier contract address on Starknet. */
|
|
90
|
+
verifierContract: string;
|
|
91
|
+
/** Starknet RPC URL. */
|
|
92
|
+
rpcUrl: string;
|
|
93
|
+
/** Starknet account for signing transactions. */
|
|
94
|
+
account?: starknet.Account;
|
|
95
|
+
/** API key for the prover server (optional). */
|
|
96
|
+
apiKey?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* AgentFirewallSDK — ZKML-powered transaction guardrails for AI agents.
|
|
101
|
+
*
|
|
102
|
+
* Wraps the full flow:
|
|
103
|
+
* 1. Classify transaction via prove-server (/api/v1/classify)
|
|
104
|
+
* 2. Submit action to AgentFirewallZK contract
|
|
105
|
+
* 3. Submit ZKML proof to ObelyskVerifier (streaming or recursive)
|
|
106
|
+
* 4. Resolve action with proven threat score
|
|
107
|
+
* 5. Query approval status
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import { AgentFirewallSDK } from '@obelyzk/sdk/firewall';
|
|
112
|
+
*
|
|
113
|
+
* const firewall = new AgentFirewallSDK({
|
|
114
|
+
* proverUrl: 'https://prover.bitsage.network',
|
|
115
|
+
* firewallContract: '0x...',
|
|
116
|
+
* verifierContract: '0x...',
|
|
117
|
+
* rpcUrl: process.env.STARKNET_RPC!,
|
|
118
|
+
* account: myAccount,
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* const result = await firewall.evaluateAction({
|
|
122
|
+
* target: '0x1234...',
|
|
123
|
+
* value: '1000000000',
|
|
124
|
+
* selector: '0xa9059cbb',
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* if (result.decision === 'approve') {
|
|
128
|
+
* // safe to execute
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
declare class AgentFirewallSDK {
|
|
134
|
+
private config;
|
|
135
|
+
private provider;
|
|
136
|
+
constructor(config: FirewallConfig);
|
|
137
|
+
/**
|
|
138
|
+
* Classify a transaction through the ZKML classifier.
|
|
139
|
+
*
|
|
140
|
+
* Sends the transaction features to the prove-server, which runs
|
|
141
|
+
* the MLP classifier and generates a GKR+STARK proof. Returns the
|
|
142
|
+
* proven threat score and decision.
|
|
143
|
+
*
|
|
144
|
+
* Does NOT submit anything on-chain — use `evaluateAction()` for
|
|
145
|
+
* the full flow including on-chain submission.
|
|
146
|
+
*/
|
|
147
|
+
classify(tx: TransactionFeatures): Promise<ClassifyResult>;
|
|
148
|
+
/**
|
|
149
|
+
* Register a new agent on the firewall contract.
|
|
150
|
+
* The calling account becomes the agent owner.
|
|
151
|
+
*/
|
|
152
|
+
registerAgent(agentId: string): Promise<string>;
|
|
153
|
+
/** Deactivate an agent (owner or contract admin). */
|
|
154
|
+
deactivateAgent(agentId: string): Promise<string>;
|
|
155
|
+
/** Reactivate an agent and reset strikes (agent owner only). */
|
|
156
|
+
reactivateAgent(agentId: string): Promise<string>;
|
|
157
|
+
/** Get the full status of an agent. */
|
|
158
|
+
getAgentStatus(agentId: string): Promise<AgentStatus>;
|
|
159
|
+
/** Check if a specific action has been approved. */
|
|
160
|
+
isActionApproved(actionId: number): Promise<boolean>;
|
|
161
|
+
/** Check if an agent is trusted. */
|
|
162
|
+
isAgentTrusted(agentId: string): Promise<boolean>;
|
|
163
|
+
private requireAccount;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { AgentFirewallSDK, type AgentStatus, type ClassifyResult, type Decision, type FirewallConfig, type ResolveResult, type SubmitActionResult, type TransactionFeatures };
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/firewall/index.ts
|
|
21
|
+
var firewall_exports = {};
|
|
22
|
+
__export(firewall_exports, {
|
|
23
|
+
AgentFirewallSDK: () => AgentFirewallSDK
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(firewall_exports);
|
|
26
|
+
|
|
27
|
+
// src/firewall/client.ts
|
|
28
|
+
var import_starknet = require("starknet");
|
|
29
|
+
var AgentFirewallSDK = class {
|
|
30
|
+
config;
|
|
31
|
+
provider;
|
|
32
|
+
constructor(config) {
|
|
33
|
+
this.config = config;
|
|
34
|
+
this.provider = new import_starknet.RpcProvider({ nodeUrl: config.rpcUrl });
|
|
35
|
+
}
|
|
36
|
+
// ── Classification ─────────────────────────────────────────────────
|
|
37
|
+
/**
|
|
38
|
+
* Classify a transaction through the ZKML classifier.
|
|
39
|
+
*
|
|
40
|
+
* Sends the transaction features to the prove-server, which runs
|
|
41
|
+
* the MLP classifier and generates a GKR+STARK proof. Returns the
|
|
42
|
+
* proven threat score and decision.
|
|
43
|
+
*
|
|
44
|
+
* Does NOT submit anything on-chain — use `evaluateAction()` for
|
|
45
|
+
* the full flow including on-chain submission.
|
|
46
|
+
*/
|
|
47
|
+
async classify(tx) {
|
|
48
|
+
const headers = {
|
|
49
|
+
"Content-Type": "application/json"
|
|
50
|
+
};
|
|
51
|
+
if (this.config.apiKey) {
|
|
52
|
+
headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
53
|
+
}
|
|
54
|
+
const body = {
|
|
55
|
+
target: tx.target,
|
|
56
|
+
value: tx.value || "0",
|
|
57
|
+
selector: tx.selector || "0x0",
|
|
58
|
+
calldata: tx.calldata || "0x",
|
|
59
|
+
agent_trust_score: tx.agentTrustScore || 0,
|
|
60
|
+
agent_strikes: tx.agentStrikes || 0,
|
|
61
|
+
agent_age_blocks: tx.agentAgeBlocks || 0,
|
|
62
|
+
target_verified: tx.targetVerified || false,
|
|
63
|
+
target_is_proxy: tx.targetIsProxy || false,
|
|
64
|
+
target_has_source: tx.targetHasSource || false,
|
|
65
|
+
target_interaction_count: tx.targetInteractionCount || 0,
|
|
66
|
+
tx_frequency: tx.txFrequency || 0,
|
|
67
|
+
unique_targets_24h: tx.uniqueTargets24h || 0,
|
|
68
|
+
avg_value_24h: tx.avgValue24h || 0,
|
|
69
|
+
max_value_24h: tx.maxValue24h || 0
|
|
70
|
+
};
|
|
71
|
+
const response = await fetch(`${this.config.proverUrl}/api/v1/classify`, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers,
|
|
74
|
+
body: JSON.stringify(body)
|
|
75
|
+
});
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
78
|
+
throw new Error(`Classification failed (${response.status}): ${error.error || response.statusText}`);
|
|
79
|
+
}
|
|
80
|
+
const data = await response.json();
|
|
81
|
+
return {
|
|
82
|
+
requestId: data.request_id,
|
|
83
|
+
decision: data.decision,
|
|
84
|
+
threatScore: data.threat_score,
|
|
85
|
+
scores: data.scores,
|
|
86
|
+
ioCommitment: data.io_commitment,
|
|
87
|
+
policyCommitment: data.policy_commitment,
|
|
88
|
+
proveTimeMs: data.prove_time_ms
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// ── Agent Management ───────────────────────────────────────────────
|
|
92
|
+
/**
|
|
93
|
+
* Register a new agent on the firewall contract.
|
|
94
|
+
* The calling account becomes the agent owner.
|
|
95
|
+
*/
|
|
96
|
+
async registerAgent(agentId) {
|
|
97
|
+
this.requireAccount();
|
|
98
|
+
const tx = await this.config.account.execute({
|
|
99
|
+
contractAddress: this.config.firewallContract,
|
|
100
|
+
entrypoint: "register_agent",
|
|
101
|
+
calldata: import_starknet.CallData.compile({ agent_id: agentId })
|
|
102
|
+
});
|
|
103
|
+
await this.provider.waitForTransaction(tx.transaction_hash);
|
|
104
|
+
return tx.transaction_hash;
|
|
105
|
+
}
|
|
106
|
+
/** Deactivate an agent (owner or contract admin). */
|
|
107
|
+
async deactivateAgent(agentId) {
|
|
108
|
+
this.requireAccount();
|
|
109
|
+
const tx = await this.config.account.execute({
|
|
110
|
+
contractAddress: this.config.firewallContract,
|
|
111
|
+
entrypoint: "deactivate_agent",
|
|
112
|
+
calldata: import_starknet.CallData.compile({ agent_id: agentId })
|
|
113
|
+
});
|
|
114
|
+
await this.provider.waitForTransaction(tx.transaction_hash);
|
|
115
|
+
return tx.transaction_hash;
|
|
116
|
+
}
|
|
117
|
+
/** Reactivate an agent and reset strikes (agent owner only). */
|
|
118
|
+
async reactivateAgent(agentId) {
|
|
119
|
+
this.requireAccount();
|
|
120
|
+
const tx = await this.config.account.execute({
|
|
121
|
+
contractAddress: this.config.firewallContract,
|
|
122
|
+
entrypoint: "reactivate_agent",
|
|
123
|
+
calldata: import_starknet.CallData.compile({ agent_id: agentId })
|
|
124
|
+
});
|
|
125
|
+
await this.provider.waitForTransaction(tx.transaction_hash);
|
|
126
|
+
return tx.transaction_hash;
|
|
127
|
+
}
|
|
128
|
+
// ── Queries ────────────────────────────────────────────────────────
|
|
129
|
+
/** Get the full status of an agent. */
|
|
130
|
+
async getAgentStatus(agentId) {
|
|
131
|
+
const contract = new import_starknet.Contract(
|
|
132
|
+
FIREWALL_ABI,
|
|
133
|
+
this.config.firewallContract,
|
|
134
|
+
this.provider
|
|
135
|
+
);
|
|
136
|
+
const [registered, active, trustScore, strikes, trusted] = await Promise.all([
|
|
137
|
+
contract.is_agent_registered(agentId),
|
|
138
|
+
contract.is_agent_active(agentId),
|
|
139
|
+
contract.get_trust_score(agentId),
|
|
140
|
+
contract.get_strikes(agentId),
|
|
141
|
+
contract.is_trusted(agentId)
|
|
142
|
+
]);
|
|
143
|
+
return {
|
|
144
|
+
registered,
|
|
145
|
+
active,
|
|
146
|
+
trustScore: Number(trustScore),
|
|
147
|
+
strikes: Number(strikes),
|
|
148
|
+
trusted
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/** Check if a specific action has been approved. */
|
|
152
|
+
async isActionApproved(actionId) {
|
|
153
|
+
const contract = new import_starknet.Contract(
|
|
154
|
+
FIREWALL_ABI,
|
|
155
|
+
this.config.firewallContract,
|
|
156
|
+
this.provider
|
|
157
|
+
);
|
|
158
|
+
return contract.is_action_approved(actionId);
|
|
159
|
+
}
|
|
160
|
+
/** Check if an agent is trusted. */
|
|
161
|
+
async isAgentTrusted(agentId) {
|
|
162
|
+
const contract = new import_starknet.Contract(
|
|
163
|
+
FIREWALL_ABI,
|
|
164
|
+
this.config.firewallContract,
|
|
165
|
+
this.provider
|
|
166
|
+
);
|
|
167
|
+
return contract.is_trusted(agentId);
|
|
168
|
+
}
|
|
169
|
+
// ── Helpers ────────────────────────────────────────────────────────
|
|
170
|
+
requireAccount() {
|
|
171
|
+
if (!this.config.account) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
"Account required for write operations. Pass `account` in FirewallConfig."
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var FIREWALL_ABI = [
|
|
179
|
+
{
|
|
180
|
+
name: "is_agent_registered",
|
|
181
|
+
type: "function",
|
|
182
|
+
inputs: [{ name: "agent_id", type: "felt" }],
|
|
183
|
+
outputs: [{ type: "felt" }],
|
|
184
|
+
state_mutability: "view"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: "is_agent_active",
|
|
188
|
+
type: "function",
|
|
189
|
+
inputs: [{ name: "agent_id", type: "felt" }],
|
|
190
|
+
outputs: [{ type: "felt" }],
|
|
191
|
+
state_mutability: "view"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "get_trust_score",
|
|
195
|
+
type: "function",
|
|
196
|
+
inputs: [{ name: "agent_id", type: "felt" }],
|
|
197
|
+
outputs: [{ type: "felt" }],
|
|
198
|
+
state_mutability: "view"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: "get_strikes",
|
|
202
|
+
type: "function",
|
|
203
|
+
inputs: [{ name: "agent_id", type: "felt" }],
|
|
204
|
+
outputs: [{ type: "felt" }],
|
|
205
|
+
state_mutability: "view"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "is_trusted",
|
|
209
|
+
type: "function",
|
|
210
|
+
inputs: [{ name: "agent_id", type: "felt" }],
|
|
211
|
+
outputs: [{ type: "felt" }],
|
|
212
|
+
state_mutability: "view"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "is_action_approved",
|
|
216
|
+
type: "function",
|
|
217
|
+
inputs: [{ name: "action_id", type: "felt" }],
|
|
218
|
+
outputs: [{ type: "felt" }],
|
|
219
|
+
state_mutability: "view"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
name: "get_action_decision",
|
|
223
|
+
type: "function",
|
|
224
|
+
inputs: [{ name: "action_id", type: "felt" }],
|
|
225
|
+
outputs: [{ type: "felt" }],
|
|
226
|
+
state_mutability: "view"
|
|
227
|
+
}
|
|
228
|
+
];
|
|
229
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
230
|
+
0 && (module.exports = {
|
|
231
|
+
AgentFirewallSDK
|
|
232
|
+
});
|