feat(android): MediaUploader — a phone puts films on a relay, in resumable pieces

MediaOwner signs owner requests and MediaUploader speaks the piece protocol
of media put (window, retries, resync after a lost answer). MediaSealer
.sealStream seals a film to a file; MediaGrant.encode/capabilityUrl make the
link to share. Owner signatures and encoded grants are pinned by new
vectors; scripts/media-live-kotlin.ts runs the uploader against a real TS
relay with a lost answer and a refused piece injected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-19 00:18:31 +02:00
parent f42a9bbe5e
commit f5125b8f66
13 changed files with 897 additions and 5 deletions

View File

@@ -57,7 +57,9 @@ import { sealWithPinnedKeys } from '../packages/shade-media/src/testing.js';
import { LivePublisher, epochKeys, chainStep, linkEpochSeed } from '../packages/shade-media/src/live/channel.js';
import { encodeContent, decodeFrame } from '../packages/shade-media/src/live/frame.js';
import type { LiveContent } from '../packages/shade-media/src/live/frame.js';
import { encodeGrant } from '../packages/shade-media/src/grant.js';
import { encodeGrant, toCapabilityUrl } from '../packages/shade-media/src/grant.js';
import { OwnerKey, ownerMessage } from '../packages/shade-media/src/owner.js';
import type { OwnerOp } from '../packages/shade-media/src/owner.js';
import type { MediaGrant } from '../packages/shade-media/src/grant.js';
import { albumMeta, encodeAlbum } from '../packages/shade-media/src/album.js';
import { withSubtitles } from '../packages/shade-media/src/subtitles.js';
@@ -1122,6 +1124,55 @@ async function generateMediaVectors(): Promise<Vector[]> {
labels: ['Norsk', null],
mediaIds: [hex(new Uint8Array(16).fill(0x55)), hex(new Uint8Array(16).fill(0x66))],
});
// Owner-signed requests: what a relay checks before it takes an upload, a
// piece of one, a delete. Ed25519 is deterministic, so the signatures are too.
const owner = new OwnerKey(new Uint8Array(32).fill(0x07));
const at = 1792360000000;
const id = '0123456789abcdef0123456789abcdef';
const readTokenHash = 'ab'.repeat(32);
const ops: OwnerOp[] = [
{ op: 'put', id, size: 4096, readTokenHash },
{ op: 'upload', id, size: 50 * 1024 ** 3, readTokenHash },
{ op: 'upload', id, size: 4096, readTokenHash: '' },
{ op: 'piece', id, offset: 3 * 16 * 1024 * 1024, length: 16 * 1024 * 1024 },
{ op: 'piece', id, offset: 50 * 1024 ** 3, length: 0 },
{ op: 'abort', id },
{ op: 'delete', id },
{ op: 'list' },
];
vectors.push({
description: 'owner: signed media requests (x-shade-owner / x-shade-at / x-shade-signature)',
seed: hex(new Uint8Array(32).fill(0x07)),
owner: owner.id,
at,
requests: ops.map((o) => ({
...o,
message: new TextDecoder().decode(ownerMessage(o, at)),
headers: owner.headers(o, at),
})),
});
// A grant as an uploader hands it on: the wire JSON (field order fixed, the
// meta canonical) and the capability link it makes.
const shared: MediaGrant = {
...film,
mediaId: new Uint8Array(16).fill(0x77),
readToken: new Uint8Array(32).fill(0x88),
meta: { extra: { 'shade.note': 'æøå' }, name: 'Fra telefonen — «Kveld».mp4', mime: 'video/mp4', durationMs: 61500, width: 1080, height: 1920 },
};
vectors.push({
description: 'grant encode: a media grant with url, token and meta, as JSON and as a capability link',
mediaId: hex(shared.mediaId),
mediaKey: hex(shared.mediaKey),
rootDigest: hex(shared.rootDigest),
url: shared.url,
readToken: hex(shared.readToken!),
meta: JSON.stringify(shared.meta),
json: encodeGrant(shared),
pageUrl: 'https://watch.example/',
link: toCapabilityUrl('https://watch.example/', shared),
});
return vectors;
}