Skip to content

Commit 411667f

Browse files
Dev (#1059)
* docs(proof): add documentation on terminating the bn128 curve to prevent resource leaks (#998) * style(proof): format code with prettier --------- Co-authored-by: VolodymyrBg <[email protected]>
1 parent 8770922 commit 411667f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/proof/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,25 @@ import { verifyProof } from "@semaphore-protocol/proof"
116116

117117
await verifyProof(proof1)
118118
```
119+
120+
## Resource management: Terminating the bn128 curve
121+
122+
When using the Semaphore proof library in Node.js environments, especially in tests or scripts that create and use the `bn128` curve (for example, via `getCurveFromName("bn128")` from the `ffjavascript` package), it is important to properly release resources associated with the curve after use. Failing to do so can result in leaked handles (such as `MessagePort` handles), which may prevent Node.js from exiting cleanly. This is particularly relevant when running test suites.
123+
124+
**How to terminate the bn128 curve:**
125+
126+
If you create a curve instance using `getCurveFromName("bn128")`, you should call its `terminate()` method when you are done with it. For example:
127+
128+
```typescript
129+
import { getCurveFromName } from "ffjavascript"
130+
131+
let curve
132+
beforeAll(async () => {
133+
curve = await getCurveFromName("bn128")
134+
})
135+
afterAll(async () => {
136+
await curve.terminate()
137+
})
138+
```
139+
140+
This ensures that all resources are properly released and Node.js can exit cleanly after your script or tests finish.

0 commit comments

Comments
 (0)