Skip to content

Commit fe18df1

Browse files
authored
refactor: Drop "dom" lib from SDK's TypeScript config and clarify environment usage (#3303)
This PR removes `"dom"` from SDK's TypeScript `lib` configuration to avoid pulling browser-specific types into the default scope. The SDK is not primarily a browser environment, and having DOM types globally available was masking environment boundaries and weakening type safety. The remaining changes are necessary follow-ups to keep the codebase compiling and to make environment assumptions more explicit. ### Changes **TypeScript configuration:** * Removed `"dom"` from the `lib` array in both `tsconfig.json` and `tsconfig.jest.json` to better reflect the intended runtime environment and prevent accidental reliance on browser-only APIs. **Type safety and cryptographic key handling:** * Updated `cachedJWK` in `ECDSAKeyPairIdentity` from `JsonWebKey` to `webcrypto.JsonWebKey`. * Explicitly imported the `webcrypto` type from Node’s `crypto` module to avoid relying on DOM-provided global types and to clarify the source of the API. This ensures cryptographic types are correctly scoped and remain available after removing the DOM lib. **Documentation and environment targeting:** * Added a `@todo` comment and a local `dom` lib reference in `RSAKeyPair.ts` to document that the file currently mixes browser and Node.js code. * This makes the environment dependency explicit and flags the file for future refactoring into environment-specific implementations.
1 parent 3413fb3 commit fe18df1

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

packages/sdk/src/encryption/RSAKeyPair.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* @todo This file contains code for both browser and Node.js environments. Consider
3+
* making it environment-specific (using separate files or conditional exports), and
4+
* remove the following "dom" lib reference when done.
5+
*/
6+
/// <reference lib="dom" />
7+
18
import crypto from 'crypto'
29
import { promisify } from 'util'
310
import { KeyExchangeKeyPair } from './KeyExchangeKeyPair'

packages/sdk/src/identity/ECDSAKeyPairIdentity.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { hexToBinary, EcdsaSecp256r1 } from '@streamr/utils'
22
import { KeyPairIdentity } from './KeyPairIdentity'
33
import { SignatureType } from '@streamr/trackerless-network'
44
import { StrictStreamrClientConfig } from '../Config'
5+
import type { webcrypto } from 'crypto'
56

67
const signingUtil = new EcdsaSecp256r1()
78

@@ -10,7 +11,7 @@ const signingUtil = new EcdsaSecp256r1()
1011
*/
1112
export class ECDSAKeyPairIdentity extends KeyPairIdentity {
1213

13-
private cachedJWK: JsonWebKey | undefined
14+
private cachedJWK: webcrypto.JsonWebKey | undefined
1415

1516
assertValidKeyPair(): void {
1617
signingUtil.assertValidKeyPair(this.publicKey, this.privateKey)

packages/sdk/tsconfig.jest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.jest.json",
33
"compilerOptions": {
4-
"lib": ["es2021", "dom"],
4+
"lib": ["es2021"],
55
"experimentalDecorators": true,
66
"emitDecoratorMetadata": true,
77
"noImplicitOverride": false

packages/sdk/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"compilerOptions": {
44
"outDir": "dist",
55
"declarationDir": "dist/types",
6-
"lib": ["es2021", "dom"],
6+
"lib": ["es2021"],
77
"experimentalDecorators": true,
88
"emitDecoratorMetadata": true,
99
"noImplicitOverride": false

0 commit comments

Comments
 (0)