npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coinfs

v0.1.2

Published

Store files in Bitcoin transactions

Downloads

9

Readme

CoinFS (coinfs)

CoinFS is a NodeJS library for storing files in Bitcoin transactions. File sizes up to 40960 bytes are supported. Both Bitcoin and Testnet networks are supported.

How it works

During encoding, the file is broken down into 20-byte chunks, each encoded as a Bitcoin address, and added as an output on the CoinFS transaction, with a value of 2730 satoshis. This is the current minimum output, or the 'dust threshold'. This value can also be specified with the options.dust property, if needed. Two more outputs are required, one for the metadata, and one for the change address.

Usage

The cost of a CoinFS transaction is roughly the sum of its outputs (N+1 20-byte chunks of data x 2730 satoshis) plus the transaction fee (50000 satoshis per 1000 bytes of transaction). The number of inputs is also contributing to the cost. Each adds about 9000 satoshis to the transaction size.

var coinfs = require('coinfs')

var options = {
  network: 'bitcoin', // [bitcoin|testnet]
  inputs: 1
}

coinfs.estimateCost('./file.txt', options, function(err, cost) {
  console.log(cost)
})

Knowing the number of inputs for the transaction is often not possible, so then you'll have to take a guess. Over-estimating it should not be a problem, since the excess funds will be sendt back to the change address.

Encoding

The encode() function creates a raw transaction. This is a hexadecimal string that can be pushed directly onto the Bitcoin network using software like Bitcoin Core, or an online service like Blockcyper. The inputs property in the options object takes an array of objects pointing to unspent outputs of earlier transactions.

var coinfs = require('coinfs')

var options = {
  network: 'bitcoin',                   // [bitcoin|testnet]
  inputs: [{
    hash: 'a5b8da60259ad3a800....',     // TX hash,
    index: 1,                           // Index of TX output
    amount: 50000000,            		// Satoshis in TX output,
    WIF: '5J115WhqnVmZuD1xe4jc1g...'    // Private key of output address
  }],
  additionalFee: 50000,                 // Optional
  changeAddress: '1E8cEJRy38LC4sv8P...' // Bitcoin address to send the change to
}

coinfs.encode('./file.txt', options, function(err, transaction) {
  console.log(transaction.toHex())
})

Decoding

The decode() function takes a raw transaction as input, and extracts the data to a buffer. The transaction must be one generated using the encode() function.

var coinfs = require('coinfs')

var options = {
  network: 'bitcoin' // [bitcoin|testnet]
}

coinfs.decode(rawTransaction, options, function (err, data) {
  console.log(data.toString())
})

You could retrieve raw transactions from https://blockchain.info by querying its transaction hash, like this: https://blockchain.info/tx/9021b49d445c719106c95d561b9c3fac7bcb3650db67684a9226cd7fa1e1c1a0?format=hex

WARNING!!! - Use this library at your own risk! You should always verify the raw transactions before pushing them onto the network. Funds sent to Bitcoin addresses generated by this library are lost!