bitcoinfilesjs
bitcoinfilesjs is a JavaScript Library for building transactions for Bitcoin Files Protocol (BFP). Methods for uploading and downloading files are provided per the BFP specification. For convenience, BITBOX network functionality has been built into the library.
Other tools using the Bitcoin Files Protocol include:
Installation
For node.js
npm install bitcoinfiles
For browser
<script src='https://unpkg.com/bitcoinfiles'></script>
Example File Download
const Bfp = bfp;const bfp = ; // 1 - download file using URIlet result;{ result = await bfp; console;}; // Wait for download to complete -- Mario.png TAKES ABOUT 6 SEC TO DOWNLOAD! // 2 - result includes a boolean check telling you if the file's sha256 matches the file's metadata```ifresultpassesHashCheck console; // 3 - do something with the file...let fileBuffer = resultfileBuf;
Example File Upload
Below is a simple example. For a more complete React.js file upload example visit SimpleToken.cash website
const Bfp = bfp;const Network = network;const BITBOX = bitbox; const bfp = ;const network = ; // 1 - get a file and file metadata somehow const someFileBuffer = 'aabbccddeeff' 'hex';const fileName = 'a test file';const fileExt = 'txt';const fileSize = someFileBufferlengthconst fileSha256Hex = BITBOXCrypto; // 2 - estimate upload cost for funding the transactionlet config = msgType: 1 chunkCount: 1 fileName: fileName fileExt: fileExt fileSize: fileSize fileSha256Hex: fileSha256Hex prevFileSha256Hex: null fileUri: null chunkData: null // chunk not needed for cost estimate stage;let uploadCost = Bfp;console; // 3 - create a funding transactionlet fundingAddress = 'bitcoincash:qqgvrkm0xpmwqgyhfm65qxv70tjtwma6lgk07ffv9u'let fundingWif = 'KzcuA9xnDRrb9cPh29N7EQbBhQQLMWtcrDwKbEMoahmwBNACNRfa' // 4 - Make sure address above is funded with the amount equal to the uploadCostlet fundingUtxo; { let txo = await network; console}; // wait for network to resolve... // 5 - upload the filelet fileId;{ fileId = await bfp; console;}; // wait for upload to complete resolve... Done.
Get File Metadata
const bfp = ; let metadata;{ metadata = await bfpbitdb; console;} // metadata : // { filename: 'tes158',// fileext: '.json',// size: '017a',// sha256: '018321383bf2672befe28629d1e159af812260268a8aa77bbd4ec27489d65b58',// prev_sha256: '',// ext_uri: '' }