cas-typescript-sdk 1.0.47 → 1.0.49

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 (86) hide show
  1. package/index.d.ts +141 -0
  2. package/index.darwin-x64.node +0 -0
  3. package/index.js +631 -0
  4. package/index.linux-x64-gnu.node +0 -0
  5. package/index.linux-x64-musl.node +0 -0
  6. package/index.win32-x64-msvc.node +0 -0
  7. package/lib/asymmetric/index.d.ts +3 -0
  8. package/lib/asymmetric/index.js +5 -0
  9. package/lib/digital-signature/index.d.ts +6 -0
  10. package/lib/digital-signature/index.js +11 -0
  11. package/lib/hashers/index.d.ts +5 -0
  12. package/lib/hashers/index.js +11 -0
  13. package/lib/hybrid/index.d.ts +2 -0
  14. package/lib/hybrid/index.js +5 -0
  15. package/lib/index.d.ts +10 -0
  16. package/lib/key_exchange/index.d.ts +3 -0
  17. package/lib/key_exchange/index.js +5 -0
  18. package/lib/message/index.d.ts +2 -0
  19. package/lib/message/index.js +5 -0
  20. package/lib/password-hashers/index.d.ts +6 -0
  21. package/lib/password-hashers/index.js +13 -0
  22. package/lib/signature/index.d.ts +2 -0
  23. package/lib/signature/index.js +5 -0
  24. package/lib/sponges/index.d.ts +2 -0
  25. package/lib/sponges/index.js +5 -0
  26. package/lib/symmetric/index.d.ts +2 -0
  27. package/lib/symmetric/index.js +5 -0
  28. package/package.json +8 -1
  29. package/.github/workflows/main-pr-linux.yml +0 -28
  30. package/.github/workflows/main-pr-windows.yml +0 -28
  31. package/.github/workflows/main-publish.yml +0 -109
  32. package/Cargo.toml +0 -19
  33. package/build.rs +0 -5
  34. package/docs/EXAMPLES.md +0 -138
  35. package/src/asymmetric/cas_ed25519.rs +0 -35
  36. package/src/asymmetric/cas_rsa.rs +0 -32
  37. package/src/digital_signature/sha_256_rsa.rs +0 -40
  38. package/src/digital_signature/sha_512_rsa.rs +0 -40
  39. package/src/digital_signature/types.rs +0 -34
  40. package/src/hashers/blake2.rs +0 -60
  41. package/src/hashers/sha.rs +0 -68
  42. package/src/hybrid/hpke.rs +0 -63
  43. package/src/hybrid/types.rs +0 -15
  44. package/src/key_exchange/types.rs +0 -17
  45. package/src/key_exchange/x25519.rs +0 -25
  46. package/src/lib.rs +0 -47
  47. package/src/message/hmac.rs +0 -21
  48. package/src/password_hashers/argon2.rs +0 -37
  49. package/src/password_hashers/bcrypt.rs +0 -37
  50. package/src/password_hashers/scrypt.rs +0 -36
  51. package/src/sponges/ascon_aead.rs +0 -66
  52. package/src/symmetric/aes.rs +0 -71
  53. package/src-ts/asymmetric/RSAWrapper.ts +0 -59
  54. package/src-ts/digital-signature/digital-siganture-sha-512.ts +0 -40
  55. package/src-ts/digital-signature/digital-signature-base.ts +0 -6
  56. package/src-ts/digital-signature/digital-signature-factory.ts +0 -25
  57. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +0 -41
  58. package/src-ts/hashers/blake2-wrapper.ts +0 -43
  59. package/src-ts/hashers/hasher-base.ts +0 -6
  60. package/src-ts/hashers/hasher-factory.ts +0 -19
  61. package/src-ts/hashers/hasher-type.ts +0 -4
  62. package/src-ts/hashers/sha-wrapper.ts +0 -60
  63. package/src-ts/hybrid/hpke.ts +0 -44
  64. package/src-ts/key_exchange/x25519.ts +0 -23
  65. package/src-ts/message/hmac.ts +0 -26
  66. package/src-ts/password-hashers/argon2-wrapper.ts +0 -31
  67. package/src-ts/password-hashers/bcrypt-wrapper.ts +0 -35
  68. package/src-ts/password-hashers/password-hasher-base.ts +0 -4
  69. package/src-ts/password-hashers/password-hasher-factory.ts +0 -25
  70. package/src-ts/password-hashers/password-hasher-type.ts +0 -5
  71. package/src-ts/password-hashers/scrypt-wrapper.ts +0 -32
  72. package/src-ts/signature/ed25519-wrapper.ts +0 -36
  73. package/src-ts/sponges/ascon-wrapper.ts +0 -72
  74. package/src-ts/symmetric/aes-wrapper.ts +0 -101
  75. package/test-ts/asymmetric.test.spec.ts +0 -15
  76. package/test-ts/digital-signature.test.spec.ts +0 -70
  77. package/test-ts/hasher.test.spec.ts +0 -139
  78. package/test-ts/helpers/array.ts +0 -10
  79. package/test-ts/hmac.test.spec.ts +0 -16
  80. package/test-ts/hybrid.test.spec.ts +0 -23
  81. package/test-ts/insecure-channel.test.spec.ts +0 -55
  82. package/test-ts/key-exchange.test.spec.ts +0 -23
  83. package/test-ts/password-hasher.test.spec.ts +0 -104
  84. package/test-ts/sponges.test.spec.ts +0 -28
  85. package/test-ts/symmetric.test.spec.ts +0 -82
  86. package/tsconfig.json +0 -22
@@ -1,25 +0,0 @@
1
- import { DigitalSignatureSHA512Wrapper } from "./digital-siganture-sha-512";
2
- import { DigitalSignatureSHA256Wrapper } from "./digital-signaturte-sha-256";
3
-
4
- export enum DigitalSignatureType {
5
- SHA512 = 1,
6
- SHA256 = 2
7
- }
8
-
9
- export class DigitalSignatureFactory {
10
-
11
- /**
12
- * Get the appropriate digital signature wrapper based upon the type passed in.
13
- * @param type
14
- * @returns
15
- */
16
- public static get(type: DigitalSignatureType) {
17
- let ds = new DigitalSignatureSHA512Wrapper();
18
- switch (type) {
19
- case DigitalSignatureType.SHA256:
20
- ds = new DigitalSignatureSHA256Wrapper();
21
- break;
22
- }
23
- return ds;
24
- }
25
- }
@@ -1,41 +0,0 @@
1
- import { CASRSADigitalSignatureResult, sha256RsaDigitalSignature, sha256RsaVerifyDigitalSignature } from "../../index";
2
- import { IDigitalSignature } from "./digital-signature-base";
3
-
4
- export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
5
-
6
- /**
7
- * Generates and RSA digital signature with SHA3-512
8
- * @param rsa_key_size
9
- * @param data_to_sign
10
- * @returns RsaDigitalSignatureResult
11
- */
12
- createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult {
13
- if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
14
- throw new Error("You need to provide an appropriate RSA key size.");
15
- }
16
- if (data_to_sign?.length === 0) {
17
- throw new Error("Must provide allocated data to sign");
18
- }
19
- return sha256RsaDigitalSignature(rsa_key_size, data_to_sign);
20
- }
21
-
22
- /**
23
- * Verifies a digital signature created with the RSA public key.
24
- * @param public_key
25
- * @param data_to_verify
26
- * @param signature
27
- * @returns boolean
28
- */
29
- verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean {
30
- if (!public_key) {
31
- throw new Error("Must provide a public key");
32
- }
33
- if (data_to_verify?.length === 0) {
34
- throw new Error("Must provide an allocated data to verify");
35
- }
36
- if (signature?.length === 0) {
37
- throw new Error("Must provide an allocated signature");
38
- }
39
- return sha256RsaVerifyDigitalSignature(public_key, data_to_verify, signature);
40
- }
41
- }
@@ -1,43 +0,0 @@
1
- import { blake2Sha512Verify, blake2Sha256Verify, blake2Sha256, blake2Sha512 } from "../../index";
2
- import { IHasherBase } from "./hasher-base";
3
-
4
- export class Blake2Wrapper implements IHasherBase {
5
-
6
- /**
7
- * Hashes the input data using Blake2b 512
8
- * @param dataToHash The data to hash
9
- * @returns The hashed output
10
- */
11
- hash512(dataToHash: number[]): number[] {
12
- return blake2Sha512(dataToHash);
13
- }
14
-
15
- /**
16
- * Verifies the input data against the hashed output using Blake2b 512
17
- * @param dataToHash The data to hash
18
- * @param dataToVerify The data to verify
19
- * @returns True if the verification is successful, false otherwise
20
- */
21
- verify512(dataToHash: number[], dataToVerify: number[]): boolean {
22
- return blake2Sha512Verify(dataToHash, dataToVerify);
23
- }
24
- /**
25
- * Hashes the input data using Blake2b 256
26
- * @param dataToHash The data to hash
27
- * @returns The hashed output
28
- */
29
-
30
- hash256(dataToHash: number[]): number[] {
31
- return blake2Sha256(dataToHash);
32
- }
33
-
34
- /**
35
- * Verifies the input data against the hashed output using Blake2b 256
36
- * @param dataToHash The data to hash
37
- * @param dataToVerify The data to verify
38
- * @returns True if the verification is successful, false otherwise
39
- */
40
- verify256(dataToHash: number[], dataToVerify: number[]): boolean {
41
- return blake2Sha256Verify(dataToHash, dataToVerify);
42
- }
43
- }
@@ -1,6 +0,0 @@
1
- export interface IHasherBase {
2
- hash512(dataToHash: number[]): number[];
3
- verify512(dataToHash: number[], dataToVerify: number[]): boolean;
4
- hash256(dataToHash: number[]): number[];
5
- verify256(dataToHash: number[], dataToVerify: number[]): boolean;
6
- }
@@ -1,19 +0,0 @@
1
- import { Blake2Wrapper } from "./blake2-wrapper";
2
- import { HasherType } from "./hasher-type";
3
- import { SHAWrapper } from "./sha-wrapper";
4
-
5
- export class HasherFactory {
6
- /**
7
- * Get the appropriate hasher wrapper based upon the type based in.
8
- * @param type
9
- * @returns
10
- */
11
- getHasher(type: HasherType): any {
12
- let result: SHAWrapper = new SHAWrapper();
13
- switch(type) {
14
- case HasherType.Blake2:
15
- result = new Blake2Wrapper();
16
- }
17
- return result;
18
- }
19
- }
@@ -1,4 +0,0 @@
1
- export enum HasherType {
2
- SHA = 1,
3
- Blake2 = 2
4
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -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,4 +0,0 @@
1
- export interface IPasswordHasherBase {
2
- hashPassword(password: string): string;
3
- verify(hashedPassword: string, passwordToVerify: string): boolean;
4
- }
@@ -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,5 +0,0 @@
1
- export enum PasswordHasherType {
2
- Bcrypt = 1,
3
- Scrypt = 2,
4
- Argon2 = 3
5
- }
@@ -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
- }
@@ -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
- });