@obelyzk/sdk 1.4.0 → 1.5.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 +3 -3
- package/dist/chunk-ASKP7TIW.mjs +153 -0
- package/dist/chunk-DGYMDV5X.mjs +153 -0
- package/dist/chunk-EHI6MQFS.mjs +566 -0
- package/dist/chunk-G3GLKFP5.mjs +0 -0
- package/dist/chunk-GK4FKSZ4.mjs +697 -0
- package/dist/chunk-NQ4E7ULF.mjs +338 -0
- package/dist/chunk-XGB3TDIC.mjs +42 -0
- package/dist/chunk-Y4PBMUWM.mjs +533 -0
- package/dist/client-DFxKbDns.d.mts +199 -0
- package/dist/client-DFxKbDns.d.ts +199 -0
- package/dist/firewall/index.d.mts +236 -130
- package/dist/firewall/index.d.ts +236 -130
- package/dist/firewall/index.js +479 -2
- package/dist/firewall/index.mjs +12 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +184 -6
- package/dist/index.mjs +9 -11
- package/dist/mcp-policy/index.d.mts +1 -0
- package/dist/mcp-policy/index.d.ts +1 -0
- package/dist/mcp-policy/index.js +27903 -0
- package/dist/mcp-policy/index.mjs +27351 -0
- package/dist/obelysk/index.mjs +2 -2
- package/dist/privacy/index.mjs +2 -2
- package/dist/react/index.mjs +2 -2
- package/examples/.claude/rules/starknet.md +17 -0
- package/examples/CLAUDE.md +59 -0
- package/examples/claude-settings.json +52 -0
- package/examples/test_confidential_swap_api.ts +313 -0
- package/package.json +12 -4
- package/src/hooks/post-tool-use.sh +116 -0
- package/src/hooks/pre-tool-use.sh +112 -0
- package/src/hooks/session-start.sh +50 -0
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ Create a prover client instance.
|
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
40
|
const client = createProverClient({
|
|
41
|
-
url: "https://api.
|
|
41
|
+
url: "https://api.bitsage.network", // default; or your own GPU prover
|
|
42
42
|
apiKey: "your-api-key", // optional, for rate limiting
|
|
43
43
|
timeout: 300_000, // request timeout in ms (default: 5 min)
|
|
44
44
|
});
|
|
@@ -133,7 +133,7 @@ console.log("Result:", job.result);
|
|
|
133
133
|
|
|
134
134
|
When `onChain: true`, the SDK submits the proof to the ObelyZK Recursive Verifier contract on Starknet Sepolia. Verification uses full OODS + Merkle + FRI + PoW (trustless).
|
|
135
135
|
|
|
136
|
-
- **Contract:** `
|
|
136
|
+
- **Contract:** `0x1c208a5fe731c0d03b098b524f274c537587ea1d43d903838cc4a2bf90c40c7`
|
|
137
137
|
- **Method:** `verify_recursive(model_id, io_commitment, stark_proof_data)`
|
|
138
138
|
- **Verification:** Full OODS + Merkle + FRI + PoW (trustless)
|
|
139
139
|
- **Felts:** ~942 per proof (49x compression)
|
|
@@ -149,7 +149,7 @@ const provider = new RpcProvider({
|
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
const result = await provider.callContract({
|
|
152
|
-
contractAddress: "
|
|
152
|
+
contractAddress: "0x1c208a5fe731c0d03b098b524f274c537587ea1d43d903838cc4a2bf90c40c7",
|
|
153
153
|
entrypoint: "get_recursive_verification_count",
|
|
154
154
|
calldata: [modelId],
|
|
155
155
|
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentFirewallSDK
|
|
3
|
+
} from "./chunk-NQ4E7ULF.mjs";
|
|
4
|
+
|
|
5
|
+
// src/firewall/middleware.ts
|
|
6
|
+
function createPolicyEnforcer(config) {
|
|
7
|
+
return new PolicyEnforcer(config);
|
|
8
|
+
}
|
|
9
|
+
var PolicyEnforcer = class {
|
|
10
|
+
sdk;
|
|
11
|
+
config;
|
|
12
|
+
blockThreshold;
|
|
13
|
+
escalateThreshold;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.blockThreshold = config.blockThreshold ?? 7e4;
|
|
17
|
+
this.escalateThreshold = config.escalateThreshold ?? 4e4;
|
|
18
|
+
this.sdk = new AgentFirewallSDK({
|
|
19
|
+
proverUrl: config.proverUrl,
|
|
20
|
+
firewallContract: config.firewallContract ?? "",
|
|
21
|
+
verifierContract: config.verifierContract ?? "",
|
|
22
|
+
rpcUrl: config.rpcUrl ?? "https://starknet-sepolia.public.blastapi.io",
|
|
23
|
+
apiKey: config.apiKey
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check whether an action should be allowed.
|
|
28
|
+
* Calls the ZKML classifier and returns a structured decision.
|
|
29
|
+
*/
|
|
30
|
+
async checkAction(tx) {
|
|
31
|
+
const result = await this.sdk.classify(tx);
|
|
32
|
+
const allowed = result.decision === "approve";
|
|
33
|
+
let reason;
|
|
34
|
+
switch (result.decision) {
|
|
35
|
+
case "approve":
|
|
36
|
+
reason = `Approved: threat_score=${result.threatScore}`;
|
|
37
|
+
break;
|
|
38
|
+
case "escalate":
|
|
39
|
+
reason = `Escalated: threat_score=${result.threatScore}. Requires human approval.`;
|
|
40
|
+
break;
|
|
41
|
+
case "block":
|
|
42
|
+
reason = `Blocked: threat_score=${result.threatScore}. Action rejected by ZKML classifier.`;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
allowed,
|
|
47
|
+
decision: result.decision,
|
|
48
|
+
threatScore: result.threatScore,
|
|
49
|
+
reason,
|
|
50
|
+
ioCommitment: result.ioCommitment,
|
|
51
|
+
policyCommitment: result.policyCommitment,
|
|
52
|
+
proveTimeMs: result.proveTimeMs
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if a Bash command contains an on-chain transaction pattern.
|
|
57
|
+
* Returns the target address if found, null otherwise.
|
|
58
|
+
*/
|
|
59
|
+
extractTarget(command) {
|
|
60
|
+
if (!/(?:starkli|sncast)\s+(?:invoke|deploy)/.test(command) && !/(?:cast\s+send|transfer|approve)/.test(command)) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const match = command.match(/0x[0-9a-fA-F]{10,66}/);
|
|
64
|
+
return match ? match[0] : null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build a canUseTool callback for the Claude Agent SDK.
|
|
68
|
+
*
|
|
69
|
+
* Returns an async function that:
|
|
70
|
+
* - Auto-allows ObelyZK policy tools
|
|
71
|
+
* - Auto-allows safe read-only tools (Read, Glob, Grep)
|
|
72
|
+
* - Classifies Bash commands containing on-chain transactions
|
|
73
|
+
* - Blocks everything else
|
|
74
|
+
*/
|
|
75
|
+
buildCanUseTool() {
|
|
76
|
+
return async (tool, input) => {
|
|
77
|
+
if (tool.startsWith("mcp__obelyzk-policy__")) {
|
|
78
|
+
return { approved: true };
|
|
79
|
+
}
|
|
80
|
+
const safeTools = ["Read", "Glob", "Grep", "Bash"];
|
|
81
|
+
if (!safeTools.includes(tool)) {
|
|
82
|
+
return {
|
|
83
|
+
approved: false,
|
|
84
|
+
reason: `Tool '${tool}' not in allowlist. Only safe tools and ObelyZK policy tools are allowed.`
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (tool === "Bash") {
|
|
88
|
+
const command = input.command || "";
|
|
89
|
+
const target = this.extractTarget(command);
|
|
90
|
+
if (target) {
|
|
91
|
+
const check = await this.checkAction({ target });
|
|
92
|
+
if (!check.allowed) {
|
|
93
|
+
return { approved: false, reason: check.reason };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { approved: true };
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the MCP server configuration for .claude/settings.json
|
|
102
|
+
* or Claude Agent SDK's mcpServers option.
|
|
103
|
+
*/
|
|
104
|
+
getMcpServerConfig() {
|
|
105
|
+
const mcpPath = this.config.mcpServerPath ?? "./node_modules/@obelyzk/sdk/src/mcp-policy/index.ts";
|
|
106
|
+
return {
|
|
107
|
+
"obelyzk-policy": {
|
|
108
|
+
command: "npx",
|
|
109
|
+
args: ["ts-node", mcpPath],
|
|
110
|
+
env: {
|
|
111
|
+
PROVER_URL: this.config.proverUrl,
|
|
112
|
+
STARKNET_RPC: this.config.rpcUrl ?? "",
|
|
113
|
+
FIREWALL_CONTRACT: this.config.firewallContract ?? "",
|
|
114
|
+
VERIFIER_CONTRACT: this.config.verifierContract ?? "",
|
|
115
|
+
PROVER_API_KEY: this.config.apiKey ?? ""
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the list of allowed tools for Claude Agent SDK.
|
|
122
|
+
* Includes safe read-only tools and all ObelyZK policy tools.
|
|
123
|
+
*/
|
|
124
|
+
getAllowedTools() {
|
|
125
|
+
return [
|
|
126
|
+
"Read",
|
|
127
|
+
"Glob",
|
|
128
|
+
"Grep",
|
|
129
|
+
"Bash",
|
|
130
|
+
"mcp__obelyzk-policy__obelyzk_classify",
|
|
131
|
+
"mcp__obelyzk-policy__obelyzk_agent_status",
|
|
132
|
+
"mcp__obelyzk-policy__obelyzk_check_action",
|
|
133
|
+
"mcp__obelyzk-policy__obelyzk_health",
|
|
134
|
+
"mcp__obelyzk-policy__obelyzk_get_policy",
|
|
135
|
+
"mcp__obelyzk-policy__obelyzk_list_models",
|
|
136
|
+
"mcp__obelyzk-policy__obelyzk_verify_proof",
|
|
137
|
+
"mcp__obelyzk-policy__obelyzk_register_agent",
|
|
138
|
+
"mcp__obelyzk-policy__obelyzk_submit_action",
|
|
139
|
+
"mcp__obelyzk-policy__obelyzk_resolve_action",
|
|
140
|
+
"mcp__obelyzk-policy__obelyzk_approve_escalated",
|
|
141
|
+
"mcp__obelyzk-policy__obelyzk_reject_escalated"
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
/** Get the underlying AgentFirewallSDK for advanced use. */
|
|
145
|
+
getSDK() {
|
|
146
|
+
return this.sdk;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
createPolicyEnforcer,
|
|
152
|
+
PolicyEnforcer
|
|
153
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentFirewallSDK
|
|
3
|
+
} from "./chunk-Y4PBMUWM.mjs";
|
|
4
|
+
|
|
5
|
+
// src/firewall/middleware.ts
|
|
6
|
+
function createPolicyEnforcer(config) {
|
|
7
|
+
return new PolicyEnforcer(config);
|
|
8
|
+
}
|
|
9
|
+
var PolicyEnforcer = class {
|
|
10
|
+
sdk;
|
|
11
|
+
config;
|
|
12
|
+
blockThreshold;
|
|
13
|
+
escalateThreshold;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.blockThreshold = config.blockThreshold ?? 7e4;
|
|
17
|
+
this.escalateThreshold = config.escalateThreshold ?? 4e4;
|
|
18
|
+
this.sdk = new AgentFirewallSDK({
|
|
19
|
+
proverUrl: config.proverUrl,
|
|
20
|
+
firewallContract: config.firewallContract ?? "",
|
|
21
|
+
verifierContract: config.verifierContract ?? "",
|
|
22
|
+
rpcUrl: config.rpcUrl ?? "https://starknet-sepolia.public.blastapi.io",
|
|
23
|
+
apiKey: config.apiKey
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check whether an action should be allowed.
|
|
28
|
+
* Calls the ZKML classifier and returns a structured decision.
|
|
29
|
+
*/
|
|
30
|
+
async checkAction(tx) {
|
|
31
|
+
const result = await this.sdk.classify(tx);
|
|
32
|
+
const allowed = result.decision === "approve";
|
|
33
|
+
let reason;
|
|
34
|
+
switch (result.decision) {
|
|
35
|
+
case "approve":
|
|
36
|
+
reason = `Approved: threat_score=${result.threatScore}`;
|
|
37
|
+
break;
|
|
38
|
+
case "escalate":
|
|
39
|
+
reason = `Escalated: threat_score=${result.threatScore}. Requires human approval.`;
|
|
40
|
+
break;
|
|
41
|
+
case "block":
|
|
42
|
+
reason = `Blocked: threat_score=${result.threatScore}. Action rejected by ZKML classifier.`;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
allowed,
|
|
47
|
+
decision: result.decision,
|
|
48
|
+
threatScore: result.threatScore,
|
|
49
|
+
reason,
|
|
50
|
+
ioCommitment: result.ioCommitment,
|
|
51
|
+
policyCommitment: result.policyCommitment,
|
|
52
|
+
proveTimeMs: result.proveTimeMs
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if a Bash command contains an on-chain transaction pattern.
|
|
57
|
+
* Returns the target address if found, null otherwise.
|
|
58
|
+
*/
|
|
59
|
+
extractTarget(command) {
|
|
60
|
+
if (!/(?:starkli|sncast)\s+(?:invoke|deploy)/.test(command) && !/(?:cast\s+send|transfer|approve)/.test(command)) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const match = command.match(/0x[0-9a-fA-F]{10,66}/);
|
|
64
|
+
return match ? match[0] : null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build a canUseTool callback for the Claude Agent SDK.
|
|
68
|
+
*
|
|
69
|
+
* Returns an async function that:
|
|
70
|
+
* - Auto-allows ObelyZK policy tools
|
|
71
|
+
* - Auto-allows safe read-only tools (Read, Glob, Grep)
|
|
72
|
+
* - Classifies Bash commands containing on-chain transactions
|
|
73
|
+
* - Blocks everything else
|
|
74
|
+
*/
|
|
75
|
+
buildCanUseTool() {
|
|
76
|
+
return async (tool, input) => {
|
|
77
|
+
if (tool.startsWith("mcp__obelyzk-policy__")) {
|
|
78
|
+
return { approved: true };
|
|
79
|
+
}
|
|
80
|
+
const safeTools = ["Read", "Glob", "Grep", "Bash"];
|
|
81
|
+
if (!safeTools.includes(tool)) {
|
|
82
|
+
return {
|
|
83
|
+
approved: false,
|
|
84
|
+
reason: `Tool '${tool}' not in allowlist. Only safe tools and ObelyZK policy tools are allowed.`
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (tool === "Bash") {
|
|
88
|
+
const command = input.command || "";
|
|
89
|
+
const target = this.extractTarget(command);
|
|
90
|
+
if (target) {
|
|
91
|
+
const check = await this.checkAction({ target });
|
|
92
|
+
if (!check.allowed) {
|
|
93
|
+
return { approved: false, reason: check.reason };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { approved: true };
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the MCP server configuration for .claude/settings.json
|
|
102
|
+
* or Claude Agent SDK's mcpServers option.
|
|
103
|
+
*/
|
|
104
|
+
getMcpServerConfig() {
|
|
105
|
+
const mcpPath = this.config.mcpServerPath ?? "./node_modules/@obelyzk/sdk/src/mcp-policy/index.ts";
|
|
106
|
+
return {
|
|
107
|
+
"obelyzk-policy": {
|
|
108
|
+
command: "npx",
|
|
109
|
+
args: ["ts-node", mcpPath],
|
|
110
|
+
env: {
|
|
111
|
+
PROVER_URL: this.config.proverUrl,
|
|
112
|
+
STARKNET_RPC: this.config.rpcUrl ?? "",
|
|
113
|
+
FIREWALL_CONTRACT: this.config.firewallContract ?? "",
|
|
114
|
+
VERIFIER_CONTRACT: this.config.verifierContract ?? "",
|
|
115
|
+
PROVER_API_KEY: this.config.apiKey ?? ""
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the list of allowed tools for Claude Agent SDK.
|
|
122
|
+
* Includes safe read-only tools and all ObelyZK policy tools.
|
|
123
|
+
*/
|
|
124
|
+
getAllowedTools() {
|
|
125
|
+
return [
|
|
126
|
+
"Read",
|
|
127
|
+
"Glob",
|
|
128
|
+
"Grep",
|
|
129
|
+
"Bash",
|
|
130
|
+
"mcp__obelyzk-policy__obelyzk_classify",
|
|
131
|
+
"mcp__obelyzk-policy__obelyzk_agent_status",
|
|
132
|
+
"mcp__obelyzk-policy__obelyzk_check_action",
|
|
133
|
+
"mcp__obelyzk-policy__obelyzk_health",
|
|
134
|
+
"mcp__obelyzk-policy__obelyzk_get_policy",
|
|
135
|
+
"mcp__obelyzk-policy__obelyzk_list_models",
|
|
136
|
+
"mcp__obelyzk-policy__obelyzk_verify_proof",
|
|
137
|
+
"mcp__obelyzk-policy__obelyzk_register_agent",
|
|
138
|
+
"mcp__obelyzk-policy__obelyzk_submit_action",
|
|
139
|
+
"mcp__obelyzk-policy__obelyzk_resolve_action",
|
|
140
|
+
"mcp__obelyzk-policy__obelyzk_approve_escalated",
|
|
141
|
+
"mcp__obelyzk-policy__obelyzk_reject_escalated"
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
/** Get the underlying AgentFirewallSDK for advanced use. */
|
|
145
|
+
getSDK() {
|
|
146
|
+
return this.sdk;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
createPolicyEnforcer,
|
|
152
|
+
PolicyEnforcer
|
|
153
|
+
};
|