cas-typescript-sdk 1.0.22 → 1.0.24
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 +3 -17
- package/README.md +7 -5
- package/index.d.ts +22 -21
- package/index.node +0 -0
- package/lib/asymmetric/RSAWrapper.d.ts +33 -3
- package/lib/asymmetric/RSAWrapper.js +33 -3
- package/lib/asymmetric/index.d.ts +2 -2
- package/lib/asymmetric/index.js +1 -3
- package/lib/digital-signature/digital-siganture-sha-512.d.ts +28 -3
- package/lib/digital-signature/digital-siganture-sha-512.js +25 -0
- package/lib/digital-signature/digital-signature-base.d.ts +3 -3
- package/lib/digital-signature/digital-signature-factory.d.ts +5 -0
- package/lib/digital-signature/digital-signature-factory.js +5 -0
- package/lib/digital-signature/digital-signaturte-sha-256.d.ts +28 -3
- package/lib/digital-signature/digital-signaturte-sha-256.js +25 -0
- package/lib/digital-signature/index.d.ts +2 -1
- package/lib/hashers/hasher-factory.d.ts +5 -0
- package/lib/hashers/hasher-factory.js +5 -0
- package/lib/hashers/sha-wrapper.d.ts +22 -0
- package/lib/hashers/sha-wrapper.js +22 -0
- package/lib/hybrid/hybrid-encryption-wrapper.d.ts +12 -0
- package/lib/hybrid/hybrid-encryption-wrapper.js +12 -0
- package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +7 -2
- package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +5 -0
- package/lib/index.d.ts +8 -9
- package/lib/index.js +22 -29
- package/lib/key_exchange/index.d.ts +2 -1
- package/lib/key_exchange/x25519.d.ts +15 -3
- package/lib/key_exchange/x25519.js +12 -0
- package/lib/password-hashers/argon2-wrapper.d.ts +22 -0
- package/lib/password-hashers/argon2-wrapper.js +22 -0
- package/lib/password-hashers/bcrypt-wrapper.d.ts +22 -0
- package/lib/password-hashers/bcrypt-wrapper.js +22 -0
- package/lib/password-hashers/password-hasher-factory.d.ts +5 -0
- package/lib/password-hashers/password-hasher-factory.js +5 -0
- package/lib/password-hashers/scrypt-wrapper.d.ts +22 -0
- package/lib/password-hashers/scrypt-wrapper.js +22 -0
- package/lib/sponges/ascon-wrapper.d.ts +22 -0
- package/lib/sponges/ascon-wrapper.js +22 -0
- package/lib/symmetric/aes-wrapper.d.ts +45 -15
- package/lib/symmetric/aes-wrapper.js +42 -12
- package/lib/symmetric/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/asymmetric/cas_rsa.rs +13 -59
- package/src/digital_signature/sha_256_ed25519.rs +6 -42
- package/src/digital_signature/sha_256_rsa.rs +7 -63
- package/src/digital_signature/sha_512_ed25519.rs +8 -48
- package/src/digital_signature/sha_512_rsa.rs +9 -62
- package/src/digital_signature/types.rs +34 -0
- package/src/hashers/sha.rs +1 -35
- package/src/key_exchange/types.rs +17 -0
- package/src/key_exchange/x25519.rs +4 -36
- package/src/lib.rs +3 -8
- package/src/password_hashers/argon2.rs +4 -44
- package/src/password_hashers/bcrypt.rs +4 -31
- package/src/password_hashers/scrypt.rs +3 -42
- package/src/sponges/ascon_aead.rs +9 -39
- package/src/symmetric/aes.rs +12 -88
- package/src/symmetric/types.rs +17 -0
- package/src-ts/asymmetric/RSAWrapper.ts +38 -5
- package/src-ts/asymmetric/index.ts +2 -2
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +29 -4
- package/src-ts/digital-signature/digital-signature-base.ts +3 -3
- package/src-ts/digital-signature/digital-signature-factory.ts +6 -0
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +28 -3
- package/src-ts/digital-signature/index.ts +4 -1
- package/src-ts/hashers/hasher-factory.ts +5 -0
- package/src-ts/hashers/sha-wrapper.ts +22 -0
- package/src-ts/hybrid/hybrid-encryption-wrapper.ts +12 -0
- package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +7 -2
- package/src-ts/index.ts +8 -46
- package/src-ts/key_exchange/index.ts +2 -1
- package/src-ts/key_exchange/x25519.ts +15 -3
- package/src-ts/password-hashers/argon2-wrapper.ts +22 -0
- package/src-ts/password-hashers/bcrypt-wrapper.ts +22 -0
- package/src-ts/password-hashers/password-hasher-factory.ts +5 -0
- package/src-ts/password-hashers/scrypt-wrapper.ts +22 -0
- package/src-ts/sponges/ascon-wrapper.ts +22 -0
- package/src-ts/symmetric/aes-wrapper.ts +46 -15
- package/src-ts/symmetric/index.ts +2 -1
- package/test-ts/asymmetric.test.spec.ts +3 -3
- package/test-ts/digital-signature.test.spec.ts +5 -5
- package/test-ts/insecure-channel.test.spec.ts +5 -5
- package/lib/helpers/nonce-generator.d.ts +0 -3
- package/lib/helpers/nonce-generator.js +0 -34
- package/src/asymmetric/cas_asymmetric_encryption.rs +0 -15
- package/src/digital_signature/cas_digital_signature_rsa.rs +0 -27
- package/src/hashers/blake2.rs +0 -37
- package/src/hashers/cas_hasher.rs +0 -8
- package/src/key_exchange/cas_key_exchange.rs +0 -6
- package/src/password_hashers/cas_password_hasher.rs +0 -4
- package/src/sponges/cas_ascon_aead.rs +0 -6
- package/src/symmetric/cas_symmetric_encryption.rs +0 -14
- package/src-ts/helpers/nonce-generator.ts +0 -9
package/Cargo.toml
CHANGED
|
@@ -8,27 +8,13 @@ path = "src/lib.rs"
|
|
|
8
8
|
crate-type = ["cdylib"]
|
|
9
9
|
|
|
10
10
|
[dependencies]
|
|
11
|
-
aes-gcm = "0.10.3"
|
|
12
|
-
argon2 = "0.5.2"
|
|
13
|
-
bcrypt = "0.15.0"
|
|
14
|
-
blake2 = "0.10.6"
|
|
15
11
|
napi = "2"
|
|
16
12
|
napi-derive = "2"
|
|
17
13
|
rand = "0.8.5"
|
|
18
14
|
rand_chacha = "0.3.1"
|
|
19
|
-
rsa = "0.9.6"
|
|
20
|
-
scrypt = "0.11.0"
|
|
21
|
-
sha3 = "0.10.8"
|
|
22
|
-
x25519-dalek = {version = "2.0.0", features = ["static_secrets"]}
|
|
23
|
-
rand_07 = { package = "rand", version = "0.7.0" }
|
|
24
|
-
ascon-aead = "0.4.2"
|
|
25
15
|
rayon = "1.10.0"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
opt-level = 3
|
|
29
|
-
|
|
30
|
-
[dependencies.ed25519-dalek]
|
|
31
|
-
version = "1"
|
|
16
|
+
csbindgen = "1.9.1"
|
|
17
|
+
cas-lib = "0.1.3"
|
|
32
18
|
|
|
33
19
|
[build-dependencies]
|
|
34
|
-
napi-build = "1"
|
|
20
|
+
napi-build = "1"
|
package/README.md
CHANGED
|
@@ -2,23 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://discord.gg/7bXXCQj45q)
|
|
4
4
|
|
|
5
|
-
Ever wanted all of your most useful cryptographic operations in one module and not
|
|
5
|
+
Ever wanted all of your most useful cryptographic operations in one module and not had to surf documentation for various packages?
|
|
6
6
|
CAS is here to provide a unified development experience as an abstract layer to the RustCrypto and Dalek-Cryptography suite of algorithms.
|
|
7
7
|
The official NPM page can be found [here](https://www.npmjs.com/package/cas-typescript-sdk).
|
|
8
8
|
|
|
9
|
-
## [Examples](./docs/EXAMPLES.md)
|
|
10
|
-
|
|
11
|
-
## Consuming Library Documentation
|
|
12
9
|
**Note: All work is experimental and we understand some benchmarks might not be the most optimal.**
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
|
|
12
|
+
|
|
15
13
|
|
|
16
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.
|
|
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)
|
|
19
19
|
- [Dalek-Cryptography](https://github.com/dalek-cryptography)
|
|
20
20
|
- [Rust Crypto](https://github.com/RustCrypto)
|
|
21
21
|
- [Rayon](https://github.com/rayon-rs/rayon)
|
|
22
22
|
|
|
23
|
+
## [Examples](./docs/EXAMPLES.md)
|
|
24
|
+
|
|
23
25
|
## Disclaimer
|
|
24
26
|
Many of the cryptographic crates that are utilized in our core FFI [layer](./src) have never had a security audit performed. Utilize this SDK at your own risk.
|
package/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export function sha512(dataToHash: Array<number>): Array<number>
|
|
|
19
19
|
export function sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
20
20
|
export function sha256(dataToHash: Array<number>): Array<number>
|
|
21
21
|
export function sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
22
|
-
export function x25519GenerateSecretAndPublicKey():
|
|
22
|
+
export function x25519GenerateSecretAndPublicKey(): CASx25519SecretPublicKeyResult
|
|
23
23
|
export function x25519DiffieHellman(mySecretKey: Array<number>, usersPublicKey: Array<number>): Array<number>
|
|
24
24
|
export function aesNonce(): Array<number>
|
|
25
25
|
export function aes128Key(): Array<number>
|
|
@@ -28,52 +28,53 @@ export function aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plain
|
|
|
28
28
|
export function aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
|
|
29
29
|
export function aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
|
|
30
30
|
export function aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
|
|
31
|
-
export function aes256KeyFromX25519SharedSecret(sharedSecret: Array<number>):
|
|
32
|
-
export function aes128KeyFromX25519SharedSecret(sharedSecret: Array<number>):
|
|
33
|
-
export function generateRsaKeys(keySize: 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
34
|
export function encryptPlaintextRsa(publicKey: string, plaintext: Array<number>): Array<number>
|
|
35
35
|
export function decryptCiphertextRsa(privateKey: string, ciphertext: Array<number>): Array<number>
|
|
36
36
|
export function signRsa(privateKey: string, hash: Array<number>): Array<number>
|
|
37
37
|
export function verifyRsa(publicKey: string, hash: Array<number>, signature: Array<number>): boolean
|
|
38
|
-
export function sha512RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>):
|
|
38
|
+
export function sha512RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CASRSADigitalSignatureResult
|
|
39
39
|
export function sha512RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
40
|
-
export function sha256RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>):
|
|
40
|
+
export function sha256RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CASRSADigitalSignatureResult
|
|
41
41
|
export function sha256RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
42
|
-
export function sha512Ed25519DigitalSignature(dataToSign: Array<number>):
|
|
42
|
+
export function sha512Ed25519DigitalSignature(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult
|
|
43
43
|
export function sha512Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
44
|
-
export function sha256Ed25519DigitalSignature(dataToSign: Array<number>):
|
|
44
|
+
export function sha256Ed25519DigitalSignature(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult
|
|
45
45
|
export function sha256Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
46
46
|
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 type
|
|
51
|
-
export class
|
|
50
|
+
export type CASx25519SecretPublicKeyResult = CaSx25519SecretPublicKeyResult
|
|
51
|
+
export class CaSx25519SecretPublicKeyResult {
|
|
52
52
|
publicKey: Array<number>
|
|
53
53
|
secretKey: Array<number>
|
|
54
54
|
constructor(publicKey: Array<number>, secretKey: Array<number>)
|
|
55
55
|
}
|
|
56
|
-
export
|
|
56
|
+
export type CASAesKeyFromX25519SharedSecret = CasAesKeyFromX25519SharedSecret
|
|
57
|
+
export class CasAesKeyFromX25519SharedSecret {
|
|
57
58
|
aesKey: Array<number>
|
|
58
59
|
aesNonce: Array<number>
|
|
59
60
|
constructor(aesKey: Array<number>, aesNonce: Array<number>)
|
|
60
61
|
}
|
|
61
|
-
export type
|
|
62
|
-
export class
|
|
62
|
+
export type CASRSAKeyPairResult = CasrsaKeyPairResult
|
|
63
|
+
export class CasrsaKeyPairResult {
|
|
63
64
|
privateKey: string
|
|
64
65
|
publicKey: string
|
|
65
66
|
constructor(privateKey: string, publicKey: string)
|
|
66
67
|
}
|
|
67
|
-
export type
|
|
68
|
-
export class
|
|
68
|
+
export type CASSHAED25519DalekDigitalSignatureResult = Casshaed25519DalekDigitalSignatureResult
|
|
69
|
+
export class Casshaed25519DalekDigitalSignatureResult {
|
|
70
|
+
publicKey: Array<number>
|
|
71
|
+
signature: Array<number>
|
|
72
|
+
constructor(publicKey: Array<number>, signature: Array<number>)
|
|
73
|
+
}
|
|
74
|
+
export type CASRSADigitalSignatureResult = CasrsaDigitalSignatureResult
|
|
75
|
+
export class CasrsaDigitalSignatureResult {
|
|
69
76
|
publicKey: string
|
|
70
77
|
privateKey: string
|
|
71
78
|
signature: Array<number>
|
|
72
79
|
constructor(publicKey: string, privateKey: string, signature: Array<number>)
|
|
73
80
|
}
|
|
74
|
-
export type SHAED25519DalekDigitalSignatureResult = Shaed25519DalekDigitalSignatureResult
|
|
75
|
-
export class Shaed25519DalekDigitalSignatureResult {
|
|
76
|
-
publicKey: Array<number>
|
|
77
|
-
signature: Array<number>
|
|
78
|
-
constructor(publicKey: Array<number>, signature: Array<number>)
|
|
79
|
-
}
|
package/index.node
CHANGED
|
Binary file
|
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASRSAKeyPairResult } from "../../index";
|
|
2
2
|
export declare class RSAWrapper {
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
|
|
5
|
+
* @param keySize
|
|
6
|
+
* @returns CASRSAKeyPairResult
|
|
7
|
+
*/
|
|
8
|
+
generateKeys(keySize: number): CASRSAKeyPairResult;
|
|
9
|
+
/**
|
|
10
|
+
* Encrypts a plaintext byte array with a RSA public key
|
|
11
|
+
* @param publicKey
|
|
12
|
+
* @param plaintext
|
|
13
|
+
* @returns Array<number>
|
|
14
|
+
*/
|
|
4
15
|
encrypt(publicKey: string, plaintext: Array<number>): Array<number>;
|
|
16
|
+
/**
|
|
17
|
+
* Decrypts a ciphertext with an RSA private key.
|
|
18
|
+
* @param privateKey
|
|
19
|
+
* @param ciphertext
|
|
20
|
+
* @returns Array<number>
|
|
21
|
+
*/
|
|
5
22
|
decrypt(privateKey: string, ciphertext: Array<number>): Array<number>;
|
|
6
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Signs a byte array with an RSA private key for verification.
|
|
25
|
+
* @param privateKey
|
|
26
|
+
* @param hash
|
|
27
|
+
* @returns Array<number>
|
|
28
|
+
*/
|
|
29
|
+
sign(privateKey: string, dataToSign: Array<number>): Array<number>;
|
|
30
|
+
/**
|
|
31
|
+
* Verifies signed data by the corresponding private key with an RSA public key.
|
|
32
|
+
* @param publicKey
|
|
33
|
+
* @param hash
|
|
34
|
+
* @param signature
|
|
35
|
+
* @returns boolean
|
|
36
|
+
*/
|
|
7
37
|
verify(publicKey: string, hash: Array<number>, signature: Array<number>): boolean;
|
|
8
38
|
}
|
|
@@ -3,12 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RSAWrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class RSAWrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
|
|
8
|
+
* @param keySize
|
|
9
|
+
* @returns CASRSAKeyPairResult
|
|
10
|
+
*/
|
|
6
11
|
generateKeys(keySize) {
|
|
7
12
|
if (keySize !== 1024 && keySize !== 2048 && keySize !== 4096) {
|
|
8
13
|
throw new Error("You must provide an appropriate key size to generate RSA keys");
|
|
9
14
|
}
|
|
10
15
|
return (0, index_1.generateRsaKeys)(keySize);
|
|
11
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Encrypts a plaintext byte array with a RSA public key
|
|
19
|
+
* @param publicKey
|
|
20
|
+
* @param plaintext
|
|
21
|
+
* @returns Array<number>
|
|
22
|
+
*/
|
|
12
23
|
encrypt(publicKey, plaintext) {
|
|
13
24
|
if (!publicKey) {
|
|
14
25
|
throw new Error("You must provide a public key to encrypt with RSA");
|
|
@@ -18,6 +29,12 @@ class RSAWrapper {
|
|
|
18
29
|
}
|
|
19
30
|
return (0, index_1.encryptPlaintextRsa)(publicKey, plaintext);
|
|
20
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Decrypts a ciphertext with an RSA private key.
|
|
34
|
+
* @param privateKey
|
|
35
|
+
* @param ciphertext
|
|
36
|
+
* @returns Array<number>
|
|
37
|
+
*/
|
|
21
38
|
decrypt(privateKey, ciphertext) {
|
|
22
39
|
if (!privateKey) {
|
|
23
40
|
throw new Error("You must provide a private key to encrypt with RSA");
|
|
@@ -27,15 +44,28 @@ class RSAWrapper {
|
|
|
27
44
|
}
|
|
28
45
|
return (0, index_1.decryptCiphertextRsa)(privateKey, ciphertext);
|
|
29
46
|
}
|
|
30
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Signs a byte array with an RSA private key for verification.
|
|
49
|
+
* @param privateKey
|
|
50
|
+
* @param hash
|
|
51
|
+
* @returns Array<number>
|
|
52
|
+
*/
|
|
53
|
+
sign(privateKey, dataToSign) {
|
|
31
54
|
if (!privateKey) {
|
|
32
55
|
throw new Error("You must provide a private key to sign with RSA");
|
|
33
56
|
}
|
|
34
|
-
if (!
|
|
57
|
+
if (!dataToSign || dataToSign.length === 0) {
|
|
35
58
|
throw new Error("You must provide an allocated hash to sign with RSA");
|
|
36
59
|
}
|
|
37
|
-
return (0, index_1.signRsa)(privateKey,
|
|
60
|
+
return (0, index_1.signRsa)(privateKey, dataToSign);
|
|
38
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Verifies signed data by the corresponding private key with an RSA public key.
|
|
64
|
+
* @param publicKey
|
|
65
|
+
* @param hash
|
|
66
|
+
* @param signature
|
|
67
|
+
* @returns boolean
|
|
68
|
+
*/
|
|
39
69
|
verify(publicKey, hash, signature) {
|
|
40
70
|
if (!publicKey) {
|
|
41
71
|
throw new Error("You must provide a public key to verify with RSA");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { RSAWrapper } from "./RSAWrapper";
|
|
2
|
-
import {
|
|
3
|
-
export { RSAWrapper,
|
|
2
|
+
import { CASRSAKeyPairResult } from "../../index";
|
|
3
|
+
export { RSAWrapper, CASRSAKeyPairResult };
|
package/lib/asymmetric/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RSAWrapper = void 0;
|
|
4
4
|
const RSAWrapper_1 = require("./RSAWrapper");
|
|
5
5
|
Object.defineProperty(exports, "RSAWrapper", { enumerable: true, get: function () { return RSAWrapper_1.RSAWrapper; } });
|
|
6
|
-
const index_1 = require("../../index");
|
|
7
|
-
Object.defineProperty(exports, "RsaKeyPairResult", { enumerable: true, get: function () { return index_1.RsaKeyPairResult; } });
|
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";
|
|
2
2
|
import { IDigitalSignature } from "./digital-signature-base";
|
|
3
3
|
export declare class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Creates an ED25519 siganture from an array of bytes with SHA3-512.
|
|
6
|
+
* @param dataToSign
|
|
7
|
+
* @returns CASSHAED25519DalekDigitalSignatureResult
|
|
8
|
+
*/
|
|
9
|
+
createED25519(dataToSign: number[]): CASSHAED25519DalekDigitalSignatureResult;
|
|
10
|
+
/**
|
|
11
|
+
* Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
|
|
12
|
+
* @param publicKey
|
|
13
|
+
* @param dataToVerify
|
|
14
|
+
* @param signature
|
|
15
|
+
* @returns boolean
|
|
16
|
+
*/
|
|
5
17
|
verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean;
|
|
6
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Generates and RSA digital signature with SHA3-512
|
|
20
|
+
* @param rsa_key_size
|
|
21
|
+
* @param data_to_sign
|
|
22
|
+
* @returns CASRSADigitalSignatureResult
|
|
23
|
+
*/
|
|
24
|
+
createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult;
|
|
25
|
+
/**
|
|
26
|
+
* Verifies a digital signature created with the RSA public key.
|
|
27
|
+
* @param public_key
|
|
28
|
+
* @param data_to_verify
|
|
29
|
+
* @param signature
|
|
30
|
+
* @returns boolean
|
|
31
|
+
*/
|
|
7
32
|
verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean;
|
|
8
33
|
}
|
|
@@ -3,12 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DigitalSignatureSHA512Wrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class DigitalSignatureSHA512Wrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Creates an ED25519 siganture from an array of bytes with SHA3-512.
|
|
8
|
+
* @param dataToSign
|
|
9
|
+
* @returns CASSHAED25519DalekDigitalSignatureResult
|
|
10
|
+
*/
|
|
6
11
|
createED25519(dataToSign) {
|
|
7
12
|
if (dataToSign?.length === 0) {
|
|
8
13
|
throw new Error("Must provide allocated data to sign");
|
|
9
14
|
}
|
|
10
15
|
return (0, index_1.sha512Ed25519DigitalSignature)(dataToSign);
|
|
11
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
|
|
19
|
+
* @param publicKey
|
|
20
|
+
* @param dataToVerify
|
|
21
|
+
* @param signature
|
|
22
|
+
* @returns boolean
|
|
23
|
+
*/
|
|
12
24
|
verifyED25519(publicKey, dataToVerify, signature) {
|
|
13
25
|
if (!publicKey) {
|
|
14
26
|
throw new Error("You must provide a public key for verify with ED25519");
|
|
@@ -21,6 +33,12 @@ class DigitalSignatureSHA512Wrapper {
|
|
|
21
33
|
}
|
|
22
34
|
return (0, index_1.sha512Ed25519DigitalSignatureVerify)(publicKey, dataToVerify, signature);
|
|
23
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Generates and RSA digital signature with SHA3-512
|
|
38
|
+
* @param rsa_key_size
|
|
39
|
+
* @param data_to_sign
|
|
40
|
+
* @returns CASRSADigitalSignatureResult
|
|
41
|
+
*/
|
|
24
42
|
createRsa(rsa_key_size, data_to_sign) {
|
|
25
43
|
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
|
|
26
44
|
throw new Error("You need to provide an appropriate RSA key size.");
|
|
@@ -30,6 +48,13 @@ class DigitalSignatureSHA512Wrapper {
|
|
|
30
48
|
}
|
|
31
49
|
return (0, index_1.sha512RsaDigitalSignature)(rsa_key_size, data_to_sign);
|
|
32
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Verifies a digital signature created with the RSA public key.
|
|
53
|
+
* @param public_key
|
|
54
|
+
* @param data_to_verify
|
|
55
|
+
* @param signature
|
|
56
|
+
* @returns boolean
|
|
57
|
+
*/
|
|
33
58
|
verifyRSa(public_key, data_to_verify, signature) {
|
|
34
59
|
if (!public_key) {
|
|
35
60
|
throw new Error("Must provide a public key");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";
|
|
2
2
|
export interface IDigitalSignature {
|
|
3
|
-
createRsa(rsa_key_size: number, data_to_sign: Array<number>):
|
|
3
|
+
createRsa(rsa_key_size: number, data_to_sign: Array<number>): CASRSADigitalSignatureResult;
|
|
4
4
|
verifyRSa(public_key: string, data_to_verify: Array<number>, signature: Array<number>): boolean;
|
|
5
|
-
createED25519(dataToSign: Array<number>):
|
|
5
|
+
createED25519(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult;
|
|
6
6
|
verifyED25519(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean;
|
|
7
7
|
}
|
|
@@ -4,5 +4,10 @@ export declare enum DigitalSignatureType {
|
|
|
4
4
|
SHA256 = 2
|
|
5
5
|
}
|
|
6
6
|
export declare class DigitalSignatureFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Get the appropriate digital signature wrapper based upon the type passed in.
|
|
9
|
+
* @param type
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
7
12
|
static get(type: DigitalSignatureType): DigitalSignatureSHA512Wrapper;
|
|
8
13
|
}
|
|
@@ -9,6 +9,11 @@ var DigitalSignatureType;
|
|
|
9
9
|
DigitalSignatureType[DigitalSignatureType["SHA256"] = 2] = "SHA256";
|
|
10
10
|
})(DigitalSignatureType || (exports.DigitalSignatureType = DigitalSignatureType = {}));
|
|
11
11
|
class DigitalSignatureFactory {
|
|
12
|
+
/**
|
|
13
|
+
* Get the appropriate digital signature wrapper based upon the type passed in.
|
|
14
|
+
* @param type
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
12
17
|
static get(type) {
|
|
13
18
|
let ds = new digital_siganture_sha_512_1.DigitalSignatureSHA512Wrapper();
|
|
14
19
|
switch (type) {
|
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";
|
|
2
2
|
import { IDigitalSignature } from "./digital-signature-base";
|
|
3
3
|
export declare class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Creates an ED25519 siganture from an array of bytes with SHA3-512.
|
|
6
|
+
* @param dataToSign
|
|
7
|
+
* @returns SHAED25519DalekDigitalSignatureResult
|
|
8
|
+
*/
|
|
9
|
+
createED25519(dataToSign: number[]): CASSHAED25519DalekDigitalSignatureResult;
|
|
10
|
+
/**
|
|
11
|
+
* Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
|
|
12
|
+
* @param publicKey
|
|
13
|
+
* @param dataToVerify
|
|
14
|
+
* @param signature
|
|
15
|
+
* @returns boolean
|
|
16
|
+
*/
|
|
5
17
|
verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean;
|
|
6
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Generates and RSA digital signature with SHA3-512
|
|
20
|
+
* @param rsa_key_size
|
|
21
|
+
* @param data_to_sign
|
|
22
|
+
* @returns RsaDigitalSignatureResult
|
|
23
|
+
*/
|
|
24
|
+
createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult;
|
|
25
|
+
/**
|
|
26
|
+
* Verifies a digital signature created with the RSA public key.
|
|
27
|
+
* @param public_key
|
|
28
|
+
* @param data_to_verify
|
|
29
|
+
* @param signature
|
|
30
|
+
* @returns boolean
|
|
31
|
+
*/
|
|
7
32
|
verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean;
|
|
8
33
|
}
|
|
@@ -3,12 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DigitalSignatureSHA256Wrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class DigitalSignatureSHA256Wrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Creates an ED25519 siganture from an array of bytes with SHA3-512.
|
|
8
|
+
* @param dataToSign
|
|
9
|
+
* @returns SHAED25519DalekDigitalSignatureResult
|
|
10
|
+
*/
|
|
6
11
|
createED25519(dataToSign) {
|
|
7
12
|
if (dataToSign?.length === 0) {
|
|
8
13
|
throw new Error("Must provide allocated data to sign");
|
|
9
14
|
}
|
|
10
15
|
return (0, index_1.sha256Ed25519DigitalSignature)(dataToSign);
|
|
11
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
|
|
19
|
+
* @param publicKey
|
|
20
|
+
* @param dataToVerify
|
|
21
|
+
* @param signature
|
|
22
|
+
* @returns boolean
|
|
23
|
+
*/
|
|
12
24
|
verifyED25519(publicKey, dataToVerify, signature) {
|
|
13
25
|
if (!publicKey) {
|
|
14
26
|
throw new Error("You must provide a public key for verify with ED25519");
|
|
@@ -21,6 +33,12 @@ class DigitalSignatureSHA256Wrapper {
|
|
|
21
33
|
}
|
|
22
34
|
return (0, index_1.sha256Ed25519DigitalSignatureVerify)(publicKey, dataToVerify, signature);
|
|
23
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Generates and RSA digital signature with SHA3-512
|
|
38
|
+
* @param rsa_key_size
|
|
39
|
+
* @param data_to_sign
|
|
40
|
+
* @returns RsaDigitalSignatureResult
|
|
41
|
+
*/
|
|
24
42
|
createRsa(rsa_key_size, data_to_sign) {
|
|
25
43
|
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
|
|
26
44
|
throw new Error("You need to provide an appropriate RSA key size.");
|
|
@@ -30,6 +48,13 @@ class DigitalSignatureSHA256Wrapper {
|
|
|
30
48
|
}
|
|
31
49
|
return (0, index_1.sha256RsaDigitalSignature)(rsa_key_size, data_to_sign);
|
|
32
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Verifies a digital signature created with the RSA public key.
|
|
53
|
+
* @param public_key
|
|
54
|
+
* @param data_to_verify
|
|
55
|
+
* @param signature
|
|
56
|
+
* @returns boolean
|
|
57
|
+
*/
|
|
33
58
|
verifyRSa(public_key, data_to_verify, signature) {
|
|
34
59
|
if (!public_key) {
|
|
35
60
|
throw new Error("Must provide a public key");
|
|
@@ -2,4 +2,5 @@ import { DigitalSignatureType } from "./digital-signature-factory";
|
|
|
2
2
|
import { DigitalSignatureFactory } from "./digital-signature-factory";
|
|
3
3
|
import { DigitalSignatureSHA256Wrapper } from "./digital-signaturte-sha-256";
|
|
4
4
|
import { DigitalSignatureSHA512Wrapper } from "./digital-siganture-sha-512";
|
|
5
|
-
|
|
5
|
+
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";
|
|
6
|
+
export { DigitalSignatureFactory, DigitalSignatureSHA256Wrapper, DigitalSignatureSHA512Wrapper, DigitalSignatureType, CASSHAED25519DalekDigitalSignatureResult, CASRSADigitalSignatureResult };
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HasherFactory = void 0;
|
|
4
4
|
const sha_wrapper_1 = require("./sha-wrapper");
|
|
5
5
|
class HasherFactory {
|
|
6
|
+
/**
|
|
7
|
+
* Get the appropriate hasher wrapper based upon the type based in.
|
|
8
|
+
* @param type
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
6
11
|
getHasher(type) {
|
|
7
12
|
let result = new sha_wrapper_1.SHAWrapper();
|
|
8
13
|
switch (type) {
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
import { IHasherBase } from "./hasher-base";
|
|
2
2
|
export declare class SHAWrapper implements IHasherBase {
|
|
3
|
+
/**
|
|
4
|
+
* Hashes a byte array with SHA3-512.
|
|
5
|
+
* @param dataToHash
|
|
6
|
+
* @returns number[]
|
|
7
|
+
*/
|
|
3
8
|
hash512(dataToHash: number[]): number[];
|
|
9
|
+
/**
|
|
10
|
+
* Verifies unsigned data against an SHA3-512 hash.
|
|
11
|
+
* @param dataToHash
|
|
12
|
+
* @param dataToVerify
|
|
13
|
+
* @returns boolean
|
|
14
|
+
*/
|
|
4
15
|
verify512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Hashes a byte array with SHA3-256.
|
|
18
|
+
* @param dataToHash
|
|
19
|
+
* @returns number[]
|
|
20
|
+
*/
|
|
5
21
|
hash256(dataToHash: number[]): number[];
|
|
22
|
+
/**
|
|
23
|
+
* Verifies unsigned data against an SHA3-256 hash.
|
|
24
|
+
* @param dataToHash
|
|
25
|
+
* @param dataToVerify
|
|
26
|
+
* @returns boolean
|
|
27
|
+
*/
|
|
6
28
|
verify256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
7
29
|
}
|
|
@@ -3,12 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SHAWrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class SHAWrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Hashes a byte array with SHA3-512.
|
|
8
|
+
* @param dataToHash
|
|
9
|
+
* @returns number[]
|
|
10
|
+
*/
|
|
6
11
|
hash512(dataToHash) {
|
|
7
12
|
if (!dataToHash || dataToHash.length === 0) {
|
|
8
13
|
throw new Error("You must provide an allocated array of data");
|
|
9
14
|
}
|
|
10
15
|
return (0, index_1.sha512)(dataToHash);
|
|
11
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Verifies unsigned data against an SHA3-512 hash.
|
|
19
|
+
* @param dataToHash
|
|
20
|
+
* @param dataToVerify
|
|
21
|
+
* @returns boolean
|
|
22
|
+
*/
|
|
12
23
|
verify512(dataToHash, dataToVerify) {
|
|
13
24
|
if (!dataToHash || dataToHash.length === 0) {
|
|
14
25
|
throw new Error("You must provide an allocated array of data");
|
|
@@ -18,12 +29,23 @@ class SHAWrapper {
|
|
|
18
29
|
}
|
|
19
30
|
return (0, index_1.sha512Verify)(dataToHash, dataToVerify);
|
|
20
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Hashes a byte array with SHA3-256.
|
|
34
|
+
* @param dataToHash
|
|
35
|
+
* @returns number[]
|
|
36
|
+
*/
|
|
21
37
|
hash256(dataToHash) {
|
|
22
38
|
if (!dataToHash || dataToHash.length === 0) {
|
|
23
39
|
throw new Error("You must provide an allocated array of data");
|
|
24
40
|
}
|
|
25
41
|
return (0, index_1.sha256)(dataToHash);
|
|
26
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Verifies unsigned data against an SHA3-256 hash.
|
|
45
|
+
* @param dataToHash
|
|
46
|
+
* @param dataToVerify
|
|
47
|
+
* @returns boolean
|
|
48
|
+
*/
|
|
27
49
|
verify256(dataToHash, dataToVerify) {
|
|
28
50
|
if (!dataToHash || dataToHash.length === 0) {
|
|
29
51
|
throw new Error("You must provide an allocated array of data");
|
|
@@ -4,6 +4,18 @@ export declare class HybridEncryptionWrapper {
|
|
|
4
4
|
private aesWrapper;
|
|
5
5
|
private rsaWrapper;
|
|
6
6
|
constructor();
|
|
7
|
+
/**
|
|
8
|
+
* Encrypts data with RSA/AES hybrid encryption. The data is encrypted with AES-GCM and the AES key is encrypted with the RSA public key.
|
|
9
|
+
* @param dataToEncrypt
|
|
10
|
+
* @param initalizer
|
|
11
|
+
* @returns AesRsaHybridEncryptResult
|
|
12
|
+
*/
|
|
7
13
|
encrypt(dataToEncrypt: Array<number>, initalizer: AESRSAHybridInitializer): AesRsaHybridEncryptResult;
|
|
14
|
+
/**
|
|
15
|
+
* Decrypts data with RSA/AES hybrid encryption. The RSA private key decrypts the AES key and then the data is decrypted with AES-GCM.
|
|
16
|
+
* @param dataToEncrypt
|
|
17
|
+
* @param initalizer
|
|
18
|
+
* @returns AesRsaHybridEncryptResult
|
|
19
|
+
*/
|
|
8
20
|
decrypt(privateKey: string, encryptResult: AesRsaHybridEncryptResult): Array<number>;
|
|
9
21
|
}
|
|
@@ -11,6 +11,12 @@ class HybridEncryptionWrapper {
|
|
|
11
11
|
this.aesWrapper = new symmetric_1.AESWrapper();
|
|
12
12
|
this.rsaWrapper = new asymmetric_1.RSAWrapper();
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Encrypts data with RSA/AES hybrid encryption. The data is encrypted with AES-GCM and the AES key is encrypted with the RSA public key.
|
|
16
|
+
* @param dataToEncrypt
|
|
17
|
+
* @param initalizer
|
|
18
|
+
* @returns AesRsaHybridEncryptResult
|
|
19
|
+
*/
|
|
14
20
|
encrypt(dataToEncrypt, initalizer) {
|
|
15
21
|
let encryptedData = (initalizer.aesType === 128)
|
|
16
22
|
? this.aesWrapper.aes128Encrypt(initalizer.aesKey, initalizer.aesNonce, dataToEncrypt)
|
|
@@ -19,6 +25,12 @@ class HybridEncryptionWrapper {
|
|
|
19
25
|
let result = new aes_rsa_hybird_encrypt_result_1.AesRsaHybridEncryptResult(encryptedData, encryptedAesKey, initalizer.aesType, initalizer.aesNonce);
|
|
20
26
|
return result;
|
|
21
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Decrypts data with RSA/AES hybrid encryption. The RSA private key decrypts the AES key and then the data is decrypted with AES-GCM.
|
|
30
|
+
* @param dataToEncrypt
|
|
31
|
+
* @param initalizer
|
|
32
|
+
* @returns AesRsaHybridEncryptResult
|
|
33
|
+
*/
|
|
22
34
|
decrypt(privateKey, encryptResult) {
|
|
23
35
|
let plaintextAesKey = this.rsaWrapper.decrypt(privateKey, encryptResult.encryptedAesKey);
|
|
24
36
|
let plaintext = (encryptResult.aesType === 128)
|