• Given a private key represented as a 32-byte Uint8Array, creates an Ed25519 public/private key pair for use with other methods in this package that accept CryptoKey objects.

    Parameters

    • bytes: ReadonlyUint8Array<ArrayBufferLike>

      32 bytes that represent the private key

    • Optionalextractable: boolean

      Setting this to true makes it possible to extract the bytes of the private key using the crypto.subtle.exportKey() API. Defaults to false.

    Returns Promise<CryptoKeyPair>

    import { createKeyPairFromPrivateKeyBytes } from '@solana/keys';

    const { privateKey, publicKey } = await createKeyPairFromPrivateKeyBytes(new Uint8Array([...]));

    This can be useful when you have a private key but not the corresponding public key or when you need to derive key pairs from seeds. For instance, the following code snippet derives a key pair from the hash of a message.

    import { getUtf8Encoder } from '@solana/codecs-strings';
    import { createKeyPairFromPrivateKeyBytes } from '@solana/keys';

    const message = getUtf8Encoder().encode('Hello, World!');
    const seed = new Uint8Array(await crypto.subtle.digest('SHA-256', message));

    const derivedKeypair = await createKeyPairFromPrivateKeyBytes(seed);