@1auth/crypto
Advanced tools
Comparing version 0.0.0-alpha.10 to 0.0.0-alpha.11
@@ -262,12 +262,15 @@ import { promisify } from 'node:util' | ||
// assocData = sub or id | ||
export const encryptFields = (values, encryptedKey, assocData, fields = []) => { | ||
// TODO optimize: don't decrypt encryptedKey more than once | ||
for (const key of fields) { | ||
values[key] &&= encrypt(values[key], encryptedKey, assocData) | ||
} | ||
return values | ||
} | ||
export const encrypt = (data, encryptedKey, assocData) => { | ||
if (!encryptedKey) return data | ||
const encryptionKey = __decrypt( | ||
encryptedKey, | ||
Buffer.from(options.encryptionSharedKey, 'hex'), | ||
assocData, | ||
'hex', | ||
'hex' | ||
) | ||
const encryptionKey = __decryptKey(encryptedKey, assocData) | ||
return __encrypt( | ||
@@ -304,11 +307,13 @@ data, | ||
export const decryptFields = (values, encryptedKey, assocData, fields = []) => { | ||
// TODO optimize: don't decrypt encryptedKey more than once | ||
for (const key of fields) { | ||
values[key] &&= decrypt(values[key], encryptedKey, assocData) | ||
} | ||
return values | ||
} | ||
export const decrypt = (encryptedData, encryptedKey, assocData) => { | ||
if (!options.encryptionSharedKey || !encryptedKey) return encryptedData | ||
const encryptionKey = __decrypt( | ||
encryptedKey, | ||
Buffer.from(options.encryptionSharedKey, 'hex'), | ||
assocData, | ||
'hex', | ||
'hex' | ||
) | ||
const encryptionKey = __decryptKey(encryptedKey, assocData) | ||
const data = __decrypt( | ||
@@ -324,2 +329,11 @@ encryptedData, | ||
const __decryptKey = (encryptedKey, assocData) => | ||
__decrypt( | ||
encryptedKey, | ||
Buffer.from(options.encryptionSharedKey, 'hex'), | ||
assocData, | ||
'hex', | ||
'hex' | ||
) | ||
const __decrypt = ( | ||
@@ -326,0 +340,0 @@ data, |
42
index.js
@@ -262,12 +262,15 @@ import { promisify } from 'node:util' | ||
// assocData = sub or id | ||
export const encryptFields = (values, encryptedKey, assocData, fields = []) => { | ||
// TODO optimize: don't decrypt encryptedKey more than once | ||
for (const key of fields) { | ||
values[key] &&= encrypt(values[key], encryptedKey, assocData) | ||
} | ||
return values | ||
} | ||
export const encrypt = (data, encryptedKey, assocData) => { | ||
if (!encryptedKey) return data | ||
const encryptionKey = __decrypt( | ||
encryptedKey, | ||
Buffer.from(options.encryptionSharedKey, 'hex'), | ||
assocData, | ||
'hex', | ||
'hex' | ||
) | ||
const encryptionKey = __decryptKey(encryptedKey, assocData) | ||
return __encrypt( | ||
@@ -304,11 +307,13 @@ data, | ||
export const decryptFields = (values, encryptedKey, assocData, fields = []) => { | ||
// TODO optimize: don't decrypt encryptedKey more than once | ||
for (const key of fields) { | ||
values[key] &&= decrypt(values[key], encryptedKey, assocData) | ||
} | ||
return values | ||
} | ||
export const decrypt = (encryptedData, encryptedKey, assocData) => { | ||
if (!options.encryptionSharedKey || !encryptedKey) return encryptedData | ||
const encryptionKey = __decrypt( | ||
encryptedKey, | ||
Buffer.from(options.encryptionSharedKey, 'hex'), | ||
assocData, | ||
'hex', | ||
'hex' | ||
) | ||
const encryptionKey = __decryptKey(encryptedKey, assocData) | ||
const data = __decrypt( | ||
@@ -324,2 +329,11 @@ encryptedData, | ||
const __decryptKey = (encryptedKey, assocData) => | ||
__decrypt( | ||
encryptedKey, | ||
Buffer.from(options.encryptionSharedKey, 'hex'), | ||
assocData, | ||
'hex', | ||
'hex' | ||
) | ||
const __decrypt = ( | ||
@@ -326,0 +340,0 @@ data, |
{ | ||
"name": "@1auth/crypto", | ||
"version": "0.0.0-alpha.10", | ||
"version": "0.0.0-alpha.11", | ||
"description": "", | ||
@@ -51,3 +51,3 @@ "type": "module", | ||
"homepage": "https://github.com/willfarrell/1auth", | ||
"gitHead": "40d015ce640f9813d809fddb847f60974c596b46", | ||
"gitHead": "7dbe007253726b9dfc6bb9c089cb4dcb19c0fee5", | ||
"dependencies": { | ||
@@ -54,0 +54,0 @@ "@node-rs/argon2": "1.5.0" |
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
30748
774