Postern for developers
Let people send passwords and files from their phone to your page
Add one button. Your users scan a QR code, type or paste on their phone, and the field fills, end-to-end encrypted. No app to install and no accounts. Works on websites, smart-TV web apps and anything that runs JavaScript, and through a plain REST API everywhere else.
Try it
Click From phone next to a field and scan the QR code with your phone.
Nothing received yet.
Using the public relay at postern.dahp.io, including through the npm package, is subject to the Terms of Use. If you add Postern to your product, section 5 of the Terms explains your responsibilities.
Install
npm install @dahp/posternOr without a build step, from a CDN:
<script src="https://cdn.jsdelivr.net/npm/@dahp/postern@1/dist/postern.global.js"></script>Add the button
Mark the fields, then attach. The button fills the field after the user checks the 4-digit code.
<input type="password" id="password" data-postern>
<script type="module">
import { attachAll } from "@dahp/postern/ui";
attachAll();
</script>Or place the button yourself with the web component, which works in React, Vue, Svelte and plain HTML:
<input type="password" id="password">
<postern-button for="password"></postern-button>To handle what arrives yourself (a file, for example), listen for the event and cancel the default fill:
button.addEventListener("postern-receive", (event) => {
event.preventDefault();
const { item, code } = event.detail; // item: { type, text } or { type: "file", name, mime, bytes }
});Your own interface
open() shows the dialog and returns what the user confirmed. receive() has no interface at all, for TV apps, kiosks and custom designs: show session.link as a QR code and wait.
import { receive, drawQr } from "@dahp/postern";
const session = await receive({ types: ["password", "text"] });
drawQr(canvas, session.link);
const { item, code } = await session.result; // show code; use item once the user confirms| Option | What it does | Default |
|---|---|---|
server | Relay address, or your self-hosted relay | https://postern.dahp.io |
types | What the phone may send: password, text, url, file | All; a password field asks for passwords and text |
transport | websocket, poll (plain HTTP) or auto | auto |
scanner | Offline mode: pass startScanner from @dahp/postern/scanner | Off |
signal | An AbortSignal that cancels the session | None |
Content-Security-Policy
If your site sets one, allow the relay:
connect-src https://postern.dahp.io wss://postern.dahp.ioThe dialog needs no inline styles or scripts.
Other platforms: the REST API
Anything that can make HTTPS requests and do HPKE can receive: Android and Google TV (Tink), iOS and Apple TV (CryptoKit), servers, set-top boxes.
| Request | Who | What it does |
|---|---|---|
GET /api/s/{id} (WebSocket) | Receiver | Waits for the message. Send ping every 20 s; the relay answers pong. |
GET /api/s/{id}/wait | Receiver | Long polling: 200 with the message, 204 after 25 s (ask again), 410 expired or used |
DELETE /api/s/{id} | Receiver | Cancels the session |
POST /api/s/{id} | Phone | Body {"v":1,"enc":"…","ct":"…"}. 200 delivered, 202 queued for a reconnecting receiver, 404 nobody waiting, 410 closed |
The QR code holds https://postern.dahp.io/#v=1&id={session id}&k={public key}, optionally &t=password,text. Encryption is HPKE base mode with DHKEM(X25519, HKDF-SHA256), HKDF-SHA256 and AES-256-GCM, info dahp postern v1, associated data v1:{session id}. The full specification and test vectors are in the project's docs/PROTOCOL.md.
Self-host the relay
The relay only passes on ciphertext, but you can run your own. It's the same API and phone page:
docker build -t postern-relay .
docker run -p 8790:8790 postern-relayPut it behind HTTPS and pass server: "https://postern.example.com".
The Dockerfile, the relay and everything else on this page are in the source repository (Apache-2.0). Security reports: see SECURITY.md there.
Security
- Encrypted on the phone with a one-time key that only your page holds. The key travels after the
#in the QR link, which browsers never send to servers. - The relay holds each ciphertext in memory for at most 2 minutes and can't read it.
- A 4-digit code on both screens shows the message came from the user's phone, not from someone who photographed the QR code.
- The encryption matches the official RFC 9180 test vectors, and the test suite attacks it 17 ways.