Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions src/relayer-provider/v1/networkV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@sdk/lowlevel/constants';
import { fetchRelayerV1Get } from './fetchRelayerV1';
import { isNonEmptyString, removeSuffix } from '@base/string';
import { getResponseBytes } from '@base/fetch';

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type CachedKey = {
Expand Down Expand Up @@ -77,13 +78,7 @@ export async function getKeysFromRelayer(
);
}

let publicKey: Uint8Array;
if (typeof publicKeyResponse.bytes === 'function') {
// bytes is not widely supported yet
publicKey = await publicKeyResponse.bytes();
} else {
publicKey = new Uint8Array(await publicKeyResponse.arrayBuffer());
}
const publicKey = await getResponseBytes(publicKeyResponse);

const publicParamsUrl = data.response.crs['2048'].urls[0];
const publicParamsId = data.response.crs['2048'].data_id;
Expand All @@ -95,15 +90,7 @@ export async function getKeysFromRelayer(
);
}

let publicParams2048: Uint8Array;
if (typeof publicParams2048Response.bytes === 'function') {
// bytes is not widely supported yet
publicParams2048 = await publicParams2048Response.bytes();
} else {
publicParams2048 = new Uint8Array(
await publicParams2048Response.arrayBuffer(),
);
}
const publicParams2048 = await getResponseBytes(publicParams2048Response);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...)).

Copilot uses AI. Check for mistakes.

let pub_key;
try {
Expand Down