Ed25519 private key is 48 bytes, but sui.js expects 32 bytes

Hello, while watching workshop I got problem with keypair of ed25519. I’ve created new wallet, took private key, but when I try to extract address I get error. Here’s my code:

import {
    TransactionBlock,
    Ed25519Keypair,
    RawSigner,
    JsonRpcProvider,
    testnetConnection
} from "./node_modules/@mysten/sui.js";

dotenv.config();
const check = 1;
const secretKey = process.env.SECRET_KEY as string;
const keyPair = Ed25519Keypair.fromSecretKey(Buffer.from(secretKey, "base64"));

const provider = new JsonRpcProvider(testnetConnection);
const signer = new RawSigner(keyPair, provider);

async function main() {
    const sender = await signer.getAddress();
    console.log(sender);
    // const tx = new TransactionBlock();
    // tx.transferObjects()
}

And here’s my error:
C:\Users\admin\Desktop\sui_work\node_modules@mysten\sui.js\src\cryptography\ed25519-keypair.ts:86
throw new Error(
^
Error: Wrong secretKey size. Expected 32 bytes, got 48.
at Function.fromSecretKey (C:\Users\admin\Desktop\sui_work\node_modules@mysten\sui.js\src\cryptography\ed25519-keypair.ts:86:13)
at Object. (C:\Users\admin\Desktop\sui_work\simple-tx.ts:13:32)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module.m._compile (C:\Users\admin\AppData\Roaming\nvm\v18.13.0\node_modules\ts-node\src\index.ts:1618:23)
at Module._extensions…js (node:internal/modules/cjs/loader:1272:10)
at Object.require.extensions. [as .ts] (C:\Users\admin\AppData\Roaming\nvm\v18.13.0\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Function.Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at phase4 (C:\Users\admin\AppData\Roaming\nvm\v18.13.0\node_modules\ts-node\src\bin.ts:649:14)

4 Likes

Where did you get the process.env.SECRET_KEY from?

1 Like

I have .env file with my Private Key written. I use dotenv because of privacy.

1 Like
4 Likes

Well, there’s nothing that can help me, I did exactly what is written.
But I found the way, here’s link to that post but you’ll need to have wallet of “Sui Wallet”.

Here it is - Import existed account to SUI CLI

3 Likes

Ahh, had you stated that in your original question may have saved a few days to solution!

Glad you found what you are looking for.

4 Likes