aboutsummaryrefslogtreecommitdiff
path: root/bidder/bid.go
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2024-04-07 13:21:53 +0200
committerÖzgür Kesim <oec@codeblau.de>2024-04-07 13:21:53 +0200
commit438b69e74b416918ef855c4a28d90779ea1e455c (patch)
tree7a5d02831cb63ebda981d05b6b9a826fa2bc7596 /bidder/bid.go
parent5733f293044bfe0d3210e7c4688172d53d54a7e0 (diff)
client->bidder
Diffstat (limited to 'bidder/bid.go')
-rw-r--r--bidder/bid.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/bidder/bid.go b/bidder/bid.go
new file mode 100644
index 0000000..5aa27c2
--- /dev/null
+++ b/bidder/bid.go
@@ -0,0 +1,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) {
+} \ No newline at end of file