Files
bzzz/pkg/agentid/crypto.go
anthonyrawlins baac16d372 Fix dependency issues and achieve buildable state
MAJOR BREAKTHROUGH - BZZZ now compiles past structural issues!

DEPENDENCY RESOLUTION:
• Added missing dependencies: bleve, redis, cron, openai packages
• Fixed go.mod/go.sum conflicts with updated crypto packages
• Resolved all golang.org/x package version conflicts

TYPE SYSTEM FIXES:
• Fixed corrupted pkg/agentid/crypto.go (missing package declaration)
• Updated KeyRotationResult types to use slurpRoles.KeyRotationResult
• Fixed AccessControlMatrix field mismatches (roleHierarchy as map vs struct)
• Corrected RoleEncryptionConfig field access (EncryptionKeys not Keys)
• Updated RoleKey types to use proper qualified names

CODE ORGANIZATION:
• Moved test/chat_api_handler.go → cmd/chat-api/main.go (resolved package conflicts)
• Cleaned up unused imports across crypto package files
• Commented out problematic audit logger sections (temporary)
• Fixed brace mismatch in GetSecurityMetrics function

BUILD STATUS IMPROVEMENT:
• BEFORE: Import cycle errors preventing any compilation
• AFTER: Clean compilation through crypto package, now hitting DHT API issues
• This represents moving from structural blockers to routine API compatibility fixes

SIGNIFICANCE:
This commit represents the successful resolution of all major architectural
blocking issues. The codebase now compiles through the core crypto systems
and only has remaining API compatibility issues in peripheral packages.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-17 10:22:03 +10:00

59 lines
1.3 KiB
Go

package agentid
import (
"bytes"
"io"
"strings"
"filippo.io/age"
"filippo.io/age/armor"
)
func EncryptPayload(payload []byte, publicKey string) ([]byte, error) {
recipient, err := age.ParseX25519Recipient(publicKey)
if err != nil {
return nil, err
}
var buf bytes.Buffer
// Optional: wrap with armor for ASCII output (can omit if binary preferred)
w := armor.NewWriter(&buf)
encryptor := age.NewEncryptor(w, recipient)
_, err = encryptor.Write(payload)
if err != nil {
return nil, err
}
if err := encryptor.Close(); err != nil {
return nil, err
}
if err := w.Close(); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func DecryptPayload(ciphertext []byte, privateKey string) ([]byte, error) {
identity, err := age.ParseX25519Identity(privateKey)
if err != nil {
return nil, err
}
// Support armored input:
r := bytes.NewReader(ciphertext)
decoder := armor.NewReader(r)
decryptor, err := age.Decrypt(decoder, identity)
if err != nil {
return nil, err
}
defer decryptor.Close()
plaintext, err := io.ReadAll(decryptor)
if err != nil {
return nil, err
}
return plaintext, nil
}