cas-typescript-sdk 1.0.24 → 1.0.26

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 CHANGED
@@ -10,11 +10,8 @@ crate-type = ["cdylib"]
10
10
  [dependencies]
11
11
  napi = "2"
12
12
  napi-derive = "2"
13
- rand = "0.8.5"
14
- rand_chacha = "0.3.1"
15
- rayon = "1.10.0"
16
13
  csbindgen = "1.9.1"
17
- cas-lib = "0.1.3"
14
+ cas-lib = "0.1.6"
18
15
 
19
16
  [build-dependencies]
20
17
  napi-build = "1"
package/README.md CHANGED
@@ -12,7 +12,7 @@ The official NPM page can be found [here](https://www.npmjs.com/package/cas-type
12
12
 
13
13
 
14
14
  ## Consuming Library Documentation
15
- This Node.js NPM module is dependent on our Rust layer [here](./src) that contains methods to run industry-standard cryptographic operations sequentially, on threads, and the thread pool.
15
+ 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.
16
16
 
17
17
  We utilize some smart people's existing work and we believe their documentation should be reviewed when possible.
18
18
  - [Spin Research](https://github.com/SpinResearch)
package/index.d.ts CHANGED
@@ -47,6 +47,10 @@ export function ascon128KeyGenerate(): Array<number>
47
47
  export function ascon128NonceGenerate(): Array<number>
48
48
  export function ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
49
49
  export function ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
50
+ export function hmacSign(key: Array<number>, message: Array<number>): Array<number>
51
+ export function hmacSignThreadpool(key: Array<number>, message: Array<number>): Array<number>
52
+ export function hmacVerify(key: Array<number>, message: Array<number>, signature: Array<number>): boolean
53
+ export function hmacVerifyThreadpool(key: Array<number>, message: Array<number>, signature: Array<number>): boolean
50
54
  export type CASx25519SecretPublicKeyResult = CaSx25519SecretPublicKeyResult
51
55
  export class CaSx25519SecretPublicKeyResult {
52
56
  publicKey: Array<number>
package/index.node CHANGED
Binary file
package/lib/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from "./asymmetric/index";
6
6
  export * from "./hybrid/index";
7
7
  export * from "./digital-signature";
8
8
  export * from "./sponges/index";
9
+ export * from "./message/index";
package/lib/index.js CHANGED
@@ -22,3 +22,4 @@ __exportStar(require("./asymmetric/index"), exports);
22
22
  __exportStar(require("./hybrid/index"), exports);
23
23
  __exportStar(require("./digital-signature"), exports);
24
24
  __exportStar(require("./sponges/index"), exports);
25
+ __exportStar(require("./message/index"), exports);
@@ -0,0 +1,6 @@
1
+ export declare class HmacWrapper {
2
+ hmacSignBytes(key: Array<number>, message: Array<number>): Array<number>;
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
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HmacWrapper = void 0;
4
+ const index_1 = require("../../index");
5
+ class HmacWrapper {
6
+ hmacSignBytes(key, message) {
7
+ if (key?.length === 0) {
8
+ throw new Error("Must provide an allocated key");
9
+ }
10
+ if (message?.length === 0) {
11
+ throw new Error("Must provide an allocated message");
12
+ }
13
+ return (0, index_1.hmacSign)(key, message);
14
+ }
15
+ hmacVerifyBytes(key, message, signature) {
16
+ if (key?.length === 0) {
17
+ throw new Error("Must provide an allocated key");
18
+ }
19
+ if (message?.length === 0) {
20
+ throw new Error("Must provide an allocated message");
21
+ }
22
+ if (signature?.length === 0) {
23
+ throw new Error("Must provide an allocated signature");
24
+ }
25
+ return (0, index_1.hmacVerify)(key, message, signature);
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
+ }
49
+ exports.HmacWrapper = HmacWrapper;
@@ -0,0 +1,2 @@
1
+ import { HmacWrapper } from "./hmac";
2
+ export { HmacWrapper };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HmacWrapper = void 0;
4
+ const hmac_1 = require("./hmac");
5
+ Object.defineProperty(exports, "HmacWrapper", { enumerable: true, get: function () { return hmac_1.HmacWrapper; } });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  {
3
3
  "name": "cas-typescript-sdk",
4
- "version": "1.0.24",
4
+ "version": "1.0.26",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -1,4 +1,4 @@
1
- use cas_lib::asymmetric::{cas_asymmetric_encryption::{CASRSAEncryption, RSAKeyPairResult}, cas_rsa::CASRSA};
1
+ use cas_lib::asymmetric::{cas_asymmetric_encryption::CASRSAEncryption, cas_rsa::CASRSA, types::RSAKeyPairResult};
2
2
  use napi_derive::napi;
3
3
 
4
4
  #[napi(constructor)]
@@ -18,7 +18,7 @@ impl From<RSAKeyPairResult> for CASRSAKeyPairResult {
18
18
 
19
19
  #[napi]
20
20
  pub fn generate_rsa_keys(key_size: u32) -> CASRSAKeyPairResult {
21
- return CASRSA::generate_rsa_keys(key_size).into();
21
+ return CASRSA::generate_rsa_keys(key_size as usize).into();
22
22
  }
23
23
 
24
24
  #[napi]
package/src/lib.rs CHANGED
@@ -32,4 +32,8 @@ mod digital_signature {
32
32
 
33
33
  mod sponges {
34
34
  pub mod ascon_aead;
35
+ }
36
+
37
+ mod message {
38
+ pub mod hmac;
35
39
  }
@@ -0,0 +1,40 @@
1
+ use cas_lib::message::{cas_hmac::CASHMAC, hmac::HMAC};
2
+ use napi_derive::napi;
3
+
4
+ #[napi]
5
+ pub fn hmac_sign(key: Vec<u8>, message: Vec<u8>) -> Vec<u8> {
6
+ return <HMAC as CASHMAC>::sign(key, message);
7
+ }
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
+ #[napi]
15
+ pub fn hmac_verify(key: Vec<u8>, message: Vec<u8>, signature: Vec<u8>) -> bool {
16
+ return <HMAC as CASHMAC>::verify(key, message, signature);
17
+ }
18
+
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
+ #[test]
25
+ fn hmac_sign_and_verify_test() {
26
+ let mut key = b"ThisIsMyKeyForHmac".to_vec();
27
+ let mut message = b"ThisIsMyMessageToSign".to_vec();
28
+ let signature = hmac_sign(key.clone(), message.clone());
29
+ let result = hmac_verify(key, message, signature);
30
+ assert_eq!(true, result);
31
+ }
32
+
33
+ #[test]
34
+ fn hmac_sign_and_verify_threadpool_test() {
35
+ let mut key = b"ThisIsMyKeyForHmac7789".to_vec();
36
+ let mut 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
+ }
@@ -1,17 +1,11 @@
1
1
  use cas_lib::symmetric::{aes::{CASAES128, CASAES256}, cas_symmetric_encryption::CASAESEncryption};
2
2
  use napi_derive::napi;
3
- use rand::{RngCore, SeedableRng};
4
- use rand_chacha::ChaCha20Rng;
5
3
 
6
4
  use super::types::CASAesKeyFromX25519SharedSecret;
7
5
 
8
6
  #[napi]
9
7
  pub fn aes_nonce() -> Vec<u8> {
10
- let mut rng = ChaCha20Rng::from_entropy();
11
- let mut random_bytes = Vec::with_capacity(12);
12
- random_bytes.resize(12, 0);
13
- rng.fill_bytes(&mut random_bytes);
14
- random_bytes
8
+ return <CASAES256 as CASAESEncryption>::generate_nonce();
15
9
  }
16
10
 
17
11
  #[napi]
package/src-ts/index.ts CHANGED
@@ -5,4 +5,5 @@ export * from "./symmetric/index";
5
5
  export * from "./asymmetric/index";
6
6
  export * from "./hybrid/index";
7
7
  export * from "./digital-signature";
8
- export * from "./sponges/index";
8
+ export * from "./sponges/index";
9
+ export * from "./message/index";
@@ -0,0 +1,49 @@
1
+ import { hmacSign, hmacSignThreadpool, hmacVerify, hmacVerifyThreadpool } from "../../index";
2
+
3
+ export class HmacWrapper {
4
+ public hmacSignBytes(key: Array<number>, message: Array<number>): Array<number> {
5
+ if (key?.length === 0) {
6
+ throw new Error("Must provide an allocated key");
7
+ }
8
+ if (message?.length === 0) {
9
+ throw new Error("Must provide an allocated message");
10
+ }
11
+ return hmacSign(key, message);
12
+ }
13
+
14
+ public hmacVerifyBytes(key: Array<number>, message: Array<number>, signature: Array<number>): boolean {
15
+ if (key?.length === 0) {
16
+ throw new Error("Must provide an allocated key");
17
+ }
18
+ if (message?.length === 0) {
19
+ throw new Error("Must provide an allocated message");
20
+ }
21
+ if(signature?.length===0) {
22
+ throw new Error("Must provide an allocated signature");
23
+ }
24
+ return hmacVerify(key, message, signature);
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
+ }
@@ -0,0 +1,3 @@
1
+ import { HmacWrapper } from "./hmac";
2
+
3
+ export { HmacWrapper };
@@ -0,0 +1,32 @@
1
+ import { assert } from "chai";
2
+ import { HmacWrapper } from "../src-ts/message/index";
3
+
4
+ describe("HMAC Tests", () => {
5
+ it("Sign and Verify", () => {
6
+ const wrapper = new HmacWrapper();
7
+ const key: string = "This is my array to hash";
8
+ const encoder = new TextEncoder();
9
+ const keyBytes: Array<number> = Array.from(encoder.encode(key));
10
+ const message: string = "This is my message";
11
+ const messageBytes = Array.from(encoder.encode(message));
12
+ const signature = wrapper.hmacSignBytes(keyBytes, messageBytes);
13
+ const result = wrapper.hmacVerifyBytes(keyBytes, messageBytes, signature);
14
+ assert.equal(true, result);
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
+ });