From b0e4bd2afa2bad6e2ff741c8eb3719218eb0ddde Mon Sep 17 00:00:00 2001 From: Stefan Liu Date: Mon, 11 Sep 2023 17:34:33 +0800 Subject: [PATCH 1/3] Add store raw key option for createaccount --- main.go | 4 ++-- relayer/cmd.go | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) 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) From da7ecc8fa1bd1ab19f0375c0e79d825fa4ceeedb Mon Sep 17 00:00:00 2001 From: Stefan Liu Date: Wed, 13 Sep 2023 16:19:45 +0800 Subject: [PATCH 2/3] Add docker build support --- Dockerfile | 12 ++++++++++++ Makefile | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bf9ffa6 --- /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 From e881f521e4ad46eefda0458d00385b8b00bfe269 Mon Sep 17 00:00:00 2001 From: Stefan Liu Date: Wed, 13 Sep 2023 16:28:22 +0800 Subject: [PATCH 3/3] Fix network var --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bf9ffa6..4d27156 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,4 @@ COPY go.mod go.sum ./ COPY . ./ RUN go mod download -RUN go build -tags ${network}} -o server . \ No newline at end of file +RUN go build -tags ${network} -o server . \ No newline at end of file