Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boilsquid/ch622/add typings files #15

Merged
merged 7 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ dist

# TernJS port file
.tern-port

# JetBrains
.idea/
20 changes: 20 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Config = require('./config');
const { Crypto, Http } = require('./core');

class EvervaultClient {

constructor(apikey) {
if (!Datatypes.isString(apikey)) {
throw new errors.InitializationError('Api key must be a string');
Expand All @@ -12,6 +13,12 @@ class EvervaultClient {
this.http = Http(this.config.http);
}

/**
*
* @param {Object || String} data
* @param {Object} options
* @returns {Promise<Object || String>}
*/
async encrypt(data, options) {
if (!Datatypes.isDefined(this._cageKey)) {
const cageKeyResponse = await this.http.getCageKey();
Expand All @@ -23,11 +30,24 @@ class EvervaultClient {
return await this.crypto.encrypt(this._cageKey, data, options || {});
}

/**
*
* @param {String} cageName
* @param {Object || String} payload
* @returns {Promise<*>}
*/
async run(cageName, payload) {
const response = await this.http.runCage(cageName, payload);
return response.body
}

/**
*
* @param {String} cageName
* @param {Object} data
* @param {Object} options
* @returns {Promise<*>}
*/
async encryptAndRun(cageName, data, options) {
const payload = await this.encrypt(data, options);
return await this.run(cageName, payload);
Expand Down