Early beta (v0.9) · free while in beta · nothing anyone says is kept once it is heard

SDK

@tin-phone/sdk

TypeScript for any project: browsers, Node 22 and React Native. It is a package in the repository, packages/sdk; it is not on npm yet.

Channels and messages: TinPhoneClient

import { TinPhoneClient } from "@tin-phone/sdk";

const client = new TinPhoneClient({ apiUrl: "https://tin-phone.example", apiKey: token });

const channel = await client.createChannel("websocket", participants);
await client.sendMessage(channel.id, sender, { type: "text", body: "Hello!" });
const history = await client.getMessages(channel.id);
await client.getAdapters();
await client.health();
await client.closeChannel(channel.id);

// Realtime
const socket = client.connect(channel.id, "user1");
socket.onMessage((msg) => console.log(msg));
socket.onPresence((p) => console.log(p));
socket.open();
socket.send({ type: "text", body: "Hi there!" });

Errors are TinPhoneError.

Device notices: NoticesClient

Contract version 1.0.0, checked by the conformance vectors.

import { NoticesClient } from "@tin-phone/sdk";

const notices = new NoticesClient({ baseUrl, tenantId, token, trustedKeys });
const sent = await notices.send({ to: [deviceId], content: { type: "text", body: "Gate 4 is open" } });
await notices.get(sent.id);                 // per-device states
await notices.waitFor(sent.id, (s) => s.deliveries.every((d) => d.state === "acknowledged"));
const { events, check } = await notices.verifiedReceipts(sent.id);   // throws unless the chain verifies
await notices.revoke(sent.id);
NoticesClient
MethodDoes
send(input)sends a notice: to, content, actions, ttlSeconds or expiresAt, followUp
get(id)the notice and each delivery's state
revoke(id)takes it back from every device that has not acknowledged
receipts(id)the sealed chain, as the server gives it
verifiedReceipts(id, keys?)the chain, verified against the keys you pinned
waitFor(id, done, options)polls until done(status) is true or the wait runs out
verifyReceiptChain(events, keys, id?)the verifier on its own: {ok, count, head} or the first failure's seq and code

Errors are NoticeApiError with a kind (invalid, unauthorised, forbidden, not-found, conflict, unavailable, server, unexpected), ReceiptVerificationError and NoticeWaitTimeoutError.

Push-to-talk: PttClient and PttSession

import { PttClient, webCryptoDeviceSigner } from "@tin-phone/sdk";

const signer = await webCryptoDeviceSigner(privateKey, publicKeyDer);   // Pillion's request signing
const ptt = new PttClient({ apiUrl, signer });
const [first] = await ptt.channels();
const talk = await ptt.connect(first.id);
talk.on("audio", (f) => player.play(f.payload));
talk.on("floor", (f) => {
  // press() only asks; send once the server grants the floor to this device
  if (f.state === "granted" && f.holder === talk.me) startSending();
});
talk.press();
// while talking (talk.talking is true), every 20 ms: talk.sendAudio(packet)
// when the key is let go: talk.release()

The session checks each sealed digest against what it heard and confirms a replay as heard only when they match. ptt.iceServers() gives STUN and TURN for WebRTC.

WebRTC: PttRtcMesh

import { PttRtcMesh } from "@tin-phone/sdk";

const mesh = new PttRtcMesh(talk, {        // the connected PttSession, then the options
  RTCPeerConnection,                       // the platform's
  iceServers: () => ptt.iceServers(),      // refreshed before the TURN credential runs out
  localStream: () => navigator.mediaDevices.getUserMedia({ audio: true }),
  onRemoteStream: (from, stream) => play(stream),
});

Writing an adapter

  1. Create packages/adapters/<name>/ with its package.json and tsconfig.json.
  2. Implement the Adapter interface from @tin-phone/core.
  3. Declare its capabilities: realtime, bidirectional, richContent, presence, typing.
  4. send() for outbound delivery; parse() for inbound events; verify() for webhook signatures, if it has them.
  5. Tests in src/__tests__/.

Writing a provider

  1. packages/providers/<name>/, exporting . and ./fake.
  2. A classifier for the provider's error bodies, and a class implementing TextSink (or a narrower API) that passes its secrets in for redaction.
  3. A fake built on FakeProvider, with the provider's real request checks and error bodies.
  4. Tests of the adapter against its fake, including each refusal and each error kind.