+ if (!$this->actor instanceof Profile) {
+ throw new ServerException('No profile to sign message with is set.');
+ } elseif (!$this->actor->isLocal()) {
+ throw new ServerException('Cannot sign magic envelopes with remote users since we have no private key.');
+ }
+
+ // Find already stored key
+ $magicsig = Magicsig::getKV('user_id', $this->actor->getID());
+ if (!$magicsig instanceof Magicsig) {
+ // and if it doesn't exist, it is time to create one!
+ $magicsig = Magicsig::generate($this->actor->getUser());
+ }
+ assert($magicsig instanceof Magicsig);