Skip to content

karanjahpn/jsquad-aegis-swarm

Repository files navigation

JSQUAD Aegis-Swarm Protocol

Browser-native P2P video delivery with on-chain Proof-of-Delivery settlement.

License: MIT TypeScript Solidity Network: Base


Overview

Aegis-Swarm is a protocol layer that turns ordinary browsers into P2P video delivery nodes. Instead of pulling video chunks from a central CDN, participating peers exchange chunks directly — verified by cryptographic attestation and settled on-chain via the AegisSettlement contract.

┌─────────────────────────────────────────────────────────────┐
│                       Browser Client                        │
│                                                             │
│  ┌─────────────┐   ┌──────────────┐   ┌─────────────────┐  │
│  │  Aegis SW   │──▶│ Swarm Engine │──▶│  POD Protocol   │  │
│  │ (intercept) │   │ (routing)    │   │ (attestation)   │  │
│  └─────────────┘   └──────────────┘   └────────┬────────┘  │
└────────────────────────────────────────────────│────────────┘
                                                 │ batch submit
                                          ┌──────▼──────────┐
                                          │ AegisSettlement │
                                          │  (Base L2)      │
                                          └─────────────────┘

Monorepo Structure

jsquad-aegis-swarm/
├── packages/
│   ├── pod-protocol/          # Chunk verification & delivery attestation
│   │   └── src/pod.ts
│   ├── swarm-engine/          # Peer topology, discovery, chunk routing
│   │   └── src/swarm.ts
│   ├── service-worker/        # Fetch interceptor (P2P-first delivery)
│   │   └── src/index.ts
│   └── contracts/             # Solidity — on-chain settlement
│       ├── contracts/AegisSettlement.sol
│       ├── scripts/deploy.ts
│       └── test/AegisSettlement.test.ts
├── docs/
│   ├── whitepaper.md
│   └── branding/
├── package.json               # Workspace root
├── tsconfig.json
└── .gitignore

Quick Start

Prerequisites

  • Node.js ≥ 20
  • npm ≥ 10

Install

git clone https://github.com/YOUR_USERNAME/jsquad-aegis-swarm.git
cd jsquad-aegis-swarm
npm install

Build TypeScript

npm run build

Run Tests

# All packages
npm test

# Contracts only (Hardhat)
npm run compile --workspace=packages/contracts
cd packages/contracts && npx hardhat test

Packages

@jsquad/pod-protocol

Chunk-level Proof-of-Delivery. Accepts raw Uint8Array chunks, verifies SHA-256 checksums, and generates signed attestation objects ready for on-chain submission.

import { PodProtocol } from "@jsquad/pod";

const pod = new PodProtocol({ maxConcurrentChunks: 32 });
await pod.registerChunk({ cid, index, size, checksum });
const attestation = await pod.verifyChunk(cid, data, peerId);
const batch = pod.flushAttestations(); // → submit to AegisSettlement

@jsquad/swarm-engine

Peer topology management. Discovers peers, scores them by delivery reliability, routes chunk requests to optimal peers, and enforces stake-based reputation decay.

import { SwarmEngine } from "@jsquad/swarm";

const swarm = new SwarmEngine(selfPeerId, { maxPeers: 50 });
swarm.start();
swarm.addPeer({ id, multiaddrs });
const peer = swarm.selectPeerForChunk({ cid, requestedBy, priority: "high" });

@jsquad/service-worker

Intercepts all .m3u8, .ts, .mp4, .webm fetch requests. Tries the swarm first, falls back to origin CDN, and notifies the main thread of delivery source via postMessage.

Register in your app:

navigator.serviceWorker.register("/aegis-sw.js");

@jsquad/contracts

AegisSettlement.sol — deployed on Base L2. Peers stake ETH to register, submit batched chunk attestations, and claim rewards. Misbehaving peers can be slashed by the contract owner.

cd packages/contracts
npx hardhat compile
npx hardhat test
npx hardhat run scripts/deploy.ts --network base-sepolia

Environment Variables

Create a .env file in packages/contracts/:

BASE_RPC_URL=https://mainnet.base.org
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
DEPLOYER_PRIVATE_KEY=0x...
BASESCAN_API_KEY=...

Contributing

See CONTRIBUTING.md.


License

MIT © JSQUAD Protocol

About

browser-native P2P video delivery with on-chain Proof-of-Delivery settlement

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors