@obelyzk/sdk 1.1.0 → 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 +109 -428
- 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 +50 -4
- package/dist/index.d.ts +50 -4
- package/dist/index.js +235 -0
- package/dist/index.mjs +36 -1
- 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 +7 -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
|
+
});
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { W as WsConfig, a as WebSocketClient, b as WsEvent, P as PrivacyKeyPair, E as ECPoint, c as ElGamalCiphertext, A as AEHint, d as EncryptedBalance, S as SchnorrProof, T as TransferProof } from './tee-CiR0hpfm.mjs';
|
|
2
2
|
export { cv as AccountHints, cz as AuditReport, ag as BatchClient, aS as BatchJobResponse, aV as BatchOperation, aU as BatchOperationType, bZ as BatchStatus, aT as BatchStatusResponse, aX as BatchVerifyRequest, aY as BatchVerifyResponse, B as BitSageClient, bH as BurnEvent, au as CAPABILITY_FLAGS, c6 as ChallengeParams, c7 as ChallengeStatus, cL as CheckpointStatus, C as ClientConfig, c4 as CompressedProof, c3 as CompressionStats, cK as ComputeCheckpoint, I as ContractClient, _ as ContractConfig, aa as ContractRegistry, bN as CreateProposalParams, co as DAILY_CAPS, D as DEFAULT_CONFIG, K as DEFAULT_CONTRACT_CONFIG, cP as DEFAULT_DISCOUNT_TIERS, cQ as DEFAULT_FEE_DISTRIBUTION, y as DEFAULT_HTTP_CONFIG, z as DEFAULT_WS_CONFIG, bs as DKGShare, ch as DailyStats, ae as DashboardClient, bP as DelegationInfo, cD as DiscountTiers, b7 as DisputeRecord, cR as DisputeStatus, bI as EcosystemEmissionStatus, c5 as EnclaveInfo, cT as ExecutionMetrics, ab as ExternalTokens, v as FaucetClaimResponse, F as FaucetStatus, cE as FeeDistribution, az as GOVERNANCE_CONFIG, cp as GPU_MULTIPLIERS, aW as GasEstimate, ax as GovernanceClient, bx as GovernanceClientConfig, bB as GovernanceProposal, bC as GovernanceRights, bD as GovernanceStats, by as GovernanceTransactionResult, ce as GpuAttestation, aI as GpuMetrics, aJ as GpuMetricsResponse, bY as GpuTeeProofParams, G as GpuTier, cq as HALVENING_SCHEDULE, aL as HistoryPeriod, b2 as HolderTier, H as HttpClient, U as HttpConfig, aO as JobAnalytics, J as JobId, cH as JobPaymentRecord, t as JobResult, i as JobStatus, s as JobStatusResponse, h as JobType, V as JobUpdateEvent, a3 as LOCAL_CONTRACTS, bg as LeaderboardEntry, bf as LeaderboardMetric, L as ListJobsParams, u as ListJobsResponse, a2 as MAINNET_CONTRACTS, a7 as MAINNET_TOKENS, ai as MAX_BATCH_SIZE, an as MIN_STAKE, bK as MilestoneStatus, ac as MiningClient, aF as MiningClientConfig, ck as MiningConfig, cm as MiningGpuTier, cj as MiningPoolStatus, bq as MixingOutput, bp as MixingTransaction, cy as MultiAssetBalance, bu as MultiAssetBalances, N as Network, o as NetworkStats, Y as NetworkStatsEvent, aR as NetworkWorkersResponse, cF as OTCConfig, a9 as PRAGMA_ORACLE, cC as PaymentQuote, cG as PaymentStats, cI as PaymentStatus, cB as PaymentToken, aj as PaymentsClient, aZ as PaymentsClientConfig, bM as PendingTransfer, be as PerformanceData, bE as PoolBalances, bk as PrivacyAsset, av as PrivacyClient, bi as PrivacyClientConfig, cM as PrivacyCreditDeposit, cN as PrivacyCreditUsage, bj as PrivacyTransactionResult, bl as PrivateAccount, bv as PrivateSwapParams, bm as PrivateTransferParams, bn as PrivateTransferWithAuditParams, cA as PrivateWorkerPayment, n as ProofDetails, b_ as ProofJobSpec, bX as ProofMetadata, c0 as ProofPriority, bU as ProofSource, c1 as ProofSubmission, b$ as ProofType, k as ProofVerificationStatus, Z as ProofVerifiedEvent, bz as ProposalStatus, bA as ProposalType, c2 as ProverMetrics, br as RagequitProof, bL as RateLimitInfo, aP as RecentJob, bh as RegisterWorkerParams, aM as RewardHistoryEntry, aN as RewardHistoryResponse, cl as RewardResult, aK as RewardsInfo, cw as RingMember, cx as RingSignature, a1 as SEPOLIA_CONTRACTS, a6 as SEPOLIA_TOKENS, ao as SLASH_PERCENTAGES, cn as STAKE_TIER_THRESHOLDS, cu as SameEncryption3Proof, e as SdkError, bG as SecurityBudget, b3 as SlashReason, b6 as SlashRecord, p as StakeInfo, cg as StakeTier, al as StakingClient, a_ as StakingClientConfig, b5 as StakingConfig, a$ as StakingTransactionResult, bw as StealthAddress, bo as SteganographicTransaction, aA as StwoClient, bR as StwoClientConfig, bV as StwoTeeType, bS as StwoTransactionResult, q as SubmitJobRequest, r as SubmitJobResponse, bW as TeeAttestation, cc as TeeChallengeParams, cd as TeeChallengeStatus, aD as TeeClient, c8 as TeeClientConfig, cb as TeeJobResult, cS as TeeQuote, ca as TeeResultParams, c9 as TeeTransactionResult, b0 as TeeType, bt as ThresholdDecryptionRequest, bJ as TokenFlowSummary, $ as TransactionReceipt, cO as TransactionResult, a0 as TxStatus, ap as UNSTAKE_LOCKUP_SECS, b9 as UnstakeRequest, aC as VERIFICATION_CONFIG, aG as ValidatorStatus, aH as ValidatorStatusResponse, cJ as VerificationSource, bT as VerificationStatus, bF as VestingStatus, bO as VoteDirection, bQ as VoterInfo, f as WalletConfig, l as WorkerCapabilities, bc as WorkerCapabilitiesExtended, g as WorkerId, m as WorkerInfo, ci as WorkerMiningStats, bd as WorkerProfile, b4 as WorkerStake, j as WorkerStatus, aQ as WorkerSummary, cf as WorkerTeeStatus, b1 as WorkerTier, b8 as WorkerTierBenefits, X as WorkerUpdateEvent, as as WorkersClient, ba as WorkersClientConfig, bb as WorkersTransactionResult, ah as createBatchClient, af as createDashboardClient, ay as createGovernanceClient, ad as createMiningClient, ak as createPaymentsClient, aw as createPrivacyClient, am as createStakingClient, aB as createStwoClient, aE as createTeeClient, at as createWorkersClient, O as fromFelt, a4 as getContractsForNetwork, cs as getDailyCapForTier, ct as getGpuMultiplier, x as getGpuTier, w as getMinStake, ar as getMinStakeForTier, cr as getStakeTierFromAmount, a8 as getTokensForNetwork, a5 as isContractConfigured, aq as isWorkerEligible, R as joinU256, Q as splitU256, M as toFelt } from './tee-CiR0hpfm.mjs';
|
|
3
|
+
export { AgentFirewallSDK, AgentStatus, ClassifyResult, Decision, FirewallConfig, TransactionFeatures } from './firewall/index.mjs';
|
|
3
4
|
export { AssetId, BalanceProof, CURVE_ORDER, ConfidentialOrder, ConfidentialSwapClient, ConfidentialSwapConfig, CreateOrderRequest, CreateOrderResponse, ElGamalKeyPair, FIELD_PRIME, GENERATOR_G, GENERATOR_H, ElGamalCiphertext as ObelyskCiphertext, EncryptionProof as ObelyskEncryptionProof, default as ObelyskPrivacy, RangeProof, RateProof, SwapHistoryEntry, SwapProofBundle, TakeOrderResponse, addMod, ecAdd, ecDouble, ecMul, invMod, isIdentity, mulMod, poseidonHash, powMod, randomScalar, subMod } from './privacy/index.mjs';
|
|
5
|
+
import 'starknet';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* WebSocket Module
|
|
@@ -400,7 +402,7 @@ declare function verifyTransferProof(proof: TransferProof, senderPublicKey: ECPo
|
|
|
400
402
|
*
|
|
401
403
|
* @example
|
|
402
404
|
* ```typescript
|
|
403
|
-
* import { createStwoProverClient } from '@
|
|
405
|
+
* import { createStwoProverClient } from '@obelyzk/sdk';
|
|
404
406
|
*
|
|
405
407
|
* const prover = createStwoProverClient({
|
|
406
408
|
* baseUrl: 'https://prover.bitsage.network',
|
|
@@ -724,13 +726,17 @@ declare class StwoProverClient {
|
|
|
724
726
|
declare function createStwoProverClient(config?: Partial<StwoProverConfig>): StwoProverClient;
|
|
725
727
|
interface ZkmlLoadModelRequest {
|
|
726
728
|
/** Path to ONNX model on the prover server filesystem */
|
|
727
|
-
modelPath
|
|
729
|
+
modelPath?: string;
|
|
730
|
+
/** Path to HuggingFace model directory on the prover */
|
|
731
|
+
model_dir?: string;
|
|
728
732
|
/** Optional description for on-chain registration */
|
|
729
733
|
description?: string;
|
|
730
734
|
}
|
|
731
735
|
interface ZkmlModelInfo {
|
|
732
736
|
/** Model identifier (hex) */
|
|
733
737
|
modelId: string;
|
|
738
|
+
/** Human-readable model name (e.g., "smollm2-135m") */
|
|
739
|
+
name: string;
|
|
734
740
|
/** Poseidon hash of weight matrices (hex) */
|
|
735
741
|
weightCommitment: string;
|
|
736
742
|
/** Number of model layers */
|
|
@@ -739,7 +745,7 @@ interface ZkmlModelInfo {
|
|
|
739
745
|
inputShape: [number, number];
|
|
740
746
|
}
|
|
741
747
|
interface ZkmlProveRequest {
|
|
742
|
-
/** Model ID (
|
|
748
|
+
/** Model ID or name (e.g., "smollm2-135m" or "0x1cb4f9...") */
|
|
743
749
|
modelId: string;
|
|
744
750
|
/** Flat array of f32 input values (optional — random if omitted) */
|
|
745
751
|
input?: number[];
|
|
@@ -781,7 +787,9 @@ interface ZkmlProveResult {
|
|
|
781
787
|
}
|
|
782
788
|
declare module './stwo-prover' {
|
|
783
789
|
interface StwoProverClient {
|
|
784
|
-
/**
|
|
790
|
+
/** List all loaded models on the prover */
|
|
791
|
+
listZkmlModels(): Promise<ZkmlModelInfo[]>;
|
|
792
|
+
/** Load a model on the prover server (ONNX or HuggingFace) */
|
|
785
793
|
loadZkmlModel(req: ZkmlLoadModelRequest): Promise<ZkmlModelInfo>;
|
|
786
794
|
/** Submit a ZKML proving job (returns immediately with job_id) */
|
|
787
795
|
submitZkmlProve(req: ZkmlProveRequest): Promise<{
|
|
@@ -798,8 +806,46 @@ declare module './stwo-prover' {
|
|
|
798
806
|
timeoutMs?: number;
|
|
799
807
|
onProgress?: (status: ZkmlProveStatus) => void;
|
|
800
808
|
}): Promise<ZkmlProveResult>;
|
|
809
|
+
/** Full attestation: prove + on-chain verification in one call */
|
|
810
|
+
attest(req: ZkmlAttestRequest): Promise<ZkmlAttestResult>;
|
|
801
811
|
}
|
|
802
812
|
}
|
|
813
|
+
interface ZkmlAttestRequest {
|
|
814
|
+
/** Model name or hex ID */
|
|
815
|
+
modelId: string;
|
|
816
|
+
/** Flat input array */
|
|
817
|
+
input: number[];
|
|
818
|
+
/** GPU acceleration (default: true) */
|
|
819
|
+
gpu?: boolean;
|
|
820
|
+
/** Submit on-chain (default: true) */
|
|
821
|
+
submitOnchain?: boolean;
|
|
822
|
+
}
|
|
823
|
+
interface ZkmlAttestResult {
|
|
824
|
+
/** Proof identifier */
|
|
825
|
+
proofId: string;
|
|
826
|
+
/** IO commitment (Poseidon hash of inputs + outputs) */
|
|
827
|
+
ioCommitment: string;
|
|
828
|
+
/** Weight commitment (Poseidon Merkle root of all weights) */
|
|
829
|
+
weightCommitment: string;
|
|
830
|
+
/** Number of computation nodes proven */
|
|
831
|
+
numProvenLayers: number;
|
|
832
|
+
/** Proof generation time in ms */
|
|
833
|
+
proveTimeMs: number;
|
|
834
|
+
/** Number of calldata felts */
|
|
835
|
+
calldataFelts: number;
|
|
836
|
+
/** Estimated gas for on-chain verification */
|
|
837
|
+
estimatedGas: number;
|
|
838
|
+
/** On-chain verification status */
|
|
839
|
+
onchain: {
|
|
840
|
+
submitted: boolean;
|
|
841
|
+
txHashes: string[];
|
|
842
|
+
network: string;
|
|
843
|
+
contract: string;
|
|
844
|
+
verified: boolean;
|
|
845
|
+
explorerUrl: string | null;
|
|
846
|
+
error: string | null;
|
|
847
|
+
};
|
|
848
|
+
}
|
|
803
849
|
declare const PROOF_TYPES: {
|
|
804
850
|
BATCH_PAYMENTS: ProofType;
|
|
805
851
|
AI_INFERENCE: ProofType;
|