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: Plugin sui support for suiprivatekey0x account #1693

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
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 };
Loading