check.tattoo scores a tattoo idea before you get it. The score is free. The full report is a one-time $19 payment for one design: the reasoning behind each score, what to change, and a brief for the artist.
There are no accounts, and that created a problem.
After payment, two things are written to the browser: the entitlement ("this design is unlocked") and the report itself. Both live in localStorage.
localStorage is not durable. Safari's tracking prevention can evict script-written storage after about a week without a return visit. So a buyer could pay, come back ten days later on an iPhone, and find nothing.
The usual fix is a restore code and a table: store the purchase server-side, hand the buyer a code, and look it up later. We considered it and rejected it for a reason specific to this product.
A lookup would restore the right to the report, not the report. The report is generated by a model running at temperature 0.4. If you re-grant the unlock and re-run the check, you get a different report, with different wording and maybe different numbers. Handing back different numbers isn't restoring a purchase.
So the restore link carries the whole report.
After paying, the buyer gets a link like this:
https://check.tattoo/restore#r=<base64url of the whole report>
Everything after # is the fragment, and browsers never send the fragment to a server. So this design stores nothing: no table of purchases, no codes anyone could guess, no personal data, nothing to delete later.
Opening the link re-installs the exact report that was paid for, for that one design.
The trade-off is explicit in the code: anyone holding the link gets that report. That's the same property a downloaded PDF has. It covers one design and can't unlock anything else.
The payload is JSON, base64url-encoded. Three things go wrong if you write this the obvious way:
export const encodeFragment = (payload: unknown): string => {
const bytes = new TextEncoder().encode(JSON.stringify(payload));
let latin1 = "";
for (const b of bytes) latin1 += String.fromCharCode(b);
return btoa(latin1).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
};
btoa is latin1-only and throws on anything above U+00FF.TextEncoder first.+, / and = are not safe in a fragment
export const decodeFragment = (hash: string, key: string): unknown => {
try {
const m = new RegExp(`[#&]${key}=([A-Za-z0-9_-]+)`).exec(hash);
if (!m) return undefined;
const b64 = m[1].replace(/-/g, "+").replace(/_/g, "/");
const latin1 = atob(b64 + "=".repeat((4 - (b64.length % 4)) % 4));
const bytes = new Uint8Array(latin1.length);
for (let i = 0; i < latin1.length; i += 1) bytes[i] = latin1.charCodeAt(i);
return JSON.parse(new TextDecoder().decode(bytes));
} catch {
return undefined;
}
};
The report includes six dimension summaries, two or three recommendations and an artist brief. To keep the URL manageable, the payload is positional: an array, not an object. Keys would add hundreds of characters.
[version, designKey, orderId, overall, headline,
[[score, verdict, summary] × 6],
[[priority, title, detail] × n],
artistBrief, contextLine]
Every field has a length cap (headline 300, each summary 1,200, the brief 4,000, at most five recommendations). According to a note in the code, five real reports measured between 2,829 and 3,443 characters. That's long for a URL, but it's the whole purchase.
A version number comes first, so the layout can change later without old links decoding into garbage.
Decoding checks the shape and rejects anything off. The version must match, scores must be integers from 0 to 100, and there must be exactly six dimensions. Strings are cut to their caps again on the way in. A shortened excerpt:
if (v !== RECOVERY_VERSION) return null;
if (typeof designKey !== "string" || !designKey) return null;
if (!isScore(overall) || typeof headline !== "string") return null;
if (!Array.isArray(dims) || dims.length !== DIMENSION_IDS.length) return null;
The browser doesn't send the fragment, but scripts on the page can read it. Our host injects a page-view measurement script into every page, and that script posts window.location.href, fragment included, to its own endpoint shortly after load. We can't change that script.
So the fragment has to leave the address bar before any deferred script runs. A synchronous inline script at the top of <head> does it:
<script>
(function () {
function strip() {
try {
var l = window.location;
if (/^\/restore\/?$/i.test(l.pathname) && /[#&]r=/.test(l.hash)) {
window.__restoreFragment = l.hash;
try { sessionStorage.setItem("checktattoo.restoreFragment.v1", l.hash); } catch (e) {}
history.replaceState(history.state, "", l.pathname + l.search);
}
} catch (e) {}
}
strip();
window.addEventListener("hashchange", strip, true);
window.addEventListener("popstate", strip, true);
})();
</script>
Three details:
location.href, the address is plain /restore. sessionStorage``hashchange and popstate listeners, in the capture phase.
Opening a recovery link doesn't restore anything by itself. Restoring writes to localStorage and replaces whatever report is already there. Someone who opens a friend's link out of curiosity shouldn't lose their own report without being asked. So /restore shows what it found and waits for a click. If a different paid report is already in that slot, it's archived rather than overwritten.
It doesn't fit if a purchase needs to be revocable, or if the payload is too large or too sensitive to hand to the user.
Our site has a page about the restore link for buyers. The tool itself is free to try at check.tattoo.