Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device sync backups #239

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
25 changes: 25 additions & 0 deletions proto/device_sync/consent_backup.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package xmtp.device_sync.consent_backup;

// Proto representation of a consent record save
message ConsentSave {
ConsentTypeSave entity_type = 1;
ConsentStateSave state = 2;
string entity = 3;
}

// Consent record type
enum ConsentTypeSave {
CONSENT_TYPE_SAVE_UNSPECIFIED = 0;
CONSENT_TYPE_SAVE_CONVERSATION_ID = 1;
CONSENT_TYPE_SAVE_INBOX_ID = 2;
CONSENT_TYPE_SAVE_ADDRESS = 3;
}

// Consent record state
enum ConsentStateSave {
CONSENT_STATE_SAVE_UNSPECIFIED = 0;
CONSENT_STATE_SAVE_UNKNOWN = 1;
CONSENT_STATE_SAVE_ALLOWED = 2;
CONSENT_STATE_SAVE_DENIED = 3;
}
32 changes: 32 additions & 0 deletions proto/device_sync/device_sync.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";
package xmtp.device_sync;

import "device_sync/group_backup.proto";
import "device_sync/message_backup.proto";
import "device_sync/consent_backup.proto";

// Union type representing everything that can be serialied and saved in a backup archive.
message BackupElement {
oneof element {
BackupMetadataSave metadata = 1;
xmtp.device_sync.group_backup.GroupSave group = 2;
xmtp.device_sync.message_backup.GroupMessageSave group_message = 3;
xmtp.device_sync.consent_backup.ConsentSave consent = 4;
}
}

// Proto representation of backup metadata
// (Backup version is explicitly missing - it's stored as a header.)
message BackupMetadataSave {
repeated BackupElementSelection elements = 2;
int64 exported_at_ns = 3;
optional int64 start_ns = 4;
optional int64 end_ns = 5;
}

// Elements selected for backup
enum BackupElementSelection {
BACKUP_ELEMENT_SELECTION_UNSPECIFIED = 0;
BACKUP_ELEMENT_SELECTION_MESSAGES = 1;
BACKUP_ELEMENT_SELECTION_CONSENT = 2;
}
34 changes: 34 additions & 0 deletions proto/device_sync/group_backup.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";
package xmtp.device_sync.group_backup;

// Proto representation of a stored group
message GroupSave {
bytes id = 1;
int64 created_at_ns = 2;
GroupMembershipStateSave membership_state = 3;
int64 installations_last_checked = 4;
string added_by_inbox_id = 5;
optional int64 welcome_id = 6;
int64 rotated_at_ns = 7;
ConversationTypeSave conversation_type = 8;
optional string dm_id = 9;
optional int64 last_message_ns = 10;
optional int64 message_disappear_from_ns = 11;
optional int64 message_disappear_in_ns = 12;
}

// Group membership state
enum GroupMembershipStateSave {
GROUP_MEMBERSHIP_STATE_SAVE_UNSPECIFIED = 0;
GROUP_MEMBERSHIP_STATE_SAVE_ALLOWED = 1;
GROUP_MEMBERSHIP_STATE_SAVE_REJECTED = 2;
GROUP_MEMBERSHIP_STATE_SAVE_PENDING = 3;
}

// Conversation type
enum ConversationTypeSave {
CONVERSATION_TYPE_SAVE_UNSPECIFIED = 0;
CONVERSATION_TYPE_SAVE_GROUP = 1;
CONVERSATION_TYPE_SAVE_DM = 2;
CONVERSATION_TYPE_SAVE_SYNC = 3;
}
49 changes: 49 additions & 0 deletions proto/device_sync/message_backup.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto3";
package xmtp.device_sync.message_backup;

// Proto representation of a stored group message
message GroupMessageSave {
bytes id = 1;
bytes group_id = 2;
bytes decrypted_message_bytes = 3;
int64 sent_at_ns = 4;
GroupMessageKindSave kind = 5;
bytes sender_installation_id = 6;
string sender_inbox_id = 7;
DeliveryStatusSave delivery_status = 8;
ContentTypeSave content_type = 9;
int32 version_major = 10;
int32 version_minor = 11;
string authority_id = 12;
optional bytes reference_id = 13;
}

// Group message kind
enum GroupMessageKindSave {
GROUP_MESSAGE_KIND_SAVE_UNSPECIFIED = 0;
GROUP_MESSAGE_KIND_SAVE_APPLICATION = 1;
GROUP_MESSAGE_KIND_SAVE_MEMBERSHIP_CHANGE = 2;
}

// Group message delivery status
enum DeliveryStatusSave {
DELIVERY_STATUS_SAVE_UNSPECIFIED = 0;
DELIVERY_STATUS_SAVE_UNPUBLISHED = 1;
DELIVERY_STATUS_SAVE_PUBLISHED = 2;
DELIVERY_STATUS_SAVE_FAILED = 3;
}

// Group message content type
enum ContentTypeSave {
CONTENT_TYPE_SAVE_UNSPECIFIED = 0;
CONTENT_TYPE_SAVE_UNKNOWN = 1;
CONTENT_TYPE_SAVE_TEXT = 2;
CONTENT_TYPE_SAVE_GROUP_MEMBERSHIP_CHANGE = 3;
CONTENT_TYPE_SAVE_GROUP_UPDATED = 4;
CONTENT_TYPE_SAVE_REACTION = 5;
CONTENT_TYPE_SAVE_READ_RECEIPT = 6;
CONTENT_TYPE_SAVE_REPLY = 7;
CONTENT_TYPE_SAVE_ATTACHMENT = 8;
CONTENT_TYPE_SAVE_REMOTE_ATTACHMENT = 9;
CONTENT_TYPE_SAVE_TRANSACTION_REFERENCE = 10;
}