Skip to content

Commit

Permalink
Merge pull request #15 from Cryptographic-API-Services/pre-release
Browse files Browse the repository at this point in the history
Function Name Matching For C# SDK
  • Loading branch information
WingZer0o committed May 10, 2024
2 parents 7410b23 + 5e7cdd5 commit 2186b42
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 46 deletions.
Binary file modified index.node
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src-ts/hashers/hasher-base.ts
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 4 additions & 4 deletions src-ts/hashers/sha-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src-ts/key_exchange/x25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class X25519Wrapper {
return x25519GenerateSecretAndPublicKey();
}

public diffieHellman(secretKey: Array<number>, publicKey: Array<number>) {
public generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>) {
return x25519DiffieHellman(secretKey, publicKey);
}
}
2 changes: 1 addition & 1 deletion src-ts/password-hashers/argon2-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src-ts/password-hashers/bcrypt-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class BCryptWrapper implements IPasswordHasherBase {
return bcryptHash(password);
}

public verifyPassword(
public verify(
hashedPassword: string,
passwordToVerify: string,
): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src-ts/password-hashers/password-hasher-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IPasswordHasherBase {
hashPassword(password: string): string;
verifyPassword(hashedPassword: string, passwordToVerify: string): boolean;
verify(hashedPassword: string, passwordToVerify: string): boolean;
}
2 changes: 1 addition & 1 deletion src-ts/password-hashers/scrypt-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
6 changes: 3 additions & 3 deletions src-ts/symmetric/aes-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AESWrapper {
return aes256Key();
}

public aesNonce(): Array<number> {
public generateAESNonce(): Array<number> {
return aesNonce();
}

Expand All @@ -40,11 +40,11 @@ export class AESWrapper {
return aes256Decrypt(aesKey, nonce, ciphertext);
}

public aes256KeyFromX25519SharedSecret(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
return aes256KeyFromX25519SharedSecret(shared_secret);
}

public aes128KeyFromX25519SharedSecret(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
return aes128KeyFromX25519SharedSecret(shared_secret);
}
}
20 changes: 10 additions & 10 deletions test-ts/hasher.test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("SHA512 Tests", () => {
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const hashed = wrapper.hash_512(tohashBytes);
const hashed = wrapper.hash512(tohashBytes);
assert.notEqual(tohashBytes, hashed);
});

Expand All @@ -16,9 +16,9 @@ describe("SHA512 Tests", () => {
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const hashed = wrapper.hash_512(tohashBytes);
const hashed = wrapper.hash512(tohashBytes);
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
const verified = wrapper.verify_512(hashed, toVerifyBytes);
const verified = wrapper.verify512(hashed, toVerifyBytes);
assert.equal(true, verified);
});

Expand All @@ -27,10 +27,10 @@ describe("SHA512 Tests", () => {
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = 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<number> = Array.from(encoder.encode(toVerify));
const verified = wrapper.verify_512(hashed, toVerifyBytes);
const verified = wrapper.verify512(hashed, toVerifyBytes);
assert.equal(false, verified);
});
});
Expand All @@ -42,7 +42,7 @@ describe("SHA256 Tests", () => {
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const hashed = wrapper.hash_256(tohashBytes);
const hashed = wrapper.hash256(tohashBytes);
assert.notEqual(tohashBytes, hashed);
});

Expand All @@ -51,9 +51,9 @@ describe("SHA256 Tests", () => {
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const hashed = wrapper.hash_256(tohashBytes);
const hashed = wrapper.hash256(tohashBytes);
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
const verified = wrapper.verify_256(hashed, toVerifyBytes);
const verified = wrapper.verify256(hashed, toVerifyBytes);
assert.equal(true, verified);
});

Expand All @@ -62,10 +62,10 @@ describe("SHA256 Tests", () => {
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = 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<number> = Array.from(encoder.encode(toVerify));
const verified = wrapper.verify_256(hashed, toVerifyBytes);
const verified = wrapper.verify256(hashed, toVerifyBytes);
assert.equal(false, verified);
});
});
16 changes: 8 additions & 8 deletions test-ts/insecure-channel.test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test-ts/key-exchange-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
12 changes: 6 additions & 6 deletions test-ts/password-hasher-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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);
});

it("verify fail", () => {
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",
);
Expand All @@ -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);
});

Expand All @@ -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",
);
Expand All @@ -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);
});

Expand All @@ -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",
);
Expand Down
4 changes: 2 additions & 2 deletions test-ts/symmetric.test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> = Array.from(encoder.encode(tohashed));
Expand All @@ -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<number> = Array.from(encoder.encode(tohashed));
Expand Down

0 comments on commit 2186b42

Please sign in to comment.