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.
- package/index.darwin-x64.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.linux-x64-musl.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +11 -4
- package/.github/workflows/main-pr-linux.yml +0 -28
- package/.github/workflows/main-pr-windows.yml +0 -28
- package/.github/workflows/main-publish.yml +0 -32
- package/Cargo.toml +0 -19
- package/build.rs +0 -5
- package/docs/EXAMPLES.md +0 -138
- package/index.node +0 -0
- package/src/asymmetric/cas_ed25519.rs +0 -35
- package/src/asymmetric/cas_rsa.rs +0 -32
- package/src/digital_signature/sha_256_rsa.rs +0 -40
- package/src/digital_signature/sha_512_rsa.rs +0 -40
- package/src/digital_signature/types.rs +0 -34
- package/src/hashers/blake2.rs +0 -60
- package/src/hashers/sha.rs +0 -68
- package/src/hybrid/hpke.rs +0 -63
- package/src/hybrid/types.rs +0 -15
- package/src/key_exchange/types.rs +0 -17
- package/src/key_exchange/x25519.rs +0 -25
- package/src/lib.rs +0 -47
- package/src/message/hmac.rs +0 -21
- package/src/password_hashers/argon2.rs +0 -37
- package/src/password_hashers/bcrypt.rs +0 -37
- package/src/password_hashers/scrypt.rs +0 -36
- package/src/sponges/ascon_aead.rs +0 -66
- package/src/symmetric/aes.rs +0 -71
- package/src-ts/asymmetric/RSAWrapper.ts +0 -59
- package/src-ts/asymmetric/index.ts +0 -4
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +0 -40
- package/src-ts/digital-signature/digital-signature-base.ts +0 -6
- package/src-ts/digital-signature/digital-signature-factory.ts +0 -25
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +0 -41
- package/src-ts/digital-signature/index.ts +0 -14
- package/src-ts/hashers/blake2-wrapper.ts +0 -43
- package/src-ts/hashers/hasher-base.ts +0 -6
- package/src-ts/hashers/hasher-factory.ts +0 -19
- package/src-ts/hashers/hasher-type.ts +0 -4
- package/src-ts/hashers/index.ts +0 -6
- package/src-ts/hashers/sha-wrapper.ts +0 -60
- package/src-ts/hybrid/hpke.ts +0 -44
- package/src-ts/hybrid/index.ts +0 -3
- package/src-ts/index.ts +0 -10
- package/src-ts/key_exchange/index.ts +0 -4
- package/src-ts/key_exchange/x25519.ts +0 -23
- package/src-ts/message/hmac.ts +0 -26
- package/src-ts/message/index.ts +0 -3
- package/src-ts/password-hashers/argon2-wrapper.ts +0 -31
- package/src-ts/password-hashers/bcrypt-wrapper.ts +0 -35
- package/src-ts/password-hashers/index.ts +0 -14
- package/src-ts/password-hashers/password-hasher-base.ts +0 -4
- package/src-ts/password-hashers/password-hasher-factory.ts +0 -25
- package/src-ts/password-hashers/password-hasher-type.ts +0 -5
- package/src-ts/password-hashers/scrypt-wrapper.ts +0 -32
- package/src-ts/signature/ed25519-wrapper.ts +0 -36
- package/src-ts/signature/index.ts +0 -3
- package/src-ts/sponges/ascon-wrapper.ts +0 -72
- package/src-ts/sponges/index.ts +0 -3
- package/src-ts/symmetric/aes-wrapper.ts +0 -101
- package/src-ts/symmetric/index.ts +0 -3
- package/test-ts/asymmetric.test.spec.ts +0 -15
- package/test-ts/digital-signature.test.spec.ts +0 -70
- package/test-ts/hasher.test.spec.ts +0 -139
- package/test-ts/helpers/array.ts +0 -10
- package/test-ts/hmac.test.spec.ts +0 -16
- package/test-ts/hybrid.test.spec.ts +0 -23
- package/test-ts/insecure-channel.test.spec.ts +0 -55
- package/test-ts/key-exchange.test.spec.ts +0 -23
- package/test-ts/password-hasher.test.spec.ts +0 -104
- package/test-ts/sponges.test.spec.ts +0 -28
- package/test-ts/symmetric.test.spec.ts +0 -82
- package/tsconfig.json +0 -22
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { sha256, sha256Verify, sha512, sha512Verify } from "../../index";
|
|
2
|
-
import { IHasherBase } from "./hasher-base";
|
|
3
|
-
|
|
4
|
-
export class SHAWrapper implements IHasherBase {
|
|
5
|
-
/**
|
|
6
|
-
* Hashes a byte array with SHA3-512.
|
|
7
|
-
* @param dataToHash
|
|
8
|
-
* @returns number[]
|
|
9
|
-
*/
|
|
10
|
-
hash512(dataToHash: number[]): number[] {
|
|
11
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
12
|
-
throw new Error("You must provide an allocated array of data");
|
|
13
|
-
}
|
|
14
|
-
return sha512(dataToHash);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Verifies unsigned data against an SHA3-512 hash.
|
|
19
|
-
* @param dataToHash
|
|
20
|
-
* @param dataToVerify
|
|
21
|
-
* @returns boolean
|
|
22
|
-
*/
|
|
23
|
-
verify512(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
24
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
25
|
-
throw new Error("You must provide an allocated array of data");
|
|
26
|
-
}
|
|
27
|
-
if (!dataToVerify || dataToVerify.length === 0) {
|
|
28
|
-
throw new Error("You must provide an allocated array of data to verify");
|
|
29
|
-
}
|
|
30
|
-
return sha512Verify(dataToHash, dataToVerify);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Hashes a byte array with SHA3-256.
|
|
35
|
-
* @param dataToHash
|
|
36
|
-
* @returns number[]
|
|
37
|
-
*/
|
|
38
|
-
hash256(dataToHash: number[]): number[] {
|
|
39
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
40
|
-
throw new Error("You must provide an allocated array of data");
|
|
41
|
-
}
|
|
42
|
-
return sha256(dataToHash);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Verifies unsigned data against an SHA3-256 hash.
|
|
47
|
-
* @param dataToHash
|
|
48
|
-
* @param dataToVerify
|
|
49
|
-
* @returns boolean
|
|
50
|
-
*/
|
|
51
|
-
verify256(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
52
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
53
|
-
throw new Error("You must provide an allocated array of data");
|
|
54
|
-
}
|
|
55
|
-
if (!dataToVerify || dataToVerify.length === 0) {
|
|
56
|
-
throw new Error("You must provide an allocated array of data to verify");
|
|
57
|
-
}
|
|
58
|
-
return sha256Verify(dataToHash, dataToVerify);
|
|
59
|
-
}
|
|
60
|
-
}
|
package/src-ts/hybrid/hpke.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { hpkeGenerateKeypair, hpkeEncrypt, hpkeDecrypt, generateInfoStr, HpkeKeyResult, HpkeEncryptResult} from "../../index"
|
|
2
|
-
|
|
3
|
-
export class HpkeWrapper {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generate a new HPKE key pair along with an info string
|
|
7
|
-
* @returns HpkeKeyResult
|
|
8
|
-
*/
|
|
9
|
-
public generateKeyPair(): HpkeKeyResult {
|
|
10
|
-
return hpkeGenerateKeypair();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Generate a new info string for HPKE
|
|
15
|
-
* @returns A byte array representing the info string
|
|
16
|
-
*/
|
|
17
|
-
public generateInfoString(): number[] {
|
|
18
|
-
return generateInfoStr();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Encrypt a message using HPKE
|
|
23
|
-
* @param plaintext The message to encrypt
|
|
24
|
-
* @param publicKey The recipient's public key
|
|
25
|
-
* @param infoStr Additional information to include in the encryption
|
|
26
|
-
* @returns HpkeEncryptResult
|
|
27
|
-
*/
|
|
28
|
-
public encrypt(plaintext: number[], publicKey: number[], infoStr: number[]): HpkeEncryptResult {
|
|
29
|
-
return hpkeEncrypt(plaintext, publicKey, infoStr);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Decrypt a message using HPKE
|
|
34
|
-
* @param ciphertext The encrypted message
|
|
35
|
-
* @param privateKey The recipient's private key
|
|
36
|
-
* @param encapsulatedKey The encapsulated key
|
|
37
|
-
* @param tag The tag
|
|
38
|
-
* @param infoStr Additional information to include in the decryption
|
|
39
|
-
* @returns The decrypted message
|
|
40
|
-
*/
|
|
41
|
-
public decrypt(ciphertext: number[], privateKey: number[], encapsulatedKey: number[], tag: number[], infoStr: number[]): number[] {
|
|
42
|
-
return hpkeDecrypt(ciphertext, privateKey, encapsulatedKey, tag, infoStr);
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src-ts/hybrid/index.ts
DELETED
package/src-ts/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./password-hashers/index";
|
|
2
|
-
export * from "./hashers/index";
|
|
3
|
-
export * from "./key_exchange/index";
|
|
4
|
-
export * from "./symmetric/index";
|
|
5
|
-
export * from "./asymmetric/index";
|
|
6
|
-
export * from "./digital-signature";
|
|
7
|
-
export * from "./sponges/index";
|
|
8
|
-
export * from "./message/index";
|
|
9
|
-
export * from "./signature/index";
|
|
10
|
-
export * from "./hybrid/index";
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { CASx25519SecretPublicKeyResult, x25519DiffieHellman, x25519GenerateSecretAndPublicKey } from "../../index"
|
|
2
|
-
|
|
3
|
-
export class X25519Wrapper {
|
|
4
|
-
/**
|
|
5
|
-
* Generates and secret and public key to be used to create a shared secret with Diffie Hellman.
|
|
6
|
-
* User should share their public key with the other user and take the other user's public key and they can generate a Shared Secret.
|
|
7
|
-
* @returns X25519SecretPublicKeyResult
|
|
8
|
-
*/
|
|
9
|
-
public generateSecretAndPublicKey(): CASx25519SecretPublicKeyResult {
|
|
10
|
-
return x25519GenerateSecretAndPublicKey();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* User takes their secret key and the other user's public key to generate a shared secret.
|
|
15
|
-
* Can be used to derive an AES key over insecure channel.
|
|
16
|
-
* @param secretKey
|
|
17
|
-
* @param publicKey
|
|
18
|
-
* @returns Array<number>
|
|
19
|
-
*/
|
|
20
|
-
public generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>): Array<number> {
|
|
21
|
-
return x25519DiffieHellman(secretKey, publicKey);
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src-ts/message/hmac.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { hmacSign, hmacVerify } 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
|
-
}
|
package/src-ts/message/index.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { argon2Hash, argon2Verify} from "./../../index";
|
|
2
|
-
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
3
|
-
|
|
4
|
-
export class Argon2Wrapper implements IPasswordHasherBase {
|
|
5
|
-
/**
|
|
6
|
-
* Hashes a password with Argon2
|
|
7
|
-
* @param password
|
|
8
|
-
* @returns string
|
|
9
|
-
*/
|
|
10
|
-
public hashPassword(password: string): string {
|
|
11
|
-
if (!password) {
|
|
12
|
-
throw new Error("You must provide a password to hash with Argon2");
|
|
13
|
-
}
|
|
14
|
-
return argon2Hash(password);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Verifies that a password is the same as the hashed password with Argon2.
|
|
19
|
-
* @param hashedPassword
|
|
20
|
-
* @param passwordToVerify
|
|
21
|
-
* @returns boolean
|
|
22
|
-
*/
|
|
23
|
-
public verify(hashedPassword: string, passwordToVerify: string): boolean {
|
|
24
|
-
if (!hashedPassword || !passwordToVerify) {
|
|
25
|
-
throw new Error(
|
|
26
|
-
"You must provide a hashed password and a plaintext password to verify with Argon2",
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return argon2Verify(hashedPassword, passwordToVerify);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
|
-
import { bcryptHash, bcryptVerify } from "./../../index";
|
|
3
|
-
|
|
4
|
-
export class BCryptWrapper implements IPasswordHasherBase {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Hashes a password with BCrypt
|
|
8
|
-
* @param password
|
|
9
|
-
* @returns string
|
|
10
|
-
*/
|
|
11
|
-
public hashPassword(password: string): string {
|
|
12
|
-
if (!password) {
|
|
13
|
-
throw new Error("You must provide a password to hash with Argon2");
|
|
14
|
-
}
|
|
15
|
-
return bcryptHash(password);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Verifies that a password is the same as the hashed password with BCrypt.
|
|
20
|
-
* @param hashedPassword
|
|
21
|
-
* @param passwordToVerify
|
|
22
|
-
* @returns boolean
|
|
23
|
-
*/
|
|
24
|
-
public verify(
|
|
25
|
-
hashedPassword: string,
|
|
26
|
-
passwordToVerify: string,
|
|
27
|
-
): boolean {
|
|
28
|
-
if (!hashedPassword || !passwordToVerify) {
|
|
29
|
-
throw new Error(
|
|
30
|
-
"You must provide a hashed password and a plaintext password to verify with Argon2",
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
return bcryptVerify(hashedPassword, passwordToVerify);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Argon2Wrapper } from "./argon2-wrapper";
|
|
2
|
-
import { BCryptWrapper } from "./bcrypt-wrapper";
|
|
3
|
-
import { ScryptWrapper } from "./scrypt-wrapper";
|
|
4
|
-
|
|
5
|
-
import { PasswordHasherType } from "./password-hasher-type";
|
|
6
|
-
import { PasswordHasherFactory } from "./password-hasher-factory";
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
Argon2Wrapper,
|
|
10
|
-
BCryptWrapper,
|
|
11
|
-
PasswordHasherFactory,
|
|
12
|
-
PasswordHasherType,
|
|
13
|
-
ScryptWrapper,
|
|
14
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Argon2Wrapper } from "./argon2-wrapper";
|
|
2
|
-
import { BCryptWrapper } from "./bcrypt-wrapper";
|
|
3
|
-
import { PasswordHasherType } from "./password-hasher-type";
|
|
4
|
-
import { ScryptWrapper } from "./scrypt-wrapper";
|
|
5
|
-
|
|
6
|
-
export class PasswordHasherFactory {
|
|
7
|
-
/**
|
|
8
|
-
* Returns the appropriate hasher type based upon the type passed in.
|
|
9
|
-
* @param type
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
static getHasher(type: PasswordHasherType): any {
|
|
13
|
-
// Argon2 by default
|
|
14
|
-
let hasher = new Argon2Wrapper();
|
|
15
|
-
switch (type) {
|
|
16
|
-
case PasswordHasherType.Bcrypt:
|
|
17
|
-
hasher = new BCryptWrapper();
|
|
18
|
-
break;
|
|
19
|
-
case PasswordHasherType.Scrypt:
|
|
20
|
-
hasher = new ScryptWrapper();
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
return hasher;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { scryptHash, scryptVerify} from "../../index";
|
|
2
|
-
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
3
|
-
|
|
4
|
-
export class ScryptWrapper implements IPasswordHasherBase {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Hashes a password with SCrypt
|
|
8
|
-
* @param password
|
|
9
|
-
* @returns string
|
|
10
|
-
*/
|
|
11
|
-
public hashPassword(password: string): string {
|
|
12
|
-
if (!password) {
|
|
13
|
-
throw new Error("You must provide a password to hash with Scrypt");
|
|
14
|
-
}
|
|
15
|
-
return scryptHash(password);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Verifies that a password is the same as the hashed password with SCrypt.
|
|
20
|
-
* @param hashedPassword
|
|
21
|
-
* @param passwordToVerify
|
|
22
|
-
* @returns boolean
|
|
23
|
-
*/
|
|
24
|
-
public verify(hashedPassword: string, passwordToVerify: string): boolean {
|
|
25
|
-
if (!hashedPassword || !passwordToVerify) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
"You must provide a hashed password and a plaintext password to verify with Scrypt",
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
return scryptVerify(hashedPassword, passwordToVerify);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Cased25519KeyPairResult,
|
|
3
|
-
generateEd25519Keys,
|
|
4
|
-
signEd25519,
|
|
5
|
-
verifyEd25519,
|
|
6
|
-
} from "../../index";
|
|
7
|
-
|
|
8
|
-
export class Ed25519Wrapper {
|
|
9
|
-
/**
|
|
10
|
-
* Generates a new Ed25519 key pair
|
|
11
|
-
*/
|
|
12
|
-
public getKeyPair(): Cased25519KeyPairResult {
|
|
13
|
-
return generateEd25519Keys();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Signs a message with the given Ed25519 private key
|
|
18
|
-
* @param privateKey The private key to sign the message with
|
|
19
|
-
* @param message The message to sign
|
|
20
|
-
* @returns The signature
|
|
21
|
-
*/
|
|
22
|
-
public signMessage(privateKey: number[], message: number[]): number[] {
|
|
23
|
-
return signEd25519(privateKey, message);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Verifies a signature for a message with the given Ed25519 public key
|
|
28
|
-
* @param publicKey The public key to verify the signature with
|
|
29
|
-
* @param message The signed message
|
|
30
|
-
* @param signature The signature to verify
|
|
31
|
-
* @returns True if the signature is valid, false otherwise
|
|
32
|
-
*/
|
|
33
|
-
public verifyMessage(publicKey: number[], message: number[], signature: number[]): boolean {
|
|
34
|
-
return verifyEd25519(publicKey, message, signature);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ascon128Decrypt,
|
|
3
|
-
ascon128Encrypt,
|
|
4
|
-
ascon128KeyGenerate,
|
|
5
|
-
ascon128NonceGenerate,
|
|
6
|
-
} from "../../index";
|
|
7
|
-
|
|
8
|
-
export class AsconWrapper {
|
|
9
|
-
/**
|
|
10
|
-
* Generates an Ascon 128 key
|
|
11
|
-
* @returns Array<number>
|
|
12
|
-
*/
|
|
13
|
-
ascon128Key(): Array<number> {
|
|
14
|
-
return ascon128KeyGenerate();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Generates and Ascon 128 nonce.
|
|
19
|
-
* @returns Array<number>
|
|
20
|
-
*/
|
|
21
|
-
ascon128Nonce(): Array<number> {
|
|
22
|
-
return ascon128NonceGenerate();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Encrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
|
|
27
|
-
* @param key
|
|
28
|
-
* @param nonce
|
|
29
|
-
* @param plaintext
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
ascon128Encrypt(
|
|
33
|
-
key: Array<number>,
|
|
34
|
-
nonce: Array<number>,
|
|
35
|
-
plaintext: Array<number>,
|
|
36
|
-
): Array<number> {
|
|
37
|
-
if (!key || key.length === 0) {
|
|
38
|
-
throw new Error("Key is required");
|
|
39
|
-
}
|
|
40
|
-
if (!nonce || nonce.length === 0) {
|
|
41
|
-
throw new Error("Nonce is required");
|
|
42
|
-
}
|
|
43
|
-
if (!plaintext || plaintext.length === 0) {
|
|
44
|
-
throw new Error("Plaintext is required");
|
|
45
|
-
}
|
|
46
|
-
return ascon128Encrypt(key, nonce, plaintext);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Decrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
|
|
51
|
-
* @param key
|
|
52
|
-
* @param nonce
|
|
53
|
-
* @param ciphertext
|
|
54
|
-
* @returns Array<number>
|
|
55
|
-
*/
|
|
56
|
-
ascon128Decrypt(
|
|
57
|
-
key: Array<number>,
|
|
58
|
-
nonce: Array<number>,
|
|
59
|
-
ciphertext: Array<number>,
|
|
60
|
-
): Array<number> {
|
|
61
|
-
if (!key || key.length === 0) {
|
|
62
|
-
throw new Error("Key is required");
|
|
63
|
-
}
|
|
64
|
-
if (!nonce || nonce.length === 0) {
|
|
65
|
-
throw new Error("Nonce is required");
|
|
66
|
-
}
|
|
67
|
-
if (!ciphertext || ciphertext.length === 0) {
|
|
68
|
-
throw new Error("Ciphertext is required");
|
|
69
|
-
}
|
|
70
|
-
return ascon128Decrypt(key, nonce, ciphertext);
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src-ts/sponges/index.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
aes128Decrypt,
|
|
3
|
-
aes128Encrypt,
|
|
4
|
-
aes128Key,
|
|
5
|
-
aes128KeyFromX25519SharedSecret,
|
|
6
|
-
aes256Decrypt,
|
|
7
|
-
aes256Encrypt,
|
|
8
|
-
aes256Key,
|
|
9
|
-
aes256KeyFromX25519SharedSecret,
|
|
10
|
-
aesNonce,
|
|
11
|
-
} from "../../index";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export class AESWrapper {
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @description Generates a 128 bit AES key
|
|
18
|
-
* @returns returns a 128 bit AES key
|
|
19
|
-
*/
|
|
20
|
-
public aes128Key(): Array<number> {
|
|
21
|
-
return aes128Key();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @description Generates a 256 bit AES key
|
|
26
|
-
* @returns returns a 256 bit AES key
|
|
27
|
-
*/
|
|
28
|
-
public aes256Key(): Array<number> {
|
|
29
|
-
return aes256Key();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Generates an 96 bit AES nonce
|
|
34
|
-
* @returns Array<number>
|
|
35
|
-
*/
|
|
36
|
-
public generateAESNonce(): Array<number> {
|
|
37
|
-
return aesNonce();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Encrypts with AES 128.
|
|
42
|
-
* @param aesKey
|
|
43
|
-
* @param nonce
|
|
44
|
-
* @param plaintext
|
|
45
|
-
* @returns Array<number>
|
|
46
|
-
*/
|
|
47
|
-
public aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
|
|
48
|
-
return aes128Encrypt(aesKey, nonce, plaintext);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Decrypts with AES 128
|
|
53
|
-
* @param aesKey
|
|
54
|
-
* @param nonce
|
|
55
|
-
* @param ciphertext
|
|
56
|
-
* @returns Array<number>
|
|
57
|
-
*/
|
|
58
|
-
public aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
|
|
59
|
-
return aes128Decrypt(aesKey, nonce, ciphertext);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Encrypts with AES-256
|
|
64
|
-
* @param aesKey
|
|
65
|
-
* @param nonce
|
|
66
|
-
* @param plaintext
|
|
67
|
-
* @returns
|
|
68
|
-
*/
|
|
69
|
-
public aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
|
|
70
|
-
return aes256Encrypt(aesKey, nonce, plaintext);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Decrypts with AES 256
|
|
75
|
-
* @param aesKey
|
|
76
|
-
* @param nonce
|
|
77
|
-
* @param ciphertext
|
|
78
|
-
* @returns
|
|
79
|
-
*/
|
|
80
|
-
public aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
|
|
81
|
-
return aes256Decrypt(aesKey, nonce, ciphertext);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
|
|
86
|
-
* @param shared_secret
|
|
87
|
-
* @returns
|
|
88
|
-
*/
|
|
89
|
-
public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): number[] {
|
|
90
|
-
return aes256KeyFromX25519SharedSecret(shared_secret);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
|
|
95
|
-
* @param shared_secret
|
|
96
|
-
* @returns
|
|
97
|
-
*/
|
|
98
|
-
public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): number[] {
|
|
99
|
-
return aes128KeyFromX25519SharedSecret(shared_secret);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { CASRSAKeyPairResult, RSAWrapper } from "..";
|
|
3
|
-
|
|
4
|
-
describe("Asymmetric Tests", () => {
|
|
5
|
-
it("RSA 2048 Sign and Verify", () => {
|
|
6
|
-
const rsaWrapper = new RSAWrapper();
|
|
7
|
-
const keys: CASRSAKeyPairResult = rsaWrapper.generateKeys(2048);
|
|
8
|
-
const tohashed: string = "This is my encrypt";
|
|
9
|
-
const encoder = new TextEncoder();
|
|
10
|
-
const toSignBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
11
|
-
const signature: Array<number> = rsaWrapper.sign(keys.privateKey, toSignBytes);
|
|
12
|
-
const verified = rsaWrapper.verify(keys.publicKey, toSignBytes, signature);
|
|
13
|
-
assert.isTrue(verified);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { DigitalSignatureFactory, DigitalSignatureType } from "../src-ts/digital-signature/digital-signature-factory";
|
|
3
|
-
import { CASRSADigitalSignatureResult } from "../index";
|
|
4
|
-
import { Ed25519Wrapper } from "../src-ts/signature/ed25519-wrapper";
|
|
5
|
-
|
|
6
|
-
describe("Digital Signature", () => {
|
|
7
|
-
it("SHA 512 RSA pass", () => {
|
|
8
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
|
|
9
|
-
const tohashed: string = "This is my array to encrypt";
|
|
10
|
-
const encoder = new TextEncoder();
|
|
11
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
12
|
-
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
|
|
13
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
|
|
14
|
-
assert.equal(verify, true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("SHA 512 RSA fails", () => {
|
|
18
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
|
|
19
|
-
const tohashed: string = "This is my array to encrypt";
|
|
20
|
-
const notOriginal: string = "This is not a fun time";
|
|
21
|
-
const encoder = new TextEncoder();
|
|
22
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
23
|
-
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
|
|
24
|
-
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
25
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
26
|
-
assert.equal(verify, false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("SHA 256 RSA pass", () => {
|
|
30
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
|
|
31
|
-
const tohashed: string = "This is my array to encrypt";
|
|
32
|
-
const encoder = new TextEncoder();
|
|
33
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
34
|
-
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
|
|
35
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
|
|
36
|
-
assert.equal(verify, true);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("SHA 256 RSA fails", () => {
|
|
40
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
|
|
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: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
47
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
48
|
-
assert.equal(verify, false);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
it("ED25519 Sign and Verify", () => {
|
|
53
|
-
const ed25519 = new Ed25519Wrapper();
|
|
54
|
-
const keyPair = ed25519.getKeyPair();
|
|
55
|
-
const message = Array.from(new TextEncoder().encode("This is a test message"));
|
|
56
|
-
const signature = ed25519.signMessage(keyPair.privateKey, message);
|
|
57
|
-
const isValid = ed25519.verifyMessage(keyPair.publicKey, message, signature);
|
|
58
|
-
assert.equal(isValid, true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("ED25519 Verify Fails with Wrong Message", () => {
|
|
62
|
-
const ed25519 = new Ed25519Wrapper();
|
|
63
|
-
const keyPair = ed25519.getKeyPair();
|
|
64
|
-
const message = Array.from(new TextEncoder().encode("This is a test message"));
|
|
65
|
-
const wrongMessage = Array.from(new TextEncoder().encode("This is a different message"));
|
|
66
|
-
const signature = ed25519.signMessage(keyPair.privateKey, message);
|
|
67
|
-
const isValid = ed25519.verifyMessage(keyPair.publicKey, wrongMessage, signature);
|
|
68
|
-
assert.equal(isValid, false);
|
|
69
|
-
});
|
|
70
|
-
});
|