-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for decentralized treasury.
- Loading branch information
1 parent
84962d3
commit f98c13b
Showing
40 changed files
with
1,123 additions
and
232 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ vendor | |
.vscode | ||
.idea | ||
rpc/tools/bin/ | ||
*.sw* |
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
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,50 @@ | ||
treasurykey | ||
=========== | ||
|
||
THIS TOOL IS FOR NETWORK OPERATORS ONLY. | ||
|
||
**DO NOT USE** | ||
|
||
The `treasurykey` utility is used to generate treasury keys that enable | ||
spending from the treasury account. | ||
|
||
The tool takes a single flag to designate which network it is generating a key | ||
for. | ||
|
||
It prints out three values: | ||
1. A serialized private key | ||
2. The serialized public key | ||
3. The WIF (Wallet Interchange Format) version of the private key. | ||
|
||
This information must be stored in a secure location. | ||
|
||
The public key will be hardcoded inside `dcrd` and `dcrwallet`. Both daemons | ||
will use it to identify valid treasury spend transactions. | ||
|
||
The WIF must be imported into the dcrwallet that will generate TSPEND | ||
transactions. | ||
|
||
For example: | ||
|
||
Generate key. | ||
``` | ||
$ treasurykey -mainnet | ||
Private key: 9bcf82e4b267585b3f0c54632d7e8eef2fc13407dfdbf7a80398085f5851baa0 | ||
Public key: 03f31aa7013b3c3e8568eb6415a895d8662b5ddceff12a62bf77c01e3e451a332f | ||
WIF : PmQeT3VmoxDRjgsfwVJLV13ioNyxmd9XuQmQu86UPiQQAn5XkRfLN | ||
``` | ||
|
||
Import key into treasury wallet. | ||
``` | ||
dcrctl --wallet importprivkey PmQeT3VmoxDRjgsfwVJLV13ioNyxmd9XuQmQu86UPiQQAn5XkRfLN imported false | ||
``` | ||
|
||
It is suggested to repeat this process so that there are at least two valid | ||
keys. | ||
|
||
Why? | ||
==== | ||
|
||
This approach was chosen in order to generate *independent* random keys. If the | ||
treasury wallet machine were to be compromised the seed would be compromised as | ||
well. |
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,69 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/decred/dcrd/chaincfg/v3" | ||
"github.com/decred/dcrd/dcrec" | ||
"github.com/decred/dcrd/dcrec/secp256k1/v3" | ||
"github.com/decred/dcrd/dcrutil/v3" | ||
) | ||
|
||
func generateKeys(params *chaincfg.Params) error { | ||
key, err := secp256k1.GeneratePrivateKey() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
keyBytes := key.Serialize() | ||
wif, err := dcrutil.NewWIF(keyBytes, params.PrivateKeyID, | ||
dcrec.STSchnorrSecp256k1) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Private key: %x\n", keyBytes) | ||
fmt.Printf("Public key: %x\n", key.PubKey().SerializeCompressed()) | ||
fmt.Printf("WIF : %s\n", wif) | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
mainnet := flag.Bool("mainnet", false, "use mainnet parameters") | ||
simnet := flag.Bool("simnet", false, "use simnet parameters") | ||
regnet := flag.Bool("regnet", false, "use regnet parameters") | ||
testnet := flag.Bool("testnet", false, "use testnet parameters") | ||
flag.Parse() | ||
|
||
var net *chaincfg.Params | ||
flags := 0 | ||
if *mainnet { | ||
flags++ | ||
net = chaincfg.MainNetParams() | ||
} | ||
if *testnet { | ||
flags++ | ||
net = chaincfg.TestNet3Params() | ||
} | ||
if *simnet { | ||
flags++ | ||
net = chaincfg.SimNetParams() | ||
} | ||
if *regnet { | ||
flags++ | ||
net = chaincfg.RegNetParams() | ||
} | ||
if flags != 1 { | ||
fmt.Println("One and only one flag must be selected") | ||
flag.Usage() | ||
os.Exit(1) | ||
} | ||
|
||
if err := generateKeys(net); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
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
Oops, something went wrong.