diff --git a/index.node b/index.node index bffaf48..6e5da6b 100644 Binary files a/index.node and b/index.node differ diff --git a/package.json b/package.json index 08d203d..1e44a31 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cas-typescript-sdk", - "version": "1.0.17", + "version": "1.0.18", "description": "", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src-ts/hashers/hasher-base.ts b/src-ts/hashers/hasher-base.ts index 9acd835..71fa2ec 100644 --- a/src-ts/hashers/hasher-base.ts +++ b/src-ts/hashers/hasher-base.ts @@ -1,6 +1,6 @@ export interface IHasherBase { - hash_512(dataToHash: number[]): number[]; - verify_512(dataToHash: number[], dataToVerify: number[]): boolean; - hash_256(dataToHash: number[]): number[]; - verify_256(dataToHash: number[], dataToVerify: number[]): boolean; + hash512(dataToHash: number[]): number[]; + verify512(dataToHash: number[], dataToVerify: number[]): boolean; + hash256(dataToHash: number[]): number[]; + verify256(dataToHash: number[], dataToVerify: number[]): boolean; } \ No newline at end of file diff --git a/src-ts/hashers/sha-wrapper.ts b/src-ts/hashers/sha-wrapper.ts index f733591..6aa949d 100644 --- a/src-ts/hashers/sha-wrapper.ts +++ b/src-ts/hashers/sha-wrapper.ts @@ -2,14 +2,14 @@ import { sha256, sha256Verify, sha512, sha512Verify } from "../../index"; import { IHasherBase } from "./hasher-base"; export class SHAWrapper implements IHasherBase { - hash_512(dataToHash: number[]): number[] { + hash512(dataToHash: number[]): number[] { if (!dataToHash || dataToHash.length === 0) { throw new Error("You must provide an allocated array of data"); } return sha512(dataToHash); } - verify_512(dataToHash: number[], dataToVerify: number[]): boolean { + verify512(dataToHash: number[], dataToVerify: number[]): boolean { if (!dataToHash || dataToHash.length === 0) { throw new Error("You must provide an allocated array of data"); } @@ -19,14 +19,14 @@ export class SHAWrapper implements IHasherBase { return sha512Verify(dataToHash, dataToVerify); } - hash_256(dataToHash: number[]): number[] { + hash256(dataToHash: number[]): number[] { if (!dataToHash || dataToHash.length === 0) { throw new Error("You must provide an allocated array of data"); } return sha256(dataToHash); } - verify_256(dataToHash: number[], dataToVerify: number[]): boolean { + verify256(dataToHash: number[], dataToVerify: number[]): boolean { if (!dataToHash || dataToHash.length === 0) { throw new Error("You must provide an allocated array of data"); } diff --git a/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts b/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts index bc84f29..dad6534 100644 --- a/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +++ b/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts @@ -15,7 +15,7 @@ export class AESRSAHybridInitializer { this.aesType = aesType; let aesWrapper = new AESWrapper(); this.aesKey = (aesType === 128) ? aesWrapper.aes128Key() : aesWrapper.aes256Key(); - this.aesNonce = aesWrapper.aesNonce(); + this.aesNonce = aesWrapper.generateAESNonce(); if (rsaSize !== 1028 && rsaSize !== 2048 && rsaSize !== 4096) { throw new Error("You must provide an appropriate RSA Key pair size to generate a hybrid initalizer"); } diff --git a/src-ts/key_exchange/x25519.ts b/src-ts/key_exchange/x25519.ts index 22f621e..60fb46e 100644 --- a/src-ts/key_exchange/x25519.ts +++ b/src-ts/key_exchange/x25519.ts @@ -5,7 +5,7 @@ export class X25519Wrapper { return x25519GenerateSecretAndPublicKey(); } - public diffieHellman(secretKey: Array, publicKey: Array) { + public generateSharedSecret(secretKey: Array, publicKey: Array) { return x25519DiffieHellman(secretKey, publicKey); } } \ No newline at end of file diff --git a/src-ts/password-hashers/argon2-wrapper.ts b/src-ts/password-hashers/argon2-wrapper.ts index 906fc50..61a1c37 100644 --- a/src-ts/password-hashers/argon2-wrapper.ts +++ b/src-ts/password-hashers/argon2-wrapper.ts @@ -9,7 +9,7 @@ export class Argon2Wrapper implements IPasswordHasherBase { return argon2Hash(password); } - public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean { + public verify(hashedPassword: string, passwordToVerify: string): boolean { if (!hashedPassword || !passwordToVerify) { throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2"); } diff --git a/src-ts/password-hashers/bcrypt-wrapper.ts b/src-ts/password-hashers/bcrypt-wrapper.ts index f0e19cc..3b94483 100644 --- a/src-ts/password-hashers/bcrypt-wrapper.ts +++ b/src-ts/password-hashers/bcrypt-wrapper.ts @@ -9,7 +9,7 @@ export class BCryptWrapper implements IPasswordHasherBase { return bcryptHash(password); } - public verifyPassword( + public verify( hashedPassword: string, passwordToVerify: string, ): boolean { diff --git a/src-ts/password-hashers/password-hasher-base.ts b/src-ts/password-hashers/password-hasher-base.ts index 88d8d34..839d56d 100644 --- a/src-ts/password-hashers/password-hasher-base.ts +++ b/src-ts/password-hashers/password-hasher-base.ts @@ -1,4 +1,4 @@ export interface IPasswordHasherBase { hashPassword(password: string): string; - verifyPassword(hashedPassword: string, passwordToVerify: string): boolean; + verify(hashedPassword: string, passwordToVerify: string): boolean; } \ No newline at end of file diff --git a/src-ts/password-hashers/scrypt-wrapper.ts b/src-ts/password-hashers/scrypt-wrapper.ts index f1f8183..17499fb 100644 --- a/src-ts/password-hashers/scrypt-wrapper.ts +++ b/src-ts/password-hashers/scrypt-wrapper.ts @@ -10,7 +10,7 @@ export class ScryptWrapper implements IPasswordHasherBase { return scryptHash(password); } - public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean { + public verify(hashedPassword: string, passwordToVerify: string): boolean { if (!hashedPassword || !passwordToVerify) { throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt"); } diff --git a/src-ts/symmetric/aes-wrapper.ts b/src-ts/symmetric/aes-wrapper.ts index 26eab0f..eeda5f6 100644 --- a/src-ts/symmetric/aes-wrapper.ts +++ b/src-ts/symmetric/aes-wrapper.ts @@ -20,7 +20,7 @@ export class AESWrapper { return aes256Key(); } - public aesNonce(): Array { + public generateAESNonce(): Array { return aesNonce(); } @@ -40,11 +40,11 @@ export class AESWrapper { return aes256Decrypt(aesKey, nonce, ciphertext); } - public aes256KeyFromX25519SharedSecret(shared_secret: Array): AesKeyFromX25519SharedSecret { + public aes256KeyNonceX25519DiffieHellman(shared_secret: Array): AesKeyFromX25519SharedSecret { return aes256KeyFromX25519SharedSecret(shared_secret); } - public aes128KeyFromX25519SharedSecret(shared_secret: Array): AesKeyFromX25519SharedSecret { + public aes128KeyNonceX25519DiffieHellman(shared_secret: Array): AesKeyFromX25519SharedSecret { return aes128KeyFromX25519SharedSecret(shared_secret); } } diff --git a/test-ts/hasher.test.spec.ts b/test-ts/hasher.test.spec.ts index ee85921..c194011 100644 --- a/test-ts/hasher.test.spec.ts +++ b/test-ts/hasher.test.spec.ts @@ -7,7 +7,7 @@ describe("SHA512 Tests", () => { const tohashed: string = "This is my array to hash"; const encoder = new TextEncoder(); const tohashBytes: Array = Array.from(encoder.encode(tohashed)); - const hashed = wrapper.hash_512(tohashBytes); + const hashed = wrapper.hash512(tohashBytes); assert.notEqual(tohashBytes, hashed); }); @@ -16,9 +16,9 @@ describe("SHA512 Tests", () => { const tohashed: string = "This is my array to hash"; const encoder = new TextEncoder(); const tohashBytes: Array = Array.from(encoder.encode(tohashed)); - const hashed = wrapper.hash_512(tohashBytes); + const hashed = wrapper.hash512(tohashBytes); const toVerifyBytes: Array = Array.from(encoder.encode(tohashed)); - const verified = wrapper.verify_512(hashed, toVerifyBytes); + const verified = wrapper.verify512(hashed, toVerifyBytes); assert.equal(true, verified); }); @@ -27,10 +27,10 @@ describe("SHA512 Tests", () => { const tohashed: string = "This is my array to hash"; const encoder = new TextEncoder(); const tohashBytes: Array = Array.from(encoder.encode(tohashed)); - const hashed = wrapper.hash_512(tohashBytes); + const hashed = wrapper.hash512(tohashBytes); const toVerify = "This Is Not The Same"; const toVerifyBytes: Array = Array.from(encoder.encode(toVerify)); - const verified = wrapper.verify_512(hashed, toVerifyBytes); + const verified = wrapper.verify512(hashed, toVerifyBytes); assert.equal(false, verified); }); }); @@ -42,7 +42,7 @@ describe("SHA256 Tests", () => { const tohashed: string = "This is my array to hash"; const encoder = new TextEncoder(); const tohashBytes: Array = Array.from(encoder.encode(tohashed)); - const hashed = wrapper.hash_256(tohashBytes); + const hashed = wrapper.hash256(tohashBytes); assert.notEqual(tohashBytes, hashed); }); @@ -51,9 +51,9 @@ describe("SHA256 Tests", () => { const tohashed: string = "This is my array to hash"; const encoder = new TextEncoder(); const tohashBytes: Array = Array.from(encoder.encode(tohashed)); - const hashed = wrapper.hash_256(tohashBytes); + const hashed = wrapper.hash256(tohashBytes); const toVerifyBytes: Array = Array.from(encoder.encode(tohashed)); - const verified = wrapper.verify_256(hashed, toVerifyBytes); + const verified = wrapper.verify256(hashed, toVerifyBytes); assert.equal(true, verified); }); @@ -62,10 +62,10 @@ describe("SHA256 Tests", () => { const tohashed: string = "This is my array to hash"; const encoder = new TextEncoder(); const tohashBytes: Array = Array.from(encoder.encode(tohashed)); - const hashed = wrapper.hash_256(tohashBytes); + const hashed = wrapper.hash256(tohashBytes); const toVerify = "This Is Not The Same"; const toVerifyBytes: Array = Array.from(encoder.encode(toVerify)); - const verified = wrapper.verify_256(hashed, toVerifyBytes); + const verified = wrapper.verify256(hashed, toVerifyBytes); assert.equal(false, verified); }); }); \ No newline at end of file diff --git a/test-ts/insecure-channel.test.spec.ts b/test-ts/insecure-channel.test.spec.ts index e01e7df..43872e9 100644 --- a/test-ts/insecure-channel.test.spec.ts +++ b/test-ts/insecure-channel.test.spec.ts @@ -11,11 +11,11 @@ describe("Insecure Channel Tests", () => { const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey(); const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey(); - const alice_shared_secret = x25519Wrapper.diffieHellman(alice_keys.secretKey, bob_keys.publicKey); - const bob_shared_secret = x25519Wrapper.diffieHellman(bob_keys.secretKey, alice_keys.publicKey); + const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey); + const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey); - const alice_aes_key = aesWrapper.aes256KeyFromX25519SharedSecret(alice_shared_secret); - const bob_aes_key = aesWrapper.aes256KeyFromX25519SharedSecret(bob_shared_secret); + const alice_aes_key = aesWrapper.aes256KeyNonceX25519DiffieHellman(alice_shared_secret); + const bob_aes_key = aesWrapper.aes256KeyNonceX25519DiffieHellman(bob_shared_secret); const tohashed: string = "This is my encrypt text"; const encoder = new TextEncoder(); @@ -33,11 +33,11 @@ describe("Insecure Channel Tests", () => { const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey(); const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey(); - const alice_shared_secret = x25519Wrapper.diffieHellman(alice_keys.secretKey, bob_keys.publicKey); - const bob_shared_secret = x25519Wrapper.diffieHellman(bob_keys.secretKey, alice_keys.publicKey); + const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey); + const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey); - const alice_aes_key = aesWrapper.aes128KeyFromX25519SharedSecret(alice_shared_secret); - const bob_aes_key = aesWrapper.aes128KeyFromX25519SharedSecret(bob_shared_secret); + const alice_aes_key = aesWrapper.aes128KeyNonceX25519DiffieHellman(alice_shared_secret); + const bob_aes_key = aesWrapper.aes128KeyNonceX25519DiffieHellman(bob_shared_secret); const tohashed: string = "This is my encrypt text"; const encoder = new TextEncoder(); diff --git a/test-ts/key-exchange-test.spec.ts b/test-ts/key-exchange-test.spec.ts index 6a10713..f3fb34f 100644 --- a/test-ts/key-exchange-test.spec.ts +++ b/test-ts/key-exchange-test.spec.ts @@ -8,11 +8,11 @@ describe("X25519 Key Exchange", () => { const alice = wrapper.generateSecretAndPublicKey(); const bob = wrapper.generateSecretAndPublicKey(); - const alice_shared_secret = wrapper.diffieHellman( + const alice_shared_secret = wrapper.generateSharedSecret( alice.secretKey, bob.publicKey, ); - const bob_shared_secret = wrapper.diffieHellman( + const bob_shared_secret = wrapper.generateSharedSecret( bob.secretKey, alice.publicKey, ); diff --git a/test-ts/password-hasher-test.spec.ts b/test-ts/password-hasher-test.spec.ts index 609b6cf..eda3de6 100644 --- a/test-ts/password-hasher-test.spec.ts +++ b/test-ts/password-hasher-test.spec.ts @@ -18,7 +18,7 @@ describe("Bcrypt Tests", () => { const hasher: BCryptWrapper = new BCryptWrapper(); const password: string = "NotThisPassword!@"; const hashedPassword: string = hasher.hashPassword(password); - const isValid: boolean = hasher.verifyPassword(hashedPassword, password); + const isValid: boolean = hasher.verify(hashedPassword, password); expect(isValid).to.equal(true); }); @@ -26,7 +26,7 @@ describe("Bcrypt Tests", () => { const hasher: BCryptWrapper = new BCryptWrapper(); const password: string = "NotThisPassword!@"; const hashedPassword: string = hasher.hashPassword(password); - const isValid: boolean = hasher.verifyPassword( + const isValid: boolean = hasher.verify( hashedPassword, "ThesePasswordsDoNotMatch", ); @@ -50,7 +50,7 @@ describe("Scrypt Tests", () => { ); const password: string = "ScryptRocks1231231"; const hashed: string = hasher.hashPassword(password); - const verified: boolean = hasher.verifyPassword(hashed, password); + const verified: boolean = hasher.verify(hashed, password); assert.isTrue(verified); }); @@ -60,7 +60,7 @@ describe("Scrypt Tests", () => { ); const password: string = "ScryptRocksSomeGarbageText"; const hashed: string = hasher.hashPassword(password); - const verified: boolean = hasher.verifyPassword( + const verified: boolean = hasher.verify( hashed, "make this fail, its not the same", ); @@ -84,7 +84,7 @@ describe("Argon2 Tests", () => { ); const password: string = "ScryptRocks1231231"; const hashed: string = hasher.hashPassword(password); - const verified: boolean = hasher.verifyPassword(hashed, password); + const verified: boolean = hasher.verify(hashed, password); assert.isTrue(verified); }); @@ -94,7 +94,7 @@ describe("Argon2 Tests", () => { ); const password: string = "ScryptRocksSomeGarbageText"; const hashed: string = hasher.hashPassword(password); - const verified: boolean = hasher.verifyPassword( + const verified: boolean = hasher.verify( hashed, "make this fail, its not the same", ); diff --git a/test-ts/symmetric.test.spec.ts b/test-ts/symmetric.test.spec.ts index ebe422f..f86ddb8 100644 --- a/test-ts/symmetric.test.spec.ts +++ b/test-ts/symmetric.test.spec.ts @@ -6,7 +6,7 @@ describe("Symmetric Tests", () => { it("aes 128 encrypt and decrypt equals", () => { const aesWrapper: AESWrapper = new AESWrapper(); const aesKey = aesWrapper.aes128Key(); - const aesNonce = aesWrapper.aesNonce(); + const aesNonce = aesWrapper.generateAESNonce(); const tohashed: string = "This is my array to encrypt"; const encoder = new TextEncoder(); const tohashBytes: Array = Array.from(encoder.encode(tohashed)); @@ -19,7 +19,7 @@ describe("Symmetric Tests", () => { it("aes 256 encrypt and decrypt equals", () => { const aesWrapper: AESWrapper = new AESWrapper(); const aesKey = aesWrapper.aes256Key(); - const aesNonce = aesWrapper.aesNonce(); + const aesNonce = aesWrapper.generateAESNonce(); const tohashed: string = "This is my array to encrypt"; const encoder = new TextEncoder(); const tohashBytes: Array = Array.from(encoder.encode(tohashed));