*Add hashQuery utility function
This commit is contained in:
parent
271a0c2911
commit
144e19e635
14
src/util.ts
14
src/util.ts
|
@ -3,6 +3,8 @@ import stringify from "json-stringify-deterministic";
|
||||||
import type { RPCRequest, RPCResponse } from "@lumeweb/relay-types";
|
import type { RPCRequest, RPCResponse } from "@lumeweb/relay-types";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import crypto from "hypercore-crypto";
|
import crypto from "hypercore-crypto";
|
||||||
|
// @ts-ignore
|
||||||
|
import sodium from "sodium-universal";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
|
|
||||||
export function isPromise(obj: Promise<any>) {
|
export function isPromise(obj: Promise<any>) {
|
||||||
|
@ -91,3 +93,15 @@ export function validateTimestampedResponse(
|
||||||
): boolean {
|
): boolean {
|
||||||
return validateResponse(relay, response, true);
|
return validateResponse(relay, response, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hashQuery(query: RPCRequest): string {
|
||||||
|
const clonedQuery: RPCRequest = {
|
||||||
|
module: query.module,
|
||||||
|
method: query.method,
|
||||||
|
data: query.data,
|
||||||
|
};
|
||||||
|
const queryHash = Buffer.allocUnsafe(32);
|
||||||
|
sodium.crypto_generichash(queryHash, Buffer.from(stringify(clonedQuery)));
|
||||||
|
|
||||||
|
return queryHash.toString("hex");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue