JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 41709
  • Score
    100M100P100Q143749F
  • License MIT

Library for encoding and decoding ecdsa private keys between PEM, DER and raw hex formats

Package Exports

  • key-encoder

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (key-encoder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ECDSA Key Encoder and Decoder

Installation

$ npm install ecdsa-key-encoder

Getting Started

To get started, first define your key encoder and hex private/public keys:

var KeyEncoder = require('ecdsa-key-encoder').KeyEncoder,
    SECP256k1Parameters = require('ecdsa-key-encoder').SECP256k1Parameters

var keyEncoder = new KeyEncoder(SECP256k1Parameters),
    privateKeyHex = '844055cca13efd78ce79a4c3a4c5aba5db0ebeb7ae9d56906c03d333c5668d5b',
    publicKeyHex = '04147b79e9e1dd3324ceea115ff4037b6c877c73777131418bfb2b713effd0f502327b923861581bd5535eeae006765269f404f5f5c52214e9721b04aa7d040a75'

Note that the parameters for SECP256k1 ([1, 3, 132, 0, 10]) are already provided but you can pass your own in for any curve you'd like.

Encoding PEM Private Keys

var privateKeyPEM = keyEncoder.hexToPrivatePEM(privateKeyHex, publicKeyHex)

Note that including the public key hex is recommended but optional. Excluding it will result in a more compact PEM:

var privateKeyPEMCompact = keyEncoder.hexToPrivatePEM(privateKeyHex)

Decoding PEM Private Keys

var decodedPrivateKeyHex = keyEncoder.privatePEMToHex(privateKeyPEM)

Encoding PEM Public Keys

var publicKeyPEM = keyEncoder.hexToPublicPEM(publicKeyHex)

Decoding PEM Public Keys

var decodedPublicKeyHex = keyEncoder.publicPEMToHex(publicKeyPEM)