-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
+506
−0
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* | ||
|
||
!dist/** | ||
!package.json | ||
!readme.md | ||
!tsup.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import eslintGlobalConfig from "../../eslint.config.mjs"; | ||
|
||
export default [...eslintGlobalConfig]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
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
98
packages/plugin-goplus/src/services/GoplusSecurityService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ofADRESS_SECURITY_CHECK
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank u!