Skip to content

Commit

Permalink
fix: Update viem version to 2.5.0 and refactor getFunctionSelector im…
Browse files Browse the repository at this point in the history
…plementation
  • Loading branch information
jnsdls committed Jan 23, 2024
1 parent 87b98d8 commit e07c5c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
12 changes: 6 additions & 6 deletions packages/thirdweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@
"@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",
"bun-types": "latest",
"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": {
Expand Down
9 changes: 2 additions & 7 deletions packages/thirdweb/src/abi/lib/getFunctionSelector.ts
Original file line number Diff line number Diff line change
@@ -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<string, Hash>();

Expand All @@ -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;
}
38 changes: 19 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e07c5c9

Please sign in to comment.