JSPM

  • Created
  • Published
  • Downloads 2459833
  • Score
    100M100P100Q204252F
  • License MIT

Elliptic Curve Integrated Encryption Scheme for secp256k1

Package Exports

  • eciesjs

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 (eciesjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

eciesjs

Codacy Badge License Npm Package Circle CI Codecov

Elliptic Curve Integrated Encryption Scheme for secp256k1, written in TypeScript with minimal dependencies.

This is the JavaScript/TypeScript version of eciespy with a built-in class-like secp256k1 API, you may go there for detailed documentation of the mechanism under the hood.

Install

Install with npm install eciesjs

Quick Start

> import { encrypt, decrypt, PrivateKey } from 'eciesjs'
> const k1 = new PrivateKey()
> const data = Buffer.from('this is a test')
> decrypt(k1.toHex(), encrypt(k1.publicKey.toHex(), data)).toString()
'this is a test'

API

encrypt(receiverPubhex: string, msg: Buffer): Buffer

Parameters:

  • receiverPubhex - Receiver's secp256k1 public key hex string
  • msg - Data to encrypt

Returns: Buffer

decrypt(receiverPrvhex: string, msg: Buffer): Buffer

Parameters:

  • receiverPrvhex - Receiver's secp256k1 private key hex string
  • msg - Data to decrypt

Returns: Buffer

PrivateKey

  • Methods
static fromHex(hex: string): PrivateKey;
constructor(secret?: Buffer);
toHex(): string;
encapsulate(pub: PublicKey): Buffer;
multiply(pub: PublicKey): Buffer;
equals(other: PrivateKey): boolean;
  • Properties
readonly secret: Buffer;
readonly publicKey: PublicKey;

PublicKey

  • Methods
static fromHex(hex: string): PublicKey;
constructor(buffer: Buffer);
toHex(compressed?: boolean): string;
decapsulate(priv: PrivateKey): Buffer;
equals(other: PublicKey): boolean;
  • Properties
readonly uncompressed: Buffer;
readonly compressed: Buffer;