Skip to content

Commit

Permalink
refactor(types): add explicit type to all exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 29, 2024
1 parent ecc9701 commit 76e8d19
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ export async function processDiscoveryResponse(
/**
* Generates 32 random bytes and encodes them using base64url.
*/
function randomBytes() {
function randomBytes(): string {
return b64u(crypto.getRandomValues(new Uint8Array(32)))
}

Expand All @@ -1167,7 +1167,7 @@ function randomBytes() {
*
* @see [RFC 7636 - Proof Key for Code Exchange (PKCE)](https://www.rfc-editor.org/rfc/rfc7636.html#section-4)
*/
export function generateRandomCodeVerifier() {
export function generateRandomCodeVerifier(): string {
return randomBytes()
}

Expand All @@ -1178,7 +1178,7 @@ export function generateRandomCodeVerifier() {
*
* @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1.1)
*/
export function generateRandomState() {
export function generateRandomState(): string {
return randomBytes()
}

Expand All @@ -1189,7 +1189,7 @@ export function generateRandomState() {
*
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#IDToken)
*/
export function generateRandomNonce() {
export function generateRandomNonce(): string {
return randomBytes()
}

Expand All @@ -1205,7 +1205,7 @@ export function generateRandomNonce() {
*
* @see [RFC 7636 - Proof Key for Code Exchange (PKCE)](https://www.rfc-editor.org/rfc/rfc7636.html#section-4)
*/
export async function calculatePKCECodeChallenge(codeVerifier: string) {
export async function calculatePKCECodeChallenge(codeVerifier: string): Promise<string> {
if (!validateString(codeVerifier)) {
throw new TypeError('"codeVerifier" must be a non-empty string')
}
Expand Down Expand Up @@ -1567,7 +1567,7 @@ export async function issueRequestObject(
client: Client,
parameters: URLSearchParams | Record<string, string> | string[][],
privateKey: CryptoKey | PrivateKey,
) {
): Promise<string> {
assertAs(as)
assertClient(client)

Expand Down Expand Up @@ -4252,7 +4252,10 @@ export interface GenerateKeyPairOptions {
*
* @group Utilities
*/
export async function generateKeyPair(alg: JWSAlgorithm, options?: GenerateKeyPairOptions) {
export async function generateKeyPair(
alg: JWSAlgorithm,
options?: GenerateKeyPairOptions,
): Promise<CryptoKeyPair> {
if (!validateString(alg)) {
throw new TypeError('"alg" must be a non-empty string')
}
Expand Down Expand Up @@ -4456,7 +4459,7 @@ export async function validateJwtAccessToken(
request: Request,
expectedAudience: string,
options?: ValidateJWTAccessTokenOptions,
) {
): Promise<JWTAccessTokenClaims> {
assertAs(as)

if (!looseInstanceOf(request, Request)) {
Expand Down

0 comments on commit 76e8d19

Please sign in to comment.