diff --git a/types/pem-jwk/index.d.ts b/types/pem-jwk/index.d.ts index 3a9d32c112..c206b12db2 100644 --- a/types/pem-jwk/index.d.ts +++ b/types/pem-jwk/index.d.ts @@ -3,25 +3,17 @@ // Definitions by: Alessio Paccoia // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export function pem2jwk(pem: string): RSAJWK; -export function jwk2pem(jwk: RSAJWK): string; - -export type RSAJWK = RSAPrivateJWK | RSAPublicJWK; - -export interface RSAPrivateJWK { +export interface RSA_JWK { kty: string; n: string; e: string; - d: string; - p: string; - q: string; - dp: string; - dq: string; - qi: string; + d?: string; + p?: string; + q?: string; + dp?: string; + dq?: string; + qi?: string; } -export interface RSAPublicJWK { - kty: string; - n: string; - e: string; -} +export function pem2jwk(rsa_pem: string): RSA_JWK; +export function jwk2pem(rsa_jwk: RSA_JWK): string; diff --git a/types/pem-jwk/pem-jwk-tests.ts b/types/pem-jwk/pem-jwk-tests.ts index 4d0c774d9f..8876f14373 100644 --- a/types/pem-jwk/pem-jwk-tests.ts +++ b/types/pem-jwk/pem-jwk-tests.ts @@ -1,4 +1,17 @@ -import * as pem_jwk from "pem-jwk"; +import { jwk2pem, pem2jwk, RSA_JWK } from "pem-jwk"; -pem_jwk.jwk2pem({kty: 'RSA', n: 'base64 modulus', e: 'base64 exponent'}); // $ExpectType string -pem_jwk.pem2jwk('PEM RSA String'); // $ExpectType pem_jwk.RSAJWK +const rsa_pem = `-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDh6RzHEsTFjD8NlB4echurwfV2 +Zrlcg0k2JoP0Z3QAgXPMwJynvs2LeBHYaOFzGzjXRKsvaLwc5PjP3NcqcP3KkX5y +1VA31VrJLfFbXthi0a8c/UBwxJD8i4S35OKr6yui3bJatgYWrSQ4MT9ktaS1TP9l +XBW58V4VlkypTaQTSQIDAQAB +-----END PUBLIC KEY-----`; + +const rsa_jwk: RSA_JWK = { + kty: 'RSA', + n: '4ekcxxLExYw_DZQeHnIbq8H1dma5XINJNiaD9Gd0AIFzzMCcp77Ni3gR2Gjhcxs410SrL2i8HOT4z9zXKnD9ypF-ctVQN9VayS3xW17YYtGvHP1AcMSQ_IuEt-Tiq-srot2yWrYGFq0kODE_ZLWktUz_ZVwVufFeFZZMqU2kE0k', + e: 'AQAB' +}; + +jwk2pem(rsa_jwk); // $ExpectType string +pem2jwk(rsa_pem); // $ExpectType RSA_JWK diff --git a/types/pem-jwk/tsconfig.json b/types/pem-jwk/tsconfig.json index b2562d8bae..992cd51066 100644 --- a/types/pem-jwk/tsconfig.json +++ b/types/pem-jwk/tsconfig.json @@ -6,6 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, + "strictFunctionTypes": true, "strictNullChecks": true, "baseUrl": "../", "typeRoots": [