Skip to content

ecdh.setPublicKey is actually useful and should be undeprecated #18977

@skerit

Description

@skerit

So ecdh.setPublicKey has been deprecated since v5.2.0, but there is a certain use case where it is very useful: when you need to uncompress a compressed public key.

Here's how I would uncompress such a public key:

const crypto = require('crypto');

let ecdh = crypto.createECDH('secp256k1');
ecdh.generateKeys();

let private_key_compressed = ecdh.getPrivateKey(null, 'compressed');
let public_key_compressed = ecdh.getPublicKey(null, 'compressed');

// Public key is a buffer of 33 bytes
console.log('Compressed public key:', public_key_compressed.length, public_key_compressed);

// Create a new ecdh object
ecdh = crypto.createECDH('secp256k1')

// Use the compressed public key to set the public key
ecdh.setPublicKey(public_key_compressed);

// Get the uncompressed get
let public_key_uncompressed = ecdh.getPublicKey();

// The returned key is a buffer of 66 bytes long
console.log('Uncomrpessed public key:', public_key_uncompressed.length, public_key_uncompressed);

If ecdh.setPublicKey where to disappear I would require another library just for this simple task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++Issues and PRs that require attention from people who are familiar with C++.cryptoIssues and PRs related to the crypto subsystem.feature requestIssues that request new features to be added to Node.js.good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions