@powerlines/plugin-crypto 0.10.501 → 0.10.505
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.
|
@@ -13,7 +13,7 @@ function cryptoModule(context) {
|
|
|
13
13
|
/**
|
|
14
14
|
* The cryptography module provides custom helper functions to support encrypting and decrypting data.
|
|
15
15
|
*
|
|
16
|
-
* @module ${context.config.framework}:crypto
|
|
16
|
+
* @module ${context.config.framework?.name || "powerlines"}:crypto
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
${(0, powerlines_utils.getFileHeader)(context)}
|
|
@@ -12,7 +12,7 @@ function cryptoModule(context) {
|
|
|
12
12
|
/**
|
|
13
13
|
* The cryptography module provides custom helper functions to support encrypting and decrypting data.
|
|
14
14
|
*
|
|
15
|
-
* @module ${context.config.framework}:crypto
|
|
15
|
+
* @module ${context.config.framework?.name || "powerlines"}:crypto
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
${getFileHeader(context)}
|
|
@@ -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":";;;;;;;;;AA2BA,SAAgB,aAAa,SAA8B;AACzD,QAAO;;;;aAII,QAAQ,OAAO,
|
|
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?.name || \"powerlines\"}: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,WAAW,QAAQ,aAAa;;;EAG1D,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"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-crypto",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.505",
|
|
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": {
|
|
7
7
|
"type": "github",
|
|
8
8
|
"url": "https://github.com/storm-software/powerlines.git",
|
|
9
|
-
"directory": "packages/plugin-crypto"
|
|
9
|
+
"directory": "packages/plugins/plugin-crypto"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://stormsoftware.com",
|
|
12
12
|
"bugs": {
|
|
@@ -39,67 +39,34 @@
|
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"private": false,
|
|
41
41
|
"exports": {
|
|
42
|
-
".": {
|
|
43
|
-
"require": {
|
|
44
|
-
"types": "./dist/index.d.cts",
|
|
45
|
-
"default": "./dist/index.cjs"
|
|
46
|
-
},
|
|
47
|
-
"import": {
|
|
48
|
-
"types": "./dist/index.d.mts",
|
|
49
|
-
"default": "./dist/index.mjs"
|
|
50
|
-
},
|
|
51
|
-
"default": {
|
|
52
|
-
"types": "./dist/index.d.mts",
|
|
53
|
-
"default": "./dist/index.mjs"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
"./package.json": "./package.json",
|
|
42
|
+
".": { "import": "./dist/index.mjs", "require": "./dist/index.cjs" },
|
|
57
43
|
"./types": {
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
"default": "./dist/types/index.cjs"
|
|
61
|
-
},
|
|
62
|
-
"import": {
|
|
63
|
-
"types": "./dist/types/index.d.mts",
|
|
64
|
-
"default": "./dist/types/index.mjs"
|
|
65
|
-
},
|
|
66
|
-
"default": {
|
|
67
|
-
"types": "./dist/types/index.d.mts",
|
|
68
|
-
"default": "./dist/types/index.mjs"
|
|
69
|
-
}
|
|
44
|
+
"import": "./dist/types/index.mjs",
|
|
45
|
+
"require": "./dist/types/index.cjs"
|
|
70
46
|
},
|
|
71
47
|
"./types/plugin": {
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"import": {
|
|
77
|
-
"types": "./dist/types/plugin.d.mts",
|
|
78
|
-
"default": "./dist/types/plugin.mjs"
|
|
79
|
-
},
|
|
80
|
-
"default": {
|
|
81
|
-
"types": "./dist/types/plugin.d.mts",
|
|
82
|
-
"default": "./dist/types/plugin.mjs"
|
|
83
|
-
}
|
|
84
|
-
}
|
|
48
|
+
"import": "./dist/types/plugin.mjs",
|
|
49
|
+
"require": "./dist/types/plugin.cjs"
|
|
50
|
+
},
|
|
51
|
+
"./package.json": "./package.json"
|
|
85
52
|
},
|
|
86
53
|
"files": ["dist/**/*"],
|
|
87
54
|
"keywords": ["powerlines", "storm-software", "powerlines-plugin"],
|
|
88
55
|
"dependencies": {
|
|
89
56
|
"@noble/ciphers": "^2.2.0",
|
|
90
|
-
"@powerlines/plugin-env": "^0.16.
|
|
91
|
-
"@storm-software/config-tools": "^1.190.
|
|
92
|
-
"@stryke/path": "^0.
|
|
57
|
+
"@powerlines/plugin-env": "^0.16.196",
|
|
58
|
+
"@storm-software/config-tools": "^1.190.2",
|
|
59
|
+
"@stryke/path": "^0.29.2",
|
|
93
60
|
"defu": "^6.1.7",
|
|
94
|
-
"powerlines": "^0.47.
|
|
61
|
+
"powerlines": "^0.47.7"
|
|
95
62
|
},
|
|
96
63
|
"devDependencies": {
|
|
97
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
98
|
-
"@types/node": "^25.
|
|
64
|
+
"@powerlines/plugin-plugin": "^0.12.419",
|
|
65
|
+
"@types/node": "^25.7.0"
|
|
99
66
|
},
|
|
100
67
|
"publishConfig": { "access": "public" },
|
|
101
68
|
"main": "./dist/index.cjs",
|
|
102
69
|
"module": "./dist/index.mjs",
|
|
103
70
|
"types": "./dist/index.d.cts",
|
|
104
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "10ae97e8d61da05b4b1d8791677b0128331b1067"
|
|
105
72
|
}
|