getPublicKeyFromPrivateKey

Call Signature

function getPublicKeyFromPrivateKey(privateKey): Promise<CryptoKey>;

Given an extractable CryptoKey private key, gets the corresponding public key as a CryptoKey.

The public key is always extractable, since public keys are not secret. This mirrors the behavior of crypto.subtle.generateKey(), and is required by verifySignature, which reads the bytes of the public key.

Parameters

ParameterType
privateKeyCryptoKey

Returns

Promise<CryptoKey>

Example

import { createPrivateKeyFromBytes, getPublicKeyFromPrivateKey } from '@solana/keys';
 
const privateKey = await createPrivateKeyFromBytes(new Uint8Array([...]), true);
 
const publicKey = await getPublicKeyFromPrivateKey(privateKey);

Call Signature

function getPublicKeyFromPrivateKey(
    privateKey,
    extractable,
): Promise<CryptoKey>;

Parameters

ParameterTypeDescription
privateKeyCryptoKey-
extractablebooleanIgnored; the public key is always extractable.

Returns

Promise<CryptoKey>

Deprecated

The extractable argument is ignored; the public key is always extractable. Omit it.

On this page