call proof generator from within a web worker

This commit is contained in:
realaravinth
2021-12-02 14:24:53 +05:30
parent ab77eed91c
commit 0126dc0e3a
8 changed files with 109 additions and 46 deletions

View File

@@ -10,27 +10,14 @@
*/
import { gen_pow } from "@mcaptcha/pow-wasm";
import { PoWConfig } from "./fetchPoWConfig";
import * as CONST from "./const";
export type Work = {
result: string;
nonce: number;
string: string;
key: string;
};
type WasmWork = {
result: string;
nonce: number;
};
import { WasmWork, PoWConfig } from "./types";
/**
* proove work
* @param {PoWConfig} config - the proof-of-work configuration using which
* work needs to be computed
* */
const prove = async (config: PoWConfig): Promise<Work> => {
const prove = (config: PoWConfig): WasmWork => {
const proofString = gen_pow(
config.salt,
config.string,
@@ -38,14 +25,7 @@ const prove = async (config: PoWConfig): Promise<Work> => {
);
const proof: WasmWork = JSON.parse(proofString);
const res: Work = {
key: CONST.sitekey(),
string: config.string,
nonce: proof.nonce,
result: proof.result,
};
return res;
return proof;
};
export default prove;