@mcaptcha/pow-wasm
Advanced tools
Comparing version 0.1.0-alpha-1 to 0.1.0-rc1
@@ -7,3 +7,3 @@ { | ||
"description": "WASM port of the proof-of-work library used in mCaptcha ", | ||
"version": "0.1.0-alpha-1", | ||
"version": "0.1.0-rc1", | ||
"license": "MIT OR Apache-2.0", | ||
@@ -19,4 +19,4 @@ "repository": { | ||
"pow_wasm.d.ts", | ||
"LICENSE_APACHE", | ||
"LICENSE_MIT" | ||
"LICENSE_MIT", | ||
"LICENSE_APACHE" | ||
], | ||
@@ -26,3 +26,6 @@ "module": "pow_wasm.js", | ||
"types": "pow_wasm.d.ts", | ||
"sideEffects": false, | ||
"sideEffects": [ | ||
"./pow_wasm.js", | ||
"./snippets/*" | ||
], | ||
"keywords": [ | ||
@@ -29,0 +32,0 @@ "pow", |
@@ -1,13 +0,58 @@ | ||
import * as wasm from './pow_wasm_bg.wasm'; | ||
let wasm; | ||
export function __wbg_set_wasm(val) { | ||
wasm = val; | ||
} | ||
let WASM_VECTOR_LEN = 0; | ||
let cachegetUint8Memory0 = null; | ||
const heap = new Array(128).fill(undefined); | ||
heap.push(undefined, null, true, false); | ||
let heap_next = heap.length; | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
heap[idx] = obj; | ||
return idx; | ||
} | ||
function getObject(idx) { return heap[idx]; } | ||
function dropObject(idx) { | ||
if (idx < 132) return; | ||
heap[idx] = heap_next; | ||
heap_next = idx; | ||
} | ||
function takeObject(idx) { | ||
const ret = getObject(idx); | ||
dropObject(idx); | ||
return ret; | ||
} | ||
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; | ||
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); | ||
cachedTextDecoder.decode(); | ||
let cachedUint8Memory0 = null; | ||
function getUint8Memory0() { | ||
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) { | ||
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer); | ||
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { | ||
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); | ||
} | ||
return cachegetUint8Memory0; | ||
return cachedUint8Memory0; | ||
} | ||
function getStringFromWasm0(ptr, len) { | ||
ptr = ptr >>> 0; | ||
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); | ||
} | ||
let WASM_VECTOR_LEN = 0; | ||
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; | ||
@@ -34,3 +79,3 @@ | ||
const buf = cachedTextEncoder.encode(arg); | ||
const ptr = malloc(buf.length); | ||
const ptr = malloc(buf.length, 1) >>> 0; | ||
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); | ||
@@ -42,3 +87,3 @@ WASM_VECTOR_LEN = buf.length; | ||
let len = arg.length; | ||
let ptr = malloc(len); | ||
let ptr = malloc(len, 1) >>> 0; | ||
@@ -59,3 +104,3 @@ const mem = getUint8Memory0(); | ||
} | ||
ptr = realloc(ptr, len, len = offset + arg.length * 3); | ||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; | ||
const view = getUint8Memory0().subarray(ptr + offset, ptr + len); | ||
@@ -71,19 +116,10 @@ const ret = encodeString(arg, view); | ||
let cachegetInt32Memory0 = null; | ||
let cachedInt32Memory0 = null; | ||
function getInt32Memory0() { | ||
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { | ||
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); | ||
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { | ||
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); | ||
} | ||
return cachegetInt32Memory0; | ||
return cachedInt32Memory0; | ||
} | ||
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; | ||
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); | ||
cachedTextDecoder.decode(); | ||
function getStringFromWasm0(ptr, len) { | ||
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); | ||
} | ||
/** | ||
@@ -94,3 +130,3 @@ * generate proof-of-work | ||
* use pow_wasm::*; | ||
* use pow_sha256::*; | ||
* use mcaptcha_pow_sha256::*; | ||
* | ||
@@ -106,3 +142,3 @@ * | ||
* // currently gen_pow() returns a JSON formated string to better communicate | ||
* // with JavaScript. See [PoW<T>][pow_sha256::PoW] for schema | ||
* // with JavaScript. See [PoW<T>][mcaptcha_pow_sha256::PoW] for schema | ||
* let serialised_work = gen_pow(SALT.into(), PHRASE.into(), DIFFICULTY); | ||
@@ -130,17 +166,84 @@ * | ||
export function gen_pow(salt, phrase, difficulty_factor) { | ||
let deferred3_0; | ||
let deferred3_1; | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
var ptr0 = passStringToWasm0(salt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
var ptr1 = passStringToWasm0(phrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len1 = WASM_VECTOR_LEN; | ||
const ptr0 = passStringToWasm0(salt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ptr1 = passStringToWasm0(phrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
const len1 = WASM_VECTOR_LEN; | ||
wasm.gen_pow(retptr, ptr0, len0, ptr1, len1, difficulty_factor); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
deferred3_0 = r0; | ||
deferred3_1 = r1; | ||
return getStringFromWasm0(r0, r1); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
wasm.__wbindgen_free(r0, r1); | ||
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); | ||
} | ||
} | ||
let stack_pointer = 128; | ||
function addBorrowedObject(obj) { | ||
if (stack_pointer == 1) throw new Error('out of js stack'); | ||
heap[--stack_pointer] = obj; | ||
return stack_pointer; | ||
} | ||
/** | ||
* @param {string} salt | ||
* @param {string} phrase | ||
* @param {number} difficulty_factor | ||
* @param {number} step | ||
* @param {Function} f | ||
* @returns {string} | ||
*/ | ||
export function stepped_gen_pow(salt, phrase, difficulty_factor, step, f) { | ||
let deferred3_0; | ||
let deferred3_1; | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passStringToWasm0(salt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ptr1 = passStringToWasm0(phrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
const len1 = WASM_VECTOR_LEN; | ||
wasm.stepped_gen_pow(retptr, ptr0, len0, ptr1, len1, difficulty_factor, step, addBorrowedObject(f)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
deferred3_0 = r0; | ||
deferred3_1 = r1; | ||
return getStringFromWasm0(r0, r1); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
heap[stack_pointer++] = undefined; | ||
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); | ||
} | ||
} | ||
function handleError(f, args) { | ||
try { | ||
return f.apply(this, args); | ||
} catch (e) { | ||
wasm.__wbindgen_exn_store(addHeapObject(e)); | ||
} | ||
} | ||
export function __wbindgen_bigint_from_u128(arg0, arg1) { | ||
const ret = BigInt.asUintN(64, arg0) << BigInt(64) | BigInt.asUintN(64, arg1); | ||
return addHeapObject(ret); | ||
}; | ||
export function __wbindgen_object_drop_ref(arg0) { | ||
takeObject(arg0); | ||
}; | ||
export function __wbg_call_01734de55d61e11d() { return handleError(function (arg0, arg1, arg2) { | ||
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); | ||
return addHeapObject(ret); | ||
}, arguments) }; | ||
export function __wbindgen_throw(arg0, arg1) { | ||
throw new Error(getStringFromWasm0(arg0, arg1)); | ||
}; | ||
@@ -8,3 +8,3 @@ /* tslint:disable */ | ||
* use pow_wasm::*; | ||
* use pow_sha256::*; | ||
* use mcaptcha_pow_sha256::*; | ||
* | ||
@@ -20,3 +20,3 @@ * | ||
* // currently gen_pow() returns a JSON formated string to better communicate | ||
* // with JavaScript. See [PoW<T>][pow_sha256::PoW] for schema | ||
* // with JavaScript. See [PoW<T>][mcaptcha_pow_sha256::PoW] for schema | ||
* let serialised_work = gen_pow(SALT.into(), PHRASE.into(), DIFFICULTY); | ||
@@ -44,1 +44,10 @@ * | ||
export function gen_pow(salt: string, phrase: string, difficulty_factor: number): string; | ||
/** | ||
* @param {string} salt | ||
* @param {string} phrase | ||
* @param {number} difficulty_factor | ||
* @param {number} step | ||
* @param {Function} f | ||
* @returns {string} | ||
*/ | ||
export function stepped_gen_pow(salt: string, phrase: string, difficulty_factor: number, step: number, f: Function): string; |
import * as wasm from "./pow_wasm_bg.wasm"; | ||
export * from "./pow_wasm_bg.js"; | ||
import { __wbg_set_wasm } from "./pow_wasm_bg.js"; | ||
__wbg_set_wasm(wasm); | ||
export * from "./pow_wasm_bg.js"; |
@@ -92,1 +92,19 @@ <div align="center"> | ||
for small code size. | ||
## Funding | ||
### NLnet | ||
<div align="center"> | ||
<img | ||
height="150px" | ||
alt="NLnet NGIZero logo" | ||
src="./static/third-party/NGIZero-green.hex.svg" | ||
/> | ||
</div> | ||
<br /> | ||
2023 development is funded through the [NGI0 Entrust | ||
Fund](https://nlnet.nl/entrust), via [NLnet](https://nlnet.nl/). Please | ||
see [here](https://nlnet.nl/project/mCaptcha/) for more details. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
258
110
83680