Skip to content

feat(engine): parse_multipart builtin + crypto ec_public_jwk/base64url_decode - #39

Merged
deblasis merged 2 commits into
mainfrom
feat/multipart-builtin
Aug 14, 2026
Merged

feat(engine): parse_multipart builtin + crypto ec_public_jwk/base64url_decode#39
deblasis merged 2 commits into
mainfrom
feat/multipart-builtin

Conversation

@deblasis

Copy link
Copy Markdown
Contributor

Why

The 2026-08 fidelity sweep (91 adapters, 603 gaps) flagged multipart/form-data as an explicit engine blocker in 6 adapters (onfido, jumio, whatsapp, cloudflare, drive, pinata): document/photo/binary uploads fell back to JSON shims or discarded bytes. Also adds the two small crypto gaps needed by the ES256 auth adapters: EC JWK export and base64url decode.

What

  • parse_multipart(content_type, body) — pure Starlark builtin (like paginate), returns (parts, err); each part is {name, filename, content_type, data} with data carrying raw bytes (Starlark strings are byte strings → binary round-trips via store_blob). err as a value lets handlers answer 400 instead of surfacing 500.
  • crypto.ec_public_jwk(pub_pem){kty, crv, x, y} (base64url, fixed 32-byte coords) — ES256 JWKS counterpart to rsa_public_jwk (Sign in with Apple, APNs, Search Ads).
  • crypto.base64url_decode(s) — inverse of base64url_encode, padding-tolerant (JWT segments).
  • whatsapp-style exemplar wiring: media upload accepts the real Cloud API multipart shape; metadata reports the upload's real sha256/file_size; new GET /v21.0/{media_id}/content serves the stored bytes byte-exact at the original mime type (the metadata url points at it, so SDK download flows work). Legacy JSON upload path preserved.

Tests

  • TestParseMultipart{FieldsAndFile,EmptyBody,BadContentType} — runtime builtin unit tests incl. binary round-trip.
  • TestECPublicJWK, TestBase64URLDecodeRoundTrip — crypto.
  • TestWhatsAppStyleMultipartMedia — end-to-end: multipart upload → metadata reflects real bytes → byte-exact download.
  • Full suite go test ./... green; gofmt/vet clean; stunt adapter lint clean.

Closes stunt-l3l (engine part; onfido/jumio/cloudflare/drive/pinata wiring follows in their adapter slices).

…l_decode

parse_multipart(content_type, body) decodes multipart/form-data in handlers,
returning (parts, err) with parts as {name, filename, content_type, data};
binary data round-trips via store_blob. whatsapp-style media upload now
accepts the real Cloud API multipart shape with real sha256/file_size and a
byte-exact GET /v21.0/{media_id}/content download endpoint.

crypto.ec_public_jwk serves ES256 JWKS params {kty,crv,x,y}; base64url_decode
inverts base64url_encode for reading JWT segments.
…tion

- parse_multipart uses NextRawPart so a Content-Transfer-Encoding header
  cannot silently transform part bytes (raw-bytes contract).
- whatsapp upload requires messaging_product=whatsapp, 400 with Meta #100
  otherwise — the most common real Cloud API client mistake.
- mime resolution: a generic octet-stream part Content-Type (curl/Go SDK
  default) no longer masks the real type; prefer mime-like type field, then
  filename extension. Legacy JSON path honors its type field again.
@deblasis
deblasis merged commit 53f3302 into main Aug 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant