Danish Arora 5fb100602b
chore(lightpush)!: move protocol implementation to @waku/sdk (1/n) (#1964)
* chore: decouple `Filter` between `core` and `sdk`
moves `SubscriptionManager` to `sdk` side

* chore: update package dependencies
also update peer deps in sdk

* chore: update imports

* chore: update tests

* chore(side-change): update lightpush

* chore: update size-limit import

* chore(sdk): update dependencies
2024-04-19 17:20:34 +05:30

58 lines
1.5 KiB
TypeScript

import { type Libp2pComponents, type LightNode } from "@waku/interfaces";
import { wakuFilter } from "../protocols/filter.js";
import { wakuLightPush } from "../protocols/light_push.js";
import { wakuStore } from "../protocols/store.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;
}