Skip to content

Commit

Permalink
Merge pull request #24 from VirgilSecurity/v0.3.2
Browse files Browse the repository at this point in the history
v0.3.2
  • Loading branch information
vadimavdeev authored Oct 10, 2019
2 parents 24e6366 + 8717f99 commit b2dba75
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can install this module from npm. Another option is to add it via `script` t
### npm
You will need to install `@virgilsecurity/keyknox`.
```sh
npm install @virgilsecurity/keyknox@0.3.1
npm install @virgilsecurity/keyknox@0.3.2
```

You will also need to install `virgil-crypto` and `virgil-sdk` from npm.
Expand All @@ -36,7 +36,7 @@ npm install virgil-crypto@4.0.0-alpha.13 virgil-sdk@6.0.0-alpha.4
### In browser via `script` tag
You will need to add `@virgilsecurity/keyknox` script.
```html
<script src="https://unpkg.com/@virgilsecurity/keyknox@0.3.1/dist/keyknox.umd.js"></script>
<script src="https://unpkg.com/@virgilsecurity/keyknox@0.3.2/dist/keyknox.umd.js"></script>
```

You will also need to add `virgil-crypto` and `virgil-sdk` scripts.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virgilsecurity/keyknox",
"version": "0.3.1",
"version": "0.3.2",
"description": "Keyknox SDK allows developers to communicate with Virgil Keyknox Service to upload, download, and synchronize encrypted sensitive data (private keys) between different devices.",
"main": "./dist/keyknox.cjs.js",
"module": "./dist/keyknox.es.js",
Expand Down Expand Up @@ -42,8 +42,8 @@
"rimraf": "^2.6.3",
"rollup": "^1.14.6",
"rollup-plugin-commonjs": "^10.0.2",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-typescript2": "^0.21.1",
"ts-node": "^8.3.0",
Expand Down
10 changes: 7 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require('path');

const commonjs = require('rollup-plugin-commonjs');
const json = require('rollup-plugin-json');
const nodeResolve = require('rollup-plugin-node-resolve');
const replace = require('rollup-plugin-replace');
const { terser } = require('rollup-plugin-terser');
const typescript = require('rollup-plugin-typescript2');

Expand All @@ -11,6 +11,8 @@ const packageJson = require('./package.json');
const dependencies = Object.keys(packageJson.dependencies);
const peerDependencies = Object.keys(packageJson.peerDependencies);

const PRODUCT_NAME = 'keyknox';

const FORMAT = {
CJS: 'cjs',
ES: 'es',
Expand All @@ -28,12 +30,14 @@ const createEntry = format => ({
file: path.join(outputPath, `keyknox.${format}.js`),
name: 'Keyknox',
globals: {
'virgil-crypto': 'VirgilCrypto',
'virgil-sdk': 'Virgil',
},
},
plugins: [
json({ compact: true }),
replace({
'process.env.PRODUCT_NAME': JSON.stringify(PRODUCT_NAME),
'process.env.PRODUCT_VERSION': JSON.stringify(packageJson.version),
}),
format === FORMAT.UMD && nodeResolve({ browser: true, preferBuiltins: false }),
format === FORMAT.UMD && commonjs(),
typescript({
Expand Down
5 changes: 5 additions & 0 deletions setup-mocha.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const dotenv = require('dotenv');
const { join } = require('path');

const { version } = require('./package.json');

dotenv.config();

process.env.KEY_ENTRIES_FOLDER = join(__dirname, '.virgil_key_entries');
process.env.PRODUCT_NAME = 'keyknox';
process.env.PRODUCT_VERSION = version;
2 changes: 1 addition & 1 deletion src/CloudKeyStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class CloudKeyStorage {

private decryptedKeyknoxValue?: DecryptedKeyknoxValue;
private cache: Map<string, CloudEntry> = new Map();
private syncWasCalled: boolean = false;
private syncWasCalled = false;

constructor(keyknoxManager: KeyknoxManager) {
this.keyknoxManager = keyknoxManager;
Expand Down
17 changes: 10 additions & 7 deletions src/KeyknoxManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { DecryptedKeyknoxValue } from './entities';
import { IPrivateKey, IPublicKey, IAccessTokenProvider } from './types';

export default class KeyknoxManager {
private readonly SERVICE_NAME = 'keyknox';

private readonly accessTokenProvider: IAccessTokenProvider;

private myPrivateKey: IPrivateKey;
Expand Down Expand Up @@ -39,7 +37,8 @@ export default class KeyknoxManager {

async pushValue(value: string, previousHash?: string): Promise<DecryptedKeyknoxValue> {
const token = await this.accessTokenProvider.getToken({
service: this.SERVICE_NAME,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
service: process.env.PRODUCT_NAME!,
operation: 'put',
});
const { metadata, encryptedData } = this.keyknoxCrypto.encrypt(
Expand All @@ -58,7 +57,8 @@ export default class KeyknoxManager {

async pullValue(): Promise<DecryptedKeyknoxValue> {
const token = await this.accessTokenProvider.getToken({
service: this.SERVICE_NAME,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
service: process.env.PRODUCT_NAME!,
operation: 'get',
});
const encryptedKeyknoxValue = await this.keyknoxClient.pullValue(token.toString());
Expand All @@ -67,7 +67,8 @@ export default class KeyknoxManager {

async resetValue(): Promise<DecryptedKeyknoxValue> {
const token = await this.accessTokenProvider.getToken({
service: this.SERVICE_NAME,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
service: process.env.PRODUCT_NAME!,
operation: 'delete',
});
return this.keyknoxClient.resetValue(token.toString());
Expand Down Expand Up @@ -96,7 +97,8 @@ export default class KeyknoxManager {
this.myPublicKeys,
);
const token = await this.accessTokenProvider.getToken({
service: this.SERVICE_NAME,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
service: process.env.PRODUCT_NAME!,
operation: 'put',
});
const encryptedKeyknoxValue = await this.keyknoxClient.pushValue(
Expand Down Expand Up @@ -129,7 +131,8 @@ export default class KeyknoxManager {
this.myPublicKeys,
);
const token = await this.accessTokenProvider.getToken({
service: this.SERVICE_NAME,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
service: process.env.PRODUCT_NAME!,
operation: 'put',
});
const encryptedKeyknoxValue = await this.keyknoxClient.pushValue(
Expand Down
6 changes: 3 additions & 3 deletions src/clients/KeyknoxClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios, { AxiosResponse } from 'axios';
import { VirgilAgent } from 'virgil-sdk';

import { version } from '../../package.json';
import { EncryptedKeyknoxValue, DecryptedKeyknoxValue, KeyknoxValue } from '../entities';
import { KeyknoxClientError } from '../errors';
import { AxiosInstance, AxiosError, AxiosRequestConfig } from '../types';
Expand All @@ -15,14 +14,15 @@ interface KeyknoxData {

export default class KeyknoxClient implements IKeyknoxClient {
private static readonly API_URL = 'https://api.virgilsecurity.com';
private static readonly PRODUCT_NAME = 'keyknox';

private readonly axios: AxiosInstance;
private readonly virgilAgent: VirgilAgent;

constructor(apiUrl?: string, axiosInstance?: AxiosInstance, virgilAgent?: VirgilAgent) {
this.axios = axiosInstance || axios.create({ baseURL: apiUrl || KeyknoxClient.API_URL });
this.virgilAgent = virgilAgent || new VirgilAgent(KeyknoxClient.PRODUCT_NAME, version);
this.virgilAgent =
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
virgilAgent || new VirgilAgent(process.env.PRODUCT_NAME!, process.env.PRODUCT_VERSION!);
this.axios.interceptors.response.use(undefined, KeyknoxClient.responseErrorHandler);
}

Expand Down

0 comments on commit b2dba75

Please sign in to comment.