@evervault/sdk
Advanced tools
Comparing version 3.5.0 to 3.6.0
@@ -36,3 +36,2 @@ const crypto = require('crypto'); | ||
}; | ||
const _traverseObject = async ( | ||
@@ -148,2 +147,12 @@ curve, | ||
const _evEncryptedFileVersion = () => { | ||
if (config.ecdhCurve == 'secp256k1') { | ||
return Buffer.from([0x00]); | ||
} else if (config.ecdhCurve === 'prime256v1') { | ||
return Buffer.from([0x01]); | ||
} else { | ||
throw new Error('Invalid curve specified'); | ||
} | ||
}; | ||
const _format = ( | ||
@@ -158,6 +167,56 @@ datatype = 'string', | ||
}:${base64RemovePadding(keyIv)}:${base64RemovePadding( | ||
ecdhPublicKey | ||
ecdhPublicKey.toString('base64') | ||
)}:${base64RemovePadding(encryptedData)}:$`; | ||
}; | ||
const _encryptFile = async ( | ||
curve, | ||
ecdhTeamKey, | ||
ecdhPublicKey, | ||
derivedSecret, | ||
data | ||
) => { | ||
const keyIv = await generateBytes(config.ivLength); | ||
const cipher = crypto.createCipheriv( | ||
config.cipherAlgorithm, | ||
derivedSecret, | ||
keyIv, | ||
{ | ||
authTagLength: config.authTagLength, | ||
} | ||
); | ||
if (curve === PRIME256V1) { | ||
cipher.setAAD(Buffer.from(ecdhTeamKey, 'base64')); | ||
} | ||
const encryptedBuffer = Buffer.concat([ | ||
cipher.update(data), | ||
cipher.final(), | ||
cipher.getAuthTag(), | ||
]); | ||
return _formatFile(keyIv, ecdhPublicKey, encryptedBuffer); | ||
}; | ||
const _formatFile = async (keyIv, ecdhPublicKey, encryptedData) => { | ||
const evEncryptedFileIdentifier = Buffer.from([ | ||
0x25, 0x45, 0x56, 0x45, 0x4e, 0x43, | ||
]); | ||
const versionNumber = _evEncryptedFileVersion(); | ||
const offsetToData = Buffer.from([0x37, 0x00]); | ||
const flags = Buffer.from([0x00]); | ||
return Buffer.concat([ | ||
evEncryptedFileIdentifier, | ||
versionNumber, | ||
offsetToData, | ||
Buffer.from(ecdhPublicKey), | ||
Buffer.from(keyIv), | ||
flags, | ||
Buffer.from(encryptedData), | ||
]); | ||
}; | ||
const encrypt = async ( | ||
@@ -175,3 +234,11 @@ curve, | ||
if (Datatypes.isObjectStrict(data)) { | ||
if (Datatypes.isBuffer(data)) { | ||
return await _encryptFile( | ||
curve, | ||
ecdhTeamKey, | ||
ecdhPublicKey, | ||
derivedSecret, | ||
data | ||
); | ||
} else if (Datatypes.isObjectStrict(data)) { | ||
return await _encryptObject( | ||
@@ -178,0 +245,0 @@ curve, |
@@ -204,3 +204,3 @@ const crypto = require('crypto'); | ||
'_ecdhPublicKey', | ||
this._ecdh.getPublicKey(null, 'compressed').toString('base64') | ||
this._ecdh.getPublicKey(null, 'compressed') | ||
); | ||
@@ -207,0 +207,0 @@ if (this.curve === EvervaultClient.CURVES.PRIME256V1) { |
{ | ||
"name": "@evervault/sdk", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"description": "Node.js SDK for Evervault", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59362
1720