chainpoint-proof-json-schema
Advanced tools
Comparing version 1.1.0 to 2.0.0
46
index.js
@@ -15,3 +15,3 @@ /* Copyright 2019 Tierion | ||
const chainpointSchemaV3 = { | ||
const chainpointSchemaV4 = { | ||
$schema: 'http://json-schema.org/draft-04/schema#', | ||
@@ -129,11 +129,11 @@ additionalProperties: false, | ||
}, | ||
description: 'This document contains a schema for validating an instance of a Chainpoint v3 Proof.', | ||
description: 'This document contains a schema for validating an instance of a Chainpoint v4 Proof.', | ||
id: 'http://example.com/example.json', | ||
properties: { | ||
'@context': { | ||
default: 'https://w3id.org/chainpoint/v3', | ||
default: 'https://w3id.org/chainpoint/v4', | ||
description: 'A registered JSON-LD context URI for this document type', | ||
title: 'The JSON-LD @context', | ||
type: 'string', | ||
enum: ['https://w3id.org/chainpoint/v3'] | ||
enum: ['https://w3id.org/chainpoint/v4'] | ||
}, | ||
@@ -147,12 +147,5 @@ type: { | ||
}, | ||
hash: { | ||
proof_id: { | ||
description: | ||
'The even length Hexadecimal output of a cryptographic one-way hash function representing the data to be anchored.', | ||
pattern: '^[a-fA-F0-9]{40,128}$', | ||
title: 'The hash to be anchored', | ||
type: 'string' | ||
}, | ||
hash_id_node: { | ||
description: | ||
'The Type 1 (timestamp) UUID used to identify and track a hash or retrieve a Chainpoint proof from a Chainpoint Node', | ||
'The Type 1 (timestamp) UUID used to identify and track a hash or retrieve a Chainpoint proof', | ||
pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$', | ||
@@ -162,18 +155,11 @@ title: 'A Type 1 (timestamp) UUID that identifies a hash', | ||
}, | ||
hash_submitted_node_at: { | ||
hash: { | ||
description: | ||
'The timestamp, in ISO8601 form, extracted from the hash_id_node that represents the time the hash was submitted to Chainpoint Node. Must be in "2017-03-23T11:30:33Z" form with granularity only to seconds and UTC zone.', | ||
pattern: '^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ$', | ||
title: 'An ISO8601 timestamp, extracted from hash_id_node', | ||
'The even length Hexadecimal output of a cryptographic one-way hash function representing the data to be anchored.', | ||
pattern: '^[a-fA-F0-9]{40,128}$', | ||
title: 'The hash to be anchored', | ||
type: 'string' | ||
}, | ||
hash_id_core: { | ||
hash_received: { | ||
description: | ||
'The Type 1 (timestamp) UUID used to by Chainpoint Node to identify and track a hash or retrieve a Chainpoint proof from Chainpoint Core', | ||
pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$', | ||
title: 'A Type 1 (timestamp) UUID that identifies a hash', | ||
type: 'string' | ||
}, | ||
hash_submitted_core_at: { | ||
description: | ||
'The timestamp, in ISO8601 form, extracted from the hash_id_core that represents the time the hash was submitted to Chainpoint Core. Must be in "2017-03-23T11:30:33Z" form with granularity only to seconds and UTC zone.', | ||
@@ -195,14 +181,12 @@ pattern: '^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ$', | ||
'type', | ||
'proof_id', | ||
'hash', | ||
'hash_id_node', | ||
'hash_submitted_node_at', | ||
'hash_id_core', | ||
'hash_submitted_core_at', | ||
'hash_received', | ||
'branches' | ||
], | ||
title: 'Chainpoint v3 JSON Schema.', | ||
title: 'Chainpoint v4 JSON Schema.', | ||
type: 'object' | ||
} | ||
const validateSchema = validator(chainpointSchemaV3, { verbose: true }) | ||
const validateSchema = validator(chainpointSchemaV4, { verbose: true }) | ||
@@ -209,0 +193,0 @@ exports.validate = function(proof) { |
{ | ||
"name": "chainpoint-proof-json-schema", | ||
"version": "1.1.0", | ||
"description": "A JSON Schema (Draft 04) validator for Chainpoint v3 Proofs", | ||
"version": "2.0.0", | ||
"description": "A JSON Schema (Draft 04) validator for Chainpoint v4 Proofs", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -1,3 +0,9 @@ | ||
# Chainpoint Proof v3 JSON Schema Validator | ||
# IMPORTANT | ||
If you're looking to validate proofs schemas from the existing Chainpoint V3 Network (chainpoint-services), use version 1.1.0. The latest update is for the unreleased V4 proof schema. | ||
This package does _not_ validate that the hashes in a proof are valid up to an anchor (e.g. BTC, ETH). In fact this package doesn't know what a hash is! It only validates that the proof you provide it with is a well formed proof according to its schema. Nothing more, nothing less. | ||
# Chainpoint Proof v4 JSON Schema Validator | ||
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
@@ -9,10 +15,6 @@ | ||
A simple npm package to validate a Chainpoint v3 Proof, in JSON format, against a JSON Schema (Draft 04). | ||
A simple npm package to validate a Chainpoint v4 Proof, in JSON format, against a JSON Schema (Draft 04). | ||
Take a look here to learn more about [https://chainpoint.org](https://chainpoint.org) | ||
## IMPORTANT | ||
This package does *not* validate that the hashes in a proof are valid up to an anchor (e.g. BTC, ETH). In fact this package doesn't know what a hash is! It only validates that the proof you provide it with is a well formed proof according to its schema. Nothing more, nothing less. | ||
## Learn More About JSON Schema: | ||
@@ -51,3 +53,2 @@ | ||
``` | ||
@@ -54,0 +55,0 @@ <script src="./node_modules/chainpoint-proof-json-schema/docs/bundle.js"> |
/* global describe, it, beforeEach */ | ||
const cps = require('../index') | ||
const sampleProofFromFile = require('../docs/samples/chainpoint-proof-v3.chp.json') | ||
const sampleProofFromFile = require('../docs/samples/chainpoint-proof-v4.chp.json') | ||
@@ -71,6 +71,6 @@ let sampleProof | ||
it('should be invalid with missing hash_id_node', function(done) { | ||
delete sampleProof['hash_id_node'] | ||
it('should be invalid with missing proof_id', function(done) { | ||
delete sampleProof['proof_id'] | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_id_node') | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.proof_id') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'is required') | ||
@@ -80,6 +80,6 @@ done() | ||
it('should be invalid with non-UUID hash_id_node', function(done) { | ||
sampleProof['hash_id_node'] = 'abc' | ||
it('should be invalid with non-UUID proof_id', function(done) { | ||
sampleProof['proof_id'] = 'abc' | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_id_node') | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.proof_id') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'pattern mismatch') | ||
@@ -89,6 +89,6 @@ done() | ||
it('should be invalid with missing hash_submitted_node_at', function(done) { | ||
delete sampleProof['hash_submitted_node_at'] | ||
it('should be invalid with missing hash_received', function(done) { | ||
delete sampleProof['hash_received'] | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_submitted_node_at') | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_received') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'is required') | ||
@@ -98,6 +98,6 @@ done() | ||
it('should be invalid with non ISO8601 date hash_submitted_node_at', function(done) { | ||
sampleProof['hash_submitted_node_at'] = 'March 1, 2017' | ||
it('should be invalid with non ISO8601 date hash_received', function(done) { | ||
sampleProof['hash_received'] = 'March 1, 2017' | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_submitted_node_at') | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_received') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'pattern mismatch') | ||
@@ -107,6 +107,6 @@ done() | ||
it('should be invalid with ISO8601 date hash_submitted_node_at in non-strict millisecond granularity form', function(done) { | ||
sampleProof['hash_submitted_node_at'] = '2017-04-25T19:10:07.171Z' | ||
it('should be invalid with ISO8601 date hash_received in non-strict millisecond granularity form', function(done) { | ||
sampleProof['hash_received'] = '2017-04-25T19:10:07.171Z' | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_submitted_node_at') | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_received') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'pattern mismatch') | ||
@@ -116,42 +116,2 @@ done() | ||
it('should be invalid with missing hash_id_core', function(done) { | ||
delete sampleProof['hash_id_core'] | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_id_core') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'is required') | ||
done() | ||
}) | ||
it('should be invalid with non-UUID hash_id_core', function(done) { | ||
sampleProof['hash_id_core'] = 'abc' | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_id_core') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'pattern mismatch') | ||
done() | ||
}) | ||
it('should be invalid with missing hash_submitted_core_at', function(done) { | ||
delete sampleProof['hash_submitted_core_at'] | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_submitted_core_at') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'is required') | ||
done() | ||
}) | ||
it('should be invalid with non ISO8601 date hash_submitted_core_at', function(done) { | ||
sampleProof['hash_submitted_core_at'] = 'March 1, 2017' | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_submitted_core_at') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'pattern mismatch') | ||
done() | ||
}) | ||
it('should be invalid with ISO8601 date hash_submitted_core_at in non-strict millisecond granularity form', function(done) { | ||
sampleProof['hash_submitted_core_at'] = '2017-04-25T19:10:07.171Z' | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
cps.validate(sampleProof).errors[0].should.have.property('field', 'data.hash_submitted_core_at') | ||
cps.validate(sampleProof).errors[0].should.have.property('message', 'pattern mismatch') | ||
done() | ||
}) | ||
it('should be invalid with missing branches at the root', function(done) { | ||
@@ -158,0 +118,0 @@ delete sampleProof['branches'] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79
136854
13
2753
2