*Switch to json-stringify-deterministic

This commit is contained in:
Derrick Hammer 2022-12-04 01:11:05 -05:00
parent d7897af137
commit c8c19b77a6
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 7 additions and 6 deletions

View File

@ -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 (

View File

@ -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