@xmtp/proto
Version:
Protobuf client and generated classes for GRPC API
592 lines (591 loc) • 21.7 kB
JavaScript
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.181.2
// protoc v3.21.12
// source: message_contents/message.proto
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { Ciphertext } from "./ciphertext.pb";
import { ConversationReference } from "./conversation_reference.pb";
import { PublicKeyBundle } from "./public_key.pb";
export const protobufPackage = "xmtp.message_contents";
function createBaseMessageHeaderV1() {
return { sender: undefined, recipient: undefined, timestamp: Long.UZERO };
}
export const MessageHeaderV1 = {
encode(message, writer = _m0.Writer.create()) {
if (message.sender !== undefined) {
PublicKeyBundle.encode(message.sender, writer.uint32(10).fork()).ldelim();
}
if (message.recipient !== undefined) {
PublicKeyBundle.encode(message.recipient, writer.uint32(18).fork()).ldelim();
}
if (!message.timestamp.equals(Long.UZERO)) {
writer.uint32(24).uint64(message.timestamp);
}
return writer;
},
decode(input, length) {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMessageHeaderV1();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}
message.sender = PublicKeyBundle.decode(reader, reader.uint32());
continue;
case 2:
if (tag !== 18) {
break;
}
message.recipient = PublicKeyBundle.decode(reader, reader.uint32());
continue;
case 3:
if (tag !== 24) {
break;
}
message.timestamp = reader.uint64();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object) {
return {
sender: isSet(object.sender) ? PublicKeyBundle.fromJSON(object.sender) : undefined,
recipient: isSet(object.recipient) ? PublicKeyBundle.fromJSON(object.recipient) : undefined,
timestamp: isSet(object.timestamp) ? Long.fromValue(object.timestamp) : Long.UZERO,
};
},
toJSON(message) {
const obj = {};
if (message.sender !== undefined) {
obj.sender = PublicKeyBundle.toJSON(message.sender);
}
if (message.recipient !== undefined) {
obj.recipient = PublicKeyBundle.toJSON(message.recipient);
}
if (!message.timestamp.equals(Long.UZERO)) {
obj.timestamp = (message.timestamp || Long.UZERO).toString();
}
return obj;
},
create(base) {
return MessageHeaderV1.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBaseMessageHeaderV1();
message.sender = (object.sender !== undefined && object.sender !== null)
? PublicKeyBundle.fromPartial(object.sender)
: undefined;
message.recipient = (object.recipient !== undefined && object.recipient !== null)
? PublicKeyBundle.fromPartial(object.recipient)
: undefined;
message.timestamp = (object.timestamp !== undefined && object.timestamp !== null)
? Long.fromValue(object.timestamp)
: Long.UZERO;
return message;
},
};
function createBaseMessageV1() {
return { headerBytes: new Uint8Array(0), ciphertext: undefined };
}
export const MessageV1 = {
encode(message, writer = _m0.Writer.create()) {
if (message.headerBytes.length !== 0) {
writer.uint32(10).bytes(message.headerBytes);
}
if (message.ciphertext !== undefined) {
Ciphertext.encode(message.ciphertext, writer.uint32(18).fork()).ldelim();
}
return writer;
},
decode(input, length) {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMessageV1();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}
message.headerBytes = reader.bytes();
continue;
case 2:
if (tag !== 18) {
break;
}
message.ciphertext = Ciphertext.decode(reader, reader.uint32());
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object) {
return {
headerBytes: isSet(object.headerBytes) ? bytesFromBase64(object.headerBytes) : new Uint8Array(0),
ciphertext: isSet(object.ciphertext) ? Ciphertext.fromJSON(object.ciphertext) : undefined,
};
},
toJSON(message) {
const obj = {};
if (message.headerBytes.length !== 0) {
obj.headerBytes = base64FromBytes(message.headerBytes);
}
if (message.ciphertext !== undefined) {
obj.ciphertext = Ciphertext.toJSON(message.ciphertext);
}
return obj;
},
create(base) {
return MessageV1.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBaseMessageV1();
message.headerBytes = object.headerBytes ?? new Uint8Array(0);
message.ciphertext = (object.ciphertext !== undefined && object.ciphertext !== null)
? Ciphertext.fromPartial(object.ciphertext)
: undefined;
return message;
},
};
function createBaseMessageHeaderV2() {
return { createdNs: Long.UZERO, topic: "" };
}
export const MessageHeaderV2 = {
encode(message, writer = _m0.Writer.create()) {
if (!message.createdNs.equals(Long.UZERO)) {
writer.uint32(8).uint64(message.createdNs);
}
if (message.topic !== "") {
writer.uint32(18).string(message.topic);
}
return writer;
},
decode(input, length) {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMessageHeaderV2();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 8) {
break;
}
message.createdNs = reader.uint64();
continue;
case 2:
if (tag !== 18) {
break;
}
message.topic = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object) {
return {
createdNs: isSet(object.createdNs) ? Long.fromValue(object.createdNs) : Long.UZERO,
topic: isSet(object.topic) ? globalThis.String(object.topic) : "",
};
},
toJSON(message) {
const obj = {};
if (!message.createdNs.equals(Long.UZERO)) {
obj.createdNs = (message.createdNs || Long.UZERO).toString();
}
if (message.topic !== "") {
obj.topic = message.topic;
}
return obj;
},
create(base) {
return MessageHeaderV2.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBaseMessageHeaderV2();
message.createdNs = (object.createdNs !== undefined && object.createdNs !== null)
? Long.fromValue(object.createdNs)
: Long.UZERO;
message.topic = object.topic ?? "";
return message;
},
};
function createBaseMessageV2() {
return { headerBytes: new Uint8Array(0), ciphertext: undefined, senderHmac: undefined, shouldPush: undefined };
}
export const MessageV2 = {
encode(message, writer = _m0.Writer.create()) {
if (message.headerBytes.length !== 0) {
writer.uint32(10).bytes(message.headerBytes);
}
if (message.ciphertext !== undefined) {
Ciphertext.encode(message.ciphertext, writer.uint32(18).fork()).ldelim();
}
if (message.senderHmac !== undefined) {
writer.uint32(26).bytes(message.senderHmac);
}
if (message.shouldPush !== undefined) {
writer.uint32(32).bool(message.shouldPush);
}
return writer;
},
decode(input, length) {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMessageV2();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}
message.headerBytes = reader.bytes();
continue;
case 2:
if (tag !== 18) {
break;
}
message.ciphertext = Ciphertext.decode(reader, reader.uint32());
continue;
case 3:
if (tag !== 26) {
break;
}
message.senderHmac = reader.bytes();
continue;
case 4:
if (tag !== 32) {
break;
}
message.shouldPush = reader.bool();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object) {
return {
headerBytes: isSet(object.headerBytes) ? bytesFromBase64(object.headerBytes) : new Uint8Array(0),
ciphertext: isSet(object.ciphertext) ? Ciphertext.fromJSON(object.ciphertext) : undefined,
senderHmac: isSet(object.senderHmac) ? bytesFromBase64(object.senderHmac) : undefined,
shouldPush: isSet(object.shouldPush) ? globalThis.Boolean(object.shouldPush) : undefined,
};
},
toJSON(message) {
const obj = {};
if (message.headerBytes.length !== 0) {
obj.headerBytes = base64FromBytes(message.headerBytes);
}
if (message.ciphertext !== undefined) {
obj.ciphertext = Ciphertext.toJSON(message.ciphertext);
}
if (message.senderHmac !== undefined) {
obj.senderHmac = base64FromBytes(message.senderHmac);
}
if (message.shouldPush !== undefined) {
obj.shouldPush = message.shouldPush;
}
return obj;
},
create(base) {
return MessageV2.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBaseMessageV2();
message.headerBytes = object.headerBytes ?? new Uint8Array(0);
message.ciphertext = (object.ciphertext !== undefined && object.ciphertext !== null)
? Ciphertext.fromPartial(object.ciphertext)
: undefined;
message.senderHmac = object.senderHmac ?? undefined;
message.shouldPush = object.shouldPush ?? undefined;
return message;
},
};
function createBaseMessage() {
return { v1: undefined, v2: undefined };
}
export const Message = {
encode(message, writer = _m0.Writer.create()) {
if (message.v1 !== undefined) {
MessageV1.encode(message.v1, writer.uint32(10).fork()).ldelim();
}
if (message.v2 !== undefined) {
MessageV2.encode(message.v2, writer.uint32(18).fork()).ldelim();
}
return writer;
},
decode(input, length) {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMessage();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}
message.v1 = MessageV1.decode(reader, reader.uint32());
continue;
case 2:
if (tag !== 18) {
break;
}
message.v2 = MessageV2.decode(reader, reader.uint32());
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object) {
return {
v1: isSet(object.v1) ? MessageV1.fromJSON(object.v1) : undefined,
v2: isSet(object.v2) ? MessageV2.fromJSON(object.v2) : undefined,
};
},
toJSON(message) {
const obj = {};
if (message.v1 !== undefined) {
obj.v1 = MessageV1.toJSON(message.v1);
}
if (message.v2 !== undefined) {
obj.v2 = MessageV2.toJSON(message.v2);
}
return obj;
},
create(base) {
return Message.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBaseMessage();
message.v1 = (object.v1 !== undefined && object.v1 !== null) ? MessageV1.fromPartial(object.v1) : undefined;
message.v2 = (object.v2 !== undefined && object.v2 !== null) ? MessageV2.fromPartial(object.v2) : undefined;
return message;
},
};
function createBaseDecodedMessage() {
return {
id: "",
messageVersion: "",
senderAddress: "",
recipientAddress: undefined,
sentNs: Long.UZERO,
contentTopic: "",
conversation: undefined,
contentBytes: new Uint8Array(0),
};
}
export const DecodedMessage = {
encode(message, writer = _m0.Writer.create()) {
if (message.id !== "") {
writer.uint32(10).string(message.id);
}
if (message.messageVersion !== "") {
writer.uint32(18).string(message.messageVersion);
}
if (message.senderAddress !== "") {
writer.uint32(26).string(message.senderAddress);
}
if (message.recipientAddress !== undefined) {
writer.uint32(34).string(message.recipientAddress);
}
if (!message.sentNs.equals(Long.UZERO)) {
writer.uint32(40).uint64(message.sentNs);
}
if (message.contentTopic !== "") {
writer.uint32(50).string(message.contentTopic);
}
if (message.conversation !== undefined) {
ConversationReference.encode(message.conversation, writer.uint32(58).fork()).ldelim();
}
if (message.contentBytes.length !== 0) {
writer.uint32(66).bytes(message.contentBytes);
}
return writer;
},
decode(input, length) {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseDecodedMessage();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}
message.id = reader.string();
continue;
case 2:
if (tag !== 18) {
break;
}
message.messageVersion = reader.string();
continue;
case 3:
if (tag !== 26) {
break;
}
message.senderAddress = reader.string();
continue;
case 4:
if (tag !== 34) {
break;
}
message.recipientAddress = reader.string();
continue;
case 5:
if (tag !== 40) {
break;
}
message.sentNs = reader.uint64();
continue;
case 6:
if (tag !== 50) {
break;
}
message.contentTopic = reader.string();
continue;
case 7:
if (tag !== 58) {
break;
}
message.conversation = ConversationReference.decode(reader, reader.uint32());
continue;
case 8:
if (tag !== 66) {
break;
}
message.contentBytes = reader.bytes();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object) {
return {
id: isSet(object.id) ? globalThis.String(object.id) : "",
messageVersion: isSet(object.messageVersion) ? globalThis.String(object.messageVersion) : "",
senderAddress: isSet(object.senderAddress) ? globalThis.String(object.senderAddress) : "",
recipientAddress: isSet(object.recipientAddress) ? globalThis.String(object.recipientAddress) : undefined,
sentNs: isSet(object.sentNs) ? Long.fromValue(object.sentNs) : Long.UZERO,
contentTopic: isSet(object.contentTopic) ? globalThis.String(object.contentTopic) : "",
conversation: isSet(object.conversation) ? ConversationReference.fromJSON(object.conversation) : undefined,
contentBytes: isSet(object.contentBytes) ? bytesFromBase64(object.contentBytes) : new Uint8Array(0),
};
},
toJSON(message) {
const obj = {};
if (message.id !== "") {
obj.id = message.id;
}
if (message.messageVersion !== "") {
obj.messageVersion = message.messageVersion;
}
if (message.senderAddress !== "") {
obj.senderAddress = message.senderAddress;
}
if (message.recipientAddress !== undefined) {
obj.recipientAddress = message.recipientAddress;
}
if (!message.sentNs.equals(Long.UZERO)) {
obj.sentNs = (message.sentNs || Long.UZERO).toString();
}
if (message.contentTopic !== "") {
obj.contentTopic = message.contentTopic;
}
if (message.conversation !== undefined) {
obj.conversation = ConversationReference.toJSON(message.conversation);
}
if (message.contentBytes.length !== 0) {
obj.contentBytes = base64FromBytes(message.contentBytes);
}
return obj;
},
create(base) {
return DecodedMessage.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBaseDecodedMessage();
message.id = object.id ?? "";
message.messageVersion = object.messageVersion ?? "";
message.senderAddress = object.senderAddress ?? "";
message.recipientAddress = object.recipientAddress ?? undefined;
message.sentNs = (object.sentNs !== undefined && object.sentNs !== null)
? Long.fromValue(object.sentNs)
: Long.UZERO;
message.contentTopic = object.contentTopic ?? "";
message.conversation = (object.conversation !== undefined && object.conversation !== null)
? ConversationReference.fromPartial(object.conversation)
: undefined;
message.contentBytes = object.contentBytes ?? new Uint8Array(0);
return message;
},
};
function bytesFromBase64(b64) {
if (globalThis.Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
}
else {
const bin = globalThis.atob(b64);
const arr = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; ++i) {
arr[i] = bin.charCodeAt(i);
}
return arr;
}
}
function base64FromBytes(arr) {
if (globalThis.Buffer) {
return globalThis.Buffer.from(arr).toString("base64");
}
else {
const bin = [];
arr.forEach((byte) => {
bin.push(globalThis.String.fromCharCode(byte));
});
return globalThis.btoa(bin.join(""));
}
}
if (_m0.util.Long !== Long) {
_m0.util.Long = Long;
_m0.configure();
}
function isSet(value) {
return value !== null && value !== undefined;
}