Export the hdkeychain min and max seed byte lens.
This commit is contained in:
parent
2539ca9860
commit
ea27722dac
1 changed files with 9 additions and 9 deletions
|
@ -35,13 +35,13 @@ const (
|
||||||
// for hardened child keys is [2^31, 2^32 - 1].
|
// for hardened child keys is [2^31, 2^32 - 1].
|
||||||
HardenedKeyStart = 0x80000000 // 2^31
|
HardenedKeyStart = 0x80000000 // 2^31
|
||||||
|
|
||||||
// minSeedBytes is the minimum number of bytes allowed for a seed to
|
// MinSeedBytes is the minimum number of bytes allowed for a seed to
|
||||||
// a master node.
|
// a master node.
|
||||||
minSeedBytes = 16 // 128 bits
|
MinSeedBytes = 16 // 128 bits
|
||||||
|
|
||||||
// maxSeedBytes is the maximum number of bytes allowed for a seed to
|
// MaxSeedBytes is the maximum number of bytes allowed for a seed to
|
||||||
// a master node.
|
// a master node.
|
||||||
maxSeedBytes = 64 // 512 bits
|
MaxSeedBytes = 64 // 512 bits
|
||||||
|
|
||||||
// serializedKeyLen is the length of a serialized public or private
|
// serializedKeyLen is the length of a serialized public or private
|
||||||
// extended key. It consists of 4 bytes version, 1 byte depth, 4 bytes
|
// extended key. It consists of 4 bytes version, 1 byte depth, 4 bytes
|
||||||
|
@ -77,7 +77,7 @@ var (
|
||||||
// ErrInvalidSeedLen describes an error in which the provided seed or
|
// ErrInvalidSeedLen describes an error in which the provided seed or
|
||||||
// seed length is not in the allowed range.
|
// seed length is not in the allowed range.
|
||||||
ErrInvalidSeedLen = fmt.Errorf("seed length must be between %d and %d "+
|
ErrInvalidSeedLen = fmt.Errorf("seed length must be between %d and %d "+
|
||||||
"bits", minSeedBytes*8, maxSeedBytes*8)
|
"bits", MinSeedBytes*8, MaxSeedBytes*8)
|
||||||
|
|
||||||
// ErrBadChecksum describes an error in which the checksum encoded with
|
// ErrBadChecksum describes an error in which the checksum encoded with
|
||||||
// a serialized extended key does not match the calculated value.
|
// a serialized extended key does not match the calculated value.
|
||||||
|
@ -440,8 +440,8 @@ func (k *ExtendedKey) Zero() {
|
||||||
// returned if this should occur, so the caller must check for it and generate a
|
// returned if this should occur, so the caller must check for it and generate a
|
||||||
// new seed accordingly.
|
// new seed accordingly.
|
||||||
func NewMaster(seed []byte) (*ExtendedKey, error) {
|
func NewMaster(seed []byte) (*ExtendedKey, error) {
|
||||||
// Per [BIP32], the seed must be in range [minSeedBytes, maxSeedBytes].
|
// Per [BIP32], the seed must be in range [MinSeedBytes, MaxSeedBytes].
|
||||||
if len(seed) < minSeedBytes || len(seed) > maxSeedBytes {
|
if len(seed) < MinSeedBytes || len(seed) > MaxSeedBytes {
|
||||||
return nil, ErrInvalidSeedLen
|
return nil, ErrInvalidSeedLen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,8 +529,8 @@ func NewKeyFromString(key string) (*ExtendedKey, error) {
|
||||||
// The recommended length is 32 (256 bits) as defined by the RecommendedSeedLen
|
// The recommended length is 32 (256 bits) as defined by the RecommendedSeedLen
|
||||||
// constant.
|
// constant.
|
||||||
func GenerateSeed(length uint8) ([]byte, error) {
|
func GenerateSeed(length uint8) ([]byte, error) {
|
||||||
// Per [BIP32], the seed must be in range [minSeedBytes, maxSeedBytes].
|
// Per [BIP32], the seed must be in range [MinSeedBytes, MaxSeedBytes].
|
||||||
if length < minSeedBytes || length > maxSeedBytes {
|
if length < MinSeedBytes || length > MaxSeedBytes {
|
||||||
return nil, ErrInvalidSeedLen
|
return nil, ErrInvalidSeedLen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue