feat: POW miner
This commit is contained in:
@ -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;
|
||||
|
@ -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"],
|
||||
|
Reference in New Issue
Block a user