diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4d27156 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1.20-bullseye + +ARG commit=main +ARG network=mainnet + +WORKDIR /workspace + +COPY go.mod go.sum ./ +COPY . ./ + +RUN go mod download +RUN go build -tags ${network} -o server . \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3a0813a --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +# branch/commit_hash/tag to build with containers +COMMIT ?= master +NETWORK ?=mainnet + +.PHONY: clean + +clean: + @echo "Cleaning build artifacts" + rm -rf server + docker container rm -f go-relayer-temp + docker rmi -f go-relayer-build + +build: clean + @echo "Building relayer binary in container with local source files" + docker build --no-cache --build-arg commit=$(COMMIT) -t go-relayer-build . + docker container create --name go-relayer-temp go-relayer-build + docker container cp go-relayer-temp:/workspace/server . + sha256sum server diff --git a/main.go b/main.go index d8eb05c..c7ecd51 100644 --- a/main.go +++ b/main.go @@ -318,8 +318,8 @@ func main() { Required: true, }, &cli.BoolFlag{ - Name: "public", - Usage: "include the public key in the output", + Name: "raw", + Usage: "generate raw key file instead", }, }, }, diff --git a/relayer/cmd.go b/relayer/cmd.go index 9a12955..d5fb8bf 100644 --- a/relayer/cmd.go +++ b/relayer/cmd.go @@ -19,7 +19,9 @@ package relayer import ( "context" + "crypto/ecdsa" "crypto/md5" + "crypto/rand" "encoding/hex" "fmt" "io/ioutil" @@ -447,11 +449,26 @@ func UpdateAccount(ctx *cli.Context) (err error) { func CreateAccount(ctx *cli.Context) (err error) { path := ctx.String("path") - showPublic := ctx.Bool("public") if path == "" { log.Error("Wallet patch can not be empty") return } + + if ctx.Bool("raw") { + privateKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader) + if err != nil { + return err + } + err = crypto.SaveECDSA(path, privateKeyECDSA) + if err != nil { + return err + } + fmt.Printf("Private key saved in %s\n", path) + fmt.Printf("Public key: %x\n", crypto.FromECDSAPub(&privateKeyECDSA.PublicKey)) + fmt.Printf("Address: %s\n", crypto.PubkeyToAddress(privateKeyECDSA.PublicKey).String()) + return nil + } + pass, err := msg.ReadPassword("passphrase") if err != nil { return @@ -465,7 +482,7 @@ func CreateAccount(ctx *cli.Context) (err error) { fmt.Printf("\nYour new key was generated\n\n") fmt.Printf("Address: %s\n", account.Address.Hex()) - if showPublic { + { keyJson, err := os.ReadFile(account.URL.Path) if err != nil { log.Error("Failed to read the keystore", "keystore path", account.URL.Path, "error", err)