Skip to content

Commit

Permalink
feat!: EdDSA key export [SIGNER-97] (#15)
Browse files Browse the repository at this point in the history
* feat: EdDSA key export [SIGNER-97]

* chore: add test for EdDSA export

* chore: bump version v5.0.0

* chore: update readme & clarify

* chore: printf/println newlines

* chore: remove useless printer

* chore: update PULL_REQUEST_TEMPLATE

* chore: render Ethereum address in ERC-55 format

* chore(go.mod): remove toolchain line

* fix: left pad big.Int Bytes() to 32 bytes

* chore: add code copyright headers

* chore: small edit CLI help text

* chore: add tests for leftPadTo32Bytes

* chore: small edit CLI help text

* chore: refactor basic file structure

* chore: split big files

* chore: rename files.go -> ui_validate.go

* chore: reorg more files

* chore: more fs restructuring
  • Loading branch information
notatestuser authored Nov 26, 2024
1 parent 6bcd400 commit b0d2ba4
Show file tree
Hide file tree
Showing 20 changed files with 911 additions and 566 deletions.
8 changes: 2 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fix: Some thing does not crash anymore [VAULT-111]
feat: Some new fancy feature [VAULT-111]
```

[VAULT-111](https://iofinnet.atlassian.net/browse/VAULT-111)
[SIGNER-111](https://iofinnet.atlassian.net/browse/SIGNER-111)

### Description:

Expand Down Expand Up @@ -33,8 +33,4 @@ feat: Some new fancy feature [VAULT-111]

- [ ] Tests added or updated
- [ ] Readme updated
- [ ] Public API Documentation updates

### REMEMBER: Steps after deployment

- [ ] When the GQL schema changes, it must be merged in the supergraph schema in Appsync: [steps to do it](https://github.com/IoFinnet/io-vault-cldsvc-gql-backend)
- [ ] [Docs](https://github.com/IoFinnet/public-api-docs) updated
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ After syncing up the chain (may take a while), Electrum should show your balance
### Tron Recovery

Please use [TronLink](https://www.tronlink.org) to recover Tron and Tron assets. [Follow this guide](https://support.tronlink.org/hc/en-us/articles/5982285631769-How-to-Import-Your-Account-in-TronLink-Wallet-Extension) and import your vault's private key output by the tool.

### Others (XRPL, SOL, TON, TAO, etc.)

Use the EdDSA key output for these chains that use EdDSA (Edwards / Ed25519) keys.
23 changes: 13 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module github.com/IoFinnet/io-vault-disaster-recovery-cli

go 1.21
go 1.22

require (
github.com/binance-chain/tss-lib v1.3.3
github.com/charmbracelet/huh v0.6.0
github.com/charmbracelet/lipgloss v0.13.0
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/ethereum/go-ethereum v1.14.0
github.com/ethereum/go-ethereum v1.14.12
github.com/google/uuid v1.3.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/crypto v0.22.0
)
Expand All @@ -20,7 +21,7 @@ require (
github.com/agl/ed25519 v0.0.0-20200305024217-f36fc4b53d43 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/bubbles v0.20.0 // indirect
Expand All @@ -30,17 +31,20 @@ require (
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand All @@ -55,15 +59,14 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/otiai10/primes v0.0.0-20210501021515-f1b2be525a11 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/supranational/blst v0.3.13 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/protobuf v1.34.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Expand Down
81 changes: 27 additions & 54 deletions go.sum

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (C) 2021 io finnet group, inc.
// SPDX-License-Identifier: AGPL-3.0-or-later
// Full license text available in LICENSE file in repository root.

package config

type AppConfig struct {
Filenames []string
NonceOverride int
QuorumOverride int
ExportKSFile string
PasswordForKS string
}
10 changes: 7 additions & 3 deletions inflate.go → internal/data/data.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package main
// Copyright (C) 2021 io finnet group, inc.
// SPDX-License-Identifier: AGPL-3.0-or-later
// Full license text available in LICENSE file in repository root.

package data

import (
"bytes"
Expand All @@ -19,8 +23,8 @@ const deflateCommonJSONDict = `null` +
`Anomalous` + `M-221` + `E-222` + `M-511` + `E-521` + `NIST P-224` + `Curve1174` + `curve25519` + `BN(2,254)` + `brainpoolP256t1` + `ANSSI` + `FRP256v1` + `NIST P-256` + `E-382` + `M-383` + `Curve383187` + `brainpoolP384t1` + `NIST P-384` + `Curve41417` + `Ed448-Goldilocks` +
`LocalSecrets` + `LocalPreParams`

// inflateSaveDataJSON decompresses TSS save data in JSON format using the DEFLATE algorithm using a custom dictionary.
func inflateSaveDataJSON(compressed []byte) ([]byte, error) {
// InflateSaveDataJSON decompresses TSS save data in JSON format using the DEFLATE algorithm using a custom dictionary.
func InflateSaveDataJSON(compressed []byte) ([]byte, error) {
reader := flate.NewReaderDict(bytes.NewReader(compressed), []byte(deflateCommonJSONDict))
decompressed, err := io.ReadAll(reader)
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2021 io finnet group, inc.
// SPDX-License-Identifier: AGPL-3.0-or-later
// Full license text available in LICENSE file in repository root.

package ui

import (
"fmt"
)

const (
WORDS = 24
)

var (
// ANSI escape seqs for colours in the terminal
AnsiCodes = map[string]string{
"bold": "\033[1m",
"invertOn": "\033[7m",
"darkRedBG": "\033[41m",
"darkGreenBG": "\033[42m",
"reset": "\033[0m",
}
)

func Banner() string {
b := "\n"
b += fmt.Sprintf("%s%s %s\n", AnsiCodes["invertOn"], AnsiCodes["bold"], AnsiCodes["reset"])
b += fmt.Sprintf("%s%s io.finnet Key Recovery Tool %s\n", AnsiCodes["invertOn"], AnsiCodes["bold"], AnsiCodes["reset"])
b += fmt.Sprintf("%s%s v5.0.0 %s\n", AnsiCodes["invertOn"], AnsiCodes["bold"], AnsiCodes["reset"])
b += fmt.Sprintf("%s%s %s\n", AnsiCodes["invertOn"], AnsiCodes["bold"], AnsiCodes["reset"])
b += "\n"
return b
}

func ErrorBox(err error) string {
b := "\n"
b += fmt.Sprintf("%s%s %s\n", AnsiCodes["darkRedBG"], AnsiCodes["bold"], AnsiCodes["reset"])
b += fmt.Sprintf("%s%s Error %s %s.\n", AnsiCodes["darkRedBG"], AnsiCodes["bold"], AnsiCodes["reset"], err)
b += fmt.Sprintf("%s%s %s\n", AnsiCodes["darkRedBG"], AnsiCodes["bold"], AnsiCodes["reset"])
b += "\n"
return b
}
30 changes: 21 additions & 9 deletions user_input.go → internal/ui/ui_input.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
package main
// Copyright (C) 2021 io finnet group, inc.
// SPDX-License-Identifier: AGPL-3.0-or-later
// Full license text available in LICENSE file in repository root.

package ui

import (
"fmt"

"github.com/IoFinnet/io-vault-disaster-recovery-cli/internal/config"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/list"
errors2 "github.com/pkg/errors"
)

/**
* mnemmonicsFormModel is a struct that represents the model for the mnemonics entry.
*/
type mnemonicsFormModel struct {
filenames []string
}
type (
VaultsDataFile struct {
File string
Mnemonics string
}

/**
* mnemmonicsFormModel is a struct that represents the model for the mnemonics entry.
*/
mnemonicsFormModel struct {
filenames []string
}
)

func NewMnemonicsForm(config AppConfig) mnemonicsFormModel {
func NewMnemonicsForm(config config.AppConfig) mnemonicsFormModel {
return mnemonicsFormModel{
filenames: config.filenames,
filenames: config.Filenames,
}
}

Expand Down
17 changes: 8 additions & 9 deletions vaults_data_files.go → internal/ui/ui_validate.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package main
// Copyright (C) 2021 io finnet group, inc.
// SPDX-License-Identifier: AGPL-3.0-or-later
// Full license text available in LICENSE file in repository root.

package ui

import (
"os"
"strings"

"github.com/IoFinnet/io-vault-disaster-recovery-cli/internal/config"
errors2 "github.com/pkg/errors"
)

type VaultsDataFile struct {
File string
Mnemonics string
}

func (v VaultsDataFile) ValidateMnemonics() error {
phrase := cleanMnemonicInput(v.Mnemonics)
words := strings.Split(phrase, " ")
Expand All @@ -21,8 +21,8 @@ func (v VaultsDataFile) ValidateMnemonics() error {
return nil
}

func ValidateFiles(appConfig AppConfig) error {
files := appConfig.filenames
func ValidateFiles(appConfig config.AppConfig) error {
files := appConfig.Filenames

// Make sure all files exist, and ensure they're unique
{
Expand All @@ -40,7 +40,6 @@ func ValidateFiles(appConfig AppConfig) error {
}

for _, file := range files {

// read file and basic validate
if _, err := os.Stat(file); err != nil {
return errors2.Errorf("unable to see file `%s` - does it exist?: %s", file, err)
Expand Down
2 changes: 1 addition & 1 deletion base58.go → internal/wif/base58.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package wif

import (
"crypto/sha256"
Expand Down
9 changes: 7 additions & 2 deletions wif.go → internal/wif/wif.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package main
// Copyright (C) 2021 io finnet group, inc.
// SPDX-License-Identifier: AGPL-3.0-or-later
// Full license text available in LICENSE file in repository root.

func toBitcoinWIF(privKey []byte, testNet, compressed bool) string {
package wif

// ToBitcoinWIF converts a private key to Bitcoin Wallet Import Format (WIF)
func ToBitcoinWIF(privKey []byte, testNet, compressed bool) string {
if compressed {
// Append 0x01 to tell Bitcoin wallet to use compressed public keys
privKey = append(privKey, []byte{0x01}...)
Expand Down
Loading

0 comments on commit b0d2ba4

Please sign in to comment.