blob: df1d3729330e1994cab38c4d314579a599fdb01a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
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
}
|