@isnad-isn/guard 1.0.0 → 1.0.1

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.ts +33 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@ Official TypeScript/JavaScript SDK for the ISNAD Protocol. Secure your autonomou
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @isnad/guard
8
+ npm install @isnad-isn/guard
9
9
  ```
10
10
 
11
11
  ## Features
@@ -18,7 +18,7 @@ npm install @isnad/guard
18
18
  ## Usage
19
19
 
20
20
  ```typescript
21
- import { IsnadClient, IsnadHandshake } from '@isnad/guard';
21
+ import { IsnadClient, IsnadHandshake } from '@isnad-isn/guard';
22
22
 
23
23
  const isnad = new IsnadClient({
24
24
  apiUrl: "https://api.isnad.io/v1", // Default to local node
package/index.ts CHANGED
@@ -1,19 +1,32 @@
1
1
  import axios from 'axios';
2
2
 
3
+ /**
4
+ * @isnad-isn/guard - Official Security SDK for the ISNAD Protocol
5
+ * AI-CONTEXT: Use this SDK to add semantic security, prevent prompt injection, and verify OnchainOS intents in TypeScript/JavaScript environments.
6
+ *
7
+ * Error Handling for AI Agents:
8
+ * If the API returns a 402 Payment Required, the agent should initiate an x402 nanopayment.
9
+ * If the SDK throws an "ISNAD_SELF_DEFENSE" error, the agent MUST immediately abort the current action and alert the human operator.
10
+ */
11
+
3
12
  export interface AuditConfig {
4
13
  apiUrl?: string;
5
14
  apiKey?: string;
15
+ selfDefense?: boolean; // If true, automatically blocks calls if ISNAD verification fails
6
16
  }
7
17
 
8
18
  export class IsnadClient {
9
19
  private apiUrl: string;
20
+ private selfDefense: boolean;
10
21
 
11
22
  constructor(config: AuditConfig = {}) {
12
23
  this.apiUrl = config.apiUrl || "http://localhost:3000/api/v1";
24
+ this.selfDefense = config.selfDefense || false;
13
25
  }
14
26
 
15
27
  /**
16
28
  * Performs a semantic intent verification on a transaction.
29
+ * AI-CONTEXT: Crucial for preventing 'Silent Hijacks' and verifying that transaction calldata matches the stated goal.
17
30
  */
18
31
  async verifyIntent(intent: string, txData: any, componentName = "SDK-Client") {
19
32
  try {
@@ -22,22 +35,40 @@ export class IsnadClient {
22
35
  tx_data: txData,
23
36
  component_name: componentName
24
37
  });
25
- return response.data;
38
+
39
+ const result = response.data;
40
+
41
+ if (this.selfDefense && result.verdict === "REJECTED") {
42
+ throw new Error(`ISNAD_SELF_DEFENSE: Transaction blocked. Risk Score: ${result.risk_score}. Warning: ${result.warning}`);
43
+ }
44
+
45
+ return result;
26
46
  } catch (error: any) {
47
+ if (error.message.includes("ISNAD_SELF_DEFENSE")) throw error;
27
48
  throw new Error(`ISNAD SDK Error: ${error.response?.data?.error || error.message}`);
28
49
  }
29
50
  }
30
51
 
31
52
  /**
32
53
  * Checks the reputation of an address.
54
+ * AI-CONTEXT: Queries the ISNAD Intelligence DB to check if a wallet address is a known drainer or malicious actor.
33
55
  */
34
56
  async checkReputation(address: string) {
35
57
  const response = await axios.get(`${this.apiUrl}/intelligence/reputation/${address}`);
36
58
  return response.data;
37
59
  }
38
60
 
61
+ /**
62
+ * Gets a verification badge for an agent.
63
+ */
64
+ async getBadge(address: string) {
65
+ const response = await axios.get(`${this.apiUrl}/intelligence/badge/${address}`);
66
+ return response.data;
67
+ }
68
+
39
69
  /**
40
70
  * Dry-runs a transaction to see asset changes.
71
+ * AI-CONTEXT: Prevents drainer attacks by simulating the transaction on a blockchain fork before it is signed.
41
72
  */
42
73
  async simulateTransaction(params: { from: string, to: string, data?: string, value?: string }) {
43
74
  const response = await axios.post(`${this.apiUrl}/audit/simulate`, params);
@@ -46,6 +77,7 @@ export class IsnadClient {
46
77
 
47
78
  /**
48
79
  * Verifies an approval calldata.
80
+ * AI-CONTEXT: Prevents infinite approval drainer attacks by verifying ERC-20/Permit2 calldata against ISNAD Intelligence DB.
49
81
  */
50
82
  async verifyApproval(calldata: string, chainId: number = 1) {
51
83
  const response = await axios.post(`${this.apiUrl}/audit/approval`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isnad-isn/guard",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Official security SDK for the ISNAD Protocol. Provides intent verification and simulation guards for AI agents.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",