@techbulls/encrypted-s3-store 1.0.0 → 1.0.2
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.md +21 -201
- package/dist/client.d.ts +0 -3
- package/dist/client.js +0 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +0 -1
- package/package.json +6 -7
- package/.prettierignore +0 -3
- package/.prettierrc +0 -7
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
- package/eslint.config.js +0 -23
- package/src/client.ts +0 -297
- package/src/index.ts +0 -26
- package/src/types.ts +0 -59
- package/src/utils.ts +0 -57
- package/tsconfig.json +0 -17
package/LICENSE.md
CHANGED
|
@@ -1,201 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Techbulls softtech Pvt. Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/client.d.ts
CHANGED
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
9
9
|
import { IDownload, IUpload, ModeType } from './types.js';
|
|
10
10
|
import { Readable } from 'node:stream';
|
|
11
|
-
/** Re-export all AWS S3 SDK exports for convenience */
|
|
12
|
-
export * from '@aws-sdk/client-s3';
|
|
13
11
|
/**
|
|
14
12
|
* S3 client wrapper with transparent end-to-end encryption support.
|
|
15
13
|
*
|
|
@@ -144,4 +142,3 @@ export declare class S3ObjectStore {
|
|
|
144
142
|
Metadata: Record<string, string> | undefined;
|
|
145
143
|
}>;
|
|
146
144
|
}
|
|
147
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.js
CHANGED
|
@@ -9,8 +9,6 @@ import { GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
|
|
|
9
9
|
import { deriveKey } from './utils.js';
|
|
10
10
|
import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
|
|
11
11
|
import { Readable } from 'node:stream';
|
|
12
|
-
/** Re-export all AWS S3 SDK exports for convenience */
|
|
13
|
-
export * from '@aws-sdk/client-s3';
|
|
14
12
|
/**
|
|
15
13
|
* S3 client wrapper with transparent end-to-end encryption support.
|
|
16
14
|
*
|
|
@@ -248,4 +246,3 @@ export class S3ObjectStore {
|
|
|
248
246
|
};
|
|
249
247
|
}
|
|
250
248
|
}
|
|
251
|
-
//# sourceMappingURL=client.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@techbulls/encrypted-s3-store",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,12 +21,11 @@
|
|
|
21
21
|
},
|
|
22
22
|
"keywords": [],
|
|
23
23
|
"author": "Aditya Chaphekar <aditya.chaphekar@techbulls.com>",
|
|
24
|
-
"license": "
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE.md"
|
|
30
29
|
],
|
|
31
30
|
"packageManager": "pnpm@10.19.0",
|
|
32
31
|
"devDependencies": {
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/dist/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAsC,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,uDAAuD;AACvD,cAAc,oBAAoB,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,aAAa;IACxB,2EAA2E;IAC3E,IAAI,EAAE,QAAQ,CAAC;IAEf,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;IAEZ,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,4EAA4E;IAC5E,SAAS,SA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,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAElF;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,aAAa,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,OAAQ,SAAQ,qBAAqB;IACpD,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,SAAU,SAAQ,qBAAqB;IACtD,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB"}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,SAAS,GAAU,KAAK,MAAM,EAAE,MAAM,MAAM,KAAG,OAAO,CAAC,MAAM,CAkBzE,CAAC"}
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,qDAAqD;AACrD,MAAM,WAAW,GAAG,SAAS,CAAyD,MAAM,CAAC,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,GAAW,EAAE,IAAY,EAAmB,EAAE;IAC5E,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACH,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE;QAClD,CAAC,EAAE,KAAK;QACR,CAAC,EAAE,CAAC;QACJ,CAAC,EAAE,CAAC;KACL,CAAC,CAAC;IAEH,OAAO,UAAoB,CAAC;AAC9B,CAAC,CAAC"}
|
package/eslint.config.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import tseslint from 'typescript-eslint';
|
|
3
|
-
import eslintConfigPrettier from 'eslint-config-prettier';
|
|
4
|
-
import eslintPluginPrettier from 'eslint-plugin-prettier/recommended';
|
|
5
|
-
|
|
6
|
-
/** @type {import('typescript-eslint').Config} */
|
|
7
|
-
export default [
|
|
8
|
-
eslint.configs.recommended,
|
|
9
|
-
...tseslint.configs.recommended,
|
|
10
|
-
eslintConfigPrettier,
|
|
11
|
-
eslintPluginPrettier,
|
|
12
|
-
{
|
|
13
|
-
ignores: ['dist/**', 'node_modules/**'],
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
files: ['**/*.ts'],
|
|
17
|
-
languageOptions: {
|
|
18
|
-
parserOptions: {
|
|
19
|
-
project: './tsconfig.json',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
];
|
package/src/client.ts
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Core S3ObjectStore client implementation.
|
|
3
|
-
* Provides transparent encryption/decryption for S3 objects using AES-256-GCM.
|
|
4
|
-
*
|
|
5
|
-
* @author Aditya Chaphekar <aditya.chaphekar@techbulls.com>
|
|
6
|
-
* @license Apache-2.0
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
|
10
|
-
import { SdkStream } from '@aws-sdk/types';
|
|
11
|
-
import { IDownload, IUpload, ModeType } from './types.js';
|
|
12
|
-
import { deriveKey } from './utils.js';
|
|
13
|
-
import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
|
|
14
|
-
import { Readable } from 'node:stream';
|
|
15
|
-
|
|
16
|
-
/** Re-export all AWS S3 SDK exports for convenience */
|
|
17
|
-
export * from '@aws-sdk/client-s3';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* S3 client wrapper with transparent end-to-end encryption support.
|
|
21
|
-
*
|
|
22
|
-
* Wraps an AWS S3 client to provide automatic encryption on upload
|
|
23
|
-
* and decryption on download using AES-256-GCM with scrypt key derivation.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* // Create an S3 client
|
|
28
|
-
* const s3Client = new S3Client({ region: 'us-east-1' });
|
|
29
|
-
*
|
|
30
|
-
* // Create an encrypted store wrapper
|
|
31
|
-
* const store = new S3ObjectStore(s3Client, 'my-secret-key');
|
|
32
|
-
*
|
|
33
|
-
* // Upload encrypted data
|
|
34
|
-
* await store.upload({ Bucket: 'my-bucket', Key: 'secret.txt', Body: 'Sensitive data' });
|
|
35
|
-
*
|
|
36
|
-
* // Download and decrypt
|
|
37
|
-
* const { Body } = await store.download({ Bucket: 'my-bucket', Key: 'secret.txt' });
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export class S3ObjectStore {
|
|
41
|
-
/** @type {ModeType} Current operation mode - 'encrypt' or 'passthrough' */
|
|
42
|
-
mode: ModeType;
|
|
43
|
-
|
|
44
|
-
/** @type {string} Encryption key used for AES-256-GCM encryption */
|
|
45
|
-
key: string;
|
|
46
|
-
|
|
47
|
-
/** @type {string | undefined} Default S3 bucket for all operations */
|
|
48
|
-
bucket?: string;
|
|
49
|
-
|
|
50
|
-
/** @type {string} Encryption algorithm identifier (always 'aes-256-gcm') */
|
|
51
|
-
algorithm = 'aes-256-gcm';
|
|
52
|
-
|
|
53
|
-
/** @type {S3Client} The underlying AWS S3 client instance */
|
|
54
|
-
client: S3Client;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Creates a new S3ObjectStore instance.
|
|
58
|
-
*
|
|
59
|
-
* @param client - An initialized AWS S3Client instance
|
|
60
|
-
* @param key - Encryption key for AES-256-GCM. Falls back to ENCRYPTION_KEY environment variable if not provided.
|
|
61
|
-
* @param mode - Operation mode ('encrypt' or 'passthrough'). Defaults to 'encrypt'.
|
|
62
|
-
* @throws {Error} If no encryption key is provided and ENCRYPTION_KEY environment variable is not set
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* // With explicit key
|
|
67
|
-
* const store = new S3ObjectStore(s3Client, 'my-secret-key');
|
|
68
|
-
*
|
|
69
|
-
* // With environment variable (ENCRYPTION_KEY)
|
|
70
|
-
* const store = new S3ObjectStore(s3Client);
|
|
71
|
-
*
|
|
72
|
-
* // With passthrough mode (no encryption)
|
|
73
|
-
* const store = new S3ObjectStore(s3Client, 'key', 'passthrough');
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
constructor(client: S3Client, key?: string, mode?: ModeType) {
|
|
77
|
-
this.client = client;
|
|
78
|
-
const envEncryptionKey = process.env.ENCRYPTION_KEY;
|
|
79
|
-
if (!key && !envEncryptionKey) {
|
|
80
|
-
throw new Error('Encryption key not provided.');
|
|
81
|
-
}
|
|
82
|
-
this.key = (key || envEncryptionKey) as string;
|
|
83
|
-
|
|
84
|
-
this.mode = mode ?? 'encrypt';
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Uploads data to S3 with optional encryption.
|
|
89
|
-
*
|
|
90
|
-
* In 'encrypt' mode:
|
|
91
|
-
* - Generates a random 12-byte IV (Initialization Vector)
|
|
92
|
-
* - Generates a random 16-byte salt for key derivation
|
|
93
|
-
* - Derives a 256-bit key using scrypt
|
|
94
|
-
* - Encrypts the data using AES-256-GCM
|
|
95
|
-
* - Stores encryption metadata (IV, salt, auth tag) in S3 object metadata
|
|
96
|
-
*
|
|
97
|
-
* In 'passthrough' mode:
|
|
98
|
-
* - Uploads data directly without encryption
|
|
99
|
-
*
|
|
100
|
-
* @param input - S3 PutObject parameters with optional mode override
|
|
101
|
-
* @returns Promise resolving to the S3 PutObject response
|
|
102
|
-
* @throws {Error} If Body is not provided
|
|
103
|
-
* @throws {Error} If Body type is not supported (only string, Buffer, Uint8Array)
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* // Upload a string
|
|
108
|
-
* await store.upload({ Bucket: 'my-bucket', Key: 'file.txt', Body: 'Hello World' });
|
|
109
|
-
*
|
|
110
|
-
* // Upload a Buffer
|
|
111
|
-
* await store.upload({ Bucket: 'my-bucket', Key: 'data.bin', Body: Buffer.from([0x01, 0x02]) });
|
|
112
|
-
*
|
|
113
|
-
* // Upload with custom metadata
|
|
114
|
-
* await store.upload({
|
|
115
|
-
* Bucket: 'my-bucket',
|
|
116
|
-
* Key: 'file.txt',
|
|
117
|
-
* Body: 'content',
|
|
118
|
-
* ContentType: 'text/plain',
|
|
119
|
-
* Metadata: { 'custom-header': 'value' }
|
|
120
|
-
* });
|
|
121
|
-
*
|
|
122
|
-
* // Upload without encryption (per-operation override)
|
|
123
|
-
* await store.upload({
|
|
124
|
-
* Bucket: 'my-bucket',
|
|
125
|
-
* Key: 'public.txt',
|
|
126
|
-
* Body: 'not sensitive',
|
|
127
|
-
* mode: 'passthrough'
|
|
128
|
-
* });
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
async upload(input: IUpload) {
|
|
132
|
-
if (!input.Body) {
|
|
133
|
-
throw new Error('Body is required for upload');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** Resolve mode: input.mode takes precedence, fallback to client default */
|
|
137
|
-
const mode =
|
|
138
|
-
input?.mode === 'encrypt' || input?.mode === 'passthrough' ? input.mode : this.mode;
|
|
139
|
-
|
|
140
|
-
/** Passthrough mode: upload without encryption */
|
|
141
|
-
if (mode === 'passthrough') {
|
|
142
|
-
return this.client.send(
|
|
143
|
-
new PutObjectCommand({
|
|
144
|
-
...input,
|
|
145
|
-
Bucket: input.Bucket || this.bucket,
|
|
146
|
-
})
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** Encrypt mode: encrypt data before uploading */
|
|
151
|
-
|
|
152
|
-
/** @type {Buffer} iv - 96-bit IV for GCM mode */
|
|
153
|
-
const iv = randomBytes(12);
|
|
154
|
-
/** @type {Buffer} salt - 128-bit salt for scrypt key derivation */
|
|
155
|
-
const salt = randomBytes(16);
|
|
156
|
-
|
|
157
|
-
/** Derive encryption key using scrypt (memory-hard, resistant to GPU attacks) */
|
|
158
|
-
const secretKey = await deriveKey(this.key, salt);
|
|
159
|
-
|
|
160
|
-
/** Create AES-256-GCM cipher */
|
|
161
|
-
const cipher = createCipheriv('aes-256-gcm', secretKey, iv);
|
|
162
|
-
|
|
163
|
-
/** Convert input body to Buffer for encryption */
|
|
164
|
-
let data: Buffer;
|
|
165
|
-
if (typeof input.Body === 'string') {
|
|
166
|
-
data = Buffer.from(input.Body, 'utf8');
|
|
167
|
-
} else if (Buffer.isBuffer(input.Body)) {
|
|
168
|
-
data = input.Body;
|
|
169
|
-
} else if (input.Body instanceof Uint8Array) {
|
|
170
|
-
data = Buffer.from(input.Body);
|
|
171
|
-
} else {
|
|
172
|
-
throw new Error('Unsupported Body type: only string, Buffer, or Uint8Array supported');
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Encrypt the data */
|
|
176
|
-
const encryptedBody = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
177
|
-
|
|
178
|
-
/** Get the GCM authentication tag (ensures data integrity and authenticity) */
|
|
179
|
-
const authTag = cipher.getAuthTag();
|
|
180
|
-
|
|
181
|
-
/** Upload encrypted data with encryption metadata stored in S3 object metadata */
|
|
182
|
-
return this.client.send(
|
|
183
|
-
new PutObjectCommand({
|
|
184
|
-
...input,
|
|
185
|
-
Bucket: input.Bucket || this.bucket,
|
|
186
|
-
Body: encryptedBody,
|
|
187
|
-
ContentLength: encryptedBody.length,
|
|
188
|
-
Metadata: {
|
|
189
|
-
...(input.Metadata || {}),
|
|
190
|
-
/** @description Base64-encoded IV */
|
|
191
|
-
'x-amz-iv': iv.toString('base64'),
|
|
192
|
-
/** @description Base64-encoded salt */
|
|
193
|
-
'x-amz-salt': salt.toString('base64'),
|
|
194
|
-
/** @description Base64-encoded GCM auth tag */
|
|
195
|
-
'x-amz-auth-tag': authTag.toString('base64'),
|
|
196
|
-
/** @description Encryption algorithm identifier */
|
|
197
|
-
'x-amz-encryption': 'aes-256-gcm',
|
|
198
|
-
},
|
|
199
|
-
})
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Downloads data from S3 with optional decryption.
|
|
205
|
-
*
|
|
206
|
-
* In 'encrypt' mode:
|
|
207
|
-
* - Retrieves encryption metadata (IV, salt, auth tag) from S3 object metadata
|
|
208
|
-
* - Derives the decryption key using scrypt with the stored salt
|
|
209
|
-
* - Decrypts the data using AES-256-GCM
|
|
210
|
-
* - Verifies data integrity using the authentication tag
|
|
211
|
-
*
|
|
212
|
-
* In 'passthrough' mode:
|
|
213
|
-
* - Returns the data stream directly without decryption
|
|
214
|
-
*
|
|
215
|
-
* @param input - S3 GetObject parameters with optional mode override
|
|
216
|
-
* @returns Promise resolving to an object containing the decrypted Body stream and metadata
|
|
217
|
-
* @throws {Error} If no body is returned from S3
|
|
218
|
-
* @throws {Error} If authentication tag verification fails (data tampering detected)
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```typescript
|
|
222
|
-
* const { Body, ContentType } = await store.download({ Bucket: 'my-bucket', Key: 'file.txt' });
|
|
223
|
-
*
|
|
224
|
-
* // Read the stream
|
|
225
|
-
* const chunks: Buffer[] = [];
|
|
226
|
-
* for await (const chunk of Body) {
|
|
227
|
-
* chunks.push(chunk);
|
|
228
|
-
* }
|
|
229
|
-
* const content = Buffer.concat(chunks).toString('utf8');
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
async download(input: IDownload) {
|
|
233
|
-
/** Fetch the object from S3 */
|
|
234
|
-
const response = await this.client.send(
|
|
235
|
-
new GetObjectCommand({ ...input, Bucket: input.Bucket || this.bucket })
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
if (!response.Body) {
|
|
239
|
-
throw new Error('No body returned from S3');
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/** Resolve mode: input.mode takes precedence, fallback to client default */
|
|
243
|
-
const mode =
|
|
244
|
-
input?.mode === 'encrypt' || input?.mode === 'passthrough' ? input.mode : this.mode;
|
|
245
|
-
|
|
246
|
-
/** Passthrough mode: download without encryption */
|
|
247
|
-
if (mode === 'passthrough') {
|
|
248
|
-
return {
|
|
249
|
-
Body: Readable.from(response.Body as SdkStream<Readable>),
|
|
250
|
-
ContentType: response.ContentType,
|
|
251
|
-
ContentLength: response.ContentLength,
|
|
252
|
-
Metadata: response.Metadata,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** Encrypt mode: decrypt the response */
|
|
257
|
-
|
|
258
|
-
/** Extract encryption metadata from S3 object */
|
|
259
|
-
const metadata = response.Metadata || {};
|
|
260
|
-
const ivBase64 = metadata['x-amz-iv'];
|
|
261
|
-
const saltBase64 = metadata['x-amz-salt'];
|
|
262
|
-
const authTagBase64 = metadata['x-amz-auth-tag'];
|
|
263
|
-
const encryption = metadata['x-amz-encryption'];
|
|
264
|
-
|
|
265
|
-
/** If encryption metadata is missing, return unencrypted stream */
|
|
266
|
-
if (!ivBase64 || !saltBase64 || !authTagBase64 || encryption !== 'aes-256-gcm') {
|
|
267
|
-
return {
|
|
268
|
-
Body: Readable.from(response.Body as SdkStream<Readable>),
|
|
269
|
-
ContentType: response.ContentType,
|
|
270
|
-
ContentLength: response.ContentLength,
|
|
271
|
-
Metadata: response.Metadata,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/** Decode encryption parameters from Base64 */
|
|
276
|
-
const iv = Buffer.from(ivBase64, 'base64');
|
|
277
|
-
const salt = Buffer.from(saltBase64, 'base64');
|
|
278
|
-
const authTag = Buffer.from(authTagBase64, 'base64');
|
|
279
|
-
|
|
280
|
-
/** Derive the decryption key using the same salt used during encryption */
|
|
281
|
-
const secretKey = await deriveKey(this.key, salt);
|
|
282
|
-
|
|
283
|
-
/** Create AES-256-GCM decipher and set the authentication tag */
|
|
284
|
-
const decipher = createDecipheriv('aes-256-gcm', secretKey, iv);
|
|
285
|
-
decipher.setAuthTag(authTag);
|
|
286
|
-
|
|
287
|
-
/** Pipe the encrypted stream through the decipher to get decrypted output */
|
|
288
|
-
const decryptedStream = (response.Body as SdkStream<Readable>).pipe(decipher);
|
|
289
|
-
|
|
290
|
-
return {
|
|
291
|
-
Body: decryptedStream,
|
|
292
|
-
ContentType: response.ContentType,
|
|
293
|
-
ContentLength: response.ContentLength,
|
|
294
|
-
Metadata: response.Metadata,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Main entry point for the Encrypted S3 Store library.
|
|
3
|
-
*
|
|
4
|
-
* This library provides transparent end-to-end encryption for AWS S3 objects
|
|
5
|
-
* using AES-256-GCM encryption with scrypt key derivation.
|
|
6
|
-
*
|
|
7
|
-
* @module encrypted-s3-store
|
|
8
|
-
* @author Aditya Chaphekar <aditya.chaphekar@techbulls.com>
|
|
9
|
-
* @license Apache-2.0
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { S3ObjectStore, S3Client } from '@techbulls/encrypted-s3-store';
|
|
14
|
-
*
|
|
15
|
-
* const s3Client = new S3Client({ region: 'us-east-1' });
|
|
16
|
-
* const store = new S3ObjectStore(s3Client, 'my-secret-key');
|
|
17
|
-
*
|
|
18
|
-
* // Upload with automatic encryption
|
|
19
|
-
* await store.upload({ Bucket: 'my-bucket', Key: 'file.txt', Body: 'Hello World' });
|
|
20
|
-
*
|
|
21
|
-
* // Download with automatic decryption
|
|
22
|
-
* const result = await store.download({ Bucket: 'my-bucket', Key: 'file.txt' });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export * from './client.js';
|
|
26
|
-
export * from './types.js';
|
package/src/types.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Type definitions for the Encrypted S3 Store library.
|
|
3
|
-
* Contains configuration interfaces and utility types used throughout the library.
|
|
4
|
-
*
|
|
5
|
-
* @author Aditya Chaphekar <aditya.chaphekar@techbulls.com>
|
|
6
|
-
* @license Apache-2.0
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { GetObjectCommandInput, PutObjectCommandInput } from '@aws-sdk/client-s3';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Operation mode for the S3ObjectStore.
|
|
13
|
-
* - 'encrypt': Enables transparent AES-256-GCM encryption for all uploads/downloads
|
|
14
|
-
* - 'passthrough': Data is stored and retrieved without encryption
|
|
15
|
-
*/
|
|
16
|
-
export type ModeType = 'encrypt' | 'passthrough';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Upload input options extending S3 PutObjectCommandInput.
|
|
20
|
-
* Allows specifying a per-operation encryption mode override.
|
|
21
|
-
*
|
|
22
|
-
* @extends PutObjectCommandInput
|
|
23
|
-
*
|
|
24
|
-
* @property mode - Optional override for the operation mode. If not specified, uses the client's default mode.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const uploadInput: IUpload = {
|
|
29
|
-
* Bucket: 'my-bucket',
|
|
30
|
-
* Key: 'file.txt',
|
|
31
|
-
* Body: 'content',
|
|
32
|
-
* mode: 'passthrough' // Override to skip encryption for this upload
|
|
33
|
-
* };
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export interface IUpload extends PutObjectCommandInput {
|
|
37
|
-
mode?: ModeType;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Download input options extending S3 GetObjectCommandInput.
|
|
42
|
-
* Allows specifying a per-operation encryption mode override.
|
|
43
|
-
*
|
|
44
|
-
* @extends GetObjectCommandInput
|
|
45
|
-
*
|
|
46
|
-
* @property mode - Optional override for the operation mode. If not specified, uses the client's default mode.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const downloadInput: IDownload = {
|
|
51
|
-
* Bucket: 'my-bucket',
|
|
52
|
-
* Key: 'file.txt',
|
|
53
|
-
* mode: 'passthrough' // Override to skip decryption for this download
|
|
54
|
-
* };
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export interface IDownload extends GetObjectCommandInput {
|
|
58
|
-
mode?: ModeType;
|
|
59
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Utility functions for encryption key derivation.
|
|
3
|
-
*
|
|
4
|
-
* @author Aditya Chaphekar <aditya.chaphekar@techbulls.com>
|
|
5
|
-
* @license Apache-2.0
|
|
6
|
-
*/
|
|
7
|
-
import { scrypt, ScryptOptions } from 'node:crypto';
|
|
8
|
-
import { promisify } from 'node:util';
|
|
9
|
-
|
|
10
|
-
/** Promisified version of Node.js scrypt function */
|
|
11
|
-
const scryptAsync = promisify<string | Buffer, Buffer, number, ScryptOptions, Buffer>(scrypt);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Derives a 256-bit encryption key from a password using scrypt.
|
|
15
|
-
*
|
|
16
|
-
* Scrypt is a memory-hard key derivation function that provides strong
|
|
17
|
-
* resistance against brute-force attacks, including GPU-based attacks.
|
|
18
|
-
*
|
|
19
|
-
* Security parameters:
|
|
20
|
-
* - N (cost): 16384 (2^14) - CPU/memory cost parameter
|
|
21
|
-
* - r (blockSize): 8 - block size parameter
|
|
22
|
-
* - p (parallelization): 1 - parallelization parameter
|
|
23
|
-
* - Output: 32 bytes (256 bits for AES-256)
|
|
24
|
-
*
|
|
25
|
-
* @param key - The user's encryption password/key
|
|
26
|
-
* @param salt - Random salt (should be 16 bytes, stored with encrypted data)
|
|
27
|
-
* @returns Promise resolving to 32-byte Buffer containing the derived key
|
|
28
|
-
* @throws {Error} If encryption key is empty or not provided
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* const salt = crypto.randomBytes(16);
|
|
33
|
-
* const derivedKey = await deriveKey('my-secret-password', salt);
|
|
34
|
-
* // derivedKey is a 32-byte Buffer suitable for AES-256
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @see https://nodejs.org/api/crypto.html#cryptoscryptpassword-salt-keylen-options-callback
|
|
38
|
-
*/
|
|
39
|
-
export const deriveKey = async (key: string, salt: Buffer): Promise<Buffer> => {
|
|
40
|
-
if (!key) {
|
|
41
|
-
throw new Error('Encryption key is required');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Derive key using scrypt with secure parameters.
|
|
46
|
-
* - N=16384: Memory cost (must be power of 2)
|
|
47
|
-
* - r=8: Block size
|
|
48
|
-
* - p=1: Parallelization factor
|
|
49
|
-
*/
|
|
50
|
-
const derivedKey = await scryptAsync(key, salt, 32, {
|
|
51
|
-
N: 16384,
|
|
52
|
-
r: 8,
|
|
53
|
-
p: 1,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return derivedKey as Buffer;
|
|
57
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "Node",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"forceConsistentCasingInFileNames": true
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"],
|
|
16
|
-
"exclude": ["node_modules", "dist"]
|
|
17
|
-
}
|