Files
nilsandClaude Sonnet 5.5 cdc9c3d20b Scaffold Allmende: identity, canonical JSON, signed listings
- internal/jcs: RFC 8785 canonical JSON (integers only)
- internal/identity: ed25519 keypair, 0600 key file, no overwrite
- internal/listing: signed listing record with PoW, validation,
  tombstones and supersede rules
- docs/PROTOCOL.md: architecture and decisions so far

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 17:02:50 +01:00

51 lines
1.0 KiB
Go

package identity
import (
"os"
"path/filepath"
"testing"
)
func TestSignVerify(t *testing.T) {
id, err := Generate()
if err != nil {
t.Fatal(err)
}
msg := []byte("hello")
sig := id.Sign(msg)
if !Verify(id.PublicKeyHex(), msg, sig) {
t.Fatal("valid signature rejected")
}
if Verify(id.PublicKeyHex(), []byte("other"), sig) {
t.Fatal("signature accepted for different message")
}
if Verify("zz", msg, sig) {
t.Fatal("garbage public key accepted")
}
}
func TestSaveLoad(t *testing.T) {
path := filepath.Join(t.TempDir(), "sub", "key")
a, err := LoadOrCreate(path)
if err != nil {
t.Fatal(err)
}
b, err := LoadOrCreate(path)
if err != nil {
t.Fatal(err)
}
if a.PublicKeyHex() != b.PublicKeyHex() {
t.Fatal("reloaded identity differs")
}
st, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if st.Mode().Perm() != 0o600 {
t.Fatalf("key file mode %v, want 0600", st.Mode().Perm())
}
if err := a.Save(path); err == nil {
t.Fatal("Save must not overwrite an existing key")
}
}