Skip to content

Commit

Permalink
refactor(types): remove index signatures from JWK interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Sep 13, 2024
1 parent bcf2de2 commit ccf0cda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
9 changes: 6 additions & 3 deletions src/runtime/node/jwk_to_key.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { createPrivateKey, createPublicKey } from 'node:crypto'
import type { KeyObject } from 'node:crypto'
import type { KeyObject, JsonWebKeyInput } from 'node:crypto'

import type { JWK } from '../../types.d'

const parse = (jwk: JWK): KeyObject => {
return (jwk.d ? createPrivateKey : createPublicKey)({ format: 'jwk', key: jwk })
const parse = (key: JWK): KeyObject => {
if (key.d) {
return createPrivateKey(<JsonWebKeyInput>{ format: 'jwk', key })
}
return createPublicKey(<JsonWebKeyInput>{ format: 'jwk', key })
}
export default parse
18 changes: 0 additions & 18 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ export interface JWKParameters {
x5u?: string
/** JWK "kid" (Key ID) Parameter. */
kid?: string

[propName: string]: unknown
}

/** Convenience interface for Public OKP JSON Web Keys */
Expand All @@ -131,16 +129,12 @@ export interface JWK_OKP_Public extends JWKParameters {
crv: string
/** The public key */
x: string

[propName: string]: unknown
}

/** Convenience interface for Private OKP JSON Web Keys */
export interface JWK_OKP_Private extends JWK_OKP_Public, JWKParameters {
/** The Private Key */
d: string

[propName: string]: unknown
}

/** Convenience interface for Public EC JSON Web Keys */
Expand All @@ -151,16 +145,12 @@ export interface JWK_EC_Public extends JWKParameters {
x: string
/** Y Coordinate */
y: string

[propName: string]: unknown
}

/** Convenience interface for Private EC JSON Web Keys */
export interface JWK_EC_Private extends JWK_EC_Public, JWKParameters {
/** ECC Private Key */
d: string

[propName: string]: unknown
}

/** Convenience interface for Public RSA JSON Web Keys */
Expand All @@ -169,8 +159,6 @@ export interface JWK_RSA_Public extends JWKParameters {
e: string
/** Modulus */
n: string

[propName: string]: unknown
}

/** Convenience interface for Private RSA JSON Web Keys */
Expand All @@ -193,16 +181,12 @@ export interface JWK_RSA_Private extends JWK_RSA_Public, JWKParameters {
q: string
/** First CRT Coefficient */
qi: string

[propName: string]: unknown
}

/** Convenience interface for oct JSON Web Keys */
export interface JWK_oct extends JWKParameters {
/** Key Value */
k: string

[propName: string]: unknown
}

/**
Expand Down Expand Up @@ -258,8 +242,6 @@ export interface JWK extends JWKParameters {
x?: string
/** (EC) Y Coordinate */
y?: string

[propName: string]: unknown
}

/**
Expand Down

0 comments on commit ccf0cda

Please sign in to comment.