know-js
Version:
JavaScript library for sending Know transactions from the client or server
39 lines (29 loc) • 1.33 kB
JavaScript
var eccrypto = require("eccrypto");
var knowjs = require('../index');
var wif = require('wif')
var passphrase = "grocery divorce dove ginger glove corn myself narrow course income occur pill";
var privateKeyA = knowjs.crypto.getKeys(passphrase).toWIF();
privateKeyA = wif.decode(privateKeyA).privateKey;
var publicKeyA = eccrypto.getPublic(privateKeyA);
// var publicKeyA = Buffer('038f49917f167381c39be4340348a362fa700919cc7054ee255df7facc8942fa02');
// Encrypting the message for B.
eccrypto.encrypt(publicKeyA, Buffer("SEGmVnWiTYTmLhTtxzwdd3dvUdhcEYRHBtLikxDYBoW6hfEpGZpT")).then(function(encrypted) {
console.log(encrypted.ciphertext.toString('hex'));
var data = {
iv: encrypted.iv,
ephemPublicKey: encrypted.ephemPublicKey,
ciphertext: encrypted.ciphertext,
mac: encrypted.mac
};
// B decrypting the message.
eccrypto.decrypt(privateKeyA, data).then(function(plaintext) {
console.log("Message to part B:", plaintext.toString());
});
});
// eccrypto.encrypt(publicKeyA, Buffer("SEGmVnWiTYTmLhTtxzwdd3dvUdhcEYRHBtLikxDYBoW6hfEpGZpT")).then(function(encrypted) {
// console.log(encrypted);
// });
//
// eccrypto.decrypt(privateKeyA, '11576635').then(function(plaintext) {
// console.log("Message to part B:", plaintext.toString());
// });