@powerlines/plugin-crypto 0.10.491 → 0.10.493
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/dist/_virtual/_rolldown/runtime.cjs +29 -1
- package/dist/components/crypto.cjs +25 -10
- package/dist/components/crypto.mjs +24 -10
- package/dist/components/crypto.mjs.map +1 -1
- package/dist/components/index.cjs +1 -1
- package/dist/components/index.mjs +3 -1
- package/dist/index.cjs +45 -1
- package/dist/index.mjs +39 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.mjs +1 -1
- package/package.json +5 -5
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
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;
|
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
require(
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let powerlines_utils = require("powerlines/utils");
|
|
3
|
+
|
|
4
|
+
//#region src/components/crypto.ts
|
|
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
|
+
function cryptoModule(context) {
|
|
12
|
+
return `
|
|
2
13
|
/**
|
|
3
14
|
* The cryptography module provides custom helper functions to support encrypting and decrypting data.
|
|
4
15
|
*
|
|
5
|
-
* @module ${
|
|
16
|
+
* @module ${context.config.framework}:crypto
|
|
6
17
|
*/
|
|
7
18
|
|
|
8
|
-
${(0,
|
|
19
|
+
${(0, powerlines_utils.getFileHeader)(context)}
|
|
9
20
|
|
|
10
21
|
import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
11
22
|
import { randomBytes, managedNonce, hexToBytes } from "@noble/ciphers/utils.js";
|
|
12
23
|
import { scrypt } from "@noble/hashes/scrypt.js";
|
|
13
24
|
import { blake3 } from "@noble/hashes/blake3.js";
|
|
14
|
-
${
|
|
25
|
+
${context.config.crypto.encryptionKey ? `
|
|
15
26
|
const nonce = randomBytes(24);
|
|
16
|
-
const chacha = xchacha20poly1305(hexToBytes("${
|
|
27
|
+
const chacha = xchacha20poly1305(hexToBytes("${context.config.crypto.encryptionKey}"), nonce);
|
|
17
28
|
|
|
18
29
|
/**
|
|
19
30
|
* Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
|
|
@@ -48,7 +59,7 @@ export function decrypt(encrypted: string): string {
|
|
|
48
59
|
|
|
49
60
|
return new TextDecoder().decode(decrypted);
|
|
50
61
|
}
|
|
51
|
-
|
|
62
|
+
` : ""}
|
|
52
63
|
|
|
53
64
|
/**
|
|
54
65
|
* Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
|
|
@@ -62,7 +73,7 @@ export function decrypt(encrypted: string): string {
|
|
|
62
73
|
export function encryptWithPassword(password: string, plaintext: string): string {
|
|
63
74
|
const key = scrypt(
|
|
64
75
|
new TextEncoder().encode(password),
|
|
65
|
-
hexToBytes("${
|
|
76
|
+
hexToBytes("${context.config.crypto.salt ? context.config.crypto.salt : "nonce"}"),
|
|
66
77
|
1048576, // requires 1GB of RAM to calculate
|
|
67
78
|
8,
|
|
68
79
|
1,
|
|
@@ -88,7 +99,7 @@ export function encryptWithPassword(password: string, plaintext: string): string
|
|
|
88
99
|
export function decryptWithPassword(password: string, encrypted: string): string {
|
|
89
100
|
const key = scrypt(
|
|
90
101
|
new TextEncoder().encode(password),
|
|
91
|
-
hexToBytes("${
|
|
102
|
+
hexToBytes("${context.config.crypto.salt ? context.config.crypto.salt : "nonce"}"),
|
|
92
103
|
1048576, // requires 1GB of RAM to calculate
|
|
93
104
|
8,
|
|
94
105
|
1,
|
|
@@ -115,7 +126,7 @@ export function decryptWithPassword(password: string, encrypted: string): string
|
|
|
115
126
|
export function hash(data: string): string {
|
|
116
127
|
return Buffer.from(
|
|
117
128
|
blake3(new TextEncoder().encode(data), {
|
|
118
|
-
key: ${
|
|
129
|
+
key: ${context.config.crypto.salt ? `hexToBytes("${context.config.crypto.salt}")` : "new TextEncoder().encode(\"powerlines\")"})
|
|
119
130
|
})
|
|
120
131
|
).toString("hex");
|
|
121
132
|
}
|
|
@@ -130,4 +141,8 @@ export * from '@noble/hashes/pbkdf2.js';
|
|
|
130
141
|
export * from '@noble/hashes/scrypt.js';
|
|
131
142
|
export * from '@noble/hashes/utils.js';
|
|
132
143
|
|
|
133
|
-
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
exports.cryptoModule = cryptoModule;
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import{getFileHeader
|
|
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 `
|
|
2
12
|
/**
|
|
3
13
|
* The cryptography module provides custom helper functions to support encrypting and decrypting data.
|
|
4
14
|
*
|
|
5
|
-
* @module ${
|
|
15
|
+
* @module ${context.config.framework}:crypto
|
|
6
16
|
*/
|
|
7
17
|
|
|
8
|
-
${
|
|
18
|
+
${getFileHeader(context)}
|
|
9
19
|
|
|
10
20
|
import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
11
21
|
import { randomBytes, managedNonce, hexToBytes } from "@noble/ciphers/utils.js";
|
|
12
22
|
import { scrypt } from "@noble/hashes/scrypt.js";
|
|
13
23
|
import { blake3 } from "@noble/hashes/blake3.js";
|
|
14
|
-
${
|
|
24
|
+
${context.config.crypto.encryptionKey ? `
|
|
15
25
|
const nonce = randomBytes(24);
|
|
16
|
-
const chacha = xchacha20poly1305(hexToBytes("${
|
|
26
|
+
const chacha = xchacha20poly1305(hexToBytes("${context.config.crypto.encryptionKey}"), nonce);
|
|
17
27
|
|
|
18
28
|
/**
|
|
19
29
|
* Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
|
|
@@ -48,7 +58,7 @@ export function decrypt(encrypted: string): string {
|
|
|
48
58
|
|
|
49
59
|
return new TextDecoder().decode(decrypted);
|
|
50
60
|
}
|
|
51
|
-
|
|
61
|
+
` : ""}
|
|
52
62
|
|
|
53
63
|
/**
|
|
54
64
|
* Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
|
|
@@ -62,7 +72,7 @@ export function decrypt(encrypted: string): string {
|
|
|
62
72
|
export function encryptWithPassword(password: string, plaintext: string): string {
|
|
63
73
|
const key = scrypt(
|
|
64
74
|
new TextEncoder().encode(password),
|
|
65
|
-
hexToBytes("${
|
|
75
|
+
hexToBytes("${context.config.crypto.salt ? context.config.crypto.salt : "nonce"}"),
|
|
66
76
|
1048576, // requires 1GB of RAM to calculate
|
|
67
77
|
8,
|
|
68
78
|
1,
|
|
@@ -88,7 +98,7 @@ export function encryptWithPassword(password: string, plaintext: string): string
|
|
|
88
98
|
export function decryptWithPassword(password: string, encrypted: string): string {
|
|
89
99
|
const key = scrypt(
|
|
90
100
|
new TextEncoder().encode(password),
|
|
91
|
-
hexToBytes("${
|
|
101
|
+
hexToBytes("${context.config.crypto.salt ? context.config.crypto.salt : "nonce"}"),
|
|
92
102
|
1048576, // requires 1GB of RAM to calculate
|
|
93
103
|
8,
|
|
94
104
|
1,
|
|
@@ -115,7 +125,7 @@ export function decryptWithPassword(password: string, encrypted: string): string
|
|
|
115
125
|
export function hash(data: string): string {
|
|
116
126
|
return Buffer.from(
|
|
117
127
|
blake3(new TextEncoder().encode(data), {
|
|
118
|
-
key: ${
|
|
128
|
+
key: ${context.config.crypto.salt ? `hexToBytes("${context.config.crypto.salt}")` : "new TextEncoder().encode(\"powerlines\")"})
|
|
119
129
|
})
|
|
120
130
|
).toString("hex");
|
|
121
131
|
}
|
|
@@ -130,5 +140,9 @@ export * from '@noble/hashes/pbkdf2.js';
|
|
|
130
140
|
export * from '@noble/hashes/scrypt.js';
|
|
131
141
|
export * from '@noble/hashes/utils.js';
|
|
132
142
|
|
|
133
|
-
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
export { cryptoModule };
|
|
134
148
|
//# sourceMappingURL=crypto.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.mjs","names":[],"sources":["../../src/components/crypto.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getFileHeader } from \"powerlines/utils\";\nimport { CryptoPluginContext } from \"../types/plugin\";\n\n/**\n * Generates the crypto module content.\n *\n * @param context - The build context containing runtime information.\n * @returns A string representing the crypto module code.\n */\nexport function cryptoModule(context: CryptoPluginContext) {\n return `\n/**\n * The cryptography module provides custom helper functions to support encrypting and decrypting data.\n *\n * @module ${context.config.framework}:crypto\n */\n\n${getFileHeader(context)}\n\nimport { xchacha20poly1305, chacha20poly1305 } from \"@noble/ciphers/chacha.js\";\nimport { randomBytes, managedNonce, hexToBytes } from \"@noble/ciphers/utils.js\";\nimport { scrypt } from \"@noble/hashes/scrypt.js\";\nimport { blake3 } from \"@noble/hashes/blake3.js\";\n${\n context.config.crypto.encryptionKey\n ? `\nconst nonce = randomBytes(24);\nconst chacha = xchacha20poly1305(hexToBytes(\"${\n context.config.crypto.encryptionKey\n }\"), nonce);\n\n/**\n * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param plaintext - The data to encrypt.\n * @returns The encrypted data.\n */\nexport function encrypt(plaintext: string): string {\n return chacha.encrypt(\n nonce,\n new TextEncoder().encode(plaintext),\n null\n );\n}\n\n/**\n * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param encrypted - The encrypted data to decrypt.\n * @returns The decrypted data.\n */\nexport function decrypt(encrypted: string): string {\n const decrypted = chacha.decrypt(\n nonce,\n encrypted,\n null\n );\n\n return new TextDecoder().decode(decrypted);\n}\n`\n : \"\"\n}\n\n/**\n * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param password - The password used to derive the encryption key.\n * @param plaintext - The data to encrypt.\n * @returns The encrypted data.\n */\nexport function encryptWithPassword(password: string, plaintext: string): string {\n const key = scrypt(\n new TextEncoder().encode(password),\n hexToBytes(\"${context.config.crypto.salt ? context.config.crypto.salt : \"nonce\"}\"),\n 1048576, // requires 1GB of RAM to calculate\n 8,\n 1,\n 32\n );\n\n return chacha20poly1305(key).encrypt(\n nonce,\n new TextEncoder().encode(plaintext),\n null\n );\n}\n\n/**\n * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param password - The password used to derive the decryption key.\n * @param encrypted - The encrypted data to decrypt.\n * @returns The decrypted data.\n */\nexport function decryptWithPassword(password: string, encrypted: string): string {\n const key = scrypt(\n new TextEncoder().encode(password),\n hexToBytes(\"${context.config.crypto.salt ? context.config.crypto.salt : \"nonce\"}\"),\n 1048576, // requires 1GB of RAM to calculate\n 8,\n 1,\n 32\n );\n\n const decrypted = chacha20poly1305(key).decrypt(\n nonce,\n encrypted,\n null\n );\n\n return new TextDecoder().decode(decrypted);\n}\n\n/**\n * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.\n *\n * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3\n *\n * @param data - The data to hash.\n * @returns The hashed data.\n */\nexport function hash(data: string): string {\n return Buffer.from(\n blake3(new TextEncoder().encode(data), {\n key: ${\n context.config.crypto.salt\n ? `hexToBytes(\"${context.config.crypto.salt}\")`\n : 'new TextEncoder().encode(\"powerlines\")'\n })\n })\n ).toString(\"hex\");\n}\n\n// Export noble cipher and hash functions for advanced usage\n\nexport * from \"@noble/ciphers/chacha.js\";\nexport * from \"@noble/ciphers/aes.js\";\nexport * from \"@noble/ciphers/utils.js\";\nexport * from '@noble/hashes/blake3.js';\nexport * from '@noble/hashes/pbkdf2.js';\nexport * from '@noble/hashes/scrypt.js';\nexport * from '@noble/hashes/utils.js';\n\n`;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto.mjs","names":[],"sources":["../../src/components/crypto.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getFileHeader } from \"powerlines/utils\";\nimport { CryptoPluginContext } from \"../types/plugin\";\n\n/**\n * Generates the crypto module content.\n *\n * @param context - The build context containing runtime information.\n * @returns A string representing the crypto module code.\n */\nexport function cryptoModule(context: CryptoPluginContext) {\n return `\n/**\n * The cryptography module provides custom helper functions to support encrypting and decrypting data.\n *\n * @module ${context.config.framework}:crypto\n */\n\n${getFileHeader(context)}\n\nimport { xchacha20poly1305, chacha20poly1305 } from \"@noble/ciphers/chacha.js\";\nimport { randomBytes, managedNonce, hexToBytes } from \"@noble/ciphers/utils.js\";\nimport { scrypt } from \"@noble/hashes/scrypt.js\";\nimport { blake3 } from \"@noble/hashes/blake3.js\";\n${\n context.config.crypto.encryptionKey\n ? `\nconst nonce = randomBytes(24);\nconst chacha = xchacha20poly1305(hexToBytes(\"${\n context.config.crypto.encryptionKey\n }\"), nonce);\n\n/**\n * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param plaintext - The data to encrypt.\n * @returns The encrypted data.\n */\nexport function encrypt(plaintext: string): string {\n return chacha.encrypt(\n nonce,\n new TextEncoder().encode(plaintext),\n null\n );\n}\n\n/**\n * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param encrypted - The encrypted data to decrypt.\n * @returns The decrypted data.\n */\nexport function decrypt(encrypted: string): string {\n const decrypted = chacha.decrypt(\n nonce,\n encrypted,\n null\n );\n\n return new TextDecoder().decode(decrypted);\n}\n`\n : \"\"\n}\n\n/**\n * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param password - The password used to derive the encryption key.\n * @param plaintext - The data to encrypt.\n * @returns The encrypted data.\n */\nexport function encryptWithPassword(password: string, plaintext: string): string {\n const key = scrypt(\n new TextEncoder().encode(password),\n hexToBytes(\"${context.config.crypto.salt ? context.config.crypto.salt : \"nonce\"}\"),\n 1048576, // requires 1GB of RAM to calculate\n 8,\n 1,\n 32\n );\n\n return chacha20poly1305(key).encrypt(\n nonce,\n new TextEncoder().encode(plaintext),\n null\n );\n}\n\n/**\n * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param password - The password used to derive the decryption key.\n * @param encrypted - The encrypted data to decrypt.\n * @returns The decrypted data.\n */\nexport function decryptWithPassword(password: string, encrypted: string): string {\n const key = scrypt(\n new TextEncoder().encode(password),\n hexToBytes(\"${context.config.crypto.salt ? context.config.crypto.salt : \"nonce\"}\"),\n 1048576, // requires 1GB of RAM to calculate\n 8,\n 1,\n 32\n );\n\n const decrypted = chacha20poly1305(key).decrypt(\n nonce,\n encrypted,\n null\n );\n\n return new TextDecoder().decode(decrypted);\n}\n\n/**\n * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.\n *\n * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3\n *\n * @param data - The data to hash.\n * @returns The hashed data.\n */\nexport function hash(data: string): string {\n return Buffer.from(\n blake3(new TextEncoder().encode(data), {\n key: ${\n context.config.crypto.salt\n ? `hexToBytes(\"${context.config.crypto.salt}\")`\n : 'new TextEncoder().encode(\"powerlines\")'\n })\n })\n ).toString(\"hex\");\n}\n\n// Export noble cipher and hash functions for advanced usage\n\nexport * from \"@noble/ciphers/chacha.js\";\nexport * from \"@noble/ciphers/aes.js\";\nexport * from \"@noble/ciphers/utils.js\";\nexport * from '@noble/hashes/blake3.js';\nexport * from '@noble/hashes/pbkdf2.js';\nexport * from '@noble/hashes/scrypt.js';\nexport * from '@noble/hashes/utils.js';\n\n`;\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,aAAa,SAA8B;AACzD,QAAO;;;;aAII,QAAQ,OAAO,UAAU;;;EAGpC,cAAc,QAAQ,CAAC;;;;;;EAOvB,QAAQ,OAAO,OAAO,gBAClB;;+CAGE,QAAQ,OAAO,OAAO,cACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoCD,GACL;;;;;;;;;;;;;;kBAciB,QAAQ,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;kBA0BlE,QAAQ,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;aA4B5E,QAAQ,OAAO,OAAO,OAClB,eAAe,QAAQ,OAAO,OAAO,KAAK,MAC1C,2CACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(
|
|
1
|
+
const require_crypto = require('./crypto.cjs');
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,45 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_crypto = require('./components/crypto.cjs');
|
|
4
|
+
require('./components/index.cjs');
|
|
5
|
+
let _noble_ciphers_utils_js = require("@noble/ciphers/utils.js");
|
|
6
|
+
let _powerlines_plugin_env = require("@powerlines/plugin-env");
|
|
7
|
+
_powerlines_plugin_env = require_runtime.__toESM(_powerlines_plugin_env, 1);
|
|
8
|
+
let defu = require("defu");
|
|
9
|
+
defu = require_runtime.__toESM(defu, 1);
|
|
10
|
+
|
|
11
|
+
//#region src/index.ts
|
|
12
|
+
/**
|
|
13
|
+
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
14
|
+
*/
|
|
15
|
+
function plugin(options = {}) {
|
|
16
|
+
return [(0, _powerlines_plugin_env.default)(options.env), {
|
|
17
|
+
name: "crypto",
|
|
18
|
+
config() {
|
|
19
|
+
return { crypto: (0, defu.default)(options, { salt: `${(this.config.name ?? this.packageJson?.name) || "powerlines"}-application` }) };
|
|
20
|
+
},
|
|
21
|
+
configResolved() {
|
|
22
|
+
this.dependencies["@noble/ciphers"] = "^2.0.1";
|
|
23
|
+
this.dependencies["@noble/hashes"] = "^2.0.1";
|
|
24
|
+
this.config.crypto.salt ??= this.env.parsed.SALT;
|
|
25
|
+
if (!this.config.crypto.salt) {
|
|
26
|
+
this.warn(`No salt provided to the Crypto plugin - a salt value will be generated automatically. Please note: It's highly recommended to provide a unique salt value via the \`salt\` plugin option or the \`SALT\` environment variable.`);
|
|
27
|
+
this.config.crypto.salt = (0, _noble_ciphers_utils_js.bytesToHex)((0, _noble_ciphers_utils_js.randomBytes)(12));
|
|
28
|
+
}
|
|
29
|
+
this.config.crypto.encryptionKey ??= this.env.parsed.ENCRYPTION_KEY;
|
|
30
|
+
if (!this.config.crypto.encryptionKey) {
|
|
31
|
+
this.warn(`No encryption key provided to the Crypto plugin - a secure key will be generated automatically. Please note: it's highly recommended to provide a secure encryption key via the \`encryptionKey\` plugin option or the \`ENCRYPTION_KEY\` environment variable.`);
|
|
32
|
+
this.config.crypto.encryptionKey = (0, _noble_ciphers_utils_js.bytesToHex)((0, _noble_ciphers_utils_js.randomBytes)(32));
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
async prepare() {
|
|
36
|
+
this.debug(`Preparing the Crypto runtime artifacts for the Powerlines project.`);
|
|
37
|
+
await this.emitBuiltin(await Promise.resolve(require_crypto.cryptoModule(this)), "crypto");
|
|
38
|
+
}
|
|
39
|
+
}];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.cryptoModule = require_crypto.cryptoModule;
|
|
44
|
+
exports.default = plugin;
|
|
45
|
+
exports.plugin = plugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
import{cryptoModule
|
|
1
|
+
import { cryptoModule } from "./components/crypto.mjs";
|
|
2
|
+
import "./components/index.mjs";
|
|
3
|
+
import { bytesToHex, randomBytes } from "@noble/ciphers/utils.js";
|
|
4
|
+
import env from "@powerlines/plugin-env";
|
|
5
|
+
import defu from "defu";
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
10
|
+
*/
|
|
11
|
+
function plugin(options = {}) {
|
|
12
|
+
return [env(options.env), {
|
|
13
|
+
name: "crypto",
|
|
14
|
+
config() {
|
|
15
|
+
return { crypto: defu(options, { salt: `${(this.config.name ?? this.packageJson?.name) || "powerlines"}-application` }) };
|
|
16
|
+
},
|
|
17
|
+
configResolved() {
|
|
18
|
+
this.dependencies["@noble/ciphers"] = "^2.0.1";
|
|
19
|
+
this.dependencies["@noble/hashes"] = "^2.0.1";
|
|
20
|
+
this.config.crypto.salt ??= this.env.parsed.SALT;
|
|
21
|
+
if (!this.config.crypto.salt) {
|
|
22
|
+
this.warn(`No salt provided to the Crypto plugin - a salt value will be generated automatically. Please note: It's highly recommended to provide a unique salt value via the \`salt\` plugin option or the \`SALT\` environment variable.`);
|
|
23
|
+
this.config.crypto.salt = bytesToHex(randomBytes(12));
|
|
24
|
+
}
|
|
25
|
+
this.config.crypto.encryptionKey ??= this.env.parsed.ENCRYPTION_KEY;
|
|
26
|
+
if (!this.config.crypto.encryptionKey) {
|
|
27
|
+
this.warn(`No encryption key provided to the Crypto plugin - a secure key will be generated automatically. Please note: it's highly recommended to provide a secure encryption key via the \`encryptionKey\` plugin option or the \`ENCRYPTION_KEY\` environment variable.`);
|
|
28
|
+
this.config.crypto.encryptionKey = bytesToHex(randomBytes(32));
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
async prepare() {
|
|
32
|
+
this.debug(`Preparing the Crypto runtime artifacts for the Powerlines project.`);
|
|
33
|
+
await this.emitBuiltin(await Promise.resolve(cryptoModule(this)), "crypto");
|
|
34
|
+
}
|
|
35
|
+
}];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { cryptoModule, plugin as default, plugin };
|
|
2
40
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { bytesToHex, randomBytes } from \"@noble/ciphers/utils.js\";\nimport env from \"@powerlines/plugin-env\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { cryptoModule } from \"./components/crypto\";\nimport { CryptoPluginContext, CryptoPluginOptions } from \"./types/plugin\";\n\nexport * from \"./components\";\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n crypto?: CryptoPluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CryptoPluginContext = CryptoPluginContext\n>(options: CryptoPluginOptions = {}) {\n return [\n env(options.env),\n {\n name: \"crypto\",\n config() {\n return {\n crypto: defu(options, {\n salt: `${(this.config.name ?? this.packageJson?.name) || \"powerlines\"}-application`\n })\n };\n },\n configResolved() {\n this.dependencies[\"@noble/ciphers\"] = \"^2.0.1\";\n this.dependencies[\"@noble/hashes\"] = \"^2.0.1\";\n\n this.config.crypto.salt ??= this.env.parsed.SALT!;\n if (!this.config.crypto.salt) {\n this.warn(\n `No salt provided to the Crypto plugin - a salt value will be generated automatically. Please note: It's highly recommended to provide a unique salt value via the \\`salt\\` plugin option or the \\`SALT\\` environment variable.`\n );\n\n this.config.crypto.salt = bytesToHex(randomBytes(12));\n }\n\n this.config.crypto.encryptionKey ??= this.env.parsed.ENCRYPTION_KEY!;\n if (!this.config.crypto.encryptionKey) {\n this.warn(\n `No encryption key provided to the Crypto plugin - a secure key will be generated automatically. Please note: it's highly recommended to provide a secure encryption key via the \\`encryptionKey\\` plugin option or the \\`ENCRYPTION_KEY\\` environment variable.`\n );\n\n this.config.crypto.encryptionKey = bytesToHex(randomBytes(32));\n }\n },\n async prepare() {\n this.debug(\n `Preparing the Crypto runtime artifacts for the Powerlines project.`\n );\n\n await this.emitBuiltin(\n await Promise.resolve(cryptoModule(this)),\n \"crypto\"\n );\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { bytesToHex, randomBytes } from \"@noble/ciphers/utils.js\";\nimport env from \"@powerlines/plugin-env\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { cryptoModule } from \"./components/crypto\";\nimport { CryptoPluginContext, CryptoPluginOptions } from \"./types/plugin\";\n\nexport * from \"./components\";\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n crypto?: CryptoPluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CryptoPluginContext = CryptoPluginContext\n>(options: CryptoPluginOptions = {}) {\n return [\n env(options.env),\n {\n name: \"crypto\",\n config() {\n return {\n crypto: defu(options, {\n salt: `${(this.config.name ?? this.packageJson?.name) || \"powerlines\"}-application`\n })\n };\n },\n configResolved() {\n this.dependencies[\"@noble/ciphers\"] = \"^2.0.1\";\n this.dependencies[\"@noble/hashes\"] = \"^2.0.1\";\n\n this.config.crypto.salt ??= this.env.parsed.SALT!;\n if (!this.config.crypto.salt) {\n this.warn(\n `No salt provided to the Crypto plugin - a salt value will be generated automatically. Please note: It's highly recommended to provide a unique salt value via the \\`salt\\` plugin option or the \\`SALT\\` environment variable.`\n );\n\n this.config.crypto.salt = bytesToHex(randomBytes(12));\n }\n\n this.config.crypto.encryptionKey ??= this.env.parsed.ENCRYPTION_KEY!;\n if (!this.config.crypto.encryptionKey) {\n this.warn(\n `No encryption key provided to the Crypto plugin - a secure key will be generated automatically. Please note: it's highly recommended to provide a secure encryption key via the \\`encryptionKey\\` plugin option or the \\`ENCRYPTION_KEY\\` environment variable.`\n );\n\n this.config.crypto.encryptionKey = bytesToHex(randomBytes(32));\n }\n },\n async prepare() {\n this.debug(\n `Preparing the Crypto runtime artifacts for the Powerlines project.`\n );\n\n await this.emitBuiltin(\n await Promise.resolve(cryptoModule(this)),\n \"crypto\"\n );\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;AAqCA,SAAgB,OAEd,UAA+B,EAAE,EAAE;AACnC,QAAO,CACL,IAAI,QAAQ,IAAI,EAChB;EACE,MAAM;EACN,SAAS;AACP,UAAO,EACL,QAAQ,KAAK,SAAS,EACpB,MAAM,IAAI,KAAK,OAAO,QAAQ,KAAK,aAAa,SAAS,aAAa,eACvE,CAAC,EACH;;EAEH,iBAAiB;AACf,QAAK,aAAa,oBAAoB;AACtC,QAAK,aAAa,mBAAmB;AAErC,QAAK,OAAO,OAAO,SAAS,KAAK,IAAI,OAAO;AAC5C,OAAI,CAAC,KAAK,OAAO,OAAO,MAAM;AAC5B,SAAK,KACH,iOACD;AAED,SAAK,OAAO,OAAO,OAAO,WAAW,YAAY,GAAG,CAAC;;AAGvD,QAAK,OAAO,OAAO,kBAAkB,KAAK,IAAI,OAAO;AACrD,OAAI,CAAC,KAAK,OAAO,OAAO,eAAe;AACrC,SAAK,KACH,kQACD;AAED,SAAK,OAAO,OAAO,gBAAgB,WAAW,YAAY,GAAG,CAAC;;;EAGlE,MAAM,UAAU;AACd,QAAK,MACH,qEACD;AAED,SAAM,KAAK,YACT,MAAM,QAAQ,QAAQ,aAAa,KAAK,CAAC,EACzC,SACD;;EAEJ,CACF"}
|
package/dist/types/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export { };
|
package/dist/types/plugin.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-crypto",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.493",
|
|
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": {
|
|
@@ -87,19 +87,19 @@
|
|
|
87
87
|
"keywords": ["powerlines", "storm-software", "powerlines-plugin"],
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@noble/ciphers": "^2.2.0",
|
|
90
|
-
"@powerlines/plugin-env": "^0.16.
|
|
90
|
+
"@powerlines/plugin-env": "^0.16.184",
|
|
91
91
|
"@storm-software/config-tools": "^1.190.1",
|
|
92
92
|
"@stryke/path": "^0.28.2",
|
|
93
93
|
"defu": "^6.1.7",
|
|
94
|
-
"powerlines": "^0.46.
|
|
94
|
+
"powerlines": "^0.46.5"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
97
|
+
"@powerlines/plugin-plugin": "^0.12.409",
|
|
98
98
|
"@types/node": "^25.6.0"
|
|
99
99
|
},
|
|
100
100
|
"publishConfig": { "access": "public" },
|
|
101
101
|
"main": "./dist/index.cjs",
|
|
102
102
|
"module": "./dist/index.mjs",
|
|
103
103
|
"types": "./dist/index.d.cts",
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "9af888c54e58a82744cc334a6b80da52429fa0ac"
|
|
105
105
|
}
|