Skip to content

Commit 498d543

Browse files
committed
Fix getFunctionId implementation (#4443)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR updates `getFunctionId` in `function-id.ts` to use `randomBytesHex` instead of `uint8ArrayToHex`. ### Detailed summary - Replaced `uint8ArrayToHex` with `randomBytesHex` function - Changed `functionIdCache` from WeakMap to Map > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 88f7e7d commit 498d543

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.changeset/twenty-hairs-act.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix getFunctionId

packages/thirdweb/src/utils/function-id.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { sha256 } from "@noble/hashes/sha256";
2-
import { uint8ArrayToHex } from "./encoding/hex.js";
1+
import { randomBytesHex } from "./random.js";
32

43
// biome-ignore lint/suspicious/noExplicitAny: the whoel point here is to accept anything
54
type AnyFunction = (...args: any[]) => any;
65

7-
// WeakMap should be fine, if we de-reference the function, it should be garbage collected
8-
const functionIdCache = new WeakMap<AnyFunction, string>();
6+
const functionIdCache = new Map<AnyFunction, string>();
97

108
/**
119
* Retrieves the unique identifier for a given function.
@@ -20,7 +18,7 @@ export function getFunctionId(fn: AnyFunction) {
2018
// biome-ignore lint/style/noNonNullAssertion: the `has` above ensures that this will always be set
2119
return functionIdCache.get(fn)!;
2220
}
23-
const id = uint8ArrayToHex(sha256(fn.toString()));
21+
const id = randomBytesHex();
2422
functionIdCache.set(fn, id);
2523
return id;
2624
}

0 commit comments

Comments
 (0)