2024-03-04 10:56:20 +01:00
|
|
|
import { wakuFilter, wakuLightPush, wakuStore } from "@waku/core";
|
|
|
|
|
import { type Libp2pComponents, type LightNode } from "@waku/interfaces";
|
2022-12-02 15:43:46 +11:00
|
|
|
|
2024-03-04 10:56:20 +01:00
|
|
|
import { createLibp2pAndUpdateOptions } from "./utils/libp2p.js";
|
|
|
|
|
import { CreateWakuNodeOptions, WakuNode, WakuOptions } from "./waku.js";
|
2023-01-31 19:47:46 +05:30
|
|
|
|
2022-12-02 15:43:46 +11:00
|
|
|
export { Libp2pComponents };
|
2022-08-01 15:43:43 +10:00
|
|
|
|
2024-01-09 23:34:30 -08:00
|
|
|
/**
|
|
|
|
|
* Create a Waku node configured to use autosharding or static sharding.
|
|
|
|
|
*/
|
|
|
|
|
export async function createNode(
|
2024-03-04 10:56:20 +01:00
|
|
|
options: CreateWakuNodeOptions = { pubsubTopics: [] }
|
2024-01-09 23:34:30 -08:00
|
|
|
): Promise<LightNode> {
|
|
|
|
|
if (!options.shardInfo) {
|
|
|
|
|
throw new Error("Shard info must be set");
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-04 10:56:20 +01:00
|
|
|
const libp2p = await createLibp2pAndUpdateOptions(options);
|
2024-01-09 23:34:30 -08:00
|
|
|
|
|
|
|
|
const store = wakuStore(options);
|
|
|
|
|
const lightPush = wakuLightPush(options);
|
|
|
|
|
const filter = wakuFilter(options);
|
|
|
|
|
|
|
|
|
|
return new WakuNode(
|
2024-01-25 20:07:58 -08:00
|
|
|
options as WakuOptions,
|
2024-01-09 23:34:30 -08:00
|
|
|
libp2p,
|
|
|
|
|
store,
|
|
|
|
|
lightPush,
|
|
|
|
|
filter
|
|
|
|
|
) as LightNode;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 16:51:43 +10:00
|
|
|
/**
|
|
|
|
|
* Create a Waku node that uses Waku Light Push, Filter and Store to send and
|
|
|
|
|
* receive messages, enabling low resource consumption.
|
2023-07-26 11:30:48 +05:30
|
|
|
* Uses Waku Filter V2 by default.
|
2022-09-07 16:51:43 +10:00
|
|
|
*/
|
|
|
|
|
export async function createLightNode(
|
2024-03-04 10:56:20 +01:00
|
|
|
options: CreateWakuNodeOptions = {}
|
2022-12-06 13:18:32 +11:00
|
|
|
): Promise<LightNode> {
|
2024-03-04 10:56:20 +01:00
|
|
|
const libp2p = await createLibp2pAndUpdateOptions(options);
|
2022-09-07 16:51:43 +10:00
|
|
|
|
2022-11-17 11:01:27 +11:00
|
|
|
const store = wakuStore(options);
|
|
|
|
|
const lightPush = wakuLightPush(options);
|
2023-07-26 11:30:48 +05:30
|
|
|
const filter = wakuFilter(options);
|
2023-02-02 08:02:06 +05:30
|
|
|
|
2022-09-07 16:51:43 +10:00
|
|
|
return new WakuNode(
|
2024-01-25 20:07:58 -08:00
|
|
|
options as WakuOptions,
|
2022-09-07 16:51:43 +10:00
|
|
|
libp2p,
|
2022-11-17 11:01:27 +11:00
|
|
|
store,
|
|
|
|
|
lightPush,
|
2023-08-16 20:18:13 +05:30
|
|
|
filter
|
2022-12-06 13:18:32 +11:00
|
|
|
) as LightNode;
|
2022-09-07 16:51:43 +10:00
|
|
|
}
|