From c8c19b77a69cbb8bef4542c38ff31c6dac4ebea8 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 4 Dec 2022 01:11:05 -0500 Subject: [PATCH] *Switch to json-stringify-deterministic --- src/modules/rpc/cache.ts | 6 +++--- src/modules/rpc/server.ts | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/modules/rpc/cache.ts b/src/modules/rpc/cache.ts index bd5218f..3984c49 100644 --- a/src/modules/rpc/cache.ts +++ b/src/modules/rpc/cache.ts @@ -11,7 +11,7 @@ import b4a from "b4a"; import { get as getSwarm } from "../swarm"; import { RPCServer } from "./server"; // @ts-ignore -import orderedJSON from "ordered-json"; +import jsonStringify from "json-stringify-deterministic"; // @ts-ignore import crypto from "hypercore-crypto"; import NodeCache from "node-cache"; @@ -51,7 +51,7 @@ export class RPCCache extends EventEmitter { const updated = item.value.updated; // @ts-ignore const data = item.value[field]; - const json = orderedJSON.stringify(data); + const json = jsonStringify(data); return this.server.signData(`${updated}${json}`); } @@ -61,7 +61,7 @@ export class RPCCache extends EventEmitter { const updated = item.value.updated; // @ts-ignore const data = item.value[field]; - const json = orderedJSON.stringify(data); + const json = jsonStringify(data); try { if ( diff --git a/src/modules/rpc/server.ts b/src/modules/rpc/server.ts index e86dcee..41a1407 100644 --- a/src/modules/rpc/server.ts +++ b/src/modules/rpc/server.ts @@ -15,9 +15,10 @@ import c from "compact-encoding"; // @ts-ignore import crypto from "hypercore-crypto"; // @ts-ignore -import orderedJSON from "ordered-json"; import { Mutex } from "async-mutex"; import { RPCCache } from "./cache"; +// @ts-ignore +import jsonStringify from "json-stringify-deterministic"; const sodium = require("sodium-universal"); let server: RPCServer; @@ -55,7 +56,7 @@ export class RPCServer extends EventEmitter { const queryHash = Buffer.allocUnsafe(32); sodium.crypto_generichash( queryHash, - Buffer.from(orderedJSON.stringify(clonedQuery)) + Buffer.from(jsonStringify(clonedQuery)) ); return queryHash.toString("hex"); } @@ -128,7 +129,7 @@ export class RPCServer extends EventEmitter { public signData(data: any): string { let raw = data; if (typeof data !== "string") { - raw = orderedJSON.stringify(data); + raw = jsonStringify(data); } return crypto