@@ -69,29 +69,33 @@ type DecodedJwt = {
69
69
input : string
70
70
}
71
71
72
+ type Bufferable = string | Buffer
73
+
72
74
type KeyFetcher =
73
- | ( ( DecodedJwt : DecodedJwt ) => Promise < string | Buffer > )
74
- | ( ( DecodedJwt : DecodedJwt , cb : ( err : Error | TokenError | null , key : string | Buffer ) => void ) => void )
75
+ | ( ( DecodedJwt : DecodedJwt ) => Promise < Bufferable > )
76
+ | ( ( DecodedJwt : DecodedJwt , cb : ( err : Error | TokenError | null , key : Bufferable ) => void ) => void )
77
+
78
+ type SignerPayload = Bufferable | Record < string , any >
75
79
76
- declare function SignerSync ( payload : string | Buffer | { [ key : string ] : any } ) : string
77
- declare function SignerAsync ( payload : string | Buffer | { [ key : string ] : any } ) : Promise < string >
78
- declare function SignerAsync ( payload : string | Buffer | { [ key : string ] : any } , cb : SignerCallback ) : void
80
+ declare function SignerSync ( payload : SignerPayload ) : string
81
+ declare function SignerAsync ( payload : SignerPayload ) : Promise < string >
82
+ declare function SignerAsync ( payload : SignerPayload , cb : SignerCallback ) : void
79
83
80
- declare function VerifierSync ( token : string | Buffer ) : any
81
- declare function VerifierAsync ( token : string | Buffer ) : Promise < any >
82
- declare function VerifierAsync ( token : string | Buffer , cb : object ) : void
84
+ declare function VerifierSync ( token : Bufferable ) : any
85
+ declare function VerifierAsync ( token : Bufferable ) : Promise < any >
86
+ declare function VerifierAsync ( token : Bufferable , cb : VerifierCallback ) : void
83
87
84
88
export interface JwtHeader extends Record < string , any > {
85
89
alg : string | Algorithm
86
- typ ?: string | undefined
87
- cty ?: string | undefined
88
- crit ?: Array < string | Exclude < keyof JwtHeader , 'crit' > > | undefined
89
- kid ?: string | undefined
90
- jku ?: string | undefined
91
- x5u ?: string | string [ ] | undefined
92
- 'x5t#S256' ?: string | undefined
93
- x5t ?: string | undefined
94
- x5c ?: string | string [ ] | undefined
90
+ typ ?: string
91
+ cty ?: string
92
+ crit ?: Array < string | Exclude < keyof JwtHeader , 'crit' > >
93
+ kid ?: string
94
+ jku ?: string
95
+ x5u ?: string | string [ ]
96
+ 'x5t#S256' ?: string
97
+ x5t ?: string
98
+ x5c ?: string | string [ ]
95
99
}
96
100
97
101
export interface SignerOptions {
@@ -115,17 +119,20 @@ export interface DecoderOptions {
115
119
checkTyp ?: string
116
120
}
117
121
122
+ type VerifierAllowedBase = string | RegExp
123
+ type VerifierAllowed = VerifierAllowedBase | Array < VerifierAllowedBase >
124
+
118
125
export interface VerifierOptions {
119
126
algorithms ?: Algorithm [ ]
120
127
complete ?: boolean
121
128
cache ?: boolean | number
122
129
cacheTTL ?: number
123
130
errorCacheTTL ?: number | ( ( tokenError : TokenError ) => number )
124
- allowedJti ?: string | RegExp | Array < string | RegExp >
125
- allowedAud ?: string | RegExp | Array < string | RegExp >
126
- allowedIss ?: string | RegExp | Array < string | RegExp >
127
- allowedSub ?: string | RegExp | Array < string | RegExp >
128
- allowedNonce ?: string | RegExp | Array < string | RegExp >
131
+ allowedJti ?: VerifierAllowed
132
+ allowedAud ?: VerifierAllowed
133
+ allowedIss ?: VerifierAllowed
134
+ allowedSub ?: VerifierAllowed
135
+ allowedNonce ?: VerifierAllowed
129
136
ignoreExpiration ?: boolean
130
137
ignoreNotBefore ?: boolean
131
138
maxAge ?: number
@@ -136,14 +143,14 @@ export interface VerifierOptions {
136
143
}
137
144
138
145
export interface PrivateKey {
139
- key : string | Buffer
146
+ key : Bufferable
140
147
passphrase : string | undefined
141
148
}
142
149
143
150
export function createSigner (
144
- options ?: Partial < SignerOptions & { key : string | Buffer | PrivateKey } >
151
+ options ?: Partial < SignerOptions & { key : Bufferable | PrivateKey } >
145
152
) : typeof SignerSync
146
153
export function createSigner ( options ?: Partial < SignerOptions & { key : KeyFetcher } > ) : typeof SignerAsync
147
- export function createDecoder ( options ?: Partial < DecoderOptions > ) : ( token : string | Buffer ) => any
148
- export function createVerifier ( options ?: Partial < VerifierOptions & { key : string | Buffer } > ) : typeof VerifierSync
154
+ export function createDecoder ( options ?: Partial < DecoderOptions > ) : ( token : Bufferable ) => any
155
+ export function createVerifier ( options ?: Partial < VerifierOptions & { key : Bufferable } > ) : typeof VerifierSync
149
156
export function createVerifier ( options ?: Partial < VerifierOptions & { key : KeyFetcher } > ) : typeof VerifierAsync
0 commit comments