From 198e2a58dc935679c3734848c29b6454b02b0f02 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Tue, 30 Apr 2024 12:13:47 +0200 Subject: [PATCH] check for scams on erc721 --- .../utils/buildNftFromPersistedErc721Nft.ts | 3 ++ .../shared/src/lib/core/nfts/utils/index.ts | 1 + .../lib/core/nfts/utils/isScamErc721Nft.ts | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 packages/shared/src/lib/core/nfts/utils/isScamErc721Nft.ts diff --git a/packages/shared/src/lib/core/nfts/utils/buildNftFromPersistedErc721Nft.ts b/packages/shared/src/lib/core/nfts/utils/buildNftFromPersistedErc721Nft.ts index d2e5dae504..0895967943 100644 --- a/packages/shared/src/lib/core/nfts/utils/buildNftFromPersistedErc721Nft.ts +++ b/packages/shared/src/lib/core/nfts/utils/buildNftFromPersistedErc721Nft.ts @@ -1,12 +1,15 @@ import { DEFAULT_NFT_NAME, MimeType } from '@core/nfts' import { IErc721Nft, IPersistedErc721Nft } from '../interfaces' +import { isScamErc721Nft } from './isScamErc721Nft' export function buildNftFromPersistedErc721Nft(nft: IPersistedErc721Nft, accountAddress: string): IErc721Nft { const isSpendable = nft.ownerAddress === accountAddress + const isScam = nft?.isScam ?? (nft.metadata ? isScamErc721Nft(nft.metadata) : false) return { ...nft, isSpendable, + isScam, name: nft.metadata?.name ?? nft.contractMetadata.name ?? DEFAULT_NFT_NAME, description: nft.metadata?.description, type: MimeType.ImagePng, diff --git a/packages/shared/src/lib/core/nfts/utils/index.ts b/packages/shared/src/lib/core/nfts/utils/index.ts index f8305f6b34..1303697b3f 100644 --- a/packages/shared/src/lib/core/nfts/utils/index.ts +++ b/packages/shared/src/lib/core/nfts/utils/index.ts @@ -12,6 +12,7 @@ export * from './getSpendableStatusFromUnspentNftOutput' export * from './isIrc27Nft' export * from './isNftLocked' export * from './isNftOwnedByAnyAccount' +export * from './isScamErc721Nft' export * from './isScamIrc27Nft' export * from './isValidNftUri' export * from './isVisibleCollection' diff --git a/packages/shared/src/lib/core/nfts/utils/isScamErc721Nft.ts b/packages/shared/src/lib/core/nfts/utils/isScamErc721Nft.ts new file mode 100644 index 0000000000..2a6cddd66a --- /dev/null +++ b/packages/shared/src/lib/core/nfts/utils/isScamErc721Nft.ts @@ -0,0 +1,28 @@ +import { appParameters } from '@core/app/stores' +import { IErc721TokenMetadata } from '../interfaces' +import { get } from 'svelte/store' + +export function isScamErc721Nft(metadata: IErc721TokenMetadata): boolean { + const { urls, keywords } = get(appParameters).denylists + + if ( + urls.some( + (url) => + metadata?.name?.toLocaleLowerCase()?.includes(url) || + metadata?.description?.toLocaleLowerCase()?.includes(url) || + metadata?.image?.toLocaleLowerCase()?.includes(url) + ) + ) { + return true + } else if ( + keywords.some( + (phrase) => + metadata?.name?.toLocaleLowerCase()?.includes(phrase) || + metadata?.description?.toLocaleLowerCase()?.includes(phrase) + ) + ) { + return true + } else { + return false + } +}