From 8deb7d56e00a57984f2f47b62095af2a2b55e294 Mon Sep 17 00:00:00 2001 From: Kris <72598069+MelodyFish@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:16:27 +0800 Subject: [PATCH] feat: extract hash calculation logic into a separate function --- scripts/simpleMintAndRegisterSpg.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/simpleMintAndRegisterSpg.ts b/scripts/simpleMintAndRegisterSpg.ts index 3250bdb..5cf0e4e 100644 --- a/scripts/simpleMintAndRegisterSpg.ts +++ b/scripts/simpleMintAndRegisterSpg.ts @@ -40,12 +40,14 @@ const main = async function () { description: 'This NFT represents ownership of an IP Asset', image: 'https://i.imgur.com/gb59b2S.png', } - + const calculateHash = (data: any): string { + return createHash('sha256').update(JSON.stringify(data)).digest('hex') + } // 4. Upload your IP and NFT Metadata to IPFS const ipIpfsHash = await uploadJSONToIPFS(ipMetadata) - const ipHash = createHash('sha256').update(JSON.stringify(ipMetadata)).digest('hex') + const ipHash = calculateHash(ipMetadata) const nftIpfsHash = await uploadJSONToIPFS(nftMetadata) - const nftHash = createHash('sha256').update(JSON.stringify(nftMetadata)).digest('hex') + const nftHash = calculateHash(nftMetadata) // 5. Register the NFT as an IP Asset //