import { createHmac } from 'crypto'; import { canonicalizeJSON } from './json'; const SECRET = 'revision IDs suck'; function _addRevisionId(aDoc: any): any { // create the content to produce the SHA256 on const normDoc = canonicalizeJSON(aDoc); const data = JSON.stringify(normDoc); // produce the revision ID const revId = createHmac('sha256', SECRET) .update(data) .digest('base64'); // update normDoc.rev = `0815-${revId}`; // ok return normDoc; } export { _addRevisionId as addRevisionId };