react-native-quick-crypto 0.6.1 → 0.7.0-rc.1

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 (205) hide show
  1. package/README.md +70 -18
  2. package/android/CMakeLists.txt +58 -61
  3. package/android/build.gradle +105 -53
  4. package/android/gradle.properties +5 -5
  5. package/android/src/main/{AndroidManifest.xml → AndroidManifestNew.xml} +1 -2
  6. package/cpp/Cipher/MGLCipherHostObject.cpp +30 -6
  7. package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +21 -31
  8. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +4 -17
  9. package/cpp/Cipher/MGLPublicCipher.h +1 -1
  10. package/cpp/Cipher/MGLPublicCipherInstaller.h +6 -6
  11. package/cpp/Cipher/MGLRsa.cpp +224 -11
  12. package/cpp/Cipher/MGLRsa.h +13 -3
  13. package/cpp/Hash/MGLHashHostObject.cpp +1 -1
  14. package/cpp/Hash/MGLHashInstaller.cpp +2 -4
  15. package/cpp/JSIUtils/MGLJSIMacros.h +10 -0
  16. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +1 -1
  17. package/cpp/MGLKeys.cpp +415 -471
  18. package/cpp/MGLKeys.h +70 -2
  19. package/cpp/MGLQuickCryptoHostObject.cpp +9 -0
  20. package/cpp/Random/MGLRandomHostObject.cpp +9 -2
  21. package/cpp/Sig/MGLSignHostObjects.cpp +1 -1
  22. package/cpp/Utils/MGLUtils.cpp +104 -32
  23. package/cpp/Utils/MGLUtils.h +172 -143
  24. package/cpp/Utils/node.h +13 -0
  25. package/cpp/webcrypto/MGLWebCrypto.cpp +63 -0
  26. package/cpp/webcrypto/MGLWebCrypto.h +34 -0
  27. package/cpp/webcrypto/crypto_ec.cpp +334 -0
  28. package/cpp/webcrypto/crypto_ec.h +65 -0
  29. package/ios/QuickCrypto.xcodeproj/project.pbxproj +4 -4
  30. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  31. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  32. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcuserdata/brad.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  33. package/ios/QuickCrypto.xcodeproj/xcuserdata/brad.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  34. package/lib/commonjs/@types/crypto-browserify.d.js.map +1 -1
  35. package/lib/commonjs/Cipher.js +54 -195
  36. package/lib/commonjs/Cipher.js.map +1 -1
  37. package/lib/commonjs/Hash.js +29 -29
  38. package/lib/commonjs/Hash.js.map +1 -1
  39. package/lib/commonjs/Hashnames.js +75 -0
  40. package/lib/commonjs/Hashnames.js.map +1 -0
  41. package/lib/commonjs/Hmac.js +6 -29
  42. package/lib/commonjs/Hmac.js.map +1 -1
  43. package/lib/commonjs/NativeQuickCrypto/Cipher.js +3 -5
  44. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -1
  45. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +11 -20
  46. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  47. package/lib/commonjs/NativeQuickCrypto/hash.js.map +1 -1
  48. package/lib/commonjs/NativeQuickCrypto/hmac.js.map +1 -1
  49. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +1 -1
  50. package/lib/commonjs/NativeQuickCrypto/random.js.map +1 -1
  51. package/lib/commonjs/NativeQuickCrypto/sig.js.map +1 -1
  52. package/lib/commonjs/NativeQuickCrypto/webcrypto.js +6 -0
  53. package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +1 -0
  54. package/lib/commonjs/QuickCrypto.js +9 -15
  55. package/lib/commonjs/QuickCrypto.js.map +1 -1
  56. package/lib/commonjs/Utils.js +374 -48
  57. package/lib/commonjs/Utils.js.map +1 -1
  58. package/lib/commonjs/aes.js +324 -0
  59. package/lib/commonjs/aes.js.map +1 -0
  60. package/lib/commonjs/constants.js +1 -2
  61. package/lib/commonjs/constants.js.map +1 -1
  62. package/lib/commonjs/ec.js +288 -0
  63. package/lib/commonjs/ec.js.map +1 -0
  64. package/lib/commonjs/index.js +3 -15
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/keys.js +280 -48
  67. package/lib/commonjs/keys.js.map +1 -1
  68. package/lib/commonjs/pbkdf2.js +44 -18
  69. package/lib/commonjs/pbkdf2.js.map +1 -1
  70. package/lib/commonjs/random.js +49 -68
  71. package/lib/commonjs/random.js.map +1 -1
  72. package/lib/commonjs/rsa.js +329 -0
  73. package/lib/commonjs/rsa.js.map +1 -0
  74. package/lib/commonjs/sig.js +13 -54
  75. package/lib/commonjs/sig.js.map +1 -1
  76. package/lib/commonjs/subtle.js +271 -0
  77. package/lib/commonjs/subtle.js.map +1 -0
  78. package/lib/module/@types/crypto-browserify.d.js.map +1 -1
  79. package/lib/module/Cipher.js +54 -189
  80. package/lib/module/Cipher.js.map +1 -1
  81. package/lib/module/Hash.js +27 -21
  82. package/lib/module/Hash.js.map +1 -1
  83. package/lib/module/Hashnames.js +71 -0
  84. package/lib/module/Hashnames.js.map +1 -0
  85. package/lib/module/Hmac.js +4 -21
  86. package/lib/module/Hmac.js.map +1 -1
  87. package/lib/module/NativeQuickCrypto/Cipher.js +3 -4
  88. package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -1
  89. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +11 -17
  90. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  91. package/lib/module/NativeQuickCrypto/hash.js.map +1 -1
  92. package/lib/module/NativeQuickCrypto/hmac.js.map +1 -1
  93. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +1 -1
  94. package/lib/module/NativeQuickCrypto/random.js.map +1 -1
  95. package/lib/module/NativeQuickCrypto/sig.js.map +1 -1
  96. package/lib/module/NativeQuickCrypto/webcrypto.js +2 -0
  97. package/lib/module/NativeQuickCrypto/webcrypto.js.map +1 -0
  98. package/lib/module/QuickCrypto.js +6 -1
  99. package/lib/module/QuickCrypto.js.map +1 -1
  100. package/lib/module/Utils.js +327 -33
  101. package/lib/module/Utils.js.map +1 -1
  102. package/lib/module/aes.js +317 -0
  103. package/lib/module/aes.js.map +1 -0
  104. package/lib/module/constants.js.map +1 -1
  105. package/lib/module/ec.js +282 -0
  106. package/lib/module/ec.js.map +1 -0
  107. package/lib/module/index.js +4 -8
  108. package/lib/module/index.js.map +1 -1
  109. package/lib/module/keys.js +279 -43
  110. package/lib/module/keys.js.map +1 -1
  111. package/lib/module/pbkdf2.js +44 -13
  112. package/lib/module/pbkdf2.js.map +1 -1
  113. package/lib/module/random.js +46 -54
  114. package/lib/module/random.js.map +1 -1
  115. package/lib/module/rsa.js +323 -0
  116. package/lib/module/rsa.js.map +1 -0
  117. package/lib/module/sig.js +13 -46
  118. package/lib/module/sig.js.map +1 -1
  119. package/lib/module/subtle.js +265 -0
  120. package/lib/module/subtle.js.map +1 -0
  121. package/lib/typescript/src/Cipher.d.ts +72 -0
  122. package/lib/typescript/src/Cipher.d.ts.map +1 -0
  123. package/lib/typescript/{Hash.d.ts → src/Hash.d.ts} +8 -7
  124. package/lib/typescript/src/Hash.d.ts.map +1 -0
  125. package/lib/typescript/src/Hashnames.d.ts +11 -0
  126. package/lib/typescript/src/Hashnames.d.ts.map +1 -0
  127. package/lib/typescript/{Hmac.d.ts → src/Hmac.d.ts} +3 -3
  128. package/lib/typescript/src/Hmac.d.ts.map +1 -0
  129. package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts +34 -0
  130. package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts.map +1 -0
  131. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/NativeQuickCrypto.d.ts +3 -0
  132. package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +1 -0
  133. package/lib/typescript/src/NativeQuickCrypto/hash.d.ts +7 -0
  134. package/lib/typescript/src/NativeQuickCrypto/hash.d.ts.map +1 -0
  135. package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts +6 -0
  136. package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts.map +1 -0
  137. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/pbkdf2.d.ts +2 -1
  138. package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts.map +1 -0
  139. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/random.d.ts +2 -1
  140. package/lib/typescript/src/NativeQuickCrypto/random.d.ts.map +1 -0
  141. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/sig.d.ts +5 -4
  142. package/lib/typescript/src/NativeQuickCrypto/sig.d.ts.map +1 -0
  143. package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts +27 -0
  144. package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts.map +1 -0
  145. package/lib/typescript/{QuickCrypto.d.ts → src/QuickCrypto.d.ts} +18 -8
  146. package/lib/typescript/src/QuickCrypto.d.ts.map +1 -0
  147. package/lib/typescript/src/Utils.d.ts +46 -0
  148. package/lib/typescript/src/Utils.d.ts.map +1 -0
  149. package/lib/typescript/src/aes.d.ts +5 -0
  150. package/lib/typescript/src/aes.d.ts.map +1 -0
  151. package/lib/typescript/{constants.d.ts → src/constants.d.ts} +1 -0
  152. package/lib/typescript/src/constants.d.ts.map +1 -0
  153. package/lib/typescript/src/ec.d.ts +5 -0
  154. package/lib/typescript/src/ec.d.ts.map +1 -0
  155. package/lib/typescript/src/index.d.ts +3 -0
  156. package/lib/typescript/src/index.d.ts.map +1 -0
  157. package/lib/typescript/src/keys.d.ts +154 -0
  158. package/lib/typescript/src/keys.d.ts.map +1 -0
  159. package/lib/typescript/src/pbkdf2.d.ts +12 -0
  160. package/lib/typescript/src/pbkdf2.d.ts.map +1 -0
  161. package/lib/typescript/{random.d.ts → src/random.d.ts} +7 -6
  162. package/lib/typescript/src/random.d.ts.map +1 -0
  163. package/lib/typescript/src/rsa.d.ts +4 -0
  164. package/lib/typescript/src/rsa.d.ts.map +1 -0
  165. package/lib/typescript/{sig.d.ts → src/sig.d.ts} +3 -3
  166. package/lib/typescript/src/sig.d.ts.map +1 -0
  167. package/lib/typescript/src/subtle.d.ts +11 -0
  168. package/lib/typescript/src/subtle.d.ts.map +1 -0
  169. package/package.json +39 -34
  170. package/react-native-quick-crypto.podspec +4 -5
  171. package/src/Cipher.ts +108 -102
  172. package/src/Hash.ts +42 -6
  173. package/src/Hashnames.ts +91 -0
  174. package/src/Hmac.ts +3 -3
  175. package/src/NativeQuickCrypto/Cipher.ts +1 -0
  176. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +2 -0
  177. package/src/NativeQuickCrypto/webcrypto.ts +46 -0
  178. package/src/QuickCrypto.ts +5 -0
  179. package/src/Utils.ts +491 -5
  180. package/src/aes.ts +365 -0
  181. package/src/ec.ts +351 -0
  182. package/src/index.ts +3 -8
  183. package/src/keys.ts +428 -54
  184. package/src/pbkdf2.ts +84 -11
  185. package/src/random.ts +37 -24
  186. package/src/rsa.ts +396 -0
  187. package/src/sig.ts +3 -2
  188. package/src/subtle.ts +358 -0
  189. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  190. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  191. package/android/gradlew +0 -183
  192. package/android/gradlew.bat +0 -100
  193. package/lib/commonjs/@types/stream-browserify.d.js +0 -2
  194. package/lib/commonjs/@types/stream-browserify.d.js.map +0 -1
  195. package/lib/module/@types/stream-browserify.d.js +0 -2
  196. package/lib/module/@types/stream-browserify.d.js.map +0 -1
  197. package/lib/typescript/Cipher.d.ts +0 -87
  198. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -32
  199. package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -6
  200. package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -5
  201. package/lib/typescript/Utils.d.ts +0 -23
  202. package/lib/typescript/index.d.ts +0 -207
  203. package/lib/typescript/keys.d.ts +0 -60
  204. package/lib/typescript/pbkdf2.d.ts +0 -9
  205. package/src/@types/stream-browserify.d.ts +0 -4
@@ -10,28 +10,19 @@ exports.createDecipheriv = createDecipheriv;
10
10
  exports.generateKeyPair = generateKeyPair;
11
11
  exports.generateKeyPairSync = generateKeyPairSync;
12
12
  exports.publicEncrypt = exports.publicDecrypt = exports.privateDecrypt = void 0;
13
-
14
13
  var _NativeQuickCrypto = require("./NativeQuickCrypto/NativeQuickCrypto");
15
-
16
- var _streamBrowserify = _interopRequireDefault(require("stream-browserify"));
17
-
14
+ var _readableStream = _interopRequireDefault(require("readable-stream"));
18
15
  var _Utils = require("./Utils");
19
-
20
16
  var _Cipher = require("./NativeQuickCrypto/Cipher");
21
-
22
17
  var _string_decoder = require("string_decoder");
23
-
24
18
  var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
25
-
26
19
  var _safeBuffer = require("safe-buffer");
27
-
28
20
  var _constants = require("./constants");
29
-
30
21
  var _keys = require("./keys");
31
-
32
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+ /* eslint-disable no-dupe-class-members */
33
24
 
34
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
+ // @types/node
35
26
 
36
27
  // make sure that nextTick is there
37
28
  global.process.nextTick = setImmediate;
@@ -40,80 +31,59 @@ const createInternalDecipher = _NativeQuickCrypto.NativeQuickCrypto.createDeciph
40
31
  const _publicEncrypt = _NativeQuickCrypto.NativeQuickCrypto.publicEncrypt;
41
32
  const _publicDecrypt = _NativeQuickCrypto.NativeQuickCrypto.publicDecrypt;
42
33
  const _privateDecrypt = _NativeQuickCrypto.NativeQuickCrypto.privateDecrypt;
43
-
44
34
  function getUIntOption(options, key) {
45
35
  let value;
46
-
47
36
  if (options && (value = options[key]) != null) {
48
37
  // >>> Turns any type into a positive integer (also sets the sign bit to 0)
49
38
  // eslint-disable-next-line no-bitwise
50
39
  if (value >>> 0 !== value) throw new Error(`options.${key}: ${value}`);
51
40
  return value;
52
41
  }
53
-
54
42
  return -1;
55
43
  }
56
-
57
44
  function normalizeEncoding(enc) {
58
45
  if (!enc) return 'utf8';
59
46
  var retried;
60
-
61
47
  while (true) {
62
48
  switch (enc) {
63
49
  case 'utf8':
64
50
  case 'utf-8':
65
51
  return 'utf8';
66
-
67
52
  case 'ucs2':
68
53
  case 'ucs-2':
69
54
  case 'utf16le':
70
55
  case 'utf-16le':
71
56
  return 'utf16le';
72
-
73
57
  case 'latin1':
74
58
  case 'binary':
75
59
  return 'latin1';
76
-
77
60
  case 'base64':
78
61
  case 'ascii':
79
62
  case 'hex':
80
63
  return enc;
81
-
82
64
  default:
83
65
  if (retried) return; // undefined
84
-
85
66
  enc = ('' + enc).toLowerCase();
86
67
  retried = true;
87
68
  }
88
69
  }
89
70
  }
90
-
91
71
  function validateEncoding(data, encoding) {
92
72
  const normalizedEncoding = normalizeEncoding(encoding);
93
73
  const length = data.length;
94
-
95
74
  if (normalizedEncoding === 'hex' && length % 2 !== 0) {
96
75
  throw new Error(`Encoding ${encoding} not valid for data length ${length}`);
97
76
  }
98
77
  }
99
-
100
78
  function getDecoder(decoder, encoding) {
101
- return decoder !== null && decoder !== void 0 ? decoder : new _string_decoder.StringDecoder(encoding);
79
+ return decoder ?? new _string_decoder.StringDecoder(encoding);
102
80
  }
103
-
104
- class CipherCommon extends _streamBrowserify.default.Transform {
105
- constructor(cipherType, cipherKey, isCipher) {
106
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
107
- let iv = arguments.length > 4 ? arguments[4] : undefined;
81
+ class CipherCommon extends _readableStream.default.Transform {
82
+ constructor(cipherType, cipherKey, isCipher, options = {}, iv) {
108
83
  super(options);
109
-
110
- _defineProperty(this, "internal", void 0);
111
-
112
- _defineProperty(this, "decoder", void 0);
113
-
114
- const cipherKeyBuffer = (0, _Utils.binaryLikeToArrayBuffer)(cipherKey); // TODO(osp) This might not be smart, check again after release
115
-
116
- const authTagLength = getUIntOption(options, 'authTagLength');
84
+ const cipherKeyBuffer = (0, _Utils.binaryLikeToArrayBuffer)(cipherKey);
85
+ // defaults to 16 bytes
86
+ const authTagLength = getUIntOption(options, 'authTagLength') !== -1 ? getUIntOption(options, 'authTagLength') : 16;
117
87
  const args = {
118
88
  cipher_type: cipherType,
119
89
  cipher_key: cipherKeyBuffer,
@@ -123,20 +93,15 @@ class CipherCommon extends _streamBrowserify.default.Transform {
123
93
  };
124
94
  this.internal = isCipher ? createInternalCipher(args) : createInternalDecipher(args);
125
95
  }
126
-
127
96
  update(data, inputEncoding, outputEncoding) {
128
- var _inputEncoding, _outputEncoding;
129
-
130
97
  const defaultEncoding = (0, _Utils.getDefaultEncoding)();
131
- inputEncoding = (_inputEncoding = inputEncoding) !== null && _inputEncoding !== void 0 ? _inputEncoding : defaultEncoding;
132
- outputEncoding = (_outputEncoding = outputEncoding) !== null && _outputEncoding !== void 0 ? _outputEncoding : defaultEncoding;
133
-
98
+ inputEncoding = inputEncoding ?? defaultEncoding;
99
+ outputEncoding = outputEncoding ?? defaultEncoding;
134
100
  if (typeof data === 'string') {
135
101
  validateEncoding(data, inputEncoding);
136
102
  } else if (!ArrayBuffer.isView(data)) {
137
103
  throw new Error('Invalid data argument');
138
104
  }
139
-
140
105
  if (typeof data === 'string') {
141
106
  // On node this is handled on the native side
142
107
  // on our case we need to correctly send the arraybuffer to the jsi side
@@ -145,171 +110,81 @@ class CipherCommon extends _streamBrowserify.default.Transform {
145
110
  } else {
146
111
  data = (0, _Utils.binaryLikeToArrayBuffer)(data, inputEncoding);
147
112
  }
148
-
149
113
  const ret = this.internal.update(data);
150
-
151
114
  if (outputEncoding && outputEncoding !== 'buffer') {
152
115
  this.decoder = getDecoder(this.decoder, outputEncoding);
153
116
  return this.decoder.write(_safeBuffer.Buffer.from(ret));
154
117
  }
155
-
156
118
  return ret;
157
119
  }
158
-
159
120
  final(outputEncoding) {
160
121
  const ret = this.internal.final();
161
-
162
122
  if (outputEncoding && outputEncoding !== 'buffer') {
163
123
  this.decoder = getDecoder(this.decoder, outputEncoding);
164
124
  return this.decoder.end(_safeBuffer.Buffer.from(ret));
165
125
  }
166
-
167
126
  return ret;
168
127
  }
169
-
170
128
  _transform(chunk, encoding, callback) {
171
129
  this.push(this.update(chunk, encoding));
172
130
  callback();
173
131
  }
174
-
175
132
  _flush(callback) {
176
133
  this.push(this.final());
177
134
  callback();
178
135
  }
179
-
180
136
  setAutoPadding(autoPadding) {
181
137
  this.internal.setAutoPadding(!!autoPadding);
182
138
  return this;
183
139
  }
184
-
185
140
  setAAD(buffer, options) {
186
141
  this.internal.setAAD({
187
142
  data: buffer.buffer,
188
- plaintextLength: options === null || options === void 0 ? void 0 : options.plaintextLength
143
+ plaintextLength: options?.plaintextLength
189
144
  });
190
145
  return this;
191
- } // protected getAuthTag(): Buffer {
192
- // return Buffer.from(this.internal.getAuthTag());
193
- // }
194
-
195
-
146
+ }
147
+ getAuthTag() {
148
+ return this.internal.getAuthTag();
149
+ }
196
150
  setAuthTag(tag) {
197
- this.internal.setAuthTag(tag.buffer);
151
+ this.internal.setAuthTag((0, _Utils.binaryLikeToArrayBuffer)(tag));
198
152
  return this;
199
153
  }
200
-
201
154
  }
202
-
203
155
  class Cipher extends CipherCommon {
204
- constructor(cipherType, cipherKey) {
205
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
206
- let iv = arguments.length > 3 ? arguments[3] : undefined;
207
-
156
+ constructor(cipherType, cipherKey, options = {}, iv) {
208
157
  if (iv != null) {
209
158
  iv = (0, _Utils.binaryLikeToArrayBuffer)(iv);
210
159
  }
211
-
212
160
  super(cipherType, cipherKey, true, options, iv);
213
161
  }
214
-
215
162
  }
216
-
217
163
  class Decipher extends CipherCommon {
218
- constructor(cipherType, cipherKey) {
219
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
220
- let iv = arguments.length > 3 ? arguments[3] : undefined;
221
-
164
+ constructor(cipherType, cipherKey, options = {}, iv) {
222
165
  if (iv != null) {
223
166
  iv = (0, _Utils.binaryLikeToArrayBuffer)(iv);
224
167
  }
225
-
226
168
  super(cipherType, cipherKey, false, options, iv);
227
169
  }
228
-
229
- } // TODO(osp) This definitions cause typescript errors when using the API
230
- // export function createDecipher(
231
- // algorithm: CipherCCMTypes,
232
- // password: BinaryLike,
233
- // options: CipherCCMOptions
234
- // ): Decipher;
235
- // export function createDecipher(
236
- // algorithm: CipherGCMTypes,
237
- // password: BinaryLike,
238
- // options?: CipherGCMOptions
239
- // ): Decipher;
240
-
241
-
170
+ }
242
171
  function createDecipher(algorithm, password, options) {
243
172
  return new Decipher(algorithm, password, options);
244
- } // TODO(osp) This definitions cause typescript errors when using the API
245
- // export function createDecipheriv(
246
- // algorithm: CipherCCMTypes,
247
- // key: BinaryLike,
248
- // iv: BinaryLike,
249
- // options: CipherCCMOptions
250
- // ): Decipher;
251
- // export function createDecipheriv(
252
- // algorithm: CipherOCBTypes,
253
- // key: BinaryLike,
254
- // iv: BinaryLike,
255
- // options: CipherOCBOptions
256
- // ): DecipherOCB;
257
- // export function createDecipheriv(
258
- // algorithm: CipherGCMTypes,
259
- // key: BinaryLike,
260
- // iv: BinaryLike,
261
- // options?: CipherGCMOptions
262
- // ): Decipher;
263
-
264
-
173
+ }
265
174
  function createDecipheriv(algorithm, key, iv, options) {
266
175
  return new Decipher(algorithm, key, options, iv);
267
- } // TODO(osp) This definitions cause typescript errors when using the API
268
- // commenting them out for now
269
- // export function createCipher(
270
- // algorithm: CipherCCMTypes,
271
- // password: BinaryLike,
272
- // options: CipherCCMOptions
273
- // ): Cipher;
274
- // export function createCipher(
275
- // algorithm: CipherGCMTypes,
276
- // password: BinaryLike,
277
- // options?: CipherGCMOptions
278
- // ): Cipher;
279
-
280
-
176
+ }
281
177
  function createCipher(algorithm, password, options) {
282
178
  return new Cipher(algorithm, password, options);
283
- } // TODO(osp) on all the createCipheriv methods, node seems to use a "KeyObject" is seems to be a thread safe
284
- // object that creates keys and what not. Not sure if we should support it.
285
- // Fow now I replaced all of them to BinaryLike
286
- // export function createCipheriv(
287
- // algorithm: CipherCCMTypes,
288
- // key: BinaryLike,
289
- // iv: BinaryLike,
290
- // options: CipherCCMOptions
291
- // ): Cipher;
292
- // export function createCipheriv(
293
- // algorithm: CipherOCBTypes,
294
- // key: BinaryLike,
295
- // iv: BinaryLike,
296
- // options: CipherOCBOptions
297
- // ): CipherOCB;
298
- // export function createCipheriv(
299
- // algorithm: CipherGCMTypes,
300
- // key: BinaryLike,
301
- // iv: BinaryLike,
302
- // options?: CipherGCMOptions
303
- // ): Cipher;
304
-
305
-
179
+ }
306
180
  function createCipheriv(algorithm, key, iv, options) {
307
181
  return new Cipher(algorithm, key, options, iv);
308
- } // RSA Functions
309
- // Follows closely the model implemented in node
310
- // TODO(osp) types...
182
+ }
311
183
 
184
+ // RSA Functions
185
+ // Follows closely the model implemented in node
312
186
 
187
+ // TODO(osp) types...
313
188
  function rsaFunctionFor(method, defaultPadding, keyType) {
314
189
  return (options, buffer) => {
315
190
  const {
@@ -333,14 +208,13 @@ function rsaFunctionFor(method, defaultPadding, keyType) {
333
208
  return _reactNativeBuffer.Buffer.from(rawRes);
334
209
  };
335
210
  }
336
-
337
- const publicEncrypt = rsaFunctionFor(_publicEncrypt, _constants.constants.RSA_PKCS1_OAEP_PADDING, 'public');
338
- exports.publicEncrypt = publicEncrypt;
339
- const publicDecrypt = rsaFunctionFor(_publicDecrypt, _constants.constants.RSA_PKCS1_PADDING, 'public'); // const privateEncrypt = rsaFunctionFor(_privateEncrypt, constants.RSA_PKCS1_PADDING,
211
+ const publicEncrypt = exports.publicEncrypt = rsaFunctionFor(_publicEncrypt, _constants.constants.RSA_PKCS1_OAEP_PADDING, 'public');
212
+ const publicDecrypt = exports.publicDecrypt = rsaFunctionFor(_publicDecrypt, _constants.constants.RSA_PKCS1_PADDING, 'public');
213
+ // const privateEncrypt = rsaFunctionFor(_privateEncrypt, constants.RSA_PKCS1_PADDING,
340
214
  // 'private');
215
+ const privateDecrypt = exports.privateDecrypt = rsaFunctionFor(_privateDecrypt, _constants.constants.RSA_PKCS1_OAEP_PADDING, 'private');
341
216
 
342
- exports.publicDecrypt = publicDecrypt;
343
- const privateDecrypt = rsaFunctionFor(_privateDecrypt, _constants.constants.RSA_PKCS1_OAEP_PADDING, 'private'); // _ _ __ _____ _
217
+ // _ _ __ _____ _
344
218
  // | | | |/ / | __ \ (_)
345
219
  // __ _ ___ _ __ ___ _ __ __ _| |_ ___| ' / ___ _ _| |__) |_ _ _ _ __
346
220
  // / _` |/ _ \ '_ \ / _ \ '__/ _` | __/ _ \ < / _ \ | | | ___/ _` | | '__|
@@ -349,16 +223,12 @@ const privateDecrypt = rsaFunctionFor(_privateDecrypt, _constants.constants.RSA_
349
223
  // __/ | __/ |
350
224
  // |___/ |___/
351
225
 
352
- exports.privateDecrypt = privateDecrypt;
353
-
354
- function parseKeyEncoding(keyType) {
355
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _Utils.kEmptyObject;
226
+ function parseKeyEncoding(keyType, options = _Utils.kEmptyObject) {
356
227
  const {
357
228
  publicKeyEncoding,
358
229
  privateKeyEncoding
359
230
  } = options;
360
231
  let publicFormat, publicType;
361
-
362
232
  if (publicKeyEncoding == null) {
363
233
  publicFormat = publicType = undefined;
364
234
  } else if (typeof publicKeyEncoding === 'object') {
@@ -369,9 +239,7 @@ function parseKeyEncoding(keyType) {
369
239
  } else {
370
240
  throw new Error('Invalid argument options.publicKeyEncoding', publicKeyEncoding);
371
241
  }
372
-
373
242
  let privateFormat, privateType, cipher, passphrase;
374
-
375
243
  if (privateKeyEncoding == null) {
376
244
  privateFormat = privateType = undefined;
377
245
  } else if (typeof privateKeyEncoding === 'object') {
@@ -384,14 +252,14 @@ function parseKeyEncoding(keyType) {
384
252
  } else {
385
253
  throw new Error('Invalid argument options.privateKeyEncoding', publicKeyEncoding);
386
254
  }
387
-
388
255
  return [publicFormat, publicType, privateFormat, privateType, cipher, passphrase];
389
256
  }
390
-
391
257
  function internalGenerateKeyPair(isAsync, type, options, callback) {
392
258
  // On node a very complex "job" chain is created, we are going for a far simpler approach and calling
393
259
  // an internal function that basically executes the same byte shuffling on the native side
394
- const encoding = parseKeyEncoding(type, options); // if (options !== undefined)
260
+ const encoding = parseKeyEncoding(type, options);
261
+
262
+ // if (options !== undefined)
395
263
  // validateObject(options, 'options');
396
264
 
397
265
  switch (type) {
@@ -406,60 +274,50 @@ function internalGenerateKeyPair(isAsync, type, options, callback) {
406
274
  let {
407
275
  publicExponent
408
276
  } = options;
409
-
410
277
  if (publicExponent == null) {
411
278
  publicExponent = 0x10001;
412
279
  } else {
413
280
  (0, _Utils.validateUint32)(publicExponent, 'options.publicExponent');
414
281
  }
415
-
416
282
  if (type === 'rsa') {
417
283
  if (isAsync) {
418
- _NativeQuickCrypto.NativeQuickCrypto.generateKeyPair(_Cipher.RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5, modulusLength, publicExponent, ...encoding).then(_ref => {
419
- let [err, publicKey, privateKey] = _ref;
420
-
284
+ _NativeQuickCrypto.NativeQuickCrypto.generateKeyPair(_Cipher.RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5, modulusLength, publicExponent, ...encoding).then(([err, publicKey, privateKey]) => {
421
285
  if (typeof publicKey === 'object') {
422
286
  publicKey = _reactNativeBuffer.Buffer.from(publicKey);
423
287
  }
424
-
425
288
  if (typeof privateKey === 'object') {
426
289
  privateKey = _reactNativeBuffer.Buffer.from(privateKey);
427
290
  }
428
-
429
- callback === null || callback === void 0 ? void 0 : callback(err, publicKey, privateKey);
291
+ callback?.(err, publicKey, privateKey);
430
292
  }).catch(err => {
431
- callback === null || callback === void 0 ? void 0 : callback(err, undefined, undefined);
293
+ callback?.(err, undefined, undefined);
432
294
  });
433
-
434
295
  return;
435
296
  } else {
436
297
  let [err, publicKey, privateKey] = _NativeQuickCrypto.NativeQuickCrypto.generateKeyPairSync(_Cipher.RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5, modulusLength, publicExponent, ...encoding);
437
-
438
298
  if (typeof publicKey === 'object') {
439
299
  publicKey = _reactNativeBuffer.Buffer.from(publicKey);
440
300
  }
441
-
442
301
  if (typeof privateKey === 'object') {
443
302
  privateKey = _reactNativeBuffer.Buffer.from(privateKey);
444
303
  }
445
-
446
304
  return [err, publicKey, privateKey];
447
305
  }
448
306
  }
449
-
450
307
  const {
451
308
  hash,
452
309
  mgf1Hash,
453
310
  hashAlgorithm,
454
311
  mgf1HashAlgorithm,
455
312
  saltLength
456
- } = options; // // We don't have a process object on RN
313
+ } = options;
314
+
315
+ // // We don't have a process object on RN
457
316
  // // const pendingDeprecation = getOptionValue('--pending-deprecation');
458
317
 
459
318
  if (saltLength !== undefined) (0, _Utils.validateInt32)(saltLength, 'options.saltLength', 0);
460
319
  if (hashAlgorithm !== undefined) (0, _Utils.validateString)(hashAlgorithm, 'options.hashAlgorithm');
461
320
  if (mgf1HashAlgorithm !== undefined) (0, _Utils.validateString)(mgf1HashAlgorithm, 'options.mgf1HashAlgorithm');
462
-
463
321
  if (hash !== undefined) {
464
322
  // pendingDeprecation && process.emitWarning(
465
323
  // '"options.hash" is deprecated, ' +
@@ -467,12 +325,10 @@ function internalGenerateKeyPair(isAsync, type, options, callback) {
467
325
  // 'DeprecationWarning',
468
326
  // 'DEP0154');
469
327
  (0, _Utils.validateString)(hash, 'options.hash');
470
-
471
328
  if (hashAlgorithm && hash !== hashAlgorithm) {
472
329
  throw new Error(`Invalid Argument options.hash ${hash}`);
473
330
  }
474
331
  }
475
-
476
332
  if (mgf1Hash !== undefined) {
477
333
  // pendingDeprecation && process.emitWarning(
478
334
  // '"options.mgf1Hash" is deprecated, ' +
@@ -480,22 +336,22 @@ function internalGenerateKeyPair(isAsync, type, options, callback) {
480
336
  // 'DeprecationWarning',
481
337
  // 'DEP0154');
482
338
  (0, _Utils.validateString)(mgf1Hash, 'options.mgf1Hash');
483
-
484
339
  if (mgf1HashAlgorithm && mgf1Hash !== mgf1HashAlgorithm) {
485
340
  throw new Error(`Invalid Argument options.mgf1Hash ${mgf1Hash}`);
486
341
  }
487
342
  }
488
-
489
343
  return _NativeQuickCrypto.NativeQuickCrypto.generateKeyPairSync(_Cipher.RSAKeyVariant.kKeyVariantRSA_PSS, modulusLength, publicExponent, hashAlgorithm || hash, mgf1HashAlgorithm || mgf1Hash, saltLength, ...encoding);
490
344
  }
491
345
  // case 'dsa': {
492
346
  // validateObject(options, 'options');
493
347
  // const { modulusLength } = options!;
494
348
  // validateUint32(modulusLength, 'options.modulusLength');
349
+
495
350
  // let { divisorLength } = options!;
496
351
  // if (divisorLength == null) {
497
352
  // divisorLength = -1;
498
353
  // } else validateInt32(divisorLength, 'options.divisorLength', 0);
354
+
499
355
  // // return new DsaKeyPairGenJob(
500
356
  // // mode,
501
357
  // // modulusLength,
@@ -514,6 +370,7 @@ function internalGenerateKeyPair(isAsync, type, options, callback) {
514
370
  // else
515
371
  // throw new Error(`Invalid Argument options.paramEncoding ${paramEncoding}`);
516
372
  // // throw new ERR_INVALID_ARG_VALUE('options.paramEncoding', paramEncoding);
373
+
517
374
  // // return new EcKeyPairGenJob(mode, namedCurve, paramEncoding, ...encoding);
518
375
  // }
519
376
  // case 'ed25519':
@@ -547,12 +404,16 @@ function internalGenerateKeyPair(isAsync, type, options, callback) {
547
404
  // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'primeLength');
548
405
  // if (generator != null)
549
406
  // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'generator');
407
+
550
408
  // validateString(group, 'options.group');
409
+
551
410
  // return new DhKeyPairGenJob(mode, group, ...encoding);
552
411
  // }
412
+
553
413
  // if (prime != null) {
554
414
  // if (primeLength != null)
555
415
  // throw new ERR_INCOMPATIBLE_OPTION_PAIR('prime', 'primeLength');
416
+
556
417
  // validateBuffer(prime, 'options.prime');
557
418
  // } else if (primeLength != null) {
558
419
  // validateInt32(primeLength, 'options.primeLength', 0);
@@ -561,6 +422,7 @@ function internalGenerateKeyPair(isAsync, type, options, callback) {
561
422
  // 'At least one of the group, prime, or primeLength options'
562
423
  // );
563
424
  // }
425
+
564
426
  // if (generator != null) {
565
427
  // validateInt32(generator, 'options.generator', 0);
566
428
  // }
@@ -571,25 +433,22 @@ function internalGenerateKeyPair(isAsync, type, options, callback) {
571
433
  // ...encoding
572
434
  // );
573
435
  // }
574
-
575
- default: // Fall through
576
-
436
+ default:
437
+ // Fall through
577
438
  }
578
-
579
439
  throw new Error(`Invalid Argument options: ${type} scheme not supported. Currently not all encryption methods are supported in quick-crypto!`);
580
- } // TODO(osp) put correct types (e.g. type -> 'rsa', etc..)
440
+ }
581
441
 
442
+ // TODO(osp) put correct types (e.g. type -> 'rsa', etc..)
582
443
 
583
444
  function generateKeyPair(type, options, callback) {
584
445
  if (typeof options === 'function') {
585
446
  callback = options;
586
447
  options = undefined;
587
448
  }
588
-
589
449
  (0, _Utils.validateFunction)(callback);
590
450
  internalGenerateKeyPair(true, type, options, callback);
591
451
  }
592
-
593
452
  function generateKeyPairSync(type, options) {
594
453
  const [_, publicKey, privateKey] = internalGenerateKeyPair(false, type, options, undefined);
595
454
  return {