A relay on jai (server/bubble_relay.py, stdlib + SQLite, tailscale address only, bearer token) carries sealed blobs between the desktop and the Rabbit: AES-256-GCM with a key the desktop makes and hands over USB (Sync to Rabbit), so jai can neither read nor forge anything. It deletes what's been picked up, and anything after 14 days. - Desktop (src/main/relay.ts): "Rabbit SIM" is a number to text from, groups included; the SIM's history and new texts arrive; older photos are fetched when shown; names and read/unread/archived go both ways. Settings → Rabbit relay connects it. - Rabbit (Relay.java, RelayJob): no timer of its own for the battery; it rides along with the background checks, plus one network job after a text, a send or a swipe. Each send from the desktop goes out at most once and not after a day. Plain http only to jai and localhost (network_security_config). - scripts/deploy-jai.sh; tests: server unit tests, an end-to-end relay test, and DEVICE=1 relay.device.test.ts against the dev app.
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
// Phone number helpers. voip.ms uses bare 10-digit NANP numbers, so everything
|
|
// is normalized to that form where possible (short codes and international
|
|
// numbers are left as plain digits).
|
|
|
|
export function normalizeNumber(raw: string): string {
|
|
let digits = raw.replace(/\D/g, '')
|
|
if (digits.length === 11 && digits.startsWith('1')) digits = digits.slice(1)
|
|
return digits
|
|
}
|
|
|
|
// The Rabbit's SIM, reached through jai (main/relay.ts): a number we text
|
|
// from that isn't a phone number here.
|
|
export const SIM_DID = 'sim'
|
|
|
|
// A number to send from, as pickers and "via" show it.
|
|
export function didName(did: string): string {
|
|
return did === SIM_DID ? 'Rabbit SIM' : formatNumber(did)
|
|
}
|
|
|
|
// Group chats: Google Voice threads, or MMS over the Rabbit's SIM.
|
|
export function groupsFrom(did: string | undefined, gvNumber: string | undefined): boolean {
|
|
return !!did && (did === gvNumber || did === SIM_DID)
|
|
}
|
|
|
|
export function formatNumber(n: string): string {
|
|
const d = normalizeNumber(n)
|
|
if (d.length === 10) return `(${d.slice(0, 3)}) ${d.slice(3, 6)}-${d.slice(6)}`
|
|
return n
|
|
}
|
|
|
|
// Group chats (Google Voice only) are keyed by their members' numbers, sorted
|
|
// and comma-joined, in the place a 1:1 chat keeps its one number.
|
|
export function groupKey(numbers: string[]): string {
|
|
return [...new Set(numbers.map(normalizeNumber).filter(Boolean))].sort().join(',')
|
|
}
|
|
|
|
export function isGroup(contact: string): boolean {
|
|
return contact.includes(',')
|
|
}
|
|
|
|
export function groupMembers(contact: string): string[] {
|
|
return contact.split(',')
|
|
}
|
|
|
|
// voip.ms's sendSMS takes at most 160 characters. Longer texts go out as one
|
|
// text-only MMS, which the recipient sees as a single message (split SMS arrive
|
|
// as separate fragments, often out of order).
|
|
export const SMS_TEXT_LIMIT = 160
|
|
|
|
export function charCount(text: string): number {
|
|
return [...text].length
|
|
}
|