mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* 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
24 lines
585 B
TypeScript
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);
|