Skip to content

Commit

Permalink
Add Identity Update Builder (#632)
Browse files Browse the repository at this point in the history
## tl;dr

- Adds `IdentityUpdateBuilder` and `SignatureRequest` structs, used to create batched Identity Updates

## Design decisions

There were a few constraints on the design that made this a tricky one to implement.

- These are batch signatures. An IdentityUpdate may contain several actions, each requiring one or two signatures. But each of those signatures are against a signature text derived from the entire batch. So, we need to gather an outline of all the updates before we can start collecting signatures.
- Passing signers over the FFI barrier has proven complicated in the past. Some signers are synchronous, some are asynchronous. The caller doesn't necessarily have all the signers available every time they use `libxmtp`, so they may have to prompt the user before they can get a signature. The most versatile solution is to have a "signature request" that goes over the FFI barrier to platform SDKs, and have the SDKs return the serialized bytes.

## Usage

```rust
        let account_address = "0x1234".to_string();
        let nonce = 0;
        let inbox_id = generate_inbox_id(&account_address, &nonce);

        let mut signature_request = IdentityUpdateBuilder::new(inbox_id)
            .create_inbox(account_address.into(), nonce)
            .add_association("0x5678".to_string().into(), account_address.into())
            .to_signature_request();

        for missing_signature in signature_request.missing_signatures() {
            signature_request.add_signature(somehow_get_signature_maybe_this_happens_over_ffi()).expect("should succeed")?;
        }

        let identity_update = signature_request.build_identity_update()?;
```
  • Loading branch information
neekolas authored Apr 8, 2024
1 parent 4326e61 commit 43884ec
Show file tree
Hide file tree
Showing 4 changed files with 513 additions and 49 deletions.
Loading

0 comments on commit 43884ec

Please sign in to comment.