Skip to content

Commit

Permalink
Merge pull request #16 from VirgilSecurity/v0.3.0-alpha.1
Browse files Browse the repository at this point in the history
v0.3.0-alpha.1
  • Loading branch information
vadimavdeev authored Sep 5, 2019
2 parents a8ff060 + 4a81e13 commit f7cbade
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "virgil-pythia",
"version": "0.3.0-alpha.0",
"version": "0.3.0-alpha.1",
"description": "Virgil Pythia SDK allows developers to implement Pythia protocol to create breach-proof passwords, immune to offline and online attacks.",
"main": "./dist/pythia.cjs.js",
"module": "./dist/pythia.es.js",
Expand Down
24 changes: 18 additions & 6 deletions src/BreachProofPassword.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { NodeBuffer } from './types';
import { NodeBuffer } from '@virgilsecurity/data-utils';

import { NodeBuffer as BufferType } from './types';

export class BreachProofPassword {
readonly salt: NodeBuffer;
readonly deblindedPassword: NodeBuffer;
readonly salt: BufferType;
readonly deblindedPassword: BufferType;
readonly version: number;

constructor(salt: NodeBuffer, deblindedPassword: NodeBuffer, version: number) {
this.salt = salt;
this.deblindedPassword = deblindedPassword;
constructor(salt: BufferType | string, deblindedPassword: BufferType | string, version: number) {
this.salt = BreachProofPassword.toNodeBuffer(salt);
this.deblindedPassword = BreachProofPassword.toNodeBuffer(deblindedPassword);
this.version = version;
}

Expand All @@ -18,4 +20,14 @@ export class BreachProofPassword {
version: this.version,
};
}

private static toNodeBuffer(value: BufferType | string) {
if (NodeBuffer.isBuffer(value)) {
return value;
}
if (typeof value === 'string') {
return NodeBuffer.from(value, 'base64');
}
throw new TypeError('`value` should be a Buffer or a string');
}
}

0 comments on commit f7cbade

Please sign in to comment.