added _toString method

This commit is contained in:
theSatvik 2021-08-30 16:06:59 +05:30
parent 1bb83c6866
commit 8a88cbc455

View File

@ -86,6 +86,12 @@ class MerkleTree {
const hash = crypto.createHash(method) const hash = crypto.createHash(method)
return hash.update(node, 'utf8').digest('hex') return hash.update(node, 'utf8').digest('hex')
} }
_toString(node) {
if (node.constructor === String) return node
if (node.constructor === Number) return node.toString()
if (node.constructor === Object) return JSON.stringify(node)
throw new Error('Input object only takes string, number, object')
}
} }