Ed25519Keypair expected 32 bytes, but got 0

Running into an issue when calling the getPublicKey() function on the Ed25519Keypair class in typescript. “Expected 32 bytes, but got 0”

I have logged out different methods to see there results. Here is my code:

const keyPair = new Ed25519Keypair(
    state.ephemeralKey.keypair as Ed25519KeypairData
  );
  console.log("keyPair: ", keyPair);
  console.log("pub: ", keyPair.getKeyScheme());
  console.log("pubkey: ", keyPair.getPublicKey());

Here are the following outputs:

keyPair:  Ed25519Keypair {
  keypair: {
    publicKey: {
      '0': 8,
      '1': 123,
      '2': 14,
      '3': 198,
      '4': 95,
      '5': 232,
      '6': 206,
      '7': 198,
      '8': 74,
      '9': 71,
      '10': 190,
      '11': 81,
      '12': 131,
      '13': 254,
      '14': 92,
      '15': 71,
      '16': 44,
      '17': 121,
      '18': 178,
      '19': 245,
      '20': 23,
      '21': 164,
      '22': 5,
      '23': 236,
      '24': 29,
      '25': 197,
      '26': 81,
      '27': 58,
      '28': 14,
      '29': 124,
      '30': 72,
      '31': 192
    },
    secretKey: {
      '0': 39,
      '1': 166,
      '2': 121,
      '3': 140,
      '4': 238,
      '5': 135,
      '6': 159,
      '7': 22,
      '8': 59,
      '9': 218,
      '10': 130,
      '11': 35,
      '12': 118,
      '13': 134,
      '14': 245,
      '15': 242,
      '16': 129,
      '17': 49,
      '18': 152,
      '19': 128,
      '20': 222,
      '21': 105,
      '22': 242,
      '23': 148,
      '24': 29,
      '25': 76,
      '26': 99,
      '27': 25,
      '28': 37,
      '29': 216,
      '30': 200,
      '31': 137,
      '32': 8,
      '33': 123,
      '34': 14,
      '35': 198,
      '36': 95,
      '37': 232,
      '38': 206,
      '39': 198,
      '40': 74,
      '41': 71,
      '42': 190,
      '43': 81,
      '44': 131,
      '45': 254,
      '46': 92,
      '47': 71,
      '48': 44,
      '49': 121,
      '50': 178,
      '51': 245,
      '52': 23,
      '53': 164,
      '54': 5,
      '55': 236,
      '56': 29,
      '57': 197,
      '58': 81,
      '59': 58,
      '60': 14,
      '61': 124,
      '62': 72,
      '63': 192
    }
  }
}

pub: ED25519

"errorType": "Error",
    "errorMessage": "Invalid public key input. Expected 32 bytes, got 0",
    "stack": [
        "Error: Invalid public key input. Expected 32 bytes, got 0",
        "    at new Ed25519PublicKey (file:///var/task/node_modules/@mysten/sui.js/dist/esm/keypairs/ed25519/publickey.js:22:13)",
        "    at Ed25519Keypair.getPublicKey (file:///var/task/node_modules/@mysten/sui.js/dist/esm/keypairs/ed25519/keypair.js:66:12)",
        "    at Runtime.handler (file:///var/task/index.js:54:37)",
        "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
    ]

I am unsure why I am receiving this error since the keyPair seems to have the correct information, and other methods on the object that is created also seem to be working (i.e. getKeyScheme()).

@rgundal2 The error does not occur when I hardcode the key pair you provided and run it in my environment. Can you try again with the same sui.js version as mine?

// @mysten/sui.js@0.51.0
import { Ed25519Keypair, type Ed25519KeypairData } from "@mysten/sui.js/keypairs/ed25519";

const keyPair = new Ed25519Keypair({
    publicKey: new Uint8Array([8, 123, 14, 198, 95, 232, 206, 198, 74, 71, 190, 81, 131, 254, 92, 71, 44, 121, 178, 245, 23, 164, 5, 236, 29, 197, 81, 58, 14, 124, 72, 192]),
    secretKey: new Uint8Array([39, 166, 121, 140, 238, 135, 159, 22, 59, 218, 130, 35, 118, 134, 245, 242, 129, 49, 152, 128, 222, 105, 242, 148, 29, 76, 99, 25, 37, 216, 200, 137, 8, 123, 14, 198, 95, 232, 206, 198, 74, 71, 190, 81, 131, 254, 92, 71, 44, 121, 178, 245, 23, 164, 5, 236, 29, 197, 81, 58, 14, 124, 72, 192]),
} as Ed25519KeypairData);
1 Like

Looks like I had to just make the parameters Uint8Arrays. Thank you!

1 Like