From adc7733dfb06f38b99d134db21197fd24aa29b66 Mon Sep 17 00:00:00 2001 From: asdfsx Date: Wed, 23 Aug 2023 19:02:52 +0800 Subject: [PATCH] add marshalBinary to pedersen.Parameter --- pkg/pedersen/pedersen.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/pedersen/pedersen.go b/pkg/pedersen/pedersen.go index 191ae370..4c5162ea 100644 --- a/pkg/pedersen/pedersen.go +++ b/pkg/pedersen/pedersen.go @@ -5,6 +5,7 @@ import ( "io" "github.com/cronokirby/saferith" + "github.com/fxamacker/cbor/v2" "github.com/taurusgroup/multi-party-sig/internal/params" "github.com/taurusgroup/multi-party-sig/pkg/math/arith" ) @@ -125,3 +126,20 @@ func (p *Parameters) WriteTo(w io.Writer) (int64, error) { func (Parameters) Domain() string { return "Pedersen Parameters" } + +func (p *Parameters) MarshalBinary() ([]byte, error) { + tmp := [3][]byte{p.n.Bytes(), p.s.Bytes(), p.t.Bytes()} + return cbor.Marshal(tmp) +} + +func (p *Parameters) UnmarshalBinary(data []byte) error { + var tmp [3][]byte + err := cbor.Unmarshal(data, &tmp) + if err != nil { + return err + } + p.n = arith.ModulusFromN(saferith.ModulusFromBytes(tmp[0])) + p.s = new(saferith.Nat).SetBytes(tmp[1]) + p.t = new(saferith.Nat).SetBytes(tmp[2]) + return nil +}