chainpoint-proof-json-schema
Advanced tools
Comparing version 1.0.2 to 1.1.0
304
index.js
@@ -1,177 +0,205 @@ | ||
'use strict' | ||
/* Copyright 2019 Tierion | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* Copyright 2017-2018 Tierion | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
const validator = require('is-my-json-valid') | ||
const chainpointSchemaV3 = { | ||
'$schema': 'http://json-schema.org/draft-04/schema#', | ||
'additionalProperties': false, | ||
'definitions': { | ||
'branch': { | ||
'additionalProperties': false, | ||
'properties': { | ||
'label': { | ||
'description': 'An aritrary text branch label. Can contain up to 64 letters, numbers, hyphen, underscore, or period characters.', | ||
'pattern': '^[a-zA-Z0-9-_\\.]*$', | ||
'title': 'The Label Schema', | ||
'type': 'string', | ||
'minLength': 0, | ||
'maxLength': 64 | ||
$schema: 'http://json-schema.org/draft-04/schema#', | ||
additionalProperties: false, | ||
definitions: { | ||
branch: { | ||
additionalProperties: false, | ||
properties: { | ||
label: { | ||
description: | ||
'An aritrary text branch label. Can contain up to 64 letters, numbers, hyphen, underscore, or period characters.', | ||
pattern: '^[a-zA-Z0-9-_\\.]*$', | ||
title: 'The Label Schema', | ||
type: 'string', | ||
minLength: 0, | ||
maxLength: 64 | ||
}, | ||
'branches': { | ||
'items': { | ||
'$ref': '#/definitions/branch' | ||
branches: { | ||
items: { | ||
$ref: '#/definitions/branch' | ||
}, | ||
'type': 'array', | ||
'uniqueItems': true | ||
type: 'array', | ||
uniqueItems: true | ||
}, | ||
'ops': { | ||
'items': { | ||
'$ref': '#/definitions/operation' | ||
ops: { | ||
items: { | ||
$ref: '#/definitions/operation' | ||
}, | ||
'type': 'array' | ||
type: 'array' | ||
} | ||
}, | ||
'required': ['ops'], | ||
'type': 'object' | ||
required: ['ops'], | ||
type: 'object' | ||
}, | ||
'anchor': { | ||
'additionalProperties': false, | ||
'properties': { | ||
'type': { | ||
'description': 'A trust anchor', | ||
'pattern': '^[a-z]{3,10}$', | ||
'title': 'A trust anchor type. e.g. Chainpoint Calendar (cal), Ethereum (eth), or Bitcoin (btc). It must be between 3 and 10 characters in length and match the Regex /^[a-z]{3,10}$/', | ||
'type': 'string' | ||
anchor: { | ||
additionalProperties: false, | ||
properties: { | ||
type: { | ||
description: 'A trust anchor', | ||
pattern: '^(cal|btc|tcal|tbtc|eth)$', | ||
title: `Chainpoint anchor type, one of 'cal' (Calendar), 'btc' (Bitcoin), 'tcal' (Testnet Calendar), 'tbtc' (Testnet Bitcoin), or 'eth' (Ethereum) anchor types`, | ||
type: 'string' | ||
}, | ||
'anchor_id': { | ||
'description': 'An identifier used to look up embedded anchor data. e.g. a Bitcoin transaction or block ID.', | ||
'title': 'A service specific unique ID for this anchor', | ||
'type': 'string', | ||
'minLength': 1, | ||
'maxLength': 512 | ||
anchor_id: { | ||
description: 'An identifier used to look up embedded anchor data. e.g. a Bitcoin transaction or block ID.', | ||
title: 'A service specific unique ID for this anchor', | ||
type: 'string', | ||
minLength: 1, | ||
maxLength: 512 | ||
}, | ||
'uris': { | ||
'items': { | ||
'description': "A URI used to lookup and retrieve the exact hash resource required to validate this anchor. The URI MUST return only a Hexadecimal hash value as a string. The URI MUST also contain the current 'anchor_id' value to lookup the URI resource. This strict requirement is to allow automated clients to retrieve and validate intermediate hashes when verifying a proof. The body value returned by the URI MUST be of even length and match the regex /^[a-fA-F0-9]+$/.", | ||
'title': 'A URI for retrieving a hash value for this item', | ||
'type': 'string', | ||
'format': 'uri', | ||
'minLength': 1, | ||
'maxLength': 512 | ||
uris: { | ||
items: { | ||
description: | ||
"A URI used to lookup and retrieve the exact hash resource required to validate this anchor. The URI MUST return only a Hexadecimal hash value as a string. The URI MUST also contain the current 'anchor_id' value to lookup the URI resource. This strict requirement is to allow automated clients to retrieve and validate intermediate hashes when verifying a proof. The body value returned by the URI MUST be of even length and match the regex /^[a-fA-F0-9]+$/.", | ||
title: 'A URI for retrieving a hash value for this item', | ||
type: 'string', | ||
format: 'uri', | ||
minLength: 1, | ||
maxLength: 512 | ||
}, | ||
'type': 'array', | ||
'uniqueItems': true | ||
type: 'array', | ||
uniqueItems: true | ||
} | ||
}, | ||
'required': ['type', 'anchor_id'], | ||
'type': 'object' | ||
required: ['type', 'anchor_id'], | ||
type: 'object' | ||
}, | ||
'operation': { | ||
'additionalProperties': false, | ||
'properties': { | ||
'l': { | ||
'description': 'Concatenate the byte array value of this property to the left of the prior state of the hash (value|prior_hash).', | ||
'title': 'Concatenate value with left side of previous value', | ||
'type': 'string', | ||
'minLength': 1, | ||
'maxLength': 512 | ||
operation: { | ||
additionalProperties: false, | ||
properties: { | ||
l: { | ||
description: | ||
'Concatenate the byte array value of this property to the left of the prior state of the hash (value|prior_hash).', | ||
title: 'Concatenate value with left side of previous value', | ||
type: 'string', | ||
minLength: 1, | ||
maxLength: 512 | ||
}, | ||
'r': { | ||
'description': 'Concatenate the byte array value of this property to the right of the prior state of the hash (prior_hash|value).', | ||
'title': 'Concatenate value with right side of previous value', | ||
'type': 'string', | ||
'minLength': 1, | ||
'maxLength': 512 | ||
r: { | ||
description: | ||
'Concatenate the byte array value of this property to the right of the prior state of the hash (prior_hash|value).', | ||
title: 'Concatenate value with right side of previous value', | ||
type: 'string', | ||
minLength: 1, | ||
maxLength: 512 | ||
}, | ||
'op': { | ||
'description': "A hashing operation from the SHA2 or SHA3 families of hash functions to apply to a left or right operation hash value. The special value of 'sha-256-x2' performs a 'sha-256' twice in a row.", | ||
'title': 'The hashing operation to apply to a left or right hash', | ||
'type': 'string', | ||
'enum': ['sha-224', 'sha-256', 'sha-384', 'sha-512', 'sha3-224', 'sha3-256', 'sha3-384', 'sha3-512', 'sha-256-x2'] | ||
op: { | ||
description: | ||
"A hashing operation from the SHA2 or SHA3 families of hash functions to apply to a left or right operation hash value. The special value of 'sha-256-x2' performs a 'sha-256' twice in a row.", | ||
title: 'The hashing operation to apply to a left or right hash', | ||
type: 'string', | ||
enum: [ | ||
'sha-224', | ||
'sha-256', | ||
'sha-384', | ||
'sha-512', | ||
'sha3-224', | ||
'sha3-256', | ||
'sha3-384', | ||
'sha3-512', | ||
'sha-256-x2' | ||
] | ||
}, | ||
'anchors': { | ||
'items': { | ||
'$ref': '#/definitions/anchor' | ||
anchors: { | ||
items: { | ||
$ref: '#/definitions/anchor' | ||
}, | ||
'type': 'array', | ||
'uniqueItems': true | ||
type: 'array', | ||
uniqueItems: true | ||
} | ||
}, | ||
'type': 'object' | ||
type: 'object' | ||
} | ||
}, | ||
'description': 'This document contains a schema for validating an instance of a Chainpoint v3 Proof.', | ||
'id': 'http://example.com/example.json', | ||
'properties': { | ||
description: 'This document contains a schema for validating an instance of a Chainpoint v3 Proof.', | ||
id: 'http://example.com/example.json', | ||
properties: { | ||
'@context': { | ||
'default': 'https://w3id.org/chainpoint/v3', | ||
'description': 'A registered JSON-LD context URI for this document type', | ||
'title': 'The JSON-LD @context', | ||
'type': 'string', | ||
'enum': ['https://w3id.org/chainpoint/v3'] | ||
default: 'https://w3id.org/chainpoint/v3', | ||
description: 'A registered JSON-LD context URI for this document type', | ||
title: 'The JSON-LD @context', | ||
type: 'string', | ||
enum: ['https://w3id.org/chainpoint/v3'] | ||
}, | ||
'type': { | ||
'default': 'Chainpoint', | ||
'description': 'The JSON-LD Type', | ||
'title': 'The JSON-LD Type', | ||
'type': 'string', | ||
'enum': ['Chainpoint'] | ||
type: { | ||
default: 'Chainpoint', | ||
description: 'The JSON-LD Type', | ||
title: 'The JSON-LD Type', | ||
type: 'string', | ||
enum: ['Chainpoint'] | ||
}, | ||
'hash': { | ||
'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: { | ||
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', | ||
'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_id_node: { | ||
description: | ||
'The Type 1 (timestamp) UUID used to identify and track a hash or retrieve a Chainpoint proof from a Chainpoint Node', | ||
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_node_at': { | ||
'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', | ||
'type': 'string' | ||
hash_submitted_node_at: { | ||
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', | ||
type: 'string' | ||
}, | ||
'hash_id_core': { | ||
'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_id_core: { | ||
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.', | ||
'pattern': '^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ$', | ||
'title': 'An ISO8601 timestamp, extracted from hash_id_core', | ||
'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.', | ||
pattern: '^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ$', | ||
title: 'An ISO8601 timestamp, extracted from hash_id_core', | ||
type: 'string' | ||
}, | ||
'branches': { | ||
'items': { | ||
'$ref': '#/definitions/branch' | ||
branches: { | ||
items: { | ||
$ref: '#/definitions/branch' | ||
}, | ||
'type': 'array', | ||
'uniqueItems': true | ||
type: 'array', | ||
uniqueItems: true | ||
} | ||
}, | ||
'required': ['@context', 'type', 'hash', 'hash_id_node', 'hash_submitted_node_at', 'hash_id_core', 'hash_submitted_core_at', 'branches'], | ||
'title': 'Chainpoint v3 JSON Schema.', | ||
'type': 'object' | ||
required: [ | ||
'@context', | ||
'type', | ||
'hash', | ||
'hash_id_node', | ||
'hash_submitted_node_at', | ||
'hash_id_core', | ||
'hash_submitted_core_at', | ||
'branches' | ||
], | ||
title: 'Chainpoint v3 JSON Schema.', | ||
type: 'object' | ||
} | ||
const validator = require('is-my-json-valid') | ||
const validateSchema = validator(chainpointSchemaV3, { verbose: true }) | ||
exports.validate = function (proof) { | ||
exports.validate = function(proof) { | ||
// Return both in a single object since the validator | ||
@@ -181,3 +209,3 @@ // actually mutates itself to hold the errors after | ||
// will only return a Boolean. | ||
return {valid: validateSchema(proof), errors: validateSchema.errors} | ||
return { valid: validateSchema(proof), errors: validateSchema.errors } | ||
} |
{ | ||
"name": "chainpoint-proof-json-schema", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "A JSON Schema (Draft 04) validator for Chainpoint v3 Proofs", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha", | ||
"browser": "yarn bundle && open docs/index.html", | ||
"bundle": "./node_modules/.bin/browserify --standalone chainpointProofSchema index.js -o docs/bundle.js", | ||
"eslint-check": "eslint --print-config . | eslint-config-prettier-check" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"linters": { | ||
"*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
], | ||
"*.{json,css,md}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
} | ||
}, | ||
"repository": "https://github.com/chainpoint/chainpoint-proof-json-schema", | ||
"author": "Glenn Rempe <glenn@tierion.com>", | ||
"author": "Jason Bukowski <jason@tierion.com>", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"is-my-json-valid": "^2.16.0" | ||
"is-my-json-valid": "^2.20.0" | ||
}, | ||
@@ -15,9 +38,10 @@ "devDependencies": { | ||
"mocha": "^5.2.0", | ||
"should": "^13.2.3" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha -w", | ||
"browser": "yarn bundle && open docs/index.html", | ||
"bundle": "./node_modules/.bin/browserify --standalone chainpointProofSchema index.js -o docs/bundle.js" | ||
"should": "^13.2.3", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.1.0", | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"husky": "^1.3.1", | ||
"lint-staged": "^8.1.5", | ||
"prettier": "^1.17.0" | ||
} | ||
} |
# Chainpoint Proof v3 JSON Schema Validator | ||
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
[![npm version](https://badge.fury.io/js/chainpoint-proof-json-schema.svg)](https://badge.fury.io/js/chainpoint-proof-json-schema) | ||
@@ -4,0 +8,0 @@ |
154
test/test.js
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
/* global describe, it, beforeEach */ | ||
@@ -8,3 +8,3 @@ const cps = require('../index') | ||
beforeEach(function () { | ||
beforeEach(function() { | ||
// Clone the sample so properties can be modified/deleted | ||
@@ -15,4 +15,4 @@ // without touching the original. | ||
describe('sample proof', function () { | ||
it('should be valid', function (done) { | ||
describe('sample proof', function() { | ||
it('should be valid', function(done) { | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -24,4 +24,4 @@ cps.validate(sampleProof).should.have.property('errors', null) | ||
describe('proof root', function () { | ||
it('should be invalid with missing @context', function (done) { | ||
describe('proof root', function() { | ||
it('should be invalid with missing @context', function(done) { | ||
delete sampleProof['@context'] | ||
@@ -34,3 +34,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with unknown @context', function (done) { | ||
it('should be invalid with unknown @context', function(done) { | ||
sampleProof['@context'] = 'foo' | ||
@@ -43,3 +43,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with missing type', function (done) { | ||
it('should be invalid with missing type', function(done) { | ||
delete sampleProof['type'] | ||
@@ -52,3 +52,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with unknown type', function (done) { | ||
it('should be invalid with unknown type', function(done) { | ||
sampleProof['type'] = 'foo' | ||
@@ -61,3 +61,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with missing hash', function (done) { | ||
it('should be invalid with missing hash', function(done) { | ||
delete sampleProof['hash'] | ||
@@ -70,3 +70,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with non-hex hash', function (done) { | ||
it('should be invalid with non-hex hash', function(done) { | ||
sampleProof['hash'] = 'xyz' | ||
@@ -79,3 +79,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with missing hash_id_node', function (done) { | ||
it('should be invalid with missing hash_id_node', function(done) { | ||
delete sampleProof['hash_id_node'] | ||
@@ -88,3 +88,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with non-UUID hash_id_node', function (done) { | ||
it('should be invalid with non-UUID hash_id_node', function(done) { | ||
sampleProof['hash_id_node'] = 'abc' | ||
@@ -97,3 +97,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with missing hash_submitted_node_at', function (done) { | ||
it('should be invalid with missing hash_submitted_node_at', function(done) { | ||
delete sampleProof['hash_submitted_node_at'] | ||
@@ -106,3 +106,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with non ISO8601 date hash_submitted_node_at', function (done) { | ||
it('should be invalid with non ISO8601 date hash_submitted_node_at', function(done) { | ||
sampleProof['hash_submitted_node_at'] = 'March 1, 2017' | ||
@@ -115,3 +115,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with ISO8601 date hash_submitted_node_at in non-strict millisecond granularity form', function (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' | ||
@@ -124,3 +124,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with missing hash_id_core', function (done) { | ||
it('should be invalid with missing hash_id_core', function(done) { | ||
delete sampleProof['hash_id_core'] | ||
@@ -133,3 +133,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with non-UUID hash_id_core', function (done) { | ||
it('should be invalid with non-UUID hash_id_core', function(done) { | ||
sampleProof['hash_id_core'] = 'abc' | ||
@@ -142,3 +142,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with missing hash_submitted_core_at', function (done) { | ||
it('should be invalid with missing hash_submitted_core_at', function(done) { | ||
delete sampleProof['hash_submitted_core_at'] | ||
@@ -151,3 +151,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with non ISO8601 date hash_submitted_core_at', function (done) { | ||
it('should be invalid with non ISO8601 date hash_submitted_core_at', function(done) { | ||
sampleProof['hash_submitted_core_at'] = 'March 1, 2017' | ||
@@ -160,3 +160,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with ISO8601 date hash_submitted_core_at in non-strict millisecond granularity form', function (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' | ||
@@ -169,3 +169,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with missing branches at the root', function (done) { | ||
it('should be invalid with missing branches at the root', function(done) { | ||
delete sampleProof['branches'] | ||
@@ -178,3 +178,3 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
it('should be invalid with an added property at the root', function (done) { | ||
it('should be invalid with an added property at the root', function(done) { | ||
sampleProof.extra = {} | ||
@@ -188,4 +188,4 @@ cps.validate(sampleProof).should.have.property('valid', false) | ||
describe('proof.branches', function () { | ||
it('should be valid with optional label removed', function (done) { | ||
describe('proof.branches', function() { | ||
it('should be valid with optional label removed', function(done) { | ||
let branch = sampleProof.branches[0] | ||
@@ -197,3 +197,3 @@ delete branch.label | ||
it('should be valid with optional branches removed', function (done) { | ||
it('should be valid with optional branches removed', function(done) { | ||
let branch = sampleProof.branches[0] | ||
@@ -205,3 +205,3 @@ delete branch.branches | ||
it('should be invalid with required ops removed', function (done) { | ||
it('should be invalid with required ops removed', function(done) { | ||
let branch = sampleProof.branches[0] | ||
@@ -215,3 +215,3 @@ delete branch.ops | ||
it('should be invalid with an additional property added', function (done) { | ||
it('should be invalid with an additional property added', function(done) { | ||
let branch = sampleProof.branches[0] | ||
@@ -226,4 +226,4 @@ branch.extra = {} | ||
describe('proof.branches[0].ops', function () { | ||
it('should be valid if empty', function (done) { | ||
describe('proof.branches[0].ops', function() { | ||
it('should be valid if empty', function(done) { | ||
sampleProof.branches[0].ops = [] | ||
@@ -234,4 +234,4 @@ cps.validate(sampleProof).should.have.property('valid', true) | ||
it('should be valid with a single approved l property', function (done) { | ||
sampleProof.branches[0].ops = [{l: 'abc'}] | ||
it('should be valid with a single approved l property', function(done) { | ||
sampleProof.branches[0].ops = [{ l: 'abc' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -241,4 +241,4 @@ done() | ||
it('should be valid with a single approved r property', function (done) { | ||
sampleProof.branches[0].ops = [{r: 'abc'}] | ||
it('should be valid with a single approved r property', function(done) { | ||
sampleProof.branches[0].ops = [{ r: 'abc' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -248,4 +248,4 @@ done() | ||
it('should be valid with a single approved op property with an sha-224 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-224'}] | ||
it('should be valid with a single approved op property with an sha-224 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-224' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -255,4 +255,4 @@ done() | ||
it('should be valid with a single approved op property with an sha-256 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-256'}] | ||
it('should be valid with a single approved op property with an sha-256 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-256' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -262,4 +262,4 @@ done() | ||
it('should be valid with a single approved op property with an sha-384 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-384'}] | ||
it('should be valid with a single approved op property with an sha-384 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-384' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -269,4 +269,4 @@ done() | ||
it('should be valid with a single approved op property with an sha-512 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-512'}] | ||
it('should be valid with a single approved op property with an sha-512 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-512' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -276,4 +276,4 @@ done() | ||
it('should be valid with a single approved op property with an sha3-224 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-224'}] | ||
it('should be valid with a single approved op property with an sha3-224 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-224' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -283,4 +283,4 @@ done() | ||
it('should be valid with a single approved op property with an sha3-256 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-256'}] | ||
it('should be valid with a single approved op property with an sha3-256 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-256' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -290,4 +290,4 @@ done() | ||
it('should be valid with a single approved op property with an sha3-384 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-384'}] | ||
it('should be valid with a single approved op property with an sha3-384 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-384' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -297,4 +297,4 @@ done() | ||
it('should be valid with a single approved op property with an sha3-512 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-512'}] | ||
it('should be valid with a single approved op property with an sha3-512 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-512' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -304,4 +304,4 @@ done() | ||
it('should be valid with a single approved op property with an sha-256-x2 hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'sha-512'}] | ||
it('should be valid with a single approved op property with an sha-256-x2 hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'sha-512' }] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
@@ -311,4 +311,4 @@ done() | ||
it('should be invalid with a single approved op property with an unknown hash', function (done) { | ||
sampleProof.branches[0].ops = [{op: 'blake2s'}] | ||
it('should be invalid with a single approved op property with an unknown hash', function(done) { | ||
sampleProof.branches[0].ops = [{ op: 'blake2s' }] | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
@@ -320,4 +320,4 @@ cps.validate(sampleProof).errors[0].should.have.property('field', 'data.branches.0') | ||
it('should be invalid with an additional property added', function (done) { | ||
sampleProof.branches[0].ops = [{foo: 'bar'}] | ||
it('should be invalid with an additional property added', function(done) { | ||
sampleProof.branches[0].ops = [{ foo: 'bar' }] | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
@@ -330,4 +330,4 @@ cps.validate(sampleProof).errors[0].should.have.property('field', 'data.branches.0') | ||
describe('proof.branches[0].ops[0].anchors', function () { | ||
it('should be valid if empty', function (done) { | ||
describe('proof.branches[0].ops[0].anchors', function() { | ||
it('should be valid if empty', function(done) { | ||
sampleProof.branches[0].ops[0].anchors = [] | ||
@@ -338,3 +338,3 @@ cps.validate(sampleProof).should.have.property('valid', true) | ||
it('should be valid with a cal type', function (done) { | ||
it('should be valid with a cal type', function(done) { | ||
let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
@@ -346,3 +346,3 @@ sampleProof.branches[0].ops[lastAnchorIndex].anchors[0].type = 'cal' | ||
it('should be valid with a eth type', function (done) { | ||
it('should be valid with a eth type', function(done) { | ||
let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
@@ -354,3 +354,3 @@ sampleProof.branches[0].ops[lastAnchorIndex].anchors[0].type = 'eth' | ||
it('should be valid with a btc type', function (done) { | ||
it('should be valid with a btc type', function(done) { | ||
let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
@@ -362,3 +362,3 @@ sampleProof.branches[0].ops[lastAnchorIndex].anchors[0].type = 'btc' | ||
it('should be invalid with an empty type', function (done) { | ||
it('should be invalid with an empty type', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -371,3 +371,3 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be invalid with an incorrectly cased type', function (done) { | ||
it('should be invalid with an incorrectly cased type', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -380,3 +380,3 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be invalid with a too short type', function (done) { | ||
it('should be invalid with a too short type', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -389,3 +389,3 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be invalid with a too long type', function (done) { | ||
it('should be invalid with a too long type', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -398,11 +398,11 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be valid with an arbitrary anchor type', function (done) { | ||
it('should NOT be valid with an unsupported anchor type', function(done) { | ||
// get the last ops, which should be an anchor | ||
let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
sampleProof.branches[0].ops[lastAnchorIndex].anchors[0].type = 'foo' | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
cps.validate(sampleProof).should.have.property('valid', false) | ||
done() | ||
}) | ||
it('should be valid with an unknown anchor_id', function (done) { | ||
it('should be valid with an unknown anchor_id', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -415,3 +415,3 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be invalid with an empty anchor_id', function (done) { | ||
it('should be invalid with an empty anchor_id', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -424,3 +424,3 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be invalid with an integer anchor_id', function (done) { | ||
it('should be invalid with an integer anchor_id', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -433,3 +433,3 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be valid with no optional uris', function (done) { | ||
it('should be valid with no optional uris', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -443,3 +443,3 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be valid with empty optional uris', function (done) { | ||
it('should be valid with empty optional uris', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -452,11 +452,13 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
it('should be valid with valid optional uris', function (done) { | ||
it('should be valid with valid optional uris', function(done) { | ||
// get the last ops, which should be an anchor | ||
let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 | ||
sampleProof.branches[0].ops[lastAnchorIndex].anchors[0].uris = ['https://a.cal.chainpoint.org', 'https://b.cal.chainpoint.org'] | ||
sampleProof.branches[0].ops[lastAnchorIndex].anchors[0].uris = [ | ||
'https://a.cal.chainpoint.org', | ||
'https://b.cal.chainpoint.org' | ||
] | ||
cps.validate(sampleProof).should.have.property('valid', true) | ||
done() | ||
}) | ||
it('should be invalid with malformed optional uris', function (done) { | ||
it('should be invalid with malformed optional uris', function(done) { | ||
// get the last ops, which should be an anchor | ||
@@ -463,0 +465,0 @@ let lastAnchorIndex = sampleProof.branches[0].ops.length - 1 |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
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
274996
15
2895
78
9
Updatedis-my-json-valid@^2.20.0