use IRouting info for typing

This commit is contained in:
fryorcraken 2025-07-19 14:30:44 +10:00
parent b8867dee38
commit d04130feb6
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
10 changed files with 49 additions and 36 deletions

View File

@ -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<IDecodedMessage> {
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<IDecodedMessage> {
*/
export function createDecoder(
contentTopic: string,
routingInfo: RoutingInfo
routingInfo: IRoutingInfo
): Decoder {
if (isAutoShardingRoutingInfo(routingInfo)) {
if (routingInfo.contentTopic !== contentTopic)

View File

@ -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<IEncryptedMessage> {
public constructor(
contentTopic: string,
routingInfo: RoutingInfo,
routingInfo: IRoutingInfo,
private privateKey: Uint8Array
) {
super(contentTopic, routingInfo);
@ -206,11 +207,12 @@ class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
* 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);

View File

@ -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<IEncryptedMessage> {
public constructor(
contentTopic: string,
routingInfo: RoutingInfo,
routingInfo: IRoutingInfo,
private symKey: Uint8Array
) {
super(contentTopic, routingInfo);
@ -212,7 +212,7 @@ class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
*/
export function createDecoder(
contentTopic: string,
routingInfo: RoutingInfo,
routingInfo: IRoutingInfo,
symKey: Uint8Array
): Decoder {
return new Decoder(contentTopic, routingInfo, symKey);

View File

@ -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<T extends IDecodedMessage> = {
};
export type RelayCreateOptions = CreateNodeOptions & {
routingInfos: RoutingInfo[];
routingInfos: IRoutingInfo[];
} & Partial<GossipsubOpts>;
export type ContentTopic = string;

View File

@ -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<IDecodedMessage> {
return createRLNDecoder({
rlnInstance: this,

View File

@ -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<PeerId>) => void;
export class Subscription {
private readonly routingInfo: RoutingInfo;
private readonly routingInfo: IRoutingInfo;
private readonly pubsubTopic: PubsubTopic;
private readonly protocol: FilterCore;
private readonly peerManager: PeerManager;

View File

@ -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<CoreProtocolResult>;
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,

View File

@ -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 {

View File

@ -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<T extends IDecodedMessage>(
decoders: IDecoder<T>[]
): {
routingInfo: RoutingInfo;
routingInfo: IRoutingInfo;
contentTopics: string[];
decodersAsMap: Map<string, IDecoder<T>>;
} {
@ -232,7 +233,7 @@ export class Store implements IStore {
}
private async getPeerToUse(
routingInfo: RoutingInfo
routingInfo: IRoutingInfo
): Promise<PeerId | undefined> {
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<string, IDecoder<T>>;

View File

@ -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 });
}