@waku/rln 0.1.1-5b9414a → 0.1.1-7e8cb89
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/index.js +71 -39
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.d.ts +5 -3
- package/dist/codec.js +8 -2
- package/dist/codec.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/keystore/keystore.d.ts +4 -3
- package/dist/keystore/keystore.js +16 -5
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +5 -5
- package/dist/message.d.ts +1 -1
- package/dist/message.js +1 -1
- package/dist/rln.js +2 -2
- package/dist/rln.js.map +1 -1
- package/dist/rln_contract.d.ts +15 -11
- package/dist/rln_contract.js +44 -29
- package/dist/rln_contract.js.map +1 -1
- package/package.json +5 -5
- package/src/codec.ts +10 -2
- package/src/constants.ts +1 -1
- package/src/message.ts +1 -1
- package/src/rln.ts +2 -2
- package/src/rln_contract.ts +70 -35
package/bundle/index.js
CHANGED
@@ -1907,7 +1907,7 @@ class RlnMessage {
|
|
1907
1907
|
this.rlnInstance = rlnInstance;
|
1908
1908
|
this.msg = msg;
|
1909
1909
|
this.rateLimitProof = rateLimitProof;
|
1910
|
-
this.
|
1910
|
+
this.pubsubTopic = "";
|
1911
1911
|
}
|
1912
1912
|
verify(roots) {
|
1913
1913
|
return this.rateLimitProof
|
@@ -1973,6 +1973,9 @@ class RLNEncoder {
|
|
1973
1973
|
console.timeEnd("proof_gen_timer");
|
1974
1974
|
return proof;
|
1975
1975
|
}
|
1976
|
+
get pubsubTopic() {
|
1977
|
+
return this.encoder.pubsubTopic;
|
1978
|
+
}
|
1976
1979
|
get contentTopic() {
|
1977
1980
|
return this.encoder.contentTopic;
|
1978
1981
|
}
|
@@ -1985,6 +1988,9 @@ class RLNDecoder {
|
|
1985
1988
|
this.rlnInstance = rlnInstance;
|
1986
1989
|
this.decoder = decoder;
|
1987
1990
|
}
|
1991
|
+
get pubsubTopic() {
|
1992
|
+
return this.decoder.pubsubTopic;
|
1993
|
+
}
|
1988
1994
|
get contentTopic() {
|
1989
1995
|
return this.decoder.contentTopic;
|
1990
1996
|
}
|
@@ -1993,8 +1999,8 @@ class RLNDecoder {
|
|
1993
1999
|
log("Message decoded", protoMessage);
|
1994
2000
|
return Promise.resolve(protoMessage);
|
1995
2001
|
}
|
1996
|
-
async fromProtoObj(
|
1997
|
-
const msg = await this.decoder.fromProtoObj(
|
2002
|
+
async fromProtoObj(pubsubTopic, proto) {
|
2003
|
+
const msg = await this.decoder.fromProtoObj(pubsubTopic, proto);
|
1998
2004
|
if (!msg)
|
1999
2005
|
return;
|
2000
2006
|
return new RlnMessage(this.rlnInstance, msg, proto.rateLimitProof);
|
@@ -2064,7 +2070,7 @@ const RLN_STORAGE_ABI = [
|
|
2064
2070
|
];
|
2065
2071
|
const SEPOLIA_CONTRACT = {
|
2066
2072
|
chainId: 11155111,
|
2067
|
-
address: "
|
2073
|
+
address: "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4",
|
2068
2074
|
abi: RLN_REGISTRY_ABI,
|
2069
2075
|
};
|
2070
2076
|
|
@@ -24528,11 +24534,11 @@ class Keystore {
|
|
24528
24534
|
// TODO: add runtime validation of nwaku credentials
|
24529
24535
|
return {
|
24530
24536
|
identity: {
|
24531
|
-
IDCommitment: _.get(obj, "identityCredential.idCommitment"),
|
24532
|
-
IDTrapdoor: _.get(obj, "identityCredential.idTrapdoor"),
|
24533
|
-
IDNullifier: _.get(obj, "identityCredential.idNullifier"),
|
24534
|
-
IDCommitmentBigInt: buildBigIntFromUint8Array(
|
24535
|
-
IDSecretHash: _.get(obj, "identityCredential.idSecretHash"),
|
24537
|
+
IDCommitment: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", [])),
|
24538
|
+
IDTrapdoor: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", [])),
|
24539
|
+
IDNullifier: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", [])),
|
24540
|
+
IDCommitmentBigInt: buildBigIntFromUint8Array(Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []))),
|
24541
|
+
IDSecretHash: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", [])),
|
24536
24542
|
},
|
24537
24543
|
membership: {
|
24538
24544
|
treeIndex: _.get(obj, "treeIndex"),
|
@@ -24546,6 +24552,17 @@ class Keystore {
|
|
24546
24552
|
return null;
|
24547
24553
|
}
|
24548
24554
|
}
|
24555
|
+
static fromArraylikeToBytes(obj) {
|
24556
|
+
const bytes = [];
|
24557
|
+
let index = 0;
|
24558
|
+
let lastElement = obj[index];
|
24559
|
+
while (lastElement !== undefined) {
|
24560
|
+
bytes.push(lastElement);
|
24561
|
+
index += 1;
|
24562
|
+
lastElement = obj[index];
|
24563
|
+
}
|
24564
|
+
return new Uint8Array(bytes);
|
24565
|
+
}
|
24549
24566
|
// follows nwaku implementation
|
24550
24567
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
24551
24568
|
static computeMembershipHash(info) {
|
@@ -25779,7 +25796,7 @@ async function loadZkey() {
|
|
25779
25796
|
* @returns RLNInstance
|
25780
25797
|
*/
|
25781
25798
|
async function create$1() {
|
25782
|
-
await init();
|
25799
|
+
await init?.();
|
25783
25800
|
init_panic_hook();
|
25784
25801
|
const witnessCalculator = await loadWitnessCalculator();
|
25785
25802
|
const zkey = await loadZkey();
|
@@ -49745,12 +49762,6 @@ class MerkleRootTracker {
|
|
49745
49762
|
}
|
49746
49763
|
|
49747
49764
|
class RLNContract {
|
49748
|
-
constructor(rlnInstance, { address, provider }) {
|
49749
|
-
this._members = [];
|
49750
|
-
const initialRoot = rlnInstance.getMerkleRoot();
|
49751
|
-
this.registryContract = new Contract(address, RLN_REGISTRY_ABI, provider);
|
49752
|
-
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
49753
|
-
}
|
49754
49765
|
static async init(rlnInstance, options) {
|
49755
49766
|
const rlnContract = new RLNContract(rlnInstance, options);
|
49756
49767
|
await rlnContract.initStorageContract(options.provider);
|
@@ -49758,22 +49769,34 @@ class RLNContract {
|
|
49758
49769
|
rlnContract.subscribeToMembers(rlnInstance);
|
49759
49770
|
return rlnContract;
|
49760
49771
|
}
|
49761
|
-
|
49762
|
-
|
49763
|
-
const
|
49764
|
-
this.
|
49765
|
-
this.
|
49772
|
+
constructor(rlnInstance, { registryAddress, provider }) {
|
49773
|
+
this._members = new Map();
|
49774
|
+
const initialRoot = rlnInstance.getMerkleRoot();
|
49775
|
+
this.registryContract = new Contract(registryAddress, RLN_REGISTRY_ABI, provider);
|
49776
|
+
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
49777
|
+
}
|
49778
|
+
async initStorageContract(provider, options = {}) {
|
49779
|
+
const storageIndex = options?.storageIndex
|
49780
|
+
? options.storageIndex
|
49781
|
+
: await this.registryContract.usingStorageIndex();
|
49782
|
+
const storageAddress = await this.registryContract.storages(storageIndex);
|
49783
|
+
if (!storageAddress || storageAddress === AddressZero) {
|
49784
|
+
throw Error("No RLN Storage initialized on registry contract.");
|
49785
|
+
}
|
49786
|
+
this.storageIndex = storageIndex;
|
49787
|
+
this.storageContract = new Contract(storageAddress, RLN_STORAGE_ABI, provider);
|
49766
49788
|
this._membersFilter = this.storageContract.filters.MemberRegistered();
|
49767
49789
|
this.deployBlock = await this.storageContract.deployedBlockNumber();
|
49768
49790
|
}
|
49769
49791
|
get contract() {
|
49770
49792
|
if (!this.storageContract) {
|
49771
|
-
throw Error("Storage contract was not initialized
|
49793
|
+
throw Error("Storage contract was not initialized");
|
49772
49794
|
}
|
49773
49795
|
return this.storageContract;
|
49774
49796
|
}
|
49775
49797
|
get members() {
|
49776
|
-
|
49798
|
+
const sortedMembers = Array.from(this._members.values()).sort((left, right) => left.index.toNumber() - right.index.toNumber());
|
49799
|
+
return sortedMembers;
|
49777
49800
|
}
|
49778
49801
|
get membersFilter() {
|
49779
49802
|
if (!this._membersFilter) {
|
@@ -49800,11 +49823,11 @@ class RLNContract {
|
|
49800
49823
|
const index = evt.args.index;
|
49801
49824
|
const toRemoveVal = toRemoveTable.get(evt.blockNumber);
|
49802
49825
|
if (toRemoveVal != undefined) {
|
49803
|
-
toRemoveVal.push(index);
|
49826
|
+
toRemoveVal.push(index.toNumber());
|
49804
49827
|
toRemoveTable.set(evt.blockNumber, toRemoveVal);
|
49805
49828
|
}
|
49806
49829
|
else {
|
49807
|
-
toRemoveTable.set(evt.blockNumber, [index]);
|
49830
|
+
toRemoveTable.set(evt.blockNumber, [index.toNumber()]);
|
49808
49831
|
}
|
49809
49832
|
}
|
49810
49833
|
else {
|
@@ -49822,14 +49845,17 @@ class RLNContract {
|
|
49822
49845
|
insertMembers(rlnInstance, toInsert) {
|
49823
49846
|
toInsert.forEach((events, blockNumber) => {
|
49824
49847
|
events.forEach((evt) => {
|
49825
|
-
|
49848
|
+
const _idCommitment = evt?.args?.idCommitment;
|
49849
|
+
const index = evt?.args?.index;
|
49850
|
+
if (!_idCommitment || !index) {
|
49826
49851
|
return;
|
49827
49852
|
}
|
49828
|
-
const
|
49829
|
-
const index = evt.args.index;
|
49830
|
-
const idCommitment = zeroPad(arrayify(pubkey), 32);
|
49853
|
+
const idCommitment = zeroPad(arrayify(_idCommitment), 32);
|
49831
49854
|
rlnInstance.insertMember(idCommitment);
|
49832
|
-
this.
|
49855
|
+
this._members.set(index.toNumber(), {
|
49856
|
+
index,
|
49857
|
+
idCommitment: _idCommitment?._hex || hexlify(idCommitment),
|
49858
|
+
});
|
49833
49859
|
});
|
49834
49860
|
const currentRoot = rlnInstance.getMerkleRoot();
|
49835
49861
|
this.merkleRootTracker.pushRoot(blockNumber, currentRoot);
|
@@ -49839,9 +49865,8 @@ class RLNContract {
|
|
49839
49865
|
const removeDescending = new Map([...toRemove].sort().reverse());
|
49840
49866
|
removeDescending.forEach((indexes, blockNumber) => {
|
49841
49867
|
indexes.forEach((index) => {
|
49842
|
-
|
49843
|
-
|
49844
|
-
this.members.splice(idx, 1);
|
49868
|
+
if (this._members.has(index)) {
|
49869
|
+
this._members.delete(index);
|
49845
49870
|
}
|
49846
49871
|
rlnInstance.deleteMember(index);
|
49847
49872
|
});
|
@@ -49849,21 +49874,28 @@ class RLNContract {
|
|
49849
49874
|
});
|
49850
49875
|
}
|
49851
49876
|
subscribeToMembers(rlnInstance) {
|
49852
|
-
this.contract.on(this.membersFilter, (_pubkey, _index, event) => this.processEvents(rlnInstance, event));
|
49877
|
+
this.contract.on(this.membersFilter, (_pubkey, _index, event) => this.processEvents(rlnInstance, [event]));
|
49853
49878
|
}
|
49854
49879
|
async registerWithSignature(rlnInstance, signature) {
|
49855
49880
|
const identityCredential = await rlnInstance.generateSeededIdentityCredential(signature);
|
49856
49881
|
return this.registerWithKey(identityCredential);
|
49857
49882
|
}
|
49858
49883
|
async registerWithKey(credential) {
|
49859
|
-
if (
|
49884
|
+
if (this.storageIndex === undefined) {
|
49860
49885
|
throw Error("Cannot register credential, no storage contract index found.");
|
49861
49886
|
}
|
49862
|
-
const txRegisterResponse = await this.registryContract
|
49863
|
-
gasLimit: 100000,
|
49864
|
-
});
|
49887
|
+
const txRegisterResponse = await this.registryContract["register(uint16,uint256)"](this.storageIndex, credential.IDCommitmentBigInt, { gasLimit: 100000 });
|
49865
49888
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
49866
|
-
|
49889
|
+
// assumption: register(uint16,uint256) emits one event
|
49890
|
+
const memberRegistered = txRegisterReceipt?.events?.[0];
|
49891
|
+
if (!memberRegistered) {
|
49892
|
+
return undefined;
|
49893
|
+
}
|
49894
|
+
const decodedData = this.contract.interface.decodeEventLog("MemberRegistered", memberRegistered.data);
|
49895
|
+
return {
|
49896
|
+
idCommitment: decodedData.idCommitment,
|
49897
|
+
index: decodedData.index,
|
49898
|
+
};
|
49867
49899
|
}
|
49868
49900
|
roots() {
|
49869
49901
|
return this.merkleRootTracker.roots();
|