mirror of
https://github.com/status-im/js-waku.git
synced 2025-02-24 19:08:12 +00:00
Merge pull request #1196 from waku-org/chore/update-proto-definition
This commit is contained in:
commit
7a3c9a8df2
@ -8,16 +8,16 @@ export type ContentFilter = {
|
|||||||
/**
|
/**
|
||||||
* FilterRPC represents a message conforming to the Waku Filter protocol
|
* FilterRPC represents a message conforming to the Waku Filter protocol
|
||||||
*/
|
*/
|
||||||
export class FilterRPC {
|
export class FilterRpc {
|
||||||
public constructor(public proto: proto.FilterRPC) {}
|
public constructor(public proto: proto.FilterRpc) {}
|
||||||
|
|
||||||
static createRequest(
|
static createRequest(
|
||||||
topic: string,
|
topic: string,
|
||||||
contentFilters: ContentFilter[],
|
contentFilters: ContentFilter[],
|
||||||
requestId?: string,
|
requestId?: string,
|
||||||
subscribe = true
|
subscribe = true
|
||||||
): FilterRPC {
|
): FilterRpc {
|
||||||
return new FilterRPC({
|
return new FilterRpc({
|
||||||
requestId: requestId || uuid(),
|
requestId: requestId || uuid(),
|
||||||
request: {
|
request: {
|
||||||
subscribe,
|
subscribe,
|
||||||
@ -31,11 +31,11 @@ export class FilterRPC {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param bytes Uint8Array of bytes from a FilterRPC message
|
* @param bytes Uint8Array of bytes from a FilterRPC message
|
||||||
* @returns FilterRPC
|
* @returns FilterRpc
|
||||||
*/
|
*/
|
||||||
static decode(bytes: Uint8Array): FilterRPC {
|
static decode(bytes: Uint8Array): FilterRpc {
|
||||||
const res = proto.FilterRPC.decode(bytes);
|
const res = proto.FilterRpc.decode(bytes);
|
||||||
return new FilterRPC(res);
|
return new FilterRpc(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,14 +43,14 @@ export class FilterRPC {
|
|||||||
* @returns Uint8Array
|
* @returns Uint8Array
|
||||||
*/
|
*/
|
||||||
encode(): Uint8Array {
|
encode(): Uint8Array {
|
||||||
return proto.FilterRPC.encode(this.proto);
|
return proto.FilterRpc.encode(this.proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
get push(): proto.MessagePush | undefined {
|
get push(): proto.MessagePush | undefined {
|
||||||
return this.proto.push;
|
return this.proto.push;
|
||||||
}
|
}
|
||||||
|
|
||||||
get requestId(): string | undefined {
|
get requestId(): string {
|
||||||
return this.proto.requestId;
|
return this.proto.requestId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import { DefaultPubSubTopic } from "../constants.js";
|
|||||||
import { groupByContentTopic } from "../group_by.js";
|
import { groupByContentTopic } from "../group_by.js";
|
||||||
import { toProtoMessage } from "../to_proto_message.js";
|
import { toProtoMessage } from "../to_proto_message.js";
|
||||||
|
|
||||||
import { ContentFilter, FilterRPC } from "./filter_rpc.js";
|
import { ContentFilter, FilterRpc } from "./filter_rpc.js";
|
||||||
|
|
||||||
export { ContentFilter };
|
export { ContentFilter };
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class Filter extends BaseProtocol implements IFilter {
|
|||||||
const contentFilters = contentTopics.map((contentTopic) => ({
|
const contentFilters = contentTopics.map((contentTopic) => ({
|
||||||
contentTopic,
|
contentTopic,
|
||||||
}));
|
}));
|
||||||
const request = FilterRPC.createRequest(
|
const request = FilterRpc.createRequest(
|
||||||
pubSubTopic,
|
pubSubTopic,
|
||||||
contentFilters,
|
contentFilters,
|
||||||
undefined,
|
undefined,
|
||||||
@ -83,10 +83,6 @@ class Filter extends BaseProtocol implements IFilter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const requestId = request.requestId;
|
const requestId = request.requestId;
|
||||||
if (!requestId)
|
|
||||||
throw new Error(
|
|
||||||
"Internal error: createRequest expected to set `requestId`"
|
|
||||||
);
|
|
||||||
|
|
||||||
const peer = await this.getPeer(opts?.peerId);
|
const peer = await this.getPeer(opts?.peerId);
|
||||||
const stream = await this.newStream(peer);
|
const stream = await this.newStream(peer);
|
||||||
@ -128,7 +124,7 @@ class Filter extends BaseProtocol implements IFilter {
|
|||||||
try {
|
try {
|
||||||
pipe(streamData.stream, lp.decode(), async (source) => {
|
pipe(streamData.stream, lp.decode(), async (source) => {
|
||||||
for await (const bytes of source) {
|
for await (const bytes of source) {
|
||||||
const res = FilterRPC.decode(bytes.slice());
|
const res = FilterRpc.decode(bytes.slice());
|
||||||
if (res.requestId && res.push?.messages?.length) {
|
if (res.requestId && res.push?.messages?.length) {
|
||||||
await this.pushMessages(res.requestId, res.push.messages);
|
await this.pushMessages(res.requestId, res.push.messages);
|
||||||
}
|
}
|
||||||
@ -228,7 +224,7 @@ class Filter extends BaseProtocol implements IFilter {
|
|||||||
requestId: string,
|
requestId: string,
|
||||||
peer: Peer
|
peer: Peer
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const unsubscribeRequest = FilterRPC.createRequest(
|
const unsubscribeRequest = FilterRpc.createRequest(
|
||||||
topic,
|
topic,
|
||||||
contentFilters,
|
contentFilters,
|
||||||
requestId,
|
requestId,
|
||||||
|
@ -18,7 +18,7 @@ import { Uint8ArrayList } from "uint8arraylist";
|
|||||||
import { BaseProtocol } from "../base_protocol.js";
|
import { BaseProtocol } from "../base_protocol.js";
|
||||||
import { DefaultPubSubTopic } from "../constants.js";
|
import { DefaultPubSubTopic } from "../constants.js";
|
||||||
|
|
||||||
import { PushRPC } from "./push_rpc.js";
|
import { PushRpc } from "./push_rpc.js";
|
||||||
|
|
||||||
const log = debug("waku:light-push");
|
const log = debug("waku:light-push");
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class LightPush extends BaseProtocol implements ILightPush {
|
|||||||
log("Failed to encode to protoMessage, aborting push");
|
log("Failed to encode to protoMessage, aborting push");
|
||||||
return { recipients };
|
return { recipients };
|
||||||
}
|
}
|
||||||
const query = PushRPC.createRequest(protoMessage, pubSubTopic);
|
const query = PushRpc.createRequest(protoMessage, pubSubTopic);
|
||||||
const res = await pipe(
|
const res = await pipe(
|
||||||
[query.encode()],
|
[query.encode()],
|
||||||
lp.encode(),
|
lp.encode(),
|
||||||
@ -68,7 +68,7 @@ class LightPush extends BaseProtocol implements ILightPush {
|
|||||||
bytes.append(chunk);
|
bytes.append(chunk);
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = PushRPC.decode(bytes).response;
|
const response = PushRpc.decode(bytes).response;
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
log("No response in PushRPC");
|
log("No response in PushRPC");
|
||||||
|
@ -2,30 +2,30 @@ import { proto_lightpush as proto } from "@waku/proto";
|
|||||||
import type { Uint8ArrayList } from "uint8arraylist";
|
import type { Uint8ArrayList } from "uint8arraylist";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
|
|
||||||
export class PushRPC {
|
export class PushRpc {
|
||||||
public constructor(public proto: proto.PushRPC) {}
|
public constructor(public proto: proto.PushRpc) {}
|
||||||
|
|
||||||
static createRequest(
|
static createRequest(
|
||||||
message: proto.WakuMessage,
|
message: proto.WakuMessage,
|
||||||
pubSubTopic: string
|
pubSubTopic: string
|
||||||
): PushRPC {
|
): PushRpc {
|
||||||
return new PushRPC({
|
return new PushRpc({
|
||||||
requestId: uuid(),
|
requestId: uuid(),
|
||||||
request: {
|
request: {
|
||||||
message: message,
|
message: message,
|
||||||
pubSubTopic: pubSubTopic,
|
pubsubTopic: pubSubTopic,
|
||||||
},
|
},
|
||||||
response: undefined,
|
response: undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static decode(bytes: Uint8ArrayList): PushRPC {
|
static decode(bytes: Uint8ArrayList): PushRpc {
|
||||||
const res = proto.PushRPC.decode(bytes);
|
const res = proto.PushRpc.decode(bytes);
|
||||||
return new PushRPC(res);
|
return new PushRpc(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
encode(): Uint8Array {
|
encode(): Uint8Array {
|
||||||
return proto.PushRPC.encode(this.proto);
|
return proto.PushRpc.encode(this.proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
get query(): proto.PushRequest | undefined {
|
get query(): proto.PushRequest | undefined {
|
||||||
|
@ -9,7 +9,7 @@ import debug from "debug";
|
|||||||
const log = debug("waku:message:topic-only");
|
const log = debug("waku:message:topic-only");
|
||||||
|
|
||||||
export class TopicOnlyMessage implements IDecodedMessage {
|
export class TopicOnlyMessage implements IDecodedMessage {
|
||||||
public payload: undefined;
|
public payload: Uint8Array = new Uint8Array();
|
||||||
public rateLimitProof: undefined;
|
public rateLimitProof: undefined;
|
||||||
public timestamp: undefined;
|
public timestamp: undefined;
|
||||||
public ephemeral: undefined;
|
public ephemeral: undefined;
|
||||||
@ -17,7 +17,7 @@ export class TopicOnlyMessage implements IDecodedMessage {
|
|||||||
constructor(private proto: ProtoTopicOnlyMessage) {}
|
constructor(private proto: ProtoTopicOnlyMessage) {}
|
||||||
|
|
||||||
get contentTopic(): string {
|
get contentTopic(): string {
|
||||||
return this.proto.contentTopic ?? "";
|
return this.proto.contentTopic;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
|||||||
log("Message decoded", protoMessage);
|
log("Message decoded", protoMessage);
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
contentTopic: protoMessage.contentTopic,
|
contentTopic: protoMessage.contentTopic,
|
||||||
payload: undefined,
|
payload: new Uint8Array(),
|
||||||
rateLimitProof: undefined,
|
rateLimitProof: undefined,
|
||||||
timestamp: undefined,
|
timestamp: undefined,
|
||||||
version: undefined,
|
version: undefined,
|
||||||
|
@ -19,22 +19,15 @@ export { proto };
|
|||||||
export class DecodedMessage implements IDecodedMessage {
|
export class DecodedMessage implements IDecodedMessage {
|
||||||
constructor(protected proto: proto.WakuMessage) {}
|
constructor(protected proto: proto.WakuMessage) {}
|
||||||
|
|
||||||
get _rawPayload(): Uint8Array | undefined {
|
|
||||||
if (this.proto.payload) {
|
|
||||||
return new Uint8Array(this.proto.payload);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
get ephemeral(): boolean {
|
get ephemeral(): boolean {
|
||||||
return Boolean(this.proto.ephemeral);
|
return Boolean(this.proto.ephemeral);
|
||||||
}
|
}
|
||||||
|
|
||||||
get payload(): Uint8Array | undefined {
|
get payload(): Uint8Array {
|
||||||
return this._rawPayload;
|
return this.proto.payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
get contentTopic(): string | undefined {
|
get contentTopic(): string {
|
||||||
return this.proto.contentTopic;
|
return this.proto.contentTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,18 +44,15 @@ export class DecodedMessage implements IDecodedMessage {
|
|||||||
const timestamp = this.proto.timestamp / OneMillion;
|
const timestamp = this.proto.timestamp / OneMillion;
|
||||||
return new Date(Number(timestamp));
|
return new Date(Number(timestamp));
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
if (this.proto.timestampDeprecated) {
|
|
||||||
return new Date(this.proto.timestampDeprecated * 1000);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get version(): number {
|
get version(): number {
|
||||||
// https://github.com/status-im/js-waku/issues/921
|
// https://rfc.vac.dev/spec/14/
|
||||||
|
// > If omitted, the value SHOULD be interpreted as version 0.
|
||||||
return this.proto.version ?? 0;
|
return this.proto.version ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +105,8 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
|||||||
const protoMessage = proto.WakuMessage.decode(bytes);
|
const protoMessage = proto.WakuMessage.decode(bytes);
|
||||||
log("Message decoded", protoMessage);
|
log("Message decoded", protoMessage);
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
payload: protoMessage.payload ?? undefined,
|
payload: protoMessage.payload,
|
||||||
contentTopic: protoMessage.contentTopic ?? undefined,
|
contentTopic: protoMessage.contentTopic,
|
||||||
version: protoMessage.version ?? undefined,
|
version: protoMessage.version ?? undefined,
|
||||||
timestamp: protoMessage.timestamp ?? undefined,
|
timestamp: protoMessage.timestamp ?? undefined,
|
||||||
rateLimitProof: protoMessage.rateLimitProof ?? undefined,
|
rateLimitProof: protoMessage.rateLimitProof ?? undefined,
|
||||||
@ -127,12 +117,9 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
|||||||
async fromProtoObj(
|
async fromProtoObj(
|
||||||
proto: IProtoMessage
|
proto: IProtoMessage
|
||||||
): Promise<DecodedMessage | undefined> {
|
): Promise<DecodedMessage | undefined> {
|
||||||
// https://github.com/status-im/js-waku/issues/921
|
// https://rfc.vac.dev/spec/14/
|
||||||
if (proto.version === undefined) {
|
// > If omitted, the value SHOULD be interpreted as version 0.
|
||||||
proto.version = 0;
|
if (proto.version ?? 0 !== Version) {
|
||||||
}
|
|
||||||
|
|
||||||
if (proto.version !== Version) {
|
|
||||||
log(
|
log(
|
||||||
"Failed to decode due to incorrect version, expected:",
|
"Failed to decode due to incorrect version, expected:",
|
||||||
Version,
|
Version,
|
||||||
|
@ -19,8 +19,8 @@ export interface Params {
|
|||||||
cursor?: proto.Index;
|
cursor?: proto.Index;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HistoryRPC {
|
export class HistoryRpc {
|
||||||
private constructor(public readonly proto: proto.HistoryRPC) {}
|
private constructor(public readonly proto: proto.HistoryRpc) {}
|
||||||
|
|
||||||
get query(): proto.HistoryQuery | undefined {
|
get query(): proto.HistoryQuery | undefined {
|
||||||
return this.proto.query;
|
return this.proto.query;
|
||||||
@ -33,7 +33,7 @@ export class HistoryRPC {
|
|||||||
/**
|
/**
|
||||||
* Create History Query.
|
* Create History Query.
|
||||||
*/
|
*/
|
||||||
static createQuery(params: Params): HistoryRPC {
|
static createQuery(params: Params): HistoryRpc {
|
||||||
const contentFilters = params.contentTopics.map((contentTopic) => {
|
const contentFilters = params.contentTopics.map((contentTopic) => {
|
||||||
return { contentTopic };
|
return { contentTopic };
|
||||||
});
|
});
|
||||||
@ -56,10 +56,10 @@ export class HistoryRPC {
|
|||||||
// milliseconds 10^-3 to nanoseconds 10^-9
|
// milliseconds 10^-3 to nanoseconds 10^-9
|
||||||
endTime = BigInt(params.endTime.valueOf()) * OneMillion;
|
endTime = BigInt(params.endTime.valueOf()) * OneMillion;
|
||||||
}
|
}
|
||||||
return new HistoryRPC({
|
return new HistoryRpc({
|
||||||
requestId: uuid(),
|
requestId: uuid(),
|
||||||
query: {
|
query: {
|
||||||
pubSubTopic: params.pubSubTopic,
|
pubsubTopic: params.pubSubTopic,
|
||||||
contentFilters,
|
contentFilters,
|
||||||
pagingInfo,
|
pagingInfo,
|
||||||
startTime,
|
startTime,
|
||||||
@ -69,13 +69,13 @@ export class HistoryRPC {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
decode(bytes: Uint8ArrayList): HistoryRPC {
|
decode(bytes: Uint8ArrayList): HistoryRpc {
|
||||||
const res = proto.HistoryRPC.decode(bytes);
|
const res = proto.HistoryRpc.decode(bytes);
|
||||||
return new HistoryRPC(res);
|
return new HistoryRpc(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
encode(): Uint8Array {
|
encode(): Uint8Array {
|
||||||
return proto.HistoryRPC.encode(this.proto);
|
return proto.HistoryRpc.encode(this.proto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +84,10 @@ function directionToProto(
|
|||||||
): proto.PagingInfo.Direction {
|
): proto.PagingInfo.Direction {
|
||||||
switch (pageDirection) {
|
switch (pageDirection) {
|
||||||
case PageDirection.BACKWARD:
|
case PageDirection.BACKWARD:
|
||||||
return proto.PagingInfo.Direction.DIRECTION_BACKWARD_UNSPECIFIED;
|
return proto.PagingInfo.Direction.BACKWARD;
|
||||||
case PageDirection.FORWARD:
|
case PageDirection.FORWARD:
|
||||||
return proto.PagingInfo.Direction.DIRECTION_FORWARD;
|
return proto.PagingInfo.Direction.FORWARD;
|
||||||
default:
|
default:
|
||||||
return proto.PagingInfo.Direction.DIRECTION_BACKWARD_UNSPECIFIED;
|
return proto.PagingInfo.Direction.BACKWARD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import {
|
|||||||
Cursor,
|
Cursor,
|
||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
Index,
|
|
||||||
IStore,
|
IStore,
|
||||||
ProtocolCreateOptions,
|
ProtocolCreateOptions,
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
@ -22,7 +21,7 @@ import { BaseProtocol } from "../base_protocol.js";
|
|||||||
import { DefaultPubSubTopic } from "../constants.js";
|
import { DefaultPubSubTopic } from "../constants.js";
|
||||||
import { toProtoMessage } from "../to_proto_message.js";
|
import { toProtoMessage } from "../to_proto_message.js";
|
||||||
|
|
||||||
import { HistoryRPC, PageDirection, Params } from "./history_rpc.js";
|
import { HistoryRpc, PageDirection, Params } from "./history_rpc.js";
|
||||||
|
|
||||||
import HistoryError = proto.HistoryResponse.HistoryError;
|
import HistoryError = proto.HistoryResponse.HistoryError;
|
||||||
|
|
||||||
@ -262,7 +261,7 @@ async function* paginate<T extends IDecodedMessage>(
|
|||||||
while (true) {
|
while (true) {
|
||||||
queryOpts.cursor = currentCursor;
|
queryOpts.cursor = currentCursor;
|
||||||
|
|
||||||
const historyRpcQuery = HistoryRPC.createQuery(queryOpts);
|
const historyRpcQuery = HistoryRpc.createQuery(queryOpts);
|
||||||
|
|
||||||
log(
|
log(
|
||||||
"Querying store peer",
|
"Querying store peer",
|
||||||
@ -294,10 +293,7 @@ async function* paginate<T extends IDecodedMessage>(
|
|||||||
|
|
||||||
const response = reply.response as proto.HistoryResponse;
|
const response = reply.response as proto.HistoryResponse;
|
||||||
|
|
||||||
if (
|
if (response.error && response.error !== HistoryError.NONE) {
|
||||||
response.error &&
|
|
||||||
response.error !== HistoryError.ERROR_NONE_UNSPECIFIED
|
|
||||||
) {
|
|
||||||
throw "History response contains an Error: " + response.error;
|
throw "History response contains an Error: " + response.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,7 +349,7 @@ export function isDefined<T>(msg: T | undefined): msg is T {
|
|||||||
export async function createCursor(
|
export async function createCursor(
|
||||||
message: IDecodedMessage,
|
message: IDecodedMessage,
|
||||||
pubsubTopic: string = DefaultPubSubTopic
|
pubsubTopic: string = DefaultPubSubTopic
|
||||||
): Promise<Index> {
|
): Promise<Cursor> {
|
||||||
if (
|
if (
|
||||||
!message ||
|
!message ||
|
||||||
!message.timestamp ||
|
!message.timestamp ||
|
||||||
@ -373,7 +369,7 @@ export async function createCursor(
|
|||||||
digest,
|
digest,
|
||||||
pubsubTopic,
|
pubsubTopic,
|
||||||
senderTime: messageTime,
|
senderTime: messageTime,
|
||||||
receivedTime: messageTime,
|
receiverTime: messageTime,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import { toProtoMessage } from "./to_proto_message.js";
|
|||||||
describe("to proto message", () => {
|
describe("to proto message", () => {
|
||||||
it("Fields are not dropped", () => {
|
it("Fields are not dropped", () => {
|
||||||
const wire: WakuMessageProto = {
|
const wire: WakuMessageProto = {
|
||||||
|
payload: new Uint8Array(),
|
||||||
contentTopic: "foo",
|
contentTopic: "foo",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@ import { IProtoMessage } from "@waku/interfaces";
|
|||||||
import { WakuMessage as WakuMessageProto } from "@waku/proto";
|
import { WakuMessage as WakuMessageProto } from "@waku/proto";
|
||||||
|
|
||||||
const EmptyMessage: IProtoMessage = {
|
const EmptyMessage: IProtoMessage = {
|
||||||
payload: undefined,
|
payload: new Uint8Array(),
|
||||||
contentTopic: undefined,
|
contentTopic: "",
|
||||||
version: undefined,
|
version: undefined,
|
||||||
timestamp: undefined,
|
timestamp: undefined,
|
||||||
rateLimitProof: undefined,
|
rateLimitProof: undefined,
|
||||||
|
@ -13,8 +13,8 @@ export interface IRateLimitProof {
|
|||||||
* Field types matches the protobuf type over the wire
|
* Field types matches the protobuf type over the wire
|
||||||
*/
|
*/
|
||||||
export interface IProtoMessage {
|
export interface IProtoMessage {
|
||||||
payload: Uint8Array | undefined;
|
payload: Uint8Array;
|
||||||
contentTopic: string | undefined;
|
contentTopic: string;
|
||||||
version: number | undefined;
|
version: number | undefined;
|
||||||
timestamp: bigint | undefined;
|
timestamp: bigint | undefined;
|
||||||
rateLimitProof: IRateLimitProof | undefined;
|
rateLimitProof: IRateLimitProof | undefined;
|
||||||
@ -25,7 +25,7 @@ export interface IProtoMessage {
|
|||||||
* Interface for messages to encode and send.
|
* Interface for messages to encode and send.
|
||||||
*/
|
*/
|
||||||
export interface IMessage {
|
export interface IMessage {
|
||||||
payload?: Uint8Array;
|
payload: Uint8Array;
|
||||||
timestamp?: Date;
|
timestamp?: Date;
|
||||||
rateLimitProof?: IRateLimitProof;
|
rateLimitProof?: IRateLimitProof;
|
||||||
}
|
}
|
||||||
@ -48,8 +48,8 @@ export interface IEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IDecodedMessage {
|
export interface IDecodedMessage {
|
||||||
payload: Uint8Array | undefined;
|
payload: Uint8Array;
|
||||||
contentTopic: string | undefined;
|
contentTopic: string;
|
||||||
timestamp: Date | undefined;
|
timestamp: Date | undefined;
|
||||||
rateLimitProof: IRateLimitProof | undefined;
|
rateLimitProof: IRateLimitProof | undefined;
|
||||||
ephemeral: boolean | undefined;
|
ephemeral: boolean | undefined;
|
||||||
|
@ -2,7 +2,7 @@ import type { PeerId } from "@libp2p/interface-peer-id";
|
|||||||
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
||||||
import type { Libp2pOptions } from "libp2p";
|
import type { Libp2pOptions } from "libp2p";
|
||||||
|
|
||||||
import type { IMessage } from "./message.js";
|
import type { IDecodedMessage } from "./message.js";
|
||||||
|
|
||||||
export enum Protocols {
|
export enum Protocols {
|
||||||
Relay = "relay",
|
Relay = "relay",
|
||||||
@ -58,7 +58,9 @@ export type ProtocolOptions = {
|
|||||||
peerId?: PeerId;
|
peerId?: PeerId;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Callback<T extends IMessage> = (msg: T) => void | Promise<void>;
|
export type Callback<T extends IDecodedMessage> = (
|
||||||
|
msg: T
|
||||||
|
) => void | Promise<void>;
|
||||||
|
|
||||||
export interface SendResult {
|
export interface SendResult {
|
||||||
recipients: PeerId[];
|
recipients: PeerId[];
|
||||||
|
@ -11,19 +11,13 @@ export interface TimeFilter {
|
|||||||
endTime: Date;
|
endTime: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Index {
|
export interface Cursor {
|
||||||
digest?: Uint8Array;
|
digest: Uint8Array;
|
||||||
receivedTime?: bigint;
|
receiverTime: bigint;
|
||||||
senderTime?: bigint;
|
senderTime: bigint;
|
||||||
pubsubTopic?: string;
|
pubsubTopic: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Cursor = {
|
|
||||||
digest?: Uint8Array;
|
|
||||||
senderTime?: bigint;
|
|
||||||
pubsubTopic?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type StoreQueryOptions = {
|
export type StoreQueryOptions = {
|
||||||
/**
|
/**
|
||||||
* The direction in which pages are retrieved:
|
* The direction in which pages are retrieved:
|
||||||
@ -45,7 +39,8 @@ export type StoreQueryOptions = {
|
|||||||
*/
|
*/
|
||||||
timeFilter?: TimeFilter;
|
timeFilter?: TimeFilter;
|
||||||
/**
|
/**
|
||||||
* Cursor as an index to start a query from.
|
* Cursor as an index to start a query from. Must be generated from a Waku
|
||||||
|
* Message.
|
||||||
*/
|
*/
|
||||||
cursor?: Cursor;
|
cursor?: Cursor;
|
||||||
} & ProtocolOptions;
|
} & ProtocolOptions;
|
||||||
|
@ -45,10 +45,6 @@ export class Encoder implements IEncoder {
|
|||||||
|
|
||||||
async toProtoObj(message: IMessage): Promise<IProtoMessage | undefined> {
|
async toProtoObj(message: IMessage): Promise<IProtoMessage | undefined> {
|
||||||
const timestamp = message.timestamp ?? new Date();
|
const timestamp = message.timestamp ?? new Date();
|
||||||
if (!message.payload) {
|
|
||||||
log("No payload to encrypt, skipping: ", message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const preparedPayload = await preCipher(message.payload, this.sigPrivKey);
|
const preparedPayload = await preCipher(message.payload, this.sigPrivKey);
|
||||||
|
|
||||||
const payload = await encryptAsymmetric(preparedPayload, this.publicKey);
|
const payload = await encryptAsymmetric(preparedPayload, this.publicKey);
|
||||||
@ -113,10 +109,6 @@ export class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let payload;
|
let payload;
|
||||||
if (!cipherPayload) {
|
|
||||||
log(`No payload to decrypt for contentTopic ${this.contentTopic}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
payload = await decryptAsymmetric(cipherPayload, this.privateKey);
|
payload = await decryptAsymmetric(cipherPayload, this.privateKey);
|
||||||
|
@ -44,10 +44,6 @@ export class Encoder implements IEncoder {
|
|||||||
|
|
||||||
async toProtoObj(message: IMessage): Promise<IProtoMessage | undefined> {
|
async toProtoObj(message: IMessage): Promise<IProtoMessage | undefined> {
|
||||||
const timestamp = message.timestamp ?? new Date();
|
const timestamp = message.timestamp ?? new Date();
|
||||||
if (!message.payload) {
|
|
||||||
log("No payload to encrypt, skipping: ", message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const preparedPayload = await preCipher(message.payload, this.sigPrivKey);
|
const preparedPayload = await preCipher(message.payload, this.sigPrivKey);
|
||||||
|
|
||||||
const payload = await encryptSymmetric(preparedPayload, this.symKey);
|
const payload = await encryptSymmetric(preparedPayload, this.symKey);
|
||||||
@ -112,10 +108,6 @@ export class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let payload;
|
let payload;
|
||||||
if (!cipherPayload) {
|
|
||||||
log(`No payload to decrypt for contentTopic ${this.contentTopic}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
payload = await decryptSymmetric(cipherPayload, this.symKey);
|
payload = await decryptSymmetric(cipherPayload, this.symKey);
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
|
// 12/WAKU2-FILTER rfc: https://rfc.vac.dev/spec/12/
|
||||||
|
// Protocol identifier: /vac/waku/filter/2.0.0-beta1
|
||||||
|
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
import "message.proto";
|
import "message.proto";
|
||||||
|
|
||||||
message FilterRequest {
|
message FilterRequest {
|
||||||
optional bool subscribe = 1;
|
|
||||||
optional string topic = 2;
|
|
||||||
repeated ContentFilter content_filters = 3;
|
|
||||||
|
|
||||||
message ContentFilter {
|
message ContentFilter {
|
||||||
optional string content_topic = 1;
|
string content_topic = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool subscribe = 1;
|
||||||
|
string topic = 2;
|
||||||
|
repeated ContentFilter content_filters = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message MessagePush {
|
message MessagePush {
|
||||||
repeated WakuMessage messages = 1;
|
repeated WakuMessage messages = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FilterRPC {
|
message FilterRpc {
|
||||||
optional string request_id = 1;
|
string request_id = 1;
|
||||||
optional FilterRequest request = 2;
|
optional FilterRequest request = 2;
|
||||||
optional MessagePush push = 3;
|
optional MessagePush push = 3;
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,14 @@ import type { Codec } from "protons-runtime";
|
|||||||
import type { Uint8ArrayList } from "uint8arraylist";
|
import type { Uint8ArrayList } from "uint8arraylist";
|
||||||
|
|
||||||
export interface FilterRequest {
|
export interface FilterRequest {
|
||||||
subscribe?: boolean;
|
subscribe: boolean;
|
||||||
topic?: string;
|
topic: string;
|
||||||
contentFilters: FilterRequest.ContentFilter[];
|
contentFilters: FilterRequest.ContentFilter[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace FilterRequest {
|
export namespace FilterRequest {
|
||||||
export interface ContentFilter {
|
export interface ContentFilter {
|
||||||
contentTopic?: string;
|
contentTopic: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace ContentFilter {
|
export namespace ContentFilter {
|
||||||
@ -30,7 +30,7 @@ export namespace FilterRequest {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.contentTopic != null) {
|
if (obj.contentTopic != null && obj.contentTopic !== "") {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.string(obj.contentTopic);
|
w.string(obj.contentTopic);
|
||||||
}
|
}
|
||||||
@ -40,7 +40,9 @@ export namespace FilterRequest {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
contentTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -84,12 +86,12 @@ export namespace FilterRequest {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.subscribe != null) {
|
if (obj.subscribe != null && obj.subscribe !== false) {
|
||||||
w.uint32(8);
|
w.uint32(8);
|
||||||
w.bool(obj.subscribe);
|
w.bool(obj.subscribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.topic != null) {
|
if (obj.topic != null && obj.topic !== "") {
|
||||||
w.uint32(18);
|
w.uint32(18);
|
||||||
w.string(obj.topic);
|
w.string(obj.topic);
|
||||||
}
|
}
|
||||||
@ -107,6 +109,8 @@ export namespace FilterRequest {
|
|||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {
|
const obj: any = {
|
||||||
|
subscribe: false,
|
||||||
|
topic: "",
|
||||||
contentFilters: [],
|
contentFilters: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -218,24 +222,24 @@ export namespace MessagePush {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FilterRPC {
|
export interface FilterRpc {
|
||||||
requestId?: string;
|
requestId: string;
|
||||||
request?: FilterRequest;
|
request?: FilterRequest;
|
||||||
push?: MessagePush;
|
push?: MessagePush;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace FilterRPC {
|
export namespace FilterRpc {
|
||||||
let _codec: Codec<FilterRPC>;
|
let _codec: Codec<FilterRpc>;
|
||||||
|
|
||||||
export const codec = (): Codec<FilterRPC> => {
|
export const codec = (): Codec<FilterRpc> => {
|
||||||
if (_codec == null) {
|
if (_codec == null) {
|
||||||
_codec = message<FilterRPC>(
|
_codec = message<FilterRpc>(
|
||||||
(obj, w, opts = {}) => {
|
(obj, w, opts = {}) => {
|
||||||
if (opts.lengthDelimited !== false) {
|
if (opts.lengthDelimited !== false) {
|
||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.requestId != null) {
|
if (obj.requestId != null && obj.requestId !== "") {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.string(obj.requestId);
|
w.string(obj.requestId);
|
||||||
}
|
}
|
||||||
@ -255,7 +259,9 @@ export namespace FilterRPC {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
requestId: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -289,12 +295,12 @@ export namespace FilterRPC {
|
|||||||
return _codec;
|
return _codec;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const encode = (obj: Partial<FilterRPC>): Uint8Array => {
|
export const encode = (obj: Partial<FilterRpc>): Uint8Array => {
|
||||||
return encodeMessage(obj, FilterRPC.codec());
|
return encodeMessage(obj, FilterRpc.codec());
|
||||||
};
|
};
|
||||||
|
|
||||||
export const decode = (buf: Uint8Array | Uint8ArrayList): FilterRPC => {
|
export const decode = (buf: Uint8Array | Uint8ArrayList): FilterRpc => {
|
||||||
return decodeMessage(buf, FilterRPC.codec());
|
return decodeMessage(buf, FilterRpc.codec());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,10 +426,9 @@ export namespace RateLimitProof {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WakuMessage {
|
export interface WakuMessage {
|
||||||
payload?: Uint8Array;
|
payload: Uint8Array;
|
||||||
contentTopic?: string;
|
contentTopic: string;
|
||||||
version?: number;
|
version?: number;
|
||||||
timestampDeprecated?: number;
|
|
||||||
timestamp?: bigint;
|
timestamp?: bigint;
|
||||||
rateLimitProof?: RateLimitProof;
|
rateLimitProof?: RateLimitProof;
|
||||||
ephemeral?: boolean;
|
ephemeral?: boolean;
|
||||||
@ -440,12 +445,12 @@ export namespace WakuMessage {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.payload != null) {
|
if (obj.payload != null && obj.payload.byteLength > 0) {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.bytes(obj.payload);
|
w.bytes(obj.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.contentTopic != null) {
|
if (obj.contentTopic != null && obj.contentTopic !== "") {
|
||||||
w.uint32(18);
|
w.uint32(18);
|
||||||
w.string(obj.contentTopic);
|
w.string(obj.contentTopic);
|
||||||
}
|
}
|
||||||
@ -455,11 +460,6 @@ export namespace WakuMessage {
|
|||||||
w.uint32(obj.version);
|
w.uint32(obj.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.timestampDeprecated != null) {
|
|
||||||
w.uint32(33);
|
|
||||||
w.double(obj.timestampDeprecated);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.timestamp != null) {
|
if (obj.timestamp != null) {
|
||||||
w.uint32(80);
|
w.uint32(80);
|
||||||
w.sint64(obj.timestamp);
|
w.sint64(obj.timestamp);
|
||||||
@ -480,7 +480,10 @@ export namespace WakuMessage {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
payload: new Uint8Array(0),
|
||||||
|
contentTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -497,9 +500,6 @@ export namespace WakuMessage {
|
|||||||
case 3:
|
case 3:
|
||||||
obj.version = reader.uint32();
|
obj.version = reader.uint32();
|
||||||
break;
|
break;
|
||||||
case 4:
|
|
||||||
obj.timestampDeprecated = reader.double();
|
|
||||||
break;
|
|
||||||
case 10:
|
case 10:
|
||||||
obj.timestamp = reader.sint64();
|
obj.timestamp = reader.sint64();
|
||||||
break;
|
break;
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
|
// 19/WAKU2-LIGHTPUSH rfc: https://rfc.vac.dev/spec/19/
|
||||||
|
// Protocol identifier: /vac/waku/lightpush/2.0.0-beta1
|
||||||
|
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
import "message.proto";
|
import "message.proto";
|
||||||
|
|
||||||
message PushRequest {
|
message PushRequest {
|
||||||
optional string pub_sub_topic = 1;
|
string pubsub_topic = 1;
|
||||||
optional WakuMessage message = 2;
|
WakuMessage message = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PushResponse {
|
message PushResponse {
|
||||||
optional bool is_success = 1;
|
bool is_success = 1;
|
||||||
optional string info = 2;
|
optional string info = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PushRPC {
|
message PushRpc {
|
||||||
optional string request_id = 1;
|
string request_id = 1;
|
||||||
optional PushRequest request = 2;
|
optional PushRequest request = 2;
|
||||||
optional PushResponse response = 3;
|
optional PushResponse response = 3;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import type { Codec } from "protons-runtime";
|
|||||||
import type { Uint8ArrayList } from "uint8arraylist";
|
import type { Uint8ArrayList } from "uint8arraylist";
|
||||||
|
|
||||||
export interface PushRequest {
|
export interface PushRequest {
|
||||||
pubSubTopic?: string;
|
pubsubTopic: string;
|
||||||
message?: WakuMessage;
|
message?: WakuMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,9 +24,9 @@ export namespace PushRequest {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.pubSubTopic != null) {
|
if (obj.pubsubTopic != null && obj.pubsubTopic !== "") {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.string(obj.pubSubTopic);
|
w.string(obj.pubsubTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.message != null) {
|
if (obj.message != null) {
|
||||||
@ -39,7 +39,9 @@ export namespace PushRequest {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
pubsubTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -48,7 +50,7 @@ export namespace PushRequest {
|
|||||||
|
|
||||||
switch (tag >>> 3) {
|
switch (tag >>> 3) {
|
||||||
case 1:
|
case 1:
|
||||||
obj.pubSubTopic = reader.string();
|
obj.pubsubTopic = reader.string();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
obj.message = WakuMessage.codec().decode(
|
obj.message = WakuMessage.codec().decode(
|
||||||
@ -80,7 +82,7 @@ export namespace PushRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface PushResponse {
|
export interface PushResponse {
|
||||||
isSuccess?: boolean;
|
isSuccess: boolean;
|
||||||
info?: string;
|
info?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ export namespace PushResponse {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.isSuccess != null) {
|
if (obj.isSuccess != null && obj.isSuccess !== false) {
|
||||||
w.uint32(8);
|
w.uint32(8);
|
||||||
w.bool(obj.isSuccess);
|
w.bool(obj.isSuccess);
|
||||||
}
|
}
|
||||||
@ -110,7 +112,9 @@ export namespace PushResponse {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
isSuccess: false,
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -147,24 +151,24 @@ export namespace PushResponse {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PushRPC {
|
export interface PushRpc {
|
||||||
requestId?: string;
|
requestId: string;
|
||||||
request?: PushRequest;
|
request?: PushRequest;
|
||||||
response?: PushResponse;
|
response?: PushResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace PushRPC {
|
export namespace PushRpc {
|
||||||
let _codec: Codec<PushRPC>;
|
let _codec: Codec<PushRpc>;
|
||||||
|
|
||||||
export const codec = (): Codec<PushRPC> => {
|
export const codec = (): Codec<PushRpc> => {
|
||||||
if (_codec == null) {
|
if (_codec == null) {
|
||||||
_codec = message<PushRPC>(
|
_codec = message<PushRpc>(
|
||||||
(obj, w, opts = {}) => {
|
(obj, w, opts = {}) => {
|
||||||
if (opts.lengthDelimited !== false) {
|
if (opts.lengthDelimited !== false) {
|
||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.requestId != null) {
|
if (obj.requestId != null && obj.requestId !== "") {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.string(obj.requestId);
|
w.string(obj.requestId);
|
||||||
}
|
}
|
||||||
@ -184,7 +188,9 @@ export namespace PushRPC {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
requestId: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -221,12 +227,12 @@ export namespace PushRPC {
|
|||||||
return _codec;
|
return _codec;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const encode = (obj: Partial<PushRPC>): Uint8Array => {
|
export const encode = (obj: Partial<PushRpc>): Uint8Array => {
|
||||||
return encodeMessage(obj, PushRPC.codec());
|
return encodeMessage(obj, PushRpc.codec());
|
||||||
};
|
};
|
||||||
|
|
||||||
export const decode = (buf: Uint8Array | Uint8ArrayList): PushRPC => {
|
export const decode = (buf: Uint8Array | Uint8ArrayList): PushRpc => {
|
||||||
return decodeMessage(buf, PushRPC.codec());
|
return decodeMessage(buf, PushRpc.codec());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,10 +358,9 @@ export namespace RateLimitProof {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WakuMessage {
|
export interface WakuMessage {
|
||||||
payload?: Uint8Array;
|
payload: Uint8Array;
|
||||||
contentTopic?: string;
|
contentTopic: string;
|
||||||
version?: number;
|
version?: number;
|
||||||
timestampDeprecated?: number;
|
|
||||||
timestamp?: bigint;
|
timestamp?: bigint;
|
||||||
rateLimitProof?: RateLimitProof;
|
rateLimitProof?: RateLimitProof;
|
||||||
ephemeral?: boolean;
|
ephemeral?: boolean;
|
||||||
@ -372,12 +377,12 @@ export namespace WakuMessage {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.payload != null) {
|
if (obj.payload != null && obj.payload.byteLength > 0) {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.bytes(obj.payload);
|
w.bytes(obj.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.contentTopic != null) {
|
if (obj.contentTopic != null && obj.contentTopic !== "") {
|
||||||
w.uint32(18);
|
w.uint32(18);
|
||||||
w.string(obj.contentTopic);
|
w.string(obj.contentTopic);
|
||||||
}
|
}
|
||||||
@ -387,11 +392,6 @@ export namespace WakuMessage {
|
|||||||
w.uint32(obj.version);
|
w.uint32(obj.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.timestampDeprecated != null) {
|
|
||||||
w.uint32(33);
|
|
||||||
w.double(obj.timestampDeprecated);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.timestamp != null) {
|
if (obj.timestamp != null) {
|
||||||
w.uint32(80);
|
w.uint32(80);
|
||||||
w.sint64(obj.timestamp);
|
w.sint64(obj.timestamp);
|
||||||
@ -412,7 +412,10 @@ export namespace WakuMessage {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
payload: new Uint8Array(0),
|
||||||
|
contentTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -429,9 +432,6 @@ export namespace WakuMessage {
|
|||||||
case 3:
|
case 3:
|
||||||
obj.version = reader.uint32();
|
obj.version = reader.uint32();
|
||||||
break;
|
break;
|
||||||
case 4:
|
|
||||||
obj.timestampDeprecated = reader.double();
|
|
||||||
break;
|
|
||||||
case 10:
|
case 10:
|
||||||
obj.timestamp = reader.sint64();
|
obj.timestamp = reader.sint64();
|
||||||
break;
|
break;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// 14/WAKU2-MESSAGE rfc: https://rfc.vac.dev/spec/14/
|
||||||
|
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
message RateLimitProof {
|
message RateLimitProof {
|
||||||
@ -7,16 +9,14 @@ message RateLimitProof {
|
|||||||
bytes share_x = 4;
|
bytes share_x = 4;
|
||||||
bytes share_y = 5;
|
bytes share_y = 5;
|
||||||
bytes nullifier = 6;
|
bytes nullifier = 6;
|
||||||
bytes rlnIdentifier = 7;
|
bytes rln_identifier = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message WakuMessage {
|
message WakuMessage {
|
||||||
optional bytes payload = 1;
|
bytes payload = 1;
|
||||||
optional string content_topic = 2;
|
string content_topic = 2;
|
||||||
optional uint32 version = 3;
|
optional uint32 version = 3;
|
||||||
optional double timestamp_deprecated = 4;
|
|
||||||
optional sint64 timestamp = 10;
|
optional sint64 timestamp = 10;
|
||||||
optional RateLimitProof rate_limit_proof = 21;
|
optional RateLimitProof rate_limit_proof = 21;
|
||||||
optional bool ephemeral = 31;
|
optional bool ephemeral = 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,10 +130,9 @@ export namespace RateLimitProof {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WakuMessage {
|
export interface WakuMessage {
|
||||||
payload?: Uint8Array;
|
payload: Uint8Array;
|
||||||
contentTopic?: string;
|
contentTopic: string;
|
||||||
version?: number;
|
version?: number;
|
||||||
timestampDeprecated?: number;
|
|
||||||
timestamp?: bigint;
|
timestamp?: bigint;
|
||||||
rateLimitProof?: RateLimitProof;
|
rateLimitProof?: RateLimitProof;
|
||||||
ephemeral?: boolean;
|
ephemeral?: boolean;
|
||||||
@ -150,12 +149,12 @@ export namespace WakuMessage {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.payload != null) {
|
if (obj.payload != null && obj.payload.byteLength > 0) {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.bytes(obj.payload);
|
w.bytes(obj.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.contentTopic != null) {
|
if (obj.contentTopic != null && obj.contentTopic !== "") {
|
||||||
w.uint32(18);
|
w.uint32(18);
|
||||||
w.string(obj.contentTopic);
|
w.string(obj.contentTopic);
|
||||||
}
|
}
|
||||||
@ -165,11 +164,6 @@ export namespace WakuMessage {
|
|||||||
w.uint32(obj.version);
|
w.uint32(obj.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.timestampDeprecated != null) {
|
|
||||||
w.uint32(33);
|
|
||||||
w.double(obj.timestampDeprecated);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.timestamp != null) {
|
if (obj.timestamp != null) {
|
||||||
w.uint32(80);
|
w.uint32(80);
|
||||||
w.sint64(obj.timestamp);
|
w.sint64(obj.timestamp);
|
||||||
@ -190,7 +184,10 @@ export namespace WakuMessage {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
payload: new Uint8Array(0),
|
||||||
|
contentTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -207,9 +204,6 @@ export namespace WakuMessage {
|
|||||||
case 3:
|
case 3:
|
||||||
obj.version = reader.uint32();
|
obj.version = reader.uint32();
|
||||||
break;
|
break;
|
||||||
case 4:
|
|
||||||
obj.timestampDeprecated = reader.double();
|
|
||||||
break;
|
|
||||||
case 10:
|
case 10:
|
||||||
obj.timestamp = reader.sint64();
|
obj.timestamp = reader.sint64();
|
||||||
break;
|
break;
|
||||||
|
@ -1,30 +1,34 @@
|
|||||||
|
// 13/WAKU2-STORE rfc: https://rfc.vac.dev/spec/13/
|
||||||
|
// Protocol identifier: /vac/waku/store/2.0.0-beta4
|
||||||
|
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
import "message.proto";
|
import "message.proto";
|
||||||
|
|
||||||
message Index {
|
message Index {
|
||||||
optional bytes digest = 1;
|
bytes digest = 1;
|
||||||
optional sint64 received_time = 2;
|
sint64 receiver_time = 2;
|
||||||
optional sint64 sender_time = 3;
|
sint64 sender_time = 3;
|
||||||
optional string pubsub_topic = 4;
|
string pubsub_topic = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PagingInfo {
|
message PagingInfo {
|
||||||
optional uint64 page_size = 1;
|
optional uint64 page_size = 1;
|
||||||
optional Index cursor = 2;
|
optional Index cursor = 2;
|
||||||
enum Direction {
|
enum Direction {
|
||||||
DIRECTION_BACKWARD_UNSPECIFIED = 0;
|
BACKWARD = 0;
|
||||||
DIRECTION_FORWARD = 1;
|
FORWARD = 1;
|
||||||
}
|
}
|
||||||
optional Direction direction = 3;
|
optional Direction direction = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ContentFilter {
|
message ContentFilter {
|
||||||
optional string content_topic = 1;
|
string content_topic = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message HistoryQuery {
|
message HistoryQuery {
|
||||||
optional string pub_sub_topic = 2;
|
// The first field is reserved for future use
|
||||||
|
optional string pubsub_topic = 2;
|
||||||
repeated ContentFilter content_filters = 3;
|
repeated ContentFilter content_filters = 3;
|
||||||
optional PagingInfo paging_info = 4;
|
optional PagingInfo paging_info = 4;
|
||||||
optional sint64 start_time = 5;
|
optional sint64 start_time = 5;
|
||||||
@ -32,17 +36,18 @@ message HistoryQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message HistoryResponse {
|
message HistoryResponse {
|
||||||
|
// The first field is reserved for future use
|
||||||
repeated WakuMessage messages = 2;
|
repeated WakuMessage messages = 2;
|
||||||
optional PagingInfo paging_info = 3;
|
optional PagingInfo paging_info = 3;
|
||||||
enum HistoryError {
|
enum HistoryError {
|
||||||
ERROR_NONE_UNSPECIFIED = 0;
|
NONE = 0;
|
||||||
ERROR_INVALID_CURSOR = 1;
|
INVALID_CURSOR = 1;
|
||||||
}
|
}
|
||||||
optional HistoryError error = 4;
|
HistoryError error = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message HistoryRPC {
|
message HistoryRpc {
|
||||||
optional string request_id = 1;
|
string request_id = 1;
|
||||||
optional HistoryQuery query = 2;
|
optional HistoryQuery query = 2;
|
||||||
optional HistoryResponse response = 3;
|
optional HistoryResponse response = 3;
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,10 @@ import type { Codec } from "protons-runtime";
|
|||||||
import type { Uint8ArrayList } from "uint8arraylist";
|
import type { Uint8ArrayList } from "uint8arraylist";
|
||||||
|
|
||||||
export interface Index {
|
export interface Index {
|
||||||
digest?: Uint8Array;
|
digest: Uint8Array;
|
||||||
receivedTime?: bigint;
|
receiverTime: bigint;
|
||||||
senderTime?: bigint;
|
senderTime: bigint;
|
||||||
pubsubTopic?: string;
|
pubsubTopic: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Index {
|
export namespace Index {
|
||||||
@ -31,22 +31,22 @@ export namespace Index {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.digest != null) {
|
if (obj.digest != null && obj.digest.byteLength > 0) {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.bytes(obj.digest);
|
w.bytes(obj.digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.receivedTime != null) {
|
if (obj.receiverTime != null && obj.receiverTime !== 0n) {
|
||||||
w.uint32(16);
|
w.uint32(16);
|
||||||
w.sint64(obj.receivedTime);
|
w.sint64(obj.receiverTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.senderTime != null) {
|
if (obj.senderTime != null && obj.senderTime !== 0n) {
|
||||||
w.uint32(24);
|
w.uint32(24);
|
||||||
w.sint64(obj.senderTime);
|
w.sint64(obj.senderTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.pubsubTopic != null) {
|
if (obj.pubsubTopic != null && obj.pubsubTopic !== "") {
|
||||||
w.uint32(34);
|
w.uint32(34);
|
||||||
w.string(obj.pubsubTopic);
|
w.string(obj.pubsubTopic);
|
||||||
}
|
}
|
||||||
@ -56,7 +56,12 @@ export namespace Index {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
digest: new Uint8Array(0),
|
||||||
|
receiverTime: 0n,
|
||||||
|
senderTime: 0n,
|
||||||
|
pubsubTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -68,7 +73,7 @@ export namespace Index {
|
|||||||
obj.digest = reader.bytes();
|
obj.digest = reader.bytes();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
obj.receivedTime = reader.sint64();
|
obj.receiverTime = reader.sint64();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
obj.senderTime = reader.sint64();
|
obj.senderTime = reader.sint64();
|
||||||
@ -107,13 +112,13 @@ export interface PagingInfo {
|
|||||||
|
|
||||||
export namespace PagingInfo {
|
export namespace PagingInfo {
|
||||||
export enum Direction {
|
export enum Direction {
|
||||||
DIRECTION_BACKWARD_UNSPECIFIED = "DIRECTION_BACKWARD_UNSPECIFIED",
|
BACKWARD = "BACKWARD",
|
||||||
DIRECTION_FORWARD = "DIRECTION_FORWARD",
|
FORWARD = "FORWARD",
|
||||||
}
|
}
|
||||||
|
|
||||||
enum __DirectionValues {
|
enum __DirectionValues {
|
||||||
DIRECTION_BACKWARD_UNSPECIFIED = 0,
|
BACKWARD = 0,
|
||||||
DIRECTION_FORWARD = 1,
|
FORWARD = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Direction {
|
export namespace Direction {
|
||||||
@ -193,7 +198,7 @@ export namespace PagingInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ContentFilter {
|
export interface ContentFilter {
|
||||||
contentTopic?: string;
|
contentTopic: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace ContentFilter {
|
export namespace ContentFilter {
|
||||||
@ -207,7 +212,7 @@ export namespace ContentFilter {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.contentTopic != null) {
|
if (obj.contentTopic != null && obj.contentTopic !== "") {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.string(obj.contentTopic);
|
w.string(obj.contentTopic);
|
||||||
}
|
}
|
||||||
@ -217,7 +222,9 @@ export namespace ContentFilter {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
contentTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -252,7 +259,7 @@ export namespace ContentFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface HistoryQuery {
|
export interface HistoryQuery {
|
||||||
pubSubTopic?: string;
|
pubsubTopic?: string;
|
||||||
contentFilters: ContentFilter[];
|
contentFilters: ContentFilter[];
|
||||||
pagingInfo?: PagingInfo;
|
pagingInfo?: PagingInfo;
|
||||||
startTime?: bigint;
|
startTime?: bigint;
|
||||||
@ -270,9 +277,9 @@ export namespace HistoryQuery {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.pubSubTopic != null) {
|
if (obj.pubsubTopic != null) {
|
||||||
w.uint32(18);
|
w.uint32(18);
|
||||||
w.string(obj.pubSubTopic);
|
w.string(obj.pubsubTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.contentFilters != null) {
|
if (obj.contentFilters != null) {
|
||||||
@ -313,7 +320,7 @@ export namespace HistoryQuery {
|
|||||||
|
|
||||||
switch (tag >>> 3) {
|
switch (tag >>> 3) {
|
||||||
case 2:
|
case 2:
|
||||||
obj.pubSubTopic = reader.string();
|
obj.pubsubTopic = reader.string();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
obj.contentFilters.push(
|
obj.contentFilters.push(
|
||||||
@ -358,18 +365,18 @@ export namespace HistoryQuery {
|
|||||||
export interface HistoryResponse {
|
export interface HistoryResponse {
|
||||||
messages: WakuMessage[];
|
messages: WakuMessage[];
|
||||||
pagingInfo?: PagingInfo;
|
pagingInfo?: PagingInfo;
|
||||||
error?: HistoryResponse.HistoryError;
|
error: HistoryResponse.HistoryError;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace HistoryResponse {
|
export namespace HistoryResponse {
|
||||||
export enum HistoryError {
|
export enum HistoryError {
|
||||||
ERROR_NONE_UNSPECIFIED = "ERROR_NONE_UNSPECIFIED",
|
NONE = "NONE",
|
||||||
ERROR_INVALID_CURSOR = "ERROR_INVALID_CURSOR",
|
INVALID_CURSOR = "INVALID_CURSOR",
|
||||||
}
|
}
|
||||||
|
|
||||||
enum __HistoryErrorValues {
|
enum __HistoryErrorValues {
|
||||||
ERROR_NONE_UNSPECIFIED = 0,
|
NONE = 0,
|
||||||
ERROR_INVALID_CURSOR = 1,
|
INVALID_CURSOR = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace HistoryError {
|
export namespace HistoryError {
|
||||||
@ -400,7 +407,7 @@ export namespace HistoryResponse {
|
|||||||
PagingInfo.codec().encode(obj.pagingInfo, w);
|
PagingInfo.codec().encode(obj.pagingInfo, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.error != null) {
|
if (obj.error != null && __HistoryErrorValues[obj.error] !== 0) {
|
||||||
w.uint32(32);
|
w.uint32(32);
|
||||||
HistoryResponse.HistoryError.codec().encode(obj.error, w);
|
HistoryResponse.HistoryError.codec().encode(obj.error, w);
|
||||||
}
|
}
|
||||||
@ -412,6 +419,7 @@ export namespace HistoryResponse {
|
|||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {
|
const obj: any = {
|
||||||
messages: [],
|
messages: [],
|
||||||
|
error: HistoryError.NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
@ -457,24 +465,24 @@ export namespace HistoryResponse {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HistoryRPC {
|
export interface HistoryRpc {
|
||||||
requestId?: string;
|
requestId: string;
|
||||||
query?: HistoryQuery;
|
query?: HistoryQuery;
|
||||||
response?: HistoryResponse;
|
response?: HistoryResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace HistoryRPC {
|
export namespace HistoryRpc {
|
||||||
let _codec: Codec<HistoryRPC>;
|
let _codec: Codec<HistoryRpc>;
|
||||||
|
|
||||||
export const codec = (): Codec<HistoryRPC> => {
|
export const codec = (): Codec<HistoryRpc> => {
|
||||||
if (_codec == null) {
|
if (_codec == null) {
|
||||||
_codec = message<HistoryRPC>(
|
_codec = message<HistoryRpc>(
|
||||||
(obj, w, opts = {}) => {
|
(obj, w, opts = {}) => {
|
||||||
if (opts.lengthDelimited !== false) {
|
if (opts.lengthDelimited !== false) {
|
||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.requestId != null) {
|
if (obj.requestId != null && obj.requestId !== "") {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.string(obj.requestId);
|
w.string(obj.requestId);
|
||||||
}
|
}
|
||||||
@ -494,7 +502,9 @@ export namespace HistoryRPC {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
requestId: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -531,12 +541,12 @@ export namespace HistoryRPC {
|
|||||||
return _codec;
|
return _codec;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const encode = (obj: Partial<HistoryRPC>): Uint8Array => {
|
export const encode = (obj: Partial<HistoryRpc>): Uint8Array => {
|
||||||
return encodeMessage(obj, HistoryRPC.codec());
|
return encodeMessage(obj, HistoryRpc.codec());
|
||||||
};
|
};
|
||||||
|
|
||||||
export const decode = (buf: Uint8Array | Uint8ArrayList): HistoryRPC => {
|
export const decode = (buf: Uint8Array | Uint8ArrayList): HistoryRpc => {
|
||||||
return decodeMessage(buf, HistoryRPC.codec());
|
return decodeMessage(buf, HistoryRpc.codec());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -662,10 +672,9 @@ export namespace RateLimitProof {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WakuMessage {
|
export interface WakuMessage {
|
||||||
payload?: Uint8Array;
|
payload: Uint8Array;
|
||||||
contentTopic?: string;
|
contentTopic: string;
|
||||||
version?: number;
|
version?: number;
|
||||||
timestampDeprecated?: number;
|
|
||||||
timestamp?: bigint;
|
timestamp?: bigint;
|
||||||
rateLimitProof?: RateLimitProof;
|
rateLimitProof?: RateLimitProof;
|
||||||
ephemeral?: boolean;
|
ephemeral?: boolean;
|
||||||
@ -682,12 +691,12 @@ export namespace WakuMessage {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.payload != null) {
|
if (obj.payload != null && obj.payload.byteLength > 0) {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.bytes(obj.payload);
|
w.bytes(obj.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.contentTopic != null) {
|
if (obj.contentTopic != null && obj.contentTopic !== "") {
|
||||||
w.uint32(18);
|
w.uint32(18);
|
||||||
w.string(obj.contentTopic);
|
w.string(obj.contentTopic);
|
||||||
}
|
}
|
||||||
@ -697,11 +706,6 @@ export namespace WakuMessage {
|
|||||||
w.uint32(obj.version);
|
w.uint32(obj.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.timestampDeprecated != null) {
|
|
||||||
w.uint32(33);
|
|
||||||
w.double(obj.timestampDeprecated);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.timestamp != null) {
|
if (obj.timestamp != null) {
|
||||||
w.uint32(80);
|
w.uint32(80);
|
||||||
w.sint64(obj.timestamp);
|
w.sint64(obj.timestamp);
|
||||||
@ -722,7 +726,10 @@ export namespace WakuMessage {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
payload: new Uint8Array(0),
|
||||||
|
contentTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
@ -739,9 +746,6 @@ export namespace WakuMessage {
|
|||||||
case 3:
|
case 3:
|
||||||
obj.version = reader.uint32();
|
obj.version = reader.uint32();
|
||||||
break;
|
break;
|
||||||
case 4:
|
|
||||||
obj.timestampDeprecated = reader.double();
|
|
||||||
break;
|
|
||||||
case 10:
|
case 10:
|
||||||
obj.timestamp = reader.sint64();
|
obj.timestamp = reader.sint64();
|
||||||
break;
|
break;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
message TopicOnlyMessage {
|
message TopicOnlyMessage {
|
||||||
optional string content_topic = 2;
|
string content_topic = 2;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import type { Codec } from "protons-runtime";
|
|||||||
import type { Uint8ArrayList } from "uint8arraylist";
|
import type { Uint8ArrayList } from "uint8arraylist";
|
||||||
|
|
||||||
export interface TopicOnlyMessage {
|
export interface TopicOnlyMessage {
|
||||||
contentTopic?: string;
|
contentTopic: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace TopicOnlyMessage {
|
export namespace TopicOnlyMessage {
|
||||||
@ -23,7 +23,7 @@ export namespace TopicOnlyMessage {
|
|||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.contentTopic != null) {
|
if (obj.contentTopic != null && obj.contentTopic !== "") {
|
||||||
w.uint32(18);
|
w.uint32(18);
|
||||||
w.string(obj.contentTopic);
|
w.string(obj.contentTopic);
|
||||||
}
|
}
|
||||||
@ -33,7 +33,9 @@ export namespace TopicOnlyMessage {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
contentTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@
|
|||||||
"privacy"
|
"privacy"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "run-s build:**",
|
||||||
|
"build:esm": "tsc",
|
||||||
"fix": "run-s fix:*",
|
"fix": "run-s fix:*",
|
||||||
"fix:prettier": "prettier . --write",
|
"fix:prettier": "prettier . --write",
|
||||||
"fix:lint": "eslint src tests --ext .ts --ext .cjs --fix",
|
"fix:lint": "eslint src tests --ext .ts --ext .cjs --fix",
|
||||||
|
@ -192,10 +192,10 @@ describe("Waku Message Ephemeral field", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const normalMsg = messages.find(
|
const normalMsg = messages.find(
|
||||||
(msg) => bytesToUtf8(msg.payload!) === normalTxt
|
(msg) => bytesToUtf8(msg.payload) === normalTxt
|
||||||
);
|
);
|
||||||
const ephemeralMsg = messages.find(
|
const ephemeralMsg = messages.find(
|
||||||
(msg) => bytesToUtf8(msg.payload!) === ephemeralTxt
|
(msg) => bytesToUtf8(msg.payload) === ephemeralTxt
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(normalMsg).to.not.be.undefined;
|
expect(normalMsg).to.not.be.undefined;
|
||||||
@ -241,10 +241,10 @@ describe("Waku Message Ephemeral field", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const normalMsg = messages.find(
|
const normalMsg = messages.find(
|
||||||
(msg) => bytesToUtf8(msg.payload!) === normalTxt
|
(msg) => bytesToUtf8(msg.payload) === normalTxt
|
||||||
);
|
);
|
||||||
const ephemeralMsg = messages.find(
|
const ephemeralMsg = messages.find(
|
||||||
(msg) => bytesToUtf8(msg.payload!) === ephemeralTxt
|
(msg) => bytesToUtf8(msg.payload) === ephemeralTxt
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(normalMsg).to.not.be.undefined;
|
expect(normalMsg).to.not.be.undefined;
|
||||||
@ -291,10 +291,10 @@ describe("Waku Message Ephemeral field", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const normalMsg = messages.find(
|
const normalMsg = messages.find(
|
||||||
(msg) => bytesToUtf8(msg.payload!) === normalTxt
|
(msg) => bytesToUtf8(msg.payload) === normalTxt
|
||||||
);
|
);
|
||||||
const ephemeralMsg = messages.find(
|
const ephemeralMsg = messages.find(
|
||||||
(msg) => bytesToUtf8(msg.payload!) === ephemeralTxt
|
(msg) => bytesToUtf8(msg.payload) === ephemeralTxt
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(normalMsg).to.not.be.undefined;
|
expect(normalMsg).to.not.be.undefined;
|
||||||
|
@ -52,7 +52,7 @@ describe("Waku Filter", () => {
|
|||||||
log("Got a message");
|
log("Got a message");
|
||||||
messageCount++;
|
messageCount++;
|
||||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||||
expect(bytesToUtf8(msg.payload!)).to.eq(messageText);
|
expect(bytesToUtf8(msg.payload)).to.eq(messageText);
|
||||||
};
|
};
|
||||||
|
|
||||||
await waku.filter.subscribe([TestDecoder], callback);
|
await waku.filter.subscribe([TestDecoder], callback);
|
||||||
|
@ -106,6 +106,6 @@ describe("Waku Light Push [node only]", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(msgs[0].contentTopic).to.equal(TestContentTopic);
|
expect(msgs[0].contentTopic).to.equal(TestContentTopic);
|
||||||
expect(base64ToUtf8(msgs[0].payload!)).to.equal(messageText);
|
expect(base64ToUtf8(msgs[0].payload)).to.equal(messageText);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -130,7 +130,7 @@ describe("Waku Relay [node only]", () => {
|
|||||||
const receivedMsg = await receivedMsgPromise;
|
const receivedMsg = await receivedMsgPromise;
|
||||||
|
|
||||||
expect(receivedMsg.contentTopic).to.eq(TestContentTopic);
|
expect(receivedMsg.contentTopic).to.eq(TestContentTopic);
|
||||||
expect(bytesToUtf8(receivedMsg.payload!)).to.eq(messageText);
|
expect(bytesToUtf8(receivedMsg.payload)).to.eq(messageText);
|
||||||
expect(receivedMsg.timestamp?.valueOf()).to.eq(
|
expect(receivedMsg.timestamp?.valueOf()).to.eq(
|
||||||
messageTimestamp.valueOf()
|
messageTimestamp.valueOf()
|
||||||
);
|
);
|
||||||
@ -173,10 +173,10 @@ describe("Waku Relay [node only]", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(fooMessages[0].contentTopic).to.eq(fooContentTopic);
|
expect(fooMessages[0].contentTopic).to.eq(fooContentTopic);
|
||||||
expect(bytesToUtf8(fooMessages[0].payload!)).to.eq(fooMessageText);
|
expect(bytesToUtf8(fooMessages[0].payload)).to.eq(fooMessageText);
|
||||||
|
|
||||||
expect(barMessages[0].contentTopic).to.eq(barContentTopic);
|
expect(barMessages[0].contentTopic).to.eq(barContentTopic);
|
||||||
expect(bytesToUtf8(barMessages[0].payload!)).to.eq(barMessageText);
|
expect(bytesToUtf8(barMessages[0].payload)).to.eq(barMessageText);
|
||||||
|
|
||||||
expect(fooMessages.length).to.eq(1);
|
expect(fooMessages.length).to.eq(1);
|
||||||
expect(barMessages.length).to.eq(1);
|
expect(barMessages.length).to.eq(1);
|
||||||
|
@ -90,7 +90,7 @@ describe("Waku Store", () => {
|
|||||||
|
|
||||||
expect(messages?.length).eq(totalMsgs);
|
expect(messages?.length).eq(totalMsgs);
|
||||||
const result = messages?.findIndex((msg) => {
|
const result = messages?.findIndex((msg) => {
|
||||||
return msg.payload![0]! === 0;
|
return msg.payload[0]! === 0;
|
||||||
});
|
});
|
||||||
expect(result).to.not.eq(-1);
|
expect(result).to.not.eq(-1);
|
||||||
});
|
});
|
||||||
@ -173,8 +173,8 @@ describe("Waku Store", () => {
|
|||||||
|
|
||||||
expect(messages.length).be.eq(totalMsgs);
|
expect(messages.length).be.eq(totalMsgs);
|
||||||
|
|
||||||
expect(bytesToUtf8(testMessage.payload!)).to.be.eq(
|
expect(bytesToUtf8(testMessage.payload)).to.be.eq(
|
||||||
bytesToUtf8(messages[cursorIndex + 1].payload!)
|
bytesToUtf8(messages[cursorIndex + 1].payload)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ describe("Waku Store", () => {
|
|||||||
|
|
||||||
expect(messages?.length).eq(totalMsgs);
|
expect(messages?.length).eq(totalMsgs);
|
||||||
const result = messages?.findIndex((msg) => {
|
const result = messages?.findIndex((msg) => {
|
||||||
return msg.payload![0]! === 0;
|
return msg.payload[0]! === 0;
|
||||||
});
|
});
|
||||||
expect(result).to.not.eq(-1);
|
expect(result).to.not.eq(-1);
|
||||||
});
|
});
|
||||||
@ -294,7 +294,7 @@ describe("Waku Store", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(messages?.length).eq(totalMsgs);
|
expect(messages?.length).eq(totalMsgs);
|
||||||
const payloads = messages.map((msg) => msg.payload![0]!);
|
const payloads = messages.map((msg) => msg.payload[0]!);
|
||||||
expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys()));
|
expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ describe("Decryption Keys", () => {
|
|||||||
const receivedMsg = await receivedMsgPromise;
|
const receivedMsg = await receivedMsgPromise;
|
||||||
|
|
||||||
expect(receivedMsg.contentTopic).to.eq(TestContentTopic);
|
expect(receivedMsg.contentTopic).to.eq(TestContentTopic);
|
||||||
expect(bytesToUtf8(receivedMsg.payload!)).to.eq(messageText);
|
expect(bytesToUtf8(receivedMsg.payload)).to.eq(messageText);
|
||||||
expect(receivedMsg.timestamp?.valueOf()).to.eq(messageTimestamp.valueOf());
|
expect(receivedMsg.timestamp?.valueOf()).to.eq(messageTimestamp.valueOf());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user