@waku/rln 0.0.1 → 0.0.2-webpack.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/20ff36861f56116ae72f.module.wasm +0 -0
- package/bundle/939.index.js +1 -0
- package/bundle/index.js +1 -10
- package/bundle/{rln-f87f6dbe.js → rln-0e12a076.js} +68 -12
- package/bundle/rln-a1a9aa71.js +574 -0
- package/bundle/rln-affbe9d4.js +574 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/files.d.ts +4 -0
- package/dist/resources/files.js +5 -0
- package/dist/resources/files.js.map +1 -0
- package/dist/resources/rln.wasm +0 -0
- package/dist/rln.d.ts +17 -5
- package/dist/rln.js +70 -14
- package/dist/rln.js.map +1 -1
- package/dist/webpack.config.d.ts +6 -0
- package/dist/webpack.config.js +11 -0
- package/dist/webpack.config.js.map +1 -0
- package/dist/witness_calculator.cjs +294 -0
- package/dist/witness_calculator.cjs.map +1 -0
- package/dist/witness_calculator.d.cts +17 -0
- package/package.json +4 -3
- package/src/index.ts +2 -2
- package/src/rln.ts +115 -20
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/resources/files.ts"],"names":[],"mappings":"AAAA,IAAI,gBAAgB,GAAG,8gKAA8gK,CAAC;AACtiK,IAAI,QAAQ,GAAC,sjvlDAAsjvlD,CAAC;AACpkvlD,IAAI,IAAI,GAAC,0mxhIAA0mxhI,CAAC;AAEpnxhI,OAAO,EAAC,gBAAgB,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC"}
|
Binary file
|
package/dist/rln.d.ts
CHANGED
@@ -8,13 +8,25 @@ export declare class MembershipKey {
|
|
8
8
|
readonly IDCommitment: Uint8Array;
|
9
9
|
constructor(memKeys: Uint8Array);
|
10
10
|
}
|
11
|
+
export declare function toEpoch(timestamp: Date, epochUnitSeconds?: number): Uint8Array;
|
12
|
+
export declare class RateLimitProof {
|
13
|
+
readonly proof: Uint8Array;
|
14
|
+
readonly merkleRoot: Uint8Array;
|
15
|
+
readonly epoch: Uint8Array;
|
16
|
+
readonly shareX: Uint8Array;
|
17
|
+
readonly shareY: Uint8Array;
|
18
|
+
readonly nullifier: Uint8Array;
|
19
|
+
readonly rlnIdentifier: Uint8Array;
|
20
|
+
constructor(proofBytes: Uint8Array);
|
21
|
+
toBytes(): Uint8Array;
|
22
|
+
}
|
11
23
|
export declare class RLNInstance {
|
12
|
-
zkRLN
|
13
|
-
witnessCalculator
|
14
|
-
constructor(zkRLN: number,
|
24
|
+
private zkRLN;
|
25
|
+
private witnessCalculator;
|
26
|
+
constructor(zkRLN: number, witnessCalculator: any);
|
15
27
|
generateMembershipKey(): MembershipKey;
|
16
28
|
inserMember(idCommitment: Uint8Array): void;
|
17
29
|
serializeMessage(uint8Msg: Uint8Array, memIndex: number, epoch: Uint8Array, idKey: Uint8Array): Uint8Array;
|
18
|
-
generateProof(msg: Uint8Array, index: number, epoch: Uint8Array, idKey: Uint8Array): Promise<
|
19
|
-
verifyProof(proof: Uint8Array): boolean;
|
30
|
+
generateProof(msg: Uint8Array, index: number, epoch: Uint8Array | Date | undefined, idKey: Uint8Array): Promise<RateLimitProof>;
|
31
|
+
verifyProof(proof: RateLimitProof | Uint8Array): boolean;
|
20
32
|
}
|
package/dist/rln.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import * as resources from "./resources";
|
2
|
-
import * as wc from "./witness_calculator";
|
3
|
-
import * as zerokitRLN from "./zerokit/rln_wasm";
|
1
|
+
import * as resources from "./resources.js";
|
2
|
+
import * as wc from "./witness_calculator.js";
|
3
|
+
import * as zerokitRLN from "./zerokit/rln_wasm.js";
|
4
4
|
/**
|
5
5
|
* Convert a base64 string into uint8Array
|
6
6
|
* @param base64
|
@@ -53,10 +53,62 @@ export class MembershipKey {
|
|
53
53
|
this.IDCommitment = memKeys.subarray(32);
|
54
54
|
}
|
55
55
|
}
|
56
|
+
// Adapted from https://github.com/feross/buffer
|
57
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
58
|
+
if (value > max || value < min)
|
59
|
+
throw new RangeError('"value" argument is out of bounds');
|
60
|
+
if (offset + ext > buf.length)
|
61
|
+
throw new RangeError("Index out of range");
|
62
|
+
}
|
63
|
+
const writeUIntLE = function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
64
|
+
value = +value;
|
65
|
+
offset = offset >>> 0;
|
66
|
+
byteLength = byteLength >>> 0;
|
67
|
+
if (!noAssert) {
|
68
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
69
|
+
checkInt(buf, value, offset, byteLength, maxBytes, 0);
|
70
|
+
}
|
71
|
+
let mul = 1;
|
72
|
+
let i = 0;
|
73
|
+
buf[offset] = value & 0xff;
|
74
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
75
|
+
buf[offset + i] = (value / mul) & 0xff;
|
76
|
+
}
|
77
|
+
return buf;
|
78
|
+
};
|
79
|
+
const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
|
80
|
+
export function toEpoch(timestamp, epochUnitSeconds = DefaultEpochUnitSeconds) {
|
81
|
+
const unix = Math.floor(timestamp.getTime() / 1000 / epochUnitSeconds);
|
82
|
+
return writeUIntLE(new Uint8Array(32), unix, 0, 8);
|
83
|
+
}
|
84
|
+
const proofOffset = 128;
|
85
|
+
const rootOffset = proofOffset + 32;
|
86
|
+
const epochOffset = rootOffset + 32;
|
87
|
+
const shareXOffset = epochOffset + 32;
|
88
|
+
const shareYOffset = shareXOffset + 32;
|
89
|
+
const nullifierOffset = shareYOffset + 32;
|
90
|
+
const rlnIdentifierOffset = nullifierOffset + 32;
|
91
|
+
export class RateLimitProof {
|
92
|
+
constructor(proofBytes) {
|
93
|
+
if (proofBytes.length < rlnIdentifierOffset)
|
94
|
+
throw "invalid proof";
|
95
|
+
// parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32>
|
96
|
+
this.proof = proofBytes.subarray(0, proofOffset);
|
97
|
+
this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset);
|
98
|
+
this.epoch = proofBytes.subarray(rootOffset, epochOffset);
|
99
|
+
this.shareX = proofBytes.subarray(epochOffset, shareXOffset);
|
100
|
+
this.shareY = proofBytes.subarray(shareXOffset, shareYOffset);
|
101
|
+
this.nullifier = proofBytes.subarray(shareYOffset, nullifierOffset);
|
102
|
+
this.rlnIdentifier = proofBytes.subarray(nullifierOffset, rlnIdentifierOffset);
|
103
|
+
}
|
104
|
+
toBytes() {
|
105
|
+
return concatenate(this.proof, this.merkleRoot, this.epoch, this.shareX, this.shareY, this.nullifier, this.rlnIdentifier);
|
106
|
+
}
|
107
|
+
}
|
56
108
|
export class RLNInstance {
|
57
|
-
constructor(zkRLN,
|
109
|
+
constructor(zkRLN, witnessCalculator) {
|
58
110
|
this.zkRLN = zkRLN;
|
59
|
-
this.witnessCalculator =
|
111
|
+
this.witnessCalculator = witnessCalculator;
|
60
112
|
}
|
61
113
|
generateMembershipKey() {
|
62
114
|
const memKeys = zerokitRLN.generateMembershipKey(this.zkRLN);
|
@@ -66,20 +118,20 @@ export class RLNInstance {
|
|
66
118
|
zerokitRLN.insertMember(this.zkRLN, idCommitment);
|
67
119
|
}
|
68
120
|
serializeMessage(uint8Msg, memIndex, epoch, idKey) {
|
69
|
-
if (epoch.length != 32)
|
70
|
-
throw "invalid epoch";
|
71
|
-
if (idKey.length != 32)
|
72
|
-
throw "invalid id key";
|
73
121
|
// calculate message length
|
74
|
-
const msgLen =
|
75
|
-
msgLen.writeUIntLE(uint8Msg.length, 0, 8);
|
122
|
+
const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
76
123
|
// Converting index to LE bytes
|
77
|
-
const memIndexBytes =
|
78
|
-
memIndexBytes.writeUIntLE(memIndex, 0, 8);
|
124
|
+
const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
79
125
|
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
|
80
126
|
return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
|
81
127
|
}
|
82
128
|
async generateProof(msg, index, epoch, idKey) {
|
129
|
+
if (epoch == undefined) {
|
130
|
+
epoch = toEpoch(new Date());
|
131
|
+
}
|
132
|
+
else if (epoch instanceof Date) {
|
133
|
+
epoch = toEpoch(epoch);
|
134
|
+
}
|
83
135
|
if (epoch.length != 32)
|
84
136
|
throw "invalid epoch";
|
85
137
|
if (idKey.length != 32)
|
@@ -90,9 +142,13 @@ export class RLNInstance {
|
|
90
142
|
const rlnWitness = zerokitRLN.getSerializedRLNWitness(this.zkRLN, serialized_msg);
|
91
143
|
const inputs = zerokitRLN.RLNWitnessToJson(this.zkRLN, rlnWitness);
|
92
144
|
const calculatedWitness = await this.witnessCalculator.calculateWitness(inputs, false); // no sanity check being used in zerokit
|
93
|
-
|
145
|
+
const proofBytes = zerokitRLN.generate_rln_proof_with_witness(this.zkRLN, calculatedWitness, rlnWitness);
|
146
|
+
return new RateLimitProof(proofBytes);
|
94
147
|
}
|
95
148
|
verifyProof(proof) {
|
149
|
+
if (proof instanceof RateLimitProof) {
|
150
|
+
proof = proof.toBytes();
|
151
|
+
}
|
96
152
|
return zerokitRLN.verifyProof(this.zkRLN, proof);
|
97
153
|
}
|
98
154
|
}
|
package/dist/rln.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,
|
1
|
+
{"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAC9C,OAAO,KAAK,UAAU,MAAM,uBAAuB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AAC,CAAC,wCAAwC;QAE3C,MAAM,UAAU,GAAG,UAAU,CAAC,+BAA+B,CAC3D,IAAI,CAAC,KAAK,EACV,iBAAiB,EACjB,UAAU,CACX,CAAC;QAEF,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED,WAAW,CAAC,KAAkC;QAC5C,IAAI,KAAK,YAAY,cAAc,EAAE;YACnC,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;SACzB;QACD,OAAO,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;CACF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"webpack.config.js","sourceRoot":"","sources":["../src/webpack.config.js"],"names":[],"mappings":";AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7B,MAAM,CAAC,OAAO,GAAG;IACf,KAAK,EAAE,iBAAiB;IACxB,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;QACvC,QAAQ,EAAE,UAAU;KACrB;IACD,IAAI,EAAE,YAAY;CACnB,CAAC"}
|
@@ -0,0 +1,294 @@
|
|
1
|
+
// @ts-nocheck
|
2
|
+
/*eslint-disable*/
|
3
|
+
// File generated with https://github.com/iden3/circom
|
4
|
+
// following the instructions from:
|
5
|
+
// https://github.com/vacp2p/zerokit/tree/master/rln#compiling-circuits
|
6
|
+
module.exports = async function builder(code, options) {
|
7
|
+
options = options || {};
|
8
|
+
let wasmModule;
|
9
|
+
try {
|
10
|
+
wasmModule = await WebAssembly.compile(code);
|
11
|
+
}
|
12
|
+
catch (err) {
|
13
|
+
console.log(err);
|
14
|
+
console.log("\nTry to run circom --c in order to generate c++ code instead\n");
|
15
|
+
throw new Error(err);
|
16
|
+
}
|
17
|
+
let wc;
|
18
|
+
let errStr = "";
|
19
|
+
let msgStr = "";
|
20
|
+
const instance = await WebAssembly.instantiate(wasmModule, {
|
21
|
+
runtime: {
|
22
|
+
exceptionHandler: function (code) {
|
23
|
+
let err;
|
24
|
+
if (code == 1) {
|
25
|
+
err = "Signal not found.\n";
|
26
|
+
}
|
27
|
+
else if (code == 2) {
|
28
|
+
err = "Too many signals set.\n";
|
29
|
+
}
|
30
|
+
else if (code == 3) {
|
31
|
+
err = "Signal already set.\n";
|
32
|
+
}
|
33
|
+
else if (code == 4) {
|
34
|
+
err = "Assert Failed.\n";
|
35
|
+
}
|
36
|
+
else if (code == 5) {
|
37
|
+
err = "Not enough memory.\n";
|
38
|
+
}
|
39
|
+
else if (code == 6) {
|
40
|
+
err = "Input signal array access exceeds the size.\n";
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
err = "Unknown error.\n";
|
44
|
+
}
|
45
|
+
throw new Error(err + errStr);
|
46
|
+
},
|
47
|
+
printErrorMessage: function () {
|
48
|
+
errStr += getMessage() + "\n";
|
49
|
+
// console.error(getMessage());
|
50
|
+
},
|
51
|
+
writeBufferMessage: function () {
|
52
|
+
const msg = getMessage();
|
53
|
+
// Any calls to `log()` will always end with a `\n`, so that's when we print and reset
|
54
|
+
if (msg === "\n") {
|
55
|
+
console.log(msgStr);
|
56
|
+
msgStr = "";
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
// If we've buffered other content, put a space in between the items
|
60
|
+
if (msgStr !== "") {
|
61
|
+
msgStr += " ";
|
62
|
+
}
|
63
|
+
// Then append the message to the message we are creating
|
64
|
+
msgStr += msg;
|
65
|
+
}
|
66
|
+
},
|
67
|
+
showSharedRWMemory: function () {
|
68
|
+
printSharedRWMemory();
|
69
|
+
}
|
70
|
+
}
|
71
|
+
});
|
72
|
+
const sanityCheck = options;
|
73
|
+
// options &&
|
74
|
+
// (
|
75
|
+
// options.sanityCheck ||
|
76
|
+
// options.logGetSignal ||
|
77
|
+
// options.logSetSignal ||
|
78
|
+
// options.logStartComponent ||
|
79
|
+
// options.logFinishComponent
|
80
|
+
// );
|
81
|
+
wc = new WitnessCalculator(instance, sanityCheck);
|
82
|
+
return wc;
|
83
|
+
function getMessage() {
|
84
|
+
var message = "";
|
85
|
+
var c = instance.exports.getMessageChar();
|
86
|
+
while (c != 0) {
|
87
|
+
message += String.fromCharCode(c);
|
88
|
+
c = instance.exports.getMessageChar();
|
89
|
+
}
|
90
|
+
return message;
|
91
|
+
}
|
92
|
+
function printSharedRWMemory() {
|
93
|
+
const shared_rw_memory_size = instance.exports.getFieldNumLen32();
|
94
|
+
const arr = new Uint32Array(shared_rw_memory_size);
|
95
|
+
for (let j = 0; j < shared_rw_memory_size; j++) {
|
96
|
+
arr[shared_rw_memory_size - 1 - j] = instance.exports.readSharedRWMemory(j);
|
97
|
+
}
|
98
|
+
// If we've buffered other content, put a space in between the items
|
99
|
+
if (msgStr !== "") {
|
100
|
+
msgStr += " ";
|
101
|
+
}
|
102
|
+
// Then append the value to the message we are creating
|
103
|
+
msgStr += (fromArray32(arr).toString());
|
104
|
+
}
|
105
|
+
};
|
106
|
+
class WitnessCalculator {
|
107
|
+
constructor(instance, sanityCheck) {
|
108
|
+
this.instance = instance;
|
109
|
+
this.version = this.instance.exports.getVersion();
|
110
|
+
this.n32 = this.instance.exports.getFieldNumLen32();
|
111
|
+
this.instance.exports.getRawPrime();
|
112
|
+
const arr = new Uint32Array(this.n32);
|
113
|
+
for (let i = 0; i < this.n32; i++) {
|
114
|
+
arr[this.n32 - 1 - i] = this.instance.exports.readSharedRWMemory(i);
|
115
|
+
}
|
116
|
+
this.prime = fromArray32(arr);
|
117
|
+
this.witnessSize = this.instance.exports.getWitnessSize();
|
118
|
+
this.sanityCheck = sanityCheck;
|
119
|
+
}
|
120
|
+
circom_version() {
|
121
|
+
return this.instance.exports.getVersion();
|
122
|
+
}
|
123
|
+
async _doCalculateWitness(input, sanityCheck) {
|
124
|
+
//input is assumed to be a map from signals to arrays of bigints
|
125
|
+
this.instance.exports.init((this.sanityCheck || sanityCheck) ? 1 : 0);
|
126
|
+
const keys = Object.keys(input);
|
127
|
+
var input_counter = 0;
|
128
|
+
keys.forEach((k) => {
|
129
|
+
const h = fnvHash(k);
|
130
|
+
const hMSB = parseInt(h.slice(0, 8), 16);
|
131
|
+
const hLSB = parseInt(h.slice(8, 16), 16);
|
132
|
+
const fArr = flatArray(input[k]);
|
133
|
+
let signalSize = this.instance.exports.getInputSignalSize(hMSB, hLSB);
|
134
|
+
if (signalSize < 0) {
|
135
|
+
throw new Error(`Signal ${k} not found\n`);
|
136
|
+
}
|
137
|
+
if (fArr.length < signalSize) {
|
138
|
+
throw new Error(`Not enough values for input signal ${k}\n`);
|
139
|
+
}
|
140
|
+
if (fArr.length > signalSize) {
|
141
|
+
throw new Error(`Too many values for input signal ${k}\n`);
|
142
|
+
}
|
143
|
+
for (let i = 0; i < fArr.length; i++) {
|
144
|
+
const arrFr = toArray32(BigInt(fArr[i]) % this.prime, this.n32);
|
145
|
+
for (let j = 0; j < this.n32; j++) {
|
146
|
+
this.instance.exports.writeSharedRWMemory(j, arrFr[this.n32 - 1 - j]);
|
147
|
+
}
|
148
|
+
try {
|
149
|
+
this.instance.exports.setInputSignal(hMSB, hLSB, i);
|
150
|
+
input_counter++;
|
151
|
+
}
|
152
|
+
catch (err) {
|
153
|
+
// console.log(`After adding signal ${i} of ${k}`)
|
154
|
+
throw new Error(err);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
});
|
158
|
+
if (input_counter < this.instance.exports.getInputSize()) {
|
159
|
+
throw new Error(`Not all inputs have been set. Only ${input_counter} out of ${this.instance.exports.getInputSize()}`);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
async calculateWitness(input, sanityCheck) {
|
163
|
+
const w = [];
|
164
|
+
await this._doCalculateWitness(input, sanityCheck);
|
165
|
+
for (let i = 0; i < this.witnessSize; i++) {
|
166
|
+
this.instance.exports.getWitness(i);
|
167
|
+
const arr = new Uint32Array(this.n32);
|
168
|
+
for (let j = 0; j < this.n32; j++) {
|
169
|
+
arr[this.n32 - 1 - j] = this.instance.exports.readSharedRWMemory(j);
|
170
|
+
}
|
171
|
+
w.push(fromArray32(arr));
|
172
|
+
}
|
173
|
+
return w;
|
174
|
+
}
|
175
|
+
async calculateBinWitness(input, sanityCheck) {
|
176
|
+
const buff32 = new Uint32Array(this.witnessSize * this.n32);
|
177
|
+
const buff = new Uint8Array(buff32.buffer);
|
178
|
+
await this._doCalculateWitness(input, sanityCheck);
|
179
|
+
for (let i = 0; i < this.witnessSize; i++) {
|
180
|
+
this.instance.exports.getWitness(i);
|
181
|
+
const pos = i * this.n32;
|
182
|
+
for (let j = 0; j < this.n32; j++) {
|
183
|
+
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
return buff;
|
187
|
+
}
|
188
|
+
async calculateWTNSBin(input, sanityCheck) {
|
189
|
+
const buff32 = new Uint32Array(this.witnessSize * this.n32 + this.n32 + 11);
|
190
|
+
const buff = new Uint8Array(buff32.buffer);
|
191
|
+
await this._doCalculateWitness(input, sanityCheck);
|
192
|
+
//"wtns"
|
193
|
+
buff[0] = "w".charCodeAt(0);
|
194
|
+
buff[1] = "t".charCodeAt(0);
|
195
|
+
buff[2] = "n".charCodeAt(0);
|
196
|
+
buff[3] = "s".charCodeAt(0);
|
197
|
+
//version 2
|
198
|
+
buff32[1] = 2;
|
199
|
+
//number of sections: 2
|
200
|
+
buff32[2] = 2;
|
201
|
+
//id section 1
|
202
|
+
buff32[3] = 1;
|
203
|
+
const n8 = this.n32 * 4;
|
204
|
+
//id section 1 length in 64bytes
|
205
|
+
const idSection1length = 8 + n8;
|
206
|
+
const idSection1lengthHex = idSection1length.toString(16);
|
207
|
+
buff32[4] = parseInt(idSection1lengthHex.slice(0, 8), 16);
|
208
|
+
buff32[5] = parseInt(idSection1lengthHex.slice(8, 16), 16);
|
209
|
+
//this.n32
|
210
|
+
buff32[6] = n8;
|
211
|
+
//prime number
|
212
|
+
this.instance.exports.getRawPrime();
|
213
|
+
var pos = 7;
|
214
|
+
for (let j = 0; j < this.n32; j++) {
|
215
|
+
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
216
|
+
}
|
217
|
+
pos += this.n32;
|
218
|
+
// witness size
|
219
|
+
buff32[pos] = this.witnessSize;
|
220
|
+
pos++;
|
221
|
+
//id section 2
|
222
|
+
buff32[pos] = 2;
|
223
|
+
pos++;
|
224
|
+
// section 2 length
|
225
|
+
const idSection2length = n8 * this.witnessSize;
|
226
|
+
const idSection2lengthHex = idSection2length.toString(16);
|
227
|
+
buff32[pos] = parseInt(idSection2lengthHex.slice(0, 8), 16);
|
228
|
+
buff32[pos + 1] = parseInt(idSection2lengthHex.slice(8, 16), 16);
|
229
|
+
pos += 2;
|
230
|
+
for (let i = 0; i < this.witnessSize; i++) {
|
231
|
+
this.instance.exports.getWitness(i);
|
232
|
+
for (let j = 0; j < this.n32; j++) {
|
233
|
+
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
234
|
+
}
|
235
|
+
pos += this.n32;
|
236
|
+
}
|
237
|
+
return buff;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
function toArray32(rem, size) {
|
241
|
+
const res = []; //new Uint32Array(size); //has no unshift
|
242
|
+
const radix = BigInt(0x100000000);
|
243
|
+
while (rem) {
|
244
|
+
res.unshift(Number(rem % radix));
|
245
|
+
rem = rem / radix;
|
246
|
+
}
|
247
|
+
if (size) {
|
248
|
+
var i = size - res.length;
|
249
|
+
while (i > 0) {
|
250
|
+
res.unshift(0);
|
251
|
+
i--;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
return res;
|
255
|
+
}
|
256
|
+
function fromArray32(arr) {
|
257
|
+
var res = BigInt(0);
|
258
|
+
const radix = BigInt(0x100000000);
|
259
|
+
for (let i = 0; i < arr.length; i++) {
|
260
|
+
res = res * radix + BigInt(arr[i]);
|
261
|
+
}
|
262
|
+
return res;
|
263
|
+
}
|
264
|
+
function flatArray(a) {
|
265
|
+
var res = [];
|
266
|
+
fillArray(res, a);
|
267
|
+
return res;
|
268
|
+
function fillArray(res, a) {
|
269
|
+
if (Array.isArray(a)) {
|
270
|
+
for (let i = 0; i < a.length; i++) {
|
271
|
+
fillArray(res, a[i]);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
else {
|
275
|
+
res.push(a);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
}
|
279
|
+
function fnvHash(str) {
|
280
|
+
const uint64_max = BigInt(2) ** BigInt(64);
|
281
|
+
let hash = BigInt("0xCBF29CE484222325");
|
282
|
+
for (var i = 0; i < str.length; i++) {
|
283
|
+
hash ^= BigInt(str[i].charCodeAt());
|
284
|
+
hash *= BigInt(0x100000001B3);
|
285
|
+
hash %= uint64_max;
|
286
|
+
}
|
287
|
+
let shash = hash.toString(16);
|
288
|
+
let n = 16 - shash.length;
|
289
|
+
shash = '0'.repeat(n).concat(shash);
|
290
|
+
return shash;
|
291
|
+
}
|
292
|
+
module.exports = { builder };
|
293
|
+
export {};
|
294
|
+
//# sourceMappingURL=witness_calculator.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"witness_calculator.cjs","sourceRoot":"","sources":["../src/witness_calculator.cjs"],"names":[],"mappings":"AAAA,cAAc;AACd,kBAAkB;AAElB,sDAAsD;AACtD,mCAAmC;AACnC,uEAAuE;AAEvE,MAAM,CAAC,OAAO,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,EAAE,OAAO;IAEjD,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAExB,IAAI,UAAU,CAAC;IACf,IAAI;QACP,UAAU,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACzC;IAAE,OAAO,GAAG,EAAE;QAClB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;QAC/E,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;KACjB;IAED,IAAI,EAAE,CAA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C,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC3B,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACxB;SACJ;aAAM;YACH,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACf;IACL,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,GAAG;IAChB,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3C,IAAI,IAAI,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;QACpC,IAAI,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC;QAC9B,IAAI,IAAI,UAAU,CAAC;KACf;IACD,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;IAC1B,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,CAAA"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
declare function _exports(code: any, options: any): Promise<WitnessCalculator>;
|
2
|
+
declare namespace _exports { }
|
3
|
+
export = _exports;
|
4
|
+
declare class WitnessCalculator {
|
5
|
+
constructor(instance: any, sanityCheck: any);
|
6
|
+
instance: any;
|
7
|
+
version: any;
|
8
|
+
n32: any;
|
9
|
+
prime: bigint;
|
10
|
+
witnessSize: any;
|
11
|
+
sanityCheck: any;
|
12
|
+
circom_version(): any;
|
13
|
+
_doCalculateWitness(input: any, sanityCheck: any): Promise<void>;
|
14
|
+
calculateWitness(input: any, sanityCheck: any): Promise<bigint[]>;
|
15
|
+
calculateBinWitness(input: any, sanityCheck: any): Promise<Uint8Array>;
|
16
|
+
calculateWTNSBin(input: any, sanityCheck: any): Promise<Uint8Array>;
|
17
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/rln",
|
3
|
-
"version": "0.0.1",
|
3
|
+
"version": "0.0.2-webpack.1",
|
4
4
|
"description": "Rate Limit Nullifier for js-waku",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"prepare": "husky install",
|
26
26
|
"build": "run-s build:**",
|
27
27
|
"build:tsc": "tsc",
|
28
|
-
"build:bundle": "
|
28
|
+
"build:bundle": "webpack --config webpack.config.cjs",
|
29
29
|
"size": "npm run build && size-limit",
|
30
30
|
"fix": "run-s fix:*",
|
31
31
|
"fix:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.*js\" \".github/**/*.yml\" --write",
|
@@ -101,7 +101,8 @@
|
|
101
101
|
"ts-loader": "^9.3.1",
|
102
102
|
"ts-node": "^10.9.1",
|
103
103
|
"typedoc": "^0.23.10",
|
104
|
-
"typescript": "^4.5.5"
|
104
|
+
"typescript": "^4.5.5",
|
105
|
+
"webpack-cli": "^4.10.0"
|
105
106
|
},
|
106
107
|
"files": [
|
107
108
|
"dist",
|
package/src/index.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { RLNInstance } from "./rln";
|
1
|
+
import { RLNInstance } from "./rln.js";
|
2
2
|
|
3
3
|
// reexport the create function, dynamically imported from rln.ts
|
4
4
|
export async function create(): Promise<RLNInstance> {
|
5
5
|
// A dependency graph that contains any wasm must all be imported
|
6
6
|
// asynchronously. This file does the single async import, so
|
7
7
|
// that no one else needs to worry about it again.
|
8
|
-
const rlnModule = await import("./rln");
|
8
|
+
const rlnModule = await import("./rln.js");
|
9
9
|
|
10
10
|
return await rlnModule.create();
|
11
11
|
}
|