package seal import ( "bytes" "crypto/ed25519" "crypto/sha512" "encoding/base32" "encoding/json" "time" "kesim.org/seal/nizk/commit" ) 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 } // Auction is the simple interface for the engine type Auction interface { Join(bidder Bidder) // A bidder calls this to join the auction Message(msg []byte, sig []byte) error // A bidder uses this method to publish a message } // Bidder is the interface that the Auction engine uses to communicate type Bidder interface { Commitment() *commit.Commitment Start(map[string]*commit.Commitment) Result() Receive(msg []byte) error } 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 }