diff --git a/packages/core/src/lib/light_push/push_rpc.ts b/packages/core/src/lib/light_push/push_rpc.ts index 23a928f374..3d4621d236 100644 --- a/packages/core/src/lib/light_push/push_rpc.ts +++ b/packages/core/src/lib/light_push/push_rpc.ts @@ -3,7 +3,7 @@ import type { Uint8ArrayList } from "uint8arraylist"; import { v4 as uuid } from "uuid"; export class PushRPC { - public constructor(public proto: proto.PushRPC) {} + public constructor(public proto: proto.PushRpc) {} static createRequest( message: proto.WakuMessage, @@ -13,19 +13,19 @@ export class PushRPC { requestId: uuid(), request: { message: message, - pubSubTopic: pubSubTopic, + pubsubTopic: pubSubTopic, }, response: undefined, }); } static decode(bytes: Uint8ArrayList): PushRPC { - const res = proto.PushRPC.decode(bytes); + const res = proto.PushRpc.decode(bytes); return new PushRPC(res); } encode(): Uint8Array { - return proto.PushRPC.encode(this.proto); + return proto.PushRpc.encode(this.proto); } get query(): proto.PushRequest | undefined { diff --git a/packages/proto/src/lib/light_push.proto b/packages/proto/src/lib/light_push.proto index d1954b6f6b..26e121ae42 100644 --- a/packages/proto/src/lib/light_push.proto +++ b/packages/proto/src/lib/light_push.proto @@ -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"; import "message.proto"; message PushRequest { - optional string pub_sub_topic = 1; - optional WakuMessage message = 2; + string pubsub_topic = 1; + WakuMessage message = 2; } message PushResponse { - optional bool is_success = 1; + bool is_success = 1; optional string info = 2; } -message PushRPC { - optional string request_id = 1; +message PushRpc { + string request_id = 1; optional PushRequest request = 2; optional PushResponse response = 3; } diff --git a/packages/proto/src/lib/light_push.ts b/packages/proto/src/lib/light_push.ts index 95f61ffbeb..3cb500240c 100644 --- a/packages/proto/src/lib/light_push.ts +++ b/packages/proto/src/lib/light_push.ts @@ -9,7 +9,7 @@ import type { Codec } from "protons-runtime"; import type { Uint8ArrayList } from "uint8arraylist"; export interface PushRequest { - pubSubTopic?: string; + pubsubTopic: string; message?: WakuMessage; } @@ -24,9 +24,9 @@ export namespace PushRequest { w.fork(); } - if (obj.pubSubTopic != null) { + if (obj.pubsubTopic != null && obj.pubsubTopic !== "") { w.uint32(10); - w.string(obj.pubSubTopic); + w.string(obj.pubsubTopic); } if (obj.message != null) { @@ -39,7 +39,9 @@ export namespace PushRequest { } }, (reader, length) => { - const obj: any = {}; + const obj: any = { + pubsubTopic: "", + }; const end = length == null ? reader.len : reader.pos + length; @@ -48,7 +50,7 @@ export namespace PushRequest { switch (tag >>> 3) { case 1: - obj.pubSubTopic = reader.string(); + obj.pubsubTopic = reader.string(); break; case 2: obj.message = WakuMessage.codec().decode( @@ -80,7 +82,7 @@ export namespace PushRequest { } export interface PushResponse { - isSuccess?: boolean; + isSuccess: boolean; info?: string; } @@ -95,7 +97,7 @@ export namespace PushResponse { w.fork(); } - if (obj.isSuccess != null) { + if (obj.isSuccess != null && obj.isSuccess !== false) { w.uint32(8); w.bool(obj.isSuccess); } @@ -110,7 +112,9 @@ export namespace PushResponse { } }, (reader, length) => { - const obj: any = {}; + const obj: any = { + isSuccess: false, + }; const end = length == null ? reader.len : reader.pos + length; @@ -147,24 +151,24 @@ export namespace PushResponse { }; } -export interface PushRPC { - requestId?: string; +export interface PushRpc { + requestId: string; request?: PushRequest; response?: PushResponse; } -export namespace PushRPC { - let _codec: Codec; +export namespace PushRpc { + let _codec: Codec; - export const codec = (): Codec => { + export const codec = (): Codec => { if (_codec == null) { - _codec = message( + _codec = message( (obj, w, opts = {}) => { if (opts.lengthDelimited !== false) { w.fork(); } - if (obj.requestId != null) { + if (obj.requestId != null && obj.requestId !== "") { w.uint32(10); w.string(obj.requestId); } @@ -184,7 +188,9 @@ export namespace PushRPC { } }, (reader, length) => { - const obj: any = {}; + const obj: any = { + requestId: "", + }; const end = length == null ? reader.len : reader.pos + length; @@ -221,12 +227,12 @@ export namespace PushRPC { return _codec; }; - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, PushRPC.codec()); + export const encode = (obj: Partial): Uint8Array => { + return encodeMessage(obj, PushRpc.codec()); }; - export const decode = (buf: Uint8Array | Uint8ArrayList): PushRPC => { - return decodeMessage(buf, PushRPC.codec()); + export const decode = (buf: Uint8Array | Uint8ArrayList): PushRpc => { + return decodeMessage(buf, PushRpc.codec()); }; }