Skip to content

Commit

Permalink
dleq check for marshall
Browse files Browse the repository at this point in the history
  • Loading branch information
lescuer97 committed Jan 31, 2025
1 parent 89be2e7 commit 5035677
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/cashu/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ type RecoverSigDB struct {
B_ string `json:"B_" db:"B_"`
C_ string `json:"C_" db:"C_"`
CreatedAt int64 `json:"created_at" db:"created_at"`
Dleq *BlindSignatureDLEQ `json:"dleq"`
Dleq *BlindSignatureDLEQ `json:"dleq,omitempty"`
}

func (r RecoverSigDB) GetSigAndMessage() (BlindSignature, BlindedMessage) {
Expand All @@ -565,6 +565,7 @@ func (r RecoverSigDB) GetBlindSignature() BlindSignature {
Amount: r.Amount,
Id: r.Id,
C_: r.C_,
Dleq: r.Dleq,
}
}

Expand Down Expand Up @@ -614,6 +615,12 @@ func (b *BlindSignatureDLEQ) UnmarshalJSON(data []byte) error {
}

func (b *BlindSignatureDLEQ) MarshalJSON() ([]byte, error) {
if b == nil {
return []byte("null"), nil
}
if b.E == nil || b.S == nil {
return []byte("null"), nil
}

return json.Marshal(&struct {
E string `json:"e"` // We want to encode the E as a string
Expand Down
5 changes: 5 additions & 0 deletions internal/database/postgresql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ func privateKeysToDleq(s_key *string, e_key *string, dleq *cashu.BlindSignatureD
if s_key == nil || e_key == nil {
return nil
}
if *s_key == "" || *e_key == "" {
return nil
}

sBytes, err := hex.DecodeString(*s_key)
if err != nil {
return errors.New("failed to decode 's' field")
Expand Down Expand Up @@ -398,6 +402,7 @@ func (pql Postgresql) GetRestoreSigsFromBlindedMessages(B_ []string) ([]cashu.Re
if err != nil {
return nil, databaseError(fmt.Errorf("row.Scan(&sig.Amount, &sig.Id, &sig.B_, &sig.C_, &sig.CreatedAt, &sig.Dleq.E, &sig.Dleq.S): %w", err))
}

err = privateKeysToDleq(&dleq_s_str, &dleq_e_str, sig.Dleq)
if err != nil {
return nil, databaseError(fmt.Errorf("privateKeysToDleq(dleq_s_str, dleq_e_str, sig.Dleq). %w", err))
Expand Down

0 comments on commit 5035677

Please sign in to comment.