@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
package/bundle/index.js
CHANGED
@@ -1,10 +1 @@
|
|
1
|
-
|
2
|
-
async function create() {
|
3
|
-
// A dependency graph that contains any wasm must all be imported
|
4
|
-
// asynchronously. This file does the single async import, so
|
5
|
-
// that no one else needs to worry about it again.
|
6
|
-
const rlnModule = await import('./rln-f87f6dbe.js');
|
7
|
-
return await rlnModule.create();
|
8
|
-
}
|
9
|
-
|
10
|
-
export { create };
|
1
|
+
(()=>{"use strict";var e,r,t,n,o,a,i={},s={};function u(e){var r=s[e];if(void 0!==r)return r.exports;var t=s[e]={id:e,exports:{}};return i[e](t,t.exports,u),t.exports}u.m=i,e="function"==typeof Symbol?Symbol("webpack queues"):"__webpack_queues__",r="function"==typeof Symbol?Symbol("webpack exports"):"__webpack_exports__",t="function"==typeof Symbol?Symbol("webpack error"):"__webpack_error__",n=e=>{e&&!e.d&&(e.d=1,e.forEach((e=>e.r--)),e.forEach((e=>e.r--?e.r++:e())))},u.a=(o,a,i)=>{var s;i&&((s=[]).d=1);var u,c,l,p=new Set,f=o.exports,d=new Promise(((e,r)=>{l=r,c=e}));d[r]=f,d[e]=e=>(s&&e(s),p.forEach(e),d.catch((e=>{}))),o.exports=d,a((o=>{var a;u=(o=>o.map((o=>{if(null!==o&&"object"==typeof o){if(o[e])return o;if(o.then){var a=[];a.d=0,o.then((e=>{i[r]=e,n(a)}),(e=>{i[t]=e,n(a)}));var i={};return i[e]=e=>e(a),i}}var s={};return s[e]=e=>{},s[r]=o,s})))(o);var i=()=>u.map((e=>{if(e[t])throw e[t];return e[r]})),c=new Promise((r=>{(a=()=>r(i)).r=0;var t=e=>e!==s&&!p.has(e)&&(p.add(e),e&&!e.d&&(a.r++,e.push(a)));u.map((r=>r[e](t)))}));return a.r?c:i()}),(e=>(e?l(d[t]=e):c(f),n(s)))),s&&(s.d=0)},u.d=(e,r)=>{for(var t in r)u.o(r,t)&&!u.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},u.f={},u.e=e=>Promise.all(Object.keys(u.f).reduce(((r,t)=>(u.f[t](e,r),r)),[])),u.u=e=>e+".index.js",u.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),u.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),o={},a="@waku/rln:",u.l=(e,r,t,n)=>{if(o[e])o[e].push(r);else{var i,s;if(void 0!==t)for(var c=document.getElementsByTagName("script"),l=0;l<c.length;l++){var p=c[l];if(p.getAttribute("src")==e||p.getAttribute("data-webpack")==a+t){i=p;break}}i||(s=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,u.nc&&i.setAttribute("nonce",u.nc),i.setAttribute("data-webpack",a+t),i.src=e),o[e]=[r];var f=(r,t)=>{i.onerror=i.onload=null,clearTimeout(d);var n=o[e];if(delete o[e],i.parentNode&&i.parentNode.removeChild(i),n&&n.forEach((e=>e(t))),r)return r(t)},d=setTimeout(f.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=f.bind(null,i.onerror),i.onload=f.bind(null,i.onload),s&&document.head.appendChild(i)}},u.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u.v=(e,r,t,n)=>{var o=fetch(u.p+""+t+".module.wasm");return"function"==typeof WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(o,n).then((r=>Object.assign(e,r.instance.exports))):o.then((e=>e.arrayBuffer())).then((e=>WebAssembly.instantiate(e,n))).then((r=>Object.assign(e,r.instance.exports)))},(()=>{var e;u.g.importScripts&&(e=u.g.location+"");var r=u.g.document;if(!e&&r&&(r.currentScript&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");t.length&&(e=t[t.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),u.p=e})(),(()=>{var e={179:0};u.f.j=(r,t)=>{var n=u.o(e,r)?e[r]:void 0;if(0!==n)if(n)t.push(n[2]);else{var o=new Promise(((t,o)=>n=e[r]=[t,o]));t.push(n[2]=o);var a=u.p+u.u(r),i=new Error;u.l(a,(t=>{if(u.o(e,r)&&(0!==(n=e[r])&&(e[r]=void 0),n)){var o=t&&("load"===t.type?"missing":t.type),a=t&&t.target&&t.target.src;i.message="Loading chunk "+r+" failed.\n("+o+": "+a+")",i.name="ChunkLoadError",i.type=o,i.request=a,n[1](i)}}),"chunk-"+r,r)}};var r=(r,t)=>{var n,o,[a,i,s]=t,c=0;if(a.some((r=>0!==e[r]))){for(n in i)u.o(i,n)&&(u.m[n]=i[n]);s&&s(u)}for(r&&r(t);c<a.length;c++)o=a[c],u.o(e,o)&&e[o]&&e[o][0](),e[o]=0},t=self.webpackChunk_waku_rln=self.webpackChunk_waku_rln||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})()})();
|
@@ -516,10 +516,62 @@ class MembershipKey {
|
|
516
516
|
this.IDCommitment = memKeys.subarray(32);
|
517
517
|
}
|
518
518
|
}
|
519
|
+
// Adapted from https://github.com/feross/buffer
|
520
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
521
|
+
if (value > max || value < min)
|
522
|
+
throw new RangeError('"value" argument is out of bounds');
|
523
|
+
if (offset + ext > buf.length)
|
524
|
+
throw new RangeError("Index out of range");
|
525
|
+
}
|
526
|
+
const writeUIntLE = function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
527
|
+
value = +value;
|
528
|
+
offset = offset >>> 0;
|
529
|
+
byteLength = byteLength >>> 0;
|
530
|
+
if (!noAssert) {
|
531
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
532
|
+
checkInt(buf, value, offset, byteLength, maxBytes, 0);
|
533
|
+
}
|
534
|
+
let mul = 1;
|
535
|
+
let i = 0;
|
536
|
+
buf[offset] = value & 0xff;
|
537
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
538
|
+
buf[offset + i] = (value / mul) & 0xff;
|
539
|
+
}
|
540
|
+
return buf;
|
541
|
+
};
|
542
|
+
const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
|
543
|
+
function toEpoch(timestamp, epochUnitSeconds = DefaultEpochUnitSeconds) {
|
544
|
+
const unix = Math.floor(timestamp.getTime() / 1000 / epochUnitSeconds);
|
545
|
+
return writeUIntLE(new Uint8Array(32), unix, 0, 8);
|
546
|
+
}
|
547
|
+
const proofOffset = 128;
|
548
|
+
const rootOffset = proofOffset + 32;
|
549
|
+
const epochOffset = rootOffset + 32;
|
550
|
+
const shareXOffset = epochOffset + 32;
|
551
|
+
const shareYOffset = shareXOffset + 32;
|
552
|
+
const nullifierOffset = shareYOffset + 32;
|
553
|
+
const rlnIdentifierOffset = nullifierOffset + 32;
|
554
|
+
class RateLimitProof {
|
555
|
+
constructor(proofBytes) {
|
556
|
+
if (proofBytes.length < rlnIdentifierOffset)
|
557
|
+
throw "invalid proof";
|
558
|
+
// parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32>
|
559
|
+
this.proof = proofBytes.subarray(0, proofOffset);
|
560
|
+
this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset);
|
561
|
+
this.epoch = proofBytes.subarray(rootOffset, epochOffset);
|
562
|
+
this.shareX = proofBytes.subarray(epochOffset, shareXOffset);
|
563
|
+
this.shareY = proofBytes.subarray(shareXOffset, shareYOffset);
|
564
|
+
this.nullifier = proofBytes.subarray(shareYOffset, nullifierOffset);
|
565
|
+
this.rlnIdentifier = proofBytes.subarray(nullifierOffset, rlnIdentifierOffset);
|
566
|
+
}
|
567
|
+
toBytes() {
|
568
|
+
return concatenate(this.proof, this.merkleRoot, this.epoch, this.shareX, this.shareY, this.nullifier, this.rlnIdentifier);
|
569
|
+
}
|
570
|
+
}
|
519
571
|
class RLNInstance {
|
520
|
-
constructor(zkRLN,
|
572
|
+
constructor(zkRLN, witnessCalculator) {
|
521
573
|
this.zkRLN = zkRLN;
|
522
|
-
this.witnessCalculator =
|
574
|
+
this.witnessCalculator = witnessCalculator;
|
523
575
|
}
|
524
576
|
generateMembershipKey() {
|
525
577
|
const memKeys = generateMembershipKey(this.zkRLN);
|
@@ -529,20 +581,20 @@ class RLNInstance {
|
|
529
581
|
insertMember(this.zkRLN, idCommitment);
|
530
582
|
}
|
531
583
|
serializeMessage(uint8Msg, memIndex, epoch, idKey) {
|
532
|
-
if (epoch.length != 32)
|
533
|
-
throw "invalid epoch";
|
534
|
-
if (idKey.length != 32)
|
535
|
-
throw "invalid id key";
|
536
584
|
// calculate message length
|
537
|
-
const msgLen =
|
538
|
-
msgLen.writeUIntLE(uint8Msg.length, 0, 8);
|
585
|
+
const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
539
586
|
// Converting index to LE bytes
|
540
|
-
const memIndexBytes =
|
541
|
-
memIndexBytes.writeUIntLE(memIndex, 0, 8);
|
587
|
+
const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
542
588
|
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
|
543
589
|
return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
|
544
590
|
}
|
545
591
|
async generateProof(msg, index, epoch, idKey) {
|
592
|
+
if (epoch == undefined) {
|
593
|
+
epoch = toEpoch(new Date());
|
594
|
+
}
|
595
|
+
else if (epoch instanceof Date) {
|
596
|
+
epoch = toEpoch(epoch);
|
597
|
+
}
|
546
598
|
if (epoch.length != 32)
|
547
599
|
throw "invalid epoch";
|
548
600
|
if (idKey.length != 32)
|
@@ -553,11 +605,15 @@ class RLNInstance {
|
|
553
605
|
const rlnWitness = getSerializedRLNWitness(this.zkRLN, serialized_msg);
|
554
606
|
const inputs = RLNWitnessToJson(this.zkRLN, rlnWitness);
|
555
607
|
const calculatedWitness = await this.witnessCalculator.calculateWitness(inputs, false); // no sanity check being used in zerokit
|
556
|
-
|
608
|
+
const proofBytes = generate_rln_proof_with_witness(this.zkRLN, calculatedWitness, rlnWitness);
|
609
|
+
return new RateLimitProof(proofBytes);
|
557
610
|
}
|
558
611
|
verifyProof(proof) {
|
612
|
+
if (proof instanceof RateLimitProof) {
|
613
|
+
proof = proof.toBytes();
|
614
|
+
}
|
559
615
|
return verifyProof(this.zkRLN, proof);
|
560
616
|
}
|
561
617
|
}
|
562
618
|
|
563
|
-
export { MembershipKey, RLNInstance, create };
|
619
|
+
export { MembershipKey, RLNInstance, RateLimitProof, create, toEpoch };
|