Skip to content

Commit

Permalink
Merge pull request elizaOS#1693 from v1xingyue/plugin-sui-patch
Browse files Browse the repository at this point in the history
feat: Plugin sui support for suiprivatekey0x account
  • Loading branch information
shakkernerd authored Jan 2, 2025
2 parents 0d80c57 + 452a309 commit ae8fa57
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,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
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-sui/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-sui/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -220,8 +221,7 @@ const walletProvider: Provider = {
_message: Memory,
_state?: State
): Promise<string | null> => {
const privateKey = runtime.getSetting("SUI_PRIVATE_KEY");
const suiAccount = Ed25519Keypair.deriveKeypair(privateKey);
const suiAccount = parseAccount(runtime);

try {
const suiClient = new SuiClient({
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-sui/src/tests/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-sui/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit ae8fa57

Please sign in to comment.