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: Sui supports the secp256k1/secp256r1 algorithms #2476

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Changes from 1 commit
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
34 changes: 31 additions & 3 deletions packages/plugin-sui/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
import { IAgentRuntime } from "@elizaos/core";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { Secp256k1Keypair } from "@mysten/sui/keypairs/secp256k1";
import { Secp256r1Keypair } from "@mysten/sui/keypairs/secp256r1";

const parseAccount = (runtime: IAgentRuntime): Ed25519Keypair => {
const parseAccount = (
runtime: IAgentRuntime
): Ed25519Keypair | Secp256k1Keypair | Secp256r1Keypair => {
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);
return loadSecretKey(privateKey);
} else {
return Ed25519Keypair.deriveKeypairFromSeed(privateKey);
return loadFromMnemonics(privateKey);
}
};

const loadSecretKey = (privateKey: string) => {
try {
return Ed25519Keypair.fromSecretKey(privateKey);
} catch {
try {
return Secp256k1Keypair.fromSecretKey(privateKey);
} catch {
return Secp256r1Keypair.fromSecretKey(privateKey);
}
}
};
lispking marked this conversation as resolved.
Show resolved Hide resolved

const loadFromMnemonics = (mnemonics: string) => {
try {
return Ed25519Keypair.deriveKeypairFromSeed(mnemonics);
} catch {
try {
return Secp256k1Keypair.deriveKeypair(mnemonics);
} catch {
return Secp256r1Keypair.deriveKeypair(mnemonics);
}
lispking marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down
Loading