blockchainethereumsmart-contractssoliditytutorialdappweb3ethtruffleweb3jstransactionsigntransactionsignaturesign-datasignpublickeyprivatekeyethereum-identityencryptioncipher
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
703 B
18 lines
703 B
import { encrypt } from 'eccrypto';
|
|
import { decompress } from './public-key';
|
|
export function encryptWithPublicKey(publicKey, message, opts) {
|
|
// ensure its an uncompressed publicKey
|
|
publicKey = decompress(publicKey);
|
|
|
|
// re-add the compression-flag
|
|
var pubString = '04' + publicKey;
|
|
return encrypt(Buffer.from(pubString, 'hex'), Buffer.from(message), opts ? opts : {}).then(function (encryptedBuffers) {
|
|
var encrypted = {
|
|
iv: encryptedBuffers.iv.toString('hex'),
|
|
ephemPublicKey: encryptedBuffers.ephemPublicKey.toString('hex'),
|
|
ciphertext: encryptedBuffers.ciphertext.toString('hex'),
|
|
mac: encryptedBuffers.mac.toString('hex')
|
|
};
|
|
return encrypted;
|
|
});
|
|
} |