Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add GoPlus Security Plugin to enhance security for agent #1898

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ export enum ServiceType {
AWS_S3 = "aws_s3",
BUTTPLUG = "buttplug",
SLACK = "slack",
GOPLUS_SECURITY = "goplus_security",
}

export enum LoggingLevel {
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-goplus/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
3 changes: 3 additions & 0 deletions packages/plugin-goplus/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [...eslintGlobalConfig];
21 changes: 21 additions & 0 deletions packages/plugin-goplus/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@elizaos/plugin-goplus",
"version": "0.1.7-alpha.2",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"tsup": "^8.3.5",
"ws": "^8.18.0"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsx watch src/index.ts",
"lint": "eslint --fix --cache ."
},
"devDependencies": {
"@types/ws": "^8.5.13",
"tsx": "^4.19.2"
}
}
17 changes: 17 additions & 0 deletions packages/plugin-goplus/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Plugin } from "@elizaos/core";
import GoplusSecurityService from "./services/GoplusSecurityService";

export * from "./services/GoplusSecurityService";


export const goplusPlugin: Plugin = {
name: "goplus",
description:
"goplus Plugin for Eliza - Enables WebSocket communication for AI-driven market insights",
actions: [],
evaluators: [],
providers: [],
services: [new GoplusSecurityService()],
};

export default goplusPlugin;
130 changes: 130 additions & 0 deletions packages/plugin-goplus/src/lib/GoPlusManage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@


export const GoPlusType = {
EVMTOKEN_SECURITY_CHECK: "EVMTOKEN_SECURITY_CHECK",
SOLTOKEN_SECURITY_CHECK: "SOLTOKEN_SECURITY_CHECK",
SUITOKEN_SECURITY_CHECK: "SUITOKEN_SECURITY_CHECK",
RUGPULL_SECURITY_CHECK: "RUGPULL_SECURITY_CHECK",
NFT_SECURITY_CHECK: "NFT_SECURITY_CHECK",
ADRESS_SECURITY_CHECK: "ADRESS_SECURITY_CHECK",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think this one should be ADDRESS_SECURITY_CHECK instead of ADRESS_SECURITY_CHECK?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank u!

APPROVAL_SECURITY_CHECK: "APPROVAL_SECURITY_CHECK",
ACCOUNT_ERC20_SECURITY_CHECK: "ACCOUNT_ERC20_SECURITY_CHECK",
ACCOUNT_ERC721_SECURITY_CHECK: "ACCOUNT_ERC721_SECURITY_CHECK",
ACCOUNT_ERC1155_SECURITY_CHECK: "ACCOUNT_ERC1155_SECURITY_CHECK",
SIGNATURE_SECURITY_CHECK: "SIGNATURE_SECURITY_CHECK",
URL_SECURITY_CHECK: "URL_SECURITY_CHECK",
}

export type GoPlusType = (typeof GoPlusType)[keyof typeof GoPlusType]

export type GoPlusParamType = {
"type": GoPlusType,
"network"?: string,
"token"?: string,
"contract"?: string,
"wallet"?: string,
"url"?: string,
"data"?: string,
}

export class GoPlusManage {
private apiKey: string;

constructor(apiKey: string = null) {
this.apiKey = apiKey;
}

async requestGet(api: string) {
const myHeaders = new Headers();
if (this.apiKey) {
myHeaders.append("Authorization", this.apiKey);
}
const url = `https://api.gopluslabs.io/${api}`
const res = await fetch(url, {
method: "GET",
headers: myHeaders,
redirect: "follow"
})

return await res.json();
}

async tokenSecurity(chainId: string, address: string) {
const api = `api/v1/token_security/${chainId}?contract_addresses=${address}`;
return await this.requestGet(api)
}

async rugpullDetection(chainId: string, address: string) {
const api = `api/v1/rugpull_detecting/${chainId}?contract_addresses=${address}`;
return await this.requestGet(api)
}

async solanaTokenSecurityUsingGET(address: string) {
const api = `api/v1/solana/token_security?contract_addresses=${address}`;
return await this.requestGet(api)
}

async suiTokenSecurityUsingGET(address: string) {
const api = `api/v1/sui/token_security?contract_addresses=${address}`;
return await this.requestGet(api)
}

async nftSecurity(chainId: string, address: string) {
const api = `api/v1/nft_security/${chainId}?contract_addresses=${address}`;
return await this.requestGet(api)
}

async addressSecurity(address: string) {
const api = `api/v1/address_security/${address}`;
return await this.requestGet(api)
}

async approvalSecurity(chainId: string, contract: string) {
const api = `api/v1/approval_security/${chainId}?contract_addresses=${contract}`;
return await this.requestGet(api)
}

async erc20ApprovalSecurity(chainId: string, wallet: string) {
const api = `api/v2/token_approval_security/${chainId}?addresses=${wallet}`;
return await this.requestGet(api)
}

async erc721ApprovalSecurity(chainId: string, wallet: string) {
const api = `api/v2/nft721_approval_security/${chainId}?addresses=${wallet}`;
return await this.requestGet(api)
}

async erc1155ApprovalSecurity(chainId: string, wallet: string) {
const api = `api/v2/nft1155_approval_security/${chainId}?addresses=${wallet}`;
return await this.requestGet(api)
}

async inputDecode(chainId: string, data: string) {
const body = JSON.stringify({
chain_id: chainId,
data: data,
})
const res = await fetch("https://api.gopluslabs.io/api/v1/abi/input_decode", {
"headers": {
"accept": "*/*",
"accept-language": "en,zh-CN;q=0.9,zh;q=0.8",
"content-type": "application/json"
},
"body": body,
"method": "POST"
});
return await res.json();
}

async dappSecurityAndPhishingSite(url: string) {
const api = `api/v1/dapp_security?url=${url}`;
const data1 = await this.requestGet(api)

const api2 = `api/v1/phishing_site?url=${url}`;
const data2 = await this.requestGet(api2)
return {
data1,
data2
}
}
}
98 changes: 98 additions & 0 deletions packages/plugin-goplus/src/services/GoplusSecurityService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { IAgentRuntime, ModelClass, Service, ServiceType, elizaLogger, generateObjectDeprecated, generateText } from "@elizaos/core";
import { GoPlusManage, GoPlusParamType, GoPlusType } from "../lib/GoPlusManage";
import { requestPrompt, responsePrompt } from "../templates";

export interface IGoplusSecurityService extends Service {
check(text: string): Promise<string>;
}

export class GoplusSecurityService extends Service implements IGoplusSecurityService {
private apiKey: string;
private runtime: IAgentRuntime;
getInstance(): GoplusSecurityService {
return this;
}
static get serviceType() {
return ServiceType.GOPLUS_SECURITY;
}

initialize(runtime: IAgentRuntime): Promise<void> {
this.runtime = runtime;
this.apiKey = runtime.getSetting("GOPLUS_API_KEY");
return;
}


/**
* Connect to WebSocket and send a message
*/
async check(text: string): Promise<string> {
try {
elizaLogger.log("check input text", text);
const obj = await generateObjectDeprecated({
runtime: this.runtime,
context: requestPrompt(text),
modelClass: ModelClass.SMALL, // gpt-4o-mini
}) as GoPlusParamType;

elizaLogger.log("check generateObjectDeprecated text", obj);

const goPlusManage = new GoPlusManage(this.apiKey)
let checkResult: any;
switch(obj.type) {
case GoPlusType.EVMTOKEN_SECURITY_CHECK:
checkResult = await goPlusManage.tokenSecurity(obj.network, obj.token);
break;
case GoPlusType.SOLTOKEN_SECURITY_CHECK:
checkResult = await goPlusManage.solanaTokenSecurityUsingGET(obj.token);
break;
case GoPlusType.SUITOKEN_SECURITY_CHECK:
checkResult = await goPlusManage.suiTokenSecurityUsingGET(obj.token);
break;
case GoPlusType.RUGPULL_SECURITY_CHECK:
checkResult = await goPlusManage.rugpullDetection(obj.network, obj.contract);
break;
case GoPlusType.NFT_SECURITY_CHECK:
checkResult = await goPlusManage.nftSecurity(obj.network, obj.token);
break;
case GoPlusType.ADRESS_SECURITY_CHECK:
checkResult = await goPlusManage.addressSecurity(obj.wallet);
break;
case GoPlusType.APPROVAL_SECURITY_CHECK:
checkResult = await goPlusManage.approvalSecurity(obj.network, obj.contract);
break;
case GoPlusType.ACCOUNT_ERC20_SECURITY_CHECK:
checkResult = await goPlusManage.erc20ApprovalSecurity(obj.network, obj.wallet);
break;
case GoPlusType.ACCOUNT_ERC721_SECURITY_CHECK:
checkResult = await goPlusManage.erc721ApprovalSecurity(obj.network, obj.wallet);
break;
case GoPlusType.ACCOUNT_ERC1155_SECURITY_CHECK:
checkResult = await goPlusManage.erc1155ApprovalSecurity(obj.network, obj.wallet);
break;
case GoPlusType.SIGNATURE_SECURITY_CHECK:
checkResult = await goPlusManage.inputDecode(obj.network, obj.data);
break;
case GoPlusType.URL_SECURITY_CHECK:
checkResult = await goPlusManage.dappSecurityAndPhishingSite(obj.url);
break;
default:
throw new Error("type is invaild")
}

elizaLogger.log("checkResult text", checkResult);
const checkResponse = await generateText({
runtime: this.runtime,
context: responsePrompt(JSON.stringify(checkResult), text),
modelClass: ModelClass.SMALL,
});
elizaLogger.log("checkResponse text", checkResponse);
return checkResponse
} catch (e) {
elizaLogger.error(e);
return "error";
}
}
}

export default GoplusSecurityService;
Loading
Loading