feat: POW miner

This commit is contained in:
2023-08-18 00:35:48 +01:00
parent 667518a2df
commit 2a851c442d
14 changed files with 209 additions and 40 deletions

View File

@ -1,12 +1,13 @@
import { ExternalStore, dedupe } from "@snort/shared";
import {
EventKind,
SystemInterface,
NostrPrefix,
encodeTLVEntries,
TLVEntryType,
TLVEntry,
decodeTLV,
PowWorker,
NostrEvent,
} from "@snort/system";
import { GiftWrapCache } from "Cache/GiftWrapCache";
import { UnwrappedGift } from "Db";
@ -103,16 +104,23 @@ export class Nip24ChatSystem extends ExternalStore<Array<Chat>> implements ChatS
}
return eb;
});
const messages = [];
const messages: Array<Promise<NostrEvent>> = [];
const powTarget = 4 * 4; // 4-char zero
for (const pt of participants) {
const recvSealedN = await pub.giftWrap(await pub.sealRumor(gossip, pt.id), pt.id);
const recvSealedN = pub.giftWrap(
await pub.sealRumor(gossip, pt.id),
pt.id,
powTarget,
new PowWorker("/pow.js")
);
messages.push(recvSealedN);
}
const sendSealed = await pub.giftWrap(await pub.sealRumor(gossip, pub.pubKey), pub.pubKey);
return [...messages, sendSealed];
messages.push(
pub.giftWrap(await pub.sealRumor(gossip, pub.pubKey), pub.pubKey, powTarget, new PowWorker("/pow.js"))
);
return await Promise.all(messages);
},
sendMessage: (ev, system: SystemInterface) => {
console.debug(ev);
sendMessage: (ev, system) => {
ev.forEach(a => system.BroadcastEvent(a));
},
} as Chat;

View File

@ -17,6 +17,10 @@ const config = {
import: "./src/service-worker.ts",
filename: "service-worker.js",
},
pow: {
import: require.resolve("@snort/system/dist/pow-worker.js"),
filename: "pow.js",
},
},
target: "browserslist",
mode: isProduction ? "production" : "development",
@ -24,12 +28,7 @@ const config = {
output: {
publicPath: "/",
path: path.resolve(__dirname, "build"),
filename: ({ runtime }) => {
if (runtime === "sw") {
return "[name].js";
}
return isProduction ? "[name].[chunkhash].js" : "[name].js";
},
filename: isProduction ? "[name].[chunkhash].js" : "[name].js",
clean: isProduction,
},
devServer: {
@ -50,7 +49,7 @@ const config = {
new HtmlWebpackPlugin({
template: "public/index.html",
favicon: "public/favicon.ico",
excludeChunks: ["sw"],
excludeChunks: ["sw", "pow"],
}),
new ESLintPlugin({
extensions: ["js", "mjs", "jsx", "ts", "tsx"],