package seal import ( "bytes" "crypto/ed25519" "crypto/sha512" "encoding/base32" "encoding/json" "time" ) type Type int const ( TypHighest = iota TypSecondHighest ) // Auction describes the asset of an auction and other // relevant meta-data type Description struct { Start time.Time End time.Time RoundTimeout time.Duration // Timeout per round by which all responses must have arrived BitLength uint8 // Length of the price encoding Currency string Type Type SellerPublicKey ed25519.PublicKey // Public key of the Seller } // The SignedAuction contains an Auction and the signature, // signed by the seller's public key off the SHA512 hash of // the normalized JSON-object. type SignedDescription struct { Description SellerSignature []byte } func (sd *SignedDescription) Verify() (bool, error) { // TODO: need to normalize this encoding buf := &bytes.Buffer{} e := json.NewEncoder(buf).Encode(sd.Description) if e != nil { return false, e } r := ed25519.Verify(sd.SellerPublicKey, buf.Bytes(), sd.SellerSignature) return r, nil } func (d *Description) Hash() (hash string, e error) { buf := &bytes.Buffer{} e = json.NewEncoder(buf).Encode(d) if e != nil { return "", e } h := sha512.Sum512(buf.Bytes()) return base32.StdEncoding.EncodeToString(h[:]), nil }