Asynchronous transaction serializers prior to signing #2696
Unanswered
CedarMist
asked this question in
Idea / Feature Request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently the transaction serializers are great, but they don't support async code prior to signing.
See the
signTransaction
function as an example.This is messy, as sometimes the transaction serializer can be async and return a Promise, sometimes it can't. It would be good to be consistent and make it so the transaction serializer can always return a promise if it wants.
If the serializer returns a non-Promise object, the
await
will be a noop, so will not require modification of existing serializers.The
signEip712Transaction
function passes a dummy signature to the transaction serializer, so is always async.Suggested Fix
Modify
signTransaction
tokeccak256(await serializer(signableTransaction))
Use Case
We are encrypting transactions prior to signing, to perform the encryption we need to fetch and validate a public key (if it hasn't already been fetched, or has expired). We cannot encrypt the transaction after signing (limitation of the protocol).
Locations Affected
signTransaction
viem/src/accounts/utils/signTransaction.ts
Lines 40 to 46 in 615d39c
viem/src/accounts/utils/signTransaction.ts
Lines 64 to 72 in 615d39c
signEip712Transaction
viem/src/accounts/utils/signTransaction.ts
Lines 40 to 46 in 615d39c
viem/src/zksync/actions/signEip712Transaction.ts
Lines 141 to 149 in 615d39c
Beta Was this translation helpful? Give feedback.
All reactions