Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frost signature MarshalBinary and UnmarshalBinary methods #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions protocols/frost/sign/round3.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (r *round3) Finalize(chan<- *round.Message) (round.Session, error) {
return r.ResultRound(sig), nil
} else {
sig := Signature{
Group: r.Helper.Group(),
R: r.R,
z: z,
}
Expand Down
34 changes: 33 additions & 1 deletion protocols/frost/sign/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package sign

import (
"errors"
"io"

"github.com/fxamacker/cbor/v2"
"github.com/taurusgroup/multi-party-sig/pkg/hash"
"github.com/taurusgroup/multi-party-sig/pkg/math/curve"
"github.com/taurusgroup/multi-party-sig/pkg/math/sample"
Expand All @@ -29,16 +31,24 @@ func (messageHash) Domain() string {
//
// This signature claims to satisfy:
//
// z * G = R + H(R, Y, m) * Y
// z * G = R + H(R, Y, m) * Y
//
// for a public key Y.
type Signature struct {
Group curve.Curve
// R is the commitment point.
R curve.Point
// z is the response scalar.
z curve.Scalar
}

type signatureMarshal struct {
// R is the commitment point.
R curve.Point
// z is the response scalar.
Z curve.Scalar
}

// Verify checks if a signature equation actually holds.
//
// Note that m is the hash of a message, and not the message itself.
Expand All @@ -56,3 +66,25 @@ func (sig Signature) Verify(public curve.Point, m []byte) bool {

return expected.Equal(actual)
}

func (sig *Signature) MarshalBinary() ([]byte, error) {
return cbor.Marshal(&signatureMarshal{
R: sig.R,
Z: sig.z,
})
}

func (sig *Signature) UnmarshalBinary(data []byte) error {
if sig.Group == nil {
return errors.New("can't unmarshal frost signature with no group")
}
sigMarshal := &signatureMarshal{
R: sig.Group.NewPoint(),
Z: sig.Group.NewScalar(),
}
if err := cbor.Unmarshal(data, sigMarshal); err != nil {
return err
}
sig.R, sig.z = sigMarshal.R, sigMarshal.Z
return nil
}