UNPKG

@xmtp/proto

Version:

Protobuf client and generated classes for GRPC API

323 lines 13.6 kB
"use strict"; 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.commitResultToJSON = exports.commitResultFromJSON = exports.CommitResult = exports.protobufPackage = void 0; /* eslint-disable */ const long_1 = __importDefault(require("long")); const signature_pb_1 = require("../../identity/associations/signature.pb"); const minimal_1 = __importDefault(require("protobufjs/minimal")); 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 || (exports.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; } } exports.commitResultFromJSON = commitResultFromJSON; 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"; } } exports.commitResultToJSON = commitResultToJSON; function createBasePlaintextCommitLogEntry() { return { groupId: new Uint8Array(), commitSequenceId: long_1.default.UZERO, lastEpochAuthenticator: new Uint8Array(), commitResult: 0, appliedEpochNumber: long_1.default.UZERO, appliedEpochAuthenticator: new Uint8Array(), }; } exports.PlaintextCommitLogEntry = { encode(message, writer = minimal_1.default.Writer.create()) { if (message.groupId.length !== 0) { writer.uint32(10).bytes(message.groupId); } if (!message.commitSequenceId.isZero()) { 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.isZero()) { 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 : new minimal_1.default.Reader(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: message.groupId = reader.bytes(); break; case 2: message.commitSequenceId = reader.uint64(); break; case 3: message.lastEpochAuthenticator = reader.bytes(); break; case 4: message.commitResult = reader.int32(); break; case 5: message.appliedEpochNumber = reader.uint64(); break; case 6: message.appliedEpochAuthenticator = reader.bytes(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromJSON(object) { return { groupId: isSet(object.groupId) ? bytesFromBase64(object.groupId) : new Uint8Array(), commitSequenceId: isSet(object.commitSequenceId) ? long_1.default.fromValue(object.commitSequenceId) : long_1.default.UZERO, lastEpochAuthenticator: isSet(object.lastEpochAuthenticator) ? bytesFromBase64(object.lastEpochAuthenticator) : new Uint8Array(), 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(), }; }, toJSON(message) { const obj = {}; message.groupId !== undefined && (obj.groupId = base64FromBytes(message.groupId !== undefined ? message.groupId : new Uint8Array())); message.commitSequenceId !== undefined && (obj.commitSequenceId = (message.commitSequenceId || long_1.default.UZERO).toString()); message.lastEpochAuthenticator !== undefined && (obj.lastEpochAuthenticator = base64FromBytes(message.lastEpochAuthenticator !== undefined ? message.lastEpochAuthenticator : new Uint8Array())); message.commitResult !== undefined && (obj.commitResult = commitResultToJSON(message.commitResult)); message.appliedEpochNumber !== undefined && (obj.appliedEpochNumber = (message.appliedEpochNumber || long_1.default.UZERO).toString()); message.appliedEpochAuthenticator !== undefined && (obj.appliedEpochAuthenticator = base64FromBytes(message.appliedEpochAuthenticator !== undefined ? message.appliedEpochAuthenticator : new Uint8Array())); return obj; }, fromPartial(object) { var _a, _b, _c, _d; const message = createBasePlaintextCommitLogEntry(); message.groupId = (_a = object.groupId) !== null && _a !== void 0 ? _a : new Uint8Array(); message.commitSequenceId = object.commitSequenceId !== undefined && object.commitSequenceId !== null ? long_1.default.fromValue(object.commitSequenceId) : long_1.default.UZERO; message.lastEpochAuthenticator = (_b = object.lastEpochAuthenticator) !== null && _b !== void 0 ? _b : new Uint8Array(); message.commitResult = (_c = object.commitResult) !== null && _c !== void 0 ? _c : 0; message.appliedEpochNumber = object.appliedEpochNumber !== undefined && object.appliedEpochNumber !== null ? long_1.default.fromValue(object.appliedEpochNumber) : long_1.default.UZERO; message.appliedEpochAuthenticator = (_d = object.appliedEpochAuthenticator) !== null && _d !== void 0 ? _d : new Uint8Array(); return message; }, }; function createBaseCommitLogEntry() { return { sequenceId: long_1.default.UZERO, serializedCommitLogEntry: new Uint8Array(), signature: undefined, }; } exports.CommitLogEntry = { encode(message, writer = minimal_1.default.Writer.create()) { if (!message.sequenceId.isZero()) { 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 : new minimal_1.default.Reader(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: message.sequenceId = reader.uint64(); break; case 2: message.serializedCommitLogEntry = reader.bytes(); break; case 3: message.signature = signature_pb_1.RecoverableEd25519Signature.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); break; } } 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(), signature: isSet(object.signature) ? signature_pb_1.RecoverableEd25519Signature.fromJSON(object.signature) : undefined, }; }, toJSON(message) { const obj = {}; message.sequenceId !== undefined && (obj.sequenceId = (message.sequenceId || long_1.default.UZERO).toString()); message.serializedCommitLogEntry !== undefined && (obj.serializedCommitLogEntry = base64FromBytes(message.serializedCommitLogEntry !== undefined ? message.serializedCommitLogEntry : new Uint8Array())); message.signature !== undefined && (obj.signature = message.signature ? signature_pb_1.RecoverableEd25519Signature.toJSON(message.signature) : undefined); return obj; }, fromPartial(object) { var _a; const message = createBaseCommitLogEntry(); message.sequenceId = object.sequenceId !== undefined && object.sequenceId !== null ? long_1.default.fromValue(object.sequenceId) : long_1.default.UZERO; message.serializedCommitLogEntry = (_a = object.serializedCommitLogEntry) !== null && _a !== void 0 ? _a : new Uint8Array(); message.signature = object.signature !== undefined && object.signature !== null ? signature_pb_1.RecoverableEd25519Signature.fromPartial(object.signature) : undefined; return message; }, }; var globalThis = (() => { if (typeof globalThis !== "undefined") return globalThis; if (typeof self !== "undefined") return self; if (typeof window !== "undefined") return window; if (typeof global !== "undefined") return global; throw "Unable to locate global object"; })(); 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(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; } //# sourceMappingURL=commit_log.pb.js.map