react-native-quick-crypto 1.0.5 → 1.0.6

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.
Files changed (74) hide show
  1. package/QuickCrypto.podspec +21 -7
  2. package/android/CMakeLists.txt +1 -0
  3. package/cpp/cipher/HybridRsaCipher.cpp +111 -25
  4. package/cpp/cipher/HybridRsaCipher.hpp +5 -1
  5. package/cpp/hash/HybridHash.cpp +11 -4
  6. package/cpp/hash/HybridHash.hpp +1 -1
  7. package/cpp/hmac/HybridHmac.cpp +13 -4
  8. package/cpp/hmac/HybridHmac.hpp +2 -1
  9. package/cpp/utils/HybridUtils.cpp +19 -0
  10. package/cpp/utils/HybridUtils.hpp +15 -0
  11. package/lib/commonjs/hash.js +7 -1
  12. package/lib/commonjs/hash.js.map +1 -1
  13. package/lib/commonjs/hmac.js +7 -1
  14. package/lib/commonjs/hmac.js.map +1 -1
  15. package/lib/commonjs/keys/publicCipher.js +30 -18
  16. package/lib/commonjs/keys/publicCipher.js.map +1 -1
  17. package/lib/commonjs/specs/utils.nitro.js +6 -0
  18. package/lib/commonjs/specs/utils.nitro.js.map +1 -0
  19. package/lib/commonjs/utils/index.js +11 -0
  20. package/lib/commonjs/utils/index.js.map +1 -1
  21. package/lib/commonjs/utils/timingSafeEqual.js +24 -0
  22. package/lib/commonjs/utils/timingSafeEqual.js.map +1 -0
  23. package/lib/module/hash.js +7 -1
  24. package/lib/module/hash.js.map +1 -1
  25. package/lib/module/hmac.js +7 -1
  26. package/lib/module/hmac.js.map +1 -1
  27. package/lib/module/keys/publicCipher.js +30 -18
  28. package/lib/module/keys/publicCipher.js.map +1 -1
  29. package/lib/module/specs/utils.nitro.js +4 -0
  30. package/lib/module/specs/utils.nitro.js.map +1 -0
  31. package/lib/module/utils/index.js +1 -0
  32. package/lib/module/utils/index.js.map +1 -1
  33. package/lib/module/utils/timingSafeEqual.js +20 -0
  34. package/lib/module/utils/timingSafeEqual.js.map +1 -0
  35. package/lib/tsconfig.tsbuildinfo +1 -1
  36. package/lib/typescript/hash.d.ts.map +1 -1
  37. package/lib/typescript/hmac.d.ts.map +1 -1
  38. package/lib/typescript/index.d.ts +1 -0
  39. package/lib/typescript/index.d.ts.map +1 -1
  40. package/lib/typescript/keys/publicCipher.d.ts +2 -0
  41. package/lib/typescript/keys/publicCipher.d.ts.map +1 -1
  42. package/lib/typescript/specs/hash.nitro.d.ts +1 -1
  43. package/lib/typescript/specs/hash.nitro.d.ts.map +1 -1
  44. package/lib/typescript/specs/hmac.nitro.d.ts +1 -1
  45. package/lib/typescript/specs/hmac.nitro.d.ts.map +1 -1
  46. package/lib/typescript/specs/rsaCipher.nitro.d.ts +14 -4
  47. package/lib/typescript/specs/rsaCipher.nitro.d.ts.map +1 -1
  48. package/lib/typescript/specs/utils.nitro.d.ts +8 -0
  49. package/lib/typescript/specs/utils.nitro.d.ts.map +1 -0
  50. package/lib/typescript/utils/index.d.ts +1 -0
  51. package/lib/typescript/utils/index.d.ts.map +1 -1
  52. package/lib/typescript/utils/timingSafeEqual.d.ts +3 -0
  53. package/lib/typescript/utils/timingSafeEqual.d.ts.map +1 -0
  54. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +1 -0
  55. package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +10 -0
  56. package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +10 -0
  57. package/nitrogen/generated/shared/c++/HybridHashSpec.hpp +2 -1
  58. package/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +2 -1
  59. package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +1 -0
  60. package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +2 -1
  61. package/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp +21 -0
  62. package/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp +63 -0
  63. package/package.json +2 -2
  64. package/src/hash.ts +6 -1
  65. package/src/hmac.ts +6 -1
  66. package/src/keys/publicCipher.ts +46 -26
  67. package/src/specs/hash.nitro.ts +1 -1
  68. package/src/specs/hmac.nitro.ts +1 -1
  69. package/src/specs/rsaCipher.nitro.ts +20 -3
  70. package/src/specs/utils.nitro.ts +5 -0
  71. package/src/utils/index.ts +1 -0
  72. package/src/utils/timingSafeEqual.ts +23 -0
  73. package/react-native.config.js +0 -19
  74. package/scripts/embed_openssl_framework.sh +0 -18
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EAChB,MAAM,SAAS,CAAC;AAiBjB,wBAAgB,SAAS,aAExB;AAED,UAAU,WAAY,SAAQ,gBAAgB;IAC5C;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAQD,cAAM,IAAK,SAAQ,MAAM,CAAC,SAAS;IACjC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,MAAM,CAAa;IAE3B,OAAO,CAAC,QAAQ;IAehB;;OAEG;IACH,OAAO;IAiBP;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAC9B,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,GAAG,MAAM;IAUzD;;;;;;;;;OASG;IACH,MAAM,IAAI,MAAM;IAChB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM;IAWlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,IAAI,IAAI,IAAI;IACZ,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAYhC;;;OAGG;IACH,iBAAiB,IAAI,MAAM;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IAChB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM;IAYlC,UAAU,CACR,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,MAAM,IAAI;IAKtB,MAAM,CAAC,QAAQ,EAAE,MAAM,IAAI;CAI5B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,gBAAgB,GACzB,IAAI,CAON;AAED,eAAO,MAAM,WAAW;;CAEvB,CAAC"}
@@ -51,6 +51,7 @@ declare const QuickCrypto: {
51
51
  name: string;
52
52
  } | undefined, context?: utils.HashContext): utils.HashAlgorithm;
53
53
  HashContext: typeof utils.HashContext;
54
+ timingSafeEqual(a: utils.ABV, b: utils.ABV): boolean;
54
55
  KFormatType: typeof utils.KFormatType;
55
56
  KeyType: typeof utils.KeyType;
56
57
  KeyEncoding: typeof utils.KeyEncoding;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAGxD,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAG3B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAE/B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAInC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAEnC;;;GAGG;AACH,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;uBANR,cAAQ;;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nC;;;GAGG;AACH,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;uBANR,cAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAkCe,yCACL,EAAC,YACf;qBAeX,0BAAoB,EACtB,2BAAqB;qBAY+K,oCAAiC,EAAC,2BAAwB;;;;;;;;;;;+DAAtN,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA5CxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,OAAO,YAMnB,CAAC;AAYF,eAAe,WAAW,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -10,6 +10,8 @@ type PublicCipherInput = BinaryLike | KeyObject | CryptoKey | PublicCipherOption
10
10
  interface PrivateCipherOptions {
11
11
  key: BinaryLike | KeyObject | CryptoKey;
12
12
  padding?: number;
13
+ oaepHash?: string;
14
+ oaepLabel?: BinaryLike;
13
15
  }
14
16
  type PrivateCipherInput = BinaryLike | KeyObject | CryptoKey | PrivateCipherOptions;
15
17
  export declare function publicEncrypt(key: PublicCipherInput, buffer: BinaryLike): Buffer;
@@ -1 +1 @@
1
- {"version":3,"file":"publicCipher.d.ts","sourceRoot":"","sources":["../../../src/keys/publicCipher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EA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CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,UAAU,CAAC;CACxB;AAED,KAAK,iBAAiB,GAClB,UAAU,GACV,SAAS,GACT,SAAS,GACT,mBAAmB,CAAC;AAExB,UAAU,oBAAoB;IAC5B,GAAG,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,UAAU,CAAC;CACxB;AAED,KAAK,kBAAkB,GACnB,UAAU,GACV,SAAS,GACT,SAAS,GACT,oBAAoB,CAAC;AA+DzB,wBAAgB,aAAa,CAC3B,GAAG,EAAE,iBAAiB,EACtB,MAAM,EAAE,UAAU,GACjB,MAAM,CAuBR;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,iBAAiB,EACtB,MAAM,EAAE,UAAU,GACjB,MAAM,CAiBR;AAoDD,wBAAgB,cAAc,CAC5B,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,UAAU,GACjB,MAAM,CAiBR;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,UAAU,GACjB,MAAM,CAuBR"}
@@ -4,7 +4,7 @@ export interface Hash extends HybridObject<{
4
4
  android: 'c++';
5
5
  }> {
6
6
  createHash(algorithm: string, outputLength?: number): void;
7
- update(data: ArrayBuffer): void;
7
+ update(data: ArrayBuffer | string): void;
8
8
  digest(encoding?: string): ArrayBuffer;
9
9
  copy(outputLength?: number): Hash;
10
10
  getSupportedHashAlgorithms(): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"hash.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/hash.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,IAAK,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACxE,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3D,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACvC,IAAI,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,0BAA0B,IAAI,MAAM,EAAE,CAAC;IACvC,iBAAiB,IAAI,MAAM,CAAC;CAC7B"}
1
+ {"version":3,"file":"hash.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/hash.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,IAAK,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACxE,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3D,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;IACzC,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACvC,IAAI,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,0BAA0B,IAAI,MAAM,EAAE,CAAC;IACvC,iBAAiB,IAAI,MAAM,CAAC;CAC7B"}
@@ -4,7 +4,7 @@ export interface Hmac extends HybridObject<{
4
4
  android: 'c++';
5
5
  }> {
6
6
  createHmac(algorithm: string, key: ArrayBuffer): void;
7
- update(data: ArrayBuffer): void;
7
+ update(data: ArrayBuffer | string): void;
8
8
  digest(): ArrayBuffer;
9
9
  }
10
10
  //# sourceMappingURL=hmac.nitro.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hmac.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/hmac.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,IAAK,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACxE,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAAC;IACtD,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,MAAM,IAAI,WAAW,CAAC;CACvB"}
1
+ {"version":3,"file":"hmac.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/hmac.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,IAAK,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACxE,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAAC;IACtD,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;IACzC,MAAM,IAAI,WAAW,CAAC;CACvB"}
@@ -24,6 +24,14 @@ export interface RsaCipher extends HybridObject<{
24
24
  * @returns Decrypted data
25
25
  */
26
26
  decrypt(keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number, hashAlgorithm: string, label?: ArrayBuffer): ArrayBuffer;
27
+ /**
28
+ * Decrypt data using public key (inverse of privateEncrypt, for signature verification)
29
+ * @param keyHandle The public key handle
30
+ * @param data The data to decrypt
31
+ * @param padding RSA padding mode (1=PKCS1)
32
+ * @returns Decrypted data
33
+ */
34
+ publicDecrypt(keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number): ArrayBuffer;
27
35
  /**
28
36
  * Encrypt data using private key (for signatures)
29
37
  * @param keyHandle The private key handle
@@ -33,12 +41,14 @@ export interface RsaCipher extends HybridObject<{
33
41
  */
34
42
  privateEncrypt(keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number): ArrayBuffer;
35
43
  /**
36
- * Decrypt data using public key (for signature verification)
37
- * @param keyHandle The public key handle
44
+ * Decrypt data using private key (inverse of publicEncrypt)
45
+ * @param keyHandle The private key handle
38
46
  * @param data The data to decrypt
39
- * @param padding RSA padding mode (1=PKCS1)
47
+ * @param padding RSA padding mode (1=PKCS1, 4=OAEP)
48
+ * @param hashAlgorithm The hash algorithm for OAEP (e.g., 'SHA-256')
49
+ * @param label Optional label for OAEP
40
50
  * @returns Decrypted data
41
51
  */
42
- privateDecrypt(keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number): ArrayBuffer;
52
+ privateDecrypt(keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number, hashAlgorithm: string, label?: ArrayBuffer): ArrayBuffer;
43
53
  }
44
54
  //# sourceMappingURL=rsaCipher.nitro.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rsaCipher.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/rsaCipher.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,MAAM,WAAW,SACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACpD;;;;;;;;OAQG;IACH,OAAO,CACL,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,EACrB,KAAK,CAAC,EAAE,WAAW,GAClB,WAAW,CAAC;IAEf;;;;;;;;OAQG;IACH,OAAO,CACL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1B,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,GACd,WAAW,CAAC;IAEf;;;;;;;;OAQG;IACH,cAAc,CACZ,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,EACrB,KAAK,CAAC,EAAE,WAAW,GAClB,WAAW,CAAC;CAChB"}
@@ -0,0 +1,8 @@
1
+ import { type HybridObject } from 'react-native-nitro-modules';
2
+ export interface Utils extends HybridObject<{
3
+ ios: 'c++';
4
+ android: 'c++';
5
+ }> {
6
+ timingSafeEqual(a: ArrayBuffer, b: ArrayBuffer): boolean;
7
+ }
8
+ //# sourceMappingURL=utils.nitro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/utils.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,KAAM,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACzE,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;CAC1D"}
@@ -1,6 +1,7 @@
1
1
  export * from './conversion';
2
2
  export * from './errors';
3
3
  export * from './hashnames';
4
+ export * from './timingSafeEqual';
4
5
  export * from './types';
5
6
  export * from './validation';
6
7
  export * from './cipher';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ABV } from './types';
2
+ export declare function timingSafeEqual(a: ABV, b: ABV): boolean;
3
+ //# sourceMappingURL=timingSafeEqual.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timingSafeEqual.d.ts","sourceRoot":"","sources":["../../../src/utils/timingSafeEqual.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAWnC,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,OAAO,CASvD"}
@@ -44,6 +44,7 @@ target_sources(
44
44
  ../nitrogen/generated/shared/c++/HybridScryptSpec.cpp
45
45
  ../nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp
46
46
  ../nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp
47
+ ../nitrogen/generated/shared/c++/HybridUtilsSpec.cpp
47
48
  # Android-specific Nitrogen C++ sources
48
49
 
49
50
  )
@@ -32,6 +32,7 @@
32
32
  #include "HybridVerifyHandle.hpp"
33
33
  #include "HybridMlDsaKeyPair.hpp"
34
34
  #include "HybridScrypt.hpp"
35
+ #include "HybridUtils.hpp"
35
36
 
36
37
  namespace margelo::nitro::crypto {
37
38
 
@@ -198,6 +199,15 @@ int initialize(JavaVM* vm) {
198
199
  return std::make_shared<HybridScrypt>();
199
200
  }
200
201
  );
202
+ HybridObjectRegistry::registerHybridObjectConstructor(
203
+ "Utils",
204
+ []() -> std::shared_ptr<HybridObject> {
205
+ static_assert(std::is_default_constructible_v<HybridUtils>,
206
+ "The HybridObject \"HybridUtils\" is not default-constructible! "
207
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
208
+ return std::make_shared<HybridUtils>();
209
+ }
210
+ );
201
211
  });
202
212
  }
203
213
 
@@ -27,6 +27,7 @@
27
27
  #include "HybridVerifyHandle.hpp"
28
28
  #include "HybridMlDsaKeyPair.hpp"
29
29
  #include "HybridScrypt.hpp"
30
+ #include "HybridUtils.hpp"
30
31
 
31
32
  @interface QuickCryptoAutolinking : NSObject
32
33
  @end
@@ -190,6 +191,15 @@
190
191
  return std::make_shared<HybridScrypt>();
191
192
  }
192
193
  );
194
+ HybridObjectRegistry::registerHybridObjectConstructor(
195
+ "Utils",
196
+ []() -> std::shared_ptr<HybridObject> {
197
+ static_assert(std::is_default_constructible_v<HybridUtils>,
198
+ "The HybridObject \"HybridUtils\" is not default-constructible! "
199
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
200
+ return std::make_shared<HybridUtils>();
201
+ }
202
+ );
193
203
  }
194
204
 
195
205
  @end
@@ -21,6 +21,7 @@ namespace margelo::nitro::crypto { class HybridHashSpec; }
21
21
  #include <string>
22
22
  #include <optional>
23
23
  #include <NitroModules/ArrayBuffer.hpp>
24
+ #include <variant>
24
25
  #include <memory>
25
26
  #include "HybridHashSpec.hpp"
26
27
  #include <vector>
@@ -57,7 +58,7 @@ namespace margelo::nitro::crypto {
57
58
  public:
58
59
  // Methods
59
60
  virtual void createHash(const std::string& algorithm, std::optional<double> outputLength) = 0;
60
- virtual void update(const std::shared_ptr<ArrayBuffer>& data) = 0;
61
+ virtual void update(const std::variant<std::string, std::shared_ptr<ArrayBuffer>>& data) = 0;
61
62
  virtual std::shared_ptr<ArrayBuffer> digest(const std::optional<std::string>& encoding) = 0;
62
63
  virtual std::shared_ptr<HybridHashSpec> copy(std::optional<double> outputLength) = 0;
63
64
  virtual std::vector<std::string> getSupportedHashAlgorithms() = 0;
@@ -18,6 +18,7 @@ namespace NitroModules { class ArrayBuffer; }
18
18
 
19
19
  #include <string>
20
20
  #include <NitroModules/ArrayBuffer.hpp>
21
+ #include <variant>
21
22
 
22
23
  namespace margelo::nitro::crypto {
23
24
 
@@ -51,7 +52,7 @@ namespace margelo::nitro::crypto {
51
52
  public:
52
53
  // Methods
53
54
  virtual void createHmac(const std::string& algorithm, const std::shared_ptr<ArrayBuffer>& key) = 0;
54
- virtual void update(const std::shared_ptr<ArrayBuffer>& data) = 0;
55
+ virtual void update(const std::variant<std::string, std::shared_ptr<ArrayBuffer>>& data) = 0;
55
56
  virtual std::shared_ptr<ArrayBuffer> digest() = 0;
56
57
 
57
58
  protected:
@@ -16,6 +16,7 @@ namespace margelo::nitro::crypto {
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
17
  prototype.registerHybridMethod("encrypt", &HybridRsaCipherSpec::encrypt);
18
18
  prototype.registerHybridMethod("decrypt", &HybridRsaCipherSpec::decrypt);
19
+ prototype.registerHybridMethod("publicDecrypt", &HybridRsaCipherSpec::publicDecrypt);
19
20
  prototype.registerHybridMethod("privateEncrypt", &HybridRsaCipherSpec::privateEncrypt);
20
21
  prototype.registerHybridMethod("privateDecrypt", &HybridRsaCipherSpec::privateDecrypt);
21
22
  });
@@ -57,8 +57,9 @@ namespace margelo::nitro::crypto {
57
57
  // Methods
58
58
  virtual std::shared_ptr<ArrayBuffer> encrypt(const std::shared_ptr<HybridKeyObjectHandleSpec>& keyHandle, const std::shared_ptr<ArrayBuffer>& data, double padding, const std::string& hashAlgorithm, const std::optional<std::shared_ptr<ArrayBuffer>>& label) = 0;
59
59
  virtual std::shared_ptr<ArrayBuffer> decrypt(const std::shared_ptr<HybridKeyObjectHandleSpec>& keyHandle, const std::shared_ptr<ArrayBuffer>& data, double padding, const std::string& hashAlgorithm, const std::optional<std::shared_ptr<ArrayBuffer>>& label) = 0;
60
+ virtual std::shared_ptr<ArrayBuffer> publicDecrypt(const std::shared_ptr<HybridKeyObjectHandleSpec>& keyHandle, const std::shared_ptr<ArrayBuffer>& data, double padding) = 0;
60
61
  virtual std::shared_ptr<ArrayBuffer> privateEncrypt(const std::shared_ptr<HybridKeyObjectHandleSpec>& keyHandle, const std::shared_ptr<ArrayBuffer>& data, double padding) = 0;
61
- virtual std::shared_ptr<ArrayBuffer> privateDecrypt(const std::shared_ptr<HybridKeyObjectHandleSpec>& keyHandle, const std::shared_ptr<ArrayBuffer>& data, double padding) = 0;
62
+ virtual std::shared_ptr<ArrayBuffer> privateDecrypt(const std::shared_ptr<HybridKeyObjectHandleSpec>& keyHandle, const std::shared_ptr<ArrayBuffer>& data, double padding, const std::string& hashAlgorithm, const std::optional<std::shared_ptr<ArrayBuffer>>& label) = 0;
62
63
 
63
64
  protected:
64
65
  // Hybrid Setup
@@ -0,0 +1,21 @@
1
+ ///
2
+ /// HybridUtilsSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridUtilsSpec.hpp"
9
+
10
+ namespace margelo::nitro::crypto {
11
+
12
+ void HybridUtilsSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("timingSafeEqual", &HybridUtilsSpec::timingSafeEqual);
18
+ });
19
+ }
20
+
21
+ } // namespace margelo::nitro::crypto
@@ -0,0 +1,63 @@
1
+ ///
2
+ /// HybridUtilsSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `ArrayBuffer` to properly resolve imports.
17
+ namespace NitroModules { class ArrayBuffer; }
18
+
19
+ #include <NitroModules/ArrayBuffer.hpp>
20
+
21
+ namespace margelo::nitro::crypto {
22
+
23
+ using namespace margelo::nitro;
24
+
25
+ /**
26
+ * An abstract base class for `Utils`
27
+ * Inherit this class to create instances of `HybridUtilsSpec` in C++.
28
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
29
+ * @example
30
+ * ```cpp
31
+ * class HybridUtils: public HybridUtilsSpec {
32
+ * public:
33
+ * HybridUtils(...): HybridObject(TAG) { ... }
34
+ * // ...
35
+ * };
36
+ * ```
37
+ */
38
+ class HybridUtilsSpec: public virtual HybridObject {
39
+ public:
40
+ // Constructor
41
+ explicit HybridUtilsSpec(): HybridObject(TAG) { }
42
+
43
+ // Destructor
44
+ ~HybridUtilsSpec() override = default;
45
+
46
+ public:
47
+ // Properties
48
+
49
+
50
+ public:
51
+ // Methods
52
+ virtual bool timingSafeEqual(const std::shared_ptr<ArrayBuffer>& a, const std::shared_ptr<ArrayBuffer>& b) = 0;
53
+
54
+ protected:
55
+ // Hybrid Setup
56
+ void loadHybridMethods() override;
57
+
58
+ protected:
59
+ // Tag for logging
60
+ static constexpr auto TAG = "Utils";
61
+ };
62
+
63
+ } // namespace margelo::nitro::crypto
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-quick-crypto",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -118,7 +118,7 @@
118
118
  "release": false
119
119
  },
120
120
  "hooks": {
121
- "after:bump": "bun tsc && bun lint && bun format && bun prepare"
121
+ "after:bump": "cd ../.. && bun i && cd packages/react-native-quick-crypto && bun tsc && bun lint && bun format && bun prepare"
122
122
  },
123
123
  "plugins": {
124
124
  "@release-it/bumper": {
package/src/hash.ts CHANGED
@@ -98,7 +98,12 @@ class Hash extends Stream.Transform {
98
98
  const defaultEncoding: Encoding = 'utf8';
99
99
  inputEncoding = inputEncoding ?? defaultEncoding;
100
100
 
101
- this.native.update(binaryLikeToArrayBuffer(data, inputEncoding));
101
+ // OPTIMIZED PATH: Pass UTF-8 strings directly to native without conversion
102
+ if (typeof data === 'string' && inputEncoding === 'utf8') {
103
+ this.native.update(data);
104
+ } else {
105
+ this.native.update(binaryLikeToArrayBuffer(data, inputEncoding));
106
+ }
102
107
 
103
108
  return this; // to support chaining syntax createHash().update().digest()
104
109
  }
package/src/hmac.ts CHANGED
@@ -54,7 +54,12 @@ class Hmac extends Stream.Transform {
54
54
  const defaultEncoding: Encoding = 'utf8';
55
55
  inputEncoding = inputEncoding ?? defaultEncoding;
56
56
 
57
- this.native.update(binaryLikeToArrayBuffer(data, inputEncoding));
57
+ // Optimize: pass UTF-8 strings directly to C++ without conversion
58
+ if (typeof data === 'string' && inputEncoding === 'utf8') {
59
+ this.native.update(data);
60
+ } else {
61
+ this.native.update(binaryLikeToArrayBuffer(data, inputEncoding));
62
+ }
58
63
 
59
64
  return this; // to support chaining syntax createHmac().update().digest()
60
65
  }
@@ -27,6 +27,8 @@ type PublicCipherInput =
27
27
  interface PrivateCipherOptions {
28
28
  key: BinaryLike | KeyObject | CryptoKey;
29
29
  padding?: number;
30
+ oaepHash?: string;
31
+ oaepLabel?: BinaryLike;
30
32
  }
31
33
 
32
34
  type PrivateCipherInput =
@@ -53,23 +55,33 @@ function preparePublicCipherKey(
53
55
  if (isEncrypt && key.type !== 'public') {
54
56
  throw new Error('publicEncrypt requires a public key');
55
57
  }
56
- if (!isEncrypt && key.type !== 'private') {
57
- throw new Error('publicDecrypt requires a private key');
58
- }
58
+ // publicDecrypt accepts both public and private keys (Node.js behavior)
59
+ // A private key contains the public components needed for verify_recover
59
60
  keyObj = key;
60
61
  } else if (isCryptoKey(key)) {
61
62
  const cryptoKey = key as CryptoKey;
62
63
  keyObj = cryptoKey.keyObject;
63
64
  } else if (isStringOrBuffer(key)) {
64
65
  const data = toAB(key);
65
- // Detect if it's PEM format (contains PEM headers) or DER binary
66
66
  const isPem = typeof key === 'string' && key.includes('-----BEGIN');
67
- keyObj = KeyObject.createKeyObject(
68
- isEncrypt ? 'public' : 'private',
69
- data,
70
- isPem ? KFormatType.PEM : KFormatType.DER,
71
- isEncrypt ? KeyEncoding.SPKI : KeyEncoding.PKCS8,
72
- );
67
+ const isPrivatePem =
68
+ typeof key === 'string' && key.includes('-----BEGIN PRIVATE');
69
+ // publicDecrypt accepts both public and private keys (Node.js behavior)
70
+ if (!isEncrypt && isPrivatePem) {
71
+ keyObj = KeyObject.createKeyObject(
72
+ 'private',
73
+ data,
74
+ KFormatType.PEM,
75
+ KeyEncoding.PKCS8,
76
+ );
77
+ } else {
78
+ keyObj = KeyObject.createKeyObject(
79
+ 'public',
80
+ data,
81
+ isPem ? KFormatType.PEM : KFormatType.DER,
82
+ KeyEncoding.SPKI,
83
+ );
84
+ }
73
85
  } else if (typeof key === 'object' && 'key' in key) {
74
86
  const options = key as PublicCipherOptions;
75
87
  const result = preparePublicCipherKey(options.key, isEncrypt);
@@ -118,23 +130,17 @@ export function publicDecrypt(
118
130
  key: PublicCipherInput,
119
131
  buffer: BinaryLike,
120
132
  ): Buffer {
121
- const { keyHandle, padding, oaepHash, oaepLabel } = preparePublicCipherKey(
122
- key,
123
- false,
124
- );
133
+ const { keyHandle, padding } = preparePublicCipherKey(key, false);
125
134
 
126
135
  const rsaCipher: RsaCipher = NitroModules.createHybridObject('RsaCipher');
127
136
  const data = toAB(buffer);
128
- const paddingMode = padding ?? constants.RSA_PKCS1_OAEP_PADDING;
129
- const hashAlgorithm = oaepHash || 'SHA-256';
137
+ const paddingMode = padding ?? constants.RSA_PKCS1_PADDING;
130
138
 
131
139
  try {
132
- const decrypted = rsaCipher.decrypt(
140
+ const decrypted = rsaCipher.publicDecrypt(
133
141
  keyHandle.handle,
134
142
  data,
135
143
  paddingMode,
136
- hashAlgorithm,
137
- oaepLabel,
138
144
  );
139
145
  return Buffer.from(decrypted);
140
146
  } catch (error) {
@@ -148,16 +154,20 @@ function preparePrivateCipherKey(
148
154
  ): {
149
155
  keyHandle: KeyObject;
150
156
  padding?: number;
157
+ oaepHash?: string;
158
+ oaepLabel?: ArrayBuffer;
151
159
  } {
152
160
  let keyObj: KeyObject;
153
161
  let padding: number | undefined;
162
+ let oaepHash: string | undefined;
163
+ let oaepLabel: ArrayBuffer | undefined;
154
164
 
155
165
  if (key instanceof KeyObject) {
156
166
  if (isEncrypt && key.type !== 'private') {
157
167
  throw new Error('privateEncrypt requires a private key');
158
168
  }
159
- if (!isEncrypt && key.type !== 'public') {
160
- throw new Error('privateDecrypt requires a public key');
169
+ if (!isEncrypt && key.type !== 'private') {
170
+ throw new Error('privateDecrypt requires a private key');
161
171
  }
162
172
  keyObj = key;
163
173
  } else if (isCryptoKey(key)) {
@@ -167,21 +177,25 @@ function preparePrivateCipherKey(
167
177
  const data = toAB(key);
168
178
  const isPem = typeof key === 'string' && key.includes('-----BEGIN');
169
179
  keyObj = KeyObject.createKeyObject(
170
- isEncrypt ? 'private' : 'public',
180
+ 'private',
171
181
  data,
172
182
  isPem ? KFormatType.PEM : KFormatType.DER,
173
- isEncrypt ? KeyEncoding.PKCS8 : KeyEncoding.SPKI,
183
+ KeyEncoding.PKCS8,
174
184
  );
175
185
  } else if (typeof key === 'object' && 'key' in key) {
176
186
  const options = key as PrivateCipherOptions;
177
187
  const result = preparePrivateCipherKey(options.key, isEncrypt);
178
188
  keyObj = result.keyHandle;
179
189
  padding = options.padding;
190
+ oaepHash = options.oaepHash;
191
+ if (options.oaepLabel) {
192
+ oaepLabel = toAB(options.oaepLabel);
193
+ }
180
194
  } else {
181
195
  throw new Error('Invalid key input');
182
196
  }
183
197
 
184
- return { keyHandle: keyObj, padding };
198
+ return { keyHandle: keyObj, padding, oaepHash, oaepLabel };
185
199
  }
186
200
 
187
201
  export function privateEncrypt(
@@ -210,17 +224,23 @@ export function privateDecrypt(
210
224
  key: PrivateCipherInput,
211
225
  buffer: BinaryLike,
212
226
  ): Buffer {
213
- const { keyHandle, padding } = preparePrivateCipherKey(key, false);
227
+ const { keyHandle, padding, oaepHash, oaepLabel } = preparePrivateCipherKey(
228
+ key,
229
+ false,
230
+ );
214
231
 
215
232
  const rsaCipher: RsaCipher = NitroModules.createHybridObject('RsaCipher');
216
233
  const data = toAB(buffer);
217
- const paddingMode = padding ?? constants.RSA_PKCS1_PADDING;
234
+ const paddingMode = padding ?? constants.RSA_PKCS1_OAEP_PADDING;
235
+ const hashAlgorithm = oaepHash || 'SHA-256';
218
236
 
219
237
  try {
220
238
  const decrypted = rsaCipher.privateDecrypt(
221
239
  keyHandle.handle,
222
240
  data,
223
241
  paddingMode,
242
+ hashAlgorithm,
243
+ oaepLabel,
224
244
  );
225
245
  return Buffer.from(decrypted);
226
246
  } catch (error) {
@@ -2,7 +2,7 @@ import type { HybridObject } from 'react-native-nitro-modules';
2
2
 
3
3
  export interface Hash extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
4
4
  createHash(algorithm: string, outputLength?: number): void;
5
- update(data: ArrayBuffer): void;
5
+ update(data: ArrayBuffer | string): void;
6
6
  digest(encoding?: string): ArrayBuffer;
7
7
  copy(outputLength?: number): Hash;
8
8
  getSupportedHashAlgorithms(): string[];
@@ -2,6 +2,6 @@ import type { HybridObject } from 'react-native-nitro-modules';
2
2
 
3
3
  export interface Hmac extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
4
4
  createHmac(algorithm: string, key: ArrayBuffer): void;
5
- update(data: ArrayBuffer): void;
5
+ update(data: ArrayBuffer | string): void;
6
6
  digest(): ArrayBuffer;
7
7
  }
@@ -37,6 +37,19 @@ export interface RsaCipher
37
37
  label?: ArrayBuffer,
38
38
  ): ArrayBuffer;
39
39
 
40
+ /**
41
+ * Decrypt data using public key (inverse of privateEncrypt, for signature verification)
42
+ * @param keyHandle The public key handle
43
+ * @param data The data to decrypt
44
+ * @param padding RSA padding mode (1=PKCS1)
45
+ * @returns Decrypted data
46
+ */
47
+ publicDecrypt(
48
+ keyHandle: KeyObjectHandle,
49
+ data: ArrayBuffer,
50
+ padding: number,
51
+ ): ArrayBuffer;
52
+
40
53
  /**
41
54
  * Encrypt data using private key (for signatures)
42
55
  * @param keyHandle The private key handle
@@ -51,15 +64,19 @@ export interface RsaCipher
51
64
  ): ArrayBuffer;
52
65
 
53
66
  /**
54
- * Decrypt data using public key (for signature verification)
55
- * @param keyHandle The public key handle
67
+ * Decrypt data using private key (inverse of publicEncrypt)
68
+ * @param keyHandle The private key handle
56
69
  * @param data The data to decrypt
57
- * @param padding RSA padding mode (1=PKCS1)
70
+ * @param padding RSA padding mode (1=PKCS1, 4=OAEP)
71
+ * @param hashAlgorithm The hash algorithm for OAEP (e.g., 'SHA-256')
72
+ * @param label Optional label for OAEP
58
73
  * @returns Decrypted data
59
74
  */
60
75
  privateDecrypt(
61
76
  keyHandle: KeyObjectHandle,
62
77
  data: ArrayBuffer,
63
78
  padding: number,
79
+ hashAlgorithm: string,
80
+ label?: ArrayBuffer,
64
81
  ): ArrayBuffer;
65
82
  }
@@ -0,0 +1,5 @@
1
+ import { type HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface Utils extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
4
+ timingSafeEqual(a: ArrayBuffer, b: ArrayBuffer): boolean;
5
+ }