From 072b103dd437ad80dac71026c36a92d0eed7dc2b Mon Sep 17 00:00:00 2001 From: Johanna Fransson Date: Fri, 22 Nov 2024 14:33:39 +0700 Subject: [PATCH 1/4] feat: measure public gateways 29 seconds, add more validation to profiles & images --- .cache/cache.db | Bin 3338240 -> 3371008 bytes config.yaml | 207 ++++++++++++++++++------------------ pnpm-lock.yaml | 4 +- src/event_handlers/hubV2.ts | 12 +-- src/ipfs.ts | 133 +++++++++++++++++++++++ src/utils.ts | 34 +----- 6 files changed, 247 insertions(+), 143 deletions(-) create mode 100644 src/ipfs.ts diff --git a/.cache/cache.db b/.cache/cache.db index ddee8407129897c5e463dc91d2e52b2e994cf68f..23d36a9f6e8dcf1b8f4bca8bd826b7e0308dac23 100644 GIT binary patch delta 11699 zcmbt)NzC+kepY{9&(=NN(>)}R%#vZ~nJg2Bc;6xcah1z+ZE$`*MY$vEP zBh--+iAAIEg+xJ#lmp^`6b(sBoCrsv2)J-TNORx_QjicAB*Ope4q>^b>V4i)z4q&J z{g>bGd7j_zm%jf;FMjF!fBfR_f92Efyz$1H^gsCe-+J-R@BRGmzW2FbeAj>D^$my6%| z62O-Mz5?)7fFA+)8o*x#_&UH}1NZ>o8vx$~_)&l#1Nd=(p8)t4z)u1|06zur*8zSS z00uw+(2t7W!G7a!e(vRGfAfuZUVQd9KlG&kDW5$MX%u? ztSmdU)|wEM{o6P5N$8M6N3C zujawo`G|P{uPu40Jyps5FzT~`r;jW;R?h6`g71*L_LU38b9&gZRvSJb zxQz0XPhV!-WuyXisshdXpn-$~o$D3*L`RqMz5W3o%J7y1WpKS3cdr=*)Z8Y{mqE7CR%RkYGjal6Hb?)e_(9i(K6I z>2%C->e#{{lwM)kQdfb^1WyW`GEJ^BoMv~U4m^T`ZHuyHhm?=^Y;z{UeROPd5;qHM zA~&rTsp~5OesJ+JJ;grPdJfT0GBW1?i=CObvyk6ER1XO_&ZYWN9Kvj%O6JyNKE}au zd`4#TDD#G)PE0!F#~j(?))Bn^-%n*_dv{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>B1j+AvZ3HtG1`e^2W)>j2{=ZuD+ zw(g$nW56G3A)IF5W(ygHNcjFZcdwlpILQ<@8_ubJ14fT-Pi*KC%JGhbHs%j@ARtAP z)S$})MC>Nlc96v`3`p(=Umo}(JtapJ!iic5og-_x@d~>4KuSR)KqQ<%N*NC0ELa?I&)Ej8@hi&?FjUsHo*Iuqmhxt$UKpH23)-9&pJ;(^9jxS==XjX`;9k0iog8c LZ+!aYo5cSDP^KKx delta 435 zcmWm8KS&!<90&0CyWAxvd6&DWHNBpHPGi(qO`eLY6^A%Fikmou5FMO#i4tDGMdi>J z8ju7!xJuBQbt;Oei(4U`+QCAHZXNXN@L9g!@9?d3?y1tbqa)XdG8W1odtWGevHs2K z+A)jlJ@L8yubu3ek+xY{Gup+0hGwDA6VJq$c57W(n{C_MP58IJQWRE$r&DwObFNM| z>POQl7~iqIR;w;A>0)XFUfK7kAU zFaU!v1Re~-2&7>YGB5_?FacSZgwHSq(~yHa2$%`Vt=X>&VdBI%1 { + console.log("Coming inside nameReg here: e", event.params.metadataDigest); let profileMetadata: { cidV0: string; data: Profile | null } | null = null; try { profileMetadata = await getProfileMetadataFromIpfs( event.params.metadataDigest ); - } catch (_) {} + } catch (_) { + console.log("Error in nameReg fetching Ipfs", _); + } const avatar = await context.Avatar.get(event.params.avatar); diff --git a/src/ipfs.ts b/src/ipfs.ts new file mode 100644 index 0000000..26edf45 --- /dev/null +++ b/src/ipfs.ts @@ -0,0 +1,133 @@ +/* export async function getProfileMetadataFromIpfs( + metadataDigest: string +): Promise<{ cidV0: string; data: Profile | null } | null> { + if (!metadataDigest) { + return null; + } + const slicedDigest = metadataDigest.slice(2, metadataDigest.length); + + const cache = await ProfileCache.init(); + const cacheResult = await cache.read(slicedDigest); + + if (cacheResult) { + return cacheResult; + } + + const cidV0 = uint8ArrayToCidV0( + Uint8Array.from(Buffer.from(slicedDigest, "hex")) + ); + + const externalResponse = await fetch(`https://ipfs.io/ipfs/${cidV0}`); + const externalData = await externalResponse.json(); + + if (!externalData) { + return { cidV0, data: null }; + } + + await cache.add(slicedDigest, cidV0, externalData as Profile); + return { cidV0, data: externalData as Profile }; +} + */ + +import multihash from "multihashes"; +import { Profile } from "./types"; +import { ProfileCache } from "./cache"; +import { Avatar, eventLog } from "generated"; +import { uint8ArrayToCidV0 } from "./utils"; + +// Simple config with only needed values +const config = { + maxImageSizeKB: 150, + imageDimension: 256, +}; + +const IPFS_ENDPOINTS = [ + "https://cloudflare-ipfs.com/ipfs", + "https://ipfs.io/ipfs", + "https://gateway.pinata.cloud/ipfs", +]; + +async function validateImage(imageUrl: string): Promise { + try { + const response = await fetch(imageUrl); + const buffer = await response.arrayBuffer(); + + // Check file size + if (buffer.byteLength > config.maxImageSizeKB * 1024) { + console.error("Image size exceeds limit"); + return false; + } else return true; + } catch (error) { + console.error("Failed to validate image:", error); + return false; + } +} + +async function fetchFromEndpoint( + endpoint: string, + cidV0: string +): Promise<{ data: Profile | null; timeTaken: number }> { + const startTime = performance.now(); + try { + const response = await fetch(`${endpoint}/${cidV0}`); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = (await response.json()) as Profile | undefined; + const timeTaken = performance.now() - startTime; + + // If there's an avatar URL, validate it + + if (data?.previewImageUrl) { + const isValidImage = await validateImage(data.previewImageUrl); + if (!isValidImage) { + console.warn(`Invalid avatar image in profile from ${endpoint}`); + data.previewImageUrl = undefined; + } + } + + console.log(`IPFS fetch from ${endpoint} took ${timeTaken.toFixed(2)}ms`); + return { data: data as Profile, timeTaken }; + } catch (e) { + const timeTaken = performance.now() - startTime; + console.warn( + `Failed to fetch from ${endpoint} (${timeTaken.toFixed(2)}ms):`, + e + ); + return { data: null, timeTaken }; + } +} + +export async function getProfileMetadataFromIpfs( + metadataDigest: string +): Promise<{ cidV0: string; data: Profile | null } | null> { + if (!metadataDigest) { + return null; + } + const slicedDigest = metadataDigest.slice(2, metadataDigest.length); + + const cache = await ProfileCache.init(); + const cacheResult = await cache.read(slicedDigest); + + if (cacheResult) { + return cacheResult; + } + + const cidV0 = uint8ArrayToCidV0( + Uint8Array.from(Buffer.from(slicedDigest, "hex")) + ); + + // Try each endpoint until we get a successful response + for (const endpoint of IPFS_ENDPOINTS) { + const { data, timeTaken } = await fetchFromEndpoint(endpoint, cidV0); + console.log(`IPFS fetch from ${endpoint} took ${timeTaken.toFixed(2)}ms`); + if (data) { + console.log("Adding IPFS data to cache", data); + await cache.add(slicedDigest, cidV0, data); + return { cidV0, data }; + } + } + + console.error("Failed to fetch from all IPFS endpoints"); + return { cidV0, data: null }; +} diff --git a/src/utils.ts b/src/utils.ts index 131bd93..c4cba83 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -8,7 +8,7 @@ import { Avatar, eventLog } from "generated"; * @param {Uint8Array} uint8Array - The 32-byte hash digest. * @returns {string} - The resulting CIDv0 string (e.g., Qm...). */ -function uint8ArrayToCidV0(uint8Array: Uint8Array): string { +export function uint8ArrayToCidV0(uint8Array: Uint8Array): string { if (uint8Array.length !== 32) { throw new Error("Invalid array length. Expected 32 bytes."); } @@ -20,36 +20,6 @@ function uint8ArrayToCidV0(uint8Array: Uint8Array): string { return multihash.toB58String(multihashBytes); } -export async function getProfileMetadataFromIpfs( - metadataDigest: string -): Promise<{ cidV0: string; data: Profile | null } | null> { - if (!metadataDigest) { - return null; - } - const slicedDigest = metadataDigest.slice(2, metadataDigest.length); - - const cache = await ProfileCache.init(); - const cacheResult = await cache.read(slicedDigest); - - if (cacheResult) { - return cacheResult; - } - - const cidV0 = uint8ArrayToCidV0( - Uint8Array.from(Buffer.from(slicedDigest, "hex")) - ); - - const externalResponse = await fetch(`https://ipfs.io/ipfs/${cidV0}`); - const externalData = await externalResponse.json(); - - if (!externalData) { - return { cidV0, data: null }; - } - - await cache.add(slicedDigest, cidV0, externalData as Profile); - return { cidV0, data: externalData as Profile }; -} - export function makeAvatarBalanceEntityId(avatarId: string, tokenId: string) { return `${avatarId}-${tokenId}`; } @@ -77,4 +47,4 @@ export function defaultAvatarProps(event: eventLog) { trustedByN: 0, isVerified: false, } as Avatar; -} \ No newline at end of file +} From ffad769d666526ef9f38948f98a95bd6b7983919 Mon Sep 17 00:00:00 2001 From: Johanna Fransson Date: Fri, 22 Nov 2024 15:01:58 +0700 Subject: [PATCH 2/4] feat: add centralized endpoint as well which uses private IPFS gateway --- .cache/cache.db | Bin 3371008 -> 3379200 bytes src/event_handlers/hubV2.ts | 2 +- src/ipfs.ts | 43 ++++++++---------------------------- 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/.cache/cache.db b/.cache/cache.db index 23d36a9f6e8dcf1b8f4bca8bd826b7e0308dac23..76fa110c6f152155e150bd29d22b98cae5bec7e8 100644 GIT binary patch delta 1059 zcmbu;|4$ob90%~{xx3z7+v}CO!glK>rMD@pUAbOY+FPRBHr87N42w8sGR^vh#$ix! zk+HZ$%1j6$3o}Rh{4@reVQfFR5TY0TVaWCy2@;K2WQr74U@^;PVxloI)la7Xfj_)H z&)t*f$vyY}{8@MWLPg%GWM;%~&RnbVWil?Wl5I0BVgaDVQ8$6X_ii1%l! z{O3f9Y9v2h4jBw=NSF`8ZRQvLL-2y`lHOfH(hg7aNha^2$b7m^zgVsxD%WE`0U9vC z23WuW9@v4yD%U&dB15kt)v{Fx4`>@Riwuf{(te%n@d~4ia~v6#op)N>By1gB@1MC++@NrWR2I6)>J*f^><#LU+&=sDM`ZR-WbN zxbs}pagbC^NJ*<}LNYK3!q1UECZ+ofKZcHwZ?8#>=4jX;<38aMS=}ZWWY#ORkhyrR zZdsp7E3^&HIEBfR4obI{r==7&p2gA-)naNa7g162xNR(bSBV&=N{I8i~gnluk91P_qY8SQyIRlE6;j1G~U(@I0sneozAfR{oYe5R>WS zXdfD(@C}^8JJEO4J?aAg3eRwNxPDG$AG1^JX~Gxf1UXfd`^eijr6grbl9@@#AfMfo zE|Di|vPo8_rD5BDZGAtibLg?SNxLbsvUk7EqD^s=`IFqa8aizK{7@dG%s0bfb75;c zW-ae^=`C#j9ZHhLYf_6}UH~tGT2Ke}fglKh{U8kL zfdV2{@Tt1o!&7(zu}yem*3+|$Kbn4RP+;?}GfU0?H|XQtC!(*O@9OT(Hnl{LWYzw@ zuA}kDq1@{o?deq8du<<_Yi~Z;m+4JtO}*LlhkQd73(5~gSa`b-GRWO6d5PRxms`m?r8IKrucL5p|LqHbz8srU H>MH&LMj>wG delta 662 zcmXZYPe>F|90%|>v$H!p>o~KPTBBR8&05-yt~!K5haH1<`8!PVB7lq?iU-E4Gx0_ug`dLdEc4CEuJd_({dTp)oPJRpM?6!7tUq`;NMbk@w> zel_EA?~bt&L5D)c>Ij9WjW)hrtd4u=!jv(b3I|ju1PyfXLlNwOy-*A#Pzw8CKMx0t z<$;o&N7xv{S@E9ndgOVzTec}QVZ=1wapkx2N|;ryDV5#~zcFFN1u9!LY_5+-2Kp%s#-^6IeI&8#c1iCou>Ow ztzn*DGZO;+?6JR4$C&kmO8e|3KDut6_qb1DX@T+`MNTTbWkLw5;4mD4YN&yu5C#is op$;NY4-GuL)%fEUm;8E*$5;KRKu#83Pp);2iK@d#uG+VizYuBZJOBUy diff --git a/src/event_handlers/hubV2.ts b/src/event_handlers/hubV2.ts index 7eecbeb..cdf3ddf 100644 --- a/src/event_handlers/hubV2.ts +++ b/src/event_handlers/hubV2.ts @@ -196,7 +196,7 @@ HubV2.PersonalMint.handlerWithLoader({ }); NameRegistry.UpdateMetadataDigest.handler(async ({ event, context }) => { - console.log("Coming inside nameReg here: e", event.params.metadataDigest); + console.log("Coming inside nameReg here", event.params.metadataDigest); let profileMetadata: { cidV0: string; data: Profile | null } | null = null; try { profileMetadata = await getProfileMetadataFromIpfs( diff --git a/src/ipfs.ts b/src/ipfs.ts index 26edf45..b11a8b2 100644 --- a/src/ipfs.ts +++ b/src/ipfs.ts @@ -1,34 +1,3 @@ -/* export async function getProfileMetadataFromIpfs( - metadataDigest: string -): Promise<{ cidV0: string; data: Profile | null } | null> { - if (!metadataDigest) { - return null; - } - const slicedDigest = metadataDigest.slice(2, metadataDigest.length); - - const cache = await ProfileCache.init(); - const cacheResult = await cache.read(slicedDigest); - - if (cacheResult) { - return cacheResult; - } - - const cidV0 = uint8ArrayToCidV0( - Uint8Array.from(Buffer.from(slicedDigest, "hex")) - ); - - const externalResponse = await fetch(`https://ipfs.io/ipfs/${cidV0}`); - const externalData = await externalResponse.json(); - - if (!externalData) { - return { cidV0, data: null }; - } - - await cache.add(slicedDigest, cidV0, externalData as Profile); - return { cidV0, data: externalData as Profile }; -} - */ - import multihash from "multihashes"; import { Profile } from "./types"; import { ProfileCache } from "./cache"; @@ -42,9 +11,11 @@ const config = { }; const IPFS_ENDPOINTS = [ - "https://cloudflare-ipfs.com/ipfs", + "https://rpc.aboutcircles.com/profiles/get", + + /* "https://cloudflare-ipfs.com/ipfs", "https://ipfs.io/ipfs", - "https://gateway.pinata.cloud/ipfs", + "https://gateway.pinata.cloud/ipfs", */ ]; async function validateImage(imageUrl: string): Promise { @@ -69,7 +40,11 @@ async function fetchFromEndpoint( ): Promise<{ data: Profile | null; timeTaken: number }> { const startTime = performance.now(); try { - const response = await fetch(`${endpoint}/${cidV0}`); + const url = endpoint.includes("aboutcircles.com") + ? `${endpoint}?cid=${cidV0}` + : `${endpoint}/${cidV0}`; + + const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } From cc359e01b97f969f2cf2827679f454b79be6a671 Mon Sep 17 00:00:00 2001 From: Johanna Fransson Date: Fri, 22 Nov 2024 15:09:20 +0700 Subject: [PATCH 3/4] feat: small cleanup --- src/event_handlers/hubV2.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/event_handlers/hubV2.ts b/src/event_handlers/hubV2.ts index cdf3ddf..ea184db 100644 --- a/src/event_handlers/hubV2.ts +++ b/src/event_handlers/hubV2.ts @@ -196,7 +196,6 @@ HubV2.PersonalMint.handlerWithLoader({ }); NameRegistry.UpdateMetadataDigest.handler(async ({ event, context }) => { - console.log("Coming inside nameReg here", event.params.metadataDigest); let profileMetadata: { cidV0: string; data: Profile | null } | null = null; try { profileMetadata = await getProfileMetadataFromIpfs( From b4bebf4e2a5c110d804ad0d3b5a8c48357e10957 Mon Sep 17 00:00:00 2001 From: Johanna Fransson Date: Fri, 22 Nov 2024 15:10:26 +0700 Subject: [PATCH 4/4] feat: small cleanup --- src/ipfs.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ipfs.ts b/src/ipfs.ts index b11a8b2..f402024 100644 --- a/src/ipfs.ts +++ b/src/ipfs.ts @@ -61,7 +61,6 @@ async function fetchFromEndpoint( } } - console.log(`IPFS fetch from ${endpoint} took ${timeTaken.toFixed(2)}ms`); return { data: data as Profile, timeTaken }; } catch (e) { const timeTaken = performance.now() - startTime;