cas-typescript-sdk 1.0.31 → 1.0.32
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/README.md +1 -2
- package/index.d.ts +8 -0
- package/index.node +0 -0
- package/lib/hashers/blake2-wrapper.d.ts +55 -0
- package/lib/hashers/blake2-wrapper.js +75 -0
- package/lib/hashers/hasher-factory.js +4 -0
- package/lib/hashers/hasher-type.d.ts +2 -1
- package/lib/hashers/hasher-type.js +1 -0
- package/lib/hashers/index.d.ts +2 -1
- package/lib/hashers/index.js +3 -1
- package/package.json +10 -10
- package/src/hashers/blake2.rs +127 -0
- package/src/lib.rs +1 -0
- package/src-ts/hashers/blake2-wrapper.ts +83 -0
- package/src-ts/hashers/hasher-factory.ts +3 -1
- package/src-ts/hashers/hasher-type.ts +2 -1
- package/src-ts/hashers/index.ts +2 -1
- package/test-ts/hasher.test.spec.ts +139 -7
- package/test-ts/symmetric.test.spec.ts +47 -0
package/README.md
CHANGED
|
@@ -8,8 +8,7 @@ The official NPM page can be found [here](https://www.npmjs.com/package/cas-type
|
|
|
8
8
|
|
|
9
9
|
**Note: All work is experimental and we understand some benchmarks might not be the most optimal.**
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
**[You can find some usage examples here](https://github.com/Cryptographic-API-Services/cas-typescript-sdk/blob/main/docs/EXAMPLES.md)**
|
|
13
12
|
|
|
14
13
|
## Consuming Library Documentation
|
|
15
14
|
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 sequentially, on threads, and the thread pool.
|
package/index.d.ts
CHANGED
|
@@ -19,6 +19,14 @@ export declare function sha512(dataToHash: Array<number>): Array<number>
|
|
|
19
19
|
export declare function sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
20
20
|
export declare function sha256(dataToHash: Array<number>): Array<number>
|
|
21
21
|
export declare function sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
22
|
+
export declare function blake2Sha512(dataToHash: Array<number>): Array<number>
|
|
23
|
+
export declare function blake2Sha512Threadpool(dataToHash: Array<number>): Array<number>
|
|
24
|
+
export declare function blake2Sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
25
|
+
export declare function blake2Sha512VerifyThreadpool(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
26
|
+
export declare function blake2Sha256(dataToHash: Array<number>): Array<number>
|
|
27
|
+
export declare function blake2Sha256Threadpool(dataToHash: Array<number>): Array<number>
|
|
28
|
+
export declare function blake2Sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
29
|
+
export declare function blake2Sha256VerifyThreadpool(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
22
30
|
export declare function x25519GenerateSecretAndPublicKey(): CASx25519SecretPublicKeyResult
|
|
23
31
|
export declare function x25519DiffieHellman(mySecretKey: Array<number>, usersPublicKey: Array<number>): Array<number>
|
|
24
32
|
export declare function aesNonce(): Array<number>
|
package/index.node
CHANGED
|
Binary file
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IHasherBase } from "./hasher-base";
|
|
2
|
+
export declare class Blake2Wrapper implements IHasherBase {
|
|
3
|
+
/**
|
|
4
|
+
* Hashes the input data using Blake2b 512
|
|
5
|
+
* @param dataToHash The data to hash
|
|
6
|
+
* @returns The hashed output
|
|
7
|
+
*/
|
|
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
|
+
/**
|
|
16
|
+
* Verifies the input data against the hashed output using Blake2b 512
|
|
17
|
+
* @param dataToHash The data to hash
|
|
18
|
+
* @param dataToVerify The data to verify
|
|
19
|
+
* @returns True if the verification is successful, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
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
|
+
/**
|
|
30
|
+
* Hashes the input data using Blake2b 256
|
|
31
|
+
* @param dataToHash The data to hash
|
|
32
|
+
* @returns The hashed output
|
|
33
|
+
*/
|
|
34
|
+
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
|
+
/**
|
|
42
|
+
* Verifies the input data against the hashed output using Blake2b 256
|
|
43
|
+
* @param dataToHash The data to hash
|
|
44
|
+
* @param dataToVerify The data to verify
|
|
45
|
+
* @returns True if the verification is successful, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
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
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Blake2Wrapper = void 0;
|
|
4
|
+
const index_1 = require("../../index");
|
|
5
|
+
class Blake2Wrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Hashes the input data using Blake2b 512
|
|
8
|
+
* @param dataToHash The data to hash
|
|
9
|
+
* @returns The hashed output
|
|
10
|
+
*/
|
|
11
|
+
hash512(dataToHash) {
|
|
12
|
+
return (0, index_1.blake2Sha512)(dataToHash);
|
|
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
|
+
/**
|
|
23
|
+
* Verifies the input data against the hashed output using Blake2b 512
|
|
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
|
+
verify512(dataToHash, dataToVerify) {
|
|
29
|
+
return (0, index_1.blake2Sha512Verify)(dataToHash, dataToVerify);
|
|
30
|
+
}
|
|
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
|
+
/**
|
|
41
|
+
* Hashes the input data using Blake2b 256
|
|
42
|
+
* @param dataToHash The data to hash
|
|
43
|
+
* @returns The hashed output
|
|
44
|
+
*/
|
|
45
|
+
hash256(dataToHash) {
|
|
46
|
+
return (0, index_1.blake2Sha256)(dataToHash);
|
|
47
|
+
}
|
|
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
|
+
/**
|
|
57
|
+
* Verifies the input data against the hashed output using Blake2b 256
|
|
58
|
+
* @param dataToHash The data to hash
|
|
59
|
+
* @param dataToVerify The data to verify
|
|
60
|
+
* @returns True if the verification is successful, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
verify256(dataToHash, dataToVerify) {
|
|
63
|
+
return (0, index_1.blake2Sha256Verify)(dataToHash, dataToVerify);
|
|
64
|
+
}
|
|
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
|
+
}
|
|
75
|
+
exports.Blake2Wrapper = Blake2Wrapper;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HasherFactory = void 0;
|
|
4
|
+
const blake2_wrapper_1 = require("./blake2-wrapper");
|
|
5
|
+
const hasher_type_1 = require("./hasher-type");
|
|
4
6
|
const sha_wrapper_1 = require("./sha-wrapper");
|
|
5
7
|
class HasherFactory {
|
|
6
8
|
/**
|
|
@@ -11,6 +13,8 @@ class HasherFactory {
|
|
|
11
13
|
getHasher(type) {
|
|
12
14
|
let result = new sha_wrapper_1.SHAWrapper();
|
|
13
15
|
switch (type) {
|
|
16
|
+
case hasher_type_1.HasherType.Blake2:
|
|
17
|
+
result = new blake2_wrapper_1.Blake2Wrapper();
|
|
14
18
|
}
|
|
15
19
|
return result;
|
|
16
20
|
}
|
package/lib/hashers/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HasherFactory } from "./hasher-factory";
|
|
2
2
|
import { HasherType } from "./hasher-type";
|
|
3
3
|
import { SHAWrapper } from "./sha-wrapper";
|
|
4
|
-
|
|
4
|
+
import { Blake2Wrapper } from "./blake2-wrapper";
|
|
5
|
+
export { SHAWrapper, HasherFactory, HasherType, Blake2Wrapper };
|
package/lib/hashers/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HasherType = exports.HasherFactory = exports.SHAWrapper = void 0;
|
|
3
|
+
exports.Blake2Wrapper = exports.HasherType = exports.HasherFactory = exports.SHAWrapper = void 0;
|
|
4
4
|
const hasher_factory_1 = require("./hasher-factory");
|
|
5
5
|
Object.defineProperty(exports, "HasherFactory", { enumerable: true, get: function () { return hasher_factory_1.HasherFactory; } });
|
|
6
6
|
const hasher_type_1 = require("./hasher-type");
|
|
7
7
|
Object.defineProperty(exports, "HasherType", { enumerable: true, get: function () { return hasher_type_1.HasherType; } });
|
|
8
8
|
const sha_wrapper_1 = require("./sha-wrapper");
|
|
9
9
|
Object.defineProperty(exports, "SHAWrapper", { enumerable: true, get: function () { return sha_wrapper_1.SHAWrapper; } });
|
|
10
|
+
const blake2_wrapper_1 = require("./blake2-wrapper");
|
|
11
|
+
Object.defineProperty(exports, "Blake2Wrapper", { enumerable: true, get: function () { return blake2_wrapper_1.Blake2Wrapper; } });
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cas-typescript-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "npm run rust:test && npm run build && npm run node:test",
|
|
9
9
|
"node:test": "mocha -r ts-node/register ./test-ts/**/*.test.spec.ts --timeout 20000 --recursive",
|
|
10
10
|
"rust:test": "cargo test --release",
|
|
11
11
|
"build": "npm run build:rust && rimraf lib && tsc",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@napi-rs/cli": "^2.18.4",
|
|
32
|
-
"@types/chai": "^4.3.
|
|
33
|
-
"@types/mocha": "^10.0.
|
|
34
|
-
"@types/node-fetch": "^2.6.
|
|
35
|
-
"chai": "^4.
|
|
36
|
-
"mocha": "^10.2
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
32
|
+
"@types/chai": "^4.3.20",
|
|
33
|
+
"@types/mocha": "^10.0.10",
|
|
34
|
+
"@types/node-fetch": "^2.6.12",
|
|
35
|
+
"chai": "^4.5.0",
|
|
36
|
+
"mocha": "^10.8.2",
|
|
37
|
+
"rimraf": "^6.0.1",
|
|
38
|
+
"ts-node": "^10.9.2",
|
|
39
|
+
"typescript": "^5.8.3"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
use cas_lib::hashers::{blake2::CASBlake2, cas_hasher::CASHasher};
|
|
2
|
+
use napi_derive::napi;
|
|
3
|
+
|
|
4
|
+
#[napi]
|
|
5
|
+
pub fn blake2_sha_512(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
6
|
+
return CASBlake2::hash_512(data_to_hash);
|
|
7
|
+
}
|
|
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
|
+
#[napi]
|
|
15
|
+
pub fn blake2_sha_512_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
16
|
+
return CASBlake2::verify_512(data_to_hash, data_to_verify);
|
|
17
|
+
}
|
|
18
|
+
|
|
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
|
+
#[napi]
|
|
25
|
+
pub fn blake2_sha_256(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
26
|
+
return CASBlake2::hash_256(data_to_hash);
|
|
27
|
+
}
|
|
28
|
+
|
|
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
|
+
#[napi]
|
|
35
|
+
pub fn blake2_sha_256_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
36
|
+
return CASBlake2::verify_256(data_to_hash, data_to_verify);
|
|
37
|
+
}
|
|
38
|
+
|
|
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
|
+
#[test]
|
|
45
|
+
pub fn blake2_sha_512_test() {
|
|
46
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
47
|
+
let hashed_data = blake2_sha_512(data_to_hash.clone());
|
|
48
|
+
assert_ne!(true, hashed_data.eq(&data_to_hash));
|
|
49
|
+
}
|
|
50
|
+
|
|
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
|
+
#[test]
|
|
75
|
+
pub fn blake2_sha_512_verify_fail_test() {
|
|
76
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
77
|
+
let _hashed_data = blake2_sha_512(data_to_hash.clone());
|
|
78
|
+
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
79
|
+
assert_ne!(true, blake2_sha_512_verify(data_to_hash, data_to_verify));
|
|
80
|
+
}
|
|
81
|
+
|
|
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
|
+
#[test]
|
|
91
|
+
pub fn blake2_sha_256_test() {
|
|
92
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
93
|
+
let hashed_data = blake2_sha_256(data_to_hash.clone());
|
|
94
|
+
assert_ne!(true, hashed_data.eq(&data_to_hash));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[test]
|
|
98
|
+
pub fn blake2_sha_256_verify_test() {
|
|
99
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
100
|
+
let _hashed_data = blake2_sha_256(data_to_hash.clone());
|
|
101
|
+
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
102
|
+
assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
|
|
103
|
+
}
|
|
104
|
+
|
|
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
|
+
#[test]
|
|
114
|
+
pub fn blake2_sha_256_verify_fail_test() {
|
|
115
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
116
|
+
let _hashed_data = blake2_sha_256(data_to_hash.clone());
|
|
117
|
+
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
118
|
+
assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
|
|
119
|
+
}
|
|
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
|
+
}
|
package/src/lib.rs
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { blake2Sha512Verify, blake2Sha256Verify, blake2Sha256, blake2Sha512, blake2Sha512Threadpool, blake2Sha512VerifyThreadpool, blake2Sha256Threadpool, blake2Sha256VerifyThreadpool } from "../../index";
|
|
2
|
+
import { IHasherBase } from "./hasher-base";
|
|
3
|
+
|
|
4
|
+
export class Blake2Wrapper implements IHasherBase {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hashes the input data using Blake2b 512
|
|
8
|
+
* @param dataToHash The data to hash
|
|
9
|
+
* @returns The hashed output
|
|
10
|
+
*/
|
|
11
|
+
hash512(dataToHash: number[]): number[] {
|
|
12
|
+
return blake2Sha512(dataToHash);
|
|
13
|
+
}
|
|
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
|
+
/**
|
|
25
|
+
* Verifies the input data against the hashed output using Blake2b 512
|
|
26
|
+
* @param dataToHash The data to hash
|
|
27
|
+
* @param dataToVerify The data to verify
|
|
28
|
+
* @returns True if the verification is successful, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
verify512(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
31
|
+
return blake2Sha512Verify(dataToHash, dataToVerify);
|
|
32
|
+
}
|
|
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
|
+
/**
|
|
45
|
+
* Hashes the input data using Blake2b 256
|
|
46
|
+
* @param dataToHash The data to hash
|
|
47
|
+
* @returns The hashed output
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
hash256(dataToHash: number[]): number[] {
|
|
51
|
+
return blake2Sha256(dataToHash);
|
|
52
|
+
}
|
|
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
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Verifies the input data against the hashed output using Blake2b 256
|
|
66
|
+
* @param dataToHash The data to hash
|
|
67
|
+
* @param dataToVerify The data to verify
|
|
68
|
+
* @returns True if the verification is successful, false otherwise
|
|
69
|
+
*/
|
|
70
|
+
verify256(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
71
|
+
return blake2Sha256Verify(dataToHash, dataToVerify);
|
|
72
|
+
}
|
|
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
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Blake2Wrapper } from "./blake2-wrapper";
|
|
1
2
|
import { HasherType } from "./hasher-type";
|
|
2
3
|
import { SHAWrapper } from "./sha-wrapper";
|
|
3
4
|
|
|
@@ -10,7 +11,8 @@ export class HasherFactory {
|
|
|
10
11
|
getHasher(type: HasherType): any {
|
|
11
12
|
let result: SHAWrapper = new SHAWrapper();
|
|
12
13
|
switch(type) {
|
|
13
|
-
|
|
14
|
+
case HasherType.Blake2:
|
|
15
|
+
result = new Blake2Wrapper();
|
|
14
16
|
}
|
|
15
17
|
return result;
|
|
16
18
|
}
|
package/src-ts/hashers/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HasherFactory } from "./hasher-factory";
|
|
2
2
|
import { HasherType } from "./hasher-type";
|
|
3
3
|
import { SHAWrapper } from "./sha-wrapper";
|
|
4
|
+
import { Blake2Wrapper } from "./blake2-wrapper";
|
|
4
5
|
|
|
5
|
-
export { SHAWrapper, HasherFactory, HasherType };
|
|
6
|
+
export { SHAWrapper, HasherFactory, HasherType, Blake2Wrapper };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from "chai";
|
|
2
|
-
import { SHAWrapper } from "../src-ts/hashers/index";
|
|
2
|
+
import { Blake2Wrapper, SHAWrapper } from "../src-ts/hashers/index";
|
|
3
3
|
|
|
4
4
|
describe("SHA512 Tests", () => {
|
|
5
5
|
it("hash", () => {
|
|
@@ -37,17 +37,116 @@ describe("SHA512 Tests", () => {
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
describe("SHA256 Tests", () => {
|
|
40
|
+
it("hash", () => {
|
|
41
|
+
const wrapper = new SHAWrapper();
|
|
42
|
+
const tohashed: string = "This is my array to hash";
|
|
43
|
+
const encoder = new TextEncoder();
|
|
44
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
46
|
+
assert.notEqual(tohashBytes, hashed);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("verify pass", () => {
|
|
50
|
+
const wrapper = new SHAWrapper();
|
|
51
|
+
const tohashed: string = "This is my array to hash";
|
|
52
|
+
const encoder = new TextEncoder();
|
|
53
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
54
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
55
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
56
|
+
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
57
|
+
assert.equal(true, verified);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("verify fail", () => {
|
|
61
|
+
const wrapper = new SHAWrapper();
|
|
62
|
+
const tohashed: string = "This is my array to hash";
|
|
63
|
+
const encoder = new TextEncoder();
|
|
64
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
65
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
66
|
+
const toVerify = "This Is Not The Same";
|
|
67
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
68
|
+
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
69
|
+
assert.equal(false, verified);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("Blake2 512", () => {
|
|
74
|
+
it("hash", () => {
|
|
75
|
+
const wrapper = new Blake2Wrapper();
|
|
76
|
+
const tohashed: string = "This is my array to hash";
|
|
77
|
+
const encoder = new TextEncoder();
|
|
78
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
79
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
80
|
+
assert.notEqual(tohashBytes, hashed);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("verify pass", () => {
|
|
84
|
+
const wrapper = new Blake2Wrapper();
|
|
85
|
+
const tohashed: string = "This is my array to hash";
|
|
86
|
+
const encoder = new TextEncoder();
|
|
87
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
88
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
89
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
90
|
+
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
91
|
+
assert.equal(true, verified);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("verify fail", () => {
|
|
95
|
+
const wrapper = new Blake2Wrapper();
|
|
96
|
+
const tohashed: string = "This is my array to hash";
|
|
97
|
+
const encoder = new TextEncoder();
|
|
98
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
99
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
100
|
+
const toVerify = "This Is Not The Same";
|
|
101
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
102
|
+
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
103
|
+
assert.equal(false, verified);
|
|
104
|
+
});
|
|
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
|
+
describe("Blake2 256", () => {
|
|
40
139
|
it("hash", () => {
|
|
41
|
-
const wrapper = new
|
|
140
|
+
const wrapper = new Blake2Wrapper();
|
|
42
141
|
const tohashed: string = "This is my array to hash";
|
|
43
142
|
const encoder = new TextEncoder();
|
|
44
143
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
144
|
const hashed = wrapper.hash256(tohashBytes);
|
|
46
145
|
assert.notEqual(tohashBytes, hashed);
|
|
47
146
|
});
|
|
48
|
-
|
|
147
|
+
|
|
49
148
|
it("verify pass", () => {
|
|
50
|
-
const wrapper = new
|
|
149
|
+
const wrapper = new Blake2Wrapper();
|
|
51
150
|
const tohashed: string = "This is my array to hash";
|
|
52
151
|
const encoder = new TextEncoder();
|
|
53
152
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
@@ -56,9 +155,9 @@ describe("SHA256 Tests", () => {
|
|
|
56
155
|
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
57
156
|
assert.equal(true, verified);
|
|
58
157
|
});
|
|
59
|
-
|
|
158
|
+
|
|
60
159
|
it("verify fail", () => {
|
|
61
|
-
const wrapper = new
|
|
160
|
+
const wrapper = new Blake2Wrapper();
|
|
62
161
|
const tohashed: string = "This is my array to hash";
|
|
63
162
|
const encoder = new TextEncoder();
|
|
64
163
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
@@ -68,4 +167,37 @@ describe("SHA256 Tests", () => {
|
|
|
68
167
|
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
69
168
|
assert.equal(false, verified);
|
|
70
169
|
});
|
|
71
|
-
|
|
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
|
+
});
|
|
203
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assert } from "chai";
|
|
2
2
|
import { AESWrapper } from "../src-ts/symmetric/aes-wrapper";
|
|
3
|
+
import { X25519Wrapper } from '../src-ts/key_exchange/x25519';
|
|
3
4
|
import { areEqual } from "./helpers/array";
|
|
4
5
|
|
|
5
6
|
describe("Symmetric Tests", () => {
|
|
@@ -28,4 +29,50 @@ describe("Symmetric Tests", () => {
|
|
|
28
29
|
var result = areEqual(plaintxt, tohashBytes);
|
|
29
30
|
assert.isTrue(result);
|
|
30
31
|
});
|
|
32
|
+
|
|
33
|
+
it("ase 256 X25519 Diffie-Hellman encrypt and decrypt", () => {
|
|
34
|
+
const x25519 = new X25519Wrapper();
|
|
35
|
+
const alice= x25519.generateSecretAndPublicKey();
|
|
36
|
+
const bob = x25519.generateSecretAndPublicKey();
|
|
37
|
+
|
|
38
|
+
const aliceSharedSecret = x25519.generateSharedSecret(alice.secretKey, bob.publicKey);
|
|
39
|
+
const bobSharedSecret = x25519.generateSharedSecret(bob.secretKey, alice.publicKey);
|
|
40
|
+
|
|
41
|
+
const aesWrapper: AESWrapper = new AESWrapper();
|
|
42
|
+
const aliceAesKey = aesWrapper.aes256KeyNonceX25519DiffieHellman(aliceSharedSecret);
|
|
43
|
+
const bobAesKey = aesWrapper.aes256KeyNonceX25519DiffieHellman(bobSharedSecret);
|
|
44
|
+
|
|
45
|
+
const tohashed: string = "This is my array to encrypt";
|
|
46
|
+
const encoder = new TextEncoder();
|
|
47
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
48
|
+
|
|
49
|
+
const aliceCiphertext = aesWrapper.aes256Encrypt(aliceAesKey.aesKey, aliceAesKey.aesNonce, tohashBytes);
|
|
50
|
+
const bobPlaintext = aesWrapper.aes256Decrypt(bobAesKey.aesKey, aliceAesKey.aesNonce, aliceCiphertext);
|
|
51
|
+
|
|
52
|
+
var result = areEqual(bobPlaintext, tohashBytes);
|
|
53
|
+
assert.isTrue(result);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("ase 128 X25519 Diffie-Hellman encrypt and decrypt", () => {
|
|
57
|
+
const x25519 = new X25519Wrapper();
|
|
58
|
+
const alice= x25519.generateSecretAndPublicKey();
|
|
59
|
+
const bob = x25519.generateSecretAndPublicKey();
|
|
60
|
+
|
|
61
|
+
const aliceSharedSecret = x25519.generateSharedSecret(alice.secretKey, bob.publicKey);
|
|
62
|
+
const bobSharedSecret = x25519.generateSharedSecret(bob.secretKey, alice.publicKey);
|
|
63
|
+
|
|
64
|
+
const aesWrapper: AESWrapper = new AESWrapper();
|
|
65
|
+
const aliceAesKey = aesWrapper.aes128KeyNonceX25519DiffieHellman(aliceSharedSecret);
|
|
66
|
+
const bobAesKey = aesWrapper.aes128KeyNonceX25519DiffieHellman(bobSharedSecret);
|
|
67
|
+
|
|
68
|
+
const tohashed: string = "This is my array to encrypt";
|
|
69
|
+
const encoder = new TextEncoder();
|
|
70
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
71
|
+
|
|
72
|
+
const aliceCiphertext = aesWrapper.aes128Encrypt(aliceAesKey.aesKey, aliceAesKey.aesNonce, tohashBytes);
|
|
73
|
+
const bobPlaintext = aesWrapper.aes128Decrypt(bobAesKey.aesKey, aliceAesKey.aesNonce, aliceCiphertext);
|
|
74
|
+
|
|
75
|
+
var result = areEqual(bobPlaintext, tohashBytes);
|
|
76
|
+
assert.isTrue(result);
|
|
77
|
+
});
|
|
31
78
|
});
|