Skip to content

Commit

Permalink
fix: validate token URI (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Dec 19, 2024
1 parent f61fb4f commit 3b9a093
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions contracts/nft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@types/chai": "^4.2.0",
"@types/mocha": ">=9.1.0",
"@types/node": ">=12.0.0",
"@types/validator": "^13.12.2",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/localnet": "4.0.0-rc6",
Expand Down Expand Up @@ -61,6 +62,7 @@
"@solana-developers/helpers": "^2.4.0",
"@solana/spl-memo": "^0.2.5",
"@solana/web3.js": "^1.95.2",
"@zetachain/protocol-contracts": "11.0.0-rc3"
"@zetachain/protocol-contracts": "11.0.0-rc3",
"validator": "^13.12.0"
}
}
}
16 changes: 16 additions & 0 deletions contracts/nft/tasks/mint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import isURL from "validator/lib/isURL";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const [signer] = await hre.ethers.getSigners();
Expand All @@ -9,6 +10,21 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
}

const supportedProtocols = ["https", "ipfs"];

const isValidTokenUri = isURL(args.tokenUri, {
require_protocol: true,
protocols: supportedProtocols,
});

if (!isValidTokenUri) {
throw new Error(
`Invalid token URI: ${
args.tokenUri
}. Supported protocols are: ${supportedProtocols.join(", ")}.`
);
}

const contract = await hre.ethers.getContractAt(
args.name as "ZetaChainUniversalNFT" | "EVMUniversalNFT",
args.contract
Expand Down
10 changes: 10 additions & 0 deletions contracts/nft/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,11 @@
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==

"@types/validator@^13.12.2":
version "13.12.2"
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.12.2.tgz#760329e756e18a4aab82fc502b51ebdfebbe49f5"
integrity sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA==

"@types/wrap-ansi@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz#18b97a972f94f60a679fd5c796d96421b9abb9fd"
Expand Down Expand Up @@ -7404,6 +7409,11 @@ v8-compile-cache-lib@^3.0.1:
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==

validator@^13.12.0:
version "13.12.0"
resolved "https://registry.yarnpkg.com/validator/-/validator-13.12.0.tgz#7d78e76ba85504da3fee4fd1922b385914d4b35f"
integrity sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==

varuint-bitcoin@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz#e76c138249d06138b480d4c5b40ef53693e24e92"
Expand Down

0 comments on commit 3b9a093

Please sign in to comment.