assertion-tools
Advanced tools
Comparing version 2.0.4 to 2.1.0
@@ -20,2 +20,2 @@ function getAssertionSizeInBytes(assertion) { | ||
getAssertionChunksNumber, | ||
}; | ||
} |
@@ -1,4 +0,4 @@ | ||
const keccak256 = require("./keccak256.js"); | ||
const ethers = require("ethers"); | ||
const { MerkleTree } = require("merkletreejs"); | ||
const ethers = require('ethers'); | ||
const { MerkleTree } = require('merkletreejs'); | ||
const keccak256 = require('./keccak256.js'); | ||
@@ -10,3 +10,3 @@ function calculateRoot(assertion) { | ||
ethers.utils.solidityPack( | ||
["bytes32", "uint256"], | ||
['bytes32', 'uint256'], | ||
[keccak256(element), index] | ||
@@ -17,5 +17,5 @@ ) | ||
const tree = new MerkleTree(leaves, keccak256, { sortPairs: true }); | ||
return `0x${tree.getRoot().toString("hex")}`; | ||
return `0x${tree.getRoot().toString('hex')}`; | ||
} | ||
module.exports = calculateRoot; |
@@ -1,4 +0,4 @@ | ||
const ethers = require("ethers"); | ||
const keccak256 = require("./keccak256.js"); | ||
const { MerkleTree } = require("merkletreejs"); | ||
const ethers = require('ethers'); | ||
const { MerkleTree } = require('merkletreejs'); | ||
const keccak256 = require('./keccak256.js'); | ||
@@ -11,3 +11,3 @@ function getMerkleProof(nquadsArray, challenge) { | ||
ethers.utils.solidityPack( | ||
["bytes32", "uint256"], | ||
['bytes32', 'uint256'], | ||
[keccak256(element), index] | ||
@@ -14,0 +14,0 @@ ) |
15
index.js
@@ -1,8 +0,9 @@ | ||
const calculateRoot = require("./calculate-root.js"); | ||
const formatAssertion = require("./format-assertion.js"); | ||
const peerId2Hash = require("./peer-id-2-hash.js"); | ||
const getMerkleProof = require("./get-merkle-proof.js"); | ||
const keccak256 = require("./keccak256.js"); | ||
const assertionMetadata = require("./assertion-metadata.js"); | ||
const assertionMetadata = require('./assertion-metadata.js'); | ||
const calculateRoot = require('./calculate-root.js'); | ||
const formatAssertion = require('./assertion-formatting.js'); | ||
const formatGraph = require('./graph-formatting.js'); | ||
const getMerkleProof = require('./get-merkle-proof.js'); | ||
const peerId2Hash = require('./peer-id-2-hash.js'); | ||
const keccak256 = require('./keccak256.js'); | ||
module.exports = { calculateRoot, formatAssertion, peerId2Hash, getMerkleProof, keccak256, assertionMetadata }; | ||
module.exports = { calculateRoot, formatAssertion, formatGraph, getMerkleProof, peerId2Hash, keccak256, assertionMetadata }; |
@@ -1,4 +0,4 @@ | ||
const ethers = require("ethers"); | ||
const ethers = require('ethers'); | ||
const keccak256 = (data) => { | ||
function keccak256(data) { | ||
let bytesLikeData = data; | ||
@@ -5,0 +5,0 @@ if (!ethers.utils.isBytesLike(data)) { |
{ | ||
"name": "assertion-tools", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Common assertion tools used in ot-node and dkg.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "nyc --all mocha --exit" | ||
}, | ||
@@ -25,4 +25,11 @@ "repository": { | ||
"devDependencies": { | ||
"mocha": "^10.1.0" | ||
"chai": "^4.3.10", | ||
"eslint": "^8.50.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-prettier": "^9.0.0", | ||
"mocha": "^10.2.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^3.0.3", | ||
"sinon": "^16.0.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
const ethers = require("ethers"); | ||
const ethers = require('ethers'); | ||
@@ -3,0 +3,0 @@ async function peerId2Hash(peerId) { |
@@ -1,4 +0,5 @@ | ||
const assert = require('assert'); | ||
const {formatAssertion, calculateRoot, encrypt, decrypt} = require("../index.js"); | ||
const crypto = require("crypto"); | ||
const { describe, it, afterEach } = require('mocha'); | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
const { calculateRoot, formatAssertion, formatGraph } = require('../index.js'); | ||
@@ -8,18 +9,73 @@ let assertion; | ||
describe('Simple tools test', () => { | ||
it('formatAssertion', async () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
it('Dataset normalization', async () => { | ||
const example = { | ||
"@context": "https://json-ld.org/contexts/person.jsonld", | ||
"@id": "http://dbpedia.org/resource/John_Lennon", | ||
"name": "John Lennon", | ||
"born": "1940-10-09", | ||
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon" | ||
'@context': 'https://json-ld.org/contexts/person.jsonld', | ||
'@id': 'http://dbpedia.org/resource/John_Lennon', | ||
'name': 'John Lennon', | ||
'born': '1940-10-09', | ||
'spouse': 'http://dbpedia.org/resource/Cynthia_Lennon' | ||
}; | ||
assertion = await formatAssertion(example); | ||
assert(assertion && assertion.length !== 0); | ||
expect(assertion).to.not.equal(null); | ||
expect(assertion.length).to.not.equal(0); | ||
}); | ||
it('calculateRoot', async () => { | ||
it('Graph formatting', async () => { | ||
const exampleContent = { | ||
public: { | ||
'@context': ['https://schema.org'], | ||
'@id': 'uuid:1', | ||
company: 'OT', | ||
user: { | ||
'@id': 'uuid:user:1', | ||
}, | ||
city: { | ||
'@id': 'uuid:belgrade', | ||
}, | ||
}, | ||
private: { | ||
'@context': ['https://schema.org'], | ||
'@graph': [ | ||
{ | ||
'@id': 'uuid:user:1', | ||
name: 'Adam', | ||
lastname: 'Smith', | ||
}, | ||
{ | ||
'@id': 'uuid:belgrade', | ||
title: 'Belgrade', | ||
postCode: '11000', | ||
}, | ||
], | ||
}, | ||
}; | ||
const expectedPublicNQuads = [ | ||
'<uuid:1> <http://schema.org/city> <uuid:belgrade> .', | ||
'<uuid:1> <http://schema.org/company> "OT" .', | ||
'<uuid:1> <http://schema.org/user> <uuid:user:1> .', | ||
'_:c14n0 <https://ontology.origintrail.io/dkg/1.0#privateAssertionID> "0xcfab2d364fe01757d7a83d3b32284395d87b1c379adabb1e28a16666e0a4fca9" .' | ||
]; | ||
const expectedPrivateNQuads = [ | ||
'<uuid:belgrade> <http://schema.org/postCode> "11000" .', | ||
'<uuid:belgrade> <http://schema.org/title> "Belgrade" .', | ||
'<uuid:user:1> <http://schema.org/lastname> "Smith" .', | ||
'<uuid:user:1> <http://schema.org/name> "Adam" .' | ||
]; | ||
const assertions = await formatGraph(exampleContent); | ||
expect(assertions).to.have.property('public').to.deep.equal(expectedPublicNQuads); | ||
expect(assertions).to.have.property('private').to.deep.equal(expectedPrivateNQuads); | ||
}); | ||
it('Merkle Root calculation', async () => { | ||
const assertionId = calculateRoot(assertion); | ||
assert(assertionId); | ||
expect(assertionId).to.not.equal(null); | ||
}); | ||
}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8834
13
224
8
1