react-native-quick-crypto 1.0.0-beta.15 → 1.0.0-beta.17

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": "react-native-quick-crypto",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5
5
  "type": "module",
6
6
  "main": "lib/commonjs/index",
@@ -68,9 +68,9 @@
68
68
  "registry": "https://registry.npmjs.org/"
69
69
  },
70
70
  "dependencies": {
71
- "@craftzdog/react-native-buffer": "6.0.5",
71
+ "@craftzdog/react-native-buffer": "6.1.0",
72
72
  "events": "3.3.0",
73
- "react-native-quick-base64": "2.1.2",
73
+ "react-native-quick-base64": "2.2.0",
74
74
  "readable-stream": "4.5.2",
75
75
  "util": "0.12.5"
76
76
  },
package/src/cipher.ts CHANGED
@@ -96,6 +96,13 @@ class CipherCommon extends Stream.Transform {
96
96
  });
97
97
  }
98
98
 
99
+ update(data: Buffer): Buffer;
100
+ update(data: BinaryLike, inputEncoding?: Encoding): Buffer;
101
+ update(
102
+ data: BinaryLike,
103
+ inputEncoding: Encoding,
104
+ outputEncoding: Encoding,
105
+ ): string;
99
106
  update(
100
107
  data: BinaryLike,
101
108
  inputEncoding?: Encoding,
@@ -207,7 +214,7 @@ class Cipheriv extends CipherCommon {
207
214
  }
208
215
  }
209
216
 
210
- type Cipher = Cipheriv;
217
+ export type Cipher = Cipheriv;
211
218
 
212
219
  class Decipheriv extends CipherCommon {
213
220
  constructor(
@@ -226,7 +233,7 @@ class Decipheriv extends CipherCommon {
226
233
  }
227
234
  }
228
235
 
229
- type Decipher = Decipheriv;
236
+ export type Decipher = Decipheriv;
230
237
 
231
238
  export function createDecipheriv(
232
239
  algorithm: CipherCCMTypes,
@@ -294,10 +301,35 @@ export function createCipheriv(
294
301
  return new Cipheriv(algorithm, key, iv, options);
295
302
  }
296
303
 
297
- export const cipherExports = {
298
- createCipheriv,
299
- createDecipheriv,
300
- getCiphers,
301
- };
302
-
303
- export type { Cipher, Decipher };
304
+ /**
305
+ * xsalsa20 stream encryption with @noble/ciphers compatible API
306
+ *
307
+ * @param key - 32 bytes
308
+ * @param nonce - 24 bytes
309
+ * @param data - data to encrypt
310
+ * @param output - unused
311
+ * @param counter - unused
312
+ * @returns encrypted data
313
+ */
314
+ export function xsalsa20(
315
+ key: Uint8Array,
316
+ nonce: Uint8Array,
317
+ data: Uint8Array,
318
+ // @ts-expect-error haven't implemented this part of @noble/ciphers API
319
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
320
+ output?: Uint8Array | undefined,
321
+ // @ts-expect-error haven't implemented this part of @noble/ciphers API
322
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
323
+ counter?: number,
324
+ ): Uint8Array {
325
+ const factory =
326
+ NitroModules.createHybridObject<CipherFactory>('CipherFactory');
327
+ const native = factory.createCipher({
328
+ isCipher: true,
329
+ cipherType: 'xsalsa20',
330
+ cipherKey: binaryLikeToArrayBuffer(key),
331
+ iv: binaryLikeToArrayBuffer(nonce),
332
+ });
333
+ const result = native.update(binaryLikeToArrayBuffer(data));
334
+ return new Uint8Array(result);
335
+ }
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@ import { Buffer } from '@craftzdog/react-native-buffer';
3
3
 
4
4
  // API imports
5
5
  import * as keys from './keys';
6
- import { cipherExports as cipher } from './cipher';
6
+ import * as cipher from './cipher';
7
7
  import * as ed from './ed';
8
8
  import { hashExports as hash } from './hash';
9
9
  import { hmacExports as hmac } from './hmac';