react-native-quick-crypto 0.3.0 → 0.4.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.
Files changed (88) hide show
  1. package/README.md +25 -14
  2. package/android/CMakeLists.txt +10 -2
  3. package/android/gradle.properties +1 -1
  4. package/android/src/main/AndroidManifest.xml +1 -1
  5. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +70 -0
  6. package/android/src/main/java/com/{reactnativequickcrypto → margelo/quickcrypto}/QuickCryptoPackage.java +11 -12
  7. package/cpp/Cipher/MGLCipherHostObject.cpp +4 -5
  8. package/cpp/Cipher/MGLCreateCipherInstaller.cpp +1 -3
  9. package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +6 -3
  10. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +5 -3
  11. package/cpp/Cipher/MGLPublicCipher.h +1 -1
  12. package/cpp/Cipher/MGLPublicCipherInstaller.h +1 -1
  13. package/cpp/Cipher/MGLRsa.h +5 -1
  14. package/cpp/JSIUtils/MGLJSIMacros.h +69 -6
  15. package/cpp/{Cipher/MGLCipherKeys.cpp → MGLKeys.cpp} +47 -49
  16. package/cpp/{Cipher/MGLCipherKeys.h → MGLKeys.h} +29 -30
  17. package/cpp/MGLQuickCryptoHostObject.cpp +12 -0
  18. package/cpp/Sig/MGLSignHostObjects.cpp +889 -0
  19. package/cpp/Sig/MGLSignHostObjects.h +88 -0
  20. package/cpp/Sig/MGLSignInstaller.cpp +24 -0
  21. package/cpp/Sig/MGLSignInstaller.h +29 -0
  22. package/cpp/Sig/MGLVerifyInstaller.cpp +24 -0
  23. package/cpp/Sig/MGLVerifyInstaller.h +22 -0
  24. package/cpp/Utils/MGLUtils.cpp +67 -29
  25. package/cpp/Utils/MGLUtils.h +17 -17
  26. package/lib/commonjs/@types/crypto-browserify.d.js +2 -0
  27. package/lib/commonjs/@types/crypto-browserify.d.js.map +1 -0
  28. package/lib/commonjs/@types/stream-browserify.d.js +2 -0
  29. package/lib/commonjs/@types/stream-browserify.d.js.map +1 -0
  30. package/lib/commonjs/Cipher.js +3 -2
  31. package/lib/commonjs/Cipher.js.map +1 -1
  32. package/lib/commonjs/Hash.js +2 -2
  33. package/lib/commonjs/Hash.js.map +1 -1
  34. package/lib/commonjs/Hmac.js +2 -2
  35. package/lib/commonjs/Hmac.js.map +1 -1
  36. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  37. package/lib/commonjs/NativeQuickCrypto/sig.js +2 -0
  38. package/lib/commonjs/NativeQuickCrypto/sig.js.map +1 -0
  39. package/lib/commonjs/QuickCrypto.js +4 -0
  40. package/lib/commonjs/QuickCrypto.js.map +1 -1
  41. package/lib/commonjs/index.js +16 -13
  42. package/lib/commonjs/index.js.map +1 -1
  43. package/lib/commonjs/keys.js +1 -4
  44. package/lib/commonjs/keys.js.map +1 -1
  45. package/lib/commonjs/sig.js +170 -0
  46. package/lib/commonjs/sig.js.map +1 -0
  47. package/lib/module/@types/crypto-browserify.d.js +2 -0
  48. package/lib/module/@types/crypto-browserify.d.js.map +1 -0
  49. package/lib/module/@types/stream-browserify.d.js +2 -0
  50. package/lib/module/@types/stream-browserify.d.js.map +1 -0
  51. package/lib/module/Cipher.js +2 -1
  52. package/lib/module/Cipher.js.map +1 -1
  53. package/lib/module/Hash.js +1 -1
  54. package/lib/module/Hash.js.map +1 -1
  55. package/lib/module/Hmac.js +1 -1
  56. package/lib/module/Hmac.js.map +1 -1
  57. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  58. package/lib/module/NativeQuickCrypto/sig.js +2 -0
  59. package/lib/module/NativeQuickCrypto/sig.js.map +1 -0
  60. package/lib/module/QuickCrypto.js +3 -0
  61. package/lib/module/QuickCrypto.js.map +1 -1
  62. package/lib/module/index.js +12 -2
  63. package/lib/module/index.js.map +1 -1
  64. package/lib/module/keys.js +1 -4
  65. package/lib/module/keys.js.map +1 -1
  66. package/lib/module/sig.js +155 -0
  67. package/lib/module/sig.js.map +1 -0
  68. package/lib/typescript/Cipher.d.ts +1 -1
  69. package/lib/typescript/Hash.d.ts +1 -1
  70. package/lib/typescript/Hmac.d.ts +1 -1
  71. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +3 -0
  72. package/lib/typescript/NativeQuickCrypto/sig.d.ts +12 -0
  73. package/lib/typescript/QuickCrypto.d.ts +3 -0
  74. package/lib/typescript/index.d.ts +207 -3
  75. package/lib/typescript/sig.d.ts +35 -0
  76. package/package.json +5 -3
  77. package/src/@types/crypto-browserify.d.ts +4 -0
  78. package/src/@types/stream-browserify.d.ts +4 -0
  79. package/src/Cipher.ts +2 -1
  80. package/src/Hash.ts +1 -1
  81. package/src/Hmac.ts +1 -1
  82. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +3 -0
  83. package/src/NativeQuickCrypto/sig.ts +17 -0
  84. package/src/QuickCrypto.ts +3 -0
  85. package/src/index.ts +12 -2
  86. package/src/keys.ts +18 -13
  87. package/src/sig.ts +179 -0
  88. package/android/src/main/java/com/reactnativequickcrypto/QuickCryptoModule.java +0 -70
@@ -0,0 +1,88 @@
1
+ #ifndef MGLSignHostObjects_h
2
+ #define MGLSignHostObjects_h
3
+
4
+ #include <jsi/jsi.h>
5
+ #include <openssl/evp.h>
6
+
7
+ #include <memory>
8
+ #include <optional>
9
+ #include <string>
10
+ #include <utility>
11
+
12
+ #include "MGLKeys.h"
13
+ #ifdef ANDROID
14
+ #include "JSIUtils/MGLSmartHostObject.h"
15
+ #include "Utils/MGLUtils.h"
16
+ #else
17
+ #include "MGLSmartHostObject.h"
18
+ #include "MGLUtils.h"
19
+ #endif
20
+
21
+ namespace margelo {
22
+
23
+ namespace jsi = facebook::jsi;
24
+
25
+ static const unsigned int kNoDsaSignature = static_cast<unsigned int>(-1);
26
+
27
+ enum mode { kModeSign, kModeVerify };
28
+
29
+ enum DSASigEnc {
30
+ kSigEncDER,
31
+ kSigEncP1363,
32
+ };
33
+
34
+ class SignBase : public MGLSmartHostObject {
35
+ public:
36
+ SignBase(std::shared_ptr<react::CallInvoker> jsCallInvoker,
37
+ std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
38
+
39
+ typedef enum {
40
+ kSignOk,
41
+ kSignUnknownDigest,
42
+ kSignInit,
43
+ kSignNotInitialised,
44
+ kSignUpdate,
45
+ kSignPrivateKey,
46
+ kSignPublicKey,
47
+ kSignMalformedSignature
48
+ } Error;
49
+
50
+ struct SignResult {
51
+ Error error;
52
+ std::optional<jsi::Value> signature;
53
+
54
+ explicit SignResult(Error err, std::optional<jsi::Value> sig = std::nullopt)
55
+ : error(err), signature(std::move(sig)) {}
56
+ };
57
+
58
+ void InstallMethods(mode);
59
+
60
+ SignResult SignFinal(jsi::Runtime& runtime, const ManagedEVPPKey& pkey,
61
+ int padding, std::optional<int>& salt_len,
62
+ DSASigEnc dsa_sig_enc);
63
+
64
+ Error VerifyFinal(const ManagedEVPPKey& pkey, const ByteSource& sig,
65
+ int padding, std::optional<int>& saltlen,
66
+ bool* verify_result);
67
+
68
+ protected:
69
+ EVPMDPointer mdctx_;
70
+ };
71
+
72
+ class MGLSignHostObject : public SignBase {
73
+ public:
74
+ explicit MGLSignHostObject(
75
+ std::shared_ptr<react::CallInvoker> jsCallInvoker,
76
+ std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
77
+ };
78
+
79
+ class MGLVerifyHostObject : public SignBase {
80
+ public:
81
+ explicit MGLVerifyHostObject(
82
+ std::shared_ptr<react::CallInvoker> jsCallInvoker,
83
+ std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
84
+ };
85
+
86
+ } // namespace margelo
87
+
88
+ #endif /* MGLSignHostObjects_h */
@@ -0,0 +1,24 @@
1
+ #include "MGLSignInstaller.h"
2
+
3
+ #include "MGLSignHostObjects.h"
4
+ #ifdef ANDROID
5
+ #include "JSIUtils/MGLJSIMacros.h"
6
+ #else
7
+ #include "MGLJSIMacros.h"
8
+ #include "logs.h"
9
+ #endif
10
+
11
+ namespace margelo {
12
+
13
+ FieldDefinition getSignFieldDefinition(
14
+ std::shared_ptr<react::CallInvoker> jsCallInvoker,
15
+ std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
16
+ return buildPair(
17
+ "createSign", JSIF([=]) {
18
+ auto hostObject =
19
+ std::make_shared<MGLSignHostObject>(jsCallInvoker, workerQueue);
20
+ return jsi::Object::createFromHostObject(runtime, hostObject);
21
+ });
22
+ }
23
+
24
+ } // namespace margelo
@@ -0,0 +1,29 @@
1
+ //
2
+ // MGLSignInstaller.hpp
3
+ // DoubleConversion
4
+ //
5
+ // Created by Oscar on 30.06.22.
6
+ //
7
+
8
+ #ifndef MGLSignInstaller_h
9
+ #define MGLSignInstaller_h
10
+
11
+ #include <jsi/jsi.h>
12
+
13
+ #include <memory>
14
+
15
+ #ifdef ANDROID
16
+ #include "JSIUtils/MGLSmartHostObject.h"
17
+ #else
18
+ #include "MGLSmartHostObject.h"
19
+ #endif
20
+
21
+ namespace margelo {
22
+ namespace jsi = facebook::jsi;
23
+
24
+ FieldDefinition getSignFieldDefinition(
25
+ std::shared_ptr<react::CallInvoker> jsCallInvoker,
26
+ std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
27
+ } // namespace margelo
28
+
29
+ #endif /* MGLSignInstaller_h */
@@ -0,0 +1,24 @@
1
+ #include "MGLVerifyInstaller.h"
2
+
3
+ #include "MGLSignHostObjects.h"
4
+ #ifdef ANDROID
5
+ #include "JSIUtils/MGLJSIMacros.h"
6
+ #else
7
+ #include "MGLJSIMacros.h"
8
+ #include "logs.h"
9
+ #endif
10
+
11
+ namespace margelo {
12
+
13
+ FieldDefinition getVerifyFieldDefinition(
14
+ std::shared_ptr<react::CallInvoker> jsCallInvoker,
15
+ std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
16
+ return buildPair(
17
+ "createVerify", JSIF([=]) {
18
+ auto hostObject =
19
+ std::make_shared<MGLVerifyHostObject>(jsCallInvoker, workerQueue);
20
+ return jsi::Object::createFromHostObject(runtime, hostObject);
21
+ });
22
+ }
23
+
24
+ } // namespace margelo
@@ -0,0 +1,22 @@
1
+ #ifndef MGLVerifyInstaller_h
2
+ #define MGLVerifyInstaller_h
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ #include <memory>
7
+
8
+ #ifdef ANDROID
9
+ #include "JSIUtils/MGLSmartHostObject.h"
10
+ #else
11
+ #include "MGLSmartHostObject.h"
12
+ #endif
13
+
14
+ namespace margelo {
15
+ namespace jsi = facebook::jsi;
16
+
17
+ FieldDefinition getVerifyFieldDefinition(
18
+ std::shared_ptr<react::CallInvoker> jsCallInvoker,
19
+ std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
20
+ } // namespace margelo
21
+
22
+ #endif /* MGLVerifyInstaller_h */
@@ -1,18 +1,46 @@
1
- //
2
- // MGLUtils.cpp
3
- // react-native-quick-crypto
4
- //
5
- // Created by Oscar on 21.06.22.
6
- //
7
-
8
1
  #include "MGLUtils.h"
9
2
 
10
3
  #include <jsi/jsi.h>
11
4
 
5
+ #include <string>
6
+
7
+ #ifdef ANDROID
8
+ #include "JSIUtils/MGLJSIMacros.h"
9
+ #else
10
+ #include "MGLJSIMacros.h"
11
+ #endif
12
+
12
13
  namespace margelo {
13
14
 
14
15
  namespace jsi = facebook::jsi;
15
16
 
17
+ ByteSource ArrayBufferToByteSource(jsi::Runtime& runtime,
18
+ const jsi::ArrayBuffer& buffer) {
19
+ if (buffer.size(runtime) == 0) return ByteSource();
20
+ char* buf = MallocOpenSSL<char>(buffer.size(runtime));
21
+ CHECK_NOT_NULL(buf);
22
+ // const cast artificially removes the const qualifier, but you cannot still
23
+ // modify the data in this case, this is safe because we are just memcopying
24
+ // to the buffer
25
+ memcpy(buf, const_cast<jsi::ArrayBuffer&>(buffer).data(runtime),
26
+ buffer.size(runtime));
27
+ return ByteSource::Allocated(buf, buffer.size(runtime));
28
+ }
29
+
30
+ ByteSource ArrayBufferToNTCByteSource(jsi::Runtime& runtime,
31
+ const jsi::ArrayBuffer& buffer) {
32
+ if (buffer.size(runtime) == 0) return ByteSource();
33
+ char* buf = MallocOpenSSL<char>(buffer.size(runtime) + 1);
34
+ CHECK_NOT_NULL(buf);
35
+ buf[buffer.size(runtime)] = 0;
36
+ // const cast artificially removes the const qualifier, but you cannot still
37
+ // modify the data in this case, this is safe because we are just memcopying
38
+ // to the buffer
39
+ memcpy(buf, const_cast<jsi::ArrayBuffer&>(buffer).data(runtime),
40
+ buffer.size(runtime));
41
+ return ByteSource::Allocated(buf, buffer.size(runtime));
42
+ }
43
+
16
44
  ByteSource::ByteSource(ByteSource&& other) noexcept
17
45
  : data_(other.data_),
18
46
  allocated_data_(other.allocated_data_),
@@ -95,28 +123,38 @@ ByteSource& ByteSource::operator=(ByteSource&& other) noexcept {
95
123
  // return out;
96
124
  // }
97
125
  //
98
- // ByteSource ByteSource::FromStringOrBuffer(Environment* env,
99
- // Local<Value> value) {
100
- // return IsAnyByteSource(value) ? FromBuffer(value)
101
- // : FromString(env, value.As<String>());
102
- // }
103
- //
104
- // ByteSource ByteSource::FromString(Environment* env, Local<String> str,
105
- // bool ntc) {
106
- // CHECK(str->IsString());
107
- // size_t size = str->Utf8Length(env->isolate());
108
- // size_t alloc_size = ntc ? size + 1 : size;
109
- // ByteSource::Builder out(alloc_size);
110
- // int opts = String::NO_OPTIONS;
111
- // if (!ntc) opts |= String::NO_NULL_TERMINATION;
112
- // str->WriteUtf8(env->isolate(), out.data<char>(), alloc_size, nullptr,
113
- // opts); return std::move(out).release();
114
- // }
115
- //
116
- // ByteSource ByteSource::FromBuffer(Local<Value> buffer, bool ntc) {
117
- // ArrayBufferOrViewContents<char> buf(buffer);
118
- // return ntc ? buf.ToNullTerminatedCopy() : buf.ToByteSource();
119
- // }
126
+ ByteSource ByteSource::FromStringOrBuffer(jsi::Runtime& runtime,
127
+ const jsi::Value& value) {
128
+ return value.isString()
129
+ ? FromString(value.asString(runtime).utf8(runtime))
130
+ : FromBuffer(runtime,
131
+ value.asObject(runtime).getArrayBuffer(runtime));
132
+ }
133
+
134
+ // ntc = null terminated copy
135
+ ByteSource ByteSource::FromString(std::string str, bool ntc) {
136
+ // CHECK(str->IsString());
137
+ size_t size = str.size();
138
+ size_t alloc_size = ntc ? size + 1 : size;
139
+ ByteSource::Builder out(alloc_size);
140
+ // int opts = String::NO_OPTIONS;
141
+ // if (!ntc) opts |= String::NO_NULL_TERMINATION;
142
+ // str->WriteUtf8(env->isolate(), out.data<char>(), alloc_size, nullptr,
143
+ // opts);
144
+ if (ntc) {
145
+ strcpy(out.data<char>(), str.data());
146
+ } else {
147
+ strncpy(out.data<char>(), str.data(), alloc_size);
148
+ }
149
+
150
+ return std::move(out).release();
151
+ }
152
+
153
+ ByteSource ByteSource::FromBuffer(jsi::Runtime& runtime,
154
+ const jsi::ArrayBuffer& buffer, bool ntc) {
155
+ return ntc ? ArrayBufferToNTCByteSource(runtime, buffer)
156
+ : ArrayBufferToByteSource(runtime, buffer);
157
+ }
120
158
  //
121
159
  // ByteSource ByteSource::FromSecretKeyBytes(
122
160
  // Environment* env,
@@ -1,10 +1,3 @@
1
- //
2
- // MGLUtils.h
3
- // Pods
4
- //
5
- // Created by Oscar on 20.06.22.
6
- //
7
-
8
1
  #ifndef MGLUtils_h
9
2
  #define MGLUtils_h
10
3
 
@@ -53,6 +46,8 @@ using EVPKeyCtxPointer = DeleteFnPtr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
53
46
  using EVPKeyPointer = DeleteFnPtr<EVP_PKEY, EVP_PKEY_free>;
54
47
  using BignumPointer = DeleteFnPtr<BIGNUM, BN_free>;
55
48
  using RSAPointer = DeleteFnPtr<RSA, RSA_free>;
49
+ using EVPMDPointer = DeleteFnPtr<EVP_MD_CTX, EVP_MD_CTX_free>;
50
+ using ECDSASigPointer = DeleteFnPtr<ECDSA_SIG, ECDSA_SIG_free>;
56
51
 
57
52
  template <typename T>
58
53
  class NonCopyableMaybe {
@@ -183,15 +178,14 @@ class ByteSource {
183
178
  // v8::Local<v8::String> value,
184
179
  // enum encoding enc = BASE64);
185
180
  //
186
- // static ByteSource FromStringOrBuffer(Environment* env,
187
- // v8::Local<v8::Value> value);
188
- //
189
- // static ByteSource FromString(Environment* env,
190
- // v8::Local<v8::String> str,
191
- // bool ntc = false);
181
+ static ByteSource FromStringOrBuffer(jsi::Runtime& runtime,
182
+ const jsi::Value& value);
192
183
 
193
- // static ByteSource FromBuffer(v8::Local<v8::Value> buffer,
194
- // bool ntc = false);
184
+ static ByteSource FromString(std::string str, bool ntc = false);
185
+
186
+ static ByteSource FromBuffer(jsi::Runtime& runtime,
187
+ const jsi::ArrayBuffer& buffer,
188
+ bool ntc = false);
195
189
 
196
190
  // static ByteSource FromBIO(const BIOPointer& bio);
197
191
  //
@@ -214,6 +208,12 @@ class ByteSource {
214
208
  : data_(data), allocated_data_(allocated_data), size_(size) {}
215
209
  };
216
210
 
211
+ ByteSource ArrayBufferToByteSource(jsi::Runtime& runtime,
212
+ const jsi::ArrayBuffer& buffer);
213
+
214
+ ByteSource ArrayBufferToNTCByteSource(jsi::Runtime& runtime,
215
+ const jsi::ArrayBuffer& buffer);
216
+
217
217
  // Originally part of the ArrayBufferContentOrView class
218
218
  inline ByteSource ToNullTerminatedByteSource(jsi::Runtime& runtime,
219
219
  jsi::ArrayBuffer& buffer) {
@@ -225,7 +225,7 @@ inline ByteSource ToNullTerminatedByteSource(jsi::Runtime& runtime,
225
225
  return ByteSource::Allocated(buf, buffer.size(runtime));
226
226
  }
227
227
 
228
- int PasswordCallback(char* buf, int size, int rwflag, void* u) {
228
+ inline int PasswordCallback(char* buf, int size, int rwflag, void* u) {
229
229
  const ByteSource* passphrase = *static_cast<const ByteSource**>(u);
230
230
  if (passphrase != nullptr) {
231
231
  size_t buflen = static_cast<size_t>(size);
@@ -238,7 +238,7 @@ int PasswordCallback(char* buf, int size, int rwflag, void* u) {
238
238
  return -1;
239
239
  }
240
240
 
241
- void CheckEntropy() {
241
+ inline void CheckEntropy() {
242
242
  for (;;) {
243
243
  int status = RAND_status();
244
244
  // CHECK_GE(status, 0); // Cannot fail.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=crypto-browserify.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=stream-browserify.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -13,7 +13,7 @@ exports.publicEncrypt = exports.publicDecrypt = exports.privateDecrypt = void 0;
13
13
 
14
14
  var _NativeQuickCrypto = require("./NativeQuickCrypto/NativeQuickCrypto");
15
15
 
16
- var _stream = _interopRequireDefault(require("stream"));
16
+ var _streamBrowserify = _interopRequireDefault(require("stream-browserify"));
17
17
 
18
18
  var _Utils = require("./Utils");
19
19
 
@@ -101,7 +101,7 @@ function getDecoder(decoder, encoding) {
101
101
  return decoder !== null && decoder !== void 0 ? decoder : new _string_decoder.StringDecoder(encoding);
102
102
  }
103
103
 
104
- class CipherCommon extends _stream.default.Transform {
104
+ class CipherCommon extends _streamBrowserify.default.Transform {
105
105
  constructor(cipherType, cipherKey, isCipher) {
106
106
  let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
107
107
  let iv = arguments.length > 4 ? arguments[4] : undefined;
@@ -591,6 +591,7 @@ function generateKeyPair(type, options, callback) {
591
591
  }
592
592
 
593
593
  function generateKeyPairSync(type, options) {
594
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
594
595
  const [_, publicKey, privateKey] = internalGenerateKeyPair(false, type, options, undefined);
595
596
  return {
596
597
  publicKey,
@@ -1 +1 @@
1
- {"version":3,"sources":["Cipher.ts"],"names":["global","process","nextTick","setImmediate","createInternalCipher","NativeQuickCrypto","createCipher","createInternalDecipher","createDecipher","_publicEncrypt","publicEncrypt","_publicDecrypt","publicDecrypt","_privateDecrypt","privateDecrypt","getUIntOption","options","key","value","Error","normalizeEncoding","enc","retried","toLowerCase","validateEncoding","data","encoding","normalizedEncoding","length","getDecoder","decoder","StringDecoder","CipherCommon","Stream","Transform","constructor","cipherType","cipherKey","isCipher","iv","cipherKeyBuffer","authTagLength","args","cipher_type","cipher_key","auth_tag_len","internal","update","inputEncoding","outputEncoding","defaultEncoding","ArrayBuffer","isView","ret","write","SBuffer","from","final","end","_transform","chunk","callback","push","_flush","setAutoPadding","autoPadding","setAAD","buffer","plaintextLength","setAuthTag","tag","Cipher","Decipher","algorithm","password","createDecipheriv","createCipheriv","rsaFunctionFor","method","defaultPadding","keyType","format","type","passphrase","padding","oaepHash","oaepLabel","undefined","rawRes","Buffer","constants","RSA_PKCS1_OAEP_PADDING","RSA_PKCS1_PADDING","parseKeyEncoding","kEmptyObject","publicKeyEncoding","privateKeyEncoding","publicFormat","publicType","privateFormat","privateType","cipher","internalGenerateKeyPair","isAsync","modulusLength","publicExponent","generateKeyPair","RSAKeyVariant","kKeyVariantRSA_SSA_PKCS1_v1_5","then","err","publicKey","privateKey","catch","generateKeyPairSync","hash","mgf1Hash","hashAlgorithm","mgf1HashAlgorithm","saltLength","kKeyVariantRSA_PSS","_"],"mappings":";;;;;;;;;;;;;AACA;;AACA;;AACA;;AAaA;;AAcA;;AACA;;AACA;;AACA;;AACA;;;;;;AAOA;AACAA,MAAM,CAACC,OAAP,CAAeC,QAAf,GAA0BC,YAA1B;AAEA,MAAMC,oBAAoB,GAAGC,qCAAkBC,YAA/C;AACA,MAAMC,sBAAsB,GAAGF,qCAAkBG,cAAjD;AACA,MAAMC,cAAc,GAAGJ,qCAAkBK,aAAzC;AACA,MAAMC,cAAc,GAAGN,qCAAkBO,aAAzC;AACA,MAAMC,eAAe,GAAGR,qCAAkBS,cAA1C;;AAEA,SAASC,aAAT,CAAuBC,OAAvB,EAAqDC,GAArD,EAAkE;AAChE,MAAIC,KAAJ;;AACA,MAAIF,OAAO,IAAI,CAACE,KAAK,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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,YA/LF,CAgME;;AAhMF;;AAkMA,QAAM,IAAIP,KAAJ,CACH,6BAA4B+D,IAAK,4FAD9B,CAAN;AAGD,C,CAED;;;AAUO,SAASwB,eAAT,CACLxB,IADK,EAELlE,OAFK,EAGL6C,QAHK,EAIL;AACA,MAAI,OAAO7C,OAAP,KAAmB,UAAvB,EAAmC;AACjC6C,IAAAA,QAAQ,GAAG7C,OAAX;AACAA,IAAAA,OAAO,GAAGuE,SAAV;AACD;;AAED,+BAAiB1B,QAAjB;AAEAyC,EAAAA,uBAAuB,CAAC,IAAD,EAAOpB,IAAP,EAAalE,OAAb,EAAsB6C,QAAtB,CAAvB;AACD;;AAUM,SAASqD,mBAAT,CACLhC,IADK,EAELlE,OAFK,EAGgC;AACrC,QAAM,CAACyG,CAAD,EAAIV,SAAJ,EAAeC,UAAf,IAA6BV,uBAAuB,CACxD,KADwD,EAExDpB,IAFwD,EAGxDlE,OAHwD,EAIxDuE,SAJwD,CAA1D;AAOA,SAAO;AACLwB,IAAAA,SADK;AAELC,IAAAA;AAFK,GAAP;AAID","sourcesContent":["/* eslint-disable no-dupe-class-members */\nimport { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport Stream from 'stream';\nimport {\n BinaryLike,\n binaryLikeToArrayBuffer,\n CipherEncoding,\n Encoding,\n getDefaultEncoding,\n kEmptyObject,\n validateFunction,\n validateObject,\n validateString,\n validateUint32,\n validateInt32,\n} from './Utils';\nimport { InternalCipher, RSAKeyVariant } from './NativeQuickCrypto/Cipher';\n// TODO(osp) re-enable type specific constructors\n// They are nice to have but not absolutely necessary\n// import type {\n// CipherCCMOptions,\n// CipherCCMTypes,\n// CipherGCMTypes,\n// CipherGCMOptions,\n// // CipherKey,\n// // KeyObject,\n// // TODO(Szymon) This types seem to be missing? Where did you get this definitions from?\n// // CipherOCBTypes,\n// // CipherOCBOptions,\n// } from 'crypto'; // Node crypto typings\nimport { StringDecoder } from 'string_decoder';\nimport { Buffer } from '@craftzdog/react-native-buffer';\nimport { Buffer as SBuffer } from 'safe-buffer';\nimport { constants } from './constants';\nimport {\n parsePrivateKeyEncoding,\n parsePublicKeyEncoding,\n preparePrivateKey,\n preparePublicOrPrivateKey,\n} from './keys';\n\n// make sure that nextTick is there\nglobal.process.nextTick = setImmediate;\n\nconst createInternalCipher = NativeQuickCrypto.createCipher;\nconst createInternalDecipher = NativeQuickCrypto.createDecipher;\nconst _publicEncrypt = NativeQuickCrypto.publicEncrypt;\nconst _publicDecrypt = NativeQuickCrypto.publicDecrypt;\nconst _privateDecrypt = NativeQuickCrypto.privateDecrypt;\n\nfunction getUIntOption(options: Record<string, any>, key: string) {\n let value;\n if (options && (value = options[key]) != null) {\n // >>> Turns any type into a positive integer (also sets the sign bit to 0)\n // eslint-disable-next-line no-bitwise\n if (value >>> 0 !== value) throw new Error(`options.${key}: ${value}`);\n return value;\n }\n return -1;\n}\n\nfunction normalizeEncoding(enc: string) {\n if (!enc) return 'utf8';\n var retried;\n while (true) {\n switch (enc) {\n case 'utf8':\n case 'utf-8':\n return 'utf8';\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n return 'utf16le';\n case 'latin1':\n case 'binary':\n return 'latin1';\n case 'base64':\n case 'ascii':\n case 'hex':\n return enc;\n default:\n if (retried) return; // undefined\n enc = ('' + enc).toLowerCase();\n retried = true;\n }\n }\n}\n\nfunction validateEncoding(data: string, encoding: string) {\n const normalizedEncoding = normalizeEncoding(encoding);\n const length = data.length;\n\n if (normalizedEncoding === 'hex' && length % 2 !== 0) {\n throw new Error(`Encoding ${encoding} not valid for data length ${length}`);\n }\n}\n\nfunction getDecoder(decoder?: StringDecoder, encoding?: BufferEncoding) {\n return decoder ?? new StringDecoder(encoding);\n}\n\nclass CipherCommon extends Stream.Transform {\n private internal: InternalCipher;\n private decoder: StringDecoder | undefined;\n\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n isCipher: boolean,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n super(options);\n const cipherKeyBuffer = binaryLikeToArrayBuffer(cipherKey);\n // TODO(osp) This might not be smart, check again after release\n const authTagLength = getUIntOption(options, 'authTagLength');\n const args = {\n cipher_type: cipherType,\n cipher_key: cipherKeyBuffer,\n iv,\n ...options,\n auth_tag_len: authTagLength,\n };\n this.internal = isCipher\n ? createInternalCipher(args)\n : createInternalDecipher(args);\n }\n\n update(\n data: BinaryLike,\n inputEncoding?: CipherEncoding,\n outputEncoding?: CipherEncoding\n ): ArrayBuffer | string {\n const defaultEncoding = getDefaultEncoding();\n inputEncoding = inputEncoding ?? defaultEncoding;\n outputEncoding = outputEncoding ?? defaultEncoding;\n\n if (typeof data === 'string') {\n validateEncoding(data, inputEncoding);\n } else if (!ArrayBuffer.isView(data)) {\n throw new Error('Invalid data argument');\n }\n\n if (typeof data === 'string') {\n // On node this is handled on the native side\n // on our case we need to correctly send the arraybuffer to the jsi side\n inputEncoding = inputEncoding === 'buffer' ? 'utf8' : inputEncoding;\n data = binaryLikeToArrayBuffer(data, inputEncoding);\n } else {\n data = binaryLikeToArrayBuffer(data as any, inputEncoding);\n }\n\n const ret = this.internal.update(data);\n\n if (outputEncoding && outputEncoding !== 'buffer') {\n this.decoder = getDecoder(this.decoder, outputEncoding);\n\n return this.decoder!.write(SBuffer.from(ret) as any);\n }\n\n return ret;\n }\n\n final(): ArrayBuffer;\n final(outputEncoding: BufferEncoding | 'buffer'): string;\n final(outputEncoding?: BufferEncoding | 'buffer'): ArrayBuffer | string {\n const ret = this.internal.final();\n\n if (outputEncoding && outputEncoding !== 'buffer') {\n this.decoder = getDecoder(this.decoder, outputEncoding);\n\n return this.decoder!.end(SBuffer.from(ret) as any);\n }\n\n return ret;\n }\n\n _transform(chunk: BinaryLike, encoding: Encoding, callback: () => void) {\n this.push(this.update(chunk, encoding));\n callback();\n }\n\n _flush(callback: () => void) {\n this.push(this.final());\n callback();\n }\n\n public setAutoPadding(autoPadding?: boolean): this {\n this.internal.setAutoPadding(!!autoPadding);\n return this;\n }\n\n public setAAD(\n buffer: Buffer,\n options?: {\n plaintextLength: number;\n }\n ): this {\n this.internal.setAAD({\n data: buffer.buffer,\n plaintextLength: options?.plaintextLength,\n });\n return this;\n }\n\n // protected getAuthTag(): Buffer {\n // return Buffer.from(this.internal.getAuthTag());\n // }\n\n public setAuthTag(tag: Buffer): this {\n this.internal.setAuthTag(tag.buffer);\n return this;\n }\n}\n\nclass Cipher extends CipherCommon {\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n if (iv != null) {\n iv = binaryLikeToArrayBuffer(iv);\n }\n super(cipherType, cipherKey, true, options, iv);\n }\n}\n\nclass Decipher extends CipherCommon {\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n if (iv != null) {\n iv = binaryLikeToArrayBuffer(iv);\n }\n\n super(cipherType, cipherKey, false, options, iv);\n }\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// export function createDecipher(\n// algorithm: CipherCCMTypes,\n// password: BinaryLike,\n// options: CipherCCMOptions\n// ): Decipher;\n// export function createDecipher(\n// algorithm: CipherGCMTypes,\n// password: BinaryLike,\n// options?: CipherGCMOptions\n// ): Decipher;\nexport function createDecipher(\n algorithm: string,\n password: BinaryLike,\n options?: Stream.TransformOptions\n): Decipher {\n return new Decipher(algorithm, password, options);\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// export function createDecipheriv(\n// algorithm: CipherCCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherCCMOptions\n// ): Decipher;\n// export function createDecipheriv(\n// algorithm: CipherOCBTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherOCBOptions\n// ): DecipherOCB;\n// export function createDecipheriv(\n// algorithm: CipherGCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options?: CipherGCMOptions\n// ): Decipher;\nexport function createDecipheriv(\n algorithm: string,\n key: BinaryLike,\n iv: BinaryLike | null,\n options?: Stream.TransformOptions\n): Decipher {\n return new Decipher(algorithm, key, options, iv);\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// commenting them out for now\n// export function createCipher(\n// algorithm: CipherCCMTypes,\n// password: BinaryLike,\n// options: CipherCCMOptions\n// ): Cipher;\n// export function createCipher(\n// algorithm: CipherGCMTypes,\n// password: BinaryLike,\n// options?: CipherGCMOptions\n// ): Cipher;\nexport function createCipher(\n algorithm: string,\n password: BinaryLike,\n options?: Stream.TransformOptions\n): Cipher {\n return new Cipher(algorithm, password, options);\n}\n\n// TODO(osp) on all the createCipheriv methods, node seems to use a \"KeyObject\" is seems to be a thread safe\n// object that creates keys and what not. Not sure if we should support it.\n// Fow now I replaced all of them to BinaryLike\n// export function createCipheriv(\n// algorithm: CipherCCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherCCMOptions\n// ): Cipher;\n// export function createCipheriv(\n// algorithm: CipherOCBTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherOCBOptions\n// ): CipherOCB;\n// export function createCipheriv(\n// algorithm: CipherGCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options?: CipherGCMOptions\n// ): Cipher;\nexport function createCipheriv(\n algorithm: string,\n key: BinaryLike,\n iv: BinaryLike | null,\n options?: Stream.TransformOptions\n): Cipher {\n return new Cipher(algorithm, key, options, iv);\n}\n\n// RSA Functions\n// Follows closely the model implemented in node\n\n// TODO(osp) types...\nfunction rsaFunctionFor(\n method: (\n data: ArrayBuffer,\n format: number,\n type: any,\n passphrase: any,\n buffer: ArrayBuffer,\n padding: number,\n oaepHash: any,\n oaepLabel: any\n ) => Buffer,\n defaultPadding: number,\n keyType: 'public' | 'private'\n) {\n return (\n options: {\n key: any;\n encoding?: string;\n format?: any;\n padding?: any;\n oaepHash?: any;\n oaepLabel?: any;\n passphrase?: string;\n },\n buffer: BinaryLike\n ) => {\n const { format, type, data, passphrase } =\n keyType === 'private'\n ? preparePrivateKey(options)\n : preparePublicOrPrivateKey(options);\n const padding = options.padding || defaultPadding;\n const { oaepHash, encoding } = options;\n let { oaepLabel } = options;\n if (oaepHash !== undefined) validateString(oaepHash, 'key.oaepHash');\n if (oaepLabel !== undefined)\n oaepLabel = binaryLikeToArrayBuffer(oaepLabel, encoding);\n buffer = binaryLikeToArrayBuffer(buffer, encoding);\n\n const rawRes = method(\n data,\n format,\n type,\n passphrase,\n buffer,\n padding,\n oaepHash,\n oaepLabel\n );\n\n return Buffer.from(rawRes);\n };\n}\n\nexport const publicEncrypt = rsaFunctionFor(\n _publicEncrypt,\n constants.RSA_PKCS1_OAEP_PADDING,\n 'public'\n);\nexport const publicDecrypt = rsaFunctionFor(\n _publicDecrypt,\n constants.RSA_PKCS1_PADDING,\n 'public'\n);\n// const privateEncrypt = rsaFunctionFor(_privateEncrypt, constants.RSA_PKCS1_PADDING,\n// 'private');\nexport const privateDecrypt = rsaFunctionFor(\n _privateDecrypt,\n constants.RSA_PKCS1_OAEP_PADDING,\n 'private'\n);\n\n// _ _ __ _____ _\n// | | | |/ / | __ \\ (_)\n// __ _ ___ _ __ ___ _ __ __ _| |_ ___| ' / ___ _ _| |__) |_ _ _ _ __\n// / _` |/ _ \\ '_ \\ / _ \\ '__/ _` | __/ _ \\ < / _ \\ | | | ___/ _` | | '__|\n// | (_| | __/ | | | __/ | | (_| | || __/ . \\ __/ |_| | | | (_| | | |\n// \\__, |\\___|_| |_|\\___|_| \\__,_|\\__\\___|_|\\_\\___|\\__, |_| \\__,_|_|_|\n// __/ | __/ |\n// |___/ |___/\ntype GenerateKeyPairOptions = {\n modulusLength: number; // Key size in bits (RSA, DSA).\n publicExponent?: number; // Public exponent (RSA). Default: 0x10001.\n hashAlgorithm?: string; // Name of the message digest (RSA-PSS).\n mgf1HashAlgorithm?: string; // string Name of the message digest used by MGF1 (RSA-PSS).\n saltLength?: number; // Minimal salt length in bytes (RSA-PSS).\n divisorLength?: number; // Size of q in bits (DSA).\n namedCurve?: string; // Name of the curve to use (EC).\n prime?: Buffer; // The prime parameter (DH).\n primeLength?: number; // Prime length in bits (DH).\n generator?: number; // Custom generator (DH). Default: 2.\n groupName?: string; // Diffie-Hellman group name (DH). See crypto.getDiffieHellman().\n publicKeyEncoding?: any; // See keyObject.export().\n privateKeyEncoding?: any; // See keyObject.export().\n paramEncoding?: string;\n hash?: any;\n mgf1Hash?: any;\n};\ntype GenerateKeyPairCallback = (\n error: unknown | null,\n publicKey?: Buffer,\n privateKey?: Buffer\n) => void;\n\nfunction parseKeyEncoding(\n keyType: string,\n options: GenerateKeyPairOptions = kEmptyObject\n) {\n const { publicKeyEncoding, privateKeyEncoding } = options;\n\n let publicFormat, publicType;\n if (publicKeyEncoding == null) {\n publicFormat = publicType = undefined;\n } else if (typeof publicKeyEncoding === 'object') {\n ({ format: publicFormat, type: publicType } = parsePublicKeyEncoding(\n publicKeyEncoding,\n keyType,\n 'publicKeyEncoding'\n ));\n } else {\n throw new Error(\n 'Invalid argument options.publicKeyEncoding',\n publicKeyEncoding\n );\n }\n\n let privateFormat, privateType, cipher, passphrase;\n if (privateKeyEncoding == null) {\n privateFormat = privateType = undefined;\n } else if (typeof privateKeyEncoding === 'object') {\n ({\n format: privateFormat,\n type: privateType,\n cipher,\n passphrase,\n } = parsePrivateKeyEncoding(\n privateKeyEncoding,\n keyType,\n 'privateKeyEncoding'\n ));\n } else {\n throw new Error(\n 'Invalid argument options.privateKeyEncoding',\n publicKeyEncoding\n );\n }\n\n return [\n publicFormat,\n publicType,\n privateFormat,\n privateType,\n cipher,\n passphrase,\n ];\n}\n\nfunction internalGenerateKeyPair(\n isAsync: boolean,\n type: string,\n options: GenerateKeyPairOptions | undefined,\n callback: GenerateKeyPairCallback | undefined\n) {\n // On node a very complex \"job\" chain is created, we are going for a far simpler approach and calling\n // an internal function that basically executes the same byte shuffling on the native side\n const encoding = parseKeyEncoding(type, options);\n\n // if (options !== undefined)\n // validateObject(options, 'options');\n\n switch (type) {\n case 'rsa-pss':\n case 'rsa': {\n validateObject<GenerateKeyPairOptions>(options, 'options');\n const { modulusLength } = options!;\n validateUint32(modulusLength, 'options.modulusLength');\n\n let { publicExponent } = options!;\n if (publicExponent == null) {\n publicExponent = 0x10001;\n } else {\n validateUint32(publicExponent, 'options.publicExponent');\n }\n\n if (type === 'rsa') {\n if (isAsync) {\n NativeQuickCrypto.generateKeyPair(\n RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5,\n modulusLength,\n publicExponent,\n ...encoding\n )\n .then(([err, publicKey, privateKey]) => {\n if (typeof publicKey === 'object') {\n publicKey = Buffer.from(publicKey);\n }\n if (typeof privateKey === 'object') {\n privateKey = Buffer.from(privateKey);\n }\n callback?.(err, publicKey, privateKey);\n })\n .catch((err) => {\n callback?.(err, undefined, undefined);\n });\n return;\n } else {\n let [err, publicKey, privateKey] =\n NativeQuickCrypto.generateKeyPairSync(\n RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5,\n modulusLength,\n publicExponent,\n ...encoding\n );\n\n if (typeof publicKey === 'object') {\n publicKey = Buffer.from(publicKey);\n }\n if (typeof privateKey === 'object') {\n privateKey = Buffer.from(privateKey);\n }\n\n return [err, publicKey, privateKey];\n }\n }\n\n const { hash, mgf1Hash, hashAlgorithm, mgf1HashAlgorithm, saltLength } =\n options!;\n\n // // We don't have a process object on RN\n // // const pendingDeprecation = getOptionValue('--pending-deprecation');\n\n if (saltLength !== undefined)\n validateInt32(saltLength, 'options.saltLength', 0);\n if (hashAlgorithm !== undefined)\n validateString(hashAlgorithm, 'options.hashAlgorithm');\n if (mgf1HashAlgorithm !== undefined)\n validateString(mgf1HashAlgorithm, 'options.mgf1HashAlgorithm');\n if (hash !== undefined) {\n // pendingDeprecation && process.emitWarning(\n // '\"options.hash\" is deprecated, ' +\n // 'use \"options.hashAlgorithm\" instead.',\n // 'DeprecationWarning',\n // 'DEP0154');\n validateString(hash, 'options.hash');\n if (hashAlgorithm && hash !== hashAlgorithm) {\n throw new Error(`Invalid Argument options.hash ${hash}`);\n }\n }\n if (mgf1Hash !== undefined) {\n // pendingDeprecation && process.emitWarning(\n // '\"options.mgf1Hash\" is deprecated, ' +\n // 'use \"options.mgf1HashAlgorithm\" instead.',\n // 'DeprecationWarning',\n // 'DEP0154');\n validateString(mgf1Hash, 'options.mgf1Hash');\n if (mgf1HashAlgorithm && mgf1Hash !== mgf1HashAlgorithm) {\n throw new Error(`Invalid Argument options.mgf1Hash ${mgf1Hash}`);\n }\n }\n\n return NativeQuickCrypto.generateKeyPairSync(\n RSAKeyVariant.kKeyVariantRSA_PSS,\n modulusLength,\n publicExponent,\n hashAlgorithm || hash,\n mgf1HashAlgorithm || mgf1Hash,\n saltLength,\n ...encoding\n );\n }\n // case 'dsa': {\n // validateObject(options, 'options');\n // const { modulusLength } = options!;\n // validateUint32(modulusLength, 'options.modulusLength');\n\n // let { divisorLength } = options!;\n // if (divisorLength == null) {\n // divisorLength = -1;\n // } else validateInt32(divisorLength, 'options.divisorLength', 0);\n\n // // return new DsaKeyPairGenJob(\n // // mode,\n // // modulusLength,\n // // divisorLength,\n // // ...encoding);\n // }\n // case 'ec': {\n // validateObject(options, 'options');\n // const { namedCurve } = options!;\n // validateString(namedCurve, 'options.namedCurve');\n // let { paramEncoding } = options!;\n // if (paramEncoding == null || paramEncoding === 'named')\n // paramEncoding = OPENSSL_EC_NAMED_CURVE;\n // else if (paramEncoding === 'explicit')\n // paramEncoding = OPENSSL_EC_EXPLICIT_CURVE;\n // else\n // throw new Error(`Invalid Argument options.paramEncoding ${paramEncoding}`);\n // // throw new ERR_INVALID_ARG_VALUE('options.paramEncoding', paramEncoding);\n\n // // return new EcKeyPairGenJob(mode, namedCurve, paramEncoding, ...encoding);\n // }\n // case 'ed25519':\n // case 'ed448':\n // case 'x25519':\n // case 'x448': {\n // let id;\n // switch (type) {\n // case 'ed25519':\n // id = EVP_PKEY_ED25519;\n // break;\n // case 'ed448':\n // id = EVP_PKEY_ED448;\n // break;\n // case 'x25519':\n // id = EVP_PKEY_X25519;\n // break;\n // case 'x448':\n // id = EVP_PKEY_X448;\n // break;\n // }\n // return new NidKeyPairGenJob(mode, id, ...encoding);\n // }\n // case 'dh': {\n // validateObject(options, 'options');\n // const { group, primeLength, prime, generator } = options;\n // if (group != null) {\n // if (prime != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'prime');\n // if (primeLength != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'primeLength');\n // if (generator != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'generator');\n\n // validateString(group, 'options.group');\n\n // return new DhKeyPairGenJob(mode, group, ...encoding);\n // }\n\n // if (prime != null) {\n // if (primeLength != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('prime', 'primeLength');\n\n // validateBuffer(prime, 'options.prime');\n // } else if (primeLength != null) {\n // validateInt32(primeLength, 'options.primeLength', 0);\n // } else {\n // throw new ERR_MISSING_OPTION(\n // 'At least one of the group, prime, or primeLength options'\n // );\n // }\n\n // if (generator != null) {\n // validateInt32(generator, 'options.generator', 0);\n // }\n // return new DhKeyPairGenJob(\n // mode,\n // prime != null ? prime : primeLength,\n // generator == null ? 2 : generator,\n // ...encoding\n // );\n // }\n default:\n // Fall through\n }\n throw new Error(\n `Invalid Argument options: ${type} scheme not supported. Currently not all encryption methods are supported in quick-crypto!`\n );\n}\n\n// TODO(osp) put correct types (e.g. type -> 'rsa', etc..)\nexport function generateKeyPair(\n type: string,\n callback: GenerateKeyPairCallback\n): void;\nexport function generateKeyPair(\n type: string,\n options: GenerateKeyPairOptions,\n callback: GenerateKeyPairCallback\n): void;\nexport function generateKeyPair(\n type: string,\n options?: GenerateKeyPairCallback | GenerateKeyPairOptions,\n callback?: GenerateKeyPairCallback\n) {\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n\n validateFunction(callback);\n\n internalGenerateKeyPair(true, type, options, callback);\n}\n\nexport function generateKeyPairSync(type: string): {\n publicKey: any;\n privateKey: any;\n};\nexport function generateKeyPairSync(\n type: string,\n options: GenerateKeyPairOptions\n): { publicKey: any; privateKey: any };\nexport function generateKeyPairSync(\n type: string,\n options?: GenerateKeyPairOptions\n): { publicKey: any; privateKey: any } {\n const [_, publicKey, privateKey] = internalGenerateKeyPair(\n false,\n type,\n options,\n undefined\n )!;\n\n return {\n publicKey,\n privateKey,\n };\n}\n"]}
1
+ {"version":3,"sources":["Cipher.ts"],"names":["global","process","nextTick","setImmediate","createInternalCipher","NativeQuickCrypto","createCipher","createInternalDecipher","createDecipher","_publicEncrypt","publicEncrypt","_publicDecrypt","publicDecrypt","_privateDecrypt","privateDecrypt","getUIntOption","options","key","value","Error","normalizeEncoding","enc","retried","toLowerCase","validateEncoding","data","encoding","normalizedEncoding","length","getDecoder","decoder","StringDecoder","CipherCommon","Stream","Transform","constructor","cipherType","cipherKey","isCipher","iv","cipherKeyBuffer","authTagLength","args","cipher_type","cipher_key","auth_tag_len","internal","update","inputEncoding","outputEncoding","defaultEncoding","ArrayBuffer","isView","ret","write","SBuffer","from","final","end","_transform","chunk","callback","push","_flush","setAutoPadding","autoPadding","setAAD","buffer","plaintextLength","setAuthTag","tag","Cipher","Decipher","algorithm","password","createDecipheriv","createCipheriv","rsaFunctionFor","method","defaultPadding","keyType","format","type","passphrase","padding","oaepHash","oaepLabel","undefined","rawRes","Buffer","constants","RSA_PKCS1_OAEP_PADDING","RSA_PKCS1_PADDING","parseKeyEncoding","kEmptyObject","publicKeyEncoding","privateKeyEncoding","publicFormat","publicType","privateFormat","privateType","cipher","internalGenerateKeyPair","isAsync","modulusLength","publicExponent","generateKeyPair","RSAKeyVariant","kKeyVariantRSA_SSA_PKCS1_v1_5","then","err","publicKey","privateKey","catch","generateKeyPairSync","hash","mgf1Hash","hashAlgorithm","mgf1HashAlgorithm","saltLength","kKeyVariantRSA_PSS","_"],"mappings":";;;;;;;;;;;;;AACA;;AACA;;AACA;;AAaA;;AAcA;;AACA;;AACA;;AACA;;AACA;;;;;;AAOA;AACAA,MAAM,CAACC,OAAP,CAAeC,QAAf,GAA0BC,YAA1B;AAEA,MAAMC,oBAAoB,GAAGC,qCAAkBC,YAA/C;AACA,MAAMC,sBAAsB,GAAGF,qCAAkBG,cAAjD;AACA,MAAMC,cAAc,GAAGJ,qCAAkBK,aAAzC;AACA,MAAMC,cAAc,GAAGN,qCAAkBO,aAAzC;AACA,MAAMC,eAAe,GAAGR,qCAAkBS,cAA1C;;AAEA,SAASC,aAAT,CAAuBC,OAAvB,EAAqDC,GAArD,EAAkE;AAChE,MAAIC,KAAJ;;AACA,MAAIF,OAAO,IAAI,CAACE,KAAK,GAAGF,OAAO,CAACC,GAAD,CAAhB,KAA0B,IAAzC,EAA+C;AAC7C;AACA;AACA,QAAIC,KAAK,KAAK,CAAV,KAAgBA,KAApB,EAA2B,MAAM,IAAIC,KAAJ,CAAW,WAAUF,GAAI,KAAIC,KAAM,EAAnC,CAAN;AAC3B,WAAOA,KAAP;AACD;;AACD,SAAO,CAAC,CAAR;AACD;;AAED,SAASE,iBAAT,CAA2BC,GAA3B,EAAwC;AACtC,MAAI,CAACA,GAAL,EAAU,OAAO,MAAP;AACV,MAAIC,OAAJ;;AACA,SAAO,IAAP,EAAa;AACX,YAAQD,GAAR;AACE,WAAK,MAAL;AACA,WAAK,OAAL;AACE,eAAO,MAAP;;AACF,WAAK,MAAL;AAC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;AACF,YAAIC,iBAAiB,KAAK/B,SAA1B,EACE,2BAAe+B,iBAAf,EAAkC,2BAAlC;;AACF,YAAIH,IAAI,KAAK5B,SAAb,EAAwB;AACtB;AACA;AACA;AACA;AACA;AACA,qCAAe4B,IAAf,EAAqB,cAArB;;AACA,cAAIE,aAAa,IAAIF,IAAI,KAAKE,aAA9B,EAA6C;AAC3C,kBAAM,IAAIlG,KAAJ,CAAW,iCAAgCgG,IAAK,EAAhD,CAAN;AACD;AACF;;AACD,YAAIC,QAAQ,KAAK7B,SAAjB,EAA4B;AAC1B;AACA;AACA;AACA;AACA;AACA,qCAAe6B,QAAf,EAAyB,kBAAzB;;AACA,cAAIE,iBAAiB,IAAIF,QAAQ,KAAKE,iBAAtC,EAAyD;AACvD,kBAAM,IAAInG,KAAJ,CAAW,qCAAoCiG,QAAS,EAAxD,CAAN;AACD;AACF;;AAED,eAAO/G,qCAAkB6G,mBAAlB,CACLP,sBAAca,kBADT,EAELhB,aAFK,EAGLC,cAHK,EAILY,aAAa,IAAIF,IAJZ,EAKLG,iBAAiB,IAAIF,QALhB,EAMLG,UANK,EAOL,GAAG7F,QAPE,CAAP;AASD;AACD;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,YA/LF,CAgME;;AAhMF;;AAkMA,QAAM,IAAIP,KAAJ,CACH,6BAA4B+D,IAAK,4FAD9B,CAAN;AAGD,C,CAED;;;AAUO,SAASwB,eAAT,CACLxB,IADK,EAELlE,OAFK,EAGL6C,QAHK,EAIL;AACA,MAAI,OAAO7C,OAAP,KAAmB,UAAvB,EAAmC;AACjC6C,IAAAA,QAAQ,GAAG7C,OAAX;AACAA,IAAAA,OAAO,GAAGuE,SAAV;AACD;;AAED,+BAAiB1B,QAAjB;AAEAyC,EAAAA,uBAAuB,CAAC,IAAD,EAAOpB,IAAP,EAAalE,OAAb,EAAsB6C,QAAtB,CAAvB;AACD;;AAUM,SAASqD,mBAAT,CACLhC,IADK,EAELlE,OAFK,EAGgC;AACrC;AACA,QAAM,CAACyG,CAAD,EAAIV,SAAJ,EAAeC,UAAf,IAA6BV,uBAAuB,CACxD,KADwD,EAExDpB,IAFwD,EAGxDlE,OAHwD,EAIxDuE,SAJwD,CAA1D;AAOA,SAAO;AACLwB,IAAAA,SADK;AAELC,IAAAA;AAFK,GAAP;AAID","sourcesContent":["/* eslint-disable no-dupe-class-members */\nimport { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport Stream from 'stream-browserify';\nimport {\n BinaryLike,\n binaryLikeToArrayBuffer,\n CipherEncoding,\n Encoding,\n getDefaultEncoding,\n kEmptyObject,\n validateFunction,\n validateObject,\n validateString,\n validateUint32,\n validateInt32,\n} from './Utils';\nimport { InternalCipher, RSAKeyVariant } from './NativeQuickCrypto/Cipher';\n// TODO(osp) re-enable type specific constructors\n// They are nice to have but not absolutely necessary\n// import type {\n// CipherCCMOptions,\n// CipherCCMTypes,\n// CipherGCMTypes,\n// CipherGCMOptions,\n// // CipherKey,\n// // KeyObject,\n// // TODO(Szymon) This types seem to be missing? Where did you get this definitions from?\n// // CipherOCBTypes,\n// // CipherOCBOptions,\n// } from 'crypto'; // Node crypto typings\nimport { StringDecoder } from 'string_decoder';\nimport { Buffer } from '@craftzdog/react-native-buffer';\nimport { Buffer as SBuffer } from 'safe-buffer';\nimport { constants } from './constants';\nimport {\n parsePrivateKeyEncoding,\n parsePublicKeyEncoding,\n preparePrivateKey,\n preparePublicOrPrivateKey,\n} from './keys';\n\n// make sure that nextTick is there\nglobal.process.nextTick = setImmediate;\n\nconst createInternalCipher = NativeQuickCrypto.createCipher;\nconst createInternalDecipher = NativeQuickCrypto.createDecipher;\nconst _publicEncrypt = NativeQuickCrypto.publicEncrypt;\nconst _publicDecrypt = NativeQuickCrypto.publicDecrypt;\nconst _privateDecrypt = NativeQuickCrypto.privateDecrypt;\n\nfunction getUIntOption(options: Record<string, any>, key: string) {\n let value;\n if (options && (value = options[key]) != null) {\n // >>> Turns any type into a positive integer (also sets the sign bit to 0)\n // eslint-disable-next-line no-bitwise\n if (value >>> 0 !== value) throw new Error(`options.${key}: ${value}`);\n return value;\n }\n return -1;\n}\n\nfunction normalizeEncoding(enc: string) {\n if (!enc) return 'utf8';\n var retried;\n while (true) {\n switch (enc) {\n case 'utf8':\n case 'utf-8':\n return 'utf8';\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n return 'utf16le';\n case 'latin1':\n case 'binary':\n return 'latin1';\n case 'base64':\n case 'ascii':\n case 'hex':\n return enc;\n default:\n if (retried) return; // undefined\n enc = ('' + enc).toLowerCase();\n retried = true;\n }\n }\n}\n\nfunction validateEncoding(data: string, encoding: string) {\n const normalizedEncoding = normalizeEncoding(encoding);\n const length = data.length;\n\n if (normalizedEncoding === 'hex' && length % 2 !== 0) {\n throw new Error(`Encoding ${encoding} not valid for data length ${length}`);\n }\n}\n\nfunction getDecoder(decoder?: StringDecoder, encoding?: BufferEncoding) {\n return decoder ?? new StringDecoder(encoding);\n}\n\nclass CipherCommon extends Stream.Transform {\n private internal: InternalCipher;\n private decoder: StringDecoder | undefined;\n\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n isCipher: boolean,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n super(options);\n const cipherKeyBuffer = binaryLikeToArrayBuffer(cipherKey);\n // TODO(osp) This might not be smart, check again after release\n const authTagLength = getUIntOption(options, 'authTagLength');\n const args = {\n cipher_type: cipherType,\n cipher_key: cipherKeyBuffer,\n iv,\n ...options,\n auth_tag_len: authTagLength,\n };\n this.internal = isCipher\n ? createInternalCipher(args)\n : createInternalDecipher(args);\n }\n\n update(\n data: BinaryLike,\n inputEncoding?: CipherEncoding,\n outputEncoding?: CipherEncoding\n ): ArrayBuffer | string {\n const defaultEncoding = getDefaultEncoding();\n inputEncoding = inputEncoding ?? defaultEncoding;\n outputEncoding = outputEncoding ?? defaultEncoding;\n\n if (typeof data === 'string') {\n validateEncoding(data, inputEncoding);\n } else if (!ArrayBuffer.isView(data)) {\n throw new Error('Invalid data argument');\n }\n\n if (typeof data === 'string') {\n // On node this is handled on the native side\n // on our case we need to correctly send the arraybuffer to the jsi side\n inputEncoding = inputEncoding === 'buffer' ? 'utf8' : inputEncoding;\n data = binaryLikeToArrayBuffer(data, inputEncoding);\n } else {\n data = binaryLikeToArrayBuffer(data as any, inputEncoding);\n }\n\n const ret = this.internal.update(data);\n\n if (outputEncoding && outputEncoding !== 'buffer') {\n this.decoder = getDecoder(this.decoder, outputEncoding);\n\n return this.decoder!.write(SBuffer.from(ret) as any);\n }\n\n return ret;\n }\n\n final(): ArrayBuffer;\n final(outputEncoding: BufferEncoding | 'buffer'): string;\n final(outputEncoding?: BufferEncoding | 'buffer'): ArrayBuffer | string {\n const ret = this.internal.final();\n\n if (outputEncoding && outputEncoding !== 'buffer') {\n this.decoder = getDecoder(this.decoder, outputEncoding);\n\n return this.decoder!.end(SBuffer.from(ret) as any);\n }\n\n return ret;\n }\n\n _transform(chunk: BinaryLike, encoding: Encoding, callback: () => void) {\n this.push(this.update(chunk, encoding));\n callback();\n }\n\n _flush(callback: () => void) {\n this.push(this.final());\n callback();\n }\n\n public setAutoPadding(autoPadding?: boolean): this {\n this.internal.setAutoPadding(!!autoPadding);\n return this;\n }\n\n public setAAD(\n buffer: Buffer,\n options?: {\n plaintextLength: number;\n }\n ): this {\n this.internal.setAAD({\n data: buffer.buffer,\n plaintextLength: options?.plaintextLength,\n });\n return this;\n }\n\n // protected getAuthTag(): Buffer {\n // return Buffer.from(this.internal.getAuthTag());\n // }\n\n public setAuthTag(tag: Buffer): this {\n this.internal.setAuthTag(tag.buffer);\n return this;\n }\n}\n\nclass Cipher extends CipherCommon {\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n if (iv != null) {\n iv = binaryLikeToArrayBuffer(iv);\n }\n super(cipherType, cipherKey, true, options, iv);\n }\n}\n\nclass Decipher extends CipherCommon {\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n if (iv != null) {\n iv = binaryLikeToArrayBuffer(iv);\n }\n\n super(cipherType, cipherKey, false, options, iv);\n }\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// export function createDecipher(\n// algorithm: CipherCCMTypes,\n// password: BinaryLike,\n// options: CipherCCMOptions\n// ): Decipher;\n// export function createDecipher(\n// algorithm: CipherGCMTypes,\n// password: BinaryLike,\n// options?: CipherGCMOptions\n// ): Decipher;\nexport function createDecipher(\n algorithm: string,\n password: BinaryLike,\n options?: Stream.TransformOptions\n): Decipher {\n return new Decipher(algorithm, password, options);\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// export function createDecipheriv(\n// algorithm: CipherCCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherCCMOptions\n// ): Decipher;\n// export function createDecipheriv(\n// algorithm: CipherOCBTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherOCBOptions\n// ): DecipherOCB;\n// export function createDecipheriv(\n// algorithm: CipherGCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options?: CipherGCMOptions\n// ): Decipher;\nexport function createDecipheriv(\n algorithm: string,\n key: BinaryLike,\n iv: BinaryLike | null,\n options?: Stream.TransformOptions\n): Decipher {\n return new Decipher(algorithm, key, options, iv);\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// commenting them out for now\n// export function createCipher(\n// algorithm: CipherCCMTypes,\n// password: BinaryLike,\n// options: CipherCCMOptions\n// ): Cipher;\n// export function createCipher(\n// algorithm: CipherGCMTypes,\n// password: BinaryLike,\n// options?: CipherGCMOptions\n// ): Cipher;\nexport function createCipher(\n algorithm: string,\n password: BinaryLike,\n options?: Stream.TransformOptions\n): Cipher {\n return new Cipher(algorithm, password, options);\n}\n\n// TODO(osp) on all the createCipheriv methods, node seems to use a \"KeyObject\" is seems to be a thread safe\n// object that creates keys and what not. Not sure if we should support it.\n// Fow now I replaced all of them to BinaryLike\n// export function createCipheriv(\n// algorithm: CipherCCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherCCMOptions\n// ): Cipher;\n// export function createCipheriv(\n// algorithm: CipherOCBTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherOCBOptions\n// ): CipherOCB;\n// export function createCipheriv(\n// algorithm: CipherGCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options?: CipherGCMOptions\n// ): Cipher;\nexport function createCipheriv(\n algorithm: string,\n key: BinaryLike,\n iv: BinaryLike | null,\n options?: Stream.TransformOptions\n): Cipher {\n return new Cipher(algorithm, key, options, iv);\n}\n\n// RSA Functions\n// Follows closely the model implemented in node\n\n// TODO(osp) types...\nfunction rsaFunctionFor(\n method: (\n data: ArrayBuffer,\n format: number,\n type: any,\n passphrase: any,\n buffer: ArrayBuffer,\n padding: number,\n oaepHash: any,\n oaepLabel: any\n ) => Buffer,\n defaultPadding: number,\n keyType: 'public' | 'private'\n) {\n return (\n options: {\n key: any;\n encoding?: string;\n format?: any;\n padding?: any;\n oaepHash?: any;\n oaepLabel?: any;\n passphrase?: string;\n },\n buffer: BinaryLike\n ) => {\n const { format, type, data, passphrase } =\n keyType === 'private'\n ? preparePrivateKey(options)\n : preparePublicOrPrivateKey(options);\n const padding = options.padding || defaultPadding;\n const { oaepHash, encoding } = options;\n let { oaepLabel } = options;\n if (oaepHash !== undefined) validateString(oaepHash, 'key.oaepHash');\n if (oaepLabel !== undefined)\n oaepLabel = binaryLikeToArrayBuffer(oaepLabel, encoding);\n buffer = binaryLikeToArrayBuffer(buffer, encoding);\n\n const rawRes = method(\n data,\n format,\n type,\n passphrase,\n buffer,\n padding,\n oaepHash,\n oaepLabel\n );\n\n return Buffer.from(rawRes);\n };\n}\n\nexport const publicEncrypt = rsaFunctionFor(\n _publicEncrypt,\n constants.RSA_PKCS1_OAEP_PADDING,\n 'public'\n);\nexport const publicDecrypt = rsaFunctionFor(\n _publicDecrypt,\n constants.RSA_PKCS1_PADDING,\n 'public'\n);\n// const privateEncrypt = rsaFunctionFor(_privateEncrypt, constants.RSA_PKCS1_PADDING,\n// 'private');\nexport const privateDecrypt = rsaFunctionFor(\n _privateDecrypt,\n constants.RSA_PKCS1_OAEP_PADDING,\n 'private'\n);\n\n// _ _ __ _____ _\n// | | | |/ / | __ \\ (_)\n// __ _ ___ _ __ ___ _ __ __ _| |_ ___| ' / ___ _ _| |__) |_ _ _ _ __\n// / _` |/ _ \\ '_ \\ / _ \\ '__/ _` | __/ _ \\ < / _ \\ | | | ___/ _` | | '__|\n// | (_| | __/ | | | __/ | | (_| | || __/ . \\ __/ |_| | | | (_| | | |\n// \\__, |\\___|_| |_|\\___|_| \\__,_|\\__\\___|_|\\_\\___|\\__, |_| \\__,_|_|_|\n// __/ | __/ |\n// |___/ |___/\ntype GenerateKeyPairOptions = {\n modulusLength: number; // Key size in bits (RSA, DSA).\n publicExponent?: number; // Public exponent (RSA). Default: 0x10001.\n hashAlgorithm?: string; // Name of the message digest (RSA-PSS).\n mgf1HashAlgorithm?: string; // string Name of the message digest used by MGF1 (RSA-PSS).\n saltLength?: number; // Minimal salt length in bytes (RSA-PSS).\n divisorLength?: number; // Size of q in bits (DSA).\n namedCurve?: string; // Name of the curve to use (EC).\n prime?: Buffer; // The prime parameter (DH).\n primeLength?: number; // Prime length in bits (DH).\n generator?: number; // Custom generator (DH). Default: 2.\n groupName?: string; // Diffie-Hellman group name (DH). See crypto.getDiffieHellman().\n publicKeyEncoding?: any; // See keyObject.export().\n privateKeyEncoding?: any; // See keyObject.export().\n paramEncoding?: string;\n hash?: any;\n mgf1Hash?: any;\n};\ntype GenerateKeyPairCallback = (\n error: unknown | null,\n publicKey?: Buffer,\n privateKey?: Buffer\n) => void;\n\nfunction parseKeyEncoding(\n keyType: string,\n options: GenerateKeyPairOptions = kEmptyObject\n) {\n const { publicKeyEncoding, privateKeyEncoding } = options;\n\n let publicFormat, publicType;\n if (publicKeyEncoding == null) {\n publicFormat = publicType = undefined;\n } else if (typeof publicKeyEncoding === 'object') {\n ({ format: publicFormat, type: publicType } = parsePublicKeyEncoding(\n publicKeyEncoding,\n keyType,\n 'publicKeyEncoding'\n ));\n } else {\n throw new Error(\n 'Invalid argument options.publicKeyEncoding',\n publicKeyEncoding\n );\n }\n\n let privateFormat, privateType, cipher, passphrase;\n if (privateKeyEncoding == null) {\n privateFormat = privateType = undefined;\n } else if (typeof privateKeyEncoding === 'object') {\n ({\n format: privateFormat,\n type: privateType,\n cipher,\n passphrase,\n } = parsePrivateKeyEncoding(\n privateKeyEncoding,\n keyType,\n 'privateKeyEncoding'\n ));\n } else {\n throw new Error(\n 'Invalid argument options.privateKeyEncoding',\n publicKeyEncoding\n );\n }\n\n return [\n publicFormat,\n publicType,\n privateFormat,\n privateType,\n cipher,\n passphrase,\n ];\n}\n\nfunction internalGenerateKeyPair(\n isAsync: boolean,\n type: string,\n options: GenerateKeyPairOptions | undefined,\n callback: GenerateKeyPairCallback | undefined\n) {\n // On node a very complex \"job\" chain is created, we are going for a far simpler approach and calling\n // an internal function that basically executes the same byte shuffling on the native side\n const encoding = parseKeyEncoding(type, options);\n\n // if (options !== undefined)\n // validateObject(options, 'options');\n\n switch (type) {\n case 'rsa-pss':\n case 'rsa': {\n validateObject<GenerateKeyPairOptions>(options, 'options');\n const { modulusLength } = options!;\n validateUint32(modulusLength, 'options.modulusLength');\n\n let { publicExponent } = options!;\n if (publicExponent == null) {\n publicExponent = 0x10001;\n } else {\n validateUint32(publicExponent, 'options.publicExponent');\n }\n\n if (type === 'rsa') {\n if (isAsync) {\n NativeQuickCrypto.generateKeyPair(\n RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5,\n modulusLength,\n publicExponent,\n ...encoding\n )\n .then(([err, publicKey, privateKey]) => {\n if (typeof publicKey === 'object') {\n publicKey = Buffer.from(publicKey);\n }\n if (typeof privateKey === 'object') {\n privateKey = Buffer.from(privateKey);\n }\n callback?.(err, publicKey, privateKey);\n })\n .catch((err) => {\n callback?.(err, undefined, undefined);\n });\n return;\n } else {\n let [err, publicKey, privateKey] =\n NativeQuickCrypto.generateKeyPairSync(\n RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5,\n modulusLength,\n publicExponent,\n ...encoding\n );\n\n if (typeof publicKey === 'object') {\n publicKey = Buffer.from(publicKey);\n }\n if (typeof privateKey === 'object') {\n privateKey = Buffer.from(privateKey);\n }\n\n return [err, publicKey, privateKey];\n }\n }\n\n const { hash, mgf1Hash, hashAlgorithm, mgf1HashAlgorithm, saltLength } =\n options!;\n\n // // We don't have a process object on RN\n // // const pendingDeprecation = getOptionValue('--pending-deprecation');\n\n if (saltLength !== undefined)\n validateInt32(saltLength, 'options.saltLength', 0);\n if (hashAlgorithm !== undefined)\n validateString(hashAlgorithm, 'options.hashAlgorithm');\n if (mgf1HashAlgorithm !== undefined)\n validateString(mgf1HashAlgorithm, 'options.mgf1HashAlgorithm');\n if (hash !== undefined) {\n // pendingDeprecation && process.emitWarning(\n // '\"options.hash\" is deprecated, ' +\n // 'use \"options.hashAlgorithm\" instead.',\n // 'DeprecationWarning',\n // 'DEP0154');\n validateString(hash, 'options.hash');\n if (hashAlgorithm && hash !== hashAlgorithm) {\n throw new Error(`Invalid Argument options.hash ${hash}`);\n }\n }\n if (mgf1Hash !== undefined) {\n // pendingDeprecation && process.emitWarning(\n // '\"options.mgf1Hash\" is deprecated, ' +\n // 'use \"options.mgf1HashAlgorithm\" instead.',\n // 'DeprecationWarning',\n // 'DEP0154');\n validateString(mgf1Hash, 'options.mgf1Hash');\n if (mgf1HashAlgorithm && mgf1Hash !== mgf1HashAlgorithm) {\n throw new Error(`Invalid Argument options.mgf1Hash ${mgf1Hash}`);\n }\n }\n\n return NativeQuickCrypto.generateKeyPairSync(\n RSAKeyVariant.kKeyVariantRSA_PSS,\n modulusLength,\n publicExponent,\n hashAlgorithm || hash,\n mgf1HashAlgorithm || mgf1Hash,\n saltLength,\n ...encoding\n );\n }\n // case 'dsa': {\n // validateObject(options, 'options');\n // const { modulusLength } = options!;\n // validateUint32(modulusLength, 'options.modulusLength');\n\n // let { divisorLength } = options!;\n // if (divisorLength == null) {\n // divisorLength = -1;\n // } else validateInt32(divisorLength, 'options.divisorLength', 0);\n\n // // return new DsaKeyPairGenJob(\n // // mode,\n // // modulusLength,\n // // divisorLength,\n // // ...encoding);\n // }\n // case 'ec': {\n // validateObject(options, 'options');\n // const { namedCurve } = options!;\n // validateString(namedCurve, 'options.namedCurve');\n // let { paramEncoding } = options!;\n // if (paramEncoding == null || paramEncoding === 'named')\n // paramEncoding = OPENSSL_EC_NAMED_CURVE;\n // else if (paramEncoding === 'explicit')\n // paramEncoding = OPENSSL_EC_EXPLICIT_CURVE;\n // else\n // throw new Error(`Invalid Argument options.paramEncoding ${paramEncoding}`);\n // // throw new ERR_INVALID_ARG_VALUE('options.paramEncoding', paramEncoding);\n\n // // return new EcKeyPairGenJob(mode, namedCurve, paramEncoding, ...encoding);\n // }\n // case 'ed25519':\n // case 'ed448':\n // case 'x25519':\n // case 'x448': {\n // let id;\n // switch (type) {\n // case 'ed25519':\n // id = EVP_PKEY_ED25519;\n // break;\n // case 'ed448':\n // id = EVP_PKEY_ED448;\n // break;\n // case 'x25519':\n // id = EVP_PKEY_X25519;\n // break;\n // case 'x448':\n // id = EVP_PKEY_X448;\n // break;\n // }\n // return new NidKeyPairGenJob(mode, id, ...encoding);\n // }\n // case 'dh': {\n // validateObject(options, 'options');\n // const { group, primeLength, prime, generator } = options;\n // if (group != null) {\n // if (prime != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'prime');\n // if (primeLength != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'primeLength');\n // if (generator != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'generator');\n\n // validateString(group, 'options.group');\n\n // return new DhKeyPairGenJob(mode, group, ...encoding);\n // }\n\n // if (prime != null) {\n // if (primeLength != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('prime', 'primeLength');\n\n // validateBuffer(prime, 'options.prime');\n // } else if (primeLength != null) {\n // validateInt32(primeLength, 'options.primeLength', 0);\n // } else {\n // throw new ERR_MISSING_OPTION(\n // 'At least one of the group, prime, or primeLength options'\n // );\n // }\n\n // if (generator != null) {\n // validateInt32(generator, 'options.generator', 0);\n // }\n // return new DhKeyPairGenJob(\n // mode,\n // prime != null ? prime : primeLength,\n // generator == null ? 2 : generator,\n // ...encoding\n // );\n // }\n default:\n // Fall through\n }\n throw new Error(\n `Invalid Argument options: ${type} scheme not supported. Currently not all encryption methods are supported in quick-crypto!`\n );\n}\n\n// TODO(osp) put correct types (e.g. type -> 'rsa', etc..)\nexport function generateKeyPair(\n type: string,\n callback: GenerateKeyPairCallback\n): void;\nexport function generateKeyPair(\n type: string,\n options: GenerateKeyPairOptions,\n callback: GenerateKeyPairCallback\n): void;\nexport function generateKeyPair(\n type: string,\n options?: GenerateKeyPairCallback | GenerateKeyPairOptions,\n callback?: GenerateKeyPairCallback\n) {\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n\n validateFunction(callback);\n\n internalGenerateKeyPair(true, type, options, callback);\n}\n\nexport function generateKeyPairSync(type: string): {\n publicKey: any;\n privateKey: any;\n};\nexport function generateKeyPairSync(\n type: string,\n options: GenerateKeyPairOptions\n): { publicKey: any; privateKey: any };\nexport function generateKeyPairSync(\n type: string,\n options?: GenerateKeyPairOptions\n): { publicKey: any; privateKey: any } {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [_, publicKey, privateKey] = internalGenerateKeyPair(\n false,\n type,\n options,\n undefined\n )!;\n\n return {\n publicKey,\n privateKey,\n };\n}\n"]}
@@ -11,7 +11,7 @@ var _NativeQuickCrypto = require("./NativeQuickCrypto/NativeQuickCrypto");
11
11
 
12
12
  var _Utils = require("./Utils");
13
13
 
14
- var _stream = _interopRequireDefault(require("stream"));
14
+ var _streamBrowserify = _interopRequireDefault(require("stream-browserify"));
15
15
 
16
16
  var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
17
17
 
@@ -26,7 +26,7 @@ function createHash(algorithm, options) {
26
26
  return new Hash(algorithm, options);
27
27
  }
28
28
 
29
- class Hash extends _stream.default.Transform {
29
+ class Hash extends _streamBrowserify.default.Transform {
30
30
  constructor(arg, options) {
31
31
  super(options !== null && options !== void 0 ? options : undefined);
32
32