cas-typescript-sdk 1.0.25 → 1.0.27

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/index.d.ts CHANGED
@@ -3,76 +3,80 @@
3
3
 
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
- export function argon2Hash(password: string): string
7
- export function argon2HashThreadPool(password: string): string
8
- export function argon2Verify(hashedPassword: string, passwordToVerify: string): boolean
9
- export function argon2VerifyThreadpool(hashedPassword: string, passwordToVerify: string): boolean
10
- export function bcryptHash(passwordToHash: string): string
11
- export function bcryptHashThreadpool(passwordToHash: string): string
12
- export function bcryptVerify(hashedPassword: string, passwordToVerify: string): boolean
13
- export function bcryptVerifyThreadpool(passwordToHash: string, passwordToVerify: string): boolean
14
- export function scryptHash(passwordToHash: string): string
15
- export function scryptVerify(hashedPassword: string, passwordToVerify: string): boolean
16
- export function scryptHashThreadpool(passwordToHash: string): string
17
- export function scryptVerifyThreadpool(hashedPassword: string, passwordToVerify: string): boolean
18
- export function sha512(dataToHash: Array<number>): Array<number>
19
- export function sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
20
- export function sha256(dataToHash: Array<number>): Array<number>
21
- export function sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
22
- export function x25519GenerateSecretAndPublicKey(): CASx25519SecretPublicKeyResult
23
- export function x25519DiffieHellman(mySecretKey: Array<number>, usersPublicKey: Array<number>): Array<number>
24
- export function aesNonce(): Array<number>
25
- export function aes128Key(): Array<number>
26
- export function aes256Key(): Array<number>
27
- export function aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
28
- export function aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
29
- export function aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
30
- export function aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
31
- export function aes256KeyFromX25519SharedSecret(sharedSecret: Array<number>): CASAesKeyFromX25519SharedSecret
32
- export function aes128KeyFromX25519SharedSecret(sharedSecret: Array<number>): CASAesKeyFromX25519SharedSecret
33
- export function generateRsaKeys(keySize: number): CasrsaKeyPairResult
34
- export function encryptPlaintextRsa(publicKey: string, plaintext: Array<number>): Array<number>
35
- export function decryptCiphertextRsa(privateKey: string, ciphertext: Array<number>): Array<number>
36
- export function signRsa(privateKey: string, hash: Array<number>): Array<number>
37
- export function verifyRsa(publicKey: string, hash: Array<number>, signature: Array<number>): boolean
38
- export function sha512RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CASRSADigitalSignatureResult
39
- export function sha512RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
40
- export function sha256RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CASRSADigitalSignatureResult
41
- export function sha256RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
42
- export function sha512Ed25519DigitalSignature(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult
43
- export function sha512Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
44
- export function sha256Ed25519DigitalSignature(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult
45
- export function sha256Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
46
- export function ascon128KeyGenerate(): Array<number>
47
- export function ascon128NonceGenerate(): Array<number>
48
- export function ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
49
- export function ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
6
+ export declare function argon2Hash(password: string): string
7
+ export declare function argon2HashThreadPool(password: string): string
8
+ export declare function argon2Verify(hashedPassword: string, passwordToVerify: string): boolean
9
+ export declare function argon2VerifyThreadpool(hashedPassword: string, passwordToVerify: string): boolean
10
+ export declare function bcryptHash(passwordToHash: string): string
11
+ export declare function bcryptHashThreadpool(passwordToHash: string): string
12
+ export declare function bcryptVerify(hashedPassword: string, passwordToVerify: string): boolean
13
+ export declare function bcryptVerifyThreadpool(passwordToHash: string, passwordToVerify: string): boolean
14
+ export declare function scryptHash(passwordToHash: string): string
15
+ 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
+ export declare function sha512(dataToHash: Array<number>): Array<number>
19
+ export declare function sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
20
+ export declare function sha256(dataToHash: Array<number>): Array<number>
21
+ export declare function sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
22
+ export declare function x25519GenerateSecretAndPublicKey(): CASx25519SecretPublicKeyResult
23
+ export declare function x25519DiffieHellman(mySecretKey: Array<number>, usersPublicKey: Array<number>): Array<number>
24
+ export declare function aesNonce(): Array<number>
25
+ export declare function aes128Key(): Array<number>
26
+ export declare function aes256Key(): Array<number>
27
+ export declare function aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
28
+ export declare function aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
29
+ export declare function aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
30
+ export declare function aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
31
+ export declare function aes256KeyFromX25519SharedSecret(sharedSecret: Array<number>): CASAesKeyFromX25519SharedSecret
32
+ export declare function aes128KeyFromX25519SharedSecret(sharedSecret: Array<number>): CASAesKeyFromX25519SharedSecret
33
+ export declare function generateRsaKeys(keySize: number): CasrsaKeyPairResult
34
+ export declare function encryptPlaintextRsa(publicKey: string, plaintext: Array<number>): Array<number>
35
+ export declare function decryptCiphertextRsa(privateKey: string, ciphertext: Array<number>): Array<number>
36
+ export declare function signRsa(privateKey: string, hash: Array<number>): Array<number>
37
+ export declare function verifyRsa(publicKey: string, hash: Array<number>, signature: Array<number>): boolean
38
+ export declare function sha512RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CASRSADigitalSignatureResult
39
+ export declare function sha512RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
40
+ export declare function sha256RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CASRSADigitalSignatureResult
41
+ export declare function sha256RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
42
+ export declare function sha512Ed25519DigitalSignature(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult
43
+ export declare function sha512Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
44
+ export declare function sha256Ed25519DigitalSignature(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult
45
+ export declare function sha256Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
46
+ export declare function ascon128KeyGenerate(): Array<number>
47
+ export declare function ascon128NonceGenerate(): Array<number>
48
+ export declare function ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
49
+ export declare function ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
50
+ export declare function hmacSign(key: Array<number>, message: Array<number>): Array<number>
51
+ export declare function hmacSignThreadpool(key: Array<number>, message: Array<number>): Array<number>
52
+ export declare function hmacVerify(key: Array<number>, message: Array<number>, signature: Array<number>): boolean
53
+ export declare function hmacVerifyThreadpool(key: Array<number>, message: Array<number>, signature: Array<number>): boolean
50
54
  export type CASx25519SecretPublicKeyResult = CaSx25519SecretPublicKeyResult
51
- export class CaSx25519SecretPublicKeyResult {
55
+ export declare class CaSx25519SecretPublicKeyResult {
52
56
  publicKey: Array<number>
53
57
  secretKey: Array<number>
54
58
  constructor(publicKey: Array<number>, secretKey: Array<number>)
55
59
  }
56
60
  export type CASAesKeyFromX25519SharedSecret = CasAesKeyFromX25519SharedSecret
57
- export class CasAesKeyFromX25519SharedSecret {
61
+ export declare class CasAesKeyFromX25519SharedSecret {
58
62
  aesKey: Array<number>
59
63
  aesNonce: Array<number>
60
64
  constructor(aesKey: Array<number>, aesNonce: Array<number>)
61
65
  }
62
66
  export type CASRSAKeyPairResult = CasrsaKeyPairResult
63
- export class CasrsaKeyPairResult {
67
+ export declare class CasrsaKeyPairResult {
64
68
  privateKey: string
65
69
  publicKey: string
66
70
  constructor(privateKey: string, publicKey: string)
67
71
  }
68
72
  export type CASSHAED25519DalekDigitalSignatureResult = Casshaed25519DalekDigitalSignatureResult
69
- export class Casshaed25519DalekDigitalSignatureResult {
73
+ export declare class Casshaed25519DalekDigitalSignatureResult {
70
74
  publicKey: Array<number>
71
75
  signature: Array<number>
72
76
  constructor(publicKey: Array<number>, signature: Array<number>)
73
77
  }
74
78
  export type CASRSADigitalSignatureResult = CasrsaDigitalSignatureResult
75
- export class CasrsaDigitalSignatureResult {
79
+ export declare class CasrsaDigitalSignatureResult {
76
80
  publicKey: string
77
81
  privateKey: string
78
82
  signature: 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,6 @@
1
-
2
1
  {
3
2
  "name": "cas-typescript-sdk",
4
- "version": "1.0.25",
3
+ "version": "1.0.27",
5
4
  "description": "",
6
5
  "main": "lib/index.js",
7
6
  "types": "lib/index.d.ts",
@@ -9,7 +8,7 @@
9
8
  "test": "cargo test && npm run build && mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
10
9
  "node:test": "mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
11
10
  "rust:test": "cargo test",
12
- "build": "npm run build:rust && rm -rf lib && tsc",
11
+ "build": "npm run build:rust && rimraf lib && tsc",
13
12
  "build:rust": "napi build --release",
14
13
  "prepare": "npm run build"
15
14
  },
@@ -29,13 +28,14 @@
29
28
  "registry": "https://registry.npmjs.org/"
30
29
  },
31
30
  "devDependencies": {
32
- "@napi-rs/cli": "^2.17.0",
31
+ "@napi-rs/cli": "^2.18.4",
33
32
  "@types/chai": "^4.3.11",
34
33
  "@types/mocha": "^10.0.6",
35
34
  "@types/node-fetch": "^2.6.3",
36
35
  "chai": "^4.4.1",
37
36
  "mocha": "^10.2.0",
38
37
  "ts-node": "^10.9.1",
39
- "typescript": "^5.0.3"
38
+ "typescript": "^5.0.3",
39
+ "rimraf": "^6.0.1"
40
40
  }
41
41
  }
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 key = b"ThisIsMyKeyForHmac".to_vec();
27
+ let 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 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
+ }
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
+ });