diff --git a/fh-sync-js.d.ts b/fh-sync-js.d.ts index 97414c8..06470c5 100644 --- a/fh-sync-js.d.ts +++ b/fh-sync-js.d.ts @@ -317,6 +317,13 @@ declare module SyncClient { * @param handler - function that wraps underlying storage solution */ function setStorageAdapter(handler: (dataset_id:string, isSave: boolean, cb: any) => void); + + /** + * Allows to override default hashing method + * + * @param handler - function that wraps underlying hashing method + */ + function setHashMethod(method: () => any); } export = SyncClient; diff --git a/src/sync-client.js b/src/sync-client.js index 779716b..f26a2c0 100755 --- a/src/sync-client.js +++ b/src/sync-client.js @@ -527,7 +527,7 @@ var self = { }, generateHash: function(object) { - var hash = CryptoJS.SHA1(self.sortedStringify(object)); + var hash = self.getHashMethod(self.sortedStringify(object)); return hash.toString(); }, @@ -908,6 +908,11 @@ var self = { setStorageAdapter: function(adapter){ self.getStorageAdapter = adapter; }, + + /** Allow to set custom hasing method **/ + setHashMethod: function(method){ + self.getHashMethod = method; + }, getStorageAdapter: function(dataset_id, isSave, cb){ var onFail = function(msg, err){ @@ -920,6 +925,8 @@ var self = { }); }, + getHashMethod: CryptoJS.SHA1, + saveDataSet: function (dataset_id, cb) { self.getDataSet(dataset_id, function(dataset) { self.getStorageAdapter(dataset_id, true, function(err, storage){ @@ -1260,5 +1267,6 @@ module.exports = { clearCache: self.clearCache, setCloudHandler: self.setCloudHandler, doCloudCall: self.doCloudCall, - setStorageAdapter: self.setStorageAdapter + setStorageAdapter: self.setStorageAdapter, + setHashMethod: self.setHashMethod };