PrivacyPin API v0 #
PrivacyPin is a federated, self-hosted location sharing app. the server stores nothing in plaintext -- all location data is end-to-end encrypted. the server acts as a dumb relay: authenticated users push encrypted location pings, and pull pings from the people sharing with them.
base URL: http://<server>:3000/v0
sharing model #
links are directed. the primitive is a share: a one-way channel source -> viewer where the source pushes encrypted pings and the viewer pulls them. there is no "friendship" object -- a two-way relationship is just two independent shares pointing opposite ways.
a share is established with a capability-based invite:
- the viewer (the person who wants to receive a location) calls
create-inviteand gets back a single-useinvite_token. they bundle{ invite_token, viewer_id, viewer_pubkey }and hand it to the source out of band (QR code, deep link, messaging app, whatever). - the source (the person who will send their location) calls
accept-invitewith that token. this is the final, consenting step: the instant it succeeds thesource -> viewerlink exists and the source may push pings.
this ordering is deliberate. the person sharing their position always performs the last action, so a share never goes live without the source's explicit, final consent. there is no ambiguous "both sides pending" state and no race over who acted last.
no acceptance polling. the viewer never asks "was my invite accepted?" -- they simply call get-pings. an empty result means the source hasn't accepted yet (or has nothing new); a non-empty result means the share is live and here's the data. acceptance and delivery are the same event. for live updates without per-contact polling, use the optional GET /events push stream.
auth #
all authenticated endpoints require these headers:
Authorization: Bearer <token>
X-User-Id: <user_id>
| field | type | description |
|---|---|---|
| token | string | the auth token returned on account creation |
| user_id | string | your user id (5-char nanoid) |
the token proves you own the account, the user_id tells the server which account you're claiming. both must match -- a token only works for the user it was issued to.
the only endpoint that skips auth is POST /create-account.
auth errors (all authenticated endpoints)
| status | body | cause |
|---|---|---|
| 401 | Missing auth header | no Authorization: Bearer header |
| 401 | Missing user id | no X-User-Id header |
| 401 | Invalid token | token doesn't match the claimed user_id |
endpoints #
POST /create-account #
create a new account using a one-time signup key.
auth required: no
request body
| field | type | description |
|---|---|---|
| signup_key | string | one-time key generated by an admin |
response 200
| field | type | description |
|---|---|---|
| user_id | string | your new user id (5-char nanoid) |
| token | string | your auth token (keep this safe) |
| is_admin | bool | true if you were the first user |
errors
| status | body | cause |
|---|---|---|
| 400 | Invalid signup key | key doesn't exist |
example
curl -X POST http://127.0.0.1:3000/v0/create-account \
-H "Content-Type: application/json" \
-d '{
"signup_key": "abc12345"
}'
{ "user_id": "xK7mP", "token": "tok_abc123def456", "is_admin": true }
POST /generate-signup-key #
generate a new one-time signup key. admin only.
auth required: yes (must be admin)
request body: empty ({})
response 200
| field | type | description |
|---|---|---|
| signup_key | string | new one-time key (5-char nanoid) |
errors
| status | body | cause |
|---|---|---|
| 403 | not allowed: admin only | non-admin called it |
example
curl -X POST http://127.0.0.1:3000/v0/generate-signup-key \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tok_abc123def456" \
-H "X-User-Id: xK7mP" \
-d '{}'
{ "signup_key": "aB3xY" }
POST /create-invite #
create a single-use invite that lets someone establish a share to you (you become the viewer, they become the source). you hand the returned token to the intended source out of band, along with your user_id and pubkey.
auth required: yes
request body: empty ({})
response 200
| field | type | description |
|---|---|---|
| invite_token | string | single-use capability token for accept-invite |
| expires_at | number | unix timestamp (seconds) after which it's rejected |
notes
- the token is a random, unguessable blob. holding it is the only way to open a share to you -- there is no way to establish a link by guessing a user id.
- single-use: consumed on the first successful
accept-invite. - the server stores only
{ invite_token -> viewer_id, expiry }. it never learns who the source will be until they accept.
example
curl -X POST http://127.0.0.1:3000/v0/create-invite \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tok_abc123def456" \
-H "X-User-Id: xK7mP" \
-d '{}'
{ "invite_token": "inv_9fK2pQ7xL0", "expires_at": 1751600000 }
POST /accept-invite #
consent to share your location with the invite's creator. this is the final step that brings a source -> viewer link into existence. after this call succeeds, you (the source) may send-pings to the viewer.
auth required: yes
request body
| field | type | description |
|---|---|---|
| invite_token | string | the token you received from a viewer |
response 200
| field | type | description |
|---|---|---|
| viewer_id | string | the id of the viewer you are now sharing with |
errors
| status | body | cause |
|---|---|---|
| 400 | Invalid invite token | token doesn't exist or was already used |
| 410 | Invite token expired | token is past its expires_at |
| 409 | Cannot share with yourself | the invite was created by your own account |
example
curl -X POST http://127.0.0.1:3000/v0/accept-invite \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tok_src999" \
-H "X-User-Id: aBcDe" \
-d '{ "invite_token": "inv_9fK2pQ7xL0" }'
{ "viewer_id": "xK7mP" }
POST /send-pings #
send one or more encrypted location pings. each ping is addressed to a viewer you have an active you -> viewer share with (i.e. a viewer whose invite you accepted).
auth required: yes
request body: an array of ping objects
| field | type | description |
|---|---|---|
| receiver_id | string | the viewer's user id |
| encrypted_ping | string | location data encrypted for the viewer |
response 200: empty body
errors
| status | body | cause |
|---|---|---|
| 403 | No share exists from sender to receiver | you have no you -> receiver link |
example
curl -X POST http://127.0.0.1:3000/v0/send-pings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tok_src999" \
-H "X-User-Id: aBcDe" \
-d '[
{ "receiver_id": "xK7mP", "encrypted_ping": "<encrypted blob>" },
{ "receiver_id": "fGhIj", "encrypted_ping": "<encrypted blob>" }
]'
(200, empty body)
POST /get-pings #
retrieve encrypted location pings sent to you by a specific source. returns them newest-first (up to the ring buffer capacity).
this doubles as the acceptance check: if you invited someone and they haven't accepted yet, there is no source -> you link and you'll get 403. once they accept and push, you get their pings. an accepted-but-idle source returns an empty array.
auth required: yes
request body
| field | type | description |
|---|---|---|
| sender_id | string | the source's user id |
response 200: JSON array of encrypted ping strings
["<encrypted ping 1>", "<encrypted ping 2>", ...]
errors
| status | body | cause |
|---|---|---|
| 403 | No share exists from sender to you | that user hasn't accepted your invite |
example
curl -X POST http://127.0.0.1:3000/v0/get-pings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tok_abc123def456" \
-H "X-User-Id: xK7mP" \
-d '{ "sender_id": "aBcDe" }'
["<encrypted location data>", "<older encrypted location data>"]
GET /events #
(optional) open a long-lived stream that nudges you when a source has new data for you, so clients don't have to poll get-pings per contact on a timer. one connection replaces N pollers.
auth required: yes (headers sent on the initial request)
response: a stream (SSE) of events. each event names a sender that has new pings waiting; the client responds by calling get-pings for that sender.
event: new-pings
data: { "sender_id": "aBcDe" }
notes
- the stream carries no location content, only "sender X has something for you" nudges. it can be reduced to a contentless "wake up and sync" signal if even sender metadata should be hidden, leaking nothing but timing.
- clients should degrade gracefully: if the stream drops or is unavailable, fall back to lazy
get-pingson app open.
notes #
- api versioning: all endpoints are under
/v0/.v0means "unstable, expect breaking changes." once the project hits a stable release, the api will be bumped to/v1/and frozen. the server may serve multiple versions simultaneously during transitions. - all user ids and signup keys are 5-character nanoids (
[A-Za-z0-9_-]) - in debug builds, server errors include a
causefield. in release, only the message is returned - the ring buffer for location pings defaults to 5 entries per link
- the first user to create an account automatically becomes the admin
- links are directed: a share
source -> viewerlets the source push and the viewer pull. the source always performs the final consenting step (accept-invite), so a share never goes live without the source knowing. a two-way relationship is two independent shares. - server state is entirely in-memory; restarts wipe everything