cylical-object-hash
Hash a cyclical object deterministically using blake2b.
Why?
There are so many of these, so why yet another object hashing library? I found all the other options lacking in one or another way. They all failed in at least one of the following ways:
- Did not have a deterministic stringification step.
- Broke on cyclical references.
- Used an insecure hashing algorithm such as md5 or sha1 instead of blake2b.
- Limited to Node.js
- Too hard to find on NPM.
Usage
const objectHash = require('cylical-object-hash')
let exampleObject = {
"@context": "http://schema.org",
"@type": "Book",
"copyrightHolder": {
"@type": "Organization",
"name": "Holt, Rinehart and Winston"
},
"copyrightYear": "2007",
"description": "NIMAC-sourced textbook",
"genre": "Educational Materials",
"inLanguage": "en-US",
"isFamilyFriendly": "true",
"isbn": "9780030426599",
"name": "Holt Physical Science",
"numberOfPages": "598",
"publisher": {
"@type": "Organization",
"name": "Holt, Rinehart and Winston"
}
}
objectHash.hex(exampleObject)
objectHash(exampleObject)
API
objectHash(obj)
This takes an ordinary object and will deterministically hash it via blake2b. It returns a Uint8Array by default.
.hex(obj)
This takes an ordinary object and will deterministically hash it via blake2b. Unlike the function above, it returns it as a hex string.
Installation
$ npm install cyclical-object-hash
License
MIT