Skip to content

Commit

Permalink
feat: add named exports for all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 15, 2021
1 parent b921b9a commit 5cba6b0
Show file tree
Hide file tree
Showing 25 changed files with 141 additions and 87 deletions.
10 changes: 6 additions & 4 deletions src/jwe/compact/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ export interface CompactDecryptGetKey extends GetKeyFunction<JWEHeaderParameters
* @example
* ```js
* // ESM import
* import compactDecrypt from 'jose/jwe/compact/decrypt'
* import { compactDecrypt } from 'jose/jwe/compact/decrypt'
* ```
*
* @example
* ```js
* // CJS import
* const { default: compactDecrypt } = require('jose/jwe/compact/decrypt')
* const { compactDecrypt } = require('jose/jwe/compact/decrypt')
* ```
*
* @example
* ```js
* // usage
* import parseJwk from 'jose/jwk/parse'
* import { parseJwk } from 'jose/jwk/parse'
*
* const decoder = new TextDecoder()
* const jwe = 'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0.nyQ19eq9ogh9wA7fFtnI2oouzy5_8b5DeLkoRMfi2yijgfTs2zEnayCEofz_qhnL-nwszabd9qUeHv0-IwvhhJJS7GUJOU3ikiIe42qcIAFme1A_Fo9CTxw4XTOy-I5qanl8So91u6hwfyN1VxAqVLsSE7_23EC-gfGEg_5znew9PyXXsOIE-K_HH7IQowRrlZ1X_bM_Liu53RzDpLDvRz59mp3S8L56YqpM8FexFGTGpEaoTcEIst375qncYt3-79IVR7gZN1RWsWgjPatfvVbnh74PglQcATSf3UUhaW0OAKn6q7r3PDx6DIKQ35bgHQg5QopuN00eIfLQL2trGw.W3grIVj5HVuAb76X.6PcuDe5D6ttWFYyv0oqqdDXfI2R8wBg1F2Q80UUA_Gv8eEimNWfxIWdLxrjzgQGSvIhxmFKuLM0.a93_Ug3uZHuczj70Zavx8Q'
Expand All @@ -60,7 +60,7 @@ export interface CompactDecryptGetKey extends GetKeyFunction<JWEHeaderParameters
* console.log(decoder.decode(plaintext))
* ```
*/
export default async function compactDecrypt(
async function compactDecrypt(
jwe: string | Uint8Array,
key: KeyLike | CompactDecryptGetKey,
options?: DecryptOptions,
Expand Down Expand Up @@ -96,4 +96,6 @@ export default async function compactDecrypt(
return { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader! }
}

export { compactDecrypt }
export default compactDecrypt
export type { KeyLike, DecryptOptions }
10 changes: 6 additions & 4 deletions src/jwe/compact/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import type {
* @example
* ```js
* // ESM import
* import CompactEncrypt from 'jose/jwe/compact/encrypt'
* import { CompactEncrypt } from 'jose/jwe/compact/encrypt'
* ```
*
* @example
* ```js
* // CJS import
* const { default: CompactEncrypt } = require('jose/jwe/compact/encrypt')
* const { CompactEncrypt } = require('jose/jwe/compact/encrypt')
* ```
*
* @example
* ```js
* // usage
* import parseJwk from 'jose/jwk/parse'
* import { parseJwk } from 'jose/jwk/parse'
*
* const encoder = new TextEncoder()
*
Expand All @@ -41,7 +41,7 @@ import type {
* console.log(jwe)
* ```
*/
export default class CompactEncrypt {
class CompactEncrypt {
private _flattened: FlattenedEncrypt

/**
Expand Down Expand Up @@ -112,4 +112,6 @@ export default class CompactEncrypt {
}
}

export { CompactEncrypt }
export default CompactEncrypt
export type { KeyLike, JWEKeyManagementHeaderParameters, JWEHeaderParameters }
10 changes: 6 additions & 4 deletions src/jwe/flattened/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ export interface FlattenedDecryptGetKey
* @example
* ```js
* // ESM import
* import flattenedDecrypt from 'jose/jwe/flattened/decrypt'
* import { flattenedDecrypt } from 'jose/jwe/flattened/decrypt'
* ```
*
* @example
* ```js
* // CJS import
* const { default: flattenedDecrypt } = require('jose/jwe/flattened/decrypt')
* const { flattenedDecrypt } = require('jose/jwe/flattened/decrypt')
* ```
*
* @example
* ```js
* // usage
* import parseJwk from 'jose/jwk/parse'
* import { parseJwk } from 'jose/jwk/parse'
*
* const decoder = new TextDecoder()
* const jwe = {
Expand Down Expand Up @@ -89,7 +89,7 @@ export interface FlattenedDecryptGetKey
* console.log(decoder.decode(additionalAuthenticatedData))
* ```
*/
export default async function flattenedDecrypt(
async function flattenedDecrypt(
jwe: FlattenedJWE,
key: KeyLike | FlattenedDecryptGetKey,
options?: DecryptOptions,
Expand Down Expand Up @@ -252,4 +252,6 @@ export default async function flattenedDecrypt(
return result
}

export { flattenedDecrypt }
export default flattenedDecrypt
export type { KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions }
10 changes: 6 additions & 4 deletions src/jwe/flattened/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ const checkExtensions = validateCrit.bind(undefined, JWEInvalid, new Map())
* @example
* ```js
* // ESM import
* import FlattenedEncrypt from 'jose/jwe/flattened/encrypt'
* import { FlattenedEncrypt } from 'jose/jwe/flattened/encrypt'
* ```
*
* @example
* ```js
* // CJS import
* const { default: FlattenedEncrypt } = require('jose/jwe/flattened/encrypt')
* const { FlattenedEncrypt } = require('jose/jwe/flattened/encrypt')
* ```
*
* @example
* ```js
* // usage
* import parseJwk from 'jose/jwk/parse'
* import { parseJwk } from 'jose/jwk/parse'
*
* const encoder = new TextEncoder()
* const publicKey = await parseJwk({
Expand All @@ -57,7 +57,7 @@ const checkExtensions = validateCrit.bind(undefined, JWEInvalid, new Map())
* console.log(jwe)
* ```
*/
export default class FlattenedEncrypt {
class FlattenedEncrypt {
private _plaintext: Uint8Array

private _protectedHeader!: JWEHeaderParameters
Expand Down Expand Up @@ -321,4 +321,6 @@ export default class FlattenedEncrypt {
}
}

export { FlattenedEncrypt }
export default FlattenedEncrypt
export type { KeyLike, FlattenedJWE, JWEHeaderParameters, JWEKeyManagementHeaderParameters }
10 changes: 6 additions & 4 deletions src/jwe/general/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export interface GeneralDecryptGetKey extends GetKeyFunction<JWEHeaderParameters
* @example
* ```js
* // ESM import
* import generalDecrypt from 'jose/jwe/general/decrypt'
* import { generalDecrypt } from 'jose/jwe/general/decrypt'
* ```
*
* @example
* ```js
* // CJS import
* const { default: generalDecrypt } = require('jose/jwe/general/decrypt')
* const { generalDecrypt } = require('jose/jwe/general/decrypt')
* ```
*
* @example
* ```js
* // usage
* import parseJwk from 'jose/jwk/parse'
* import { parseJwk } from 'jose/jwk/parse'
*
* const decoder = new TextDecoder()
* const jwe = {
Expand Down Expand Up @@ -77,7 +77,7 @@ export interface GeneralDecryptGetKey extends GetKeyFunction<JWEHeaderParameters
* console.log(decoder.decode(additionalAuthenticatedData))
* ```
*/
export default async function generalDecrypt(
async function generalDecrypt(
jwe: GeneralJWE,
key: KeyLike | GeneralDecryptGetKey,
options?: DecryptOptions,
Expand Down Expand Up @@ -115,4 +115,6 @@ export default async function generalDecrypt(
throw new JWEDecryptionFailed()
}

export { generalDecrypt }
export default generalDecrypt
export type { KeyLike, GeneralJWE, DecryptOptions }
11 changes: 7 additions & 4 deletions src/jwk/embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import { JWSInvalid } from '../util/errors.js'
* @example
* ```js
* // ESM import
* import EmbeddedJWK from 'jose/jwk/embedded'
* import { EmbeddedJWK } from 'jose/jwk/embedded'
* ```
*
* @example
* ```js
* // CJS import
* const { default: EmbeddedJWK } = require('jose/jwk/embedded')
* const { EmbeddedJWK } = require('jose/jwk/embedded')
* ```
*
* @example
* ```js
* // usage
* import jwtVerify from 'jose/jwt/verify'
* import { jwtVerify } from 'jose/jwt/verify'
*
* const jwt = 'eyJqd2siOnsiY3J2IjoiUC0yNTYiLCJ4IjoiVU05ZzVuS25aWFlvdldBbE03NmNMejl2VG96UmpfX0NIVV9kT2wtZ09vRSIsInkiOiJkczhhZVF3MWwyY0RDQTdiQ2tPTnZ3REtwWEFidFhqdnFDbGVZSDhXc19VIiwia3R5IjoiRUMifSwiYWxnIjoiRVMyNTYifQ.eyJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSIsImlhdCI6MTYwNDU4MDc5NH0.60boak3_dErnW47ZPty1C0nrjeVq86EN_eK0GOq6K8w2OA0thKoBxFK4j-NuU9yZ_A9UKGxPT_G87DladBaV9g'
*
Expand All @@ -40,7 +40,7 @@ import { JWSInvalid } from '../util/errors.js'
* console.log(payload)
* ```
*/
export default async function EmbeddedJWK(
async function EmbeddedJWK(
protectedHeader: JWSHeaderParameters,
token: FlattenedJWSInput,
) {
Expand All @@ -61,3 +61,6 @@ export default async function EmbeddedJWK(

return key
}

export { EmbeddedJWK }
export default EmbeddedJWK
8 changes: 5 additions & 3 deletions src/jwk/from_key_like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import asJWK from '../runtime/key_to_jwk.js'
* @example
* ```js
* // ESM import
* import fromKeyLike from 'jose/jwk/from_key_like'
* import { fromKeyLike } from 'jose/jwk/from_key_like'
* ```
*
* @example
* ```js
* // CJS import
* const { default: fromKeyLike } = require('jose/jwk/from_key_like')
* const { fromKeyLike } = require('jose/jwk/from_key_like')
* ```
*
* @example
Expand All @@ -29,7 +29,7 @@ import asJWK from '../runtime/key_to_jwk.js'
* console.log(publicJwk)
* ```
*/
export default async function fromKeyLike(key: KeyLike): Promise<JWK> {
async function fromKeyLike(key: KeyLike): Promise<JWK> {
if (key instanceof Uint8Array) {
return {
kty: 'oct',
Expand All @@ -40,4 +40,6 @@ export default async function fromKeyLike(key: KeyLike): Promise<JWK> {
return asJWK(key)
}

export { fromKeyLike }
export default fromKeyLike
export type { KeyLike, JWK }
8 changes: 5 additions & 3 deletions src/jwk/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import type { JWK, KeyLike } from '../types.d'
* @example
* ```js
* // ESM import
* import parseJwk from 'jose/jwk/parse'
* import { parseJwk } from 'jose/jwk/parse'
* ```
*
* @example
* ```js
* // CJS import
* const { default: parseJwk } = require('jose/jwk/parse')
* const { parseJwk } = require('jose/jwk/parse')
* ```
*
* @example
Expand All @@ -47,7 +47,7 @@ import type { JWK, KeyLike } from '../types.d'
* }, 'PS256')
* ```
*/
export default async function parseJwk(
async function parseJwk(
jwk: JWK,
alg?: string,
octAsKeyObject?: boolean,
Expand Down Expand Up @@ -92,4 +92,6 @@ export default async function parseJwk(
}
}

export { parseJwk }
export default parseJwk
export type { KeyLike, JWK }
8 changes: 5 additions & 3 deletions src/jwk/thumbprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const check = (value: any, description: string) => {
* @example
* ```js
* // ESM import
* import calculateThumbprint from 'jose/jwk/thumbprint'
* import { calculateThumbprint } from 'jose/jwk/thumbprint'
* ```
*
* @example
* ```js
* // CJS import
* const { default: calculateThumbprint } = require('jose/jwk/thumbprint')
* const { calculateThumbprint } = require('jose/jwk/thumbprint')
* ```
*
* @example
Expand All @@ -44,7 +44,7 @@ const check = (value: any, description: string) => {
* console.log(thumbprint)
* ```
*/
export default async function calculateThumbprint(
async function calculateThumbprint(
jwk: JWK,
digestAlgorithm: 'sha256' | 'sha384' | 'sha512' = 'sha256',
): Promise<string> {
Expand Down Expand Up @@ -82,4 +82,6 @@ export default async function calculateThumbprint(
return base64url(await digest(digestAlgorithm, data))
}

export { calculateThumbprint }
export default calculateThumbprint
export type { JWK }
11 changes: 7 additions & 4 deletions src/jwks/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,19 @@ class RemoteJWKSet {
* @example
* ```js
* // ESM import
* import createRemoteJWKSet from 'jose/jwks/remote'
* import { createRemoteJWKSet } from 'jose/jwks/remote'
* ```
*
* @example
* ```js
* // CJS import
* const { default: createRemoteJWKSet } = require('jose/jwks/remote')
* const { createRemoteJWKSet } = require('jose/jwks/remote')
* ```
*
* @example
* ```js
* // usage
* import jwtVerify from 'jose/jwt/verify'
* import { jwtVerify } from 'jose/jwt/verify'
*
* const JWKS = createRemoteJWKSet(new URL('https://www.googleapis.com/oauth2/v3/certs'))
*
Expand All @@ -242,10 +242,13 @@ class RemoteJWKSet {
* @param url URL to fetch the JSON Web Key Set from.
* @param options Options for the remote JSON Web Key Set.
*/
export default function createRemoteJWKSet(
function createRemoteJWKSet(
url: URL,
options?: RemoteJWKSetOptions,
): GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
const set = new RemoteJWKSet(url, options)
return set.getKey.bind(set)
}

export { createRemoteJWKSet }
export default createRemoteJWKSet
Loading

0 comments on commit 5cba6b0

Please sign in to comment.