web5-js icon indicating copy to clipboard operation
web5-js copied to clipboard

Require `agent` when `connectedDid` is provided

Open angiejones opened this issue 1 year ago • 2 comments

Both agent and connectedDid are optional properties on connect(). A user attempted to provide connectedDid without agent. No error occurred. The DID they provided was simply ignored, and a new one was created and returned to them from connect().

image

After assistance, the user realized they have to provide agent if they provide connectedDid. Should we make this a requirement in the API (or at the very least, provide a helpful error message)? Ignoring their provided DID doesn't seem like the right approach.

angiejones avatar Oct 07 '23 23:10 angiejones

more context from user

Screenshot_20231011_104028_Discord

angiejones avatar Oct 11 '23 15:10 angiejones

Before getting into the technical details, it would be helpful to understand the context or use case @cbruguera had in mind when passing in a connectedDid to Web5.connect(). That might reveal whether this would be the recommended approach or if there's another way to accomplish the same thing.

After assistance, the user realized they have to provide agent if they provide connectedDid. Should we make this a requirement in the API (or at the very least, provide a helpful error message)? Ignoring their provided DID doesn't seem like the right approach.

It shouldn't be a requirement since passing in a custom agent is optional and only useful if the developer instantiated a customized Web5Agent implementation or implemented their own agent. However, if the developer chooses not to use the default, passing the connectedDid is necessary so that the instantiated Web instance knows which DID to use when signing DWeb messages, etc.

That being said, it does make sense to throw an Error if a connectedDid is provided without also defining an agent instance.

Additional note:

const newDID = await DidIonMethod.create()

This command creates and returns a PortableDid instance, including keys. However, there's no way for the underlying Web5Agent that's instantiated as part of Web5.connect() to know about this DID and keys -- they only exist in memory referenced by the newDID variable. One potential option would be to instantiate a Web5Agent, create the DID and store it in the Agent's DWN, and then pass that agent instance along with the DID as connectedDid to Web5.connect(). However, that gets back to the question of what the motivation/use case was to determine whether this approach makes sense.

frankhinek avatar Nov 03 '23 13:11 frankhinek