Kit
Functions

createKeyPairFromBytes

createKeyPairFromBytes(bytes, extractable?): Promise<CryptoKeyPair>

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

Parameters

ParameterTypeDescription
bytesReadonlyUint8Array64 bytes, the first 32 of which represent the private key and the last 32 of which represent its associated public key
extractable?booleanSetting 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>

Example

import fs from 'fs';
import { createKeyPairFromBytes } from '@solana/keys';
 
// Get bytes from local keypair file.
const keypairFile = fs.readFileSync('~/.config/solana/id.json');
const keypairBytes = new Uint8Array(JSON.parse(keypairFile.toString()));
 
// Create a CryptoKeyPair from the bytes.
const { privateKey, publicKey } = await createKeyPairFromBytes(keypairBytes);

On this page