Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary async keyword from getHashedName function #14

Open
martincode515 opened this issue Apr 26, 2023 · 0 comments
Open

Remove unnecessary async keyword from getHashedName function #14

martincode515 opened this issue Apr 26, 2023 · 0 comments

Comments

@martincode515
Copy link

martincode515 commented Apr 26, 2023

Issue description:

The getHashedName function in the tld-parser/src/utils.ts file is marked as async, but it does not contain any asynchronous operations, such as await. The sha256 function looks to be synchronous, and no asynchronous actions look like they are being performed within the function. The async keyword can be removed from the function declaration to avoid confusion.

Affected code:

The issue can be found in the tld-parser/src/utils.ts file on line 66:

export async function getHashedName(name: string): Promise<Buffer> {
    const input = NameRecordHeader.HASH_PREFIX + name;
    const str = sha256(Buffer.from(input, 'utf8')).slice(2);
    return Buffer.from(str, 'hex');
}

Proposed change:

Remove the async keyword from the function declaration and update the function signature:

export function getHashedName(name: string): Buffer {
    const input = NameRecordHeader.HASH_PREFIX + name;
    const str = sha256(Buffer.from(input, 'utf8')).slice(2);
    return Buffer.from(str, 'hex');
}

Impact:

This change shouldn't affect its functionality, may prevent potential misunderstandings related to the use of the async keyword.

TypeScript is going to complain / warn about the await no longer being needed given the signature changed to Buffer now, so other functions and methods awaiting or using .then() on this function don't need to, will help with code clarity removing await from other methods / functions using this function across the library anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant