chainpoint-validate-js
A Node.js module for validating Chainpoint blockchain receipts
Installation
$ npm install --save chainpoint-validate
Usage
Use the isValidReceipt function to validate your Chainpoint receipt.
chainpointValidate.isValidReceipt(receipt, confirmAnchor, callback);
Example
var chainpointvalidate = require('chainpoint-validate');
var chainpointValidate = new chainpointvalidate();
var validReceipt = {
"@context": "https://w3id.org/chainpoint/v2",
"type": "ChainpointSHA256v2",
"targetHash": "bdf8c9bdf076d6aff0292a1c9448691d2ae283f2ce41b045355e2c8cb8e85ef2",
"merkleRoot": "51296468ea48ddbcc546abb85b935c73058fd8acdb0b953da6aa1ae966581a7a",
"proof": [
{
"left": "bdf8c9bdf076d6aff0292a1c9448691d2ae283f2ce41b045355e2c8cb8e85ef2"
},
{
"left": "cb0dbbedb5ec5363e39be9fc43f56f321e1572cfcf304d26fc67cb6ea2e49faf"
},
{
"right": "cb0dbbedb5ec5363e39be9fc43f56f321e1572cfcf304d26fc67cb6ea2e49faf"
}
],
"anchors": [
{
"type": "BTCOpReturn",
"sourceId": "f3be82fe1b5d8f18e009cb9a491781289d2e01678311fe2b2e4e84381aafadee"
}
]
};
var invalidReceipt = "not a receipt";
chainpointValidate.isValidReceipt(validReceipt, true, function (err, result) {
if(err) {
} else {
}
});
chainpointValidate.isValidReceipt(invalidReceipt, true, function (err, result) {
if(err) {
} else {
}
});
Sample Valid Result
{
isValid: true,
anchors: [
{
type: 'BTCOpReturn',
sourceId: 'f3be82fe1b5d8f18e009cb9a491781289d2e01678311fe2b2e4e84381aafadee',
exists: true
}
]
}
When 'confirmAnchor' is set to true, an additional 'exists' value is added indicating the whether or not the data actually exists in the transaction. This function relies on BlockCypher's API which currently rate limits to 3 per second and 200 per hour. Confirmations requested beyond those limits will return false.
Sample Invalid Result
{
isValid: false,
error: 'Cannot parse receipt JSON'
}