From 0db50b929b97796f2e958c88054a271d849ff9f1 Mon Sep 17 00:00:00 2001 From: Julien Date: Thu, 1 Feb 2024 11:54:09 -0800 Subject: [PATCH] chore: improve browser support (#6384) * fix: remove unsupported syntax * fix: handle undefined process * chore: remove uneeded type --- packages/light-client/src/transport/rest.ts | 18 +++++++----------- packages/params/src/index.ts | 4 +++- packages/state-transition/src/util/sszBytes.ts | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/light-client/src/transport/rest.ts b/packages/light-client/src/transport/rest.ts index ebbd8e52f691..2c63f2ea988a 100644 --- a/packages/light-client/src/transport/rest.ts +++ b/packages/light-client/src/transport/rest.ts @@ -1,25 +1,21 @@ import EventEmitter from "events"; -import StrictEventEmitter from "strict-event-emitter-types"; -import {allForks, SyncPeriod} from "@lodestar/types"; -import {Api, ApiError, routes} from "@lodestar/api"; -import {ForkName} from "@lodestar/params"; -import {LightClientTransport} from "./interface.js"; +import {type StrictEventEmitter} from "strict-event-emitter-types"; +import {type allForks, type SyncPeriod} from "@lodestar/types"; +import {type Api, ApiError, routes} from "@lodestar/api"; +import {type ForkName} from "@lodestar/params"; +import {type LightClientTransport} from "./interface.js"; export type LightClientRestEvents = { [routes.events.EventType.lightClientFinalityUpdate]: allForks.LightClientFinalityUpdate; [routes.events.EventType.lightClientOptimisticUpdate]: allForks.LightClientOptimisticUpdate; }; -type RestEvents = StrictEventEmitter; - -export class LightClientRestTransport extends (EventEmitter as {new (): RestEvents}) implements LightClientTransport { +export class LightClientRestTransport implements LightClientTransport { private controller = new AbortController(); private readonly eventEmitter: StrictEventEmitter = new EventEmitter(); private subscribedEventstream = false; - constructor(private readonly api: Api) { - super(); - } + constructor(private readonly api: Api) {} async getUpdates( startPeriod: SyncPeriod, diff --git a/packages/params/src/index.ts b/packages/params/src/index.ts index d111d090b8c3..6a95e3ca632e 100644 --- a/packages/params/src/index.ts +++ b/packages/params/src/index.ts @@ -28,7 +28,9 @@ presetStatus.frozen = true; * The active preset can be manually overridden with `setActivePreset` */ export const ACTIVE_PRESET = - userSelectedPreset ?? PresetName[process?.env?.LODESTAR_PRESET as PresetName] ?? PresetName.mainnet; + userSelectedPreset ?? + (typeof process !== "undefined" ? PresetName[process?.env?.LODESTAR_PRESET as PresetName] : undefined) ?? + PresetName.mainnet; export const activePreset = {...presets[ACTIVE_PRESET], ...userOverrides}; // These variables must be exported individually and explicitly diff --git a/packages/state-transition/src/util/sszBytes.ts b/packages/state-transition/src/util/sszBytes.ts index 25b65626a0dd..b5141e1673e5 100644 --- a/packages/state-transition/src/util/sszBytes.ts +++ b/packages/state-transition/src/util/sszBytes.ts @@ -37,14 +37,14 @@ export const VALIDATOR_BYTES_SIZE = 121; */ const SLOT_BYTES_POSITION_IN_STATE = 40; -export function getForkFromStateBytes(config: ChainForkConfig, bytes: Buffer | Uint8Array): ForkSeq { +export function getForkFromStateBytes(config: ChainForkConfig, bytes: Uint8Array): ForkSeq { const slot = bytesToInt(bytes.subarray(SLOT_BYTES_POSITION_IN_STATE, SLOT_BYTES_POSITION_IN_STATE + SLOT_BYTE_COUNT)); return config.getForkSeq(slot); } export function getStateTypeFromBytes( config: ChainForkConfig, - bytes: Buffer | Uint8Array + bytes: Uint8Array ): allForks.AllForksSSZTypes["BeaconState"] { const slot = getStateSlotFromBytes(bytes); return config.getForkTypes(slot).BeaconState;