mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-01-24 19:03:12 +00:00
* chore: restructure @waku/sdk * chore: introduce `BaseProtocolCore` and `BaseProtocolSDK` * chore: introduce `LightPushCore` and `LightPushSDK` * chore: update `relay` for new types * chore(sdk): update structure * chore(filter): add `numPeersToUse` * chore: update tests * update: size-limit * chore: update more tests * attach issue link to TODOs
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { wakuFilter, wakuStore } from "@waku/core";
|
|
import { type Libp2pComponents, type LightNode } from "@waku/interfaces";
|
|
|
|
import { wakuLightPush } from "../protocols/light_push.js";
|
|
import { createLibp2pAndUpdateOptions } from "../utils/libp2p.js";
|
|
import { CreateWakuNodeOptions, WakuNode, WakuOptions } from "../waku.js";
|
|
|
|
export { Libp2pComponents };
|
|
|
|
/**
|
|
* Create a Waku node configured to use autosharding or static sharding.
|
|
*/
|
|
export async function createNode(
|
|
options: CreateWakuNodeOptions = { pubsubTopics: [] }
|
|
): Promise<LightNode> {
|
|
if (!options.shardInfo) {
|
|
throw new Error("Shard info must be set");
|
|
}
|
|
|
|
const libp2p = await createLibp2pAndUpdateOptions(options);
|
|
|
|
const store = wakuStore(options);
|
|
const lightPush = wakuLightPush(options);
|
|
const filter = wakuFilter(options);
|
|
|
|
return new WakuNode(
|
|
options as WakuOptions,
|
|
libp2p,
|
|
store,
|
|
lightPush,
|
|
filter
|
|
) as LightNode;
|
|
}
|
|
|
|
/**
|
|
* Create a Waku node that uses Waku Light Push, Filter and Store to send and
|
|
* receive messages, enabling low resource consumption.
|
|
* Uses Waku Filter V2 by default.
|
|
*/
|
|
export async function createLightNode(
|
|
options: CreateWakuNodeOptions = {}
|
|
): Promise<LightNode> {
|
|
const libp2p = await createLibp2pAndUpdateOptions(options);
|
|
|
|
const store = wakuStore(options);
|
|
const lightPush = wakuLightPush(options);
|
|
const filter = wakuFilter(options);
|
|
|
|
return new WakuNode(
|
|
options as WakuOptions,
|
|
libp2p,
|
|
store,
|
|
lightPush,
|
|
filter
|
|
) as LightNode;
|
|
}
|