I have a JSON object with private data. It has the following (complex!) structure:
{
name: "JB",
age: 35,
children:
[ {
name: "Alice",
age: "5",
favColor: "pink"
},
{
name: "Bob",
age: "8",
favColor: "blue"
},
{
name: "Charlie",
age: "9",
favColor: "green"
},
]
}
I want to create a hash tree that allows others to verify pieces of the data I send them - e.g. by declaring the root on public blockchain.
For instance, I'd like to be able to share my age ONLY, and have the receiver be able to compute the hash and check that it is correct. Later, I may want to disclose to a different user that my first child is named "Alice" and her favorite color is "pink".
My understanding is that Merkle Trees are binary - each node has two leaves only. Is there a fixed schema or method for 'flattening' complex structures like the one above into a merkle tree consistently?
Alternatively, is there another type of hash tree structure that provides this kind of complexity innately for data?
For example:
Root ( = hash of name + age + children)
/ | \
/ | \
name age children (= hash of all children in array)
/ | \
/ | \
/ | \
[0] [1] [n]
/ | \
/ | \
name age favC
It seems that however the tree is constructed, it is important that the original data's structure is somehow preserved and is can be scrutinised by the validator.
- e.g. to prevent me from providing a child's age instead of my own.
- In the case of a binary merkle tree: to account for the fact that a leaf index may represent entirely different data depending on the number of children they have.
What is the best way to approach this problem? I'm using Node.JS, and the neat Merkle Tools package, but I'm not sure the merkle tree is the right tool for the job. If I've missed anything important out, or you have any clarifying questions, I will do my best to improve the question.
Many thanks.