From c98e80ccc085b5fc87582f8630d8b50f153acdb2 Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Tue, 9 Apr 2024 19:22:47 +0200 Subject: seal: added verifier of descriptions --- auction.go | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/auction.go b/auction.go index 78b9af6..df1d372 100644 --- a/auction.go +++ b/auction.go @@ -1,9 +1,14 @@ package seal import ( - "crypto" - "net/url" + "bytes" + "crypto/ed25519" + "crypto/sha512" + "encoding/base32" + "encoding/json" "time" + + "kesim.org/seal/nizk/commit" ) type Type int @@ -16,33 +21,54 @@ const ( // Auction describes the asset of an auction and other // relevant meta-data type Description struct { - DashboardUrl *url.URL // can be empty 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 crypto.PublicKey // Public key of the Seller + 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. -// TODO(oec): normalized? -type SignedDesciption struct { +type SignedDescription struct { Description - SellerSignature string + SellerSignature []byte } // Auction is the simple interface for the engine type Auction interface { - Join(bidder Bidder) - Received(msg []byte) error + 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() - Send(msg []byte, sig []byte) error + 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 +} \ No newline at end of file -- cgit v1.2.3