Skip to content

Provide a way to derive a public key from a private key? #406

Open
WICG/webcrypto-modern-algos
#17

Description

@twiss

In WICG/webcrypto-secure-curves#26, it was requested to provide a method to derive a public key from a private key for Ed25519, but this may be useful to provide a generic method for.

There is a workaround by exporting the private key as JWK, which typically also contains the public key material. However, this requires to then manually take the public key properties from the JWK (and which ones those are depends on the algorithm).

Perhaps it would be simpler to provide an explicit method for this; e.g. crypto.subtle.getPublicKey(privateKey)?

Alternatively, we could allow exporting public keys from private key objects, such that (in combination with #393) the following would be possible:

const privateKey = await crypto.subtle.importKey('raw-private', privateKeyMaterial, 'Ed25519', false, ['sign']);
const publicKeyMaterial = await crypto.subtle.exportKey('raw-public', privateKey);

(which would be more convenient if what you want is the public key material, but less convenient if you want a public key object).

Activity

  1. Frosne commented on Jul 7, 2025

    @Frosne
    Member

    I think providing an explicit method (getPublicKey) would improve the code readability. In order to use the importKey/exportKey trick you still need a bit of knowledge about how the keys are stored.

  2. panva commented on Jul 7, 2025

    @panva
    Member

    I think a getPublicKey method would be nice. Its argument is a private CryptoKey, its extractable slot is irrelevant, key_ops array as a second argument, and it resolves a public extractable CryptoKey with the same algorithm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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