@powerlines/plugin-crypto 0.1.0 → 0.2.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
@@ -4,7 +4,7 @@
4
4
  *
5
5
  *****************************************/
6
6
 
7
- var a=Object.defineProperty;var t=(e,r)=>a(e,"name",{value:r,configurable:true});function d(e){return `
7
+ var a=Object.defineProperty;var t=(e,r)=>a(e,"name",{value:r,configurable:true});function h(e){return `
8
8
  /**
9
9
  * The cryptography module provides custom helper functions to support encrypting and decrypting data.
10
10
  *
@@ -16,6 +16,7 @@ ${fileHeader.getFileHeader(e)}
16
16
  import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
17
17
  import { randomBytes, managedNonce } from "@noble/ciphers/utils.js";
18
18
  import { scrypt } from "@noble/hashes/scrypt.js";
19
+ import { blake3 } from "@noble/hashes/blake3.js";
19
20
 
20
21
  const CIPHER_KEY_LENGTH = 32; // https://stackoverflow.com/a/28307668/4397028
21
22
  const CIPHER_NONCE_LENGTH = 24;
@@ -57,9 +58,6 @@ export function decrypt(encrypted: string): string {
57
58
  return new TextDecoder().decode(decrypted);
58
59
  }
59
60
 
60
- export * from "@noble/ciphers/chacha.js";
61
- export * from "@noble/ciphers/utils.js";
62
-
63
61
  /**
64
62
  * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
65
63
  *
@@ -114,4 +112,30 @@ export function decryptWithPassword(password: string, encrypted: string): string
114
112
  return new TextDecoder().decode(decrypted);
115
113
  }
116
114
 
117
- `}t(d,"cryptoModule");exports.cryptoModule=d;
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;
@@ -4,7 +4,7 @@ import {getFileHeader}from'powerlines/lib/utilities/file-header';/**************
4
4
  *
5
5
  *****************************************/
6
6
 
7
- var a=Object.defineProperty;var t=(e,r)=>a(e,"name",{value:r,configurable:true});function h(e){return `
7
+ var a=Object.defineProperty;var t=(e,r)=>a(e,"name",{value:r,configurable:true});function d(e){return `
8
8
  /**
9
9
  * The cryptography module provides custom helper functions to support encrypting and decrypting data.
10
10
  *
@@ -16,6 +16,7 @@ ${getFileHeader(e)}
16
16
  import { xchacha20poly1305, chacha20poly1305 } from "@noble/ciphers/chacha.js";
17
17
  import { randomBytes, managedNonce } from "@noble/ciphers/utils.js";
18
18
  import { scrypt } from "@noble/hashes/scrypt.js";
19
+ import { blake3 } from "@noble/hashes/blake3.js";
19
20
 
20
21
  const CIPHER_KEY_LENGTH = 32; // https://stackoverflow.com/a/28307668/4397028
21
22
  const CIPHER_NONCE_LENGTH = 24;
@@ -57,9 +58,6 @@ export function decrypt(encrypted: string): string {
57
58
  return new TextDecoder().decode(decrypted);
58
59
  }
59
60
 
60
- export * from "@noble/ciphers/chacha.js";
61
- export * from "@noble/ciphers/utils.js";
62
-
63
61
  /**
64
62
  * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher with a password.
65
63
  *
@@ -114,4 +112,30 @@ export function decryptWithPassword(password: string, encrypted: string): string
114
112
  return new TextDecoder().decode(decrypted);
115
113
  }
116
114
 
117
- `}t(h,"cryptoModule");export{h as cryptoModule};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-crypto",
3
- "version": "0.1.0",
3
+ "version": "0.2.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.4.0",
120
120
  "@storm-software/config-tools": "^1.188.6",
121
121
  "@stryke/path": "^0.15.5",
122
122
  "defu": "^6.1.4",
123
123
  "powerlines": "^0.4.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": "56dc46d2a2d16d8b13be33fadb90e0e0c328baee"
132
132
  }