Skip to content

sonr-io/motr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Motr

Multi-purpose WebAssembly monorepo powering secure cryptographic operations and decentralized identity for the Sonr ecosystem.

License: MIT Go Version TinyGo TypeScript Bun

Overview

Motr is a comprehensive WebAssembly-based monorepo that provides secure cryptographic operations, decentralized identity management, and a suite of web applications for the Sonr ecosystem. The architecture leverages Cloudflare Workers for edge computing and Go-compiled WASM for cryptographic operations.

Key Features

  • πŸš€ Hono-based Worker - Edge-deployed orchestrator serving multiple frontends with SSR
  • πŸ” Cryptographic Vault - WASM-based secure key management with MPC and threshold cryptography
  • 🎭 DID Management - Decentralized identity with WebAuthn integration via Enclave
  • ⚑ Vite Frontends - Modern React apps for auth, console, profile, and search
  • πŸ“¦ Shared Packages - Reusable TypeScript libraries and UI components

Repository Structure

motr/
β”œβ”€β”€ apps/                    # Vite-based frontend applications
β”‚   β”œβ”€β”€ auth/               # Authentication & registration app
β”‚   β”œβ”€β”€ console/            # Developer console & admin interface
β”‚   β”œβ”€β”€ profile/            # User profile management
β”‚   └── search/             # Sonr network search
β”‚
β”œβ”€β”€ libs/                   # Go/WASM cryptographic libraries
β”‚   β”œβ”€β”€ enclave/           # DID & WebAuthn Durable Object worker
β”‚   └── vault/             # Cryptographic vault operations
β”‚
β”œβ”€β”€ pkgs/                   # TypeScript packages
β”‚   β”œβ”€β”€ config/            # Shared build & lint configs
β”‚   β”œβ”€β”€ react/             # React hooks & providers
β”‚   β”œβ”€β”€ sdk/               # Core TypeScript SDK
β”‚   └── ui/                # Shared UI components (shadcn)
β”‚
β”œβ”€β”€ src/                    # Cloudflare Worker (Hono-based)
β”‚   └── worker.ts          # Main orchestrator serving all frontends
β”‚
β”œβ”€β”€ docs/                   # Documentation & MDX content
β”œβ”€β”€ wrangler.toml          # Worker deployment configuration
β”œβ”€β”€ tsconfig.json          # Worker TypeScript config
β”œβ”€β”€ package.json           # Root workspace configuration
└── turbo.json             # Turborepo build pipeline

Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/sonr-io/motr.git
cd motr

# Install all dependencies (uses Bun workspaces)
bun install

# Build all packages and libraries
turbo build

Development

# Start main worker (serves all frontends via Hono)
bun run dev

# Start specific frontend app
bun run dev:auth       # Authentication app
bun run dev:console    # Console app
bun run dev:profile    # Profile app
bun run dev:search     # Search app

# Start enclave worker (Durable Object)
cd libs/enclave && wrangler dev

# Start vault worker
cd libs/vault && wrangler dev

# Run tests
turbo test            # All tests
bun run test:all     # All package tests

# Linting and formatting
turbo lint           # Lint all packages
turbo format         # Format all packages
turbo check          # Type check all packages

Architecture

1. Cloudflare Worker (Hono)

The main orchestrator at src/worker.ts using Hono framework:

Features:

  • 🎯 Smart routing based on subdomain, path, and session state
  • πŸ“¦ Static asset serving for all Vite-built frontends
  • πŸ” Session management with KV storage
  • πŸ”Œ Service bindings to Enclave and Vault workers
  • πŸš€ Built-in middleware (logger, etag, CORS)

Routing Strategy:

// Subdomain routing
console.sonr.id/*  β†’ Console app
profile.sonr.id/*  β†’ Profile app
search.sonr.id/*   β†’ Search app

// Path-based routing
/console/*         β†’ Console app
/profile/*         β†’ Profile app
/search/*          β†’ Search app

// Session-based (authenticated users)
/                  β†’ Default app from user preferences

// Default (unauthenticated)
/                  β†’ Auth app

Development:

bun run dev          # Start worker at http://localhost:5165
bun run preview      # Test with remote bindings
bun run logs         # Tail production logs

2. Frontend Applications

Modern React apps built with Vite and TanStack:

Auth App (apps/auth/)

  • User registration and authentication
  • WebAuthn credential management
  • OAuth/OIDC flows
  • OTP verification

Console App (apps/console/)

  • Developer dashboard
  • API key management
  • Service configuration
  • Analytics and monitoring

Profile App (apps/profile/)

  • User profile management
  • DID document viewer
  • Credential management
  • Settings and preferences

Search App (apps/search/)

  • Sonr network search
  • User discovery
  • Service discovery
  • Explorer interface

Tech Stack:

  • React 19
  • TanStack Router, Query, Form
  • Vite 5
  • Tailwind CSS 4
  • TypeScript 5.9+

Development:

cd apps/auth
bun run dev          # Start dev server on port 3000

bun run build        # Build for production
bun run preview      # Preview production build

3. Cryptographic Libraries (Go/WASM)

Enclave (libs/enclave/)

Durable Object worker for decentralized identity:

Features:

  • DID document management (did:snr method)
  • WebAuthn credential storage and verification
  • Cryptographic key operations
  • Identity recovery flows

Technology:

  • Go β†’ WASM via TinyGo
  • Cloudflare Durable Objects
  • Persistent state storage

Build:

cd libs/enclave
bun run build        # Compile Go to WASM
wrangler deploy      # Deploy Durable Object

Vault (libs/vault/)

Service worker for cryptographic operations:

Features:

  • Multi-party computation (MPC)
  • Threshold signature schemes
  • Multi-chain transaction signing
  • Secure key derivation
  • IPFS import/export

Supported Chains:

  • Cosmos SDK chains
  • Ethereum/EVM chains
  • Solana
  • Bitcoin

Technology:

  • Go β†’ WASM via TinyGo
  • Service Worker runtime
  • Extism plugin system

Build:

cd libs/vault
bun run build        # Compile Go to WASM

4. TypeScript Packages

SDK (pkgs/sdk/)

Core TypeScript SDK for Sonr integration:

import { SonrClient, createVault } from '@sonr.io/sdk';

// Initialize client
const client = new SonrClient({
  rpcUrl: 'https://rpc.sonr.id',
  restUrl: 'https://api.sonr.id',
});

// Create vault
const vault = await createVault({
  name: 'my-vault',
  password: 'secure-password',
});

// Sign transaction
const signature = await vault.sign({
  chain: 'cosmos',
  transaction: tx,
});

Features:

  • Chain-agnostic transaction signing
  • DID management utilities
  • WebAuthn helpers
  • IPFS integration

UI Components (pkgs/ui/)

Shared UI component library built on shadcn/ui:

import { Button, Card, Input } from '@sonr.io/ui';

export function MyComponent() {
  return (
    <Card>
      <Input placeholder="Enter value" />
      <Button>Submit</Button>
    </Card>
  );
}

Features:

  • 50+ accessible components
  • Tailwind CSS styling
  • Dark mode support
  • TypeScript strict mode

React (pkgs/react/)

React-specific hooks and providers:

import { useSonr, SonrProvider } from '@sonr.io/react';

function App() {
  return (
    <SonrProvider config={config}>
      <MyApp />
    </SonrProvider>
  );
}

function MyApp() {
  const { account, connect, disconnect } = useSonr();
  // ...
}

Config (pkgs/config/)

Shared build configurations:

// vite.config.ts
import { createReactAppConfig } from '@sonr.io/config/vite/react-app';

export default createReactAppConfig();
// tsconfig.json
{
  "extends": "../../pkgs/config/typescript/react-app.json"
}

Build System

Turborepo Pipeline

turbo build          # Build all packages (respects dependencies)
turbo test           # Run all tests in parallel
turbo lint           # Lint all packages
turbo dev            # Start all dev servers

Build Order:

  1. @sonr.io/sdk - Core SDK (no dependencies)
  2. @sonr.io/ui - UI components (depends on sdk)
  3. @sonr.io/react - React hooks (depends on ui)
  4. libs/vault & libs/enclave - WASM builds (parallel)
  5. Frontend apps - Vite builds (depends on react)
  6. Worker - TypeScript compilation (depends on all apps)

Scripts Reference

Root Scripts

# Development
bun run dev                    # Start main worker
bun run dev:worker             # Start main worker (alias)
bun run dev:auth               # Start auth app
bun run dev:console            # Start console app
bun run dev:profile            # Start profile app
bun run dev:search             # Start search app
bun run dev:all                # Start all in parallel

# Building
bun run build                  # Build all packages
bun run build:apps             # Build only frontend apps
bun run build:libs             # Build only WASM libraries
bun run build:pkgs             # Build only TS packages
bun run build:force            # Force rebuild ignoring cache

# Testing
bun run test                   # Run all tests
bun run test:all               # Run tests in all packages
bun run test:watch             # Run tests in watch mode

# Quality
bun run lint                   # Lint all packages
bun run lint:fix               # Lint and auto-fix
bun run format                 # Format all files
bun run check                  # Run type checks
bun run typecheck              # Run type checks (alias)

# Deployment
bun run deploy                 # Deploy main worker
bun run deploy:staging         # Deploy to staging
bun run deploy:production      # Deploy to production
bun run preview                # Test with remote bindings
bun run logs                   # Tail production logs

# Maintenance
bun run clean                  # Clean build artifacts
bun run clean:cache            # Clean turbo cache
bun run clean:turbo            # Clean turbo daemon

Deployment

Single Worker Deployment

All frontend apps are served by a single Cloudflare Worker:

# Deploy to production
bun run deploy

# Deploy to staging
bun run deploy:staging

# Test before deploying
bun run preview

Deployment Process:

  1. Build all frontend apps (turbo build)
  2. Compile worker TypeScript
  3. Wrangler bundles static assets
  4. Deploy to Cloudflare edge network

Environment Configuration

# wrangler.toml
name = "motr-orchestrator"
main = "src/worker.ts"
compatibility_date = "2025-01-11"

[env.production]
routes = [
  { pattern = "sonr.id/*", custom_domain = true },
  { pattern = "*.sonr.id/*", custom_domain = true }
]

[env.staging]
name = "motr-orchestrator-staging"
workers_dev = true

Durable Objects

Enclave and Vault workers are deployed separately:

# Deploy enclave (Durable Object)
cd libs/enclave && wrangler deploy

# Deploy vault
cd libs/vault && wrangler deploy

Testing

Unit Tests

# All tests
turbo test

# Specific package
bun --filter '@sonr.io/sdk' test

# Watch mode
turbo test -- --watch

# Coverage
turbo test -- --coverage

Integration Tests

# End-to-end tests
bun run test:e2e

# Worker tests
wrangler dev --test

Documentation

Contributing

We welcome contributions! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and linting (turbo check && turbo test)
  5. Commit your changes (conventional commits preferred)
  6. Push to your branch
  7. Open a Pull Request

Code Style

  • TypeScript: Oxlint + Biome formatting
  • Go: gofmt + golangci-lint
  • Commits: Conventional commits (feat:, fix:, docs:, etc.)

Security

Reporting Security Issues

DO NOT open public issues for security vulnerabilities.

Email: [email protected]

Security Features

  • All cryptographic operations run in sandboxed WASM
  • Keys never leave the secure enclave
  • Multi-party computation for threshold operations
  • Zero-knowledge proofs for privacy-preserving operations
  • WebAuthn integration for passwordless authentication

Performance

  • Edge Computing: Cloudflare Workers in 300+ cities worldwide
  • Cold Start: < 5ms worker execution time
  • Build Size: Optimized WASM bundles (< 500KB)
  • Caching: Aggressive caching for static assets
  • Code Splitting: Route-based splitting for frontends

License

MIT License - see LICENSE for details

Links

Acknowledgments

Built with outstanding open-source technologies:

  • Hono - Ultrafast web framework
  • TinyGo - Go compiler for WebAssembly
  • Extism - Universal plugin system
  • TanStack - Modern React utilities
  • Cloudflare Workers - Edge computing platform
  • Vite - Next generation frontend tooling
  • Bun - Fast all-in-one JavaScript runtime
  • shadcn/ui - Accessible component library

Made with ❀️ by the Sonr Team

About

🚧 Under Construction | JS Light Node for the Sonr Network

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published