Replies: 3 comments 1 reply
-
Great proposal @nedsalk, I especially like the DX improvements here. Even just the nomenclature change and providing a flow that is more akin to what we already provide with resources will be an improvement. An iterative approach is also appreciated. Phase 1, providing a signer that is called by the transaction request provides a good DX improvement with minimal interruption to the current implementation. I think we should exercise caution with phase 2, given the pre-requisites. |
Beta Was this translation helpful? Give feedback.
-
@nedsalk This seems to be a good improvement. I am just curious how each wallet/signer will be linked to the resources to be signed later. I wonder if the current implementation was made this way for a specific reason. The way that works right now, the wallet is used to sign the request at a very specific moment, and then it is not needed anymore. Just thinking if we will not have any security problems by attaching an unlocked wallet to a transaction request, that will only be used later on. |
Beta Was this translation helpful? Give feedback.
-
The rust sdk's initial refactoring of transaction signing was implemented such that they were passing the private key to their |
Beta Was this translation helpful? Give feedback.
-
Current situation
This current implementation of adding witnesses gives a suboptimal developer experience when crafting a custom transaction. In order to sign the transaction, one has to do the following:
The above example has two issues:
wallet
twice: once as an address, and once to sign the transaction. This is a sign of incomplete design.Proposal
I propose an alternative approach:
Here, the signers wouldn't actually sign the transaction. They'd just be added to a list of signers that would be used in the
transactionRequest.finalize()
method described below.When the time comes to send the transaction, the current implementation of sending the transaction would force us to approach this redesign in two steps. First, we'd leave the
Provider.sendTransaction(transactionRequestLike: TransactionRequestLike)
interface and finish the signing within it:This call to the new
transactionRequest.finalize()
method would return an immutable transaction request which we can identify with theImmutableTx
type for the sake of this discussion. This method would use the signers added viarequest.addSigner
to sign the transaction appropriately, among possibly other things. It returningImmutableTx
would guarantee that nobody can modify the transaction afterwards.The second redesign step would be to change the
provider.sendTransaction
method's interface to acceptImmutableTx
, where the workflow with it would now look like this:The benefit of this would be:
provider.sendTransaction
wouldn't be mutating the transaction; it would only do some last validity checks (e.g. around gas price), and send it to the node as the user sent it.This second step would probably take more time to implement. Some things that come to mind that might slow it down:
sendTransaction
onAccount
/BaseWalletUnlocked
/Predicate
might interfere and might have to be done beforehand.ScriptTransactionRequest
is one of the building blocks of our SDK, it might span multiple packages.Notes on the current implementation
Adding a resource to a
ScriptTransactionRequest
currently automatically adds an empty witness as well:This is done to be able to correctly correlate inputs with their witnesses when the time for signing comes. Based on a search for the
updateWitnessByOwner
method ofScriptTransactionRequest
, the actual usage of signing across our code base is happening only inBaseWalletUnlocked.populateTransactionWitnessesSignature
.Conceptually, however, there shouldn't be a need to add an empty witness when adding a resource. It's being added purely due to internal implementation details.
Beta Was this translation helpful? Give feedback.
All reactions