@powerlines/plugin-crypto 0.1.0 → 0.3.0

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/README.md CHANGED
@@ -47,6 +47,13 @@ This package is part of the ⚡<b>Powerlines</b> monorepo. Powerlines packages i
47
47
 
48
48
  A Powerlines plugin that provides cryptography capabilities at runtime by adding the `crypto` builtin module.
49
49
 
50
+ Since cryptography is such a complex and nuanced topic, this plugin relies on the noble cryptography packages since they are audited for security and written in pure TypeScript.
51
+
52
+ The noble packages used can be found below:
53
+
54
+ - [`@noble/ciphers`](https://www.npmjs.com/package/@noble/ciphers)
55
+ - [`@noble/hashes`](https://www.npmjs.com/package/@noble/hashes)
56
+
50
57
  <!-- START doctoc -->
51
58
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
52
59
  ## Table of Contents
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-crypto",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
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": {
@@ -116,17 +116,17 @@
116
116
  "files": ["dist/**/*"],
117
117
  "keywords": ["powerlines", "storm-software", "powerlines-plugin"],
118
118
  "dependencies": {
119
- "@powerlines/plugin-env": "^0.3.0",
119
+ "@powerlines/plugin-env": "^0.5.0",
120
120
  "@storm-software/config-tools": "^1.188.6",
121
- "@stryke/path": "^0.15.5",
121
+ "@stryke/path": "^0.16.0",
122
122
  "defu": "^6.1.4",
123
- "powerlines": "^0.4.0"
123
+ "powerlines": "^0.5.0"
124
124
  },
125
125
  "devDependencies": {
126
- "@powerlines/nx": "^0.4.0",
126
+ "@powerlines/nx": "^0.5.0",
127
127
  "@storm-software/tsup": "^0.2.4",
128
- "@types/node": "^22.18.11"
128
+ "@types/node": "^22.18.12"
129
129
  },
130
130
  "publishConfig": { "access": "public" },
131
- "gitHead": "f4d0c8a8f0036ac8de46ac96afd9336a390a7268"
131
+ "gitHead": "8ec5ff52ffc87cfbf2807e077209ea5745a95d43"
132
132
  }
@@ -1,117 +0,0 @@
1
- 'use strict';var fileHeader=require('powerlines/lib/utilities/file-header');/*****************************************
2
- *
3
- * ⚡ Built by Storm Software
4
- *
5
- *****************************************/
6
-
7
- var a=Object.defineProperty;var t=(e,r)=>a(e,"name",{value:r,configurable:true});function d(e){return `
8
- /**
9
- * The cryptography module provides custom helper functions to support encrypting and decrypting data.
10
- *
11
- * @module ${e.config.output.builtinPrefix}:crypto
12
- */
13
-
14
- ${fileHeader.getFileHeader(e)}
15
-
16
- import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
17
- import { randomBytes, managedNonce } from "@noble/ciphers/utils.js";
18
- import { scrypt } from "@noble/hashes/scrypt.js";
19
-
20
- const CIPHER_KEY_LENGTH = 32; // https://stackoverflow.com/a/28307668/4397028
21
- const CIPHER_NONCE_LENGTH = 24;
22
-
23
- const nonce = randomBytes(CIPHER_NONCE_LENGTH);
24
- const chacha = xchacha20poly1305("${e.env.parsed.ENCRYPTION_KEY}", nonce);
25
-
26
- /**
27
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
28
- *
29
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
30
- *
31
- * @param plaintext - The data to encrypt.
32
- * @returns The encrypted data.
33
- */
34
- export function encrypt(plaintext: string): string {
35
- return chacha.encrypt(
36
- nonce,
37
- new TextEncoder().encode(plaintext),
38
- null
39
- );
40
- }
41
-
42
- /**
43
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
44
- *
45
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
46
- *
47
- * @param encrypted - The encrypted data to decrypt.
48
- * @returns The decrypted data.
49
- */
50
- export function decrypt(encrypted: string): string {
51
- const decrypted = chacha.decrypt(
52
- nonce,
53
- encrypted,
54
- null
55
- );
56
-
57
- return new TextDecoder().decode(decrypted);
58
- }
59
-
60
- export * from "@noble/ciphers/chacha.js";
61
- export * from "@noble/ciphers/utils.js";
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
- ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
76
- 1048576, // requires 1GB of RAM to calculate
77
- 8,
78
- 1,
79
- CIPHER_KEY_LENGTH
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
- ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
102
- 1048576, // requires 1GB of RAM to calculate
103
- 8,
104
- 1,
105
- CIPHER_KEY_LENGTH
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
- `}t(d,"cryptoModule");exports.cryptoModule=d;
@@ -1,35 +0,0 @@
1
- import { CryptoPluginContext } from '../types/plugin.cjs';
2
- import '@alloy-js/core/jsx-runtime';
3
- import '@babel/core';
4
- import '@storm-software/build-tools/types';
5
- import '@storm-software/config-tools/types';
6
- import '@storm-software/config/types';
7
- import '@stryke/types/configuration';
8
- import '@stryke/types/file';
9
- import 'vite';
10
- import '@babel/helper-plugin-utils';
11
- import '@stryke/env/get-env-paths';
12
- import '@stryke/types/package-json';
13
- import 'jiti';
14
- import '@deepkit/type';
15
- import 'semver';
16
- import 'unplugin';
17
- import '@stryke/capnp';
18
- import '@stryke/types/base';
19
- import '@stryke/types/tsconfig';
20
- import 'typescript';
21
- import 'memfs';
22
- import 'node:fs';
23
- import 'unionfs';
24
- import '@stryke/types/array';
25
- import '@stryke/env/types';
26
-
27
- /**
28
- * Generates the crypto module content.
29
- *
30
- * @param context - The build context containing runtime information.
31
- * @returns A string representing the crypto module code.
32
- */
33
- declare function cryptoModule(context: CryptoPluginContext): string;
34
-
35
- export { cryptoModule };
@@ -1,35 +0,0 @@
1
- import { CryptoPluginContext } from '../types/plugin.js';
2
- import '@alloy-js/core/jsx-runtime';
3
- import '@babel/core';
4
- import '@storm-software/build-tools/types';
5
- import '@storm-software/config-tools/types';
6
- import '@storm-software/config/types';
7
- import '@stryke/types/configuration';
8
- import '@stryke/types/file';
9
- import 'vite';
10
- import '@babel/helper-plugin-utils';
11
- import '@stryke/env/get-env-paths';
12
- import '@stryke/types/package-json';
13
- import 'jiti';
14
- import '@deepkit/type';
15
- import 'semver';
16
- import 'unplugin';
17
- import '@stryke/capnp';
18
- import '@stryke/types/base';
19
- import '@stryke/types/tsconfig';
20
- import 'typescript';
21
- import 'memfs';
22
- import 'node:fs';
23
- import 'unionfs';
24
- import '@stryke/types/array';
25
- import '@stryke/env/types';
26
-
27
- /**
28
- * Generates the crypto module content.
29
- *
30
- * @param context - The build context containing runtime information.
31
- * @returns A string representing the crypto module code.
32
- */
33
- declare function cryptoModule(context: CryptoPluginContext): string;
34
-
35
- export { cryptoModule };
@@ -1,117 +0,0 @@
1
- import {getFileHeader}from'powerlines/lib/utilities/file-header';/*****************************************
2
- *
3
- * ⚡ Built by Storm Software
4
- *
5
- *****************************************/
6
-
7
- var a=Object.defineProperty;var t=(e,r)=>a(e,"name",{value:r,configurable:true});function h(e){return `
8
- /**
9
- * The cryptography module provides custom helper functions to support encrypting and decrypting data.
10
- *
11
- * @module ${e.config.output.builtinPrefix}:crypto
12
- */
13
-
14
- ${getFileHeader(e)}
15
-
16
- import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
17
- import { randomBytes, managedNonce } from "@noble/ciphers/utils.js";
18
- import { scrypt } from "@noble/hashes/scrypt.js";
19
-
20
- const CIPHER_KEY_LENGTH = 32; // https://stackoverflow.com/a/28307668/4397028
21
- const CIPHER_NONCE_LENGTH = 24;
22
-
23
- const nonce = randomBytes(CIPHER_NONCE_LENGTH);
24
- const chacha = xchacha20poly1305("${e.env.parsed.ENCRYPTION_KEY}", nonce);
25
-
26
- /**
27
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
28
- *
29
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
30
- *
31
- * @param plaintext - The data to encrypt.
32
- * @returns The encrypted data.
33
- */
34
- export function encrypt(plaintext: string): string {
35
- return chacha.encrypt(
36
- nonce,
37
- new TextEncoder().encode(plaintext),
38
- null
39
- );
40
- }
41
-
42
- /**
43
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
44
- *
45
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
46
- *
47
- * @param encrypted - The encrypted data to decrypt.
48
- * @returns The decrypted data.
49
- */
50
- export function decrypt(encrypted: string): string {
51
- const decrypted = chacha.decrypt(
52
- nonce,
53
- encrypted,
54
- null
55
- );
56
-
57
- return new TextDecoder().decode(decrypted);
58
- }
59
-
60
- export * from "@noble/ciphers/chacha.js";
61
- export * from "@noble/ciphers/utils.js";
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
- ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
76
- 1048576, // requires 1GB of RAM to calculate
77
- 8,
78
- 1,
79
- CIPHER_KEY_LENGTH
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
- ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
102
- 1048576, // requires 1GB of RAM to calculate
103
- 8,
104
- 1,
105
- CIPHER_KEY_LENGTH
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
- `}t(h,"cryptoModule");export{h as cryptoModule};
@@ -1 +0,0 @@
1
- 'use strict';var crypto=require('./crypto');Object.keys(crypto).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return crypto[k]}})});
@@ -1,26 +0,0 @@
1
- export { cryptoModule } from './crypto.cjs';
2
- import '../types/plugin.cjs';
3
- import '@alloy-js/core/jsx-runtime';
4
- import '@babel/core';
5
- import '@storm-software/build-tools/types';
6
- import '@storm-software/config-tools/types';
7
- import '@storm-software/config/types';
8
- import '@stryke/types/configuration';
9
- import '@stryke/types/file';
10
- import 'vite';
11
- import '@babel/helper-plugin-utils';
12
- import '@stryke/env/get-env-paths';
13
- import '@stryke/types/package-json';
14
- import 'jiti';
15
- import '@deepkit/type';
16
- import 'semver';
17
- import 'unplugin';
18
- import '@stryke/capnp';
19
- import '@stryke/types/base';
20
- import '@stryke/types/tsconfig';
21
- import 'typescript';
22
- import 'memfs';
23
- import 'node:fs';
24
- import 'unionfs';
25
- import '@stryke/types/array';
26
- import '@stryke/env/types';
@@ -1,26 +0,0 @@
1
- export { cryptoModule } from './crypto.js';
2
- import '../types/plugin.js';
3
- import '@alloy-js/core/jsx-runtime';
4
- import '@babel/core';
5
- import '@storm-software/build-tools/types';
6
- import '@storm-software/config-tools/types';
7
- import '@storm-software/config/types';
8
- import '@stryke/types/configuration';
9
- import '@stryke/types/file';
10
- import 'vite';
11
- import '@babel/helper-plugin-utils';
12
- import '@stryke/env/get-env-paths';
13
- import '@stryke/types/package-json';
14
- import 'jiti';
15
- import '@deepkit/type';
16
- import 'semver';
17
- import 'unplugin';
18
- import '@stryke/capnp';
19
- import '@stryke/types/base';
20
- import '@stryke/types/tsconfig';
21
- import 'typescript';
22
- import 'memfs';
23
- import 'node:fs';
24
- import 'unionfs';
25
- import '@stryke/types/array';
26
- import '@stryke/env/types';
@@ -1 +0,0 @@
1
- export*from'./crypto';
@@ -1 +0,0 @@
1
- 'use strict';var plugin=require('./plugin');Object.keys(plugin).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return plugin[k]}})});
@@ -1,25 +0,0 @@
1
- export { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig, __ΩCryptoPluginContext, __ΩCryptoPluginOptions, __ΩCryptoPluginResolvedConfig, __ΩCryptoPluginUserConfig } from './plugin.cjs';
2
- import '@alloy-js/core/jsx-runtime';
3
- import '@babel/core';
4
- import '@storm-software/build-tools/types';
5
- import '@storm-software/config-tools/types';
6
- import '@storm-software/config/types';
7
- import '@stryke/types/configuration';
8
- import '@stryke/types/file';
9
- import 'vite';
10
- import '@babel/helper-plugin-utils';
11
- import '@stryke/env/get-env-paths';
12
- import '@stryke/types/package-json';
13
- import 'jiti';
14
- import '@deepkit/type';
15
- import 'semver';
16
- import 'unplugin';
17
- import '@stryke/capnp';
18
- import '@stryke/types/base';
19
- import '@stryke/types/tsconfig';
20
- import 'typescript';
21
- import 'memfs';
22
- import 'node:fs';
23
- import 'unionfs';
24
- import '@stryke/types/array';
25
- import '@stryke/env/types';
@@ -1,25 +0,0 @@
1
- export { CryptoPluginContext, CryptoPluginOptions, CryptoPluginResolvedConfig, CryptoPluginUserConfig, __ΩCryptoPluginContext, __ΩCryptoPluginOptions, __ΩCryptoPluginResolvedConfig, __ΩCryptoPluginUserConfig } from './plugin.js';
2
- import '@alloy-js/core/jsx-runtime';
3
- import '@babel/core';
4
- import '@storm-software/build-tools/types';
5
- import '@storm-software/config-tools/types';
6
- import '@storm-software/config/types';
7
- import '@stryke/types/configuration';
8
- import '@stryke/types/file';
9
- import 'vite';
10
- import '@babel/helper-plugin-utils';
11
- import '@stryke/env/get-env-paths';
12
- import '@stryke/types/package-json';
13
- import 'jiti';
14
- import '@deepkit/type';
15
- import 'semver';
16
- import 'unplugin';
17
- import '@stryke/capnp';
18
- import '@stryke/types/base';
19
- import '@stryke/types/tsconfig';
20
- import 'typescript';
21
- import 'memfs';
22
- import 'node:fs';
23
- import 'unionfs';
24
- import '@stryke/types/array';
25
- import '@stryke/env/types';
@@ -1 +0,0 @@
1
- export*from'./plugin';
@@ -1 +0,0 @@
1
- 'use strict';