Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add store raw key option for createaccount #90

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 .
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down
21 changes: 19 additions & 2 deletions relayer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package relayer

import (
"context"
"crypto/ecdsa"
"crypto/md5"
"crypto/rand"
"encoding/hex"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down