Skip to content

Commit

Permalink
rename fn
Browse files Browse the repository at this point in the history
  • Loading branch information
tarassh committed Dec 23, 2024
1 parent b75f8a3 commit da02d92
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
23 changes: 1 addition & 22 deletions internal/light-client/poller/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package poller
import (
"bytes"
"crypto/sha256"
"encoding/base32"
"encoding/binary"
"errors"
"fmt"
"math/big"
"strings"

pb "github.com/covalenthq/das-ipfs-pinner/internal/light-client/schemapb"
"github.com/covalenthq/das-ipfs-pinner/internal/light-client/utils"
Expand All @@ -34,26 +32,7 @@ type Challenge struct {
ClauseType ClauseType
}

// Decode a Base32 encoded string into a Challenge
func Decode(encoded string) (*Challenge, error) {
// Validate the prefix
if !strings.HasPrefix(encoded, "ewm") {
return nil, errors.New("invalid prefix: must start with 'ewm'")
}

// Remove the "ewm" prefix
encodedBody := encoded[3:]

// Decode Base32
decoded, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(strings.ToUpper(encodedBody))
if err != nil {
return nil, fmt.Errorf("failed to decode Base32: %w", err)
}

return DecodeRaw(decoded)
}

func DecodeRaw(data []byte) (*Challenge, error) {
func Decode(data []byte) (*Challenge, error) {
if len(data) < 3 {
return nil, errors.New("invalid challenge length")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/light-client/poller/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (p *WorkloadPoller) periodicPoll() {
// Process the workloads
for _, workload := range response.Workloads {
log.Debugf("processing workload: %v", workload)
challenge, err := DecodeRaw(workload.Workload.Challenge)
challenge, err := Decode(workload.Workload.Challenge)
if err != nil {
log.Errorf("failed to decode challenge: %s", err)
}
Expand Down

0 comments on commit da02d92

Please sign in to comment.