Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sdk/action/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import (
//
//go:generate mockery --name=Client --output=testutil/mocks --outpkg=mocks --filename=client_mock.go
type Client interface {
StartCascade(ctx context.Context, filePath string, actionID string) (string, error)
// - signature: Base64-encoded cryptographic signature of the file's data hash (blake3)
// 1- hash(blake3) > 2- sign > 3- base64
// The signature must be created by the same account that created the Lumera action.
// It must be a digital signature of the data hash found in the action's CASCADE metadata.
StartCascade(ctx context.Context, filePath string, actionID string, signature string) (string, error)
DeleteTask(ctx context.Context, taskID string) error
GetTask(ctx context.Context, taskID string) (*task.TaskEntry, bool)
SubscribeToEvents(ctx context.Context, eventType event.EventType, handler event.Handler) error
Expand Down Expand Up @@ -54,7 +58,7 @@ func NewClient(ctx context.Context, config config.Config, logger log.Logger, key
}

// StartCascade initiates a cascade operation
func (c *ClientImpl) StartCascade(ctx context.Context, filePath string, actionID string) (string, error) {
func (c *ClientImpl) StartCascade(ctx context.Context, filePath string, actionID string, signature string) (string, error) {
if actionID == "" {
c.logger.Error(ctx, "Empty action ID provided")
return "", ErrEmptyActionID
Expand All @@ -64,7 +68,7 @@ func (c *ClientImpl) StartCascade(ctx context.Context, filePath string, actionID
return "", ErrEmptyData
}

taskID, err := c.taskManager.CreateCascadeTask(ctx, filePath, actionID)
taskID, err := c.taskManager.CreateCascadeTask(ctx, filePath, actionID, signature)
if err != nil {
c.logger.Error(ctx, "Failed to create cascade task", "error", err)
return "", fmt.Errorf("failed to create cascade task: %w", err)
Expand Down
143 changes: 0 additions & 143 deletions sdk/action/testutil/mocks/client_mock.go

This file was deleted.

34 changes: 33 additions & 1 deletion sdk/adapters/lumera/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import (
sntypes "github.com/LumeraProtocol/lumera/x/supernode/types"
lumeraclient "github.com/LumeraProtocol/supernode/pkg/lumera"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/golang/protobuf/proto"
)

//go:generate mockery --name=Client --output=testutil/mocks --outpkg=mocks --filename=lumera_mock.go
type Client interface {
GetAction(ctx context.Context, actionID string) (Action, error)
GetSupernodes(ctx context.Context, height int64) ([]Supernode, error)
DecodeCascadeMetadata(ctx context.Context, action Action) (actiontypes.CascadeMetadata, error)
VerifySignature(ctx context.Context, accountAddr string, data []byte, signature []byte) error
}

// ConfigParams holds configuration parameters from global config
Expand Down Expand Up @@ -128,13 +131,42 @@ func (a *Adapter) GetSupernodes(ctx context.Context, height int64) ([]Supernode,
return supernodes, nil
}

func toSdkAction(resp *actiontypes.QueryGetActionResponse) Action {
func (a *Adapter) VerifySignature(ctx context.Context, accountAddr string, data, signature []byte) error {

err := a.client.Auth().Verify(ctx, accountAddr, data, signature)
if err != nil {
a.logger.Error(ctx, "Signature verification failed", "accountAddr", accountAddr, "error", err)
return fmt.Errorf("signature verification failed: %w", err)
}
a.logger.Debug(ctx, "Signature verified successfully", "accountAddr", accountAddr)
return nil
}

// DecodeCascadeMetadata decodes the raw metadata bytes into CascadeMetadata
func (a *Adapter) DecodeCascadeMetadata(ctx context.Context, action Action) (actiontypes.CascadeMetadata, error) {
if action.ActionType != "ACTION_TYPE_CASCADE" {
return actiontypes.CascadeMetadata{}, fmt.Errorf("action is not of type CASCADE, got %s", action.ActionType)
}

var meta actiontypes.CascadeMetadata
if err := proto.Unmarshal(action.Metadata, &meta); err != nil {
a.logger.Error(ctx, "Failed to unmarshal cascade metadata", "actionID", action.ID, "error", err)
return meta, fmt.Errorf("failed to unmarshal cascade metadata: %w", err)
}

a.logger.Debug(ctx, "Successfully decoded cascade metadata", "actionID", action.ID)
return meta, nil
}

func toSdkAction(resp *actiontypes.QueryGetActionResponse) Action {
return Action{
ID: resp.Action.ActionID,
State: ACTION_STATE(resp.Action.State.String()),
Height: resp.Action.BlockHeight,
ExpirationTime: resp.Action.ExpirationTime,
ActionType: resp.Action.ActionType.String(),
Metadata: resp.Action.Metadata,
Creator: resp.Action.Creator,
}
}

Expand Down
87 changes: 0 additions & 87 deletions sdk/adapters/lumera/testutil/mocks/lumera_mock.go

This file was deleted.

3 changes: 3 additions & 0 deletions sdk/adapters/lumera/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type Action struct {
State ACTION_STATE
Height int64
ExpirationTime int64
ActionType string // Type of the action (e.g., CASCADE)
Metadata []byte // Raw metadata bytes
Creator string // Creator of the action
}

type Supernodes []Supernode
Expand Down
8 changes: 7 additions & 1 deletion sdk/adapters/supernodeservice/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ func (a *cascadeAdapter) CascadeSupernodeRegister(ctx context.Context, in *Casca
a.logger.Info(ctx, "Supernode progress update received", "event_type", resp.EventType, "message", resp.Message, "tx_hash", resp.TxHash, "task_id", in.TaskId, "action_id", in.ActionID)

if in.EventLogger != nil {
in.EventLogger(ctx, toSdkEvent(resp.EventType), resp.Message, nil)
in.EventLogger(ctx, toSdkEvent(resp.EventType), resp.Message, event.EventData{
event.KeyEventType: resp.EventType,
event.KeyMessage: resp.Message,
event.KeyTxHash: resp.TxHash,
event.KeyTaskID: in.TaskId,
event.KeyActionID: in.ActionID,
})
}

// Optionally capture the final response
Expand Down
Loading