DefinitelyTyped/types/sic-ecies/sic-ecies-tests.ts
Methrat0n ee1a310306 Add @types for sic-ecies (#38460)
* write sic-ecies types

* use bitcore-lib PrivateKey and PublicKey and add the CBC constructor parameters. Also add readonly before all parameter arrays (they are not modified)

* test corrections, also remove readonly to keep lower ts version
2019-10-01 13:00:33 -07:00

24 lines
585 B
TypeScript

import { ECIES } from 'sic-ecies';
import { PrivateKey, PublicKey } from 'bitcore-lib';
const aliceKey = new PrivateKey();
const bobKey = new PrivateKey();
const alice = ECIES()
.privateKey(aliceKey)
.publicKey(bobKey.publicKey);
const message = 'some secret message';
const encrypted = alice.encrypt(message);
// encrypted will contain an encrypted buffer only Bob can decrypt
const bob = ECIES()
.privateKey(bobKey)
.publicKey(aliceKey.publicKey);
const decrypted = bob.decrypt(encrypted).toString();
// decrypted will be 'some secret message'
console.log(decrypted);