Skip to content

ecies/js

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

eciesjs

Codacy Badge License Npm Package CI Codecov

Elliptic Curve Integrated Encryption Scheme for secp256k1 in TypeScript.

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

If you want a WASM version to run directly in modern browsers or on some blockchains, check ecies-wasm.

Install

npm install eciesjs

Quick Start

Run the code below with npx ts-node.

> 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(receiverRawPK: string | Buffer, msg: Buffer): Buffer

Parameters:

  • receiverRawPK - Receiver's secp256k1 public key, hex string or buffer
  • msg - Data to encrypt

Returns: Buffer

decrypt(receiverRawSK: string | Buffer, msg: Buffer): Buffer

Parameters:

  • receiverRawSK - Receiver's secp256k1 private key, hex string or buffer
  • 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;

Release Notes

0.3.1 ~ 0.3.16

  • Support Node 18
  • Drop Node 10, 12 support
  • Bump dependencies
  • Update documentation
  • Extract constant variables and rename some parameters

0.3.0

  • API change: encrypt/decrypt now can take both hex string and Buffer

0.2.0

  • API change: use HKDF-sha256 to derive shared keys instead of sha256
  • Bump dependencies
  • Update documentation

0.1.1 ~ 0.1.5

  • Bump dependencies
  • Update documentation

0.1.0

  • First beta version release