@waku/rln 0.1.8-e224c05.0 → 0.1.8-e800af3.0
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/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/index.js +6 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/_sha2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/hmac.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/pbkdf2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/scrypt.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha256.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha512.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/utils.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
- package/bundle/node_modules/@chainsafe/is-ip/lib/is-ip.js +12 -0
- package/bundle/node_modules/@chainsafe/is-ip/lib/parse.js +26 -0
- package/bundle/node_modules/@chainsafe/is-ip/lib/parser.js +202 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/constants.js +43 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/errors.js +17 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/registry.js +245 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/utils.js +191 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/validation.js +30 -0
- package/bundle/node_modules/@noble/hashes/esm/hmac.js +88 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +1 -1
- package/bundle/node_modules/@noble/hashes/esm/utils.js +8 -1
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +517 -255
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +3 -1
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +4 -2
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +3 -1
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +3 -1
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +11 -9
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +4 -2
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +4 -2
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +6 -4
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +3 -1
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +3 -1
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +15 -1
- package/bundle/node_modules/multiformats/dist/src/cid.js +371 -0
- package/bundle/node_modules/multiformats/dist/src/hashes/digest.js +62 -0
- package/bundle/node_modules/multiformats/dist/src/varint.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/varint.js +78 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/concat.js +20 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/to-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/as-uint8array.js +9 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_limiter.js +18 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +24 -0
- package/bundle/packages/core/dist/lib/connection_manager/dialer.js +14 -0
- package/bundle/packages/core/dist/lib/connection_manager/discovery_dialer.js +14 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +15 -0
- package/bundle/packages/core/dist/lib/connection_manager/shard_reader.js +14 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +28 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +28 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +172 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +28 -0
- package/bundle/packages/core/dist/lib/store/store.js +24 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +9 -0
- package/bundle/packages/interfaces/dist/health_status.js +17 -0
- package/bundle/packages/interfaces/dist/protocols.js +92 -0
- package/bundle/packages/interfaces/dist/waku.js +7 -0
- package/bundle/packages/proto/dist/generated/filter.js +447 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +426 -0
- package/bundle/packages/proto/dist/generated/light_push.js +550 -0
- package/bundle/packages/proto/dist/generated/message.js +215 -0
- package/bundle/packages/proto/dist/generated/metadata.js +132 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +211 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +172 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +492 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +63 -0
- package/bundle/packages/rln/dist/codec.js +92 -0
- package/bundle/packages/rln/dist/contract/constants.js +14 -7
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +2 -1
- package/bundle/packages/rln/dist/contract/rln_contract.js +109 -0
- package/bundle/packages/rln/dist/credentials_manager.js +45 -4
- package/bundle/packages/rln/dist/identity.js +2 -1
- package/bundle/packages/rln/dist/keystore/keystore.js +30 -9
- package/bundle/packages/rln/dist/message.js +59 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +1 -1
- package/bundle/packages/rln/dist/rln.js +36 -4
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +70 -31
- package/bundle/packages/rln/dist/utils/epoch.js +23 -1
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/zerokit.js +99 -2
- package/bundle/packages/utils/dist/bytes/index.js +31 -0
- package/bundle/resources/rln.wasm +0 -0
- package/bundle/resources/rln_final.zkey +0 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +7 -21
- package/bundle/resources/witness_calculator.js +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.d.ts +40 -0
- package/dist/codec.js +79 -0
- package/dist/codec.js.map +1 -0
- package/dist/codec.test-utils.d.ts +37 -0
- package/dist/codec.test-utils.js +61 -0
- package/dist/codec.test-utils.js.map +1 -0
- package/dist/contract/constants.d.ts +10 -3
- package/dist/contract/constants.js +13 -6
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/index.d.ts +1 -0
- package/dist/contract/index.js +1 -0
- package/dist/contract/index.js.map +1 -1
- package/dist/contract/rln_base_contract.js +2 -1
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +17 -0
- package/dist/contract/rln_contract.js +107 -0
- package/dist/contract/rln_contract.js.map +1 -0
- package/dist/contract/test_setup.d.ts +26 -0
- package/dist/contract/test_setup.js +56 -0
- package/dist/contract/test_setup.js.map +1 -0
- package/dist/contract/test_utils.d.ts +39 -0
- package/dist/contract/test_utils.js +118 -0
- package/dist/contract/test_utils.js.map +1 -0
- package/dist/credentials_manager.d.ts +14 -2
- package/dist/credentials_manager.js +45 -4
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.js +2 -1
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.js +30 -9
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/message.d.ts +19 -0
- package/dist/message.js +51 -0
- package/dist/message.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +50 -0
- package/dist/proof.js.map +1 -0
- package/dist/resources/rln.wasm +0 -0
- package/dist/resources/rln_final.zkey +0 -0
- package/dist/resources/verification_key.d.ts +13 -0
- package/dist/resources/verification_key.js +112 -0
- package/dist/resources/witness_calculator.d.ts +7 -21
- package/dist/resources/witness_calculator.js +1 -1
- package/dist/rln.d.ts +9 -0
- package/dist/rln.js +32 -4
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.d.ts +10 -0
- package/dist/root_tracker.js +75 -0
- package/dist/root_tracker.js.map +1 -0
- package/dist/utils/bytes.d.ts +31 -9
- package/dist/utils/bytes.js +70 -31
- package/dist/utils/bytes.js.map +1 -1
- package/dist/zerokit.d.ts +11 -0
- package/dist/zerokit.js +97 -1
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -1
- package/src/codec.test-utils.ts +88 -0
- package/src/codec.ts +138 -0
- package/src/contract/constants.ts +16 -6
- package/src/contract/index.ts +1 -0
- package/src/contract/rln_base_contract.ts +2 -1
- package/src/contract/rln_contract.ts +147 -0
- package/src/contract/test_setup.ts +86 -0
- package/src/contract/test_utils.ts +179 -0
- package/src/credentials_manager.ts +72 -8
- package/src/identity.ts +2 -1
- package/src/index.ts +11 -1
- package/src/keystore/keystore.ts +32 -9
- package/src/message.ts +73 -0
- package/src/proof.ts +69 -0
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +7 -21
- package/src/rln.ts +65 -5
- package/src/root_tracker.ts +92 -0
- package/src/utils/bytes.ts +73 -36
- package/src/zerokit.ts +217 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const verificationKey: {
|
|
2
|
+
protocol: string;
|
|
3
|
+
curve: string;
|
|
4
|
+
nPublic: number;
|
|
5
|
+
vk_alpha_1: string[];
|
|
6
|
+
vk_beta_2: string[][];
|
|
7
|
+
vk_gamma_2: string[][];
|
|
8
|
+
vk_delta_2: string[][];
|
|
9
|
+
vk_alphabeta_12: string[][][];
|
|
10
|
+
IC: string[][];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default verificationKey;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const verificationKey = {
|
|
2
|
+
protocol: "groth16",
|
|
3
|
+
curve: "bn128",
|
|
4
|
+
nPublic: 6,
|
|
5
|
+
vk_alpha_1: [
|
|
6
|
+
"20124996762962216725442980738609010303800849578410091356605067053491763969391",
|
|
7
|
+
"9118593021526896828671519912099489027245924097793322973632351264852174143923",
|
|
8
|
+
"1"
|
|
9
|
+
],
|
|
10
|
+
vk_beta_2: [
|
|
11
|
+
[
|
|
12
|
+
"4693952934005375501364248788849686435240706020501681709396105298107971354382",
|
|
13
|
+
"14346958885444710485362620645446987998958218205939139994511461437152241966681"
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"16851772916911573982706166384196538392731905827088356034885868448550849804972",
|
|
17
|
+
"823612331030938060799959717749043047845343400798220427319188951998582076532"
|
|
18
|
+
],
|
|
19
|
+
["1", "0"]
|
|
20
|
+
],
|
|
21
|
+
vk_gamma_2: [
|
|
22
|
+
[
|
|
23
|
+
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
|
24
|
+
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
|
28
|
+
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
|
29
|
+
],
|
|
30
|
+
["1", "0"]
|
|
31
|
+
],
|
|
32
|
+
vk_delta_2: [
|
|
33
|
+
[
|
|
34
|
+
"8353516066399360694538747105302262515182301251524941126222712285088022964076",
|
|
35
|
+
"9329524012539638256356482961742014315122377605267454801030953882967973561832"
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
"16805391589556134376869247619848130874761233086443465978238468412168162326401",
|
|
39
|
+
"10111259694977636294287802909665108497237922060047080343914303287629927847739"
|
|
40
|
+
],
|
|
41
|
+
["1", "0"]
|
|
42
|
+
],
|
|
43
|
+
vk_alphabeta_12: [
|
|
44
|
+
[
|
|
45
|
+
[
|
|
46
|
+
"12608968655665301215455851857466367636344427685631271961542642719683786103711",
|
|
47
|
+
"9849575605876329747382930567422916152871921500826003490242628251047652318086"
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"6322029441245076030714726551623552073612922718416871603535535085523083939021",
|
|
51
|
+
"8700115492541474338049149013125102281865518624059015445617546140629435818912"
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
"10674973475340072635573101639867487770811074181475255667220644196793546640210",
|
|
55
|
+
"2926286967251299230490668407790788696102889214647256022788211245826267484824"
|
|
56
|
+
]
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
[
|
|
60
|
+
"9660441540778523475944706619139394922744328902833875392144658911530830074820",
|
|
61
|
+
"19548113127774514328631808547691096362144426239827206966690021428110281506546"
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
"1870837942477655969123169532603615788122896469891695773961478956740992497097",
|
|
65
|
+
"12536105729661705698805725105036536744930776470051238187456307227425796690780"
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
"21811903352654147452884857281720047789720483752548991551595462057142824037334",
|
|
69
|
+
"19021616763967199151052893283384285352200445499680068407023236283004353578353"
|
|
70
|
+
]
|
|
71
|
+
]
|
|
72
|
+
],
|
|
73
|
+
IC: [
|
|
74
|
+
[
|
|
75
|
+
"11992897507809711711025355300535923222599547639134311050809253678876341466909",
|
|
76
|
+
"17181525095924075896332561978747020491074338784673526378866503154966799128110",
|
|
77
|
+
"1"
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
"17018665030246167677911144513385572506766200776123272044534328594850561667818",
|
|
81
|
+
"18601114175490465275436712413925513066546725461375425769709566180981674884464",
|
|
82
|
+
"1"
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"18799470100699658367834559797874857804183288553462108031963980039244731716542",
|
|
86
|
+
"13064227487174191981628537974951887429496059857753101852163607049188825592007",
|
|
87
|
+
"1"
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
"17432501889058124609368103715904104425610382063762621017593209214189134571156",
|
|
91
|
+
"13406815149699834788256141097399354592751313348962590382887503595131085938635",
|
|
92
|
+
"1"
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
"10320964835612716439094703312987075811498239445882526576970512041988148264481",
|
|
96
|
+
"9024164961646353611176283204118089412001502110138072989569118393359029324867",
|
|
97
|
+
"1"
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
"718355081067365548229685160476620267257521491773976402837645005858953849298",
|
|
101
|
+
"14635482993933988261008156660773180150752190597753512086153001683711587601974",
|
|
102
|
+
"1"
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
"11777720285956632126519898515392071627539405001940313098390150593689568177535",
|
|
106
|
+
"8483603647274280691250972408211651407952870456587066148445913156086740744515",
|
|
107
|
+
"1"
|
|
108
|
+
]
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export default verificationKey;
|
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export async function builder(
|
|
2
2
|
code: Uint8Array,
|
|
3
|
-
sanityCheck
|
|
4
|
-
)
|
|
3
|
+
sanityCheck: boolean
|
|
4
|
+
): Promise<WitnessCalculator>;
|
|
5
5
|
|
|
6
6
|
export class WitnessCalculator {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
calculateWitness(
|
|
12
|
-
input: Record<string, unknown>,
|
|
13
|
-
sanityCheck?: boolean
|
|
14
|
-
): Promise<bigint[]>;
|
|
15
|
-
|
|
16
|
-
calculateBinWitness(
|
|
17
|
-
input: Record<string, unknown>,
|
|
18
|
-
sanityCheck?: boolean
|
|
19
|
-
): Promise<Uint8Array>;
|
|
20
|
-
|
|
21
|
-
calculateWTNSBin(
|
|
22
|
-
input: Record<string, unknown>,
|
|
23
|
-
sanityCheck?: boolean
|
|
24
|
-
): Promise<Uint8Array>;
|
|
7
|
+
public calculateWitness(
|
|
8
|
+
input: unknown,
|
|
9
|
+
sanityCheck: boolean
|
|
10
|
+
): Promise<Array<bigint>>;
|
|
25
11
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated with https://github.com/iden3/circom
|
|
2
2
|
// following the instructions from:
|
|
3
|
-
// https://github.com/vacp2p/zerokit/tree/master/rln#
|
|
3
|
+
// https://github.com/vacp2p/zerokit/tree/master/rln#compiling-circuits
|
|
4
4
|
|
|
5
5
|
export async function builder(code, options) {
|
|
6
6
|
options = options || {};
|
package/dist/rln.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import type { ContentTopic, IDecodedMessage, IRoutingInfo, EncoderOptions as WakuEncoderOptions } from "@waku/interfaces";
|
|
2
|
+
import { type RLNDecoder, type RLNEncoder } from "./codec.js";
|
|
1
3
|
import { RLNCredentialsManager } from "./credentials_manager.js";
|
|
4
|
+
import type { DecryptedCredentials, EncryptedCredentials } from "./keystore/index.js";
|
|
2
5
|
import { WitnessCalculator } from "./resources/witness_calculator";
|
|
3
6
|
import { Zerokit } from "./zerokit.js";
|
|
7
|
+
type WakuRLNEncoderOptions = WakuEncoderOptions & {
|
|
8
|
+
credentials: EncryptedCredentials | DecryptedCredentials;
|
|
9
|
+
};
|
|
4
10
|
export declare class RLNInstance extends RLNCredentialsManager {
|
|
5
11
|
zerokit: Zerokit;
|
|
6
12
|
/**
|
|
@@ -9,6 +15,9 @@ export declare class RLNInstance extends RLNCredentialsManager {
|
|
|
9
15
|
*/
|
|
10
16
|
static create(): Promise<RLNInstance>;
|
|
11
17
|
private constructor();
|
|
18
|
+
createEncoder(options: WakuRLNEncoderOptions): Promise<RLNEncoder>;
|
|
19
|
+
createDecoder(contentTopic: ContentTopic, routingInfo: IRoutingInfo): RLNDecoder<IDecodedMessage>;
|
|
12
20
|
static loadWitnessCalculator(): Promise<WitnessCalculator>;
|
|
13
21
|
static loadZkey(): Promise<Uint8Array>;
|
|
14
22
|
}
|
|
23
|
+
export {};
|
package/dist/rln.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { createDecoder, createEncoder } from "@waku/core";
|
|
1
2
|
import { Logger } from "@waku/utils";
|
|
2
|
-
import init
|
|
3
|
+
import init from "@waku/zerokit-rln-wasm";
|
|
4
|
+
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
|
5
|
+
import { createRLNDecoder, createRLNEncoder } from "./codec.js";
|
|
3
6
|
import { DEFAULT_RATE_LIMIT } from "./contract/constants.js";
|
|
4
7
|
import { RLNCredentialsManager } from "./credentials_manager.js";
|
|
8
|
+
import verificationKey from "./resources/verification_key";
|
|
5
9
|
import * as wc from "./resources/witness_calculator";
|
|
6
10
|
import { Zerokit } from "./zerokit.js";
|
|
7
11
|
const log = new Logger("waku:rln");
|
|
@@ -13,11 +17,15 @@ export class RLNInstance extends RLNCredentialsManager {
|
|
|
13
17
|
*/
|
|
14
18
|
static async create() {
|
|
15
19
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
await init?.();
|
|
22
|
+
zerokitRLN.init_panic_hook();
|
|
18
23
|
const witnessCalculator = await RLNInstance.loadWitnessCalculator();
|
|
19
24
|
const zkey = await RLNInstance.loadZkey();
|
|
20
|
-
const
|
|
25
|
+
const stringEncoder = new TextEncoder();
|
|
26
|
+
const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
|
|
27
|
+
const DEPTH = 20;
|
|
28
|
+
const zkRLN = zerokitRLN.newRLN(DEPTH, zkey, vkey);
|
|
21
29
|
const zerokit = new Zerokit(zkRLN, witnessCalculator, DEFAULT_RATE_LIMIT);
|
|
22
30
|
return new RLNInstance(zerokit);
|
|
23
31
|
}
|
|
@@ -30,6 +38,26 @@ export class RLNInstance extends RLNCredentialsManager {
|
|
|
30
38
|
super(zerokit);
|
|
31
39
|
this.zerokit = zerokit;
|
|
32
40
|
}
|
|
41
|
+
async createEncoder(options) {
|
|
42
|
+
const { credentials: decryptedCredentials } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
|
43
|
+
const credentials = decryptedCredentials || this.credentials;
|
|
44
|
+
if (!credentials) {
|
|
45
|
+
throw Error("Failed to create Encoder: missing RLN credentials. Use createRLNEncoder directly.");
|
|
46
|
+
}
|
|
47
|
+
await this.verifyCredentialsAgainstContract(credentials);
|
|
48
|
+
return createRLNEncoder({
|
|
49
|
+
encoder: createEncoder(options),
|
|
50
|
+
rlnInstance: this,
|
|
51
|
+
index: credentials.membership.treeIndex,
|
|
52
|
+
credential: credentials.identity
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
createDecoder(contentTopic, routingInfo) {
|
|
56
|
+
return createRLNDecoder({
|
|
57
|
+
rlnInstance: this,
|
|
58
|
+
decoder: createDecoder(contentTopic, routingInfo)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
33
61
|
static async loadWitnessCalculator() {
|
|
34
62
|
try {
|
|
35
63
|
const url = new URL("./resources/rln.wasm", import.meta.url);
|
package/dist/rln.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAO1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAKjE,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AAMnC,MAAM,OAAO,WAAY,SAAQ,qBAAqB;IA4BzB;IA3B3B;;;OAGG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM;QACxB,IAAI,CAAC;YACH,8DAA8D;YAC9D,MAAO,IAAY,EAAE,EAAE,CAAC;YACxB,UAAU,CAAC,eAAe,EAAE,CAAC;YAE7B,MAAM,iBAAiB,GAAG,MAAM,WAAW,CAAC,qBAAqB,EAAE,CAAC;YACpE,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;YAE1C,MAAM,aAAa,GAAG,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AQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAClE,CAAC;YACJ,CAAC;YAED,OAAO,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,wBAAwB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACjF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class MerkleRootTracker {
|
|
2
|
+
private acceptableRootWindowSize;
|
|
3
|
+
private validMerkleRoots;
|
|
4
|
+
private merkleRootBuffer;
|
|
5
|
+
constructor(acceptableRootWindowSize: number, initialRoot: Uint8Array);
|
|
6
|
+
backFill(fromBlockNumber: number): void;
|
|
7
|
+
pushRoot(blockNumber: number, root: Uint8Array): void;
|
|
8
|
+
roots(): Array<Uint8Array>;
|
|
9
|
+
buffer(): Array<Uint8Array>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
class RootPerBlock {
|
|
2
|
+
root;
|
|
3
|
+
blockNumber;
|
|
4
|
+
constructor(root, blockNumber) {
|
|
5
|
+
this.root = root;
|
|
6
|
+
this.blockNumber = blockNumber;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const maxBufferSize = 20;
|
|
10
|
+
export class MerkleRootTracker {
|
|
11
|
+
acceptableRootWindowSize;
|
|
12
|
+
validMerkleRoots = new Array();
|
|
13
|
+
merkleRootBuffer = new Array();
|
|
14
|
+
constructor(acceptableRootWindowSize, initialRoot) {
|
|
15
|
+
this.acceptableRootWindowSize = acceptableRootWindowSize;
|
|
16
|
+
this.pushRoot(0, initialRoot);
|
|
17
|
+
}
|
|
18
|
+
backFill(fromBlockNumber) {
|
|
19
|
+
if (this.validMerkleRoots.length == 0)
|
|
20
|
+
return;
|
|
21
|
+
let numBlocks = 0;
|
|
22
|
+
for (let i = this.validMerkleRoots.length - 1; i >= 0; i--) {
|
|
23
|
+
if (this.validMerkleRoots[i].blockNumber >= fromBlockNumber) {
|
|
24
|
+
numBlocks++;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (numBlocks == 0)
|
|
28
|
+
return;
|
|
29
|
+
const olderBlock = fromBlockNumber < this.validMerkleRoots[0].blockNumber;
|
|
30
|
+
// Remove last roots
|
|
31
|
+
let rootsToPop = numBlocks;
|
|
32
|
+
if (this.validMerkleRoots.length < rootsToPop) {
|
|
33
|
+
rootsToPop = this.validMerkleRoots.length;
|
|
34
|
+
}
|
|
35
|
+
this.validMerkleRoots = this.validMerkleRoots.slice(0, this.validMerkleRoots.length - rootsToPop);
|
|
36
|
+
if (this.merkleRootBuffer.length == 0)
|
|
37
|
+
return;
|
|
38
|
+
if (olderBlock) {
|
|
39
|
+
const idx = this.merkleRootBuffer.findIndex((x) => x.blockNumber == fromBlockNumber);
|
|
40
|
+
if (idx > -1) {
|
|
41
|
+
this.merkleRootBuffer = this.merkleRootBuffer.slice(0, idx);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Backfill the tree's acceptable roots
|
|
45
|
+
let rootsToRestore = this.acceptableRootWindowSize - this.validMerkleRoots.length;
|
|
46
|
+
if (this.merkleRootBuffer.length < rootsToRestore) {
|
|
47
|
+
rootsToRestore = this.merkleRootBuffer.length;
|
|
48
|
+
}
|
|
49
|
+
for (let i = 0; i < rootsToRestore; i++) {
|
|
50
|
+
const x = this.merkleRootBuffer.pop();
|
|
51
|
+
if (x)
|
|
52
|
+
this.validMerkleRoots.unshift(x);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
pushRoot(blockNumber, root) {
|
|
56
|
+
this.validMerkleRoots.push(new RootPerBlock(root, blockNumber));
|
|
57
|
+
// Maintain valid merkle root window
|
|
58
|
+
if (this.validMerkleRoots.length > this.acceptableRootWindowSize) {
|
|
59
|
+
const x = this.validMerkleRoots.shift();
|
|
60
|
+
if (x)
|
|
61
|
+
this.merkleRootBuffer.push(x);
|
|
62
|
+
}
|
|
63
|
+
// Maintain merkle root buffer
|
|
64
|
+
if (this.merkleRootBuffer.length > maxBufferSize) {
|
|
65
|
+
this.merkleRootBuffer.shift();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
roots() {
|
|
69
|
+
return this.validMerkleRoots.map((x) => x.root);
|
|
70
|
+
}
|
|
71
|
+
buffer() {
|
|
72
|
+
return this.merkleRootBuffer.map((x) => x.root);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=root_tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root_tracker.js","sourceRoot":"","sources":["../src/root_tracker.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY;IAEP;IACA;IAFT,YACS,IAAgB,EAChB,WAAmB;QADnB,SAAI,GAAJ,IAAI,CAAY;QAChB,gBAAW,GAAX,WAAW,CAAQ;IACzB,CAAC;CACL;AAED,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB,MAAM,OAAO,iBAAiB;IAKlB;IAJF,gBAAgB,GAAwB,IAAI,KAAK,EAAgB,CAAC;IAClE,gBAAgB,GAAwB,IAAI,KAAK,EAAgB,CAAC;IAE1E,YACU,wBAAgC,EACxC,WAAuB;QADf,6BAAwB,GAAxB,wBAAwB,CAAQ;QAGxC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAChC,CAAC;IAEM,QAAQ,CAAC,eAAuB;QACrC,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,IAAI,CAAC;YAAE,OAAO;QAE9C,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,KAAK,IAAI,CAAC,GAAG,IAA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ED
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
export declare class BytesUtils {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param input
|
|
5
|
-
* @returns concatenation of all Uint8Array received as input
|
|
3
|
+
* Switches endianness of a byte array
|
|
6
4
|
*/
|
|
7
|
-
static
|
|
5
|
+
static switchEndianness(bytes: Uint8Array): Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* Builds a BigInt from a big-endian Uint8Array
|
|
8
|
+
* @param bytes The big-endian bytes to convert
|
|
9
|
+
* @returns The resulting BigInt in big-endian format
|
|
10
|
+
*/
|
|
11
|
+
static buildBigIntFromUint8ArrayBE(bytes: Uint8Array): bigint;
|
|
12
|
+
/**
|
|
13
|
+
* Switches endianness of a bigint value
|
|
14
|
+
* @param value The bigint value to switch endianness for
|
|
15
|
+
* @returns The bigint value with reversed endianness
|
|
16
|
+
*/
|
|
17
|
+
static switchEndiannessBigInt(value: bigint): bigint;
|
|
8
18
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
12
|
-
* @returns BigInt representation of the bytes
|
|
19
|
+
* Converts a big-endian bigint to a 32-byte big-endian Uint8Array
|
|
20
|
+
* @param value The big-endian bigint to convert
|
|
21
|
+
* @returns A 32-byte big-endian Uint8Array
|
|
13
22
|
*/
|
|
14
|
-
static
|
|
23
|
+
static bigIntToUint8Array32BE(value: bigint): Uint8Array;
|
|
15
24
|
/**
|
|
16
25
|
* Writes an unsigned integer to a buffer in little-endian format
|
|
17
26
|
*/
|
|
18
27
|
static writeUIntLE(buf: Uint8Array, value: number, offset: number, byteLength: number, noAssert?: boolean): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* Fills with zeros to set length
|
|
30
|
+
* @param array little endian Uint8Array
|
|
31
|
+
* @param length amount to pad
|
|
32
|
+
* @returns little endian Uint8Array padded with zeros to set length
|
|
33
|
+
*/
|
|
34
|
+
static zeroPadLE(array: Uint8Array, length: number): Uint8Array;
|
|
19
35
|
static checkInt(buf: Uint8Array, value: number, offset: number, ext: number, max: number, min: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Concatenate Uint8Arrays
|
|
38
|
+
* @param input
|
|
39
|
+
* @returns concatenation of all Uint8Array received as input
|
|
40
|
+
*/
|
|
41
|
+
static concatenate(...input: Uint8Array[]): Uint8Array;
|
|
20
42
|
}
|
package/dist/utils/bytes.js
CHANGED
|
@@ -1,44 +1,52 @@
|
|
|
1
1
|
export class BytesUtils {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param input
|
|
5
|
-
* @returns concatenation of all Uint8Array received as input
|
|
3
|
+
* Switches endianness of a byte array
|
|
6
4
|
*/
|
|
7
|
-
static
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
static switchEndianness(bytes) {
|
|
6
|
+
return new Uint8Array([...bytes].reverse());
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Builds a BigInt from a big-endian Uint8Array
|
|
10
|
+
* @param bytes The big-endian bytes to convert
|
|
11
|
+
* @returns The resulting BigInt in big-endian format
|
|
12
|
+
*/
|
|
13
|
+
static buildBigIntFromUint8ArrayBE(bytes) {
|
|
14
|
+
let result = 0n;
|
|
15
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
16
|
+
result = (result << 8n) + BigInt(bytes[i]);
|
|
17
17
|
}
|
|
18
18
|
return result;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @param
|
|
23
|
-
* @
|
|
24
|
-
* @returns BigInt representation of the bytes
|
|
21
|
+
* Switches endianness of a bigint value
|
|
22
|
+
* @param value The bigint value to switch endianness for
|
|
23
|
+
* @returns The bigint value with reversed endianness
|
|
25
24
|
*/
|
|
26
|
-
static
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (inputEndianness === "little") {
|
|
34
|
-
workingBytes.reverse();
|
|
25
|
+
static switchEndiannessBigInt(value) {
|
|
26
|
+
// Convert bigint to byte array
|
|
27
|
+
const bytes = [];
|
|
28
|
+
let tempValue = value;
|
|
29
|
+
while (tempValue > 0n) {
|
|
30
|
+
bytes.push(Number(tempValue & 0xffn));
|
|
31
|
+
tempValue >>= 8n;
|
|
35
32
|
}
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
// Reverse bytes and convert back to bigint
|
|
34
|
+
return bytes
|
|
35
|
+
.reverse()
|
|
36
|
+
.reduce((acc, byte) => (acc << 8n) + BigInt(byte), 0n);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a big-endian bigint to a 32-byte big-endian Uint8Array
|
|
40
|
+
* @param value The big-endian bigint to convert
|
|
41
|
+
* @returns A 32-byte big-endian Uint8Array
|
|
42
|
+
*/
|
|
43
|
+
static bigIntToUint8Array32BE(value) {
|
|
44
|
+
const bytes = new Uint8Array(32);
|
|
45
|
+
for (let i = 31; i >= 0; i--) {
|
|
46
|
+
bytes[i] = Number(value & 0xffn);
|
|
47
|
+
value >>= 8n;
|
|
40
48
|
}
|
|
41
|
-
return
|
|
49
|
+
return bytes;
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
52
|
* Writes an unsigned integer to a buffer in little-endian format
|
|
@@ -59,6 +67,19 @@ export class BytesUtils {
|
|
|
59
67
|
}
|
|
60
68
|
return buf;
|
|
61
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Fills with zeros to set length
|
|
72
|
+
* @param array little endian Uint8Array
|
|
73
|
+
* @param length amount to pad
|
|
74
|
+
* @returns little endian Uint8Array padded with zeros to set length
|
|
75
|
+
*/
|
|
76
|
+
static zeroPadLE(array, length) {
|
|
77
|
+
const result = new Uint8Array(length);
|
|
78
|
+
for (let i = 0; i < length; i++) {
|
|
79
|
+
result[i] = array[i] || 0;
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
62
83
|
// Adapted from https://github.com/feross/buffer
|
|
63
84
|
static checkInt(buf, value, offset, ext, max, min) {
|
|
64
85
|
if (value > max || value < min)
|
|
@@ -66,5 +87,23 @@ export class BytesUtils {
|
|
|
66
87
|
if (offset + ext > buf.length)
|
|
67
88
|
throw new RangeError("Index out of range");
|
|
68
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Concatenate Uint8Arrays
|
|
92
|
+
* @param input
|
|
93
|
+
* @returns concatenation of all Uint8Array received as input
|
|
94
|
+
*/
|
|
95
|
+
static concatenate(...input) {
|
|
96
|
+
let totalLength = 0;
|
|
97
|
+
for (const arr of input) {
|
|
98
|
+
totalLength += arr.length;
|
|
99
|
+
}
|
|
100
|
+
const result = new Uint8Array(totalLength);
|
|
101
|
+
let offset = 0;
|
|
102
|
+
for (const arr of input) {
|
|
103
|
+
result.set(arr, offset);
|
|
104
|
+
offset += arr.length;
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
69
108
|
}
|
|
70
109
|
//# sourceMappingURL=bytes.js.map
|
package/dist/utils/bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/utils/bytes.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IACrB
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/utils/bytes.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IACrB;;OAEG;IACI,MAAM,CAAC,gBAAgB,CAAC,KAAiB;QAC9C,OAAO,IAAI,UAAU,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,2BAA2B,CAAC,KAAiB;QACzD,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,K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AAU,CAAC,mCAAmC,CAAC,CAAC;QAC5D,IAAI,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM;YAAE,MAAM,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAC5E,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,GAAG,KAAmB;QAC9C,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC;QAC5B,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACxB,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC;QACvB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
package/dist/zerokit.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IRateLimitProof } from "@waku/interfaces";
|
|
1
2
|
import { IdentityCredential } from "./identity.js";
|
|
2
3
|
import { WitnessCalculator } from "./resources/witness_calculator";
|
|
3
4
|
export declare class Zerokit {
|
|
@@ -8,5 +9,15 @@ export declare class Zerokit {
|
|
|
8
9
|
get getZkRLN(): number;
|
|
9
10
|
get getWitnessCalculator(): WitnessCalculator;
|
|
10
11
|
get rateLimit(): number;
|
|
12
|
+
generateIdentityCredentials(): IdentityCredential;
|
|
11
13
|
generateSeededIdentityCredential(seed: string): IdentityCredential;
|
|
14
|
+
insertMember(idCommitment: Uint8Array): void;
|
|
15
|
+
insertMembers(index: number, ...idCommitments: Array<Uint8Array>): void;
|
|
16
|
+
deleteMember(index: number): void;
|
|
17
|
+
getMerkleRoot(): Uint8Array;
|
|
18
|
+
serializeMessage(uint8Msg: Uint8Array, memIndex: number, epoch: Uint8Array, idKey: Uint8Array, rateLimit?: number): Uint8Array;
|
|
19
|
+
generateRLNProof(msg: Uint8Array, index: number, epoch: Uint8Array | Date | undefined, idSecretHash: Uint8Array, rateLimit?: number): Promise<IRateLimitProof>;
|
|
20
|
+
verifyRLNProof(proof: IRateLimitProof | Uint8Array, msg: Uint8Array, rateLimit?: number): boolean;
|
|
21
|
+
verifyWithRoots(proof: IRateLimitProof | Uint8Array, msg: Uint8Array, roots: Array<Uint8Array>, rateLimit?: number): boolean;
|
|
22
|
+
verifyWithNoRoot(proof: IRateLimitProof | Uint8Array, msg: Uint8Array, rateLimit?: number): boolean;
|
|
12
23
|
}
|