cyclical-object-hash

0.2.0 • Public • Published

cylical-object-hash stability

npm version downloads js-standard-style

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:

  1. Did not have a deterministic stringification step.
  2. Broke on cyclical references.
  3. Used an insecure hashing algorithm such as md5 or sha1 instead of blake2b.
  4. Limited to Node.js
  5. 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)
// '79fc74f0dd70d955a7d61271d09f0806aadff55ea770621cbb9a9194e9b9053cc59c3ca669b273dd0fb1a0efc4617d2c9824a339ad0200fdbd231b549f946027'
 
objectHash(exampleObject)
// Uint8Array 
// Blake2b { digestLength: 64, finalized: false, pointer: 64 }

API

objectHash(obj, [key], [salt], [personal])

This takes an ordinary object and will deterministically hash it via blake2b. It returns a Uint8Array by default. All optionals arguments such as key, salt, and personal will be passed to blake2b.

.hex(obj, [key], [salt], [personal])

This takes an ordinary object and will deterministically hash it via blake2b. Unlike the function above, it returns it as a hex string. All optionals arguments such as key, salt, and personal will be passed to blake2b.

Installation

$ npm install cyclical-object-hash

License

MIT

Dependents (1)

Package Sidebar

Install

npm i cyclical-object-hash

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

7 kB

Total Files

6

Last publish

Collaborators

  • jdvorak