diff --git a/index.d.ts b/index.d.ts index 7fafd15..aac6461 100644 --- a/index.d.ts +++ b/index.d.ts @@ -107,6 +107,10 @@ export declare function aesGcmSivNonce(): Array export declare function aesNonce(): Array +export declare function argon2DeriveAes128Key(password: Array): Array + +export declare function argon2DeriveAes256Key(password: Array): Array + export declare function argon2Hash(password: string): string export declare function argon2HashParams(memoryCost: number, iterations: number, parallelism: number, password: string): string diff --git a/index.js b/index.js index f71f1cd..e2acd9a 100644 --- a/index.js +++ b/index.js @@ -77,8 +77,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-android-arm64') const bindingPackageVersion = require('cas-typescript-sdk-android-arm64/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -93,8 +93,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-android-arm-eabi') const bindingPackageVersion = require('cas-typescript-sdk-android-arm-eabi/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -114,8 +114,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-win32-x64-gnu') const bindingPackageVersion = require('cas-typescript-sdk-win32-x64-gnu/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -130,8 +130,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-win32-x64-msvc') const bindingPackageVersion = require('cas-typescript-sdk-win32-x64-msvc/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -147,8 +147,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-win32-ia32-msvc') const bindingPackageVersion = require('cas-typescript-sdk-win32-ia32-msvc/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -163,8 +163,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-win32-arm64-msvc') const bindingPackageVersion = require('cas-typescript-sdk-win32-arm64-msvc/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -182,8 +182,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-darwin-universal') const bindingPackageVersion = require('cas-typescript-sdk-darwin-universal/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -198,8 +198,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-darwin-x64') const bindingPackageVersion = require('cas-typescript-sdk-darwin-x64/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -214,8 +214,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-darwin-arm64') const bindingPackageVersion = require('cas-typescript-sdk-darwin-arm64/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -234,8 +234,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-freebsd-x64') const bindingPackageVersion = require('cas-typescript-sdk-freebsd-x64/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -250,8 +250,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-freebsd-arm64') const bindingPackageVersion = require('cas-typescript-sdk-freebsd-arm64/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -271,8 +271,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-x64-musl') const bindingPackageVersion = require('cas-typescript-sdk-linux-x64-musl/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -287,8 +287,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-x64-gnu') const bindingPackageVersion = require('cas-typescript-sdk-linux-x64-gnu/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -305,8 +305,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-arm64-musl') const bindingPackageVersion = require('cas-typescript-sdk-linux-arm64-musl/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -321,8 +321,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-arm64-gnu') const bindingPackageVersion = require('cas-typescript-sdk-linux-arm64-gnu/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -339,8 +339,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-arm-musleabihf') const bindingPackageVersion = require('cas-typescript-sdk-linux-arm-musleabihf/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -355,8 +355,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-arm-gnueabihf') const bindingPackageVersion = require('cas-typescript-sdk-linux-arm-gnueabihf/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -373,8 +373,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-loong64-musl') const bindingPackageVersion = require('cas-typescript-sdk-linux-loong64-musl/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -389,8 +389,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-loong64-gnu') const bindingPackageVersion = require('cas-typescript-sdk-linux-loong64-gnu/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -407,8 +407,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-riscv64-musl') const bindingPackageVersion = require('cas-typescript-sdk-linux-riscv64-musl/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -423,8 +423,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-riscv64-gnu') const bindingPackageVersion = require('cas-typescript-sdk-linux-riscv64-gnu/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -440,8 +440,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-ppc64-gnu') const bindingPackageVersion = require('cas-typescript-sdk-linux-ppc64-gnu/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -456,8 +456,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-linux-s390x-gnu') const bindingPackageVersion = require('cas-typescript-sdk-linux-s390x-gnu/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -476,8 +476,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-openharmony-arm64') const bindingPackageVersion = require('cas-typescript-sdk-openharmony-arm64/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -492,8 +492,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-openharmony-x64') const bindingPackageVersion = require('cas-typescript-sdk-openharmony-x64/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -508,8 +508,8 @@ function requireNative() { try { const binding = require('cas-typescript-sdk-openharmony-arm') const bindingPackageVersion = require('cas-typescript-sdk-openharmony-arm/package.json').version - if (bindingPackageVersion !== '1.0.68' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 1.0.68 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + if (bindingPackageVersion !== '1.1.001' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 1.1.001 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } return binding } catch (e) { @@ -625,6 +625,8 @@ module.exports.aes256KeyFromVec = nativeBinding.aes256KeyFromVec module.exports.aes256KeyFromX25519SharedSecret = nativeBinding.aes256KeyFromX25519SharedSecret module.exports.aesGcmSivNonce = nativeBinding.aesGcmSivNonce module.exports.aesNonce = nativeBinding.aesNonce +module.exports.argon2DeriveAes128Key = nativeBinding.argon2DeriveAes128Key +module.exports.argon2DeriveAes256Key = nativeBinding.argon2DeriveAes256Key module.exports.argon2Hash = nativeBinding.argon2Hash module.exports.argon2HashParams = nativeBinding.argon2HashParams module.exports.argon2Verify = nativeBinding.argon2Verify diff --git a/package-lock.json b/package-lock.json index 5061ee1..73c3232 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cas-typescript-sdk", - "version": "1.1.000", + "version": "1.1.001", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cas-typescript-sdk", - "version": "1.1.000", + "version": "1.1.001", "license": "Apache 2.0", "dependencies": { "@napi-rs/cli": "3.7.2", diff --git a/package.json b/package.json index edcd57c..f6cdecf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cas-typescript-sdk", - "version": "1.1.000", + "version": "1.1.001", "description": "", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/src-ts/password-hashers/argon2-wrapper.ts b/src-ts/password-hashers/argon2-wrapper.ts index 461a935..8283664 100644 --- a/src-ts/password-hashers/argon2-wrapper.ts +++ b/src-ts/password-hashers/argon2-wrapper.ts @@ -1,5 +1,5 @@ -import { argon2Hash, argon2HashParams, argon2Verify} from "./../../index"; +import { argon2DeriveAes128Key, argon2DeriveAes256Key, argon2Hash, argon2HashParams, argon2Verify} from "./../../index"; import { IPasswordHasherBase } from "./password-hasher-base"; export class Argon2Wrapper implements IPasswordHasherBase { @@ -33,6 +33,36 @@ export class Argon2Wrapper implements IPasswordHasherBase { return argon2HashParams(memoryCost, timeCost, parallelism, password); } + /** + * Derives a 16 byte AES-128 key from a password with Argon2id. + * A random salt is generated internally and discarded, so the key cannot be + * re-derived from the password — each call produces a fresh one-time key. + * Use Pbkdf2Wrapper.deriveWithSalt if you need a re-derivable key. + * @param password + * @returns Array + */ + public deriveAes128Key(password: Array): Array { + if (!password || password.length === 0) { + throw new Error("You must provide a password to derive an AES-128 key with Argon2"); + } + return argon2DeriveAes128Key(password); + } + + /** + * Derives a 32 byte AES-256 key from a password with Argon2id. + * A random salt is generated internally and discarded, so the key cannot be + * re-derived from the password — each call produces a fresh one-time key. + * Use Pbkdf2Wrapper.deriveWithSalt if you need a re-derivable key. + * @param password + * @returns Array + */ + public deriveAes256Key(password: Array): Array { + if (!password || password.length === 0) { + throw new Error("You must provide a password to derive an AES-256 key with Argon2"); + } + return argon2DeriveAes256Key(password); + } + /** * Verifies that a password is the same as the hashed password with Argon2. * @param hashedPassword diff --git a/src-ts/password-hashers/password-hasher-factory.ts b/src-ts/password-hashers/password-hasher-factory.ts index c66cccb..69fdc29 100644 --- a/src-ts/password-hashers/password-hasher-factory.ts +++ b/src-ts/password-hashers/password-hasher-factory.ts @@ -1,5 +1,6 @@ import { Argon2Wrapper } from "./argon2-wrapper"; import { BCryptWrapper } from "./bcrypt-wrapper"; +import { IPasswordHasherBase } from "./password-hasher-base"; import { PasswordHasherType } from "./password-hasher-type"; import { ScryptWrapper } from "./scrypt-wrapper"; @@ -11,7 +12,7 @@ export class PasswordHasherFactory { */ static getHasher(type: PasswordHasherType): any { // Argon2 by default - let hasher = new Argon2Wrapper(); + let hasher: IPasswordHasherBase | null = null; switch (type) { case PasswordHasherType.Bcrypt: hasher = new BCryptWrapper(); @@ -19,7 +20,15 @@ export class PasswordHasherFactory { case PasswordHasherType.Scrypt: hasher = new ScryptWrapper(); break; + case PasswordHasherType.Argon2: + hasher = new Argon2Wrapper(); + break; + } + + if (!hasher) { + throw new Error(`Password hasher type ${type} is not supported.`); } + return hasher; } } diff --git a/src/password_hashers/argon2.rs b/src/password_hashers/argon2.rs index be36f97..0504f00 100644 --- a/src/password_hashers/argon2.rs +++ b/src/password_hashers/argon2.rs @@ -17,6 +17,16 @@ pub fn argon2_hash_params(memory_cost: u32, iterations: u32, parallelism: u32, p crate::map_cas_err(CASArgon::hash_password_parameters(memory_cost, iterations, parallelism, password)) } +#[napi] +pub fn argon2_derive_aes_128_key(password: Vec) -> napi::Result> { + crate::map_cas_err(CASArgon::derive_aes_128_key(password)) +} + +#[napi] +pub fn argon2_derive_aes_256_key(password: Vec) -> napi::Result> { + crate::map_cas_err(CASArgon::derive_aes_256_key(password)) +} + #[test] pub fn argon2_hash_params_test() { let password = "ThisIsNotMyPasswolrd".to_string(); @@ -39,6 +49,36 @@ pub fn argon2_verify_test() { assert_eq!(true, verified); } +#[test] +pub fn argon2_derive_aes_128_key_test() { + let password = b"ThisIsNotMyPasswolrd".to_vec(); + let key = argon2_derive_aes_128_key(password.clone()).unwrap(); + assert_eq!(key.len(), 16); + // A random salt is generated per call, so the same password must not repeat a key. + let second_key = argon2_derive_aes_128_key(password).unwrap(); + assert_ne!(key, second_key); +} + +#[test] +pub fn argon2_derive_aes_256_key_test() { + let password = b"ThisIsNotMyPasswolrd".to_vec(); + let key = argon2_derive_aes_256_key(password.clone()).unwrap(); + assert_eq!(key.len(), 32); + let second_key = argon2_derive_aes_256_key(password).unwrap(); + assert_ne!(key, second_key); +} + +#[test] +pub fn argon2_derive_aes_256_key_encrypt_decrypt_test() { + use crate::symmetric::aes::{aes256_decrypt, aes256_encrypt, aes_nonce}; + let key = argon2_derive_aes_256_key(b"ThisIsNotMyPasswolrd".to_vec()).unwrap(); + let nonce = aes_nonce(); + let plaintext = b"WelcomeHome".to_vec(); + let ciphertext = aes256_encrypt(key.clone(), nonce.clone(), plaintext.clone()).unwrap(); + let decrypted_plaintext = aes256_decrypt(key, nonce, ciphertext).unwrap(); + assert_eq!(decrypted_plaintext, plaintext) +} + #[test] pub fn argon2_verify_fail_test() { let password = "ThisIsNotMyPasswolrd".to_string(); diff --git a/tests/password-hasher.spec.ts b/tests/password-hasher.spec.ts index 24e8f21..c566e27 100644 --- a/tests/password-hasher.spec.ts +++ b/tests/password-hasher.spec.ts @@ -5,6 +5,7 @@ import { PasswordHasherFactory, PasswordHasherType, } from "../src-ts/password-hashers"; +import { AESWrapper } from "../src-ts/symmetric"; test.describe("Bcrypt Tests", () => { @@ -122,4 +123,35 @@ test.describe("Argon2 Tests", () => { const hashed: string = hasher.hashPasswordWithParameters(password, 1024, 3, 1); expect(hashed).not.toBe(password); }); + + test("derive aes 128 key", () => { + const hasher: Argon2Wrapper = new Argon2Wrapper(); + const password: number[] = Array.from(new TextEncoder().encode("Argon2Rocks")); + const key: number[] = hasher.deriveAes128Key(password); + expect(key.length).toBe(16); + // A random salt is generated per call, so the same password must not repeat a key. + const secondKey: number[] = hasher.deriveAes128Key(password); + expect(secondKey).not.toEqual(key); + }); + + test("derive aes 256 key", () => { + const hasher: Argon2Wrapper = new Argon2Wrapper(); + const password: number[] = Array.from(new TextEncoder().encode("Argon2Rocks")); + const key: number[] = hasher.deriveAes256Key(password); + expect(key.length).toBe(32); + const secondKey: number[] = hasher.deriveAes256Key(password); + expect(secondKey).not.toEqual(key); + }); + + test("derive aes 256 key encrypt and decrypt round trip", () => { + const hasher: Argon2Wrapper = new Argon2Wrapper(); + const aes: AESWrapper = new AESWrapper(); + const password: number[] = Array.from(new TextEncoder().encode("Argon2Rocks")); + const key: number[] = hasher.deriveAes256Key(password); + const nonce: number[] = aes.generateAESNonce(); + const plaintext: number[] = Array.from(new TextEncoder().encode("WelcomeHome")); + const ciphertext: number[] = aes.aes256Encrypt(key, nonce, plaintext); + const decrypted: number[] = aes.aes256Decrypt(key, nonce, ciphertext); + expect(decrypted).toEqual(plaintext); + }); }); \ No newline at end of file