Skip to content

Commit 11f0aa3

Browse files
committed
refactor: lazy-init EcUtils native object for getCurves()
Defer HybridObject allocation until getCurves() is actually called, avoiding an unnecessary native object creation at module import time.
1 parent b85c71a commit 11f0aa3

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • packages/react-native-quick-crypto/src

packages/react-native-quick-crypto/src/ec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ import { Buffer } from '@craftzdog/react-native-buffer';
3535
import { ECDH } from './ecdh';
3636

3737
class EcUtils {
38-
private static native =
39-
NitroModules.createHybridObject<EcKeyPair>('EcKeyPair');
38+
private static _native: EcKeyPair | undefined;
39+
private static get native(): EcKeyPair {
40+
if (!this._native) {
41+
this._native = NitroModules.createHybridObject<EcKeyPair>('EcKeyPair');
42+
}
43+
return this._native;
44+
}
4045
public static getSupportedCurves(): string[] {
4146
return this.native.getSupportedCurves();
4247
}

0 commit comments

Comments
 (0)