@powerlines/plugin-crypto 0.10.108 → 0.10.110

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.
Files changed (178) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  2. package/dist/components/crypto.cjs +147 -0
  3. package/dist/components/crypto.d.cts +13 -0
  4. package/dist/components/crypto.d.mts +13 -0
  5. package/dist/components/crypto.mjs +147 -0
  6. package/dist/components/index.cjs +1 -0
  7. package/dist/components/index.d.cts +1 -0
  8. package/dist/components/index.d.mts +1 -0
  9. package/dist/components/index.mjs +3 -0
  10. package/dist/deepkit/schemas/reflection.cjs +3998 -0
  11. package/dist/deepkit/schemas/reflection.d.cts +1560 -0
  12. package/dist/deepkit/schemas/reflection.d.mts +1560 -0
  13. package/dist/deepkit/schemas/reflection.mjs +3996 -0
  14. package/dist/deepkit/schemas/reflection2.cjs +4112 -0
  15. package/dist/deepkit/schemas/reflection2.mjs +4110 -0
  16. package/dist/deepkit/src/capnp.cjs +913 -0
  17. package/dist/deepkit/src/capnp.mjs +911 -0
  18. package/dist/deepkit/src/esbuild-plugin.cjs +47 -0
  19. package/dist/deepkit/src/esbuild-plugin.mjs +46 -0
  20. package/dist/deepkit/src/reflect-type.cjs +22 -0
  21. package/dist/deepkit/src/reflect-type.mjs +20 -0
  22. package/dist/deepkit/src/resolve-reflections.cjs +16 -0
  23. package/dist/deepkit/src/resolve-reflections.mjs +15 -0
  24. package/dist/deepkit/src/transformer.cjs +52 -0
  25. package/dist/deepkit/src/transformer.mjs +49 -0
  26. package/dist/deepkit/src/transpile.cjs +29 -0
  27. package/dist/deepkit/src/transpile.mjs +27 -0
  28. package/dist/deepkit/src/types.d.cts +10 -0
  29. package/dist/deepkit/src/types.d.mts +10 -0
  30. package/dist/deepkit/src/utilities.cjs +66 -0
  31. package/dist/deepkit/src/utilities.mjs +65 -0
  32. package/dist/index.cjs +8 -12056
  33. package/dist/index.d.cts +5 -12
  34. package/dist/index.d.mts +5 -12
  35. package/dist/index.mjs +3 -12018
  36. package/dist/plugin-alloy/src/core/components/output.cjs +38 -0
  37. package/dist/plugin-alloy/src/core/components/output.mjs +37 -0
  38. package/dist/plugin-alloy/src/core/components/single-line-comment.cjs +20 -0
  39. package/dist/plugin-alloy/src/core/components/single-line-comment.mjs +19 -0
  40. package/dist/plugin-alloy/src/core/components/source-file.cjs +60 -0
  41. package/dist/plugin-alloy/src/core/components/source-file.mjs +58 -0
  42. package/dist/plugin-alloy/src/core/contexts/context.cjs +60 -0
  43. package/dist/plugin-alloy/src/core/contexts/context.mjs +54 -0
  44. package/dist/plugin-alloy/src/core/contexts/index.cjs +2 -0
  45. package/dist/plugin-alloy/src/core/contexts/index.mjs +4 -0
  46. package/dist/plugin-alloy/src/core/contexts/reflection.cjs +46 -0
  47. package/dist/plugin-alloy/src/core/contexts/reflection.mjs +42 -0
  48. package/dist/plugin-alloy/src/helpers/refkey.cjs +16 -0
  49. package/dist/plugin-alloy/src/helpers/refkey.mjs +15 -0
  50. package/dist/plugin-alloy/src/index.cjs +96 -0
  51. package/dist/plugin-alloy/src/index.mjs +94 -0
  52. package/dist/plugin-alloy/src/markdown/components/markdown-file.cjs +7 -0
  53. package/dist/plugin-alloy/src/markdown/components/markdown-file.mjs +9 -0
  54. package/dist/plugin-alloy/src/markdown/components/markdown-table.cjs +5 -0
  55. package/dist/plugin-alloy/src/markdown/components/markdown-table.mjs +7 -0
  56. package/dist/plugin-alloy/src/markdown/contexts/markdown-table.cjs +17 -0
  57. package/dist/plugin-alloy/src/markdown/contexts/markdown-table.mjs +17 -0
  58. package/dist/plugin-alloy/src/types/components.d.mts +3 -0
  59. package/dist/plugin-alloy/src/types/index.d.mts +2 -0
  60. package/dist/plugin-alloy/src/types/plugin.d.cts +37 -0
  61. package/dist/plugin-alloy/src/types/plugin.d.mts +37 -0
  62. package/dist/plugin-alloy/src/typescript/components/builtin-file.cjs +47 -0
  63. package/dist/plugin-alloy/src/typescript/components/builtin-file.mjs +46 -0
  64. package/dist/plugin-alloy/src/typescript/components/tsdoc-reflection.cjs +75 -0
  65. package/dist/plugin-alloy/src/typescript/components/tsdoc-reflection.mjs +73 -0
  66. package/dist/plugin-alloy/src/typescript/components/tsdoc.cjs +359 -0
  67. package/dist/plugin-alloy/src/typescript/components/tsdoc.mjs +350 -0
  68. package/dist/plugin-alloy/src/typescript/components/typescript-file.cjs +143 -0
  69. package/dist/plugin-alloy/src/typescript/components/typescript-file.mjs +140 -0
  70. package/dist/plugin-alloy/src/typescript/components/typescript-interface.cjs +53 -0
  71. package/dist/plugin-alloy/src/typescript/components/typescript-interface.mjs +52 -0
  72. package/dist/plugin-alloy/src/typescript/components/typescript-object.cjs +94 -0
  73. package/dist/plugin-alloy/src/typescript/components/typescript-object.mjs +93 -0
  74. package/dist/plugin-automd/src/index.cjs +101 -0
  75. package/dist/plugin-automd/src/index.mjs +98 -0
  76. package/dist/plugin-automd/src/types/plugin.d.cts +38 -0
  77. package/dist/plugin-automd/src/types/plugin.d.mts +40 -0
  78. package/dist/plugin-automd/src/types/toc.d.cts +33 -0
  79. package/dist/plugin-automd/src/types/toc.d.mts +33 -0
  80. package/dist/plugin-babel/src/helpers/ast-utils.cjs +10 -0
  81. package/dist/plugin-babel/src/helpers/ast-utils.mjs +9 -0
  82. package/dist/plugin-babel/src/helpers/create-plugin.cjs +41 -0
  83. package/dist/plugin-babel/src/helpers/create-plugin.mjs +39 -0
  84. package/dist/plugin-babel/src/helpers/filters.cjs +23 -0
  85. package/dist/plugin-babel/src/helpers/filters.mjs +21 -0
  86. package/dist/plugin-babel/src/helpers/index.cjs +5 -0
  87. package/dist/plugin-babel/src/helpers/index.mjs +7 -0
  88. package/dist/plugin-babel/src/helpers/module-helpers.cjs +38 -0
  89. package/dist/plugin-babel/src/helpers/module-helpers.mjs +35 -0
  90. package/dist/plugin-babel/src/helpers/options.cjs +50 -0
  91. package/dist/plugin-babel/src/helpers/options.mjs +47 -0
  92. package/dist/plugin-babel/src/index.cjs +91 -0
  93. package/dist/plugin-babel/src/index.mjs +89 -0
  94. package/dist/plugin-babel/src/types/index.d.mts +1 -0
  95. package/dist/plugin-babel/src/types/plugin.d.cts +15 -0
  96. package/dist/plugin-babel/src/types/plugin.d.mts +15 -0
  97. package/dist/plugin-env/src/babel/index.cjs +1 -0
  98. package/dist/plugin-env/src/babel/index.mjs +3 -0
  99. package/dist/plugin-env/src/babel/plugin.cjs +121 -0
  100. package/dist/plugin-env/src/babel/plugin.mjs +119 -0
  101. package/dist/plugin-env/src/components/docs.cjs +9 -0
  102. package/dist/plugin-env/src/components/docs.mjs +11 -0
  103. package/dist/plugin-env/src/components/env.cjs +487 -0
  104. package/dist/plugin-env/src/components/env.mjs +484 -0
  105. package/dist/plugin-env/src/components/index.cjs +2 -0
  106. package/dist/plugin-env/src/components/index.mjs +4 -0
  107. package/dist/plugin-env/src/helpers/automd-generator.cjs +22 -0
  108. package/dist/plugin-env/src/helpers/automd-generator.mjs +21 -0
  109. package/dist/plugin-env/src/helpers/create-reflection-resource.cjs +55 -0
  110. package/dist/plugin-env/src/helpers/create-reflection-resource.mjs +54 -0
  111. package/dist/plugin-env/src/helpers/index.cjs +6 -0
  112. package/dist/plugin-env/src/helpers/index.mjs +8 -0
  113. package/dist/plugin-env/src/helpers/load.cjs +83 -0
  114. package/dist/plugin-env/src/helpers/load.mjs +80 -0
  115. package/dist/plugin-env/src/helpers/persistence.cjs +199 -0
  116. package/dist/plugin-env/src/helpers/persistence.mjs +188 -0
  117. package/dist/plugin-env/src/helpers/reflect.cjs +125 -0
  118. package/dist/plugin-env/src/helpers/reflect.mjs +117 -0
  119. package/dist/plugin-env/src/helpers/source-file-env.cjs +24 -0
  120. package/dist/plugin-env/src/helpers/source-file-env.mjs +23 -0
  121. package/dist/plugin-env/src/helpers/template-helpers.cjs +2 -0
  122. package/dist/plugin-env/src/helpers/template-helpers.mjs +4 -0
  123. package/dist/plugin-env/src/index.cjs +172 -0
  124. package/dist/plugin-env/src/index.mjs +170 -0
  125. package/dist/plugin-env/src/types/plugin.d.cts +151 -0
  126. package/dist/plugin-env/src/types/plugin.d.mts +153 -0
  127. package/dist/plugin-env/src/types/runtime.d.cts +792 -0
  128. package/dist/plugin-env/src/types/runtime.d.mts +792 -0
  129. package/dist/powerlines/src/lib/build/esbuild.cjs +102 -0
  130. package/dist/powerlines/src/lib/build/esbuild.mjs +100 -0
  131. package/dist/powerlines/src/lib/entry.cjs +12 -0
  132. package/dist/powerlines/src/lib/entry.mjs +14 -0
  133. package/dist/powerlines/src/lib/logger.cjs +41 -0
  134. package/dist/powerlines/src/lib/logger.mjs +39 -0
  135. package/dist/powerlines/src/lib/utilities/bundle.cjs +35 -0
  136. package/dist/powerlines/src/lib/utilities/bundle.mjs +34 -0
  137. package/dist/powerlines/src/lib/utilities/file-header.cjs +22 -0
  138. package/dist/powerlines/src/lib/utilities/file-header.mjs +21 -0
  139. package/dist/powerlines/src/lib/utilities/resolve.cjs +30 -0
  140. package/dist/powerlines/src/lib/utilities/resolve.mjs +29 -0
  141. package/dist/powerlines/src/plugin-utils/paths.cjs +1 -0
  142. package/dist/powerlines/src/plugin-utils/paths.mjs +3 -0
  143. package/dist/powerlines/src/types/babel.d.cts +22 -0
  144. package/dist/powerlines/src/types/babel.d.mts +22 -0
  145. package/dist/powerlines/src/types/build.d.cts +145 -0
  146. package/dist/powerlines/src/types/build.d.mts +147 -0
  147. package/dist/powerlines/src/types/commands.d.cts +8 -0
  148. package/dist/powerlines/src/types/commands.d.mts +9 -0
  149. package/dist/powerlines/src/types/config.d.cts +387 -0
  150. package/dist/powerlines/src/types/config.d.mts +388 -0
  151. package/dist/powerlines/src/types/context.d.cts +414 -0
  152. package/dist/powerlines/src/types/context.d.mts +416 -0
  153. package/dist/powerlines/src/types/fs.d.cts +486 -0
  154. package/dist/powerlines/src/types/fs.d.mts +486 -0
  155. package/dist/powerlines/src/types/hooks.d.mts +2 -0
  156. package/dist/powerlines/src/types/plugin.d.cts +231 -0
  157. package/dist/powerlines/src/types/plugin.d.mts +231 -0
  158. package/dist/powerlines/src/types/resolved.d.cts +82 -0
  159. package/dist/powerlines/src/types/resolved.d.mts +83 -0
  160. package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
  161. package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
  162. package/dist/types/index.cjs +0 -2
  163. package/dist/types/index.d.cts +1 -2
  164. package/dist/types/index.d.mts +1 -2
  165. package/dist/types/index.mjs +0 -3
  166. package/dist/types/plugin.cjs +0 -1
  167. package/dist/types/plugin.d.cts +41 -1
  168. package/dist/types/plugin.d.mts +41 -1
  169. package/dist/types/plugin.mjs +0 -2
  170. package/package.json +5 -5
  171. package/dist/index-BgAdqTbb.d.mts +0 -1
  172. package/dist/index-CEgs-Dz2.d.cts +0 -1
  173. package/dist/plugin-C3MaN5jp.mjs +0 -1
  174. package/dist/plugin-DHXHjv16.cjs +0 -0
  175. package/dist/plugin-Dhgjf-aI.d.mts +0 -4441
  176. package/dist/plugin-Dw1wCT6b.d.cts +0 -4438
  177. package/dist/types-CTUnla4x.mjs +0 -1
  178. package/dist/types-DHkg7xmX.cjs +0 -0
@@ -0,0 +1,29 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -0,0 +1,147 @@
1
+ const require_file_header = require('../powerlines/src/lib/utilities/file-header.cjs');
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.output.builtinPrefix}:crypto
16
+ */
17
+
18
+ ${require_file_header.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
+ ${context.config.crypto.encryptionKey ? `
25
+ 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;
@@ -0,0 +1,13 @@
1
+ import { CryptoPluginContext } from "../types/plugin.cjs";
2
+
3
+ //#region src/components/crypto.d.ts
4
+
5
+ /**
6
+ * Generates the crypto module content.
7
+ *
8
+ * @param context - The build context containing runtime information.
9
+ * @returns A string representing the crypto module code.
10
+ */
11
+ declare function cryptoModule(context: CryptoPluginContext): string;
12
+ //#endregion
13
+ export { cryptoModule };
@@ -0,0 +1,13 @@
1
+ import { CryptoPluginContext } from "../types/plugin.mjs";
2
+
3
+ //#region src/components/crypto.d.ts
4
+
5
+ /**
6
+ * Generates the crypto module content.
7
+ *
8
+ * @param context - The build context containing runtime information.
9
+ * @returns A string representing the crypto module code.
10
+ */
11
+ declare function cryptoModule(context: CryptoPluginContext): string;
12
+ //#endregion
13
+ export { cryptoModule };
@@ -0,0 +1,147 @@
1
+ import { getFileHeader } from "../powerlines/src/lib/utilities/file-header.mjs";
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.output.builtinPrefix}: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
+ ${context.config.crypto.encryptionKey ? `
25
+ 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 };
@@ -0,0 +1 @@
1
+ const require_crypto = require('./crypto.cjs');
@@ -0,0 +1 @@
1
+ import { cryptoModule } from "./crypto.cjs";
@@ -0,0 +1 @@
1
+ import { cryptoModule } from "./crypto.mjs";
@@ -0,0 +1,3 @@
1
+ import { cryptoModule } from "./crypto.mjs";
2
+
3
+ export { };