Skip to content

Commit

Permalink
feat(typescript): export consume module interface types (#213)
Browse files Browse the repository at this point in the history
Co-authored-by: Filip Skokan <[email protected]>
  • Loading branch information
codyebberson and panva authored Jun 22, 2021
1 parent e431c50 commit 0c0bd6c
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
"test-webcrypto": "WEBCRYPTO=true npm test"
},
"devDependencies": {
"@types/node": "^15.0.1",
"@types/node": "^15.12.4",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"ava": "^3.13.0",
"bowser": "^2.11.0",
Expand Down
2 changes: 1 addition & 1 deletion src/jwe/compact/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ async function compactDecrypt(

export { compactDecrypt }
export default compactDecrypt
export type { KeyLike, DecryptOptions }
export type { KeyLike, DecryptOptions, CompactDecryptResult }
2 changes: 1 addition & 1 deletion src/jwe/flattened/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,4 @@ async function flattenedDecrypt(

export { flattenedDecrypt }
export default flattenedDecrypt
export type { KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions }
export type { KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions, FlattenedDecryptResult }
2 changes: 1 addition & 1 deletion src/jwe/general/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ async function generalDecrypt(

export { generalDecrypt }
export default generalDecrypt
export type { KeyLike, GeneralJWE, DecryptOptions }
export type { KeyLike, GeneralJWE, DecryptOptions, GeneralDecryptResult }
2 changes: 1 addition & 1 deletion src/jws/compact/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ async function compactVerify(

export { compactVerify }
export default compactVerify
export type { KeyLike, VerifyOptions }
export type { KeyLike, VerifyOptions, CompactVerifyResult }
9 changes: 8 additions & 1 deletion src/jws/flattened/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,11 @@ async function flattenedVerify(

export { flattenedVerify }
export default flattenedVerify
export type { KeyLike, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, VerifyOptions }
export type {
KeyLike,
FlattenedJWSInput,
GetKeyFunction,
JWSHeaderParameters,
VerifyOptions,
FlattenedVerifyResult,
}
2 changes: 1 addition & 1 deletion src/jws/general/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ async function generalVerify(

export { generalVerify }
export default generalVerify
export type { KeyLike, GeneralJWSInput, VerifyOptions }
export type { KeyLike, GeneralJWSInput, VerifyOptions, GeneralVerifyResult }
2 changes: 1 addition & 1 deletion src/jwt/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ async function jwtDecrypt(

export { jwtDecrypt }
export default jwtDecrypt
export type { KeyLike, DecryptOptions, JWTPayload, JWTDecryptOptions }
export type { KeyLike, DecryptOptions, JWTPayload, JWTDecryptOptions, JWTDecryptResult }
12 changes: 7 additions & 5 deletions src/jwt/unsecured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { JWTInvalid } from '../util/errors.js'
import jwtPayload from '../lib/jwt_claims_set.js'
import ProduceJWT from '../lib/jwt_producer.js'

interface UnsecuredResult {
payload: JWTPayload
header: JWSHeaderParameters
}

/**
* The UnsecuredJWT class is a utility for dealing with `{ "alg": "none" }` Unsecured JWTs.
*
Expand Down Expand Up @@ -59,10 +64,7 @@ class UnsecuredJWT extends ProduceJWT {
* @param jwt Unsecured JWT to decode the payload of.
* @param options JWT Claims Set validation options.
*/
static decode(
jwt: string,
options?: JWTClaimVerificationOptions,
): { payload: JWTPayload; header: JWSHeaderParameters } {
static decode(jwt: string, options?: JWTClaimVerificationOptions): UnsecuredResult {
if (typeof jwt !== 'string') {
throw new JWTInvalid('Unsecured JWT must be a string')
}
Expand All @@ -88,4 +90,4 @@ class UnsecuredJWT extends ProduceJWT {

export { UnsecuredJWT }
export default UnsecuredJWT
export type { JWSHeaderParameters, JWTPayload }
export type { JWSHeaderParameters, JWTPayload, UnsecuredResult }
9 changes: 8 additions & 1 deletion src/jwt/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ async function jwtVerify(

export { jwtVerify }
export default jwtVerify
export type { KeyLike, JWTPayload, JWTVerifyOptions, JWSHeaderParameters, GetKeyFunction }
export type {
KeyLike,
JWTPayload,
JWTVerifyOptions,
JWSHeaderParameters,
GetKeyFunction,
JWTVerifyResult,
}
1 change: 0 additions & 1 deletion src/runtime/node/check_modulus_length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const getModulusLength = (key: KeyObject): number => {
}

const modulusLength: number =
// @ts-expect-error
key.asymmetricKeyDetails?.modulusLength ??
(getLengthOfSeqIndex(
key.export({ format: 'der', type: 'pkcs1' }),
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/webcrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (util.types.isCryptoKey) {
} else if (webcrypto) {
impl = function isCryptoKey(obj): obj is CryptoKey {
//@ts-expect-error
return obj != null && obj instanceof webcrypto.CryptoKey;
return obj != null && obj instanceof webcrypto.CryptoKey
}
} else {
// @ts-expect-error
Expand Down
4 changes: 2 additions & 2 deletions src/util/decode_protected_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ function decodeProtectedHeader(token: string | object) {

try {
if (typeof protectedB64u !== 'string' || !protectedB64u) {
throw new Error();
throw new Error()
}
const result = JSON.parse(decoder.decode(base64url(protectedB64u!)))
if (!isObject(result)) {
throw new Error();
throw new Error()
}
return <ProtectedHeaderParameters>result
} catch (err) {
Expand Down

0 comments on commit 0c0bd6c

Please sign in to comment.