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