feat(sdk): shareMedia / onMediaGrant — media grants over a Shade session

A grant for a sealed file or a live channel rides the Double Ratchet like
any message. With an onMediaGrant handler registered, grants are routed
there instead of onMessage; with none, they arrive as text as before.
Bench results for @shade/media (1 GiB, up to 200 live viewers, 100 %
delivered) committed with their chart spec.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-18 21:17:59 +02:00
parent e9ae5bd28e
commit 8fd1b19902
7 changed files with 347 additions and 0 deletions

67
bench/media-results.json Normal file
View File

@@ -0,0 +1,67 @@
{
"at": "2026-10-18T19:15:13.188Z",
"bun": "1.3.5",
"bigMiB": 1024,
"seal": {
"mibPerSec": 259.1,
"ms": 3951.4,
"overheadPct": 0.0046
},
"readDisk": {
"mibPerSec": 480.2,
"ms": 2132.4
},
"upload": {
"mibPerSec": 50.9
},
"readHttp": {
"mibPerSec": 209.5,
"ms": 4889
},
"open": {
"p50": 3.28,
"p95": 6.58
},
"seek": {
"p50": 3.98,
"p95": 8.21,
"max": 16.08
},
"live": [
{
"viewers": 1,
"delivered": 100,
"p50": 3,
"p95": 12,
"max": 14
},
{
"viewers": 10,
"delivered": 100,
"p50": 6,
"p95": 20,
"max": 49
},
{
"viewers": 50,
"delivered": 100,
"p50": 22,
"p95": 58,
"max": 213
},
{
"viewers": 100,
"delivered": 100,
"p50": 15,
"p95": 72,
"max": 255
},
{
"viewers": 200,
"delivered": 100,
"p50": 28,
"p95": 151,
"max": 443
}
]
}

147
bench/media.chart.json Normal file
View File

@@ -0,0 +1,147 @@
[
{
"type": "bar",
"title": "Sealed media throughput (MiB/s)",
"subtitle": "1024 MiB of incompressible data, 1 MiB segments, one core",
"y": {
"label": "MiB/s",
"min": 0
},
"note": "Bun 1.3.5; HTTP is localhost through the real media routes; size overhead 0.0046 %",
"source": {
"path": "media-results.json"
},
"series": [
{
"name": "MiB/s",
"data": [
[
"seal (disk → disk)",
259.1
],
[
"read + verify (disk)",
480.2
],
[
"upload (HTTP PUT)",
50.9
],
[
"read + verify (HTTP Range)",
209.5
]
]
}
]
},
{
"type": "bar",
"title": "Seeking in a sealed film over HTTP (ms)",
"subtitle": "open = footer + trailer + root check; seek = first 64 KiB at a random offset, no cache",
"y": {
"label": "ms",
"min": 0
},
"note": "n = 10 opens, 100 seeks; localhost",
"source": {
"path": "media-results.json"
},
"series": [
{
"name": "p50",
"data": [
[
"open",
3.28
],
[
"seek",
3.98
]
]
},
{
"name": "p95",
"data": [
[
"open",
6.58
],
[
"seek",
8.21
]
]
}
]
},
{
"type": "line",
"title": "Live fan-out: latency publish → decrypted, by viewers",
"subtitle": "10 fps × 32 KiB frames (≈ 2.6 Mbit/s) for 6 s; relay in its own process, all viewers in one",
"x": {
"label": "viewers"
},
"y": {
"label": "ms",
"min": 0
},
"note": "delivered: 1 → 100 %, 10 → 100 %, 50 → 100 %, 100 → 100 %, 200 → 100 %. Every viewer verifies every signature and decrypts every frame, in one process, so the curve is mostly the viewers' CPU, not the relay's.",
"source": {
"path": "media-results.json"
},
"series": [
{
"name": "p50",
"data": [
[
1,
3
],
[
10,
6
],
[
50,
22
],
[
100,
15
],
[
200,
28
]
]
},
{
"name": "p95",
"data": [
[
1,
12
],
[
10,
20
],
[
50,
58
],
[
100,
72
],
[
200,
151
]
]
}
]
}
]