Skip to content

Commit e8075e6

Browse files
📝 Add docstrings to feat/evault-provisioning-via-phone
Docstrings generation was requested by @coodos. * #188 (comment) The following files were modified: * `infrastructure/eid-wallet/src/lib/utils/capitalize.ts` * `infrastructure/evault-provisioner/src/utils/hmac.ts`
1 parent 5992cac commit e8075e6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

infrastructure/eid-wallet/src/lib/utils/capitalize.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Returns a new string with the first letter of each word in uppercase and the remaining letters in lowercase.
3+
*
4+
* @param str - The input string to capitalize.
5+
* @returns The capitalized string.
6+
*/
17
export function capitalize(str: string) {
28
return str
39
.toLowerCase()

infrastructure/evault-provisioner/src/utils/hmac.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import { createHmac } from "crypto";
22

3+
/**
4+
* Generates an HMAC SHA-256 signature for a JSON-serializable object using the provided secret key.
5+
*
6+
* @param body - The object to be signed.
7+
* @param secret - The secret key used for HMAC generation.
8+
* @returns The hexadecimal string representation of the HMAC signature.
9+
*/
310
export function createHmacSignature(body: Record<string, any>, secret: string) {
411
return createHmac("sha256", secret)
512
.update(JSON.stringify(body))
613
.digest("hex");
714
}
815

16+
/**
17+
* Verifies that a provided HMAC signature matches the expected signature for a given object and secret key.
18+
*
19+
* @param body - The object whose signature is to be verified.
20+
* @param signature - The HMAC signature to compare against.
21+
* @param secret - The secret key used to generate the expected signature.
22+
* @returns `true` if the signature is valid; otherwise, `false`.
23+
*/
924
export function verifyHmacSignature(
1025
body: Record<string, any>,
1126
signature: string,

0 commit comments

Comments
 (0)