Compare commits
No commits in common. "a87660b678f8b890ea574f11ec4c9ccb54fbff9b" and "616b74a82098e2b3a7ef3cb4039a5f233dff03e3" have entirely different histories.
a87660b678
...
616b74a820
|
@ -41,7 +41,6 @@
|
|||
"fetch-blob": "https://github.com/LumeWeb/fetch-blob.git",
|
||||
"hyperswarm": "^3.0.4",
|
||||
"json-stable-stringify": "^1.0.1",
|
||||
"json-stringify-deterministic": "^1.0.7",
|
||||
"libskynet": "https://github.com/LumeWeb/libskynet.git",
|
||||
"libskynetnode": "https://github.com/LumeWeb/libskynetnode.git",
|
||||
"loady": "https://github.com/LumeWeb/loady.git",
|
||||
|
@ -50,6 +49,7 @@
|
|||
"node-cache": "^5.1.2",
|
||||
"node-cron": "^3.0.1",
|
||||
"node-fetch": "2",
|
||||
"ordered-json": "^0.1.1",
|
||||
"promise-retry": "^2.0.1",
|
||||
"protomux": "^3.4.0",
|
||||
"protomux-rpc": "^1.3.0",
|
||||
|
|
|
@ -4,7 +4,6 @@ import {
|
|||
PluginAPI,
|
||||
RPCBroadcastRequest,
|
||||
RPCBroadcastResponse,
|
||||
RPCCacheItem,
|
||||
RPCRequest,
|
||||
RPCResponse,
|
||||
} from "@lumeweb/relay-types";
|
||||
|
@ -59,8 +58,8 @@ const plugin: Plugin = {
|
|||
|
||||
return {
|
||||
data: true,
|
||||
...cache.get<RPCCacheItem>(req)?.value,
|
||||
signature: cache.get<RPCCacheItem>(req)?.signature,
|
||||
...cache[req]?.value,
|
||||
signature: cache[req]?.signature,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
@ -93,13 +92,6 @@ const plugin: Plugin = {
|
|||
throw new Error("relays required");
|
||||
}
|
||||
|
||||
if (
|
||||
req?.request?.module === "rpc" &&
|
||||
req?.request?.method === "broadcast_request"
|
||||
) {
|
||||
throw new Error("recursive broadcast_request calls are not allowed");
|
||||
}
|
||||
|
||||
let resp = await broadcastRequest(req.request, req.relays);
|
||||
|
||||
const result: RPCBroadcastResponse = {
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
import EventEmitter from "events";
|
||||
import DHTCache from "@lumeweb/dht-cache";
|
||||
import { RPCCacheItem, RPCRequest, RPCResponse } from "@lumeweb/relay-types";
|
||||
import {
|
||||
RPCCacheData,
|
||||
RPCCacheItem,
|
||||
RPCRequest,
|
||||
RPCResponse,
|
||||
} from "@lumeweb/relay-types";
|
||||
import { getRpcByPeer } from "../rpc";
|
||||
import b4a from "b4a";
|
||||
import { get as getSwarm } from "../swarm";
|
||||
import { RPCServer } from "./server";
|
||||
// @ts-ignore
|
||||
import jsonStringify from "json-stringify-deterministic";
|
||||
import orderedJSON from "ordered-json";
|
||||
// @ts-ignore
|
||||
import crypto from "hypercore-crypto";
|
||||
import NodeCache from "node-cache";
|
||||
|
@ -43,11 +50,8 @@ export class RPCCache extends EventEmitter {
|
|||
const field = item.value.signedField || "data";
|
||||
const updated = item.value.updated;
|
||||
// @ts-ignore
|
||||
let json = item.value[field];
|
||||
|
||||
if (typeof json !== "string") {
|
||||
json = jsonStringify(json);
|
||||
}
|
||||
const data = item.value[field];
|
||||
const json = orderedJSON.stringify(data);
|
||||
|
||||
return this.server.signData(`${updated}${json}`);
|
||||
}
|
||||
|
@ -56,11 +60,8 @@ export class RPCCache extends EventEmitter {
|
|||
const field = item.value.signedField || "data";
|
||||
const updated = item.value.updated;
|
||||
// @ts-ignore
|
||||
let json = item.value[field];
|
||||
|
||||
if (typeof json !== "string") {
|
||||
json = jsonStringify(json);
|
||||
}
|
||||
const data = item.value[field];
|
||||
const json = orderedJSON.stringify(data);
|
||||
|
||||
try {
|
||||
if (
|
||||
|
|
|
@ -15,10 +15,9 @@ 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;
|
||||
|
@ -56,7 +55,7 @@ export class RPCServer extends EventEmitter {
|
|||
const queryHash = Buffer.allocUnsafe(32);
|
||||
sodium.crypto_generichash(
|
||||
queryHash,
|
||||
Buffer.from(jsonStringify(clonedQuery))
|
||||
Buffer.from(orderedJSON.stringify(clonedQuery))
|
||||
);
|
||||
return queryHash.toString("hex");
|
||||
}
|
||||
|
@ -129,7 +128,7 @@ export class RPCServer extends EventEmitter {
|
|||
public signData(data: any): string {
|
||||
let raw = data;
|
||||
if (typeof data !== "string") {
|
||||
raw = jsonStringify(data);
|
||||
raw = orderedJSON.stringify(data);
|
||||
}
|
||||
|
||||
return crypto
|
||||
|
@ -148,7 +147,7 @@ export class RPCServer extends EventEmitter {
|
|||
|
||||
if (cachedRequest) {
|
||||
this.getRequestLock(request)?.release();
|
||||
return { ...cachedRequest.value, signature: cachedRequest.signature };
|
||||
return cachedRequest.value;
|
||||
}
|
||||
|
||||
let method = this.getMethodByRequest(request);
|
||||
|
|
|
@ -558,7 +558,7 @@
|
|||
|
||||
"@lumeweb/relay-types@https://git.lumeweb.com/LumeWeb/relay-types.git":
|
||||
version "0.1.0"
|
||||
resolved "https://git.lumeweb.com/LumeWeb/relay-types.git#298d043b3924bbe427e047d1c02db7c239fdadac"
|
||||
resolved "https://git.lumeweb.com/LumeWeb/relay-types.git#33b87a1075441043e7e0219264d66f6610864685"
|
||||
|
||||
"@msgpackr-extract/msgpackr-extract-darwin-arm64@2.2.0":
|
||||
version "2.2.0"
|
||||
|
@ -2300,11 +2300,6 @@ json-stable-stringify@^1.0.1:
|
|||
dependencies:
|
||||
jsonify "^0.0.1"
|
||||
|
||||
json-stringify-deterministic@^1.0.7:
|
||||
version "1.0.7"
|
||||
resolved "https://registry.yarnpkg.com/json-stringify-deterministic/-/json-stringify-deterministic-1.0.7.tgz#b5e37549581ac8ec8439ca7e9b746d23da56ac20"
|
||||
integrity sha512-VGSL+V2s/AqL25ixC4459kAlyIYsS+VUJ3owa/FKr4ZeMJeTZERlzGXJ2xWIHcTfd/fwgTvNyh7/RWMDvkFciw==
|
||||
|
||||
json-stringify-safe@^5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
|
||||
|
|
Loading…
Reference in New Issue