@xmtp/proto
Version:
Protobuf client and generated classes for GRPC API
327 lines (326 loc) • 13.6 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: mls/message_contents/commit_log.proto
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommitLogEntry = exports.PlaintextCommitLogEntry = exports.CommitResult = exports.protobufPackage = void 0;
exports.commitResultFromJSON = commitResultFromJSON;
exports.commitResultToJSON = commitResultToJSON;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const signature_pb_1 = require("../../identity/associations/signature.pb");
exports.protobufPackage = "xmtp.mls.message_contents";
/**
* Defines entries on the commit log, used for fork detection and recovery
* XIP: https://community.xmtp.org/t/xip-68-draft-automated-fork-recovery/951
*/
var CommitResult;
(function (CommitResult) {
CommitResult[CommitResult["COMMIT_RESULT_UNSPECIFIED"] = 0] = "COMMIT_RESULT_UNSPECIFIED";
CommitResult[CommitResult["COMMIT_RESULT_APPLIED"] = 1] = "COMMIT_RESULT_APPLIED";
CommitResult[CommitResult["COMMIT_RESULT_WRONG_EPOCH"] = 2] = "COMMIT_RESULT_WRONG_EPOCH";
CommitResult[CommitResult["COMMIT_RESULT_UNDECRYPTABLE"] = 3] = "COMMIT_RESULT_UNDECRYPTABLE";
CommitResult[CommitResult["COMMIT_RESULT_INVALID"] = 4] = "COMMIT_RESULT_INVALID";
CommitResult[CommitResult["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(CommitResult || (exports.CommitResult = CommitResult = {}));
function commitResultFromJSON(object) {
switch (object) {
case 0:
case "COMMIT_RESULT_UNSPECIFIED":
return CommitResult.COMMIT_RESULT_UNSPECIFIED;
case 1:
case "COMMIT_RESULT_APPLIED":
return CommitResult.COMMIT_RESULT_APPLIED;
case 2:
case "COMMIT_RESULT_WRONG_EPOCH":
return CommitResult.COMMIT_RESULT_WRONG_EPOCH;
case 3:
case "COMMIT_RESULT_UNDECRYPTABLE":
return CommitResult.COMMIT_RESULT_UNDECRYPTABLE;
case 4:
case "COMMIT_RESULT_INVALID":
return CommitResult.COMMIT_RESULT_INVALID;
case -1:
case "UNRECOGNIZED":
default:
return CommitResult.UNRECOGNIZED;
}
}
function commitResultToJSON(object) {
switch (object) {
case CommitResult.COMMIT_RESULT_UNSPECIFIED:
return "COMMIT_RESULT_UNSPECIFIED";
case CommitResult.COMMIT_RESULT_APPLIED:
return "COMMIT_RESULT_APPLIED";
case CommitResult.COMMIT_RESULT_WRONG_EPOCH:
return "COMMIT_RESULT_WRONG_EPOCH";
case CommitResult.COMMIT_RESULT_UNDECRYPTABLE:
return "COMMIT_RESULT_UNDECRYPTABLE";
case CommitResult.COMMIT_RESULT_INVALID:
return "COMMIT_RESULT_INVALID";
case CommitResult.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
}
}
function createBasePlaintextCommitLogEntry() {
return {
groupId: new Uint8Array(0),
commitSequenceId: long_1.default.UZERO,
lastEpochAuthenticator: new Uint8Array(0),
commitResult: 0,
appliedEpochNumber: long_1.default.UZERO,
appliedEpochAuthenticator: new Uint8Array(0),
};
}
exports.PlaintextCommitLogEntry = {
encode(message, writer = minimal_1.default.Writer.create()) {
if (message.groupId.length !== 0) {
writer.uint32(10).bytes(message.groupId);
}
if (!message.commitSequenceId.equals(long_1.default.UZERO)) {
writer.uint32(16).uint64(message.commitSequenceId);
}
if (message.lastEpochAuthenticator.length !== 0) {
writer.uint32(26).bytes(message.lastEpochAuthenticator);
}
if (message.commitResult !== 0) {
writer.uint32(32).int32(message.commitResult);
}
if (!message.appliedEpochNumber.equals(long_1.default.UZERO)) {
writer.uint32(40).uint64(message.appliedEpochNumber);
}
if (message.appliedEpochAuthenticator.length !== 0) {
writer.uint32(50).bytes(message.appliedEpochAuthenticator);
}
return writer;
},
decode(input, length) {
const reader = input instanceof minimal_1.default.Reader ? input : minimal_1.default.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePlaintextCommitLogEntry();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}
message.groupId = reader.bytes();
continue;
case 2:
if (tag !== 16) {
break;
}
message.commitSequenceId = reader.uint64();
continue;
case 3:
if (tag !== 26) {
break;
}
message.lastEpochAuthenticator = reader.bytes();
continue;
case 4:
if (tag !== 32) {
break;
}
message.commitResult = reader.int32();
continue;
case 5:
if (tag !== 40) {
break;
}
message.appliedEpochNumber = reader.uint64();
continue;
case 6:
if (tag !== 50) {
break;
}
message.appliedEpochAuthenticator = reader.bytes();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object) {
return {
groupId: isSet(object.groupId) ? bytesFromBase64(object.groupId) : new Uint8Array(0),
commitSequenceId: isSet(object.commitSequenceId) ? long_1.default.fromValue(object.commitSequenceId) : long_1.default.UZERO,
lastEpochAuthenticator: isSet(object.lastEpochAuthenticator)
? bytesFromBase64(object.lastEpochAuthenticator)
: new Uint8Array(0),
commitResult: isSet(object.commitResult) ? commitResultFromJSON(object.commitResult) : 0,
appliedEpochNumber: isSet(object.appliedEpochNumber) ? long_1.default.fromValue(object.appliedEpochNumber) : long_1.default.UZERO,
appliedEpochAuthenticator: isSet(object.appliedEpochAuthenticator)
? bytesFromBase64(object.appliedEpochAuthenticator)
: new Uint8Array(0),
};
},
toJSON(message) {
const obj = {};
if (message.groupId.length !== 0) {
obj.groupId = base64FromBytes(message.groupId);
}
if (!message.commitSequenceId.equals(long_1.default.UZERO)) {
obj.commitSequenceId = (message.commitSequenceId || long_1.default.UZERO).toString();
}
if (message.lastEpochAuthenticator.length !== 0) {
obj.lastEpochAuthenticator = base64FromBytes(message.lastEpochAuthenticator);
}
if (message.commitResult !== 0) {
obj.commitResult = commitResultToJSON(message.commitResult);
}
if (!message.appliedEpochNumber.equals(long_1.default.UZERO)) {
obj.appliedEpochNumber = (message.appliedEpochNumber || long_1.default.UZERO).toString();
}
if (message.appliedEpochAuthenticator.length !== 0) {
obj.appliedEpochAuthenticator = base64FromBytes(message.appliedEpochAuthenticator);
}
return obj;
},
create(base) {
return exports.PlaintextCommitLogEntry.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBasePlaintextCommitLogEntry();
message.groupId = object.groupId ?? new Uint8Array(0);
message.commitSequenceId = (object.commitSequenceId !== undefined && object.commitSequenceId !== null)
? long_1.default.fromValue(object.commitSequenceId)
: long_1.default.UZERO;
message.lastEpochAuthenticator = object.lastEpochAuthenticator ?? new Uint8Array(0);
message.commitResult = object.commitResult ?? 0;
message.appliedEpochNumber = (object.appliedEpochNumber !== undefined && object.appliedEpochNumber !== null)
? long_1.default.fromValue(object.appliedEpochNumber)
: long_1.default.UZERO;
message.appliedEpochAuthenticator = object.appliedEpochAuthenticator ?? new Uint8Array(0);
return message;
},
};
function createBaseCommitLogEntry() {
return { sequenceId: long_1.default.UZERO, serializedCommitLogEntry: new Uint8Array(0), signature: undefined };
}
exports.CommitLogEntry = {
encode(message, writer = minimal_1.default.Writer.create()) {
if (!message.sequenceId.equals(long_1.default.UZERO)) {
writer.uint32(8).uint64(message.sequenceId);
}
if (message.serializedCommitLogEntry.length !== 0) {
writer.uint32(18).bytes(message.serializedCommitLogEntry);
}
if (message.signature !== undefined) {
signature_pb_1.RecoverableEd25519Signature.encode(message.signature, writer.uint32(26).fork()).ldelim();
}
return writer;
},
decode(input, length) {
const reader = input instanceof minimal_1.default.Reader ? input : minimal_1.default.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseCommitLogEntry();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 8) {
break;
}
message.sequenceId = reader.uint64();
continue;
case 2:
if (tag !== 18) {
break;
}
message.serializedCommitLogEntry = reader.bytes();
continue;
case 3:
if (tag !== 26) {
break;
}
message.signature = signature_pb_1.RecoverableEd25519Signature.decode(reader, reader.uint32());
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object) {
return {
sequenceId: isSet(object.sequenceId) ? long_1.default.fromValue(object.sequenceId) : long_1.default.UZERO,
serializedCommitLogEntry: isSet(object.serializedCommitLogEntry)
? bytesFromBase64(object.serializedCommitLogEntry)
: new Uint8Array(0),
signature: isSet(object.signature) ? signature_pb_1.RecoverableEd25519Signature.fromJSON(object.signature) : undefined,
};
},
toJSON(message) {
const obj = {};
if (!message.sequenceId.equals(long_1.default.UZERO)) {
obj.sequenceId = (message.sequenceId || long_1.default.UZERO).toString();
}
if (message.serializedCommitLogEntry.length !== 0) {
obj.serializedCommitLogEntry = base64FromBytes(message.serializedCommitLogEntry);
}
if (message.signature !== undefined) {
obj.signature = signature_pb_1.RecoverableEd25519Signature.toJSON(message.signature);
}
return obj;
},
create(base) {
return exports.CommitLogEntry.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBaseCommitLogEntry();
message.sequenceId = (object.sequenceId !== undefined && object.sequenceId !== null)
? long_1.default.fromValue(object.sequenceId)
: long_1.default.UZERO;
message.serializedCommitLogEntry = object.serializedCommitLogEntry ?? new Uint8Array(0);
message.signature = (object.signature !== undefined && object.signature !== null)
? signature_pb_1.RecoverableEd25519Signature.fromPartial(object.signature)
: undefined;
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 (minimal_1.default.util.Long !== long_1.default) {
minimal_1.default.util.Long = long_1.default;
minimal_1.default.configure();
}
function isSet(value) {
return value !== null && value !== undefined;
}