@vollcrypt/db-guard 0.1.2 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/LICENSE-COMMERCIAL.md +71 -0
- package/LICENSE-GPL +674 -0
- package/dist/blind-index.d.ts +1 -7
- package/dist/blind-index.js +3 -22
- package/dist/cli.js +3 -3
- package/dist/drivers.js +52 -16
- package/dist/drizzle.js +23 -22
- package/dist/index.d.ts +2 -6
- package/dist/index.js +4 -12
- package/dist/kms.d.ts +10 -0
- package/dist/kms.js +58 -2
- package/dist/mongoose.d.ts +1 -1
- package/dist/mongoose.js +33 -24
- package/dist/prisma.d.ts +4 -24
- package/dist/prisma.js +44 -176
- package/dist/provenance.json +37 -21
- package/dist/provenance.json.sig +2 -1
- package/dist/sbom.json +45 -21
- package/dist/sbom.json.sig +1 -2
- package/dist/security.d.ts +11 -3
- package/dist/security.js +223 -76
- package/dist/typeorm.d.ts +1 -1
- package/dist/typeorm.js +12 -11
- package/package.json +105 -50
package/dist/typeorm.js
CHANGED
|
@@ -35,24 +35,25 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.createTypeOrmSubscriber = createTypeOrmSubscriber;
|
|
38
|
-
const typeorm_1 = require("typeorm");
|
|
39
|
-
const prisma_1 = require("./prisma");
|
|
40
|
-
const blind_index_1 = require("./blind-index");
|
|
41
38
|
const security_1 = require("./security");
|
|
42
39
|
function getKeys(options) {
|
|
43
40
|
let keys;
|
|
44
41
|
let activeVersion;
|
|
45
42
|
if (Buffer.isBuffer(options.key)) {
|
|
46
|
-
keys = { '1': options.key };
|
|
43
|
+
keys = { '1': Buffer.from(options.key) };
|
|
47
44
|
activeVersion = '1';
|
|
48
45
|
}
|
|
49
46
|
else {
|
|
50
|
-
keys =
|
|
47
|
+
keys = {};
|
|
48
|
+
for (const [v, k] of Object.entries(options.key)) {
|
|
49
|
+
keys[v] = Buffer.from(k);
|
|
50
|
+
}
|
|
51
51
|
activeVersion = options.activeKeyVersion || Object.keys(keys)[0];
|
|
52
52
|
}
|
|
53
53
|
return { keys, activeVersion };
|
|
54
54
|
}
|
|
55
55
|
function createTypeOrmSubscriber(options) {
|
|
56
|
+
const { EventSubscriber } = require('typeorm');
|
|
56
57
|
const { keys, activeVersion } = getKeys(options);
|
|
57
58
|
const activeKey = keys[activeVersion];
|
|
58
59
|
if (!activeKey) {
|
|
@@ -60,7 +61,7 @@ function createTypeOrmSubscriber(options) {
|
|
|
60
61
|
}
|
|
61
62
|
(0, security_1.registerKeysForZeroization)(keys);
|
|
62
63
|
let VollcryptDbGuardSubscriber = (() => {
|
|
63
|
-
let _classDecorators = [
|
|
64
|
+
let _classDecorators = [EventSubscriber()];
|
|
64
65
|
let _classDescriptor;
|
|
65
66
|
let _classExtraInitializers = [];
|
|
66
67
|
let _classThis;
|
|
@@ -87,7 +88,7 @@ function createTypeOrmSubscriber(options) {
|
|
|
87
88
|
for (const field of bidxFields) {
|
|
88
89
|
if (event.entity[field] !== undefined && event.entity[field] !== null) {
|
|
89
90
|
const bidxField = `${field}_bidx`;
|
|
90
|
-
event.entity[bidxField] = (0,
|
|
91
|
+
event.entity[bidxField] = (0, security_1.computeBlindIndex)(event.entity[field], options.blindIndexes.rootSalt, `${entityName}.${field}`);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
}
|
|
@@ -95,7 +96,7 @@ function createTypeOrmSubscriber(options) {
|
|
|
95
96
|
// Encrypt fields
|
|
96
97
|
for (const field of fields) {
|
|
97
98
|
if (event.entity[field] !== undefined && event.entity[field] !== null) {
|
|
98
|
-
event.entity[field] = (0,
|
|
99
|
+
event.entity[field] = (0, security_1.encryptValue)(event.entity[field], activeKey, activeVersion);
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
}
|
|
@@ -111,7 +112,7 @@ function createTypeOrmSubscriber(options) {
|
|
|
111
112
|
for (const field of bidxFields) {
|
|
112
113
|
if (event.entity[field] !== undefined && event.entity[field] !== null) {
|
|
113
114
|
const bidxField = `${field}_bidx`;
|
|
114
|
-
event.entity[bidxField] = (0,
|
|
115
|
+
event.entity[bidxField] = (0, security_1.computeBlindIndex)(event.entity[field], options.blindIndexes.rootSalt, `${entityName}.${field}`);
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
}
|
|
@@ -119,7 +120,7 @@ function createTypeOrmSubscriber(options) {
|
|
|
119
120
|
// Encrypt fields
|
|
120
121
|
for (const field of fields) {
|
|
121
122
|
if (event.entity[field] !== undefined && event.entity[field] !== null) {
|
|
122
|
-
event.entity[field] = (0,
|
|
123
|
+
event.entity[field] = (0, security_1.encryptValue)(event.entity[field], activeKey, activeVersion);
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
}
|
|
@@ -133,7 +134,7 @@ function createTypeOrmSubscriber(options) {
|
|
|
133
134
|
for (const field of fields) {
|
|
134
135
|
if (entity[field] !== undefined && entity[field] !== null) {
|
|
135
136
|
try {
|
|
136
|
-
entity[field] = (0, security_1.decryptWithSecurity)(entity[field], (val) => (0,
|
|
137
|
+
entity[field] = (0, security_1.decryptWithSecurity)(entity[field], (val) => (0, security_1.decryptValue)(val, keys), entityName, field, entity.id || entity._id, options);
|
|
137
138
|
}
|
|
138
139
|
catch (err) {
|
|
139
140
|
throw new Error(`TypeORM db-guard failed to decrypt field "${field}": ${err.message}`);
|
package/package.json
CHANGED
|
@@ -1,50 +1,105 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@vollcrypt/db-guard",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "Database field-level encryption integrations for Vollcrypt (Prisma, Mongoose, Drizzle, TypeORM)",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"bin": {
|
|
8
|
-
"vollcrypt-db-guard": "dist/cli.js"
|
|
9
|
-
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@vollcrypt/db-guard",
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "Database field-level encryption integrations for Vollcrypt (Prisma, Mongoose, Drizzle, TypeORM)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"vollcrypt-db-guard": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./prisma": {
|
|
16
|
+
"types": "./dist/prisma.d.ts",
|
|
17
|
+
"default": "./dist/prisma.js"
|
|
18
|
+
},
|
|
19
|
+
"./mongoose": {
|
|
20
|
+
"types": "./dist/mongoose.d.ts",
|
|
21
|
+
"default": "./dist/mongoose.js"
|
|
22
|
+
},
|
|
23
|
+
"./drizzle": {
|
|
24
|
+
"types": "./dist/drizzle.d.ts",
|
|
25
|
+
"default": "./dist/drizzle.js"
|
|
26
|
+
},
|
|
27
|
+
"./typeorm": {
|
|
28
|
+
"types": "./dist/typeorm.d.ts",
|
|
29
|
+
"default": "./dist/typeorm.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"compliance-config.json",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"LICENSE-COMMERCIAL.md",
|
|
38
|
+
"LICENSE-GPL"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/BeratVural/vollcrypt.git",
|
|
46
|
+
"directory": "db-guard/node"
|
|
47
|
+
},
|
|
48
|
+
"author": "Berat Vural <berat.vural.tr@gmail.com>",
|
|
49
|
+
"license": "GPL-3.0-only OR LicenseRef-Commercial",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/BeratVural/vollcrypt/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/BeratVural/vollcrypt/tree/main/db-guard/node#readme",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc && node scripts/generate-sbom.js",
|
|
56
|
+
"test": "node --import tsx --test tests/*.test.ts"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@prisma/client": ">=4.7.0",
|
|
61
|
+
"mongoose": ">=6.0.0",
|
|
62
|
+
"drizzle-orm": ">=0.28.0",
|
|
63
|
+
"typeorm": ">=0.3.0",
|
|
64
|
+
"@aws-sdk/client-kms": ">=3.0.0",
|
|
65
|
+
"@google-cloud/kms": ">=3.0.0",
|
|
66
|
+
"node-vault": ">=0.9.0",
|
|
67
|
+
"pkcs11js": ">=1.0.0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"@prisma/client": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"mongoose": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"drizzle-orm": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"typeorm": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"@aws-sdk/client-kms": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"@google-cloud/kms": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"node-vault": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"pkcs11js": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"devDependencies": {
|
|
96
|
+
"@prisma/client": "^5.0.0",
|
|
97
|
+
"@types/node": "^20.11.0",
|
|
98
|
+
"mongoose": "^8.0.0",
|
|
99
|
+
"prisma": "^5.0.0",
|
|
100
|
+
"drizzle-orm": "^0.30.0",
|
|
101
|
+
"typeorm": "^0.3.20",
|
|
102
|
+
"tsx": "^4.7.0",
|
|
103
|
+
"typescript": "^5.5.2"
|
|
104
|
+
}
|
|
105
|
+
}
|