bitcoin-util
Utility functions for Bitcoin hashes and targets
Usage
npm install bitcoin-util
Methods
toHash(hex)
Takes a hex string that contains a Bitcoin hash as input, and returns a Bitcoin-protocol-friendly Big-endian Buffer. Throws an error if the hex string is not of length 64 (representing a 256-bit hash).
toCompactTarget(n)
Converts the difficulty target n
to its compact representation (used in the "bits" field in block headers). n
can be a Buffer
, hex string, or BN
(from the bn.js
package).
NOTE
bitcoin-util
uses the buffertools
package as a dependency, which is a compiled native module. When browserifying, the browserify-buffertools
package will be used instead (to keep browser compatibility).