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
Elliptic Curve Integrated Encryption Scheme for secp256k1
This is the JavaScript version of eciespy, please go to there for detailed mechanism documentation.
Install
Install with npm install eciesjs (only secp256k1 is the dependency).
Quick Start
> import { encrypt, decrypt, PrivateKey, utils } 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'
> utils.sha256(Buffer.from('0')).slice(0, 8)
<Buffer 5f ec eb 66 ff c8 6f 38>
> const k2 = new PrivateKey()
> k1.ecdh(k2.publicKey).equals(k2.ecdh(k1.publicKey))
trueAPI
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
static fromHex(hex: string): PrivateKey;
readonly secret: Buffer;
readonly publicKey: PublicKey;
constructor(secret?: Buffer);
toHex(): string;
ecdh(pub: PublicKey): Buffer;
equals(other: PrivateKey): boolean;PublicKey
static fromHex(hex: string): PublicKey;
readonly uncompressed: Buffer;
readonly compressed: Buffer;
constructor(buffer: Buffer);
toHex(compressed?: boolean): string;
equals(other: PublicKey): boolean;