@enshell/sdk 0.1.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/client.d.ts +18 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +105 -0
- package/dist/client.js.map +1 -0
- package/dist/contract.d.ts +9 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +42 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/networks.d.ts +11 -0
- package/dist/networks.d.ts.map +1 -0
- package/dist/networks.js +18 -0
- package/dist/networks.js.map +1 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ENShell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# ENShell SDK
|
|
2
|
+
|
|
3
|
+
[](https://codecov.io/gh/0xenshell/sdk)
|
|
4
|
+
|
|
5
|
+
Core SDK for **ENShell**, an on-chain firewall for AI agents. Provides a typed client to register agents, submit actions through the firewall, manage target permissions, and handle Ledger approvals. Built on ethers.js v6.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
Requires Node.js >= 22.10.0.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @enshell/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { ENShell, Network } from "@enshell/sdk";
|
|
19
|
+
import { Wallet, JsonRpcProvider } from "ethers";
|
|
20
|
+
|
|
21
|
+
const provider = new JsonRpcProvider("https://rpc.sepolia.org");
|
|
22
|
+
const signer = new Wallet(process.env.PRIVATE_KEY!, provider);
|
|
23
|
+
|
|
24
|
+
const enshell = new ENShell({
|
|
25
|
+
network: Network.SEPOLIA,
|
|
26
|
+
signer,
|
|
27
|
+
contractAddress: "0x...",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Register an agent
|
|
31
|
+
await enshell.registerAgent("my-agent", {
|
|
32
|
+
ensNode: "0x...",
|
|
33
|
+
agentAddress: "0x...",
|
|
34
|
+
spendLimit: "0.1",
|
|
35
|
+
allowedTargets: ["0x..."],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Submit an action through the firewall
|
|
39
|
+
const result = await enshell.submitAction(
|
|
40
|
+
"my-agent",
|
|
41
|
+
"0x...", // target
|
|
42
|
+
"0.05", // value in ETH
|
|
43
|
+
"0x", // calldata
|
|
44
|
+
"Send 0.05 ETH to treasury",
|
|
45
|
+
);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Development
|
|
49
|
+
|
|
50
|
+
### Build
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm run build
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Test
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm test
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Coverage
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm run test:coverage
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ENShellConfig, Agent, RegisterAgentOptions, ActionResult, QueuedAction } from "./types.js";
|
|
2
|
+
export declare class ENShell {
|
|
3
|
+
private contract;
|
|
4
|
+
private config;
|
|
5
|
+
constructor(config: ENShellConfig);
|
|
6
|
+
registerAgent(agentId: string, options: RegisterAgentOptions): Promise<void>;
|
|
7
|
+
getAgent(agentId: string): Promise<Agent>;
|
|
8
|
+
getAgentCount(): Promise<bigint>;
|
|
9
|
+
deactivateAgent(agentId: string): Promise<void>;
|
|
10
|
+
reactivateAgent(agentId: string): Promise<void>;
|
|
11
|
+
setAllowedTarget(agentId: string, target: string, allowed: boolean): Promise<void>;
|
|
12
|
+
isTargetAllowed(agentId: string, target: string): Promise<boolean>;
|
|
13
|
+
submitAction(agentId: string, target: string, value: string, data: string, instruction: string): Promise<ActionResult>;
|
|
14
|
+
approveAction(actionId: bigint): Promise<void>;
|
|
15
|
+
rejectAction(actionId: bigint): Promise<void>;
|
|
16
|
+
getQueuedAction(actionId: bigint): Promise<QueuedAction>;
|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AM,GAAG,OAAO,CAAC,YAAY,CAAC;CAa/D"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { parseEther } from "ethers";
|
|
2
|
+
import { getFirewallContract } from "./contract.js";
|
|
3
|
+
import { NETWORK_CONFIG } from "./networks.js";
|
|
4
|
+
import { ActionStatus } from "./types.js";
|
|
5
|
+
export class ENShell {
|
|
6
|
+
contract;
|
|
7
|
+
config;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
const address = config.contractAddress ??
|
|
11
|
+
NETWORK_CONFIG[config.network].firewallAddress;
|
|
12
|
+
if (!address) {
|
|
13
|
+
throw new Error(`No contract address configured for network ${config.network}`);
|
|
14
|
+
}
|
|
15
|
+
this.contract = getFirewallContract(address, config.signer);
|
|
16
|
+
}
|
|
17
|
+
// -- Agent Management --
|
|
18
|
+
async registerAgent(agentId, options) {
|
|
19
|
+
const tx = await this.contract.registerAgentSimple(agentId, options.ensNode, options.agentAddress, parseEther(options.spendLimit));
|
|
20
|
+
await tx.wait();
|
|
21
|
+
if (options.allowedTargets && options.allowedTargets.length > 0) {
|
|
22
|
+
const targetTx = await this.contract.setAllowedTargets(agentId, options.allowedTargets, true);
|
|
23
|
+
await targetTx.wait();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async getAgent(agentId) {
|
|
27
|
+
const raw = await this.contract.getAgent(agentId);
|
|
28
|
+
return {
|
|
29
|
+
ensNode: raw.ensNode,
|
|
30
|
+
agentAddress: raw.agentAddress,
|
|
31
|
+
spendLimit: raw.spendLimit,
|
|
32
|
+
threatScore: raw.threatScore,
|
|
33
|
+
strikes: raw.strikes,
|
|
34
|
+
active: raw.active,
|
|
35
|
+
worldIdVerified: raw.worldIdVerified,
|
|
36
|
+
registeredAt: raw.registeredAt,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async getAgentCount() {
|
|
40
|
+
return this.contract.getAgentCount();
|
|
41
|
+
}
|
|
42
|
+
async deactivateAgent(agentId) {
|
|
43
|
+
const tx = await this.contract.deactivateAgent(agentId);
|
|
44
|
+
await tx.wait();
|
|
45
|
+
}
|
|
46
|
+
async reactivateAgent(agentId) {
|
|
47
|
+
const tx = await this.contract.reactivateAgent(agentId);
|
|
48
|
+
await tx.wait();
|
|
49
|
+
}
|
|
50
|
+
// -- Target Permissions --
|
|
51
|
+
async setAllowedTarget(agentId, target, allowed) {
|
|
52
|
+
const tx = await this.contract.setAllowedTarget(agentId, target, allowed);
|
|
53
|
+
await tx.wait();
|
|
54
|
+
}
|
|
55
|
+
async isTargetAllowed(agentId, target) {
|
|
56
|
+
return this.contract.isTargetAllowed(agentId, target);
|
|
57
|
+
}
|
|
58
|
+
// -- Action Submission --
|
|
59
|
+
async submitAction(agentId, target, value, data, instruction) {
|
|
60
|
+
const tx = await this.contract.submitAction(agentId, target, parseEther(value), data, instruction);
|
|
61
|
+
const receipt = await tx.wait();
|
|
62
|
+
const iface = this.contract.interface;
|
|
63
|
+
for (const log of receipt.logs) {
|
|
64
|
+
try {
|
|
65
|
+
const parsed = iface.parseLog(log);
|
|
66
|
+
if (parsed?.name === "ActionApproved") {
|
|
67
|
+
return { actionId: parsed.args[0], status: ActionStatus.APPROVED };
|
|
68
|
+
}
|
|
69
|
+
if (parsed?.name === "ActionEscalated") {
|
|
70
|
+
return { actionId: parsed.args[0], status: ActionStatus.ESCALATED };
|
|
71
|
+
}
|
|
72
|
+
if (parsed?.name === "ActionBlocked") {
|
|
73
|
+
return { actionId: parsed.args[0], status: ActionStatus.BLOCKED };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Skip logs from other contracts
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
throw new Error("Could not determine action result from transaction logs");
|
|
81
|
+
}
|
|
82
|
+
// -- Ledger Approval --
|
|
83
|
+
async approveAction(actionId) {
|
|
84
|
+
const tx = await this.contract.approveAction(actionId);
|
|
85
|
+
await tx.wait();
|
|
86
|
+
}
|
|
87
|
+
async rejectAction(actionId) {
|
|
88
|
+
const tx = await this.contract.rejectAction(actionId);
|
|
89
|
+
await tx.wait();
|
|
90
|
+
}
|
|
91
|
+
async getQueuedAction(actionId) {
|
|
92
|
+
const raw = await this.contract.getQueuedAction(actionId);
|
|
93
|
+
return {
|
|
94
|
+
agentId: raw.agentId,
|
|
95
|
+
target: raw.target,
|
|
96
|
+
value: raw.value,
|
|
97
|
+
data: raw.data,
|
|
98
|
+
instruction: raw.instruction,
|
|
99
|
+
threatScore: raw.threatScore,
|
|
100
|
+
queuedAt: raw.queuedAt,
|
|
101
|
+
resolved: raw.resolved,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAQ/C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,OAAO,OAAO;IACV,QAAQ,CAAW;IACnB,MAAM,CAAgB;IAE9B,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,MAAM,OAAO,GACX,MAAM,CAAC,eAAe;YACtB,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC;QAEjD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACb,8CAA8C,MAAM,CAAC,OAAO,EAAE,CAC/D,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC;IA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AAE,GAAG,CAAC,WAAW;YAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Contract, type Signer, type Provider } from "ethers";
|
|
2
|
+
/**
|
|
3
|
+
* Human-readable ABI for AgentFirewall.
|
|
4
|
+
* Only includes functions currently deployed on-chain.
|
|
5
|
+
* Updated as new features are added to the contract.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AGENT_FIREWALL_ABI: readonly ["function registerAgentSimple(string agentId, bytes32 ensNode, address agentAddress, uint256 spendLimit) external", "function getAgent(string agentId) external view returns (tuple(bytes32 ensNode, address agentAddress, uint256 spendLimit, uint256 threatScore, uint256 strikes, bool active, bool worldIdVerified, uint256 registeredAt))", "function getAgentCount() external view returns (uint256)", "function deactivateAgent(string agentId) external", "function reactivateAgent(string agentId) external", "function setAllowedTarget(string agentId, address target, bool allowed) external", "function setAllowedTargets(string agentId, address[] targets, bool allowed) external", "function isTargetAllowed(string agentId, address target) external view returns (bool)", "function submitAction(string agentId, address target, uint256 value, bytes data, string instruction) external returns (uint256 actionId, uint8 status)", "function getQueuedAction(uint256 actionId) external view returns (tuple(string agentId, address target, uint256 value, bytes data, string instruction, uint256 threatScore, uint256 queuedAt, bool resolved))", "function approveAction(uint256 actionId) external", "function rejectAction(uint256 actionId) external", "function updateThreatScore(string agentId, uint256 rawScore) external", "function setMaxStrikes(uint256 _max) external", "event AgentRegistered(string indexed agentId, bytes32 ensNode, address agentAddress, uint256 spendLimit, bool worldIdVerified)", "event AgentDeactivated(string indexed agentId, string reason)", "event AllowedTargetUpdated(string indexed agentId, address target, bool allowed)", "event ActionSubmitted(uint256 indexed actionId, string indexed agentId, address target, uint256 value, string instruction)", "event ActionApproved(uint256 indexed actionId, string indexed agentId)", "event ActionBlocked(uint256 indexed actionId, string indexed agentId, string reason)", "event ActionEscalated(uint256 indexed actionId, string indexed agentId, uint256 threatScore)", "event ThreatScoreUpdated(string indexed agentId, uint256 previousScore, uint256 newScore, uint256 rawDetectionScore, uint256 strikes)"];
|
|
8
|
+
export declare function getFirewallContract(address: string, signerOrProvider: Signer | Provider): Contract;
|
|
9
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,qnEAsCrB,CAAC;AAEX,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,GAAG,QAAQ,GAClC,QAAQ,CAEV"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Contract } from "ethers";
|
|
2
|
+
/**
|
|
3
|
+
* Human-readable ABI for AgentFirewall.
|
|
4
|
+
* Only includes functions currently deployed on-chain.
|
|
5
|
+
* Updated as new features are added to the contract.
|
|
6
|
+
*/
|
|
7
|
+
export const AGENT_FIREWALL_ABI = [
|
|
8
|
+
// Agent registration
|
|
9
|
+
"function registerAgentSimple(string agentId, bytes32 ensNode, address agentAddress, uint256 spendLimit) external",
|
|
10
|
+
"function getAgent(string agentId) external view returns (tuple(bytes32 ensNode, address agentAddress, uint256 spendLimit, uint256 threatScore, uint256 strikes, bool active, bool worldIdVerified, uint256 registeredAt))",
|
|
11
|
+
"function getAgentCount() external view returns (uint256)",
|
|
12
|
+
// Agent lifecycle
|
|
13
|
+
"function deactivateAgent(string agentId) external",
|
|
14
|
+
"function reactivateAgent(string agentId) external",
|
|
15
|
+
// Allowed targets
|
|
16
|
+
"function setAllowedTarget(string agentId, address target, bool allowed) external",
|
|
17
|
+
"function setAllowedTargets(string agentId, address[] targets, bool allowed) external",
|
|
18
|
+
"function isTargetAllowed(string agentId, address target) external view returns (bool)",
|
|
19
|
+
// Action submission
|
|
20
|
+
"function submitAction(string agentId, address target, uint256 value, bytes data, string instruction) external returns (uint256 actionId, uint8 status)",
|
|
21
|
+
"function getQueuedAction(uint256 actionId) external view returns (tuple(string agentId, address target, uint256 value, bytes data, string instruction, uint256 threatScore, uint256 queuedAt, bool resolved))",
|
|
22
|
+
// Ledger approval
|
|
23
|
+
"function approveAction(uint256 actionId) external",
|
|
24
|
+
"function rejectAction(uint256 actionId) external",
|
|
25
|
+
// Threat scores
|
|
26
|
+
"function updateThreatScore(string agentId, uint256 rawScore) external",
|
|
27
|
+
// Admin
|
|
28
|
+
"function setMaxStrikes(uint256 _max) external",
|
|
29
|
+
// Events
|
|
30
|
+
"event AgentRegistered(string indexed agentId, bytes32 ensNode, address agentAddress, uint256 spendLimit, bool worldIdVerified)",
|
|
31
|
+
"event AgentDeactivated(string indexed agentId, string reason)",
|
|
32
|
+
"event AllowedTargetUpdated(string indexed agentId, address target, bool allowed)",
|
|
33
|
+
"event ActionSubmitted(uint256 indexed actionId, string indexed agentId, address target, uint256 value, string instruction)",
|
|
34
|
+
"event ActionApproved(uint256 indexed actionId, string indexed agentId)",
|
|
35
|
+
"event ActionBlocked(uint256 indexed actionId, string indexed agentId, string reason)",
|
|
36
|
+
"event ActionEscalated(uint256 indexed actionId, string indexed agentId, uint256 threatScore)",
|
|
37
|
+
"event ThreatScoreUpdated(string indexed agentId, uint256 previousScore, uint256 newScore, uint256 rawDetectionScore, uint256 strikes)",
|
|
38
|
+
];
|
|
39
|
+
export function getFirewallContract(address, signerOrProvider) {
|
|
40
|
+
return new Contract(address, AGENT_FIREWALL_ABI, signerOrProvider);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA8B,MAAM,QAAQ,CAAC;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,qBAAqB;IACrB,kHAAkH;IAClH,2NAA2N;IAC3N,0DAA0D;IAE1D,kBAAkB;IAClB,mDAAmD;IACnD,mDAAmD;IAEnD,kBAAkB;IAClB,kFAAkF;IAClF,sFAAsF;IACtF,uFAAuF;IAEvF,oBAAoB;IACpB,wJAAwJ;IACxJ,+MAA+M;IAE/M,kBAAkB;IAClB,mDAAmD;IACnD,kDAAkD;IAElD,gBAAgB;IAChB,uEAAuE;IAEvE,QAAQ;IACR,+CAA+C;IAE/C,SAAS;IACT,gIAAgI;IAChI,+DAA+D;IAC/D,kFAAkF;IAClF,4HAA4H;IAC5H,wEAAwE;IACxE,sFAAsF;IACtF,8FAA8F;IAC9F,uIAAuI;CAC/H,CAAC;AAEX,MAAM,UAAU,mBAAmB,CACjC,OAAe,EACf,gBAAmC;IAEnC,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,CAAC;AACrE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Network, NETWORK_CONFIG } from "./networks.js";
|
|
2
|
+
export type { NetworkConfig } from "./networks.js";
|
|
3
|
+
export { AGENT_FIREWALL_ABI, getFirewallContract } from "./contract.js";
|
|
4
|
+
export { ENShell } from "./client.js";
|
|
5
|
+
export { ActionStatus } from "./types.js";
|
|
6
|
+
export type { Agent, RegisterAgentOptions, ActionResult, QueuedAction, ProtectOptions, ENShellConfig, } from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,YAAY,EACV,KAAK,EACL,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare enum Network {
|
|
2
|
+
MAINNET = "mainnet",
|
|
3
|
+
SEPOLIA = "sepolia"
|
|
4
|
+
}
|
|
5
|
+
export interface NetworkConfig {
|
|
6
|
+
chainId: number;
|
|
7
|
+
rpcUrl: string;
|
|
8
|
+
firewallAddress: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const NETWORK_CONFIG: Record<Network, NetworkConfig>;
|
|
11
|
+
//# sourceMappingURL=networks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAAA,oBAAY,OAAO;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,OAAO,EAAE,aAAa,CAWzD,CAAC"}
|
package/dist/networks.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export var Network;
|
|
2
|
+
(function (Network) {
|
|
3
|
+
Network["MAINNET"] = "mainnet";
|
|
4
|
+
Network["SEPOLIA"] = "sepolia";
|
|
5
|
+
})(Network || (Network = {}));
|
|
6
|
+
export const NETWORK_CONFIG = {
|
|
7
|
+
[Network.MAINNET]: {
|
|
8
|
+
chainId: 1,
|
|
9
|
+
rpcUrl: "https://eth.llamarpc.com",
|
|
10
|
+
firewallAddress: "",
|
|
11
|
+
},
|
|
12
|
+
[Network.SEPOLIA]: {
|
|
13
|
+
chainId: 11155111,
|
|
14
|
+
rpcUrl: "https://rpc.sepolia.org",
|
|
15
|
+
firewallAddress: "",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=networks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.js","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,8BAAmB,CAAA;IACnB,8BAAmB,CAAA;AACrB,CAAC,EAHW,OAAO,KAAP,OAAO,QAGlB;AAQD,MAAM,CAAC,MAAM,cAAc,GAAmC;IAC5D,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QACjB,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,0BAA0B;QAClC,eAAe,EAAE,EAAE;KACpB;IACD,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QACjB,OAAO,EAAE,QAAQ;QACjB,MAAM,EAAE,yBAAyB;QACjC,eAAe,EAAE,EAAE;KACpB;CACF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Signer } from "ethers";
|
|
2
|
+
import type { Network } from "./networks.js";
|
|
3
|
+
export interface Agent {
|
|
4
|
+
ensNode: string;
|
|
5
|
+
agentAddress: string;
|
|
6
|
+
spendLimit: bigint;
|
|
7
|
+
threatScore: bigint;
|
|
8
|
+
strikes: bigint;
|
|
9
|
+
active: boolean;
|
|
10
|
+
worldIdVerified: boolean;
|
|
11
|
+
registeredAt: bigint;
|
|
12
|
+
}
|
|
13
|
+
export interface RegisterAgentOptions {
|
|
14
|
+
agentAddress: string;
|
|
15
|
+
spendLimit: string;
|
|
16
|
+
ensNode: string;
|
|
17
|
+
allowedTargets?: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare enum ActionStatus {
|
|
20
|
+
APPROVED = 0,
|
|
21
|
+
ESCALATED = 1,
|
|
22
|
+
BLOCKED = 2
|
|
23
|
+
}
|
|
24
|
+
export interface ActionResult {
|
|
25
|
+
actionId: bigint;
|
|
26
|
+
status: ActionStatus;
|
|
27
|
+
}
|
|
28
|
+
export interface QueuedAction {
|
|
29
|
+
agentId: string;
|
|
30
|
+
target: string;
|
|
31
|
+
value: bigint;
|
|
32
|
+
data: string;
|
|
33
|
+
instruction: string;
|
|
34
|
+
threatScore: bigint;
|
|
35
|
+
queuedAt: bigint;
|
|
36
|
+
resolved: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ProtectOptions {
|
|
39
|
+
tx: {
|
|
40
|
+
to: string;
|
|
41
|
+
value?: string;
|
|
42
|
+
data?: string;
|
|
43
|
+
};
|
|
44
|
+
prompt: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ENShellConfig {
|
|
47
|
+
network: Network;
|
|
48
|
+
signer: Signer;
|
|
49
|
+
contractAddress?: string;
|
|
50
|
+
onApproved?: (action: ActionResult) => Promise<void>;
|
|
51
|
+
onEscalated?: (action: ActionResult) => Promise<void>;
|
|
52
|
+
onBlocked?: (action: ActionResult) => Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -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M,EAAE,MAAM,CAAC;CAChB;AAID,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// -- Actions --
|
|
2
|
+
export var ActionStatus;
|
|
3
|
+
(function (ActionStatus) {
|
|
4
|
+
ActionStatus[ActionStatus["APPROVED"] = 0] = "APPROVED";
|
|
5
|
+
ActionStatus[ActionStatus["ESCALATED"] = 1] = "ESCALATED";
|
|
6
|
+
ActionStatus[ActionStatus["BLOCKED"] = 2] = "BLOCKED";
|
|
7
|
+
})(ActionStatus || (ActionStatus = {}));
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAuBA,gBAAgB;AAEhB,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,yDAAa,CAAA;IACb,qDAAW,CAAA;AACb,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enshell/sdk",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"test:coverage": "vitest run --coverage",
|
|
14
|
+
"clean": "rm -rf dist",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"ethers": "^6.15.0"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.18.11",
|
|
25
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
26
|
+
"typescript": "~5.8.0",
|
|
27
|
+
"vitest": "^4.1.2"
|
|
28
|
+
}
|
|
29
|
+
}
|