-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add query decrypted tx method to confidential transfers client #1950
Conversation
} | ||
|
||
// ApplyPendingBalanceDecrypted is the decrypted version of ApplyPendingBalance | ||
func (r *ApplyPendingBalance) Decrypt(decryptor *elgamal.TwistedElGamal, privKey ecdsa.PrivateKey, decryptAvailableBalance bool, address string) (*ApplyPendingBalanceDecrypted, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool flag signals the method needs to be split in two. e.g Decrypt
and DecryptWithAvailableBalance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried this but decided not to change in the end - felt a little bit awkward to have 2 methods (Decrypt and DecryptWithAvailableBalance) that do almost the same thing in this specific case, since the only use case here is:
Current:
var result proto.Message
switch message := sdkmsg.(type) {
case *types.MsgInitializeAccount:
result, err = message.Decrypt(decryptor, *privKey, decryptAvailableBalance)
case *types.MsgWithdraw:
result, err = message.Decrypt(decryptor, *privKey, decryptAvailableBalance)
case *types.MsgApplyPendingBalance:
result, err = message.Decrypt(decryptor, *privKey, decryptAvailableBalance)
case *types.MsgTransfer:
result, err = message.Decrypt(decryptor, *privKey, decryptAvailableBalance, address)
case *types.MsgDeposit:
result = message
case *types.MsgCloseAccount:
result = message
default:
return nil, false, nil
With separate methods it would become:
var result proto.Message
switch message := sdkmsg.(type) {
case *types.MsgInitializeAccount:
if decryptAvailableBalance {
result, err = message.DecryptWithAvailableBalnace(decryptor, *privKey)
} else {
result, err = message.Decrypt(decryptor, *privKey)
}
case *types.MsgWithdraw:
if decryptAvailableBalance {
result, err = message.DecryptWithAvailableBalnace(decryptor, *privKey)
} else {
result, err = message.Decrypt(decryptor, *privKey)
}
case *types.MsgApplyPendingBalance:
if decryptAvailableBalance {
result, err = message.DecryptWithAvailableBalnace(decryptor, *privKey)
} else {
result, err = message.Decrypt(decryptor, *privKey)
}
case *types.MsgTransfer:
if decryptAvailableBalance {
result, err = message.DecryptWithAvailableBalnace(decryptor, *privKey)
} else {
result, err = message.Decrypt(decryptor, *privKey)
}
case *types.MsgDeposit:
result = message
case *types.MsgCloseAccount:
result = message
default:
return nil, false, nil
Point taken for future methods though I think it's a helpful idea
@@ -205,6 +215,113 @@ func NewTransfer( | |||
}, nil | |||
} | |||
|
|||
// Decrypts the transfer transaction and returns the decrypted data. | |||
// The aesKey and decryptAvailableBalance field are only used if address is the sender address of the transaction. | |||
func (r *Transfer) Decrypt(decryptor *elgamal.TwistedElGamal, privKey ecdsa.PrivateKey, decryptAvailableBalance bool, address string) (*TransferDecrypted, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think generalization in a form of Decryptable
interface, leads to more complexity in current implementation and/or degraded implementation (like skipped address params in other implementation).
We may need type (sender/receiver/auditor) based implementations of Decryptable
and a separate factory function to avoid types based decision in this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback - since we figured out how to parse the message type properly, I removed the Decryptable interface and just have it call Decrypt for each method.
Also split the Decrypt logic up in the Transfer class to shorten the function.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/ct_types #1950 +/- ##
====================================================
- Coverage 61.57% 59.80% -1.77%
====================================================
Files 263 283 +20
Lines 23306 25876 +2570
====================================================
+ Hits 14351 15476 +1125
- Misses 7948 9266 +1318
- Partials 1007 1134 +127
|
Describe your changes and provide context
We want users to have the ability to easily query a tx hash in it's decrypted state (if they have the private key)
This PR adds a seid method seid q ct tx --from that queries a tx by it's hash, then decrypts it using the user's private key.
Testing performed to validate your change
Manual testing using the updated seid