ffjavascript
Advanced tools
Comparing version 0.2.63 to 0.3.0
{ | ||
"name": "ffjavascript", | ||
"type": "module", | ||
"version": "0.2.63", | ||
"version": "0.3.0", | ||
"description": "Finite Field Library in Javascript", | ||
@@ -6,0 +6,0 @@ "main": "./build/main.cjs", |
# ffjavascript | ||
Finite Field Library in Javascript | ||
This package is tested to work in the following environments: | ||
- **NodeJS** | ||
- **Browser** | ||
- **Chrome Extension** | ||
- **Metamask Snaps (SES)** | ||
## Knows Issues | ||
### Webpack Configuration | ||
If you're using the `ffjavascript` package in a webpack project (Next.js/Angular), you may need to disable the `splitChunks` option in your webpack configuration. | ||
```javascript | ||
module.exports = { | ||
// ... | ||
optimization: { | ||
splitChunks: false, | ||
}, | ||
// ... | ||
}; | ||
``` | ||
## License | ||
ffjavascript is part of the iden3 project copyright 2020 0KIMS association and published with GPL-3 license. Please check the COPYING file for more details. | ||
@@ -25,2 +25,3 @@ import commonJS from "@rollup/plugin-commonjs"; | ||
"process.browser": true, | ||
"import Worker from \"web-worker\"": "", | ||
/* | ||
@@ -27,0 +28,0 @@ Because of some frontend frameworks uses monkey patching to track UI changes or other purposes (including Angular, AngularJS, Ember.js, JQuery...), it's important to make sure that the thread function is not modified by the framework and passing in the web worker as it is. |
@@ -195,3 +195,3 @@ /* | ||
eval(p,x) { | ||
evaluate(p,x) { | ||
const F = this.F; | ||
@@ -227,3 +227,3 @@ if (p.length == 0) return F.zero; | ||
this.F.mul( | ||
this.F.inv(this.eval(mpol, points[i][0])), | ||
this.F.inv(this.evaluate(mpol, points[i][0])), | ||
points[i][1]); | ||
@@ -230,0 +230,0 @@ mpol = this.mulScalar(mpol, factor); |
@@ -41,15 +41,19 @@ /* | ||
function stringToBase64(str) { | ||
if (process.browser) { | ||
return globalThis.btoa(str); | ||
let workerSource; | ||
const threadStr = `(${thread.toString()})(self)`; | ||
if(process.browser) { | ||
if(globalThis?.Blob) { | ||
const threadBytes= new TextEncoder().encode(threadStr); | ||
const workerBlob = new Blob([threadBytes], { type: "application/javascript" }) ; | ||
workerSource = URL.createObjectURL(workerBlob); | ||
} else { | ||
return Buffer.from(str).toString("base64"); | ||
workerSource = "data:application/javascript;base64," + globalThis.btoa(threadStr); | ||
} | ||
} else { | ||
workerSource = "data:application/javascript;base64," + Buffer.from(threadStr).toString("base64"); | ||
} | ||
const threadSource = stringToBase64("(" + thread.toString() + ")(self)"); | ||
const workerSource = "data:application/javascript;base64," + threadSource; | ||
export default async function buildThreadManager(wasm, singleThread) { | ||
@@ -69,3 +73,7 @@ const tm = new ThreadManager(); | ||
}); | ||
if(process.browser && !globalThis?.Worker) { | ||
singleThread = true; | ||
} | ||
tm.singleThread = singleThread; | ||
@@ -84,3 +92,2 @@ tm.initalPFree = tm.u32[0]; // Save the Pointer to free space. | ||
if (singleThread) { | ||
@@ -102,7 +109,7 @@ tm.code = wasm.code; | ||
if (process.browser) { | ||
if (typeof navigator === "object" && navigator.hardwareConcurrency) { | ||
concurrency = navigator.hardwareConcurrency; | ||
} | ||
if (typeof navigator === "object" && navigator.hardwareConcurrency) { | ||
concurrency = navigator.hardwareConcurrency; | ||
} | ||
} else { | ||
concurrency = os.cpus().length; | ||
concurrency = os.cpus().length; | ||
} | ||
@@ -159,3 +166,3 @@ | ||
class ThreadManager { | ||
export class ThreadManager { | ||
constructor() { | ||
@@ -162,0 +169,0 @@ this.actionQueue = []; |
@@ -131,3 +131,3 @@ /* | ||
const p = [PF.F.neg(PF.F.e(2)), PF.F.e(1)]; | ||
const v = PF.eval(p, PF.F.e(2)); | ||
const v = PF.evaluate(p, PF.F.e(2)); | ||
assert(PF.F.eq(v, PF.F.e(0))); | ||
@@ -138,3 +138,3 @@ }); | ||
const p = [PF.F.e(1), PF.F.e(2), PF.F.e(3)]; | ||
const v = PF.eval(p, PF.F.e(2)); | ||
const v = PF.evaluate(p, PF.F.e(2)); | ||
assert(PF.F.eq(v, PF.F.e(17))); | ||
@@ -153,3 +153,3 @@ }); | ||
for (let i=0; i<points.length; i++) { | ||
const v = PF.eval(p, points[i][0]); | ||
const v = PF.evaluate(p, points[i][0]); | ||
assert(PF.F.eq(v, points[i][1])); | ||
@@ -170,3 +170,3 @@ } | ||
for (let i=0; i<points.length; i++) { | ||
const v = PF.eval(p, points[i][0]); | ||
const v = PF.evaluate(p, points[i][0]); | ||
assert(PF.F.eq(v, points[i][1])); | ||
@@ -218,3 +218,3 @@ } | ||
for (let i=0; i<a.length; i++) { | ||
const s = PF.eval(p, PF.oneRoot(8,i)); | ||
const s = PF.evaluate(p, PF.oneRoot(8,i)); | ||
assert(PF.F.eq(s, a[i])); | ||
@@ -221,0 +221,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
997141
51
26230
31
1