import { personalSign } from '../../../extension/background-script/EthereumService' ; import type { AvatarMetaDB } from '../types' ; import { getNFTAvatarFromJSON } from './db' ; import { getUserAddress , setUserAddress } from './gun' ; import { getNFTAvatarFromRSS , saveNFTAvatarToRSS } from './rss3' ; export async function getNFTAvatar ( userId ) { let result ; const address = await getUserAddress ( userId ) ; if ( ! address ) { result = await getNFTAvatarFromJSON ( userId ) ; return result ; } result = await getNFTAvatarFromRSS ( userId , address ) ; if ( ! result ) { result = await getNFTAvatarFromJSON ( userId ) ; } return result ; } export async function saveNFTAvatar ( address , nft ) { const signature = await personalSign ( nft . userId , address ) ; setUserAddress ( nft . userId , address ) ; const avatar = await saveNFTAvatarToRSS ( address , nft , signature ) ; return avatar ; } export async function getAddress ( userId ) { const address = await getUserAddress ( userId ) ; return ( address ?? '' ) as string ; } export { getNFTContractVerifiedFromJSON } from './verified' ; export { getUserAddresses } from './gun' ; export async function getImage ( image ) { const response = await globalThis . fetch ( image ) ; return ( await blobToBase64 ( await response . blob ( ) ) ) as string ; } function blobToBase64 ( blob ) { return new Promise ( ( resolve , _ ) => { const reader = new FileReader ( ) ; reader . onloadend = ( ) => resolve ( reader . result ) ; reader . readAsDataURL ( blob ) ; } ) ; }