@sebastienrousseau/crypto-lib 0.0.9 → 0.0.24

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.
@@ -4,11 +4,17 @@ exports.WEB_STREAM_HASH_ALGORITHMS = void 0;
4
4
  exports.createEncryptStream = createEncryptStream;
5
5
  exports.createDecryptStream = createDecryptStream;
6
6
  exports.createHashStream = createHashStream;
7
+ exports.createPqEncryptStream = createPqEncryptStream;
8
+ exports.createPqDecryptStream = createPqDecryptStream;
9
+ exports.createMultiPqEncryptStream = createMultiPqEncryptStream;
10
+ exports.createMultiPqDecryptStream = createMultiPqDecryptStream;
7
11
  const chacha_js_1 = require("@noble/ciphers/chacha.js");
8
12
  const utils_js_1 = require("@noble/ciphers/utils.js");
9
13
  const sha2_js_1 = require("@noble/hashes/sha2.js");
10
14
  const sha3_js_1 = require("@noble/hashes/sha3.js");
11
15
  const blake3_js_1 = require("@noble/hashes/blake3.js");
16
+ const stream_pq_aead_1 = require("./stream-pq-aead");
17
+ const stream_multi_pq_aead_1 = require("./stream-multi-pq-aead");
12
18
  const TS = globalThis
13
19
  .TransformStream;
14
20
  const NONCE_LEN = 24;
@@ -111,4 +117,104 @@ function createHashStream(algorithm) {
111
117
  },
112
118
  });
113
119
  }
120
+ function createPqEncryptStream(options) {
121
+ const chunks = [];
122
+ let totalLen = 0;
123
+ return new TS({
124
+ transform(chunk) {
125
+ chunks.push(chunk);
126
+ totalLen += chunk.length;
127
+ },
128
+ flush(controller) {
129
+ const plaintext = new Uint8Array(totalLen);
130
+ let offset = 0;
131
+ for (const c of chunks) {
132
+ plaintext.set(c, offset);
133
+ offset += c.length;
134
+ }
135
+ const encrypted = (0, stream_pq_aead_1.streamPqEncrypt)({
136
+ recipientX25519Public: options.recipientX25519Public,
137
+ recipientMlKemPublic: options.recipientMlKemPublic,
138
+ plaintext,
139
+ chunkSize: options.chunkSize,
140
+ });
141
+ controller.enqueue(encrypted.ciphertext);
142
+ },
143
+ });
144
+ }
145
+ function createPqDecryptStream(options) {
146
+ const chunks = [];
147
+ let totalLen = 0;
148
+ return new TS({
149
+ transform(chunk) {
150
+ chunks.push(chunk);
151
+ totalLen += chunk.length;
152
+ },
153
+ flush(controller) {
154
+ const ciphertext = new Uint8Array(totalLen);
155
+ let offset = 0;
156
+ for (const c of chunks) {
157
+ ciphertext.set(c, offset);
158
+ offset += c.length;
159
+ }
160
+ const decrypted = (0, stream_pq_aead_1.streamPqDecrypt)({
161
+ recipientX25519Secret: options.recipientX25519Secret,
162
+ recipientMlKemSecret: options.recipientMlKemSecret,
163
+ ciphertext,
164
+ chunkSize: options.chunkSize,
165
+ });
166
+ controller.enqueue(decrypted);
167
+ },
168
+ });
169
+ }
170
+ function createMultiPqEncryptStream(options) {
171
+ const chunks = [];
172
+ let totalLen = 0;
173
+ return new TS({
174
+ transform(chunk) {
175
+ chunks.push(chunk);
176
+ totalLen += chunk.length;
177
+ },
178
+ flush(controller) {
179
+ const plaintext = new Uint8Array(totalLen);
180
+ let offset = 0;
181
+ for (const c of chunks) {
182
+ plaintext.set(c, offset);
183
+ offset += c.length;
184
+ }
185
+ const encrypted = (0, stream_multi_pq_aead_1.streamMultiPqEncrypt)({
186
+ recipients: options.recipients,
187
+ plaintext,
188
+ chunkSize: options.chunkSize,
189
+ });
190
+ controller.enqueue(encrypted.ciphertext);
191
+ },
192
+ });
193
+ }
194
+ function createMultiPqDecryptStream(options) {
195
+ const chunks = [];
196
+ let totalLen = 0;
197
+ return new TS({
198
+ transform(chunk) {
199
+ chunks.push(chunk);
200
+ totalLen += chunk.length;
201
+ },
202
+ flush(controller) {
203
+ const ciphertext = new Uint8Array(totalLen);
204
+ let offset = 0;
205
+ for (const c of chunks) {
206
+ ciphertext.set(c, offset);
207
+ offset += c.length;
208
+ }
209
+ const decrypted = (0, stream_multi_pq_aead_1.streamMultiPqDecrypt)({
210
+ recipientId: options.recipientId,
211
+ recipientX25519Secret: options.recipientX25519Secret,
212
+ recipientMlKemSecret: options.recipientMlKemSecret,
213
+ ciphertext,
214
+ chunkSize: options.chunkSize,
215
+ });
216
+ controller.enqueue(decrypted.plaintext);
217
+ },
218
+ });
219
+ }
114
220
  //# sourceMappingURL=web-streams.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-lib",
3
- "version": "0.0.9",
3
+ "version": "0.0.24",
4
4
  "description": "Crypto Lib is a powerful intuitive cryptographic JavaScript library that encapsulates common algorithms, functions and provides an interface for low-level cryptographic operations.",
5
5
  "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
6
6
  "license": "MIT OR Apache-2.0",
@@ -107,7 +107,7 @@
107
107
  "@noble/hashes": "^2.4.0",
108
108
  "@noble/post-quantum": "^0.7.1",
109
109
  "@openpgp/web-stream-tools": "^0.3.1",
110
- "openpgp": "^6.3.1"
110
+ "openpgp": "^6.3.2"
111
111
  },
112
112
  "devDependencies": {
113
113
  "@types/chai": "^5.2.3",