Skip to content

Commit ab1c957

Browse files
committed
Add hashDeterministicObject
1 parent 3948c37 commit ab1c957

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

package-lock.json

Lines changed: 2 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
"dotenv": "16.4.5",
188188
"embla-carousel-react": "8.1.8",
189189
"fast-deep-equal": "3.1.3",
190+
"fast-json-stable-stringify": "2.1.0",
190191
"fastify": "5.8.3",
191192
"fastify-favicon": "5.0.0",
192193
"fastify-plugin": "5.0.1",

packages/server/shared/src/lib/hash.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as crypto from 'crypto';
2+
import stringify from 'fast-json-stable-stringify';
23

34
function hashObject(
45
object: object,
@@ -8,6 +9,12 @@ function hashObject(
89
return crypto.createHash('sha256').update(jsonString).digest('hex');
910
}
1011

12+
function hashDeterministicObject(object: object): string {
13+
const jsonString = stringify(object);
14+
return crypto.createHash('sha256').update(jsonString).digest('hex');
15+
}
16+
1117
export const hashUtils = {
1218
hashObject,
19+
hashDeterministicObject,
1320
};

0 commit comments

Comments
 (0)