=== Signed Posts ===
Contributors: marc4
Tags: openpgp, did, signature, security, verification
Requires at least: 6.9
Tested up to: 7.2
Requires PHP: 8.2
Tested up to PHP: 8.5
Stable tag: 0.6
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Attach an OpenPGP or DID signature to a post. The visitor's browser checks it against the author's published key.

== Description ==

Attach an OpenPGP or DID signature to a post. The visitor's browser checks it against the author's published key.

**Features:**

* **In-browser verification:** The signature verification is done on the client side (in the visitor's browser).
* **Methods:** OpenPGP (ASCII-armored detached signature) and DID (did:key, did:web) using Ed25519 detached JWS (b64=false).
* **Source of trust:** For OpenPGP, the author specifies the URL of their public key in their profile. For DID, the author sets their DID (did:key or did:web). For did:web, the plugin fetches `https://<host>/.well-known/did.json`.
* **Status block:** An informative block is automatically added to the end of each signed article, showing the verification status (valid, invalid, or error).
* **Author badge:** The author name in posts is enhanced with an icon and KeyID/fingerprint text.

**What it checks (and what it does not):** the browser compares the post text stored on your site with the signature and with the public key the author published (for example on GitHub). A valid result means the stored text was signed by that key, so changes made without the author's private key are detected. It does not protect against someone who controls your server: they can change the key URL stored in the author's profile, or the script, and sign again with their own key. To check independently, compare the key fingerprint with the one published by the author, or verify the signature with `gpg`.

== Installation ==

1. Go to **Plugins > Add New Plugin**.
2. Search for **Signed Posts**.
3. Install and activate the **Signed Posts** plugin.

== Frequently Asked Questions ==

**How do I get the content of my post to sign it?**
Once you've finished your post, click the three dots in the top-right corner of the Gutenberg editor. When the options menu opens, select "Copy all blocks." That is the content you should sign.

**How do I sign with OpenPGP?**
Save the copied blocks to `post.txt` (ending with a single newline) and run `gpg --armor --detach-sign --textmode post.txt`. Paste the contents of `post.txt.asc` into the Signed Posts box of the post.

**Where can I host my OpenPGP public key?**
Outside your WordPress site, for example on GitHub or another domain you control. It needs a direct link and CORS (Cross-Origin Resource Sharing) access. Hosting it elsewhere is what makes the check stronger.

**I edited the post and the signature is now invalid. Why?**
Any change to the content breaks the signature. Sign the new version and paste the new signature.

**What happens to my data if I delete the plugin?**
Nothing is deleted by default. Administrators can choose what to delete in their user profile, under "Cleanup preferences for Signed Posts".

**What happens if the signature isn't valid?**
The plugin will display a warning message indicating that the signature doesn't match the content or the public key, which can be a sign of content tampering.

**What exactly is verified?**
The post content stored in the database (`post_content`), after normalising line endings and adding a trailing newline. The title, date, images and the HTML your theme finally prints are not signed.

**Does the plugin affect my site's performance?**
The impact on the server is minimal, as the verification is performed entirely in the visitor's browser. The only additional resource is the download of the public key, which is usually very small.

**What format should I use to sign with DID?**  
Use Compact JWS (detached) with `{"alg":"EdDSA","b64":false,"crit":["b64"],"kid":"<your did#key>"}` and sign the canonicalized post content (same text you would sign with OpenPGP).

**Where do I set my DID?**  
In your User Profile, in the "Decentralized Identifiers (DID)" field. For `did:web`, ensure your `did.json` is hosted at `https://<host>/.well-known/did.json`.

== External services ==

To verify a signature, the visitor's browser downloads the author's public key from the URL set in their profile (OpenPGP) or the `did.json` of their domain (did:web). Those requests go to the server the author chose, not to any service of this plugin, and that server can see the visitor's IP address. The plugin itself sends no data to third parties.

== Source Code and Libraries ==

**OpenPGP.js**
* **Version:** 6.3.3
* **License:** LGPL-3.0-or-later
* **Public Source Code:** https://github.com/openpgpjs/openpgpjs

**Web Crypto API**
* Used to verify Ed25519 signatures for DID.

== Changelog ==

= [0.6] - 2026-12-01 =
* Fixed: OpenPGP verification works again (the script contained the DID verifier by mistake).
* Fixed: Fatal error when saving a profile with an OpenPGP key URL.
* Fixed: Valid signatures failed on posts containing HTML entities such as &amp;.
* Fixed: The key URL can be cleared, and the author badge only appears on the displayed post.
* Changed: Only the profile owner can edit the DID, and saving a signature requires the edit_post capability.
* Changed: Any http(s) key URL is accepted; invalid values keep the previous one.
* Changed: Texts say what is checked instead of promising integrity, and front-end strings are translatable.
* Changed: RTL support, better accessibility and contrast, options stored without autoload.
* Updated OpenPGP.js to 6.3.3. Passes PHPCS and Plugin Check.

= [0.5] - 2026-03-07 =
* Updated minimum WordPress requirement to 6.9.
* Updated minimum PHP requirement to 8.2.
* Activation hook refactored to named function.
* Dashicons enqueued conditionally to avoid redundant loading.
* Added type hints and return types to all functions (PHP 8.2+).
* Added PHPDoc blocks to all functions (WordPress-Docs standard).
* Extracted post signature data to a cached helper function to avoid redundant meta queries.
* Restored function_exists() guard for delete_post_meta_by_key() in uninstall handler.

= [0.4] - 2025-10-08 =
* DID support added: did:key and did:web with Ed25519 JWS (detached).
* Method selector per post.
* DID field in user profile.
* Uninstall options extended to remove DID and method meta.
* Maintains full backward compatibility with OpenPGP flow.

= [0.3] - 2025-10-03 =
* Author badge with icon and fingerprint text linked to the verification result.
* OpenPGP updated to 6.2.2.
* Some corrections.

= [0.1] - 2025-09-23 =
* First version.
