Skip to content

Commit

Permalink
wip implementation of account.Wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Jul 7, 2018
1 parent 40e83e4 commit fe0d7ac
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ test:
.PHONY: deps/cp
deps/cp:
@cp -r "${GOPATH}/src/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1" "vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/"

.PHONY: example
example:
@go run -v example/example.go
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# go-ethereum-hdwallet

> Ethereum HD Wallet derivations from mnemonic in Go (golang)
Note: This is a WIP. Although it's working, I'm going to implement the `Wallet` interface from go-ethereum which will break the current API.
> Ethereum HD Wallet derivations from mnemonic in Go (golang). Implements the [go-ethereum](https://github.com/ethereum/go-ethereum) [`accounts.Wallet`](https://github.com/ethereum/go-ethereum/blob/master/accounts/accounts.go) interface.
## Install

Expand Down
31 changes: 20 additions & 11 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@ package main

import (
"fmt"
"log"

"github.com/miguelmota/go-ethereum-hdwallet"
//"github.com/miguelmota/go-ethereum-hdwallet"
hdwallet ".."
)

func main() {
mnemonic := "tag volcano eight thank tide danger coast health above argue embrace heavy"
root, _ := hdwallet.New(&hdwallet.Config{
Mnemonic: mnemonic,
Path: `m/44'/60'/0'/0`,
})
wallet, err := hdwallet.NewFromMnemonic(mnemonic)
if err != nil {
log.Fatal(err)
}

wallet0, _ := root.Derive(0)
fmt.Println(wallet0.AddressHex()) // 0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947
path := hdwallet.MustParseDerivationPath("m/44'/60'/0'/0/0")
account, err := wallet.Derive(path, false)
if err != nil {
log.Fatal(err)
}

wallet1, _ := root.Derive(1)
fmt.Println(wallet1.AddressHex()) // 0x8230645aC28A4EdD1b0B53E7Cd8019744E9dD559
fmt.Println(account.Address.Hex()) // 0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947

wallet2, _ := root.Derive(2)
fmt.Println(wallet2.AddressHex()) // 0x65c150B7eF3B1adbB9cB2b8041C892b15eDde05A
path = hdwallet.MustParseDerivationPath("m/44'/60'/0'/0/1")
account, err = wallet.Derive(path, false)
if err != nil {
log.Fatal(err)
}

fmt.Println(account.Address.Hex()) // 0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947
}
Loading

0 comments on commit fe0d7ac

Please sign in to comment.