mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-14 14:34:40 +00:00
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
2
package-lock.json
generated
2
package-lock.json
generated
@ -26642,6 +26642,7 @@
|
|||||||
"license": "MIT OR Apache-2.0",
|
"license": "MIT OR Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/hashes": "^1.3.2",
|
"@noble/hashes": "^1.3.2",
|
||||||
|
"@waku/interfaces": "0.0.20",
|
||||||
"chai": "^4.3.10",
|
"chai": "^4.3.10",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"uint8arrays": "^4.0.4"
|
"uint8arrays": "^4.0.4"
|
||||||
@ -26651,7 +26652,6 @@
|
|||||||
"@rollup/plugin-json": "^6.0.0",
|
"@rollup/plugin-json": "^6.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||||
"@waku/build-utils": "*",
|
"@waku/build-utils": "*",
|
||||||
"@waku/interfaces": "0.0.20",
|
|
||||||
"cspell": "^7.3.2",
|
"cspell": "^7.3.2",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"rollup": "^4.6.0"
|
"rollup": "^4.6.0"
|
||||||
|
@ -8,6 +8,19 @@
|
|||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.js"
|
"import": "./dist/index.js"
|
||||||
|
},
|
||||||
|
"./relay": {
|
||||||
|
"types": "./dist/relay/index.d.ts",
|
||||||
|
"import": "./dist/relay/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"typesVersions": {
|
||||||
|
"*": {
|
||||||
|
"*": [
|
||||||
|
"*",
|
||||||
|
"dist/*",
|
||||||
|
"dist/*/index"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
@ -22,7 +22,6 @@ import type {
|
|||||||
Libp2pComponents,
|
Libp2pComponents,
|
||||||
LightNode,
|
LightNode,
|
||||||
ProtocolCreateOptions,
|
ProtocolCreateOptions,
|
||||||
RelayNode,
|
|
||||||
ShardingParams
|
ShardingParams
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
|
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
|
||||||
@ -136,47 +135,6 @@ export async function createLightNode(
|
|||||||
) as LightNode;
|
) 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.
|
* Create a Waku node that uses all Waku protocols.
|
||||||
*
|
*
|
||||||
|
48
packages/sdk/src/relay/index.ts
Normal file
48
packages/sdk/src/relay/index.ts
Normal file
@ -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 { EnrDecoder } from "@waku/enr";
|
||||||
import type { RelayNode } from "@waku/interfaces";
|
import type { RelayNode } from "@waku/interfaces";
|
||||||
import { Protocols } from "@waku/interfaces";
|
import { Protocols } from "@waku/interfaces";
|
||||||
import { createRelayNode } from "@waku/sdk";
|
import { createRelayNode } from "@waku/sdk/relay";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { makeLogFileName, NOISE_KEY_1, tearDownNodes } from "../src/index.js";
|
import { makeLogFileName, NOISE_KEY_1, tearDownNodes } from "../src/index.js";
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
createDecoder as createSymDecoder,
|
createDecoder as createSymDecoder,
|
||||||
createEncoder as createSymEncoder
|
createEncoder as createSymEncoder
|
||||||
} from "@waku/message-encryption/symmetric";
|
} from "@waku/message-encryption/symmetric";
|
||||||
import { createRelayNode } from "@waku/sdk";
|
import { createRelayNode } from "@waku/sdk/relay";
|
||||||
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import type { PeerId } from "@libp2p/interface/peer-id";
|
import type { PeerId } from "@libp2p/interface/peer-id";
|
||||||
import { DecodedMessage, waitForRemotePeer } from "@waku/core";
|
import { DecodedMessage, waitForRemotePeer } from "@waku/core";
|
||||||
import { DefaultPubsubTopic, Protocols, RelayNode } from "@waku/interfaces";
|
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 { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
SingleShardInfo
|
SingleShardInfo
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { Protocols } from "@waku/interfaces";
|
import { Protocols } from "@waku/interfaces";
|
||||||
import { createRelayNode } from "@waku/sdk";
|
import { createRelayNode } from "@waku/sdk/relay";
|
||||||
import {
|
import {
|
||||||
contentTopicToPubsubTopic,
|
contentTopicToPubsubTopic,
|
||||||
singleShardInfoToPubsubTopic
|
singleShardInfoToPubsubTopic
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { createEncoder } from "@waku/core";
|
import { createEncoder } from "@waku/core";
|
||||||
import { IRateLimitProof, RelayNode, SendError } from "@waku/interfaces";
|
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 { utf8ToBytes } from "@waku/utils/bytes";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { createDecoder, createEncoder } from "@waku/core";
|
import { createDecoder, createEncoder } from "@waku/core";
|
||||||
import { DefaultPubsubTopic, RelayNode } from "@waku/interfaces";
|
import { DefaultPubsubTopic, RelayNode } from "@waku/interfaces";
|
||||||
import { createRelayNode } from "@waku/sdk";
|
import { createRelayNode } from "@waku/sdk/relay";
|
||||||
import { utf8ToBytes } from "@waku/utils/bytes";
|
import { utf8ToBytes } from "@waku/utils/bytes";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { waitForRemotePeer } from "@waku/core";
|
import { waitForRemotePeer } from "@waku/core";
|
||||||
import type { LightNode, RelayNode } from "@waku/interfaces";
|
import type { LightNode, RelayNode } from "@waku/interfaces";
|
||||||
import { DefaultPubsubTopic, Protocols } 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 { expect } from "chai";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -14,9 +14,9 @@ import {
|
|||||||
} from "@waku/message-encryption/symmetric";
|
} from "@waku/message-encryption/symmetric";
|
||||||
import {
|
import {
|
||||||
createLightNode,
|
createLightNode,
|
||||||
createEncoder as createPlainEncoder,
|
createEncoder as createPlainEncoder
|
||||||
createRelayNode
|
|
||||||
} from "@waku/sdk";
|
} from "@waku/sdk";
|
||||||
|
import { createRelayNode } from "@waku/sdk/relay";
|
||||||
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user