Shared: Shared Types and Utilities
Foundational package providing Result<T,E> discriminated unions, ok()/err() constructors, TLV type codes, and 140+ TypeScript interfaces covering every domain in the PRIVATE.ME ecosystem.
The Problem
Multi-package ecosystems need consistent type definitions. Type mismatches between packages cause silent runtime errors. No standard error handling pattern leads to inconsistent failure modes.
When packages define their own types independently, subtle incompatibilities emerge at integration boundaries. A "Share" type in one package may differ from the "Share" type in another by a single field, causing silent data loss or corruption at runtime despite successful TypeScript compilation.
Without a standard error handling pattern, some packages throw exceptions, others return null, and still others use custom error objects. Callers cannot predict failure modes, leading to unhandled errors in production and inconsistent user experiences across the platform.
The Old Way
The PRIVATE.ME Solution
A single source of truth for every type, constant, and error pattern in the PRIVATE.ME ecosystem. Result<T,E> discriminated unions enforce exhaustive error handling at compile time.
All 65 packages in the ecosystem import their shared types from @private.me/shared. When a type changes, it changes everywhere simultaneously. No drift, no mismatches, no silent incompatibilities. TypeScript strict mode catches any integration issues at compile time, not runtime.
The Result<T,E> pattern replaces thrown exceptions with discriminated unions. Every function returns either { ok: true, value: T } or { ok: false, error: E }. Callers must handle both cases. The compiler enforces this. Unhandled errors become impossible.
The New Way
How It Works
The shared package provides three layers: type definitions (interfaces and enums), utility constructors (ok/err/uuid), and domain constants (TLV codes, magic numbers, thresholds).
Use Cases
Result<T,E> with ok()/err() constructors. Discriminated unions force exhaustive error handling at compile time. No unhandled exceptions possible in library code.
Result<T,E>TLV type codes, IDA5 magic number (0x49444135), error code enumerations, and threshold constants used consistently across the entire platform.
single sourceShare, ContactInfo, DeviceInfo, and 140+ other interfaces ensure that data flows between packages without type mismatches or silent field drops.
140+ interfacesTLV (Type-Length-Value) codes for binary serialization of shares, metadata, and protocol messages. Consistent encoding across all transport channels.
TLV codesIntegration
import { ok, err, type Result } from '@private.me/shared'; // Type-safe error handling function processShare(data: Uint8Array): Result<Share, ShareError> { if (data.length === 0) { return err({ code: 'EMPTY_DATA', message: 'No data' }); } return ok({ index: 0, data, hmac: computeHmac(data) }); } // Caller MUST handle both cases const result = processShare(input); if (result.ok) { console.log(result.value); // Share } else { console.log(result.error); // ShareError }
Security Properties
| Property | Mechanism | Guarantee |
|---|---|---|
| Type Safety | TypeScript strict mode | Compile-time mismatch detection |
| Error Handling | Result<T,E> discriminated union | No unhandled exceptions |
| Consistency | Single source of truth | No type drift across 65 packages |
| Serialization | TLV type codes | Deterministic binary encoding |
| Supply Chain | Zero external dependencies | No transitive attack surface |
Ship Proofs, Not Source
Shared generates cryptographic proofs of correct execution without exposing proprietary algorithms. Verify integrity using zero-knowledge proofs — no source code required.
- Tier 1 HMAC (~0.7KB)
- Tier 2 Commit-Reveal (~0.5KB)
- Tier 3 IT-MAC (~0.3KB)
- Tier 4 KKW ZK (~0.4KB)
Use Cases
Deployment Options
SaaS Recommended
Fully managed infrastructure. Call our REST API, we handle scaling, updates, and operations.
- Zero infrastructure setup
- Automatic updates
- 99.9% uptime SLA
- Enterprise SLA available
SDK Integration
Embed directly in your application. Runs in your codebase with full programmatic control.
npm install @private.me/shared- TypeScript/JavaScript SDK
- Full source access
- Enterprise support available
On-Premise Upon Request
Enterprise CLI for compliance, air-gap, or data residency requirements.
- Complete data sovereignty
- Air-gap capable deployment
- Custom SLA + dedicated support
- Professional services included
Enterprise On-Premise Deployment
While Shared is primarily delivered as SaaS or SDK, we build dedicated on-premise infrastructure for customers with:
- Regulatory mandates — HIPAA, SOX, FedRAMP, CMMC requiring self-hosted processing
- Air-gapped environments — SCIF, classified networks, offline operations
- Data residency requirements — EU GDPR, China data laws, government mandates
- Custom integration needs — Embed in proprietary platforms, specialized workflows
Includes: Enterprise CLI, Docker/Kubernetes orchestration, RBAC, audit logging, and dedicated support.