├── .gitignore ├── .idea ├── dictionaries │ └── luyao.xml └── vcs.xml ├── LICENSE ├── README.md ├── enum.go ├── errors.go ├── go.mod ├── go.sum ├── key.go ├── mnemonic.go ├── option.go ├── params.go ├── wallet.go ├── wallet_bch.go ├── wallet_btc.go ├── wallet_dash.go ├── wallet_doge.go ├── wallet_eos.go ├── wallet_etc.go ├── wallet_eth.go ├── wallet_iost.go ├── wallet_ltc.go ├── wallet_nuls.go ├── wallet_qtum.go ├── wallet_trx.go ├── wallet_usdc.go ├── wallet_usdt.go ├── wallet_wicc.go ├── wallet_xrp.go └── wallet_zen.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /.idea/dictionaries/luyao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 foxnut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## go-hdwallet 2 | 3 | A multi-cryptocurrency HD wallet implementated by golang. 4 | 5 | ## supported coins 6 | 7 | - BTC 8 | - LTC 9 | - DOGE 10 | - DASH 11 | - ETH 12 | - ETC 13 | - BCH 14 | - QTUM 15 | - USDT 16 | - IOST 17 | - USDC 18 | 19 | ## install 20 | 21 | ```sh 22 | go get -v -u github.com/foxnut/go-hdwallet 23 | ``` 24 | 25 | ## example 26 | 27 | ```go 28 | package main 29 | 30 | import ( 31 | "fmt" 32 | 33 | "github.com/foxnut/go-hdwallet" 34 | ) 35 | 36 | var ( 37 | mnemonic = "range sheriff try enroll deer over ten level bring display stamp recycle" 38 | ) 39 | 40 | func main() { 41 | master, err := hdwallet.NewKey( 42 | hdwallet.Mnemonic(mnemonic), 43 | ) 44 | if err != nil { 45 | panic(err) 46 | } 47 | 48 | // BTC: 1AwEPfoojHnKrhgt1vfuZAhrvPrmz7Rh4 49 | wallet, _ := master.GetWallet(hdwallet.CoinType(hdwallet.BTC), hdwallet.AddressIndex(1)) 50 | address, _ := wallet.GetAddress() 51 | addressP2WPKH, _ := wallet.GetKey().AddressP2WPKH() 52 | addressP2WPKHInP2SH, _ := wallet.GetKey().AddressP2WPKHInP2SH() 53 | fmt.Println("BTC: ", address, addressP2WPKH, addressP2WPKHInP2SH) 54 | 55 | // BCH: 1CSBT18sjcCwLCpmnnyN5iqLc46Qx7CC91 56 | wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.BCH)) 57 | address, _ = wallet.GetAddress() 58 | addressBCH, _ := wallet.GetKey().AddressBCH() 59 | fmt.Println("BCH: ", address, addressBCH) 60 | 61 | // LTC: LLCaMFT8AKjDTvz1Ju8JoyYXxuug4PZZmS 62 | wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.LTC)) 63 | address, _ = wallet.GetAddress() 64 | fmt.Println("LTC: ", address) 65 | 66 | // DOGE: DHLA3rJcCjG2tQwvnmoJzD5Ej7dBTQqhHK 67 | wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.DOGE)) 68 | address, _ = wallet.GetAddress() 69 | fmt.Println("DOGE:", address) 70 | 71 | // ETH: 0x37039021cBA199663cBCb8e86bB63576991A28C1 72 | wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.ETH)) 73 | address, _ = wallet.GetAddress() 74 | fmt.Println("ETH: ", address) 75 | 76 | // ETC: 0x480C69E014C7f018dAbF17A98273e90f0b0680cf 77 | wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.ETC)) 78 | address, _ = wallet.GetAddress() 79 | fmt.Println("ETC: ", address) 80 | } 81 | ``` 82 | -------------------------------------------------------------------------------- /enum.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | // mnemonic language 4 | const ( 5 | English = "english" 6 | ChineseSimplified = "chinese_simplified" 7 | ChineseTraditional = "chinese_traditional" 8 | ) 9 | 10 | // zero is deafult of uint32 11 | const ( 12 | Zero uint32 = 0 13 | ZeroQuote uint32 = 0x80000000 14 | BTCToken uint32 = 0x10000000 15 | ETHToken uint32 = 0x20000000 16 | ) 17 | 18 | 19 | // wallet type from bip44 20 | const ( 21 | // https://github.com/satoshilabs/slips/blob/master/slip-0044.md#registered-coin-types 22 | BTC = ZeroQuote + 0 23 | LTC = ZeroQuote + 2 24 | DOGE = ZeroQuote + 3 25 | DASH = ZeroQuote + 5 26 | ETH = ZeroQuote + 60 27 | ETC = ZeroQuote + 61 28 | BCH = ZeroQuote + 145 29 | QTUM = ZeroQuote + 2301 30 | 31 | //my add 32 | TRON = ZeroQuote + 195 33 | EOS = ZeroQuote + 194 34 | XRP = ZeroQuote + 144 35 | ZEN = ZeroQuote + 121 36 | WICC = ZeroQuote + 99999 37 | NULS = ZeroQuote + 8964 38 | IOST = ZeroQuote + 291 39 | 40 | // btc token 41 | USDT = BTCToken + 1 42 | 43 | // eth token 44 | //IOST = ETHToken + 1 //remove 45 | USDC = ETHToken + 2 46 | ) 47 | 48 | var coinTypes = map[uint32]uint32{ 49 | USDT: BTC, 50 | IOST: ETH, 51 | USDC: ETH, 52 | } 53 | -------------------------------------------------------------------------------- /errors.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // errors 8 | var ( 9 | ErrCoinTypeUnknow = errors.New("unknow coin type") 10 | ) 11 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/go-chain/go-hdwallet 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/blocktree/go-owcdrivers v1.1.12 7 | github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 8 | github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d 9 | github.com/cpacia/bchutil v0.0.0-20181003130114-b126f6a35b6c 10 | github.com/eoscanada/eos-go v0.8.16 11 | github.com/ethereum/go-ethereum v1.9.2 12 | github.com/go-chain/go-tron v0.0.0-20190805034144-d8a8e5fd9586 13 | github.com/go-chain/go-xrp v0.0.0-20190826040159-24c51eeb15fe 14 | github.com/iost-official/go-iost v3.3.0+incompatible // indirect 15 | github.com/tyler-smith/go-bip39 v1.0.0 16 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 17 | ) 18 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | docker.io/go-docker v1.0.0/go.mod h1:7tiAn5a0LFmjbPDbyTPOaTTOuG1ZRNXdPA6RvKY+fpY= 3 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 4 | github.com/DataDog/zstd v1.3.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= 5 | github.com/DataDog/zstd v1.4.0/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= 6 | github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= 7 | github.com/Microsoft/go-winio v0.4.12/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= 8 | github.com/NebulousLabs/entropy-mnemonics v0.0.0-20181203154559-bc7e13c5ccd8/go.mod h1:ed2ZsnmJfqVNZOwxWWFZaSHJY3ifOjCS7i5yX9dvKHs= 9 | github.com/Sereal/Sereal v0.0.0-20190408200019-e0834539921c/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM= 10 | github.com/Sereal/Sereal v0.0.0-20190529075751-4d99287c2c28/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM= 11 | github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= 12 | github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI= 13 | github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= 14 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 15 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 16 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 17 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 18 | github.com/allegro/bigcache v1.2.0/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= 19 | github.com/asdine/storm v2.1.2+incompatible/go.mod h1:RarYDc9hq1UPLImuiXK3BIWPJLdIygvV3PsInK0FbVQ= 20 | github.com/assetsadapterstore/tivalue-adapter v1.0.3/go.mod h1:iD9MU+7G3/XPvGlsVFFY5NMRq3VqrWdddJXujQyH9xw= 21 | github.com/astaxie/beego v1.11.1/go.mod h1:i69hVzgauOPSw5qeyF4GVZhn7Od0yG5bbCGzmhbWxgQ= 22 | github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ= 23 | github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU= 24 | github.com/belogik/goes v0.0.0-20151229125003-e54d722c3aff/go.mod h1:PhH1ZhyCzHKt4uAasyx+ljRCgoezetRNf59CUtwUkqY= 25 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 26 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 27 | github.com/binance-chain/go-sdk v1.0.8/go.mod h1:ahR+bb8rCbVRuK9ukmNTr/ghj7n4awioQQgLS5xb7wQ= 28 | github.com/binance-chain/ledger-cosmos-go v0.9.9-binance.1/go.mod h1:FI6WAujuiBpoSavYreux2zTKyrUkngXDlRJczxsDK5M= 29 | github.com/blocktree/arkecosystem-adapter v1.0.4/go.mod h1:InOEfMymxfiD8sSt4hsASZmGA46J2pBeVzaMN8nWjUU= 30 | github.com/blocktree/bitshares-adapter v1.0.5/go.mod h1:tyzkgBUWF65zFQoQSj3l1IRhI/3pkSWFwnG9bnM3XZE= 31 | github.com/blocktree/ddmchain-adapter v1.0.5/go.mod h1:oqsMVtGaRVm0JIEld4Ge9vblhwjSuv4k73artQE+EO8= 32 | github.com/blocktree/eosio-adapter v1.0.0/go.mod h1:Ck5C4aIg+z9DbqjAngn6sVemI5GQF/6BPoxzvdE7pa8= 33 | github.com/blocktree/ethereum-adapter v1.1.10/go.mod h1:jrz6vFh94fb86PjWsdwRAojkjUqznkioz+57liA8TtY= 34 | github.com/blocktree/futurepia-adapter v1.0.9/go.mod h1:46VvLidqafh6kxLKBCFKeVlbVPmjTp0oOhyg9pGxhXM= 35 | github.com/blocktree/futurepia-adapter v1.0.12/go.mod h1:46VvLidqafh6kxLKBCFKeVlbVPmjTp0oOhyg9pGxhXM= 36 | github.com/blocktree/go-owcdrivers v1.0.4/go.mod h1:HS5S8MYW1hdN6hEmwgqu/kWyFPkxvjGN9Le0zAGmFZM= 37 | github.com/blocktree/go-owcdrivers v1.0.5/go.mod h1:HS5S8MYW1hdN6hEmwgqu/kWyFPkxvjGN9Le0zAGmFZM= 38 | github.com/blocktree/go-owcdrivers v1.0.12/go.mod h1:TKevypdvkQD4ItBGscwMJqWWMOhDo9vXwnV1wacNs9w= 39 | github.com/blocktree/go-owcdrivers v1.0.15/go.mod h1:8dHbObmem3ac25DCMxUTBpOgbLaddwv1I3OkO0hG7+8= 40 | github.com/blocktree/go-owcdrivers v1.0.21/go.mod h1:V+u/NTvUrjzxh5FhDW+B9d7+e4UzuGZfF9ImZerCCMA= 41 | github.com/blocktree/go-owcdrivers v1.0.24/go.mod h1:iyyJs7nj3LyRGjcoLnIpUK6238GIGLv9IB3uE6B0I4k= 42 | github.com/blocktree/go-owcdrivers v1.0.37/go.mod h1:ZhndO+bVH1s39I/ECFg2lHwo6OuTI3xfXS2w06rTJtU= 43 | github.com/blocktree/go-owcdrivers v1.0.39/go.mod h1:ZhndO+bVH1s39I/ECFg2lHwo6OuTI3xfXS2w06rTJtU= 44 | github.com/blocktree/go-owcdrivers v1.0.42/go.mod h1:icMC6RUkkOp+Zw9jRZ+x+TCwSosX2v2rT9aePeyn+4E= 45 | github.com/blocktree/go-owcdrivers v1.1.12 h1:oWcihXOwasOEh5i23lZUjfYt3yZWstTxqbSKWuSdvgI= 46 | github.com/blocktree/go-owcdrivers v1.1.12/go.mod h1:Ob+XKMlsFIT+c+1vd9bnBbTiMWn78BPFqFf3w4XUHTI= 47 | github.com/blocktree/go-owcrypt v1.0.1/go.mod h1:5FCinL/4XVEqbmAFTOUgfMJVNJEw6WzVy624qsxzZC8= 48 | github.com/blocktree/go-owcrypt v1.0.2/go.mod h1:5FCinL/4XVEqbmAFTOUgfMJVNJEw6WzVy624qsxzZC8= 49 | github.com/blocktree/go-owcrypt v1.0.3 h1:qfAwJsWYp7WaI26hAwPuFUrMXhD9bWwuGXYWBOLsVes= 50 | github.com/blocktree/go-owcrypt v1.0.3/go.mod h1:5FCinL/4XVEqbmAFTOUgfMJVNJEw6WzVy624qsxzZC8= 51 | github.com/blocktree/moacchain-adapter v1.0.3/go.mod h1:xqI9JVRImzfAqNaRTPsDwSGroCZ+DI7fzA3D5hkS9tA= 52 | github.com/blocktree/nulsio-adapter v1.0.9/go.mod h1:rZCU7FqIodBjRArb1SJ4u2Ft58Zxznx2MxOo27vjxjI= 53 | github.com/blocktree/nulsio-adapter v1.1.5/go.mod h1:4GD5l1GpwZzphGkfNkVOtiZLj918GNuQVBX2W0WqK8Y= 54 | github.com/blocktree/nulsio-adapter v1.1.7/go.mod h1:4GD5l1GpwZzphGkfNkVOtiZLj918GNuQVBX2W0WqK8Y= 55 | github.com/blocktree/ontology-adapter v1.0.8/go.mod h1:NA7qQB0g/85ty9XGLt+I0YeuV7ErnWhTTXC1MH/jCS8= 56 | github.com/blocktree/openwallet v1.4.1/go.mod h1:jStJigV8cNTOmvzvWJ4bdjXhiRvtQtSh++uJxSZRcb0= 57 | github.com/blocktree/openwallet v1.4.3/go.mod h1:jStJigV8cNTOmvzvWJ4bdjXhiRvtQtSh++uJxSZRcb0= 58 | github.com/blocktree/openwallet v1.4.5/go.mod h1:e5IqJ6OqCM5qEN4TTxeeWbd3l3kCRLPC6fG4/KLiA7I= 59 | github.com/blocktree/openwallet v1.4.6/go.mod h1:e5IqJ6OqCM5qEN4TTxeeWbd3l3kCRLPC6fG4/KLiA7I= 60 | github.com/blocktree/openwallet v1.4.8/go.mod h1:e5IqJ6OqCM5qEN4TTxeeWbd3l3kCRLPC6fG4/KLiA7I= 61 | github.com/blocktree/ripple-adapter v1.0.3/go.mod h1:9BidhMwPmLjKnyuI7YurlyFCNdX4SzLsXG835q8zfLQ= 62 | github.com/blocktree/ripple-adapter v1.0.13/go.mod h1:eHHzuuFqm9NnWfc+wpx0XgcKQPxGmiyZ5pFcLV4ngjA= 63 | github.com/blocktree/virtualeconomy-adapter v1.1.5/go.mod h1:L1qpSNof49eCtN1ep/LEz2H9ngKsDxzhRqoistQWa/U= 64 | github.com/blocktree/waykichain-adapter v1.0.3/go.mod h1:WwX/retaUfrLYP4ZOFVxtC4Duw1R4cjs+ErfjefqhEU= 65 | github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U= 66 | github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60= 67 | github.com/bradfitz/gomemcache v0.0.0-20190329173943-551aad21a668/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= 68 | github.com/bradhe/stopwatch v0.0.0-20180424000511-fd55e776a960/go.mod h1:P/j2DSP/kCOakHBACzMqmOdrTEieqdSiB3U9fqk7qgc= 69 | github.com/btcsuite/btcd v0.0.0-20181013004428-67e573d211ac/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= 70 | github.com/btcsuite/btcd v0.0.0-20181130015935-7d2daa5bfef2/go.mod h1:Jr9bmNVGZ7TH2Ux1QuP0ec+yGgh0gE9FIlkzQiI5bR0= 71 | github.com/btcsuite/btcd v0.0.0-20190315201642-aa6e0f35703c/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= 72 | github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0= 73 | github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= 74 | github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= 75 | github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= 76 | github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= 77 | github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= 78 | github.com/btcsuite/btcutil v0.0.0-20190316010144-3ac1210f4b38/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= 79 | github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= 80 | github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= 81 | github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= 82 | github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= 83 | github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= 84 | github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= 85 | github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= 86 | github.com/bwmarrin/snowflake v0.0.0-20180412010544-68117e6bbede/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= 87 | github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE= 88 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 89 | github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= 90 | github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= 91 | github.com/codeskyblue/go-sh v0.0.0-20190328095946-f4ce45e7999e/go.mod h1:2hUMLQDY+46DXIf/i7n2rUCHUwF3gZrb4slZV8C4RYI= 92 | github.com/coreos/go-iptables v0.4.0/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU= 93 | github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= 94 | github.com/couchbase/go-couchbase v0.0.0-20181122212707-3e9b6e1258bb/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U= 95 | github.com/couchbase/go-couchbase v0.0.0-20190401022532-e1757383bdca/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U= 96 | github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c= 97 | github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs= 98 | github.com/cpacia/bchutil v0.0.0-20181003130114-b126f6a35b6c h1:4e6Zsb6LFd3kadoMiut2zcd3hCb4zywpJnQa8+NV2Cs= 99 | github.com/cpacia/bchutil v0.0.0-20181003130114-b126f6a35b6c/go.mod h1:k5D13LCXSsMrQyfdW0yGYs4GWUvirqoxHht8qwtqyRY= 100 | github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY= 101 | github.com/cweill/gotests v1.5.3/go.mod h1:XZYOJkGVkCRoymaIzmp9Wyi3rUgfA3oOnkuljYrjFV8= 102 | github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495 h1:6IyqGr3fnd0tM3YxipK27TUskaOVUjU2nG45yzwcQKY= 103 | github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 104 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 105 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 106 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 107 | github.com/denkhaus/bitshares v0.6.1-0.20190502142618-5ae8c00cb394/go.mod h1:sqR/EYCsPyCVo4gqT8BmvogqU/JTl90PMr13wIHFLEE= 108 | github.com/denkhaus/gojson v1.0.0/go.mod h1:DkbeLekwsSNeg+G3ns0YdxtbRMr1OoPoxf+rcrd1d44= 109 | github.com/denkhaus/logging v0.0.0-20180714213349-14bfb935047c/go.mod h1:NoshWlJzg/buES7COwcZSPtRKrnfJI+TyRyzWrCoEm0= 110 | github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= 111 | github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= 112 | github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= 113 | github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= 114 | github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= 115 | github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= 116 | github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= 117 | github.com/eoscanada/eos-go v0.8.10/go.mod h1:RKrm2XzZEZWxSMTRqH5QOyJ1fb/qKEjs2ix1aQl0sk4= 118 | github.com/eoscanada/eos-go v0.8.16 h1:NsgiB3FLvF09SAg38m8PMJh3kT+/+XzWaKdwjGla3Js= 119 | github.com/eoscanada/eos-go v0.8.16/go.mod h1:RKrm2XzZEZWxSMTRqH5QOyJ1fb/qKEjs2ix1aQl0sk4= 120 | github.com/ethereum/go-ethereum v1.8.24/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= 121 | github.com/ethereum/go-ethereum v1.8.25/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= 122 | github.com/ethereum/go-ethereum v1.9.2 h1:RMIHDO/diqXEgORSVzYx8xW9x2+S32PoAX5lQwya0Lw= 123 | github.com/ethereum/go-ethereum v1.9.2/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= 124 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 125 | github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= 126 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 127 | github.com/go-chain/go-tron v0.0.0-20190805034144-d8a8e5fd9586 h1:opMGOhjveI+dzVI0sqk3Ryi0aSOmrZGorkaa0pYtJGU= 128 | github.com/go-chain/go-tron v0.0.0-20190805034144-d8a8e5fd9586/go.mod h1:Nc3Fqzau99mrslo7pl01z/VSN1dxfHV+SFnn8/MmEtk= 129 | github.com/go-chain/go-xrp v0.0.0-20190826040159-24c51eeb15fe h1:Dz/vOKITU1BthF4gryieHDbhT4ly+hLwZr4HjSsZuyc= 130 | github.com/go-chain/go-xrp v0.0.0-20190826040159-24c51eeb15fe/go.mod h1:h2uhXLfudIivSq/JM8Mwf0spZz0xDj0xN6VIbxSE6r4= 131 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 132 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 133 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 134 | github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= 135 | github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= 136 | github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= 137 | github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= 138 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 139 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 140 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 141 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 142 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 143 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 144 | github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 145 | github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= 146 | github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= 147 | github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 148 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 149 | github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 150 | github.com/graarh/golang-socketio v0.0.0-20170510162725-2c44953b9b5f/go.mod h1:8gudiNCFh3ZfvInknmoXzPeV17FSH+X2J5k2cUPIwnA= 151 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 152 | github.com/imroc/req v0.2.3/go.mod h1:J9FsaNHDTIVyW/b5r6/Df5qKEEEq2WzZKIgKSajd1AE= 153 | github.com/iost-official/go-iost v3.3.0+incompatible h1:XWe6Yf5Bf3Wh1ISkTfjWMv+uWseY3FT5LN4iEKkKer8= 154 | github.com/iost-official/go-iost v3.3.0+incompatible/go.mod h1:y+TV3xUWaJIPcRCMdf7/dAS5HzcatqDiQBl9SEC0nis= 155 | github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= 156 | github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= 157 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 158 | github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= 159 | github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= 160 | github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= 161 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 162 | github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= 163 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 164 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 165 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 166 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 167 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 168 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 169 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 170 | github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= 171 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 172 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 173 | github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 174 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 175 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= 176 | github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= 177 | github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= 178 | github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= 179 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 180 | github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= 181 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 182 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 183 | github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= 184 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 185 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 186 | github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 187 | github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= 188 | github.com/ontio/ontology v1.6.2/go.mod h1:1Tw+XYq8tDX9hqJ1qB51FCzVqntTQipyOL+ibKbaFSg= 189 | github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= 190 | github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= 191 | github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= 192 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 193 | github.com/peterh/liner v1.1.0/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= 194 | github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= 195 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 196 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 197 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 198 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 199 | github.com/pquerna/ffjson v0.0.0-20181028064349-e517b90714f7/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M= 200 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 201 | github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= 202 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 203 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 204 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 205 | github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 206 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 207 | github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= 208 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 209 | github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 210 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 211 | github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= 212 | github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= 213 | github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= 214 | github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= 215 | github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw= 216 | github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg= 217 | github.com/siddontang/ledisdb v0.0.0-20190202134119-8ceb77e66a92/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg= 218 | github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA= 219 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 220 | github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE= 221 | github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= 222 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 223 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 224 | github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= 225 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 226 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 227 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 228 | github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= 229 | github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= 230 | github.com/tendermint/btcd v0.0.0-20180816174608-e5840949ff4f/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= 231 | github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9/go.mod h1:nt45hbhDkWVdMBkr2TOgOzCrpBccXdN09WOiOYTHVEk= 232 | github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= 233 | github.com/tendermint/tendermint v0.31.2-rc0/go.mod h1:ymcPyWblXCplCPQjbOYbrF1fWnpslATMVqiGgWbZrlc= 234 | github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5/go.mod h1:f1SCnEOt6sc3fOJfPQDRDzHOtSXuTtnz0ImG9kPRDV0= 235 | github.com/tidwall/gjson v1.2.1/go.mod h1:c/nTNbUr0E0OrXEhq1pwa8iEgc2DOt4ZZqAt1HtCkPA= 236 | github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= 237 | github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= 238 | github.com/tidwall/sjson v1.0.4/go.mod h1:bURseu1nuBkFpIES5cz6zBtjmYeOQmEESshn7VpF15Y= 239 | github.com/tyler-smith/go-bip39 v1.0.0 h1:FOHg9gaQLeBBRbHE/QrTLfEiBHy5pQ/yXzf9JG5pYFM= 240 | github.com/tyler-smith/go-bip39 v1.0.0/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= 241 | github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= 242 | github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc= 243 | github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= 244 | github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= 245 | github.com/zondax/ledger-go v0.9.0/go.mod h1:b2vIcu3u9gJoIx4kTWuXOgzGV7FPWeUktqRqVf6feG0= 246 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 247 | go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 248 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 249 | go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 250 | golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 h1:9lP3x0pW80sDI6t1UMSLA4to18W7R7imwAI/sWS9S8Q= 251 | golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 252 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 253 | golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 254 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 255 | golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= 256 | golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= 257 | golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 258 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0= 259 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 260 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 261 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 262 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 263 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 264 | golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 265 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 266 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 267 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 268 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 269 | golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 270 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 271 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 272 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 273 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 274 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 275 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 276 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 277 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 278 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 279 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 280 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 281 | golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 282 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 283 | golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 284 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= 285 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 286 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 287 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 288 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 289 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 290 | google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 291 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 292 | google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 293 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 294 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 295 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 296 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 297 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 298 | gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= 299 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 300 | gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= 301 | gopkg.in/resty.v1 v1.10.3/go.mod h1:nrgQYbPhkRfn2BfT32NNTLfq3K9NuHRB0MsAcA9weWY= 302 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 303 | gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637/go.mod h1:BHsqpu/nsuzkT5BpiH1EMZPLyqSMM8JbIavyFACoFNk= 304 | gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= 305 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 306 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 307 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 308 | -------------------------------------------------------------------------------- /key.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "crypto/ecdsa" 5 | "encoding/hex" 6 | "github.com/btcsuite/btcd/btcec" 7 | "github.com/btcsuite/btcd/txscript" 8 | "github.com/btcsuite/btcutil" 9 | "github.com/btcsuite/btcutil/hdkeychain" 10 | "github.com/cpacia/bchutil" 11 | ) 12 | 13 | // Key struct 14 | type Key struct { 15 | opt *Options 16 | Extended *hdkeychain.ExtendedKey 17 | 18 | // for btc 19 | Private *btcec.PrivateKey 20 | Public *btcec.PublicKey 21 | 22 | // for eth 23 | PrivateECDSA *ecdsa.PrivateKey 24 | PublicECDSA *ecdsa.PublicKey 25 | } 26 | 27 | // NewKey creates a master key 28 | // params: [Mnemonic], [Password], [Language], [Seed] 29 | func NewKey(opts ...Option) (*Key, error) { 30 | var ( 31 | err error 32 | o = newOptions(opts...) 33 | ) 34 | 35 | if len(o.Seed) <= 0 { 36 | o.Seed, err = NewSeed(o.Mnemonic, o.Password, o.Language) 37 | } 38 | 39 | if err != nil { 40 | return nil, err 41 | } 42 | 43 | extended, err := hdkeychain.NewMaster(o.Seed, o.Params) 44 | if err != nil { 45 | return nil, err 46 | } 47 | 48 | key := &Key{ 49 | opt: o, 50 | Extended: extended, 51 | } 52 | 53 | err = key.init() 54 | if err != nil { 55 | return nil, err 56 | } 57 | 58 | return key, nil 59 | } 60 | 61 | func (k *Key) init() error { 62 | var err error 63 | 64 | k.Private, err = k.Extended.ECPrivKey() 65 | if err != nil { 66 | return err 67 | } 68 | 69 | k.Public, err = k.Extended.ECPubKey() 70 | if err != nil { 71 | return err 72 | } 73 | 74 | k.PrivateECDSA = k.Private.ToECDSA() 75 | k.PublicECDSA = &k.PrivateECDSA.PublicKey 76 | return nil 77 | } 78 | 79 | // GetChildKey return a key from master key 80 | // params: [Purpose], [CoinType], [Account], [Change], [AddressIndex], [Path] 81 | func (k *Key) GetChildKey(opts ...Option) (*Key, error) { 82 | var ( 83 | err error 84 | o = newOptions(opts...) 85 | no = o 86 | ) 87 | 88 | typ, ok := coinTypes[o.CoinType] 89 | if ok { 90 | no = newOptions(append(opts, CoinType(typ))...) 91 | } 92 | 93 | extended := k.Extended 94 | for _, i := range no.GetPath() { 95 | extended, err = extended.Child(i) 96 | if err != nil { 97 | return nil, err 98 | } 99 | } 100 | 101 | key := &Key{ 102 | opt: o, 103 | Extended: extended, 104 | } 105 | 106 | //fmt.Println(no.GetPath()) 107 | err = key.init() 108 | if err != nil { 109 | return nil, err 110 | } 111 | 112 | return key, nil 113 | } 114 | 115 | // GetWallet return wallet from master key 116 | // params: [Purpose], [CoinType], [Account], [Change], [AddressIndex], [Path] 117 | func (k *Key) GetWallet(opts ...Option) (Wallet, error) { 118 | key, err := k.GetChildKey(opts...) 119 | if err != nil { 120 | return nil, err 121 | } 122 | 123 | coin, ok := coins[key.opt.CoinType] 124 | if !ok { 125 | return nil, ErrCoinTypeUnknow 126 | } 127 | 128 | return coin(key), nil 129 | } 130 | 131 | // PrivateHex generate private key to string by hex 132 | func (k *Key) PrivateHex() string { 133 | return hex.EncodeToString(k.Private.Serialize()) 134 | } 135 | 136 | // PrivateWIF generate private key to string by wif 137 | func (k *Key) PrivateWIF(compress bool) (string, error) { 138 | wif, err := btcutil.NewWIF(k.Private, k.opt.Params, compress) 139 | if err != nil { 140 | return "", err 141 | } 142 | 143 | return wif.String(), nil 144 | } 145 | 146 | // PublicHex generate public key to string by hex 147 | func (k *Key) PublicHex(compress bool) string { 148 | if compress { 149 | return hex.EncodeToString(k.Public.SerializeCompressed()) 150 | } 151 | 152 | return hex.EncodeToString(k.Public.SerializeUncompressed()) 153 | } 154 | 155 | // PublicHash generate public key by hash160 156 | func (k *Key) PublicHash() ([]byte, error) { 157 | address, err := k.Extended.Address(k.opt.Params) 158 | if err != nil { 159 | return nil, err 160 | } 161 | 162 | return address.ScriptAddress(), nil 163 | } 164 | 165 | // AddressBTC generate public key to btc style address 166 | func (k *Key) AddressBTC() (string, error) { 167 | address, err := k.Extended.Address(k.opt.Params) 168 | if err != nil { 169 | return "", err 170 | } 171 | 172 | return address.EncodeAddress(), nil 173 | } 174 | 175 | // AddressBCH generate public key to bch style address 176 | func (k *Key) AddressBCH() (string, error) { 177 | address, err := k.Extended.Address(k.opt.Params) 178 | if err != nil { 179 | return "", err 180 | } 181 | 182 | addr, err := bchutil.NewCashAddressPubKeyHash(address.ScriptAddress(), k.opt.Params) 183 | if err != nil { 184 | return "", err 185 | } 186 | 187 | data := addr.EncodeAddress() 188 | prefix := bchutil.Prefixes[k.opt.Params.Name] 189 | return prefix + ":" + data, nil 190 | } 191 | 192 | // AddressP2WPKH generate public key to p2wpkh style address 193 | func (k *Key) AddressP2WPKH() (string, error) { 194 | pubHash, err := k.PublicHash() 195 | if err != nil { 196 | return "", err 197 | } 198 | 199 | addr, err := btcutil.NewAddressWitnessPubKeyHash(pubHash, k.opt.Params) 200 | if err != nil { 201 | return "", err 202 | } 203 | 204 | return addr.EncodeAddress(), nil 205 | } 206 | 207 | // AddressP2WPKHInP2SH generate public key to p2wpkh nested within p2sh style address 208 | func (k *Key) AddressP2WPKHInP2SH() (string, error) { 209 | pubHash, err := k.PublicHash() 210 | if err != nil { 211 | return "", err 212 | } 213 | 214 | addr, err := btcutil.NewAddressWitnessPubKeyHash(pubHash, k.opt.Params) 215 | if err != nil { 216 | return "", err 217 | } 218 | 219 | script, err := txscript.PayToAddrScript(addr) 220 | if err != nil { 221 | return "", err 222 | } 223 | 224 | addr1, err := btcutil.NewAddressScriptHash(script, k.opt.Params) 225 | if err != nil { 226 | return "", err 227 | } 228 | 229 | return addr1.EncodeAddress(), nil 230 | } 231 | -------------------------------------------------------------------------------- /mnemonic.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/tyler-smith/go-bip39" 5 | "github.com/tyler-smith/go-bip39/wordlists" 6 | ) 7 | 8 | func setLanguage(language string) { 9 | switch language { 10 | case ChineseSimplified: 11 | bip39.SetWordList(wordlists.ChineseSimplified) 12 | case ChineseTraditional: 13 | bip39.SetWordList(wordlists.ChineseTraditional) 14 | } 15 | } 16 | 17 | // NewMnemonic creates a random mnemonic 18 | func NewMnemonic(length int, language string) (string, error) { 19 | setLanguage(language) 20 | 21 | if length < 12 { 22 | length = 12 23 | } 24 | 25 | if length > 24 { 26 | length = 24 27 | } 28 | 29 | entropy, err := bip39.NewEntropy(length / 3 * 32) 30 | if err != nil { 31 | return "", err 32 | } 33 | 34 | return bip39.NewMnemonic(entropy) 35 | } 36 | 37 | // NewSeed creates a hashed seed 38 | func NewSeed(mnemonic, password, language string) ([]byte, error) { 39 | setLanguage(language) 40 | return bip39.NewSeedWithErrorChecking(mnemonic, password) 41 | } 42 | -------------------------------------------------------------------------------- /option.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/btcsuite/btcd/chaincfg" 5 | ) 6 | 7 | // default options 8 | var ( 9 | DefaultParams = &chaincfg.MainNetParams 10 | 11 | // master key options 12 | DefaultPassword = "" 13 | DefaultLanguage = "" 14 | 15 | // child key options 16 | DefaultPurpose = ZeroQuote + 44 17 | DefaultCoinType = BTC 18 | DefaultAccount = ZeroQuote 19 | DefaultChange = Zero 20 | DefaultAddressIndex = Zero 21 | ) 22 | 23 | // Option of key 24 | type Option func(*Options) 25 | 26 | // Options of key 27 | type Options struct { 28 | Params *chaincfg.Params 29 | 30 | // master key options 31 | Mnemonic string 32 | Password string 33 | Language string 34 | Seed []byte 35 | 36 | // child key options 37 | Purpose uint32 38 | CoinType uint32 39 | Account uint32 40 | Change uint32 41 | AddressIndex uint32 42 | } 43 | 44 | func newOptions(opts ...Option) *Options { 45 | opt := &Options{ 46 | Params: DefaultParams, 47 | Password: DefaultPassword, 48 | Language: DefaultLanguage, 49 | Purpose: DefaultPurpose, 50 | CoinType: DefaultCoinType, 51 | Account: DefaultAccount, 52 | Change: DefaultChange, 53 | AddressIndex: DefaultAddressIndex, 54 | } 55 | 56 | for _, o := range opts { 57 | o(opt) 58 | } 59 | 60 | return opt 61 | } 62 | 63 | // GetPath return path in bip44 style 64 | func (o *Options) GetPath() []uint32 { 65 | return []uint32{ 66 | o.Purpose, 67 | o.CoinType, 68 | o.Account, 69 | o.Change, 70 | o.AddressIndex, 71 | } 72 | } 73 | 74 | // Params set to options 75 | func Params(p *chaincfg.Params) Option { 76 | return func(o *Options) { 77 | o.Params = p 78 | } 79 | } 80 | 81 | // Mnemonic set to options 82 | func Mnemonic(m string) Option { 83 | return func(o *Options) { 84 | o.Mnemonic = m 85 | } 86 | } 87 | 88 | // Password set to options 89 | func Password(p string) Option { 90 | return func(o *Options) { 91 | o.Password = p 92 | } 93 | } 94 | 95 | // Language set to options 96 | func Language(l string) Option { 97 | return func(o *Options) { 98 | o.Language = l 99 | } 100 | } 101 | 102 | // Seed set to options 103 | func Seed(s []byte) Option { 104 | return func(o *Options) { 105 | o.Seed = s 106 | } 107 | } 108 | 109 | // Purpose set to options 110 | func Purpose(p uint32) Option { 111 | return func(o *Options) { 112 | o.Purpose = p 113 | } 114 | } 115 | 116 | // CoinType set to options 117 | func CoinType(c uint32) Option { 118 | return func(o *Options) { 119 | o.CoinType = c 120 | } 121 | } 122 | 123 | // Account set to options 124 | func Account(a uint32) Option { 125 | return func(o *Options) { 126 | o.Account = a 127 | } 128 | } 129 | 130 | // Change set to options 131 | func Change(c uint32) Option { 132 | return func(o *Options) { 133 | o.Change = c 134 | } 135 | } 136 | 137 | // AddressIndex set to options 138 | func AddressIndex(a uint32) Option { 139 | return func(o *Options) { 140 | o.AddressIndex = a 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /params.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/btcsuite/btcd/chaincfg" 5 | ) 6 | 7 | // init net params 8 | var ( 9 | BTCParams = chaincfg.MainNetParams 10 | LTCParams = chaincfg.MainNetParams 11 | DOGEParams = chaincfg.MainNetParams 12 | DASHParams = chaincfg.MainNetParams 13 | BCHParams = chaincfg.MainNetParams 14 | QTUMParams = chaincfg.MainNetParams 15 | USDTParams = chaincfg.MainNetParams 16 | ZENParams = chaincfg.MainNetParams 17 | WICCParams = chaincfg.MainNetParams 18 | 19 | ) 20 | 21 | func init() { 22 | // ltc net params 23 | // https://github.com/litecoin-project/litecoin/blob/master/src/chainparams.cpp 24 | LTCParams.Bech32HRPSegwit = "ltc" 25 | LTCParams.PubKeyHashAddrID = 0x30 // 48 26 | LTCParams.ScriptHashAddrID = 0x32 // 50 27 | LTCParams.PrivateKeyID = 0xb0 // 176 28 | 29 | // doge net params 30 | // https://github.com/dogecoin/dogecoin/blob/master/src/chainparams.cpp 31 | DOGEParams.PubKeyHashAddrID = 0x1e // 30 32 | DOGEParams.ScriptHashAddrID = 0x16 // 22 33 | DOGEParams.PrivateKeyID = 0x9e // 158 34 | 35 | // dash net params 36 | // https://github.com/dashpay/dash/blob/master/src/chainparams.cpp 37 | DASHParams.PubKeyHashAddrID = 0x4c // 76 38 | DASHParams.ScriptHashAddrID = 0x10 // 16 39 | DASHParams.PrivateKeyID = 0xcc // 204 40 | 41 | //zen net params 42 | // https://github.com/dashpay/dash/blob/master/src/chainparams.cpp 43 | ZENParams.PubKeyHashAddrID = 1// 76 44 | ZENParams.ScriptHashAddrID = 0x10 // 16 45 | ZENParams.PrivateKeyID = 0xcc // 204 46 | 47 | //wicc net params 48 | WICCParams.PubKeyHashAddrID = 0x49// 76 49 | WICCParams.ScriptHashAddrID = 0x10 // 16 50 | WICCParams.PrivateKeyID = 0x99 // 204 51 | 52 | 53 | 54 | // bch net params 55 | // https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/src/chainparams.cpp 56 | BCHParams.PubKeyHashAddrID = 0x00 // 0 57 | BCHParams.ScriptHashAddrID = 0x05 // 5 58 | BCHParams.PrivateKeyID = 0x80 // 128 59 | 60 | // qtum net params 61 | // https://github.com/qtumproject/qtum/blob/master/src/chainparams.cpp 62 | QTUMParams.PubKeyHashAddrID = 0x3a // 58 63 | QTUMParams.ScriptHashAddrID = 0x32 // 50 64 | QTUMParams.PrivateKeyID = 0x80 // 128 65 | 66 | // usdt net params 67 | // https://github.com/OmniLayer/omnicore/blob/master/src/chainparams.cpp 68 | USDTParams.PubKeyHashAddrID = 0x00 // 0 69 | USDTParams.ScriptHashAddrID = 0x05 // 5 70 | USDTParams.PrivateKeyID = 0x80 // 128 71 | } 72 | -------------------------------------------------------------------------------- /wallet.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | var coins = make(map[uint32]func(*Key) Wallet) 4 | 5 | // Wallet interface 6 | type Wallet interface { 7 | GetType() uint32 8 | GetName() string 9 | GetSymbol() string 10 | GetKey() *Key 11 | GetAddress() (string, error) 12 | } 13 | -------------------------------------------------------------------------------- /wallet_bch.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | func init() { 4 | coins[BCH] = newBCH 5 | } 6 | 7 | type bch struct { 8 | *btc 9 | } 10 | 11 | func newBCH(key *Key) Wallet { 12 | 13 | if key.opt.Params == nil { 14 | key.opt.Params = &BCHParams 15 | } 16 | token := newBTC(key).(*btc) 17 | token.name = "Bitcoin Cash" 18 | token.symbol = "BCH" 19 | 20 | return &bch{btc: token} 21 | } 22 | -------------------------------------------------------------------------------- /wallet_btc.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | func init() { 4 | coins[BTC] = newBTC 5 | } 6 | 7 | type btc struct { 8 | name string 9 | symbol string 10 | key *Key 11 | } 12 | 13 | func newBTC(key *Key) Wallet { 14 | return &btc{ 15 | name: "Bitcoin", 16 | symbol: "BTC", 17 | key: key, 18 | } 19 | } 20 | 21 | func (c *btc) GetType() uint32 { 22 | return c.key.opt.CoinType 23 | } 24 | 25 | func (c *btc) GetName() string { 26 | return c.name 27 | } 28 | 29 | func (c *btc) GetSymbol() string { 30 | return c.symbol 31 | } 32 | 33 | func (c *btc) GetKey() *Key { 34 | return c.key 35 | } 36 | 37 | func (c *btc) GetAddress() (string, error) { 38 | return c.key.AddressBTC() 39 | } 40 | -------------------------------------------------------------------------------- /wallet_dash.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | func init() { 4 | coins[DASH] = newDASH 5 | } 6 | 7 | type dash struct { 8 | *btc 9 | } 10 | 11 | func newDASH(key *Key) Wallet { 12 | if key.opt.Params == nil { 13 | key.opt.Params = &DASHParams 14 | } 15 | token := newBTC(key).(*btc) 16 | token.name = "Dash" 17 | token.symbol = "DASH" 18 | 19 | return &dash{btc: token} 20 | } 21 | -------------------------------------------------------------------------------- /wallet_doge.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | func init() { 4 | coins[DOGE] = newDOGE 5 | } 6 | 7 | type doge struct { 8 | *btc 9 | } 10 | 11 | func newDOGE(key *Key) Wallet { 12 | token := newBTC(key).(*btc) 13 | token.name = "Dogecoin" 14 | token.symbol = "DOGE" 15 | token.key.opt.Params = &DOGEParams 16 | 17 | return &doge{btc: token} 18 | } 19 | -------------------------------------------------------------------------------- /wallet_eos.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/btcsuite/btcd/chaincfg" 5 | "github.com/btcsuite/btcutil" 6 | "github.com/eoscanada/eos-go/ecc" 7 | ) 8 | 9 | 10 | func init() { 11 | coins[EOS] = newEOS 12 | } 13 | 14 | type eos struct { 15 | name string 16 | symbol string 17 | key *Key 18 | } 19 | 20 | func newEOS(key *Key) Wallet { 21 | return &eos{ 22 | name: "eos", 23 | symbol: "eos", 24 | key: key, 25 | } 26 | } 27 | 28 | func (c *eos) GetType() uint32 { 29 | return c.key.opt.CoinType 30 | } 31 | 32 | func (c *eos) GetName() string { 33 | return c.name 34 | } 35 | 36 | func (c *eos) GetSymbol() string { 37 | return c.symbol 38 | } 39 | 40 | func (c *eos) GetKey() *Key { 41 | return c.key 42 | } 43 | 44 | func (c *eos) GetAddress() (string, error) { 45 | 46 | wif, err := btcutil.NewWIF(c.GetKey().Private,&chaincfg.MainNetParams,true) 47 | if err != nil { 48 | panic(err) 49 | } 50 | 51 | acc, err := ecc.NewPrivateKey(wif.String()) 52 | if err != nil { 53 | return "",err 54 | } 55 | 56 | return acc.PublicKey().String(),nil 57 | } 58 | 59 | -------------------------------------------------------------------------------- /wallet_etc.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/ethereum/go-ethereum/crypto" 5 | ) 6 | 7 | func init() { 8 | coins[ETC] = newETC 9 | } 10 | 11 | type etc struct { 12 | name string 13 | symbol string 14 | key *Key 15 | } 16 | 17 | func newETC(key *Key) Wallet { 18 | return &etc{ 19 | name: "Ethereum Classic", 20 | symbol: "ETC", 21 | key: key, 22 | } 23 | } 24 | 25 | func (c *etc) GetType() uint32 { 26 | return c.key.opt.CoinType 27 | } 28 | 29 | func (c *etc) GetName() string { 30 | return c.name 31 | } 32 | 33 | func (c *etc) GetSymbol() string { 34 | return c.symbol 35 | } 36 | 37 | func (c *etc) GetKey() *Key { 38 | return c.key 39 | } 40 | 41 | func (c *etc) GetAddress() (string, error) { 42 | return crypto.PubkeyToAddress(*c.key.PublicECDSA).Hex(), nil 43 | } 44 | -------------------------------------------------------------------------------- /wallet_eth.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/ethereum/go-ethereum/crypto" 5 | ) 6 | 7 | func init() { 8 | coins[ETH] = newETH 9 | } 10 | 11 | type eth struct { 12 | name string 13 | symbol string 14 | key *Key 15 | 16 | // eth token 17 | contract string 18 | } 19 | 20 | func newETH(key *Key) Wallet { 21 | return ð{ 22 | name: "Ethereum", 23 | symbol: "ETH", 24 | key: key, 25 | } 26 | } 27 | 28 | func (c *eth) GetType() uint32 { 29 | return c.key.opt.CoinType 30 | } 31 | 32 | func (c *eth) GetName() string { 33 | return c.name 34 | } 35 | 36 | func (c *eth) GetSymbol() string { 37 | return c.symbol 38 | } 39 | 40 | func (c *eth) GetKey() *Key { 41 | return c.key 42 | } 43 | 44 | func (c *eth) GetAddress() (string, error) { 45 | return crypto.PubkeyToAddress(*c.key.PublicECDSA).Hex(), nil 46 | } 47 | -------------------------------------------------------------------------------- /wallet_iost.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import "github.com/iost-official/go-iost/account" 4 | 5 | func init() { 6 | coins[IOST] = newIOST 7 | } 8 | 9 | type iost struct { 10 | name string 11 | symbol string 12 | key *Key 13 | } 14 | 15 | func newIOST(key *Key) Wallet { 16 | return &iost{ 17 | name: "Internet of Services", 18 | symbol: "IOST", 19 | key: key, 20 | } 21 | } 22 | 23 | func (c *iost) GetType() uint32 { 24 | return c.key.opt.CoinType 25 | } 26 | 27 | func (c *iost) GetName() string { 28 | return c.name 29 | } 30 | 31 | func (c *iost) GetSymbol() string { 32 | return c.symbol 33 | } 34 | 35 | func (c *iost) GetKey() *Key { 36 | return c.key 37 | } 38 | 39 | func (c *iost) GetAddress() (string,error) { 40 | return account.EncodePubkey(c.key.Public.SerializeCompressed()),nil 41 | } -------------------------------------------------------------------------------- /wallet_ltc.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | func init() { 4 | coins[LTC] = newLTC 5 | } 6 | 7 | type ltc struct { 8 | *btc 9 | } 10 | 11 | func newLTC(key *Key) Wallet { 12 | 13 | if key.opt.Params == nil { 14 | key.opt.Params = <CParams 15 | } 16 | 17 | token := newBTC(key).(*btc) 18 | token.name = "Litecoin" 19 | token.symbol = "LTC" 20 | 21 | return <c{btc: token} 22 | } 23 | -------------------------------------------------------------------------------- /wallet_nuls.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "crypto/sha256" 5 | "errors" 6 | "github.com/btcsuite/btcutil/base58" 7 | "golang.org/x/crypto/ripemd160" 8 | ) 9 | 10 | func init() { 11 | coins[NULS] = newNULS 12 | } 13 | 14 | type nuls struct { 15 | name string 16 | symbol string 17 | key *Key 18 | } 19 | 20 | func newNULS(key *Key) Wallet { 21 | return &nuls{ 22 | name: "nulsio", 23 | symbol: "nuls", 24 | key: key, 25 | } 26 | } 27 | 28 | func (c *nuls) GetType() uint32 { 29 | return c.key.opt.CoinType 30 | } 31 | 32 | func (c *nuls) GetName() string { 33 | return c.name 34 | } 35 | 36 | func (c *nuls) GetSymbol() string { 37 | return c.symbol 38 | } 39 | 40 | func (c *nuls) GetKey() *Key { 41 | return c.key 42 | } 43 | 44 | func (c *nuls) GetAddress() (string, error) { 45 | return GetAddressByPub(c.key.Public.SerializeCompressed()) 46 | } 47 | 48 | type NULSAddress struct { 49 | AddType uint8 50 | Prefix string 51 | } 52 | 53 | const addType = 1 54 | var ( 55 | constant = []rune{'a', 'b', 'c', 'd', 'e'} 56 | 57 | NULS_defalut NULSAddress 58 | 59 | NULS_mainnetAddress = NULSAddress{AddType:1,Prefix:"NULS"} 60 | NULS_testnetAddress = NULSAddress{AddType:2,Prefix:"tNULS"} 61 | 62 | ) 63 | 64 | //sha256之后hash160 65 | func Sha256hash160(pub []byte) []byte { 66 | h := sha256.New() 67 | h.Write(pub) 68 | hasher := ripemd160.New() 69 | hasher.Write(h.Sum(nil)) 70 | hashBytes := hasher.Sum(nil) 71 | return hashBytes 72 | } 73 | 74 | func GetAddressByPub(pub []byte) (string, error) { 75 | pubPart := Sha256hash160(pub) 76 | if len(pubPart) != 20 { 77 | return "", errors.New("pubPart len not 20") 78 | } 79 | chainPart := ShortToBytes(int(NULS_defalut.AddType)) 80 | resultPart1 := make([]byte, 23) 81 | for index, v := range chainPart { 82 | resultPart1[index] = v 83 | } 84 | resultPart1[2] = addType 85 | for index, v := range pubPart { 86 | resultPart1[index+3] = v 87 | } 88 | xor := GetXor(resultPart1) 89 | resultPart2 := make([]byte, 24) 90 | for index, v := range resultPart1 { 91 | resultPart2[index] = v 92 | } 93 | resultPart2[23] = xor 94 | resultBytes := base58.Encode(resultPart2) 95 | return NULS_defalut.Prefix + string(constant[len(NULS_defalut.Prefix)-1]) + string(resultBytes), nil 96 | } 97 | 98 | //异或方法 99 | func GetXor(body []byte) byte { 100 | var xor byte 101 | xor = 0x00 102 | for i := 0; i < len(body); i++ { 103 | xor = byte(xor) ^ body[i] 104 | } 105 | return xor 106 | } 107 | 108 | //chainid转换 109 | func ShortToBytes(val int) []byte { 110 | bytes := make([]byte, 2) 111 | bytes[1] = (byte)(0xFF & (val >> 8)) 112 | bytes[0] = (byte)(0xFF & (val >> 0)) 113 | return bytes 114 | } 115 | -------------------------------------------------------------------------------- /wallet_qtum.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | func init() { 4 | coins[QTUM] = newQTUM 5 | } 6 | 7 | type qtum struct { 8 | *btc 9 | } 10 | 11 | func newQTUM(key *Key) Wallet { 12 | token := newBTC(key).(*btc) 13 | token.name = "Qtum" 14 | token.symbol = "QTUM" 15 | token.key.opt.Params = &QTUMParams 16 | 17 | return &qtum{btc: token} 18 | } 19 | -------------------------------------------------------------------------------- /wallet_trx.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/go-chain/go-tron/address" 5 | ) 6 | 7 | 8 | func init() { 9 | coins[TRON] = newTRX 10 | } 11 | 12 | type trx struct { 13 | name string 14 | symbol string 15 | key *Key 16 | } 17 | 18 | func newTRX(key *Key) Wallet { 19 | return &trx{ 20 | name: "tron", 21 | symbol: "xrp", 22 | key: key, 23 | } 24 | } 25 | 26 | func (c *trx) GetType() uint32 { 27 | return c.key.opt.CoinType 28 | } 29 | 30 | func (c *trx) GetName() string { 31 | return c.name 32 | } 33 | 34 | func (c *trx) GetSymbol() string { 35 | return c.symbol 36 | } 37 | 38 | func (c *trx) GetKey() *Key { 39 | return c.key 40 | } 41 | 42 | func (c *trx) GetAddress() (string, error) { 43 | return address.FromPublicKey(c.key.PublicECDSA).ToBase58(),nil 44 | } 45 | -------------------------------------------------------------------------------- /wallet_usdc.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | func init() { 4 | coins[USDC] = newUSDC 5 | } 6 | 7 | type usdc struct { 8 | *eth 9 | } 10 | 11 | func newUSDC(key *Key) Wallet { 12 | token := newETH(key).(*eth) 13 | token.name = "USD Coin" 14 | token.symbol = "USDC" 15 | token.contract = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" 16 | 17 | return &usdc{eth: token} 18 | } 19 | -------------------------------------------------------------------------------- /wallet_usdt.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | func init() { 4 | coins[USDT] = newUSDT 5 | } 6 | 7 | type usdt struct { 8 | *btc 9 | } 10 | 11 | func newUSDT(key *Key) Wallet { 12 | token := newBTC(key).(*btc) 13 | token.name = "Tether" 14 | token.symbol = "USDT" 15 | token.key.opt.Params = &USDTParams 16 | 17 | return &usdt{btc: token} 18 | } 19 | -------------------------------------------------------------------------------- /wallet_wicc.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | 4 | func init() { 5 | coins[WICC] = newWicc 6 | } 7 | 8 | type wicc struct { 9 | *btc 10 | } 11 | 12 | func newWicc(key *Key) Wallet { 13 | 14 | if key.opt.Params == nil { 15 | key.opt.Params = &WICCParams 16 | } 17 | token := newBTC(key).(*btc) 18 | token.name = "WaykiChain" 19 | token.symbol = "WICC" 20 | 21 | return &wicc{btc: token} 22 | } -------------------------------------------------------------------------------- /wallet_xrp.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/go-chain/go-xrp/crypto" 5 | ) 6 | 7 | 8 | func init() { 9 | coins[XRP] = newXRP 10 | } 11 | 12 | type xrp struct { 13 | name string 14 | symbol string 15 | key *Key 16 | } 17 | 18 | func newXRP(key *Key) Wallet { 19 | return &xrp{ 20 | name: "ripple", 21 | symbol: "xrp", 22 | key: key, 23 | } 24 | } 25 | 26 | func (c *xrp) GetType() uint32 { 27 | return c.key.opt.CoinType 28 | } 29 | 30 | func (c *xrp) GetName() string { 31 | return c.name 32 | } 33 | 34 | func (c *xrp) GetSymbol() string { 35 | return c.symbol 36 | } 37 | 38 | func (c *xrp) GetKey() *Key { 39 | return c.key 40 | } 41 | 42 | func (c *xrp) GetAddress() (string, error) { 43 | return GenerateAddress(c.key.Public.SerializeCompressed()) 44 | } 45 | 46 | func GenerateAddress(b []byte) (string,error) { 47 | 48 | hash, err := crypto.NewAccountId(crypto.Sha256RipeMD160(b)) 49 | if err != nil { 50 | return "",err 51 | } 52 | return hash.String(),nil 53 | } -------------------------------------------------------------------------------- /wallet_zen.go: -------------------------------------------------------------------------------- 1 | package hdwallet 2 | 3 | import ( 4 | "github.com/blocktree/go-owcdrivers/addressEncoder" 5 | "github.com/btcsuite/btcutil" 6 | ) 7 | 8 | func init() { 9 | coins[ZEN] = newZEN 10 | } 11 | 12 | const ( 13 | btcAlphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" 14 | ) 15 | 16 | var ZEN_mainnetAddressP2PKH = addressEncoder.AddressType{EncodeType: "base58", Alphabet: btcAlphabet, ChecksumType: "doubleSHA256", HashType: "h160", HashLen: 20, Prefix: []byte{0x20,0x89}, Suffix: nil} 17 | 18 | 19 | type zen struct { 20 | name string 21 | symbol string 22 | key *Key 23 | } 24 | 25 | func newZEN(key *Key) Wallet { 26 | return &zen{ 27 | name: "ZenCash", 28 | symbol: "zen", 29 | key: key, 30 | } 31 | } 32 | 33 | func (c *zen) GetType() uint32 { 34 | return c.key.opt.CoinType 35 | } 36 | 37 | func (c *zen) GetName() string { 38 | return c.name 39 | } 40 | 41 | func (c *zen) GetSymbol() string { 42 | return c.symbol 43 | } 44 | 45 | func (c *zen) GetKey() *Key { 46 | return c.key 47 | } 48 | 49 | func (c *zen) GetAddress() (string,error) { 50 | //fmt.Println(hex.EncodeToString(c.key.Public.SerializeCompressed())) 51 | //fmt.Println(hex.EncodeToString(btcutil.Hash160(c.key.Public.SerializeCompressed()))) 52 | return addressEncoder.AddressEncode(btcutil.Hash160(c.key.Public.SerializeCompressed()), ZEN_mainnetAddressP2PKH),nil 53 | } 54 | --------------------------------------------------------------------------------