cas-typescript-sdk 1.0.46 → 1.0.48

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.
Files changed (75) hide show
  1. package/index.darwin-x64.node +0 -0
  2. package/index.linux-x64-gnu.node +0 -0
  3. package/index.linux-x64-musl.node +0 -0
  4. package/index.win32-x64-msvc.node +0 -0
  5. package/package.json +11 -4
  6. package/.github/workflows/main-pr-linux.yml +0 -28
  7. package/.github/workflows/main-pr-windows.yml +0 -28
  8. package/.github/workflows/main-publish.yml +0 -32
  9. package/Cargo.toml +0 -19
  10. package/build.rs +0 -5
  11. package/docs/EXAMPLES.md +0 -138
  12. package/index.node +0 -0
  13. package/src/asymmetric/cas_ed25519.rs +0 -35
  14. package/src/asymmetric/cas_rsa.rs +0 -32
  15. package/src/digital_signature/sha_256_rsa.rs +0 -40
  16. package/src/digital_signature/sha_512_rsa.rs +0 -40
  17. package/src/digital_signature/types.rs +0 -34
  18. package/src/hashers/blake2.rs +0 -60
  19. package/src/hashers/sha.rs +0 -68
  20. package/src/hybrid/hpke.rs +0 -63
  21. package/src/hybrid/types.rs +0 -15
  22. package/src/key_exchange/types.rs +0 -17
  23. package/src/key_exchange/x25519.rs +0 -25
  24. package/src/lib.rs +0 -47
  25. package/src/message/hmac.rs +0 -21
  26. package/src/password_hashers/argon2.rs +0 -37
  27. package/src/password_hashers/bcrypt.rs +0 -37
  28. package/src/password_hashers/scrypt.rs +0 -36
  29. package/src/sponges/ascon_aead.rs +0 -66
  30. package/src/symmetric/aes.rs +0 -71
  31. package/src-ts/asymmetric/RSAWrapper.ts +0 -59
  32. package/src-ts/asymmetric/index.ts +0 -4
  33. package/src-ts/digital-signature/digital-siganture-sha-512.ts +0 -40
  34. package/src-ts/digital-signature/digital-signature-base.ts +0 -6
  35. package/src-ts/digital-signature/digital-signature-factory.ts +0 -25
  36. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +0 -41
  37. package/src-ts/digital-signature/index.ts +0 -14
  38. package/src-ts/hashers/blake2-wrapper.ts +0 -43
  39. package/src-ts/hashers/hasher-base.ts +0 -6
  40. package/src-ts/hashers/hasher-factory.ts +0 -19
  41. package/src-ts/hashers/hasher-type.ts +0 -4
  42. package/src-ts/hashers/index.ts +0 -6
  43. package/src-ts/hashers/sha-wrapper.ts +0 -60
  44. package/src-ts/hybrid/hpke.ts +0 -44
  45. package/src-ts/hybrid/index.ts +0 -3
  46. package/src-ts/index.ts +0 -10
  47. package/src-ts/key_exchange/index.ts +0 -4
  48. package/src-ts/key_exchange/x25519.ts +0 -23
  49. package/src-ts/message/hmac.ts +0 -26
  50. package/src-ts/message/index.ts +0 -3
  51. package/src-ts/password-hashers/argon2-wrapper.ts +0 -31
  52. package/src-ts/password-hashers/bcrypt-wrapper.ts +0 -35
  53. package/src-ts/password-hashers/index.ts +0 -14
  54. package/src-ts/password-hashers/password-hasher-base.ts +0 -4
  55. package/src-ts/password-hashers/password-hasher-factory.ts +0 -25
  56. package/src-ts/password-hashers/password-hasher-type.ts +0 -5
  57. package/src-ts/password-hashers/scrypt-wrapper.ts +0 -32
  58. package/src-ts/signature/ed25519-wrapper.ts +0 -36
  59. package/src-ts/signature/index.ts +0 -3
  60. package/src-ts/sponges/ascon-wrapper.ts +0 -72
  61. package/src-ts/sponges/index.ts +0 -3
  62. package/src-ts/symmetric/aes-wrapper.ts +0 -101
  63. package/src-ts/symmetric/index.ts +0 -3
  64. package/test-ts/asymmetric.test.spec.ts +0 -15
  65. package/test-ts/digital-signature.test.spec.ts +0 -70
  66. package/test-ts/hasher.test.spec.ts +0 -139
  67. package/test-ts/helpers/array.ts +0 -10
  68. package/test-ts/hmac.test.spec.ts +0 -16
  69. package/test-ts/hybrid.test.spec.ts +0 -23
  70. package/test-ts/insecure-channel.test.spec.ts +0 -55
  71. package/test-ts/key-exchange.test.spec.ts +0 -23
  72. package/test-ts/password-hasher.test.spec.ts +0 -104
  73. package/test-ts/sponges.test.spec.ts +0 -28
  74. package/test-ts/symmetric.test.spec.ts +0 -82
  75. package/tsconfig.json +0 -22
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cas-typescript-sdk",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -8,9 +8,9 @@
8
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
- "build": "npm run build:rust && rimraf lib && tsc",
12
- "build:rust": "napi build --release",
13
- "postinstall": "npm run build"
11
+ "build:ts": "rimraf lib && tsc",
12
+ "build:rust": "napi build --release --platform",
13
+ "build": "npm run build:rust && npm run build:ts"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -23,6 +23,13 @@
23
23
  "url": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk/issues"
24
24
  },
25
25
  "homepage": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk#readme",
26
+ "files": [
27
+ "lib",
28
+ "index.js",
29
+ "index.d.ts",
30
+ "*.node",
31
+ "README.md"
32
+ ],
26
33
  "publishConfig": {
27
34
  "access": "public",
28
35
  "registry": "https://registry.npmjs.org/"
@@ -1,28 +0,0 @@
1
- # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
- # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
-
4
- name: Linux Build / Test
5
-
6
- on:
7
- pull_request:
8
- branches: [ "main" ]
9
-
10
- jobs:
11
- build:
12
-
13
- runs-on: ubuntu-latest
14
-
15
- strategy:
16
- matrix:
17
- node-version: [24.x]
18
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
-
20
- steps:
21
- - uses: actions/checkout@v3
22
- - name: Use Node.js ${{ matrix.node-version }}
23
- uses: actions/setup-node@v3
24
- with:
25
- node-version: ${{ matrix.node-version }}
26
- cache: 'npm'
27
- - run: npm ci
28
- - run: npm test
@@ -1,28 +0,0 @@
1
- # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
- # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
-
4
- name: Windows Build / Test
5
-
6
- on:
7
- pull_request:
8
- branches: [ "main" ]
9
-
10
- jobs:
11
- build:
12
-
13
- runs-on: windows-latest
14
-
15
- strategy:
16
- matrix:
17
- node-version: [24.x]
18
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
-
20
- steps:
21
- - uses: actions/checkout@v3
22
- - name: Use Node.js ${{ matrix.node-version }}
23
- uses: actions/setup-node@v3
24
- with:
25
- node-version: ${{ matrix.node-version }}
26
- cache: 'npm'
27
- - run: npm ci
28
- - run: npm test
@@ -1,32 +0,0 @@
1
- # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
- # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
-
4
- name: Node.js CI
5
-
6
- on:
7
- push:
8
- branches: [ "main" ]
9
-
10
- jobs:
11
- build:
12
-
13
- runs-on: ubuntu-latest
14
-
15
- strategy:
16
- matrix:
17
- node-version: [24.x]
18
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
-
20
- steps:
21
- - uses: actions/checkout@v3
22
- - name: Use Node.js ${{ matrix.node-version }}
23
- uses: actions/setup-node@v3
24
- with:
25
- node-version: ${{ matrix.node-version }}
26
- registry-url: 'https://registry.npmjs.org'
27
- cache: 'npm'
28
- - run: npm ci
29
- - run: npm test
30
- - run: npm publish
31
- env:
32
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/Cargo.toml DELETED
@@ -1,19 +0,0 @@
1
- [package]
2
- name = "cas-typescript-sdk-napi"
3
- version = "0.1.0"
4
- edition = "2021"
5
-
6
- [lib]
7
- path = "src/lib.rs"
8
- crate-type = ["cdylib"]
9
-
10
- [dependencies]
11
- napi = "3"
12
- napi-derive = "3"
13
- csbindgen = "1.9.3"
14
- cas-lib = { version = "=0.2.65" }
15
- zeroize = "1.8.1"
16
- zeroizing-alloc = "0.1.0"
17
-
18
- [build-dependencies]
19
- napi-build = "1"
package/build.rs DELETED
@@ -1,5 +0,0 @@
1
- extern crate napi_build;
2
-
3
- fn main() {
4
- napi_build::setup();
5
- }
package/docs/EXAMPLES.md DELETED
@@ -1,138 +0,0 @@
1
- ### Symmetric
2
- - AES 256
3
- ```typescript
4
- const aesWrapper: AESWrapper = new AESWrapper();
5
- const aesKey = aesWrapper.aes128Key();
6
- const aesNonce = aesWrapper.aesNonce();
7
- const toEncrypt: string = "This is my array to encrypt";
8
- const encoder = new TextEncoder();
9
- const tohashBytes: Array<number> = Array.from(encoder.encode(toEncrypt));
10
- const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
11
- const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
12
- ```
13
-
14
- ### Asymmetric
15
- -RSA
16
- ```typescript
17
- const rsaWrapper: RSAWrapper = new RSAWrapper();
18
- const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
19
- const tohashed: string = "This is my array to encrypt";
20
- const encoder = new TextEncoder();
21
- const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
22
- const ciphertext = rsaWrapper.encrypt(keys.publicKey, tohashBytes);
23
- const plaintext = rsaWrapper.decrypt(keys.privateKey, ciphertext);
24
- ```
25
-
26
-
27
- ### Digital Signature
28
- -ED25519 SHA
29
- ```typescript
30
- const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
31
- const toHash: string = "This is my array to encrypt";
32
- const encoder = new TextEncoder();
33
- const toHashBytes: Array<number> = Array.from(encoder.encode(toHash));
34
- const dsResult = shaDsWrapper.createED25519(toHashBytes);
35
- const verify = shaDsWrapper.verifyED25519(dsResult.publicKey, toHashBytes, dsResult.signature);
36
- ```
37
-
38
- -RSA SHA
39
- ```typescript
40
- const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
41
- const tohashed: string = "This is my array to encrypt";
42
- const notOriginal: string = "This is not a fun time";
43
- const encoder = new TextEncoder();
44
- const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
45
- const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
46
- const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
47
- const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
48
- ```
49
-
50
-
51
- ### Hashers
52
- -SHA3 512
53
- ```typescript
54
- const wrapper = new SHAWrapper();
55
- const tohashed: string = "This is my array to hash";
56
- const encoder = new TextEncoder();
57
- const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
58
- const hashed = wrapper.hash512(tohashBytes);
59
- ```
60
-
61
- -SHA3 256
62
- ```typescript
63
- const wrapper = new SHAWrapper();
64
- const tohashed: string = "This is my array to hash";
65
- const encoder = new TextEncoder();
66
- const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
67
- const hashed = wrapper.hash256(tohashBytes);
68
- ```
69
-
70
- ### Hybrid Encryption
71
- -AES/RSA Encryption
72
- ```typescript
73
- const hybridWrapper = new HybridEncryptionWrapper();
74
- let initalizer = new AESRSAHybridInitializer(128, 4096);
75
- const tohashed: string = "This is my encrypt text for rsa hybrid";
76
- const encoder = new TextEncoder();
77
- const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
78
- let result: AesRsaHybridEncryptResult = hybridWrapper.encrypt(toEncrypt, initalizer);
79
- let plaintext: Array<number> = hybridWrapper.decrypt(initalizer.rsaKeyPair.privateKey, result);
80
- ```
81
-
82
- ### Key Exchange
83
- -X25519
84
- ```typescript
85
- const wrapper = new X25519Wrapper();
86
- const alice = wrapper.generateSecretAndPublicKey();
87
- const bob = wrapper.generateSecretAndPublicKey();
88
-
89
- const alice_shared_secret = wrapper.generateSharedSecret(
90
- alice.secretKey,
91
- bob.publicKey,
92
- );
93
- const bob_shared_secret = wrapper.generateSharedSecret(
94
- bob.secretKey,
95
- alice.publicKey,
96
- );
97
-
98
- var result = areEqual(alice_shared_secret, bob_shared_secret);
99
- ```
100
-
101
- ### Sponges
102
- -Ascon 128
103
- ```typescript
104
- const wrapper: AsconWrapper = new AsconWrapper();
105
- const key: Array<number> = wrapper.ascon128Key();
106
- const nonce: Array<number> = wrapper.ascon128Nonce();
107
- const tohashed: string = "This is my array to encrypt";
108
- const encoder = new TextEncoder();
109
- const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
110
- const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
111
- const plaintext = wrapper.ascon128Decrypt(key, nonce, ciphertext);
112
- ```
113
-
114
- ### Passwords
115
- - BCrypt
116
- ```typescript
117
- const hasher: BCryptWrapper = new BCryptWrapper();
118
- const password: string = "ThisOneBadPassword!@";
119
- const hashedPassword: string = hasher.hashPassword(password);
120
- ```
121
-
122
- - SCrypt
123
- ```typescript
124
- const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
125
- PasswordHasherType.Scrypt,
126
- );
127
- const password: string = "ScryptRocks";
128
- const hashed: string = hasher.hashPassword(password);
129
- ```
130
-
131
- - Argon2
132
- ```typescript
133
- const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
134
- PasswordHasherType.Argon2,
135
- );
136
- const password: string = "ScryptRocks";
137
- const hashed: string = hasher.hashPassword(password);
138
- ```
package/index.node DELETED
Binary file
@@ -1,35 +0,0 @@
1
-
2
- use cas_lib::signatures::cas_ed25519::{Ed25519ByteKeyPair, Ed25519ByteSignature};
3
- use cas_lib::signatures::ed25519::{get_ed25519_key_pair, ed25519_sign_with_key_pair, ed25519_verify_with_public_key};
4
- use napi_derive::napi;
5
-
6
- #[napi(constructor)]
7
- pub struct CASED25519KeyPairResult {
8
- pub private_key: Vec<u8>,
9
- pub public_key: Vec<u8>,
10
- }
11
-
12
- impl From<Ed25519ByteKeyPair> for CASED25519KeyPairResult {
13
- fn from(result: Ed25519ByteKeyPair) -> Self {
14
- CASED25519KeyPairResult {
15
- private_key: result.key_pair,
16
- public_key: result.public_key
17
- }
18
- }
19
- }
20
-
21
- #[napi]
22
- pub fn generate_ed25519_keys() -> CASED25519KeyPairResult {
23
- return get_ed25519_key_pair().into();
24
- }
25
-
26
- #[napi]
27
- pub fn sign_ed25519(private_key: Vec<u8>, message: Vec<u8>) -> Vec<u8> {
28
- let signature = ed25519_sign_with_key_pair(private_key, message);
29
- signature.signature // assuming Ed25519ByteSignature has a field named `signature: Vec<u8>`
30
- }
31
-
32
- #[napi]
33
- pub fn verify_ed25519(public_key: Vec<u8>, message: Vec<u8>, signature: Vec<u8>) -> bool {
34
- return ed25519_verify_with_public_key(public_key, signature, message);
35
- }
@@ -1,32 +0,0 @@
1
- use cas_lib::asymmetric::{cas_rsa::CASRSA, types::{CASRSAEncryption, RSAKeyPairResult}};
2
- use napi_derive::napi;
3
-
4
- #[napi(constructor)]
5
- pub struct CASRSAKeyPairResult {
6
- pub private_key: String,
7
- pub public_key: String,
8
- }
9
-
10
- impl From<RSAKeyPairResult> for CASRSAKeyPairResult {
11
- fn from(result: RSAKeyPairResult) -> Self {
12
- CASRSAKeyPairResult {
13
- private_key: result.private_key,
14
- public_key: result.public_key,
15
- }
16
- }
17
- }
18
-
19
- #[napi]
20
- pub fn generate_rsa_keys(key_size: u32) -> CASRSAKeyPairResult {
21
- return CASRSA::generate_rsa_keys(key_size as usize).into();
22
- }
23
-
24
- #[napi]
25
- pub fn sign_rsa(private_key: String, hash: Vec<u8>) -> Vec<u8> {
26
- return CASRSA::sign(private_key, hash);
27
- }
28
-
29
- #[napi]
30
- pub fn verify_rsa(public_key: String, hash: Vec<u8>, signature: Vec<u8>) -> bool {
31
- return CASRSA::verify(public_key, hash, signature);
32
- }
@@ -1,40 +0,0 @@
1
- use cas_lib::digital_signature::{cas_digital_signature_rsa::RSADigitalSignature, sha_256_rsa::SHA256RSADigitalSignature};
2
- use napi_derive::napi;
3
-
4
- use super::types::CASRSADigitalSignatureResult;
5
-
6
- #[napi]
7
- pub fn sha_256_rsa_digital_signature(
8
- rsa_key_size: u32,
9
- data_to_sign: Vec<u8>,
10
- ) -> CASRSADigitalSignatureResult {
11
- return <SHA256RSADigitalSignature as RSADigitalSignature>::digital_signature_rsa(rsa_key_size, data_to_sign).into();
12
- }
13
-
14
- #[napi]
15
- pub fn sha_256_rsa_verify_digital_signature(
16
- public_key: String,
17
- data_to_verify: Vec<u8>,
18
- signature: Vec<u8>,
19
- ) -> bool {
20
- return <SHA256RSADigitalSignature as RSADigitalSignature>::verify_rsa(public_key, data_to_verify, signature);
21
- }
22
-
23
- #[test]
24
- fn sha_256_rsa_digital_signature_test() {
25
- let key_size: u32 = 1024;
26
- let data_to_sign = b"GetTheseBytes".to_vec();
27
- let signature_result: CASRSADigitalSignatureResult = <SHA256RSADigitalSignature as RSADigitalSignature>::digital_signature_rsa(key_size, data_to_sign.clone()).into();
28
- let is_verified: bool = SHA256RSADigitalSignature::verify_rsa(signature_result.public_key, data_to_sign, signature_result.signature);
29
- assert_eq!(is_verified, true);
30
- }
31
-
32
- #[test]
33
- fn sha_256_rsa_digital_signature_fail_test() {
34
- let key_size: u32 = 1024;
35
- let data_to_sign = b"GetTheseBytes".to_vec();
36
- let signature_result: CASRSADigitalSignatureResult = <SHA256RSADigitalSignature as RSADigitalSignature>::digital_signature_rsa(key_size, data_to_sign.clone()).into();
37
- let new_data = b"NOtTheOriginalData".to_vec();
38
- let is_verified: bool = SHA256RSADigitalSignature::verify_rsa(signature_result.public_key, new_data, signature_result.signature);
39
- assert_eq!(is_verified, false);
40
- }
@@ -1,40 +0,0 @@
1
- use cas_lib::digital_signature::{cas_digital_signature_rsa::RSADigitalSignature, sha_512_rsa::SHA512RSADigitalSignature};
2
- use napi_derive::napi;
3
-
4
- use super::types::CASRSADigitalSignatureResult;
5
-
6
- #[napi]
7
- pub fn sha_512_rsa_digital_signature(
8
- rsa_key_size: u32,
9
- data_to_sign: Vec<u8>,
10
- ) -> CASRSADigitalSignatureResult {
11
- return <SHA512RSADigitalSignature as RSADigitalSignature>::digital_signature_rsa(rsa_key_size, data_to_sign).into();
12
- }
13
-
14
- #[napi]
15
- pub fn sha_512_rsa_verify_digital_signature(
16
- public_key: String,
17
- data_to_verify: Vec<u8>,
18
- signature: Vec<u8>,
19
- ) -> bool {
20
- return <SHA512RSADigitalSignature as RSADigitalSignature>::verify_rsa(public_key, data_to_verify, signature);
21
- }
22
-
23
- #[test]
24
- fn sha_512_rsa_digital_signature_test() {
25
- let key_size: u32 = 1024;
26
- let data_to_sign = b"GetTheseBytes".to_vec();
27
- let signature_result: CASRSADigitalSignatureResult = SHA512RSADigitalSignature::digital_signature_rsa(key_size, data_to_sign.clone()).into();
28
- let is_verified: bool = <SHA512RSADigitalSignature as RSADigitalSignature>::verify_rsa(signature_result.public_key, data_to_sign, signature_result.signature);
29
- assert_eq!(is_verified, true);
30
- }
31
-
32
- #[test]
33
- fn sha_512_rsa_digital_signature_fail_test() {
34
- let key_size: u32 = 1024;
35
- let data_to_sign = b"GetTheseBytes".to_vec();
36
- let signature_result: CASRSADigitalSignatureResult = SHA512RSADigitalSignature::digital_signature_rsa(key_size, data_to_sign.clone()).into();
37
- let new_data = b"NOtTheOriginalData".to_vec();
38
- let is_verified: bool = <SHA512RSADigitalSignature as RSADigitalSignature>::verify_rsa(signature_result.public_key, new_data, signature_result.signature);
39
- assert_eq!(is_verified, false);
40
- }
@@ -1,34 +0,0 @@
1
- use cas_lib::digital_signature::cas_digital_signature_rsa::{RSADigitalSignatureResult, SHAED25519DalekDigitalSignatureResult};
2
- use napi_derive::napi;
3
-
4
- #[napi(constructor)]
5
- pub struct CASSHAED25519DalekDigitalSignatureResult {
6
- pub public_key: Vec<u8>,
7
- pub signature: Vec<u8>
8
- }
9
-
10
- impl From<SHAED25519DalekDigitalSignatureResult> for CASSHAED25519DalekDigitalSignatureResult {
11
- fn from(value: SHAED25519DalekDigitalSignatureResult) -> Self {
12
- CASSHAED25519DalekDigitalSignatureResult {
13
- public_key: value.public_key.to_vec(),
14
- signature: value.signature.to_vec()
15
- }
16
- }
17
- }
18
-
19
- #[napi(constructor)]
20
- pub struct CASRSADigitalSignatureResult {
21
- pub public_key: String,
22
- pub private_key: String,
23
- pub signature: Vec<u8>,
24
- }
25
-
26
- impl From<RSADigitalSignatureResult> for CASRSADigitalSignatureResult {
27
- fn from(value: RSADigitalSignatureResult) -> Self {
28
- CASRSADigitalSignatureResult {
29
- public_key: value.public_key,
30
- private_key: value.private_key,
31
- signature: value.signature
32
- }
33
- }
34
- }
@@ -1,60 +0,0 @@
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_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
11
- return CASBlake2::verify_512(data_to_hash, data_to_verify);
12
- }
13
-
14
- #[napi]
15
- pub fn blake2_sha_256(data_to_hash: Vec<u8>) -> Vec<u8> {
16
- return CASBlake2::hash_256(data_to_hash);
17
- }
18
-
19
- #[napi]
20
- pub fn blake2_sha_256_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
21
- return CASBlake2::verify_256(data_to_hash, data_to_verify);
22
- }
23
-
24
- #[test]
25
- pub fn blake2_sha_512_test() {
26
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
27
- let hashed_data = blake2_sha_512(data_to_hash.clone());
28
- assert_ne!(true, hashed_data.eq(&data_to_hash));
29
- }
30
-
31
- #[test]
32
- pub fn blake2_sha_512_verify_fail_test() {
33
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
34
- let _hashed_data = blake2_sha_512(data_to_hash.clone());
35
- let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
36
- assert_ne!(true, blake2_sha_512_verify(data_to_hash, data_to_verify));
37
- }
38
-
39
- #[test]
40
- pub fn blake2_sha_256_test() {
41
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
42
- let hashed_data = blake2_sha_256(data_to_hash.clone());
43
- assert_ne!(true, hashed_data.eq(&data_to_hash));
44
- }
45
-
46
- #[test]
47
- pub fn blake2_sha_256_verify_test() {
48
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
49
- let _hashed_data = blake2_sha_256(data_to_hash.clone());
50
- let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
51
- assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
52
- }
53
-
54
- #[test]
55
- pub fn blake2_sha_256_verify_fail_test() {
56
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
57
- let _hashed_data = blake2_sha_256(data_to_hash.clone());
58
- let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
59
- assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
60
- }
@@ -1,68 +0,0 @@
1
- use cas_lib::hashers::{cas_hasher::CASHasher, sha::CASSHA};
2
- use napi_derive::napi;
3
-
4
- #[napi]
5
- pub fn sha_512(data_to_hash: Vec<u8>) -> Vec<u8> {
6
- return <CASSHA as CASHasher>::hash_512(data_to_hash);
7
- }
8
-
9
- #[napi]
10
- pub fn sha_512_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
11
- return <CASSHA as CASHasher>::verify_512(data_to_hash, data_to_verify);
12
- }
13
-
14
- #[napi]
15
- pub fn sha_256(data_to_hash: Vec<u8>) -> Vec<u8> {
16
- return <CASSHA as CASHasher>::hash_256(data_to_hash);
17
- }
18
-
19
- #[napi]
20
- pub fn sha_256_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
21
- return <CASSHA as CASHasher>::verify_256(data_to_hash, data_to_verify);
22
- }
23
-
24
- #[test]
25
- pub fn sha_512_test() {
26
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
27
- let hashed_data = sha_512(data_to_hash.clone());
28
- assert_ne!(true, hashed_data.eq(&data_to_hash));
29
- }
30
-
31
- #[test]
32
- pub fn sha_512_verify_test() {
33
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
34
- let hashed_data = sha_512(data_to_hash.clone());
35
- let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
36
- assert_ne!(true, sha_512_verify(data_to_hash, data_to_verify));
37
- }
38
-
39
- #[test]
40
- pub fn sha_512_verify_fail_test() {
41
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
42
- let _hashed_data = sha_512(data_to_hash.clone());
43
- let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
44
- assert_ne!(true, sha_512_verify(data_to_hash, data_to_verify));
45
- }
46
-
47
- #[test]
48
- pub fn sha_256_test() {
49
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
50
- let hashed_data = sha_256(data_to_hash.clone());
51
- assert_ne!(true, hashed_data.eq(&data_to_hash));
52
- }
53
-
54
- #[test]
55
- pub fn sha_256_verify_test() {
56
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
57
- let _hashed_data = sha_256(data_to_hash.clone());
58
- let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
59
- assert_ne!(true, sha_256_verify(data_to_hash, data_to_verify));
60
- }
61
-
62
- #[test]
63
- pub fn sha_256_verify_fail_test() {
64
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
65
- let _hashed_data = sha_256(data_to_hash.clone());
66
- let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
67
- assert_ne!(true, sha_256_verify(data_to_hash, data_to_verify));
68
- }
@@ -1,63 +0,0 @@
1
- use crate::hybrid::types::{HpkeEncryptResult, HpkeKeyResult};
2
- use cas_lib::hybrid::{cas_hybrid::CASHybrid, hpke::CASHPKE};
3
- use napi_derive::napi;
4
-
5
- #[napi]
6
- pub fn hpke_generate_keypair() -> HpkeKeyResult {
7
- let (secret_key, public_key, info_str) = <CASHPKE as CASHybrid>::generate_key_pair();
8
- HpkeKeyResult {
9
- public_key: public_key,
10
- secret_key: secret_key,
11
- info_str: info_str
12
- }
13
- }
14
-
15
- #[napi]
16
- pub fn generate_info_str() -> Vec<u8> {
17
- return <CASHPKE as CASHybrid>::generate_info_str();
18
- }
19
-
20
- #[napi]
21
- pub fn hpke_encrypt(
22
- plaintext: Vec<u8>,
23
- public_key: Vec<u8>,
24
- info_str: Vec<u8>,
25
- ) -> HpkeEncryptResult {
26
- let encrypt_result: (Vec<u8>, Vec<u8>, Vec<u8>) =
27
- <CASHPKE as CASHybrid>::encrypt(plaintext, public_key, info_str);
28
- return HpkeEncryptResult {
29
- tag: encrypt_result.2,
30
- ciphertext: encrypt_result.1,
31
- encapsulated_key: encrypt_result.0,
32
- }
33
- }
34
-
35
- #[napi]
36
- pub fn hpke_decrypt(
37
- ciphertext: Vec<u8>,
38
- private_key: Vec<u8>,
39
- encapped_key: Vec<u8>,
40
- tag: Vec<u8>,
41
- info_str: Vec<u8>,
42
- ) -> Vec<u8> {
43
- return <CASHPKE as CASHybrid>::decrypt(ciphertext, private_key, encapped_key, tag, info_str);
44
- }
45
-
46
- #[test]
47
- pub fn hpke_encrypt_decrypt_test() {
48
- let hpke_keypair = hpke_generate_keypair();
49
- let plaintext = "This is a secret message".as_bytes().to_vec();
50
- let encrypt_result = hpke_encrypt(
51
- plaintext.clone(),
52
- hpke_keypair.public_key,
53
- hpke_keypair.info_str.clone(),
54
- );
55
- let decrypted_plaintext = hpke_decrypt(
56
- encrypt_result.ciphertext,
57
- hpke_keypair.secret_key,
58
- encrypt_result.encapsulated_key,
59
- encrypt_result.tag,
60
- hpke_keypair.info_str,
61
- );
62
- assert_eq!(plaintext, decrypted_plaintext);
63
- }