mockle
Version:
Mock TSC merkle proof generator
61 lines (38 loc) • 2.51 kB
Markdown
Mock TSC merkle proof generator
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
```js
const mockle = require('mockle')
// or
import mockle from 'mockle'
```
Generate a mock proof for a random TXID
```js
const mockProof = mockle()
```
Generate a mock proof for a given `txOrId`, `index` and `targetType`
```js
const mockProof = mockle({
txOrId: '...',
index: 1337,
targetType: 'header'
})
```
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
* [mockle](
* [Parameters](
Generate a fake TSC-format merkle proof
* `param` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** All parameters are given in an object (optional, default `{}`)
* `param.txOrId` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** A custom target type for the proof, either "hash", "header" or "merkleRoot" which is the default (optional, default `"merkleRoot"`)
* `param.index` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the TSC format merkle proof given as a JavaScript object
The license for the code in this repository is the Open BSV License.