mirror of https://github.com/status-im/js-waku.git
chore!: discourage the use of relay in browsers (#1778)
* add a comment discouraging relay * move createRelayNode under an explicit export * fix: build
This commit is contained in:
parent
b99f828cfb
commit
906c93329e
|
@ -26642,6 +26642,7 @@
|
|||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@noble/hashes": "^1.3.2",
|
||||
"@waku/interfaces": "0.0.20",
|
||||
"chai": "^4.3.10",
|
||||
"debug": "^4.3.4",
|
||||
"uint8arrays": "^4.0.4"
|
||||
|
@ -26651,7 +26652,6 @@
|
|||
"@rollup/plugin-json": "^6.0.0",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
"@waku/build-utils": "*",
|
||||
"@waku/interfaces": "0.0.20",
|
||||
"cspell": "^7.3.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"rollup": "^4.6.0"
|
||||
|
|
|
@ -8,6 +8,19 @@
|
|||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
},
|
||||
"./relay": {
|
||||
"types": "./dist/relay/index.d.ts",
|
||||
"import": "./dist/relay/index.js"
|
||||
}
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"*",
|
||||
"dist/*",
|
||||
"dist/*/index"
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
|
|
|
@ -22,7 +22,6 @@ import type {
|
|||
Libp2pComponents,
|
||||
LightNode,
|
||||
ProtocolCreateOptions,
|
||||
RelayNode,
|
||||
ShardingParams
|
||||
} from "@waku/interfaces";
|
||||
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
|
||||
|
@ -136,47 +135,6 @@ export async function createLightNode(
|
|||
) as LightNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Waku node that uses Waku Relay to send and receive messages,
|
||||
* enabling some privacy preserving properties.
|
||||
*/
|
||||
export async function createRelayNode(
|
||||
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
|
||||
): Promise<RelayNode> {
|
||||
options = options ?? {};
|
||||
|
||||
if (options.shardInfo) {
|
||||
ensureShardingConfigured(options.shardInfo);
|
||||
}
|
||||
|
||||
const libp2pOptions = options?.libp2p ?? {};
|
||||
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
||||
if (options?.defaultBootstrap) {
|
||||
peerDiscovery.push(...defaultPeerDiscoveries());
|
||||
Object.assign(libp2pOptions, { peerDiscovery });
|
||||
}
|
||||
|
||||
const libp2p = await defaultLibp2p(
|
||||
options.shardInfo,
|
||||
wakuGossipSub(options),
|
||||
libp2pOptions,
|
||||
options?.userAgent
|
||||
);
|
||||
|
||||
const relay = wakuRelay(options);
|
||||
|
||||
return new WakuNode(
|
||||
options,
|
||||
options.pubsubTopics,
|
||||
libp2p,
|
||||
options.shardInfo,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
relay
|
||||
) as RelayNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Waku node that uses all Waku protocols.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
import { WakuNode, WakuOptions } from "@waku/core";
|
||||
import type { ProtocolCreateOptions, RelayNode } from "@waku/interfaces";
|
||||
import { RelayCreateOptions, wakuGossipSub, wakuRelay } from "@waku/relay";
|
||||
|
||||
import { defaultLibp2p, defaultPeerDiscoveries } from "../create.js";
|
||||
|
||||
/**
|
||||
* Create a Waku node that uses Waku Relay to send and receive messages,
|
||||
* enabling some privacy preserving properties.
|
||||
* * @remarks
|
||||
* This function creates a Relay Node using the Waku Relay protocol.
|
||||
* While it is technically possible to use this function in a browser environment,
|
||||
* it is not recommended due to potential performance issues and limited browser capabilities.
|
||||
* If you are developing a browser-based application, consider alternative approaches like creating a Light Node
|
||||
* or use this function with caution.
|
||||
*/
|
||||
export async function createRelayNode(
|
||||
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
|
||||
): Promise<RelayNode> {
|
||||
options = options ?? {};
|
||||
|
||||
const libp2pOptions = options?.libp2p ?? {};
|
||||
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
||||
if (options?.defaultBootstrap) {
|
||||
peerDiscovery.push(...defaultPeerDiscoveries());
|
||||
Object.assign(libp2pOptions, { peerDiscovery });
|
||||
}
|
||||
|
||||
const libp2p = await defaultLibp2p(
|
||||
options.shardInfo,
|
||||
wakuGossipSub(options),
|
||||
libp2pOptions,
|
||||
options?.userAgent
|
||||
);
|
||||
|
||||
const relay = wakuRelay(options);
|
||||
|
||||
return new WakuNode(
|
||||
options,
|
||||
options.pubsubTopics,
|
||||
libp2p,
|
||||
options.shardInfo,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
relay
|
||||
) as RelayNode;
|
||||
}
|
|
@ -2,7 +2,7 @@ import { waitForRemotePeer } from "@waku/core";
|
|||
import { EnrDecoder } from "@waku/enr";
|
||||
import type { RelayNode } from "@waku/interfaces";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import { createRelayNode } from "@waku/sdk";
|
||||
import { createRelayNode } from "@waku/sdk/relay";
|
||||
import { expect } from "chai";
|
||||
|
||||
import { makeLogFileName, NOISE_KEY_1, tearDownNodes } from "../src/index.js";
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
createDecoder as createSymDecoder,
|
||||
createEncoder as createSymEncoder
|
||||
} from "@waku/message-encryption/symmetric";
|
||||
import { createRelayNode } from "@waku/sdk";
|
||||
import { createRelayNode } from "@waku/sdk/relay";
|
||||
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { PeerId } from "@libp2p/interface/peer-id";
|
||||
import { DecodedMessage, waitForRemotePeer } from "@waku/core";
|
||||
import { DefaultPubsubTopic, Protocols, RelayNode } from "@waku/interfaces";
|
||||
import { createRelayNode } from "@waku/sdk";
|
||||
import { createRelayNode } from "@waku/sdk/relay";
|
||||
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
SingleShardInfo
|
||||
} from "@waku/interfaces";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import { createRelayNode } from "@waku/sdk";
|
||||
import { createRelayNode } from "@waku/sdk/relay";
|
||||
import {
|
||||
contentTopicToPubsubTopic,
|
||||
singleShardInfoToPubsubTopic
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { createEncoder } from "@waku/core";
|
||||
import { IRateLimitProof, RelayNode, SendError } from "@waku/interfaces";
|
||||
import { createRelayNode } from "@waku/sdk";
|
||||
import { createRelayNode } from "@waku/sdk/relay";
|
||||
import { utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { createDecoder, createEncoder } from "@waku/core";
|
||||
import { DefaultPubsubTopic, RelayNode } from "@waku/interfaces";
|
||||
import { createRelayNode } from "@waku/sdk";
|
||||
import { createRelayNode } from "@waku/sdk/relay";
|
||||
import { utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { waitForRemotePeer } from "@waku/core";
|
||||
import type { LightNode, RelayNode } from "@waku/interfaces";
|
||||
import { DefaultPubsubTopic, Protocols } from "@waku/interfaces";
|
||||
import { createLightNode, createRelayNode } from "@waku/sdk";
|
||||
import { createLightNode } from "@waku/sdk";
|
||||
import { createRelayNode } from "@waku/sdk/relay";
|
||||
import { expect } from "chai";
|
||||
|
||||
import {
|
||||
|
|
|
@ -14,9 +14,9 @@ import {
|
|||
} from "@waku/message-encryption/symmetric";
|
||||
import {
|
||||
createLightNode,
|
||||
createEncoder as createPlainEncoder,
|
||||
createRelayNode
|
||||
createEncoder as createPlainEncoder
|
||||
} from "@waku/sdk";
|
||||
import { createRelayNode } from "@waku/sdk/relay";
|
||||
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
||||
|
|
Loading…
Reference in New Issue