Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the object-hash dependency from the API #3

Open
Kmaschta opened this issue Feb 28, 2017 · 1 comment
Open

Remove the object-hash dependency from the API #3

Kmaschta opened this issue Feb 28, 2017 · 1 comment

Comments

@Kmaschta
Copy link
Contributor

Kmaschta commented Feb 28, 2017

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 Kmaschta modified the milestone: 0.1 Mar 2, 2017
@Kmaschta Kmaschta modified the milestone: 0.1 Mar 29, 2017
@Kmaschta Kmaschta modified the milestones: 0.1, 0.2 Apr 28, 2017
@Kmaschta Kmaschta removed this from the 0.2 milestone Oct 3, 2018
@Kmaschta Kmaschta added this to the 2.0 milestone Apr 8, 2020
@Kmaschta
Copy link
Contributor Author

Kmaschta commented Apr 8, 2020

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

@Kmaschta Kmaschta removed this from the 2.0 milestone Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants