swa

package module
v0.0.0-...-cc01e78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2019 License: GPL-3.0 Imports: 11 Imported by: 2

README

HD Wallet

Base BIP0032 HD Wallet derivations from mnemonic seed. master key can be derive child key from given path. Path: Path should start with the m/ prefix, for example, to derive the first child account, the path will be "m/0" if path with ' , it will be hardened path, hardened key can be derive only using the private key or his parent key

Install

go get github.com/symphonyprotocol/swa

Compile

go build -o swa *.go

How to use

Generate memonic
➜  swa git:(dev) ✗ ./swa newmnemonic
Mnemonic is: orphan sentence network gun purpose toe wolf bulk another slide involve mercy
Get Master Public key and Master Private key from mnemonic words

-m: mnemonic words -p: your password

➜  swa git:(dev) ✗ ./swa getkey -m "orphan sentence network gun purpose toe wolf bulk another slide involve mercy" -p "User@123"
master public key compressed           :0262B1764E5CBF6CAFCB3B72DFEBAE85348827F8772E4EB4A19BC7D3A5295BE194
master public key un compressed        :0462B1764E5CBF6CAFCB3B72DFEBAE85348827F8772E4EB4A19BC7D3A5295BE19442419221C40C2002CB008F60B999837AC3FB01333DF05738C440FCC70BC76A7A
master public key address              :12Xyeo1m2bmqANFAV6NWRj6oz5R1c5d7ZB
master public key address compressed   :1T3r9yFFM6St9wGSp7zMYP24G6pUYnL7y
master private key wif                 :5KjEcrVAEwtWEeKn46ySebFd6AxwuN9YwBf2kj3o26eSZtNigd6
master private key wif compressed      :L5fR7FRHnZGL3DjsrhN8CvBYHpywL8LjxA2rjzbL7qvFqjgbNVQ5
master private key str                 :FBEC50438CFD849DEE6EBEDDA98217EA75ACD06E27569571CB0D54446A392EFB
Derive Key

-m: mnemonic words -pwd: your password -path: derivations path

examples,derive the first child key from master key

➜  swa git:(dev) ✗ ./swa derivekey -m "orphan sentence network gun purpose toe wolf bulk another slide involve mercy" -pwd "User@123" -path "m/0"
derive public key compressed           :02879C2CE29F14FF2115229AC1834A471F8DAB6B1863449FE52968B81BD7D3B9DD
derive public key un compressed        :04879C2CE29F14FF2115229AC1834A471F8DAB6B1863449FE52968B81BD7D3B9DDC96CE28B46F90D1DE18F9ADF5485E9E87B84C4E7FAB4C3D368ACEAE16EDCAA64
derive public key address              :1CNJWMArmbrerkGN9JBnfdEQzHQY6SwMGN
derive public key address compressed   :14S5x7J74bm273WPc1CHu2NBwaZJfxVSDT
derive private key wif                 :5J1s8thMpkzgUyKATYNTo71d4xRSHoKGYSXcCnBLySMRi4uFpvU
derive private key wif compressed      :Kx6pHqB8uoBbGTZAk9TjGVXkCTcrd9Rdbmg6NzQfA6uA4FHb11Rk
derive private key str                 :1A4A5DC3FB04031D91A468869184DFFAFFB4FD15282D050948197DF93913D959

Module Support

  • In progress

Documentation

Index

Constants

View Source
const (
	WIF_VERSION         = 0x80
	WIF_COMPRESSED_FLAG = 0x01
	WALLET_ADDRESS_FLAG = 0x00

	PUBKEY_NOT_COMPRESSED_FLAG = 0x04
	PUBKEY_COMPRESSED_EVEN     = 0x02
	PUBKEY_COMPRESSED_ODD      = 0x03

	CHECKSUM_LEN = 4

	PRIVATE_KEY_KEN = 32
)

Variables

This section is empty.

Functions

func GenMnemonic

func GenMnemonic() (string, error)

func MakePath

func MakePath(path []uint32) string

func ParseDerivationPath

func ParseDerivationPath(path string) ([]uint32, error)

解析路径 0到2^{31}-1之间的索引号(0x0到0x7FFFFFFF)仅用于正常推导 2^31和2^{32}-1 之间的索引号(0x80000000至0xFFFFFFFF)仅用于强化推导

Types

type CLI

type CLI struct{}

func (*CLI) CreateMnemonic

func (cli *CLI) CreateMnemonic() string

func (*CLI) DeriveKey

func (cli *CLI) DeriveKey(mnemonic string, pwd string, path string)

func (*CLI) GetKey

func (cli *CLI) GetKey(mnemonic string, pwd string)

func (*CLI) Run

func (cli *CLI) Run()

type Wallet

type Wallet struct {
	// contains filtered or unexported fields
}

func NewFromMnemonic

func NewFromMnemonic(mnemonic string, pwd string) (*Wallet, error)

func (*Wallet) DeriveKey

func (w *Wallet) DeriveKey(path string) (*ec.PrivateKey, *ec.PublicKey, error)

func (*Wallet) GetMasterKey

func (w *Wallet) GetMasterKey() *hd.ExtendedKey

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL