Skip to content

Commit

Permalink
update context
Browse files Browse the repository at this point in the history
  • Loading branch information
suutaku committed Mar 26, 2023
1 parent f7bf0f9 commit d617efd
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions pkg/bbs/blind_signature_context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package bbs

import (
"bytes"
"encoding/json"
"fmt"

"github.com/suutaku/bls12381"
Expand Down Expand Up @@ -55,11 +57,30 @@ func NewBlindSignatureContext(msgs map[int][]byte, generators *PublicKeyWithGene
}

func (bsc *BlindSignatureContext) MarshalJSON() ([]byte, error) {
return bsc.ToBytes(), nil
b := bsc.ToBytes()
buf := bytes.Buffer{}
encoder := json.NewEncoder(&buf)
encoder.SetEscapeHTML(false)
err := encoder.Encode(b)
return buf.Bytes(), err
}

func (bsc *BlindSignatureContext) UnmarshalJSON(input []byte) error {
return bsc.FromBytes(input)
buf := bytes.NewBuffer(input)
tBytes := make([]byte, 0)
err := json.NewDecoder(buf).Decode(&tBytes)
if err != nil {
return err
}
tmp := &BlindSignatureContext{}
err = tmp.FromBytes(tBytes)
if err != nil {
return err
}
bsc.challenge = tmp.challenge
bsc.commitment = tmp.commitment
bsc.proofs = tmp.proofs
return nil
}

func (bsc *BlindSignatureContext) ToBytes() []byte {
Expand Down

0 comments on commit d617efd

Please sign in to comment.