feat: enable autosharding in rln-js

This commit is contained in:
Sasha 2024-01-22 23:09:17 +01:00
parent cbb436ad35
commit 1fcc640016
No known key found for this signature in database
2 changed files with 18 additions and 4 deletions

View File

@ -9,7 +9,12 @@ import {
} from "@waku/rln";
import { createEncoder, createDecoder } from "@waku/sdk";
import { CONTENT_TOPIC, MEMBERSHIP_ID, RLN_CREDENTIALS } from "./const";
import {
CONTENT_TOPIC,
MEMBERSHIP_ID,
RLN_CREDENTIALS,
CLUSTER_ID,
} from "./const";
export async function initRLN(onStatusChange) {
onStatusChange("Connecting to wallet...");
@ -40,16 +45,21 @@ export async function initRLN(onStatusChange) {
onStatusChange("Failed to initialize RLN", "error");
throw Error(err);
}
const encoder = new RLNEncoder(
createEncoder({
ephemeral: false,
contentTopic: CONTENT_TOPIC,
pubsubTopicShardInfo: { clusterId: CLUSTER_ID },
}),
rlnInstance,
MEMBERSHIP_ID,
RLN_CREDENTIALS
);
const decoder = new RLNDecoder(rlnInstance, createDecoder(CONTENT_TOPIC));
const decoder = new RLNDecoder(
rlnInstance,
createDecoder(CONTENT_TOPIC, { clusterId: CLUSTER_ID })
);
onStatusChange("RLN initialized", "success");

View File

@ -1,6 +1,6 @@
import { createLightNode, waitForRemotePeer } from "@waku/sdk";
import { ProtoChatMessage } from "./const";
import { CLUSTER_ID, ProtoChatMessage } from "./const";
export async function initWaku({
encoder,
@ -11,6 +11,7 @@ export async function initWaku({
onStatusChange("Initializing Waku...");
const node = await createLightNode({
defaultBootstrap: true,
shardInfo: { clusterId: CLUSTER_ID, contentTopics: [CONTENT_TOPIC] },
});
onStatusChange("Waiting for peers");
await node.start();
@ -31,7 +32,10 @@ export async function initWaku({
};
onStatusChange("Subscribing to content topic...");
const subscription = await node.filter.createSubscription();
const subscription = await node.filter.createSubscription({
clusterId: CLUSTER_ID,
shard: contentTopicToShardIndex(CONTENT_TOPIC),
});
const onSubscribe = async (cb) => {
await subscription.subscribe(decoder, (message) => {
try {