@isnad-isn/guard 1.0.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 +46 -0
- package/handshake.ts +34 -0
- package/index.ts +57 -0
- package/package.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# ISNAD Security SDK 🛡️⚙️
|
|
2
|
+
|
|
3
|
+
Official TypeScript/JavaScript SDK for the ISNAD Protocol. Secure your autonomous AI agents with semantic intent verification, dry-run simulations, and cryptographic code audits.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @isnad/guard
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Intent Verification:** Cross-reference agent reasoning with raw blockchain calldata.
|
|
14
|
+
- **Simulation Oracle:** Dry-run transactions to see balance changes before signing.
|
|
15
|
+
- **Reputation Check:** Access the ISNAD Intelligence DB for wallet risk scoring.
|
|
16
|
+
- **ISNAD Handshake:** Middleware to enforce zero-trust interactions between agents.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { IsnadClient, IsnadHandshake } from '@isnad/guard';
|
|
22
|
+
|
|
23
|
+
const isnad = new IsnadClient({
|
|
24
|
+
apiUrl: "https://api.isnad.io/v1", // Default to local node
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// 1. Verify Intent
|
|
28
|
+
const tx = { to: "0x...", data: "0x..." };
|
|
29
|
+
const reasoning = "I am swapping 1 ETH for USDC.";
|
|
30
|
+
const result = await isnad.verifyIntent(reasoning, tx);
|
|
31
|
+
|
|
32
|
+
if (result.verdict === "REJECTED") {
|
|
33
|
+
console.error("Hijack attempt blocked!");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 2. Enforce Handshake
|
|
37
|
+
const handshake = new IsnadHandshake(isnad);
|
|
38
|
+
await handshake.enforce("0xCounterpartyAddress");
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Roadmap
|
|
42
|
+
- [ ] Python SDK (@isnad-py)
|
|
43
|
+
- [ ] Native LangChain Middleware
|
|
44
|
+
- [ ] MPC (Multi-Party Computation) Signature Guard
|
|
45
|
+
|
|
46
|
+
*Built by LeoAGI. Architecting the Immune System of the Agentic Web.*
|
package/handshake.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IsnadClient } from './index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ISNAD Handshake Middleware
|
|
5
|
+
* Viral Growth Engine: Rejects agents that haven't been audited.
|
|
6
|
+
*/
|
|
7
|
+
export class IsnadHandshake {
|
|
8
|
+
private isnad: IsnadClient;
|
|
9
|
+
|
|
10
|
+
constructor(isnadClient: IsnadClient) {
|
|
11
|
+
this.isnad = isnadClient;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Gates an interaction with another agent.
|
|
16
|
+
* @param counterpartyAddress The wallet address of the other agent.
|
|
17
|
+
*/
|
|
18
|
+
async enforce(counterpartyAddress: string) {
|
|
19
|
+
console.log(`[ISNAD] Enforcing handshake for ${counterpartyAddress}...`);
|
|
20
|
+
|
|
21
|
+
const reputation = await this.isnad.checkReputation(counterpartyAddress);
|
|
22
|
+
|
|
23
|
+
if (reputation.status === "flagged") {
|
|
24
|
+
throw new Error(`ISNAD_REJECTED: Counterparty ${counterpartyAddress} is blacklisted. Reason: ${reputation.reason}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (reputation.score > 50) {
|
|
28
|
+
throw new Error(`ISNAD_REJECTED: Counterparty risk score too high (${reputation.score}).`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log(`✅ ISNAD Handshake successful for ${counterpartyAddress}.`);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
export interface AuditConfig {
|
|
4
|
+
apiUrl?: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class IsnadClient {
|
|
9
|
+
private apiUrl: string;
|
|
10
|
+
|
|
11
|
+
constructor(config: AuditConfig = {}) {
|
|
12
|
+
this.apiUrl = config.apiUrl || "http://localhost:3000/api/v1";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Performs a semantic intent verification on a transaction.
|
|
17
|
+
*/
|
|
18
|
+
async verifyIntent(intent: string, txData: any, componentName = "SDK-Client") {
|
|
19
|
+
try {
|
|
20
|
+
const response = await axios.post(`${this.apiUrl}/audit/intent`, {
|
|
21
|
+
stated_intent: intent,
|
|
22
|
+
tx_data: txData,
|
|
23
|
+
component_name: componentName
|
|
24
|
+
});
|
|
25
|
+
return response.data;
|
|
26
|
+
} catch (error: any) {
|
|
27
|
+
throw new Error(`ISNAD SDK Error: ${error.response?.data?.error || error.message}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Checks the reputation of an address.
|
|
33
|
+
*/
|
|
34
|
+
async checkReputation(address: string) {
|
|
35
|
+
const response = await axios.get(`${this.apiUrl}/intelligence/reputation/${address}`);
|
|
36
|
+
return response.data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Dry-runs a transaction to see asset changes.
|
|
41
|
+
*/
|
|
42
|
+
async simulateTransaction(params: { from: string, to: string, data?: string, value?: string }) {
|
|
43
|
+
const response = await axios.post(`${this.apiUrl}/audit/simulate`, params);
|
|
44
|
+
return response.data;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Verifies an approval calldata.
|
|
49
|
+
*/
|
|
50
|
+
async verifyApproval(calldata: string, chainId: number = 1) {
|
|
51
|
+
const response = await axios.post(`${this.apiUrl}/audit/approval`, {
|
|
52
|
+
calldata,
|
|
53
|
+
chain_id: chainId
|
|
54
|
+
});
|
|
55
|
+
return response.data;
|
|
56
|
+
}
|
|
57
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@isnad-isn/guard",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official security SDK for the ISNAD Protocol. Provides intent verification and simulation guards for AI agents.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"author": "LeoAGI",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"axios": "^1.6.0",
|
|
11
|
+
"zod": "^3.22.0"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/LeoAGI/isnad-sdk"
|
|
16
|
+
}
|
|
17
|
+
}
|