@estiva-app/protocol 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,91 @@ Every entry answers the wire question explicitly, including when the answer is
4
4
  nothing (ADR 0002 §4b). A change to the bytes an app publishes is a MAJOR — in
5
5
  `0.x`, a MINOR — even when no TypeScript signature moved.
6
6
 
7
+ ## 0.19.0 — 2026-09-10
8
+
9
+ **Wire behaviour: the bytes an upload sends change.** `uploadBlob` now strips
10
+ an image's metadata before hashing it, so the blob's sha256 — and therefore the
11
+ `x` and `url` of the `imeta` that names it — differ from what the same file
12
+ would have produced in 0.18.0. Nothing already published can disagree, because
13
+ in 0.18.0 such an upload **failed**: the relay refused it. This turns a 422 into
14
+ a blob.
15
+
16
+ - **New: `canonicalizeImage`, and `uploadBlob` applies it by default.**
17
+
18
+ Buzz refuses media carrying metadata, structurally — `validate_image_metadata_free`
19
+ returns `MetadataForbidden` and the upload 422s with
20
+ `media contains metadata or a non-canonical metadata channel`. Its video path
21
+ names the piece that was missing: *"only the canonical primary stream produced
22
+ by the client sanitizer is permitted."* There was no client sanitizer, in
23
+ either app, so **an unmodified screenshot was refused every time** — capture
24
+ tools write a `pHYs` and a `tEXt` software tag, and neither is on Buzz's
25
+ rendering allowlist. `pHYs` is excluded deliberately; the relay's comment
26
+ calls arbitrary values an identity channel.
27
+
28
+ PNG: keeps the critical chunks and the eleven rendering ancillaries Buzz
29
+ allows, plus a single Buzz snapshot-manifest `tEXt` — stripping that would
30
+ leave a `.agent.png` that still looks like an image and silently no longer
31
+ carries its manifest. JPEG: keeps a canonical JFIF `APP0` and a 12-byte Adobe
32
+ `APP14`, drops `APP1`–`APP13` (EXIF lives in `APP1`), `APP15` and `COM`, and
33
+ truncates trailing bytes after `EOI`, which is where a metadata editor leaves
34
+ them.
35
+
36
+ **Chunks are dropped, never re-encoded.** A canvas round trip is the obvious
37
+ implementation and it does not work: the browser's encoder adds an ICC profile
38
+ back, which the relay refuses identically. Dropping is also lossless — every
39
+ chunk removed is ancillary by the format's own definition.
40
+
41
+ GIF and WebP pass through untouched. Their metadata is not a droppable chunk
42
+ (WebP records EXIF/ICC/XMP presence in `VP8X` flags that must stay consistent
43
+ with the chunks; GIF hides it in extension blocks) and a wrong rewrite makes a
44
+ corrupt image, which is worse than the refusal it replaces.
45
+
46
+ `canonicalize: false` opts out for a caller sending something it does not want
47
+ touched. It is not a way round a refusal — the relay's answer is the same.
48
+
49
+ ## Backfill — 0.16.0 through 0.18.0
50
+
51
+ These three shipped without entries, which this file's own header forbids. The
52
+ omissions were mine. Recorded now rather than left as three published versions
53
+ whose wire question nobody answered. (`0.14.0` is still missing and is not mine
54
+ to reconstruct.)
55
+
56
+ ## 0.18.0 — 2026-09-09
57
+
58
+ **Wire behaviour: unchanged in shape.** It adds a request an app did not make
59
+ before — `PUT /upload` — but nothing about a published event moves.
60
+
61
+ - **New: `uploadBlob`, `imetaFor`, `sha256Of`.** CON-12's write half. The
62
+ upload must land before the message that names it: ingest runs
63
+ `verify_imeta_blobs` and refuses a message whose blob it does not already
64
+ hold, so a dangling attachment cannot be published at all. `imetaFor` exists
65
+ because `m` and `x` must be the **relay's** answers about what it stored, not
66
+ the client's guess from a file extension — `validate_imeta_tags` compares them
67
+ and refuses with nothing to say which field was wrong.
68
+
69
+ ## 0.17.0 — 2026-09-09
70
+
71
+ **Wire behaviour: unchanged.** Read-only; nothing is published.
72
+
73
+ - **New: `fetchBlob`, `sha256FromMediaUrl`.** Media GET is unconditionally
74
+ authenticated — `get_blob` calls `authenticate_media_read` before it touches
75
+ storage, and the `BUZZ_REQUIRE_MEDIA_GET_AUTH` flag that reads like an opt-in
76
+ is inert — so an `<img src>` answers 401 and every reader has to sign a `get`
77
+ authorization. Shared because both apps have the same problem with the same
78
+ relay, and one trap is genuinely surprising: **a thumbnail authorizes against
79
+ its parent hash**, since the relay splits `sha256_ext` on the first dot.
80
+
81
+ ## 0.16.0 — 2026-09-08
82
+
83
+ **Wire behaviour: new.** Apps begin publishing an `imeta` tag on messages, and
84
+ signing a `kind:24242` that never existed here before.
85
+
86
+ - **New: `buildBlossomAuth`, `blossomAuthHeader`, `imetaTag`, `imetaOf`, `Imeta`.**
87
+ A `kind:24242` Blossom authorization (BUD-01/BUD-11) and the NIP-92 tag that
88
+ references a blob. Parsing lives here rather than in each app because the
89
+ relay refuses a malformed tag, and a second parser is a second set of refusals
90
+ to get wrong.
91
+
7
92
  ## 0.15.0 — 2026-09-07
8
93
 
9
94
  **Wire behaviour: unchanged.** Nothing about what an app publishes moves, and
package/dist/index.d.ts CHANGED
@@ -46,7 +46,7 @@
46
46
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
47
47
  * pins the two together. It exists so "the upgrade reached the app" can be
48
48
  * checked by grepping a built bundle rather than by trusting a lockfile. */
49
- export declare const PROTOCOL_VERSION = "0.18.0";
49
+ export declare const PROTOCOL_VERSION = "0.19.0";
50
50
  export { type NostrTag, type UnsignedEvent, type SignedEvent, type Profile, type ThreadRef, type ChannelVisibility, type ChannelKind, type MemberRole, type Label, type ResolutionAction, KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE, computeEventId, toNostrSeconds, canonicalChannelName, threadTags, addr, relayAuthUrl, buildProfile, parseProfile, buildCreateChannel, buildDeleteChannel, buildEditChannelMetadata, buildAddMember, buildReaction, buildDeletion, buildEdit, buildMessage, buildResolution, buildFile, buildComponent, buildHighlight, buildUnsignedRelayAuthEvent, } from './events.js';
51
51
  export { type AddressPointer, type EventPointer, encodeNevent, decodeNevent, convertBits, bech32Encode, bech32Decode, encodeNaddr, decodeNaddr, pointerToAddress, addressToPointer, addrToNaddr, naddrToAddr, referenceToPointer, NADDR_RE, findNaddrs, stripNaddrs, encodeNpub, decodeNpub, NOSTR_URI_RE, findNostrUris, } from './nip19.js';
52
52
  export { type AuthEventArgs, TIMESTAMP_TOLERANCE_SECS, normalizeUrl, buildUnsignedAuthEvent, base64, authorizationHeaderFor, authorizationHeader, } from './nip98.js';
@@ -59,5 +59,5 @@ export { type Block, type BlockDocument, type KnownBlockType, KNOWN_BLOCK_TYPES,
59
59
  export { type RenderInline, type RenderBlock, type RenderFormat, type ContentFormat, CONTENT_FORMAT_TAG, BLOCK_DOCUMENT_FORMAT, contentFormatOf, toRenderTree, renderTreeText, standaloneReference, referencesIn, } from './render.js';
60
60
  export { markerTextToBlockDocument, blockDocumentToMarkerText, } from './bridge-content.js';
61
61
  export { type BlockAnchor, BLOCK_ANCHOR_TAG, blockAnchorOf, resolveBlockAnchor, } from './anchors.js';
62
- export { type BlossomVerb, type Imeta, BLOSSOM_AUTH_TTL_SECS, buildBlossomAuth, blossomAuthHeader, imetaTag, imetaOf, type BlobFetchLike, type BlobResponseLike, type FetchedBlob, sha256FromMediaUrl, fetchBlob, sha256Of, uploadBlob, imetaFor, type UploadedBlob, type BlobUploadFetchLike, } from './media.js';
62
+ export { type BlossomVerb, type Imeta, BLOSSOM_AUTH_TTL_SECS, buildBlossomAuth, blossomAuthHeader, imetaTag, imetaOf, type BlobFetchLike, type BlobResponseLike, type FetchedBlob, sha256FromMediaUrl, fetchBlob, sha256Of, uploadBlob, imetaFor, canonicalizeImage, type UploadedBlob, type BlobUploadFetchLike, } from './media.js';
63
63
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACt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AAK,WAAW,EAChB,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,gBAAgB,EAErB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAEjB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY,EAEZ,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,KAAK,aAAa,EAClB,wBAAwB,EACxB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B,KAAK,aAAa,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,KAAK,WAAW,EAChB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@
46
46
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
47
47
  * pins the two together. It exists so "the upgrade reached the app" can be
48
48
  * checked by grepping a built bundle rather than by trusting a lockfile. */
49
- export const PROTOCOL_VERSION = '0.18.0';
49
+ export const PROTOCOL_VERSION = '0.19.0';
50
50
  export {
51
51
  // constants
52
52
  KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE,
@@ -65,5 +65,5 @@ export { KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBloc
65
65
  export { CONTENT_FORMAT_TAG, BLOCK_DOCUMENT_FORMAT, contentFormatOf, toRenderTree, renderTreeText, standaloneReference, referencesIn, } from './render.js';
66
66
  export { markerTextToBlockDocument, blockDocumentToMarkerText, } from './bridge-content.js';
67
67
  export { BLOCK_ANCHOR_TAG, blockAnchorOf, resolveBlockAnchor, } from './anchors.js';
68
- export { BLOSSOM_AUTH_TTL_SECS, buildBlossomAuth, blossomAuthHeader, imetaTag, imetaOf, sha256FromMediaUrl, fetchBlob, sha256Of, uploadBlob, imetaFor, } from './media.js';
68
+ export { BLOSSOM_AUTH_TTL_SECS, buildBlossomAuth, blossomAuthHeader, imetaTag, imetaOf, sha256FromMediaUrl, fetchBlob, sha256Of, uploadBlob, imetaFor, canonicalizeImage, } from './media.js';
69
69
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAA;AAExC,OAAO;AAYL,YAAY;AACZ,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB;AACjB,8CAA8C;AAC9C,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY;AACZ,WAAW;AACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EAGL,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAA;AAEnB,OAAO,EAEL,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,EACtB,MAAM,EACN,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAGL,mBAAmB,EACnB,SAAS,EACT,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EAOL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,EACrB,KAAK,GACN,MAAM,aAAa,CAAA;AAEpB,OAAO,EAOL,cAAc,EACd,UAAU,EACV,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EAIL,0BAA0B,GAC3B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAML,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EAIL,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EAKL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAGL,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EAIP,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,QAAQ,GAGT,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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AAM,oBAAoB,CAAA;AAE3B,OAAO,EAML,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EAIL,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EAKL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAGL,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EAIP,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,iBAAiB,GAGlB,MAAM,YAAY,CAAA"}
package/dist/media.d.ts CHANGED
@@ -239,6 +239,8 @@ export declare function uploadBlob(args: {
239
239
  sign: (unsigned: UnsignedEvent) => Promise<SignedEvent>;
240
240
  pubkey: string;
241
241
  transport?: BlobUploadFetchLike;
242
+ /** Skip {@link canonicalizeImage}. Default `true`; see the note below. */
243
+ canonicalize?: boolean;
242
244
  }): Promise<UploadedBlob>;
243
245
  /**
244
246
  * An uploaded blob as the `imeta` that references it.
@@ -253,4 +255,38 @@ export declare function imetaFor(blob: UploadedBlob, extra?: {
253
255
  alt?: string;
254
256
  filename?: string;
255
257
  }): Imeta;
258
+ /**
259
+ * Strip an image down to what the relay will store — SHA-25.
260
+ *
261
+ * Buzz refuses media carrying metadata, and refuses it *structurally* rather
262
+ * than by scrubbing it: `validate_image_metadata_free` returns
263
+ * `MetadataForbidden` and the whole upload 422s. Its video path names the piece
264
+ * that was missing — "only the canonical primary stream produced by the **client
265
+ * sanitizer** is permitted" — and until this there was no client sanitizer, in
266
+ * either app. An unmodified screenshot was refused, every time, because capture
267
+ * tools write `pHYs` and a `tEXt` software tag.
268
+ *
269
+ * ## Chunks are dropped, never re-encoded
270
+ *
271
+ * The obvious implementation is a canvas round trip, and it does not work: the
272
+ * browser's encoder **adds an ICC profile back**, which the relay refuses
273
+ * identically. Dropping chunks is also lossless — every chunk removed here is
274
+ * ancillary by the format's own definition — where a re-encode would quietly
275
+ * degrade a screenshot to make it acceptable.
276
+ *
277
+ * ## PNG and JPEG only
278
+ *
279
+ * GIF and WebP are accepted by the relay and are **passed through untouched**.
280
+ * Their metadata is not a droppable chunk: WebP records EXIF/ICC/XMP presence
281
+ * in `VP8X` flags that have to stay consistent with the chunks, and GIF hides
282
+ * it in extension blocks. Rewriting either wrongly produces a corrupt image,
283
+ * which is worse than the refusal it replaces — so they keep today's behaviour
284
+ * and the relay's own words. Screenshots are PNG or JPEG, which is the case
285
+ * that was actually costing anything.
286
+ *
287
+ * Throws on malformed input rather than returning the bytes unchanged: an image
288
+ * this cannot parse is one it cannot vouch for, and uploading it anyway would
289
+ * turn a clear failure here into an opaque 422 later.
290
+ */
291
+ export declare function canonicalizeImage(bytes: ArrayBuffer | Uint8Array): Uint8Array;
256
292
  //# sourceMappingURL=media.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAMvE,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE9D,8EAA8E;AAC9E,eA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GAAG,KAAK,CAW/F;AA0JD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,CAW7E"}
package/dist/media.js CHANGED
@@ -215,7 +215,35 @@ export function sha256Of(bytes) {
215
215
  * Throws with the relay's own words. What that means is the caller's to decide.
216
216
  */
217
217
  export async function uploadBlob(args) {
218
- const digest = sha256Of(args.bytes);
218
+ /*
219
+ Canonicalized first, and the hash taken after — SHA-25.
220
+
221
+ The relay refuses media carrying metadata, so an unmodified screenshot 422s:
222
+ capture tools write a `pHYs` and a `tEXt` software tag, and neither is on
223
+ Buzz's rendering allowlist. Doing it here rather than asking each caller to
224
+ remember means there is one place the relay's rule is understood, which is
225
+ the same argument that put `uploadBlob` in this package at all.
226
+
227
+ The order is forced. `x` in the authorization, `x-sha-256` on the PUT and
228
+ `x` in the `imeta` must all be the digest of the bytes the relay actually
229
+ stores, so hashing before stripping would name a blob that never existed.
230
+
231
+ `canonicalize: false` is for a caller that has already done it, or is
232
+ sending something this does not understand and does not want touched. It is
233
+ not a way round a refusal: the relay's answer does not change.
234
+ */
235
+ const canonical = args.canonicalize === false
236
+ ? args.bytes instanceof Uint8Array
237
+ ? args.bytes
238
+ : new Uint8Array(args.bytes)
239
+ : canonicalizeImage(args.bytes);
240
+ /*
241
+ A standalone `ArrayBuffer`, because the transport's `body` is one and a
242
+ `Uint8Array` may be a window onto a larger buffer — sending `.buffer` would
243
+ upload whatever else is in it. One copy, against a network PUT.
244
+ */
245
+ const payload = canonical.buffer.slice(canonical.byteOffset, canonical.byteOffset + canonical.byteLength);
246
+ const digest = sha256Of(payload);
219
247
  const auth = await args.sign(buildBlossomAuth(args.pubkey, Date.now(), {
220
248
  verb: 'upload',
221
249
  sha256: digest,
@@ -230,7 +258,7 @@ export async function uploadBlob(args) {
230
258
  'x-sha-256': digest,
231
259
  'content-type': args.contentType || 'application/octet-stream',
232
260
  },
233
- body: args.bytes,
261
+ body: payload,
234
262
  });
235
263
  const body = await response.text();
236
264
  if (response.status < 200 || response.status >= 300) {
@@ -278,4 +306,206 @@ export function imetaFor(blob, extra) {
278
306
  filename: extra?.filename,
279
307
  };
280
308
  }
309
+ /* ────────────────────────────────────────────────────────────────────────────
310
+ Canonicalizing an image before it is uploaded — SHA-25
311
+ ──────────────────────────────────────────────────────────────────────────── */
312
+ /**
313
+ * PNG ancillary chunks the relay treats as rendering rather than metadata.
314
+ *
315
+ * Exactly `known_rendering` in `buzz-media`'s `validate_png_metadata_free`.
316
+ * **`pHYs` is not on it**, deliberately: the relay's comment calls arbitrary
317
+ * values an identity channel, and nearly every screen-capture tool writes one.
318
+ * That single omission is why an ordinary screenshot is refused.
319
+ */
320
+ const PNG_RENDERING_CHUNKS = new Set([
321
+ 'cHRM', 'gAMA', 'sBIT', 'sRGB', 'bKGD', 'hIST', 'tRNS', 'sPLT', 'acTL', 'fcTL', 'fdAT',
322
+ ]);
323
+ /**
324
+ * `tEXt` keywords the relay exempts — Buzz agent/team snapshot manifests.
325
+ *
326
+ * A deliberate product payload rather than metadata, so it is kept. Stripping
327
+ * it would leave a `.agent.png` that still looks like an image and silently no
328
+ * longer carries the thing it exists to carry, which is worse than a refusal.
329
+ */
330
+ const PNG_SNAPSHOT_KEYWORDS = ['buzz_agent_snapshot', 'buzz_team_snapshot'];
331
+ const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
332
+ /** A `tEXt` payload is `<keyword>\0<text>`. Only an allowlisted keyword survives. */
333
+ function isSnapshotText(payload) {
334
+ return PNG_SNAPSHOT_KEYWORDS.some((keyword) => {
335
+ if (payload.length <= keyword.length || payload[keyword.length] !== 0)
336
+ return false;
337
+ for (let i = 0; i < keyword.length; i++)
338
+ if (payload[i] !== keyword.charCodeAt(i))
339
+ return false;
340
+ return true;
341
+ });
342
+ }
343
+ function canonicalizePng(bytes) {
344
+ const kept = [new Uint8Array(PNG_SIGNATURE)];
345
+ let i = PNG_SIGNATURE.length;
346
+ let sawSnapshot = false;
347
+ let sawIend = false;
348
+ while (i < bytes.length) {
349
+ if (i + 12 > bytes.length)
350
+ throw new Error('malformed PNG: truncated chunk header');
351
+ const length = (bytes[i] << 24) | (bytes[i + 1] << 16) | (bytes[i + 2] << 8) | bytes[i + 3];
352
+ const type = String.fromCharCode(bytes[i + 4], bytes[i + 5], bytes[i + 6], bytes[i + 7]);
353
+ const end = i + 12 + length;
354
+ if (length < 0 || end > bytes.length)
355
+ throw new Error(`malformed PNG: truncated ${type} chunk`);
356
+ // Bit 5 of the first byte: lowercase means ancillary, and ancillary means
357
+ // droppable. Critical chunks are the image and are never touched.
358
+ const ancillary = (bytes[i + 4] & 0x20) !== 0;
359
+ let keep = !ancillary || PNG_RENDERING_CHUNKS.has(type);
360
+ if (type === 'tEXt') {
361
+ // One snapshot manifest survives; a second is a metadata channel again.
362
+ keep = !sawSnapshot && isSnapshotText(bytes.subarray(i + 8, end - 4));
363
+ if (keep)
364
+ sawSnapshot = true;
365
+ }
366
+ if (keep)
367
+ kept.push(bytes.subarray(i, end));
368
+ i = end;
369
+ if (type === 'IEND') {
370
+ sawIend = true;
371
+ break; // Anything after IEND is trailing data, which the relay refuses.
372
+ }
373
+ }
374
+ if (!sawIend)
375
+ throw new Error('malformed PNG: no IEND');
376
+ return concatBytes(kept);
377
+ }
378
+ /**
379
+ * A JPEG segment the relay accepts.
380
+ *
381
+ * `APP0` and `APP14` are allowed only in their canonical colour-header forms —
382
+ * accepting an arbitrary payload under those markers would leave exactly the
383
+ * side channel the ban is for. `APP1`–`APP13`, `APP15` and `COM` are refused
384
+ * outright, and `APP1` is where EXIF lives.
385
+ */
386
+ function keepJpegSegment(marker, payload) {
387
+ if (marker === 0xe0) {
388
+ const jfif = payload.length >= 14 && String.fromCharCode(...payload.subarray(0, 5)) === 'JFIF\0';
389
+ return jfif && payload.length === 14 + 3 * payload[12] * payload[13];
390
+ }
391
+ if (marker === 0xee) {
392
+ return payload.length === 12 && String.fromCharCode(...payload.subarray(0, 5)) === 'Adobe';
393
+ }
394
+ if ((marker >= 0xe1 && marker <= 0xed) || marker === 0xef || marker === 0xfe)
395
+ return false;
396
+ return true;
397
+ }
398
+ function canonicalizeJpeg(bytes) {
399
+ if (bytes[0] !== 0xff || bytes[1] !== 0xd8)
400
+ throw new Error('malformed JPEG: no SOI');
401
+ const kept = [new Uint8Array([0xff, 0xd8])];
402
+ let i = 2;
403
+ let inScan = false;
404
+ while (i < bytes.length) {
405
+ if (bytes[i] !== 0xff) {
406
+ // Entropy-coded data between SOS and the next marker. Copied verbatim —
407
+ // it is the image.
408
+ if (!inScan)
409
+ throw new Error('malformed JPEG: expected a marker');
410
+ const start = i;
411
+ while (i < bytes.length && bytes[i] !== 0xff)
412
+ i++;
413
+ kept.push(bytes.subarray(start, i));
414
+ continue;
415
+ }
416
+ // Fill bytes: any run of 0xFF before a marker. One is emitted.
417
+ while (i < bytes.length && bytes[i] === 0xff)
418
+ i++;
419
+ if (i >= bytes.length)
420
+ throw new Error('malformed JPEG: marker ran off the end');
421
+ const marker = bytes[i++];
422
+ // 0x00 is a stuffed byte inside the scan, not a marker; RSTn and TEM are
423
+ // standalone. All three are part of the image and carry no payload.
424
+ if ((inScan && marker === 0x00) || (marker >= 0xd0 && marker <= 0xd7) || marker === 0x01) {
425
+ kept.push(new Uint8Array([0xff, marker]));
426
+ continue;
427
+ }
428
+ if (marker === 0xd9) {
429
+ // EOI. Stop here rather than copying on: the relay refuses trailing
430
+ // bytes after EOI, and that is where a stripped-EXIF editor leaves them.
431
+ kept.push(new Uint8Array([0xff, 0xd9]));
432
+ return concatBytes(kept);
433
+ }
434
+ if (marker === 0xd8)
435
+ throw new Error('malformed JPEG: a second SOI');
436
+ if (i + 2 > bytes.length)
437
+ throw new Error('malformed JPEG: truncated segment length');
438
+ const length = (bytes[i] << 8) | bytes[i + 1];
439
+ if (length < 2)
440
+ throw new Error('malformed JPEG: bad segment length');
441
+ const end = i + length;
442
+ if (end > bytes.length)
443
+ throw new Error('malformed JPEG: truncated segment');
444
+ if (keepJpegSegment(marker, bytes.subarray(i + 2, end))) {
445
+ kept.push(new Uint8Array([0xff, marker]), bytes.subarray(i, end));
446
+ }
447
+ i = end;
448
+ inScan = marker === 0xda;
449
+ }
450
+ throw new Error('malformed JPEG: no EOI');
451
+ }
452
+ function concatBytes(parts) {
453
+ let size = 0;
454
+ for (const part of parts)
455
+ size += part.length;
456
+ const out = new Uint8Array(size);
457
+ let at = 0;
458
+ for (const part of parts) {
459
+ out.set(part, at);
460
+ at += part.length;
461
+ }
462
+ return out;
463
+ }
464
+ /**
465
+ * Strip an image down to what the relay will store — SHA-25.
466
+ *
467
+ * Buzz refuses media carrying metadata, and refuses it *structurally* rather
468
+ * than by scrubbing it: `validate_image_metadata_free` returns
469
+ * `MetadataForbidden` and the whole upload 422s. Its video path names the piece
470
+ * that was missing — "only the canonical primary stream produced by the **client
471
+ * sanitizer** is permitted" — and until this there was no client sanitizer, in
472
+ * either app. An unmodified screenshot was refused, every time, because capture
473
+ * tools write `pHYs` and a `tEXt` software tag.
474
+ *
475
+ * ## Chunks are dropped, never re-encoded
476
+ *
477
+ * The obvious implementation is a canvas round trip, and it does not work: the
478
+ * browser's encoder **adds an ICC profile back**, which the relay refuses
479
+ * identically. Dropping chunks is also lossless — every chunk removed here is
480
+ * ancillary by the format's own definition — where a re-encode would quietly
481
+ * degrade a screenshot to make it acceptable.
482
+ *
483
+ * ## PNG and JPEG only
484
+ *
485
+ * GIF and WebP are accepted by the relay and are **passed through untouched**.
486
+ * Their metadata is not a droppable chunk: WebP records EXIF/ICC/XMP presence
487
+ * in `VP8X` flags that have to stay consistent with the chunks, and GIF hides
488
+ * it in extension blocks. Rewriting either wrongly produces a corrupt image,
489
+ * which is worse than the refusal it replaces — so they keep today's behaviour
490
+ * and the relay's own words. Screenshots are PNG or JPEG, which is the case
491
+ * that was actually costing anything.
492
+ *
493
+ * Throws on malformed input rather than returning the bytes unchanged: an image
494
+ * this cannot parse is one it cannot vouch for, and uploading it anyway would
495
+ * turn a clear failure here into an opaque 422 later.
496
+ */
497
+ export function canonicalizeImage(bytes) {
498
+ const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
499
+ /*
500
+ Sniffed from the bytes, with no `contentType` argument at all. The MIME a
501
+ caller has is the browser's guess from a file extension — a `.png` that is
502
+ really a JPEG is ordinary — and this has the actual bytes in hand. Taking
503
+ the parameter would invite trusting it.
504
+ */
505
+ if (PNG_SIGNATURE.every((byte, at) => view[at] === byte))
506
+ return canonicalizePng(view);
507
+ if (view[0] === 0xff && view[1] === 0xd8)
508
+ return canonicalizeJpeg(view);
509
+ return view;
510
+ }
281
511
  //# sourceMappingURL=media.js.map
package/dist/media.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAKhD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAA;AAExC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,WAAmB,EACnB,IAUC;IAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;IACD,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAA;IAC7C,MAAM,IAAI,GAAe;QACvB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC;QAChB,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AI,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;QAAE,OAAO,eAAe,CAAC,IAAI,CAAC,CAAA;IACtF,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;QAAE,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAA;IACvE,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/protocol",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "The Estiva wire format: Buzz-shaped Nostr event builders, NIP-01 ids, NIP-19 naddr, NIP-98 HTTP auth, and the relay clients. Speaks the protocol; interprets nothing.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -47,7 +47,7 @@
47
47
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
48
48
  * pins the two together. It exists so "the upgrade reached the app" can be
49
49
  * checked by grepping a built bundle rather than by trusting a lockfile. */
50
- export const PROTOCOL_VERSION = '0.18.0'
50
+ export const PROTOCOL_VERSION = '0.19.0'
51
51
 
52
52
  export {
53
53
  // types
@@ -243,6 +243,7 @@ export {
243
243
  sha256Of,
244
244
  uploadBlob,
245
245
  imetaFor,
246
+ canonicalizeImage,
246
247
  type UploadedBlob,
247
248
  type BlobUploadFetchLike,
248
249
  } from './media.js'
package/src/media.ts CHANGED
@@ -355,8 +355,42 @@ export async function uploadBlob(args: {
355
355
  sign: (unsigned: UnsignedEvent) => Promise<SignedEvent>
356
356
  pubkey: string
357
357
  transport?: BlobUploadFetchLike
358
+ /** Skip {@link canonicalizeImage}. Default `true`; see the note below. */
359
+ canonicalize?: boolean
358
360
  }): Promise<UploadedBlob> {
359
- const digest = sha256Of(args.bytes)
361
+ /*
362
+ Canonicalized first, and the hash taken after — SHA-25.
363
+
364
+ The relay refuses media carrying metadata, so an unmodified screenshot 422s:
365
+ capture tools write a `pHYs` and a `tEXt` software tag, and neither is on
366
+ Buzz's rendering allowlist. Doing it here rather than asking each caller to
367
+ remember means there is one place the relay's rule is understood, which is
368
+ the same argument that put `uploadBlob` in this package at all.
369
+
370
+ The order is forced. `x` in the authorization, `x-sha-256` on the PUT and
371
+ `x` in the `imeta` must all be the digest of the bytes the relay actually
372
+ stores, so hashing before stripping would name a blob that never existed.
373
+
374
+ `canonicalize: false` is for a caller that has already done it, or is
375
+ sending something this does not understand and does not want touched. It is
376
+ not a way round a refusal: the relay's answer does not change.
377
+ */
378
+ const canonical =
379
+ args.canonicalize === false
380
+ ? args.bytes instanceof Uint8Array
381
+ ? args.bytes
382
+ : new Uint8Array(args.bytes)
383
+ : canonicalizeImage(args.bytes)
384
+ /*
385
+ A standalone `ArrayBuffer`, because the transport's `body` is one and a
386
+ `Uint8Array` may be a window onto a larger buffer — sending `.buffer` would
387
+ upload whatever else is in it. One copy, against a network PUT.
388
+ */
389
+ const payload = canonical.buffer.slice(
390
+ canonical.byteOffset,
391
+ canonical.byteOffset + canonical.byteLength,
392
+ ) as ArrayBuffer
393
+ const digest = sha256Of(payload)
360
394
  const auth = await args.sign(
361
395
  buildBlossomAuth(args.pubkey, Date.now(), {
362
396
  verb: 'upload',
@@ -374,7 +408,7 @@ export async function uploadBlob(args: {
374
408
  'x-sha-256': digest,
375
409
  'content-type': args.contentType || 'application/octet-stream',
376
410
  },
377
- body: args.bytes,
411
+ body: payload,
378
412
  })
379
413
 
380
414
  const body = await response.text()
@@ -423,3 +457,201 @@ export function imetaFor(blob: UploadedBlob, extra?: { alt?: string; filename?:
423
457
  filename: extra?.filename,
424
458
  }
425
459
  }
460
+
461
+ /* ────────────────────────────────────────────────────────────────────────────
462
+ Canonicalizing an image before it is uploaded — SHA-25
463
+ ──────────────────────────────────────────────────────────────────────────── */
464
+
465
+ /**
466
+ * PNG ancillary chunks the relay treats as rendering rather than metadata.
467
+ *
468
+ * Exactly `known_rendering` in `buzz-media`'s `validate_png_metadata_free`.
469
+ * **`pHYs` is not on it**, deliberately: the relay's comment calls arbitrary
470
+ * values an identity channel, and nearly every screen-capture tool writes one.
471
+ * That single omission is why an ordinary screenshot is refused.
472
+ */
473
+ const PNG_RENDERING_CHUNKS: ReadonlySet<string> = new Set([
474
+ 'cHRM', 'gAMA', 'sBIT', 'sRGB', 'bKGD', 'hIST', 'tRNS', 'sPLT', 'acTL', 'fcTL', 'fdAT',
475
+ ])
476
+
477
+ /**
478
+ * `tEXt` keywords the relay exempts — Buzz agent/team snapshot manifests.
479
+ *
480
+ * A deliberate product payload rather than metadata, so it is kept. Stripping
481
+ * it would leave a `.agent.png` that still looks like an image and silently no
482
+ * longer carries the thing it exists to carry, which is worse than a refusal.
483
+ */
484
+ const PNG_SNAPSHOT_KEYWORDS = ['buzz_agent_snapshot', 'buzz_team_snapshot'] as const
485
+
486
+ const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]
487
+
488
+ /** A `tEXt` payload is `<keyword>\0<text>`. Only an allowlisted keyword survives. */
489
+ function isSnapshotText(payload: Uint8Array): boolean {
490
+ return PNG_SNAPSHOT_KEYWORDS.some((keyword) => {
491
+ if (payload.length <= keyword.length || payload[keyword.length] !== 0) return false
492
+ for (let i = 0; i < keyword.length; i++) if (payload[i] !== keyword.charCodeAt(i)) return false
493
+ return true
494
+ })
495
+ }
496
+
497
+ function canonicalizePng(bytes: Uint8Array): Uint8Array {
498
+ const kept: Uint8Array[] = [new Uint8Array(PNG_SIGNATURE)]
499
+ let i = PNG_SIGNATURE.length
500
+ let sawSnapshot = false
501
+ let sawIend = false
502
+
503
+ while (i < bytes.length) {
504
+ if (i + 12 > bytes.length) throw new Error('malformed PNG: truncated chunk header')
505
+ const length = (bytes[i] << 24) | (bytes[i + 1] << 16) | (bytes[i + 2] << 8) | bytes[i + 3]
506
+ const type = String.fromCharCode(bytes[i + 4], bytes[i + 5], bytes[i + 6], bytes[i + 7])
507
+ const end = i + 12 + length
508
+ if (length < 0 || end > bytes.length) throw new Error(`malformed PNG: truncated ${type} chunk`)
509
+
510
+ // Bit 5 of the first byte: lowercase means ancillary, and ancillary means
511
+ // droppable. Critical chunks are the image and are never touched.
512
+ const ancillary = (bytes[i + 4] & 0x20) !== 0
513
+ let keep = !ancillary || PNG_RENDERING_CHUNKS.has(type)
514
+ if (type === 'tEXt') {
515
+ // One snapshot manifest survives; a second is a metadata channel again.
516
+ keep = !sawSnapshot && isSnapshotText(bytes.subarray(i + 8, end - 4))
517
+ if (keep) sawSnapshot = true
518
+ }
519
+ if (keep) kept.push(bytes.subarray(i, end))
520
+
521
+ i = end
522
+ if (type === 'IEND') {
523
+ sawIend = true
524
+ break // Anything after IEND is trailing data, which the relay refuses.
525
+ }
526
+ }
527
+ if (!sawIend) throw new Error('malformed PNG: no IEND')
528
+ return concatBytes(kept)
529
+ }
530
+
531
+ /**
532
+ * A JPEG segment the relay accepts.
533
+ *
534
+ * `APP0` and `APP14` are allowed only in their canonical colour-header forms —
535
+ * accepting an arbitrary payload under those markers would leave exactly the
536
+ * side channel the ban is for. `APP1`–`APP13`, `APP15` and `COM` are refused
537
+ * outright, and `APP1` is where EXIF lives.
538
+ */
539
+ function keepJpegSegment(marker: number, payload: Uint8Array): boolean {
540
+ if (marker === 0xe0) {
541
+ const jfif = payload.length >= 14 && String.fromCharCode(...payload.subarray(0, 5)) === 'JFIF\0'
542
+ return jfif && payload.length === 14 + 3 * payload[12] * payload[13]
543
+ }
544
+ if (marker === 0xee) {
545
+ return payload.length === 12 && String.fromCharCode(...payload.subarray(0, 5)) === 'Adobe'
546
+ }
547
+ if ((marker >= 0xe1 && marker <= 0xed) || marker === 0xef || marker === 0xfe) return false
548
+ return true
549
+ }
550
+
551
+ function canonicalizeJpeg(bytes: Uint8Array): Uint8Array {
552
+ if (bytes[0] !== 0xff || bytes[1] !== 0xd8) throw new Error('malformed JPEG: no SOI')
553
+ const kept: Uint8Array[] = [new Uint8Array([0xff, 0xd8])]
554
+ let i = 2
555
+ let inScan = false
556
+
557
+ while (i < bytes.length) {
558
+ if (bytes[i] !== 0xff) {
559
+ // Entropy-coded data between SOS and the next marker. Copied verbatim —
560
+ // it is the image.
561
+ if (!inScan) throw new Error('malformed JPEG: expected a marker')
562
+ const start = i
563
+ while (i < bytes.length && bytes[i] !== 0xff) i++
564
+ kept.push(bytes.subarray(start, i))
565
+ continue
566
+ }
567
+ // Fill bytes: any run of 0xFF before a marker. One is emitted.
568
+ while (i < bytes.length && bytes[i] === 0xff) i++
569
+ if (i >= bytes.length) throw new Error('malformed JPEG: marker ran off the end')
570
+ const marker = bytes[i++]
571
+
572
+ // 0x00 is a stuffed byte inside the scan, not a marker; RSTn and TEM are
573
+ // standalone. All three are part of the image and carry no payload.
574
+ if ((inScan && marker === 0x00) || (marker >= 0xd0 && marker <= 0xd7) || marker === 0x01) {
575
+ kept.push(new Uint8Array([0xff, marker]))
576
+ continue
577
+ }
578
+ if (marker === 0xd9) {
579
+ // EOI. Stop here rather than copying on: the relay refuses trailing
580
+ // bytes after EOI, and that is where a stripped-EXIF editor leaves them.
581
+ kept.push(new Uint8Array([0xff, 0xd9]))
582
+ return concatBytes(kept)
583
+ }
584
+ if (marker === 0xd8) throw new Error('malformed JPEG: a second SOI')
585
+
586
+ if (i + 2 > bytes.length) throw new Error('malformed JPEG: truncated segment length')
587
+ const length = (bytes[i] << 8) | bytes[i + 1]
588
+ if (length < 2) throw new Error('malformed JPEG: bad segment length')
589
+ const end = i + length
590
+ if (end > bytes.length) throw new Error('malformed JPEG: truncated segment')
591
+
592
+ if (keepJpegSegment(marker, bytes.subarray(i + 2, end))) {
593
+ kept.push(new Uint8Array([0xff, marker]), bytes.subarray(i, end))
594
+ }
595
+ i = end
596
+ inScan = marker === 0xda
597
+ }
598
+ throw new Error('malformed JPEG: no EOI')
599
+ }
600
+
601
+ function concatBytes(parts: readonly Uint8Array[]): Uint8Array {
602
+ let size = 0
603
+ for (const part of parts) size += part.length
604
+ const out = new Uint8Array(size)
605
+ let at = 0
606
+ for (const part of parts) {
607
+ out.set(part, at)
608
+ at += part.length
609
+ }
610
+ return out
611
+ }
612
+
613
+ /**
614
+ * Strip an image down to what the relay will store — SHA-25.
615
+ *
616
+ * Buzz refuses media carrying metadata, and refuses it *structurally* rather
617
+ * than by scrubbing it: `validate_image_metadata_free` returns
618
+ * `MetadataForbidden` and the whole upload 422s. Its video path names the piece
619
+ * that was missing — "only the canonical primary stream produced by the **client
620
+ * sanitizer** is permitted" — and until this there was no client sanitizer, in
621
+ * either app. An unmodified screenshot was refused, every time, because capture
622
+ * tools write `pHYs` and a `tEXt` software tag.
623
+ *
624
+ * ## Chunks are dropped, never re-encoded
625
+ *
626
+ * The obvious implementation is a canvas round trip, and it does not work: the
627
+ * browser's encoder **adds an ICC profile back**, which the relay refuses
628
+ * identically. Dropping chunks is also lossless — every chunk removed here is
629
+ * ancillary by the format's own definition — where a re-encode would quietly
630
+ * degrade a screenshot to make it acceptable.
631
+ *
632
+ * ## PNG and JPEG only
633
+ *
634
+ * GIF and WebP are accepted by the relay and are **passed through untouched**.
635
+ * Their metadata is not a droppable chunk: WebP records EXIF/ICC/XMP presence
636
+ * in `VP8X` flags that have to stay consistent with the chunks, and GIF hides
637
+ * it in extension blocks. Rewriting either wrongly produces a corrupt image,
638
+ * which is worse than the refusal it replaces — so they keep today's behaviour
639
+ * and the relay's own words. Screenshots are PNG or JPEG, which is the case
640
+ * that was actually costing anything.
641
+ *
642
+ * Throws on malformed input rather than returning the bytes unchanged: an image
643
+ * this cannot parse is one it cannot vouch for, and uploading it anyway would
644
+ * turn a clear failure here into an opaque 422 later.
645
+ */
646
+ export function canonicalizeImage(bytes: ArrayBuffer | Uint8Array): Uint8Array {
647
+ const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes)
648
+ /*
649
+ Sniffed from the bytes, with no `contentType` argument at all. The MIME a
650
+ caller has is the browser's guess from a file extension — a `.png` that is
651
+ really a JPEG is ordinary — and this has the actual bytes in hand. Taking
652
+ the parameter would invite trusting it.
653
+ */
654
+ if (PNG_SIGNATURE.every((byte, at) => view[at] === byte)) return canonicalizePng(view)
655
+ if (view[0] === 0xff && view[1] === 0xd8) return canonicalizeJpeg(view)
656
+ return view
657
+ }