mirror of
https://github.com/mineracks/seedhammer-v1-companion.git
synced 2026-06-26 22:01:05 +10:00
Twelve packages lifted from seedhammer/seedhammer @ v1.3.0
(commit 2f071c1d8f23eb7fd39b15fc0acb8874113f801e):
address/ — bitcoin address parsing
backup/ — v1 plate dimensions + UR-coded multi-plate backup
bc/ — Blockchain Commons: ur, fountain, bytewords, urtypes,
xoshiro256 (5 subpkgs)
bip32/ — HD-key derivation
bip39/ — mnemonic seed phrases + 2048-word wordlist
engrave/ — text/QR → MoveTo/LineTo command stream conversion
seedqr/ — SeedQR / CompactSeedQR encoders
image/ — paletted, rgb565, alpha4, ninepatch image formats
nonstandard/ — bitcoin descriptor + script parsing
font/ — bitmap + vector font runtime
font/{comfortaa,poppins,constant,bitmap,vector}/ — actual fonts
driver/mjolnir/ — MarkingWay USB-serial engraver driver
Plus an earlier-aside backup_test.go restored (its deps are now lifted).
Import paths globally rewritten seedhammer.com → mineracks namespace
via single sed pass; verified no orphan refs remain. go.mod adopts
upstream's full dep set plus the replace-directive for the patched
kortschak/qr fork.
go build ./... clean (all 27 packages)
go test ./... clean (12 packages with tests, all passing)
NOT lifted in this commit:
- driver/{wshat,drm,libcamera} (hardware-specific GPIO/LCD/camera —
will be platform-v1/-shaped abstractions instead)
- gui/ (depends on the above; lifts in Phase 2)
- cmd/{controller,...} (Pi binary entrypoints — not needed for the
companion repo)
- zbar/ (QR scanner — needs libcamera)
Next:
- Write the SH1E reference encoder/decoder in engrave/wire/sh1e/
- Lift Gangleri42's cmd/webnfc/ shell + retune to v1 plates
- First buildable composer WASM with a working preview
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package bytewords
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
func TestRoundtrip(t *testing.T) {
|
|
want := make([]byte, 255)
|
|
for i := range want {
|
|
want[i] = byte(i)
|
|
}
|
|
enc := Encode(want)
|
|
got, err := Decode(enc)
|
|
if err != nil {
|
|
t.Fatalf("%v encoded to %s, but failed to decode: %v", want, enc, err)
|
|
}
|
|
if !bytes.Equal(want, got) {
|
|
t.Errorf("%v encoded to %s, but roundtripped to %v", want, enc, got)
|
|
}
|
|
}
|
|
|
|
func TestEncoding(t *testing.T) {
|
|
tests := []struct {
|
|
bw string
|
|
wanthex string
|
|
error bool
|
|
}{
|
|
{"aeadaolazmjendeoti", "00010280ff", false},
|
|
{"taaddwoeadgdstaslplabghydrpfmkbggufgludprfgmaotpiecffltntddwgmrp", "d9012ca20150c7098580125e2ab0981253468b2dbc5202d8641947da", false},
|
|
// Bad checksum.
|
|
{"taaddwoeadgdstaslplabghydrpfmkbggufgludprfgmaotpiecffltntddwgmrs", "", true},
|
|
{"", "", true},
|
|
}
|
|
for _, test := range tests {
|
|
got, err := Decode(test.bw)
|
|
if err != nil {
|
|
if !test.error {
|
|
t.Errorf("failed to decode %q: %v", test.bw, err)
|
|
}
|
|
} else {
|
|
if test.error {
|
|
t.Errorf("unexpected successful decoding of %q", test.bw)
|
|
}
|
|
}
|
|
if test.error {
|
|
continue
|
|
}
|
|
want, err := hex.DecodeString(test.wanthex)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(got, want) {
|
|
t.Errorf("decoding %q got %#x, expected %#x", test.bw, got, want)
|
|
}
|
|
roundtrip := Encode(want)
|
|
if roundtrip != test.bw {
|
|
t.Errorf("encoding %s got %s, expected %s", test.wanthex, roundtrip, test.bw)
|
|
}
|
|
}
|
|
}
|