xmtp / didethresolver

XMTP Registry Resolver
MIT License
3 stars 1 forks source link

add a `set_id` method on the `DidUrl` type #12

Closed insipx closed 8 months ago

insipx commented 9 months ago

Is your feature request related to a problem?

when constructing a document, we manipulate the original did by cloning and modify the parts of the DID-URL as necessasry. For instance, the code to set a controller account is as follows:

/// Set the controller of the document
    pub fn controller(&mut self, controller: &Address) -> Result<()> {
        let mut did = self.id.clone();
        // TODO: Include a `set_id` method on `DidUrl
        did.set_path(&format!("ethr:0x{}", hex::encode(&controller)))?;
        self.controller = Some(did);
        Ok(())
    }

Here, we clone the original did, format a did path parameter, and then set the documents controller to this DID.

This isn't the best, because by passing a formatted path in the form of ethr:controller_address, DidUrl re-parses this path even though we already have Method and ID types parsed.

For usability/general enhancment, it would be better to provide a set_id method on DidUrl which can directly manipulate the ID of a did. We must also ensure that the underlying Url representation of the did contains this new address (simply assigning method.id.public_key won't change how the address is serialized to JSON because the underlying URL type still contains this address).

Describe the solution to the problem

No response

Describe the uses cases for the feature

No response

Additional details

No response