Skip to content

Commit

Permalink
Merge pull request #63 from spacemeshos/genesisverify
Browse files Browse the repository at this point in the history
Add `genesis` command
  • Loading branch information
lrettig authored Jul 12, 2023
2 parents ad73ffd + e2a29a6 commit 0916711
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 18 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ Note that the created wallet file will not contain any private keys or mnemonic

**NOTE: We strongly recommend only creating a new wallet on a hardware wallet or on a secure, airgapped computer. You are responsible for safely storing your mnemonic and wallet files. Your mnemonic is the ONLY way to restore access to your wallet and accounts if you misplace the wallet file, so it's essential that you back it up securely and reliably. There is absolutely nothing that we can do to help you recover your wallet if you misplace the file or mnemonic.**

## Genesis

smcli includes commands to verify the information contained in the genesis ledger.

### Verify

To verify the vesting (owner) address and vault address for a particular genesis vesting vault, run:

```
smcli genesis verify
```

This command will prompt you to enter one or more public keys, along with the multisig params (minimum required signers) and vaulted amount. It will subsequently output the vesting and vault addresses associated with the vault.

## Building

Building the app is fairly straightforward. The only prerequisites are Golang with CGO support, `libudev` on Linux (`sudo apt-get install libudev-dev` on Debian/Ubuntu) and two libraries that will be statically linked into the binary. All of the details are handled in `Makefile` and should work on Linux (AMD64 and ARM64), macOS (Intel and Apple Silicon), and Windows. Simply run `make build`, which should download the correct libraries for your OS and platform. See the [release CI workflow](https://github.com/spacemeshos/smcli/blob/develop/.github/workflows/release.yml) for more details, and feel free to open an issue if you encounter any trouble.
101 changes: 101 additions & 0 deletions cmd/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package cmd

import (
"crypto/ed25519"
"encoding/hex"
"fmt"
"log"

"github.com/spacemeshos/economics/constants"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/genvm/core"
"github.com/spacemeshos/go-spacemesh/genvm/templates/multisig"
"github.com/spacemeshos/go-spacemesh/genvm/templates/vault"
"github.com/spacemeshos/go-spacemesh/genvm/templates/vesting"
"github.com/spf13/cobra"
)

// genesisCmd represents the wallet command.
var genesisCmd = &cobra.Command{
Use: "genesis",
Short: "Genesis-related utilities",
}

// createCmd represents the create command.
var verifyCmd = &cobra.Command{
Use: "verify",
Short: "Verify a genesis ledger account",
Args: cobra.MaximumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
var err error

// first, collect the keys
var keys []core.PublicKey
fmt.Print("First, let's collect your public keys. Keys must be entered in hex format: 64 characters, without 0x prefix.\n")
fmt.Print("Enter pubkeys one at a time; press enter again when done: ")
for {
var keyStr string
_, err := fmt.Scanln(&keyStr)
if err != nil {
break
}
keyBytes, err := hex.DecodeString(keyStr)
if err != nil || len(keyBytes) != ed25519.PublicKeySize {
log.Fatalln("Error: key is unreadable")
}
key := [ed25519.PublicKeySize]byte{}
copy(key[:], keyBytes)
keys = append(keys, key)
fmt.Printf("[enter next key or just press enter to end] > ")
}
if len(keys) == 0 {
log.Fatalln("Error: must enter at least one key")
}

// next collect multisig params
m := uint8(1)
if len(keys) > 1 {
fmt.Printf("Enter number of required signatures (between 1 and %d): ", len(keys))
_, err := fmt.Scanln(&m)
cobra.CheckErr(err)
}

// finally, collect amount
var amount uint64
fmt.Printf("Enter vault balance (denominated in SMH): ")
_, err = fmt.Scanln(&amount)
cobra.CheckErr(err)
amount *= constants.OneSmesh

// calculate keys
vestingArgs := &multisig.SpawnArguments{
Required: m,
PublicKeys: keys,
}
if int(vestingArgs.Required) > len(vestingArgs.PublicKeys) {
log.Fatalf("requires more signatures (%d) than public keys (%d) in the wallet\n",
vestingArgs.Required,
len(vestingArgs.PublicKeys),
)
}
vestingAddress := core.ComputePrincipal(vesting.TemplateAddress, vestingArgs)
vaultArgs := &vault.SpawnArguments{
Owner: vestingAddress,
TotalAmount: amount,
InitialUnlockAmount: amount / 4,
VestingStart: types.LayerID(constants.VestStart),
VestingEnd: types.LayerID(constants.VestEnd),
}
vaultAddress := core.ComputePrincipal(vault.TemplateAddress, vaultArgs)

// output addresses
fmt.Printf("Vesting address: %s\nVault address: %s\n",
vestingAddress.String(),
vaultAddress.String())
},
}

func init() {
rootCmd.AddCommand(genesisCmd)
genesisCmd.AddCommand(verifyCmd)
}
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ var cfgFile string

// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "sm",
Use: "smcli",
Short: "The official CLI for Spacemesh.",
Long: `sm is your terminal's connection to the Spacemesh network.
Long: `smcli is your terminal's connection to the Spacemesh network.
The sm CLI provides an ergonomic set of tools for managing a node and wallet.`,
This tool provides an ergonomic set of tools for managing a wallet.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) {
Expand Down
45 changes: 40 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,46 @@ go 1.18
require (
github.com/btcsuite/btcutil v1.0.2
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/spacemeshos/economics v0.1.0
github.com/spacemeshos/go-spacemesh v0.3.3-beta.0.0.20230710094357-ba923401156a
github.com/spacemeshos/smkeys v1.0.4
github.com/stretchr/testify v1.8.4
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/c0mm4nd/go-ripemd v0.0.0-20200326052756-bd1759ad7d10 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/go-llsqlite/llsqlite v0.0.0-20230612031458-a9e271fe723a // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/spacemeshos/go-scale v1.1.10 // indirect
github.com/spacemeshos/merkle-tree v0.2.2 // indirect
github.com/spacemeshos/poet v0.8.6 // indirect
github.com/spacemeshos/post v0.8.6 // indirect
github.com/spacemeshos/sha256-simd v0.1.0 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
golang.org/x/net v0.12.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.56.2 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand All @@ -30,11 +66,10 @@ require (
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tyler-smith/go-bip39 v1.1.0
github.com/xdg-go/pbkdf2 v1.0.0
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 0916711

Please sign in to comment.