diff --git a/packages/core/src/lib/message/version_0.ts b/packages/core/src/lib/message/version_0.ts index 53f337ccde..4715ebe6e3 100644 --- a/packages/core/src/lib/message/version_0.ts +++ b/packages/core/src/lib/message/version_0.ts @@ -5,10 +5,11 @@ import type { IMessage, IMetaSetter, IProtoMessage, - IRateLimitProof + IRateLimitProof, + IRoutingInfo } from "@waku/interfaces"; import { proto_message as proto } from "@waku/proto"; -import { isAutoShardingRoutingInfo, Logger, RoutingInfo } from "@waku/utils"; +import { isAutoShardingRoutingInfo, Logger } from "@waku/utils"; const log = new Logger("message:version-0"); const OneMillion = BigInt(1_000_000); @@ -68,7 +69,7 @@ export type EncoderOptions = { /** * The routing information for messages to encode. */ - routingInfo: RoutingInfo; + routingInfo: IRoutingInfo; /** The content topic to set on outgoing messages. */ contentTopic: string; /** @@ -88,7 +89,7 @@ export class Encoder implements IEncoder { public constructor( public contentTopic: string, public ephemeral: boolean = false, - public routingInfo: RoutingInfo, + public routingInfo: IRoutingInfo, public metaSetter?: IMetaSetter ) { if (!contentTopic || contentTopic === "") { @@ -146,7 +147,7 @@ export function createEncoder({ export class Decoder implements IDecoder { public constructor( public contentTopic: string, - public routingInfo: RoutingInfo + public routingInfo: IRoutingInfo ) { if (!contentTopic || contentTopic === "") { throw new Error("Content topic must be specified"); @@ -201,7 +202,7 @@ export class Decoder implements IDecoder { */ export function createDecoder( contentTopic: string, - routingInfo: RoutingInfo + routingInfo: IRoutingInfo ): Decoder { if (isAutoShardingRoutingInfo(routingInfo)) { if (routingInfo.contentTopic !== contentTopic) diff --git a/packages/message-encryption/src/ecies.ts b/packages/message-encryption/src/ecies.ts index 4fec13531b..bb7f1ded23 100644 --- a/packages/message-encryption/src/ecies.ts +++ b/packages/message-encryption/src/ecies.ts @@ -5,10 +5,11 @@ import { type IEncryptedMessage, type IMessage, type IMetaSetter, - type IProtoMessage + type IProtoMessage, + type IRoutingInfo } from "@waku/interfaces"; import { WakuMessage } from "@waku/proto"; -import { Logger, RoutingInfo } from "@waku/utils"; +import { Logger } from "@waku/utils"; import { generatePrivateKey } from "./crypto/utils.js"; import { DecodedMessage } from "./decoded_message.js"; @@ -33,7 +34,7 @@ const log = new Logger("message-encryption:ecies"); class Encoder implements IEncoder { public constructor( public contentTopic: string, - public routingInfo: RoutingInfo, + public routingInfo: IRoutingInfo, private publicKey: Uint8Array, private sigPrivKey?: Uint8Array, public ephemeral: boolean = false, @@ -82,7 +83,7 @@ export interface EncoderOptions { /** * The routing information for messages to encode. */ - routingInfo: RoutingInfo; + routingInfo: IRoutingInfo; /** The content topic to set on outgoing messages. */ contentTopic: string; /** @@ -135,7 +136,7 @@ export function createEncoder({ class Decoder extends DecoderV0 implements IDecoder { public constructor( contentTopic: string, - routingInfo: RoutingInfo, + routingInfo: IRoutingInfo, private privateKey: Uint8Array ) { super(contentTopic, routingInfo); @@ -206,11 +207,12 @@ class Decoder extends DecoderV0 implements IDecoder { * decode incoming messages. * * @param contentTopic The resulting decoder will only decode messages with this content topic. + * @param routingInfo * @param privateKey The private key used to decrypt the message. */ export function createDecoder( contentTopic: string, - routingInfo: RoutingInfo, + routingInfo: IRoutingInfo, privateKey: Uint8Array ): Decoder { return new Decoder(contentTopic, routingInfo, privateKey); diff --git a/packages/message-encryption/src/symmetric.ts b/packages/message-encryption/src/symmetric.ts index 80692dd834..d6f0ebfe41 100644 --- a/packages/message-encryption/src/symmetric.ts +++ b/packages/message-encryption/src/symmetric.ts @@ -9,7 +9,7 @@ import type { IRoutingInfo } from "@waku/interfaces"; import { WakuMessage } from "@waku/proto"; -import { Logger, RoutingInfo } from "@waku/utils"; +import { Logger } from "@waku/utils"; import { generateSymmetricKey } from "./crypto/utils.js"; import { DecodedMessage } from "./decoded_message.js"; @@ -83,7 +83,7 @@ export interface EncoderOptions { /** * The routing information for messages to encode. */ - routingInfo: RoutingInfo; + routingInfo: IRoutingInfo; /** The content topic to set on outgoing messages. */ contentTopic: string; /** @@ -136,7 +136,7 @@ export function createEncoder({ class Decoder extends DecoderV0 implements IDecoder { public constructor( contentTopic: string, - routingInfo: RoutingInfo, + routingInfo: IRoutingInfo, private symKey: Uint8Array ) { super(contentTopic, routingInfo); @@ -212,7 +212,7 @@ class Decoder extends DecoderV0 implements IDecoder { */ export function createDecoder( contentTopic: string, - routingInfo: RoutingInfo, + routingInfo: IRoutingInfo, symKey: Uint8Array ): Decoder { return new Decoder(contentTopic, routingInfo, symKey); diff --git a/packages/relay/src/relay.ts b/packages/relay/src/relay.ts index 571a6a78cd..6c4c5b9136 100644 --- a/packages/relay/src/relay.ts +++ b/packages/relay/src/relay.ts @@ -17,12 +17,13 @@ import { IEncoder, IMessage, IRelay, + type IRoutingInfo, Libp2p, ProtocolError, PubsubTopic, SDKProtocolResult } from "@waku/interfaces"; -import { isWireSizeUnderCap, RoutingInfo, toAsyncIterator } from "@waku/utils"; +import { isWireSizeUnderCap, toAsyncIterator } from "@waku/utils"; import { pushOrInitMapSet } from "@waku/utils"; import { Logger } from "@waku/utils"; import { pEvent } from "p-event"; @@ -39,7 +40,7 @@ export type Observer = { }; export type RelayCreateOptions = CreateNodeOptions & { - routingInfos: RoutingInfo[]; + routingInfos: IRoutingInfo[]; } & Partial; export type ContentTopic = string; diff --git a/packages/rln/src/rln.ts b/packages/rln/src/rln.ts index 8dbfc69fc0..2c9f6f653d 100644 --- a/packages/rln/src/rln.ts +++ b/packages/rln/src/rln.ts @@ -2,9 +2,10 @@ import { createDecoder, createEncoder } from "@waku/core"; import type { ContentTopic, IDecodedMessage, - IMetaSetter + IMetaSetter, + IRoutingInfo } from "@waku/interfaces"; -import { Logger, RoutingInfo } from "@waku/utils"; +import { Logger } from "@waku/utils"; import init from "@waku/zerokit-rln-wasm"; import * as zerokitRLN from "@waku/zerokit-rln-wasm"; @@ -31,7 +32,7 @@ type WakuRLNEncoderOptions = { /** * The routing information for messages to encode. */ - routingInfo: RoutingInfo; + routingInfo: IRoutingInfo; /** The content topic to set on outgoing messages. */ contentTopic: string; /** @@ -108,7 +109,7 @@ export class RLNInstance extends RLNCredentialsManager { public createDecoder( contentTopic: ContentTopic, - routingInfo: RoutingInfo + routingInfo: IRoutingInfo ): RLNDecoder { return createRLNDecoder({ rlnInstance: this, diff --git a/packages/sdk/src/filter/subscription.ts b/packages/sdk/src/filter/subscription.ts index 67b3f6aa33..e35429572d 100644 --- a/packages/sdk/src/filter/subscription.ts +++ b/packages/sdk/src/filter/subscription.ts @@ -10,12 +10,13 @@ import type { IDecodedMessage, IDecoder, IProtoMessage, + IRoutingInfo, PeerIdStr, PubsubTopic } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces"; import { WakuMessage } from "@waku/proto"; -import { Logger, RoutingInfo } from "@waku/utils"; +import { Logger } from "@waku/utils"; import { PeerManager, PeerManagerEventNames } from "../peer_manager/index.js"; @@ -36,7 +37,7 @@ type AttemptUnsubscribeParams = { type Libp2pEventHandler = (e: CustomEvent) => void; export class Subscription { - private readonly routingInfo: RoutingInfo; + private readonly routingInfo: IRoutingInfo; private readonly pubsubTopic: PubsubTopic; private readonly protocol: FilterCore; private readonly peerManager: PeerManager; diff --git a/packages/sdk/src/light_push/retry_manager.ts b/packages/sdk/src/light_push/retry_manager.ts index 9fe63fc92e..380c954277 100644 --- a/packages/sdk/src/light_push/retry_manager.ts +++ b/packages/sdk/src/light_push/retry_manager.ts @@ -1,6 +1,10 @@ import type { PeerId } from "@libp2p/interface"; -import { type CoreProtocolResult, Protocols } from "@waku/interfaces"; -import { Logger, RoutingInfo } from "@waku/utils"; +import { + type CoreProtocolResult, + type IRoutingInfo, + Protocols +} from "@waku/interfaces"; +import { Logger } from "@waku/utils"; import type { PeerManager } from "../peer_manager/index.js"; @@ -15,7 +19,7 @@ type AttemptCallback = (peerId: PeerId) => Promise; export type ScheduledTask = { maxAttempts: number; - routingInfo: RoutingInfo; + routingInfo: IRoutingInfo; callback: AttemptCallback; }; @@ -54,7 +58,7 @@ export class RetryManager { public push( callback: AttemptCallback, maxAttempts: number, - routingInfo: RoutingInfo + routingInfo: IRoutingInfo ): void { this.queue.push({ maxAttempts, diff --git a/packages/sdk/src/peer_manager/peer_manager.ts b/packages/sdk/src/peer_manager/peer_manager.ts index 73ab46c72a..cb68f3da56 100644 --- a/packages/sdk/src/peer_manager/peer_manager.ts +++ b/packages/sdk/src/peer_manager/peer_manager.ts @@ -12,11 +12,12 @@ import { } from "@waku/core"; import { CONNECTION_LOCKED_TAG, + type IRoutingInfo, Libp2p, Libp2pEventHandler, Protocols } from "@waku/interfaces"; -import { Logger, RoutingInfo } from "@waku/utils"; +import { Logger } from "@waku/utils"; const log = new Logger("peer-manager"); @@ -34,7 +35,7 @@ type PeerManagerParams = { type GetPeersParams = { protocol: Protocols; - routingInfo: RoutingInfo; + routingInfo: IRoutingInfo; }; export enum PeerManagerEventNames { diff --git a/packages/sdk/src/store/store.ts b/packages/sdk/src/store/store.ts index 1e85274f6e..0d8e686d23 100644 --- a/packages/sdk/src/store/store.ts +++ b/packages/sdk/src/store/store.ts @@ -5,6 +5,7 @@ import { messageHash, StoreCore } from "@waku/core"; import { IDecodedMessage, IDecoder, + type IRoutingInfo, IStore, Libp2p, Protocols, @@ -12,7 +13,7 @@ import { StoreCursor, StoreProtocolOptions } from "@waku/interfaces"; -import { isDefined, Logger, RoutingInfo } from "@waku/utils"; +import { isDefined, Logger } from "@waku/utils"; import { PeerManager } from "../peer_manager/index.js"; @@ -181,7 +182,7 @@ export class Store implements IStore { private validateDecodersAndPubsubTopic( decoders: IDecoder[] ): { - routingInfo: RoutingInfo; + routingInfo: IRoutingInfo; contentTopics: string[]; decodersAsMap: Map>; } { @@ -232,7 +233,7 @@ export class Store implements IStore { } private async getPeerToUse( - routingInfo: RoutingInfo + routingInfo: IRoutingInfo ): Promise { const peers = await this.peerManager.getPeers({ protocol: Protocols.Store, @@ -301,7 +302,7 @@ export class Store implements IStore { const isHashQuery = options?.messageHashes && options.messageHashes.length > 0; - let routingInfo: RoutingInfo; + let routingInfo: IRoutingInfo; let contentTopics: string[]; let decodersAsMap: Map>; diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index 5d44a2c609..b0ada06494 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -16,6 +16,7 @@ import type { IFilter, ILightPush, IRelay, + IRoutingInfo, IStore, IWaku, IWakuEventEmitter, @@ -27,7 +28,7 @@ import { HealthStatus, Protocols } from "@waku/interfaces"; -import { createRoutingInfo, Logger, RoutingInfo } from "@waku/utils"; +import { createRoutingInfo, Logger } from "@waku/utils"; import { Filter } from "../filter/index.js"; import { HealthIndicator } from "../health_indicator/index.js"; @@ -286,6 +287,6 @@ function getRoutingInfo( networkConfig: NetworkConfig, contentTopic?: string, shardId?: number -): RoutingInfo { +): IRoutingInfo { return createRoutingInfo(networkConfig, { contentTopic, shardId }); }