@adonisjs/hash
Advanced tools
| /// <reference path="../../adonis-typings/hash.d.ts" /> | ||
| import { FakeContract } from '@ioc:Adonis/Core/Hash'; | ||
| /** | ||
| * Generates and verifies hash using no algorigthm. | ||
| */ | ||
| export declare class Fake implements FakeContract { | ||
| ids: FakeContract['ids']; | ||
| params: { | ||
| [key: string]: string; | ||
| }; | ||
| /** | ||
| * Alias for [[this.make]] | ||
| */ | ||
| hash(value: string): Promise<string>; | ||
| /** | ||
| * Returns hash for a given value | ||
| */ | ||
| make(value: string): Promise<string>; | ||
| /** | ||
| * Verify hash to know if two values are same. | ||
| */ | ||
| verify(hashedValue: string, plainValue: string): Promise<boolean>; | ||
| /** | ||
| * Returns a boolean telling if hash needs a rehash. Returns true when | ||
| * one of the original params have been changed. | ||
| */ | ||
| needsReHash(_value: string): boolean; | ||
| } |
| "use strict"; | ||
| /* | ||
| * @adonisjs/hash | ||
| * | ||
| * (c) Harminder Virk <virk@adonisjs.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Fake = void 0; | ||
| /** | ||
| * Generates and verifies hash using no algorigthm. | ||
| */ | ||
| class Fake { | ||
| constructor() { | ||
| this.ids = ['fake']; | ||
| } | ||
| /** | ||
| * Alias for [[this.make]] | ||
| */ | ||
| hash(value) { | ||
| return Promise.resolve(value); | ||
| } | ||
| /** | ||
| * Returns hash for a given value | ||
| */ | ||
| make(value) { | ||
| return this.hash(value); | ||
| } | ||
| /** | ||
| * Verify hash to know if two values are same. | ||
| */ | ||
| verify(hashedValue, plainValue) { | ||
| return Promise.resolve(hashedValue === plainValue); | ||
| } | ||
| /** | ||
| * Returns a boolean telling if hash needs a rehash. Returns true when | ||
| * one of the original params have been changed. | ||
| */ | ||
| needsReHash(_value) { | ||
| return false; | ||
| } | ||
| } | ||
| exports.Fake = Fake; |
| /// <reference path="../../adonis-typings/hash.d.ts" /> | ||
| import { Manager } from '@poppinss/manager'; | ||
| import { HashConfig, HashersList, HashContract, HashDriverContract } from '@ioc:Adonis/Core/Hash'; | ||
| /** | ||
| * The Hash module exposes the API to hash values using an underlying | ||
| * Hash driver. | ||
| */ | ||
| export declare class Hash<Config extends HashConfig> extends Manager<HashDriverContract, HashDriverContract, { | ||
| [P in keyof HashersList]: HashersList[P]['implementation']; | ||
| }> implements HashContract { | ||
| config: Config; | ||
| private fakeDriver; | ||
| /** | ||
| * A boolean to know, if hash module is running in fake | ||
| * mode or not | ||
| */ | ||
| get isFaked(): boolean; | ||
| constructor(container: any, config: Config); | ||
| /** | ||
| * Initiate faking hash calls. All methods invoked on the main hash | ||
| * module and the underlying drivers will be faked using the | ||
| * fake driver. | ||
| * | ||
| * To restore the fake. Run the `Hash.restore` method. | ||
| */ | ||
| fake(): void; | ||
| /** | ||
| * Restore fake | ||
| */ | ||
| restore(): void; | ||
| /** | ||
| * Validate config | ||
| */ | ||
| private validateConfig; | ||
| protected $cacheMappings: boolean; | ||
| /** | ||
| * Pulling the default driver name from the user config. | ||
| */ | ||
| protected getDefaultMappingName(): string; | ||
| /** | ||
| * Returns the config for a mapping | ||
| */ | ||
| protected getMappingConfig(name: string): any; | ||
| /** | ||
| * Returns the driver name for a mapping | ||
| */ | ||
| protected getMappingDriver(name: string): string | undefined; | ||
| /** | ||
| * Creating bcrypt driver. The manager will call this method anytime | ||
| * someone will ask for the `bcrypt` driver. | ||
| */ | ||
| protected createBcrypt(_: string, config: any): any; | ||
| /** | ||
| * Creating argon driver. The manager will call this method anytime | ||
| * someone will ask for the `argon` driver. | ||
| */ | ||
| protected createArgon2(_: string, config: any): any; | ||
| /** | ||
| * Creating fake driver. The manager will call this method anytime | ||
| * someone will ask for the `fake` driver. | ||
| */ | ||
| protected createFake(): any; | ||
| /** | ||
| * Alias for [[this.make]] | ||
| */ | ||
| hash(value: string): never | any; | ||
| /** | ||
| * Hash value using the default driver | ||
| */ | ||
| make(value: string): Promise<string>; | ||
| /** | ||
| * Verify value using the default driver | ||
| */ | ||
| verify(hashedValue: string, plainValue: string): Promise<boolean>; | ||
| /** | ||
| * Find if value needs to be re-hashed as per the default driver. | ||
| */ | ||
| needsReHash(hashedValue: string): boolean; | ||
| /** | ||
| * Pull pre-configured driver instance | ||
| */ | ||
| use(name?: string): HashDriverContract; | ||
| } |
| "use strict"; | ||
| /* | ||
| * @adonisjs/hash | ||
| * | ||
| * (c) Harminder Virk <virk@adonisjs.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Hash = void 0; | ||
| /// <reference path="../../adonis-typings/hash.ts" /> | ||
| const manager_1 = require("@poppinss/manager"); | ||
| const utils_1 = require("@poppinss/utils"); | ||
| /** | ||
| * The Hash module exposes the API to hash values using an underlying | ||
| * Hash driver. | ||
| */ | ||
| class Hash extends manager_1.Manager { | ||
| constructor(container, config) { | ||
| super(container); | ||
| this.config = config; | ||
| this.$cacheMappings = true; | ||
| this.validateConfig(); | ||
| } | ||
| /** | ||
| * A boolean to know, if hash module is running in fake | ||
| * mode or not | ||
| */ | ||
| get isFaked() { | ||
| return !!this.fakeDriver; | ||
| } | ||
| /** | ||
| * Initiate faking hash calls. All methods invoked on the main hash | ||
| * module and the underlying drivers will be faked using the | ||
| * fake driver. | ||
| * | ||
| * To restore the fake. Run the `Hash.restore` method. | ||
| */ | ||
| fake() { | ||
| this.fakeDriver = this.fakeDriver || this.createFake(); | ||
| } | ||
| /** | ||
| * Restore fake | ||
| */ | ||
| restore() { | ||
| this.fakeDriver = undefined; | ||
| } | ||
| /** | ||
| * Validate config | ||
| */ | ||
| validateConfig() { | ||
| const validator = new utils_1.ManagerConfigValidator(this.config, 'hash', 'config/hash'); | ||
| validator.validateDefault('default'); | ||
| validator.validateList('list', 'default'); | ||
| } | ||
| /** | ||
| * Pulling the default driver name from the user config. | ||
| */ | ||
| getDefaultMappingName() { | ||
| return this.config.default; | ||
| } | ||
| /** | ||
| * Returns the config for a mapping | ||
| */ | ||
| getMappingConfig(name) { | ||
| return this.config.list[name]; | ||
| } | ||
| /** | ||
| * Returns the driver name for a mapping | ||
| */ | ||
| getMappingDriver(name) { | ||
| const config = this.getMappingConfig(name); | ||
| return config ? config.driver : undefined; | ||
| } | ||
| /** | ||
| * Creating bcrypt driver. The manager will call this method anytime | ||
| * someone will ask for the `bcrypt` driver. | ||
| */ | ||
| createBcrypt(_, config) { | ||
| const { Bcrypt } = require('../Drivers/Bcrypt'); | ||
| return new Bcrypt(config); | ||
| } | ||
| /** | ||
| * Creating argon driver. The manager will call this method anytime | ||
| * someone will ask for the `argon` driver. | ||
| */ | ||
| createArgon2(_, config) { | ||
| const { Argon } = require('../Drivers/Argon'); | ||
| return new Argon(config); | ||
| } | ||
| /** | ||
| * Creating fake driver. The manager will call this method anytime | ||
| * someone will ask for the `fake` driver. | ||
| */ | ||
| createFake() { | ||
| const { Fake } = require('../Drivers/Fake'); | ||
| return new Fake(); | ||
| } | ||
| /** | ||
| * Alias for [[this.make]] | ||
| */ | ||
| hash(value) { | ||
| if (this.fakeDriver) { | ||
| return this.fakeDriver.hash(value); | ||
| } | ||
| return this.use().hash(value); | ||
| } | ||
| /** | ||
| * Hash value using the default driver | ||
| */ | ||
| make(value) { | ||
| if (this.fakeDriver) { | ||
| return this.fakeDriver.make(value); | ||
| } | ||
| return this.use().make(value); | ||
| } | ||
| /** | ||
| * Verify value using the default driver | ||
| */ | ||
| verify(hashedValue, plainValue) { | ||
| if (this.fakeDriver) { | ||
| return this.fakeDriver.verify(hashedValue, plainValue); | ||
| } | ||
| return this.use().verify(hashedValue, plainValue); | ||
| } | ||
| /** | ||
| * Find if value needs to be re-hashed as per the default driver. | ||
| */ | ||
| needsReHash(hashedValue) { | ||
| if (this.fakeDriver) { | ||
| return this.fakeDriver.needsReHash(hashedValue); | ||
| } | ||
| return this.use().needsReHash(hashedValue); | ||
| } | ||
| /** | ||
| * Pull pre-configured driver instance | ||
| */ | ||
| use(name) { | ||
| if (this.fakeDriver) { | ||
| return this.fakeDriver; | ||
| } | ||
| return super.use(name); | ||
| } | ||
| } | ||
| exports.Hash = Hash; |
@@ -66,2 +66,5 @@ declare module '@ioc:Adonis/Core/Hash' { | ||
| } | ||
| export interface FakeContract extends HashDriverContract { | ||
| ids: ['fake']; | ||
| } | ||
| /** | ||
@@ -83,2 +86,5 @@ * Default list of available drivers. One can you reference this type | ||
| }; | ||
| fake: { | ||
| implementation: FakeContract; | ||
| }; | ||
| }; | ||
@@ -108,2 +114,3 @@ /** | ||
| }> { | ||
| readonly isFaked: boolean; | ||
| /** | ||
@@ -115,2 +122,7 @@ * Hash plain text value using the default mapping | ||
| /** | ||
| * Fake/restore hash implementations | ||
| */ | ||
| fake(): void; | ||
| restore(): void; | ||
| /** | ||
| * Verify plain value against the hashed value to find if it's | ||
@@ -117,0 +129,0 @@ * valid or not |
@@ -14,2 +14,3 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Argon = void 0; | ||
| /// <reference path="../../adonis-typings/hash.ts" /> | ||
@@ -16,0 +17,0 @@ const format_1 = __importDefault(require("@phc/format")); |
@@ -14,2 +14,3 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Bcrypt = void 0; | ||
| /// <reference path="../../adonis-typings/hash.ts" /> | ||
@@ -16,0 +17,0 @@ const format_1 = __importDefault(require("@phc/format")); |
@@ -12,2 +12,2 @@ "use strict"; | ||
| var Hash_1 = require("./src/Hash"); | ||
| exports.Hash = Hash_1.Hash; | ||
| Object.defineProperty(exports, "Hash", { enumerable: true, get: function () { return Hash_1.Hash; } }); |
+5
-5
| { | ||
| "name": "@adonisjs/hash", | ||
| "version": "3.0.0", | ||
| "version": "3.1.0", | ||
| "description": "Multi driver hash module with support for PHC string formats", | ||
@@ -43,3 +43,3 @@ "main": "build/providers/HashProvider", | ||
| "@adonisjs/mrm-preset": "^2.3.0", | ||
| "@types/node": "^13.13.5", | ||
| "@types/node": "^14.0.1", | ||
| "argon2": "^0.26.2", | ||
@@ -52,3 +52,3 @@ "bcrypt": "^4.0.1", | ||
| "eslint": "^7.0.0", | ||
| "eslint-plugin-adonis": "^1.0.9", | ||
| "eslint-plugin-adonis": "^1.0.10", | ||
| "husky": "^4.2.5", | ||
@@ -61,3 +61,3 @@ "japa": "^3.0.1", | ||
| "ts-node": "^8.10.1", | ||
| "typescript": "^3.8.3" | ||
| "typescript": "^3.9.2" | ||
| }, | ||
@@ -89,3 +89,3 @@ "nyc": { | ||
| "@phc/format": "^0.5.0", | ||
| "@poppinss/manager": "^2.1.7", | ||
| "@poppinss/manager": "^2.1.8", | ||
| "@poppinss/utils": "^2.2.6" | ||
@@ -92,0 +92,0 @@ }, |
| /// <reference path="../adonis-typings/hash.d.ts" /> | ||
| import { Manager } from '@poppinss/manager'; | ||
| import { HashConfig, HashersList, HashContract, HashDriverContract } from '@ioc:Adonis/Core/Hash'; | ||
| /** | ||
| * The Hash module exposes the API to hash values using an underlying | ||
| * Hash driver. | ||
| */ | ||
| export declare class Hash<Config extends HashConfig> extends Manager<HashDriverContract, HashDriverContract, { | ||
| [P in keyof HashersList]: HashersList[P]['implementation']; | ||
| }> implements HashContract { | ||
| config: Config; | ||
| constructor(container: any, config: Config); | ||
| /** | ||
| * Validate config | ||
| */ | ||
| private validateConfig; | ||
| protected $cacheMappings: boolean; | ||
| /** | ||
| * Pulling the default driver name from the user config. | ||
| */ | ||
| protected getDefaultMappingName(): string; | ||
| /** | ||
| * Returns the config for a mapping | ||
| */ | ||
| protected getMappingConfig(name: string): any; | ||
| /** | ||
| * Returns the driver name for a mapping | ||
| */ | ||
| protected getMappingDriver(name: string): string | undefined; | ||
| /** | ||
| * Creating bcrypt driver. The manager will call this method anytime | ||
| * someone will ask for the `bcrypt` driver. | ||
| */ | ||
| protected createBcrypt(_: string, config: any): any; | ||
| /** | ||
| * Creating argon driver. The manager will call this method anytime | ||
| * someone will ask for the `argon` driver. | ||
| */ | ||
| protected createArgon2(_: string, config: any): any; | ||
| /** | ||
| * Alias for [[this.make]] | ||
| */ | ||
| hash(value: string): never | any; | ||
| /** | ||
| * Hash value using the default driver | ||
| */ | ||
| make(value: string): Promise<string>; | ||
| /** | ||
| * Verify value using the default driver | ||
| */ | ||
| verify(hashedValue: string, plainValue: string): Promise<boolean>; | ||
| /** | ||
| * Find if value needs to be re-hashed as per the default driver. | ||
| */ | ||
| needsReHash(hashedValue: string): boolean; | ||
| } |
| "use strict"; | ||
| /* | ||
| * @adonisjs/hash | ||
| * | ||
| * (c) Harminder Virk <virk@adonisjs.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| /// <reference path="../adonis-typings/hash.ts" /> | ||
| const manager_1 = require("@poppinss/manager"); | ||
| const utils_1 = require("@poppinss/utils"); | ||
| /** | ||
| * The Hash module exposes the API to hash values using an underlying | ||
| * Hash driver. | ||
| */ | ||
| class Hash extends manager_1.Manager { | ||
| constructor(container, config) { | ||
| super(container); | ||
| this.config = config; | ||
| this.$cacheMappings = true; | ||
| this.validateConfig(); | ||
| } | ||
| /** | ||
| * Validate config | ||
| */ | ||
| validateConfig() { | ||
| const validator = new utils_1.ManagerConfigValidator(this.config, 'hash', 'config/hash'); | ||
| validator.validateDefault('default'); | ||
| validator.validateList('list', 'default'); | ||
| } | ||
| /** | ||
| * Pulling the default driver name from the user config. | ||
| */ | ||
| getDefaultMappingName() { | ||
| return this.config.default; | ||
| } | ||
| /** | ||
| * Returns the config for a mapping | ||
| */ | ||
| getMappingConfig(name) { | ||
| return this.config.list[name]; | ||
| } | ||
| /** | ||
| * Returns the driver name for a mapping | ||
| */ | ||
| getMappingDriver(name) { | ||
| const config = this.getMappingConfig(name); | ||
| return config ? config.driver : undefined; | ||
| } | ||
| /** | ||
| * Creating bcrypt driver. The manager will call this method anytime | ||
| * someone will ask for the `bcrypt` driver. | ||
| */ | ||
| createBcrypt(_, config) { | ||
| const { Bcrypt } = require('./Drivers/Bcrypt'); | ||
| return new Bcrypt(config); | ||
| } | ||
| /** | ||
| * Creating argon driver. The manager will call this method anytime | ||
| * someone will ask for the `argon` driver. | ||
| */ | ||
| createArgon2(_, config) { | ||
| const { Argon } = require('./Drivers/Argon'); | ||
| return new Argon(config); | ||
| } | ||
| /** | ||
| * Alias for [[this.make]] | ||
| */ | ||
| hash(value) { | ||
| return this.use().hash(value); | ||
| } | ||
| /** | ||
| * Hash value using the default driver | ||
| */ | ||
| make(value) { | ||
| return this.use().make(value); | ||
| } | ||
| /** | ||
| * Verify value using the default driver | ||
| */ | ||
| verify(hashedValue, plainValue) { | ||
| return this.use().verify(hashedValue, plainValue); | ||
| } | ||
| /** | ||
| * Find if value needs to be re-hashed as per the default driver. | ||
| */ | ||
| needsReHash(hashedValue) { | ||
| return this.use().needsReHash(hashedValue); | ||
| } | ||
| } | ||
| exports.Hash = Hash; |
27836
19%17
13.33%737
29.3%Updated