fix: normalize response bytes in getKeysFromRelayer#2
fix: normalize response bytes in getKeysFromRelayer#2luchobonatti wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR normalizes relayer key/CRS response body handling in getKeysFromRelayer by reusing the shared getResponseBytes() utility, improving compatibility with fetch implementations (e.g., undici/Next.js returning ArrayBuffer from response.bytes()).
Changes:
- Replace inline
response.bytes()/response.arrayBuffer()branching withgetResponseBytes()for the public key fetch. - Replace inline
response.bytes()/response.arrayBuffer()branching withgetResponseBytes()for the CRS (2048) fetch.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await publicParams2048Response.arrayBuffer(), | ||
| ); | ||
| } | ||
| const publicParams2048 = await getResponseBytes(publicParams2048Response); |
There was a problem hiding this comment.
getResponseBytes() already returns a Uint8Array, but later this buffer is wrapped with new Uint8Array(publicParams2048) before deserialization. That constructor call will clone the entire CRS byte array, which can be very large and adds avoidable memory/CPU overhead. Since the bytes are already normalized, pass publicParams2048 directly to CompactPkeCrs.safe_deserialize(...) (and drop the extra new Uint8Array(...)).
Closes: zama-ai#378
Summary
response.bytes()/response.arrayBuffer()logic ingetKeysFromRelayerwith the existinggetResponseBytes()utilitygetResponseBytes()already usesnormalizeBytes()which handlesUint8Array,ArrayBuffer, andArrayBufferView— fixing the case where undici (Next.js) returnsArrayBufferfromresponse.bytes()Changes
src/relayer-provider/v1/networkV1.tsgetResponseBytes()calls (2 lines)Test plan
prettier:checkpasseseslintpassesnetworkV1.test.ts— 1 suite, all passfetch.test.ts— 1 suite, all pass