🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

bfp-encrypt

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bfp-encrypt

Node.js library to encrypt and decrypt data using the Bitcoin File Protocol on Bitcoin Cash

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

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. It uses the most recent UTXO in the sender's address and, if the UTXO amount is inadequate, will give an error saying the minimum satoshis necessary to send the data.

const BfpEncrypt = require('bfp-encrypt');

const senderWif = 'L2UzaFZxz6ATgo4zTiNXmR9ioHbtdcyhG89cLdSZGFwdMamDV14u'; // Address = bitcoincash:qpjvzz50gscheeh0fk6mnpr70zrf8lzccu2fu7lr3p
const recipientPublicKey = Buffer.from('02551b0063575007fe4e757f37cda5f03144d207bc19404ea1a37c1f1cceb12a3b', 'hex'); // Address = bitcoincash:qqcrlpjfkjwaep56c42fnlhj3uancz8wsgr36ajq2z
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'; // Address = bitcoincash:qqcrlpjfkjwaep56c42fnlhj3uancz8wsgr36ajq2z
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'));

})();

FAQs

Package last updated on 22 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts