Merge branch 'pow-worker' into 'main'
Add PowWorker to mine Nostr events off the main thread See merge request soapbox-pub/soapbox!2863
This commit is contained in:
commit
eb52007609
4 changed files with 25 additions and 0 deletions
|
@ -99,6 +99,7 @@
|
|||
"bowser": "^2.11.0",
|
||||
"browserslist": "^4.16.6",
|
||||
"clsx": "^2.0.0",
|
||||
"comlink": "^4.4.1",
|
||||
"core-js": "^3.27.2",
|
||||
"cryptocurrency-icons": "^0.18.1",
|
||||
"cssnano": "^6.0.0",
|
||||
|
|
9
src/workers.ts
Normal file
9
src/workers.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import * as Comlink from 'comlink';
|
||||
|
||||
import type { PowWorker } from './workers/pow.worker';
|
||||
|
||||
const powWorker = Comlink.wrap<typeof PowWorker>(
|
||||
new Worker(new URL('./workers/pow.worker.ts', import.meta.url), { type: 'module' }),
|
||||
);
|
||||
|
||||
export { powWorker };
|
10
src/workers/pow.worker.ts
Normal file
10
src/workers/pow.worker.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import * as Comlink from 'comlink';
|
||||
import { nip13, type UnsignedEvent } from 'nostr-tools';
|
||||
|
||||
export const PowWorker = {
|
||||
mine<K extends number>(event: UnsignedEvent<K>, difficulty: number) {
|
||||
return nip13.minePow(event, difficulty);
|
||||
},
|
||||
};
|
||||
|
||||
Comlink.expose(PowWorker);
|
|
@ -3566,6 +3566,11 @@ combined-stream@^1.0.8:
|
|||
dependencies:
|
||||
delayed-stream "~1.0.0"
|
||||
|
||||
comlink@^4.4.1:
|
||||
version "4.4.1"
|
||||
resolved "https://registry.yarnpkg.com/comlink/-/comlink-4.4.1.tgz#e568b8e86410b809e8600eb2cf40c189371ef981"
|
||||
integrity sha512-+1dlx0aY5Jo1vHy/tSsIGpSkN4tS9rZSW8FIhG0JH/crs9wwweswIo/POr451r7bZww3hFbPAKnTpimzL/mm4Q==
|
||||
|
||||
commander@^2.20.0:
|
||||
version "2.20.3"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
|
||||
|
|
Loading…
Reference in a new issue