Skip to content

Commit 2a8386d

Browse files
authored
Merge pull request #13 from 0xbeekeeper/goplus-security
feat: add GoPlus Security Plugin to enhance security for agent
2 parents 6c388cd + daed957 commit 2a8386d

File tree

10 files changed

+506
-0
lines changed

10 files changed

+506
-0
lines changed

packages/core/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ export enum ServiceType {
12951295
AWS_S3 = "aws_s3",
12961296
BUTTPLUG = "buttplug",
12971297
SLACK = "slack",
1298+
GOPLUS_SECURITY = "goplus_security",
12981299
}
12991300

13001301
export enum LoggingLevel {

packages/plugin-goplus/.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
3+
!dist/**
4+
!package.json
5+
!readme.md
6+
!tsup.config.ts
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.config.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/plugin-goplus/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@elizaos/plugin-goplus",
3+
"version": "0.1.7-alpha.2",
4+
"main": "dist/index.js",
5+
"type": "module",
6+
"types": "dist/index.d.ts",
7+
"dependencies": {
8+
"@elizaos/core": "workspace:*",
9+
"tsup": "^8.3.5",
10+
"ws": "^8.18.0"
11+
},
12+
"scripts": {
13+
"build": "tsup --format esm --dts",
14+
"dev": "tsx watch src/index.ts",
15+
"lint": "eslint --fix --cache ."
16+
},
17+
"devDependencies": {
18+
"@types/ws": "^8.5.13",
19+
"tsx": "^4.19.2"
20+
}
21+
}

packages/plugin-goplus/src/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Plugin } from "@elizaos/core";
2+
import GoplusSecurityService from "./services/GoplusSecurityService";
3+
4+
export * from "./services/GoplusSecurityService";
5+
6+
7+
export const goplusPlugin: Plugin = {
8+
name: "goplus",
9+
description:
10+
"goplus Plugin for Eliza - Enables WebSocket communication for AI-driven market insights",
11+
actions: [],
12+
evaluators: [],
13+
providers: [],
14+
services: [new GoplusSecurityService()],
15+
};
16+
17+
export default goplusPlugin;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
3+
export const GoPlusType = {
4+
EVMTOKEN_SECURITY_CHECK: "EVMTOKEN_SECURITY_CHECK",
5+
SOLTOKEN_SECURITY_CHECK: "SOLTOKEN_SECURITY_CHECK",
6+
SUITOKEN_SECURITY_CHECK: "SUITOKEN_SECURITY_CHECK",
7+
RUGPULL_SECURITY_CHECK: "RUGPULL_SECURITY_CHECK",
8+
NFT_SECURITY_CHECK: "NFT_SECURITY_CHECK",
9+
ADRESS_SECURITY_CHECK: "ADRESS_SECURITY_CHECK",
10+
APPROVAL_SECURITY_CHECK: "APPROVAL_SECURITY_CHECK",
11+
ACCOUNT_ERC20_SECURITY_CHECK: "ACCOUNT_ERC20_SECURITY_CHECK",
12+
ACCOUNT_ERC721_SECURITY_CHECK: "ACCOUNT_ERC721_SECURITY_CHECK",
13+
ACCOUNT_ERC1155_SECURITY_CHECK: "ACCOUNT_ERC1155_SECURITY_CHECK",
14+
SIGNATURE_SECURITY_CHECK: "SIGNATURE_SECURITY_CHECK",
15+
URL_SECURITY_CHECK: "URL_SECURITY_CHECK",
16+
}
17+
18+
export type GoPlusType = (typeof GoPlusType)[keyof typeof GoPlusType]
19+
20+
export type GoPlusParamType = {
21+
"type": GoPlusType,
22+
"network"?: string,
23+
"token"?: string,
24+
"contract"?: string,
25+
"wallet"?: string,
26+
"url"?: string,
27+
"data"?: string,
28+
}
29+
30+
export class GoPlusManage {
31+
private apiKey: string;
32+
33+
constructor(apiKey: string = null) {
34+
this.apiKey = apiKey;
35+
}
36+
37+
async requestGet(api: string) {
38+
const myHeaders = new Headers();
39+
if (this.apiKey) {
40+
myHeaders.append("Authorization", this.apiKey);
41+
}
42+
const url = `https://api.gopluslabs.io/${api}`
43+
const res = await fetch(url, {
44+
method: "GET",
45+
headers: myHeaders,
46+
redirect: "follow"
47+
})
48+
49+
return await res.json();
50+
}
51+
52+
async tokenSecurity(chainId: string, address: string) {
53+
const api = `api/v1/token_security/${chainId}?contract_addresses=${address}`;
54+
return await this.requestGet(api)
55+
}
56+
57+
async rugpullDetection(chainId: string, address: string) {
58+
const api = `api/v1/rugpull_detecting/${chainId}?contract_addresses=${address}`;
59+
return await this.requestGet(api)
60+
}
61+
62+
async solanaTokenSecurityUsingGET(address: string) {
63+
const api = `api/v1/solana/token_security?contract_addresses=${address}`;
64+
return await this.requestGet(api)
65+
}
66+
67+
async suiTokenSecurityUsingGET(address: string) {
68+
const api = `api/v1/sui/token_security?contract_addresses=${address}`;
69+
return await this.requestGet(api)
70+
}
71+
72+
async nftSecurity(chainId: string, address: string) {
73+
const api = `api/v1/nft_security/${chainId}?contract_addresses=${address}`;
74+
return await this.requestGet(api)
75+
}
76+
77+
async addressSecurity(address: string) {
78+
const api = `api/v1/address_security/${address}`;
79+
return await this.requestGet(api)
80+
}
81+
82+
async approvalSecurity(chainId: string, contract: string) {
83+
const api = `api/v1/approval_security/${chainId}?contract_addresses=${contract}`;
84+
return await this.requestGet(api)
85+
}
86+
87+
async erc20ApprovalSecurity(chainId: string, wallet: string) {
88+
const api = `api/v2/token_approval_security/${chainId}?addresses=${wallet}`;
89+
return await this.requestGet(api)
90+
}
91+
92+
async erc721ApprovalSecurity(chainId: string, wallet: string) {
93+
const api = `api/v2/nft721_approval_security/${chainId}?addresses=${wallet}`;
94+
return await this.requestGet(api)
95+
}
96+
97+
async erc1155ApprovalSecurity(chainId: string, wallet: string) {
98+
const api = `api/v2/nft1155_approval_security/${chainId}?addresses=${wallet}`;
99+
return await this.requestGet(api)
100+
}
101+
102+
async inputDecode(chainId: string, data: string) {
103+
const body = JSON.stringify({
104+
chain_id: chainId,
105+
data: data,
106+
})
107+
const res = await fetch("https://api.gopluslabs.io/api/v1/abi/input_decode", {
108+
"headers": {
109+
"accept": "*/*",
110+
"accept-language": "en,zh-CN;q=0.9,zh;q=0.8",
111+
"content-type": "application/json"
112+
},
113+
"body": body,
114+
"method": "POST"
115+
});
116+
return await res.json();
117+
}
118+
119+
async dappSecurityAndPhishingSite(url: string) {
120+
const api = `api/v1/dapp_security?url=${url}`;
121+
const data1 = await this.requestGet(api)
122+
123+
const api2 = `api/v1/phishing_site?url=${url}`;
124+
const data2 = await this.requestGet(api2)
125+
return {
126+
data1,
127+
data2
128+
}
129+
}
130+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { IAgentRuntime, ModelClass, Service, ServiceType, elizaLogger, generateObjectDeprecated, generateText } from "@elizaos/core";
2+
import { GoPlusManage, GoPlusParamType, GoPlusType } from "../lib/GoPlusManage";
3+
import { requestPrompt, responsePrompt } from "../templates";
4+
5+
export interface IGoplusSecurityService extends Service {
6+
check(text: string): Promise<string>;
7+
}
8+
9+
export class GoplusSecurityService extends Service implements IGoplusSecurityService {
10+
private apiKey: string;
11+
private runtime: IAgentRuntime;
12+
getInstance(): GoplusSecurityService {
13+
return this;
14+
}
15+
static get serviceType() {
16+
return ServiceType.GOPLUS_SECURITY;
17+
}
18+
19+
initialize(runtime: IAgentRuntime): Promise<void> {
20+
this.runtime = runtime;
21+
this.apiKey = runtime.getSetting("GOPLUS_API_KEY");
22+
return;
23+
}
24+
25+
26+
/**
27+
* Connect to WebSocket and send a message
28+
*/
29+
async check(text: string): Promise<string> {
30+
try {
31+
elizaLogger.log("check input text", text);
32+
const obj = await generateObjectDeprecated({
33+
runtime: this.runtime,
34+
context: requestPrompt(text),
35+
modelClass: ModelClass.SMALL, // gpt-4o-mini
36+
}) as GoPlusParamType;
37+
38+
elizaLogger.log("check generateObjectDeprecated text", obj);
39+
40+
const goPlusManage = new GoPlusManage(this.apiKey)
41+
let checkResult: any;
42+
switch(obj.type) {
43+
case GoPlusType.EVMTOKEN_SECURITY_CHECK:
44+
checkResult = await goPlusManage.tokenSecurity(obj.network, obj.token);
45+
break;
46+
case GoPlusType.SOLTOKEN_SECURITY_CHECK:
47+
checkResult = await goPlusManage.solanaTokenSecurityUsingGET(obj.token);
48+
break;
49+
case GoPlusType.SUITOKEN_SECURITY_CHECK:
50+
checkResult = await goPlusManage.suiTokenSecurityUsingGET(obj.token);
51+
break;
52+
case GoPlusType.RUGPULL_SECURITY_CHECK:
53+
checkResult = await goPlusManage.rugpullDetection(obj.network, obj.contract);
54+
break;
55+
case GoPlusType.NFT_SECURITY_CHECK:
56+
checkResult = await goPlusManage.nftSecurity(obj.network, obj.token);
57+
break;
58+
case GoPlusType.ADRESS_SECURITY_CHECK:
59+
checkResult = await goPlusManage.addressSecurity(obj.wallet);
60+
break;
61+
case GoPlusType.APPROVAL_SECURITY_CHECK:
62+
checkResult = await goPlusManage.approvalSecurity(obj.network, obj.contract);
63+
break;
64+
case GoPlusType.ACCOUNT_ERC20_SECURITY_CHECK:
65+
checkResult = await goPlusManage.erc20ApprovalSecurity(obj.network, obj.wallet);
66+
break;
67+
case GoPlusType.ACCOUNT_ERC721_SECURITY_CHECK:
68+
checkResult = await goPlusManage.erc721ApprovalSecurity(obj.network, obj.wallet);
69+
break;
70+
case GoPlusType.ACCOUNT_ERC1155_SECURITY_CHECK:
71+
checkResult = await goPlusManage.erc1155ApprovalSecurity(obj.network, obj.wallet);
72+
break;
73+
case GoPlusType.SIGNATURE_SECURITY_CHECK:
74+
checkResult = await goPlusManage.inputDecode(obj.network, obj.data);
75+
break;
76+
case GoPlusType.URL_SECURITY_CHECK:
77+
checkResult = await goPlusManage.dappSecurityAndPhishingSite(obj.url);
78+
break;
79+
default:
80+
throw new Error("type is invaild")
81+
}
82+
83+
elizaLogger.log("checkResult text", checkResult);
84+
const checkResponse = await generateText({
85+
runtime: this.runtime,
86+
context: responsePrompt(JSON.stringify(checkResult), text),
87+
modelClass: ModelClass.SMALL,
88+
});
89+
elizaLogger.log("checkResponse text", checkResponse);
90+
return checkResponse
91+
} catch (e) {
92+
elizaLogger.error(e);
93+
return "error";
94+
}
95+
}
96+
}
97+
98+
export default GoplusSecurityService;

0 commit comments

Comments
 (0)