cas-typescript-sdk 1.0.34 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +1 -1
- package/README.md +3 -3
- package/index.d.ts +0 -12
- package/index.node +0 -0
- package/lib/hashers/blake2-wrapper.d.ts +0 -26
- package/lib/hashers/blake2-wrapper.js +0 -34
- package/lib/message/hmac.d.ts +0 -2
- package/lib/message/hmac.js +0 -21
- package/lib/password-hashers/argon2-wrapper.d.ts +0 -13
- package/lib/password-hashers/argon2-wrapper.js +0 -26
- package/lib/password-hashers/bcrypt-wrapper.d.ts +0 -13
- package/lib/password-hashers/bcrypt-wrapper.js +0 -23
- package/lib/password-hashers/password-hasher-base.d.ts +0 -2
- package/lib/password-hashers/scrypt-wrapper.d.ts +0 -13
- package/lib/password-hashers/scrypt-wrapper.js +0 -23
- package/package.json +1 -1
- package/src/hashers/blake2.rs +0 -67
- package/src/hybrid/hpke.rs +0 -0
- package/src/hybrid/types.rs +0 -0
- package/src/lib.rs +5 -0
- package/src/message/hmac.rs +0 -19
- package/src/password_hashers/argon2.rs +0 -26
- package/src/password_hashers/bcrypt.rs +0 -25
- package/src/password_hashers/scrypt.rs +0 -25
- package/src-ts/hashers/blake2-wrapper.ts +1 -41
- package/src-ts/message/hmac.ts +1 -24
- package/src-ts/password-hashers/argon2-wrapper.ts +1 -30
- package/src-ts/password-hashers/bcrypt-wrapper.ts +1 -28
- package/src-ts/password-hashers/password-hasher-base.ts +0 -2
- package/src-ts/password-hashers/scrypt-wrapper.ts +1 -28
- package/test-ts/hasher.test.spec.ts +0 -64
- package/test-ts/hmac.test.spec.ts +0 -16
- package/test-ts/password-hasher.test.spec.ts +1 -50
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -6,18 +6,18 @@ Ever wanted all of your most useful cryptographic operations in one module and n
|
|
|
6
6
|
CAS is here to provide a unified development experience as an abstract layer to the RustCrypto and Dalek-Cryptography suite of algorithms.
|
|
7
7
|
The official NPM page can be found [here](https://www.npmjs.com/package/cas-typescript-sdk).
|
|
8
8
|
|
|
9
|
-
**Note: All work is experimental and we understand some benchmarks might not be the most optimal
|
|
9
|
+
**Note: All work is experimental and we understand some benchmarks might not be the most optimal.**
|
|
10
10
|
|
|
11
11
|
## Consuming Library Documentation
|
|
12
|
-
This Node.js NPM module is dependent on our Rust layer [cas-lib](https://github.com/Cryptographic-API-Services/cas-lib)
|
|
12
|
+
This Node.js NPM module is dependent on our Rust layer [cas-lib](https://github.com/Cryptographic-API-Services/cas-lib) that contains methods to run industry-standard cryptographic operations.
|
|
13
13
|
|
|
14
14
|
We utilize some smart people's existing work and we believe their documentation should be reviewed when possible.
|
|
15
15
|
- [Spin Research](https://github.com/SpinResearch)
|
|
16
16
|
- [Dalek-Cryptography](https://github.com/dalek-cryptography)
|
|
17
17
|
- [Rust Crypto](https://github.com/RustCrypto)
|
|
18
|
-
- [Rayon](https://github.com/rayon-rs/rayon)
|
|
19
18
|
|
|
20
19
|
## [Examples](./docs/EXAMPLES.md)
|
|
21
20
|
|
|
22
21
|
## Disclaimer
|
|
23
22
|
Many of the cryptographic crates that are utilized in our core FFI [layer](./src) have never had a security audit performed. Utilize this SDK at your own risk.
|
|
23
|
+
|
package/index.d.ts
CHANGED
|
@@ -4,29 +4,19 @@
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
6
|
export declare function argon2Hash(password: string): string
|
|
7
|
-
export declare function argon2HashThreadPool(password: string): string
|
|
8
7
|
export declare function argon2Verify(hashedPassword: string, passwordToVerify: string): boolean
|
|
9
|
-
export declare function argon2VerifyThreadpool(hashedPassword: string, passwordToVerify: string): boolean
|
|
10
8
|
export declare function bcryptHash(passwordToHash: string): string
|
|
11
|
-
export declare function bcryptHashThreadpool(passwordToHash: string): string
|
|
12
9
|
export declare function bcryptVerify(hashedPassword: string, passwordToVerify: string): boolean
|
|
13
|
-
export declare function bcryptVerifyThreadpool(passwordToHash: string, passwordToVerify: string): boolean
|
|
14
10
|
export declare function scryptHash(passwordToHash: string): string
|
|
15
11
|
export declare function scryptVerify(hashedPassword: string, passwordToVerify: string): boolean
|
|
16
|
-
export declare function scryptHashThreadpool(passwordToHash: string): string
|
|
17
|
-
export declare function scryptVerifyThreadpool(hashedPassword: string, passwordToVerify: string): boolean
|
|
18
12
|
export declare function sha512(dataToHash: Array<number>): Array<number>
|
|
19
13
|
export declare function sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
20
14
|
export declare function sha256(dataToHash: Array<number>): Array<number>
|
|
21
15
|
export declare function sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
22
16
|
export declare function blake2Sha512(dataToHash: Array<number>): Array<number>
|
|
23
|
-
export declare function blake2Sha512Threadpool(dataToHash: Array<number>): Array<number>
|
|
24
17
|
export declare function blake2Sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
25
|
-
export declare function blake2Sha512VerifyThreadpool(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
26
18
|
export declare function blake2Sha256(dataToHash: Array<number>): Array<number>
|
|
27
|
-
export declare function blake2Sha256Threadpool(dataToHash: Array<number>): Array<number>
|
|
28
19
|
export declare function blake2Sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
29
|
-
export declare function blake2Sha256VerifyThreadpool(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
30
20
|
export declare function x25519GenerateSecretAndPublicKey(): CASx25519SecretPublicKeyResult
|
|
31
21
|
export declare function x25519DiffieHellman(mySecretKey: Array<number>, usersPublicKey: Array<number>): Array<number>
|
|
32
22
|
export declare function aesNonce(): Array<number>
|
|
@@ -54,9 +44,7 @@ export declare function ascon128NonceGenerate(): Array<number>
|
|
|
54
44
|
export declare function ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
|
|
55
45
|
export declare function ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
|
|
56
46
|
export declare function hmacSign(key: Array<number>, message: Array<number>): Array<number>
|
|
57
|
-
export declare function hmacSignThreadpool(key: Array<number>, message: Array<number>): Array<number>
|
|
58
47
|
export declare function hmacVerify(key: Array<number>, message: Array<number>, signature: Array<number>): boolean
|
|
59
|
-
export declare function hmacVerifyThreadpool(key: Array<number>, message: Array<number>, signature: Array<number>): boolean
|
|
60
48
|
export type CASx25519SecretPublicKeyResult = CaSx25519SecretPublicKeyResult
|
|
61
49
|
export declare class CaSx25519SecretPublicKeyResult {
|
|
62
50
|
publicKey: Array<number>
|
package/index.node
CHANGED
|
Binary file
|
|
@@ -6,12 +6,6 @@ export declare class Blake2Wrapper implements IHasherBase {
|
|
|
6
6
|
* @returns The hashed output
|
|
7
7
|
*/
|
|
8
8
|
hash512(dataToHash: number[]): number[];
|
|
9
|
-
/**
|
|
10
|
-
* Hashes the input data using Blake2b 512 in a thread pool
|
|
11
|
-
* @param dataToHash The data to hash
|
|
12
|
-
* @returns The hashed output
|
|
13
|
-
*/
|
|
14
|
-
hash512Threadpool(dataToHash: number[]): number[];
|
|
15
9
|
/**
|
|
16
10
|
* Verifies the input data against the hashed output using Blake2b 512
|
|
17
11
|
* @param dataToHash The data to hash
|
|
@@ -19,25 +13,12 @@ export declare class Blake2Wrapper implements IHasherBase {
|
|
|
19
13
|
* @returns True if the verification is successful, false otherwise
|
|
20
14
|
*/
|
|
21
15
|
verify512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Verifies the input data against the hashed output using Blake2b 512 in a thread pool
|
|
24
|
-
* @param dataToHash The data to hash
|
|
25
|
-
* @param dataToVerify The data to verify
|
|
26
|
-
* @returns True if the verification is successful, false otherwise
|
|
27
|
-
*/
|
|
28
|
-
verify512Threadpool(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
29
16
|
/**
|
|
30
17
|
* Hashes the input data using Blake2b 256
|
|
31
18
|
* @param dataToHash The data to hash
|
|
32
19
|
* @returns The hashed output
|
|
33
20
|
*/
|
|
34
21
|
hash256(dataToHash: number[]): number[];
|
|
35
|
-
/**
|
|
36
|
-
* Hashes the input data using Blake2b 256 in a thread pool
|
|
37
|
-
* @param dataToHash The data to hash
|
|
38
|
-
* @returns The hashed output
|
|
39
|
-
*/
|
|
40
|
-
hash256Threadpool(dataToHash: number[]): number[];
|
|
41
22
|
/**
|
|
42
23
|
* Verifies the input data against the hashed output using Blake2b 256
|
|
43
24
|
* @param dataToHash The data to hash
|
|
@@ -45,11 +26,4 @@ export declare class Blake2Wrapper implements IHasherBase {
|
|
|
45
26
|
* @returns True if the verification is successful, false otherwise
|
|
46
27
|
*/
|
|
47
28
|
verify256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Verifies the input data against the hashed output using Blake2b 256 in a thread pool
|
|
50
|
-
* @param dataToHash The data to hash
|
|
51
|
-
* @param dataToVerify The data to verify
|
|
52
|
-
* @returns True if the verification is successful, false otherwise
|
|
53
|
-
*/
|
|
54
|
-
verify256Threadpool(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
55
29
|
}
|
|
@@ -11,14 +11,6 @@ class Blake2Wrapper {
|
|
|
11
11
|
hash512(dataToHash) {
|
|
12
12
|
return (0, index_1.blake2Sha512)(dataToHash);
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Hashes the input data using Blake2b 512 in a thread pool
|
|
16
|
-
* @param dataToHash The data to hash
|
|
17
|
-
* @returns The hashed output
|
|
18
|
-
*/
|
|
19
|
-
hash512Threadpool(dataToHash) {
|
|
20
|
-
return (0, index_1.blake2Sha512Threadpool)(dataToHash);
|
|
21
|
-
}
|
|
22
14
|
/**
|
|
23
15
|
* Verifies the input data against the hashed output using Blake2b 512
|
|
24
16
|
* @param dataToHash The data to hash
|
|
@@ -28,15 +20,6 @@ class Blake2Wrapper {
|
|
|
28
20
|
verify512(dataToHash, dataToVerify) {
|
|
29
21
|
return (0, index_1.blake2Sha512Verify)(dataToHash, dataToVerify);
|
|
30
22
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Verifies the input data against the hashed output using Blake2b 512 in a thread pool
|
|
33
|
-
* @param dataToHash The data to hash
|
|
34
|
-
* @param dataToVerify The data to verify
|
|
35
|
-
* @returns True if the verification is successful, false otherwise
|
|
36
|
-
*/
|
|
37
|
-
verify512Threadpool(dataToHash, dataToVerify) {
|
|
38
|
-
return (0, index_1.blake2Sha512VerifyThreadpool)(dataToHash, dataToVerify);
|
|
39
|
-
}
|
|
40
23
|
/**
|
|
41
24
|
* Hashes the input data using Blake2b 256
|
|
42
25
|
* @param dataToHash The data to hash
|
|
@@ -45,14 +28,6 @@ class Blake2Wrapper {
|
|
|
45
28
|
hash256(dataToHash) {
|
|
46
29
|
return (0, index_1.blake2Sha256)(dataToHash);
|
|
47
30
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Hashes the input data using Blake2b 256 in a thread pool
|
|
50
|
-
* @param dataToHash The data to hash
|
|
51
|
-
* @returns The hashed output
|
|
52
|
-
*/
|
|
53
|
-
hash256Threadpool(dataToHash) {
|
|
54
|
-
return (0, index_1.blake2Sha256Threadpool)(dataToHash);
|
|
55
|
-
}
|
|
56
31
|
/**
|
|
57
32
|
* Verifies the input data against the hashed output using Blake2b 256
|
|
58
33
|
* @param dataToHash The data to hash
|
|
@@ -62,14 +37,5 @@ class Blake2Wrapper {
|
|
|
62
37
|
verify256(dataToHash, dataToVerify) {
|
|
63
38
|
return (0, index_1.blake2Sha256Verify)(dataToHash, dataToVerify);
|
|
64
39
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Verifies the input data against the hashed output using Blake2b 256 in a thread pool
|
|
67
|
-
* @param dataToHash The data to hash
|
|
68
|
-
* @param dataToVerify The data to verify
|
|
69
|
-
* @returns True if the verification is successful, false otherwise
|
|
70
|
-
*/
|
|
71
|
-
verify256Threadpool(dataToHash, dataToVerify) {
|
|
72
|
-
return (0, index_1.blake2Sha256VerifyThreadpool)(dataToHash, dataToVerify);
|
|
73
|
-
}
|
|
74
40
|
}
|
|
75
41
|
exports.Blake2Wrapper = Blake2Wrapper;
|
package/lib/message/hmac.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export declare class HmacWrapper {
|
|
2
2
|
hmacSignBytes(key: Array<number>, message: Array<number>): Array<number>;
|
|
3
3
|
hmacVerifyBytes(key: Array<number>, message: Array<number>, signature: Array<number>): boolean;
|
|
4
|
-
hmacSignBytesThreadpool(key: Array<number>, message: Array<number>): Array<number>;
|
|
5
|
-
hmacVerifyBytesThreadpool(key: Array<number>, message: Array<number>, signature: Array<number>): boolean;
|
|
6
4
|
}
|
package/lib/message/hmac.js
CHANGED
|
@@ -24,26 +24,5 @@ class HmacWrapper {
|
|
|
24
24
|
}
|
|
25
25
|
return (0, index_1.hmacVerify)(key, message, signature);
|
|
26
26
|
}
|
|
27
|
-
hmacSignBytesThreadpool(key, message) {
|
|
28
|
-
if (key?.length === 0) {
|
|
29
|
-
throw new Error("Must provide an allocated key");
|
|
30
|
-
}
|
|
31
|
-
if (message?.length === 0) {
|
|
32
|
-
throw new Error("Must provide an allocated message");
|
|
33
|
-
}
|
|
34
|
-
return (0, index_1.hmacSignThreadpool)(key, message);
|
|
35
|
-
}
|
|
36
|
-
hmacVerifyBytesThreadpool(key, message, signature) {
|
|
37
|
-
if (key?.length === 0) {
|
|
38
|
-
throw new Error("Must provide an allocated key");
|
|
39
|
-
}
|
|
40
|
-
if (message?.length === 0) {
|
|
41
|
-
throw new Error("Must provide an allocated message");
|
|
42
|
-
}
|
|
43
|
-
if (signature?.length === 0) {
|
|
44
|
-
throw new Error("Must provide an allocated signature");
|
|
45
|
-
}
|
|
46
|
-
return (0, index_1.hmacVerifyThreadpool)(key, message, signature);
|
|
47
|
-
}
|
|
48
27
|
}
|
|
49
28
|
exports.HmacWrapper = HmacWrapper;
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class Argon2Wrapper implements IPasswordHasherBase {
|
|
3
|
-
/**
|
|
4
|
-
* Verifies a password with Argon2 on the threadpool.
|
|
5
|
-
* @param hashedPassword
|
|
6
|
-
* @param passwordToCheck
|
|
7
|
-
* @returns boolean
|
|
8
|
-
*/
|
|
9
|
-
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Hashes a password with Argon2 on the threadpool.
|
|
12
|
-
* @param password
|
|
13
|
-
* @returns string
|
|
14
|
-
*/
|
|
15
|
-
hashPasswordThreadPool(password: string): string;
|
|
16
3
|
/**
|
|
17
4
|
* Hashes a password with Argon2
|
|
18
5
|
* @param password
|
|
@@ -3,32 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Argon2Wrapper = void 0;
|
|
4
4
|
const index_1 = require("./../../index");
|
|
5
5
|
class Argon2Wrapper {
|
|
6
|
-
/**
|
|
7
|
-
* Verifies a password with Argon2 on the threadpool.
|
|
8
|
-
* @param hashedPassword
|
|
9
|
-
* @param passwordToCheck
|
|
10
|
-
* @returns boolean
|
|
11
|
-
*/
|
|
12
|
-
verifyThreadPool(hashedPassword, passwordToCheck) {
|
|
13
|
-
if (!hashedPassword) {
|
|
14
|
-
throw new Error("You must provide a password to verify with Argon2");
|
|
15
|
-
}
|
|
16
|
-
if (!passwordToCheck) {
|
|
17
|
-
throw new Error("You must provide a password to check to verify with Argon2");
|
|
18
|
-
}
|
|
19
|
-
return (0, index_1.argon2VerifyThreadpool)(hashedPassword, passwordToCheck);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Hashes a password with Argon2 on the threadpool.
|
|
23
|
-
* @param password
|
|
24
|
-
* @returns string
|
|
25
|
-
*/
|
|
26
|
-
hashPasswordThreadPool(password) {
|
|
27
|
-
if (!password) {
|
|
28
|
-
throw new Error("You must provide a password to hash with Argon2");
|
|
29
|
-
}
|
|
30
|
-
return (0, index_1.argon2HashThreadPool)(password);
|
|
31
|
-
}
|
|
32
6
|
/**
|
|
33
7
|
* Hashes a password with Argon2
|
|
34
8
|
* @param password
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class BCryptWrapper implements IPasswordHasherBase {
|
|
3
|
-
/**
|
|
4
|
-
* Verifies a password with BCrypt on the threadpool.
|
|
5
|
-
* @param hashedPassword
|
|
6
|
-
* @param passwordToCheck
|
|
7
|
-
* @returns boolean
|
|
8
|
-
*/
|
|
9
|
-
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Hashes a password with BCrypt on the threadpool.
|
|
12
|
-
* @param password
|
|
13
|
-
* @returns string
|
|
14
|
-
*/
|
|
15
|
-
hashPasswordThreadPool(password: string): string;
|
|
16
3
|
/**
|
|
17
4
|
* Hashes a password with BCrypt
|
|
18
5
|
* @param password
|
|
@@ -3,29 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BCryptWrapper = void 0;
|
|
4
4
|
const index_1 = require("./../../index");
|
|
5
5
|
class BCryptWrapper {
|
|
6
|
-
/**
|
|
7
|
-
* Verifies a password with BCrypt on the threadpool.
|
|
8
|
-
* @param hashedPassword
|
|
9
|
-
* @param passwordToCheck
|
|
10
|
-
* @returns boolean
|
|
11
|
-
*/
|
|
12
|
-
verifyThreadPool(hashedPassword, passwordToCheck) {
|
|
13
|
-
if (!hashedPassword || !passwordToCheck) {
|
|
14
|
-
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
15
|
-
}
|
|
16
|
-
return (0, index_1.bcryptVerifyThreadpool)(hashedPassword, passwordToCheck);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Hashes a password with BCrypt on the threadpool.
|
|
20
|
-
* @param password
|
|
21
|
-
* @returns string
|
|
22
|
-
*/
|
|
23
|
-
hashPasswordThreadPool(password) {
|
|
24
|
-
if (!password) {
|
|
25
|
-
throw new Error("You must provide a password to hash with Argon2");
|
|
26
|
-
}
|
|
27
|
-
return (0, index_1.bcryptHashThreadpool)(password);
|
|
28
|
-
}
|
|
29
6
|
/**
|
|
30
7
|
* Hashes a password with BCrypt
|
|
31
8
|
* @param password
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export interface IPasswordHasherBase {
|
|
2
2
|
hashPassword(password: string): string;
|
|
3
3
|
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
4
|
-
hashPasswordThreadPool(password: string): string;
|
|
5
|
-
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
6
4
|
}
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class ScryptWrapper implements IPasswordHasherBase {
|
|
3
|
-
/**
|
|
4
|
-
* Verifies a password with SCrypt on the threadpool.
|
|
5
|
-
* @param hashedPassword
|
|
6
|
-
* @param passwordToCheck
|
|
7
|
-
* @returns boolean
|
|
8
|
-
*/
|
|
9
|
-
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Hashes a password with SCrypt on the threadpool.
|
|
12
|
-
* @param password
|
|
13
|
-
* @returns string
|
|
14
|
-
*/
|
|
15
|
-
hashPasswordThreadPool(password: string): string;
|
|
16
3
|
/**
|
|
17
4
|
* Hashes a password with SCrypt
|
|
18
5
|
* @param password
|
|
@@ -3,29 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ScryptWrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class ScryptWrapper {
|
|
6
|
-
/**
|
|
7
|
-
* Verifies a password with SCrypt on the threadpool.
|
|
8
|
-
* @param hashedPassword
|
|
9
|
-
* @param passwordToCheck
|
|
10
|
-
* @returns boolean
|
|
11
|
-
*/
|
|
12
|
-
verifyThreadPool(hashedPassword, passwordToCheck) {
|
|
13
|
-
if (!hashedPassword || !passwordToCheck) {
|
|
14
|
-
throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
|
|
15
|
-
}
|
|
16
|
-
return (0, index_1.scryptVerifyThreadpool)(hashedPassword, passwordToCheck);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Hashes a password with SCrypt on the threadpool.
|
|
20
|
-
* @param password
|
|
21
|
-
* @returns string
|
|
22
|
-
*/
|
|
23
|
-
hashPasswordThreadPool(password) {
|
|
24
|
-
if (!password) {
|
|
25
|
-
throw new Error("You must provide a password to hash with Scrypt");
|
|
26
|
-
}
|
|
27
|
-
return (0, index_1.scryptHashThreadpool)(password);
|
|
28
|
-
}
|
|
29
6
|
/**
|
|
30
7
|
* Hashes a password with SCrypt
|
|
31
8
|
* @param password
|
package/package.json
CHANGED
package/src/hashers/blake2.rs
CHANGED
|
@@ -6,41 +6,21 @@ pub fn blake2_sha_512(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
|
6
6
|
return CASBlake2::hash_512(data_to_hash);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
#[napi]
|
|
10
|
-
pub fn blake2_sha_512_threadpool(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
11
|
-
return CASBlake2::hash_512_threadpool(data_to_hash);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
#[napi]
|
|
15
10
|
pub fn blake2_sha_512_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
16
11
|
return CASBlake2::verify_512(data_to_hash, data_to_verify);
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
#[napi]
|
|
20
|
-
pub fn blake2_sha_512_verify_threadpool(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
21
|
-
return CASBlake2::verify_512_threadpool(data_to_hash, data_to_verify);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
14
|
#[napi]
|
|
25
15
|
pub fn blake2_sha_256(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
26
16
|
return CASBlake2::hash_256(data_to_hash);
|
|
27
17
|
}
|
|
28
18
|
|
|
29
|
-
#[napi]
|
|
30
|
-
pub fn blake2_sha_256_threadpool(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
31
|
-
return CASBlake2::hash_256_threadpool(data_to_hash);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
19
|
#[napi]
|
|
35
20
|
pub fn blake2_sha_256_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
36
21
|
return CASBlake2::verify_256(data_to_hash, data_to_verify);
|
|
37
22
|
}
|
|
38
23
|
|
|
39
|
-
#[napi]
|
|
40
|
-
pub fn blake2_sha_256_verify_threadpool(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
41
|
-
return CASBlake2::verify_256_threadpool(data_to_hash, data_to_verify);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
24
|
#[test]
|
|
45
25
|
pub fn blake2_sha_512_test() {
|
|
46
26
|
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
@@ -48,29 +28,6 @@ pub fn blake2_sha_512_test() {
|
|
|
48
28
|
assert_ne!(true, hashed_data.eq(&data_to_hash));
|
|
49
29
|
}
|
|
50
30
|
|
|
51
|
-
#[test]
|
|
52
|
-
pub fn blake2_sha_512_threadpool_test() {
|
|
53
|
-
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
54
|
-
let hashed_data = blake2_sha_512_threadpool(data_to_hash.clone());
|
|
55
|
-
assert_ne!(true, hashed_data.eq(&data_to_hash));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
#[test]
|
|
59
|
-
pub fn blake2_sha_512_verify_test() {
|
|
60
|
-
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
61
|
-
let hashed_data = blake2_sha_512(data_to_hash.clone());
|
|
62
|
-
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
63
|
-
assert_ne!(true, blake2_sha_512_verify_threadpool(data_to_hash, data_to_verify));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
#[test]
|
|
67
|
-
pub fn blake2_sha_512_threadpool_verify_test() {
|
|
68
|
-
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
69
|
-
let hashed_data = blake2_sha_512_threadpool(data_to_hash.clone());
|
|
70
|
-
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
71
|
-
assert_ne!(true, blake2_sha_512_verify_threadpool(data_to_hash, data_to_verify));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
31
|
#[test]
|
|
75
32
|
pub fn blake2_sha_512_verify_fail_test() {
|
|
76
33
|
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
@@ -79,14 +36,6 @@ pub fn blake2_sha_512_verify_fail_test() {
|
|
|
79
36
|
assert_ne!(true, blake2_sha_512_verify(data_to_hash, data_to_verify));
|
|
80
37
|
}
|
|
81
38
|
|
|
82
|
-
#[test]
|
|
83
|
-
pub fn blake2_sha_512_verify_threadpool_fail_test() {
|
|
84
|
-
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
85
|
-
let _hashed_data = blake2_sha_512_threadpool(data_to_hash.clone());
|
|
86
|
-
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
87
|
-
assert_ne!(true, blake2_sha_512_verify_threadpool(data_to_hash, data_to_verify));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
39
|
#[test]
|
|
91
40
|
pub fn blake2_sha_256_test() {
|
|
92
41
|
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
@@ -102,14 +51,6 @@ pub fn blake2_sha_256_verify_test() {
|
|
|
102
51
|
assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
|
|
103
52
|
}
|
|
104
53
|
|
|
105
|
-
#[test]
|
|
106
|
-
pub fn blake2_sha_256_verify_threadpool_test() {
|
|
107
|
-
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
108
|
-
let _hashed_data = blake2_sha_256_threadpool(data_to_hash.clone());
|
|
109
|
-
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
110
|
-
assert_ne!(true, blake2_sha_256_verify_threadpool(data_to_hash, data_to_verify));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
54
|
#[test]
|
|
114
55
|
pub fn blake2_sha_256_verify_fail_test() {
|
|
115
56
|
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
@@ -117,11 +58,3 @@ pub fn blake2_sha_256_verify_fail_test() {
|
|
|
117
58
|
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
118
59
|
assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
|
|
119
60
|
}
|
|
120
|
-
|
|
121
|
-
#[test]
|
|
122
|
-
pub fn blake2_sha_256_verify_threadpool_fail_test() {
|
|
123
|
-
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
124
|
-
let _hashed_data = blake2_sha_256_threadpool(data_to_hash.clone());
|
|
125
|
-
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
126
|
-
assert_ne!(true, blake2_sha_256_verify_threadpool(data_to_hash, data_to_verify));
|
|
127
|
-
}
|
|
File without changes
|
|
File without changes
|
package/src/lib.rs
CHANGED
package/src/message/hmac.rs
CHANGED
|
@@ -6,21 +6,11 @@ pub fn hmac_sign(key: Vec<u8>, message: Vec<u8>) -> Vec<u8> {
|
|
|
6
6
|
return <HMAC as CASHMAC>::sign(key, message);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
#[napi]
|
|
10
|
-
pub fn hmac_sign_threadpool(key: Vec<u8>, message: Vec<u8>) -> Vec<u8> {
|
|
11
|
-
return <HMAC as CASHMAC>::sign_threadpool(key, message);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
#[napi]
|
|
15
10
|
pub fn hmac_verify(key: Vec<u8>, message: Vec<u8>, signature: Vec<u8>) -> bool {
|
|
16
11
|
return <HMAC as CASHMAC>::verify(key, message, signature);
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
#[napi]
|
|
20
|
-
pub fn hmac_verify_threadpool(key: Vec<u8>, message: Vec<u8>, signature: Vec<u8>) -> bool {
|
|
21
|
-
return <HMAC as CASHMAC>::verify_threadpool(key, message, signature);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
14
|
#[test]
|
|
25
15
|
fn hmac_sign_and_verify_test() {
|
|
26
16
|
let key = b"ThisIsMyKeyForHmac".to_vec();
|
|
@@ -28,13 +18,4 @@ fn hmac_sign_and_verify_test() {
|
|
|
28
18
|
let signature = hmac_sign(key.clone(), message.clone());
|
|
29
19
|
let result = hmac_verify(key, message, signature);
|
|
30
20
|
assert_eq!(true, result);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
#[test]
|
|
34
|
-
fn hmac_sign_and_verify_threadpool_test() {
|
|
35
|
-
let key = b"ThisIsMyKeyForHmac7789".to_vec();
|
|
36
|
-
let message = b"ThisIsMyMessageToSign1230".to_vec();
|
|
37
|
-
let signature = hmac_sign_threadpool(key.clone(), message.clone());
|
|
38
|
-
let result = hmac_verify_threadpool(key, message, signature);
|
|
39
|
-
assert_eq!(true, result);
|
|
40
21
|
}
|
|
@@ -7,37 +7,11 @@ pub fn argon2_hash(password: String) -> String {
|
|
|
7
7
|
return CASArgon::hash_password(password);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
#[napi]
|
|
11
|
-
pub fn argon2_hash_thread_pool(password: String) -> String {
|
|
12
|
-
return CASArgon::hash_password_threadpool(password);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
10
|
#[napi]
|
|
16
11
|
pub fn argon2_verify(hashed_password: String, password_to_verify: String) -> bool {
|
|
17
12
|
return CASArgon::verify_password(hashed_password, password_to_verify);
|
|
18
13
|
}
|
|
19
14
|
|
|
20
|
-
#[napi]
|
|
21
|
-
pub fn argon2_verify_threadpool(hashed_password: String, password_to_verify: String) -> bool {
|
|
22
|
-
return CASArgon::verify_password_threadpool(hashed_password, password_to_verify);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
#[test]
|
|
26
|
-
pub fn argon2_hash_threadpool_test() {
|
|
27
|
-
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
28
|
-
let hashed = argon2_hash_thread_pool(password.clone());
|
|
29
|
-
assert_ne!(password, hashed);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#[test]
|
|
33
|
-
pub fn argon2_verify_threadpool_test() {
|
|
34
|
-
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
35
|
-
let passwordToCheck = "ThisIsNotMyPasswolrd".to_string();
|
|
36
|
-
let hashed = argon2_hash_thread_pool(password);
|
|
37
|
-
let result = argon2_verify_threadpool(hashed, passwordToCheck);
|
|
38
|
-
assert_eq!(result, true);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
15
|
#[test]
|
|
42
16
|
pub fn argon2_hash_test() {
|
|
43
17
|
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
@@ -7,21 +7,11 @@ pub fn bcrypt_hash(password_to_hash: String) -> String {
|
|
|
7
7
|
return <CASBCrypt as CASPasswordHasher>::hash_password(password_to_hash);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
#[napi]
|
|
11
|
-
pub fn bcrypt_hash_threadpool(password_to_hash: String) -> String {
|
|
12
|
-
return <CASBCrypt as CASPasswordHasher>::hash_password_threadpool(password_to_hash);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
10
|
#[napi]
|
|
16
11
|
pub fn bcrypt_verify(hashed_password: String, password_to_verify: String) -> bool {
|
|
17
12
|
return <CASBCrypt as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
|
|
18
13
|
}
|
|
19
14
|
|
|
20
|
-
#[napi]
|
|
21
|
-
pub fn bcrypt_verify_threadpool(password_to_hash: String, password_to_verify: String) -> bool {
|
|
22
|
-
return <CASBCrypt as CASPasswordHasher>::verify_password_threadpool(password_to_hash, password_to_verify);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
15
|
#[test]
|
|
26
16
|
pub fn bcrypt_hash_test() {
|
|
27
17
|
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
@@ -29,13 +19,6 @@ pub fn bcrypt_hash_test() {
|
|
|
29
19
|
assert_ne!(password, hashed);
|
|
30
20
|
}
|
|
31
21
|
|
|
32
|
-
#[test]
|
|
33
|
-
pub fn bcrypt_hash_threadpool_test() {
|
|
34
|
-
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
35
|
-
let hashed = bcrypt_hash_threadpool(password.clone());
|
|
36
|
-
assert_ne!(password, hashed);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
22
|
#[test]
|
|
40
23
|
pub fn bcrypt_verify_test() {
|
|
41
24
|
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
@@ -44,14 +27,6 @@ pub fn bcrypt_verify_test() {
|
|
|
44
27
|
assert_eq!(true, verified);
|
|
45
28
|
}
|
|
46
29
|
|
|
47
|
-
#[test]
|
|
48
|
-
pub fn bcrypt_verify_threadpool_test() {
|
|
49
|
-
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
50
|
-
let hashed = bcrypt_hash_threadpool(password.clone());
|
|
51
|
-
let verified = bcrypt_verify_threadpool(hashed, password);
|
|
52
|
-
assert_eq!(true, verified);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
30
|
#[test]
|
|
56
31
|
pub fn bcrypt_verify_fail_test() {
|
|
57
32
|
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
@@ -11,31 +11,6 @@ pub fn scrypt_verify(hashed_password: String, password_to_verify: String) -> boo
|
|
|
11
11
|
return <CASScrypt as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
#[napi]
|
|
15
|
-
pub fn scrypt_hash_threadpool(password_to_hash: String) -> String {
|
|
16
|
-
return <CASScrypt as CASPasswordHasher>::hash_password_threadpool(password_to_hash);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
#[napi]
|
|
20
|
-
pub fn scrypt_verify_threadpool(hashed_password: String, password_to_verify: String) -> bool {
|
|
21
|
-
return <CASScrypt as CASPasswordHasher>::verify_password_threadpool(hashed_password, password_to_verify);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
#[test]
|
|
25
|
-
pub fn scrypt_hash_threadpool_test() {
|
|
26
|
-
let password = "BadPassword".to_string();
|
|
27
|
-
let hashed_password = scrypt_hash_threadpool(password.clone());
|
|
28
|
-
assert_ne!(password, hashed_password);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
#[test]
|
|
32
|
-
pub fn scrypt_verify_threadpool_test() {
|
|
33
|
-
let password = "BadPassword".to_string();
|
|
34
|
-
let hashed_password = scrypt_hash_threadpool(password.clone());
|
|
35
|
-
let verified = scrypt_verify_threadpool(hashed_password, password);
|
|
36
|
-
assert_eq!(true, verified);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
14
|
#[test]
|
|
40
15
|
pub fn scrypt_hash_test() {
|
|
41
16
|
let password = "BadPassword".to_string();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { blake2Sha512Verify, blake2Sha256Verify, blake2Sha256, blake2Sha512
|
|
1
|
+
import { blake2Sha512Verify, blake2Sha256Verify, blake2Sha256, blake2Sha512 } from "../../index";
|
|
2
2
|
import { IHasherBase } from "./hasher-base";
|
|
3
3
|
|
|
4
4
|
export class Blake2Wrapper implements IHasherBase {
|
|
@@ -12,15 +12,6 @@ export class Blake2Wrapper implements IHasherBase {
|
|
|
12
12
|
return blake2Sha512(dataToHash);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Hashes the input data using Blake2b 512 in a thread pool
|
|
17
|
-
* @param dataToHash The data to hash
|
|
18
|
-
* @returns The hashed output
|
|
19
|
-
*/
|
|
20
|
-
hash512Threadpool(dataToHash: number[]): number[] {
|
|
21
|
-
return blake2Sha512Threadpool(dataToHash);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
15
|
/**
|
|
25
16
|
* Verifies the input data against the hashed output using Blake2b 512
|
|
26
17
|
* @param dataToHash The data to hash
|
|
@@ -30,17 +21,6 @@ export class Blake2Wrapper implements IHasherBase {
|
|
|
30
21
|
verify512(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
31
22
|
return blake2Sha512Verify(dataToHash, dataToVerify);
|
|
32
23
|
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Verifies the input data against the hashed output using Blake2b 512 in a thread pool
|
|
36
|
-
* @param dataToHash The data to hash
|
|
37
|
-
* @param dataToVerify The data to verify
|
|
38
|
-
* @returns True if the verification is successful, false otherwise
|
|
39
|
-
*/
|
|
40
|
-
verify512Threadpool(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
41
|
-
return blake2Sha512VerifyThreadpool(dataToHash, dataToVerify);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
24
|
/**
|
|
45
25
|
* Hashes the input data using Blake2b 256
|
|
46
26
|
* @param dataToHash The data to hash
|
|
@@ -50,16 +30,6 @@ export class Blake2Wrapper implements IHasherBase {
|
|
|
50
30
|
hash256(dataToHash: number[]): number[] {
|
|
51
31
|
return blake2Sha256(dataToHash);
|
|
52
32
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Hashes the input data using Blake2b 256 in a thread pool
|
|
56
|
-
* @param dataToHash The data to hash
|
|
57
|
-
* @returns The hashed output
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
hash256Threadpool(dataToHash: number[]): number[] {
|
|
61
|
-
return blake2Sha256Threadpool(dataToHash);
|
|
62
|
-
}
|
|
63
33
|
|
|
64
34
|
/**
|
|
65
35
|
* Verifies the input data against the hashed output using Blake2b 256
|
|
@@ -70,14 +40,4 @@ export class Blake2Wrapper implements IHasherBase {
|
|
|
70
40
|
verify256(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
71
41
|
return blake2Sha256Verify(dataToHash, dataToVerify);
|
|
72
42
|
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Verifies the input data against the hashed output using Blake2b 256 in a thread pool
|
|
76
|
-
* @param dataToHash The data to hash
|
|
77
|
-
* @param dataToVerify The data to verify
|
|
78
|
-
* @returns True if the verification is successful, false otherwise
|
|
79
|
-
*/
|
|
80
|
-
verify256Threadpool(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
81
|
-
return blake2Sha256VerifyThreadpool(dataToHash, dataToVerify);
|
|
82
|
-
}
|
|
83
43
|
}
|
package/src-ts/message/hmac.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hmacSign,
|
|
1
|
+
import { hmacSign, hmacVerify } from "../../index";
|
|
2
2
|
|
|
3
3
|
export class HmacWrapper {
|
|
4
4
|
public hmacSignBytes(key: Array<number>, message: Array<number>): Array<number> {
|
|
@@ -23,27 +23,4 @@ export class HmacWrapper {
|
|
|
23
23
|
}
|
|
24
24
|
return hmacVerify(key, message, signature);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
public hmacSignBytesThreadpool(key: Array<number>, message: Array<number>): Array<number> {
|
|
28
|
-
if (key?.length === 0) {
|
|
29
|
-
throw new Error("Must provide an allocated key");
|
|
30
|
-
}
|
|
31
|
-
if (message?.length === 0) {
|
|
32
|
-
throw new Error("Must provide an allocated message");
|
|
33
|
-
}
|
|
34
|
-
return hmacSignThreadpool(key, message);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public hmacVerifyBytesThreadpool(key: Array<number>, message: Array<number>, signature: Array<number>): boolean {
|
|
38
|
-
if (key?.length === 0) {
|
|
39
|
-
throw new Error("Must provide an allocated key");
|
|
40
|
-
}
|
|
41
|
-
if (message?.length === 0) {
|
|
42
|
-
throw new Error("Must provide an allocated message");
|
|
43
|
-
}
|
|
44
|
-
if(signature?.length===0) {
|
|
45
|
-
throw new Error("Must provide an allocated signature");
|
|
46
|
-
}
|
|
47
|
-
return hmacVerifyThreadpool(key, message, signature);
|
|
48
|
-
}
|
|
49
26
|
}
|
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
import { argon2Hash,
|
|
1
|
+
import { argon2Hash, argon2Verify} from "./../../index";
|
|
2
2
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
3
3
|
|
|
4
4
|
export class Argon2Wrapper implements IPasswordHasherBase {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Verifies a password with Argon2 on the threadpool.
|
|
8
|
-
* @param hashedPassword
|
|
9
|
-
* @param passwordToCheck
|
|
10
|
-
* @returns boolean
|
|
11
|
-
*/
|
|
12
|
-
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
|
|
13
|
-
if (!hashedPassword) {
|
|
14
|
-
throw new Error("You must provide a password to verify with Argon2");
|
|
15
|
-
}
|
|
16
|
-
if (!passwordToCheck) {
|
|
17
|
-
throw new Error("You must provide a password to check to verify with Argon2");
|
|
18
|
-
}
|
|
19
|
-
return argon2VerifyThreadpool(hashedPassword, passwordToCheck);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Hashes a password with Argon2 on the threadpool.
|
|
24
|
-
* @param password
|
|
25
|
-
* @returns string
|
|
26
|
-
*/
|
|
27
|
-
public hashPasswordThreadPool(password: string): string {
|
|
28
|
-
if (!password) {
|
|
29
|
-
throw new Error("You must provide a password to hash with Argon2");
|
|
30
|
-
}
|
|
31
|
-
return argon2HashThreadPool(password);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
5
|
/**
|
|
35
6
|
* Hashes a password with Argon2
|
|
36
7
|
* @param password
|
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
|
-
import { bcryptHash,
|
|
2
|
+
import { bcryptHash, bcryptVerify } from "./../../index";
|
|
3
3
|
|
|
4
4
|
export class BCryptWrapper implements IPasswordHasherBase {
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Verifies a password with BCrypt on the threadpool.
|
|
8
|
-
* @param hashedPassword
|
|
9
|
-
* @param passwordToCheck
|
|
10
|
-
* @returns boolean
|
|
11
|
-
*/
|
|
12
|
-
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
|
|
13
|
-
if (!hashedPassword || !passwordToCheck) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"You must provide a hashed password and a plaintext password to verify with Argon2",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
return bcryptVerifyThreadpool(hashedPassword, passwordToCheck);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Hashes a password with BCrypt on the threadpool.
|
|
23
|
-
* @param password
|
|
24
|
-
* @returns string
|
|
25
|
-
*/
|
|
26
|
-
public hashPasswordThreadPool(password: string): string {
|
|
27
|
-
if (!password) {
|
|
28
|
-
throw new Error("You must provide a password to hash with Argon2");
|
|
29
|
-
}
|
|
30
|
-
return bcryptHashThreadpool(password);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
6
|
/**
|
|
34
7
|
* Hashes a password with BCrypt
|
|
35
8
|
* @param password
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export interface IPasswordHasherBase {
|
|
2
2
|
hashPassword(password: string): string;
|
|
3
3
|
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
4
|
-
hashPasswordThreadPool(password: string): string;
|
|
5
|
-
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
6
4
|
}
|
|
@@ -1,35 +1,8 @@
|
|
|
1
|
-
import { scryptHash,
|
|
1
|
+
import { scryptHash, scryptVerify} from "../../index";
|
|
2
2
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
3
3
|
|
|
4
4
|
export class ScryptWrapper implements IPasswordHasherBase {
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Verifies a password with SCrypt on the threadpool.
|
|
8
|
-
* @param hashedPassword
|
|
9
|
-
* @param passwordToCheck
|
|
10
|
-
* @returns boolean
|
|
11
|
-
*/
|
|
12
|
-
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
|
|
13
|
-
if (!hashedPassword || !passwordToCheck) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"You must provide a hashed password and a plaintext password to verify with Scrypt",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
return scryptVerifyThreadpool(hashedPassword, passwordToCheck);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Hashes a password with SCrypt on the threadpool.
|
|
23
|
-
* @param password
|
|
24
|
-
* @returns string
|
|
25
|
-
*/
|
|
26
|
-
hashPasswordThreadPool(password: string): string {
|
|
27
|
-
if (!password) {
|
|
28
|
-
throw new Error("You must provide a password to hash with Scrypt");
|
|
29
|
-
}
|
|
30
|
-
return scryptHashThreadpool(password);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
6
|
/**
|
|
34
7
|
* Hashes a password with SCrypt
|
|
35
8
|
* @param password
|
|
@@ -103,38 +103,6 @@ describe("Blake2 512", () => {
|
|
|
103
103
|
assert.equal(false, verified);
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
it("hash threadpool", () => {
|
|
107
|
-
const wrapper = new Blake2Wrapper();
|
|
108
|
-
const tohashed: string = "This is my array to hash";
|
|
109
|
-
const encoder = new TextEncoder();
|
|
110
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
111
|
-
const hashed = wrapper.hash512Threadpool(tohashBytes);
|
|
112
|
-
assert.notEqual(tohashBytes, hashed);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("verify threadpool pass", () => {
|
|
116
|
-
const wrapper = new Blake2Wrapper();
|
|
117
|
-
const tohashed: string = "This is my array to hash";
|
|
118
|
-
const encoder = new TextEncoder();
|
|
119
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
120
|
-
const hashed = wrapper.hash512Threadpool(tohashBytes);
|
|
121
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
122
|
-
const verified = wrapper.verify512Threadpool(hashed, toVerifyBytes);
|
|
123
|
-
assert.equal(true, verified);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("verify threadpool fail", () => {
|
|
127
|
-
const wrapper = new Blake2Wrapper();
|
|
128
|
-
const tohashed: string = "This is my array to hash";
|
|
129
|
-
const encoder = new TextEncoder();
|
|
130
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
131
|
-
const hashed = wrapper.hash512Threadpool(tohashBytes);
|
|
132
|
-
const toVerify = "This Is Not The Same";
|
|
133
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
134
|
-
const verified = wrapper.verify512Threadpool(hashed, toVerifyBytes);
|
|
135
|
-
assert.equal(false, verified);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
106
|
describe("Blake2 256", () => {
|
|
139
107
|
it("hash", () => {
|
|
140
108
|
const wrapper = new Blake2Wrapper();
|
|
@@ -167,37 +135,5 @@ describe("Blake2 512", () => {
|
|
|
167
135
|
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
168
136
|
assert.equal(false, verified);
|
|
169
137
|
});
|
|
170
|
-
|
|
171
|
-
it("hash threadpool", () => {
|
|
172
|
-
const wrapper = new Blake2Wrapper();
|
|
173
|
-
const tohashed: string = "This is my array to hash";
|
|
174
|
-
const encoder = new TextEncoder();
|
|
175
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
176
|
-
const hashed = wrapper.hash256Threadpool(tohashBytes);
|
|
177
|
-
assert.notEqual(tohashBytes, hashed);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("verify threadpool pass", () => {
|
|
181
|
-
const wrapper = new Blake2Wrapper();
|
|
182
|
-
const tohashed: string = "This is my array to hash";
|
|
183
|
-
const encoder = new TextEncoder();
|
|
184
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
185
|
-
const hashed = wrapper.hash256Threadpool(tohashBytes);
|
|
186
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
187
|
-
const verified = wrapper.verify256Threadpool(hashed, toVerifyBytes);
|
|
188
|
-
assert.equal(true, verified);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("verify threadpool fail", () => {
|
|
192
|
-
const wrapper = new Blake2Wrapper();
|
|
193
|
-
const tohashed: string = "This is my array to hash";
|
|
194
|
-
const encoder = new TextEncoder();
|
|
195
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
196
|
-
const hashed = wrapper.hash256Threadpool(tohashBytes);
|
|
197
|
-
const toVerify = "This Is Not The Same";
|
|
198
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
199
|
-
const verified = wrapper.verify256Threadpool(hashed, toVerifyBytes);
|
|
200
|
-
assert.equal(false, verified);
|
|
201
|
-
});
|
|
202
138
|
});
|
|
203
139
|
});
|
|
@@ -13,20 +13,4 @@ describe("HMAC Tests", () => {
|
|
|
13
13
|
const result = wrapper.hmacVerifyBytes(keyBytes, messageBytes, signature);
|
|
14
14
|
assert.equal(true, result);
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
it("Sign and Verify Threadpool", () => {
|
|
18
|
-
const wrapper = new HmacWrapper();
|
|
19
|
-
const key: string = "This is my array to hash";
|
|
20
|
-
const encoder = new TextEncoder();
|
|
21
|
-
const keyBytes: Array<number> = Array.from(encoder.encode(key));
|
|
22
|
-
const message: string = "This is my message";
|
|
23
|
-
const messageBytes = Array.from(encoder.encode(message));
|
|
24
|
-
const signature = wrapper.hmacSignBytesThreadpool(keyBytes, messageBytes);
|
|
25
|
-
const result = wrapper.hmacVerifyBytesThreadpool(
|
|
26
|
-
keyBytes,
|
|
27
|
-
messageBytes,
|
|
28
|
-
signature,
|
|
29
|
-
);
|
|
30
|
-
assert.equal(true, result);
|
|
31
|
-
});
|
|
32
16
|
});
|
|
@@ -8,21 +8,6 @@ import {
|
|
|
8
8
|
|
|
9
9
|
describe("Bcrypt Tests", () => {
|
|
10
10
|
|
|
11
|
-
it("hash threadpool", () => {
|
|
12
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
13
|
-
const password: string = "ThisOneBadPassword!@";
|
|
14
|
-
const hashedPassword: string = hasher.hashPasswordThreadPool(password);
|
|
15
|
-
assert.notEqual(hashedPassword, password);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("verify threadpool", () => {
|
|
19
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
20
|
-
const password: string = "NotThisPassword!@";
|
|
21
|
-
const hashedPassword: string = hasher.hashPassword(password);
|
|
22
|
-
const isValid: boolean = hasher.verifyThreadPool(hashedPassword, password);
|
|
23
|
-
expect(isValid).to.equal(true);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
11
|
it("hash", () => {
|
|
27
12
|
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
28
13
|
const password: string = "ThisOneBadPassword!@";
|
|
@@ -51,25 +36,6 @@ describe("Bcrypt Tests", () => {
|
|
|
51
36
|
});
|
|
52
37
|
|
|
53
38
|
describe("Scrypt Tests", () => {
|
|
54
|
-
it("hash with threadpool", () => {
|
|
55
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
56
|
-
PasswordHasherType.Scrypt,
|
|
57
|
-
);
|
|
58
|
-
const password: string = "ScryptRocks";
|
|
59
|
-
const hashed: string = hasher.hashPasswordThreadPool(password);
|
|
60
|
-
assert.notEqual(password, hashed);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("verify pass with threadpool", () => {
|
|
64
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
65
|
-
PasswordHasherType.Scrypt,
|
|
66
|
-
);
|
|
67
|
-
const password: string = "ScryptRocks1231231";
|
|
68
|
-
const hashed: string = hasher.hashPasswordThreadPool(password);
|
|
69
|
-
const verified: boolean = hasher.verifyThreadPool(hashed, password);
|
|
70
|
-
assert.isTrue(verified);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
39
|
it("hash with factory", () => {
|
|
74
40
|
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
75
41
|
PasswordHasherType.Scrypt,
|
|
@@ -103,22 +69,7 @@ describe("Scrypt Tests", () => {
|
|
|
103
69
|
});
|
|
104
70
|
});
|
|
105
71
|
|
|
106
|
-
describe("Argon2 Tests", () => {
|
|
107
|
-
it("hash with threadpool", () => {
|
|
108
|
-
const argon2: Argon2Wrapper = PasswordHasherFactory.getHasher(PasswordHasherType.Argon2);
|
|
109
|
-
const password = "Argon2OverBCrypt";
|
|
110
|
-
const hashed = argon2.hashPasswordThreadPool(password);
|
|
111
|
-
assert.notEqual(password, hashed);
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it("verify with threadpool", () => {
|
|
115
|
-
const argon2: Argon2Wrapper = PasswordHasherFactory.getHasher(PasswordHasherType.Argon2);
|
|
116
|
-
const password = "Argon2OverBCrypt";
|
|
117
|
-
const hashed = argon2.hashPasswordThreadPool(password);
|
|
118
|
-
const result = argon2.verifyThreadPool(hashed, password);
|
|
119
|
-
assert.equal(result, true);
|
|
120
|
-
});
|
|
121
|
-
|
|
72
|
+
describe("Argon2 Tests", () => {
|
|
122
73
|
it("hash with factory", () => {
|
|
123
74
|
const hasher: Argon2Wrapper = PasswordHasherFactory.getHasher(
|
|
124
75
|
PasswordHasherType.Argon2,
|