@powerlines/plugin-crypto 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-crypto",
3
- "version": "0.2.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,11 +116,11 @@
116
116
  "files": ["dist/**/*"],
117
117
  "keywords": ["powerlines", "storm-software", "powerlines-plugin"],
118
118
  "dependencies": {
119
- "@powerlines/plugin-env": "^0.4.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
126
  "@powerlines/nx": "^0.5.0",
@@ -128,5 +128,5 @@
128
128
  "@types/node": "^22.18.12"
129
129
  },
130
130
  "publishConfig": { "access": "public" },
131
- "gitHead": "56dc46d2a2d16d8b13be33fadb90e0e0c328baee"
131
+ "gitHead": "8ec5ff52ffc87cfbf2807e077209ea5745a95d43"
132
132
  }
@@ -1,141 +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 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
- ${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
- import { blake3 } from "@noble/hashes/blake3.js";
20
-
21
- const CIPHER_KEY_LENGTH = 32; // https://stackoverflow.com/a/28307668/4397028
22
- const CIPHER_NONCE_LENGTH = 24;
23
-
24
- const nonce = randomBytes(CIPHER_NONCE_LENGTH);
25
- const chacha = xchacha20poly1305("${e.env.parsed.ENCRYPTION_KEY}", nonce);
26
-
27
- /**
28
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
29
- *
30
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
31
- *
32
- * @param plaintext - The data to encrypt.
33
- * @returns The encrypted data.
34
- */
35
- export function encrypt(plaintext: string): string {
36
- return chacha.encrypt(
37
- nonce,
38
- new TextEncoder().encode(plaintext),
39
- null
40
- );
41
- }
42
-
43
- /**
44
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
45
- *
46
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
47
- *
48
- * @param encrypted - The encrypted data to decrypt.
49
- * @returns The decrypted data.
50
- */
51
- export function decrypt(encrypted: string): string {
52
- const decrypted = chacha.decrypt(
53
- nonce,
54
- encrypted,
55
- null
56
- );
57
-
58
- return new TextDecoder().decode(decrypted);
59
- }
60
-
61
- /**
62
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
63
- *
64
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
65
- *
66
- * @param password - The password used to derive the encryption key.
67
- * @param plaintext - The data to encrypt.
68
- * @returns The encrypted data.
69
- */
70
- export function encryptWithPassword(password: string, plaintext: string): string {
71
- const key = scrypt(
72
- new TextEncoder().encode(password),
73
- ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
74
- 1048576, // requires 1GB of RAM to calculate
75
- 8,
76
- 1,
77
- CIPHER_KEY_LENGTH
78
- );
79
-
80
- return chacha20poly1305(key).encrypt(
81
- nonce,
82
- new TextEncoder().encode(plaintext),
83
- null
84
- );
85
- }
86
-
87
- /**
88
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
89
- *
90
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
91
- *
92
- * @param password - The password used to derive the decryption key.
93
- * @param encrypted - The encrypted data to decrypt.
94
- * @returns The decrypted data.
95
- */
96
- export function decryptWithPassword(password: string, encrypted: string): string {
97
- const key = scrypt(
98
- new TextEncoder().encode(password),
99
- ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
100
- 1048576, // requires 1GB of RAM to calculate
101
- 8,
102
- 1,
103
- CIPHER_KEY_LENGTH
104
- );
105
-
106
- const decrypted = chacha20poly1305(key).decrypt(
107
- nonce,
108
- encrypted,
109
- null
110
- );
111
-
112
- return new TextDecoder().decode(decrypted);
113
- }
114
-
115
- /**
116
- * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.
117
- *
118
- * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3
119
- *
120
- * @param data - The data to hash.
121
- * @returns The hashed data.
122
- */
123
- export function hash(data: string): string {
124
- return Buffer.from(
125
- blake3(new TextEncoder().encode(data), {
126
- key: new TextEncoder().encode(${e.config.crypto.salt?e.config.crypto.salt:"powerlines"})
127
- })
128
- ).toString("hex");
129
- }
130
-
131
- // Export noble cipher and hash functions for advanced usage
132
-
133
- export * from "@noble/ciphers/chacha.js";
134
- export * from "@noble/ciphers/aes.js";
135
- export * from "@noble/ciphers/utils.js";
136
- export * from '@noble/hashes/blake3.js';
137
- export * from '@noble/hashes/pbkdf2.js';
138
- export * from '@noble/hashes/scrypt.js';
139
- export * from '@noble/hashes/utils.js';
140
-
141
- `}t(h,"cryptoModule");exports.cryptoModule=h;
@@ -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,141 +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 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
- ${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
- import { blake3 } from "@noble/hashes/blake3.js";
20
-
21
- const CIPHER_KEY_LENGTH = 32; // https://stackoverflow.com/a/28307668/4397028
22
- const CIPHER_NONCE_LENGTH = 24;
23
-
24
- const nonce = randomBytes(CIPHER_NONCE_LENGTH);
25
- const chacha = xchacha20poly1305("${e.env.parsed.ENCRYPTION_KEY}", nonce);
26
-
27
- /**
28
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
29
- *
30
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
31
- *
32
- * @param plaintext - The data to encrypt.
33
- * @returns The encrypted data.
34
- */
35
- export function encrypt(plaintext: string): string {
36
- return chacha.encrypt(
37
- nonce,
38
- new TextEncoder().encode(plaintext),
39
- null
40
- );
41
- }
42
-
43
- /**
44
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
45
- *
46
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
47
- *
48
- * @param encrypted - The encrypted data to decrypt.
49
- * @returns The decrypted data.
50
- */
51
- export function decrypt(encrypted: string): string {
52
- const decrypted = chacha.decrypt(
53
- nonce,
54
- encrypted,
55
- null
56
- );
57
-
58
- return new TextDecoder().decode(decrypted);
59
- }
60
-
61
- /**
62
- * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
63
- *
64
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
65
- *
66
- * @param password - The password used to derive the encryption key.
67
- * @param plaintext - The data to encrypt.
68
- * @returns The encrypted data.
69
- */
70
- export function encryptWithPassword(password: string, plaintext: string): string {
71
- const key = scrypt(
72
- new TextEncoder().encode(password),
73
- ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
74
- 1048576, // requires 1GB of RAM to calculate
75
- 8,
76
- 1,
77
- CIPHER_KEY_LENGTH
78
- );
79
-
80
- return chacha20poly1305(key).encrypt(
81
- nonce,
82
- new TextEncoder().encode(plaintext),
83
- null
84
- );
85
- }
86
-
87
- /**
88
- * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
89
- *
90
- * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
91
- *
92
- * @param password - The password used to derive the decryption key.
93
- * @param encrypted - The encrypted data to decrypt.
94
- * @returns The decrypted data.
95
- */
96
- export function decryptWithPassword(password: string, encrypted: string): string {
97
- const key = scrypt(
98
- new TextEncoder().encode(password),
99
- ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
100
- 1048576, // requires 1GB of RAM to calculate
101
- 8,
102
- 1,
103
- CIPHER_KEY_LENGTH
104
- );
105
-
106
- const decrypted = chacha20poly1305(key).decrypt(
107
- nonce,
108
- encrypted,
109
- null
110
- );
111
-
112
- return new TextDecoder().decode(decrypted);
113
- }
114
-
115
- /**
116
- * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.
117
- *
118
- * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3
119
- *
120
- * @param data - The data to hash.
121
- * @returns The hashed data.
122
- */
123
- export function hash(data: string): string {
124
- return Buffer.from(
125
- blake3(new TextEncoder().encode(data), {
126
- key: new TextEncoder().encode(${e.config.crypto.salt?e.config.crypto.salt:"powerlines"})
127
- })
128
- ).toString("hex");
129
- }
130
-
131
- // Export noble cipher and hash functions for advanced usage
132
-
133
- export * from "@noble/ciphers/chacha.js";
134
- export * from "@noble/ciphers/aes.js";
135
- export * from "@noble/ciphers/utils.js";
136
- export * from '@noble/hashes/blake3.js';
137
- export * from '@noble/hashes/pbkdf2.js';
138
- export * from '@noble/hashes/scrypt.js';
139
- export * from '@noble/hashes/utils.js';
140
-
141
- `}t(d,"cryptoModule");export{d 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';