package bidder import ( "fmt" . "kesim.org/seal/nizk" "kesim.org/seal/nizk/commit" ) type bid struct { // TODO: These should probably become ed25519.(Private|Public)Key's id *Scalar Id *Point 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) (*bid, 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) } bid := &bid{ price: price, n: bitlength, } bid.id = Curve.RandomScalar() bid.Id = G.Exp(bid.id) 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) { c = make([]*commit.Commitment, len(bid.bits)) for i := range bid.bits { c[i] = bid.bits[i].Commit(bid.Id) } return c } func (bid *bid) Result() { } func (bid *bid) Send(msg []byte, sig []byte) error { return fmt.Errorf("bidder.Send not implemented") }