mockle
v1.0.1
Published
Mock TSC merkle proof generator
Downloads
8
Readme
mockle
Mock TSC merkle proof generator
Notes
This tool generates mocked (fake) SPV proofs in the JSON TSC format, and returns them as JavaScript objects. It does this by taking the given transaction or transaction ID (or by randomly generating a TXID), and then hashing it with randomly generated merkle branches to arrive at a random merkle root.
Needless to say, these proofs will not validate against the real chain of blocks, since the random merkle branches are not inputs to any real block's merkle root. This tool is useful for testing software that deals with the SPV ecosystem
Example Usage
const mockle = require('mockle')
// or
import mockle from 'mockle'
Generate a mock proof for a random TXID
const mockProof = mockle()
Generate a mock proof for a given txOrId
, index
and targetType
const mockProof = mockle({
txOrId: '...',
index: 1337,
targetType: 'header'
})
API
Table of Contents
mockle
Generate a fake TSC-format merkle proof
Parameters
param
Object All parameters are given in an object (optional, default{}
)param.txOrId
String A custom transaction or transaction ID to use for the proof, instead of randomly generating a TXID (optional, default"A random TXID"
)param.targetType
String A custom target type for the proof, either "hash", "header" or "merkleRoot" which is the default (optional, default"merkleRoot"
)param.index
Number A custom index in the block for the mock proof, by default it will be a random integer between 0 and 255. The larger the index, the larger your proof will be. Every doubling of the index value will add another node to the proof (optional, default"random between 0 and 255"
)
Returns Object the TSC format merkle proof given as a JavaScript object
License
The license for the code in this repository is the Open BSV License.