fix: resolve mnd (magic number) linter errors in agehd and bip85 packages

- Define x25519KeySize constant (32) at package level in agehd
- Replace all magic number 32 uses with x25519KeySize constant
- Define bech32BitSize8 and bech32BitSize5 constants for bit conversions
- Define bip85EntropySize constant (64) for entropy validation
- Define BIP39 word count constants (words12-24) with descriptive names
This commit is contained in:
2025-07-09 12:52:46 -07:00
parent 95ba80f618
commit 93a32217e0
2 changed files with 29 additions and 15 deletions

View File

@@ -52,8 +52,9 @@ type DRNG struct {
// NewBIP85DRNG creates a new DRNG seeded with BIP85 entropy
func NewBIP85DRNG(entropy []byte) *DRNG {
const bip85EntropySize = 64 // 512 bits
// The entropy must be exactly 64 bytes (512 bits)
if len(entropy) != 64 {
if len(entropy) != bip85EntropySize {
panic("DRNG entropy must be 64 bytes")
}
@@ -169,17 +170,26 @@ func DeriveBIP39Entropy(masterKey *hdkeychain.ExtendedKey, language, words, inde
}
// Determine how many bits of entropy to use based on the words
// BIP39 defines specific word counts and their corresponding entropy bits
const (
words12 = 12 // 128 bits of entropy
words15 = 15 // 160 bits of entropy
words18 = 18 // 192 bits of entropy
words21 = 21 // 224 bits of entropy
words24 = 24 // 256 bits of entropy
)
var bits int
switch words {
case 12:
case words12:
bits = 128
case 15:
case words15:
bits = 160
case 18:
case words18:
bits = 192
case 21:
case words21:
bits = 224
case 24:
case words24:
bits = 256
default:
return nil, fmt.Errorf("invalid BIP39 word count: %d", words)