ipld-bitcoin
0.1.7

Intro

Installable via npm install --save ipld-bitcoin, it can also be used directly in the browser.

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

$ npm install --save ipld-bitcoin

You can then require() ipld-bitcoin as normal:

const ipldBitcoin = require('ipld-bitcoin')

In the Browser

Ipld-bitcoin should work in any ES2015 environment out of the box.

Usage:

<script type="text/javascript" src="index.js"></script>

The portable versions of ipld-bitcoin, including index.js and index.min.js, are included in the /dist folder. Ipld-bitcoin can also be found on unkpkg.com under

ResolveCallback

Parameters

  1. error: Error?:  
    Error if path can't be resolved
  2. result: Object:  
    Result of the path it it was resolved successfully
  3. result.value: any:  
    Value the path resolves to
  4. result.remainderPath: string:  
    If the path resolves half-way to a link, then the remainderPath is the part after the link that can be used for further resolving.

resolve

Resolves a path in a Bitcoin block.

Returns the value or a link and the partial mising path. This way the IPLD Resolver can fetch the link and continue to resolve.

Parameters

  1. binaryBlob: Buffer:  
    Binary representation of a Bitcoin block
  2. path: string (='/'):  
    Path that should be resolved
  3. callback: ResolveCallback:  
    Callback that handles the return value

Returns

void

TreeCallback

Parameters

  1. error: Error?:  
    Error if paths can't be retreived
  2. result: (Array<string> | Array<Object<string, any>>):  
    The result depends on options.values , whether it returns only the paths, or the paths with the corresponding values

tree

Return all available paths of a block.

Parameters

  1. binaryBlob: Buffer:  
    Binary representation of a Bitcoin block
  2. options: Object?:  
    Possible options
  3. options.values: boolean (=false):  
    Retun only the paths by default. If it is true also return the values
  4. callback: TreeCallback:  
    Callback that handles the return value

Returns

void

SerializeCallback

Parameters

  1. error: Error?:  
    Error if serialization failed
  2. binaryBlob: Buffer?:  
    Binary Bitcoin block if serialization was successful

serialize

Serialize internal representation into a binary Bitcoin block.

Parameters

  1. dagNode: BitcoinBlock:  
    Internal representation of a Bitcoin block
  2. callback: SerializeCallback:  
    Callback that handles the return value

Returns

void

DeserializeCallback

Parameters

  1. error: Error?:  
    Error if deserialization failed
  2. dagNode: BitcoinBlock?:  
    Internal representation of a Bitcoin block if deserialization was successful

deserialize

Deserialize Bitcoin block into the internal representation,

Parameters

  1. binaryBlob: Buffer:  
    Binary representation of a Bitcoin block
  2. callback: DeserializeCallback:  
    Callback that handles the return value

Returns

void

CidCallback

Parameters

  1. error: Error?:  
    Error if getting the CID failed
  2. cid: CID?:  
    CID if call was successful

cid

Get the CID of the DAG-Node.

Parameters

  1. dagNode: BitcoinBlock:  
    Internal representation of a Bitcoin block
  2. options: Object?:  
    Options to create the CID
  3. options.version: number (=1):  
    CID version number
  4. options.hashAlg: string (='dbl-sha2-256'):  
    Hashing algorithm
  5. callback: CidCallback:  
    Callback that handles the return value

Returns

void