bfp-encrypt
Javascript library to encrypt and decrypt data and write that data to the Bitcoin Cash blockchain using the Bitcoin Files Protocol (BFP).
Uses Elliptic Curve Integrated Encryption Scheme (ECIES) and is compatible with the following Javascript libraries:
Installation
For node.js
npm install bfp-encrypt
Example Data / Message Send
Below is an example of sending a text message from one address (sender WIF) to the P2PKH address associated with the recipient's public key.
const BfpEncrypt = require('bfp-encrypt');
const senderWif = 'L2UzaFZxz6ATgo4zTiNXmR9ioHbtdcyhG89cLdSZGFwdMamDV14u';
const recipientPublicKey = Buffer.from('02551b0063575007fe4e757f37cda5f03144d207bc19404ea1a37c1f1cceb12a3b', 'hex');
const data = Buffer.from('You can put whatever kind of data or message you want right here as a buffer');
const fileName = 'EncryptedData';
const fileExt = '.txt';
(async function(){
try {
let bfpEnc = new BfpEncrypt();
let bfpUri = await bfpEnc.sendData(data, senderWif, recipientPublicKey, fileName, fileExt);
console.log('BFP File ID:', bfpUri);
} catch (e) {
console.error(e)
}
})();
Example Data / Message Receive
Below is an example of downloading and decrypting a text message sent to the recipient's address
const BfpEncrypt = require('bfp-encrypt');
const recipientWif = 'KwR6LVssEsTNV238wDCqhAbtvRquNWg8425AkujYDe5pRrMg1LjE';
const bfpUri = 'bitcoinfile:afe0cacba2635eb0696f353f31eabf01232695c092fc24f2da98eaf2ba355b87';
(async function(){
let bfpEnc = new BfpEncrypt();
let fileBuf = await bfpEnc.fetchEncryptedData(bfpUri, recipientWif);
console.log('Decrypted message:', fileBuf.toString('utf-8'));
})();