<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sailxe</title>
    <description>The latest articles on DEV Community by Sailxe (@sailxe).</description>
    <link>https://dev.to/sailxe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4204851%2Fc214a552-b65d-4fe3-9273-a47b49752a18.png</url>
      <title>DEV Community: Sailxe</title>
      <link>https://dev.to/sailxe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sailxe"/>
    <language>en</language>
    <item>
      <title>Two layers or it didn't happen: marking AI images for the EU AI Act in pure TypeScript</title>
      <dc:creator>Sailxe</dc:creator>
      <pubDate>Sat, 24 Oct 2026 14:36:16 +0000</pubDate>
      <link>https://dev.to/sailxe/two-layers-or-it-didnt-happen-marking-ai-images-for-the-eu-ai-act-in-pure-typescript-52d1</link>
      <guid>https://dev.to/sailxe/two-layers-or-it-didnt-happen-marking-ai-images-for-the-eu-ai-act-in-pure-typescript-52d1</guid>
      <description>&lt;p&gt;Since 2 August 2026, the EU AI Act requires AI products to mark generated content in a machine-readable way. The European Commission's Code of Practice adds a practical twist: use at least two layers, because any single technique can be stripped. Systems already on the market have until 2 December.&lt;/p&gt;

&lt;p&gt;I wanted this to be a one-line change for web developers, so I built &lt;a href="https://github.com/Sailxe42/filigrane" rel="noopener noreferrer"&gt;Filigrane&lt;/a&gt;, an MIT-licensed TypeScript toolkit. Here is what I learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 1: C2PA, from the spec
&lt;/h2&gt;

&lt;p&gt;C2PA ("Content Credentials") is the industry standard: a signed manifest embedded in the file. The official SDK is written in Rust, and its npm package ships a native binary. I wanted something that runs in browsers and edge runtimes, so I implemented the parts I needed in TypeScript on WebCrypto: a CBOR codec, JUMBF boxes, COSE_Sign1 signatures and X.509 certificates.&lt;/p&gt;

&lt;p&gt;The most fun bug was a chicken-and-egg problem. The manifest contains a hash of the file &lt;em&gt;excluding the manifest itself&lt;/em&gt;, so the exclusion range depends on the manifest size, which depends on how the exclusion range is encoded. The fix is a small fixed-point loop: build, measure, rebuild until the layout is stable. It converges in two iterations.&lt;/p&gt;

&lt;p&gt;The golden rule: never trust your own validator. Every commit, CI signs JPEG, PNG and WebP files and asks the reference implementation (c2pa-rs, through its Python bindings) to validate them. All are reported "Valid".&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 2: IPTC metadata
&lt;/h2&gt;

&lt;p&gt;The IPTC &lt;code&gt;DigitalSourceType&lt;/code&gt; field (&lt;code&gt;trainedAlgorithmicMedia&lt;/code&gt;) is what search engines and photo tools already read to display "AI-generated". It is a few lines of XMP, and it costs nothing to add.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 3: an invisible watermark
&lt;/h2&gt;

&lt;p&gt;Metadata disappears the moment a social network re-encodes your image. A watermark lives in the pixels. Filigrane's watermark spreads a 64-bit code over thousands of DCT coefficients of a &lt;em&gt;canonical&lt;/em&gt; 256-pixel copy of the image, which is why it survives resizing. Embedding is "informed": each coefficient is pushed only as far as needed, and less in flat areas, keeping the change invisible (about 44 dB PSNR).&lt;/p&gt;

&lt;p&gt;Measured on five photo-like images, it survives JPEG quality 30, resizing to 25 %, brightness and contrast changes, and metadata stripping, with zero false positives on 20 unmarked images. It does not survive cropping yet; that's next.&lt;/p&gt;

&lt;p&gt;The watermark ID is recorded in the C2PA manifest as a soft binding, so the two layers point to each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verification in the browser
&lt;/h2&gt;

&lt;p&gt;The whole engine (C2PA, crypto, JPEG/PNG codecs, watermark) is about 33 kB gzipped and runs in a Web Worker. The &lt;a href="https://sailxe42.github.io/filigrane/verify.html" rel="noopener noreferrer"&gt;online verifier&lt;/a&gt; never uploads your file. You can try a demo there: mark an image, "post" it to a simulated social network, and see the watermark keep the signal alive when the other two layers are gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Attack your own verifier
&lt;/h2&gt;

&lt;p&gt;Before launching, I attacked my own verifier. The worst finding: an unsigned assertion slipped into a manifest could make a completely modified image look "valid". A certificate that was not a CA could also issue "trusted" certificates under any name, one crafted PNG froze the parser, and a 500 kB PNG inflated to 512 MB in memory. All of it is fixed in 0.1.2, each attack has a regression test, and a fuzzer ran 3,000 corrupted files without a hang.&lt;/p&gt;

&lt;h2&gt;
  
  
  And the chatbot?
&lt;/h2&gt;

&lt;p&gt;Article 50 also requires telling users they are talking to an AI. &lt;code&gt;&amp;lt;ai-disclosure&amp;gt;&lt;/code&gt; is a Web Component that speaks the 24 official EU languages, works with any framework, and leaves a visible "AI" chip after it is dismissed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @filigranejs/core @filigranejs/ui
npx filigrane scan &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Repository, docs and benchmark: &lt;a href="https://github.com/Sailxe42/filigrane" rel="noopener noreferrer"&gt;https://github.com/Sailxe42/filigrane&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is not legal advice. I built Filigrane with an AI coding assistant, trying to back every claim with a test, and this article was drafted by an AI assistant from my notes and checked by me. Feedback and contributions, especially translation reviews, are very welcome.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>opensource</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
