@powerlines/plugin-crypto 0.10.21 → 0.10.23

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
@@ -3,7 +3,13 @@
3
3
  <!-- markdownlint-disable -->
4
4
 
5
5
 
6
- <div align="center"><img src="https://public.storm-cdn.com/storm-banner.gif" width="100%" alt="Powerlines" /></div>
6
+ <div align="center">
7
+ <picture>
8
+ <source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/powerlines/banner-1280x640-dark-optimized.gif">
9
+ <source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/powerlines/banner-1280x640-light-optimized.gif">
10
+ <img src="https://public.storm-cdn.com/powerlines/banner-1280x640-dark-optimized.gif" width="100%" alt="Powerlines" />
11
+ </picture>
12
+ </div>
7
13
  <br />
8
14
 
9
15
  <div align="center">
@@ -16,7 +22,7 @@
16
22
  </div>
17
23
 
18
24
  <br />
19
- This package is part of the ⚡<b>Powerlines</b> monorepo. Powerlines packages include CLI utility applications, tools, and various libraries used to create modern, scalable web applications.
25
+ This package is part of the 🔌 <b>Powerlines</b> monorepo. Powerlines packages include CLI utility applications, tools, and various libraries used to create modern, scalable web applications.
20
26
  <br />
21
27
 
22
28
  <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
@@ -1,139 +1 @@
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 s(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, hexToBytes } 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(hexToBytes("${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
- hexToBytes("${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
- hexToBytes("${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: ${e.config.crypto.salt?`hexToBytes("${e.config.crypto.salt}")`:'new TextEncoder().encode("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(s,"cryptoModule");exports.cryptoModule=s;
1
+ const e=require(`../crypto-B-aare-W.cjs`);exports.cryptoModule=e.t;
@@ -0,0 +1 @@
1
+ import{t as e}from"../crypto-BH9o0GJJ.mjs";export{e as cryptoModule};
@@ -1 +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]}})});
1
+ const e=require(`../crypto-B-aare-W.cjs`);require(`../components-BWLXb7a2.cjs`),exports.cryptoModule=e.t;
@@ -0,0 +1 @@
1
+ import{t as e}from"../crypto-BH9o0GJJ.mjs";import"../components-ipRi4DSE.mjs";export{e as cryptoModule};
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1,142 @@
1
+ const e=require(`./index.cjs`);let t=require(`@stryke/string-format/title-case`);function n(e){return`
2
+ // Generated with ${(0,t.titleCase)(e.config.framework)}
3
+ // Note: Do not edit this file manually - it will be overwritten automatically
4
+ `}function r(e,t={}){let{directive:r=null,prettierIgnore:i=!1}=t;return`/* eslint-disable */
5
+ // biome-ignore lint: disable
6
+ ${i?`// prettier-ignore`:``}${r?`\n\n${r}\n`:`
7
+ `}
8
+ ${n(e)}
9
+
10
+ `}function i(e){return`
11
+ /**
12
+ * The cryptography module provides custom helper functions to support encrypting and decrypting data.
13
+ *
14
+ * @module ${e.config.output.builtinPrefix}:crypto
15
+ */
16
+
17
+ ${r(e)}
18
+
19
+ import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
20
+ import { randomBytes, managedNonce, hexToBytes } from "@noble/ciphers/utils.js";
21
+ import { scrypt } from "@noble/hashes/scrypt.js";
22
+ import { blake3 } from "@noble/hashes/blake3.js";
23
+ ${e.config.crypto.encryptionKey?`
24
+ const nonce = randomBytes(24);
25
+ const chacha = xchacha20poly1305(hexToBytes("${e.config.crypto.encryptionKey}"), 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
+ /**
63
+ * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
64
+ *
65
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
66
+ *
67
+ * @param password - The password used to derive the encryption key.
68
+ * @param plaintext - The data to encrypt.
69
+ * @returns The encrypted data.
70
+ */
71
+ export function encryptWithPassword(password: string, plaintext: string): string {
72
+ const key = scrypt(
73
+ new TextEncoder().encode(password),
74
+ hexToBytes("${e.config.crypto.salt?e.config.crypto.salt:`nonce`}"),
75
+ 1048576, // requires 1GB of RAM to calculate
76
+ 8,
77
+ 1,
78
+ 32
79
+ );
80
+
81
+ return chacha20poly1305(key).encrypt(
82
+ nonce,
83
+ new TextEncoder().encode(plaintext),
84
+ null
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
90
+ *
91
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
92
+ *
93
+ * @param password - The password used to derive the decryption key.
94
+ * @param encrypted - The encrypted data to decrypt.
95
+ * @returns The decrypted data.
96
+ */
97
+ export function decryptWithPassword(password: string, encrypted: string): string {
98
+ const key = scrypt(
99
+ new TextEncoder().encode(password),
100
+ hexToBytes("${e.config.crypto.salt?e.config.crypto.salt:`nonce`}"),
101
+ 1048576, // requires 1GB of RAM to calculate
102
+ 8,
103
+ 1,
104
+ 32
105
+ );
106
+
107
+ const decrypted = chacha20poly1305(key).decrypt(
108
+ nonce,
109
+ encrypted,
110
+ null
111
+ );
112
+
113
+ return new TextDecoder().decode(decrypted);
114
+ }
115
+
116
+ /**
117
+ * Hashes data using the [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function.
118
+ *
119
+ * @see https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3
120
+ *
121
+ * @param data - The data to hash.
122
+ * @returns The hashed data.
123
+ */
124
+ export function hash(data: string): string {
125
+ return Buffer.from(
126
+ blake3(new TextEncoder().encode(data), {
127
+ key: ${e.config.crypto.salt?`hexToBytes("${e.config.crypto.salt}")`:`new TextEncoder().encode("powerlines")`})
128
+ })
129
+ ).toString("hex");
130
+ }
131
+
132
+ // Export noble cipher and hash functions for advanced usage
133
+
134
+ export * from "@noble/ciphers/chacha.js";
135
+ export * from "@noble/ciphers/aes.js";
136
+ export * from "@noble/ciphers/utils.js";
137
+ export * from '@noble/hashes/blake3.js';
138
+ export * from '@noble/hashes/pbkdf2.js';
139
+ export * from '@noble/hashes/scrypt.js';
140
+ export * from '@noble/hashes/utils.js';
141
+
142
+ `}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
@@ -1,17 +1,20 @@
1
- import {a}from'../chunk-UCUR73HG.js';import {getFileHeader}from'powerlines/lib/utilities/file-header';/*****************************************
2
- *
3
- * ⚡ Built by Storm Software
4
- *
5
- *****************************************/
1
+ import{titleCase as e}from"@stryke/string-format/title-case";function t(t){return`
2
+ // Generated with ${e(t.config.framework)}
3
+ // Note: Do not edit this file manually - it will be overwritten automatically
4
+ `}function n(e,n={}){let{directive:r=null,prettierIgnore:i=!1}=n;return`/* eslint-disable */
5
+ // biome-ignore lint: disable
6
+ ${i?`// prettier-ignore`:``}${r?`\n\n${r}\n`:`
7
+ `}
8
+ ${t(e)}
6
9
 
7
- function i(e){return `
10
+ `}function r(e){return`
8
11
  /**
9
12
  * The cryptography module provides custom helper functions to support encrypting and decrypting data.
10
13
  *
11
14
  * @module ${e.config.output.builtinPrefix}:crypto
12
15
  */
13
16
 
14
- ${getFileHeader(e)}
17
+ ${n(e)}
15
18
 
16
19
  import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
17
20
  import { randomBytes, managedNonce, hexToBytes } from "@noble/ciphers/utils.js";
@@ -54,7 +57,7 @@ export function decrypt(encrypted: string): string {
54
57
 
55
58
  return new TextDecoder().decode(decrypted);
56
59
  }
57
- `:""}
60
+ `:``}
58
61
 
59
62
  /**
60
63
  * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
@@ -68,7 +71,7 @@ export function decrypt(encrypted: string): string {
68
71
  export function encryptWithPassword(password: string, plaintext: string): string {
69
72
  const key = scrypt(
70
73
  new TextEncoder().encode(password),
71
- hexToBytes("${e.config.crypto.salt?e.config.crypto.salt:"nonce"}"),
74
+ hexToBytes("${e.config.crypto.salt?e.config.crypto.salt:`nonce`}"),
72
75
  1048576, // requires 1GB of RAM to calculate
73
76
  8,
74
77
  1,
@@ -94,7 +97,7 @@ export function encryptWithPassword(password: string, plaintext: string): string
94
97
  export function decryptWithPassword(password: string, encrypted: string): string {
95
98
  const key = scrypt(
96
99
  new TextEncoder().encode(password),
97
- hexToBytes("${e.config.crypto.salt?e.config.crypto.salt:"nonce"}"),
100
+ hexToBytes("${e.config.crypto.salt?e.config.crypto.salt:`nonce`}"),
98
101
  1048576, // requires 1GB of RAM to calculate
99
102
  8,
100
103
  1,
@@ -121,7 +124,7 @@ export function decryptWithPassword(password: string, encrypted: string): string
121
124
  export function hash(data: string): string {
122
125
  return Buffer.from(
123
126
  blake3(new TextEncoder().encode(data), {
124
- key: ${e.config.crypto.salt?`hexToBytes("${e.config.crypto.salt}")`:'new TextEncoder().encode("powerlines")'})
127
+ key: ${e.config.crypto.salt?`hexToBytes("${e.config.crypto.salt}")`:`new TextEncoder().encode("powerlines")`})
125
128
  })
126
129
  ).toString("hex");
127
130
  }
@@ -136,4 +139,4 @@ export * from '@noble/hashes/pbkdf2.js';
136
139
  export * from '@noble/hashes/scrypt.js';
137
140
  export * from '@noble/hashes/utils.js';
138
141
 
139
- `}a(i,"cryptoModule");export{i as cryptoModule};
142
+ `}export{r as t};