Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontaneousOverthrow committed Nov 22, 2023
1 parent 06773e9 commit 821d900
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 164 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/func-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ jobs:
echo -e "Getting Wallets: ${green}OK${nc}"
for w in $wallets_list; do
accounts=$(ethdo wallet --base-dir "$input_path" accounts --wallet="$w" | tr '\n' ' ')
echo -e "Getting Accounts For [$w]: ${green}OK${nc}"
for a in $accounts; do
input_key=$(ethdo account --base-dir "$input_path" info --account "$w/$a" | grep -i "$input_grep" | awk '{print $NF}')
output_key=$(ethdo account --base-dir "$output_path" info --account "$w/$a" | grep -i "$output_grep" | awk '{print $NF}')
Expand All @@ -81,7 +80,6 @@ jobs:
fi
echo -e "Checking Account [$w/$a]: ${green}OK${nc}"
done;
echo -e "Checking Wallet [$w]: ${green}OK${nc}"
done;
env:
red: '\033[0;31m'
Expand Down
231 changes: 75 additions & 156 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Dirk Key Converter (dkc)

![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/p2p-org/dkc/func-tests.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/p2p-org/dkc)](https://goreportcard.com/report/github.com/p2p-org/dkc)

Transform wallets between [distributed type](https://github.com/wealdtech/go-eth2-wallet-distributed) and [non-deterministic type](https://github.com/wealdtech/go-eth2-wallet-nd).
Convert wallets from [distributed type](https://github.com/wealdtech/go-eth2-wallet-distributed),[non-deterministic type](https://github.com/wealdtech/go-eth2-wallet-nd),[hierarchical deterministic](https://github.com/wealdtech/go-eth2-wallet-hd) to [distributed type](https://github.com/wealdtech/go-eth2-wallet-distributed),[non-deterministic type](https://github.com/wealdtech/go-eth2-wallet-nd)

:bangbang: It is highly recommended to refrain from any operations on the validation keys and use the provided script only in critical situations to avoid any ponential risks of slashing.

Expand All @@ -13,8 +14,8 @@ Transform wallets between [distributed type](https://github.com/wealdtech/go-eth
- [Source](#source)
- [Usage](#usage)
- [Config](#config)
- [Combine](#combine)
- [Split](#split)
- [File Structure](#file structure)
- [Convert](#convert)
- [Maintainers](#maintainers)
- [Contribute](#contribute)
- [License](#license)
Expand All @@ -38,197 +39,115 @@ go build .

`dkc` uses [herumi/bls-eth-go-binary](https://github.com/herumi/bls-eth-go-binary). Some research code of using [herumi/bls-eth-go-binary](https://github.com/herumi/bls-eth-go-binary) in `dkc` is available [here](./research/research.go)

You can also test `dkc` on predefiened inputs [here](.github/workflows/func-tests.yml).
You can test `dkc` on predefiened inputs [here](.github/workflows/func-tests.yml).

### Config

An example config can be found [here](.github/examples/config.yaml)
An example configs for each pair could be found [here](.github/examples/)

```yaml
distributed-wallets: #Distributed-wallets section
path: ./wallet #Path to distributed wallet (Default: None)
passphrases: ./passphrases.txt #Path to file containing passphrases for unlocking/locking accounts (Default: None)
threshold: 2 #Threshlod value (Default: None)
walletname: myDKWallet
peers: #Peers dict, number of peers must be greater than threshold value (Default: None)
10: old1:9091
20: old2:9091
30: old3:9091
nd-wallets: #Non-determenistic-wallets section
path: nd_wallets #Path to non-determenistic wallet (Default: None)
passphrases: ./passphrases.txt #Path to file containing passphrases for unlocking/locking accounts (Default: None)
input: #Input section
store: #Store section
path: ./i_wallet #Location of input wallets
wallet: #Wallet section
type: distributed #Type for input wallet. Valid types are: distributed, non-deterministic,hierarchical deterministic
threshold: 2 #Threshold number. It must be len(peers)/2 < threshold < len(peers)
peers: #Peers section
10: #Peer ID is used for generating bls participants
name: old1:9091 #Peer name is used for generating bls participants. All wallets for this peer are located in ./i_wallet/old1
passphrases: #Passphrases section
path: ./peer1.txt #Path to passphrases file(you can use separate passphrases file for each peer)
index: 1 #Password index in passphrases file. If not provided will use all passwords for unlocking wallets and only first password for creating accounts (Default: Using all passwords provided in passphrases file)
20:
name: old2:9091
passphrases:
path: ./peer2.txt
index: 1
30:
name: old3:9091
passphrases:
path: ./peer3.txt
index: 1
output: #Output Wallet Section
store:
path: ./o_wallet
wallet:
type: hierarchical deterministic
passphrases:
path: ./o_passphrases.txt
log-level: debug #Log-level (Default: INFO)
```
### File structure
### File Structure
##### Combine
##### Distributed Wallet
The following is an [example](.github/examples/wallets) file structure if one were to combine threshold keys. `old1`, `old2`, `old3` are each the `base-dir` wallet directory from the dirk instance. `old1`, `old2`, `old3` are each their own wallet directory.
This wallet type can be used as input or output wallet. More information about this wallet type is provided [here]((https://github.com/wealdtech/go-eth2-wallet-distributed)
`ethdo wallet list --base-dir ./wallet` should return nothing.
The following is an [example](.github/examples/distributed-to-nd/distributed) file structure if one were to combine threshold keys. `test1`, `test2`, `test3` are each the `base-dir` wallet directory from the dirk instance. `test1`, `test2`, `test3` are each their own wallet directory.

The subdirectories of `wallet` folder are the actual `ethdo` wallets:
`ethdo wallet list --base-dir ./distributed-to-nd/distributed` should return nothing.

```
$ ethdo wallet list --base-dir wallets/old1
9faf1408-839c-4b21-9d15-80d192c2bced
$ ethdo wallet list --base-dir wallets/old2
ff3918f1-16ef-47bf-83d2-16b5a64c9aa1
$ ethdo wallet list --base-dir wallets/old3
dd428711-4681-41d1-ad47-746cc6cfea8f
```

It should look like this:
The subdirectories of `wallet` folder are the actual `ethdo` wallets:

```
wallet
├── old1
│ └── 9a76c4f3-aa46-4864-b7fd-55681f8afa3b
│ ├── 69e976d2-3c78-44e3-b9a6-45149078723d
│ ├── 85587167-c356-4968-aa36-37464d05640c
│ ├── 9a76c4f3-aa46-4864-b7fd-55681f8afa3b
│ ├── a99d9d83-4afb-4870-8cce-a57c69c6bda2
│ ├── fd83339a-d36e-4c7a-a30c-0999be075dcb
│ └── index
├── old2
│ └── 32b277e3-b71a-45ed-b47d-5b6c155b8cf9
│ ├── 026b1c48-9a1a-49f8-b289-792d79378090
│ ├── 32b277e3-b71a-45ed-b47d-5b6c155b8cf9
│ ├── 6880aa1f-e490-4508-868f-f2af3b7f34f7
│ ├── ab1cc0d8-5447-41bd-b3b5-0c100ae9747a
│ ├── f282e1ff-0364-48e6-a674-26ea18184bf3
│ └── index
└── old3
└── 68f2bf6c-4266-49e2-915a-be9946c0882b
├── 5613693b-1b36-4bac-9b85-d96deeeb8d7c
├── 5a8c805d-9056-4ded-b9a2-611cdaa99427
├── 5ee08d46-70d0-430a-b4ef-f461567c344c
├── 68f2bf6c-4266-49e2-915a-be9946c0882b
├── e177e6d7-195a-44a0-b350-7bcf73642253
└── index
$ ethdo wallet list --base-dir distributed-to-nd/distributed/test1
Wallet2
Wallet3
Wallet1
$ ethdo wallet list --base-dir distributed-to-nd/distributed/test2
Wallet2
Wallet3
Wallet1
$ ethdo wallet list --base-dir distributed-to-nd/distributed/test3
Wallet1
Wallet2
Wallet3
```

*Importantly, the names of each wallet folder must correspond with the values in `distributed-wallets.peers` defined in the config.*
*Importantly, the names of each wallet folder must correspond with the values in `*.wallet.peers` defined in the config.*

The keys within each wallet must also have the same name

```
cat wallets/old1/56f23183-85e7-4f65-863e-738975f137ad/index | jq
[
{
"uuid": "37be3c86-5d24-47f3-99b8-83b6ac62e6b7",
"name": "3"
},
{
"uuid": "54799fa9-3239-4df2-857b-50c5d725cbfe",
"name": "4"
},
{
"uuid": "5676a9e5-e1de-4eef-9473-8c52c0810ce5",
"name": "1"
},
{
"uuid": "c153e6f1-2ae2-44fd-9a4b-e91965c8a2a6",
"name": "2"
}
]

cat wallets/old3/e5dc7bb0-9be2-45a5-b54b-768f4fd105df/index | jq
[
{
"uuid": "d38d8796-5022-42ea-8495-cd5d67743afc",
"name": "3"
},
{
"uuid": "0d69229d-cbcc-42eb-b29b-10ae91f28dff",
"name": "4"
},
{
"uuid": "b043fbf2-f392-4c09-b8ff-319ed8345dc8",
"name": "1"
},
{
"uuid": "c38ac2af-f5ee-4326-bd03-8572d2449623",
"name": "2"
}
]

cat wallets/old3/e5dc7bb0-9be2-45a5-b54b-768f4fd105df/index | jq
[
{
"uuid": "d38d8796-5022-42ea-8495-cd5d67743afc",
"name": "3"
},
{
"uuid": "0d69229d-cbcc-42eb-b29b-10ae91f28dff",
"name": "4"
},
{
"uuid": "b043fbf2-f392-4c09-b8ff-319ed8345dc8",
"name": "1"
},
{
"uuid": "c38ac2af-f5ee-4326-bd03-8572d2449623",
"name": "2"
}
]
```
All of the keys with corresponding names (ex: `name = 1`) should be the threshold keys corresponding to the same composite public key.

##### Split
##### Hierarchical Deterministic

The following is an example file structure if one were to want to split non-deterministic keys into threshold keys.
This wallet type can be used only ad input wallet. More information about this wallet type is provided [here]((https://github.com/wealdtech/go-eth2-wallet-hd)

```
nd_wallets
└── 20384d86-bc39-4ac4-a827-3cff41043cbd
├── 20384d86-bc39-4ac4-a827-3cff41043cbd
├── 2c2cd425-fa58-43b7-808b-d2ba32d692cc
├── 5bee4007-73ba-452f-9e53-6d04110dbb7c
├── 95b9898b-667f-49cd-9097-9da9bf760173
├── b9d79ea4-9e15-4f3c-9c63-b67e7965a060
└── index
```
The following is an [example](.github/examples/hd-to-distributed/hd) file structure. The `base-dir` wallet directory is `hd-to-distributed/hd`

In this instance, `nd_wallets` is the wallet `base-dir`.
```
$ ethdo wallet list --base-dir nd_wallets
be7efee0-a219-4fb5-a0b7-a47662320755
$ ethdo wallet --base-dir hd-to-distributed/hd list
Wallet1
Wallet3
Wallet2
```
To split up, non-deterministic keys, just put them into the wallet.
```
nd_wallets
└── 20384d86-bc39-4ac4-a827-3cff41043cbd
├── 20384d86-bc39-4ac4-a827-3cff41043cbd
├── 2c2cd425-fa58-43b7-808b-d2ba32d692cc
├── 5bee4007-73ba-452f-9e53-6d04110dbb7c
├── 95b9898b-667f-49cd-9097-9da9bf760173
├── b9d79ea4-9e15-4f3c-9c63-b67e7965a060
└── index
```
##### Non-Deterministic
##### Output Formats
This wallet type can be used as input or output wallet. More information about this wallet type is provided [here]((https://github.com/wealdtech/go-eth2-wallet-nd)
The output file hierarchy is the same as the opposite side's input hierarchy. For example, the format needed to split keys, will be the output format of combined keys.
The following is an [example](.github/examples/nd-to-distributed/nd) file structure. The `base-dir` wallet directory is `hd-to-distributed/nd`
### Combine
```
$ ethdo wallet --base-dir nd-to-distributed/hd list
Wallet1
Wallet3
Wallet2
```
Combine [distributed type](https://github.com/wealdtech/go-eth2-wallet-distributed) to [non-deterministic type](https://github.com/wealdtech/go-eth2-wallet-nd).
##### Output Formats
```sh
./dkc combine --config=config.yaml
```
The output file hierarchy is the same as the opposite side's input hierarchy.
### Split
### Convert
Split [non-deterministic type](https://github.com/wealdtech/go-eth2-wallet-nd) to [distributed type](https://github.com/wealdtech/go-eth2-wallet-distributed)
After preparing config and backuping keys simply run:
```sh
./dkc split --config=config.yaml
./dkc convert --config=config.yaml
```

## Maintainers
Expand Down
12 changes: 6 additions & 6 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
input:
store:
path: DISTRIBUTED_WALLETS
path: ./input_distributed_wallet
wallet:
type: distributed
threshold: 2
peers:
10:
name: old1:9091
passphrases:
path: ./input_wallet_passphrases.txt
path: ./input_peer1_passphrases.txt
index: 1
20:
name: old2:9091
passphrases:
path: ./input_wallet_passphrases.txt
path: ./input_peer2_passphrases.txt
index: 1
30:
name: old3:9091
passphrases:
path: ./input_wallet_passphrases.txt
path: ./input_peer3_passphrases.txt
index: 1
output:
store:
path: HD_WALLETS
path: ./output_hd_wallet
wallet:
type: hierarchical deterministic
passphrases:
path: ./output_wallet_passphrases.txt
path: ./output_hd_wallet_passphrases.txt

log-level: debug
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ require (
)

require (
github.com/alecthomas/gometalinter v3.0.0+incompatible // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aws/aws-sdk-go v1.48.0 // indirect
github.com/client9/misspell v0.3.4 // indirect
github.com/ferranbt/fastssz v0.1.3 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fzipp/gocyclo v0.6.0 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gordonklaus/ineffassign v0.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -31,6 +37,8 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nicksnyder/go-i18n v1.10.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/phoreproject/bls v0.0.0-20191211001008-9d5f85bf4a9b // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
Expand All @@ -57,8 +65,12 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 821d900

Please sign in to comment.