diff --git a/cosmos/injective/tokens/inj16jf4qkcarp3lan4wl2qkrelf4kduvvujwg0780.json b/cosmos/injective/tokens/inj16jf4qkcarp3lan4wl2qkrelf4kduvvujwg0780.json new file mode 100644 index 0000000..e89dded --- /dev/null +++ b/cosmos/injective/tokens/inj16jf4qkcarp3lan4wl2qkrelf4kduvvujwg0780.json @@ -0,0 +1,9 @@ +{ + "contractAddress": "inj16jf4qkcarp3lan4wl2qkrelf4kduvvujwg0780", + "imageUrl": "https://raw.githubusercontent.com/chainapsis/keplr-contract-registry/main/images/injective/nATOM.png", + "metadata": { + "name": "Neptune Receipt ATOM", + "symbol": "nATOM", + "decimals": 6 + } +} diff --git a/cosmos/injective/tokens/inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s.json b/cosmos/injective/tokens/inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s.json new file mode 100644 index 0000000..e0e2f9d --- /dev/null +++ b/cosmos/injective/tokens/inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s.json @@ -0,0 +1,9 @@ +{ + "contractAddress": "inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s", + "imageUrl": "https://raw.githubusercontent.com/chainapsis/keplr-contract-registry/main/images/injective/nUSDT.png", + "metadata": { + "name": "Neptune Receipt USDT", + "symbol": "nUSDT", + "decimals": 6 + } +} diff --git a/cosmos/injective/tokens/inj1rmzufd7h09sqfrre5dtvu5d09ta7c0t4jzkr2f.json b/cosmos/injective/tokens/inj1rmzufd7h09sqfrre5dtvu5d09ta7c0t4jzkr2f.json new file mode 100644 index 0000000..bcb87de --- /dev/null +++ b/cosmos/injective/tokens/inj1rmzufd7h09sqfrre5dtvu5d09ta7c0t4jzkr2f.json @@ -0,0 +1,10 @@ +{ + "contractAddress": "inj1rmzufd7h09sqfrre5dtvu5d09ta7c0t4jzkr2f", + "imageUrl": "https://raw.githubusercontent.com/chainapsis/keplr-contract-registry/main/images/injective/nINJ.png", + "metadata": { + "name": "Neptune Receipt INJ", + "symbol": "nINJ", + "decimals": 18 + } +} + diff --git a/images/injective/nATOM.png b/images/injective/nATOM.png new file mode 100644 index 0000000..26176a1 Binary files /dev/null and b/images/injective/nATOM.png differ diff --git a/images/injective/nINJ.png b/images/injective/nINJ.png new file mode 100644 index 0000000..85b722b Binary files /dev/null and b/images/injective/nINJ.png differ diff --git a/images/injective/nUSDT.png b/images/injective/nUSDT.png new file mode 100644 index 0000000..39a5fa9 Binary files /dev/null and b/images/injective/nUSDT.png differ diff --git a/package.json b/package.json index 59fb877..43ca5a6 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "lint-test": "eslint \"src/**/*\" && prettier --check \"src/**/*\"", "lint-fix": "eslint --fix \"src/**/*\" && prettier --write \"src/**/*\"", "validate:token": "ts-node src/scripts/validate-token.ts", + "validate:image": "ts-node src/scripts/validate-image.ts", "pre-commit": "lint-staged" }, "pre-commit": [ @@ -52,6 +53,7 @@ "@keplr-wallet/cosmos": "^0.12.12", "axios": "^1.4.0", "curve25519-js": "^0.0.4", + "image-size": "^1.1.1", "joi": "^17.9.2", "koa": "^2.14.2", "koa-router": "^12.0.0", diff --git a/src/scripts/validate-token.ts b/src/scripts/validate-token.ts index d8e8515..3ba130f 100644 --- a/src/scripts/validate-token.ts +++ b/src/scripts/validate-token.ts @@ -1,8 +1,9 @@ import FS from "fs"; +import sizeOf from "image-size"; import { CW20TokenScheme } from "../scheme"; -import { getChainBaseMap } from "../utils"; +import { getChainBaseMap, validateImageUrl } from "../utils"; import Path from "path"; -import { Bech32Address } from "@keplr-wallet/cosmos"; +import { Bech32Address, ChainIdHelper } from "@keplr-wallet/cosmos"; import { fetchTokenMetadata } from "../query"; import { sortedJsonByKeyStringify } from "@keplr-wallet/common"; @@ -67,6 +68,29 @@ import { sortedJsonByKeyStringify } from "@keplr-wallet/common"; )}), contract: ${validated.value.contractAddress}, chain: ${chain})` ); } + + if (validated.value.imageUrl) { + const chainIdentifier = ChainIdHelper.parse(base.chainId).identifier; + const tokenImageUrl = validateImageUrl( + chainIdentifier, + validated.value.imageUrl + ); + + const dimensions = sizeOf( + `images/${chainIdentifier}/${tokenImageUrl}` + ); + + if (dimensions.type === "png") { + const width = dimensions.width ?? 0; + const height = dimensions.height ?? 0; + + if (width > 512 || height > 512) { + throw new Error( + `Reduce image size to 512x512 or smaller (expected: 512x512, actual: ${width}x${height})` + ); + } + } + } } else { throw new Error(`Invalid path: ${path}`); } diff --git a/src/utils.ts b/src/utils.ts index 539b8b7..60fdf97 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -49,3 +49,19 @@ export const getChainBaseMap = ( return map; }; + +export const validateImageUrl = ( + chainIdentifier: string, + url: string +): string => { + const baseURL = `https://raw.githubusercontent.com/chainapsis/keplr-contract-registry/main/images/${chainIdentifier}/`; + + if (!url.startsWith(baseURL)) { + throw new Error(`Invalid image url: ${url}`); + } + if (!(url.endsWith(".png") || url.endsWith(".svg"))) { + throw new Error(`Image formats can only be PNG and SVG.`); + } + + return url.replace(baseURL, ""); +}; diff --git a/yarn.lock b/yarn.lock index d09b92a..65a6db8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3316,6 +3316,17 @@ __metadata: languageName: node linkType: hard +"image-size@npm:^1.1.1": + version: 1.1.1 + resolution: "image-size@npm:1.1.1" + dependencies: + queue: 6.0.2 + bin: + image-size: bin/image-size.js + checksum: 23b3a515dded89e7f967d52b885b430d6a5a903da954fce703130bfb6069d738d80e6588efd29acfaf5b6933424a56535aa7bf06867e4ebd0250c2ee51f19a4a + languageName: node + linkType: hard + "import-fresh@npm:^3.0.0, import-fresh@npm:^3.2.1": version: 3.3.0 resolution: "import-fresh@npm:3.3.0" @@ -3750,6 +3761,7 @@ __metadata: eslint: ^8.34.0 eslint-config-prettier: ^8.6.0 eslint-plugin-prettier: ^4.2.1 + image-size: ^1.1.1 joi: ^17.9.2 koa: ^2.14.2 koa-router: ^12.0.0 @@ -4802,6 +4814,15 @@ __metadata: languageName: node linkType: hard +"queue@npm:6.0.2": + version: 6.0.2 + resolution: "queue@npm:6.0.2" + dependencies: + inherits: ~2.0.3 + checksum: ebc23639248e4fe40a789f713c20548e513e053b3dc4924b6cb0ad741e3f264dcff948225c8737834dd4f9ec286dbc06a1a7c13858ea382d9379f4303bcc0916 + languageName: node + linkType: hard + "read-package-json@npm:^2.0.0": version: 2.1.2 resolution: "read-package-json@npm:2.1.2"