Skip to content

Instantly share code, notes, and snippets.

@orthanc
Created November 18, 2024 08:03
Show Gist options
  • Save orthanc/d793ad00b2cb6ea2821623def22ba38d to your computer and use it in GitHub Desktop.
Save orthanc/d793ad00b2cb6ea2821623def22ba38d to your computer and use it in GitHub Desktop.
import {
createECDH,
} from 'node:crypto';
import { base58btc } from 'multiformats/bases/base58'
const ecdh = createECDH('prime256v1');
ecdh.generateKeys();
const curvePrefix = Buffer.from([0x80, 0x24]);
const compressedKey = ecdh.getPublicKey(undefined, 'compressed');
const compressedKeyWithPrefix = Buffer.concat([curvePrefix, compressedKey])
console.log(compressedKey);
console.log(compressedKeyWithPrefix);
console.log(base58btc.encode(compressedKeyWithPrefix))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment