package crypto import ( "git.mleku.dev/mleku/dendrite/pkg/axiom" "git.mleku.dev/mleku/dendrite/pkg/lattice" "git.mleku.dev/mleku/dendrite/pkg/spore" ) // PublicKey is the lattice structure visible to anyone. // It is derived from a spore: portable, compact, and sufficient // to nucleate a lattice for encryption. type PublicKey struct { Basis *Basis SporeHash string // SHA-256 of the generating spore Spore *spore.Spore // the full spore for nucleation } // PrivateKey is the constraint envelope — the trapdoor. // Knowing the specific Constraint implementations allows // direct reading of the bonding pattern (efficient CVP). type PrivateKey struct { // ConstraintFactory produces a constraint for a given type tag. // This is the short basis — the trapdoor that makes decryption // and signing efficient. ConstraintFactory func(tag string) axiom.Constraint // Lattice is the live lattice with all constraints loaded. Lattice *lattice.Lattice } // KeyPair bundles public and private keys. type KeyPair struct { Public PublicKey Private PrivateKey } // GenerateKeyPair produces a keypair from a mature lattice. // The lattice must have been through at least one grow/dissolve cycle // (i.e., it should have bonded elements and structural history). // // Algorithm: // 1. Extract spore from lattice // 2. Public key = spore's structural fingerprint // 3. Private key = the lattice itself + its constraint factory func GenerateKeyPair(l *lattice.Lattice, params Params, factory func(string) axiom.Constraint) *KeyPair { s := spore.Extract(l) basis := FromSpore(s, params.Q) return &KeyPair{ Public: PublicKey{ Basis: basis, SporeHash: s.Hash(), Spore: s, }, Private: PrivateKey{ ConstraintFactory: factory, Lattice: l, }, } }