function createMerkleTree(nodes){
if (nodes.length > 1) {
let newNodes = []
let leafNodes = []
if(typeof nodes[0] =='string'){
nodes.forEach((value, index, array) => {
leafNodes.push({hash: value})
})
nodes = leafNodes
}
if(nodes.length % 2 == 1){
nodes.push(nodes[nodes.length - 1])
}
nodes.forEach((value, index, array) => {
if(index % 2 == 0){
newNodes.push({hash: sha256(value.hash + array[index + 1].hash), children: [value, array[index+1]]})
}
})
return createMerkleTree(newNodes)
} else {
return nodes[0]
}
}