From 6ed900133f98a9b6c35f967453b7ff6dbc82dc25 Mon Sep 17 00:00:00 2001 From: v1xingyue Date: Thu, 2 Jan 2025 22:01:35 +0800 Subject: [PATCH 1/2] plugin-sui support suiprivatekey private key --- packages/plugin-sui/src/actions/transfer.ts | 4 ++-- packages/plugin-sui/src/providers/wallet.ts | 4 ++-- packages/plugin-sui/src/tests/wallet.test.ts | 6 ++++++ packages/plugin-sui/src/utils.ts | 15 +++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 packages/plugin-sui/src/utils.ts diff --git a/packages/plugin-sui/src/actions/transfer.ts b/packages/plugin-sui/src/actions/transfer.ts index ab6d8f65ca9..721a27d5cf5 100644 --- a/packages/plugin-sui/src/actions/transfer.ts +++ b/packages/plugin-sui/src/actions/transfer.ts @@ -19,6 +19,7 @@ import { Transaction } from "@mysten/sui/transactions"; import { SUI_DECIMALS } from "@mysten/sui/utils"; import { walletProvider } from "../providers/wallet"; +import { parseAccount } from "../utils"; type SuiNetwork = "mainnet" | "testnet" | "devnet" | "localnet"; @@ -139,8 +140,7 @@ export default { } try { - const privateKey = runtime.getSetting("SUI_PRIVATE_KEY"); - const suiAccount = Ed25519Keypair.deriveKeypair(privateKey); + const suiAccount = parseAccount(runtime); const network = runtime.getSetting("SUI_NETWORK"); const suiClient = new SuiClient({ url: getFullnodeUrl(network as SuiNetwork), diff --git a/packages/plugin-sui/src/providers/wallet.ts b/packages/plugin-sui/src/providers/wallet.ts index 4ee649befbc..478fc2ce49c 100644 --- a/packages/plugin-sui/src/providers/wallet.ts +++ b/packages/plugin-sui/src/providers/wallet.ts @@ -13,6 +13,7 @@ import { MIST_PER_SUI } from "@mysten/sui/utils"; import BigNumber from "bignumber.js"; import NodeCache from "node-cache"; import * as path from "path"; +import { parseAccount } from "../utils"; // Provider configuration const PROVIDER_CONFIG = { @@ -220,8 +221,7 @@ const walletProvider: Provider = { _message: Memory, _state?: State ): Promise => { - const privateKey = runtime.getSetting("SUI_PRIVATE_KEY"); - const suiAccount = Ed25519Keypair.deriveKeypair(privateKey); + const suiAccount = parseAccount(runtime); try { const suiClient = new SuiClient({ diff --git a/packages/plugin-sui/src/tests/wallet.test.ts b/packages/plugin-sui/src/tests/wallet.test.ts index 39d3c62d4dc..df3372f57de 100644 --- a/packages/plugin-sui/src/tests/wallet.test.ts +++ b/packages/plugin-sui/src/tests/wallet.test.ts @@ -49,6 +49,12 @@ describe("WalletProvider", () => { "gaze throw also reveal kite load tennis tone club cloth chaos picture" ); + const suiAccountx = Ed25519Keypair.fromSecretKey( + "suiprivkey1qzuw2uvhqz330pwl94rv39jvk93kuvfd4pvdkw9vl922kum80prqvxtlntr" + ); + + console.log(suiAccountx.toSuiAddress()); + // Create new instance of TokenProvider with mocked dependencies walletProvider = new WalletProvider( suiClient, diff --git a/packages/plugin-sui/src/utils.ts b/packages/plugin-sui/src/utils.ts new file mode 100644 index 00000000000..4db8623eb1f --- /dev/null +++ b/packages/plugin-sui/src/utils.ts @@ -0,0 +1,15 @@ +import { IAgentRuntime } from "@elizaos/core"; +import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"; + +const parseAccount = (runtime: IAgentRuntime): Ed25519Keypair => { + const privateKey = runtime.getSetting("SUI_PRIVATE_KEY"); + if (!privateKey) { + throw new Error("SUI_PRIVATE_KEY is not set"); + } else if (privateKey.startsWith("suiprivkey")) { + return Ed25519Keypair.fromSecretKey(privateKey); + } else { + return Ed25519Keypair.deriveKeypairFromSeed(privateKey); + } +}; + +export { parseAccount }; From c0b105543ac51c8baa0c0d92fcaa00b7d64992ba Mon Sep 17 00:00:00 2001 From: v1xingyue Date: Thu, 2 Jan 2025 22:03:57 +0800 Subject: [PATCH 2/2] add parse cmdline --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index f54f552f6af..31a1304802e 100644 --- a/.env.example +++ b/.env.example @@ -341,7 +341,7 @@ AWS_S3_UPLOAD_PATH= DEEPGRAM_API_KEY= # Sui -SUI_PRIVATE_KEY= # Sui Mnemonic Seed Phrase (`sui keytool generate ed25519`) +SUI_PRIVATE_KEY= # Sui Mnemonic Seed Phrase (`sui keytool generate ed25519`) , Also support `suiprivatekeyxxxx` (sui keytool export --key-identity 0x63) SUI_NETWORK= # must be one of mainnet, testnet, devnet, localnet # Story