UOMP Implementation Design

This document explains how the UOMP reference implementation uomp-mvp turns the protocol specification into runnable code.


1. Implementation Overview

uomp-mvp is a TypeScript monorepo. Each package maps to a Spec role:

Package / AppRoleResponsibility
packages/coreSharedTypes, constants, utilities
packages/storeMemory StorePluggable storage backends (SQLite / Encrypted Object S3 / IPFS)
packages/tokenEdDSA JWT issuance and verification
packages/authAuth ServiceSession create/grant/close/revoke
packages/guardMemory GuardToken validation, scope filtering, audit logging
packages/identityIdentity VerificationWallet auth (MetaMask / Argent X / Braavos) + seed phrase
packages/sdkAgent SDKUompClient, dual-build for Node.js + browser
packages/cliUser UIUser CLI: data import, authorization, session/store/gateway management
apps/serverCombined Auth + Guard HTTP service (127.0.0.1:9374)
apps/gatewaySelf-hosted Gateway: mTLS + token forwarding + Cloudflare Tunnel
apps/relayCloud RelayStateless public Relay (design phase): pubkey verification + ciphertext forwarding

2. Architecture & Deployment Modes

UOMP supports three deployment modes, ordered by user burden (low to high):

2.1 Local Mode (Agent + Guard on same machine)

Default, zero-config. Agent connects directly to Memory Guard at http://127.0.0.1:9374.

┌──────────┐   HTTP   ┌──────────────┐   ┌──────────────┐
│  Agent   │ ───────► │ Memory Guard │──►│ Memory Store │
└──────────┘          └──────────────┘   └──────────────┘
pnpm --filter @uomp/server start
pnpm cli authorize ./my-agent --no-server
source /tmp/uomp.env && node index.js

pnpm cli agent run ./my-agent bundles auth + guard + agent launch — dev shortcut only.

2.2 Remote Mode (Agent external, via Gateway)

Agent runs on cloud (Digital Ocean / VPS / container), connects back through Gateway.

┌──────────────┐   mTLS + Token   ┌──────────────┐   HTTP   ┌──────────────┐
│ Remote Agent │ ────────────────► │   Gateway    │ ───────► │ Memory Guard │
└──────────────┘                  └──────────────┘          └──────────────┘

One command with Cloudflare Tunnel (no public IP needed):

uomp gateway start
# ═══ Public Gateway URL ═══
#   https://xxx.trycloudflare.com

2.3 Browser Mode (wallet auth + S3 direct + Cloud Relay)

Web Apps use @uomp/sdk/browser. Reads require zero server dependencies (S3 direct + in-browser decryption). Writes go through Cloud Relay.

Browser App ──read──► S3 (ciphertext) ──► in-browser decrypt
            ──write─► Cloud Relay ──► Guard ──► Store

No local install required. SDK auto-detects Gateway availability; falls back to S3 direct read when offline.


3. SDK

packages/sdk provides the UompClient class — same API for Node.js Agents and browser Web Apps.

3.1 Node.js Mode

import { UompClient } from '@uomp/sdk';

const uomp = UompClient.fromEnv(); // reads UOM_TOKEN + UOMP_BASE_URL

await uomp.memory.getByTag('portfolio:holdings');
await uomp.aggregate.sum('portfolio:holdings', 'value.market_value');
await uomp.payload.upload(report);
await uomp.session.finalize(); // deletion proof + close
await uomp.auth.createSession({ agentId, requestedScopes });

console.log(uomp.tokenInfo.scopes);
console.log(uomp.tokenInfo.expiresAt);

Transport handles: http:// → direct, https:// → mTLS auto-load, retry + backoff + timeout, UompError.

3.2 Browser Mode

import { BrowserSDK } from '@uomp/sdk/browser';

const uomp = await BrowserSDK.fromWallet();

// Read: auto-fallback (Gateway online → Gateway; offline → S3 direct + decrypt)
const holdings = await uomp.memory.getByTag('portfolio:holdings');

// Write: Cloud Relay
await uomp.memory.set('AAPL', newData);

if (!uomp.isGatewayOnline) { /* read-only mode */ }

Built-in StoreRouter: Gateway online routes through Gateway; offline falls back to S3 direct with client-side verification.

3.3 Wallet Authentication

Sdk derives encryption keys from wallet signatures:

WalletPlatformSDK Call
MetaMaskBrowserBrowserSDK.fromWallet()
Argent XBrowser (Starknet)BrowserSDK.fromWallet()
BraavosBrowser (Starknet)BrowserSDK.fromWallet()
Argent MobileiOS/AndroidWalletConnect
const id = await uomp.identity.fromWallet('starknet');
// → Argent X popup → sign → HKDF derives masterKey
// → Same wallet + same message → same key → same data on any device

Seed phrase (12-word BIP-39) retained as fallback for non-wallet scenarios.

3.4 Sub-client Quick Reference

Sub-clientKey Methods
uomp.memoryget(key), getByTag(tag), getByKeys(keys), listTags(), has(key)
uomp.aggregatesum(tag, field), avg(), count(), min(), max()
uomp.payloadupload(data), download(id), info(id)
uomp.sessionsubmitDeletionProof(), finalize(), close(), trackAccess(key)
uomp.auditquery({ sessionId, limit }), getLastAccess()
uomp.authcreateSession(), grant(), revoke(), validate()
uomp.identityfromWallet(chain), fromSeedPhrase(phrase)

4. Remote Access

4.1 User Gateway

apps/gateway is the user’s self-hosted Memory Guard entry point:

uomp gateway start               # Gateway + Cloudflare Tunnel
uomp gateway start --no-tunnel   # Gateway only
uomp gateway start --browser     # CORS enabled for browser apps

Responsibilities: mTLS termination, token validation (audience + signature + expiry), memory/audit forwarding, payload cache.

4.2 Cloud Relay

Cloud Relay is a stateless public version of Gateway. UOMP runs a default instance (relay.uomp.org); open-source code allows anyone to self-host.

User GatewayCloud Relay
DeployedUser localPublic cloud (always online)
Sees plaintext❌ (encrypted in Guard before storage)
User burdenInstall + runZero install
Use caseHigh-sensitivity dataGeneral use, Webapp developers

Relay stores no data and reads no plaintext — it only validates tokens and forwards ciphertext.

4.3 Store Abstraction

Memory Store is abstracted behind the IMemoryStore interface:

Guard → IMemoryStore ─┬─ SQLiteStore (local, default)
                       ├─ EncryptedObjectStore (S3/R2, multi-device)
                       └─ IPFSStore (decentralized)

Encryption occurs inside the Guard process; cloud backends store only ciphertext. Keys derived from wallet signatures via HKDF.

Full design doc: docs/store-abstraction-design.md.


5. Auth & Authorization

5.1 Agent Manifest (uom.json)

Agents declare requested_scopes, data_retention_policy, external_data_sources in uom.json. The CLI parses these in packages/cli/src/utils/manifest.ts.

5.2 Session Lifecycle

[created] ──grant──► [active] ──close/timeout/revoke/deletion-proof──► [closed/expired/revoked]

AuthService.grantSession() issues Capability Tokens with optional allowedFields, aggregationOnly, taskBound constraints.

5.3 JWT Implementation

5.4 Guard Enforcement

MemoryGuard.validateRequest() checks in order: signature → expiry → denylist → scope → sensitivity. aggregation_only tokens are rejected on non-aggregation paths. High-sensitivity items require explicit key authorization.


6. Stock Analyst Example

examples/stock-analyst/ is the full acceptance example:

  1. uomp import holdings CSV + risk profile
  2. uomp discover / uomp connect verify the Agent
  3. uomp authorize issues the Token
  4. Agent reads data → fetches quotes → analyzes (P&L, Sharpe, Beta, RSI, scenarios)
  5. Generates bilingual reports (JSON + Markdown + HTML)
  6. uomp sessions / uomp audit for auditing
  7. uomp revoke to revoke

Full steps: examples/stock-analyst/README.md.


7. Local Config Files

~/.uomp/
├── config.json           # Service port, store backend config
├── user.json             # User identity (wallet address, masterKey hash)
├── memory.db             # Memory Store (SQLite)
├── auth.db               # Sessions and denylist
├── audit.db              # Audit logs
├── remote-profile.json   # Gateway config (endpoint, allowlist)
├── .secrets/             # Ed25519 keypair
└── .gateway-certs/       # Gateway mTLS certs (CA + server + client)

8. MVP Limitations & Future Extensions

CapabilityStatusNotes
Agent readAuthorized by tag/key/field
Agent writeGuard returns 503 WRITE_NOT_AVAILABLE
Remote GatewaymTLS + Cloudflare Tunnel + browser CORS
Aggregationsum/avg/count/min/max, paired with aggregation_only
Deletion proofAgent submits signed proof, session auto-closes
Field filteringToken specifies allowed_fields, Guard filters
Browser SDKWallet auth + S3 direct read + Cloud Relay write
Store abstraction⚠️ DesignedSQLite / S3 / IPFS pluggable, Phase 2 implementation pending
Cloud Relay⚠️ DesignedPublic Gateway implementation, Phase 3.5 pending
Wallet auth⚠️ DesignedMetaMask / Argent X / Braavos, Phase 2 implementation pending
Identity verification⚠️DID/GPG framework present, verification to be strengthened