@powerlines/plugin-crypto 0.10.673 → 0.10.675

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.
@@ -0,0 +1,258 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
4
+ let _alloy_js_core = require("@alloy-js/core");
5
+ let _alloy_js_typescript = require("@alloy-js/typescript");
6
+ let _power_plant_alloy_js_core_components_spacing = require("@power-plant/alloy-js/core/components/spacing");
7
+ let _power_plant_alloy_js_typescript_components_tsdoc = require("@power-plant/alloy-js/typescript/components/tsdoc");
8
+ let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
9
+ let _powerlines_plugin_alloy_typescript_components_builtin_file = require("@powerlines/plugin-alloy/typescript/components/builtin-file");
10
+ let defu = require("defu");
11
+ defu = require_runtime.__toESM(defu, 1);
12
+
13
+ //#region src/components/crypto-builtin.tsx
14
+ /**
15
+ * Generates the cryptography builtin module for the Powerlines project.
16
+ */
17
+ function CryptoBuiltin(props) {
18
+ const [{ children, imports }, rest] = (0, _alloy_js_core.splitProps)(props, ["children", "imports"]);
19
+ const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
20
+ const encryptionKey = context.config.crypto.encryptionKey;
21
+ const salt = context.config.crypto.salt;
22
+ const saltHex = salt || "nonce";
23
+ const hashKeyExpr = salt ? `hexToBytes("${salt}")` : `new TextEncoder().encode("powerlines")`;
24
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_builtin_file.BuiltinFile, (0, _alloy_js_core_jsx_runtime.mergeProps)({
25
+ id: "crypto",
26
+ description: "The cryptography module provides custom helper functions to support encrypting and decrypting data."
27
+ }, rest, {
28
+ get imports() {
29
+ return (0, defu.default)({
30
+ "@noble/ciphers/chacha.js": [{ name: "xchacha20poly1305" }, { name: "chacha20poly1305" }],
31
+ "@noble/ciphers/utils.js": [{ name: "randomBytes" }, { name: "hexToBytes" }],
32
+ "@noble/hashes/scrypt.js": [{ name: "scrypt" }],
33
+ "@noble/hashes/blake3.js": [{ name: "blake3" }]
34
+ }, imports ?? {});
35
+ },
36
+ get children() {
37
+ return [
38
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
39
+ get when() {
40
+ return Boolean(encryptionKey);
41
+ },
42
+ get children() {
43
+ return [
44
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
45
+ "const": true,
46
+ name: "nonce",
47
+ initializer: _alloy_js_core.code`randomBytes(24)`
48
+ }),
49
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_core_components_spacing.Spacing, {}),
50
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
51
+ "const": true,
52
+ name: "chacha",
53
+ initializer: _alloy_js_core.code`xchacha20poly1305(hexToBytes("${encryptionKey}"), nonce)`
54
+ }),
55
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_core_components_spacing.Spacing, {}),
56
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDoc, {
57
+ heading: "Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.",
58
+ get children() {
59
+ return [
60
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocLink, { children: `https://en.wikipedia.org/wiki/ChaCha20-Poly1305` }),
61
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocParam, {
62
+ name: "plaintext",
63
+ children: `The data to encrypt.`
64
+ }),
65
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocReturns, { children: `The encrypted data.` })
66
+ ];
67
+ }
68
+ }),
69
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
70
+ name: "encrypt",
71
+ "export": true,
72
+ parameters: [{
73
+ name: "plaintext",
74
+ type: "string"
75
+ }],
76
+ returnType: "string",
77
+ children: _alloy_js_core.code`return chacha.encrypt(
78
+ nonce,
79
+ new TextEncoder().encode(plaintext),
80
+ null
81
+ );`
82
+ }),
83
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_core_components_spacing.Spacing, {}),
84
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDoc, {
85
+ heading: "Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.",
86
+ get children() {
87
+ return [
88
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocLink, { children: `https://en.wikipedia.org/wiki/ChaCha20-Poly1305` }),
89
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocParam, {
90
+ name: "encrypted",
91
+ children: `The encrypted data to decrypt.`
92
+ }),
93
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocReturns, { children: `The decrypted data.` })
94
+ ];
95
+ }
96
+ }),
97
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
98
+ name: "decrypt",
99
+ "export": true,
100
+ parameters: [{
101
+ name: "encrypted",
102
+ type: "string"
103
+ }],
104
+ returnType: "string",
105
+ children: _alloy_js_core.code`const decrypted = chacha.decrypt(
106
+ nonce,
107
+ encrypted,
108
+ null
109
+ );
110
+
111
+ return new TextDecoder().decode(decrypted);`
112
+ }),
113
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_core_components_spacing.Spacing, {})
114
+ ];
115
+ }
116
+ }),
117
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDoc, {
118
+ heading: "Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.",
119
+ get children() {
120
+ return [
121
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocLink, { children: `https://en.wikipedia.org/wiki/ChaCha20-Poly1305` }),
122
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocParam, {
123
+ name: "password",
124
+ children: `The password used to derive the encryption key.`
125
+ }),
126
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocParam, {
127
+ name: "plaintext",
128
+ children: `The data to encrypt.`
129
+ }),
130
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocReturns, { children: `The encrypted data.` })
131
+ ];
132
+ }
133
+ }),
134
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
135
+ name: "encryptWithPassword",
136
+ "export": true,
137
+ parameters: [{
138
+ name: "password",
139
+ type: "string"
140
+ }, {
141
+ name: "plaintext",
142
+ type: "string"
143
+ }],
144
+ returnType: "string",
145
+ children: _alloy_js_core.code`const key = scrypt(
146
+ new TextEncoder().encode(password),
147
+ hexToBytes("${saltHex}"),
148
+ 1048576, // requires 1GB of RAM to calculate
149
+ 8,
150
+ 1,
151
+ 32
152
+ );
153
+
154
+ return chacha20poly1305(key).encrypt(
155
+ nonce,
156
+ new TextEncoder().encode(plaintext),
157
+ null
158
+ );`
159
+ }),
160
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_core_components_spacing.Spacing, {}),
161
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDoc, {
162
+ heading: "Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.",
163
+ get children() {
164
+ return [
165
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocLink, { children: `https://en.wikipedia.org/wiki/ChaCha20-Poly1305` }),
166
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocParam, {
167
+ name: "password",
168
+ children: `The password used to derive the decryption key.`
169
+ }),
170
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocParam, {
171
+ name: "encrypted",
172
+ children: `The encrypted data to decrypt.`
173
+ }),
174
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocReturns, { children: `The decrypted data.` })
175
+ ];
176
+ }
177
+ }),
178
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
179
+ name: "decryptWithPassword",
180
+ "export": true,
181
+ parameters: [{
182
+ name: "password",
183
+ type: "string"
184
+ }, {
185
+ name: "encrypted",
186
+ type: "string"
187
+ }],
188
+ returnType: "string",
189
+ children: _alloy_js_core.code`const key = scrypt(
190
+ new TextEncoder().encode(password),
191
+ hexToBytes("${saltHex}"),
192
+ 1048576, // requires 1GB of RAM to calculate
193
+ 8,
194
+ 1,
195
+ 32
196
+ );
197
+
198
+ const decrypted = chacha20poly1305(key).decrypt(
199
+ nonce,
200
+ encrypted,
201
+ null
202
+ );
203
+
204
+ return new TextDecoder().decode(decrypted);`
205
+ }),
206
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_core_components_spacing.Spacing, {}),
207
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDoc, {
208
+ heading: "Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.",
209
+ get children() {
210
+ return [
211
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocLink, { children: `https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3` }),
212
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocParam, {
213
+ name: "data",
214
+ children: `The data to hash.`
215
+ }),
216
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_typescript_components_tsdoc.TSDocReturns, { children: `The hashed data.` })
217
+ ];
218
+ }
219
+ }),
220
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
221
+ name: "hash",
222
+ "export": true,
223
+ parameters: [{
224
+ name: "data",
225
+ type: "string"
226
+ }],
227
+ returnType: "string",
228
+ children: _alloy_js_core.code`return Buffer.from(
229
+ blake3(new TextEncoder().encode(data), {
230
+ key: ${hashKeyExpr}
231
+ })
232
+ ).toString("hex");`
233
+ }),
234
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_power_plant_alloy_js_core_components_spacing.Spacing, {}),
235
+ _alloy_js_core.code`
236
+ // Export noble cipher and hash functions for advanced usage
237
+
238
+ export * from "@noble/ciphers/chacha.js";
239
+ export * from "@noble/ciphers/aes.js";
240
+ export * from "@noble/ciphers/utils.js";
241
+ export * from "@noble/hashes/blake3.js";
242
+ export * from "@noble/hashes/pbkdf2.js";
243
+ export * from "@noble/hashes/scrypt.js";
244
+ export * from "@noble/hashes/utils.js";
245
+ `,
246
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
247
+ get when() {
248
+ return Boolean(children);
249
+ },
250
+ children
251
+ })
252
+ ];
253
+ }
254
+ }));
255
+ }
256
+
257
+ //#endregion
258
+ exports.CryptoBuiltin = CryptoBuiltin;
@@ -0,0 +1,10 @@
1
+ import { BuiltinFileProps } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
2
+ //#region src/components/crypto-builtin.d.ts
3
+ type CryptoBuiltinProps = Omit<BuiltinFileProps, "id">;
4
+ /**
5
+ * Generates the cryptography builtin module for the Powerlines project.
6
+ */
7
+ declare function CryptoBuiltin(props: CryptoBuiltinProps): import("@alloy-js/core").Children;
8
+ //#endregion
9
+ export { CryptoBuiltin, CryptoBuiltinProps };
10
+ //# sourceMappingURL=crypto-builtin.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-builtin.d.cts","names":[],"sources":["../../src/components/crypto-builtin.tsx"],"mappings":";;KAmCY,qBAAqB,KAAK;;;;iBAKtB,cAAc,OAAO,8CAAkB"}
@@ -0,0 +1,10 @@
1
+ import { BuiltinFileProps } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
2
+ //#region src/components/crypto-builtin.d.ts
3
+ type CryptoBuiltinProps = Omit<BuiltinFileProps, "id">;
4
+ /**
5
+ * Generates the cryptography builtin module for the Powerlines project.
6
+ */
7
+ declare function CryptoBuiltin(props: CryptoBuiltinProps): import("@alloy-js/core").Children;
8
+ //#endregion
9
+ export { CryptoBuiltin, CryptoBuiltinProps };
10
+ //# sourceMappingURL=crypto-builtin.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-builtin.d.mts","names":[],"sources":["../../src/components/crypto-builtin.tsx"],"mappings":""}
@@ -0,0 +1,256 @@
1
+ import { createComponent, mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { Show, code, splitProps } from "@alloy-js/core";
3
+ import { FunctionDeclaration, VarDeclaration } from "@alloy-js/typescript";
4
+ import { Spacing } from "@power-plant/alloy-js/core/components/spacing";
5
+ import { TSDoc, TSDocLink, TSDocParam, TSDocReturns } from "@power-plant/alloy-js/typescript/components/tsdoc";
6
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
7
+ import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
8
+ import defu from "defu";
9
+
10
+ //#region src/components/crypto-builtin.tsx
11
+ /**
12
+ * Generates the cryptography builtin module for the Powerlines project.
13
+ */
14
+ function CryptoBuiltin(props) {
15
+ const [{ children, imports }, rest] = splitProps(props, ["children", "imports"]);
16
+ const context = usePowerlines();
17
+ const encryptionKey = context.config.crypto.encryptionKey;
18
+ const salt = context.config.crypto.salt;
19
+ const saltHex = salt || "nonce";
20
+ const hashKeyExpr = salt ? `hexToBytes("${salt}")` : `new TextEncoder().encode("powerlines")`;
21
+ return createComponent(BuiltinFile, mergeProps({
22
+ id: "crypto",
23
+ description: "The cryptography module provides custom helper functions to support encrypting and decrypting data."
24
+ }, rest, {
25
+ get imports() {
26
+ return defu({
27
+ "@noble/ciphers/chacha.js": [{ name: "xchacha20poly1305" }, { name: "chacha20poly1305" }],
28
+ "@noble/ciphers/utils.js": [{ name: "randomBytes" }, { name: "hexToBytes" }],
29
+ "@noble/hashes/scrypt.js": [{ name: "scrypt" }],
30
+ "@noble/hashes/blake3.js": [{ name: "blake3" }]
31
+ }, imports ?? {});
32
+ },
33
+ get children() {
34
+ return [
35
+ createComponent(Show, {
36
+ get when() {
37
+ return Boolean(encryptionKey);
38
+ },
39
+ get children() {
40
+ return [
41
+ createComponent(VarDeclaration, {
42
+ "const": true,
43
+ name: "nonce",
44
+ initializer: code`randomBytes(24)`
45
+ }),
46
+ createComponent(Spacing, {}),
47
+ createComponent(VarDeclaration, {
48
+ "const": true,
49
+ name: "chacha",
50
+ initializer: code`xchacha20poly1305(hexToBytes("${encryptionKey}"), nonce)`
51
+ }),
52
+ createComponent(Spacing, {}),
53
+ createComponent(TSDoc, {
54
+ heading: "Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.",
55
+ get children() {
56
+ return [
57
+ createComponent(TSDocLink, { children: `https://en.wikipedia.org/wiki/ChaCha20-Poly1305` }),
58
+ createComponent(TSDocParam, {
59
+ name: "plaintext",
60
+ children: `The data to encrypt.`
61
+ }),
62
+ createComponent(TSDocReturns, { children: `The encrypted data.` })
63
+ ];
64
+ }
65
+ }),
66
+ createComponent(FunctionDeclaration, {
67
+ name: "encrypt",
68
+ "export": true,
69
+ parameters: [{
70
+ name: "plaintext",
71
+ type: "string"
72
+ }],
73
+ returnType: "string",
74
+ children: code`return chacha.encrypt(
75
+ nonce,
76
+ new TextEncoder().encode(plaintext),
77
+ null
78
+ );`
79
+ }),
80
+ createComponent(Spacing, {}),
81
+ createComponent(TSDoc, {
82
+ heading: "Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.",
83
+ get children() {
84
+ return [
85
+ createComponent(TSDocLink, { children: `https://en.wikipedia.org/wiki/ChaCha20-Poly1305` }),
86
+ createComponent(TSDocParam, {
87
+ name: "encrypted",
88
+ children: `The encrypted data to decrypt.`
89
+ }),
90
+ createComponent(TSDocReturns, { children: `The decrypted data.` })
91
+ ];
92
+ }
93
+ }),
94
+ createComponent(FunctionDeclaration, {
95
+ name: "decrypt",
96
+ "export": true,
97
+ parameters: [{
98
+ name: "encrypted",
99
+ type: "string"
100
+ }],
101
+ returnType: "string",
102
+ children: code`const decrypted = chacha.decrypt(
103
+ nonce,
104
+ encrypted,
105
+ null
106
+ );
107
+
108
+ return new TextDecoder().decode(decrypted);`
109
+ }),
110
+ createComponent(Spacing, {})
111
+ ];
112
+ }
113
+ }),
114
+ createComponent(TSDoc, {
115
+ heading: "Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.",
116
+ get children() {
117
+ return [
118
+ createComponent(TSDocLink, { children: `https://en.wikipedia.org/wiki/ChaCha20-Poly1305` }),
119
+ createComponent(TSDocParam, {
120
+ name: "password",
121
+ children: `The password used to derive the encryption key.`
122
+ }),
123
+ createComponent(TSDocParam, {
124
+ name: "plaintext",
125
+ children: `The data to encrypt.`
126
+ }),
127
+ createComponent(TSDocReturns, { children: `The encrypted data.` })
128
+ ];
129
+ }
130
+ }),
131
+ createComponent(FunctionDeclaration, {
132
+ name: "encryptWithPassword",
133
+ "export": true,
134
+ parameters: [{
135
+ name: "password",
136
+ type: "string"
137
+ }, {
138
+ name: "plaintext",
139
+ type: "string"
140
+ }],
141
+ returnType: "string",
142
+ children: code`const key = scrypt(
143
+ new TextEncoder().encode(password),
144
+ hexToBytes("${saltHex}"),
145
+ 1048576, // requires 1GB of RAM to calculate
146
+ 8,
147
+ 1,
148
+ 32
149
+ );
150
+
151
+ return chacha20poly1305(key).encrypt(
152
+ nonce,
153
+ new TextEncoder().encode(plaintext),
154
+ null
155
+ );`
156
+ }),
157
+ createComponent(Spacing, {}),
158
+ createComponent(TSDoc, {
159
+ heading: "Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.",
160
+ get children() {
161
+ return [
162
+ createComponent(TSDocLink, { children: `https://en.wikipedia.org/wiki/ChaCha20-Poly1305` }),
163
+ createComponent(TSDocParam, {
164
+ name: "password",
165
+ children: `The password used to derive the decryption key.`
166
+ }),
167
+ createComponent(TSDocParam, {
168
+ name: "encrypted",
169
+ children: `The encrypted data to decrypt.`
170
+ }),
171
+ createComponent(TSDocReturns, { children: `The decrypted data.` })
172
+ ];
173
+ }
174
+ }),
175
+ createComponent(FunctionDeclaration, {
176
+ name: "decryptWithPassword",
177
+ "export": true,
178
+ parameters: [{
179
+ name: "password",
180
+ type: "string"
181
+ }, {
182
+ name: "encrypted",
183
+ type: "string"
184
+ }],
185
+ returnType: "string",
186
+ children: code`const key = scrypt(
187
+ new TextEncoder().encode(password),
188
+ hexToBytes("${saltHex}"),
189
+ 1048576, // requires 1GB of RAM to calculate
190
+ 8,
191
+ 1,
192
+ 32
193
+ );
194
+
195
+ const decrypted = chacha20poly1305(key).decrypt(
196
+ nonce,
197
+ encrypted,
198
+ null
199
+ );
200
+
201
+ return new TextDecoder().decode(decrypted);`
202
+ }),
203
+ createComponent(Spacing, {}),
204
+ createComponent(TSDoc, {
205
+ heading: "Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.",
206
+ get children() {
207
+ return [
208
+ createComponent(TSDocLink, { children: `https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3` }),
209
+ createComponent(TSDocParam, {
210
+ name: "data",
211
+ children: `The data to hash.`
212
+ }),
213
+ createComponent(TSDocReturns, { children: `The hashed data.` })
214
+ ];
215
+ }
216
+ }),
217
+ createComponent(FunctionDeclaration, {
218
+ name: "hash",
219
+ "export": true,
220
+ parameters: [{
221
+ name: "data",
222
+ type: "string"
223
+ }],
224
+ returnType: "string",
225
+ children: code`return Buffer.from(
226
+ blake3(new TextEncoder().encode(data), {
227
+ key: ${hashKeyExpr}
228
+ })
229
+ ).toString("hex");`
230
+ }),
231
+ createComponent(Spacing, {}),
232
+ code`
233
+ // Export noble cipher and hash functions for advanced usage
234
+
235
+ export * from "@noble/ciphers/chacha.js";
236
+ export * from "@noble/ciphers/aes.js";
237
+ export * from "@noble/ciphers/utils.js";
238
+ export * from "@noble/hashes/blake3.js";
239
+ export * from "@noble/hashes/pbkdf2.js";
240
+ export * from "@noble/hashes/scrypt.js";
241
+ export * from "@noble/hashes/utils.js";
242
+ `,
243
+ createComponent(Show, {
244
+ get when() {
245
+ return Boolean(children);
246
+ },
247
+ children
248
+ })
249
+ ];
250
+ }
251
+ }));
252
+ }
253
+
254
+ //#endregion
255
+ export { CryptoBuiltin };
256
+ //# sourceMappingURL=crypto-builtin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-builtin.mjs","names":[],"sources":[],"mappings":""}
@@ -1,3 +1,4 @@
1
- const require_crypto = require('./crypto.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_components_crypto_builtin = require('./crypto-builtin.cjs');
2
3
 
3
- exports.cryptoModule = require_crypto.cryptoModule;
4
+ exports.CryptoBuiltin = require_components_crypto_builtin.CryptoBuiltin;
@@ -1,2 +1,2 @@
1
- import { cryptoModule } from "./crypto.cjs";
2
- export { cryptoModule };
1
+ import { CryptoBuiltin, CryptoBuiltinProps } from "./crypto-builtin.cjs";
2
+ export { CryptoBuiltin, CryptoBuiltinProps };
@@ -1,2 +1,2 @@
1
- import { cryptoModule } from "./crypto.mjs";
2
- export { cryptoModule };
1
+ import { CryptoBuiltin, CryptoBuiltinProps } from "./crypto-builtin.mjs";
2
+ export { CryptoBuiltin, CryptoBuiltinProps };
@@ -1,3 +1,3 @@
1
- import { cryptoModule } from "./crypto.mjs";
1
+ import { CryptoBuiltin } from "./crypto-builtin.mjs";
2
2
 
3
- export { cryptoModule };
3
+ export { CryptoBuiltin };
package/dist/index.cjs CHANGED
@@ -1,14 +1,16 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- const require_crypto = require('./components/crypto.cjs');
3
+ const require_components_crypto_builtin = require('./components/crypto-builtin.cjs');
4
4
  require('./components/index.cjs');
5
+ let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
6
+ let defu = require("defu");
7
+ defu = require_runtime.__toESM(defu, 1);
5
8
  let _noble_ciphers_utils_js = require("@noble/ciphers/utils.js");
9
+ let _powerlines_plugin_alloy_render = require("@powerlines/plugin-alloy/render");
6
10
  let _powerlines_plugin_env = require("@powerlines/plugin-env");
7
11
  _powerlines_plugin_env = require_runtime.__toESM(_powerlines_plugin_env, 1);
8
- let defu = require("defu");
9
- defu = require_runtime.__toESM(defu, 1);
10
12
 
11
- //#region src/index.ts
13
+ //#region src/index.tsx
12
14
  /**
13
15
  * A Powerlines plugin to assist in developing other Powerlines plugins.
14
16
  */
@@ -34,12 +36,12 @@ function plugin(options = {}) {
34
36
  },
35
37
  async prepare() {
36
38
  this.debug(`Preparing the Crypto runtime artifacts for the Powerlines project.`);
37
- await this.emitBuiltin(await Promise.resolve(require_crypto.cryptoModule(this)), "crypto");
39
+ return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_crypto_builtin.CryptoBuiltin, {}));
38
40
  }
39
41
  }];
40
42
  }
41
43
 
42
44
  //#endregion
43
- exports.cryptoModule = require_crypto.cryptoModule;
45
+ exports.CryptoBuiltin = require_components_crypto_builtin.CryptoBuiltin;
44
46
  exports.default = plugin;
45
47
  exports.plugin = plugin;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig } from "./types/plugin.cjs";
2
- import { cryptoModule } from "./components/crypto.cjs";
1
+ import { CryptoBuiltin, CryptoBuiltinProps } from "./components/crypto-builtin.cjs";
3
2
  import "./components/index.cjs";
3
+ import { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig } from "./types/plugin.cjs";
4
4
  import "./types/index.cjs";
5
5
  import { Plugin } from "powerlines";
6
6
  //#region src/index.d.ts
@@ -14,5 +14,5 @@ declare module "powerlines" {
14
14
  */
15
15
  declare function plugin<TContext extends CryptoPluginContext = CryptoPluginContext>(options?: CryptoPluginOptions): Plugin<TContext>[];
16
16
  //#endregion
17
- export { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig, cryptoModule, plugin as default, plugin };
17
+ export { CryptoBuiltin, CryptoBuiltinProps, CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig, plugin as default, plugin };
18
18
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;YA6BY;IACR,SAAS;;;;;;iBAOG,OACd,iBAAiB,sBAAsB,qBACvC,UAAS,sBA6CJ,OAAO"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;YA8BY;IACR,SAAS;;;;;;iBAOG,OACd,iBAAiB,sBAAsB,qBACvC,UAAS,sBA0CJ,OAAO"}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig } from "./types/plugin.mjs";
2
- import { cryptoModule } from "./components/crypto.mjs";
1
+ import { CryptoBuiltin, CryptoBuiltinProps } from "./components/crypto-builtin.mjs";
3
2
  import "./components/index.mjs";
3
+ import { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig } from "./types/plugin.mjs";
4
4
  import "./types/index.mjs";
5
5
  import { Plugin } from "powerlines";
6
6
  //#region src/index.d.ts
@@ -14,5 +14,5 @@ declare module "powerlines" {
14
14
  */
15
15
  declare function plugin<TContext extends CryptoPluginContext = CryptoPluginContext>(options?: CryptoPluginOptions): Plugin<TContext>[];
16
16
  //#endregion
17
- export { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig, cryptoModule, plugin as default, plugin };
17
+ export { CryptoBuiltin, CryptoBuiltinProps, CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig, plugin as default, plugin };
18
18
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":""}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":""}
package/dist/index.mjs CHANGED
@@ -1,10 +1,12 @@
1
- import { cryptoModule } from "./components/crypto.mjs";
1
+ import { CryptoBuiltin } from "./components/crypto-builtin.mjs";
2
2
  import "./components/index.mjs";
3
+ import { createComponent } from "@alloy-js/core/jsx-runtime";
4
+ import defu from "defu";
3
5
  import { bytesToHex, randomBytes } from "@noble/ciphers/utils.js";
6
+ import { render } from "@powerlines/plugin-alloy/render";
4
7
  import env from "@powerlines/plugin-env";
5
- import defu from "defu";
6
8
 
7
- //#region src/index.ts
9
+ //#region src/index.tsx
8
10
  /**
9
11
  * A Powerlines plugin to assist in developing other Powerlines plugins.
10
12
  */
@@ -30,11 +32,11 @@ function plugin(options = {}) {
30
32
  },
31
33
  async prepare() {
32
34
  this.debug(`Preparing the Crypto runtime artifacts for the Powerlines project.`);
33
- await this.emitBuiltin(await Promise.resolve(cryptoModule(this)), "crypto");
35
+ return render(this, createComponent(CryptoBuiltin, {}));
34
36
  }
35
37
  }];
36
38
  }
37
39
 
38
40
  //#endregion
39
- export { cryptoModule, plugin as default, plugin };
41
+ export { CryptoBuiltin, plugin as default, plugin };
40
42
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-crypto",
3
- "version": "0.10.673",
3
+ "version": "0.10.675",
4
4
  "type": "module",
5
5
  "description": "A Powerlines plugin that provides unique identifier generation capabilities at runtime by adding the `id` builtin module.",
6
6
  "repository": {
@@ -53,6 +53,34 @@
53
53
  "default": "./dist/index.mjs"
54
54
  }
55
55
  },
56
+ "./components": {
57
+ "require": {
58
+ "types": "./dist/components/index.d.cts",
59
+ "default": "./dist/components/index.cjs"
60
+ },
61
+ "import": {
62
+ "types": "./dist/components/index.d.mts",
63
+ "default": "./dist/components/index.mjs"
64
+ },
65
+ "default": {
66
+ "types": "./dist/components/index.d.mts",
67
+ "default": "./dist/components/index.mjs"
68
+ }
69
+ },
70
+ "./components/crypto-builtin": {
71
+ "require": {
72
+ "types": "./dist/components/crypto-builtin.d.cts",
73
+ "default": "./dist/components/crypto-builtin.cjs"
74
+ },
75
+ "import": {
76
+ "types": "./dist/components/crypto-builtin.d.mts",
77
+ "default": "./dist/components/crypto-builtin.mjs"
78
+ },
79
+ "default": {
80
+ "types": "./dist/components/crypto-builtin.d.mts",
81
+ "default": "./dist/components/crypto-builtin.mjs"
82
+ }
83
+ },
56
84
  "./package.json": "./package.json",
57
85
  "./types": {
58
86
  "require": {
@@ -83,23 +111,29 @@
83
111
  }
84
112
  }
85
113
  },
86
- "files": ["dist/**/*"],
114
+ "files": ["dist"],
87
115
  "keywords": ["powerlines", "storm-software", "powerlines-plugin"],
88
116
  "dependencies": {
117
+ "@alloy-js/core": "^0.24.1",
118
+ "@alloy-js/json": "^0.24.0",
119
+ "@alloy-js/markdown": "^0.24.0",
120
+ "@alloy-js/typescript": "^0.24.0",
89
121
  "@noble/ciphers": "^2.2.0",
90
- "@powerlines/plugin-env": "^0.16.364",
122
+ "@power-plant/alloy-js": "^0.0.39",
123
+ "@powerlines/plugin-alloy": "^0.26.255",
124
+ "@powerlines/plugin-env": "^0.16.366",
91
125
  "@storm-software/config-tools": "^1.190.109",
92
126
  "@stryke/path": "^0.29.25",
93
127
  "defu": "^6.1.7",
94
- "powerlines": "^0.47.160"
128
+ "powerlines": "^0.47.162"
95
129
  },
96
130
  "devDependencies": {
97
- "@powerlines/plugin-plugin": "^0.12.572",
131
+ "@powerlines/plugin-plugin": "^0.12.574",
98
132
  "@types/node": "^25.9.5"
99
133
  },
100
134
  "publishConfig": { "access": "public" },
101
135
  "main": "./dist/index.cjs",
102
136
  "module": "./dist/index.mjs",
103
137
  "types": "./dist/index.d.cts",
104
- "gitHead": "de2000d03a08aa0992aefe09286a1ec1aad8fd9f"
138
+ "gitHead": "9d7a99095d9907e5751917b9f00e98e9f3ffac53"
105
139
  }
@@ -1,147 +0,0 @@
1
- let powerlines_utils = require("powerlines/utils");
2
-
3
- //#region src/components/crypto.ts
4
- /**
5
- * Generates the crypto module content.
6
- *
7
- * @param context - The build context containing runtime information.
8
- * @returns A string representing the crypto module code.
9
- */
10
- function cryptoModule(context) {
11
- return `
12
- /**
13
- * The cryptography module provides custom helper functions to support encrypting and decrypting data.
14
- *
15
- * @module ${context.config.framework?.name || "powerlines"}:crypto
16
- */
17
-
18
- ${(0, powerlines_utils.getFileHeader)(context)}
19
-
20
- import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
21
- import { randomBytes, managedNonce, hexToBytes } from "@noble/ciphers/utils.js";
22
- import { scrypt } from "@noble/hashes/scrypt.js";
23
- import { blake3 } from "@noble/hashes/blake3.js";
24
-
25
- ${context.config.crypto.encryptionKey ? `const nonce = randomBytes(24);
26
- const chacha = xchacha20poly1305(hexToBytes("${context.config.crypto.encryptionKey}"), nonce);
27
-
28
- /**
29
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
30
- *
31
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
32
- *
33
- * @param plaintext - The data to encrypt.
34
- * @returns The encrypted data.
35
- */
36
- export function encrypt(plaintext: string): string {
37
- return chacha.encrypt(
38
- nonce,
39
- new TextEncoder().encode(plaintext),
40
- null
41
- );
42
- }
43
-
44
- /**
45
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
46
- *
47
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
48
- *
49
- * @param encrypted - The encrypted data to decrypt.
50
- * @returns The decrypted data.
51
- */
52
- export function decrypt(encrypted: string): string {
53
- const decrypted = chacha.decrypt(
54
- nonce,
55
- encrypted,
56
- null
57
- );
58
-
59
- return new TextDecoder().decode(decrypted);
60
- }
61
- ` : ""}
62
-
63
- /**
64
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
65
- *
66
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
67
- *
68
- * @param password - The password used to derive the encryption key.
69
- * @param plaintext - The data to encrypt.
70
- * @returns The encrypted data.
71
- */
72
- export function encryptWithPassword(password: string, plaintext: string): string {
73
- const key = scrypt(
74
- new TextEncoder().encode(password),
75
- hexToBytes("${context.config.crypto.salt ? context.config.crypto.salt : "nonce"}"),
76
- 1048576, // requires 1GB of RAM to calculate
77
- 8,
78
- 1,
79
- 32
80
- );
81
-
82
- return chacha20poly1305(key).encrypt(
83
- nonce,
84
- new TextEncoder().encode(plaintext),
85
- null
86
- );
87
- }
88
-
89
- /**
90
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
91
- *
92
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
93
- *
94
- * @param password - The password used to derive the decryption key.
95
- * @param encrypted - The encrypted data to decrypt.
96
- * @returns The decrypted data.
97
- */
98
- export function decryptWithPassword(password: string, encrypted: string): string {
99
- const key = scrypt(
100
- new TextEncoder().encode(password),
101
- hexToBytes("${context.config.crypto.salt ? context.config.crypto.salt : "nonce"}"),
102
- 1048576, // requires 1GB of RAM to calculate
103
- 8,
104
- 1,
105
- 32
106
- );
107
-
108
- const decrypted = chacha20poly1305(key).decrypt(
109
- nonce,
110
- encrypted,
111
- null
112
- );
113
-
114
- return new TextDecoder().decode(decrypted);
115
- }
116
-
117
- /**
118
- * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.
119
- *
120
- * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3
121
- *
122
- * @param data - The data to hash.
123
- * @returns The hashed data.
124
- */
125
- export function hash(data: string): string {
126
- return Buffer.from(
127
- blake3(new TextEncoder().encode(data), {
128
- key: ${context.config.crypto.salt ? `hexToBytes("${context.config.crypto.salt}")` : "new TextEncoder().encode(\"powerlines\")"})
129
- })
130
- ).toString("hex");
131
- }
132
-
133
- // Export noble cipher and hash functions for advanced usage
134
-
135
- export * from "@noble/ciphers/chacha.js";
136
- export * from "@noble/ciphers/aes.js";
137
- export * from "@noble/ciphers/utils.js";
138
- export * from '@noble/hashes/blake3.js';
139
- export * from '@noble/hashes/pbkdf2.js';
140
- export * from '@noble/hashes/scrypt.js';
141
- export * from '@noble/hashes/utils.js';
142
-
143
- `;
144
- }
145
-
146
- //#endregion
147
- exports.cryptoModule = cryptoModule;
@@ -1,12 +0,0 @@
1
- import { CryptoPluginContext } from "../types/plugin.cjs";
2
- //#region src/components/crypto.d.ts
3
- /**
4
- * Generates the crypto module content.
5
- *
6
- * @param context - The build context containing runtime information.
7
- * @returns A string representing the crypto module code.
8
- */
9
- declare function cryptoModule(context: CryptoPluginContext): string;
10
- //#endregion
11
- export { cryptoModule };
12
- //# sourceMappingURL=crypto.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto.d.cts","names":[],"sources":["../../src/components/crypto.ts"],"mappings":";;;;;;;;iBA2BgB,aAAa,SAAS"}
@@ -1,12 +0,0 @@
1
- import { CryptoPluginContext } from "../types/plugin.mjs";
2
- //#region src/components/crypto.d.ts
3
- /**
4
- * Generates the crypto module content.
5
- *
6
- * @param context - The build context containing runtime information.
7
- * @returns A string representing the crypto module code.
8
- */
9
- declare function cryptoModule(context: CryptoPluginContext): string;
10
- //#endregion
11
- export { cryptoModule };
12
- //# sourceMappingURL=crypto.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto.d.mts","names":[],"sources":["../../src/components/crypto.ts"],"mappings":""}
@@ -1,148 +0,0 @@
1
- import { getFileHeader } from "powerlines/utils";
2
-
3
- //#region src/components/crypto.ts
4
- /**
5
- * Generates the crypto module content.
6
- *
7
- * @param context - The build context containing runtime information.
8
- * @returns A string representing the crypto module code.
9
- */
10
- function cryptoModule(context) {
11
- return `
12
- /**
13
- * The cryptography module provides custom helper functions to support encrypting and decrypting data.
14
- *
15
- * @module ${context.config.framework?.name || "powerlines"}:crypto
16
- */
17
-
18
- ${getFileHeader(context)}
19
-
20
- import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
21
- import { randomBytes, managedNonce, hexToBytes } from "@noble/ciphers/utils.js";
22
- import { scrypt } from "@noble/hashes/scrypt.js";
23
- import { blake3 } from "@noble/hashes/blake3.js";
24
-
25
- ${context.config.crypto.encryptionKey ? `const nonce = randomBytes(24);
26
- const chacha = xchacha20poly1305(hexToBytes("${context.config.crypto.encryptionKey}"), nonce);
27
-
28
- /**
29
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
30
- *
31
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
32
- *
33
- * @param plaintext - The data to encrypt.
34
- * @returns The encrypted data.
35
- */
36
- export function encrypt(plaintext: string): string {
37
- return chacha.encrypt(
38
- nonce,
39
- new TextEncoder().encode(plaintext),
40
- null
41
- );
42
- }
43
-
44
- /**
45
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
46
- *
47
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
48
- *
49
- * @param encrypted - The encrypted data to decrypt.
50
- * @returns The decrypted data.
51
- */
52
- export function decrypt(encrypted: string): string {
53
- const decrypted = chacha.decrypt(
54
- nonce,
55
- encrypted,
56
- null
57
- );
58
-
59
- return new TextDecoder().decode(decrypted);
60
- }
61
- ` : ""}
62
-
63
- /**
64
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
65
- *
66
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
67
- *
68
- * @param password - The password used to derive the encryption key.
69
- * @param plaintext - The data to encrypt.
70
- * @returns The encrypted data.
71
- */
72
- export function encryptWithPassword(password: string, plaintext: string): string {
73
- const key = scrypt(
74
- new TextEncoder().encode(password),
75
- hexToBytes("${context.config.crypto.salt ? context.config.crypto.salt : "nonce"}"),
76
- 1048576, // requires 1GB of RAM to calculate
77
- 8,
78
- 1,
79
- 32
80
- );
81
-
82
- return chacha20poly1305(key).encrypt(
83
- nonce,
84
- new TextEncoder().encode(plaintext),
85
- null
86
- );
87
- }
88
-
89
- /**
90
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
91
- *
92
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
93
- *
94
- * @param password - The password used to derive the decryption key.
95
- * @param encrypted - The encrypted data to decrypt.
96
- * @returns The decrypted data.
97
- */
98
- export function decryptWithPassword(password: string, encrypted: string): string {
99
- const key = scrypt(
100
- new TextEncoder().encode(password),
101
- hexToBytes("${context.config.crypto.salt ? context.config.crypto.salt : "nonce"}"),
102
- 1048576, // requires 1GB of RAM to calculate
103
- 8,
104
- 1,
105
- 32
106
- );
107
-
108
- const decrypted = chacha20poly1305(key).decrypt(
109
- nonce,
110
- encrypted,
111
- null
112
- );
113
-
114
- return new TextDecoder().decode(decrypted);
115
- }
116
-
117
- /**
118
- * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.
119
- *
120
- * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3
121
- *
122
- * @param data - The data to hash.
123
- * @returns The hashed data.
124
- */
125
- export function hash(data: string): string {
126
- return Buffer.from(
127
- blake3(new TextEncoder().encode(data), {
128
- key: ${context.config.crypto.salt ? `hexToBytes("${context.config.crypto.salt}")` : "new TextEncoder().encode(\"powerlines\")"})
129
- })
130
- ).toString("hex");
131
- }
132
-
133
- // Export noble cipher and hash functions for advanced usage
134
-
135
- export * from "@noble/ciphers/chacha.js";
136
- export * from "@noble/ciphers/aes.js";
137
- export * from "@noble/ciphers/utils.js";
138
- export * from '@noble/hashes/blake3.js';
139
- export * from '@noble/hashes/pbkdf2.js';
140
- export * from '@noble/hashes/scrypt.js';
141
- export * from '@noble/hashes/utils.js';
142
-
143
- `;
144
- }
145
-
146
- //#endregion
147
- export { cryptoModule };
148
- //# sourceMappingURL=crypto.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto.mjs","names":[],"sources":[],"mappings":""}