Skip to content

Commit 092df1a

Browse files
authored
fix: Checking the type of useHash and useHmac (#58)
* fix: Checking the type of useHash and useHmac * chore: Return to Labeled Tuple. * fix: useHmac type referred to HashAlgorithms, so make it HmacAlgorithms.
1 parent 41c6fee commit 092df1a

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

index.d.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@ declare namespace RNHash {
2929

3030
export namespace CONSTANTS {
3131
export namespace HashAlgorithms {
32-
export const md2: string;
33-
export const md5: string;
34-
export const sha1: string;
35-
export const sha224: string;
36-
export const sha256: string;
37-
export const sha384: string;
38-
export const sha512: string;
39-
export const keccak: string;
32+
export const md2: 'MD2';
33+
export const md5: 'MD5';
34+
export const sha1: 'SHA-1';
35+
export const sha224: 'SHA-224';
36+
export const sha256: 'SHA-256';
37+
export const sha384: 'SHA-384';
38+
export const sha512: 'SHA-512';
39+
export const keccak: 'keccak';
4040
}
4141
export namespace HmacAlgorithms {
42-
export const HmacMD5: string;
43-
export const HmacSHA1: string;
44-
export const HmacSHA224: string;
45-
export const HmacSHA256: string;
46-
export const HmacSHA384: string;
47-
export const HmacSHA512: string;
48-
export const PBEwithHmacSHA: string;
49-
export const PBEwithHmacSHA1: string;
50-
export const PBEwithHmacSHA224: string;
51-
export const PBEwithHmacSHA256: string;
52-
export const PBEwithHmacSHA384: string;
53-
export const PBEwithHmacSHA512: string;
42+
export const HmacMD5: 'HmacMD5';
43+
export const HmacSHA1: 'HmacSHA1';
44+
export const HmacSHA224: 'HmacSHA224';
45+
export const HmacSHA256: 'HmacSHA256';
46+
export const HmacSHA384: 'HmacSHA384';
47+
export const HmacSHA512: 'HmacSHA512';
48+
export const PBEwithHmacSHA: 'PBEwithHmacSHA';
49+
export const PBEwithHmacSHA1: 'PBEwithHmacSHA1';
50+
export const PBEwithHmacSHA224: 'PBEwithHmacSHA224';
51+
export const PBEwithHmacSHA256: 'PBEwithHmacSHA256';
52+
export const PBEwithHmacSHA384: 'PBEwithHmacSHA384';
53+
export const PBEwithHmacSHA512: 'PBEwithHmacSHA512';
5454
}
5555
export namespace Events {
5656
export const onBatchReccieved: string;
@@ -65,18 +65,18 @@ export function JSHash(message: string, algorithm: string): Promise<string>;
6565
export function JSHmac(message: string, secret: string, algorithm: string): Promise<string>;
6666

6767
export function useHash(
68-
hmacAlgo?: CONSTANTS.HashAlgorithms = CONSTANTS.HashAlgorithms.md5,
69-
initialMessage: ?string = "hello World"
68+
hmacAlgo?: typeof CONSTANTS.HashAlgorithms[keyof typeof CONSTANTS.HashAlgorithms],
69+
initialMessage?: string
7070
): [
7171
hashed: string,
7272
setMessage: (message: string) => Promise<void>,
7373
setAlgo: (algo: string) => Promise<void>
7474
];
7575

7676
export function useHmac(
77-
hmacAlgo?: CONSTANTS.HmacAlgorithms = CONSTANTS.HmacAlgorithms.HmacMD5,
78-
initialMessage: ?string = "hello World",
79-
initialSecret: ?string = "SecretKey"
77+
hmacAlgo?: typeof CONSTANTS.HmacAlgorithms[keyof typeof CONSTANTS.HmacAlgorithms],
78+
initialMessage?: string,
79+
initialSecret?: string
8080
): [
8181
hashed: string,
8282
setMessage: (message: string) => Promise<void>,

0 commit comments

Comments
 (0)