@obelyzk/sdk 1.4.0 → 1.6.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 +7 -7
- 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 +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +231 -6
- package/dist/index.mjs +54 -9
- 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/dist/index.js
CHANGED
|
@@ -85,10 +85,10 @@ __export(index_exports, {
|
|
|
85
85
|
createMiningClient: () => createMiningClient,
|
|
86
86
|
createPaymentsClient: () => createPaymentsClient,
|
|
87
87
|
createPrivacyClient: () => createPrivacyClient,
|
|
88
|
-
createProverClient: () =>
|
|
88
|
+
createProverClient: () => createStwoProverClient,
|
|
89
89
|
createStakingClient: () => createStakingClient,
|
|
90
90
|
createStwoClient: () => createStwoClient,
|
|
91
|
-
createStwoProverClient: () =>
|
|
91
|
+
createStwoProverClient: () => createStwoProverClient,
|
|
92
92
|
createTeeClient: () => createTeeClient,
|
|
93
93
|
createTransferProof: () => createTransferProof,
|
|
94
94
|
createWebSocketClient: () => createWebSocketClient,
|
|
@@ -6418,6 +6418,53 @@ var StwoProverClient = class {
|
|
|
6418
6418
|
/**
|
|
6419
6419
|
* Generate proof for AI/ML inference
|
|
6420
6420
|
*/
|
|
6421
|
+
/**
|
|
6422
|
+
* Verifiable chat inference — send a prompt, get a response with on-chain proof.
|
|
6423
|
+
*
|
|
6424
|
+
* @example
|
|
6425
|
+
* ```typescript
|
|
6426
|
+
* const result = await prover.chat("What is 2+2?", { model: "local", maxTokens: 1 });
|
|
6427
|
+
* console.log(result.text); // model output
|
|
6428
|
+
* console.log(result.txHash); // Starknet TX hash
|
|
6429
|
+
* console.log(result.explorerUrl); // Starkscan link
|
|
6430
|
+
* console.log(result.calldataFelts); // ~950 felts
|
|
6431
|
+
* console.log(result.modelId); // weight commitment hash
|
|
6432
|
+
* ```
|
|
6433
|
+
*/
|
|
6434
|
+
async chat(prompt, options) {
|
|
6435
|
+
const response = await fetch(`${this.config.baseUrl}/v1/chat/completions`, {
|
|
6436
|
+
method: "POST",
|
|
6437
|
+
headers: {
|
|
6438
|
+
"Content-Type": "application/json",
|
|
6439
|
+
...this.config.apiKey ? { Authorization: `Bearer ${this.config.apiKey}` } : {}
|
|
6440
|
+
},
|
|
6441
|
+
body: JSON.stringify({
|
|
6442
|
+
model: options?.model ?? "local",
|
|
6443
|
+
messages: [{ role: "user", content: prompt }],
|
|
6444
|
+
max_tokens: options?.maxTokens ?? 1,
|
|
6445
|
+
stream: false,
|
|
6446
|
+
session_id: options?.sessionId
|
|
6447
|
+
})
|
|
6448
|
+
});
|
|
6449
|
+
if (!response.ok) {
|
|
6450
|
+
const err = await response.text();
|
|
6451
|
+
throw new Error(`Chat failed (${response.status}): ${err}`);
|
|
6452
|
+
}
|
|
6453
|
+
const data = await response.json();
|
|
6454
|
+
const choice = data.choices?.[0];
|
|
6455
|
+
const meta = data.obelyzk ?? {};
|
|
6456
|
+
return {
|
|
6457
|
+
text: choice?.message?.content ?? "",
|
|
6458
|
+
txHash: meta.tx_hash,
|
|
6459
|
+
proofHash: meta.proof_hash,
|
|
6460
|
+
modelId: meta.model_id,
|
|
6461
|
+
ioCommitment: meta.io_commitment,
|
|
6462
|
+
calldataFelts: meta.calldata_felts,
|
|
6463
|
+
explorerUrl: meta.explorer_url,
|
|
6464
|
+
proveTimeSecs: meta.prove_time_secs,
|
|
6465
|
+
trustModel: meta.trust_model ?? "unknown"
|
|
6466
|
+
};
|
|
6467
|
+
}
|
|
6421
6468
|
async proveInference(modelId, inputs, outputs, options) {
|
|
6422
6469
|
const job = await this.submitProofJob({
|
|
6423
6470
|
proofType: "ai_inference",
|
|
@@ -6513,7 +6560,7 @@ var StwoProverClient = class {
|
|
|
6513
6560
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6514
6561
|
}
|
|
6515
6562
|
};
|
|
6516
|
-
function
|
|
6563
|
+
function createStwoProverClient(config) {
|
|
6517
6564
|
return new StwoProverClient(config ?? {});
|
|
6518
6565
|
}
|
|
6519
6566
|
StwoProverClient.prototype.listZkmlModels = async function() {
|
|
@@ -6786,6 +6833,124 @@ var AgentFirewallSDK = class {
|
|
|
6786
6833
|
);
|
|
6787
6834
|
return contract.is_trusted(agentId);
|
|
6788
6835
|
}
|
|
6836
|
+
/** Get the decision for an action (0=pending, 1=approved, 2=escalated, 3=blocked). */
|
|
6837
|
+
async getActionDecision(actionId) {
|
|
6838
|
+
const contract = new import_starknet.Contract(
|
|
6839
|
+
FIREWALL_ABI,
|
|
6840
|
+
this.config.firewallContract,
|
|
6841
|
+
this.provider
|
|
6842
|
+
);
|
|
6843
|
+
return Number(await contract.get_action_decision(actionId));
|
|
6844
|
+
}
|
|
6845
|
+
/** Get the threat score for a resolved action. */
|
|
6846
|
+
async getActionThreatScore(actionId) {
|
|
6847
|
+
const contract = new import_starknet.Contract(
|
|
6848
|
+
FIREWALL_ABI,
|
|
6849
|
+
this.config.firewallContract,
|
|
6850
|
+
this.provider
|
|
6851
|
+
);
|
|
6852
|
+
return Number(await contract.get_action_threat_score(actionId));
|
|
6853
|
+
}
|
|
6854
|
+
/** Get the IO commitment for an action. */
|
|
6855
|
+
async getActionIoCommitment(actionId) {
|
|
6856
|
+
const contract = new import_starknet.Contract(
|
|
6857
|
+
FIREWALL_ABI,
|
|
6858
|
+
this.config.firewallContract,
|
|
6859
|
+
this.provider
|
|
6860
|
+
);
|
|
6861
|
+
const result = await contract.get_action_io_commitment(actionId);
|
|
6862
|
+
return `0x${BigInt(result).toString(16)}`;
|
|
6863
|
+
}
|
|
6864
|
+
// ── On-Chain Actions ────────────────────────────────────────────────
|
|
6865
|
+
/**
|
|
6866
|
+
* Submit a pending action to the firewall contract.
|
|
6867
|
+
* Returns the action_id assigned by the contract.
|
|
6868
|
+
*/
|
|
6869
|
+
async submitAction(agentId, target, value, selector, ioCommitment) {
|
|
6870
|
+
this.requireAccount();
|
|
6871
|
+
const tx = await this.config.account.execute({
|
|
6872
|
+
contractAddress: this.config.firewallContract,
|
|
6873
|
+
entrypoint: "submit_action",
|
|
6874
|
+
calldata: import_starknet.CallData.compile({
|
|
6875
|
+
agent_id: agentId,
|
|
6876
|
+
target,
|
|
6877
|
+
value,
|
|
6878
|
+
selector,
|
|
6879
|
+
io_commitment: ioCommitment
|
|
6880
|
+
})
|
|
6881
|
+
});
|
|
6882
|
+
const receipt = await this.provider.waitForTransaction(tx.transaction_hash);
|
|
6883
|
+
let actionId = 0;
|
|
6884
|
+
const events = receipt.events;
|
|
6885
|
+
if (Array.isArray(events)) {
|
|
6886
|
+
for (const event of events) {
|
|
6887
|
+
if (event.data && event.data.length >= 2) {
|
|
6888
|
+
const candidateId = Number(BigInt(event.data[0]));
|
|
6889
|
+
if (candidateId > 0) {
|
|
6890
|
+
actionId = candidateId;
|
|
6891
|
+
break;
|
|
6892
|
+
}
|
|
6893
|
+
}
|
|
6894
|
+
}
|
|
6895
|
+
}
|
|
6896
|
+
return { actionId, txHash: tx.transaction_hash };
|
|
6897
|
+
}
|
|
6898
|
+
/**
|
|
6899
|
+
* Resolve a pending action with a verified ZKML proof.
|
|
6900
|
+
* The proof must already be verified on the ObelyskVerifier contract.
|
|
6901
|
+
*/
|
|
6902
|
+
async resolveAction(actionId, proofHash, originalIoLen, packedRawIo) {
|
|
6903
|
+
this.requireAccount();
|
|
6904
|
+
const tx = await this.config.account.execute({
|
|
6905
|
+
contractAddress: this.config.firewallContract,
|
|
6906
|
+
entrypoint: "resolve_action_with_proof",
|
|
6907
|
+
calldata: import_starknet.CallData.compile({
|
|
6908
|
+
action_id: actionId,
|
|
6909
|
+
proof_hash: proofHash,
|
|
6910
|
+
original_io_len: originalIoLen,
|
|
6911
|
+
packed_raw_io: packedRawIo
|
|
6912
|
+
})
|
|
6913
|
+
});
|
|
6914
|
+
const receipt = await this.provider.waitForTransaction(tx.transaction_hash);
|
|
6915
|
+
let decision = "approve";
|
|
6916
|
+
let threatScore = 0;
|
|
6917
|
+
const resolveEvents = receipt.events;
|
|
6918
|
+
if (Array.isArray(resolveEvents)) {
|
|
6919
|
+
for (const event of resolveEvents) {
|
|
6920
|
+
if (event.data && event.data.length >= 4) {
|
|
6921
|
+
const decisionCode = Number(BigInt(event.data[2]));
|
|
6922
|
+
threatScore = Number(BigInt(event.data[3]));
|
|
6923
|
+
if (decisionCode === 1) decision = "approve";
|
|
6924
|
+
else if (decisionCode === 2) decision = "escalate";
|
|
6925
|
+
else if (decisionCode === 3) decision = "block";
|
|
6926
|
+
break;
|
|
6927
|
+
}
|
|
6928
|
+
}
|
|
6929
|
+
}
|
|
6930
|
+
return { decision, threatScore, txHash: tx.transaction_hash };
|
|
6931
|
+
}
|
|
6932
|
+
/** Approve an escalated action (human-in-the-loop). */
|
|
6933
|
+
async approveEscalated(actionId) {
|
|
6934
|
+
this.requireAccount();
|
|
6935
|
+
const tx = await this.config.account.execute({
|
|
6936
|
+
contractAddress: this.config.firewallContract,
|
|
6937
|
+
entrypoint: "approve_escalated",
|
|
6938
|
+
calldata: import_starknet.CallData.compile({ action_id: actionId })
|
|
6939
|
+
});
|
|
6940
|
+
await this.provider.waitForTransaction(tx.transaction_hash);
|
|
6941
|
+
return tx.transaction_hash;
|
|
6942
|
+
}
|
|
6943
|
+
/** Reject an escalated action and add a strike. */
|
|
6944
|
+
async rejectEscalated(actionId) {
|
|
6945
|
+
this.requireAccount();
|
|
6946
|
+
const tx = await this.config.account.execute({
|
|
6947
|
+
contractAddress: this.config.firewallContract,
|
|
6948
|
+
entrypoint: "reject_escalated",
|
|
6949
|
+
calldata: import_starknet.CallData.compile({ action_id: actionId })
|
|
6950
|
+
});
|
|
6951
|
+
await this.provider.waitForTransaction(tx.transaction_hash);
|
|
6952
|
+
return tx.transaction_hash;
|
|
6953
|
+
}
|
|
6789
6954
|
// ── Helpers ────────────────────────────────────────────────────────
|
|
6790
6955
|
requireAccount() {
|
|
6791
6956
|
if (!this.config.account) {
|
|
@@ -6844,6 +7009,69 @@ var FIREWALL_ABI = [
|
|
|
6844
7009
|
inputs: [{ name: "action_id", type: "felt" }],
|
|
6845
7010
|
outputs: [{ type: "felt" }],
|
|
6846
7011
|
state_mutability: "view"
|
|
7012
|
+
},
|
|
7013
|
+
{
|
|
7014
|
+
name: "get_action_threat_score",
|
|
7015
|
+
type: "function",
|
|
7016
|
+
inputs: [{ name: "action_id", type: "felt" }],
|
|
7017
|
+
outputs: [{ type: "felt" }],
|
|
7018
|
+
state_mutability: "view"
|
|
7019
|
+
},
|
|
7020
|
+
{
|
|
7021
|
+
name: "get_action_io_commitment",
|
|
7022
|
+
type: "function",
|
|
7023
|
+
inputs: [{ name: "action_id", type: "felt" }],
|
|
7024
|
+
outputs: [{ type: "felt" }],
|
|
7025
|
+
state_mutability: "view"
|
|
7026
|
+
},
|
|
7027
|
+
{
|
|
7028
|
+
name: "get_owner",
|
|
7029
|
+
type: "function",
|
|
7030
|
+
inputs: [],
|
|
7031
|
+
outputs: [{ type: "felt" }],
|
|
7032
|
+
state_mutability: "view"
|
|
7033
|
+
},
|
|
7034
|
+
{
|
|
7035
|
+
name: "get_verifier",
|
|
7036
|
+
type: "function",
|
|
7037
|
+
inputs: [],
|
|
7038
|
+
outputs: [{ type: "felt" }],
|
|
7039
|
+
state_mutability: "view"
|
|
7040
|
+
},
|
|
7041
|
+
{
|
|
7042
|
+
name: "get_classifier_model_id",
|
|
7043
|
+
type: "function",
|
|
7044
|
+
inputs: [],
|
|
7045
|
+
outputs: [{ type: "felt" }],
|
|
7046
|
+
state_mutability: "view"
|
|
7047
|
+
},
|
|
7048
|
+
{
|
|
7049
|
+
name: "get_thresholds",
|
|
7050
|
+
type: "function",
|
|
7051
|
+
inputs: [],
|
|
7052
|
+
outputs: [{ type: "felt" }, { type: "felt" }, { type: "felt" }],
|
|
7053
|
+
state_mutability: "view"
|
|
7054
|
+
},
|
|
7055
|
+
{
|
|
7056
|
+
name: "get_agent_owner",
|
|
7057
|
+
type: "function",
|
|
7058
|
+
inputs: [{ name: "agent_id", type: "felt" }],
|
|
7059
|
+
outputs: [{ type: "felt" }],
|
|
7060
|
+
state_mutability: "view"
|
|
7061
|
+
},
|
|
7062
|
+
{
|
|
7063
|
+
name: "get_action_agent",
|
|
7064
|
+
type: "function",
|
|
7065
|
+
inputs: [{ name: "action_id", type: "felt" }],
|
|
7066
|
+
outputs: [{ type: "felt" }],
|
|
7067
|
+
state_mutability: "view"
|
|
7068
|
+
},
|
|
7069
|
+
{
|
|
7070
|
+
name: "is_paused",
|
|
7071
|
+
type: "function",
|
|
7072
|
+
inputs: [],
|
|
7073
|
+
outputs: [{ type: "felt" }],
|
|
7074
|
+
state_mutability: "view"
|
|
6847
7075
|
}
|
|
6848
7076
|
];
|
|
6849
7077
|
|
|
@@ -7584,9 +7812,6 @@ var ConfidentialSwapClient = class {
|
|
|
7584
7812
|
};
|
|
7585
7813
|
}
|
|
7586
7814
|
};
|
|
7587
|
-
|
|
7588
|
-
// src/index.ts
|
|
7589
|
-
var createProverClient = createStwoProverClient;
|
|
7590
7815
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7591
7816
|
0 && (module.exports = {
|
|
7592
7817
|
AgentFirewallSDK,
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import "./chunk-DGYMDV5X.mjs";
|
|
1
2
|
import {
|
|
2
3
|
AgentFirewallSDK
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-Y4PBMUWM.mjs";
|
|
4
5
|
import {
|
|
5
6
|
BatchClient,
|
|
6
7
|
BitSageClient,
|
|
@@ -87,8 +88,8 @@ import {
|
|
|
87
88
|
powMod,
|
|
88
89
|
randomScalar,
|
|
89
90
|
subMod
|
|
90
|
-
} from "./chunk-
|
|
91
|
-
import "./chunk-
|
|
91
|
+
} from "./chunk-GK4FKSZ4.mjs";
|
|
92
|
+
import "./chunk-XGB3TDIC.mjs";
|
|
92
93
|
|
|
93
94
|
// src/types.ts
|
|
94
95
|
function getMinStake(tier) {
|
|
@@ -499,6 +500,53 @@ var StwoProverClient = class {
|
|
|
499
500
|
/**
|
|
500
501
|
* Generate proof for AI/ML inference
|
|
501
502
|
*/
|
|
503
|
+
/**
|
|
504
|
+
* Verifiable chat inference — send a prompt, get a response with on-chain proof.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* const result = await prover.chat("What is 2+2?", { model: "local", maxTokens: 1 });
|
|
509
|
+
* console.log(result.text); // model output
|
|
510
|
+
* console.log(result.txHash); // Starknet TX hash
|
|
511
|
+
* console.log(result.explorerUrl); // Starkscan link
|
|
512
|
+
* console.log(result.calldataFelts); // ~950 felts
|
|
513
|
+
* console.log(result.modelId); // weight commitment hash
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
async chat(prompt, options) {
|
|
517
|
+
const response = await fetch(`${this.config.baseUrl}/v1/chat/completions`, {
|
|
518
|
+
method: "POST",
|
|
519
|
+
headers: {
|
|
520
|
+
"Content-Type": "application/json",
|
|
521
|
+
...this.config.apiKey ? { Authorization: `Bearer ${this.config.apiKey}` } : {}
|
|
522
|
+
},
|
|
523
|
+
body: JSON.stringify({
|
|
524
|
+
model: options?.model ?? "local",
|
|
525
|
+
messages: [{ role: "user", content: prompt }],
|
|
526
|
+
max_tokens: options?.maxTokens ?? 1,
|
|
527
|
+
stream: false,
|
|
528
|
+
session_id: options?.sessionId
|
|
529
|
+
})
|
|
530
|
+
});
|
|
531
|
+
if (!response.ok) {
|
|
532
|
+
const err = await response.text();
|
|
533
|
+
throw new Error(`Chat failed (${response.status}): ${err}`);
|
|
534
|
+
}
|
|
535
|
+
const data = await response.json();
|
|
536
|
+
const choice = data.choices?.[0];
|
|
537
|
+
const meta = data.obelyzk ?? {};
|
|
538
|
+
return {
|
|
539
|
+
text: choice?.message?.content ?? "",
|
|
540
|
+
txHash: meta.tx_hash,
|
|
541
|
+
proofHash: meta.proof_hash,
|
|
542
|
+
modelId: meta.model_id,
|
|
543
|
+
ioCommitment: meta.io_commitment,
|
|
544
|
+
calldataFelts: meta.calldata_felts,
|
|
545
|
+
explorerUrl: meta.explorer_url,
|
|
546
|
+
proveTimeSecs: meta.prove_time_secs,
|
|
547
|
+
trustModel: meta.trust_model ?? "unknown"
|
|
548
|
+
};
|
|
549
|
+
}
|
|
502
550
|
async proveInference(modelId, inputs, outputs, options) {
|
|
503
551
|
const job = await this.submitProofJob({
|
|
504
552
|
proofType: "ai_inference",
|
|
@@ -594,7 +642,7 @@ var StwoProverClient = class {
|
|
|
594
642
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
595
643
|
}
|
|
596
644
|
};
|
|
597
|
-
function
|
|
645
|
+
function createStwoProverClient(config) {
|
|
598
646
|
return new StwoProverClient(config ?? {});
|
|
599
647
|
}
|
|
600
648
|
StwoProverClient.prototype.listZkmlModels = async function() {
|
|
@@ -792,9 +840,6 @@ function getVersionBanner(version) {
|
|
|
792
840
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
793
841
|
`;
|
|
794
842
|
}
|
|
795
|
-
|
|
796
|
-
// src/index.ts
|
|
797
|
-
var createProverClient = createStwoProverClient;
|
|
798
843
|
export {
|
|
799
844
|
AgentFirewallSDK,
|
|
800
845
|
AssetId,
|
|
@@ -861,10 +906,10 @@ export {
|
|
|
861
906
|
createMiningClient,
|
|
862
907
|
createPaymentsClient,
|
|
863
908
|
createPrivacyClient,
|
|
864
|
-
createProverClient,
|
|
909
|
+
createStwoProverClient as createProverClient,
|
|
865
910
|
createStakingClient,
|
|
866
911
|
createStwoClient,
|
|
867
|
-
|
|
912
|
+
createStwoProverClient,
|
|
868
913
|
createTeeClient,
|
|
869
914
|
createTransferProof,
|
|
870
915
|
createWebSocketClient,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|