comfygure icon indicating copy to clipboard operation
comfygure copied to clipboard

Remove the `object-hash` dependency from the API

Open Kmaschta opened this issue 7 years ago • 1 comments

Rationale

For now, we use object-hash to get a hash of configuration version. We want to remove this dependency and write our own hashing function.

Details

Here is an example of the new API:

const currentVersion = {
    hash: '000000000000000000000000', // Already computed unique hash
    entries: {
        A: 'value A',
    },
};

const newVersion = {
    // ...
    entries: {
        A: 'value A',
        B: 'value B',
    },
};

const hash = getHash(newVersion.entries, currentVersion.hash); // Should be a unique hash
// or, if there is no precedent version (for example for the first version)
const hash = getHash(newVersion.entries);

The idea is to concatenate the following values:

[PRECEDENT VERSION HASH] + [ENTRY KEY 0] + [ENTRY VALUE 0] + [ENTRY KEY 1] ...
eg: 000000000000000000000000 A value A B value B

or, for no precedent version

[ENTRY KEY 0] + [ENTRY VALUE 0] + [ENTRY KEY 1] +  [ENTRY VALUE 1] ...

Then, get a unique hash of this character chain. You can use the native Node.JS crypto module to find the better way to do this.

Requirements

  • The code MUST be tested
  • The transpiled code should be compatible with Node 6 (see node.green)
  • The hash MUST be unique for two different strings getHash({ a: 1 }) !== getHash({ b: 2 })
  • The hash MUST be the same for the same string getHash({ a: 1 }) !== getHash({ a: 1 })

It is highly recommended to write the tests first and then code the function. Feel free to ask your questions here!

Kmaschta avatar Feb 28 '17 14:02 Kmaschta

Changing the way we compute hashes would be a breaking change now

Kmaschta avatar Apr 08 '20 08:04 Kmaschta