Files
keyfunc/internal/derive/derive_test.go
clawbot 279cba6bcf
All checks were successful
check / check (push) Successful in 5s
Skeleton, mnemonic input, derivation, and the ssh pub and priv commands (closes #1)
The module, the script entrypoints and Makefile, Docker-only linting, the mnemonic sources in the specified order with their refusals, the BIP-85 derivation, and keyfunc ssh pub and priv with the README test vectors as tests. Two review rounds; the second passed with no findings.

Model: opus-5 (implementation and review); fable-5-1 (landing)
2026-09-07 17:34:54 +02:00

62 lines
1.4 KiB
Go

package derive_test
import (
"bytes"
"strings"
"testing"
"git.eeqj.de/sneak/keyfunc/internal/derive"
"github.com/stretchr/testify/require"
)
// application is the number the SSH key type uses.
const application = 838372
// example returns the mnemonic every BIP-39 document uses to show its
// test vectors: eleven abandons and about.
func example() string {
return strings.Repeat("abandon ", 11) + "about"
}
func TestPathIsTheOneTheSpecificationGives(t *testing.T) {
t.Parallel()
require.Equal(t, "m/83696968'/838372'/3'", derive.Path(application, 3))
}
func TestEveryIndexGivesItsOwnBytes(t *testing.T) {
t.Parallel()
first, err := derive.Bytes(example(), application, 0)
require.NoError(t, err)
require.Len(t, first, derive.Size)
second, err := derive.Bytes(example(), application, 1)
require.NoError(t, err)
require.Len(t, second, derive.Size)
require.False(t, bytes.Equal(first, second))
}
func TestAnIndexWithNoHardenedChildIsRefused(t *testing.T) {
t.Parallel()
_, err := derive.Bytes(example(), application, derive.MaxIndex+1)
require.ErrorIs(t, err, derive.ErrIndexTooLarge)
_, err = derive.Bytes(example(), application, derive.MaxIndex)
require.NoError(t, err)
}
func TestTheSameInputAlwaysGivesTheSameBytes(t *testing.T) {
t.Parallel()
once, err := derive.Bytes(example(), application, 7)
require.NoError(t, err)
again, err := derive.Bytes(example(), application, 7)
require.NoError(t, err)
require.Equal(t, once, again)
}