Documentation ¶
Overview ¶
Package account contains code for managing account keypairs, generating a HD wallet as well as saving them securely to disk.
HD wallet functionality per AEX-10 (https://github.com/aeternity/AEXs/blob/master/AEXS/aex-10.md) is implemented in this fashion:
+----------------------------+ | BIP39 Mnemonic | +-------------+--------------+ | +-------------+--------------+ | Binary Seed | +-------------+--------------+ | +-------------+--------------+ | BIP32 Master Key | +----X-----------------------+ XXX XXX +-----X---+ +---------+ +----------+ | | | | | | | | | | | | | | | | | | +---------XX +---------+ +----------+ XXX +---------+ +--XX-----+ | | | | | | | | | | | | +---------+ +-------XX+ X +---------------------+ +----XX+----+ | | | | | | | Child Key +-------------------> aeternity Account | | | | | +-----------+ | | +---------------------+
Example ¶
mnemonic := "ring defense obey exhaust boat popular surround supreme front lemon monster number" seed, err := ParseMnemonic(mnemonic) if err != nil { fmt.Println(err) } // Derive the subaccount m/44'/457'/3'/0'/1' key, err := DerivePathFromSeed(seed, 3, 1) if err != nil { fmt.Println(err) } // Deriving the aeternity Account from a BIP32 Key is a destructive process alice, err := BIP32KeyToAeKey(key) if err != nil { fmt.Println(err) } fmt.Println(alice.Address)
Output:
Index ¶
- Constants
- Variables
- func CheckWalletExists(path string) (walletPath string, err error)
- func KeystoreSeal(account *Account, password string) (j []byte, e error)
- func ParseMnemonic(mnemonic string) (masterSeed []byte, err error)
- func StoreToKeyStoreFile(account *Account, password, walletName string) (filePath string, err error)
- func Verify(address string, message, signature []byte) (valid bool, err error)
- type Account
- func BIP32KeyToAeKey(key *Key) (acc *Account, err error)
- func FromHexString(hexPrivateKey string) (account *Account, err error)
- func KeystoreOpen(data []byte, password string) (account *Account, err error)
- func LoadFromKeyStoreFile(keyFile, password string) (account *Account, err error)
- func New() (account *Account, err error)
- type Key
- type Path
- type PathNode
Examples ¶
Constants ¶
const FirstHardenedChild = uint32(0x80000000)
FirstHardenedChild (2^31) denotes when hardened child derivation starts.
Variables ¶
var ( // ErrPathNoMaster HD wallet path does not start with m ErrPathNoMaster = errors.New("Path must start with m") // ErrPathChildMaster HD wallet path contains m in a child node ErrPathChildMaster = errors.New("Path contains m as a child node") // ErrPathNodeNotNumber HD wallet path node is not a valid uint32 number ErrPathNodeNotNumber = errors.New("Path node is not a valid uint32 number") // ErrPathNodeNumberTooLarge HD wallet path node is >= 2^31 ErrPathNodeNumberTooLarge = errors.New("Path node must be less than 2^31") )
var ErrHardenedChildPublicKey = errors.New("Can't create hardened child from public key")
ErrHardenedChildPublicKey is returned when trying to create a hardened child from a public key.
var ErrHardenedOnly = errors.New("ed25519 only works with hardened children")
ErrHardenedOnly is returned when a node in the path is not hardened.
Functions ¶
func CheckWalletExists ¶
CheckWalletExists checks if a file exists at the specified path.
func KeystoreSeal ¶
KeystoreSeal create an encrypted json keystore with the private key of the account
func ParseMnemonic ¶
ParseMnemonic uses BIP39 to parse a mnemonic. BIP39 uses a password along with the mnemonic to arrive at the final seed bytearray value, but aeternity only ever uses a blank string for the password, so the point of ParseMnemonic is to reduce ambiguity/confusion.
Types ¶
type Account ¶
type Account struct { SigningKey ed25519.PrivateKey Address string }
Account holds the signing/private key and the aeternity account address
func BIP32KeyToAeKey ¶
BIP32KeyToAeKey translates a BIP32 Key into an aeternity Account.
func FromHexString ¶
FromHexString creates an Account from a hexstring
func KeystoreOpen ¶
KeystoreOpen open and decrypt a keystore
func LoadFromKeyStoreFile ¶
LoadFromKeyStoreFile loads an encrypted Account from a JSON file
func (*Account) SigningKeyToHexString ¶
SigningKeyToHexString returns the SigningKey as an hex string
type Key ¶
type Key struct { Key []byte // 33 bytes ChildNumber uint32 // 4 bytes ChainCode []byte // 32 bytes NEEDED FOR CHILDKEY DERIVATION Depth uint32 // 1 bytes IsPrivate bool // unserialized }
Key represents a bip32 extended key, used for deriving subaccounts for HD wallets.
func DerivePathFromSeed ¶
DerivePathFromSeed derives a BIP32 Key given a seed (usually derived from a mnemonic) and an account index and address index, as standardized by AEX-10.
func NewMasterKey ¶
NewMasterKey creates a new master extended key from a seed