Skip to content

Commit

Permalink
fixes on things that were not compiling on go build ./...
Browse files Browse the repository at this point in the history
  • Loading branch information
mleku committed Nov 28, 2024
1 parent 50bdee3 commit 1434e3c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 38 deletions.
15 changes: 7 additions & 8 deletions ec/secp256k1/precomps/genprecomps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package main

import (
"fmt"
"log"
"math/big"
"os"

Expand All @@ -28,9 +27,8 @@ func bigAffineToJacobian(x, y *big.Int, result *secp256k1.JacobianPoint) {
result.Z.SetInt(1)
}

// serializedBytePoints returns a serialized byte slice which contains all of
// the possible points per 8-bit window. This is used to when generating
// compressedbytepoints.go.
// serializedBytePoints returns a serialized byte slice which contains all possible points per
// 8-bit window. This is used to when generating compressedbytepoints.go.
func serializedBytePoints() []byte {
// Calculate G^(2^i) for i in 0..255. These are used to avoid recomputing
// them for each digit of the 8-bit windows.
Expand Down Expand Up @@ -310,11 +308,12 @@ func main() {
os.Exit(1)
}
serialized := serializedBytePoints()
embeded, err := os.Create("secp256k1/rawbytepoints.bin")
embedded, err := os.Create("secp256k1/rawbytepoints.bin")
if err != nil {
log.Fatal(err)
log.F.Ln(err)
os.Exit(1)
}
n, err := embeded.Write(serialized)
n, err := embedded.Write(serialized)
if err != nil {
panic(err)
}
Expand All @@ -323,5 +322,5 @@ func main() {
n, len(serialized))
panic("fail")
}
_ = embeded.Close()
_ = embedded.Close()
}
21 changes: 21 additions & 0 deletions ec/secp256k1/precomps/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"bytes"

"realy.lol/context"
"realy.lol/lol"
)

type (
B = []byte
S = string
E = error
N = int
Ctx = context.T
)

var (
log, chk, errorf = lol.Main.Log, lol.Main.Check, lol.Main.Errorf
equals = bytes.Equal
)
41 changes: 24 additions & 17 deletions keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,50 @@ package keys
import (
"strings"

btcec "realy.lol/ec"
"realy.lol/ec/schnorr"
"realy.lol/hex"
"realy.lol/p256k"
)

var GeneratePrivateKey = func() B { return GenerateSecretKeyHex() }
// GeneratePrivateKey - deprecated, use GenerateSecretKeyHex
var GeneratePrivateKey = func() S { return GenerateSecretKeyHex() }

func GenerateSecretKeyHex() (sks B) {
var err E
var skb B
func GenerateSecretKey() (skb B, err E) {
signer := &p256k.Signer{}
if err = signer.Generate(); chk.E(err) {
return
}
skb = signer.Sec()
sks = B(hex.Enc(skb))
return
}

func GetPublicKeyHex(sk S) (S, E) {
b, err := hex.Dec(sk)
func GenerateSecretKeyHex() (sks S) {
skb, err := GenerateSecretKey()
if chk.E(err) {
return "", err
return
}
_, pk := btcec.PrivKeyFromBytes(b)
return hex.Enc(schnorr.SerializePubKey(pk)), nil
return hex.Enc(skb)
}

func SecretBytesToPubKeyHex(skb B) (pk S, err E) {
_, pkk := btcec.SecKeyFromBytes(skb)
return hex.Enc(schnorr.SerializePubKey(pkk)), nil
func GetPublicKeyHex(sk S) (pk S, err E) {
var b B
if b, err = hex.Dec(sk); chk.E(err) {
return
}
signer := &p256k.Signer{}
if err = signer.InitSec(b); chk.E(err) {
return
}

return hex.Enc(signer.Pub()), nil
}

func SecretToPubKeyBytes(skb B) (pk B, err E) {
_, pkk := btcec.SecKeyFromBytes(skb)
return schnorr.SerializePubKey(pkk), nil
func SecretBytesToPubKeyHex(skb B) (pk S, err E) {
signer := &p256k.Signer{}
if err = signer.InitSec(skb); chk.E(err) {
return
}
return hex.Enc(signer.Pub()), nil
}

func IsValid32ByteHex(pk string) bool {
Expand Down
22 changes: 13 additions & 9 deletions layer2/badgerbadger/tester/badgerbadger.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package main

import (
"lukechampine.com/frand"
"os"
"sync"
"time"

"lukechampine.com/frand"

"realy.lol/bech32encoding"
"realy.lol/context"
"realy.lol/event"
Expand All @@ -16,8 +20,6 @@ import (
"realy.lol/tag"
"realy.lol/tests"
"realy.lol/units"
"sync"
"time"
)

type Counter struct {
Expand All @@ -43,15 +45,17 @@ func main() {
// fill rate capped to size of difference between high and low water mark
diff = TotalSize * units.Gb * (HW - LW) / 100
)
sec = keys.GenerateSecretKeyHex()
if sec, err = keys.GenerateSecretKey(); chk.E(err) {
panic(err)
}
var nsec B
if nsec, err = bech32encoding.HexToNsec(sec); chk.E(err) {
panic(err)
}
log.T.Ln("signing with", nsec)
c, cancel := context.Cancel(context.Bg())
var wg sync.WaitGroup
//defer cancel()
// defer cancel()
// create L1 with cache management settings enabled; we do it in the current dir
// because os.TempDir can point to a ramdisk which is very impractical for this
// test.
Expand All @@ -62,7 +66,7 @@ func main() {
// create L2 with no cache management
b2 := ratel.GetBackend(c, &wg, false, units.Gb, lol.Trace, 4*units.Mb)
// Respond to interrupt signal and clean up after interrupt or end of test.
//defer chk.E(os.RemoveAll(path))
// defer chk.E(os.RemoveAll(path))
interrupt.AddHandler(func() {
cancel()
chk.E(os.RemoveAll(path))
Expand All @@ -78,7 +82,7 @@ func main() {
os.Exit(1)
}
// start GC
//go b1.GarbageCollector()
// go b1.GarbageCollector()
end:
for {
select {
Expand Down Expand Up @@ -126,9 +130,9 @@ end:
sum += counter[i].size
}
}
//if len(fetchIDs) > 0 {
// if len(fetchIDs) > 0 {
// log.T.Ln("fetchIDs", len(fetchIDs), fetchIDs)
//}
// }
mx.Unlock()
case <-ticker.C:
// copy out current list of events to request
Expand Down
6 changes: 2 additions & 4 deletions tests/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"

"lukechampine.com/frand"

"realy.lol/event"
"realy.lol/kind"
"realy.lol/p256k"
Expand All @@ -21,14 +22,11 @@ func GenerateEvent(maxSize int) (ev *event.T, binSize int, err E) {
if err = signer.Generate(); chk.E(err) {
return
}
//if err = signer.InitSec(sec); chk.E(err) {
// return
//}
if err = ev.Sign(signer); chk.E(err) {
return
}
var bin []byte
bin, err = ev.MarshalBinary(bin)
bin, err = ev.MarshalJSON(bin)
binSize = len(bin)
return
}

0 comments on commit 1434e3c

Please sign in to comment.