mirror of
https://github.com/arnaucube/go-iden3-crypto.git
synced 2026-02-07 11:36:41 +01:00
Add scanner/valuer interface to signature
This commit is contained in:
@@ -2,6 +2,8 @@ package babyjub
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/iden3/go-iden3-crypto/mimc7"
|
||||
"github.com/iden3/go-iden3-crypto/poseidon"
|
||||
@@ -175,6 +177,27 @@ func (s *SignatureComp) Decompress() (*Signature, error) {
|
||||
return new(Signature).Decompress(*s)
|
||||
}
|
||||
|
||||
// Scan implements Scanner for database/sql.
|
||||
func (s *Signature) Scan(src interface{}) error {
|
||||
srcB, ok := src.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("can't scan %T into Signature", src)
|
||||
}
|
||||
if len(srcB) != 64 {
|
||||
return fmt.Errorf("can't scan []byte of len %d into Signature, want %d", len(srcB), 64)
|
||||
}
|
||||
buf := [64]byte{}
|
||||
copy(buf[:], srcB[:])
|
||||
_, err := s.Decompress(buf)
|
||||
return err
|
||||
}
|
||||
|
||||
// Value implements valuer for database/sql.
|
||||
func (s *Signature) Value() (driver.Value, error) {
|
||||
comp := s.Compress()
|
||||
return comp[:], nil
|
||||
}
|
||||
|
||||
// SignMimc7 signs a message encoded as a big.Int in Zq using blake-512 hash
|
||||
// for buffer hashing and mimc7 for big.Int hashing.
|
||||
func (k *PrivateKey) SignMimc7(msg *big.Int) *Signature {
|
||||
|
||||
Reference in New Issue
Block a user