Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
snanovskyi committed Aug 30, 2019
1 parent cc25506 commit 56dc18b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ In order to create a user's BrainKey, go through the following operations:
Promise.all([VirgilCrypto.initCrypto(), VirgilPythiaCrypto.initPythia()])
.then(() => {
const virgilCrypto = new VirgilCrypto.VirgilCrypto();
const virgilPythiaCrypto = new VirgilPythiaCrypto.VirgilPythiaCrypto();
const virgilBrainKeyCrypto = new VirgilPythiaCrypto.VirgilBrainKeyCrypto();
const accessTokenProvider = new Virgil.CachingJwtProvider(fetchJwt);
const brainKey = VirgilPythia.createBrainKey({
virgilCrypto,
virgilPythiaCrypto,
virgilBrainKeyCrypto,
accessTokenProvider,
});
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/createBrainKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('createBrainKey', () => {

it('returns an instance of `BrainKey`', () => {
const virgilCrypto = new VirgilCrypto();
const virgilPythiaCrypto = new VirgilBrainKeyCrypto();
const virgilBrainKeyCrypto = new VirgilBrainKeyCrypto();
const jwtGenerator = new JwtGenerator({
apiKey: virgilCrypto.importPrivateKey({
value: process.env.VIRGIL_API_KEY!,
Expand All @@ -27,7 +27,7 @@ describe('createBrainKey', () => {
const accessTokenProvider = new GeneratorJwtProvider(jwtGenerator, undefined, uuid());
const brainKey = createBrainKey({
virgilCrypto,
virgilPythiaCrypto,
virgilBrainKeyCrypto,
accessTokenProvider,
apiUrl: process.env.VIRGIL_API_URL!,
});
Expand Down
10 changes: 7 additions & 3 deletions src/createBrainKey.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { BrainKey } from './BrainKey';
import { PythiaClient } from './PythiaClient';
import { ICrypto, IBrainKeyCrypto, IAccessTokenProvider } from './types';
import { ICrypto, IBrainKeyCrypto, IPythiaCrypto, IAccessTokenProvider } from './types';

export const createBrainKey = (options: {
virgilCrypto: ICrypto;
virgilPythiaCrypto: IBrainKeyCrypto;
virgilBrainKeyCrypto: IBrainKeyCrypto;
accessTokenProvider: IAccessTokenProvider;
virgilPythiaCrypto?: IPythiaCrypto;
keyPairType?: unknown;
apiUrl?: string;
}) => {
const pythiaClient = new PythiaClient(options.accessTokenProvider, options.apiUrl);
if (options.virgilPythiaCrypto && console) {
console.warn('Option `virgilPythiaCrypto` is deprecated. Use `virgilBrainKeyCrypto` instead.');
}
return new BrainKey({
pythiaClient,
crypto: options.virgilCrypto,
brainKeyCrypto: options.virgilPythiaCrypto,
brainKeyCrypto: options.virgilBrainKeyCrypto || options.virgilPythiaCrypto,
keyPairType: options.keyPairType,
});
};

0 comments on commit 56dc18b

Please sign in to comment.