@powerlines/plugin-crypto 0.9.8 → 0.9.9

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.
@@ -0,0 +1,7 @@
1
+ 'use strict';/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ var c=Object.defineProperty;var d=(a,b)=>c(a,"name",{value:b,configurable:true});exports.a=d;
@@ -0,0 +1,7 @@
1
+ /*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ var c=Object.defineProperty;var d=(a,b)=>c(a,"name",{value:b,configurable:true});export{d as a};
@@ -0,0 +1,139 @@
1
+ 'use strict';var chunkFBBMZ4NC_cjs=require('../chunk-FBBMZ4NC.cjs'),fileHeader=require('powerlines/lib/utilities/file-header');/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ function i(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
+ ${e.config.crypto.encryptionKey?`
21
+ const nonce = randomBytes(24);
22
+ const chacha = xchacha20poly1305(new TextEncoder().encode("${e.config.crypto.encryptionKey}"), nonce);
23
+
24
+ /**
25
+ * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
26
+ *
27
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
28
+ *
29
+ * @param plaintext - The data to encrypt.
30
+ * @returns The encrypted data.
31
+ */
32
+ export function encrypt(plaintext: string): string {
33
+ return chacha.encrypt(
34
+ nonce,
35
+ new TextEncoder().encode(plaintext),
36
+ null
37
+ );
38
+ }
39
+
40
+ /**
41
+ * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
42
+ *
43
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
44
+ *
45
+ * @param encrypted - The encrypted data to decrypt.
46
+ * @returns The decrypted data.
47
+ */
48
+ export function decrypt(encrypted: string): string {
49
+ const decrypted = chacha.decrypt(
50
+ nonce,
51
+ encrypted,
52
+ null
53
+ );
54
+
55
+ return new TextDecoder().decode(decrypted);
56
+ }
57
+ `:""}
58
+
59
+ /**
60
+ * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
61
+ *
62
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
63
+ *
64
+ * @param password - The password used to derive the encryption key.
65
+ * @param plaintext - The data to encrypt.
66
+ * @returns The encrypted data.
67
+ */
68
+ export function encryptWithPassword(password: string, plaintext: string): string {
69
+ const key = scrypt(
70
+ new TextEncoder().encode(password),
71
+ ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
72
+ 1048576, // requires 1GB of RAM to calculate
73
+ 8,
74
+ 1,
75
+ 32
76
+ );
77
+
78
+ return chacha20poly1305(key).encrypt(
79
+ nonce,
80
+ new TextEncoder().encode(plaintext),
81
+ null
82
+ );
83
+ }
84
+
85
+ /**
86
+ * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
87
+ *
88
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
89
+ *
90
+ * @param password - The password used to derive the decryption key.
91
+ * @param encrypted - The encrypted data to decrypt.
92
+ * @returns The decrypted data.
93
+ */
94
+ export function decryptWithPassword(password: string, encrypted: string): string {
95
+ const key = scrypt(
96
+ new TextEncoder().encode(password),
97
+ ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
98
+ 1048576, // requires 1GB of RAM to calculate
99
+ 8,
100
+ 1,
101
+ 32
102
+ );
103
+
104
+ const decrypted = chacha20poly1305(key).decrypt(
105
+ nonce,
106
+ encrypted,
107
+ null
108
+ );
109
+
110
+ return new TextDecoder().decode(decrypted);
111
+ }
112
+
113
+ /**
114
+ * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.
115
+ *
116
+ * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3
117
+ *
118
+ * @param data - The data to hash.
119
+ * @returns The hashed data.
120
+ */
121
+ export function hash(data: string): string {
122
+ return Buffer.from(
123
+ blake3(new TextEncoder().encode(data), {
124
+ key: new TextEncoder().encode(${e.config.crypto.salt?e.config.crypto.salt:"powerlines"})
125
+ })
126
+ ).toString("hex");
127
+ }
128
+
129
+ // Export noble cipher and hash functions for advanced usage
130
+
131
+ export * from "@noble/ciphers/chacha.js";
132
+ export * from "@noble/ciphers/aes.js";
133
+ export * from "@noble/ciphers/utils.js";
134
+ export * from '@noble/hashes/blake3.js';
135
+ export * from '@noble/hashes/pbkdf2.js';
136
+ export * from '@noble/hashes/scrypt.js';
137
+ export * from '@noble/hashes/utils.js';
138
+
139
+ `}chunkFBBMZ4NC_cjs.a(i,"cryptoModule");exports.cryptoModule=i;
@@ -0,0 +1,37 @@
1
+ import { a as CryptoPluginContext } from '../index-DHmlsdWC.cjs';
2
+ import '@alloy-js/core/jsx-runtime';
3
+ import '@deepkit/type';
4
+ import '@stryke/capnp';
5
+ import '@babel/core';
6
+ import '@storm-software/build-tools/types';
7
+ import '@storm-software/config-tools/types';
8
+ import '@storm-software/config/types';
9
+ import '@stryke/types/base';
10
+ import '@stryke/types/configuration';
11
+ import '@stryke/types/file';
12
+ import 'vite';
13
+ import '@babel/helper-plugin-utils';
14
+ import '@stryke/env/get-env-paths';
15
+ import '@stryke/types/package-json';
16
+ import 'jiti';
17
+ import 'oxc-parser';
18
+ import 'semver';
19
+ import 'unplugin';
20
+ import '@stryke/types/tsconfig';
21
+ import 'typescript';
22
+ import '@stryke/json/types';
23
+ import 'memfs';
24
+ import 'node:fs';
25
+ import 'unionfs';
26
+ import '@stryke/types/array';
27
+ import '@stryke/env/types';
28
+
29
+ /**
30
+ * Generates the crypto module content.
31
+ *
32
+ * @param context - The build context containing runtime information.
33
+ * @returns A string representing the crypto module code.
34
+ */
35
+ declare function cryptoModule(context: CryptoPluginContext): string;
36
+
37
+ export { cryptoModule };
@@ -0,0 +1,37 @@
1
+ import { a as CryptoPluginContext } from '../index-DHmlsdWC.js';
2
+ import '@alloy-js/core/jsx-runtime';
3
+ import '@deepkit/type';
4
+ import '@stryke/capnp';
5
+ import '@babel/core';
6
+ import '@storm-software/build-tools/types';
7
+ import '@storm-software/config-tools/types';
8
+ import '@storm-software/config/types';
9
+ import '@stryke/types/base';
10
+ import '@stryke/types/configuration';
11
+ import '@stryke/types/file';
12
+ import 'vite';
13
+ import '@babel/helper-plugin-utils';
14
+ import '@stryke/env/get-env-paths';
15
+ import '@stryke/types/package-json';
16
+ import 'jiti';
17
+ import 'oxc-parser';
18
+ import 'semver';
19
+ import 'unplugin';
20
+ import '@stryke/types/tsconfig';
21
+ import 'typescript';
22
+ import '@stryke/json/types';
23
+ import 'memfs';
24
+ import 'node:fs';
25
+ import 'unionfs';
26
+ import '@stryke/types/array';
27
+ import '@stryke/env/types';
28
+
29
+ /**
30
+ * Generates the crypto module content.
31
+ *
32
+ * @param context - The build context containing runtime information.
33
+ * @returns A string representing the crypto module code.
34
+ */
35
+ declare function cryptoModule(context: CryptoPluginContext): string;
36
+
37
+ export { cryptoModule };
@@ -0,0 +1,139 @@
1
+ import {a}from'../chunk-UCUR73HG.js';import {getFileHeader}from'powerlines/lib/utilities/file-header';/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ function c(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
+ ${e.config.crypto.encryptionKey?`
21
+ const nonce = randomBytes(24);
22
+ const chacha = xchacha20poly1305(new TextEncoder().encode("${e.config.crypto.encryptionKey}"), nonce);
23
+
24
+ /**
25
+ * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
26
+ *
27
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
28
+ *
29
+ * @param plaintext - The data to encrypt.
30
+ * @returns The encrypted data.
31
+ */
32
+ export function encrypt(plaintext: string): string {
33
+ return chacha.encrypt(
34
+ nonce,
35
+ new TextEncoder().encode(plaintext),
36
+ null
37
+ );
38
+ }
39
+
40
+ /**
41
+ * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
42
+ *
43
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
44
+ *
45
+ * @param encrypted - The encrypted data to decrypt.
46
+ * @returns The decrypted data.
47
+ */
48
+ export function decrypt(encrypted: string): string {
49
+ const decrypted = chacha.decrypt(
50
+ nonce,
51
+ encrypted,
52
+ null
53
+ );
54
+
55
+ return new TextDecoder().decode(decrypted);
56
+ }
57
+ `:""}
58
+
59
+ /**
60
+ * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
61
+ *
62
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
63
+ *
64
+ * @param password - The password used to derive the encryption key.
65
+ * @param plaintext - The data to encrypt.
66
+ * @returns The encrypted data.
67
+ */
68
+ export function encryptWithPassword(password: string, plaintext: string): string {
69
+ const key = scrypt(
70
+ new TextEncoder().encode(password),
71
+ ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
72
+ 1048576, // requires 1GB of RAM to calculate
73
+ 8,
74
+ 1,
75
+ 32
76
+ );
77
+
78
+ return chacha20poly1305(key).encrypt(
79
+ nonce,
80
+ new TextEncoder().encode(plaintext),
81
+ null
82
+ );
83
+ }
84
+
85
+ /**
86
+ * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
87
+ *
88
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
89
+ *
90
+ * @param password - The password used to derive the decryption key.
91
+ * @param encrypted - The encrypted data to decrypt.
92
+ * @returns The decrypted data.
93
+ */
94
+ export function decryptWithPassword(password: string, encrypted: string): string {
95
+ const key = scrypt(
96
+ new TextEncoder().encode(password),
97
+ ${e.config.crypto.salt?e.config.crypto.salt:"nonce"},
98
+ 1048576, // requires 1GB of RAM to calculate
99
+ 8,
100
+ 1,
101
+ 32
102
+ );
103
+
104
+ const decrypted = chacha20poly1305(key).decrypt(
105
+ nonce,
106
+ encrypted,
107
+ null
108
+ );
109
+
110
+ return new TextDecoder().decode(decrypted);
111
+ }
112
+
113
+ /**
114
+ * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.
115
+ *
116
+ * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3
117
+ *
118
+ * @param data - The data to hash.
119
+ * @returns The hashed data.
120
+ */
121
+ export function hash(data: string): string {
122
+ return Buffer.from(
123
+ blake3(new TextEncoder().encode(data), {
124
+ key: new TextEncoder().encode(${e.config.crypto.salt?e.config.crypto.salt:"powerlines"})
125
+ })
126
+ ).toString("hex");
127
+ }
128
+
129
+ // Export noble cipher and hash functions for advanced usage
130
+
131
+ export * from "@noble/ciphers/chacha.js";
132
+ export * from "@noble/ciphers/aes.js";
133
+ export * from "@noble/ciphers/utils.js";
134
+ export * from '@noble/hashes/blake3.js';
135
+ export * from '@noble/hashes/pbkdf2.js';
136
+ export * from '@noble/hashes/scrypt.js';
137
+ export * from '@noble/hashes/utils.js';
138
+
139
+ `}a(c,"cryptoModule");export{c as cryptoModule};
@@ -0,0 +1 @@
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]}})});
@@ -0,0 +1,28 @@
1
+ export { cryptoModule } from './crypto.cjs';
2
+ import '../index-DHmlsdWC.cjs';
3
+ import '@alloy-js/core/jsx-runtime';
4
+ import '@deepkit/type';
5
+ import '@stryke/capnp';
6
+ import '@babel/core';
7
+ import '@storm-software/build-tools/types';
8
+ import '@storm-software/config-tools/types';
9
+ import '@storm-software/config/types';
10
+ import '@stryke/types/base';
11
+ import '@stryke/types/configuration';
12
+ import '@stryke/types/file';
13
+ import 'vite';
14
+ import '@babel/helper-plugin-utils';
15
+ import '@stryke/env/get-env-paths';
16
+ import '@stryke/types/package-json';
17
+ import 'jiti';
18
+ import 'oxc-parser';
19
+ import 'semver';
20
+ import 'unplugin';
21
+ import '@stryke/types/tsconfig';
22
+ import 'typescript';
23
+ import '@stryke/json/types';
24
+ import 'memfs';
25
+ import 'node:fs';
26
+ import 'unionfs';
27
+ import '@stryke/types/array';
28
+ import '@stryke/env/types';
@@ -0,0 +1,28 @@
1
+ export { cryptoModule } from './crypto.js';
2
+ import '../index-DHmlsdWC.js';
3
+ import '@alloy-js/core/jsx-runtime';
4
+ import '@deepkit/type';
5
+ import '@stryke/capnp';
6
+ import '@babel/core';
7
+ import '@storm-software/build-tools/types';
8
+ import '@storm-software/config-tools/types';
9
+ import '@storm-software/config/types';
10
+ import '@stryke/types/base';
11
+ import '@stryke/types/configuration';
12
+ import '@stryke/types/file';
13
+ import 'vite';
14
+ import '@babel/helper-plugin-utils';
15
+ import '@stryke/env/get-env-paths';
16
+ import '@stryke/types/package-json';
17
+ import 'jiti';
18
+ import 'oxc-parser';
19
+ import 'semver';
20
+ import 'unplugin';
21
+ import '@stryke/types/tsconfig';
22
+ import 'typescript';
23
+ import '@stryke/json/types';
24
+ import 'memfs';
25
+ import 'node:fs';
26
+ import 'unionfs';
27
+ import '@stryke/types/array';
28
+ import '@stryke/env/types';
@@ -0,0 +1 @@
1
+ export*from'./crypto';