Skip to content

Commit ae8fa57

Browse files
authored
Merge pull request #1693 from v1xingyue/plugin-sui-patch
feat: Plugin sui support for suiprivatekey0x account
2 parents 0d80c57 + 452a309 commit ae8fa57

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ AWS_S3_UPLOAD_PATH=
356356
DEEPGRAM_API_KEY=
357357

358358
# Sui
359-
SUI_PRIVATE_KEY= # Sui Mnemonic Seed Phrase (`sui keytool generate ed25519`)
359+
SUI_PRIVATE_KEY= # Sui Mnemonic Seed Phrase (`sui keytool generate ed25519`) , Also support `suiprivatekeyxxxx` (sui keytool export --key-identity 0x63)
360360
SUI_NETWORK= # must be one of mainnet, testnet, devnet, localnet
361361

362362
# Story

packages/plugin-sui/src/actions/transfer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Transaction } from "@mysten/sui/transactions";
1919
import { SUI_DECIMALS } from "@mysten/sui/utils";
2020

2121
import { walletProvider } from "../providers/wallet";
22+
import { parseAccount } from "../utils";
2223

2324
type SuiNetwork = "mainnet" | "testnet" | "devnet" | "localnet";
2425

@@ -139,8 +140,7 @@ export default {
139140
}
140141

141142
try {
142-
const privateKey = runtime.getSetting("SUI_PRIVATE_KEY");
143-
const suiAccount = Ed25519Keypair.deriveKeypair(privateKey);
143+
const suiAccount = parseAccount(runtime);
144144
const network = runtime.getSetting("SUI_NETWORK");
145145
const suiClient = new SuiClient({
146146
url: getFullnodeUrl(network as SuiNetwork),

packages/plugin-sui/src/providers/wallet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { MIST_PER_SUI } from "@mysten/sui/utils";
1313
import BigNumber from "bignumber.js";
1414
import NodeCache from "node-cache";
1515
import * as path from "path";
16+
import { parseAccount } from "../utils";
1617

1718
// Provider configuration
1819
const PROVIDER_CONFIG = {
@@ -220,8 +221,7 @@ const walletProvider: Provider = {
220221
_message: Memory,
221222
_state?: State
222223
): Promise<string | null> => {
223-
const privateKey = runtime.getSetting("SUI_PRIVATE_KEY");
224-
const suiAccount = Ed25519Keypair.deriveKeypair(privateKey);
224+
const suiAccount = parseAccount(runtime);
225225

226226
try {
227227
const suiClient = new SuiClient({

packages/plugin-sui/src/tests/wallet.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ describe("WalletProvider", () => {
4949
"gaze throw also reveal kite load tennis tone club cloth chaos picture"
5050
);
5151

52+
const suiAccountx = Ed25519Keypair.fromSecretKey(
53+
"suiprivkey1qzuw2uvhqz330pwl94rv39jvk93kuvfd4pvdkw9vl922kum80prqvxtlntr"
54+
);
55+
56+
console.log(suiAccountx.toSuiAddress());
57+
5258
// Create new instance of TokenProvider with mocked dependencies
5359
walletProvider = new WalletProvider(
5460
suiClient,

packages/plugin-sui/src/utils.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { IAgentRuntime } from "@elizaos/core";
2+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
3+
4+
const parseAccount = (runtime: IAgentRuntime): Ed25519Keypair => {
5+
const privateKey = runtime.getSetting("SUI_PRIVATE_KEY");
6+
if (!privateKey) {
7+
throw new Error("SUI_PRIVATE_KEY is not set");
8+
} else if (privateKey.startsWith("suiprivkey")) {
9+
return Ed25519Keypair.fromSecretKey(privateKey);
10+
} else {
11+
return Ed25519Keypair.deriveKeypairFromSeed(privateKey);
12+
}
13+
};
14+
15+
export { parseAccount };

0 commit comments

Comments
 (0)