Coder Social home page Coder Social logo

smcli's Introduction

smcli: Spacemesh Command-line Interface Tool

smcli is a simple command line tool that you can use to manage wallet files (in the future it may be expanded with additional functionality).

It currently supports the following features. Note that this documentation is not intended to be as complete as the built-in help documentation in the application itself, which fully documents all commands, flags, and features. Run smcli -h to see this documentation.

Wallet

smcli allows you to read encrypted wallet files (including those created using Smapp and other compatible tools), and generate new wallet files.

Reading

To read an encrypted wallet file, run:

smcli wallet read <filename>

You'll be prompted to enter the (optional) password used to encrypt the wallet file. If you enter the correct password, you'll see the contents of the wallet printed, including the accounts it contains. Include the flags --full to see full keys, and --private to see private keys and mnemonic in addition to public keys.

Note that you can read both wallet files created using smcli as well as those created using Smapp or any other tool that supports standard Spacemesh wallet format.

Generation

To generate a new wallet, run:

smcli wallet create

The command will prompt you to enter a BIP39-compatible mnemonic, or alternatively generate a new, random mnemonic for you. It will then prompt you to enter a password to encrypt the wallet file (optional but highly recommended) and will then generate an encrypted wallet file with one or more new keypairs.

Note that these keypairs (public and private key) are not the same as Spacemesh wallet addresses. The public key can be converted directly and deterministically into your wallet address; in other words, there is a one-to-one mapping between public keys and wallet addresses. Conversion and outputting of public keys as wallet addresses will be available shortly.

Hardware wallet support

smcli supports key generation using Ledger hardware devices including Nano S, Nano S+, and Nano X. To generate a wallet file using a hardware wallet, first sideload the Spacemesh Ledger app onto your device (follow the instructions in that README). Make sure the device is connected and unlocked and the Spacemesh app is open, then run:

smcli wallet create --ledger

Note that the created wallet file will not contain any private keys or mnemonic (as these obviously remain on the Ledger device). If you subsequently use smcli wallet read to read the file, these will not be printed. We still recommend encrypting the wallet file with a secure password for privacy purposes.

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 for more details, and feel free to open an issue if you encounter any trouble.

smcli's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smcli's Issues

BIP39 password support

Add an option for the user to provide an additional password, which along with the mnemonic would go into seed generation

Support multiple ledger devices

smkeys supports a path argument that allows the user to specify which ledger device they want to use. Add support in smcli for specifying a ledger device. The format should match that in the solana CLI, e.g., "usb://ledger/1" for the second device.

It would be nice to support listing the present devices; this would require adding upstream support in smkeys and spacemesh-sdk as well.

Spacemesh wallet address format

This tool currently allows generation and display of public keys, but not Spacemesh account addresses in the bech32 format that can, e.g., be used as a coinbase address for receiving rewards in the protocol. Add this conversion:

  • smcli wallet read should print pubkeys in this format
  • we should add a new smcli address command that allows conversion between the two formats

See the addressgen tool added here: spacemeshos/go-spacemesh#4276

use canonical `crypto/ed25519` everywhere

          for a future PR: we are now using canonical `crypto/ed25519` everywhere in go-spacemesh. The `ed25519-recovery` library is not used any more.

It looks like its only used for tests in smcli, so its not urgent to remove it ๐Ÿ™‚

Originally posted by @fasmat in #34 (comment)

Wallet file format

smcli currently creates a "bare" wallet file with just encrypted data, nonce, and salt:

{"encrypted_wallet":"rwM5BjJZvU5r6sYTCq1tERPJEQY9GLvoiQWqqwSi7pMq5SBoG2g4R65ssEBdYGpBBVhs6vKA2n9DiApQ5Es7oDURgdBx6W4P6t2rxQJqJQ6Zy9GRFUouVuaZZJCSDpHewcGK8avsnCVYPPK3GPVSrkTqw3oF4ksD29feXTxh26AGEMxH1Bz1XiYNFNdP4HCwBQnDud92Nq3XGhdnCL7qDfksHTJ9Lkp8JbLBpjeDjwskTji","salt":"ANniW2QWCYDSv6cT5cMK6u","nonce":"DJtclI199GqCpTdE"}

It should output a wallet file in the format specified in spacemeshos/SMIPS#17 and expected by smapp.

Use mnemonic and path/index for wallet creation

Offer two creation modes: HW and mnemonic. For mnemonic mode, accept an existing mnemonic or generate a new one. If a new one is generated, print it. Also accept account index (less critical for genesis).

sm wallet create

  • Generate master keypair
  • Generate first account
  • Save wallet in format described in: spacemeshos/SMIPS#17
  • Open and decrypt wallet successfully to validate saved wallet

[BUG] File not found when installing

Cmd

make
go build

Version

go version go1.21.4 darwin/arm64

Error

go build
# github.com/spacemeshos/smkeys/remote-wallet
../../go/pkg/mod/github.com/spacemeshos/[email protected]/remote-wallet/remote_wallet.go:4:11: fatal error: 'remote_wallet.h' file not found
        #include "remote_wallet.h"
                 ^~~~~~~~~~~~~~~~~
1 error generated.
# github.com/spacemeshos/smkeys/bip32
../../go/pkg/mod/github.com/spacemeshos/[email protected]/bip32/bip32.go:4:11: fatal error: 'ed25519_bip32.h' file not found
        #include "ed25519_bip32.h"
                 ^~~~~~~~~~~~~~~~~
1 error generated.

glibc issue/Debian support

Reported by community in v1.0.7:

./smcli: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.32' not found (required by ./smcli)

uname -a:
Linux cs-8965316041-ephemeral-h1n4 5.15.107+ #1 SMP Thu Jun 15 09:51:46 UTC 2023 x86_64 GNU/Linux

cat /etc/os-release:
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian

Building from source caused dylib linking issues

"Error: The handle is invalid." on Windows

Just documenting this here in case it comes up for anyone else because it confused the heck out of me. Trying to run smcli on Windows just now, I kept getting the following error (from wallet create and wallet read):

$ ./smcli.exe wallet create
Enter a BIP-39-compatible mnemonic (or leave blank to generate a new one):
Error: The handle is invalid.

Turns out this happened because I'm running it inside of Git Bash on Windows. It works fine in Powershell. See golang/go#11914.

Store keys in hex format

Right now in #20, keys are marshaled using base58 (I think) as this is the default JSON handling of byte strings. Output keys in hex format instead, like smapp does.

Clean up error handling in WalletKeyOpt functional options

          Exiting the program in case the functional options have been defined in the wrong order is a bit extrem imo

I would prefer one of the following:

  1. WithPdkdf2Password also takes a salt and the user must not also call WithSalt
  2. WalletKey has a verify method that is called after applying all functional options that verifies a correct state and returns an error if something is missing (e.g. no salt provided)

Originally posted by @fasmat in #20 (comment)

Finalize tool name

The CLI command (the binary) was originally sm but it's now smcli. The help message is therefore contradictory:

> ./smcli -h
sm is your terminal's connection to the Spacemesh network.

The sm CLI provides an ergonomic set of tools for managing a node and wallet.

Usage:
  sm [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  wallet      A brief description of your command

Flags:
      --config string   config file (default is $HOME/.smcli.yaml)
  -h, --help            help for sm
  -t, --toggle          Help message for toggle

Use "sm [command] --help" for more information about a command.

Pick a name and harmonize these.

Remove "Master Key"

This can be a little confusing and it's probably not necessary. For instance, the wallet files created by smapp don't have this. CC @brusherru

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.