This repository has been archived by the owner on May 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from vegaprotocol/develop
release v0.2.0
- Loading branch information
Showing
43 changed files
with
1,537 additions
and
864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master, develop ] | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.13 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Tests | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
# Sequence of patterns matched against refs/tags | ||
tags: | ||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.13 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
- name: Tests | ||
run: go test -v ./... | ||
|
||
- name: Build | ||
run: make release | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: build/* | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Vega | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/http/httputil" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
type consoleProxy struct { | ||
log *zap.Logger | ||
port int | ||
consoleURL string | ||
s *http.Server | ||
} | ||
|
||
func newConsoleProxy(log *zap.Logger, port int, consoleURL string) *consoleProxy { | ||
return &consoleProxy{ | ||
log: log, | ||
port: port, | ||
consoleURL: consoleURL, | ||
} | ||
} | ||
|
||
func (c *consoleProxy) Start() error { | ||
proxy := httputil.ReverseProxy{ | ||
Director: func(req *http.Request) { | ||
req.URL.Scheme = "https" | ||
req.URL.Host = c.consoleURL | ||
req.Host = c.consoleURL | ||
}, | ||
} | ||
consoleProxyAddr := fmt.Sprintf("localhost:%v", c.port) | ||
c.s = &http.Server{ | ||
Addr: consoleProxyAddr, | ||
Handler: &proxy, | ||
} | ||
|
||
c.log.Info("starting console proxy", | ||
zap.String("proxy.address", consoleProxyAddr), | ||
zap.String("address", c.consoleURL), | ||
) | ||
return c.s.ListenAndServe() | ||
} | ||
|
||
func (c *consoleProxy) Stop() error { | ||
return c.s.Shutdown(context.Background()) | ||
} | ||
|
||
func (c *consoleProxy) GetBrowserURL() string { | ||
return fmt.Sprintf("http://localhost:%v", c.port) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"code.vegaprotocol.io/go-wallet/fsutil" | ||
"code.vegaprotocol.io/go-wallet/wallet" | ||
"code.vegaprotocol.io/go-wallet/wallet/crypto" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
genkeyArgs struct { | ||
walletOwner string | ||
passphrase string | ||
} | ||
|
||
// genkeyCmd represents the genkey command | ||
genkeyCmd = &cobra.Command{ | ||
Use: "genkey", | ||
Short: "Generate a new keypair for a wallet", | ||
Long: "Generate a new keypair for a wallet, this will implicitly generate a new wallet if none exist for the given name", | ||
RunE: runGenkey, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(genkeyCmd) | ||
genkeyCmd.Flags().StringVarP(&genkeyArgs.walletOwner, "name", "n", "", "Name of the wallet to use") | ||
genkeyCmd.Flags().StringVarP(&genkeyArgs.passphrase, "passphrase", "p", "", "Passphrase to access the wallet") | ||
} | ||
|
||
func runGenkey(cmd *cobra.Command, args []string) error { | ||
if len(genkeyArgs.walletOwner) <= 0 { | ||
return errors.New("wallet name is required") | ||
} | ||
if len(genkeyArgs.passphrase) <= 0 { | ||
var err error | ||
genkeyArgs.passphrase, err = promptForPassphrase() | ||
if err != nil { | ||
return fmt.Errorf("could not get passphrase: %v", err) | ||
} | ||
} | ||
|
||
if ok, err := fsutil.PathExists(rootArgs.rootPath); !ok { | ||
if _, ok := err.(*fsutil.PathNotFound); !ok { | ||
return fmt.Errorf("invalid root directory path: %v", err) | ||
} | ||
// create the folder | ||
if err := fsutil.EnsureDir(rootArgs.rootPath); err != nil { | ||
return fmt.Errorf("error creating root directory: %v", err) | ||
} | ||
} | ||
|
||
if err := wallet.EnsureBaseFolder(rootArgs.rootPath); err != nil { | ||
return fmt.Errorf("unable to initialization root folder: %v", err) | ||
} | ||
|
||
_, err := wallet.Read(rootArgs.rootPath, genkeyArgs.walletOwner, genkeyArgs.passphrase) | ||
if err != nil { | ||
if err != wallet.ErrWalletDoesNotExists { | ||
// this an invalid key, returning error | ||
return fmt.Errorf("unable to decrypt wallet: %v", err) | ||
} | ||
// wallet do not exit, let's try to create it | ||
_, err = wallet.Create(rootArgs.rootPath, genkeyArgs.walletOwner, genkeyArgs.passphrase) | ||
if err != nil { | ||
return fmt.Errorf("unable to create wallet: %v", err) | ||
} | ||
} | ||
|
||
// at this point we have a valid wallet | ||
// let's generate the keypair | ||
// defaulting to ed25519 for now | ||
algo := crypto.NewEd25519() | ||
kp, err := wallet.GenKeypair(algo.Name()) | ||
if err != nil { | ||
return fmt.Errorf("unable to generate new key pair: %v", err) | ||
} | ||
|
||
// now updating the wallet and saving it | ||
_, err = wallet.AddKeypair(kp, rootArgs.rootPath, genkeyArgs.walletOwner, genkeyArgs.passphrase) | ||
if err != nil { | ||
return fmt.Errorf("unable to add keypair to wallet: %v", err) | ||
} | ||
|
||
// print the new keys for user info | ||
fmt.Printf("new generated keys:\n") | ||
fmt.Printf("public: %v\n", kp.Pub) | ||
fmt.Printf("private: %v\n", kp.Priv) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"code.vegaprotocol.io/go-wallet/fsutil" | ||
"code.vegaprotocol.io/go-wallet/wallet" | ||
|
||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
) | ||
|
||
var ( | ||
initArgs struct { | ||
force bool | ||
genRsaKey bool | ||
} | ||
|
||
// initCmd represents the init command | ||
initCmd = &cobra.Command{ | ||
Use: "init", | ||
Short: "Generate the configuration", | ||
Long: "Generate the configuration for the wallet service", | ||
RunE: runServiceInit, | ||
} | ||
) | ||
|
||
func init() { | ||
serviceCmd.AddCommand(initCmd) | ||
initCmd.Flags().BoolVarP(&initArgs.force, "force", "f", false, "Erase exiting wallet service configuration at the specified path") | ||
initCmd.Flags().BoolVarP(&initArgs.genRsaKey, "genrsakey", "g", false, "Generate rsa keys for the jwt tokens") | ||
} | ||
|
||
func runServiceInit(cmd *cobra.Command, args []string) error { | ||
if ok, err := fsutil.PathExists(rootArgs.rootPath); !ok { | ||
if _, ok := err.(*fsutil.PathNotFound); !ok { | ||
return fmt.Errorf("invalid root directory path: %v", err) | ||
} | ||
// create the folder | ||
if err := fsutil.EnsureDir(rootArgs.rootPath); err != nil { | ||
return fmt.Errorf("error creating root directory: %v", err) | ||
} | ||
} | ||
|
||
log, err := zap.NewProduction() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return wallet.GenConfig(log, rootArgs.rootPath, initArgs.force, initArgs.genRsaKey) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
|
||
"code.vegaprotocol.io/go-wallet/fsutil" | ||
"code.vegaprotocol.io/go-wallet/wallet" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
listArgs struct { | ||
walletOwner string | ||
passphrase string | ||
} | ||
|
||
// listCmd represents the list command | ||
listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List keypairs of a wallet", | ||
Long: "List all the keypairs for a given wallet", | ||
RunE: runList, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(listCmd) | ||
listCmd.Flags().StringVarP(&listArgs.walletOwner, "name", "n", "", "Name of the wallet to use") | ||
listCmd.Flags().StringVarP(&listArgs.passphrase, "passphrase", "p", "", "Passphrase to access the wallet") | ||
|
||
} | ||
|
||
func runList(cmd *cobra.Command, args []string) error { | ||
if len(listArgs.walletOwner) <= 0 { | ||
return errors.New("wallet name is required") | ||
} | ||
if len(listArgs.passphrase) <= 0 { | ||
var err error | ||
listArgs.passphrase, err = promptForPassphrase() | ||
if err != nil { | ||
return fmt.Errorf("could not get passphrase: %v", err) | ||
} | ||
} | ||
|
||
if ok, err := fsutil.PathExists(rootArgs.rootPath); !ok { | ||
return fmt.Errorf("invalid root directory path: %v", err) | ||
} | ||
|
||
wal, err := wallet.Read(rootArgs.rootPath, listArgs.walletOwner, listArgs.passphrase) | ||
if err != nil { | ||
return fmt.Errorf("unable to decrypt wallet: %v", err) | ||
} | ||
|
||
buf, err := json.MarshalIndent(wal, " ", " ") | ||
if err != nil { | ||
return fmt.Errorf("unable to marshal message: %v", err) | ||
} | ||
|
||
// print the new keys for user info | ||
fmt.Printf("List of all your keypairs:\n") | ||
fmt.Printf("%v\n", string(buf)) | ||
|
||
return nil | ||
} |
Oops, something went wrong.