aboutsummaryrefslogtreecommitdiff
path: root/bidder/bid.go
blob: 5aa27c2ac95b970a29131a9032b026fe7dfc1cbc (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
package bidder

import (
	"crypto/ed25519"
	"fmt"

	"kesim.org/seal"
	. "kesim.org/seal/nizk"

	"kesim.org/seal/nizk/commit"
)

type bid struct {
	id ed25519.PrivateKey
	ID ed25519.PublicKey

	price uint64 // bigendian encoding of the bid
	n     uint8  // number of bits encoded in zbid.

	// bits are derived from zbid and the zero element in
	// the slice corresponds to the highest bit in zbid
	bits []*commit.Statement
}

// NewBid creates a new Bidder for the given price, using the lower bits up to bitlength
func newBid(price uint64, bitlength uint8) (seal.Bidder, error) {
	if bitlength > 63 {
		return nil, fmt.Errorf("bitlength too large, maximum is 63")
	} else if 0 != (price >> bitlength) {
		return nil, fmt.Errorf("price %d too large for given bitlength %d", price, bitlength)
	}

	var (
		e   error
		bid = &bid{
			price: price,
		}
	)

	bid.ID, bid.id, e = ed25519.GenerateKey(nil)
	if e != nil {
		return nil, e
	}

	bid.bits = make([]*commit.Statement, bitlength)
	for i := bitlength; i > 0; i-- {
		set := (price>>(i-1)&1 != 0)
		a, b := Curve.RandomScalar(), Curve.RandomScalar()
		bid.bits[i-1] = commit.NewStatement(a, b, set)
	}

	return bid, nil
}

// Commit returns the public commitment to the bits and a signature
// TODO: return signature over bid
func (bid *bid) Commit() (c []*commit.Commitment, pub ed25519.PublicKey, sig []byte) {
	c = make([]*commit.Commitment, len(bid.bits))
	for i := range bid.bits {
		c[i] = bid.bits[i].Commit()
	}
	return c, bid.ID, nil
}

func (bid *bid) Result() {
}

func (bid *bid) Send(msg []byte, sig []byte) {
}