OpenTimestamps anchor
OC Stamp envelopes carry an optional ots field that anchors the envelope's
id to a Bitcoin block header via
OpenTimestamps (OTS) (opens in a new tab). @orangecheck/stamp-ots is
the thin client-side glue.
What OTS is (one paragraph)Link to this section
OTS calendars batch many arbitrary-digest timestamp requests into a Merkle tree
and publish the tree root on-chain via an OP_RETURN transaction. A calendar
hands back a proof — a path of hash operations from your digest to the tree
root, then on through the transaction that committed the root to the Merkle root
of a Bitcoin block. Anyone with that block's header can verify the proof chain
and conclude "this digest existed before this block."
OTS is calendar-operator-trust-minimized (you can submit to multiple calendars; forgery requires block-level collusion), free to use, and widely deployed since 2016.
What @orangecheck/stamp-ots doesLink to this section
Five exports cover the whole flow:
submitToCalendars(id, opts)— POST an envelope's 32-byte digest to OTS calendars, the three defaults unless you passcalendars. Two must answer unless you setminSuccesses. Returns a pendingOtsProofyou fold into the envelope'sotsfield.upgradeProof(proof, id, { headerSource })— poll calendars for an upgraded proof once OTS has anchored the batch to a Bitcoin block.headerSourceis required. Returns a confirmedOtsProofonly after the block header at the anchor's height has the proof's Merkle root, or the same pending proof if not yet confirmed.createCalendarClient(url)— low-level HTTP client implementing the minimal OTS calendar API (POST /digest,GET /timestamp/<hex>).makeAnchorVerifier({ headerSource })— theverifyOtsAnchorfunctionstamp-core'sverify()takes. It walks the proof with the package's own OTS parser and checks it against the block header at the declared height.mempoolHeaderSource()— block headers from mempool.space (or any Esplora API viabaseUrl). Each header is checked against the declared block hash, so it is trusted only to say which block sits at a height.
SubmitLink to this section
import type { StampEnvelope } from '@orangecheck/stamp-core';
import { submitToCalendars, toStampOts } from '@orangecheck/stamp-ots';
declare const env: StampEnvelope; // a signed envelope from stamp()
const proof = await submitToCalendars(env.id, {
calendars: [
'https://alice.btc.calendar.opentimestamps.org',
'https://bob.btc.calendar.opentimestamps.org',
],
});
const anchored = { ...env, ots: toStampOts(proof) };
Leave out calendars to use the three defaults (alice, bob and finney). With
the two listed here, both must answer: minSuccesses defaults to two, or to the
number of calendars when fewer are given.
The returned proof is pending: the calendar has accepted your digest but the OTS batch for the next hour (or whatever the calendar's cadence is) hasn't yet been anchored to Bitcoin. The envelope is still useful at this point — it proves authorship — it just doesn't have a time anchor yet.
Submit to at least two calendars operated by different parties. The proof keeps every calendar's receipt, so if one calendar goes dark before anchoring, the other's still lets you upgrade.
UpgradeLink to this section
import type { StampEnvelope } from '@orangecheck/stamp-core';
import {
fromStampOts,
mempoolHeaderSource,
toStampOts,
upgradeProof,
} from '@orangecheck/stamp-ots';
declare const anchored: StampEnvelope; // the pending envelope from Submit
// Call again later while it stays pending. Typically an hour or more.
const upgradedProof = await upgradeProof(
fromStampOts(anchored.ots!),
anchored.id,
{
headerSource: mempoolHeaderSource(),
}
);
const upgraded = { ...anchored, ots: toStampOts(upgradedProof) };
console.log(upgraded.ots.status); // "pending" until the batch is in a block
upgradeProof() asks each calendar in the proof "has the batch containing my
digest been anchored yet?" When the answer is yes, the calendar returns the rest
of the path, from its commitment to a Bitcoin block's Merkle root, and
upgradeProof() checks that root against the block header before it reports
confirmed. From then on the proof is independently verifiable against any
Bitcoin node.
Cache the upgraded proof. Once the chain has confirmed, the proof never changes — you can verify it offline forever.
In a web appLink to this section
@orangecheck/stamp-ots calls the calendars straight from the browser, and that
works from any origin, with one gap. Measured in Chromium from
https://example.com on 2026-10-21, against alice, bob and finney:
| Request | What the page gets |
|---|---|
POST /, the 32-byte digest, no Content- (what submitToCalendars sends) | 200 and the pending proof, with Access- |
the same POST with a Content- such as application/ | blocked: the preflight OPTIONS gets 404 or 501 |
GET /, once that commitment is in a block | 200 and the upgrade, with Access- |
GET /, while it is still pending | a network error: the calendar's 404 carries no Access- |
mempool.space GET / and GET / | 200, with Access- |
So submitting and upgrading work as shipped. upgradeProof() treats a calendar
it cannot read as "no answer yet", so a pending proof stays pending, and the
browser console shows a CORS error for each pending check. Allow the three
calendar hosts and your header source in your Content-Security-Policy's
connect-src.
To tell "still pending" from "calendar down", or to keep those errors out of the console, put a small proxy on your own origin. It forwards two paths per calendar and nothing else:
POST /digest, the 32-byte body as it came;GET /timestamp/<hex>, passing the calendar's status through, so a404reaches the page as a404.
Point stamp-ots at it with its fetch option. The proof still names the
calendars themselves, so anyone can upgrade it later without your proxy:
import type { StampEnvelope } from '@orangecheck/stamp-core';
import {
mempoolHeaderSource,
submitToCalendars,
upgradeProof,
} from '@orangecheck/stamp-ots';
declare const env: StampEnvelope; // a signed envelope from stamp()
const PROXY: Record<string, string> = {
'https://alice.btc.calendar.opentimestamps.org': '/ots/alice',
'https://bob.btc.calendar.opentimestamps.org': '/ots/bob',
'https://finney.calendar.eternitywall.com': '/ots/finney',
};
const viaProxy: typeof fetch = (input, init) => {
const url = String(input);
const calendar = Object.keys(PROXY).find((c) => url.startsWith(c));
return fetch(
calendar ? PROXY[calendar] + url.slice(calendar.length) : url,
init
);
};
const proof = await submitToCalendars(env.id, { fetch: viaProxy });
const later = await upgradeProof(proof, env.id, {
headerSource: mempoolHeaderSource(),
fetch: viaProxy,
});
stamp.ochk.io runs a proxy like this for its own pages. It is not a public service, so don't point another site at it.
VerifyLink to this section
@orangecheck/stamp-ots parses the OTS proof format itself. Give it a source of
block headers and pass the result to verify():
import type { StampEnvelope } from '@orangecheck/stamp-core';
import { verifySignature } from '@orangecheck/bip322';
import { verify } from '@orangecheck/stamp-core';
import {
makeAnchorVerifier,
mempoolHeaderSource,
} from '@orangecheck/stamp-ots';
declare const upgraded: StampEnvelope; // the upgraded envelope from Upgrade
const result = await verify({
envelope: upgraded,
verifyBip322: async (msg, sig, addr) => verifySignature(addr, msg, sig),
verifyOtsAnchor: makeAnchorVerifier({
headerSource: mempoolHeaderSource(),
}),
});
if (!result.ok) throw new Error(`${result.code}: ${result.message}`);
console.log(result.anchor); // { status: 'confirmed', blockHeight, blockHash, verified: true }
A header source is any object with getHeaderAt(height) returning the 80-byte
header: a local Bitcoin node, an Esplora mirror, or a bundle of headers on disk.
With your own headers the check needs no network at all. Without
verifyOtsAnchor, a confirmed proof is reported as claimed, not verified.
What a label may sayLink to this section
The proof names a block height, but only a block header can show the proof leads
there, and the ots block sits outside the signature. Until a header has been
checked, the height is the envelope's say-so. Word a label by what has been
checked:
| What you know | The label |
|---|---|
anchor. is none | No timestamp |
anchor. is pending | Waiting for a Bitcoin block |
anchor. is claimed: confirmed, no header check asked for | Waiting to be checked against block N |
anchor. is unchecked: the header did not load | Couldn't check against block N yet |
the proof checked against the header at N (confirmed, verified) | Stamped in block N |
E_: a header in hand, and the proof does not lead to it | The proof does not lead to block N |
Never show "Stamped in block N" before the header check. From stamp-core 1.4.0,
pass verifyOtsAnchor straight to verify(): a header source that does not
answer gives anchor.status: 'unchecked' with a reason, and only a header
that was read and does not match gives E_BAD_ANCHOR. Offer a way to check
again for unchecked.
import type { StampEnvelope } from '@orangecheck/stamp-core';
import { verifySignature } from '@orangecheck/bip322';
import { verify } from '@orangecheck/stamp-core';
import {
makeAnchorVerifier,
mempoolHeaderSource,
} from '@orangecheck/stamp-ots';
declare const envelope: StampEnvelope; // the envelope you are labelling
const headers = mempoolHeaderSource({
baseUrl: 'https://esplora.example.com/api',
});
const result = await verify({
envelope,
verifyBip322: async (msg, sig, addr) => verifySignature(addr, msg, sig),
verifyOtsAnchor: makeAnchorVerifier({ headerSource: headers }),
});
function label(): string {
if (!result.ok) {
return result.code === 'E_BAD_ANCHOR'
? `The proof does not lead to block ${envelope.ots!.block_height}`
: `Does not verify: ${result.code}`;
}
const a = result.anchor;
if (a.status === 'confirmed') return `Stamped in block ${a.blockHeight}`;
// The header did not load (a.reason says why): check again later.
if (a.status === 'unchecked')
return `Couldn't check against block ${a.blockHeight} yet`;
if (a.status === 'claimed')
return `Waiting to be checked against block ${a.blockHeight}`;
return a.status === 'pending'
? 'Waiting for a Bitcoin block'
: 'No timestamp';
}
The header source learns which block each visitor is checking, and it is trusted
to say which block sits at a height. Use your own node (any
getHeaderAt(height) that returns the 80-byte header), or an Esplora you name
on your privacy page: mempoolHeaderSource({ baseUrl }) in code, or
--headers-url with stamp on the command line.
Offline verificationLink to this section
Given the envelope, the content, an upgraded OTS proof, and a cached block-header database, a verifier can confirm the stamp without any network call. This matters for:
- Air-gapped archives.
- Historical records (you want to verify a 2030 stamp in 2050 without trusting whatever OTS calendar operators happen to exist then).
- Adversarial environments where upstream calendars might be censored.
The whole check, wired: the signature through @orangecheck/bip322, the anchor
through makeAnchorVerifier, and the header from your own node, saved once to
disk.
import type { BlockHeaderSource } from '@orangecheck/stamp-ots';
import { readFile } from 'node:fs/promises';
import { verifySignature } from '@orangecheck/bip322';
import { parseStamp, verify } from '@orangecheck/stamp-core';
import { makeAnchorVerifier } from '@orangecheck/stamp-ots';
// Saved from your own node, once per anchor block:
// bitcoin-cli getblockheader "$(bitcoin-cli getblockhash 972551)" false \
// > headers/972551.hex
const headers: BlockHeaderSource = {
async getHeaderAt(height) {
const hex = await readFile(`headers/${height}.hex`, 'utf8');
return Uint8Array.from(Buffer.from(hex.trim(), 'hex')); // 80 bytes
},
};
const envelope = parseStamp(
await readFile('the-introductions.mp4.stamp', 'utf8')
);
const result = await verify({
envelope,
content: await readFile('the-introductions.mp4'), // optional
verifyBip322: async (msg, sig, addr) => verifySignature(addr, msg, sig),
verifyOtsAnchor: makeAnchorVerifier({ headerSource: headers }),
});
if (!result.ok) throw new Error(`${result.code}: ${result.message}`);
console.log(result.anchor);
// { status: 'confirmed', blockHeight: 972551, blockHash: '0000…8f69', verified: true }
Run as written, with every network call made to throw, against a stamp a
third-party app made and anchored in block 972,551, it reports confirmed. The
same envelope without verifyOtsAnchor reports
{ status: 'claimed', verified: false }: the block is the envelope's say-so
until a header has been checked. With a header from another block it fails with
E_BAD_ANCHOR, and without verifyBip322 it fails closed with E_BAD_SIG.
What could go wrongLink to this section
- Calendar disappears before anchoring. Mitigation: submit to ≥2 independent calendars.
- Calendar anchors but lies about the path. Mitigation: the proof chain is cryptographically self-checking against the Bitcoin header. A dishonest calendar can't fake the path; they can only refuse to publish.
- Bitcoin block reorgs deeper than the anchor. Mitigation: wait for ≥6 confirmations before treating a stamp as permanent. OTS proofs still verify; you just care about rollback risk for whatever you're doing.
See alsoLink to this section
- How it works — where
otsfits in the envelope flow - Use cases — when anchoring matters (release signing, publishing) and when it doesn't