Skip to content
Open
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
8 changes: 4 additions & 4 deletions internal/api/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
)

func (s *Server) GetPublicKeyFees(c echo.Context) error {
pluginID, ok := c.Get("plugin_id").(types.PluginID)
pluginID, ok := c.Get("plugin_id").(string)
if !ok || pluginID == "" {
return c.JSON(http.StatusBadRequest, NewErrorResponseWithMessage(msgRequiredPluginID))
}
if pluginID != types.PluginVultisigFees_feee {
if pluginID != itypes.PluginVultisigFees {
return c.JSON(http.StatusUnauthorized, NewErrorResponseWithMessage("unauthorized"))
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func (s *Server) GetPluginFeeHistory(c echo.Context) error {

fees, totalCount, err := s.db.GetFeesByPluginID(
c.Request().Context(),
types.PluginID(pluginID),
pluginID,
publicKey,
skip,
take,
Expand Down Expand Up @@ -204,7 +204,7 @@ func (s *Server) GetPluginBillingSummary(c echo.Context) error {
for i, row := range rows {
pricings := pricingsMap[row.PluginID]
summaries[i] = itypes.PluginBillingSummary{
PluginID: types.PluginID(row.PluginID),
PluginID: row.PluginID,
AppName: titleMap[row.PluginID],
Pricing: formatPricings(pricings),
StartDate: row.StartDate.UTC(),
Expand Down
36 changes: 18 additions & 18 deletions internal/api/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func (s *Server) SignPluginMessages(c echo.Context) error {

// Verify authenticated plugin ID matches the requested plugin ID
// This prevents a malicious plugin from impersonating another plugin
authenticatedPluginID, ok := c.Get("plugin_id").(vtypes.PluginID)
authenticatedPluginID, ok := c.Get("plugin_id").(string)
if !ok {
return c.JSON(http.StatusBadRequest, NewErrorResponseWithMessage(msgRequiredPluginID))
}
if authenticatedPluginID.String() != req.PluginID {
if authenticatedPluginID != req.PluginID {
s.logger.Warnf("Plugin ID mismatch: authenticated=%s, requested=%s", authenticatedPluginID, req.PluginID)
return c.JSON(http.StatusForbidden, NewErrorResponseWithMessage(msgPluginIDMismatch))
}
Expand All @@ -70,7 +70,7 @@ func (s *Server) SignPluginMessages(c echo.Context) error {
}

// Get policy from database
if req.PluginID == vtypes.PluginVultisigFees_feee.String() {
if req.PluginID == types.PluginVultisigFees {
s.logger.Debug("SIGN FEE PLUGIN MESSAGES")
return s.validateAndSign(c, &req, types.FeeDefaultPolicy, uuid.New())
} else {
Expand All @@ -88,7 +88,7 @@ func (s *Server) SignPluginMessages(c echo.Context) error {
}

if !isTrialActive {
filePathName := common.GetVaultBackupFilename(req.PublicKey, vtypes.PluginVultisigFees_feee.String())
filePathName := common.GetVaultBackupFilename(req.PublicKey, types.PluginVultisigFees)
exist, err := s.vaultStorage.Exist(filePathName)
if err != nil {
errMsg := "failed to check vault existence"
Expand All @@ -111,7 +111,7 @@ func (s *Server) SignPluginMessages(c echo.Context) error {
}

// Validate policy matches plugin
if policy.PluginID != vtypes.PluginID(req.PluginID) {
if policy.PluginID != req.PluginID {
return fmt.Errorf("policy plugin ID mismatch")
}

Expand Down Expand Up @@ -243,7 +243,7 @@ func (s *Server) validateAndSign(c echo.Context, req *vtypes.PluginKeysignReques

var matchedRule *rtypes.Rule
//TODO: fee plugin priority for testing purposes
if req.PluginID == vtypes.PluginVultisigFees_feee.String() {
if req.PluginID == types.PluginVultisigFees {
matchedRule, err = ngn.Evaluate(types.FeeDefaultPolicy, firstKeysignMessage.Chain, txBytesEvaluate)
if err != nil {
return s.forbidden(c, msgTxNotAllowed, err)
Expand All @@ -261,7 +261,7 @@ func (s *Server) validateAndSign(c echo.Context, req *vtypes.PluginKeysignReques
toAddress := extractToAddressFromRule(matchedRule)

txToTrack, err := s.txIndexerService.CreateTx(c.Request().Context(), storage.CreateTxDto{
PluginID: vtypes.PluginID(req.PluginID),
PluginID: req.PluginID,
ChainID: firstKeysignMessage.Chain,
PolicyID: policyID,
TokenID: tokenID,
Expand Down Expand Up @@ -373,7 +373,7 @@ func (s *Server) applyImageToPlugin(plugin *types.Plugin, img types.PluginImageR
}

func (s *Server) enrichPluginWithImages(ctx context.Context, plugin *types.Plugin) {
images, err := s.db.GetPluginImagesByPluginIDs(ctx, []vtypes.PluginID{plugin.ID})
images, err := s.db.GetPluginImagesByPluginIDs(ctx, []string{plugin.ID})
if err != nil {
s.logger.WithError(err).Warn("failed to fetch plugin images for enrichment")
return
Expand All @@ -388,7 +388,7 @@ func (s *Server) enrichPluginsWithImages(ctx context.Context, plugins []types.Pl
return
}

pluginIDs := make([]vtypes.PluginID, len(plugins))
pluginIDs := make([]string, len(plugins))
for i, p := range plugins {
pluginIDs[i] = p.ID
}
Expand All @@ -402,9 +402,9 @@ func (s *Server) enrichPluginsWithImages(ctx context.Context, plugins []types.Pl
return
}

imagesByPlugin := make(map[vtypes.PluginID][]types.PluginImageRecord)
imagesByPlugin := make(map[string][]types.PluginImageRecord)
for _, img := range images {
imagesByPlugin[vtypes.PluginID(img.PluginID)] = append(imagesByPlugin[vtypes.PluginID(img.PluginID)], img)
imagesByPlugin[img.PluginID] = append(imagesByPlugin[img.PluginID], img)
}

for i := range plugins {
Expand Down Expand Up @@ -444,7 +444,7 @@ func (s *Server) GetInstalledPlugins(c echo.Context) error {
installed.Plugins = make([]types.Plugin, 0, len(pluginList.Plugins))

for _, plugin := range pluginList.Plugins {
fileName := common.GetVaultBackupFilename(publicKey, string(plugin.ID))
fileName := common.GetVaultBackupFilename(publicKey, plugin.ID)

exist, err := s.vaultStorage.Exist(fileName)
if err != nil {
Expand Down Expand Up @@ -560,7 +560,7 @@ func (s *Server) GetPluginTransactionHistory(c echo.Context) error {
// Filter by specific plugin
txs, totalCount, err = s.txIndexerService.GetByPluginIDAndPublicKey(
c.Request().Context(),
vtypes.PluginID(pluginID),
pluginID,
publicKey,
skip,
take,
Expand Down Expand Up @@ -600,7 +600,7 @@ func (s *Server) buildPluginTitleMap(ctx context.Context, txs []storage.Tx) (map
// Get unique plugin IDs
pluginIDSet := make(map[string]struct{})
for _, tx := range txs {
pluginIDSet[string(tx.PluginID)] = struct{}{}
pluginIDSet[tx.PluginID] = struct{}{}
}

if len(pluginIDSet) == 0 {
Expand Down Expand Up @@ -763,7 +763,7 @@ func (s *Server) GetPluginInstallationsCountByID(c echo.Context) error {
return c.JSON(http.StatusBadRequest, NewErrorResponseWithMessage(msgRequiredPluginID))
}

count, err := s.policyService.GetPluginInstallationsCount(c.Request().Context(), vtypes.PluginID(pluginID))
count, err := s.policyService.GetPluginInstallationsCount(c.Request().Context(), pluginID)
if err != nil {
s.logger.WithError(err).Errorf("Failed to get installation count for pluginId: %s", pluginID)
return c.JSON(http.StatusInternalServerError, NewErrorResponseWithMessage(msgPluginInstallationCountFailed))
Expand Down Expand Up @@ -952,7 +952,7 @@ func (s *Server) ReportPlugin(c echo.Context) error {
reason := p.Sanitize(req.Reason)
details := p.Sanitize(req.Details)

result, err := s.reportService.SubmitReport(c.Request().Context(), vtypes.PluginID(pluginID), publicKey, reason, details)
result, err := s.reportService.SubmitReport(c.Request().Context(), pluginID, publicKey, reason, details)
if err != nil {
if errors.Is(err, service.ErrNotEligible) {
return c.JSON(http.StatusBadRequest, NewErrorResponseWithMessage(msgReportNotEligible))
Expand Down Expand Up @@ -1006,7 +1006,7 @@ func (s *Server) GetAvailablePlugins(c echo.Context) error {
go func(idx int, p types.Plugin) {
defer func() { <-sem }() // release

skills, err := s.pluginService.GetPluginSkills(ctx, string(p.ID))
skills, err := s.pluginService.GetPluginSkills(ctx, p.ID)
if err != nil {
s.logger.WithError(err).Warnf("Plugin %s unavailable, excluding from available list", p.ID)
results <- result{index: idx, success: false}
Expand All @@ -1015,7 +1015,7 @@ func (s *Server) GetAvailablePlugins(c echo.Context) error {
results <- result{
index: idx,
plugin: AvailablePlugin{
ID: string(p.ID),
ID: p.ID,
Name: p.Title,
SkillsMD: skills.SkillsMD,
},
Expand Down
12 changes: 6 additions & 6 deletions internal/api/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"google.golang.org/protobuf/proto"

"github.com/vultisig/verifier/internal/sigutil"
itypes "github.com/vultisig/verifier/internal/types"
"github.com/vultisig/verifier/types"
vtypes "github.com/vultisig/verifier/types"
"github.com/vultisig/vultisig-go/address"
"github.com/vultisig/vultisig-go/common"
)
Expand All @@ -42,7 +42,7 @@ func (s *Server) validatePluginPolicy(ctx context.Context, policy types.PluginPo
return fmt.Errorf("fail to unmarshal recipe: %w", err)
}

spec, err := s.pluginService.GetPluginRecipeSpecification(ctx, policy.PluginID.String())
spec, err := s.pluginService.GetPluginRecipeSpecification(ctx, policy.PluginID)
if err != nil {
return fmt.Errorf("failed to get plugin recipe specification: %w", err)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *Server) CreatePluginPolicy(c echo.Context) error {
}

if !isTrialActive {
filePathName := common.GetVaultBackupFilename(publicKey, vtypes.PluginVultisigFees_feee.String())
filePathName := common.GetVaultBackupFilename(publicKey, itypes.PluginVultisigFees)
exist, err := s.vaultStorage.Exist(filePathName)
if err != nil {
s.logger.WithError(err).Error("failed to check vault existence")
Expand Down Expand Up @@ -151,7 +151,7 @@ func (s *Server) verifyPolicySignature(policy types.PluginPolicy) bool {
s.logger.WithError(err).Error("failed to decode signature bytes")
return false
}
vault, err := s.getVault(policy.PublicKey, policy.PluginID.String())
vault, err := s.getVault(policy.PublicKey, policy.PluginID)
if err != nil {
s.logger.WithError(err).Error("fail to get vault")
return false
Expand Down Expand Up @@ -227,7 +227,7 @@ func (s *Server) UpdatePluginPolicyById(c echo.Context) error {
}

if *r == types.DeactivationReasonPluginPause {
err := s.safetyMgm.EnforceKeysign(c.Request().Context(), string(oldPolicy.PluginID))
err := s.safetyMgm.EnforceKeysign(c.Request().Context(), oldPolicy.PluginID)
if err != nil {
return c.JSON(http.StatusLocked, NewErrorResponseWithMessage(msgPluginPaused))
}
Expand Down Expand Up @@ -362,7 +362,7 @@ func (s *Server) GetAllPluginPolicies(c echo.Context) error {
take = 100
}

policies, err := s.policyService.GetPluginPolicies(c.Request().Context(), publicKey, vtypes.PluginID(pluginID), take, skip, activeFilter)
policies, err := s.policyService.GetPluginPolicies(c.Request().Context(), publicKey, pluginID, take, skip, activeFilter)
if err != nil {
s.logger.WithError(err).Errorf("Failed to get policies for public_key: %s", publicKey)
return c.JSON(http.StatusInternalServerError, NewErrorResponseWithMessage(msgPoliciesGetFailed))
Expand Down
13 changes: 7 additions & 6 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/vultisig/verifier/internal/storage"
"github.com/vultisig/verifier/internal/storage/postgres"
"github.com/vultisig/verifier/internal/syncer"
itypes "github.com/vultisig/verifier/internal/types"
"github.com/vultisig/verifier/plugin/tasks"
"github.com/vultisig/verifier/plugin/tx_indexer"
vtypes "github.com/vultisig/verifier/types"
Expand Down Expand Up @@ -292,7 +293,7 @@ func (s *Server) ReshareVault(c echo.Context) error {
// notifyPluginServerReshare sends the reshare request to the plugin server
func (s *Server) notifyPluginServerReshare(ctx context.Context, req vtypes.ReshareRequest) error {
// Look up plugin server endpoint
plugin, err := s.db.FindPluginById(ctx, nil, vtypes.PluginID(req.PluginID))
plugin, err := s.db.FindPluginById(ctx, nil, req.PluginID)
if err != nil {
return fmt.Errorf("failed to find plugin: %w", err)
}
Expand Down Expand Up @@ -654,13 +655,13 @@ func (s *Server) GetActiveTokens(c echo.Context) error {
}

// notifyPluginServerDeletePlugin user would like to delete a plugin, we need to notify the plugin server
func (s *Server) notifyPluginServerDeletePlugin(ctx context.Context, id vtypes.PluginID, publicKeyEcdsa string) error {
func (s *Server) notifyPluginServerDeletePlugin(ctx context.Context, id string, publicKeyEcdsa string) error {
// Look up plugin server endpoint
plugin, err := s.db.FindPluginById(ctx, nil, id)
if err != nil {
return fmt.Errorf("failed to find plugin: %w", err)
}
keyInfo, err := s.db.GetAPIKeyByPluginId(ctx, id.String())
keyInfo, err := s.db.GetAPIKeyByPluginId(ctx, id)
if err != nil {
return fmt.Errorf("failed to get api key by id: %w", err)
}
Expand Down Expand Up @@ -705,16 +706,16 @@ func (s *Server) DeletePlugin(c echo.Context) error {
if !ok || publicKey == "" {
return c.JSON(http.StatusInternalServerError, NewErrorResponseWithMessage(msgVaultPublicKeyGetFailed))
}
if pluginID == vtypes.PluginVultisigFees_feee.String() {
if pluginID == itypes.PluginVultisigFees {
return c.JSON(http.StatusForbidden, NewErrorResponseWithMessage("Unable to uninstall due to outstanding fees"))
}

if err := s.notifyPluginServerDeletePlugin(c.Request().Context(), vtypes.PluginID(pluginID), publicKey); err != nil {
if err := s.notifyPluginServerDeletePlugin(c.Request().Context(), pluginID, publicKey); err != nil {
s.logger.WithError(err).Errorf("Failed to notify plugin server for deletion of plugin %s", pluginID)
return c.JSON(http.StatusServiceUnavailable, NewErrorResponseWithMessage(msgPluginServerUnavailable))
}
// remove plugin policies
if err := s.policyService.DeleteAllPolicies(c.Request().Context(), vtypes.PluginID(pluginID), publicKey); err != nil {
if err := s.policyService.DeleteAllPolicies(c.Request().Context(), pluginID, publicKey); err != nil {
s.logger.Errorf("Failed to delete plugin policies: %v", err)
return c.JSON(http.StatusInternalServerError, NewErrorResponseWithMessage(msgPoliciesDeleteFailed))
}
Expand Down
8 changes: 4 additions & 4 deletions internal/fee_manager/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func (s *FeeManagementService) HandleReshareDKLS(ctx context.Context, t *asynq.T
return fmt.Errorf("json.Unmarshal failed: %v: %w", err, asynq.SkipRetry)
}

if err := s.RegisterInstallation(ctx, vtypes.PluginID(req.PluginID), req.PublicKey); err != nil {
if err := s.RegisterInstallation(ctx, req.PluginID, req.PublicKey); err != nil {
s.logger.WithError(err).Error("s.RegisterInstallation failed")
return fmt.Errorf("s.RegisterInstallation failed: %v: %w", err, asynq.SkipRetry)
}

return nil
}

func (s *FeeManagementService) RegisterInstallation(ctx context.Context, pluginID vtypes.PluginID, publicKey string) error {
func (s *FeeManagementService) RegisterInstallation(ctx context.Context, pluginID string, publicKey string) error {
return s.db.WithTransaction(ctx, func(ctx context.Context, tx pgx.Tx) error {
pluginInfo, err := s.db.FindPluginById(ctx, tx, pluginID)
if err != nil {
Expand All @@ -79,13 +79,13 @@ func (s *FeeManagementService) RegisterInstallation(ctx context.Context, pluginI
}

_, err = s.db.InsertFee(ctx, tx, &vtypes.Fee{
PluginID: pluginID.String(),
PluginID: pluginID,
PublicKey: publicKey,
TxType: vtypes.TxTypeDebit,
Amount: installationFee,
FeeType: vtypes.FeeTypeInstallationFee,
UnderlyingType: "plugin",
UnderlyingID: pluginID.String(),
UnderlyingID: pluginID,
})
if err != nil {
return err
Expand Down
Loading
Loading