Energyweb Origin project's proof-of-concept Precise Proofs implementation and demo.
npm install ew-precise-proofs-js
This is a JS npm package and some demo scripts for creating-, verifying- and getting started with Precise Proofs.
This implementation was inspired by Centrifuge's Precise Proofs implementation in Go. In our version we emphasized improved security by:
- making the leaf positions matter in the tree
- adding the hash of the document schema to the tree as well
to prevent injection/duplicate key attacks and the prover to create phony proofs.
Heiko Burkhardt (@hai-ko), who did the heavy lifting and should get the credit for creating this implementation.
In your project:
``bash`
npm install ew-precise-proofs-js
Then in a JS project:
`javascript
const {PreciseProofs} = require("ew-precise-proofs-js");
[...]
``
Or in a Typescript project:javascript`
import {PreciseProofs} from "ew-precise-proofs-js"
[...]
Unfortunately the code is not documented. For examples look into the demo files or read the good source. They are quite intuitive though.
`javascript`
console.log(PreciseProofs)``
> { printTree: [Function],
hash: [Function],
getRootHash: [Function],
sortLeafsByKey: [Function],
sortSchema: [Function],
canonizeValue: [Function],
createMerkleTree: [Function],
hashSchema: [Function],
createExtendedTreeRootHash: [Function],
createLeafs: [Function],
createProof: [Function],
verifyProof: [Function] }
After cloning the repo and installing dependencies, you can run the demo scripts with `npm run demoX`, where X should be replaced by the number of the demo you are interested in.
Lesson: you have to include the schema.
Lesson: again, you have to include the schema.
Lesson: if you see a published commitment & schema with 2 identical keys, you should not trust any proof for that. In the implementation, a duplicate key attack is only possible for the key first in the "abc" order, otherwise the verification simply fails (leaf position matters).
Please read contributing and our code of conduct for details.
- node, npm
- Truffle, if you want to deploy Smart Contracts
`bash`
git clone https://github.com/energywebfoundation/precise-proofs.git
cd precise-proofs
npm install -D
`bash`
npm test
We use SemVer for versioning.
This project is licensed under MIT - see the LICENSE file for details.
{ operationalSince: 0,
capacityWh: 10,
country: 'Germany',
region: 'Saxony',
active: true,
nestedObject: {
id: 1 },
zip: '09648',
city: 'Mittweida',
street: 'Main Street',
houseNumber: '101',
gpsLatitude: '0',
gpsLongitude: '0' }
`
$3
`
[ { key: 'region',
value: 'U2F4b255',
salt: 'LpFp9PDgFfumrYj/',
hash:
'0xa9137a2bea5ce2c04c4406d764ea91044e3f793f9e273732a3bc691c435256a7',
{ key: 'gpsLongitude',
value: 'MTIuOTgwOTc3',
salt: 'PPiIor5ZjSb3ISpV',
hash:
'0x5c7687899e737d4394bb7f66409441c900f2c2cbc32514e76596115fb6405929' },
...]
`$3
!Tree
Proof:
`
{
key: 'street',
value: 'TWFpbiBTdHJlZXQ=',
salt: 'zcgja7NX7lkC2QRf',
proofPath: [
{
right: '0x1aa21bd98ca498bfdf530f6ef508ef088b3db6b5c3492ff530e695a213cf962e'
},
{
left: '0x8c792b76a96463f40e9c40ab10c203eb0f49d401c25a91f0284158ec34db6255'
},
{
left: '0x570c210a5bb120c6fddab47d59c38b1932b51c262b2fe2434f95d46f93d1b119'
},
{
right: '0xf69d1880dd4b21e9c462fc76e3e59103b86756aa2c775b0bb47a16e079e7c862'
}
]
}
``