Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@evervault/sdk

Package Overview
Dependencies
Maintainers
5
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@evervault/sdk - npm Package Compare versions

Comparing version 3.14.0 to 3.14.1

8

lib/config.js

@@ -12,7 +12,11 @@ const { version } = require('../package.json');

module.exports = () => ({
module.exports = (apikey) => ({
http: {
baseUrl: process.env.EV_API_URL || DEFAULT_API_URL,
functionRunUrl: process.env.EV_CAGE_RUN_URL || DEFAULT_FUNCTION_RUN_URL,
userAgent: `evervault-node/${version}`,
headers: {
'API-KEY': apikey,
'user-agent': `evervault-node/${version}`,
},
responseType: 'json',
tunnelHostname: process.env.EV_TUNNEL_HOSTNAME || DEFAULT_TUNNEL_HOSTNAME,

@@ -19,0 +23,0 @@ certHostname: process.env.EV_CERT_HOSTNAME || DEFAULT_CA_HOSTNAME,

@@ -1,44 +0,18 @@

const { errors, Datatypes } = require('../utils');
const { errors } = require('../utils');
const phin = require('phin');
module.exports = (appUuid, apiKey, config) => {
const request = (
method,
path,
additionalHeaders = {},
data = undefined,
basicAuth = false,
parse = 'json'
) => {
const headers = {
'user-agent': config.userAgent,
...additionalHeaders,
};
if (basicAuth) {
headers['authorization'] = `Basic ${Buffer.from(
`${appUuid}:${apiKey}`
).toString('base64')}`;
} else {
headers['api-key'] = apiKey;
}
module.exports = (config) => {
const request = (method, path, headers = {}, data = undefined) => {
return phin({
url: path.startsWith('https://') ? path : `${config.baseUrl}/${path}`,
method,
headers,
headers: { ...config.headers, ...headers },
data,
parse,
parse: config.responseType,
});
};
const get = (path, headers) => request('GET', path, headers);
const post = (path, data, headers = { 'Content-Type': 'application/json' }) =>
request('POST', path, headers, data);
const post = (
path,
data,
headers = { 'Content-Type': 'application/json' },
basicAuth = false,
parse = 'json'
) => request('POST', path, headers, data, basicAuth, parse);
const getCageKey = async () => {

@@ -158,33 +132,2 @@ const getCagesKeyCallback = async () => {

const decrypt = async (encryptedData) => {
let contentType;
let data;
if (Buffer.isBuffer(encryptedData)) {
contentType = 'application/octet-stream';
data = encryptedData;
} else {
contentType = 'application/json';
data = {
data: encryptedData,
};
}
const response = await post(
`${config.baseUrl}/decrypt`,
data,
{
'Content-Type': contentType,
},
true,
'none'
);
if (response.statusCode >= 200 && response.statusCode < 300) {
if (contentType === 'application/json') {
const { data } = JSON.parse(response.body);
return data;
}
return response.body;
}
throw errors.mapApiResponseToError(response);
};
async function makeGetRequestWithRetry(

@@ -220,4 +163,3 @@ requestCallback,

getRelayOutboundConfig,
decrypt,
};
};
declare module "@evervault/sdk" {
export default class Evervault {
constructor(appId: string, apiKey: string)
constructor(apiKey: string)
encrypt: (data: any) => Promise<any>;
decrypt: (encryptedData: any) => Promise<any>;
run: <T>(functionName: string, data: object, options?: { async?: boolean, version?: string }) => Promise<{ result: T, runId: string, appUuid: string }>;

@@ -7,0 +6,0 @@ createRunToken: (functionName: string, data: object) => Promise<{ token: string }>;

@@ -26,15 +26,7 @@ const crypto = require('crypto');

constructor(appId, apiKey, options = {}) {
if (
appId === '' ||
!Datatypes.isString(appId) ||
!appId.startsWith('app_')
) {
throw new errors.InitializationError(
'The provided App ID is invalid. The App ID can be retrieved in the Evervault dashboard (App Settings).'
);
constructor(apiKey, options = {}) {
if (!Datatypes.isString(apiKey)) {
throw new errors.InitializationError('API key must be a string');
}
validationHelper.validateApiKey(appId, apiKey);
if (apiKey.startsWith('pk:')) {

@@ -58,7 +50,6 @@ this.defineHiddenProperty(

this.retry = options.retry;
this.http = Http(appId, apiKey, this.config.http);
this.http = Http(this.config.http);
this.crypto = Crypto(this.config.encryption[curve], this.http);
this.httpsHelper = httpsHelper;
this.apiKey = apiKey;
this.appId = appId;

@@ -290,11 +281,2 @@ this.defineHiddenProperty(

/**
*
* @param {any} encryptedData
* @returns {Promise<any>}
*/
async decrypt(encryptedData) {
return this.http.decrypt(encryptedData);
}
/**
* @param {String} functionName

@@ -301,0 +283,0 @@ * @param {Object} payload

@@ -46,7 +46,2 @@ class EvervaultError extends Error {

}
if (statusCode === 403) {
return new ApiKeyError(
'The API key provided does not have the required permissions.'
);
}
if (statusCode === 422) {

@@ -53,0 +48,0 @@ return new DecryptError(body.message || 'Unable to decrypt data.');

@@ -1,27 +0,4 @@

const crypto = require('crypto');
const errors = require('./errors');
const Datatypes = require('./datatypes');
const validateApiKey = (appUuid, apiKey) => {
if (apiKey === '' || !Datatypes.isString(apiKey)) {
throw new errors.InitializationError(
'The API key must be a string and cannot be empty.'
);
}
if (apiKey.startsWith('ev:key')) {
// Scoped API key
const appUuidHash = crypto
.createHash('sha512')
.update(appUuid)
.digest('base64')
.slice(0, 6);
const appUuidHashFromApiKey = apiKey.split(':')[4];
if (appUuidHash !== appUuidHashFromApiKey) {
throw new errors.InitializationError(
`The API key is not valid for app ${appUuid}. Make sure to use an API key belonging to the app ${appUuid}.`
);
}
}
};
const validatePayload = (payload) => {

@@ -66,3 +43,2 @@ if (

module.exports = {
validateApiKey,
validatePayload,

@@ -69,0 +45,0 @@ validateFunctionName,

{
"name": "@evervault/sdk",
"version": "3.14.0",
"version": "3.14.1",
"description": "Node.js SDK for Evervault",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -34,4 +34,4 @@ [![Evervault](https://evervault.com/evervault.svg)](https://evervault.com/)

// Initialize the client with your App ID and API Key
const evervaultClient = new Evervault('<API-KEY>', '<APP_ID>');
// Initialize the client with your team's api key
const evervaultClient = new Evervault('<API-KEY>');

@@ -48,11 +48,9 @@ // Encrypt your sensitive data

// Decrypt the data
const decrypted = await evervaultClient.decrypt(encrypted);
// Enable the Cages beta client
await evervaultClient.enableCagesBeta({ 'my-cage': { pcr8: '...' } });
// This connection will be attested by the Cages beta client
const response = await axios.post(
'https://my-cage.my-app.cages.evervault.com',
encrypted
); // This connection will be attested by the Cages beta client
);
```

@@ -62,33 +60,19 @@

The Evervault Node.js SDK exposes six functions.
The Evervault Node.js SDK exposes four functions.
### evervault.encrypt()
`evervault.encrypt()` encrypts data. To encrypt data at the server, simply pass a string, boolean, number, array, object or buffer into the `evervault.encrypt()` function. Store the encrypted data in your database as normal.
`evervault.encrypt()`encrypts data for use in your [Functions](https://docs.evervault.com/tutorial). To encrypt data at the server, simply pass an object or string into the evervault.encrypt() function. Store the encrypted data in your database as normal.
```javascript
async evervault.encrypt(data: string | boolean | number | Array | Object | Buffer);
async evervault.encrypt(data: Object | String);
```
| Parameter | Type | Description |
| --------- | ------------------------------------------------ | --------------------- |
| data | String, Boolean, Number, Array, Object or String | Data to be encrypted. |
| Parameter | Type | Description |
| --------- | ---------------- | --------------------- |
| data | Object or String | Data to be encrypted. |
### evervault.decrypt()
`evervault.decrypt()` decrypts data previously encrypted with the `encrypt()` function or through Evervault's Relay (Evervault's encryption proxy).
An API Key with the `decrypt` permission must be used to perform this operation.
```javascript
async evervault.decrypt(encrypted: string | Array | Object | Buffer);
```
| Parameter | Type | Description |
| -------------- | --------------------------------| --------------------- |
| encrypted | String, Array, Object or Buffer | Data to be decrypted. |
### evervault.run()
`evervault.run()` invokes a Function with a given payload.
An API Key with the `run function` permission must be used to perform this operation.

@@ -117,3 +101,2 @@ ```javascript

`evervault.createRunToken()` creates a single use, time bound token for invoking a Function.
An API Key with the `create a run token` permission must be used to perform this operation.

@@ -120,0 +103,0 @@ ```javascript

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc