Skip to content

Commit

Permalink
Add coinType and fullFundraiserPath fields in Config.
Browse files Browse the repository at this point in the history
  This is fully compatible with cosmos-sdk v0.34.6. This library will be replaced with official cosmos-sdk library after cosmos-sdk release includes setCoinType and setFullFundraiserPath
  • Loading branch information
ggomma authored and cl9200 committed Jul 25, 2019
1 parent 028bbef commit f4df6bd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
10 changes: 2 additions & 8 deletions crypto/keys/hd/hdpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ import (
"github.com/btcsuite/btcd/btcec"
)

// BIP44Prefix is the parts of the BIP32 HD path that are fixed by what we used during the fundraiser.
const (
BIP44Prefix = "44'/118'/"
FullFundraiserPath = BIP44Prefix + "0'/0/0"
)

// BIP44Params wraps BIP 44 params (5 level BIP 32 path).
// To receive a canonical string representation ala
// m / purpose' / coinType' / account' / change / addressIndex
Expand Down Expand Up @@ -132,8 +126,8 @@ func isHardened(field string) bool {
// NewFundraiserParams creates a BIP 44 parameter object from the params:
// m / 44' / 118' / account' / 0 / address_index
// The fixed parameters (purpose', coin_type', and change) are determined by what was used in the fundraiser.
func NewFundraiserParams(account uint32, addressIdx uint32) *BIP44Params {
return NewParams(44, 118, account, false, addressIdx)
func NewFundraiserParams(account, coinType, addressIdx uint32) *BIP44Params {
return NewParams(44, coinType, account, false, addressIdx)
}

// DerivationPath returns the BIP44 fields as an array.
Expand Down
7 changes: 7 additions & 0 deletions types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const (
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32MainPrefix = "cosmos"

// Atom in https://github.com/satoshilabs/slips/blob/master/slip-0044.md
CoinType = 118

// BIP44Prefix is the parts of the BIP32 HD path that are fixed by
// what we used during the fundraiser.
FullFundraiserPath = "44'/118'/0'/0/0"

// PrefixAccount is the prefix for account keys
PrefixAccount = "acc"
// PrefixValidator is the prefix for validator keys
Expand Down
28 changes: 27 additions & 1 deletion types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type Config struct {
mtx sync.RWMutex
sealed bool
bech32AddressPrefix map[string]string
coinType uint32
fullFundraiserPath string
txEncoder TxEncoder
}

Expand All @@ -25,7 +27,9 @@ var (
"validator_pub": Bech32PrefixValPub,
"consensus_pub": Bech32PrefixConsPub,
},
txEncoder: nil,
coinType: CoinType,
fullFundraiserPath: FullFundraiserPath,
txEncoder: nil,
}
)

Expand Down Expand Up @@ -73,6 +77,18 @@ func (config *Config) SetTxEncoder(encoder TxEncoder) {
config.txEncoder = encoder
}

// Set the BIP-0044 CoinType code on the config
func (config *Config) SetCoinType(coinType uint32) {
config.assertNotSealed()
config.coinType = coinType
}

// Set the FullFundraiserPath (BIP44Prefix) on the config
func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) {
config.assertNotSealed()
config.fullFundraiserPath = fullFundraiserPath
}

// Seal seals the config such that the config state could not be modified further
func (config *Config) Seal() *Config {
config.mtx.Lock()
Expand Down Expand Up @@ -116,3 +132,13 @@ func (config *Config) GetBech32ConsensusPubPrefix() string {
func (config *Config) GetTxEncoder() TxEncoder {
return config.txEncoder
}

// Get the BIP-0044 CoinType code on the config
func (config *Config) GetCoinType() uint32 {
return config.coinType
}

// Get the FullFundraiserPath (BIP44Prefix) on the config
func (config *Config) GetFullFundraiserPath() string {
return config.fullFundraiserPath
}

0 comments on commit f4df6bd

Please sign in to comment.