mirror of https://github.com/waku-org/js-rln.git
feat: generate and validate proofs
This commit is contained in:
parent
e0cd5f297a
commit
24c6c8e3d7
|
@ -3,7 +3,6 @@
|
|||
build
|
||||
dist
|
||||
node_modules
|
||||
src/**.js
|
||||
coverage
|
||||
*.log
|
||||
/tsconfig.tsbuildinfo
|
||||
|
|
104
README.md
104
README.md
|
@ -1,3 +1,105 @@
|
|||
# js-rln
|
||||
|
||||
Browser library providing the cryptographic functions for Waku RLN Relay https://rfc.vac.dev/spec/17/
|
||||
Browser library providing the cryptographic functions for Waku RLN Relay
|
||||
https://rfc.vac.dev/spec/17/
|
||||
|
||||
### Install
|
||||
```
|
||||
npm install @waku/rln
|
||||
|
||||
# or with yarn
|
||||
|
||||
yarn add @waku/rln
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
#### Initializing the library
|
||||
```js
|
||||
import * as rln from "@waku/rln";
|
||||
|
||||
const rlnInstance = wait rln.create();
|
||||
```
|
||||
|
||||
#### Generating RLN membership keypair
|
||||
```js
|
||||
let memKeys = rlnInstance.generateMembershipKey();
|
||||
```
|
||||
|
||||
|
||||
#### Adding membership keys into merkle tree
|
||||
```js
|
||||
rlnInstance.inserMember(memKeys.IDCommitment);
|
||||
```
|
||||
|
||||
#### Generating a proof
|
||||
```js
|
||||
// prepare the message
|
||||
const uint8Msg = Uint8Array.from("Hello World".split("").map(x => x.charCodeAt()));
|
||||
|
||||
// setting up the epoch (With 0s for the test)
|
||||
const epoch = new Uint8Array(32);
|
||||
|
||||
// generating a proof
|
||||
const proof = await rlnInstance.generateProof(uint8Msg, index, epoch, memKeys.IDKey)
|
||||
```
|
||||
|
||||
#### Verifying a proof
|
||||
```js
|
||||
try {
|
||||
// verify the proof
|
||||
const verifResult = rlnInstance.verifyProof(proof);
|
||||
console.log("Is proof verified?", verifResult ? "yes" : "no");
|
||||
} catch (err) {
|
||||
console.log("Invalid proof")
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Updating circuit, verification key and zkey
|
||||
The RLN specs defines the defaults. These values are fixed and should not
|
||||
change. If they do, this file needs to be updated in `resources.ts` which
|
||||
contains these values encoded in base64 in this format:
|
||||
|
||||
```
|
||||
const verification_key = "...";
|
||||
const circuit = "..."; // wasm file generated by circom
|
||||
const zkey = "...";
|
||||
export {verification_key, circuit, zkey};
|
||||
```
|
||||
|
||||
A tool like GNU's `base64` could be used to encode this data
|
||||
|
||||
### Updating zerokit
|
||||
1. Make sure you have nodejs installed and a C compiler
|
||||
2. Install wasm-pack
|
||||
```
|
||||
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
```
|
||||
3. Compile RLN for wasm
|
||||
```
|
||||
git clone https://github.com/vacp2p/zerokit
|
||||
cd zerokit/rln-wasm
|
||||
wasm-pack build --release
|
||||
```
|
||||
4. Copy `pkg/rln*` into `src/zerokit`
|
||||
|
||||
|
||||
## Bugs, Questions & Features
|
||||
|
||||
If you encounter any bug or would like to propose new features, feel free to [open an issue](https://github.com/waku-org/js-rln/issues/new/).
|
||||
|
||||
For more general discussion, help and latest news, join [Vac Discord](https://discord.gg/PQFdubGt6d) or [Telegram](https://t.me/vacp2p).
|
||||
|
||||
|
||||
## License
|
||||
Licensed and distributed under either of
|
||||
|
||||
* MIT license: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT
|
||||
|
||||
or
|
||||
|
||||
* Apache License, Version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
at your option. These files may not be copied, modified, or distributed except according to those terms.
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# RLN example app
|
||||
|
||||
```
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
Browse http://localhost:8080 and open the developer tools to see console logs
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Hello!</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Open the developer tools to see the generated proof and its validation</p>
|
||||
<script src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,52 @@
|
|||
import * as rln from "@waku/rln";
|
||||
|
||||
rln.create().then(async rlnInstance => {
|
||||
let memKeys = rlnInstance.generateMembershipKey();
|
||||
|
||||
//peer's index in the Merkle Tree
|
||||
const index = 5
|
||||
|
||||
// Create a Merkle tree with random members
|
||||
for (let i = 0; i < 10; i++) {
|
||||
if (i == index) {
|
||||
// insert the current peer's pk
|
||||
rlnInstance.inserMember(memKeys.IDCommitment);
|
||||
} else {
|
||||
// create a new key pair
|
||||
let memKeys = rlnInstance.generateMembershipKey(); // TODO: handle error
|
||||
rlnInstance.inserMember(memKeys.IDCommitment);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// prepare the message
|
||||
const uint8Msg = Uint8Array.from("Hello World".split("").map(x => x.charCodeAt()));
|
||||
|
||||
// setting up the epoch (With 0s for the test)
|
||||
const epoch = new Uint8Array(32);
|
||||
|
||||
console.log("Generating proof...");
|
||||
console.time("proof_gen_timer");
|
||||
let proof = await rlnInstance.generateProof(uint8Msg, index, epoch, memKeys.IDKey)
|
||||
console.timeEnd("proof_gen_timer");
|
||||
console.log("Proof", proof)
|
||||
|
||||
try {
|
||||
// verify the proof
|
||||
let verifResult = rlnInstance.verifyProof(proof);
|
||||
console.log("Is proof verified?", verifResult ? "yes" : "no");
|
||||
} catch (err) {
|
||||
console.log("Invalid proof")
|
||||
}
|
||||
|
||||
try {
|
||||
// Modifying the proof so it's invalid
|
||||
proof[7] = 7;
|
||||
// verify the proof
|
||||
let verifResult = rlnInstance.verifyProof(proof);
|
||||
console.log("Is proof verified?", verifResult ? "yes" : "no");
|
||||
} catch (err) {
|
||||
console.log("Invalid proof")
|
||||
}
|
||||
|
||||
});
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "rln-wasm-example",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "webpack --config webpack.config.js",
|
||||
"start": "webpack-dev-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@waku/rln": "file:../"
|
||||
},
|
||||
"devDependencies": {
|
||||
"webpack": "^4.29.3",
|
||||
"webpack-cli": "^3.1.0",
|
||||
"webpack-dev-server": "^3.1.5",
|
||||
"copy-webpack-plugin": "^5.0.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: "./index.js",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: "index.js",
|
||||
},
|
||||
mode: "development",
|
||||
plugins: [
|
||||
new CopyWebpackPlugin(['index.html'])
|
||||
],
|
||||
};
|
|
@ -4,9 +4,9 @@ const webpack = require("webpack");
|
|||
module.exports = function (config) {
|
||||
config.set({
|
||||
frameworks: ["webpack", "mocha"],
|
||||
files: ["src/lib/**/!(node).spec.ts"],
|
||||
files: ["src/**/!(node).spec.ts"],
|
||||
preprocessors: {
|
||||
"src/lib/**/!(node).spec.ts": ["webpack"],
|
||||
"src/**/!(node).spec.ts": ["webpack"],
|
||||
},
|
||||
envPreprocessor: ["CI"],
|
||||
reporters: ["progress"],
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
{
|
||||
"name": "js-rln",
|
||||
"name": "@waku/rln",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "js-rln",
|
||||
"name": "@waku/rln",
|
||||
"version": "0.0.1",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-commonjs": "^22.0.2",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||
"@rollup/plugin-wasm": "^5.2.0",
|
||||
"@size-limit/preset-big-lib": "^8.0.0",
|
||||
"@types/app-root-path": "^1.2.4",
|
||||
"@types/chai": "^4.2.15",
|
||||
|
@ -48,7 +49,9 @@
|
|||
"p-timeout": "^4.1.0",
|
||||
"prettier": "^2.1.1",
|
||||
"process": "^0.11.10",
|
||||
"puppeteer": "^13.0.1",
|
||||
"rollup": "^2.75.0",
|
||||
"rollup-plugin-copy": "^3.4.0",
|
||||
"size-limit": "^8.0.0",
|
||||
"tail": "^2.2.0",
|
||||
"ts-loader": "^9.3.1",
|
||||
|
@ -589,8 +592,9 @@
|
|||
},
|
||||
"node_modules/@rollup/plugin-commonjs": {
|
||||
"version": "22.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-22.0.2.tgz",
|
||||
"integrity": "sha512-//NdP6iIwPbMTcazYsiBMbJW7gfmpHom33u1beiIoHDEM0Q9clvtQB1T0efvMqHeKsGohiHo97BCPCkBXdscwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rollup/pluginutils": "^3.1.0",
|
||||
"commondir": "^1.0.1",
|
||||
|
@ -620,8 +624,9 @@
|
|||
},
|
||||
"node_modules/@rollup/plugin-node-resolve": {
|
||||
"version": "13.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.3.0.tgz",
|
||||
"integrity": "sha512-Lus8rbUo1eEcnS4yTFKLZrVumLPY+YayBdWXgFSHYhTT2iJbMhoaaBL3xl5NCdeRytErGr8tZ0L71BMRmnlwSw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rollup/pluginutils": "^3.1.0",
|
||||
"@types/resolve": "1.17.1",
|
||||
|
@ -637,6 +642,18 @@
|
|||
"rollup": "^2.42.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@rollup/plugin-wasm": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-wasm/-/plugin-wasm-5.2.0.tgz",
|
||||
"integrity": "sha512-PR3ff67ls2Kr9H04pZ24wJYPZq0YV+UHySpk7OuAJxyc7o5Q8NHFdwi4pfMtJkJkqfN1/QY/nq46SoRDoDvK2w==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"rollup": "^1.20.0 || ^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@rollup/pluginutils": {
|
||||
"version": "3.1.0",
|
||||
"dev": true,
|
||||
|
@ -815,6 +832,25 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/fs-extra": {
|
||||
"version": "8.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-8.1.2.tgz",
|
||||
"integrity": "sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/glob": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz",
|
||||
"integrity": "sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/minimatch": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.11",
|
||||
"dev": true,
|
||||
|
@ -825,6 +861,12 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/minimatch": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz",
|
||||
"integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/mocha": {
|
||||
"version": "9.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.1.tgz",
|
||||
|
@ -4348,6 +4390,15 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/is-plain-object": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-3.0.1.tgz",
|
||||
"integrity": "sha512-Xnpx182SBMrr/aBik8y+GuR4U1L9FqMSojwDQwPMmxyC6bvEqly9UBCxhauBF5vNh2gwWJNX6oDV7O+OM4z34g==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/is-potential-custom-element-name": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
|
@ -6089,6 +6140,30 @@
|
|||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/puppeteer": {
|
||||
"version": "13.7.0",
|
||||
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-13.7.0.tgz",
|
||||
"integrity": "sha512-U1uufzBjz3+PkpCxFrWzh4OrMIdIb2ztzCu0YEPfRHjHswcSwHZswnK+WdsOQJsRV8WeTg3jLhJR4D867+fjsA==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"cross-fetch": "3.1.5",
|
||||
"debug": "4.3.4",
|
||||
"devtools-protocol": "0.0.981744",
|
||||
"extract-zip": "2.0.1",
|
||||
"https-proxy-agent": "5.0.1",
|
||||
"pkg-dir": "4.2.0",
|
||||
"progress": "2.0.3",
|
||||
"proxy-from-env": "1.1.0",
|
||||
"rimraf": "3.0.2",
|
||||
"tar-fs": "2.1.1",
|
||||
"unbzip2-stream": "1.4.3",
|
||||
"ws": "8.5.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.18.1"
|
||||
}
|
||||
},
|
||||
"node_modules/puppeteer-core": {
|
||||
"version": "13.7.0",
|
||||
"dev": true,
|
||||
|
@ -6131,6 +6206,27 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"node_modules/puppeteer/node_modules/ws": {
|
||||
"version": "8.5.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
|
||||
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": "^5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/pure-rand": {
|
||||
"version": "5.0.1",
|
||||
"dev": true,
|
||||
|
@ -6464,6 +6560,79 @@
|
|||
"fsevents": "~2.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/rollup-plugin-copy": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz",
|
||||
"integrity": "sha512-rGUmYYsYsceRJRqLVlE9FivJMxJ7X6jDlP79fmFkL8sJs7VVMSVyA2yfyL+PGyO/vJs4A87hwhgVfz61njI+uQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/fs-extra": "^8.0.1",
|
||||
"colorette": "^1.1.0",
|
||||
"fs-extra": "^8.1.0",
|
||||
"globby": "10.0.1",
|
||||
"is-plain-object": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.3"
|
||||
}
|
||||
},
|
||||
"node_modules/rollup-plugin-copy/node_modules/colorette": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/colorette/-/colorette-1.4.0.tgz",
|
||||
"integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/rollup-plugin-copy/node_modules/fs-extra": {
|
||||
"version": "8.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
||||
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^4.0.0",
|
||||
"universalify": "^0.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6 <7 || >=8"
|
||||
}
|
||||
},
|
||||
"node_modules/rollup-plugin-copy/node_modules/globby": {
|
||||
"version": "10.0.1",
|
||||
"resolved": "https://registry.npmjs.org/globby/-/globby-10.0.1.tgz",
|
||||
"integrity": "sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/glob": "^7.1.1",
|
||||
"array-union": "^2.1.0",
|
||||
"dir-glob": "^3.0.1",
|
||||
"fast-glob": "^3.0.3",
|
||||
"glob": "^7.1.3",
|
||||
"ignore": "^5.1.1",
|
||||
"merge2": "^1.2.3",
|
||||
"slash": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/rollup-plugin-copy/node_modules/jsonfile": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
||||
"integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==",
|
||||
"dev": true,
|
||||
"optionalDependencies": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/rollup-plugin-copy/node_modules/universalify": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/run-parallel": {
|
||||
"version": "1.2.0",
|
||||
"dev": true,
|
||||
|
@ -8424,6 +8593,8 @@
|
|||
},
|
||||
"@rollup/plugin-commonjs": {
|
||||
"version": "22.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-22.0.2.tgz",
|
||||
"integrity": "sha512-//NdP6iIwPbMTcazYsiBMbJW7gfmpHom33u1beiIoHDEM0Q9clvtQB1T0efvMqHeKsGohiHo97BCPCkBXdscwg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@rollup/pluginutils": "^3.1.0",
|
||||
|
@ -8444,6 +8615,8 @@
|
|||
},
|
||||
"@rollup/plugin-node-resolve": {
|
||||
"version": "13.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.3.0.tgz",
|
||||
"integrity": "sha512-Lus8rbUo1eEcnS4yTFKLZrVumLPY+YayBdWXgFSHYhTT2iJbMhoaaBL3xl5NCdeRytErGr8tZ0L71BMRmnlwSw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@rollup/pluginutils": "^3.1.0",
|
||||
|
@ -8454,6 +8627,13 @@
|
|||
"resolve": "^1.19.0"
|
||||
}
|
||||
},
|
||||
"@rollup/plugin-wasm": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-wasm/-/plugin-wasm-5.2.0.tgz",
|
||||
"integrity": "sha512-PR3ff67ls2Kr9H04pZ24wJYPZq0YV+UHySpk7OuAJxyc7o5Q8NHFdwi4pfMtJkJkqfN1/QY/nq46SoRDoDvK2w==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
},
|
||||
"@rollup/pluginutils": {
|
||||
"version": "3.1.0",
|
||||
"dev": true,
|
||||
|
@ -8584,6 +8764,25 @@
|
|||
"version": "0.0.39",
|
||||
"dev": true
|
||||
},
|
||||
"@types/fs-extra": {
|
||||
"version": "8.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-8.1.2.tgz",
|
||||
"integrity": "sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/glob": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz",
|
||||
"integrity": "sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/minimatch": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/json-schema": {
|
||||
"version": "7.0.11",
|
||||
"dev": true
|
||||
|
@ -8592,6 +8791,12 @@
|
|||
"version": "0.0.29",
|
||||
"dev": true
|
||||
},
|
||||
"@types/minimatch": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz",
|
||||
"integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/mocha": {
|
||||
"version": "9.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.1.tgz",
|
||||
|
@ -10882,6 +11087,12 @@
|
|||
"integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==",
|
||||
"dev": true
|
||||
},
|
||||
"is-plain-object": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-3.0.1.tgz",
|
||||
"integrity": "sha512-Xnpx182SBMrr/aBik8y+GuR4U1L9FqMSojwDQwPMmxyC6bvEqly9UBCxhauBF5vNh2gwWJNX6oDV7O+OM4z34g==",
|
||||
"dev": true
|
||||
},
|
||||
"is-potential-custom-element-name": {
|
||||
"version": "1.0.1",
|
||||
"dev": true
|
||||
|
@ -12010,6 +12221,35 @@
|
|||
"version": "2.1.1",
|
||||
"dev": true
|
||||
},
|
||||
"puppeteer": {
|
||||
"version": "13.7.0",
|
||||
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-13.7.0.tgz",
|
||||
"integrity": "sha512-U1uufzBjz3+PkpCxFrWzh4OrMIdIb2ztzCu0YEPfRHjHswcSwHZswnK+WdsOQJsRV8WeTg3jLhJR4D867+fjsA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"cross-fetch": "3.1.5",
|
||||
"debug": "4.3.4",
|
||||
"devtools-protocol": "0.0.981744",
|
||||
"extract-zip": "2.0.1",
|
||||
"https-proxy-agent": "5.0.1",
|
||||
"pkg-dir": "4.2.0",
|
||||
"progress": "2.0.3",
|
||||
"proxy-from-env": "1.1.0",
|
||||
"rimraf": "3.0.2",
|
||||
"tar-fs": "2.1.1",
|
||||
"unbzip2-stream": "1.4.3",
|
||||
"ws": "8.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ws": {
|
||||
"version": "8.5.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
|
||||
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"puppeteer-core": {
|
||||
"version": "13.7.0",
|
||||
"dev": true,
|
||||
|
@ -12237,6 +12477,69 @@
|
|||
"fsevents": "~2.3.2"
|
||||
}
|
||||
},
|
||||
"rollup-plugin-copy": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz",
|
||||
"integrity": "sha512-rGUmYYsYsceRJRqLVlE9FivJMxJ7X6jDlP79fmFkL8sJs7VVMSVyA2yfyL+PGyO/vJs4A87hwhgVfz61njI+uQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/fs-extra": "^8.0.1",
|
||||
"colorette": "^1.1.0",
|
||||
"fs-extra": "^8.1.0",
|
||||
"globby": "10.0.1",
|
||||
"is-plain-object": "^3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"colorette": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/colorette/-/colorette-1.4.0.tgz",
|
||||
"integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==",
|
||||
"dev": true
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "8.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
||||
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^4.0.0",
|
||||
"universalify": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"globby": {
|
||||
"version": "10.0.1",
|
||||
"resolved": "https://registry.npmjs.org/globby/-/globby-10.0.1.tgz",
|
||||
"integrity": "sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/glob": "^7.1.1",
|
||||
"array-union": "^2.1.0",
|
||||
"dir-glob": "^3.0.1",
|
||||
"fast-glob": "^3.0.3",
|
||||
"glob": "^7.1.3",
|
||||
"ignore": "^5.1.1",
|
||||
"merge2": "^1.2.3",
|
||||
"slash": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
||||
"integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"universalify": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"run-parallel": {
|
||||
"version": "1.2.0",
|
||||
"dev": true,
|
||||
|
|
12
package.json
12
package.json
|
@ -10,13 +10,6 @@
|
|||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"lib/*": [
|
||||
"dist/lib/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
"repository": "https://github.com/waku-org/js-rln",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
|
@ -56,9 +49,10 @@
|
|||
"node": ">=16"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-commonjs": "^22.0.2",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||
"@rollup/plugin-wasm": "^5.2.0",
|
||||
"@size-limit/preset-big-lib": "^8.0.0",
|
||||
"@types/app-root-path": "^1.2.4",
|
||||
"@types/chai": "^4.2.15",
|
||||
|
@ -95,7 +89,9 @@
|
|||
"p-timeout": "^4.1.0",
|
||||
"prettier": "^2.1.1",
|
||||
"process": "^0.11.10",
|
||||
"puppeteer": "^13.0.1",
|
||||
"rollup": "^2.75.0",
|
||||
"rollup-plugin-copy": "^3.4.0",
|
||||
"size-limit": "^8.0.0",
|
||||
"tail": "^2.2.0",
|
||||
"ts-loader": "^9.3.1",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import json from "@rollup/plugin-json";
|
||||
import { wasm } from '@rollup/plugin-wasm';
|
||||
import copy from 'rollup-plugin-copy'
|
||||
|
||||
export default {
|
||||
input: {
|
||||
|
@ -11,11 +13,21 @@ export default {
|
|||
format: "esm",
|
||||
},
|
||||
plugins: [
|
||||
copy({
|
||||
hook: 'buildStart',
|
||||
targets: [
|
||||
{ src: 'src/zerokit/rln_wasm_bg.wasm', dest: 'dist/zerokit' },
|
||||
]
|
||||
}),
|
||||
commonjs(),
|
||||
json(),
|
||||
wasm({
|
||||
maxFileSize: 0
|
||||
}),
|
||||
nodeResolve({
|
||||
browser: true,
|
||||
preferBuiltins: false,
|
||||
extensions: [".js", ".ts", ".wasm"]
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
|
14
src/index.ts
14
src/index.ts
|
@ -1,5 +1,11 @@
|
|||
export class RLN {
|
||||
constructor() {
|
||||
alert("Hello world");
|
||||
}
|
||||
import { RLNInstance } from "./rln";
|
||||
|
||||
// reexport the create function, dynamically imported from rln.ts
|
||||
export async function create(): Promise<RLNInstance> {
|
||||
// A dependency graph that contains any wasm must all be imported
|
||||
// asynchronously. This file does the single async import, so
|
||||
// that no one else needs to worry about it again.
|
||||
const rlnModule = await import("./rln");
|
||||
|
||||
return await rlnModule.create();
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,136 @@
|
|||
import * as resources from "./resources";
|
||||
import * as wc from "./witness_calculator";
|
||||
import * as zerokitRLN from "./zerokit/rln_wasm";
|
||||
|
||||
/**
|
||||
* Convert a base64 string into uint8Array
|
||||
* @param base64
|
||||
* @returns Uint8Array
|
||||
*/
|
||||
function base64ToUint8Array(base64: string): Uint8Array {
|
||||
const binary_string = window.atob(base64);
|
||||
const len = binary_string.length;
|
||||
const bytes = new Uint8Array(len);
|
||||
for (let i = 0; i < len; i++) {
|
||||
bytes[i] = binary_string.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate Uint8Arrays
|
||||
* @param input
|
||||
* @returns concatenation of all Uint8Array received as input
|
||||
*/
|
||||
function concatenate(...input: Uint8Array[]): Uint8Array {
|
||||
let totalLength = 0;
|
||||
for (const arr of input) {
|
||||
totalLength += arr.length;
|
||||
}
|
||||
const result = new Uint8Array(totalLength);
|
||||
let offset = 0;
|
||||
for (const arr of input) {
|
||||
result.set(arr, offset);
|
||||
offset += arr.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const DEPTH = 20;
|
||||
const VERIFICATION_KEY = base64ToUint8Array(resources.verification_key);
|
||||
const ZKEY = base64ToUint8Array(resources.zkey);
|
||||
const CIRCUIT = base64ToUint8Array(resources.circuit);
|
||||
|
||||
zerokitRLN.init_panic_hook();
|
||||
|
||||
/**
|
||||
* Create an instance of RLN
|
||||
* @returns RLNInstance
|
||||
*/
|
||||
export async function create(): Promise<RLNInstance> {
|
||||
const witnessCalculator = await wc.builder(CIRCUIT, false);
|
||||
const zkRLN = zerokitRLN.newRLN(DEPTH, ZKEY, VERIFICATION_KEY);
|
||||
return new RLNInstance(zkRLN, witnessCalculator);
|
||||
}
|
||||
|
||||
export class MembershipKey {
|
||||
readonly IDKey: Uint8Array;
|
||||
readonly IDCommitment: Uint8Array;
|
||||
|
||||
constructor(memKeys: Uint8Array) {
|
||||
this.IDKey = memKeys.subarray(0, 32);
|
||||
this.IDCommitment = memKeys.subarray(32);
|
||||
}
|
||||
}
|
||||
|
||||
export class RLNInstance {
|
||||
zkRLN: number;
|
||||
witnessCalculator: any;
|
||||
|
||||
constructor(zkRLN: number, wc: any) {
|
||||
this.zkRLN = zkRLN;
|
||||
this.witnessCalculator = wc;
|
||||
}
|
||||
|
||||
generateMembershipKey(): MembershipKey {
|
||||
const memKeys = zerokitRLN.generateMembershipKey(this.zkRLN);
|
||||
return new MembershipKey(memKeys);
|
||||
}
|
||||
|
||||
inserMember(idCommitment: Uint8Array): void {
|
||||
zerokitRLN.insertMember(this.zkRLN, idCommitment);
|
||||
}
|
||||
|
||||
serializeMessage(
|
||||
uint8Msg: Uint8Array,
|
||||
memIndex: number,
|
||||
epoch: Uint8Array,
|
||||
idKey: Uint8Array
|
||||
): Uint8Array {
|
||||
if (epoch.length != 32) throw "invalid epoch";
|
||||
if (idKey.length != 32) throw "invalid id key";
|
||||
|
||||
// calculate message length
|
||||
const msgLen = Buffer.allocUnsafe(8);
|
||||
msgLen.writeUIntLE(uint8Msg.length, 0, 8);
|
||||
|
||||
// Converting index to LE bytes
|
||||
const memIndexBytes = Buffer.allocUnsafe(8);
|
||||
memIndexBytes.writeUIntLE(memIndex, 0, 8);
|
||||
|
||||
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
|
||||
return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
|
||||
}
|
||||
|
||||
async generateProof(
|
||||
msg: Uint8Array,
|
||||
index: number,
|
||||
epoch: Uint8Array,
|
||||
idKey: Uint8Array
|
||||
): Promise<Uint8Array> {
|
||||
if (epoch.length != 32) throw "invalid epoch";
|
||||
if (idKey.length != 32) throw "invalid id key";
|
||||
if (index < 0) throw "index must be >= 0";
|
||||
|
||||
const serialized_msg = this.serializeMessage(msg, index, epoch, idKey);
|
||||
const rlnWitness = zerokitRLN.getSerializedRLNWitness(
|
||||
this.zkRLN,
|
||||
serialized_msg
|
||||
);
|
||||
const inputs = zerokitRLN.RLNWitnessToJson(this.zkRLN, rlnWitness);
|
||||
const calculatedWitness = await this.witnessCalculator.calculateWitness(
|
||||
inputs,
|
||||
false
|
||||
); // no sanity check being used in zerokit
|
||||
|
||||
return zerokitRLN.generate_rln_proof_with_witness(
|
||||
this.zkRLN,
|
||||
calculatedWitness,
|
||||
rlnWitness
|
||||
);
|
||||
}
|
||||
|
||||
verifyProof(proof: Uint8Array): boolean {
|
||||
return zerokitRLN.verifyProof(this.zkRLN, proof);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export async function builder(
|
||||
code: Uint8Array,
|
||||
sanityCheck: bool
|
||||
): Promise<any>;
|
|
@ -0,0 +1,335 @@
|
|||
// File generated with https://github.com/iden3/circom
|
||||
// following the instructions from:
|
||||
// https://github.com/vacp2p/zerokit/tree/master/rln#compiling-circuits
|
||||
|
||||
export async function builder(code, options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
let wasmModule;
|
||||
try {
|
||||
wasmModule = await WebAssembly.compile(code);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
console.log("\nTry to run circom --c in order to generate c++ code instead\n");
|
||||
throw new Error(err);
|
||||
}
|
||||
|
||||
let wc;
|
||||
|
||||
let errStr = "";
|
||||
let msgStr = "";
|
||||
|
||||
const instance = await WebAssembly.instantiate(wasmModule, {
|
||||
runtime: {
|
||||
exceptionHandler : function(code) {
|
||||
let err;
|
||||
if (code == 1) {
|
||||
err = "Signal not found.\n";
|
||||
} else if (code == 2) {
|
||||
err = "Too many signals set.\n";
|
||||
} else if (code == 3) {
|
||||
err = "Signal already set.\n";
|
||||
} else if (code == 4) {
|
||||
err = "Assert Failed.\n";
|
||||
} else if (code == 5) {
|
||||
err = "Not enough memory.\n";
|
||||
} else if (code == 6) {
|
||||
err = "Input signal array access exceeds the size.\n";
|
||||
} else {
|
||||
err = "Unknown error.\n";
|
||||
}
|
||||
throw new Error(err + errStr);
|
||||
},
|
||||
printErrorMessage : function() {
|
||||
errStr += getMessage() + "\n";
|
||||
// console.error(getMessage());
|
||||
},
|
||||
writeBufferMessage : function() {
|
||||
const msg = getMessage();
|
||||
// Any calls to `log()` will always end with a `\n`, so that's when we print and reset
|
||||
if (msg === "\n") {
|
||||
console.log(msgStr);
|
||||
msgStr = "";
|
||||
} else {
|
||||
// If we've buffered other content, put a space in between the items
|
||||
if (msgStr !== "") {
|
||||
msgStr += " "
|
||||
}
|
||||
// Then append the message to the message we are creating
|
||||
msgStr += msg;
|
||||
}
|
||||
},
|
||||
showSharedRWMemory : function() {
|
||||
printSharedRWMemory ();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
const sanityCheck =
|
||||
options
|
||||
// options &&
|
||||
// (
|
||||
// options.sanityCheck ||
|
||||
// options.logGetSignal ||
|
||||
// options.logSetSignal ||
|
||||
// options.logStartComponent ||
|
||||
// options.logFinishComponent
|
||||
// );
|
||||
|
||||
|
||||
wc = new WitnessCalculator(instance, sanityCheck);
|
||||
return wc;
|
||||
|
||||
function getMessage() {
|
||||
var message = "";
|
||||
var c = instance.exports.getMessageChar();
|
||||
while ( c != 0 ) {
|
||||
message += String.fromCharCode(c);
|
||||
c = instance.exports.getMessageChar();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
function printSharedRWMemory () {
|
||||
const shared_rw_memory_size = instance.exports.getFieldNumLen32();
|
||||
const arr = new Uint32Array(shared_rw_memory_size);
|
||||
for (let j=0; j<shared_rw_memory_size; j++) {
|
||||
arr[shared_rw_memory_size-1-j] = instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
|
||||
// If we've buffered other content, put a space in between the items
|
||||
if (msgStr !== "") {
|
||||
msgStr += " "
|
||||
}
|
||||
// Then append the value to the message we are creating
|
||||
msgStr += (fromArray32(arr).toString());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class WitnessCalculator {
|
||||
constructor(instance, sanityCheck) {
|
||||
this.instance = instance;
|
||||
|
||||
this.version = this.instance.exports.getVersion();
|
||||
this.n32 = this.instance.exports.getFieldNumLen32();
|
||||
|
||||
this.instance.exports.getRawPrime();
|
||||
const arr = new Uint32Array(this.n32);
|
||||
for (let i=0; i<this.n32; i++) {
|
||||
arr[this.n32-1-i] = this.instance.exports.readSharedRWMemory(i);
|
||||
}
|
||||
this.prime = fromArray32(arr);
|
||||
|
||||
this.witnessSize = this.instance.exports.getWitnessSize();
|
||||
|
||||
this.sanityCheck = sanityCheck;
|
||||
}
|
||||
|
||||
circom_version() {
|
||||
return this.instance.exports.getVersion();
|
||||
}
|
||||
|
||||
async _doCalculateWitness(input, sanityCheck) {
|
||||
//input is assumed to be a map from signals to arrays of bigints
|
||||
this.instance.exports.init((this.sanityCheck || sanityCheck) ? 1 : 0);
|
||||
const keys = Object.keys(input);
|
||||
var input_counter = 0;
|
||||
keys.forEach( (k) => {
|
||||
const h = fnvHash(k);
|
||||
const hMSB = parseInt(h.slice(0,8), 16);
|
||||
const hLSB = parseInt(h.slice(8,16), 16);
|
||||
const fArr = flatArray(input[k]);
|
||||
let signalSize = this.instance.exports.getInputSignalSize(hMSB, hLSB);
|
||||
if (signalSize < 0){
|
||||
throw new Error(`Signal ${k} not found\n`);
|
||||
}
|
||||
if (fArr.length < signalSize) {
|
||||
throw new Error(`Not enough values for input signal ${k}\n`);
|
||||
}
|
||||
if (fArr.length > signalSize) {
|
||||
throw new Error(`Too many values for input signal ${k}\n`);
|
||||
}
|
||||
for (let i=0; i<fArr.length; i++) {
|
||||
const arrFr = toArray32(BigInt(fArr[i])%this.prime,this.n32)
|
||||
for (let j=0; j<this.n32; j++) {
|
||||
this.instance.exports.writeSharedRWMemory(j,arrFr[this.n32-1-j]);
|
||||
}
|
||||
try {
|
||||
this.instance.exports.setInputSignal(hMSB, hLSB,i);
|
||||
input_counter++;
|
||||
} catch (err) {
|
||||
// console.log(`After adding signal ${i} of ${k}`)
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
if (input_counter < this.instance.exports.getInputSize()) {
|
||||
throw new Error(`Not all inputs have been set. Only ${input_counter} out of ${this.instance.exports.getInputSize()}`);
|
||||
}
|
||||
}
|
||||
|
||||
async calculateWitness(input, sanityCheck) {
|
||||
|
||||
const w = [];
|
||||
|
||||
await this._doCalculateWitness(input, sanityCheck);
|
||||
|
||||
for (let i=0; i<this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i);
|
||||
const arr = new Uint32Array(this.n32);
|
||||
for (let j=0; j<this.n32; j++) {
|
||||
arr[this.n32-1-j] = this.instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
w.push(fromArray32(arr));
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
async calculateBinWitness(input, sanityCheck) {
|
||||
|
||||
const buff32 = new Uint32Array(this.witnessSize*this.n32);
|
||||
const buff = new Uint8Array( buff32.buffer);
|
||||
await this._doCalculateWitness(input, sanityCheck);
|
||||
|
||||
for (let i=0; i<this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i);
|
||||
const pos = i*this.n32;
|
||||
for (let j=0; j<this.n32; j++) {
|
||||
buff32[pos+j] = this.instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
}
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
||||
async calculateWTNSBin(input, sanityCheck) {
|
||||
|
||||
const buff32 = new Uint32Array(this.witnessSize*this.n32+this.n32+11);
|
||||
const buff = new Uint8Array( buff32.buffer);
|
||||
await this._doCalculateWitness(input, sanityCheck);
|
||||
|
||||
//"wtns"
|
||||
buff[0] = "w".charCodeAt(0)
|
||||
buff[1] = "t".charCodeAt(0)
|
||||
buff[2] = "n".charCodeAt(0)
|
||||
buff[3] = "s".charCodeAt(0)
|
||||
|
||||
//version 2
|
||||
buff32[1] = 2;
|
||||
|
||||
//number of sections: 2
|
||||
buff32[2] = 2;
|
||||
|
||||
//id section 1
|
||||
buff32[3] = 1;
|
||||
|
||||
const n8 = this.n32*4;
|
||||
//id section 1 length in 64bytes
|
||||
const idSection1length = 8 + n8;
|
||||
const idSection1lengthHex = idSection1length.toString(16);
|
||||
buff32[4] = parseInt(idSection1lengthHex.slice(0,8), 16);
|
||||
buff32[5] = parseInt(idSection1lengthHex.slice(8,16), 16);
|
||||
|
||||
//this.n32
|
||||
buff32[6] = n8;
|
||||
|
||||
//prime number
|
||||
this.instance.exports.getRawPrime();
|
||||
|
||||
var pos = 7;
|
||||
for (let j=0; j<this.n32; j++) {
|
||||
buff32[pos+j] = this.instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
pos += this.n32;
|
||||
|
||||
// witness size
|
||||
buff32[pos] = this.witnessSize;
|
||||
pos++;
|
||||
|
||||
//id section 2
|
||||
buff32[pos] = 2;
|
||||
pos++;
|
||||
|
||||
// section 2 length
|
||||
const idSection2length = n8*this.witnessSize;
|
||||
const idSection2lengthHex = idSection2length.toString(16);
|
||||
buff32[pos] = parseInt(idSection2lengthHex.slice(0,8), 16);
|
||||
buff32[pos+1] = parseInt(idSection2lengthHex.slice(8,16), 16);
|
||||
|
||||
pos += 2;
|
||||
for (let i=0; i<this.witnessSize; i++) {
|
||||
this.instance.exports.getWitness(i);
|
||||
for (let j=0; j<this.n32; j++) {
|
||||
buff32[pos+j] = this.instance.exports.readSharedRWMemory(j);
|
||||
}
|
||||
pos += this.n32;
|
||||
}
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function toArray32(rem,size) {
|
||||
const res = []; //new Uint32Array(size); //has no unshift
|
||||
const radix = BigInt(0x100000000);
|
||||
while (rem) {
|
||||
res.unshift( Number(rem % radix));
|
||||
rem = rem / radix;
|
||||
}
|
||||
if (size) {
|
||||
var i = size - res.length;
|
||||
while (i>0) {
|
||||
res.unshift(0);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function fromArray32(arr) { //returns a BigInt
|
||||
var res = BigInt(0);
|
||||
const radix = BigInt(0x100000000);
|
||||
for (let i = 0; i<arr.length; i++) {
|
||||
res = res*radix + BigInt(arr[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function flatArray(a) {
|
||||
var res = [];
|
||||
fillArray(res, a);
|
||||
return res;
|
||||
|
||||
function fillArray(res, a) {
|
||||
if (Array.isArray(a)) {
|
||||
for (let i=0; i<a.length; i++) {
|
||||
fillArray(res, a[i]);
|
||||
}
|
||||
} else {
|
||||
res.push(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fnvHash(str) {
|
||||
const uint64_max = BigInt(2) ** BigInt(64);
|
||||
let hash = BigInt("0xCBF29CE484222325");
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
hash ^= BigInt(str[i].charCodeAt());
|
||||
hash *= BigInt(0x100000001B3);
|
||||
hash %= uint64_max;
|
||||
}
|
||||
let shash = hash.toString(16);
|
||||
let n = 16 - shash.length;
|
||||
shash = '0'.repeat(n).concat(shash);
|
||||
return shash;
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
*/
|
||||
export function init_panic_hook(): void;
|
||||
/**
|
||||
* @param {number} tree_height
|
||||
* @param {Uint8Array} zkey
|
||||
* @param {Uint8Array} vk
|
||||
* @returns {number}
|
||||
*/
|
||||
export function newRLN(tree_height: number, zkey: Uint8Array, vk: Uint8Array): number;
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {Uint8Array} input
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function getSerializedRLNWitness(ctx: number, input: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {Uint8Array} input
|
||||
*/
|
||||
export function insertMember(ctx: number, input: Uint8Array): void;
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {Uint8Array} serialized_witness
|
||||
* @returns {object}
|
||||
*/
|
||||
export function RLNWitnessToJson(ctx: number, serialized_witness: Uint8Array): object;
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {(bigint)[]} calculated_witness
|
||||
* @param {Uint8Array} serialized_witness
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function generate_rln_proof_with_witness(ctx: number, calculated_witness: (bigint)[], serialized_witness: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function generateMembershipKey(ctx: number): Uint8Array;
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {Uint8Array} proof
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function verifyProof(ctx: number, proof: Uint8Array): boolean;
|
||||
/**
|
||||
*/
|
||||
export class RLN {
|
||||
free(): void;
|
||||
}
|
||||
/**
|
||||
* A struct representing an aborted instruction execution, with a message
|
||||
* indicating the cause.
|
||||
*/
|
||||
export class WasmerRuntimeError {
|
||||
free(): void;
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
import * as wasm from "./rln_wasm_bg.wasm";
|
||||
export * from "./rln_wasm_bg.js";
|
|
@ -0,0 +1,611 @@
|
|||
import * as wasm from './rln_wasm_bg.wasm';
|
||||
|
||||
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 = new Uint8Array();
|
||||
|
||||
function getUint8Memory0() {
|
||||
if (cachedUint8Memory0.byteLength === 0) {
|
||||
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint8Memory0;
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
const heap = new Array(32).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 < 36) return;
|
||||
heap[idx] = heap_next;
|
||||
heap_next = idx;
|
||||
}
|
||||
|
||||
function takeObject(idx) {
|
||||
const ret = getObject(idx);
|
||||
dropObject(idx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
|
||||
|
||||
let cachedTextEncoder = new lTextEncoder('utf-8');
|
||||
|
||||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
||||
? function (arg, view) {
|
||||
return cachedTextEncoder.encodeInto(arg, view);
|
||||
}
|
||||
: function (arg, view) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
view.set(buf);
|
||||
return {
|
||||
read: arg.length,
|
||||
written: buf.length
|
||||
};
|
||||
});
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
|
||||
if (realloc === undefined) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length);
|
||||
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let len = arg.length;
|
||||
let ptr = malloc(len);
|
||||
|
||||
const mem = getUint8Memory0();
|
||||
|
||||
let offset = 0;
|
||||
|
||||
for (; offset < len; offset++) {
|
||||
const code = arg.charCodeAt(offset);
|
||||
if (code > 0x7F) break;
|
||||
mem[ptr + offset] = code;
|
||||
}
|
||||
|
||||
if (offset !== len) {
|
||||
if (offset !== 0) {
|
||||
arg = arg.slice(offset);
|
||||
}
|
||||
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
||||
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
||||
const ret = encodeString(arg, view);
|
||||
|
||||
offset += ret.written;
|
||||
}
|
||||
|
||||
WASM_VECTOR_LEN = offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function isLikeNone(x) {
|
||||
return x === undefined || x === null;
|
||||
}
|
||||
|
||||
let cachedInt32Memory0 = new Int32Array();
|
||||
|
||||
function getInt32Memory0() {
|
||||
if (cachedInt32Memory0.byteLength === 0) {
|
||||
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedInt32Memory0;
|
||||
}
|
||||
|
||||
function debugString(val) {
|
||||
// primitive types
|
||||
const type = typeof val;
|
||||
if (type == 'number' || type == 'boolean' || val == null) {
|
||||
return `${val}`;
|
||||
}
|
||||
if (type == 'string') {
|
||||
return `"${val}"`;
|
||||
}
|
||||
if (type == 'symbol') {
|
||||
const description = val.description;
|
||||
if (description == null) {
|
||||
return 'Symbol';
|
||||
} else {
|
||||
return `Symbol(${description})`;
|
||||
}
|
||||
}
|
||||
if (type == 'function') {
|
||||
const name = val.name;
|
||||
if (typeof name == 'string' && name.length > 0) {
|
||||
return `Function(${name})`;
|
||||
} else {
|
||||
return 'Function';
|
||||
}
|
||||
}
|
||||
// objects
|
||||
if (Array.isArray(val)) {
|
||||
const length = val.length;
|
||||
let debug = '[';
|
||||
if (length > 0) {
|
||||
debug += debugString(val[0]);
|
||||
}
|
||||
for(let i = 1; i < length; i++) {
|
||||
debug += ', ' + debugString(val[i]);
|
||||
}
|
||||
debug += ']';
|
||||
return debug;
|
||||
}
|
||||
// Test for built-in
|
||||
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
||||
let className;
|
||||
if (builtInMatches.length > 1) {
|
||||
className = builtInMatches[1];
|
||||
} else {
|
||||
// Failed to match the standard '[object ClassName]'
|
||||
return toString.call(val);
|
||||
}
|
||||
if (className == 'Object') {
|
||||
// we're a user defined class or Object
|
||||
// JSON.stringify avoids problems with cycles, and is generally much
|
||||
// easier than looping through ownProperties of `val`.
|
||||
try {
|
||||
return 'Object(' + JSON.stringify(val) + ')';
|
||||
} catch (_) {
|
||||
return 'Object';
|
||||
}
|
||||
}
|
||||
// errors
|
||||
if (val instanceof Error) {
|
||||
return `${val.name}: ${val.message}\n${val.stack}`;
|
||||
}
|
||||
// TODO we could test for more things here, like `Set`s and `Map`s.
|
||||
return className;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
export function init_panic_hook() {
|
||||
wasm.init_panic_hook();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} tree_height
|
||||
* @param {Uint8Array} zkey
|
||||
* @param {Uint8Array} vk
|
||||
* @returns {number}
|
||||
*/
|
||||
export function newRLN(tree_height, zkey, vk) {
|
||||
const ret = wasm.newRLN(tree_height, addHeapObject(zkey), addHeapObject(vk));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {Uint8Array} input
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function getSerializedRLNWitness(ctx, input) {
|
||||
const ret = wasm.getSerializedRLNWitness(ctx, addHeapObject(input));
|
||||
return takeObject(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {Uint8Array} input
|
||||
*/
|
||||
export function insertMember(ctx, input) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
wasm.insertMember(retptr, ctx, addHeapObject(input));
|
||||
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
||||
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
||||
if (r1) {
|
||||
throw takeObject(r0);
|
||||
}
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {Uint8Array} serialized_witness
|
||||
* @returns {object}
|
||||
*/
|
||||
export function RLNWitnessToJson(ctx, serialized_witness) {
|
||||
const ret = wasm.RLNWitnessToJson(ctx, addHeapObject(serialized_witness));
|
||||
return takeObject(ret);
|
||||
}
|
||||
|
||||
let cachedUint32Memory0 = new Uint32Array();
|
||||
|
||||
function getUint32Memory0() {
|
||||
if (cachedUint32Memory0.byteLength === 0) {
|
||||
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint32Memory0;
|
||||
}
|
||||
|
||||
function passArrayJsValueToWasm0(array, malloc) {
|
||||
const ptr = malloc(array.length * 4);
|
||||
const mem = getUint32Memory0();
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
mem[ptr / 4 + i] = addHeapObject(array[i]);
|
||||
}
|
||||
WASM_VECTOR_LEN = array.length;
|
||||
return ptr;
|
||||
}
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {(bigint)[]} calculated_witness
|
||||
* @param {Uint8Array} serialized_witness
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function generate_rln_proof_with_witness(ctx, calculated_witness, serialized_witness) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayJsValueToWasm0(calculated_witness, wasm.__wbindgen_malloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.generate_rln_proof_with_witness(retptr, ctx, ptr0, len0, addHeapObject(serialized_witness));
|
||||
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
||||
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
||||
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
||||
if (r2) {
|
||||
throw takeObject(r1);
|
||||
}
|
||||
return takeObject(r0);
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function generateMembershipKey(ctx) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
wasm.generateMembershipKey(retptr, ctx);
|
||||
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
||||
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
||||
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
||||
if (r2) {
|
||||
throw takeObject(r1);
|
||||
}
|
||||
return takeObject(r0);
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} ctx
|
||||
* @param {Uint8Array} proof
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function verifyProof(ctx, proof) {
|
||||
const ret = wasm.verifyProof(ctx, addHeapObject(proof));
|
||||
return ret !== 0;
|
||||
}
|
||||
|
||||
function handleError(f, args) {
|
||||
try {
|
||||
return f.apply(this, args);
|
||||
} catch (e) {
|
||||
wasm.__wbindgen_exn_store(addHeapObject(e));
|
||||
}
|
||||
}
|
||||
|
||||
function getArrayU8FromWasm0(ptr, len) {
|
||||
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
||||
}
|
||||
|
||||
const u32CvtShim = new Uint32Array(2);
|
||||
|
||||
const uint64CvtShim = new BigUint64Array(u32CvtShim.buffer);
|
||||
|
||||
const int64CvtShim = new BigInt64Array(u32CvtShim.buffer);
|
||||
/**
|
||||
*/
|
||||
export class RLN {
|
||||
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.ptr;
|
||||
this.ptr = 0;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_rln_free(ptr);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A struct representing an aborted instruction execution, with a message
|
||||
* indicating the cause.
|
||||
*/
|
||||
export class WasmerRuntimeError {
|
||||
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.ptr;
|
||||
this.ptr = 0;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_wasmerruntimeerror_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
export function __wbindgen_string_new(arg0, arg1) {
|
||||
const ret = getStringFromWasm0(arg0, arg1);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbindgen_object_drop_ref(arg0) {
|
||||
takeObject(arg0);
|
||||
};
|
||||
|
||||
export function __wbindgen_is_string(arg0) {
|
||||
const ret = typeof(getObject(arg0)) === 'string';
|
||||
return ret;
|
||||
};
|
||||
|
||||
export function __wbindgen_string_get(arg0, arg1) {
|
||||
const obj = getObject(arg1);
|
||||
const ret = typeof(obj) === 'string' ? obj : undefined;
|
||||
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
var len0 = WASM_VECTOR_LEN;
|
||||
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
||||
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
||||
};
|
||||
|
||||
export function __wbg_BigInt_73b2c10d8e6eb5a5(arg0, arg1) {
|
||||
u32CvtShim[0] = arg0;
|
||||
u32CvtShim[1] = arg1;
|
||||
const n0 = int64CvtShim[0];
|
||||
const ret = BigInt(n0);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbindgen_number_new(arg0) {
|
||||
const ret = arg0;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_BigInt_1a499fbb5f402f4c(arg0, arg1) {
|
||||
u32CvtShim[0] = arg0;
|
||||
u32CvtShim[1] = arg1;
|
||||
const n0 = uint64CvtShim[0];
|
||||
const ret = BigInt(n0);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbindgen_object_clone_ref(arg0) {
|
||||
const ret = getObject(arg0);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbindgen_is_undefined(arg0) {
|
||||
const ret = getObject(arg0) === undefined;
|
||||
return ret;
|
||||
};
|
||||
|
||||
export function __wbindgen_is_object(arg0) {
|
||||
const val = getObject(arg0);
|
||||
const ret = typeof(val) === 'object' && val !== null;
|
||||
return ret;
|
||||
};
|
||||
|
||||
export function __wbg_set_e93b31d47b90bff6(arg0, arg1, arg2) {
|
||||
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
||||
};
|
||||
|
||||
export function __wbg_new_693216e109162396() {
|
||||
const ret = new Error();
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_stack_0ddaca5d1abfb52f(arg0, arg1) {
|
||||
const ret = getObject(arg1).stack;
|
||||
const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
||||
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
||||
};
|
||||
|
||||
export function __wbg_error_09919627ac0992f5(arg0, arg1) {
|
||||
try {
|
||||
console.error(getStringFromWasm0(arg0, arg1));
|
||||
} finally {
|
||||
wasm.__wbindgen_free(arg0, arg1);
|
||||
}
|
||||
};
|
||||
|
||||
export function __wbg_process_e56fd54cf6319b6c(arg0) {
|
||||
const ret = getObject(arg0).process;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_versions_77e21455908dad33(arg0) {
|
||||
const ret = getObject(arg0).versions;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_node_0dd25d832e4785d5(arg0) {
|
||||
const ret = getObject(arg0).node;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_static_accessor_NODE_MODULE_26b231378c1be7dd() {
|
||||
const ret = module;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_require_0db1598d9ccecb30() { return handleError(function (arg0, arg1, arg2) {
|
||||
const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_crypto_b95d7173266618a9(arg0) {
|
||||
const ret = getObject(arg0).crypto;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_msCrypto_5a86d77a66230f81(arg0) {
|
||||
const ret = getObject(arg0).msCrypto;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_getRandomValues_b14734aa289bc356() { return handleError(function (arg0, arg1) {
|
||||
getObject(arg0).getRandomValues(getObject(arg1));
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_randomFillSync_91e2b39becca6147() { return handleError(function (arg0, arg1, arg2) {
|
||||
getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_new_ee1a3da85465d621() {
|
||||
const ret = new Array();
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_newnoargs_971e9a5abe185139(arg0, arg1) {
|
||||
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_new_ac586205e4424583() {
|
||||
const ret = new Map();
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_call_33d7bcddbbfa394a() { return handleError(function (arg0, arg1) {
|
||||
const ret = getObject(arg0).call(getObject(arg1));
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_new_e6a9fecc2bf26696() {
|
||||
const ret = new Object();
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_self_fd00a1ef86d1b2ed() { return handleError(function () {
|
||||
const ret = self.self;
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_window_6f6e346d8bbd61d7() { return handleError(function () {
|
||||
const ret = window.window;
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_globalThis_3348936ac49df00a() { return handleError(function () {
|
||||
const ret = globalThis.globalThis;
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_global_67175caf56f55ca9() { return handleError(function () {
|
||||
const ret = global.global;
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_set_64cc39858b2ec3f1(arg0, arg1, arg2) {
|
||||
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
||||
};
|
||||
|
||||
export function __wbg_toString_b1dd862c6b41dd95() { return handleError(function (arg0, arg1) {
|
||||
const ret = getObject(arg0).toString(arg1);
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_new_3ee7ebe9952c1fbd(arg0, arg1) {
|
||||
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_set_a55cff623a9eaa21(arg0, arg1, arg2) {
|
||||
const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_fromEntries_576d8e028b09637c() { return handleError(function (arg0) {
|
||||
const ret = Object.fromEntries(getObject(arg0));
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
export function __wbg_buffer_34f5ec9f8a838ba0(arg0) {
|
||||
const ret = getObject(arg0).buffer;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_newwithbyteoffsetandlength_88fdad741db1b182(arg0, arg1, arg2) {
|
||||
const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_new_cda198d9dbc6d7ea(arg0) {
|
||||
const ret = new Uint8Array(getObject(arg0));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_set_1a930cfcda1a8067(arg0, arg1, arg2) {
|
||||
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
||||
};
|
||||
|
||||
export function __wbg_length_51f19f73d6d9eff3(arg0) {
|
||||
const ret = getObject(arg0).length;
|
||||
return ret;
|
||||
};
|
||||
|
||||
export function __wbg_newwithlength_66e5530e7079ea1b(arg0) {
|
||||
const ret = new Uint8Array(arg0 >>> 0);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_subarray_270ff8dd5582c1ac(arg0, arg1, arg2) {
|
||||
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbindgen_debug_string(arg0, arg1) {
|
||||
const ret = debugString(getObject(arg1));
|
||||
const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
||||
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
||||
};
|
||||
|
||||
export function __wbindgen_throw(arg0, arg1) {
|
||||
throw new Error(getStringFromWasm0(arg0, arg1));
|
||||
};
|
||||
|
||||
export function __wbindgen_memory() {
|
||||
const ret = wasm.memory;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const memory: WebAssembly.Memory;
|
||||
export function __wbg_rln_free(a: number): void;
|
||||
export function newRLN(a: number, b: number, c: number): number;
|
||||
export function getSerializedRLNWitness(a: number, b: number): number;
|
||||
export function insertMember(a: number, b: number, c: number): void;
|
||||
export function RLNWitnessToJson(a: number, b: number): number;
|
||||
export function generate_rln_proof_with_witness(a: number, b: number, c: number, d: number, e: number): void;
|
||||
export function generateMembershipKey(a: number, b: number): void;
|
||||
export function verifyProof(a: number, b: number): number;
|
||||
export function init_panic_hook(): void;
|
||||
export function __wbg_wasmerruntimeerror_free(a: number): void;
|
||||
export function __wbindgen_malloc(a: number): number;
|
||||
export function __wbindgen_realloc(a: number, b: number, c: number): number;
|
||||
export function __wbindgen_add_to_stack_pointer(a: number): number;
|
||||
export function __wbindgen_free(a: number, b: number): void;
|
||||
export function __wbindgen_exn_store(a: number): void;
|
|
@ -7,6 +7,7 @@
|
|||
"moduleResolution": "node",
|
||||
"module": "es2020",
|
||||
"declaration": true,
|
||||
"allowJs": true,
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||
"resolveJsonModule": true /* Include modules imported with .json extension. */,
|
||||
|
|
Loading…
Reference in New Issue