cas-typescript-sdk 1.0.47 → 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.
Files changed (85) hide show
  1. package/index.d.ts +141 -0
  2. package/index.darwin-x64.node +0 -0
  3. package/index.linux-x64-gnu.node +0 -0
  4. package/index.linux-x64-musl.node +0 -0
  5. package/index.win32-x64-msvc.node +0 -0
  6. package/lib/asymmetric/index.d.ts +3 -0
  7. package/lib/asymmetric/index.js +5 -0
  8. package/lib/digital-signature/index.d.ts +6 -0
  9. package/lib/digital-signature/index.js +11 -0
  10. package/lib/hashers/index.d.ts +5 -0
  11. package/lib/hashers/index.js +11 -0
  12. package/lib/hybrid/index.d.ts +2 -0
  13. package/lib/hybrid/index.js +5 -0
  14. package/lib/index.d.ts +10 -0
  15. package/lib/key_exchange/index.d.ts +3 -0
  16. package/lib/key_exchange/index.js +5 -0
  17. package/lib/message/index.d.ts +2 -0
  18. package/lib/message/index.js +5 -0
  19. package/lib/password-hashers/index.d.ts +6 -0
  20. package/lib/password-hashers/index.js +13 -0
  21. package/lib/signature/index.d.ts +2 -0
  22. package/lib/signature/index.js +5 -0
  23. package/lib/sponges/index.d.ts +2 -0
  24. package/lib/sponges/index.js +5 -0
  25. package/lib/symmetric/index.d.ts +2 -0
  26. package/lib/symmetric/index.js +5 -0
  27. package/package.json +8 -1
  28. package/.github/workflows/main-pr-linux.yml +0 -28
  29. package/.github/workflows/main-pr-windows.yml +0 -28
  30. package/.github/workflows/main-publish.yml +0 -109
  31. package/Cargo.toml +0 -19
  32. package/build.rs +0 -5
  33. package/docs/EXAMPLES.md +0 -138
  34. package/src/asymmetric/cas_ed25519.rs +0 -35
  35. package/src/asymmetric/cas_rsa.rs +0 -32
  36. package/src/digital_signature/sha_256_rsa.rs +0 -40
  37. package/src/digital_signature/sha_512_rsa.rs +0 -40
  38. package/src/digital_signature/types.rs +0 -34
  39. package/src/hashers/blake2.rs +0 -60
  40. package/src/hashers/sha.rs +0 -68
  41. package/src/hybrid/hpke.rs +0 -63
  42. package/src/hybrid/types.rs +0 -15
  43. package/src/key_exchange/types.rs +0 -17
  44. package/src/key_exchange/x25519.rs +0 -25
  45. package/src/lib.rs +0 -47
  46. package/src/message/hmac.rs +0 -21
  47. package/src/password_hashers/argon2.rs +0 -37
  48. package/src/password_hashers/bcrypt.rs +0 -37
  49. package/src/password_hashers/scrypt.rs +0 -36
  50. package/src/sponges/ascon_aead.rs +0 -66
  51. package/src/symmetric/aes.rs +0 -71
  52. package/src-ts/asymmetric/RSAWrapper.ts +0 -59
  53. package/src-ts/digital-signature/digital-siganture-sha-512.ts +0 -40
  54. package/src-ts/digital-signature/digital-signature-base.ts +0 -6
  55. package/src-ts/digital-signature/digital-signature-factory.ts +0 -25
  56. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +0 -41
  57. package/src-ts/hashers/blake2-wrapper.ts +0 -43
  58. package/src-ts/hashers/hasher-base.ts +0 -6
  59. package/src-ts/hashers/hasher-factory.ts +0 -19
  60. package/src-ts/hashers/hasher-type.ts +0 -4
  61. package/src-ts/hashers/sha-wrapper.ts +0 -60
  62. package/src-ts/hybrid/hpke.ts +0 -44
  63. package/src-ts/key_exchange/x25519.ts +0 -23
  64. package/src-ts/message/hmac.ts +0 -26
  65. package/src-ts/password-hashers/argon2-wrapper.ts +0 -31
  66. package/src-ts/password-hashers/bcrypt-wrapper.ts +0 -35
  67. package/src-ts/password-hashers/password-hasher-base.ts +0 -4
  68. package/src-ts/password-hashers/password-hasher-factory.ts +0 -25
  69. package/src-ts/password-hashers/password-hasher-type.ts +0 -5
  70. package/src-ts/password-hashers/scrypt-wrapper.ts +0 -32
  71. package/src-ts/signature/ed25519-wrapper.ts +0 -36
  72. package/src-ts/sponges/ascon-wrapper.ts +0 -72
  73. package/src-ts/symmetric/aes-wrapper.ts +0 -101
  74. package/test-ts/asymmetric.test.spec.ts +0 -15
  75. package/test-ts/digital-signature.test.spec.ts +0 -70
  76. package/test-ts/hasher.test.spec.ts +0 -139
  77. package/test-ts/helpers/array.ts +0 -10
  78. package/test-ts/hmac.test.spec.ts +0 -16
  79. package/test-ts/hybrid.test.spec.ts +0 -23
  80. package/test-ts/insecure-channel.test.spec.ts +0 -55
  81. package/test-ts/key-exchange.test.spec.ts +0 -23
  82. package/test-ts/password-hasher.test.spec.ts +0 -104
  83. package/test-ts/sponges.test.spec.ts +0 -28
  84. package/test-ts/symmetric.test.spec.ts +0 -82
  85. package/tsconfig.json +0 -22
@@ -1,71 +0,0 @@
1
- use cas_lib::symmetric::{aes::{CASAES128, CASAES256}, cas_symmetric_encryption::{CASAES128Encryption, CASAES256Encryption}};
2
- use napi_derive::napi;
3
-
4
- #[napi]
5
- pub fn aes_nonce() -> Vec<u8> {
6
- return <CASAES256 as CASAES256Encryption>::generate_nonce().to_vec();
7
- }
8
-
9
- #[napi]
10
- pub fn aes128_key() -> Vec<u8> {
11
- return <CASAES128 as CASAES128Encryption>::generate_key().to_vec();
12
- }
13
-
14
- #[napi]
15
- pub fn aes256_key() -> Vec<u8> {
16
- return <CASAES256 as CASAES256Encryption>::generate_key().to_vec();
17
- }
18
-
19
- #[napi]
20
- pub fn aes128_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
21
- <CASAES128 as CASAES128Encryption>::encrypt_plaintext(aes_key, nonce, plaintext)
22
- }
23
-
24
- #[napi]
25
- pub fn aes128_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
26
- <CASAES128 as CASAES128Encryption>::decrypt_ciphertext(aes_key, nonce, ciphertext)
27
- }
28
-
29
- #[napi]
30
- pub fn aes256_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
31
- <CASAES256 as CASAES256Encryption>::encrypt_plaintext(aes_key, nonce, plaintext)
32
- }
33
-
34
- #[napi]
35
- pub fn aes256_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
36
- <CASAES256 as CASAES256Encryption>::decrypt_ciphertext(aes_key, nonce, ciphertext)
37
- }
38
-
39
- #[napi]
40
- pub fn aes_256_key_from_x25519_shared_secret(
41
- shared_secret: Vec<u8>,
42
- ) -> Vec<u8> {
43
- return <CASAES256 as CASAES256Encryption>::key_from_x25519_shared_secret(shared_secret).into();
44
- }
45
-
46
- #[napi]
47
- pub fn aes_128_key_from_x25519_shared_secret(
48
- shared_secret: Vec<u8>,
49
- ) -> Vec<u8> {
50
- return <CASAES128 as CASAES128Encryption>::key_from_x25519_shared_secret(shared_secret).into();
51
- }
52
-
53
- #[test]
54
- fn aes128_encrypt_decrypt_test() {
55
- let aes_key = aes128_key();
56
- let nonce = aes_nonce();
57
- let plaintext = b"WelcomeHome".to_vec();
58
- let ciphertext = aes128_encrypt(aes_key.clone(), nonce.clone(), plaintext.clone());
59
- let decrypted_plaintext = aes128_decrypt(aes_key, nonce, ciphertext);
60
- assert_eq!(decrypted_plaintext, plaintext)
61
- }
62
-
63
- #[test]
64
- fn aes256_encrypt_decrypt_test() {
65
- let aes_key = aes256_key();
66
- let nonce = aes_nonce();
67
- let plaintext = b"WelcomeHome".to_vec();
68
- let ciphertext = aes256_encrypt(aes_key.clone(), nonce.clone(), plaintext.clone());
69
- let decrypted_plaintext = aes256_decrypt(aes_key, nonce, ciphertext);
70
- assert_eq!(decrypted_plaintext, plaintext)
71
- }
@@ -1,59 +0,0 @@
1
- import { CASRSAKeyPairResult, generateRsaKeys, signRsa, verifyRsa } from "../../index";
2
-
3
- export class RSAWrapper {
4
-
5
- /**
6
- * Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
7
- * @param keySize
8
- * @returns CASRSAKeyPairResult
9
- */
10
- public generateKeys(keySize: number): CASRSAKeyPairResult {
11
- if (keySize !== 1024 && keySize !== 2048 && keySize !== 4096) {
12
- throw new Error("You must provide an appropriate key size to generate RSA keys");
13
- }
14
- return generateRsaKeys(keySize);
15
- }
16
-
17
- /**
18
- * Encrypts a plaintext byte array with a RSA public key
19
- * @param publicKey
20
- * @param plaintext
21
- * @returns Array<number>
22
- */
23
-
24
- /**
25
- * Signs a byte array with an RSA private key for verification.
26
- * @param privateKey
27
- * @param hash
28
- * @returns Array<number>
29
- */
30
- public sign(privateKey: string, dataToSign: Array<number>): Array<number> {
31
- if (!privateKey) {
32
- throw new Error("You must provide a private key to sign with RSA");
33
- }
34
- if (!dataToSign || dataToSign.length === 0) {
35
- throw new Error("You must provide an allocated hash to sign with RSA");
36
- }
37
- return signRsa(privateKey, dataToSign);
38
- }
39
-
40
- /**
41
- * Verifies signed data by the corresponding private key with an RSA public key.
42
- * @param publicKey
43
- * @param hash
44
- * @param signature
45
- * @returns boolean
46
- */
47
- public verify(publicKey: string, hash: Array<number>, signature: Array<number>): boolean {
48
- if (!publicKey) {
49
- throw new Error("You must provide a public key to verify with RSA");
50
- }
51
- if (!hash || hash.length === 0) {
52
- throw new Error("You must provide an allocated hash to verify with RSA");
53
- }
54
- if (!signature || signature.length === 0) {
55
- throw new Error("You must provide and allocated signature to verify with RSA");
56
- }
57
- return verifyRsa(publicKey, hash, signature);
58
- }
59
- }
@@ -1,40 +0,0 @@
1
- import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult, sha512RsaDigitalSignature, sha512RsaVerifyDigitalSignature } from "../../index";
2
- import { IDigitalSignature } from "./digital-signature-base";
3
-
4
- export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
5
- /**
6
- * Generates and RSA digital signature with SHA3-512
7
- * @param rsa_key_size
8
- * @param data_to_sign
9
- * @returns CASRSADigitalSignatureResult
10
- */
11
- createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult {
12
- if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
13
- throw new Error("You need to provide an appropriate RSA key size.");
14
- }
15
- if (data_to_sign?.length === 0) {
16
- throw new Error("Must provide allocated data to sign");
17
- }
18
- return sha512RsaDigitalSignature(rsa_key_size, data_to_sign);
19
- }
20
-
21
- /**
22
- * Verifies a digital signature created with the RSA public key.
23
- * @param public_key
24
- * @param data_to_verify
25
- * @param signature
26
- * @returns boolean
27
- */
28
- verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean {
29
- if (!public_key) {
30
- throw new Error("Must provide a public key");
31
- }
32
- if (data_to_verify?.length === 0) {
33
- throw new Error("Must provide an allocated data to verify");
34
- }
35
- if (signature?.length === 0) {
36
- throw new Error("Must provide an allocated signature");
37
- }
38
- return sha512RsaVerifyDigitalSignature(public_key, data_to_verify, signature);
39
- }
40
- }
@@ -1,6 +0,0 @@
1
- import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";
2
-
3
- export interface IDigitalSignature {
4
- createRsa(rsa_key_size: number, data_to_sign: Array<number>): CASRSADigitalSignatureResult;
5
- verifyRSa(public_key: string, data_to_verify: Array<number>, signature: Array<number>): boolean;
6
- }
@@ -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
- }