mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 01:55:40 +00:00
call proof generator from within a web worker
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user