Skip to content

Commit

Permalink
chore: remove UNFORKINGTODO from smart account module (osmosis-labs#8572
Browse files Browse the repository at this point in the history
)

* chore: remove UNFORKINGTODO from smart account module

* Update x/smart-account/authenticator/authentication_request.go

Co-authored-by: PaddyMc <paddymchale@hotmail.com>

---------

Co-authored-by: Nicolas Lara <nicolaslara@gmail.com>
  • Loading branch information
PaddyMc and nicolaslara authored Aug 1, 2024
1 parent c65bb2c commit 641f753
Showing 1 changed file with 25 additions and 39 deletions.
64 changes: 25 additions & 39 deletions x/smart-account/authenticator/authentication_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func GetSignerAndSignatures(tx sdk.Tx) (signers []sdk.AccAddress, signatures []s
}

// Retrieve messages from the transaction.
// UNFORKING v2 TODO: I dont know if ranging over the address bytes and assigning to AccAddress is correct
signerBytes, err := sigTx.GetSigners()
if err != nil {
return nil, nil, err
Expand All @@ -91,30 +90,7 @@ func GetSignerAndSignatures(tx sdk.Tx) (signers []sdk.AccAddress, signatures []s
}

// getSignerData returns the signer data for a given account. This is part of the data that needs to be signed.
func getSignerData(ctx sdk.Context, ak authante.AccountKeeper, account sdk.AccAddress) txsigning.SignerData {
// Retrieve and build the signer data struct
baseAccount := ak.GetAccount(ctx, account)
genesis := ctx.BlockHeight() == 0
chainID := ctx.ChainID()
var accNum uint64
if !genesis {
accNum = baseAccount.GetAccountNumber()
}
var sequence uint64
if baseAccount != nil {
sequence = baseAccount.GetSequence()
}

return txsigning.SignerData{
ChainID: chainID,
AccountNumber: accNum,
Sequence: sequence,
}
}

// getSignerData returns the signer data for a given account. This is part of the data that needs to be signed.
// UNFORKING v2 TODO: Maybe we can just type cast txsigning.SignerData to authsigning.SignerData instead of using whole new method.
func getSignerDataOld(ctx sdk.Context, ak authante.AccountKeeper, account sdk.AccAddress) authsigning.SignerData {
func getSignerData(ctx sdk.Context, ak authante.AccountKeeper, account sdk.AccAddress) authsigning.SignerData {
// Retrieve and build the signer data struct
baseAccount := ak.GetAccount(ctx, account)
genesis := ctx.BlockHeight() == 0
Expand All @@ -137,7 +113,7 @@ func getSignerDataOld(ctx sdk.Context, ak authante.AccountKeeper, account sdk.Ac

// extractExplicitTxData makes the transaction data concrete for the authentication request. This is necessary to
// pass the parsed data to the cosmwasm authenticator.
func extractExplicitTxData(tx sdk.Tx, signerData txsigning.SignerData) (ExplicitTxData, error) {
func extractExplicitTxData(tx sdk.Tx, signerData authsigning.SignerData) (ExplicitTxData, error) {
timeoutTx, ok := tx.(sdk.TxWithTimeoutHeight)
if !ok {
return ExplicitTxData{}, errorsmod.Wrap(sdkerrors.ErrInvalidType, "failed to cast tx to TxWithTimeoutHeight")
Expand Down Expand Up @@ -234,16 +210,7 @@ func GenerateAuthenticationRequest(
}

// Get the signer data for the account. This is needed in the SignDoc
// UNFORKING v2 TODO: Use a single method and maybe type case as needed, instead of using a whole new getSignerDataOld method
signerData := getSignerData(ctx, ak, account)
signerDataOld := getSignerDataOld(ctx, ak, account)

// Get the sign bytes for the transaction
// UNFORKING v2 TODO: I don't know if using the adapter here is correct, we just dont have access to the TxData but have the sdk.Tx
signBytes, err := authsigning.GetSignBytesAdapter(ctx, sigModeHandler, signing.SignMode_SIGN_MODE_DIRECT, signerDataOld, tx)
if err != nil {
return AuthenticationRequest{}, errorsmod.Wrap(err, "failed to get signBytes")
}

// Get the concrete transaction data to be passed to the authenticators
txData, err := extractExplicitTxData(tx, signerData)
Expand All @@ -257,7 +224,8 @@ func GenerateAuthenticationRequest(
return AuthenticationRequest{}, errorsmod.Wrap(err, "failed to get signatures")
}

return AuthenticationRequest{
// Build the authentication request
authRequest := AuthenticationRequest{
Account: account,
FeePayer: feePayer,
FeeGranter: feeGranter,
Expand All @@ -266,14 +234,32 @@ func GenerateAuthenticationRequest(
MsgIndex: uint64(msgIndex),
Signature: msgSignature,
TxData: txData,
SignModeTxData: SignModeData{ // TODO: Add other sign modes. Specifically textual when it becomes available
Direct: signBytes,
SignModeTxData: SignModeData{
Direct: []byte("signBytes"),
},
SignatureData: SimplifiedSignatureData{
Signers: txSigners,
Signatures: signatures,
},
Simulate: simulate,
AuthenticatorParams: nil,
}, nil
}

// We do not generate the sign bytes if simulate is true
if simulate {
return authRequest, nil
}

// Get the sign bytes for the transaction
signBytes, err := authsigning.GetSignBytesAdapter(ctx, sigModeHandler, signing.SignMode_SIGN_MODE_DIRECT, signerData, tx)
if err != nil {
return AuthenticationRequest{}, errorsmod.Wrap(err, "failed to get signBytes")
}

// TODO: Add other sign modes. Specifically json when it becomes available
authRequest.SignModeTxData = SignModeData{
Direct: signBytes,
}

return authRequest, nil
}

0 comments on commit 641f753

Please sign in to comment.