*Switch to json-stringify-deterministic
This commit is contained in:
parent
d7897af137
commit
c8c19b77a6
|
@ -11,7 +11,7 @@ import b4a from "b4a";
|
||||||
import { get as getSwarm } from "../swarm";
|
import { get as getSwarm } from "../swarm";
|
||||||
import { RPCServer } from "./server";
|
import { RPCServer } from "./server";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import orderedJSON from "ordered-json";
|
import jsonStringify from "json-stringify-deterministic";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import crypto from "hypercore-crypto";
|
import crypto from "hypercore-crypto";
|
||||||
import NodeCache from "node-cache";
|
import NodeCache from "node-cache";
|
||||||
|
@ -51,7 +51,7 @@ export class RPCCache extends EventEmitter {
|
||||||
const updated = item.value.updated;
|
const updated = item.value.updated;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const data = item.value[field];
|
const data = item.value[field];
|
||||||
const json = orderedJSON.stringify(data);
|
const json = jsonStringify(data);
|
||||||
|
|
||||||
return this.server.signData(`${updated}${json}`);
|
return this.server.signData(`${updated}${json}`);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ export class RPCCache extends EventEmitter {
|
||||||
const updated = item.value.updated;
|
const updated = item.value.updated;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const data = item.value[field];
|
const data = item.value[field];
|
||||||
const json = orderedJSON.stringify(data);
|
const json = jsonStringify(data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -15,9 +15,10 @@ import c from "compact-encoding";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import crypto from "hypercore-crypto";
|
import crypto from "hypercore-crypto";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import orderedJSON from "ordered-json";
|
|
||||||
import { Mutex } from "async-mutex";
|
import { Mutex } from "async-mutex";
|
||||||
import { RPCCache } from "./cache";
|
import { RPCCache } from "./cache";
|
||||||
|
// @ts-ignore
|
||||||
|
import jsonStringify from "json-stringify-deterministic";
|
||||||
|
|
||||||
const sodium = require("sodium-universal");
|
const sodium = require("sodium-universal");
|
||||||
let server: RPCServer;
|
let server: RPCServer;
|
||||||
|
@ -55,7 +56,7 @@ export class RPCServer extends EventEmitter {
|
||||||
const queryHash = Buffer.allocUnsafe(32);
|
const queryHash = Buffer.allocUnsafe(32);
|
||||||
sodium.crypto_generichash(
|
sodium.crypto_generichash(
|
||||||
queryHash,
|
queryHash,
|
||||||
Buffer.from(orderedJSON.stringify(clonedQuery))
|
Buffer.from(jsonStringify(clonedQuery))
|
||||||
);
|
);
|
||||||
return queryHash.toString("hex");
|
return queryHash.toString("hex");
|
||||||
}
|
}
|
||||||
|
@ -128,7 +129,7 @@ export class RPCServer extends EventEmitter {
|
||||||
public signData(data: any): string {
|
public signData(data: any): string {
|
||||||
let raw = data;
|
let raw = data;
|
||||||
if (typeof data !== "string") {
|
if (typeof data !== "string") {
|
||||||
raw = orderedJSON.stringify(data);
|
raw = jsonStringify(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return crypto
|
return crypto
|
||||||
|
|
Loading…
Reference in New Issue