Browser-native P2P video delivery with on-chain Proof-of-Delivery settlement.
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) │
└─────────────────┘
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
- Node.js ≥ 20
- npm ≥ 10
git clone https://github.com/YOUR_USERNAME/jsquad-aegis-swarm.git
cd jsquad-aegis-swarm
npm installnpm run build# All packages
npm test
# Contracts only (Hardhat)
npm run compile --workspace=packages/contracts
cd packages/contracts && npx hardhat testChunk-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 AegisSettlementPeer 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" });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");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-sepoliaCreate 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=...See CONTRIBUTING.md.
MIT © JSQUAD Protocol