3box-js icon indicating copy to clipboard operation
3box-js copied to clipboard

Question: Passing a signature method to 3box rather than web3 object

Open Schwartz10 opened this issue 6 years ago • 3 comments

Hey! I'm wondering how you guys feel about allowing custom functions to be passed to the openBox 3box method rather than a web3 object (or use the web3 object as a default).

For example:

// must have the same interface as web3.eth.personal_sign method
const someCustomFunction = ([message], callback) => { 
   try {
      const sig = await signMessage(message)
      callback(null, { result: signature, error: null })
   } catch (error) {
      callback(error, { error })
   }
}

const box = await Box.openBox(ethAddress, { personal_sign: someCustomFunction })

Last time we talked about this, the only JSON-RPC method y'all were using was sendAsync with personal_sign, so instead of passing an entire web3 object, i would love to just be able to pass a custom signature method with the same interface as the web3 personal_sign method.

My use case: Aragon has a nifty user experience for signing tx's and messages - we open up an information panel in the UI with more information about who's requesting the signature, what data is being signed...etc. If the user clicks "sign", THEN we popup metamask (and invoke personal_sign).

So when it comes to interacting with 3box, i've written a (scary) hack, which basically just fakes a web3 object with a customized personal_sign method. This works fine for now, but... its kinda uncomfortable. Here's the codes:

  1. invoking openBox with an ethereumAddress and a "fake" web3 object
  2. The fake web3 object is created here
  3. It has a sendAsync method that throws an error if the method isn't personal_sign
  4. It implements a custom personal_sign method

Sorry if this is a lot to handle - this isn't a solution we need to desperately find a solution for. But it would be nice to allow custom web3 handlers to be used instead of the native web3 object stuff.

Schwartz10 avatar May 29 '19 19:05 Schwartz10

I don't really have any strong opinion here. Your argument seems reasonable, but I also don't see any major benefit other than removing a few lines of code on your end.

Contributions are welcome though 😄

oed avatar May 30 '19 08:05 oed

I also don't see any major benefit other than removing a few lines of code on your end

Interesting! Could you elaborate?

Schwartz10 avatar May 30 '19 11:05 Schwartz10

Interesting! Could you elaborate?

Maybe I'm missing something but the only code you could replace by this feature would be: https://github.com/openworklabs/aragon/blob/dev/src/apps/Profile/modules/3box-aragon.js#L13

oed avatar May 30 '19 12:05 oed