Skip to content

Commit

Permalink
Changing to proper FFI bindings (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotboyd authored Apr 4, 2024
1 parent 42acd28 commit 25126e6
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 59 deletions.
24 changes: 24 additions & 0 deletions diagrams/HLSDK.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
block-beta
columns 4
block:group1:2
columns 2
Android LibXMTP
end
space:2

block:group3:2
columns 2
React C["LibXMTP"]
end
space
Node["XMTP Node"]
block:group2:2
columns 2
iOS B["LibXMTP"]
end
group1-->Node
Node-->group1
group2-->Node
Node-->group2
group3-->Node
Node-->group3
27 changes: 14 additions & 13 deletions diagrams/add-remove.mermaid
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,37 @@ sequenceDiagram
participant Charlie
participant LibXMTP
participant Node

Note left of Alice: Remove Charlie

Alice->>LibXMTP: group.removeMembers(Charlie)
Alice->>LibXMTP: group.remove_members(Charlie)
LibXMTP->>+Node: get-identity-updates(Charlie)
Node-->>-LibXMTP: installation_key:Charlie + credential_identity:Charlie
LibXMTP->>Node: send-group-message(REMOVE_MEMBER:installation_key:Charlie)
Alice->>+LibXMTP: group.messages()
Alice->>+LibXMTP: group.sync()
LibXMTP->>+Node: query-group-messages(group_id)
Node->>-LibXMTP: REMOVE_MEMBER:Charlie
LibXMTP-->>-Alice: "Charlie has been removed from the group"
Bob->>+LibXMTP: group.messages()
Bob->>+LibXMTP: group.sync()
LibXMTP->>+Node: query-group-messages(group_id)
Node->>-LibXMTP: REMOVE_MEMBER:Charlie
LibXMTP-->>-Bob: "Charlie has been removed from the group"

Note left of Alice: Add Charlie
Bob->>LibXMTP: addMembers(Charlie)
Alice->>LibXMTP: addMembers(Charlie)
LibXMTP->>+Node: get-identity-updates(Charlie)
Node-->>-LibXMTP: installation_key:Charlie + credential_identity:Charlie
LibXMTP->>Node: send-group-message(ADD_MEMBER:installation_key:Charlie)
Bob->>+LibXMTP: group.messages()
Alice->>+LibXMTP: group.sync()
LibXMTP->>+Node: query-group-messages(group_id)
Node->>-LibXMTP: ADD_MEMBER:Charlie
LibXMTP-->>-Bob: "Charlie has been added to the group"
Alice->>+LibXMTP: group.messages()
LibXMTP-->>-Alice: "Charlie has been added to the group"
Bob->>+LibXMTP: group.sync()
LibXMTP->>+Node: query-group-messages(group_id)
Node->>-LibXMTP: ADD_MEMBER:Charlie
LibXMTP-->>-Alice: "Charlie has been added to the group"
Charlie->>+LibXMTP: syncGroups()
LibXMTP-->>-Bob: "Charlie has been added to the group"
Charlie->>+LibXMTP: conversations.sync()
LibXMTP->>+Node: query-welcome-messages(installation_key:Charlie)
Node-->>-LibXMTP: WelcomeMessages()
LibXMTP-->>-Charlie: "Alice has added you to a group"
Charlie->>LibXMTP: rotate_key_packages()
LibXMTP->>Node: upload-key-package()
Charlie->>+LibXMTP: conversations.list()
LibXMTP-->>-Charlie: List of groups including new group
14 changes: 14 additions & 0 deletions diagrams/create-client.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sequenceDiagram
participant Alice
participant LibXMTP
participant Node

Note over Alice,LibXMTP: These calls are coming from higher-level SDKs on behalf of users
Note over Alice,Node: Step 1 (Account Creation) & 2 (Initial Keying Material) of MLS group creation combined
Alice->>+LibXMTP: create_client(encryption_key, account_address)
LibXMTP-->>-Alice: client
Alice->>+LibXMTP: client.text_to_sign()
LibXMTP-->>-Alice: text to be signed for register_identity
Alice->>LibXMTP: client.register_identity(recoverable_wallet_signature)
LibXMTP->>+Node: register_installation(key_package:Alice)
Node-->>-LibXMTP: installation_key:Alice
68 changes: 39 additions & 29 deletions diagrams/diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The sequence diagrams stored here are for documenting LibXMTP's group chat imple

The diagrams represent the creation of a group chat between Alice, Bob, and Charlie, our implmentation of [Figure 2](https://messaginglayersecurity.rocks/mls-architecture/draft-ietf-mls-architecture.html#fig-group-formation-example) from [The Messaging Layer Security (MLS) Architecture](https://messaginglayersecurity.rocks/mls-architecture/draft-ietf-mls-architecture.html) spec.

Note: calls into LibXMTP with the `conversations.` prefix use the [Conversations](https://github.com/xmtp/libxmtp/blob/204b35a337daf2a9f2ed0cb20199e254d0a7493a/bindings_ffi/src/mls.rs#L188) protocol, and calls with a `group.` prefix use the [Group](https://github.com/xmtp/libxmtp/blob/204b35a337daf2a9f2ed0cb20199e254d0a7493a/bindings_ffi/src/mls.rs#L315) protocol.

* *form-group.mermaid* - Covers Steps 1-4 of forming a group. In LibXMTP, steps 1 and 2 happen at the same time, and steps 3 and 4 can also be consolidated by calling `newGroup()` with multiple participants.
* *send-recieve.mermaid* - Covers sending and receiving messages to the newly formed group.
* *add-remove.mermaid* - Covers adding and removing group members.
Expand All @@ -21,37 +23,47 @@ sequenceDiagram
Note over Alice,Charlie: These calls are coming from higher-level<br/> SDKs on behalf of users
Note over Alice,Node: Step 1 (Account Creation) & 2 (Initial Keying Material) of MLS group creation combined
Alice->>LibXMTP: create_client(encryption_key, account_address)
Alice->>+LibXMTP: create_client(encryption_key, account_address)
LibXMTP-->>-Alice: client
Alice->>+LibXMTP: client.text_to_sign()
LibXMTP-->>-Alice: text to be signed for register_identity
Alice->>LibXMTP: client.register_identity(recoverable_wallet_signature)
LibXMTP->>+Node: register_installation(key_package:Alice)
Node-->>-LibXMTP: installation_key:Alice
Bob->>LibXMTP: create_client(encryption_key, account_address)
Bob->>+LibXMTP: create_client(encryption_key, account_address)
LibXMTP-->>-Bob: client
Bob->>+LibXMTP: client.text_to_sign()
LibXMTP-->>-Bob: text to be signed for register_identity
Bob->>LibXMTP: client.register_identity(recoverable_wallet_signature)
LibXMTP->>+Node: register_installation(key_package:Bob)
Node-->>-LibXMTP: installation_key:Bob
Charlie->>LibXMTP: create_client(encryption_key, account_address)
Charlie->>+LibXMTP: create_client(encryption_key, account_address)
LibXMTP-->>-Charlie: client
Charlie->>+LibXMTP: client.text_to_sign()
LibXMTP-->>-Charlie: text to be signed for register_identity
Charlie->>LibXMTP: client.register_identity(recoverable_wallet_signature)
LibXMTP->>+Node: register_installation(key_package:Charlie)
Node-->>-LibXMTP: installation_key:Charlie
Note over Alice,Node: Step 3 (Adding Bob) & 4 (Adding Charlie) of MLS group creation
Alice->>LibXMTP: newGroup(Bob, Charlie)
Alice->>LibXMTP: conversations.create_group(Bob, Charlie)
LibXMTP->>+Node: get-identity-updates(Bob)
Node-->>-LibXMTP: installation_key:Bob + credential_identity:Bob
LibXMTP->>+Node: get-identity-updates(Charlie)
Node-->>-LibXMTP: installation_key:Charlie + credential_identity:Charlie
LibXMTP->>Node: fetch-key-packages(installation_keys: Bob + Charlie)
Node-->>LibXMTP: KeyPackages(Bob+Charlie)
LibXMTP->>Node: send-welcome-messages(KeyPackages:Bob + Charlie)
Bob->>+LibXMTP: syncGroups()
Bob->>+LibXMTP: conversations.sync()
LibXMTP->>+Node: query-welcome-messages(installation_key:Bob)
Node-->>-LibXMTP: WelcomeMessages()
LibXMTP-->>-Bob: "Alice has added you to a group"
Bob->>LibXMTP: rotate_key_packages()
LibXMTP->>Node: upload-key-package()
Charlie->>+LibXMTP: syncGroups()
Bob->>+LibXMTP: conversations.list()
LibXMTP-->>-Bob: List of groups including new group
Charlie->>+LibXMTP: conversations.sync()
LibXMTP->>+Node: query-welcome-messages(installation_key:Charlie)
Node-->>-LibXMTP: WelcomeMessages()
LibXMTP-->>-Charlie: "Alice has added you to a group"
Charlie->>LibXMTP: rotate_key_packages()
LibXMTP->>Node: upload-key-package()
Charlie->>+LibXMTP: conversations.list()
LibXMTP-->>-Charlie: List of groups including new group
```

## Send and Receive Messages
Expand All @@ -60,7 +72,6 @@ sequenceDiagram
sequenceDiagram
participant Alice
participant Bob
participant Charlie
participant LibXMTP
participant Node
Expand All @@ -69,10 +80,11 @@ sequenceDiagram
LibXMTP->>Node: send-group-messages(SEND_MESSAGE:"Hello, group!")
Note left of Alice: Receive Message
Bob->>+LibXMTP: group.messages()
LibXMTP->>+Node: query-group-messages(group_id)
Node-->>-LibXMTP: "Hello, group!"
LibXMTP->>-Bob: "Hello, group!"
Bob->>LibXMTP: group.sync()
LibXMTP->>Node: query-group-messages(group_id)
Node-->>LibXMTP: "Hello, group!"
Bob->>LibXMTP: group.find_messages()
LibXMTP->>Bob: "Hello, group!"
```

## Add and Remove Group Members
Expand All @@ -84,39 +96,37 @@ sequenceDiagram
participant Charlie
participant LibXMTP
participant Node
Note left of Alice: Remove Charlie
Alice->>LibXMTP: group.removeMembers(Charlie)
Alice->>LibXMTP: group.remove_members(Charlie)
LibXMTP->>Node: send-group-message(REMOVE_MEMBER:installation_key:Charlie)
Alice->>+LibXMTP: group.messages()
Alice->>+LibXMTP: group.sync()
LibXMTP->>+Node: query-group-messages(group_id)
Node->>-LibXMTP: REMOVE_MEMBER:Charlie
LibXMTP-->>-Alice: "Charlie has been removed from the group"
Bob->>+LibXMTP: group.messages()
Bob->>+LibXMTP: group.sync()
LibXMTP->>+Node: query-group-messages(group_id)
Node->>-LibXMTP: REMOVE_MEMBER:Charlie
LibXMTP-->>-Bob: "Charlie has been removed from the group"
Note left of Alice: Add Charlie
Bob->>LibXMTP: addMembers(Charlie)
Alice->>LibXMTP: add_members(Charlie)
LibXMTP->>+Node: get-identity-updates(Charlie)
Node-->>-LibXMTP: installation_key:Charlie + credential_identity:Charlie
LibXMTP->>Node: send-group-message(ADD_MEMBER:installation_key:Charlie)
Bob->>+LibXMTP: group.messages()
Alice->>+LibXMTP: group.sync()
LibXMTP->>+Node: query-group-messages(group_id)
Node->>-LibXMTP: ADD_MEMBER:Charlie
LibXMTP-->>-Bob: "Charlie has been added to the group"
Alice->>+LibXMTP: group.messages()
LibXMTP-->>-Alice: "Charlie has been added to the group"
Bob->>+LibXMTP: group.sync()
LibXMTP->>+Node: query-group-messages(group_id)
Node->>-LibXMTP: ADD_MEMBER:Charlie
LibXMTP-->>-Alice: "Charlie has been added to the group"
Charlie->>+LibXMTP: syncGroups()
LibXMTP-->>-Bob: "Charlie has been added to the group"
Charlie->>+LibXMTP: conversations.sync()
LibXMTP->>+Node: query-welcome-messages(installation_key:Charlie)
Node-->>-LibXMTP: WelcomeMessages()
LibXMTP-->>-Charlie: "Alice has added you to a group"
Charlie->>LibXMTP: rotate_key_packages()
LibXMTP->>Node: upload-key-package()
```

## Sync Installations
Expand Down
34 changes: 22 additions & 12 deletions diagrams/form-group.mermaid
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,44 @@ sequenceDiagram

Note over Alice,Charlie: These calls are coming from higher-level<br/> SDKs on behalf of users
Note over Alice,Node: Step 1 (Account Creation) & 2 (Initial Keying Material) of MLS group creation combined
Alice->>LibXMTP: create_client(encryption_key, account_address)
Alice->>+LibXMTP: create_client(encryption_key, account_address)
LibXMTP-->>-Alice: client
Alice->>+LibXMTP: client.text_to_sign()
LibXMTP-->>-Alice: text to be signed for register_identity
Alice->>LibXMTP: client.register_identity(recoverable_wallet_signature)
LibXMTP->>+Node: register_installation(key_package:Alice)
Node-->>-LibXMTP: installation_key:Alice
Bob->>LibXMTP: create_client(encryption_key, account_address)
Bob->>+LibXMTP: create_client(encryption_key, account_address)
LibXMTP-->>-Bob: client
Bob->>+LibXMTP: client.text_to_sign()
LibXMTP-->>-Bob: text to be signed for register_identity
Bob->>LibXMTP: client.register_identity(recoverable_wallet_signature)
LibXMTP->>+Node: register_installation(key_package:Bob)
Node-->>-LibXMTP: installation_key:Bob
Charlie->>LibXMTP: create_client(encryption_key, account_address)
Charlie->>+LibXMTP: create_client(encryption_key, account_address)
LibXMTP-->>-Charlie: client
Charlie->>+LibXMTP: client.text_to_sign()
LibXMTP-->>-Charlie: text to be signed for register_identity
Charlie->>LibXMTP: client.register_identity(recoverable_wallet_signature)
LibXMTP->>+Node: register_installation(key_package:Charlie)
Node-->>-LibXMTP: installation_key:Charlie

Note over Alice,Node: Step 3 (Adding Bob) & 4 (Adding Charlie) of MLS group creation
Alice->>LibXMTP: newGroup(Bob, Charlie)
Alice->>LibXMTP: conversations.create_group(Bob, Charlie)
LibXMTP->>+Node: get-identity-updates(Bob)
Node-->>-LibXMTP: installation_key:Bob + credential_identity:Bob
LibXMTP->>+Node: get-identity-updates(Charlie)
Node-->>-LibXMTP: installation_key:Charlie + credential_identity:Charlie
LibXMTP->>Node: fetch-key-packages(installation_keys: Bob + Charlie)
Node-->>LibXMTP: KeyPackages(Bob+Charlie)
LibXMTP->>Node: send-welcome-messages(KeyPackages:Bob + Charlie)
Bob->>+LibXMTP: syncGroups()
Bob->>+LibXMTP: conversations.sync()
LibXMTP->>+Node: query-welcome-messages(installation_key:Bob)
Node-->>-LibXMTP: WelcomeMessages()
LibXMTP-->>-Bob: "Alice has added you to a group"
Bob->>LibXMTP: rotate_key_packages()
LibXMTP->>Node: upload-key-package()
Charlie->>+LibXMTP: syncGroups()
Bob->>+LibXMTP: conversations.list()
LibXMTP-->>-Bob: List of groups including new group
Charlie->>+LibXMTP: conversations.sync()
LibXMTP->>+Node: query-welcome-messages(installation_key:Charlie)
Node-->>-LibXMTP: WelcomeMessages()
LibXMTP-->>-Charlie: "Alice has added you to a group"
Charlie->>LibXMTP: rotate_key_packages()
LibXMTP->>Node: upload-key-package()
Charlie->>+LibXMTP: conversations.list()
LibXMTP-->>-Charlie: List of groups including new group
10 changes: 5 additions & 5 deletions diagrams/send-receive.mermaid
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
sequenceDiagram
participant Alice
participant Bob
participant Charlie
participant LibXMTP
participant Node

Expand All @@ -10,7 +9,8 @@ sequenceDiagram
LibXMTP->>Node: send-group-messages(SEND_MESSAGE:"Hello, group!")

Note left of Alice: Receive Message
Bob->>+LibXMTP: group.messages()
LibXMTP->>+Node: query-group-messages(group_id)
Node-->>-LibXMTP: "Hello, group!"
LibXMTP->>-Bob: "Hello, group!"
Bob->>LibXMTP: group.sync()
LibXMTP->>Node: query-group-messages(group_id)
Node-->>LibXMTP: "Alice: Hello, group!"
Bob->>LibXMTP: group.find_messages()
LibXMTP-->>Bob: "Alice: Hello, group!"

0 comments on commit 25126e6

Please sign in to comment.