marmelab / comfygure

Encrypted and versioned configuration store built with collaboration in mind
https://marmelab.com/comfygure
MIT License
193 stars 6 forks source link

Remove the `object-hash` dependency from the API #3

Open Kmaschta opened 7 years ago

Kmaschta commented 7 years ago

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

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

Kmaschta commented 4 years ago

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