From 8bfa2ff521314b6aa1617487252929997d285b84 Mon Sep 17 00:00:00 2001 From: tate Date: Fri, 8 Sep 2023 14:47:24 +1000 Subject: [PATCH] sha256 on av upload --- package.json | 1 + pnpm-lock.yaml | 14 ++++++++++---- .../ProfileEditor/Avatar/AvatarUpload.tsx | 5 +++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 4c885803c..ba4faa86f 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@metamask/inpage-provider": "^8.1.0", "@metamask/mobile-provider": "^2.1.0", "@metamask/post-message-stream": "^6.1.2", + "@noble/hashes": "^1.3.2", "@rainbow-me/rainbowkit": "1.0.8", "@sentry/nextjs": "^7.43.0", "@svgr/webpack": "^8.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7325a6710..9f523fb59 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,6 +39,7 @@ importers: '@metamask/mobile-provider': ^2.1.0 '@metamask/post-message-stream': ^6.1.2 '@next/bundle-analyzer': ^13.4.19 + '@noble/hashes': ^1.3.2 '@nomiclabs/hardhat-ethers': npm:hardhat-deploy-ethers@0.3.0-beta.13 '@openzeppelin/contracts': ^4.7.3 '@openzeppelin/test-helpers': ^0.5.16 @@ -168,6 +169,7 @@ importers: '@metamask/inpage-provider': 8.1.0 '@metamask/mobile-provider': 2.1.0 '@metamask/post-message-stream': 6.1.2 + '@noble/hashes': 1.3.2 '@rainbow-me/rainbowkit': 1.0.8_6ohvwx4vltwvdm27d4nutgyik4 '@sentry/nextjs': 7.43.0_next@13.4.19+react@18.2.0 '@svgr/webpack': 8.1.0_typescript@5.1.6 @@ -1970,7 +1972,7 @@ packages: resolution: {integrity: sha512-gcENLemRR13+1MED2NeZBMA7FRS0xQPM7L2vhMqvKkjqtFT4YfjSVADq5U0iLuQLhFUJEMVuA8fbv5v+TN6O9A==} dependencies: '@chainsafe/as-sha256': 0.4.1 - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 /@chainsafe/ssz/0.11.1: resolution: {integrity: sha512-cB8dBkgGN6ZoeOKuk+rIRHKN0L5i9JLGeC0Lui71QX0TuLcQKwgbfkUexpyJxnGFatWf8yeJxlOjozMn/OTP0g==} @@ -3767,6 +3769,10 @@ packages: resolution: {integrity: sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==} engines: {node: '>= 16'} + /@noble/hashes/1.3.2: + resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==} + engines: {node: '>= 16'} + /@noble/secp256k1/1.6.3: resolution: {integrity: sha512-T04e4iTurVy7I8Sw4+c5OSN9/RkPlo1uKxAomtxQNLq8j1uPAqnsqG1bqvY3Jv7c13gyr6dui0zmh/I3+f/JaQ==} dev: true @@ -4261,7 +4267,7 @@ packages: resolution: {integrity: sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==} dependencies: '@noble/curves': 1.0.0 - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 '@scure/base': 1.1.1 /@scure/bip39/1.1.0: @@ -4274,7 +4280,7 @@ packages: /@scure/bip39/1.2.0: resolution: {integrity: sha512-SX/uKq52cuxm4YFXWFaVByaSHJh2w3BnokVSeUJVCv6K7WulT9u2BuNRBhuFl8vAuYnzx9bEu9WgpcNYTrYieg==} dependencies: - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 '@scure/base': 1.1.1 /@sentry/browser/7.43.0: @@ -4557,7 +4563,7 @@ packages: dependencies: '@babel/runtime': 7.19.0 '@noble/ed25519': 1.7.3 - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 '@noble/secp256k1': 1.7.1 '@solana/buffer-layout': 4.0.0 agentkeepalive: 4.3.0 diff --git a/src/components/@molecules/ProfileEditor/Avatar/AvatarUpload.tsx b/src/components/@molecules/ProfileEditor/Avatar/AvatarUpload.tsx index 59d2ec779..3c35d777d 100644 --- a/src/components/@molecules/ProfileEditor/Avatar/AvatarUpload.tsx +++ b/src/components/@molecules/ProfileEditor/Avatar/AvatarUpload.tsx @@ -1,14 +1,15 @@ /* eslint-disable no-multi-assign */ +import { sha256 } from '@noble/hashes/sha256' import { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import styled, { css } from 'styled-components' +import { bytesToHex } from 'viem' import { useMutation, useQueryClient, useSignTypedData } from 'wagmi' import { Button, Dialog, mq } from '@ensdomains/thorin' import { useChainName } from '@app/hooks/chain/useChainName' -import { keccak256 } from 'viem' import { useQueryKeys } from '../../../../utils/cacheKeyFactory' import { AvCancelButton, CropComponent } from './AvatarCrop' @@ -52,7 +53,7 @@ const UploadComponent = ({ const { t } = useTranslation('transactionFlow') const queryClient = useQueryClient() const queryKeys = useQueryKeys().avatar.avatar(name) - const urlHash = useMemo(() => keccak256(dataURLToBytes(dataURL)), [dataURL]) + const urlHash = useMemo(() => bytesToHex(sha256(dataURLToBytes(dataURL))), [dataURL]) const expiry = useMemo(() => `${Date.now() + 1000 * 60 * 60 * 24 * 7}`, []) const network = useChainName()