aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2024-04-09 19:22:47 +0200
committerÖzgür Kesim <oec@codeblau.de>2024-04-09 19:22:47 +0200
commitc98e80ccc085b5fc87582f8630d8b50f153acdb2 (patch)
treea99ad8780149b60d9a8eeb75caab4a9254c30459
parentd7277eca5c0171744fd6fb479604e53b89896387 (diff)
seal: added verifier of descriptions
-rw-r--r--auction.go46
1 files 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