Skip to content

feat: add network icons keyed by CAIP-2 and upload them to S3 - #2076

Open
blurpesec wants to merge 8 commits into
masterfrom
feat/network-icons
Open

blurpesec wants to merge 8 commits into
masterfrom
feat/network-icons

Conversation

@blurpesec

@blurpesec blurpesec commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a network-icons/ section: one SVG per network, named by its CAIP-2 chain ID (network-icons/eip155:1.svg, network-icons/bip122:000000000019d6689c085ae165831e93.svg). On merge to master, the icons are uploaded to the static cache bucket at:

https://static.cx.metamask.io/api/v2/networkIcons/{namespace}/{reference}.svg

This uses the same CAIP path layout as api/v2/tokenIcons/assets/....

Icons

All 50 network logos that token-api serves from src/assets/networkLogos/. Each file name was mapped to a chain ID using mm-config-registry chain configs, @codefi/metafi-common network configs, and, for Eden, the token-api commit that added it (eip155:714). One ID per logo; testnets that share a mainnet logo are not duplicated.

eip155:50 (XDC): removed Adobe Illustrator export data (DOCTYPE/ENTITY declarations, <switch>/<foreignObject>, i:pgf blob). The file went from 58KB to 1.5KB and renders identically.

All icons are resized to 256×256 (root width/height). The artwork scales through the viewBox. Non-square viewBoxes (arbitrum, cronos, linea, unichain, pharos, harmony, matchain, sonic) are padded to a square so the art stays centered instead of stretching. The two icons without a viewBox (eip155:166 omni, eip155:11297108109 palm) get one taken from their original width/height.

Validation

scripts/network-icons.js verify runs as part of yarn test via test/network-icons.js. It checks that each file:

  • is .svg and named by a valid CAIP-2 chain ID
  • has an <svg> root with the SVG xmlns
  • is width="256" height="256" with a square viewBox
  • is 100KB or smaller
  • contains no <script>, <foreignObject>, <image>, inline event handlers, DOCTYPE/ENTITY, javascript: URLs, or non-#fragment href/url() references

These files are served from a MetaMask origin, so the checks are deliberately strict.

Upload

The workflow in update-caip-map.yml gets a new upload-network-icons job that:

  • reuses the existing generate-uniswap-list environment and S3_ROLE_ARN
  • stages the icons as <namespace>/<reference>.svg, validating again first
  • runs aws s3 sync with Content-Type: image/svg+xml and Cache-Control: max-age=3600

The sync only adds or replaces files. Removing an icon here does not delete it from S3.

network-icons is also added to the npm package files.

⚠️ Dependency

The github-contract-metadata IAM role can currently write only metamask-uniswap-tokenlist.json. The api/v2/networkIcons/* grant must be applied in va-mmcx-api-platform-infra (prd) before this merges: consensys-vertical-apps/va-mmcx-api-platform-infra#77. Otherwise upload-network-icons fails with AccessDenied. The token list job is unaffected either way.

Test plan

  • yarn test passes, including the new test/network-icons.js
  • The validator rejects the original XDC SVG, an SVG with onload and an external <image>, a .png, and a non-CAIP file name
  • Before/after contact sheets render identically, with no clipping or distortion after the resize
  • node scripts/network-icons.js stage <dir> produces 50 files under eip155/ and bip122/
  • After merge: curl -I https://static.cx.metamask.io/api/v2/networkIcons/eip155/1.svg returns 200 with image/svg+xml

🤖 Generated with Claude Code

Adds network-icons/<caip2>.svg for all 50 network logos served by
token-api (src/assets/networkLogos), validated by
scripts/network-icons.js (SVG only, CAIP-2 file names, no scripts,
event handlers, foreignObject, DOCTYPE/ENTITY, embedded rasters or
external references) and uploaded on merge to master to
static.cx.metamask.io/api/v2/networkIcons/<namespace>/<reference>.svg.

xdc.svg (eip155:50) is stripped of Adobe Illustrator pgf/foreignObject
data (58KB -> 1.5KB); it renders identically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blurpesec
blurpesec requested review from a team and MRabenda as code owners November 12, 2026 17:39
Comment thread scripts/network-icons.js Fixed
blurpesec and others added 3 commits November 12, 2026 09:52
Sets every root <svg> to width="256" height="256". Artwork is scaled via
the viewBox; non-square viewBoxes are padded to a square so the art stays
centered instead of stretching. Adds a viewBox to the two icons that had
none (eip155:166, eip155:11297108109). Validation now enforces 256x256
with a square viewBox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each environment has its own static bucket in its own AWS account
(dev-static / uat-static / static.cx.metamask.io), so the upload job is
now a matrix over the three, assuming the per-env role from
S3_ROLE_ARN_DEV / S3_ROLE_ARN_UAT / S3_ROLE_ARN. An env whose variable
is unset is skipped with a warning; fail-fast is off so one env failing
doesn't block the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit 61d9d93. Keep the network icons upload prd-only,
matching the existing token list upload; nothing in this repo pushes to
the dev/uat static buckets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
maxime-oe
maxime-oe previously approved these changes Nov 12, 2026
MRabenda
MRabenda previously approved these changes Nov 20, 2026
@MRabenda

Copy link
Copy Markdown
Collaborator

Can you pls resolve conflicts?

@maxime-oe
maxime-oe dismissed stale reviews from MRabenda and themself via 57395a4 November 27, 2026 14:19
Resolves CodeQL js/file-system-race by deriving size from the same buffer
that is validated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@blurpesec
blurpesec requested a review from a team November 27, 2026 16:58

This branch has not been deployed

No deployments
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.

4 participants