Skip to content

Solana private keys use the 'array of numbers' format rather than base58. #6

@mikemaccana

Description

@mikemaccana

The Solana CLI uses the 'array of numbers' format for Solana private keys (eg. ~/.config/solana/id.json).

We should make svmPrivateKey either default to Array<Number> or let people specify Array<Number> | string and throw an error if their private key isn't decodable using either.

Workaround for short term:

import { readFile } from "node:fs/promises";
import { getBase58Decoder } from "@solana/codecs";

// Solana private keys usually use 'array of numbers'
// format, so convert to base58
const loadPrivateKeyAndConvertToBase58 = async (
  keyFilePath: string,
): Promise<string> => {
  const keyBytes = JSON.parse(
    await readFile(keyFilePath, "utf-8"),
  ) as Array<number>;
  return getBase58Decoder().decode(new Uint8Array(keyBytes));
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions