Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/x-compliance' into feat/x-c…
Browse files Browse the repository at this point in the history
…ompliance
  • Loading branch information
delneg committed Mar 15, 2024
2 parents 6e1ecc0 + 0e0f8db commit 42214b2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
6 changes: 6 additions & 0 deletions go-sgxvm/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type QueryBlockHashResponse = types.QueryBlockHashResponse
type VerificationMethod = types.VerificationMethod
type QueryVerificationMethods = types.QueryVerificationMethods
type QueryVerificationMethodsResponse = types.QueryVerificationMethodsResponse
type QueryAddVerificationDetails = types.QueryAddVerificationDetails
type QueryAddVerificationDetailsResponse = types.QueryAddVerificationDetailsResponse
type QueryHasVerification = types.QueryHasVerification
type QueryHasVerificationResponse = types.QueryHasVerificationResponse

// Storage requests
type CosmosRequest_GetAccount = types.CosmosRequest_GetAccount
Expand All @@ -54,6 +58,8 @@ type CosmosRequest_InsertStorageCell = types.CosmosRequest_InsertStorageCell
type CosmosRequest_Remove = types.CosmosRequest_Remove
type CosmosRequest_RemoveStorageCell = types.CosmosRequest_RemoveStorageCell
type CosmosRequest_VerificationMethods = types.CosmosRequest_VerificationMethods
type CosmosRequest_AddVerificationDetails = types.CosmosRequest_AddVerificationDetails
type CosmosRequest_HasVerification = types.CosmosRequest_HasVerification

// Backend requests
type CosmosRequest_BlockHash = types.CosmosRequest_BlockHash
Expand Down
4 changes: 2 additions & 2 deletions x/compliance/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (k Keeper) MarkAddressAsVerified(ctx sdk.Context, address sdk.Address) erro
}

// AddVerificationDetails writes details of passed verification by provided address.
func (k Keeper) AddVerificationDetails(ctx sdk.Context, userAddress sdk.Address, verificationType types.VerificationType, details types.VerificationDetails) error {
func (k Keeper) AddVerificationDetails(ctx sdk.Context, userAddress sdk.Address, verificationType types.VerificationType, details *types.VerificationDetails) error {
// Check if issuer is verified and not banned
issuerAddress, err := sdk.AccAddressFromBech32(details.IssuerAddress)
if err != nil {
Expand Down Expand Up @@ -300,7 +300,7 @@ func (k Keeper) GetVerificationDetails(ctx sdk.Context, verificationDetailsId []

// HasVerificationOfType checks if user has verifications of specific type (for example, passed KYC) from provided issuers.
// If there is no provided expected issuers, this function will check if user has any verification of appropriate type.
func (k Keeper) HasVerificationOfType(ctx sdk.Context, userAddress sdk.Address, expectedType types.VerificationType, expectedIssuers ...sdk.Address) (bool, error) {
func (k Keeper) HasVerificationOfType(ctx sdk.Context, userAddress sdk.Address, expectedType types.VerificationType, expectedIssuers []sdk.Address) (bool, error) {
// Obtain user address details
userAddressDetails, err := k.GetAddressDetails(ctx, userAddress)
if err != nil {
Expand Down
49 changes: 42 additions & 7 deletions x/evm/keeper/sgxvm_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/golang/protobuf/proto"
"math/big"

compliancetypes "swisstronik/x/compliance/types"
)

// Connector allows our VM interact with existing Cosmos application.
Expand Down Expand Up @@ -62,6 +64,10 @@ func (q Connector) Query(req []byte) ([]byte, error) {
// Returns verification methods for DID Document
case *librustgo.CosmosRequest_VerificationMethods:
return q.GetVerificationMethods(request)
case *librustgo.CosmosRequest_AddVerificationDetails:
return q.AddVerificationDetails(request)
case *librustgo.CosmosRequest_HasVerification:
return q.HasVerification(request)
}

return nil, errors.New("wrong query received")
Expand Down Expand Up @@ -226,14 +232,43 @@ func (q Connector) GetVerificationMethods(req *librustgo.CosmosRequest_Verificat
})
}

// SetVerificationDetails writes provided verification details to x/compliance module
func (q Connector) SetVerificationDetails() ([]byte, error) {
// TODO: Implement
// AddVerificationDetails writes provided verification details to x/compliance module
func (q Connector) AddVerificationDetails(req *librustgo.CosmosRequest_AddVerificationDetails) ([]byte, error) {
verificationType := compliancetypes.VerificationType(req.AddVerificationDetails.VerificationType)
userAddress := sdk.AccAddress(req.AddVerificationDetails.UserAddress)
issuerAddress := sdk.AccAddress(req.AddVerificationDetails.IssuerAddress).String()

verificationDetails := &compliancetypes.VerificationDetails{
IssuerAddress: issuerAddress,
OriginChain: "samplechain", // TODO: Read chain from proto
IssuanceTimestamp: req.AddVerificationDetails.IssuanceTimestamp,
ExpirationTimestamp: req.AddVerificationDetails.ExpirationTimestamp,
OriginalData: req.AddVerificationDetails.ProofData,
}

if err := q.EVMKeeper.ComplianceKeeper.AddVerificationDetails(q.Context, userAddress, verificationType, verificationDetails); err != nil {
return nil, err
}

return nil, nil
}

// GetVerificationDetails returns verification details from x/compliance module
func (q Connector) GetVerificationDetails() ([]byte, error) {
// TODO: Implement
return nil, nil
// HasVerification returns if user has verification of provided type from x/compliance module
func (q Connector) HasVerification(req *librustgo.CosmosRequest_HasVerification) ([]byte, error) {
userAddress := sdk.AccAddress(req.HasVerification.UserAddress)
verificationType := compliancetypes.VerificationType(req.HasVerification.VerificationType)

var allowedIssuers []sdk.Address
for _, issuer := range req.HasVerification.AllowedIssuers {
allowedIssuers = append(allowedIssuers, sdk.AccAddress(issuer))
}

hasVerification, err := q.EVMKeeper.ComplianceKeeper.HasVerificationOfType(q.Context, userAddress, verificationType, allowedIssuers)
if err != nil {
return nil, err
}

return proto.Marshal(&librustgo.QueryHasVerificationResponse{
HasVerification: hasVerification,
})
}
4 changes: 2 additions & 2 deletions x/evm/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ type DIDKeeper interface {

// ComplianceKeeper
type ComplianceKeeper interface {
AddVerificationDetails(ctx sdk.Context, userAddress sdk.Address, verificationType compliancetypes.VerificationType, details compliancetypes.VerificationDetails) error
GetVerificationsOfType(ctx sdk.Context, userAddress sdk.Address, expectedType compliancetypes.VerificationType, expectedIssuers ...sdk.Address) ([]*compliancetypes.VerificationDetails, error)
AddVerificationDetails(ctx sdk.Context, userAddress sdk.Address, verificationType compliancetypes.VerificationType, details *compliancetypes.VerificationDetails) error
HasVerificationOfType(ctx sdk.Context, userAddress sdk.Address, expectedType compliancetypes.VerificationType, expectedIssuers []sdk.Address) (bool, error)
}

// Event Hooks
Expand Down

0 comments on commit 42214b2

Please sign in to comment.