3

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.

nervous-energy
  • 367
  • 6
  • 10
  • 1
    Is the actual tree you are building more complex than this? Or is this an exact presentation of the structure? – NonCreature0714 Jan 20 '18 at 17:56
  • 1
    Also, can you identify a node? At the moment, your JSON is not actually representing a tree, but an object which stores other objects. – NonCreature0714 Jan 20 '18 at 17:57
  • Thanks for the reply. The structure could be could be anything, I'm asking generically. I understand why a fixed structure may be easier, but flexibility would be ideal: e.g. include arrays whose length & location vary between user. Phrased another way, the question could be: is there any schema that allows you to represent an arbitrary JSON object in a hash 'tree', where the tree reflects the underlying structure? Or, must we use Binary Merkle Trees, and somehow ensure the tree structure is always consistent for the object, and that each leaf provides appropriate context for its data. – nervous-energy Jan 21 '18 at 00:01
  • 2
    This is better asked at the crypto.SE site. – Maarten Bodewes Jan 21 '18 at 01:27

0 Answers0