From e07c5c917e233c607cf739d0840653702a2053e9 Mon Sep 17 00:00:00 2001 From: Jonas Daniels Date: Tue, 23 Jan 2024 15:58:59 +1300 Subject: [PATCH] fix: Update viem version to 2.5.0 and refactor getFunctionSelector implementation --- packages/thirdweb/package.json | 12 +++--- .../src/abi/lib/getFunctionSelector.ts | 9 +---- pnpm-lock.yaml | 38 +++++++++---------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/packages/thirdweb/package.json b/packages/thirdweb/package.json index 131717e5b8d..82c6c4752f9 100644 --- a/packages/thirdweb/package.json +++ b/packages/thirdweb/package.json @@ -97,7 +97,7 @@ "@noble/hashes": "^1.3.3", "@thirdweb-dev/cli": "workspace:*", "abitype": "^0.10.3", - "viem": "^2.0.10" + "viem": "^2.5.0" }, "devDependencies": { "@types/react": "^18.2.17", @@ -105,15 +105,15 @@ "eslint-config-thirdweb": "workspace:*", "eslint-plugin-better-tree-shaking": "0.0.4", "eslint-plugin-tsdoc": "^0.2.16", + "ethers5": "npm:ethers@^5.0.0", + "ethers6": "npm:ethers@^6.0.0", "react": "^18.2.0", "rimraf": "^3.0.2", - "typescript": "^5.1.6", - "ethers5": "npm:ethers@^5.0.0", - "ethers6": "npm:ethers@^6.0.0" + "typescript": "^5.1.6" }, "peerDependencies": { - "react": ">=18", - "ethers": "^5 || ^6" + "ethers": "^5 || ^6", + "react": ">=18" }, "peerDependenciesMeta": { "react": { diff --git a/packages/thirdweb/src/abi/lib/getFunctionSelector.ts b/packages/thirdweb/src/abi/lib/getFunctionSelector.ts index b2e41d61b4d..30e8b1309ab 100644 --- a/packages/thirdweb/src/abi/lib/getFunctionSelector.ts +++ b/packages/thirdweb/src/abi/lib/getFunctionSelector.ts @@ -1,12 +1,7 @@ import type { AbiFunction } from "abitype"; import { getFunctionSignature } from "./getFunctionSignature.js"; -import { slice } from "viem/utils"; +import { toFunctionSelector } from "viem"; import type { Hash } from "viem"; -import { keccak_256 } from "@noble/hashes/sha3"; -import { uint8ArrayToHex } from "../../utils/uint8-array.js"; - -const hash = (value: string) => - `0x${uint8ArrayToHex(keccak_256(value))}` as const; const FN_SELECTOR_CACHE = /*@__PURE__*/ new Map(); @@ -17,7 +12,7 @@ export function getFunctionSelector(fn: string | AbiFunction): Hash { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return FN_SELECTOR_CACHE.get(normalizedFn)!; } - const functionSelector = slice(hash(normalizedFn), 0, 4); + const functionSelector = toFunctionSelector(normalizedFn); FN_SELECTOR_CACHE.set(normalizedFn, functionSelector); return functionSelector; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8dcd79684ee..97e2ae4b09e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1427,8 +1427,8 @@ importers: specifier: ^5 || ^6 version: 5.7.2 viem: - specifier: ^2.0.10 - version: 2.0.10(typescript@5.3.3) + specifier: ^2.5.0 + version: 2.5.0(typescript@5.3.3) devDependencies: '@types/react': specifier: ^18.2.17 @@ -14467,20 +14467,6 @@ packages: resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==} dev: false - /abitype@0.10.0(typescript@5.3.3): - resolution: {integrity: sha512-QvMHEUzgI9nPj9TWtUGnS2scas80/qaL5PBxGdwWhhvzqXfOph+IEiiiWrzuisu3U3JgDQVruW9oLbJoQ3oZ3A==} - peerDependencies: - typescript: '>=5.0.4' - zod: ^3 >=3.22.0 - peerDependenciesMeta: - typescript: - optional: true - zod: - optional: true - dependencies: - typescript: 5.3.3 - dev: false - /abitype@0.10.3(typescript@5.3.3): resolution: {integrity: sha512-tRN+7XIa7J9xugdbRzFv/95ka5ivR/sRe01eiWvM0HWWjHuigSZEACgKa0sj4wGuekTDtghCx+5Izk/cOi78pQ==} peerDependencies: @@ -14522,6 +14508,20 @@ packages: typescript: 5.3.3 dev: true + /abitype@1.0.0(typescript@5.3.3): + resolution: {integrity: sha512-NMeMah//6bJ56H5XRj8QCV4AwuW6hB6zqz2LnhhLdcWVQOsXki6/Pn3APeqxCma62nXIcmZWdu1DlHWS74umVQ==} + peerDependencies: + typescript: '>=5.0.4' + zod: ^3 >=3.22.0 + peerDependenciesMeta: + typescript: + optional: true + zod: + optional: true + dependencies: + typescript: 5.3.3 + dev: false + /abort-controller@3.0.0: resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==} engines: {node: '>=6.5'} @@ -31105,8 +31105,8 @@ packages: - zod dev: true - /viem@2.0.10(typescript@5.3.3): - resolution: {integrity: sha512-ncdvXJ0v8Qc83qQaPzPG7pTr7gbg9hRUCNL7n/1b5ZFE17YIeQVtGTx6zqg4zdjTXlTKPrecKvqeKUUjKrmnYg==} + /viem@2.5.0(typescript@5.3.3): + resolution: {integrity: sha512-ytHXIWtlgPs4mcsGxXjJrQ25v+N4dE2hBzgCU8CVv4iXNh3PRFRgyYa7igZlmxiMVzkfSHHADOtivS980JhilA==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -31118,7 +31118,7 @@ packages: '@noble/hashes': 1.3.2 '@scure/bip32': 1.3.2 '@scure/bip39': 1.2.1 - abitype: 0.10.0(typescript@5.3.3) + abitype: 1.0.0(typescript@5.3.3) isows: 1.0.3(ws@8.13.0) typescript: 5.3.3 ws: 8.13.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)