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

coindjs-protocol

v0.0.1

Published

Parse and generate binary messages and formats for bitcoin-based systems.

Downloads

6

Readme

CoinDJs - Protocol

This is the protocol component of CoinDJs, a bitcoin (namecoin and ilk) full node and library.

This includes the necessary libraries to serialize and deserialize the binary format to send over the wire.

Install

npm install coindjs-protocol

Build a Message

This is the method bitcoind uses today, which operates against a list of trusted DNS seeds included in the bitcoind source code.

var timestamp = (new Date()).getTime();
var versionMessage = new protocol.messages.version({
    version: 1,
    services: 1,
    timestamp: timestamp,
    addr_recv: {
        timestamp: timestamp,
        services: 1,
        address: '127.0.0.1',
        port: 8883
    },
    addr_from: {
        timestamp: timestamp,
        services: 1,
        address: '127.0.0.1',
        port: 8883
    },
    nonce: (new Buffer('0123456789abcdef', 'hex')),
    user_agent: "SomeAgent/0.9",
    start_height: 100000
});

// When we create the message, we specify the magic number to put in the header
var bitcoinMagicNumber = new Buffer('f9beb4d9', 'hex');
console.log(versionMessage.toBinary(bitcoinMagicNumber).toString('hex'))

Parse a Binary Message

var getblocksMessage = new Buffer('f9beb4d9676574626c6f636b73000000650000001801d1880200000002333433343334333433343334333433343334333433343334333433343334333434353435343534353435343534353435343534353435343534353435343534353132313231323132313231323132313231323132313231323132313231323132', 'hex');
console.log(protocol.messageFromBinary(getblocksMessage, protocol.messages))

Converting a Message from Binary

var pingHex = new Buffer('3132333470696e6700000000000000000800000070912a883031323334353637', 'hex');
console.log(protocol.messages.ping.fromBinary(pingHex));

Defining a Custom Format

As a quick example of using the format primitives to define a new message definition, here is the format to read the raw blocks from the blk????.dat files from the bitcoind datadir:

var BlockMessage = new format.FormatCompound([
    ['version', format.UInt32],
    ['prev_block', format.Bytes32],
    ['merkle_root', format.Bytes32],
    ['timestamp', format.UInt32],
    ['bits', format.UInt32],
    ['nonce', format.UInt32],
    ['txns', new format.FormatList(format.Tx, 1)],
])

Testing

For now, there is a test.js that does basic/manual sanity checks... More testing coming soon.

Donations?

Obviously, it's all licensed under the MIT license, so use it as you wish; but if you'd like to buy me a coffee, I won't complain. =)

  • Bitcoin - 1EMFpt82U3XHLYTXwZZhKnK4erqAyDf5SW
  • Dogecoin - DFXSxgGRpNvAFH6LLXMjgvtZhcexr4TH4i
  • Testnet3 - n4S2tas4vKDPMrV32TE4rebyToi65hHDN1