@powerlines/plugin-crypto 0.10.316 → 0.10.318
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/components/crypto.cjs +2 -2
- package/dist/components/crypto.mjs +1 -1
- package/dist/components/crypto.mjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let powerlines_utils = require("powerlines/utils");
|
|
3
3
|
|
|
4
4
|
//#region src/components/crypto.ts
|
|
5
5
|
/**
|
|
@@ -16,7 +16,7 @@ function cryptoModule(context) {
|
|
|
16
16
|
* @module ${context.config.framework}:crypto
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
${(0,
|
|
19
|
+
${(0, powerlines_utils.getFileHeader)(context)}
|
|
20
20
|
|
|
21
21
|
import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
22
22
|
import { randomBytes, managedNonce, hexToBytes } from "@noble/ciphers/utils.js";
|
|
@@ -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/
|
|
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"}
|
package/dist/index.d.cts
CHANGED
|
@@ -2,9 +2,14 @@ import { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, C
|
|
|
2
2
|
import { cryptoModule } from "./components/crypto.cjs";
|
|
3
3
|
import "./components/index.cjs";
|
|
4
4
|
import "./types/index.cjs";
|
|
5
|
-
import { Plugin } from "powerlines
|
|
5
|
+
import { Plugin } from "powerlines";
|
|
6
6
|
|
|
7
7
|
//#region src/index.d.ts
|
|
8
|
+
declare module "powerlines" {
|
|
9
|
+
interface UserConfig {
|
|
10
|
+
crypto?: CryptoPluginOptions;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
8
13
|
/**
|
|
9
14
|
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
10
15
|
*/
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;aA8Ba;EAJW;;;;;AAWR,iBAAA,MAAM,CAAA,iBACH,mBADG,GACmB,mBADnB,CAAA,CAAA,OAAA,CAAA,EAEX,mBAFW,CAAA,EAkDf,MAlDe,CAkDR,QAlDQ,CAAA,EAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -2,9 +2,14 @@ import { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, C
|
|
|
2
2
|
import { cryptoModule } from "./components/crypto.mjs";
|
|
3
3
|
import "./components/index.mjs";
|
|
4
4
|
import "./types/index.mjs";
|
|
5
|
-
import { Plugin } from "powerlines
|
|
5
|
+
import { Plugin } from "powerlines";
|
|
6
6
|
|
|
7
7
|
//#region src/index.d.ts
|
|
8
|
+
declare module "powerlines" {
|
|
9
|
+
interface UserConfig {
|
|
10
|
+
crypto?: CryptoPluginOptions;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
8
13
|
/**
|
|
9
14
|
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
10
15
|
*/
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;aA8Ba;EAJW;;;;;AAWR,iBAAA,MAAM,CAAA,iBACH,mBADG,GACmB,mBADnB,CAAA,CAAA,OAAA,CAAA,EAEX,mBAFW,CAAA,EAkDf,MAlDe,CAkDR,QAlDQ,CAAA,EAAA"}
|
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
|
|
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 export interface UserConfig {\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: `${\n (this.config.name ?? this.workspaceConfig?.name) ||\n this.packageJson?.name\n }-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,IACH,KAAK,OAAO,QAAQ,KAAK,iBAAiB,SAC3C,KAAK,aAAa,KACnB,eACF,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;;AAGH,kBAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-crypto",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.318",
|
|
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,7 +53,7 @@
|
|
|
53
53
|
"default": "./dist/index.mjs"
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
|
-
"
|
|
56
|
+
"./*": "./*",
|
|
57
57
|
"./types": {
|
|
58
58
|
"require": {
|
|
59
59
|
"types": "./dist/types/index.d.cts",
|
|
@@ -87,19 +87,19 @@
|
|
|
87
87
|
"keywords": ["powerlines", "storm-software", "powerlines-plugin"],
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@noble/ciphers": "^2.1.1",
|
|
90
|
-
"@powerlines/plugin-env": "^0.16.
|
|
91
|
-
"@storm-software/config-tools": "^1.189.
|
|
90
|
+
"@powerlines/plugin-env": "^0.16.9",
|
|
91
|
+
"@storm-software/config-tools": "^1.189.10",
|
|
92
92
|
"@stryke/path": "^0.26.6",
|
|
93
93
|
"defu": "^6.1.4",
|
|
94
|
-
"powerlines": "^0.
|
|
94
|
+
"powerlines": "^0.39.1"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
98
|
-
"@types/node": "^25.3.
|
|
97
|
+
"@powerlines/plugin-plugin": "^0.12.243",
|
|
98
|
+
"@types/node": "^25.3.3"
|
|
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": "30a096fed42d3462dbc028b16145250c373f3d99"
|
|
105
105
|
}
|