Skip to content

Commit

Permalink
fix(types): add missing index signature on the convenience JWK types
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Sep 13, 2024
1 parent 092dadf commit 90a93dc
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/interfaces/types.CompactJWEHeaderParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ___

### jwk

`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"crv"`` \| ``"e"`` \| ``"n"`` \| ``"kty"``\>
`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"kty"`` \| ``"crv"`` \| ``"e"`` \| ``"n"``\>

"jwk" (JSON Web Key) Header Parameter.

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/types.CompactJWSHeaderParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ___

### jwk

`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"crv"`` \| ``"e"`` \| ``"n"`` \| ``"kty"``\>
`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"kty"`` \| ``"crv"`` \| ``"e"`` \| ``"n"``\>

"jwk" (JSON Web Key) Header Parameter.

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/types.JWEHeaderParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ___

### jwk

`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"crv"`` \| ``"e"`` \| ``"n"`` \| ``"kty"``\>
`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"kty"`` \| ``"crv"`` \| ``"e"`` \| ``"n"``\>

"jwk" (JSON Web Key) Header Parameter.

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/types.JWSHeaderParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ___

### jwk

`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"crv"`` \| ``"e"`` \| ``"n"`` \| ``"kty"``\>
`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"kty"`` \| ``"crv"`` \| ``"e"`` \| ``"n"``\>

"jwk" (JSON Web Key) Header Parameter.

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/types.JWTHeaderParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ___

### jwk

`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"crv"`` \| ``"e"`` \| ``"n"`` \| ``"kty"``\>
`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"kty"`` \| ``"crv"`` \| ``"e"`` \| ``"n"``\>

"jwk" (JSON Web Key) Header Parameter.

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/types.JoseHeaderParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ___

### jwk

`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"crv"`` \| ``"e"`` \| ``"n"`` \| ``"kty"``\>
`Optional` **jwk**: [`Pick`]( https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys )\<[`JWK`](types.JWK.md), ``"x"`` \| ``"y"`` \| ``"kty"`` \| ``"crv"`` \| ``"e"`` \| ``"n"``\>

"jwk" (JSON Web Key) Header Parameter.

Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ export * as base64url from './util/base64url.js'
export type {
KeyLike,
JWK,
JWKParameters,
JWK_OKP_Public,
JWK_OKP_Private,
JWK_EC_Public,
JWK_EC_Private,
JWK_RSA_Public,
JWK_RSA_Private,
JWK_oct,
FlattenedJWSInput,
GeneralJWSInput,
FlattenedJWS,
Expand Down
16 changes: 16 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ 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 @@ -129,12 +131,16 @@ 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 @@ -145,12 +151,16 @@ 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 @@ -159,6 +169,8 @@ 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 @@ -181,12 +193,16 @@ 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
12 changes: 9 additions & 3 deletions test/types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ expectType<lib.KeyLike>(await lib.importX509('', 'RS256'))
expectType<CryptoKey>(await lib.importX509<CryptoKey>('', 'RS256'))
expectType<KeyObject>(await lib.importX509<KeyObject>('', 'RS256'))

expectType<lib.KeyLike | Uint8Array>(await lib.importJWK({ kty: 'RSA' }))
expectType<CryptoKey | Uint8Array>(await lib.importJWK<CryptoKey>({ kty: 'RSA' }))
expectType<KeyObject | Uint8Array>(await lib.importJWK<KeyObject>({ kty: 'RSA' }))
expectType<lib.KeyLike | Uint8Array>(
await lib.importJWK(<lib.JWK_OKP_Public>{ kty: 'OKP', crv: '', x: '' }),
)
expectType<CryptoKey | Uint8Array>(
await lib.importJWK<CryptoKey>(<lib.JWK_OKP_Public>{ kty: 'OKP', crv: '', x: '' }),
)
expectType<KeyObject | Uint8Array>(
await lib.importJWK<KeyObject>(<lib.JWK_OKP_Public>{ kty: 'OKP', crv: '', x: '' }),
)

{
const result = await lib.jwtVerify('', lib.createLocalJWKSet({ keys: [] }))
Expand Down

0 comments on commit 90a93dc

Please sign in to comment.